From a56a84df82b7a8bd075dc09046d997289dc0be16 Mon Sep 17 00:00:00 2001 From: aBin Date: Tue, 27 Jul 2021 16:31:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=8C=89=E9=92=AE=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 62 +++++++++++++++++++++++++++++++++++------------ package-lock.json | 12 +++++++++ 2 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 package-lock.json diff --git a/index.html b/index.html index 933df37..bd4ce31 100644 --- a/index.html +++ b/index.html @@ -47,10 +47,10 @@ -
-
- - +
+
+ +
@@ -65,21 +65,52 @@ 1.进页面首先查询绑定状态 2.根据返回的数据,判断显示哪个btn */ - ;(function() { - var dom = document.getElementById('bind-box').parentNode - console.log(dom.getAttribute('data-pid')) - const uid = dom.getAttribute('data-uid') - getToken('1321399402832728064') - })() - function getToken(uid) { - console.log(uid); - fetch(`https://www.tall.wiki/gateway/tall/v1.0/users/userId?userId=${1202064120040525824}`) + ;(async function() { + var dom = document.querySelector("div[data-root=p101]"); + var domBox = dom.parentNode; + var domChild = document.querySelectorAll('div[data-root=p101]>button'); + const uid = domBox.getAttribute('data-uid'); + const pid = domBox.getAttribute('data-pid'); + const token = await getToken(uid); + const carInfo = await getBindCar(pid,token); + if(carInfo && carInfo.length) { + domChild[0].innerHTML = `平车${carNumber}` + domChild[0].style.display = 'block' + } else { + domChild[1].style.display = 'block' + } + })(); + /* + 根据uid获取token接口 + */ + async function getToken(uid) { + var token = '' + await fetch(`https://www.tall.wiki/gateway/tall/v1.0/users/userId?userId=${uid}`) .then(function(response) { return response.json(); }) .then(function(myJson) { - console.log(myJson); + token = myJson.data.token + }); + return token + } + /* + 查询绑定好的平车 + 1. 有则显示 平车+编号 按钮 + 2. 无泽显示 绑定平车 按钮 + */ + async function getBindCar(projectId,token) { + const params = { param: { projectId } } + const response = await fetch('https://www.tall.wiki/gateway/wisdomcar/car/queryBindingCar', { + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + 'Authorization': 'Bearer ' + token, + }, + body: JSON.stringify(params) }); + const json = await response.json(); + return json.data; } /* 1. p101插件的所有事件及属性 @@ -92,8 +123,9 @@ bindTwo(that) { console.log(that.parentNode.parentNode) console.log('data-uid',that.parentNode.parentNode.getAttribute('data-uid')) + location.href = 'https://www.baidu.com' } - } + };
diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..5d62d9f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "plugin-templete", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "version": "1.0.0", + "license": "ISC" + } + } +}