From fec4276cc8f6ebc028d80a3165a5bb6e41443fbe Mon Sep 17 00:00:00 2001 From: XiaoMo Date: Wed, 25 Jun 2025 12:43:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=AE=BE=E5=A4=87=E6=95=B0=E6=8D=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BD=BF?= =?UTF-8?q?=E7=94=A8deviceData=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将分散的设备信息存储改为统一的deviceData对象 - 更新相关API请求参数传递方式 - 增加设备类型支持,动态构建API路径 - 修复设备信息初始化问题,确保数据一致性 --- app.js | 19 +++++++++++-------- pages/duiquan/duiquan.js | 13 ++++++++++--- pages/index/index.js | 16 ++++++++-------- pages/washCodeList/washCodeList.js | 13 +++++++++---- pages/washing/washing.js | 4 ++-- project.private.config.json | 2 +- utils/login.js | 5 ++++- 7 files changed, 45 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index 9660f23..f264764 100644 --- a/app.js +++ b/app.js @@ -21,15 +21,13 @@ App({ // 上报地址 LOG_URL: 'https://t-jm.v0750.com/v2/stat/send', }, - onLaunch: function(e) { + onLaunch: function (e) { // 40 位的随机码 if (!wx.getStorageSync("session")) { wx.setStorageSync("session", generateRandomCode(40)); } - - console.log("options", e), this.globalData.options = e, t.getLogin(this, !0); try { var o = wx.getSystemInfoSync(); @@ -43,16 +41,16 @@ App({ }); } }, - onShow: function(e) { + onShow: function (e) { console.log("onshowwwwwwwoptions", e); var o = e.scene; - [ 1011, 1012, 1013, 1024, 1047, 1048, 1049 ].indexOf(o) > -1 && (console.log("扫码进入的"), - t.getDevicecode(this, e)); + [1011, 1012, 1013, 1024, 1047, 1048, 1049].indexOf(o) > -1 && (console.log("扫码进入的"), + t.getDevicecode(this, e)); }, - computeNavigateBarHeight: function(t) { + computeNavigateBarHeight: function (t) { var e = wx.getMenuButtonBoundingClientRect(), o = e.bottom + 6, i = t.windowHeight, n = e.top, a = e.height; i < 10 && (i = t.windowHeight, a = o - (n = t.statusBarHeight)), o < 10 && (console.log("更新"), - o = 68, /iPhone X|MI 8|PAAM00|COR-AL00/.test(t.model) ? o = 88 : /iPhone/.test(t.model) && (o = 64)); + o = 68, /iPhone X|MI 8|PAAM00|COR-AL00/.test(t.model) ? o = 88 : /iPhone/.test(t.model) && (o = 64)); var s = t.windowWidth; this.globalData.screen_data = { windowWidth: s, @@ -76,6 +74,11 @@ App({ isneedUpload: !1, needJumpUrl: !1, devicecode: "", + deviceData: { + type: 'machine', + devicecode: '', + options: {} + }, protocol: {}, tips: "" } diff --git a/pages/duiquan/duiquan.js b/pages/duiquan/duiquan.js index 7aa1fa1..52770d2 100644 --- a/pages/duiquan/duiquan.js +++ b/pages/duiquan/duiquan.js @@ -26,6 +26,7 @@ Page({ }), e.globalData.qrcode = i.result, t.request("/v2/miniprogram/identify/index", i, !0).then(function (t) { console.log("data", t), wx.hideLoading(); // 保存设备编号 + getApp().globalData.deviceData = t.data || getApp().globalData.deviceData || {}; getApp().globalData.devicecode = t.data.devicecode || getApp().globalData.devicecode; a.startup(); }).catch(function (e) { @@ -36,9 +37,15 @@ Page({ }, // 启动 startup: function () { - if (getApp().globalData.devicecode) { + if (getApp().globalData.deviceData.devicecode) { + + // 合并参数 t.globalData.deviceData 与 washcode + let params = Object.assign(getApp().globalData.deviceData, { + washcode: this.data.code + }); + // 已扫码,启动机器 - t.request('/v2/miniprogram/machine/carwashcodestartup', { devicecode: getApp().globalData.devicecode, washcode: this.data.code }, !0).then((startRes) => { + t.request('/v2/miniprogram/' + getApp().globalData.deviceData.type + '/carwashcodestartup', params, !0).then((startRes) => { if (startRes.code == 200) { wx.showToast({ title: startRes.message || '启动成功', icon: 'success' }); // 跳转到洗车券列表页面 @@ -92,7 +99,7 @@ Page({ wx.showModal({ title: "提示", - content: "你当前将要使用的机器编号是:".concat(getApp().globalData.devicecode, ",确认开机吗?"), + content: "你当前将要使用的机器编号是:".concat(getApp().globalData.deviceData.devicecode, ",确认开机吗?"), success: (res) => { if (res.confirm) { // 用户点击了确认按钮,执行开机操作 diff --git a/pages/index/index.js b/pages/index/index.js index 32d64b0..e19bf1f 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -101,7 +101,7 @@ Page({ load: function (e) { console.log(e); }, - openLocation: function(e) { + openLocation: function (e) { var latitude = Number(e.currentTarget.dataset.latitude); var longitude = Number(e.currentTarget.dataset.longitude); var name = e.currentTarget.dataset.name; @@ -158,10 +158,12 @@ Page({ console.log(i), wx.showLoading({ title: "" }), e.globalData.qrcode = i.result, t.request("/v2/miniprogram/identify/index", i, !0).then(function (t) { - console.log("data", t), wx.hideLoading(), e.globalData.devicecode = t.data.devicecode || e.globalData.devicecode, - a.setData({ - isScan: !!t.data.devicecode - }); + console.log("data", t), wx.hideLoading(), + e.globalData.deviceData = t.data || e.globalData.deviceData || {}; + e.globalData.devicecode = t.data.devicecode || e.globalData.devicecode; + a.setData({ + isScan: !!t.data.devicecode + }); }).catch(function (e) { wx.hideLoading(); }); @@ -205,9 +207,7 @@ Page({ success: function (i) { i.confirm && (a.isSubmit = !0, wx.showLoading({ title: "正在启动" - }), t.request('/v2/miniprogram/machine/startup', { - washcode: a.data.selectID - }, !0).then(function (e) { + }), t.request('/v2/miniprogram/' + e.globalData.deviceData.type + '/startup', e.globalData.deviceData || {}, !0).then(function (e) { a.isSubmit = !1, wx.hideLoading(), 200 == e.code && (wx.showModal({ title: "", content: e.message diff --git a/pages/washCodeList/washCodeList.js b/pages/washCodeList/washCodeList.js index 5cddf7e..5ed4ae6 100644 --- a/pages/washCodeList/washCodeList.js +++ b/pages/washCodeList/washCodeList.js @@ -91,6 +91,7 @@ Page({ title: "提示", content: e.message }), !1; + t.globalData.deviceData = e.data || t.globalData.deviceData || {}; t.globalData.devicecode = e.data.devicecode || t.globalData.devicecode, a.setData({ isScan: !!e.data.devicecode }), a.getList(); @@ -117,13 +118,17 @@ Page({ var a = this; wx.showModal({ title: "提示", - content: "你当前将要使用的机器编号是:".concat(t.globalData.devicecode, ",确认开机吗?"), + content: "你当前将要使用的机器编号是:".concat(t.globalData.deviceData.devicecode, ",确认开机吗?"), success: function (i) { + + // 合并参数 t.globalData.deviceData 与 washcode + let params = Object.assign(t.globalData.deviceData, { + washcode: a.data.selectID + }); + i.confirm && (a.isSubmit = !0, wx.showLoading({ title: "正在启动" - }), e.request('/v2/miniprogram/machine/carwashcodestartup', { - washcode: a.data.selectID - }, !0).then(function (t) { + }), e.request('/v2/miniprogram/' + t.globalData.deviceData.type + '/carwashcodestartup', params, !0).then(function (t) { // 成功后返回提示 wx.showToast({ title: t.message || '启动成功', icon: 'success' }); // 成功后跳转 diff --git a/pages/washing/washing.js b/pages/washing/washing.js index cfade02..d2021bc 100644 --- a/pages/washing/washing.js +++ b/pages/washing/washing.js @@ -18,7 +18,7 @@ Page({ */ onLoad(options) { var a = this; - e.request('/v2/miniprogram/index/balance', {}, !0).then(function (res) { + e.request('/v2/miniprogram/index/balance', getApp().globalData.deviceData, !0).then(function (res) { if (!res.data || !res.data.progressorder) { wx.showToast({ title: '没有进行中的订单', @@ -116,7 +116,7 @@ Page({ content: '确定要结算此次洗车订单吗?', success: (res) => { if (res.confirm) { - e.request('/v2/miniprogram/machine/shutdown', { + e.request('/v2/miniprogram/' + getApp().globalData.deviceData.type + '/shutdown', { orderid: this.data.orderid }, true).then((res) => { if (res.code === 200) { diff --git a/project.private.config.json b/project.private.config.json index 59e28f6..1ae9d49 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -67,5 +67,5 @@ ] } }, - "libVersion": "3.8.8" + "libVersion": "3.8.9" } \ No newline at end of file diff --git a/utils/login.js b/utils/login.js index e1257f5..6e64184 100644 --- a/utils/login.js +++ b/utils/login.js @@ -124,7 +124,10 @@ module.exports = { getDevicecode: function (e, a) { o = e, n("https://t-jm.v0750.com/v2/miniprogram/identify/reload", a, !0).then(function (e) { var a = e.data; - console.log("onshow获取到的数据", a), o.globalData.devicecode = a.devicecode || o.globalData.devicecode; + if (e.code == 200) { + o.globalData.deviceData = a || {}; + o.globalData.devicecode = a.devicecode || ''; + } }); } }; \ No newline at end of file