feat: 新增身份选择弹窗并优化登录跳转逻辑
- 新增身份选择组件,用户登录后未选择身份时弹出选择框 - 优化登录跳转逻辑,支持页面栈返回模式 - 修复跳转时参数处理的边界情况 - 新增服务配置缓存机制,减少重复请求 - 优化小程序跳转逻辑,增加防重复点击锁 - 修复订单页联系人信息初始化逻辑
这个提交包含在:
@@ -4,6 +4,26 @@
|
||||
import { get, post, uploadFile } from './request';
|
||||
import config from '@/config/config.js';
|
||||
|
||||
const SERVICE_CONFIG_CACHE_TTL = 5 * 60 * 1000;
|
||||
|
||||
function resolveTargetMiniProgramEnv() {
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const getter = (typeof uni !== 'undefined' && typeof uni.getAccountInfoSync === 'function')
|
||||
? uni.getAccountInfoSync
|
||||
: (typeof wx !== 'undefined' && typeof wx.getAccountInfoSync === 'function' ? wx.getAccountInfoSync : null);
|
||||
if (getter) {
|
||||
const info = getter();
|
||||
const envVersion = info && info.miniProgram && info.miniProgram.envVersion;
|
||||
if (envVersion === 'develop' || envVersion === 'trial') {
|
||||
return envVersion;
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
// #endif
|
||||
return 'release';
|
||||
}
|
||||
|
||||
export default {
|
||||
/* ---------- 公共 / 上传 / 字典 ---------- */
|
||||
upload: (filePath, category = 'other') => uploadFile(filePath, category),
|
||||
@@ -85,6 +105,7 @@ export default {
|
||||
service_corp_id: String(cached.service_corp_id || '').trim(),
|
||||
service_kf_url: String(cached.service_kf_url || '').trim(),
|
||||
user_appid: String(cached.user_appid || '').trim(),
|
||||
updated_at: Number(cached.updated_at || 0),
|
||||
};
|
||||
}
|
||||
} catch (e) {}
|
||||
@@ -94,11 +115,13 @@ export default {
|
||||
service_corp_id: '',
|
||||
service_kf_url: '',
|
||||
user_appid: '',
|
||||
updated_at: 0,
|
||||
};
|
||||
},
|
||||
getServiceConfig: async function (force = false) {
|
||||
const cached = this.getCachedServiceConfig();
|
||||
if (!force && (cached.service_phone || cached.service_corp_id || cached.service_kf_url) && cached.user_appid) {
|
||||
const isFresh = cached.updated_at > 0 && (Date.now() - cached.updated_at < SERVICE_CONFIG_CACHE_TTL);
|
||||
if (!force && isFresh && cached.user_appid) {
|
||||
return cached;
|
||||
}
|
||||
try {
|
||||
@@ -110,6 +133,7 @@ export default {
|
||||
service_corp_id: String(res.service_corp_id || '').trim(),
|
||||
service_kf_url: String(res.service_kf_url || '').trim(),
|
||||
user_appid: String(res.user_appid || '').trim(),
|
||||
updated_at: Date.now(),
|
||||
};
|
||||
uni.setStorageSync('yjyf_master_service_config', cfg);
|
||||
if (cfg.service_phone) {
|
||||
@@ -117,35 +141,69 @@ export default {
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
console.warn('获取客服配置失败', e);
|
||||
}
|
||||
return cached;
|
||||
},
|
||||
_openingUserMini: false,
|
||||
openUserMiniProgram: async function (path = 'pages/index/index') {
|
||||
let cfg = await this.getServiceConfig();
|
||||
if (!cfg.user_appid) {
|
||||
cfg = await this.getServiceConfig(true);
|
||||
}
|
||||
const targetAppId = cfg.user_appid;
|
||||
if (this._openingUserMini) return;
|
||||
this._openingUserMini = true;
|
||||
const releaseLock = () => {
|
||||
setTimeout(() => { this._openingUserMini = false; }, 600);
|
||||
};
|
||||
const cached = this.getCachedServiceConfig();
|
||||
// #ifdef MP-WEIXIN
|
||||
if (!targetAppId) {
|
||||
uni.showToast({ title: '后台暂未配置用户端小程序 AppID', icon: 'none' });
|
||||
const launch = (appId) => {
|
||||
if (!appId) {
|
||||
releaseLock();
|
||||
uni.showModal({
|
||||
title: '优匠优服用户端',
|
||||
content: '后台暂未配置用户端小程序 AppID,请在微信搜索打开「优匠优服」小程序或联系平台管理员在后台系统配置中完善。',
|
||||
showCancel: false,
|
||||
confirmText: '知道了',
|
||||
confirmColor: '#F0710D'
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.navigateToMiniProgram({
|
||||
appId: appId,
|
||||
path: path,
|
||||
envVersion: resolveTargetMiniProgramEnv(),
|
||||
complete: () => {
|
||||
releaseLock();
|
||||
},
|
||||
fail: (err) => {
|
||||
if (err && err.errMsg && err.errMsg.indexOf('cancel') !== -1) return;
|
||||
console.warn('[openUserMiniProgram] navigateToMiniProgram fail:', err);
|
||||
uni.showToast({ title: '打开用户端小程序失败,请稍后重试', icon: 'none' });
|
||||
}
|
||||
});
|
||||
};
|
||||
if (cached.user_appid) {
|
||||
launch(cached.user_appid);
|
||||
if (!cached.updated_at || Date.now() - cached.updated_at >= SERVICE_CONFIG_CACHE_TTL) {
|
||||
this.getServiceConfig(true).catch(() => {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
uni.navigateToMiniProgram({
|
||||
appId: targetAppId,
|
||||
path: path,
|
||||
fail: (err) => {
|
||||
if (err && err.errMsg && err.errMsg.indexOf('cancel') !== -1) return;
|
||||
uni.showToast({ title: '打开用户端小程序失败,请稍后重试', icon: 'none' });
|
||||
}
|
||||
});
|
||||
try {
|
||||
const cfg = await this.getServiceConfig(true);
|
||||
launch(cfg.user_appid);
|
||||
} catch (e) {
|
||||
releaseLock();
|
||||
uni.showToast({ title: '获取用户端配置失败,请稍后重试', icon: 'none' });
|
||||
}
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
releaseLock();
|
||||
uni.showModal({
|
||||
title: '前往优匠优服用户端',
|
||||
content: '请在微信中搜索「优匠优服」小程序发布安装维修需求。',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
confirmText: '知道了',
|
||||
confirmColor: '#F0710D'
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户