fix: pre-process order userbAvatar in JS, simplify WXML image tags

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>
This commit is contained in:
renjianbo
2026-06-07 11:53:49 +08:00
parent f5024c0ed0
commit ade42d9b27
6 changed files with 22 additions and 14 deletions

View File

@@ -107,11 +107,11 @@ App({
};
},
// 修复图片路径:相对路径补全图片基地址,绝对 URL 或空值原样返回
// 修复图片路径:相对路径补全 baseUrl,绝对 URL 或空值原样返回
fixImageUrl: function (path) {
if (!path) return '';
if (path.indexOf('http') === 0) return path;
return this.globalData.imageBaseUrl + path;
return this.globalData.url + path;
},
// 获取订单状态文案

View File

@@ -1,13 +1,21 @@
var app = getApp();
const { request } = require('../../utils/request')
// 处理订单列表中的图片路径
function processOrderList(list) {
return list.map(function(item) {
item.userbAvatar = app.fixImageUrl(item.userbAvatar) || '/pages/image/userimg.png';
return item;
});
}
Page({
data: {
order_list: [],
nav_type: 1,
all: true,
height: '',
url: app.globalData.imageBaseUrl,
url: app.globalData.url,
statusType: ["全部", "待接单", "已接单", "服务中", "待支付", "已完成","已取消"],
status: ["", "0", "1", "2", "3","4","-2"],
currentType: 0,
@@ -55,7 +63,6 @@ Page({
},
onShow: function () {
// 首次加载或从其他页返回刷新
if (this.data.firstLoad) {
this.setData({ firstLoad: false })
this.getOrderList()
@@ -87,7 +94,7 @@ Page({
usercId: wx.getStorageSync('uid')
}
})
var list = res.rows || res.data || []
var list = processOrderList(res.rows || res.data || []);
this.setData({
order_list: list,
pageNum: 2,
@@ -114,7 +121,7 @@ Page({
usercId: wx.getStorageSync('uid')
}
})
var newList = res.rows || res.data || []
var newList = processOrderList(res.rows || res.data || []);
if (this.data.pageNum === 1) {
this.setData({
order_list: newList,
@@ -131,4 +138,4 @@ Page({
} catch (e) {}
this.setData({ loading: false })
},
})
})

View File

@@ -35,7 +35,7 @@
<view style="height: 1rpx;background: #ECECEC;"></view>
<view class="details_box">
<image src="{{(item.userbAvatar && item.userbAvatar.indexOf('http') === 0) ? item.userbAvatar : (item.userbAvatar ? url + item.userbAvatar : '/pages/image/userimg.png')}}" class="Group-image"></image>
<image src="{{item.userbAvatar}}" class="Group-image"></image>
<view style="margin-left: 31rpx;margin-top: 40rpx;">
<view class="title">{{item.userbName}}</view>
<view class="detail_number">{{item.serviceTime}}天</view>

View File

@@ -14,7 +14,7 @@ Page({
qrcode: '',
id: '',
item: {},
url: app.globalData.imageBaseUrl,
url: app.globalData.url,
refund: '',
charge_phone: '',
refund_box: false,
@@ -86,9 +86,9 @@ Page({
}
var that = this;
let item = JSON.parse(e.item);
that.setData({
item.userbAvatar = app.fixImageUrl(item.userbAvatar) || '/pages/image/userimg.png';
this.setData({
item: item,
charge_phone: item.usercPhonenumber || '',
order_id: item.orderId
@@ -148,6 +148,7 @@ Page({
data: { orderId: this.data.order_id }
})
if (res.data) {
res.data.userbAvatar = app.fixImageUrl(res.data.userbAvatar) || '/pages/image/userimg.png';
this.setData({ item: res.data })
}
} catch (e) {}

View File

@@ -19,7 +19,7 @@
<view wx:if="{{item.status==8}}" class="status_msg">{{"已结算"}}</view>
</view>
<view class="details_box">
<image src="{{(item.userbAvatar && item.userbAvatar.indexOf('http') === 0) ? item.userbAvatar : (item.userbAvatar ? url + item.userbAvatar : '/pages/image/userimg.png')}}" binderror="onAvatarError" style="width:230rpx;height:230rpx;"></image>
<image src="{{item.userbAvatar || '/pages/image/userimg.png'}}" binderror="onAvatarError" style="width:230rpx;height:230rpx;"></image>
<view style="margin-left: 31rpx;">
<view class="title">专业陪护服务({{item.userbName}}</view>
<!-- <view class="detail_number">数量x{{detail.num}}</view> -->
@@ -70,7 +70,7 @@
<view class="contact">
<view class="contact_title">联系信息</view>
<view style="display: flex;align-items: center;">
<image src="{{(item.userbAvatar && item.userbAvatar.indexOf('http') === 0) ? item.userbAvatar : (item.userbAvatar ? url + item.userbAvatar : '/pages/image/userimg.png')}}" binderror="onAvatarError" style="width:94rpx;height:94rpx;border-radius:50%;margin-right:23rpx;">
<image src="{{item.userbAvatar || '/pages/image/userimg.png'}}" binderror="onAvatarError" style="width:94rpx;height:94rpx;border-radius:50%;margin-right:23rpx;">
</image>
<view>
<view style="color: #333;font-size: 28rpx;font-family: PingFang SC;font-weight: bold;">{{item.userbName}}</view>

View File

@@ -5,7 +5,7 @@ Page({
data: {
height: '',
url: app.globalData.imageBaseUrl,
url: app.globalData.url,
seckill_start: '请输入开始日期',
seckill_endx: '请输入结束日期',
time: 30 * 60 * 60 * 1000,