527 lines
12 KiB
Vue
527 lines
12 KiB
Vue
<template>
|
||
<view class="page">
|
||
<view class="profile-header" :style="headPad">
|
||
<view class="profile-info">
|
||
<view class="profile-avatar">
|
||
<text class="avatar-text">{{ avatarText }}</text>
|
||
</view>
|
||
<view class="profile-detail">
|
||
<text class="profile-name">{{ user?.nickname || user?.name || '温新云用户' }}</text>
|
||
<text class="profile-id">{{ user?.account ? `账号: ${user.account}` : `ID: ${userId}` }}</text>
|
||
</view>
|
||
<view class="profile-edit" @tap="onEdit">
|
||
<FaIcon name="pen-to-square" color="#ffffff" :size="16" />
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<scroll-view class="main-scroll" scroll-y>
|
||
<view class="menu-card">
|
||
<view class="menu-row" @tap="onSubscribe">
|
||
<view class="tint-icon row-icon tint-0">
|
||
<FaIcon name="bell" color="#ffffff" :size="16" />
|
||
</view>
|
||
<view class="row-main">
|
||
<text class="row-title">订阅消息提醒</text>
|
||
<text class="row-sub">审批、日程与公告的微信通知</text>
|
||
</view>
|
||
<text class="row-value">去开启</text>
|
||
<FaIcon name="chevron-right" color="#c8cfdf" :size="12" />
|
||
</view>
|
||
</view>
|
||
|
||
<view class="menu-card">
|
||
<view class="menu-row" @tap="goChangePassword">
|
||
<view class="tint-icon row-icon tint-1">
|
||
<FaIcon name="key" color="#ffffff" :size="16" />
|
||
</view>
|
||
<view class="row-main">
|
||
<text class="row-title">修改密码</text>
|
||
<text class="row-sub">定期更换密码,保障账号安全</text>
|
||
</view>
|
||
<FaIcon name="chevron-right" color="#c8cfdf" :size="12" />
|
||
</view>
|
||
<view class="menu-row" @tap="goBindTenant">
|
||
<view class="tint-icon row-icon tint-2">
|
||
<FaIcon name="building" color="#ffffff" :size="16" />
|
||
</view>
|
||
<view class="row-main">
|
||
<text class="row-title">企业绑定</text>
|
||
<text class="row-sub">查看已绑定企业,或申请绑定其他企业</text>
|
||
</view>
|
||
<FaIcon name="chevron-right" color="#c8cfdf" :size="12" />
|
||
</view>
|
||
</view>
|
||
|
||
<view class="menu-card">
|
||
<view class="menu-row" @tap="goHelp">
|
||
<view class="tint-icon row-icon tint-3">
|
||
<FaIcon name="circle-question" color="#ffffff" :size="16" />
|
||
</view>
|
||
<view class="row-main">
|
||
<text class="row-title">帮助中心</text>
|
||
</view>
|
||
<FaIcon name="chevron-right" color="#c8cfdf" :size="12" />
|
||
</view>
|
||
<view class="menu-row" @tap="goSettings">
|
||
<view class="tint-icon row-icon tint-4">
|
||
<FaIcon name="gear" color="#ffffff" :size="16" />
|
||
</view>
|
||
<view class="row-main">
|
||
<text class="row-title">设置</text>
|
||
</view>
|
||
<FaIcon name="chevron-right" color="#c8cfdf" :size="12" />
|
||
</view>
|
||
</view>
|
||
|
||
<view class="logout" @tap="handleLogout">
|
||
<text class="logout-text">退出登录</text>
|
||
</view>
|
||
|
||
<view class="bottom-space" />
|
||
</scroll-view>
|
||
|
||
<AppTabbar current="profile" :tabs="profileTabs" />
|
||
|
||
<view v-if="editVisible" class="edit-mask" @tap="closeEdit">
|
||
<view class="edit-sheet" @tap.stop>
|
||
<view class="edit-head">
|
||
<text class="edit-title">编辑资料</text>
|
||
<text class="edit-close" @tap="closeEdit">取消</text>
|
||
</view>
|
||
<view class="edit-field">
|
||
<text class="edit-label">姓名</text>
|
||
<input v-model="editForm.name" class="edit-input" placeholder="请输入姓名" :maxlength="30" />
|
||
</view>
|
||
<view class="edit-field">
|
||
<text class="edit-label">邮箱</text>
|
||
<input v-model="editForm.email" class="edit-input" placeholder="选填" />
|
||
</view>
|
||
<view class="edit-field">
|
||
<text class="edit-label">手机号</text>
|
||
<view class="edit-readonly">
|
||
<text>{{ phoneText }}</text>
|
||
<text class="readonly-tag">微信验证,不可修改</text>
|
||
</view>
|
||
</view>
|
||
<text v-if="editError" class="edit-error">{{ editError }}</text>
|
||
<button class="edit-submit" :disabled="saving" @tap="saveProfile">
|
||
{{ saving ? '保存中…' : '保存' }}
|
||
</button>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, reactive, computed, onMounted } from 'vue'
|
||
import { mpHeadPad } from '@/utils/mpHead.js'
|
||
|
||
const headPad = mpHeadPad()
|
||
import { getUser, setUser, logout, isLoggedIn, isSSOEnabled, getToken } from '@/utils/auth.js'
|
||
import { getCurrentUser, updateCurrentUserProfile, logoutApi, logoutUAC } from '@/api/auth.js'
|
||
import { requestSubscribeNotice } from '@/utils/subscribe.js'
|
||
import AppTabbar from '@/components/MainTabbar.vue'
|
||
|
||
const user = ref(null)
|
||
|
||
const profileTabs = [
|
||
{ name: 'profile', text: '我的', icon: 'user' },
|
||
{ name: 'platform', text: '回平台', icon: 'arrow-left' }
|
||
]
|
||
|
||
const avatarText = computed(() => {
|
||
const name = user.value?.nickname || user.value?.name || '云'
|
||
return name.charAt(0).toUpperCase()
|
||
})
|
||
|
||
const userId = computed(() => {
|
||
if (user.value?.phone) {
|
||
return user.value.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
|
||
}
|
||
if (user.value?.account) return user.value.account
|
||
if (user.value?.id) return String(user.value.id)
|
||
return '-'
|
||
})
|
||
|
||
async function loadUser() {
|
||
user.value = getUser()
|
||
try {
|
||
const data = await getCurrentUser()
|
||
if (data) {
|
||
const prev = getUser() || {}
|
||
const merged = {
|
||
...prev,
|
||
...data,
|
||
nickname: data.name || data.nickname || data.account || prev.nickname || '温新云用户'
|
||
}
|
||
setUser(merged)
|
||
user.value = merged
|
||
}
|
||
} catch {
|
||
user.value = getUser()
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
if (!isLoggedIn()) {
|
||
uni.reLaunch({ url: '/pages/nav/nav' })
|
||
return
|
||
}
|
||
loadUser()
|
||
})
|
||
|
||
function onSubscribe() {
|
||
requestSubscribeNotice({ tip: '已开启消息提醒' })
|
||
}
|
||
|
||
function goChangePassword() {
|
||
uni.navigateTo({ url: '/pages/profile/changePassword' })
|
||
}
|
||
|
||
function goBindTenant() {
|
||
uni.navigateTo({ url: '/pages/profile/bindTenant' })
|
||
}
|
||
|
||
function goHelp() {
|
||
uni.navigateTo({ url: '/pages/common/developing?t=' + encodeURIComponent('帮助中心') })
|
||
}
|
||
|
||
function goSettings() {
|
||
uni.navigateTo({ url: '/pages/common/developing?t=' + encodeURIComponent('设置') })
|
||
}
|
||
|
||
const editVisible = ref(false)
|
||
const saving = ref(false)
|
||
const editError = ref('')
|
||
const editForm = reactive({ name: '', email: '' })
|
||
|
||
const phoneText = computed(() => {
|
||
const u = user.value || {}
|
||
const p = u.phone || (u.account && /^1\d{10}$/.test(String(u.account)) ? String(u.account) : '')
|
||
return p ? String(p).replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : '微信已验证'
|
||
})
|
||
|
||
function onEdit() {
|
||
editForm.name = user.value?.nickname || user.value?.name || ''
|
||
editForm.email = user.value?.email || ''
|
||
editError.value = ''
|
||
editVisible.value = true
|
||
}
|
||
|
||
function closeEdit() {
|
||
if (!saving.value) editVisible.value = false
|
||
}
|
||
|
||
async function saveProfile() {
|
||
if (saving.value) return
|
||
const name = String(editForm.name || '').trim()
|
||
const email = String(editForm.email || '').trim()
|
||
if (!name) {
|
||
editError.value = '请填写姓名'
|
||
return
|
||
}
|
||
if (email && !email.includes('@')) {
|
||
editError.value = '邮箱格式不正确'
|
||
return
|
||
}
|
||
saving.value = true
|
||
editError.value = ''
|
||
try {
|
||
const res = await updateCurrentUserProfile({ name, email })
|
||
const next = {
|
||
...(getUser() || {}),
|
||
...(user.value || {}),
|
||
...(res || {}),
|
||
name,
|
||
nickname: name,
|
||
email
|
||
}
|
||
setUser(next)
|
||
user.value = next
|
||
editVisible.value = false
|
||
uni.showToast({ title: '资料已更新', icon: 'success' })
|
||
} catch (e) {
|
||
editError.value = (e && e.message) || '保存失败,请重试'
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
function handleLogout() {
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: '确定要退出登录吗?',
|
||
confirmText: '退出',
|
||
cancelText: '取消',
|
||
success(res) {
|
||
if (!res.confirm) return
|
||
if (isSSOEnabled() && getToken()) {
|
||
logoutUAC().catch(() => {})
|
||
} else {
|
||
logoutApi().catch(() => {})
|
||
}
|
||
logout()
|
||
uni.reLaunch({ url: '/pages/nav/nav' })
|
||
}
|
||
})
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
@import '@/src/styles/page-common.scss';
|
||
|
||
.page {
|
||
@include page-shell;
|
||
}
|
||
|
||
.profile-header {
|
||
flex-shrink: 0;
|
||
padding: calc(var(--status-bar-height, 44px) + 24rpx) $page-padding-x 40rpx;
|
||
/* #ifdef MP-WEIXIN */
|
||
padding-top: calc(env(safe-area-inset-top, 25px) + 88rpx);
|
||
/* #endif */
|
||
background: $hero-gradient;
|
||
position: relative;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.profile-header::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: -50%;
|
||
right: -50%;
|
||
width: 400rpx;
|
||
height: 400rpx;
|
||
border-radius: 50%;
|
||
background: rgba(255, 255, 255, 0.1);
|
||
pointer-events: none;
|
||
}
|
||
|
||
.profile-header::after {
|
||
content: '';
|
||
position: absolute;
|
||
bottom: -30%;
|
||
left: -20%;
|
||
width: 350rpx;
|
||
height: 350rpx;
|
||
border-radius: 50%;
|
||
background: rgba(255, 255, 255, 0.08);
|
||
pointer-events: none;
|
||
}
|
||
|
||
.profile-info {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 24rpx;
|
||
margin-top: 20rpx;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
|
||
.profile-avatar {
|
||
width: 120rpx;
|
||
height: 120rpx;
|
||
border-radius: 50%;
|
||
background: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.15) 100%);
|
||
border: 3rpx solid rgba(255, 255, 255, 0.4);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.15);
|
||
}
|
||
|
||
.avatar-text {
|
||
font-size: 44rpx;
|
||
font-weight: 600;
|
||
color: #ffffff;
|
||
}
|
||
|
||
.profile-detail {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.profile-name {
|
||
display: block;
|
||
font-size: 36rpx;
|
||
font-weight: 600;
|
||
color: #ffffff;
|
||
}
|
||
|
||
.profile-id {
|
||
display: block;
|
||
font-size: 24rpx;
|
||
color: rgba(255, 255, 255, 0.75);
|
||
margin-top: 6rpx;
|
||
}
|
||
|
||
.profile-edit {
|
||
width: 60rpx;
|
||
height: 60rpx;
|
||
border-radius: 50%;
|
||
background: rgba(255, 255, 255, 0.15);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
|
||
&:active {
|
||
background: rgba(255, 255, 255, 0.25);
|
||
}
|
||
}
|
||
|
||
.main-scroll {
|
||
@include scroll-body;
|
||
margin-top: -20rpx;
|
||
}
|
||
|
||
.menu-card {
|
||
@include card;
|
||
padding: 0 24rpx;
|
||
margin-bottom: 24rpx;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.menu-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 18rpx;
|
||
padding: 26rpx 0;
|
||
|
||
& + & {
|
||
border-top: 1rpx solid $color-divider;
|
||
}
|
||
|
||
&:active {
|
||
opacity: 0.75;
|
||
}
|
||
}
|
||
|
||
.row-icon {
|
||
@include tint-icon(64rpx, 18rpx);
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.row-main {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.row-title {
|
||
display: block;
|
||
font-size: 28rpx;
|
||
color: $color-text;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.row-sub {
|
||
display: block;
|
||
margin-top: 6rpx;
|
||
font-size: 22rpx;
|
||
color: $color-text-muted;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.row-value {
|
||
flex-shrink: 0;
|
||
font-size: 24rpx;
|
||
color: $color-primary;
|
||
}
|
||
|
||
.logout {
|
||
@include card;
|
||
margin-top: 12rpx;
|
||
padding: 28rpx 0;
|
||
text-align: center;
|
||
|
||
&:active {
|
||
background: $color-bg-page;
|
||
}
|
||
}
|
||
|
||
.logout-text {
|
||
font-size: 28rpx;
|
||
color: $color-danger;
|
||
}
|
||
|
||
.bottom-space {
|
||
height: 48rpx;
|
||
}
|
||
|
||
.edit-mask {
|
||
position: fixed;
|
||
left: 0;
|
||
top: 0;
|
||
right: 0;
|
||
bottom: 0;
|
||
z-index: 1000;
|
||
display: flex;
|
||
align-items: flex-end;
|
||
background: rgba(15, 23, 42, .48);
|
||
@include mask-responsive;
|
||
}
|
||
.edit-sheet {
|
||
width: 100%;
|
||
padding: 28rpx $page-padding-x 40rpx;
|
||
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
|
||
box-sizing: border-box;
|
||
border-radius: 32rpx 32rpx 0 0;
|
||
background: #ffffff;
|
||
@include sheet-responsive;
|
||
}
|
||
.edit-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 30rpx;
|
||
}
|
||
.edit-title { font-size: 32rpx; font-weight: 700; color: $color-text; }
|
||
.edit-close { font-size: 26rpx; color: $color-text-muted; }
|
||
.edit-field { margin-bottom: 26rpx; }
|
||
.edit-label { display: block; margin-bottom: 12rpx; font-size: 25rpx; font-weight: 600; color: #334155; }
|
||
.edit-input {
|
||
height: 88rpx;
|
||
padding: 0 22rpx;
|
||
box-sizing: border-box;
|
||
border: 1rpx solid #dce7f7;
|
||
border-radius: $radius-md;
|
||
background: #fbfdff;
|
||
font-size: 28rpx;
|
||
color: $color-text;
|
||
}
|
||
.edit-readonly {
|
||
height: 88rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 0 22rpx;
|
||
box-sizing: border-box;
|
||
border: 1rpx solid #e2e8f0;
|
||
border-radius: $radius-md;
|
||
background: #f1f5f9;
|
||
font-size: 27rpx;
|
||
color: #475569;
|
||
}
|
||
.readonly-tag { font-size: 21rpx; color: #94a3b8; }
|
||
.edit-error { display: block; margin: 4rpx 0 16rpx; font-size: 24rpx; color: $color-danger; }
|
||
.edit-submit {
|
||
height: 92rpx;
|
||
line-height: 92rpx;
|
||
margin-top: 12rpx;
|
||
border: none;
|
||
border-radius: $radius-full;
|
||
background: linear-gradient(135deg, #60a5fa, #2563eb);
|
||
color: #ffffff;
|
||
font-size: 30rpx;
|
||
font-weight: 600;
|
||
|
||
&::after { border: none; }
|
||
&[disabled] { opacity: .6; }
|
||
}
|
||
</style>
|