页面优化

This commit is contained in:
Dev
2026-10-19 15:46:10 +08:00
parent 44405743bb
commit 6beeeb2383
14 changed files with 229 additions and 120 deletions
@@ -16,7 +16,7 @@
<t-cell title="工期" note="{{_calc.withUnit(demandInfo.limit_time, '天')}}" bordered hover />
<t-cell title="联系方式" note="{{demandInfo.contactText}}" bordered hover />
<view class="qrcode-row">
<image class="qrcode-img" wx:if="{{demandInfo.demand_group_chat.qr_code && (demandInfo.isMy || demandInfo.isMyWin )}}" src="{{demandInfo.demand_group_chat.qr_code}}" data-index="{{0}}" data-images="{{[demandInfo.demand_group_chat.qr_code]}}" mode="widthFix" bind:tap="onImageView" show-menu-by-longpress="{{true}}" />
<image class="qrcode-img" wx:if="{{demandInfo.demand_group_chat.qr_code && (demandInfo.isMy || demandInfo.isMyWin )}}" src="{{demandInfo.demand_group_chat.qr_code}}" data-index="{{0}}" data-images="{{[demandInfo.demand_group_chat.qr_code]}}" mode="widthFix" bind:tap="onImageView" show-menu-by-longpress="{{true}}"></image>
</view>
<!-- 任务内容 -->
<t-collapse value="{{activeValues}}" bind:change="handleChange">
@@ -59,7 +59,7 @@
<view class="delivery-section">
<view class="delivery-title">开发完成凭证截图</view>
<view class="delivery-images">
<image wx:for="{{_calc.getDelivery(demandInfo).images}}" wx:key="index" class="delivery-image" src="{{item.url}}" mode="aspectFill" data-index="{{index}}" data-images="{{_calc.getDelivery(demandInfo).images}}" bindtap="onDeliveryImagePreview" />
<image wx:for="{{_calc.getDelivery(demandInfo).images}}" wx:key="index" class="delivery-image" src="{{item.url}}" mode="aspectFill" data-index="{{index}}" data-images="{{_calc.getDelivery(demandInfo).images}}" bindtap="onDeliveryImagePreview"></image>
</view>
<view class="delivery-title">交付附件</view>
<view class="file-list">
@@ -44,7 +44,7 @@
{{item.expanded ? '收起' : '查看全文'}}
</view>
<view class="content-img-list">
<image wx:for="{{item.images}}" wx:for-item="img" wx:for-index="imgIndex" wx:key="*this" class="content-img" mode="aspectFill" data-index="{{imgIndex}}" data-images="{{item.images}}" src="{{img}}" bind:tap="onImageView"></image>
<image wx:for="{{item.images}}" wx:for-item="img" wx:for-index="imgIndex" wx:key="*this" class="content-img" mode="aspectFill" src="{{img}}" data-index="{{imgIndex}}" data-images="{{item.images}}" bind:tap="onImageView"></image>
</view>
</view>
<view class="bottom-row">
+20 -5
View File
@@ -48,7 +48,13 @@ Page({
onShow() {
this.getTabBar().init();
this.refreshRole();
const app = getApp();
const appShowAt = app && app.globalData ? app.globalData.appShowAt : 0;
// 冷启动和从后台回到前台才拉角色;切换 Tab 不重复请求
if (!this._roleLoadedAt || appShowAt !== this._seenAppShowAt) {
this._seenAppShowAt = appShowAt;
this.refreshRole();
}
},
onLoad() {
@@ -64,12 +70,12 @@ Page({
},
onPullDownRefresh() {
this.init();
this.loadHomePage(true);
this.refreshRole();
},
init() {
this.loadHomePage();
this.loadHomePage(false);
},
/**
@@ -77,6 +83,10 @@ Page({
* 入驻审核通过后,用户回到小程序触发 onShow 即可看到「进入接单大厅」入口
*/
refreshRole() {
if (this._roleLoading) {
return Promise.resolve();
}
this._roleLoading = true;
return fetchPerson().then((res) => {
if (res.code === 1 && res.data) {
const role = res.data.role || '';
@@ -87,15 +97,20 @@ Page({
wx.setStorageSync('userInfo', userInfo);
}
}
}).catch((err) => {
console.error('refreshRole failed:', err);
}).then(() => {
this._roleLoading = false;
this._roleLoadedAt = Date.now();
});
},
async loadHomePage() {
async loadHomePage(force = false) {
this.setData({
pageLoading: true,
});
try {
const [configRes, bannerRes] = await Promise.all([fetchConfig(), fetchHomeBanners()]);
const [configRes, bannerRes] = await Promise.all([fetchConfig({ force }), fetchHomeBanners()]);
const next = { pageLoading: false };
if (configRes.code === 1) {
next.tabList = configRes.data.developTypes || [];
@@ -5,7 +5,7 @@ function tagTheme(type) {
'1': 'warning',
'2': 'success'
};
return map[String(type)] || 'default';
return map['' + type] || 'default';
}
module.exports = {
tagTheme: tagTheme
@@ -9,7 +9,7 @@ function tagTheme(type) {
'1': 'warning',
'2': 'success'
};
return map[String(type)] || 'default';
return map['' + type] || 'default';
}
module.exports = {
ellipsis: ellipsis,
@@ -298,7 +298,7 @@ Page({
onAmountTap() {
this.setData({
'serviceFrom.amount.temp': priceFormat(this.data.serviceFrom.amount.current),
'serviceFrom.amount.temp': priceFormat(this.data.serviceFrom.amount.current, 2),
'serviceFrom.amount.focus': true,
inputDialogVisible: true,
});
@@ -307,8 +307,13 @@ Page({
confirmBtn: '确定',
});
this.inputDialog._onConfirm = () => {
const max = Number(this.data.serviceFrom.amount.max) || 0;
let amount = parseFloat(this.data.serviceFrom.amount.temp) || 0;
if (amount > max) {
amount = max;
}
this.setData({
'serviceFrom.amount.current': this.data.serviceFrom.amount.temp * 100,
'serviceFrom.amount.current': amount,
});
};
this.inputDialog._onCancel = () => {};
@@ -327,12 +332,13 @@ Page({
let { value } = e.detail;
const regRes = value.match(/\d+(\.?\d+)?/); // 失去焦点时,不允许末尾为小数点
value = regRes ? regRes[0] : '0';
value = parseFloat(value) * 100;
if (value > this.data.serviceFrom.amount.max) {
value = this.data.serviceFrom.amount.max;
let amount = parseFloat(value) || 0;
const max = Number(this.data.serviceFrom.amount.max) || 0;
if (amount > max) {
amount = max;
}
this.setData({
'serviceFrom.amount.temp': priceFormat(value),
'serviceFrom.amount.temp': priceFormat(amount, 2),
'serviceFrom.amount.focus': false,
});
},
+77 -42
View File
@@ -3,6 +3,8 @@ import {
} from '../../services/usercenter/fetchUsercenter';
import Toast from 'tdesign-miniprogram/toast/index';
const USER_CENTER_TTL = 30000;
const menuData = [
[{
title: '我发布的需求',
@@ -94,6 +96,31 @@ const orderTagInfos = [{
},
];
function cloneMenu(list) {
return list.map((row) => row.map((item) => ({ ...item })));
}
/** 按角色组装菜单,每次返回新数组,避免改到模块上的模板 */
function buildMenu(userInfo = {}, countsData = []) {
const menu = cloneMenu(menuData);
menu[0] = menu[0].filter((item) => item.type !== 'quote' && item.type !== 'promoter');
if (userInfo.role === 'dev') {
menu[0].splice(1, 0, { title: '我投标的需求', tit: '', url: '', icon: '', type: 'quote' });
}
if (userInfo.group_name === PROMOTER_GROUP) {
const balanceIndex = menu[0].findIndex((item) => item.type === 'balance');
menu[0].splice(balanceIndex === -1 ? menu[0].length : balanceIndex + 1, 0, { ...promoterMenu });
}
const counts = Array.isArray(countsData) ? countsData : [];
menu[0].forEach((item) => {
const matched = counts.find((count) => count.type === item.type);
if (matched) {
item.tit = matched.num;
}
});
return menu;
}
const getDefaultData = () => ({
showMakePhone: false,
userInfo: {
@@ -101,8 +128,8 @@ const getDefaultData = () => ({
nickName: '正在登录...',
phoneNumber: '',
},
menuData,
orderTagInfos,
menuData: cloneMenu(menuData),
orderTagInfos: orderTagInfos.map((item) => ({ ...item })),
customerServiceInfo: {},
currAuthStep: 1,
showKefu: true,
@@ -118,10 +145,22 @@ Page({
onShow() {
this.getTabBar().init();
this.init();
const app = getApp();
const appShowAt = app && app.globalData ? app.globalData.appShowAt : 0;
const fromBackground = appShowAt !== this._seenAppShowAt;
this._seenAppShowAt = appShowAt;
const stale = !this._loadedAt || Date.now() - this._loadedAt > USER_CENTER_TTL;
// 从后台回来,或距离上次成功超过 30 秒,才重新拉用户中心
if (fromBackground || stale) {
this.init();
}
},
onPullDownRefresh() {
this.init();
if (this._loading) {
wx.stopPullDownRefresh();
return;
}
this.fetUseriInfoHandle();
},
init() {
@@ -129,44 +168,40 @@ Page({
},
fetUseriInfoHandle() {
fetchUserCenter().then(
(res) => {
const {
userInfo,
countsData,
orderTagInfos: orderTags,
customerServiceInfo,
} = res.data;
// eslint-disable-next-line no-unused-expressions
menuData[0] = menuData[0].filter((item) => item.type !== 'quote' && item.type !== 'promoter');
if (userInfo.role === 'dev') {
menuData[0].splice(1, 0, { title: '我投标的需求', tit: '', url: '', icon: '', type: 'quote' });
}
if (userInfo.group_name === PROMOTER_GROUP) {
const balanceIndex = menuData[0].findIndex((item) => item.type === 'balance');
menuData[0].splice(balanceIndex === -1 ? menuData[0].length : balanceIndex + 1, 0, { ...promoterMenu });
}
menuData[0].forEach((v) => {
countsData.forEach((counts) => {
if (counts.type === v.type) {
v.tit = counts.num;
}
});
});
const info = orderTagInfos.map((v, index) => ({
...v,
...orderTags[index],
}));
this.setData({
userInfo,
menuData,
orderTagInfos: info,
customerServiceInfo,
currAuthStep: 2,
});
wx.stopPullDownRefresh();
},
);
if (this._loading) {
return;
}
this._loading = true;
fetchUserCenter().then((res) => {
if (!res || res.code !== 1 || !res.data) {
wx.showToast({ title: (res && res.msg) || '加载失败', icon: 'none' });
return;
}
const {
userInfo,
countsData,
orderTagInfos: orderTags,
customerServiceInfo,
} = res.data;
const info = orderTagInfos.map((item, index) => ({
...item,
...(orderTags && orderTags[index] ? orderTags[index] : {}),
}));
this._loadedAt = Date.now();
this.setData({
userInfo,
menuData: buildMenu(userInfo, countsData),
orderTagInfos: info,
customerServiceInfo,
currAuthStep: 2,
});
}).catch((err) => {
console.error('fetchUserCenter failed:', err);
wx.showToast({ title: '网络异常,请重试', icon: 'none' });
}).then(() => {
this._loading = false;
wx.stopPullDownRefresh();
});
},
onClickCell({