feat: 新增身份选择弹窗并优化登录跳转逻辑
- 新增身份选择组件,用户登录后未选择身份时弹出选择框 - 优化登录跳转逻辑,支持页面栈返回模式 - 修复跳转时参数处理的边界情况 - 新增服务配置缓存机制,减少重复请求 - 优化小程序跳转逻辑,增加防重复点击锁 - 修复订单页联系人信息初始化逻辑
这个提交包含在:
140
tests/login_navigation.test.mjs
普通文件
140
tests/login_navigation.test.mjs
普通文件
@@ -0,0 +1,140 @@
|
|||||||
|
import assert from 'assert';
|
||||||
|
import {
|
||||||
|
buildLoginUrl,
|
||||||
|
normalizeRoutePath,
|
||||||
|
parseLoginParams,
|
||||||
|
resolvePostLoginAction,
|
||||||
|
shouldPreservePageOnLogin
|
||||||
|
} from '../yjyf-app/utils/login-navigation.mjs';
|
||||||
|
|
||||||
|
assert.equal(normalizeRoutePath('/pages/order/quick?service_id=12#top'), 'pages/order/quick');
|
||||||
|
assert.equal(shouldPreservePageOnLogin('pages/order/quick'), true);
|
||||||
|
assert.equal(shouldPreservePageOnLogin('/pages/order/quick?cat_id=3'), true);
|
||||||
|
assert.equal(shouldPreservePageOnLogin('pages/order/goods-template'), false);
|
||||||
|
assert.equal(shouldPreservePageOnLogin('pages/invoice/detail'), false);
|
||||||
|
|
||||||
|
// 1. 构建与解析登录参数
|
||||||
|
const quickLoginUrl = buildLoginUrl('/pages/order/quick?cat_id=2&service_id=10', { back: true });
|
||||||
|
assert.equal(
|
||||||
|
quickLoginUrl,
|
||||||
|
'/pages/login/login?redirect=%2Fpages%2Forder%2Fquick%3Fcat_id%3D2%26service_id%3D10&back=1'
|
||||||
|
);
|
||||||
|
|
||||||
|
const parsedQuick = parseLoginParams({
|
||||||
|
redirect: encodeURIComponent('/pages/order/quick?cat_id=2&service_id=10'),
|
||||||
|
back: '1'
|
||||||
|
});
|
||||||
|
assert.deepEqual(parsedQuick, {
|
||||||
|
redirectUrl: '/pages/order/quick?cat_id=2&service_id=10',
|
||||||
|
preferBack: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// 兼容双层 encodeURIComponent 的场景
|
||||||
|
const parsedDoubleEncoded = parseLoginParams({
|
||||||
|
redirect: encodeURIComponent(encodeURIComponent('/pages/order/quick')),
|
||||||
|
back: '1'
|
||||||
|
});
|
||||||
|
assert.deepEqual(parsedDoubleEncoded, {
|
||||||
|
redirectUrl: '/pages/order/quick',
|
||||||
|
preferBack: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. 下单到最后一步触发登录,返回时应直接 navigateBack 保留原页面与步骤状态
|
||||||
|
assert.deepEqual(
|
||||||
|
resolvePostLoginAction({
|
||||||
|
redirectUrl: '/pages/order/quick?cat_id=2&service_id=10',
|
||||||
|
preferBack: true,
|
||||||
|
pages: [{ route: 'pages/index/index' }, { route: 'pages/order/quick' }, { route: 'pages/login/login' }]
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: 'navigateBack',
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: '/pages/order/quick?cat_id=2&service_id=10'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 3. 若页面栈仅剩登录页(如 H5 刷新后),安全兜底回原目标 URL
|
||||||
|
assert.deepEqual(
|
||||||
|
resolvePostLoginAction({
|
||||||
|
redirectUrl: '/pages/order/quick?cat_id=2',
|
||||||
|
preferBack: true,
|
||||||
|
pages: [{ route: 'pages/login/login' }]
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: 'redirectTo',
|
||||||
|
url: '/pages/order/quick?cat_id=2',
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: '/pages/order/quick?cat_id=2'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 4. 若栈上一页并非目标页(不匹配),避免误返回无关页面,走 redirectTo
|
||||||
|
assert.deepEqual(
|
||||||
|
resolvePostLoginAction({
|
||||||
|
redirectUrl: '/pages/order/quick',
|
||||||
|
preferBack: true,
|
||||||
|
pages: [{ route: 'pages/service/detail' }, { route: 'pages/login/login' }]
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: 'redirectTo',
|
||||||
|
url: '/pages/order/quick',
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: '/pages/order/quick'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 5. 首页 / Tab 切页重定向保持 reLaunch 行为不变
|
||||||
|
assert.deepEqual(
|
||||||
|
resolvePostLoginAction({
|
||||||
|
redirectUrl: '/pages/index/index?tab=1&status=wait_pay',
|
||||||
|
preferBack: false,
|
||||||
|
pages: [{ route: 'pages/index/index' }, { route: 'pages/login/login' }]
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: 'reLaunch',
|
||||||
|
url: '/pages/index/index?tab=1&status=wait_pay'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 6. 仅在 onLoad 拉数据的子页面维持 redirectTo 以触发重新加载
|
||||||
|
assert.deepEqual(
|
||||||
|
resolvePostLoginAction({
|
||||||
|
redirectUrl: '/pages/order/goods-template?cat_id=1',
|
||||||
|
preferBack: false,
|
||||||
|
pages: [{ route: 'pages/order/quick' }, { route: 'pages/order/goods-template' }, { route: 'pages/login/login' }]
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: 'redirectTo',
|
||||||
|
url: '/pages/order/goods-template?cat_id=1',
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: '/pages/order/goods-template?cat_id=1'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 7. 无 redirectUrl 时依据页面栈返回或回首页
|
||||||
|
assert.deepEqual(
|
||||||
|
resolvePostLoginAction({
|
||||||
|
redirectUrl: '',
|
||||||
|
preferBack: false,
|
||||||
|
pages: [{ route: 'pages/order/quick' }, { route: 'pages/login/login' }]
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: 'navigateBack',
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: '/pages/index/index'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
resolvePostLoginAction({
|
||||||
|
redirectUrl: '',
|
||||||
|
preferBack: false,
|
||||||
|
pages: [{ route: 'pages/login/login' }]
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
type: 'reLaunch',
|
||||||
|
url: '/pages/index/index'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('login navigation tests passed');
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import api from '@/utils/api.js';
|
||||||
|
|
||||||
let lastNavUrl = '';
|
let lastNavUrl = '';
|
||||||
let lastNavAt = 0;
|
let lastNavAt = 0;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function() {
|
onLaunch: function() {
|
||||||
|
api.getServiceConfig(true).catch(() => {});
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
if (typeof wx !== 'undefined' && typeof wx.onNeedPrivacyAuthorization === 'function') {
|
if (typeof wx !== 'undefined' && typeof wx.onNeedPrivacyAuthorization === 'function') {
|
||||||
wx.onNeedPrivacyAuthorization((resolve) => {
|
wx.onNeedPrivacyAuthorization((resolve) => {
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<template>
|
||||||
|
<view v-if="visible" class="identity-mask">
|
||||||
|
<view class="identity-dialog">
|
||||||
|
<text class="identity-title">请选择用户类型</text>
|
||||||
|
<text class="identity-description">请选择您的使用身份,确认后不可自行修改</text>
|
||||||
|
<view
|
||||||
|
class="identity-option"
|
||||||
|
:class="{ selected: identityChoice === 'personal' }"
|
||||||
|
@tap="identityChoice = 'personal'"
|
||||||
|
>
|
||||||
|
<text class="identity-option-title">个人用户</text>
|
||||||
|
<text class="identity-option-desc">家庭或个人使用</text>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
class="identity-option"
|
||||||
|
:class="{ selected: identityChoice === 'merchant' }"
|
||||||
|
@tap="identityChoice = 'merchant'"
|
||||||
|
>
|
||||||
|
<text class="identity-option-title">商家用户</text>
|
||||||
|
<text class="identity-option-desc">商家或企业使用</text>
|
||||||
|
</view>
|
||||||
|
<button
|
||||||
|
class="identity-confirm"
|
||||||
|
:disabled="!identityChoice || selectingIdentity"
|
||||||
|
@tap="confirmIdentity"
|
||||||
|
>
|
||||||
|
{{ selectingIdentity ? '提交中...' : '确认选择' }}
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
import api from '@/utils/api.js';
|
||||||
|
import { setUser } from '@/utils/request.js';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:visible', 'confirmed']);
|
||||||
|
|
||||||
|
const identityChoice = ref('');
|
||||||
|
const selectingIdentity = ref(false);
|
||||||
|
|
||||||
|
watch(() => props.visible, (val) => {
|
||||||
|
if (val) {
|
||||||
|
identityChoice.value = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function confirmIdentity() {
|
||||||
|
if (!identityChoice.value || selectingIdentity.value) return;
|
||||||
|
selectingIdentity.value = true;
|
||||||
|
try {
|
||||||
|
const res = await api.selectIdentity({ user_type: identityChoice.value });
|
||||||
|
setUser(res.userinfo);
|
||||||
|
emit('update:visible', false);
|
||||||
|
emit('confirmed', res.userinfo);
|
||||||
|
} catch (e) {
|
||||||
|
// 网络响应丢失但服务端可能已保存身份时,回查 profile 确认状态
|
||||||
|
try {
|
||||||
|
const current = await api.profile();
|
||||||
|
if (current && current.identity_selected) {
|
||||||
|
setUser(current);
|
||||||
|
emit('update:visible', false);
|
||||||
|
emit('confirmed', current);
|
||||||
|
}
|
||||||
|
} catch (profileError) {}
|
||||||
|
} finally {
|
||||||
|
selectingIdentity.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '@/uni.scss';
|
||||||
|
|
||||||
|
.identity-mask {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 999;
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 48rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-dialog {
|
||||||
|
width: 100%;
|
||||||
|
background: $yjyf-bg-card;
|
||||||
|
border-radius: 24rpx;
|
||||||
|
padding: 40rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-title {
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
color: $yjyf-text-main;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-description {
|
||||||
|
margin: 16rpx 0 32rpx;
|
||||||
|
font-size: 25rpx;
|
||||||
|
color: $yjyf-text-secondary;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-option {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 24rpx;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
border: 2rpx solid $yjyf-border-color;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-option.selected {
|
||||||
|
border-color: $yjyf-primary;
|
||||||
|
background: $yjyf-primary-bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-option-title {
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: $yjyf-text-main;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-option-desc {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: $yjyf-text-secondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-confirm {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 12rpx;
|
||||||
|
background: $yjyf-gradient-primary;
|
||||||
|
color: $yjyf-bg-card;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.identity-confirm[disabled] {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -315,8 +315,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openMasterApp() {
|
const openingMasterApp = ref(false);
|
||||||
api.openMasterMiniProgram('pages/master/apply');
|
|
||||||
|
async function openMasterApp() {
|
||||||
|
if (openingMasterApp.value) return;
|
||||||
|
openingMasterApp.value = true;
|
||||||
|
try {
|
||||||
|
await api.openMasterMiniProgram('pages/master/hall');
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => { openingMasterApp.value = false; }, 600);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
|
|||||||
@@ -23,19 +23,7 @@
|
|||||||
<!-- 全局统一底部导航 (方案 A:单母页组件化调度,0ms 极速秒切) -->
|
<!-- 全局统一底部导航 (方案 A:单母页组件化调度,0ms 极速秒切) -->
|
||||||
<YjyfTabBar :current="activeTab" @change="onTabChange" />
|
<YjyfTabBar :current="activeTab" @change="onTabChange" />
|
||||||
<YjyfPrivacyPopup />
|
<YjyfPrivacyPopup />
|
||||||
<view v-if="showIdentityPicker" class="identity-mask">
|
<YjyfIdentityPicker v-model:visible="showIdentityPicker" />
|
||||||
<view class="identity-dialog">
|
|
||||||
<text class="identity-title">请选择用户类型</text>
|
|
||||||
<text class="identity-description">请选择您的使用身份,确认后不可自行修改</text>
|
|
||||||
<view class="identity-option" :class="{ selected: identityChoice === 'personal' }" @tap="identityChoice = 'personal'">
|
|
||||||
<text class="identity-option-title">个人用户</text><text class="identity-option-desc">家庭或个人使用</text>
|
|
||||||
</view>
|
|
||||||
<view class="identity-option" :class="{ selected: identityChoice === 'merchant' }" @tap="identityChoice = 'merchant'">
|
|
||||||
<text class="identity-option-title">商家用户</text><text class="identity-option-desc">商家或企业使用</text>
|
|
||||||
</view>
|
|
||||||
<button class="identity-confirm" :disabled="!identityChoice || selectingIdentity" @tap="confirmIdentity">{{ selectingIdentity ? '提交中...' : '确认选择' }}</button>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -48,13 +36,11 @@
|
|||||||
import UserMineView from '@/components/user/UserMineView.vue';
|
import UserMineView from '@/components/user/UserMineView.vue';
|
||||||
import YjyfTabBar from '@/components/YjyfTabBar.vue';
|
import YjyfTabBar from '@/components/YjyfTabBar.vue';
|
||||||
import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue';
|
import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue';
|
||||||
import { isLogin, toLogin, getUser, setUser } from '@/utils/request.js';
|
import YjyfIdentityPicker from '@/components/YjyfIdentityPicker.vue';
|
||||||
import api from '@/utils/api.js';
|
import { isLogin, toLogin, getUser } from '@/utils/request.js';
|
||||||
import { useShare } from '@/utils/share.js';
|
import { useShare } from '@/utils/share.js';
|
||||||
|
|
||||||
const showIdentityPicker = ref(false);
|
const showIdentityPicker = ref(false);
|
||||||
const identityChoice = ref('');
|
|
||||||
const selectingIdentity = ref(false);
|
|
||||||
const activeTab = ref(0);
|
const activeTab = ref(0);
|
||||||
const initialOrderStatus = ref('all');
|
const initialOrderStatus = ref('all');
|
||||||
const visitedTabs = reactive({ 0: true, 1: false, 2: false, 3: false });
|
const visitedTabs = reactive({ 0: true, 1: false, 2: false, 3: false });
|
||||||
@@ -135,27 +121,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function confirmIdentity() {
|
|
||||||
if (!identityChoice.value || selectingIdentity.value) return;
|
|
||||||
selectingIdentity.value = true;
|
|
||||||
try {
|
|
||||||
const res = await api.selectIdentity({ user_type: identityChoice.value });
|
|
||||||
setUser(res.userinfo);
|
|
||||||
showIdentityPicker.value = false;
|
|
||||||
} catch (e) {
|
|
||||||
// A response can be lost after the selection has been saved.
|
|
||||||
try {
|
|
||||||
const current = await api.profile();
|
|
||||||
if (current.identity_selected) {
|
|
||||||
setUser(current);
|
|
||||||
showIdentityPicker.value = false;
|
|
||||||
}
|
|
||||||
} catch (profileError) {}
|
|
||||||
} finally {
|
|
||||||
selectingIdentity.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onBackPress(() => showIdentityPicker.value);
|
onBackPress(() => showIdentityPicker.value);
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
@@ -175,16 +140,6 @@
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import '@/uni.scss';
|
@import '@/uni.scss';
|
||||||
.identity-mask { position: fixed; inset: 0; z-index: 999; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 48rpx; }
|
|
||||||
.identity-dialog { width: 100%; background: $yjyf-bg-card; border-radius: 24rpx; padding: 40rpx; display: flex; flex-direction: column; }
|
|
||||||
.identity-title { font-size: 36rpx; font-weight: 700; color: $yjyf-text-main; text-align: center; }
|
|
||||||
.identity-description { margin: 16rpx 0 32rpx; font-size: 25rpx; color: $yjyf-text-secondary; text-align: center; }
|
|
||||||
.identity-option { display: flex; flex-direction: column; padding: 24rpx; margin-bottom: 20rpx; border: 2rpx solid $yjyf-border-color; border-radius: 16rpx; }
|
|
||||||
.identity-option.selected { border-color: $yjyf-primary; background: $yjyf-primary-bg; }
|
|
||||||
.identity-option-title { font-size: 30rpx; font-weight: 600; color: $yjyf-text-main; }
|
|
||||||
.identity-option-desc { margin-top: 8rpx; font-size: 24rpx; color: $yjyf-text-secondary; }
|
|
||||||
.identity-confirm { width: 100%; margin-top: 12rpx; background: $yjyf-gradient-primary; color: $yjyf-bg-card; border-radius: 16rpx; font-size: 30rpx; }
|
|
||||||
.identity-confirm[disabled] { opacity: .5; }
|
|
||||||
|
|
||||||
.user-container-page {
|
.user-container-page {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
|||||||
@@ -127,6 +127,7 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<YjyfPrivacyPopup />
|
<YjyfPrivacyPopup />
|
||||||
|
<YjyfIdentityPicker v-model:visible="showIdentityPicker" @confirmed="onIdentityConfirmed" />
|
||||||
|
|
||||||
<!-- 短信重置密码弹窗 -->
|
<!-- 短信重置密码弹窗 -->
|
||||||
<view class="reset-mask" v-if="showReset" @tap="closeResetModal">
|
<view class="reset-mask" v-if="showReset" @tap="closeResetModal">
|
||||||
@@ -244,12 +245,14 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { onLoad, onUnload } from '@dcloudio/uni-app';
|
import { onLoad, onUnload, onBackPress } from '@dcloudio/uni-app';
|
||||||
import api from '@/utils/api.js';
|
import api from '@/utils/api.js';
|
||||||
import { setToken, setUser } from '@/utils/request.js';
|
import { setToken, setUser } from '@/utils/request.js';
|
||||||
import { getWxCode } from '@/utils/wxlogin.js';
|
import { getWxCode } from '@/utils/wxlogin.js';
|
||||||
import { getWindowInfoSafe } from '@/utils/system.js';
|
import { getWindowInfoSafe } from '@/utils/system.js';
|
||||||
|
import { parseLoginParams, resolvePostLoginAction } from '@/utils/login-navigation.mjs';
|
||||||
import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue';
|
import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue';
|
||||||
|
import YjyfIdentityPicker from '@/components/YjyfIdentityPicker.vue';
|
||||||
|
|
||||||
const LOGIN_AGREEMENT_EVENT = 'login_agreement_confirm';
|
const LOGIN_AGREEMENT_EVENT = 'login_agreement_confirm';
|
||||||
|
|
||||||
@@ -257,6 +260,7 @@
|
|||||||
const showBack = ref(false);
|
const showBack = ref(false);
|
||||||
const agreePolicy = ref(false);
|
const agreePolicy = ref(false);
|
||||||
const needShake = ref(false);
|
const needShake = ref(false);
|
||||||
|
const showIdentityPicker = ref(false);
|
||||||
|
|
||||||
// H5 账号密码登录状态
|
// H5 账号密码登录状态
|
||||||
const account = ref('');
|
const account = ref('');
|
||||||
@@ -276,6 +280,7 @@
|
|||||||
let resetTimer = null;
|
let resetTimer = null;
|
||||||
|
|
||||||
let redirectUrl = '';
|
let redirectUrl = '';
|
||||||
|
let preferBack = false;
|
||||||
|
|
||||||
const statusBarHeight = ref(20);
|
const statusBarHeight = ref(20);
|
||||||
|
|
||||||
@@ -324,20 +329,16 @@
|
|||||||
statusBarHeight.value = sys.statusBarHeight;
|
statusBarHeight.value = sys.statusBarHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options && options.redirect) {
|
const parsed = parseLoginParams(options);
|
||||||
let decoded = decodeURIComponent(options.redirect);
|
redirectUrl = parsed.redirectUrl;
|
||||||
if (decoded.startsWith('%2F') || decoded.startsWith('%2f')) {
|
preferBack = parsed.preferBack;
|
||||||
try {
|
|
||||||
decoded = decodeURIComponent(decoded);
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
redirectUrl = decoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
showBack.value = pages.length > 1;
|
showBack.value = pages.length > 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onBackPress(() => showIdentityPicker.value);
|
||||||
|
|
||||||
onUnload(() => {
|
onUnload(() => {
|
||||||
uni.$off(LOGIN_AGREEMENT_EVENT, handleAgreementConfirm);
|
uni.$off(LOGIN_AGREEMENT_EVENT, handleAgreementConfirm);
|
||||||
if (resetTimer) {
|
if (resetTimer) {
|
||||||
@@ -523,7 +524,11 @@
|
|||||||
|
|
||||||
if (res.userinfo.identity_selected === false) {
|
if (res.userinfo.identity_selected === false) {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
uni.reLaunch({ url: '/pages/index/index' });
|
if (preferBack && (getCurrentPages() || []).length > 1) {
|
||||||
|
showIdentityPicker.value = true;
|
||||||
|
} else {
|
||||||
|
uni.reLaunch({ url: '/pages/index/index' });
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast('登录成功');
|
toast('登录成功');
|
||||||
@@ -573,7 +578,11 @@
|
|||||||
|
|
||||||
if (res.userinfo.identity_selected === false) {
|
if (res.userinfo.identity_selected === false) {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
uni.reLaunch({ url: '/pages/index/index' });
|
if (preferBack && (getCurrentPages() || []).length > 1) {
|
||||||
|
showIdentityPicker.value = true;
|
||||||
|
} else {
|
||||||
|
uni.reLaunch({ url: '/pages/index/index' });
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast(res.is_new ? '欢迎加入优匠优服' : '登录成功');
|
toast(res.is_new ? '欢迎加入优匠优服' : '登录成功');
|
||||||
@@ -587,27 +596,38 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onIdentityConfirmed() {
|
||||||
|
toast('欢迎加入优匠优服');
|
||||||
|
setTimeout(() => {
|
||||||
|
finishLogin();
|
||||||
|
}, 400);
|
||||||
|
}
|
||||||
|
|
||||||
/** 登录完成后流转回原目标页或用户首页 */
|
/** 登录完成后流转回原目标页或用户首页 */
|
||||||
function finishLogin() {
|
function finishLogin() {
|
||||||
if (redirectUrl) {
|
const action = resolvePostLoginAction({
|
||||||
if (redirectUrl.startsWith('/pages/index/') || redirectUrl.startsWith('/pages/mine/')) {
|
redirectUrl,
|
||||||
uni.reLaunch({ url: redirectUrl });
|
preferBack,
|
||||||
} else {
|
pages: getCurrentPages() || []
|
||||||
uni.redirectTo({
|
});
|
||||||
url: redirectUrl,
|
if (action.type === 'navigateBack') {
|
||||||
fail: () => {
|
uni.navigateBack({
|
||||||
uni.reLaunch({ url: redirectUrl });
|
fail: () => {
|
||||||
}
|
uni.reLaunch({ url: action.fallbackUrl || '/pages/index/index' });
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (action.type === 'redirectTo') {
|
||||||
if (getCurrentPages().length > 1) {
|
uni.redirectTo({
|
||||||
uni.navigateBack();
|
url: action.url,
|
||||||
} else {
|
fail: () => {
|
||||||
uni.reLaunch({ url: '/pages/index/index' });
|
uni.reLaunch({ url: action.fallbackUrl || action.url });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
uni.reLaunch({ url: action.url || '/pages/index/index' });
|
||||||
}
|
}
|
||||||
|
|
||||||
function openAgreement(type) {
|
function openAgreement(type) {
|
||||||
|
|||||||
@@ -2167,8 +2167,12 @@
|
|||||||
try {
|
try {
|
||||||
const p = await api.profile();
|
const p = await api.profile();
|
||||||
if (p) {
|
if (p) {
|
||||||
form.order_contact_name = p.nickname || ('用户' + String(p.mobile || '').slice(-4));
|
if (!form.order_contact_name) {
|
||||||
form.order_contact_mobile = p.mobile || '';
|
form.order_contact_name = p.nickname || ('用户' + String(p.mobile || '').slice(-4));
|
||||||
|
}
|
||||||
|
if (!form.order_contact_mobile) {
|
||||||
|
form.order_contact_mobile = p.mobile || '';
|
||||||
|
}
|
||||||
if (!goodsArrivedTouched.value) {
|
if (!goodsArrivedTouched.value) {
|
||||||
const isMerchantUser = p.user_type === 'merchant' || Number(p.is_merchant) === 1;
|
const isMerchantUser = p.user_type === 'merchant' || Number(p.is_merchant) === 1;
|
||||||
form.goods_arrived = isMerchantUser ? 0 : 1;
|
form.goods_arrived = isMerchantUser ? 0 : 1;
|
||||||
@@ -2823,6 +2827,14 @@
|
|||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
loadUserWallet();
|
loadUserWallet();
|
||||||
|
if (isLogin()) {
|
||||||
|
if (!form.order_contact_name || !form.order_contact_mobile) {
|
||||||
|
initOrderContactFromProfile();
|
||||||
|
}
|
||||||
|
if (!form.contact && !form.address) {
|
||||||
|
initDefaultCustomerAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
const pickedTpl = uni.getStorageSync('yjyf_picked_goods_template');
|
const pickedTpl = uni.getStorageSync('yjyf_picked_goods_template');
|
||||||
if (pickedTpl) {
|
if (pickedTpl) {
|
||||||
onReceiveGoodsTemplate(pickedTpl);
|
onReceiveGoodsTemplate(pickedTpl);
|
||||||
|
|||||||
@@ -4,6 +4,26 @@
|
|||||||
import { get, post, uploadFile } from './request';
|
import { get, post, uploadFile } from './request';
|
||||||
import config from '@/config/config.js';
|
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 {
|
export default {
|
||||||
/* ---------- 公共 / 上传 / 字典 ---------- */
|
/* ---------- 公共 / 上传 / 字典 ---------- */
|
||||||
upload: (filePath, category = 'other') => uploadFile(filePath, category),
|
upload: (filePath, category = 'other') => uploadFile(filePath, category),
|
||||||
@@ -126,6 +146,7 @@ export default {
|
|||||||
service_corp_id: String(cached.service_corp_id || '').trim(),
|
service_corp_id: String(cached.service_corp_id || '').trim(),
|
||||||
service_kf_url: String(cached.service_kf_url || '').trim(),
|
service_kf_url: String(cached.service_kf_url || '').trim(),
|
||||||
master_appid: String(cached.master_appid || '').trim(),
|
master_appid: String(cached.master_appid || '').trim(),
|
||||||
|
updated_at: Number(cached.updated_at || 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@@ -136,11 +157,13 @@ export default {
|
|||||||
service_corp_id: '',
|
service_corp_id: '',
|
||||||
service_kf_url: '',
|
service_kf_url: '',
|
||||||
master_appid: '',
|
master_appid: '',
|
||||||
|
updated_at: 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getServiceConfig: async function (force = false) {
|
getServiceConfig: async function (force = false) {
|
||||||
const cached = this.getCachedServiceConfig();
|
const cached = this.getCachedServiceConfig();
|
||||||
if (!force && (cached.service_phone || cached.service_corp_id || cached.service_kf_url) && cached.master_appid) {
|
const isFresh = cached.updated_at > 0 && (Date.now() - cached.updated_at < SERVICE_CONFIG_CACHE_TTL);
|
||||||
|
if (!force && isFresh && cached.master_appid) {
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -152,6 +175,7 @@ export default {
|
|||||||
service_corp_id: String(res.service_corp_id || '').trim(),
|
service_corp_id: String(res.service_corp_id || '').trim(),
|
||||||
service_kf_url: String(res.service_kf_url || '').trim(),
|
service_kf_url: String(res.service_kf_url || '').trim(),
|
||||||
master_appid: String(res.master_appid || '').trim(),
|
master_appid: String(res.master_appid || '').trim(),
|
||||||
|
updated_at: Date.now(),
|
||||||
};
|
};
|
||||||
uni.setStorageSync('yjyf_service_config', cfg);
|
uni.setStorageSync('yjyf_service_config', cfg);
|
||||||
if (cfg.service_phone) {
|
if (cfg.service_phone) {
|
||||||
@@ -166,33 +190,58 @@ export default {
|
|||||||
}
|
}
|
||||||
return cached;
|
return cached;
|
||||||
},
|
},
|
||||||
|
_openingMasterMini: false,
|
||||||
openMasterMiniProgram: async function (path = 'pages/master/hall') {
|
openMasterMiniProgram: async function (path = 'pages/master/hall') {
|
||||||
let cfg = await this.getServiceConfig();
|
if (this._openingMasterMini) return;
|
||||||
if (!cfg.master_appid) {
|
this._openingMasterMini = true;
|
||||||
cfg = await this.getServiceConfig(true);
|
const releaseLock = () => {
|
||||||
}
|
setTimeout(() => { this._openingMasterMini = false; }, 600);
|
||||||
const targetAppId = cfg.master_appid;
|
};
|
||||||
|
const cached = this.getCachedServiceConfig();
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
if (!targetAppId) {
|
const launch = (appId) => {
|
||||||
uni.showModal({
|
if (!appId) {
|
||||||
title: '优匠优服师傅端',
|
releaseLock();
|
||||||
content: '后台暂未配置师傅端小程序 AppID,请在微信搜索打开「优匠师傅端」小程序或联系平台管理员在后台系统配置中完善。',
|
uni.showModal({
|
||||||
showCancel: false,
|
title: '优匠优服师傅端',
|
||||||
confirmText: '知道了',
|
content: '后台暂未配置师傅端小程序 AppID,请在微信搜索打开「优匠优服师傅端」小程序或联系平台管理员在后台系统配置中完善。',
|
||||||
confirmColor: '#F0710D'
|
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('[openMasterMiniProgram] navigateToMiniProgram fail:', err);
|
||||||
|
uni.showToast({ title: '打开师傅端小程序失败,请稍后重试', icon: 'none' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
if (cached.master_appid) {
|
||||||
|
launch(cached.master_appid);
|
||||||
|
if (!cached.updated_at || Date.now() - cached.updated_at >= SERVICE_CONFIG_CACHE_TTL) {
|
||||||
|
this.getServiceConfig(true).catch(() => {});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uni.navigateToMiniProgram({
|
try {
|
||||||
appId: targetAppId,
|
const cfg = await this.getServiceConfig(true);
|
||||||
path: path,
|
launch(cfg.master_appid);
|
||||||
fail: (err) => {
|
} catch (e) {
|
||||||
if (err && err.errMsg && err.errMsg.indexOf('cancel') !== -1) return;
|
releaseLock();
|
||||||
uni.showToast({ title: '打开师傅端小程序失败,请稍后重试', icon: 'none' });
|
uni.showToast({ title: '获取师傅端配置失败,请稍后重试', icon: 'none' });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
// #endif
|
// #endif
|
||||||
// #ifndef MP-WEIXIN
|
// #ifndef MP-WEIXIN
|
||||||
|
releaseLock();
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '前往优匠优服师傅端',
|
title: '前往优匠优服师傅端',
|
||||||
content: '请在微信中搜索「优匠优服师傅端」小程序进行师傅实名入驻与接单。',
|
content: '请在微信中搜索「优匠优服师傅端」小程序进行师傅实名入驻与接单。',
|
||||||
|
|||||||
115
yjyf-app/utils/login-navigation.mjs
普通文件
115
yjyf-app/utils/login-navigation.mjs
普通文件
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
* 登录跳转与回返路由决策助手
|
||||||
|
* 区分“保留原页面栈直接返回”与“重定向刷新/切换目标页”两种模式。
|
||||||
|
*/
|
||||||
|
|
||||||
|
const PRESERVE_STATE_ROUTES = new Set([
|
||||||
|
'pages/order/quick'
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规范化页面路由(去除前导斜杠与查询参数)
|
||||||
|
* @param {string} routeOrUrl
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function normalizeRoutePath(routeOrUrl) {
|
||||||
|
const raw = String(routeOrUrl || '').trim();
|
||||||
|
if (!raw) return '';
|
||||||
|
const pathOnly = raw.split('?')[0].split('#')[0];
|
||||||
|
return pathOnly.replace(/^\/+/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前路由在触发登录后是否应直接 navigateBack 保留原页面实例状态
|
||||||
|
* @param {string} route
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export function shouldPreservePageOnLogin(route) {
|
||||||
|
return PRESERVE_STATE_ROUTES.has(normalizeRoutePath(route));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建登录页跳转 URL
|
||||||
|
* @param {string} targetRedirect
|
||||||
|
* @param {{ back?: boolean }} [options]
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function buildLoginUrl(targetRedirect = '', options = {}) {
|
||||||
|
const params = [];
|
||||||
|
if (targetRedirect) {
|
||||||
|
params.push(`redirect=${encodeURIComponent(targetRedirect)}`);
|
||||||
|
}
|
||||||
|
if (options && options.back) {
|
||||||
|
params.push('back=1');
|
||||||
|
}
|
||||||
|
return params.length ? `/pages/login/login?${params.join('&')}` : '/pages/login/login';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析登录页 onLoad 参数
|
||||||
|
* @param {Record<string, any>} options
|
||||||
|
* @returns {{ redirectUrl: string, preferBack: boolean }}
|
||||||
|
*/
|
||||||
|
export function parseLoginParams(options = {}) {
|
||||||
|
let redirectUrl = '';
|
||||||
|
if (options && options.redirect) {
|
||||||
|
let decoded = String(options.redirect);
|
||||||
|
try {
|
||||||
|
decoded = decodeURIComponent(decoded);
|
||||||
|
} catch (e) {}
|
||||||
|
if (decoded.startsWith('%2F') || decoded.startsWith('%2f')) {
|
||||||
|
try {
|
||||||
|
decoded = decodeURIComponent(decoded);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
redirectUrl = decoded;
|
||||||
|
}
|
||||||
|
const preferBack = String((options && options.back) || '') === '1';
|
||||||
|
return { redirectUrl, preferBack };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 决策登录完成后的页面流转动作
|
||||||
|
* @param {{ redirectUrl?: string, preferBack?: boolean, pages?: Array<{ route?: string }> }} ctx
|
||||||
|
* @returns {{ type: 'navigateBack' | 'redirectTo' | 'reLaunch', url?: string, fallbackType?: 'reLaunch', fallbackUrl?: string }}
|
||||||
|
*/
|
||||||
|
export function resolvePostLoginAction(ctx = {}) {
|
||||||
|
const redirectUrl = String(ctx.redirectUrl || '').trim();
|
||||||
|
const preferBack = !!ctx.preferBack;
|
||||||
|
const pages = Array.isArray(ctx.pages) ? ctx.pages : [];
|
||||||
|
|
||||||
|
if (preferBack && pages.length > 1) {
|
||||||
|
const prevPage = pages[pages.length - 2];
|
||||||
|
const prevRoute = normalizeRoutePath(prevPage && prevPage.route);
|
||||||
|
const targetRoute = normalizeRoutePath(redirectUrl);
|
||||||
|
if (!targetRoute || !prevRoute || prevRoute === targetRoute) {
|
||||||
|
return {
|
||||||
|
type: 'navigateBack',
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: redirectUrl || '/pages/index/index'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (redirectUrl) {
|
||||||
|
if (redirectUrl.startsWith('/pages/index/') || redirectUrl.startsWith('/pages/mine/')) {
|
||||||
|
return { type: 'reLaunch', url: redirectUrl };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: 'redirectTo',
|
||||||
|
url: redirectUrl,
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: redirectUrl
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pages.length > 1) {
|
||||||
|
return {
|
||||||
|
type: 'navigateBack',
|
||||||
|
fallbackType: 'reLaunch',
|
||||||
|
fallbackUrl: '/pages/index/index'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { type: 'reLaunch', url: '/pages/index/index' };
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
* - 内置 POST 请求 500ms 防并发快速连击锁
|
* - 内置 POST 请求 500ms 防并发快速连击锁
|
||||||
*/
|
*/
|
||||||
import config from '@/config/config.js';
|
import config from '@/config/config.js';
|
||||||
|
import { buildLoginUrl, shouldPreservePageOnLogin } from '@/utils/login-navigation.mjs';
|
||||||
|
|
||||||
export const BASE_URL = (config.baseUrl || config.dev).replace(/\/+$/, '') + '/api';
|
export const BASE_URL = (config.baseUrl || config.dev).replace(/\/+$/, '') + '/api';
|
||||||
|
|
||||||
@@ -51,19 +52,21 @@ export function isLogin() {
|
|||||||
|
|
||||||
let loginRedirectLock = false;
|
let loginRedirectLock = false;
|
||||||
|
|
||||||
export function toLogin(redirect) {
|
export function toLogin(redirect, options = {}) {
|
||||||
clearAuth();
|
clearAuth();
|
||||||
if (loginRedirectLock) return;
|
if (loginRedirectLock) return;
|
||||||
loginRedirectLock = true;
|
loginRedirectLock = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
loginRedirectLock = false;
|
loginRedirectLock = false;
|
||||||
}, 800);
|
}, 800);
|
||||||
let targetRedirect = redirect || '';
|
let targetRedirect = typeof redirect === 'string' ? redirect : '';
|
||||||
if (!targetRedirect) {
|
let currentRoute = '';
|
||||||
try {
|
try {
|
||||||
const pages = getCurrentPages() || [];
|
const pages = getCurrentPages() || [];
|
||||||
const cur = pages[pages.length - 1];
|
const cur = pages[pages.length - 1];
|
||||||
if (cur && cur.route && cur.route !== 'pages/login/login') {
|
if (cur && cur.route && cur.route !== 'pages/login/login') {
|
||||||
|
currentRoute = cur.route;
|
||||||
|
if (!targetRedirect) {
|
||||||
const opts = cur.options || {};
|
const opts = cur.options || {};
|
||||||
const qs = Object.keys(opts)
|
const qs = Object.keys(opts)
|
||||||
.filter((k) => opts[k] !== undefined && opts[k] !== '')
|
.filter((k) => opts[k] !== undefined && opts[k] !== '')
|
||||||
@@ -71,11 +74,13 @@ export function toLogin(redirect) {
|
|||||||
.join('&');
|
.join('&');
|
||||||
targetRedirect = '/' + cur.route + (qs ? `?${qs}` : '');
|
targetRedirect = '/' + cur.route + (qs ? `?${qs}` : '');
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
}
|
||||||
}
|
} catch (e) {}
|
||||||
const url = targetRedirect
|
const shouldBack = Boolean(
|
||||||
? `/pages/login/login?redirect=${encodeURIComponent(targetRedirect)}`
|
(options && options.back) ||
|
||||||
: '/pages/login/login';
|
(typeof redirect !== 'string' && shouldPreservePageOnLogin(currentRoute))
|
||||||
|
);
|
||||||
|
const url = buildLoginUrl(targetRedirect, { back: shouldBack });
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url,
|
url,
|
||||||
fail: () => {
|
fail: () => {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function() {
|
onLaunch: function() {
|
||||||
|
api.getServiceConfig(true).catch(() => {});
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
if (typeof wx !== 'undefined' && typeof wx.onNeedPrivacyAuthorization === 'function') {
|
if (typeof wx !== 'undefined' && typeof wx.onNeedPrivacyAuthorization === 'function') {
|
||||||
wx.onNeedPrivacyAuthorization((resolve) => {
|
wx.onNeedPrivacyAuthorization((resolve) => {
|
||||||
|
|||||||
@@ -895,8 +895,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function exitToUser() {
|
async function exitToUser() {
|
||||||
api.openUserMiniProgram('pages/index/index');
|
if (switchingRole.value) return;
|
||||||
|
switchingRole.value = true;
|
||||||
|
try {
|
||||||
|
await api.openUserMiniProgram('pages/index/index');
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => { switchingRole.value = false; }, 600);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -261,7 +261,7 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 6. 跨小程序跳转:前往用户端下单 -->
|
<!-- 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">
|
<view class="src-left">
|
||||||
<image class="src-ico" src="/static/icons/master/role-switch-orange.svg" mode="aspectFit" />
|
<image class="src-ico" src="/static/icons/master/role-switch-orange.svg" mode="aspectFit" />
|
||||||
<view class="src-text">
|
<view class="src-text">
|
||||||
@@ -605,8 +605,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function backToUser() {
|
async function backToUser() {
|
||||||
api.openUserMiniProgram('pages/index/index');
|
if (switchingRole.value) return;
|
||||||
|
switchingRole.value = true;
|
||||||
|
try {
|
||||||
|
await api.openUserMiniProgram('pages/index/index');
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => { switchingRole.value = false; }, 600);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
@@ -1280,6 +1286,10 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
box-shadow: $yjyf-shadow-card;
|
box-shadow: $yjyf-shadow-card;
|
||||||
|
|
||||||
|
&.disabled {
|
||||||
|
opacity: 0.65;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.src-left {
|
.src-left {
|
||||||
|
|||||||
@@ -560,6 +560,15 @@
|
|||||||
) {
|
) {
|
||||||
uni.switchTab({ url: redirectUrl.split('?')[0] });
|
uni.switchTab({ url: redirectUrl.split('?')[0] });
|
||||||
} else {
|
} 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({
|
uni.redirectTo({
|
||||||
url: redirectUrl,
|
url: redirectUrl,
|
||||||
fail: () => uni.switchTab({ url: '/pages/master/hall' })
|
fail: () => uni.switchTab({ url: '/pages/master/hall' })
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<!-- 未登录引导条 -->
|
<!-- 未登录引导条 -->
|
||||||
<view class="login-tip-bar" v-if="!loggedIn">
|
<view class="login-tip-bar" v-if="!loggedIn">
|
||||||
<text class="login-tip-txt">请先登录账号,再上传证件并提交实名入驻</text>
|
<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>
|
<text class="login-tip-btn-txt">去登录</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -245,6 +245,9 @@
|
|||||||
<view class="profile-save clickable-hover" :class="{ disabled: profileSaving || profileUploading }" @tap="saveProfile">
|
<view class="profile-save clickable-hover" :class="{ disabled: profileSaving || profileUploading }" @tap="saveProfile">
|
||||||
<text>{{ profileSaving ? '保存中...' : '保存资料' }}</text>
|
<text>{{ profileSaving ? '保存中...' : '保存资料' }}</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="profile-hall-btn clickable-hover" @tap="goHall">
|
||||||
|
<text class="profile-hall-txt">进入接单大厅</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -425,6 +428,14 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function goLogin() {
|
||||||
|
toLogin('/pages/master/apply');
|
||||||
|
}
|
||||||
|
|
||||||
|
function goHall() {
|
||||||
|
uni.switchTab({ url: '/pages/master/hall' });
|
||||||
|
}
|
||||||
|
|
||||||
function goWorkbench() {
|
function goWorkbench() {
|
||||||
uni.switchTab({ url: '/pages/master/workbench' });
|
uni.switchTab({ url: '/pages/master/workbench' });
|
||||||
}
|
}
|
||||||
@@ -443,6 +454,7 @@
|
|||||||
const uploadingSide = ref('');
|
const uploadingSide = ref('');
|
||||||
const isSelectingImage = ref(false);
|
const isSelectingImage = ref(false);
|
||||||
const hasInitialLoaded = ref(false);
|
const hasInitialLoaded = ref(false);
|
||||||
|
const loadedWhileLoggedIn = ref(false);
|
||||||
const isExpired = ref(false);
|
const isExpired = ref(false);
|
||||||
const validDate = ref('');
|
const validDate = ref('');
|
||||||
|
|
||||||
@@ -544,6 +556,8 @@
|
|||||||
async function load() {
|
async function load() {
|
||||||
loggedIn.value = isLogin();
|
loggedIn.value = isLogin();
|
||||||
if (!loggedIn.value) {
|
if (!loggedIn.value) {
|
||||||
|
info.value = null;
|
||||||
|
loadedWhileLoggedIn.value = false;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -578,6 +592,7 @@
|
|||||||
if (u && !form.mobile) form.mobile = u.mobile || '';
|
if (u && !form.mobile) form.mobile = u.mobile || '';
|
||||||
}
|
}
|
||||||
hasInitialLoaded.value = true;
|
hasInitialLoaded.value = true;
|
||||||
|
loadedWhileLoggedIn.value = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@@ -677,7 +692,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loggedIn.value = isLogin();
|
loggedIn.value = isLogin();
|
||||||
if (!hasInitialLoaded.value) {
|
if (!hasInitialLoaded.value || (loggedIn.value && !loadedWhileLoggedIn.value) || (!loggedIn.value && loadedWhileLoggedIn.value)) {
|
||||||
await load();
|
await load();
|
||||||
}
|
}
|
||||||
if (!cats.value.length) {
|
if (!cats.value.length) {
|
||||||
@@ -725,6 +740,8 @@
|
|||||||
.identity-cert-caption { font-size: $yjyf-font-micro; color: $yjyf-text-inverse; font-weight: 500; }
|
.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 { 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-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 {
|
.page {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
background: $yjyf-bg-page;
|
background: $yjyf-bg-page;
|
||||||
|
|||||||
@@ -4,6 +4,26 @@
|
|||||||
import { get, post, uploadFile } from './request';
|
import { get, post, uploadFile } from './request';
|
||||||
import config from '@/config/config.js';
|
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 {
|
export default {
|
||||||
/* ---------- 公共 / 上传 / 字典 ---------- */
|
/* ---------- 公共 / 上传 / 字典 ---------- */
|
||||||
upload: (filePath, category = 'other') => uploadFile(filePath, category),
|
upload: (filePath, category = 'other') => uploadFile(filePath, category),
|
||||||
@@ -85,6 +105,7 @@ export default {
|
|||||||
service_corp_id: String(cached.service_corp_id || '').trim(),
|
service_corp_id: String(cached.service_corp_id || '').trim(),
|
||||||
service_kf_url: String(cached.service_kf_url || '').trim(),
|
service_kf_url: String(cached.service_kf_url || '').trim(),
|
||||||
user_appid: String(cached.user_appid || '').trim(),
|
user_appid: String(cached.user_appid || '').trim(),
|
||||||
|
updated_at: Number(cached.updated_at || 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@@ -94,11 +115,13 @@ export default {
|
|||||||
service_corp_id: '',
|
service_corp_id: '',
|
||||||
service_kf_url: '',
|
service_kf_url: '',
|
||||||
user_appid: '',
|
user_appid: '',
|
||||||
|
updated_at: 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getServiceConfig: async function (force = false) {
|
getServiceConfig: async function (force = false) {
|
||||||
const cached = this.getCachedServiceConfig();
|
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;
|
return cached;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -110,6 +133,7 @@ export default {
|
|||||||
service_corp_id: String(res.service_corp_id || '').trim(),
|
service_corp_id: String(res.service_corp_id || '').trim(),
|
||||||
service_kf_url: String(res.service_kf_url || '').trim(),
|
service_kf_url: String(res.service_kf_url || '').trim(),
|
||||||
user_appid: String(res.user_appid || '').trim(),
|
user_appid: String(res.user_appid || '').trim(),
|
||||||
|
updated_at: Date.now(),
|
||||||
};
|
};
|
||||||
uni.setStorageSync('yjyf_master_service_config', cfg);
|
uni.setStorageSync('yjyf_master_service_config', cfg);
|
||||||
if (cfg.service_phone) {
|
if (cfg.service_phone) {
|
||||||
@@ -117,35 +141,69 @@ export default {
|
|||||||
}
|
}
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
console.warn('获取客服配置失败', e);
|
||||||
|
}
|
||||||
return cached;
|
return cached;
|
||||||
},
|
},
|
||||||
|
_openingUserMini: false,
|
||||||
openUserMiniProgram: async function (path = 'pages/index/index') {
|
openUserMiniProgram: async function (path = 'pages/index/index') {
|
||||||
let cfg = await this.getServiceConfig();
|
if (this._openingUserMini) return;
|
||||||
if (!cfg.user_appid) {
|
this._openingUserMini = true;
|
||||||
cfg = await this.getServiceConfig(true);
|
const releaseLock = () => {
|
||||||
}
|
setTimeout(() => { this._openingUserMini = false; }, 600);
|
||||||
const targetAppId = cfg.user_appid;
|
};
|
||||||
|
const cached = this.getCachedServiceConfig();
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
if (!targetAppId) {
|
const launch = (appId) => {
|
||||||
uni.showToast({ title: '后台暂未配置用户端小程序 AppID', icon: 'none' });
|
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;
|
return;
|
||||||
}
|
}
|
||||||
uni.navigateToMiniProgram({
|
try {
|
||||||
appId: targetAppId,
|
const cfg = await this.getServiceConfig(true);
|
||||||
path: path,
|
launch(cfg.user_appid);
|
||||||
fail: (err) => {
|
} catch (e) {
|
||||||
if (err && err.errMsg && err.errMsg.indexOf('cancel') !== -1) return;
|
releaseLock();
|
||||||
uni.showToast({ title: '打开用户端小程序失败,请稍后重试', icon: 'none' });
|
uni.showToast({ title: '获取用户端配置失败,请稍后重试', icon: 'none' });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
// #endif
|
// #endif
|
||||||
// #ifndef MP-WEIXIN
|
// #ifndef MP-WEIXIN
|
||||||
|
releaseLock();
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '前往优匠优服用户端',
|
title: '前往优匠优服用户端',
|
||||||
content: '请在微信中搜索「优匠优服」小程序发布安装维修需求。',
|
content: '请在微信中搜索「优匠优服」小程序发布安装维修需求。',
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
confirmText: '知道了'
|
confirmText: '知道了',
|
||||||
|
confirmColor: '#F0710D'
|
||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export function toLogin(redirect) {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
loginRedirectLock = false;
|
loginRedirectLock = false;
|
||||||
}, 800);
|
}, 800);
|
||||||
let targetRedirect = redirect || '';
|
let targetRedirect = typeof redirect === 'string' ? redirect : '';
|
||||||
if (!targetRedirect) {
|
if (!targetRedirect) {
|
||||||
try {
|
try {
|
||||||
const pages = getCurrentPages() || [];
|
const pages = getCurrentPages() || [];
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户