|
@@ -46,8 +46,8 @@ const initWasm = (url) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-let canvasEl
|
|
|
let ctx
|
|
|
+let baseUrl
|
|
|
|
|
|
const r = 26 // 圆的半径
|
|
|
const l_x = 47 + r // 左上角圆的圆的心x坐标
|
|
@@ -62,7 +62,7 @@ const drawPlc = async (key, index, val, type) => {
|
|
|
if (!ctx) return
|
|
|
ctx.font = '30px Noto Sans SC'
|
|
|
if (type === 'init') {
|
|
|
- const response = await fetch(new URL('/wxapp/canvas-icon/ditu.png', self.location.href).href)
|
|
|
+ const response = await fetch(new URL(baseUrl + 'canvas-icon/ditu.png', self.location.href).href)
|
|
|
const blob = await response.blob()
|
|
|
const imgBitmap = await createImageBitmap(blob)
|
|
|
ctx.drawImage(imgBitmap, 0, 0)
|
|
@@ -107,23 +107,15 @@ const DIValMap = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
|
let doCom = false
|
|
|
|
|
|
onmessage = (e) => {
|
|
|
- const { type, url, canvas, position, val, i } = e.data
|
|
|
- if (!canvasEl && type === 'init') {
|
|
|
- canvasEl = canvas
|
|
|
+ const { type, url, canvas, position, val, i, pathname } = e.data
|
|
|
+ if (type === 'init') {
|
|
|
+ baseUrl = pathname
|
|
|
ctx = canvas.getContext('2d')
|
|
|
initWasm(url)
|
|
|
drawPlc(null, null, null, 'init')
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
- drawPlc('DI', i, 0, 'draw')
|
|
|
- drawPlc('DO', i, 0, 'draw')
|
|
|
DIValMap[i] = 0
|
|
|
}
|
|
|
- for (let i = 0; i < 4; i++) {
|
|
|
- drawPlc('AI', i, 0, 'draw')
|
|
|
- }
|
|
|
- for (let i = 0; i < 2; i++) {
|
|
|
- drawPlc('AO', i, 0, 'draw')
|
|
|
- }
|
|
|
}
|
|
|
if (type === 'set') {
|
|
|
_SetTrustAI(+i, +val * 1000)
|