modify:新增小程序

This commit is contained in:
ECRZ
2026-01-06 18:00:43 +08:00
parent 498fa0e915
commit da4a055c1c
47 changed files with 7321 additions and 61 deletions

View File

@@ -0,0 +1,90 @@
Component({
properties: {
canvasId: {
type: String,
value: 'ec-canvas'
},
ec: {
type: Object,
value: {}
},
disableTouch: {
type: Boolean,
value: false
}
},
data: {
isNew: true
},
ready() {
console.log('ec-canvas ready')
if (!this.data.ec) {
console.warn('组件需绑定 ec 对象')
return
}
if (!this.data.ec.onInit) {
console.warn('ec 对象需包含 onInit 方法')
return
}
const query = this.createSelectorQuery()
query.select(`#${this.data.canvasId}`)
.fields({ node: true, size: true })
.exec((res) => {
console.log('Canvas query 结果:', res)
if (!res || !res[0]) {
console.error('Canvas 节点未找到')
return
}
const canvasNode = res[0].node
const ctx = canvasNode.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
const width = res[0].width
const height = res[0].height
console.log('Canvas 尺寸信息:', { width, height, dpr })
canvasNode.width = width * dpr
canvasNode.height = height * dpr
ctx.scale(dpr, dpr)
const canvas = {
width: width * dpr, // 使用缩放后的宽度
height: height * dpr, // 使用缩放后的高度
getContext: () => ctx,
node: canvasNode
}
console.log('准备调用 onInitcanvas 对象:', canvas)
this.chart = this.data.ec.onInit(canvas, width, height, res)
console.log('onInit 返回的 chart:', this.chart)
})
},
methods: {
touchStart(e) {
if (this.chart && this.chart.touchStart) {
this.chart.touchStart(e)
}
},
touchMove(e) {
if (this.chart && this.chart.touchMove) {
this.chart.touchMove(e)
}
},
touchEnd(e) {
if (this.chart && this.chart.touchEnd) {
this.chart.touchEnd(e)
}
}
}
})