Move image URL construction from WXML ternary to JS pre-processing. This ensures fixImageUrl() is properly applied before template rendering. Also reverts fixImageUrl to use API base URL (images served via backend). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
135 lines
3.8 KiB
JavaScript
135 lines
3.8 KiB
JavaScript
// 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,
|
||
imageBaseUrl: config.imageBaseUrl,
|
||
|
||
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
|
||
});
|
||
}
|
||
}) |