feat: 新增身份选择弹窗并优化登录跳转逻辑
- 新增身份选择组件,用户登录后未选择身份时弹出选择框 - 优化登录跳转逻辑,支持页面栈返回模式 - 修复跳转时参数处理的边界情况 - 新增服务配置缓存机制,减少重复请求 - 优化小程序跳转逻辑,增加防重复点击锁 - 修复订单页联系人信息初始化逻辑
这个提交包含在:
@@ -27,6 +27,7 @@
|
||||
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
api.getServiceConfig(true).catch(() => {});
|
||||
// #ifdef MP-WEIXIN
|
||||
if (typeof wx !== 'undefined' && typeof wx.onNeedPrivacyAuthorization === 'function') {
|
||||
wx.onNeedPrivacyAuthorization((resolve) => {
|
||||
|
||||
@@ -895,8 +895,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
function exitToUser() {
|
||||
api.openUserMiniProgram('pages/index/index');
|
||||
async function exitToUser() {
|
||||
if (switchingRole.value) return;
|
||||
switchingRole.value = true;
|
||||
try {
|
||||
await api.openUserMiniProgram('pages/index/index');
|
||||
} finally {
|
||||
setTimeout(() => { switchingRole.value = false; }, 600);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -261,7 +261,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 6. 跨小程序跳转:前往用户端下单 -->
|
||||
<view class="switch-role-card clickable-hover" @tap="backToUser">
|
||||
<view class="switch-role-card clickable-hover" :class="{ disabled: switchingRole }" @tap="backToUser">
|
||||
<view class="src-left">
|
||||
<image class="src-ico" src="/static/icons/master/role-switch-orange.svg" mode="aspectFit" />
|
||||
<view class="src-text">
|
||||
@@ -605,8 +605,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
function backToUser() {
|
||||
api.openUserMiniProgram('pages/index/index');
|
||||
async function backToUser() {
|
||||
if (switchingRole.value) return;
|
||||
switchingRole.value = true;
|
||||
try {
|
||||
await api.openUserMiniProgram('pages/index/index');
|
||||
} finally {
|
||||
setTimeout(() => { switchingRole.value = false; }, 600);
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
@@ -1280,6 +1286,10 @@
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
box-shadow: $yjyf-shadow-card;
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.65;
|
||||
}
|
||||
}
|
||||
|
||||
.src-left {
|
||||
|
||||
@@ -560,6 +560,15 @@
|
||||
) {
|
||||
uni.switchTab({ url: redirectUrl.split('?')[0] });
|
||||
} else {
|
||||
try {
|
||||
const pages = getCurrentPages() || [];
|
||||
const prev = pages.length >= 2 ? pages[pages.length - 2] : null;
|
||||
const prevRoute = prev ? ('/' + (prev.route || (prev.$page && prev.$page.route) || '')) : '';
|
||||
if (prevRoute && prevRoute === redirectUrl.split('?')[0]) {
|
||||
uni.navigateBack();
|
||||
return;
|
||||
}
|
||||
} catch (e) {}
|
||||
uni.redirectTo({
|
||||
url: redirectUrl,
|
||||
fail: () => uni.switchTab({ url: '/pages/master/hall' })
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<!-- 未登录引导条 -->
|
||||
<view class="login-tip-bar" v-if="!loggedIn">
|
||||
<text class="login-tip-txt">请先登录账号,再上传证件并提交实名入驻</text>
|
||||
<view class="login-tip-btn clickable-hover" @tap="toLogin">
|
||||
<view class="login-tip-btn clickable-hover" @tap="goLogin">
|
||||
<text class="login-tip-btn-txt">去登录</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -245,6 +245,9 @@
|
||||
<view class="profile-save clickable-hover" :class="{ disabled: profileSaving || profileUploading }" @tap="saveProfile">
|
||||
<text>{{ profileSaving ? '保存中...' : '保存资料' }}</text>
|
||||
</view>
|
||||
<view class="profile-hall-btn clickable-hover" @tap="goHall">
|
||||
<text class="profile-hall-txt">进入接单大厅</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -425,6 +428,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
function goLogin() {
|
||||
toLogin('/pages/master/apply');
|
||||
}
|
||||
|
||||
function goHall() {
|
||||
uni.switchTab({ url: '/pages/master/hall' });
|
||||
}
|
||||
|
||||
function goWorkbench() {
|
||||
uni.switchTab({ url: '/pages/master/workbench' });
|
||||
}
|
||||
@@ -443,6 +454,7 @@
|
||||
const uploadingSide = ref('');
|
||||
const isSelectingImage = ref(false);
|
||||
const hasInitialLoaded = ref(false);
|
||||
const loadedWhileLoggedIn = ref(false);
|
||||
const isExpired = ref(false);
|
||||
const validDate = ref('');
|
||||
|
||||
@@ -544,6 +556,8 @@
|
||||
async function load() {
|
||||
loggedIn.value = isLogin();
|
||||
if (!loggedIn.value) {
|
||||
info.value = null;
|
||||
loadedWhileLoggedIn.value = false;
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
@@ -578,6 +592,7 @@
|
||||
if (u && !form.mobile) form.mobile = u.mobile || '';
|
||||
}
|
||||
hasInitialLoaded.value = true;
|
||||
loadedWhileLoggedIn.value = true;
|
||||
} catch (e) {
|
||||
} finally {
|
||||
loading.value = false;
|
||||
@@ -677,7 +692,7 @@
|
||||
return;
|
||||
}
|
||||
loggedIn.value = isLogin();
|
||||
if (!hasInitialLoaded.value) {
|
||||
if (!hasInitialLoaded.value || (loggedIn.value && !loadedWhileLoggedIn.value) || (!loggedIn.value && loadedWhileLoggedIn.value)) {
|
||||
await load();
|
||||
}
|
||||
if (!cats.value.length) {
|
||||
@@ -725,6 +740,8 @@
|
||||
.identity-cert-caption { font-size: $yjyf-font-micro; color: $yjyf-text-inverse; font-weight: 500; }
|
||||
.profile-save { height: 88rpx; margin: 36rpx $yjyf-space-md 0; border-radius: $yjyf-radius-pill; background: $yjyf-gradient-primary; box-shadow: $yjyf-shadow-button; color: $yjyf-text-inverse; display: flex; align-items: center; justify-content: center; font-size: $yjyf-font-body; font-weight: 700; }
|
||||
.profile-save.disabled { opacity: 0.6; }
|
||||
.profile-hall-btn { height: 84rpx; margin: 20rpx $yjyf-space-md 0; border-radius: $yjyf-radius-pill; background: $yjyf-bg-card; border: 2rpx solid $yjyf-primary; display: flex; align-items: center; justify-content: center; }
|
||||
.profile-hall-txt { font-size: $yjyf-font-body; color: $yjyf-primary; font-weight: 600; }
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: $yjyf-bg-page;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export function toLogin(redirect) {
|
||||
setTimeout(() => {
|
||||
loginRedirectLock = false;
|
||||
}, 800);
|
||||
let targetRedirect = redirect || '';
|
||||
let targetRedirect = typeof redirect === 'string' ? redirect : '';
|
||||
if (!targetRedirect) {
|
||||
try {
|
||||
const pages = getCurrentPages() || [];
|
||||
|
||||
在新工单中引用
屏蔽一个用户