|
|
@ -48,9 +48,8 @@ |
|
|
|
<button class="bg-blue-500 py-2 px-5 rounded text-white" onclick="p100.show()">测试组建2</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 data-root="p102" style="height:100%;width:100"> |
|
|
|
<img style="height:100%;width:100" onclick="p102.jumpDetails()" src="https://img2.baidu.com/it/u=3960470193,627689163&fm=26&fmt=auto&gp=0.jpg"> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
@ -61,68 +60,8 @@ |
|
|
|
alert(this.name) |
|
|
|
} |
|
|
|
} |
|
|
|
/* |
|
|
|
1.进页面首先查询绑定状态 |
|
|
|
2.根据返回的数据,判断显示哪个btn |
|
|
|
*/ |
|
|
|
;(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) { |
|
|
|
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插件的所有事件及属性 |
|
|
|
*/ |
|
|
|
const p101 = { |
|
|
|
bindOne(that) { |
|
|
|
console.log(that.parentNode.parentNode) |
|
|
|
console.log('data-pid',that.parentNode.parentNode.getAttribute('data-pid')) |
|
|
|
}, |
|
|
|
bindTwo(that) { |
|
|
|
console.log(that.parentNode.parentNode) |
|
|
|
console.log('data-uid',that.parentNode.parentNode.getAttribute('data-uid')) |
|
|
|
const p102 = { |
|
|
|
jumpDetails() { |
|
|
|
location.href = 'https://www.baidu.com' |
|
|
|
} |
|
|
|
}; |
|
|
|