diff --git a/miniprogram/app.json b/miniprogram/app.json
index 9a3cf55..fe42e9c 100644
--- a/miniprogram/app.json
+++ b/miniprogram/app.json
@@ -13,5 +13,10 @@
"componentFramework": "glass-easel",
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents",
- "enablePullDownRefresh": false
+ "enablePullDownRefresh": false,
+ "permission": {
+ "scope.writePhotosAlbum": {
+ "desc": "需要保存涂色卡到相册"
+ }
+ }
}
diff --git a/miniprogram/components/introduction-popup/introduction-popup.less b/miniprogram/components/introduction-popup/introduction-popup.less
index e1d907d..7ec54d9 100644
--- a/miniprogram/components/introduction-popup/introduction-popup.less
+++ b/miniprogram/components/introduction-popup/introduction-popup.less
@@ -30,38 +30,38 @@
position: absolute;
&--first {
- top: 122rpx;
+ top: 114rpx;
left: 50%;
transform: translateX(-50%);
width: 680rpx;
height: 96rpx;
&.android {
- top: 128rpx;
+ top: 116rpx;
}
}
&--second {
- top: 248rpx;
- left: 50rpx;
+ top: 244rpx;
+ left: 48rpx;
width: 96rpx;
height: 96rpx;
&.android {
- top: 256rpx;
- left: 54rpx;
+ top: 248rpx;
+ left: 52rpx;
}
}
&--third {
- top: 248rpx;
- left: 232rpx;
+ top: 244rpx;
+ left: 252rpx;
width: 96rpx;
height: 96rpx;
&.android {
- top: 254rpx;
- left: 236rpx;
+ top: 246rpx;
+ left: 260rpx;
}
}
diff --git a/miniprogram/demoPages/textPaint2/textPaint.ts b/miniprogram/demoPages/textPaint2/textPaint.ts
index da770e6..c9a5ed4 100644
--- a/miniprogram/demoPages/textPaint2/textPaint.ts
+++ b/miniprogram/demoPages/textPaint2/textPaint.ts
@@ -266,11 +266,11 @@ Page({
fileType: 'png',
quality: 1,
success: (res) => {
- wx.getImageInfo({
- src: res.tempFilePath,
- success: (res) =>
- console.log('getImageInfo image size :', res.width, res.height), // 应输出2480x3508
- });
+ // wx.getImageInfo({
+ // src: res.tempFilePath,
+ // success: (res) =>
+ // console.log('getImageInfo image size :', res.width, res.height), // 应输出2480x3508
+ // });
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: () => wx.showToast({ title: '保存成功' }),
diff --git a/miniprogram/pages/debug/debug.json b/miniprogram/pages/debug/debug.json
index 5741b65..36ac758 100644
--- a/miniprogram/pages/debug/debug.json
+++ b/miniprogram/pages/debug/debug.json
@@ -9,6 +9,7 @@
"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"
+ "van-cell-group": "@vant/weapp/cell-group/index",
+ "van-switch": "@vant/weapp/switch/index"
}
}
diff --git a/miniprogram/pages/debug/debug.less b/miniprogram/pages/debug/debug.less
index dd4ec8f..c32450a 100644
--- a/miniprogram/pages/debug/debug.less
+++ b/miniprogram/pages/debug/debug.less
@@ -4,6 +4,7 @@
background-color: #F6F6F6;
.debug-wrapper {
+ margin-top: 30rpx;
background-color: #fff;
border-radius: 20rpx;
overflow: hidden;
@@ -13,6 +14,12 @@
color: #666;
border-top: 0 none;
}
+
+ .debug-cell {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ }
}
.btn-area {
diff --git a/miniprogram/pages/debug/debug.ts b/miniprogram/pages/debug/debug.ts
index a353ba8..f532e66 100644
--- a/miniprogram/pages/debug/debug.ts
+++ b/miniprogram/pages/debug/debug.ts
@@ -1,11 +1,13 @@
Page({
data: {
- header: 'wechat'
+ header: 'wechat',
+ enableDebug: false
},
onLoad() {
const header = getApp().getPrintHeader() || 'wechat';
- this.setData({ header });
+ const enableDebug = wx.getStorageSync('enableDebug') || false;
+ this.setData({ header, enableDebug });
},
onChangeHeader(e: WechatMiniprogram.CustomEvent) {
@@ -20,6 +22,15 @@ Page({
onConfirm() {
getApp().setPrintHeader(this.data.header);
+ const enableDebug = this.data.enableDebug;
+ wx.setStorageSync('enableDebug', enableDebug);
+ wx.setEnableDebug({ enableDebug });
wx.navigateBack();
+ },
+
+ /** 真机调试线上包 */
+ toggleDebug() {
+ const enableDebug = !this.data.enableDebug;
+ this.setData({ enableDebug });
}
});
\ No newline at end of file
diff --git a/miniprogram/pages/debug/debug.wxml b/miniprogram/pages/debug/debug.wxml
index 99849a7..9ba8df9 100644
--- a/miniprogram/pages/debug/debug.wxml
+++ b/miniprogram/pages/debug/debug.wxml
@@ -36,6 +36,26 @@
+
+
+
+
+
+
+
+
确定
diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts
index 96ae920..b44e75c 100644
--- a/miniprogram/pages/index/index.ts
+++ b/miniprogram/pages/index/index.ts
@@ -1,6 +1,7 @@
import { WATER_COLORS, PAPER_SIZE } from '../../constants/colors';
import { WORDS } from '../../constants/words';
import TextDrawService from '../../service/textDrawService';
+import { checkAndSaveImage } from '../../utils/saveImage';
Page({
canvas: null as Canvas | null,
@@ -196,26 +197,7 @@ Page({
/** 下载打印 */
exportToPrint() {
if (this.canvas && this.data.cardList.length > 0) {
- wx.canvasToTempFilePath({
- canvas: this.canvas,
- fileType: 'png',
- quality: 1,
- success: (res) => {
- wx.getImageInfo({
- src: res.tempFilePath,
- success: (res) =>
- console.log(
- 'getImageInfo image size :',
- res.width,
- res.height,
- ), // 应输出2480x3508
- });
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: () => wx.showToast({ title: '保存成功' }),
- });
- },
- });
+ checkAndSaveImage(this.canvas);
return;
}
},
diff --git a/miniprogram/utils/saveImage.ts b/miniprogram/utils/saveImage.ts
new file mode 100644
index 0000000..e4beeec
--- /dev/null
+++ b/miniprogram/utils/saveImage.ts
@@ -0,0 +1,55 @@
+const doSaveImage = (canvas: Canvas) => {
+ wx.canvasToTempFilePath({
+ canvas: canvas,
+ fileType: 'png',
+ quality: 1,
+ success: (res) => {
+ wx.saveImageToPhotosAlbum({
+ filePath: res.tempFilePath,
+ success: () => wx.showToast({
+ title: '保存成功,请在相册中查看',
+ icon: 'success',
+ duration: 2000,
+ }),
+ // fail: () => wx.showToast({
+ // title: '保存涂色卡失败,请重试!',
+ // icon: 'none',
+ // duration: 2000,
+ // })
+ });
+ },
+ fail: (err: any) => {
+ wx.showToast({
+ title: '生成涂色卡失败,请重试!',
+ icon: 'none',
+ duration: 2000,
+ })
+ }
+ });
+}
+
+const requestPhotoPermission = (canvas: Canvas) => {
+ wx.authorize({
+ scope: 'scope.writePhotosAlbum',
+ success: () => doSaveImage(canvas),
+ fail: () => wx.showToast({
+ title: '请在“设置-添加到相册”中开启相册权限以保存涂色卡',
+ icon: 'none',
+ duration: 3000,
+ })
+ })
+}
+
+
+export const checkAndSaveImage = (canvas: Canvas) => {
+ wx.getSetting({
+ success: res => {
+ if (!res.authSetting['scope.writePhotosAlbum']) {
+ requestPhotoPermission(canvas)
+ } else {
+ doSaveImage(canvas)
+ }
+ }
+ })
+};
+