Browse Source

绑定按钮插件

8-zhikong
aBin 4 years ago
parent
commit
a56a84df82
  1. 62
      index.html
  2. 12
      package-lock.json

62
index.html

@ -47,10 +47,10 @@
<!-- 示例插件2 id=100-->
<button class="bg-blue-500 py-2 px-5 rounded text-white" onclick="p100.show()">测试组建2</button>
<div data-pid="pid111" data-uid="1321399402832728064" data-rid="rid333" data-tid="tid444" data-did="did555">
<div class="bind-box">
<button class="bg-blue-500 py-2 px-5 rounded text-white" id="bind-status-one" style="display:none" onclick="p101.bindOne(this)">插件测试</button>
<button class="bg-blue-500 py-2 px-5 rounded text-white" id="bind-status-two" style="display:none" onclick="p101.bindTwo(this)">插件测试</button>
<div data-pid="1402932548627206144" data-uid="1323567842540523520" data-rid="rid333" data-tid="tid444" data-did="did555" style="height:40px;width:100px">
<div data-root="p101">
<button class="bg-green-500 py-1 px-3 rounded text-white" style="display:none" onclick="p101.bindOne(this)">插件测试</button>
<button class="bg-blue-500 py-1 px-3 rounded text-white" style="display:none" onclick="p101.bindTwo(this)">绑定平车</button>
</div>
</div>
@ -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'
}
}
};
</script>
</div>
</div>

12
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"
}
}
}
Loading…
Cancel
Save