文件
yjyf/yjyf-app/components/user/UserMineView.vue
YuanWen cd0da0324b feat: 新增用户和师傅消息中心及订单页重构
- 新增用户消息中心组件 UserMessageView
- 新增师傅消息中心组件 MasterMessageView
- 新增用户订单列表组件 UserOrdersView
- 重构订单列表页,复用独立组件
- 新增系统工具 getWindowInfoSafe 兼容多端系统信息获取
- 重构 TabBar 组件,支持单母页模式和事件回调
- 优化消息跳转逻辑,支持角色自适应 Tab 切换
2026-11-05 16:52:12 +08:00

821 行
21 KiB
Vue

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

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

<template>
<view class="user-mine-view">
<!-- 头部个人名片与资产核心区 (Zone 1: 一体化沉浸渐变背景) -->
<view class="profile-hero">
<view class="hero-bg-deco deco-lg"></view>
<view class="hero-bg-deco deco-sm"></view>
<!-- 沉浸式透明导航栏(单一大背景贯穿,彻底消除分层断层) -->
<YjyfNavBar theme="transparent" title="个人中心" :fixed="false" />
<view class="hero-body">
<!-- 用户基本信息 -->
<view class="user-card">
<view class="avatar-wrap">
<image v-if="user && user.avatar" class="avatar-img" :src="user.avatar" mode="aspectFill" />
<image v-else class="avatar-ph-img" src="/static/icons/user-avatar.svg" mode="aspectFit" />
</view>
<view class="user-info">
<view class="name-line">
<text class="user-name">{{ user ? user.nickname : '未登录' }}</text>
<view class="role-badge" :class="{ 'is-pro': isMasterOrMerchant }">
<text class="role-badge-txt">{{ roleText }}</text>
</view>
</view>
<text class="user-mobile" v-if="mobileText">{{ mobileText }}</text>
<text class="user-subtag" v-if="master && master.score">服务评分 {{ master.score }} 分</text>
</view>
</view>
<!-- 核心资产卡片(仅聚焦余额与优惠券,无冗余项) -->
<view class="assets-card">
<view class="asset-item clickable-hover" @tap="showBalanceTip">
<view class="asset-val-box">
<text class="asset-symbol">¥</text>
<text class="asset-number">{{ user ? Number(user.balance).toFixed(2) : '0.00' }}</text>
</view>
<text class="asset-title">账户余额</text>
</view>
<view class="asset-line"></view>
<view class="asset-item clickable-hover" @tap="go('/pages/coupon/coupon')">
<view class="asset-val-box">
<text class="asset-number">{{ coupon }}</text>
<text class="asset-unit">张</text>
</view>
<text class="asset-title">优惠券</text>
</view>
</view>
</view>
</view>
<!-- 页面内容主体区 (Zone 2 - Zone 5) -->
<view class="content-body">
<!-- 身份工作台专区:针对已认证或审核中用户 (Zone 2) -->
<view class="role-workbench-section" v-if="hasRoleStatus">
<!-- 师傅身份卡片 -->
<view class="workbench-card master-card" v-if="master">
<view class="wb-left">
<image class="wb-icon" src="/static/icons/join-master.svg" mode="aspectFit" />
<view class="wb-texts">
<text class="wb-title">{{ masterCard.title }}</text>
<text class="wb-desc">{{ masterCard.desc }}</text>
</view>
</view>
<view class="wb-btn clickable-hover" @tap="masterCard.action">
{{ masterCard.btn }}
</view>
</view>
<!-- 商家身份卡片 -->
<view class="workbench-card merchant-card" v-if="merchant">
<view class="wb-left">
<image class="wb-icon" src="/static/icons/join-merchant.svg" mode="aspectFit" />
<view class="wb-texts">
<text class="wb-title">{{ merchantCard.title }}</text>
<text class="wb-desc">{{ merchantCard.desc }}</text>
</view>
</view>
<view class="wb-btn clickable-hover" @tap="merchantCard.action">
{{ merchantCard.btn }}
</view>
</view>
</view>
<!-- 常用基础服务 (Zone 3) -->
<view class="card-panel">
<view class="panel-header">
<text class="panel-title">常用服务</text>
</view>
<view class="menu-group">
<view class="menu-item clickable-hover" @tap="go('/pages/address/list')">
<view class="menu-item-l">
<image class="menu-ico" src="/static/icons/menu-address.svg" mode="aspectFit" />
<text class="menu-txt">服务地址管理</text>
</view>
<view class="menu-item-r">
<image class="arrow-ico" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
</view>
<view class="menu-item clickable-hover" @tap="go('/pages/coupon/coupon')">
<view class="menu-item-l">
<image class="menu-ico" src="/static/icons/menu-coupon.svg" mode="aspectFit" />
<text class="menu-txt">领券中心</text>
</view>
<view class="menu-item-r">
<text class="menu-extra" v-if="coupon > 0">{{ coupon }} 张可用</text>
<image class="arrow-ico" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
</view>
<!-- #ifdef MP-WEIXIN -->
<button class="menu-item menu-btn clickable-hover" open-type="contact">
<view class="menu-item-l">
<image class="menu-ico" src="/static/icons/menu-service.svg" mode="aspectFit" />
<text class="menu-txt">在线客服</text>
</view>
<view class="menu-item-r">
<text class="menu-extra">微信官方专属客服</text>
<image class="arrow-ico" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
</button>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<view class="menu-item clickable-hover" @tap="callService">
<view class="menu-item-l">
<image class="menu-ico" src="/static/icons/menu-service.svg" mode="aspectFit" />
<text class="menu-txt">联系官方客服</text>
</view>
<view class="menu-item-r">
<text class="menu-extra">400-000-0000</text>
<image class="arrow-ico" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
</view>
<!-- #endif -->
<view class="menu-item clickable-hover" @tap="showPlatformAssure">
<view class="menu-item-l">
<image class="menu-ico" src="/static/icons/menu-about.svg" mode="aspectFit" />
<text class="menu-txt">平台服务保障</text>
</view>
<view class="menu-item-r">
<text class="menu-extra">实名认证·先行赔付</text>
<image class="arrow-ico" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
</view>
</view>
</view>
<!-- 合作与入驻通道(Zone 4:仅对未全部认证的普通用户开放,轻量化双列排版) -->
<view class="card-panel partner-panel" v-if="showPartnerEntry">
<view class="panel-header">
<text class="panel-title">入驻与合作</text>
</view>
<view class="partner-grid">
<view class="partner-card clickable-hover" v-if="!master" @tap="masterCard.action">
<view class="partner-head">
<image class="partner-icon" src="/static/icons/join-master.svg" mode="aspectFit" />
<text class="partner-tag tag-master">成为师傅</text>
</view>
<text class="partner-main-title">师傅招募</text>
<text class="partner-brief">技能认证,接单赚收入</text>
</view>
<view class="partner-card clickable-hover" v-if="!merchant" @tap="merchantCard.action">
<view class="partner-head">
<image class="partner-icon" src="/static/icons/join-merchant.svg" mode="aspectFit" />
<text class="partner-tag tag-merchant">企业合作</text>
</view>
<text class="partner-main-title">商家入驻</text>
<text class="partner-brief">批量下单与对账开票</text>
</view>
</view>
</view>
<!-- 账号安全操作 (Zone 5) -->
<view class="logout-action clickable-hover" @tap="logout">
<text class="logout-txt">退出登录</text>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
import api from '@/utils/api.js';
import { isLogin, toLogin, setUser, clearAuth } from '@/utils/request.js';
import { getRole, setRole } from '@/utils/role.js';
const user = ref(null);
const master = ref(null);
const merchant = ref(null);
const coupon = ref(0);
const currentRole = ref('user');
const mobileText = computed(() => {
if (!user.value || !user.value.mobile) return '';
const m = String(user.value.mobile);
if (m.length >= 11) {
return m.slice(0, 3) + '****' + m.slice(7);
}
return m;
});
const isMasterOrMerchant = computed(() => {
return (master.value && master.value.verify_status === 'pass') ||
(merchant.value && merchant.value.verify_status === 'pass');
});
const hasRoleStatus = computed(() => {
return !!(master.value || merchant.value);
});
const showPartnerEntry = computed(() => {
return !master.value || !merchant.value;
});
const roleText = computed(() => {
const curRole = currentRole.value;
if (curRole === 'merchant' && merchant.value && merchant.value.verify_status === 'pass') {
return merchant.value.is_owner === false ? '关联商家' : '认证商家';
}
if (curRole === 'master' && master.value && master.value.verify_status === 'pass') {
return '认证师傅';
}
if (merchant.value && merchant.value.verify_status === 'pass') {
return merchant.value.is_owner === false ? '关联商家' : '认证商家';
}
if (master.value && master.value.verify_status === 'pass') return '认证师傅';
if (merchant.value && merchant.value.verify_status === 'pending') return '商家审核中';
if (master.value && master.value.verify_status === 'pending') return '师傅审核中';
return '个人用户';
});
const masterCard = computed(() => {
const m = master.value;
if (!m) {
return { title: '成为优匠优服师傅', desc: '实名认证 + 技能认证,接单赚收入', btn: '立即入驻', action: () => go('/pages/master/apply') };
}
if (m.verify_status === 'pending') {
return { title: '师傅资质审核中', desc: '平台将在 1-2 个工作日内完成审核', btn: '查看进度', action: () => go('/pages/master/apply') };
}
if (m.verify_status === 'reject') {
return { title: '师傅资质未通过', desc: m.audit_msg || '请补充资料后重新提交', btn: '重新提交', action: () => go('/pages/master/apply') };
}
return { title: '师傅工作台', desc: '已通过认证,进入工作台开始接单', btn: '切换师傅端', action: switchToMaster };
});
const merchantCard = computed(() => {
const m = merchant.value;
if (!m) {
return { title: '成为优匠优服商家', desc: '企业认证,支持批量下单 / 对账 / 开票', btn: '商家入驻', action: () => go('/pages/merchant/apply') };
}
if (m.verify_status === 'pending') {
return { title: '商家资质审核中', desc: '平台将在 1-2 个工作日内完成审核', btn: '查看进度', action: () => go('/pages/merchant/apply') };
}
if (m.verify_status === 'reject') {
return { title: '商家资质未通过', desc: m.audit_msg || '请补充资料后重新提交', btn: '重新提交', action: () => go('/pages/merchant/apply') };
}
if (m.is_owner === false) {
return { title: m.name || '关联企业账号', desc: '订单 / 账单 / 开票数据与企业主账号同步', btn: '切换商家端', action: switchToMerchant };
}
return { title: m.name || '商家企业工作台', desc: '进入商家工作台:批量下单 / 账单 / 开票', btn: '切换商家端', action: switchToMerchant };
});
function go(url) {
uni.navigateTo({ url });
}
function showBalanceTip() {
const bal = user.value ? Number(user.value.balance).toFixed(2) : '0.00';
uni.showModal({
title: '账户余额',
content: `当前可用余额:¥${bal}`,
showCancel: false,
confirmColor: '#F0710D'
});
}
function showPlatformAssure() {
uni.showModal({
title: '优匠优服 · 服务保障',
content: '1. 实名认证:所有上门师傅均通过公安实名与技能审核\n2. 价格公道:标准服务定价,杜绝隐形加价与乱收费\n3. 售后保障:平台客服全程跟踪,质保期内免费返工',
showCancel: false,
confirmText: '我知道了',
confirmColor: '#F0710D'
});
}
function callService() {
uni.makePhoneCall({
phoneNumber: '4000000000',
fail: () => {}
});
}
async function load() {
currentRole.value = getRole();
if (!isLogin()) {
toLogin();
return;
}
try {
const res = await api.profile();
user.value = res;
master.value = res.master;
merchant.value = res.merchant;
coupon.value = Number(res.coupon_count) || 0;
setUser(res);
} catch (e) {
console.error('加载个人信息失败', e);
}
}
async function switchToMerchant() {
try {
const res = await api.switchRole({ role: 'merchant' });
setRole('merchant');
currentRole.value = 'merchant';
uni.showToast({ title: '已切换为商家身份' });
setTimeout(() => uni.reLaunch({ url: res.redirect }), 500);
} catch (e) {}
}
async function switchToMaster() {
try {
const res = await api.switchRole({ role: 'master' });
setRole('master');
currentRole.value = 'master';
uni.showToast({ title: '已切换为师傅身份' });
setTimeout(() => uni.reLaunch({ url: res.redirect }), 500);
} catch (e) {}
}
function logout() {
uni.showModal({
title: '提示',
content: '确认退出当前登录账号?',
confirmColor: '#F0710D',
success: (r) => {
if (!r.confirm) return;
clearAuth();
uni.reLaunch({ url: '/pages/login/login' });
}
});
}
onMounted(() => {
load();
});
defineExpose({
load
});
</script>
<style scoped>
.user-mine-view {
min-height: 100vh;
background: #F5F6F8;
padding-bottom: calc(150rpx + env(safe-area-inset-bottom));
box-sizing: border-box;
}
/* ---------- 头部个人主页英雄区 (Zone 1: 一体化沉浸) ---------- */
.profile-hero {
position: relative;
overflow: hidden;
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
padding-bottom: 36rpx;
border-bottom-left-radius: 36rpx;
border-bottom-right-radius: 36rpx;
}
.hero-body {
position: relative;
z-index: 2;
padding: 10rpx 32rpx 0;
}
.hero-bg-deco {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
pointer-events: none;
}
.hero-bg-deco.deco-lg {
width: 360rpx;
height: 360rpx;
right: -80rpx;
top: -100rpx;
}
.hero-bg-deco.deco-sm {
width: 180rpx;
height: 180rpx;
left: -40rpx;
bottom: -60rpx;
}
.user-card {
position: relative;
display: flex;
align-items: center;
z-index: 2;
}
.avatar-wrap {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background: #FFFFFF;
box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.12);
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
border: 4rpx solid rgba(255, 255, 255, 0.85);
}
.avatar-img {
width: 100%;
height: 100%;
}
.avatar-ph-img {
width: 100%;
height: 100%;
}
.user-info {
flex: 1;
min-width: 0;
margin-left: 24rpx;
display: flex;
flex-direction: column;
}
.name-line {
display: flex;
align-items: center;
}
.user-name {
font-size: 36rpx;
font-weight: 700;
color: #FFFFFF;
line-height: 1.25;
max-width: 320rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.role-badge {
margin-left: 14rpx;
padding: 4rpx 16rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.22);
backdrop-filter: blur(4px);
border: 1rpx solid rgba(255, 255, 255, 0.35);
display: inline-flex;
align-items: center;
}
.role-badge.is-pro {
background: #FFF4E5;
border-color: #FFA940;
}
.role-badge-txt {
font-size: 20rpx;
font-weight: 600;
color: #FFFFFF;
}
.role-badge.is-pro .role-badge-txt {
color: #D45B00;
}
.user-mobile {
margin-top: 8rpx;
font-size: 24rpx;
color: rgba(255, 255, 255, 0.88);
}
.user-subtag {
margin-top: 6rpx;
font-size: 22rpx;
color: #FFF2D6;
font-weight: 500;
}
/* ---------- 资产双卡片展示行 ---------- */
.assets-card {
position: relative;
z-index: 2;
display: flex;
align-items: center;
margin-top: 28rpx;
padding: 24rpx 20rpx 8rpx;
border-top: 1rpx solid rgba(255, 255, 255, 0.22);
}
.asset-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.asset-val-box {
display: flex;
align-items: baseline;
}
.asset-symbol {
font-size: 24rpx;
font-weight: 600;
color: #FFFFFF;
margin-right: 4rpx;
}
.asset-unit {
margin-left: 4rpx;
font-size: 22rpx;
font-weight: normal;
color: rgba(255, 255, 255, 0.9);
}
.asset-number {
font-size: 40rpx;
font-weight: 700;
color: #FFFFFF;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.asset-title {
margin-top: 6rpx;
font-size: 22rpx;
color: rgba(255, 255, 255, 0.9);
}
.asset-line {
width: 1rpx;
height: 48rpx;
background: rgba(255, 255, 255, 0.28);
}
/* ---------- 主体内容区 ---------- */
.content-body {
padding: 24rpx 28rpx 0;
}
/* ---------- 身份工作台专区 (Zone 2) ---------- */
.role-workbench-section {
display: flex;
flex-direction: column;
gap: 20rpx;
margin-bottom: 24rpx;
}
.workbench-card {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 24rpx;
border-radius: 20rpx;
background: #FFFFFF;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
border-left: 8rpx solid #F0710D;
}
.wb-left {
display: flex;
align-items: center;
flex: 1;
min-width: 0;
margin-right: 16rpx;
}
.wb-icon {
width: 48rpx;
height: 48rpx;
flex-shrink: 0;
margin-right: 20rpx;
}
.wb-texts {
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
}
.wb-title {
font-size: 28rpx;
font-weight: 700;
color: #1D2129;
}
.wb-desc {
margin-top: 4rpx;
font-size: 22rpx;
color: #86909C;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.wb-btn {
flex-shrink: 0;
padding: 0 24rpx;
height: 56rpx;
line-height: 56rpx;
border-radius: 28rpx;
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
color: #FFFFFF;
font-size: 24rpx;
font-weight: 600;
box-shadow: 0 4rpx 12rpx rgba(240, 113, 13, 0.25);
}
/* ---------- 通用卡片容器 ---------- */
.card-panel {
background: #FFFFFF;
border-radius: 24rpx;
padding: 24rpx 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.035);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16rpx;
padding: 4rpx 0;
}
.panel-title {
font-size: 30rpx;
font-weight: 700;
color: #1D2129;
position: relative;
padding-left: 18rpx;
}
.panel-title::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 6rpx;
height: 24rpx;
border-radius: 3rpx;
background: #F0710D;
}
.arrow-ico {
width: 28rpx;
height: 28rpx;
opacity: 0.7;
}
/* ---------- 常用服务菜单 (Zone 3) ---------- */
.menu-group {
display: flex;
flex-direction: column;
}
.menu-item {
display: flex;
align-items: center;
justify-content: space-between;
height: 96rpx;
border-bottom: 1rpx solid #F5F6F8;
}
.menu-btn {
width: 100%;
padding: 0;
background: transparent;
line-height: normal;
border: none;
border-radius: 0;
text-align: left;
font-size: inherit;
color: inherit;
box-sizing: border-box;
}
.menu-btn::after {
border: none;
}
.menu-item:last-child {
border-bottom: none;
}
.menu-item-l {
display: flex;
align-items: center;
}
.menu-ico {
width: 40rpx;
height: 40rpx;
margin-right: 20rpx;
}
.menu-txt {
font-size: 28rpx;
color: #1D2129;
font-weight: 500;
}
.menu-item-r {
display: flex;
align-items: center;
}
.menu-extra {
font-size: 24rpx;
color: #86909C;
margin-right: 8rpx;
}
/* ---------- 师傅与商家合作专区 (Zone 4) ---------- */
.partner-panel {
padding-bottom: 24rpx;
}
.partner-grid {
display: flex;
gap: 20rpx;
margin-top: 8rpx;
}
.partner-card {
flex: 1;
min-width: 0;
padding: 22rpx 20rpx;
border-radius: 18rpx;
background: #FBFBFC;
border: 1rpx solid #F0F2F5;
display: flex;
flex-direction: column;
}
.partner-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14rpx;
}
.partner-icon {
width: 44rpx;
height: 44rpx;
}
.partner-tag {
font-size: 20rpx;
padding: 2rpx 14rpx;
border-radius: 14rpx;
font-weight: 600;
}
.tag-master {
background: #FFF2E6;
color: #E66606;
}
.tag-merchant {
background: #E8F3FF;
color: #1976D2;
}
.partner-main-title {
font-size: 28rpx;
font-weight: 700;
color: #1D2129;
}
.partner-brief {
margin-top: 6rpx;
font-size: 22rpx;
color: #86909C;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* ---------- 退出登录 (Zone 5) ---------- */
.logout-action {
margin: 32rpx 0 20rpx;
height: 88rpx;
background: #FFFFFF;
border-radius: 44rpx;
display: flex;
align-items: center;
justify-content: center;
border: 1rpx solid #E5E6EB;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.02);
}
.logout-txt {
font-size: 28rpx;
color: #86909C;
font-weight: 500;
}
/* ---------- 点击反馈与无障碍 ---------- */
.clickable-hover {
transition: opacity 0.15s ease, transform 0.15s ease;
}
.clickable-hover:active {
opacity: 0.75;
transform: scale(0.98);
}
</style>