文件
yjyf/yjyf-app/pages/index/index.vue
MiAn 14533eadb7 feat: 用户端与师傅端双小程序架构解耦,新增师傅独立认证及超时自动关单机制
1. 账号体系与数据库解耦:
   - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表;
   - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read;
   - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。

2. 服务端(Server):
   - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken);
   - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token;
   - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环;
   - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换);
   - 系统业务配置全面收敛至数据库 fa_config 及 site.php。

3. 小程序端:
   - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块;
   - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
2026-11-23 15:10:30 +08:00

201 行
7.3 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="user-container-page">
<!-- 1. 首页 (Tab 0) -->
<view class="tab-pane" v-show="activeTab === 0">
<UserHomeView ref="homeRef" @switch-tab="onTabChange" />
</view>
<!-- 2. 订单 (Tab 1) -->
<view class="tab-pane" v-if="visitedTabs[1]" v-show="activeTab === 1">
<UserOrdersView ref="ordersRef" :initial-status="initialOrderStatus" />
</view>
<!-- 3. 消息 (Tab 2) -->
<view class="tab-pane" v-if="visitedTabs[2]" v-show="activeTab === 2">
<UserMessageView ref="messageRef" role-type="user" />
</view>
<!-- 4. 我的 (Tab 3) -->
<view class="tab-pane" v-if="visitedTabs[3]" v-show="activeTab === 3">
<UserMineView ref="mineRef" @go-orders="goOrdersWithStatus" />
</view>
<!-- 全局统一底部导航 (方案 A:单母页组件化调度,0ms 极速秒切) -->
<YjyfTabBar :current="activeTab" @change="onTabChange" />
<YjyfPrivacyPopup />
<view v-if="showIdentityPicker" 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>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue';
import { onLoad, onShow, onBackPress } from '@dcloudio/uni-app';
import UserHomeView from '@/components/user/UserHomeView.vue';
import UserOrdersView from '@/components/user/UserOrdersView.vue';
import UserMessageView from '@/components/user/UserMessageView.vue';
import UserMineView from '@/components/user/UserMineView.vue';
import YjyfTabBar from '@/components/YjyfTabBar.vue';
import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue';
import { isLogin, toLogin, getUser, setUser } from '@/utils/request.js';
import api from '@/utils/api.js';
import { useShare } from '@/utils/share.js';
const showIdentityPicker = ref(false);
const identityChoice = ref('');
const selectingIdentity = ref(false);
const activeTab = ref(0);
const initialOrderStatus = ref('all');
const visitedTabs = reactive({ 0: true, 1: false, 2: false, 3: false });
let initialLoaded = false;
useShare(() => ({
title: '优匠优服 · 专业家居安装维修平台,实名师傅极速上门',
path: '/pages/index/index',
query: ''
}));
const homeRef = ref(null);
const ordersRef = ref(null);
const messageRef = ref(null);
const mineRef = ref(null);
function refreshCurrentTab() {
if (activeTab.value === 0 && homeRef.value?.load) {
homeRef.value.load();
} else if (activeTab.value === 1 && ordersRef.value?.load) {
ordersRef.value.load();
} else if (activeTab.value === 2 && messageRef.value?.load) {
messageRef.value.load();
} else if (activeTab.value === 3 && mineRef.value?.load) {
mineRef.value.load();
}
}
function onTabChange(index) {
const targetIndex = Number(index);
if (isNaN(targetIndex) || targetIndex < 0 || targetIndex > 3) return;
if (activeTab.value === targetIndex) return;
const firstVisit = !visitedTabs[targetIndex];
visitedTabs[targetIndex] = true;
activeTab.value = targetIndex;
if (!firstVisit) {
setTimeout(() => {
refreshCurrentTab();
}, 0);
}
}
function goOrdersWithStatus(statusKey = 'all') {
const targetStatus = statusKey || 'all';
if (!isLogin()) {
toLogin(`/pages/index/index?tab=1&status=${targetStatus}`);
return;
}
initialOrderStatus.value = targetStatus;
const firstVisit = !visitedTabs[1];
visitedTabs[1] = true;
activeTab.value = 1;
if (!firstVisit) {
setTimeout(() => {
if (ordersRef.value?.switchTab) {
ordersRef.value.switchTab(targetStatus);
} else if (ordersRef.value?.load) {
ordersRef.value.load();
}
}, 0);
}
}
onLoad((query) => {
const currentUser = getUser();
if (isLogin() && currentUser && currentUser.identity_selected === false) {
return;
}
if (query && query.status) {
initialOrderStatus.value = String(query.status);
}
if (query && query.tab !== undefined) {
const t = parseInt(query.tab);
if (!isNaN(t) && t >= 0 && t <= 3) {
activeTab.value = t;
visitedTabs[t] = true;
}
}
});
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);
onShow(() => {
const currentUser = getUser();
if (isLogin() && currentUser && currentUser.identity_selected === false) {
activeTab.value = 0;
showIdentityPicker.value = true;
return;
}
if (!initialLoaded) {
initialLoaded = true;
return;
}
refreshCurrentTab();
});
</script>
<style lang="scss" scoped>
@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 {
height: 100vh;
overflow: hidden;
background: #F5F6F8;
}
.tab-pane {
width: 100%;
height: calc(100vh - 112rpx - constant(safe-area-inset-bottom));
height: calc(100vh - 112rpx - env(safe-area-inset-bottom));
overflow: hidden;
}
</style>