feat:优化页面按钮等样式

This commit is contained in:
R524809
2025-10-13 16:03:48 +08:00
parent 9df15e1ab4
commit 7ac81eb961
5 changed files with 59 additions and 42 deletions
-6
View File
@@ -42,12 +42,6 @@
"iconPath": "assets/tabBar/icon-shape.png", "iconPath": "assets/tabBar/icon-shape.png",
"selectedIconPath": "assets/tabBar/icon-shape-active.png", "selectedIconPath": "assets/tabBar/icon-shape-active.png",
"text": "图形" "text": "图形"
},
{
"pagePath": "pages/copyBook/index",
"iconPath": "assets/tabBar/icon-word.png",
"selectedIconPath": "assets/tabBar/icon-word-active.png",
"text": "练字"
} }
] ]
} }
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"navigationBarTitleText": "涂鸦丫", "navigationBarTitleText": "涂鸦丫-识字",
"navigationBarBackgroundColor": "#FFD719", "navigationBarBackgroundColor": "#FFD719",
"homeButton": true, "homeButton": true,
"backgroundColor": "#F6F6F6", "backgroundColor": "#F6F6F6",
+38 -13
View File
@@ -54,6 +54,12 @@ Page({
}, },
onReady() { onReady() {
// 当cardList为空时,canvas相关元素不会被渲染,所以不需要在这里初始化
// 尺寸计算将在initCanvas方法中进行
},
initCanvas() {
// 先获取canvasWrapper的尺寸来计算canvas尺寸
const query = wx.createSelectorQuery(); const query = wx.createSelectorQuery();
query query
.select('#canvasWrapper') .select('#canvasWrapper')
@@ -65,13 +71,8 @@ Page({
this.boxHeight = boxHeight; this.boxHeight = boxHeight;
this.boxWidth = boxWidth; this.boxWidth = boxWidth;
this.initCanvas(boxWidth, boxHeight);
}
})
.exec();
},
initCanvas(boxWidth: number, boxHeight: number) { // 然后初始化canvas
wx.createSelectorQuery() wx.createSelectorQuery()
.select('#canvasContent') .select('#canvasContent')
.fields({ .fields({
@@ -85,14 +86,20 @@ Page({
if (ctx) { if (ctx) {
this.canvas = canvas; this.canvas = canvas;
this.ctx = ctx; this.ctx = ctx;
// const rect = res[0];
this.textDrawService = new TextDrawService(canvas, ctx); this.textDrawService = new TextDrawService(canvas, ctx);
// textDrawService.draw();
this.setData({ boxWidth, boxHeight }); this.setData({ boxWidth, boxHeight });
this.drawCanvas();
// 初始化完成后,如果有cardList内容则立即绘制
const currentCardList = this.data.cardList;
if (currentCardList.length > 0) {
this.textDrawService.draw(currentCardList);
}
} }
} }
}); });
}
})
.exec();
}, },
/** 变更cardList 并更新canvas */ /** 变更cardList 并更新canvas */
@@ -102,12 +109,26 @@ Page({
) { ) {
if (updatedCardList) { if (updatedCardList) {
this.setData({ cardList: updatedCardList }, () => { this.setData({ cardList: updatedCardList }, () => {
this.textDrawService?.draw(updatedCardList!); // 如果cardList有内容且canvas未初始化,先初始化canvas
if (!this.canvas) {
this.initCanvas();
}
// 如果canvas已初始化且有内容,则绘制
if (this.textDrawService && updatedCardList!.length > 0) {
this.textDrawService.draw(updatedCardList!);
}
callback(); callback();
}); });
} else { } else {
updatedCardList = this.data.cardList; const currentCardList = this.data.cardList;
this.textDrawService?.draw(updatedCardList); // 如果cardList有内容且canvas未初始化,先初始化canvas
if (!this.canvas) {
this.initCanvas();
}
// 如果canvas已初始化且有内容,则绘制
if (this.textDrawService && currentCardList.length > 0) {
this.textDrawService.draw(currentCardList);
}
} }
}, },
@@ -212,7 +233,7 @@ Page({
}, },
onColorTap(e: WechatMiniprogram.CustomEvent) { onColorTap(e: WechatMiniprogram.CustomEvent) {
const { key, word, color } = e.detail; const { key, color } = e.detail;
this.setData({ this.setData({
showColorPopup: true, showColorPopup: true,
currentKey: key, currentKey: key,
@@ -262,6 +283,10 @@ Page({
}, },
clearCardList() { clearCardList() {
// 清空cardList时,重置canvas相关引用,因为DOM元素会被移除
this.canvas = null;
this.ctx = null;
this.textDrawService = null;
this.drawCanvas([]); this.drawCanvas([]);
}, },
+3 -5
View File
@@ -18,6 +18,7 @@
wx:for="{{cardList}}" wx:for="{{cardList}}"
wx:for-item="item" wx:for-item="item"
wx:for-index="index" wx:for-index="index"
key="{{index}}"
word="{{item.word}}" word="{{item.word}}"
color="{{item.color}}" color="{{item.color}}"
bind:onDelete="deleteWordCard" bind:onDelete="deleteWordCard"
@@ -59,12 +60,9 @@
</toy-button> </toy-button>
</view> </view>
</view> </view>
<view id="previewWrapper" class="wrapper"> <view id="previewWrapper" class="wrapper" wx:if="{{cardList.length > 0}}">
<text class="wrapper-title">预览打印效果</text> <text class="wrapper-title">预览打印效果</text>
<view <view id="canvasWrapper" class="canvas-wrapper">
wx:if="{{!isPCDevtool}}"
id="canvasWrapper"
class="canvas-wrapper">
<canvas <canvas
type="2d" type="2d"
id="canvasContent" id="canvasContent"
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"navigationBarTitleText": "涂鸦丫-图形", "navigationBarTitleText": "涂鸦丫-认识图形",
"navigationBarBackgroundColor": "#FFD719", "navigationBarBackgroundColor": "#FFD719",
"homeButton": true, "homeButton": true,
"backgroundColor": "#F6F6F6", "backgroundColor": "#F6F6F6",