8 changed files with 2334 additions and 18 deletions
File diff suppressed because it is too large
@ -0,0 +1,147 @@ |
|||
import { defineStore, storeToRefs } from 'pinia' |
|||
|
|||
import { useStore } from '@/store/root' |
|||
|
|||
import MD5 from 'crypto-js/md5' |
|||
|
|||
const useShockmanStore = defineStore('shockman', { |
|||
state: () => ({ |
|||
list: [], |
|||
intervalTimer: 0, |
|||
playTimer: 0, |
|||
index: 0 |
|||
}), |
|||
actions: { |
|||
SET_LIST(list) { |
|||
this.list = list |
|||
}, |
|||
SET_INTERVAL_TIMER(intervalTimer) { |
|||
this.intervalTimer = intervalTimer |
|||
}, |
|||
SET_PLAY_TIMER(playTimer) { |
|||
this.playTimer = playTimer |
|||
}, |
|||
APPEND_INDEX() { |
|||
this.index++ |
|||
} |
|||
} |
|||
}) |
|||
|
|||
export const isZhiluji = () => { |
|||
const store = useStore() |
|||
const { device } = storeToRefs(store) |
|||
return device.value.machineTypeName === '指路机' && device.value.targetInfoList && device.value.controlInfo |
|||
} |
|||
|
|||
const sendMsg2Shockman = async ({ progMode, progText1, progText2, progDist, progAngel }) => { |
|||
try { |
|||
const deviceKey = 'shockman!_$2023' |
|||
const body = new FormData() |
|||
body.append('deviceKey', deviceKey) |
|||
body.append('progMode', progMode) |
|||
body.append('progText1', progText1) |
|||
body.append('progTextColor', '6') |
|||
body.append('progText2', progText2) |
|||
body.append('progText2Color', '6') |
|||
body.append('progDist', progDist) |
|||
body.append('progDistColor', '6') |
|||
body.append('progAngel', progAngel) |
|||
body.append('progArmNo', '1') |
|||
body.append('progRota', '1') |
|||
body.append('progTrans', '1') |
|||
body.append('progDuration', '7200000') |
|||
body.append('progMd5', MD5(`${progMode}${progText1}6${progText2}6${progDist}6${progAngel}1117200000${deviceKey}`).toString().toUpperCase()) |
|||
body.append('progStat', '1') |
|||
const res = await fetch('http://192.168.2.124:8100/program/play', { method: 'POST', body }) |
|||
const json = await res.json() |
|||
if (json.rtnCode === '0') { |
|||
console.log(progText1, progText2, progDist, progAngel, '指路机执行成功') |
|||
} else { |
|||
console.log(progText1, progText2, progDist, progAngel, '指路机执行失败', json.rtnMsg) |
|||
} |
|||
} catch (error) { |
|||
console.log(progText1, progText2, progDist, progAngel, '指路机执行失败', error) |
|||
} |
|||
} |
|||
const sendMsgByInfo = info => { |
|||
const progMode = String(info.playWay) |
|||
const progText1 = info.oneText |
|||
const progText2 = info.playWay === 1 || info.playWay === 4 ? info.twoText : ' ' |
|||
const progDist = info.playWay === 3 || info.playWay === 4 ? ' ' : info.cost + '米' |
|||
const progAngel = String(info.angle) |
|||
sendMsg2Shockman({ progMode, progText1, progText2, progDist, progAngel }) |
|||
} |
|||
|
|||
const getIntervalTimer = () => { |
|||
const store = useStore() |
|||
const shockmanStore = useShockmanStore() |
|||
const { device } = storeToRefs(store) |
|||
const { list, index, playTimer } = storeToRefs(shockmanStore) |
|||
return setInterval(() => { |
|||
if (playTimer.value) { |
|||
clearTimeout(playTimer.value) |
|||
shockmanStore.SET_PLAY_TIMER(0) |
|||
} |
|||
shockmanStore.APPEND_INDEX() |
|||
const current = list.value[index.value % list.value.length] |
|||
if (current) sendMsgByInfo(current) |
|||
}, (device.value.controlInfo?.rotationTime || Infinity) * 1000) |
|||
} |
|||
|
|||
export const useShockman = () => { |
|||
const store = useStore() |
|||
const { device } = storeToRefs(store) |
|||
if (!(device.value.machineTypeName === '指路机' && device.value.targetInfoList && device.value.controlInfo)) { |
|||
return |
|||
} |
|||
const shockmanStore = useShockmanStore() |
|||
const { list, index } = storeToRefs(shockmanStore) |
|||
window.Map_QM.getObjectAngle && |
|||
shockmanStore.SET_LIST(window.Map_QM.getObjectAngle(device.value.targetInfoList.filter(({ status }) => status === 1)).filter(({ cost }) => cost)) |
|||
shockmanStore.SET_INTERVAL_TIMER(getIntervalTimer()) |
|||
|
|||
if (list.value.length) { |
|||
sendMsgByInfo(list.value[index.value]) |
|||
} |
|||
} |
|||
|
|||
export const playShockmanByNav = ({ progText1, progDist, progAngel }) => { |
|||
try { |
|||
const store = useStore() |
|||
const { device } = storeToRefs(store) |
|||
if (!(device.value.machineTypeName === '指路机' && device.value.targetInfoList && device.value.controlInfo)) { |
|||
return |
|||
} |
|||
const shockmanStore = useShockmanStore() |
|||
const { intervalTimer, playTimer } = storeToRefs(shockmanStore) |
|||
if (intervalTimer.value) { |
|||
clearInterval(intervalTimer.value) |
|||
shockmanStore.SET_INTERVAL_TIMER(0) |
|||
} |
|||
if (playTimer.value) { |
|||
clearTimeout(playTimer.value) |
|||
} |
|||
shockmanStore.SET_PLAY_TIMER( |
|||
setTimeout(() => { |
|||
shockmanStore.SET_INTERVAL_TIMER(getIntervalTimer()) |
|||
}, 60000) |
|||
) |
|||
sendMsg2Shockman({ progMode: '1', progText1, progText2: '由此方向向前', progDist, progAngel }) |
|||
} catch (error) { |
|||
console.log('指路机播放导航信息失败', error) |
|||
} |
|||
} |
|||
|
|||
export const resetIntervalTimer = () => { |
|||
const store = useStore() |
|||
const { device } = storeToRefs(store) |
|||
if (!(device.value.machineTypeName === '指路机' && device.value.targetInfoList && device.value.controlInfo)) { |
|||
return |
|||
} |
|||
const shockmanStore = useShockmanStore() |
|||
const { intervalTimer } = storeToRefs(shockmanStore) |
|||
if (intervalTimer.value) { |
|||
clearInterval(intervalTimer.value) |
|||
} |
|||
shockmanStore.SET_INTERVAL_TIMER(getIntervalTimer()) |
|||
} |
|||
Loading…
Reference in new issue