更新go结构和uniapp

This commit is contained in:
2026-07-15 22:38:33 +08:00
parent bca5170e22
commit 61a937f7a3
23 changed files with 3536 additions and 293 deletions
+51 -17
View File
@@ -6,8 +6,8 @@
<text class="avatar-text">{{ avatarText }}</text>
</view>
<view class="profile-detail">
<text class="profile-name">{{ user?.nickname || '云泽用户' }}</text>
<text class="profile-id">ID: {{ userId }}</text>
<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" />
@@ -43,7 +43,7 @@
</view>
</view>
<view class="logout-btn" @tap="handleLogout">
<view class="logout-btn" hover-class="logout-btn-hover" @tap.stop="handleLogout">
<text class="logout-text">退出登录</text>
</view>
@@ -56,20 +56,24 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
import { getUser, logout, isLoggedIn } from '@/utils/auth.js'
import { getUser, setUser, logout, isLoggedIn } from '@/utils/auth.js'
import { getCurrentUser, logoutApi } from '@/api/auth.js'
import AppTabbar from '@/components/AppTabbar.vue'
const user = ref(null)
const avatarText = computed(() => {
const name = user.value?.nickname || '云'
const name = user.value?.nickname || user.value?.name || '云'
return name.charAt(0).toUpperCase()
})
const userId = computed(() => {
return user.value?.phone
? user.value.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
: '10086'
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 '-'
})
const profileStats = ref([
@@ -96,12 +100,32 @@ const menuGroups = ref([
]
])
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 {
// 401 时 request 会跳转登录
user.value = getUser()
}
}
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
user.value = getUser()
loadUser()
})
function onEdit() {
@@ -109,6 +133,10 @@ function onEdit() {
}
function onMenuTap(item) {
if (item.title === '账号安全') {
uni.navigateTo({ url: '/pages/login/forget' })
return
}
uni.showToast({ title: item.title, icon: 'none' })
}
@@ -116,11 +144,15 @@ function handleLogout() {
uni.showModal({
title: '提示',
content: '确定要退出登录吗?',
confirmText: '退出',
cancelText: '取消',
success(res) {
if (res.confirm) {
logout()
uni.reLaunch({ url: '/pages/login/login' })
}
if (!res.confirm) return
// 先清本地并跳转,避免接口超时/失败导致“退出无效”
logout()
// 后端无状态退出,失败可忽略(不阻塞)
logoutApi().catch(() => {})
uni.reLaunch({ url: '/pages/login/login' })
}
})
}
@@ -289,18 +321,20 @@ function handleLogout() {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 8rpx;
}
&:active {
background: $color-bg-page;
}
.logout-btn-hover {
background: $color-bg-page !important;
}
.logout-text {
font-size: 30rpx;
color: $color-text-secondary;
pointer-events: none;
}
.bottom-space {
height: 24rpx;
height: 48rpx;
}
</style>