diff --git a/miniprogram/app.json b/miniprogram/app.json index 46de07e..9a3cf55 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -1,5 +1,5 @@ { - "pages": ["pages/index/index"], + "pages": ["pages/index/index", "pages/debug/debug"], "window": {}, "style": "v2", "rendererOptions": { diff --git a/miniprogram/app.ts b/miniprogram/app.ts index 41afee8..7810a45 100644 --- a/miniprogram/app.ts +++ b/miniprogram/app.ts @@ -1,7 +1,33 @@ // app.ts App({ - globalData: {}, - onLaunch() { - + globalData: { + env: 'release' }, + onLaunch() { + const accountInfo = wx.getAccountInfoSync(); + const env = accountInfo.miniProgram.envVersion; + this.globalData.env = env; + if (env !== 'release') { + const printHeader = wx.getStorageSync('printHeader') || 'wechat'; + this.globalData.printHeader = printHeader; + } + }, + + onShow() { + // 小程序显示时的生命周期 + }, + + onHide() { + // 小程序隐藏时的生命周期 + }, + + getPrintHeader(): PrintHeader { + return this.globalData.printHeader || 'wechat'; + }, + + setPrintHeader(header: PrintHeader) { + header = header || 'wechat'; + this.globalData.printHeader = header; + wx.setStorageSync('printHeader', header); + } }); diff --git a/miniprogram/assets/imgs/doodle-logo.png b/miniprogram/assets/imgs/doodle-logo.png index f20995d..7cc6fc9 100644 Binary files a/miniprogram/assets/imgs/doodle-logo.png and b/miniprogram/assets/imgs/doodle-logo.png differ diff --git a/miniprogram/components/introduction-popup/introduction-popup.ts b/miniprogram/components/introduction-popup/introduction-popup.ts index 087a83c..c69993f 100644 --- a/miniprogram/components/introduction-popup/introduction-popup.ts +++ b/miniprogram/components/introduction-popup/introduction-popup.ts @@ -26,7 +26,6 @@ Component({ lifetimes: { attached() { const { platform } = wx.getDeviceInfo(); - console.log('platform:', platform); this.setData({ platform, }); @@ -53,6 +52,6 @@ Component({ }); }, - preventScroll() {}, + preventScroll() { }, }, }); diff --git a/miniprogram/components/word-picker/word-picker.ts b/miniprogram/components/word-picker/word-picker.ts index 4dea8c5..86c7678 100644 --- a/miniprogram/components/word-picker/word-picker.ts +++ b/miniprogram/components/word-picker/word-picker.ts @@ -14,7 +14,7 @@ Component({ type: Number, value: 0, }, - selectedWords: { + cardList: { type: Array, value: [], }, @@ -24,11 +24,18 @@ Component({ */ data: { wordList: WORDS, + selectedWords: [] as string[], }, lifetimes: { ready() { }, }, + observers: { + cardList(newVal: CardList) { + const selectedWords = newVal.map((item) => item.word); + this.setData({ selectedWords }); + }, + }, /** * 组件的方法列表 */ diff --git a/miniprogram/config/config.ts b/miniprogram/config/config.ts index 5cd3918..e69de29 100644 --- a/miniprogram/config/config.ts +++ b/miniprogram/config/config.ts @@ -1,6 +0,0 @@ -type Channel = 'wechat' | 'noLogo' | 'rednoteLogo' | 'miniHeader'; -const channel: Channel = 'wechat'; - -export const CHANNEL = channel; - -export const APP_NAME = '涂鸦丫'; \ No newline at end of file diff --git a/miniprogram/demoPages/textPaint/textPaint.ts b/miniprogram/demoPages/textPaint/textPaint.ts index 012199e..bc78028 100644 --- a/miniprogram/demoPages/textPaint/textPaint.ts +++ b/miniprogram/demoPages/textPaint/textPaint.ts @@ -17,7 +17,6 @@ Page({ .select('#textCanvas') .fields({ node: true, size: true }) .exec((res) => { - console.log('res----:', res); const canvas = res[0].node; const ctx = canvas.getContext('2d'); this.canvas = canvas; @@ -43,7 +42,7 @@ Page({ }); }, - setCanvasSize() {}, + setCanvasSize() { }, drawCircles: function () { if (!this.canvas) { diff --git a/miniprogram/pages/debug/debug.json b/miniprogram/pages/debug/debug.json new file mode 100644 index 0000000..5741b65 --- /dev/null +++ b/miniprogram/pages/debug/debug.json @@ -0,0 +1,14 @@ +{ + "navigationBarTitleText": "Debug", + "navigationBarBackgroundColor": "#FFD719", + "homeButton": true, + "backgroundColor": "#F6F6F6", + "enablePullDownRefresh": false, + "usingComponents": { + "toy-button": "../../ui/button/button", + "van-radio": "@vant/weapp/radio/index", + "van-radio-group": "@vant/weapp/radio-group/index", + "van-cell": "@vant/weapp/cell/index", + "van-cell-group": "@vant/weapp/cell-group/index" + } +} diff --git a/miniprogram/pages/debug/debug.less b/miniprogram/pages/debug/debug.less new file mode 100644 index 0000000..dd4ec8f --- /dev/null +++ b/miniprogram/pages/debug/debug.less @@ -0,0 +1,24 @@ +.debug-page { + min-height: 100vh; + padding: 20rpx; + background-color: #F6F6F6; + + .debug-wrapper { + background-color: #fff; + border-radius: 20rpx; + overflow: hidden; + + .centered-title { + text-align: center; + color: #666; + border-top: 0 none; + } + } + + .btn-area { + display: flex; + align-items: center; + justify-content: center; + margin-top: 40rpx; + } +} \ No newline at end of file diff --git a/miniprogram/pages/debug/debug.ts b/miniprogram/pages/debug/debug.ts new file mode 100644 index 0000000..a353ba8 --- /dev/null +++ b/miniprogram/pages/debug/debug.ts @@ -0,0 +1,25 @@ +Page({ + data: { + header: 'wechat' + }, + + onLoad() { + const header = getApp().getPrintHeader() || 'wechat'; + this.setData({ header }); + }, + + onChangeHeader(e: WechatMiniprogram.CustomEvent) { + const header = e.detail.value as PrintHeader; + this.setData({ header }); + }, + + onClickHeaderSetting(e: WechatMiniprogram.CustomEvent) { + const header = e.currentTarget.dataset.name as PrintHeader; + this.setData({ header }); + }, + + onConfirm() { + getApp().setPrintHeader(this.data.header); + wx.navigateBack(); + } +}); \ No newline at end of file diff --git a/miniprogram/pages/debug/debug.wxml b/miniprogram/pages/debug/debug.wxml new file mode 100644 index 0000000..99849a7 --- /dev/null +++ b/miniprogram/pages/debug/debug.wxml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + 确定 + + + diff --git a/miniprogram/pages/demoIndex/index.ts b/miniprogram/pages/demoIndex/index.ts index 74d58be..87dfc38 100644 --- a/miniprogram/pages/demoIndex/index.ts +++ b/miniprogram/pages/demoIndex/index.ts @@ -26,7 +26,6 @@ Page({ tapCard(e: WechatMiniprogram.TouchEvent) { const { url } = e.currentTarget.dataset; - console.log('navigateTo url:', url); wx.navigateTo({ url }); }, }); diff --git a/miniprogram/pages/index/index.json b/miniprogram/pages/index/index.json index 66cd3e9..621fbc1 100644 --- a/miniprogram/pages/index/index.json +++ b/miniprogram/pages/index/index.json @@ -5,6 +5,7 @@ "backgroundColor": "#F6F6F6", "enablePullDownRefresh": false, "usingComponents": { + "van-cell": "@vant/weapp/cell/index", "van-icon": "@vant/weapp/icon/index", "van-popup": "@vant/weapp/popup/index", "word-input": "../../components/word-input/word-input", diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts index a13e21a..f41dd64 100644 --- a/miniprogram/pages/index/index.ts +++ b/miniprogram/pages/index/index.ts @@ -10,12 +10,13 @@ Page({ textDrawService: null as TextDrawService | null, data: { - cardList: [] as Array<{ color: string; word: string }>, + cardList: [] as CardList, showColorPopup: false, currentKey: 0, currentColor: '', showIntroductionPopup: false, showSelectWordPopup: false, // 选择文字弹窗 + env: getApp().globalData.env || 'release', }, onLoad() { @@ -345,4 +346,10 @@ Page({ this.setData({ showSelectWordPopup: false }); this.drawCanvas(cardList); }, + + onDebugEntryTap() { + wx.navigateTo({ + url: '/pages/debug/debug', + }); + }, }); diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index 01a5dd0..96869d5 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -70,6 +70,11 @@ style="width:{{boxWidth}}px;height:{{boxHeight}}px" /> + @@ -92,14 +97,6 @@ icon-class-prefix="toy-icon"> 下载打印 - ; @@ -83,12 +83,13 @@ class TextDrawService { } draw(list: Array<{ color: string; word: string }>) { + this.headerType = getApp().getPrintHeader() || 'wechat'; + this.colors = list.map((item) => item.color || '#000'); this.characters = list.map((item) => item.word || '日'); this.clear(); this.setPaper(); - // @ts-ignore - if (CHANNEL !== 'miniHeader') { + if (this.headerType !== 'minimal') { this.drawHeader(); } else { this.drawMiniHeader(); @@ -112,15 +113,17 @@ class TextDrawService { const logoWidth = 200; const logoHeight = 200; - switch (CHANNEL) { - // @ts-ignore - case 'rednoteLogo': { + switch (this.headerType) { + case 'LogoImage': { const image = await getImage(canvas, '/assets/imgs/doodle-logo.png'); ctx.drawImage(image, logoX, logoY, logoWidth, logoHeight); break; } - // @ts-ignore - case 'noLogo': { + case 'noLogoImage': { + titleX = 120; + break; + } + case 'minimal': { titleX = 120; break; } @@ -187,6 +190,7 @@ class TextDrawService { const { canvas, ctx, colors, characters } = this; if (characters.length <= 0) return; // const { colors, characters } = options; + this.currentY = this.headerType === 'minimal' ? 200 : 304; const radius = 65; const rectWidth = 180; const rectHeight = 80; @@ -233,8 +237,7 @@ class TextDrawService { ); }); - // @ts-ignore - this.currentY = CHANNEL === 'miniHeader' ? 522 : 612; // 计算分割线的Y坐标,距离示例图20px + this.currentY = this.headerType === 'minimal' ? 522 : 612; // 计算分割线的Y坐标,距离示例图20px this.drawLine(this.currentY); } @@ -243,8 +246,7 @@ class TextDrawService { if (characters.length <= 0) return; const len = characters.length; - // @ts-ignore - const rows = CHANNEL === 'miniHeader' ? 9 : 8; + const rows = this.headerType === 'minimal' ? 9 : 8; const radius = 80; const fontSize = 72; diff --git a/project.private.config.json b/project.private.config.json index 1e54751..11df584 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -20,5 +20,17 @@ "bigPackageSizeSupport": false }, "libVersion": "3.7.12", - "condition": {} + "condition": { + "miniprogram": { + "list": [ + { + "name": "debug页", + "pathName": "pages/debug/debug", + "query": "", + "scene": null, + "launchMode": "default" + } + ] + } + } } \ No newline at end of file diff --git a/typings/common.d.ts b/typings/common.d.ts new file mode 100644 index 0000000..aab53f2 --- /dev/null +++ b/typings/common.d.ts @@ -0,0 +1,7 @@ +type PrintHeader = 'wechat' | 'noLogoImage' | 'LogoImage' | 'minimal'; +type WordCard = { + color: string; + word: string; +}; + +interface CardList extends Array { } \ No newline at end of file diff --git a/typings/index.d.ts b/typings/index.d.ts index 6007efa..016735b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,7 +1,12 @@ /// +/// + interface IAppOption { globalData: { userInfo?: WechatMiniprogram.UserInfo; + env: string; + printHeader?: PrintHeader; }; userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback; + [key: string]: any; }