diff --git a/miniprogram/pages/index/index.js b/miniprogram/pages/index/index.js index a264f42..9da9900 100644 --- a/miniprogram/pages/index/index.js +++ b/miniprogram/pages/index/index.js @@ -17,7 +17,6 @@ Page({ onLoad(option) { wx.hideHomeButton() - // 携带机器识别码进入 if (option.machineQrcodeId) { this.setData({ @@ -48,22 +47,27 @@ Page({ title: '加载中', }) this.getImageList(10, this.data.currentIndex) + } }, onShow() { const isLogin = wx.getStorageSync('token') const isPay = wx.getStorageSync('isPay') + + console.log(isLogin, 'isLogin'); this.setData({ isLogin, currentIndex: 1 }) if (isLogin) { + request.setHead(isLogin) wx.showLoading({ title: '加载中', }) this.getImageList(10, this.data.currentIndex) if (this.data.machineQrcodeId && !isPay) { + this.getPayInfo(this.data.machineQrcodeId) } } @@ -287,6 +291,7 @@ Page({ title: '支付成功!', icon: "success" }) + that.startSub() wx.hideLoading() } else if ((res.data.orderStatus == 1 && !isSuccess) || res.data.orderStatus == 4) { clearInterval(timer) @@ -301,6 +306,72 @@ Page({ }) }, + startSub() { + const that = this + request.get({ + url: `/api/templateMsg/list?projectType=6&plat=1` + }).then(res => { + console.log(res, 'res'); + const id = res.data[0].templateId + + wx.showModal({ + title: '订阅消息', + content: '作品生成完毕后将会通知您', + confirmColor: "", + confirmText: "好的", + showCancel: false, + complete: (res) => { + if (res.cancel) { + + } + + if (res.confirm) { + that.subscribe(id) + } + } + }) + }).catch(err => { + console.log(err, 'err'); + }) + }, + + subscribe(templateId) { + const arr = [templateId] + wx.requestSubscribeMessage({ + //此处填写刚才申请模板的模板ID + tmplIds: arr, + success(res) { + console.log(res); + let failFlag = true; + arr.forEach((item) => { + if (res[item] == "accept") { + wx.showToast({ + title: "订阅成功", + icon: "success", + }); + failFlag = false; + } + }); + if (failFlag) { + wx.showModal({ + title: "提示", + content: + "订阅失败 ,您可以在 \n 小程序设置->通知管理 \n 中重新启用订阅功能", + confirmText: "确定", + showCancel: false, + }); + } + }, + fail(err) { + console.log("订阅消息失败", err); + wx.showToast({ + title: "订阅失败", + icon: "none", + }); + }, + }); + }, + onShareAppMessage() { const promise = new Promise(resolve => { setTimeout(() => { diff --git a/miniprogram/pages/login/login.js b/miniprogram/pages/login/login.js index 3e7808e..bd4bb84 100644 --- a/miniprogram/pages/login/login.js +++ b/miniprogram/pages/login/login.js @@ -112,6 +112,11 @@ Page({ data }).then(res => { // 获取手机号之后,绑定用户与机器 + if (res.data.token) { + wx.setStorageSync('token', res.data.token) + request.setHead(res.data.token) + } + that.bindUser() }).catch(err => { console.log(err, 'err'); diff --git a/miniprogram/pages/upload/upload.js b/miniprogram/pages/upload/upload.js index 8aaec3e..572f5d9 100644 --- a/miniprogram/pages/upload/upload.js +++ b/miniprogram/pages/upload/upload.js @@ -43,7 +43,7 @@ Page({ chooseImage(e) { const that = this - const action = e.currentTarget.dataset.action + const action = e ? e.currentTarget.dataset.action : false if (action && that.data.tempFilePath) { that.setData({ @@ -77,6 +77,10 @@ Page({ const filePath = that.data.tempFilePath const BaseUrl = request.baseUrl + wx.showLoading({ + title: '检测中 1/3', + }) + wx.uploadFile({ filePath, url: BaseUrl + "/api/userDigital/checkPhoto", @@ -89,6 +93,7 @@ Page({ if (code == 200) { that.imgCheckByBaidu() } else { + wx.hideLoading() that.setData({ showScanLine: false }) @@ -99,6 +104,7 @@ Page({ } }, fail: err => { + wx.hideLoading() wx.showToast({ title: '上传失败,请稍后再试', icon: "none" @@ -113,6 +119,10 @@ Page({ const filePath = that.data.tempFilePath const BaseUrl = request.baseUrl + wx.showLoading({ + title: '验证中 2/3', + }) + wx.uploadFile({ filePath, url: BaseUrl + "/api/baidu/checkPhoto", @@ -125,6 +135,7 @@ Page({ if (code == 200) { that.doUploadImg() } else { + wx.hideLoading() that.setData({ showScanLine: false }) @@ -135,6 +146,7 @@ Page({ } }, fail: err => { + wx.hideLoading() wx.showToast({ title: '上传失败,请稍后再试', icon: "none" @@ -149,6 +161,10 @@ Page({ const filePath = that.data.tempFilePath const BaseUrl = request.baseUrl + wx.showLoading({ + title: '上传中 3/3', + }) + wx.uploadFile({ filePath, url: BaseUrl + "/api/upload/awsImgUpload", @@ -163,26 +179,41 @@ Page({ console.log(res, 'res'); const data = JSON.parse(res.data) if (data.code == 200) { + wx.hideLoading() that.setData({ showScanLine: false, isSuccess: true, onlineFilePath: data.data.url }) - wx.showToast({ - title: '上传成功!', - icon: "success" + wx.showModal({ + title: '照片验证成功!', + content: '是否要使用这张照片?', + confirmText: "使用", + confirmColor: "#ff4f00", + cancelText: "换一张", + complete: (res) => { + if (res.cancel) { + that.chooseImage(false) + } + + if (res.confirm) { + that.confirmImage() + } + } }) } else { wx.showToast({ title: '服务器繁忙,请稍后再试', icon: "none" }) + wx.hideLoading() that.setData({ showScanLine: false }) } }, fail: err => { + wx.hideLoading() wx.showToast({ title: '上传失败,请稍后再试', icon: "none" @@ -212,12 +243,78 @@ Page({ that.setData({ topTitle: "上传成功!" }) + that.startSub() } }).catch(err => { console.log(err, 'err'); }) }, + startSub() { + const that = this + request.get({ + url: `/api/templateMsg/list?projectType=6&plat=1` + }).then(res => { + console.log(res, 'res'); + const id = res.data[0].templateId + wx.showModal({ + title: '订阅消息', + content: '作品生成完毕后将会通知您', + confirmColor: "", + confirmText: "好的", + showCancel: false, + complete: (res) => { + if (res.cancel) { + + } + + if (res.confirm) { + that.subscribe(id) + } + } + }) + }).catch(err => { + console.log(err, 'err'); + }) + }, + + subscribe(templateId) { + const arr = [templateId] + wx.requestSubscribeMessage({ + //此处填写刚才申请模板的模板ID + tmplIds: arr, + success(res) { + console.log(res); + let failFlag = true; + arr.forEach((item) => { + if (res[item] == "accept") { + wx.showToast({ + title: "订阅成功", + icon: "success", + }); + failFlag = false; + } + }); + if (failFlag) { + wx.showModal({ + title: "提示", + content: + "订阅失败 ,您可以在 \n 小程序设置->通知管理 \n 中重新启用订阅功能", + confirmText: "确定", + showCancel: false, + }); + } + }, + fail(err) { + console.log("订阅消息失败", err); + wx.showToast({ + title: "订阅失败", + icon: "none", + }); + }, + }); + }, + /** * 页面相关事件处理函数--监听用户下拉动作 */ diff --git a/miniprogram/utils/request.js b/miniprogram/utils/request.js index 7ed8477..50e20eb 100644 --- a/miniprogram/utils/request.js +++ b/miniprogram/utils/request.js @@ -33,9 +33,8 @@ class request { * @description 设置请求头 * @param {*} data token , tenantId */ - setHead(token, tenantId) { + setHead(token) { this.headers.token = token; - this.headers.tenantId = tenantId; } /** diff --git a/project.private.config.json b/project.private.config.json index 90e24d9..0bd0c64 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -12,7 +12,7 @@ { "name": "", "pathName": "pages/login/login", - "query": "scene=865789927095844864", + "query": "scene=866529281119674368", "launchMode": "default", "scene": null },