Files
rlz/coupon/app.js
renjianbo 310dc6720f refactor: extract shared helpers, remove dead code, fix conventions
- Add getNavBarHeight() to App, replace 9x duplicate statusBarHeight calc
- Add fixImageUrl() helper, replace 3x duplicate image URL fixup
- Add STATUS_MAP and REFUND_REASONS to globalData, replace duplicates
- Replace hardcoded domain in WXML with {{url}} data binding (4 places)
- Delete dead backup file orderdetailbeifen.js (contained real phone number)
- Delete empty pages: tuiguang, subPackages/withdrawal, orderdetiltwo
- Remove unused import (Token in my.js)
- Convert paysuccess.js from raw wx.request to request() utility
- Remove unused baseUrl variables after switching to fixImageUrl()

Net: +81 / -917 lines

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-07 11:29:35 +08:00

134 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// app.js
const config = require('./utils/config')
App({
onLaunch() {
const uid = wx.getStorageSync('uid')
const token = wx.getStorageSync('token')
if (uid) {
this.globalData.uid = uid
}
if (token) {
this.globalData.token = token
}
},
globalData: {
userInfo: null,
encryptedData: '',
iv: '',
code: '',
url: config.baseUrl,
domain: config.baseUrl,
domaintwo: config.baseUrl,
phone: '',
uid: '',
sessionKey: '',
version_number: '1.0.0',
// 订单状态映射(订单状态:-2:已取消 -1:拒绝接单 0:待接单 1:已接单
// 2:待服务 3:服务中 4:已完成 5:退款中 6:退款中 7:已退款 8:已结算)
STATUS_MAP: {
'-2': '已取消', '-1': '拒绝接单', '0': '待接单',
'1': '已接单', '2': '服务中', '3': '待支付',
'4': '已完成', '5': '申请退款', '6': '退款中',
'7': '已退款', '8': '已结算'
},
// 退款原因列表(全局公用,避免每页重复定义)
REFUND_REASONS: [
{ text: '不喜欢/不想要' },
{ text: '商品信息与描述不符' },
{ text: '买多/买错/计划有变' },
{ text: '更换其他项目、购买了其他项目' },
{ text: '没有时间/个人原因' },
{ text: '其他原因' }
],
},
console: function (msg) {
console.log(msg);
},
tip: function (params) {
var that = this;
var title = params.hasOwnProperty('title') ? params['title'] : '提示您';
var content = params.hasOwnProperty('content') ? params['content'] : '';
wx.showModal({
title: title,
content: content,
success: function (res) {
if (res.confirm) { //点击确定
if (params.hasOwnProperty('cb_confirm') && typeof (params.cb_confirm) == "function") {
params.cb_confirm();
}
} else { //点击否
if (params.hasOwnProperty('cb_cancel') && typeof (params.cb_cancel) == "function") {
params.cb_cancel();
}
}
}
})
},
getRequestHeader: function () {
return {
'content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ' + this.getCache("token")
}
},
buildUrl: function (path, params) {
var url = this.globalData.domain + path;
var _paramUrl = "";
if (params) {
_paramUrl = Object.keys(params).map(function (k) {
return [encodeURIComponent(k), encodeURIComponent(params[k])].join("=");
}).join("&");
_paramUrl = "?" + _paramUrl;
}
return url + _paramUrl;
},
buildUrltwo: function (path, params) {
var url = this.globalData.domaintwo + path;
var _paramUrl = "";
if (params) {
_paramUrl = Object.keys(params).map(function (k) {
return [encodeURIComponent(k), encodeURIComponent(params[k])].join("=");
}).join("&");
_paramUrl = "?" + _paramUrl;
}
return url + _paramUrl;
},
// 公共导航栏高度,避免每个页面重复计算
getNavBarHeight: function () {
var statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
return {
statusBarHeight: statusBarHeight,
height: 46 + statusBarHeight
};
},
// 修复图片路径:相对路径补全 baseUrl,绝对 URL 或空值原样返回
fixImageUrl: function (path) {
if (!path) return '';
if (path.indexOf('http') === 0) return path;
return this.globalData.url + path;
},
// 获取订单状态文案
getStatusLabel: function (status) {
return this.globalData.STATUS_MAP[String(status)] || '';
},
getCache: function (key) {
var value = undefined;
try {
value = wx.getStorageSync(key);
} catch (e) {}
return value;
},
setCache: function (key, value) {
wx.setStorage({
key: key,
data: value
});
}
})