feat(设备管理): 重构设备数据管理逻辑,统一使用deviceData对象

- 将分散的设备信息存储改为统一的deviceData对象
- 更新相关API请求参数传递方式
- 增加设备类型支持,动态构建API路径
- 修复设备信息初始化问题,确保数据一致性
This commit is contained in:
XiaoMo 2025-06-25 12:43:31 +08:00
parent ea5ed7c9ce
commit fec4276cc8
7 changed files with 45 additions and 27 deletions

19
app.js
View File

@ -21,15 +21,13 @@ App({
// 上报地址 // 上报地址
LOG_URL: 'https://t-jm.v0750.com/v2/stat/send', LOG_URL: 'https://t-jm.v0750.com/v2/stat/send',
}, },
onLaunch: function(e) { onLaunch: function (e) {
// 40 位的随机码 // 40 位的随机码
if (!wx.getStorageSync("session")) { if (!wx.getStorageSync("session")) {
wx.setStorageSync("session", generateRandomCode(40)); wx.setStorageSync("session", generateRandomCode(40));
} }
console.log("options", e), this.globalData.options = e, t.getLogin(this, !0); console.log("options", e), this.globalData.options = e, t.getLogin(this, !0);
try { try {
var o = wx.getSystemInfoSync(); var o = wx.getSystemInfoSync();
@ -43,16 +41,16 @@ App({
}); });
} }
}, },
onShow: function(e) { onShow: function (e) {
console.log("onshowwwwwwwoptions", e); console.log("onshowwwwwwwoptions", e);
var o = e.scene; var o = e.scene;
[ 1011, 1012, 1013, 1024, 1047, 1048, 1049 ].indexOf(o) > -1 && (console.log("扫码进入的"), [1011, 1012, 1013, 1024, 1047, 1048, 1049].indexOf(o) > -1 && (console.log("扫码进入的"),
t.getDevicecode(this, e)); 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; 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("更新"), 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; var s = t.windowWidth;
this.globalData.screen_data = { this.globalData.screen_data = {
windowWidth: s, windowWidth: s,
@ -76,6 +74,11 @@ App({
isneedUpload: !1, isneedUpload: !1,
needJumpUrl: !1, needJumpUrl: !1,
devicecode: "", devicecode: "",
deviceData: {
type: 'machine',
devicecode: '',
options: {}
},
protocol: {}, protocol: {},
tips: "" tips: ""
} }

View File

@ -26,6 +26,7 @@ Page({
}), e.globalData.qrcode = i.result, t.request("/v2/miniprogram/identify/index", i, !0).then(function (t) { }), e.globalData.qrcode = i.result, t.request("/v2/miniprogram/identify/index", i, !0).then(function (t) {
console.log("data", t), wx.hideLoading(); console.log("data", t), wx.hideLoading();
// 保存设备编号 // 保存设备编号
getApp().globalData.deviceData = t.data || getApp().globalData.deviceData || {};
getApp().globalData.devicecode = t.data.devicecode || getApp().globalData.devicecode; getApp().globalData.devicecode = t.data.devicecode || getApp().globalData.devicecode;
a.startup(); a.startup();
}).catch(function (e) { }).catch(function (e) {
@ -36,9 +37,15 @@ Page({
}, },
// 启动 // 启动
startup: function () { 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) { if (startRes.code == 200) {
wx.showToast({ title: startRes.message || '启动成功', icon: 'success' }); wx.showToast({ title: startRes.message || '启动成功', icon: 'success' });
// 跳转到洗车券列表页面 // 跳转到洗车券列表页面
@ -92,7 +99,7 @@ Page({
wx.showModal({ wx.showModal({
title: "提示", title: "提示",
content: "你当前将要使用的机器编号是:".concat(getApp().globalData.devicecode, ",确认开机吗?"), content: "你当前将要使用的机器编号是:".concat(getApp().globalData.deviceData.devicecode, ",确认开机吗?"),
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
// 用户点击了确认按钮,执行开机操作 // 用户点击了确认按钮,执行开机操作

View File

@ -101,7 +101,7 @@ Page({
load: function (e) { load: function (e) {
console.log(e); console.log(e);
}, },
openLocation: function(e) { openLocation: function (e) {
var latitude = Number(e.currentTarget.dataset.latitude); var latitude = Number(e.currentTarget.dataset.latitude);
var longitude = Number(e.currentTarget.dataset.longitude); var longitude = Number(e.currentTarget.dataset.longitude);
var name = e.currentTarget.dataset.name; var name = e.currentTarget.dataset.name;
@ -158,10 +158,12 @@ Page({
console.log(i), wx.showLoading({ console.log(i), wx.showLoading({
title: "" title: ""
}), e.globalData.qrcode = i.result, t.request("/v2/miniprogram/identify/index", i, !0).then(function (t) { }), 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, console.log("data", t), wx.hideLoading(),
a.setData({ e.globalData.deviceData = t.data || e.globalData.deviceData || {};
isScan: !!t.data.devicecode e.globalData.devicecode = t.data.devicecode || e.globalData.devicecode;
}); a.setData({
isScan: !!t.data.devicecode
});
}).catch(function (e) { }).catch(function (e) {
wx.hideLoading(); wx.hideLoading();
}); });
@ -205,9 +207,7 @@ Page({
success: function (i) { success: function (i) {
i.confirm && (a.isSubmit = !0, wx.showLoading({ i.confirm && (a.isSubmit = !0, wx.showLoading({
title: "正在启动" title: "正在启动"
}), t.request('/v2/miniprogram/machine/startup', { }), t.request('/v2/miniprogram/' + e.globalData.deviceData.type + '/startup', e.globalData.deviceData || {}, !0).then(function (e) {
washcode: a.data.selectID
}, !0).then(function (e) {
a.isSubmit = !1, wx.hideLoading(), 200 == e.code && (wx.showModal({ a.isSubmit = !1, wx.hideLoading(), 200 == e.code && (wx.showModal({
title: "", title: "",
content: e.message content: e.message

View File

@ -91,6 +91,7 @@ Page({
title: "提示", title: "提示",
content: e.message content: e.message
}), !1; }), !1;
t.globalData.deviceData = e.data || t.globalData.deviceData || {};
t.globalData.devicecode = e.data.devicecode || t.globalData.devicecode, a.setData({ t.globalData.devicecode = e.data.devicecode || t.globalData.devicecode, a.setData({
isScan: !!e.data.devicecode isScan: !!e.data.devicecode
}), a.getList(); }), a.getList();
@ -117,13 +118,17 @@ Page({
var a = this; var a = this;
wx.showModal({ wx.showModal({
title: "提示", title: "提示",
content: "你当前将要使用的机器编号是:".concat(t.globalData.devicecode, ",确认开机吗?"), content: "你当前将要使用的机器编号是:".concat(t.globalData.deviceData.devicecode, ",确认开机吗?"),
success: function (i) { 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({ i.confirm && (a.isSubmit = !0, wx.showLoading({
title: "正在启动" title: "正在启动"
}), e.request('/v2/miniprogram/machine/carwashcodestartup', { }), e.request('/v2/miniprogram/' + t.globalData.deviceData.type + '/carwashcodestartup', params, !0).then(function (t) {
washcode: a.data.selectID
}, !0).then(function (t) {
// 成功后返回提示 // 成功后返回提示
wx.showToast({ title: t.message || '启动成功', icon: 'success' }); wx.showToast({ title: t.message || '启动成功', icon: 'success' });
// 成功后跳转 // 成功后跳转

View File

@ -18,7 +18,7 @@ Page({
*/ */
onLoad(options) { onLoad(options) {
var a = this; 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) { if (!res.data || !res.data.progressorder) {
wx.showToast({ wx.showToast({
title: '没有进行中的订单', title: '没有进行中的订单',
@ -116,7 +116,7 @@ Page({
content: '确定要结算此次洗车订单吗?', content: '确定要结算此次洗车订单吗?',
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
e.request('/v2/miniprogram/machine/shutdown', { e.request('/v2/miniprogram/' + getApp().globalData.deviceData.type + '/shutdown', {
orderid: this.data.orderid orderid: this.data.orderid
}, true).then((res) => { }, true).then((res) => {
if (res.code === 200) { if (res.code === 200) {

View File

@ -67,5 +67,5 @@
] ]
} }
}, },
"libVersion": "3.8.8" "libVersion": "3.8.9"
} }

View File

@ -124,7 +124,10 @@ module.exports = {
getDevicecode: function (e, a) { getDevicecode: function (e, a) {
o = e, n("https://t-jm.v0750.com/v2/miniprogram/identify/reload", a, !0).then(function (e) { o = e, n("https://t-jm.v0750.com/v2/miniprogram/identify/reload", a, !0).then(function (e) {
var a = e.data; 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 || '';
}
}); });
} }
}; };