| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <template>
- <view class="profile-page">
- <view v-if="loading" class="loading-bar">同步中…</view>
- <!-- 个人信息卡片(只读,数据来自 GET /users/me) -->
- <view class="card">
- <view class="row">
- <text class="label">头像</text>
- <view class="row-right">
- <view class="avatar-wrap">
- <UserAvatar
- :name="user.name"
- :id="user.id"
- :src="user.avatar"
- :size="80"
- unit="rpx"
- />
- </view>
- </view>
- </view>
- <view class="row">
- <text class="label">姓名</text>
- <view class="row-right">
- <text class="value">{{ user.name || '—' }}</text>
- </view>
- </view>
- <view class="row">
- <text class="label">账号名</text>
- <view class="row-right">
- <text class="value" :class="{ placeholder: !user.alias }">{{ user.alias || '—' }}</text>
- </view>
- </view>
- </view>
- <view class="card">
- <view class="row no-arrow">
- <text class="label">企业</text>
- <text class="value">{{ displayOrg }}</text>
- </view>
- </view>
- <text class="hint">信息由服务端维护,暂不支持在应用内修改。</text>
- <view class="logout-section">
- <view
- v-if="isAndroid"
- class="action-btn check-update-btn"
- @click="onCheckUpdate"
- >
- 检测更新
- </view>
- <view class="action-btn change-pwd-btn" @click="onChangePassword">修改密码</view>
- <view class="logout-btn" @click="onLogout">退出登录</view>
- </view>
- </view>
- </template>
- <script>
- import UserAvatar from '../../components/UserAvatar.vue'
- import { getToken, getCurrentUserInfo, normalizeUserPayload, setToken } from '../../utils/api'
- // #ifdef APP-PLUS
- import { manualCheckAndroidApkUpdate } from '../../utils/appUpgrade'
- // #endif
- const USER_KEY = 'current_user'
- const DEFAULT_ORG = '韫珠科技'
- export default {
- components: { UserAvatar },
- data() {
- return {
- isAndroid: false,
- loading: false,
- user: {
- name: '',
- id: '',
- avatar: '',
- alias: '',
- orgName: ''
- }
- }
- },
- computed: {
- displayOrg() {
- return this.user.orgName || DEFAULT_ORG
- }
- },
- onLoad() {
- this.applyFromStorage()
- this.refreshAndroidFlag()
- },
- onShow() {
- this.applyFromStorage()
- this.refreshAndroidFlag()
- this.refreshFromServer()
- },
- methods: {
- refreshAndroidFlag() {
- // #ifdef APP-PLUS
- try {
- this.isAndroid = uni.getSystemInfoSync().platform === 'android'
- } catch (e) {
- this.isAndroid = false
- }
- // #endif
- },
- applyFromStorage() {
- try {
- const raw = uni.getStorageSync(USER_KEY)
- const u = normalizeUserPayload(raw)
- if (u) {
- this.user = {
- name: u.name,
- id: u.id,
- avatar: u.avatar,
- alias: u.alias,
- orgName: u.orgName || u.org_name || ''
- }
- }
- } catch (e) {}
- },
- async refreshFromServer() {
- const token = getToken()
- if (!token) return
- this.loading = true
- try {
- const me = await getCurrentUserInfo(token)
- const u = normalizeUserPayload(me)
- if (!u) return
- const orgName = u.orgName || u.org_name || DEFAULT_ORG
- this.user = {
- name: u.name,
- id: u.id,
- avatar: u.avatar,
- alias: u.alias,
- orgName
- }
- try {
- const prev = uni.getStorageSync(USER_KEY)
- const base = prev && typeof prev === 'object' ? prev : {}
- uni.setStorageSync(USER_KEY, {
- ...base,
- ...u,
- orgName,
- org_name: orgName
- })
- } catch (e) {}
- } catch (e) {
- // 网络失败时保留本地/缓存展示
- } finally {
- this.loading = false
- }
- },
- onCheckUpdate() {
- // #ifdef APP-PLUS
- manualCheckAndroidApkUpdate()
- // #endif
- },
- onChangePassword() {
- uni.navigateTo({ url: '/pages/change-password/index' })
- },
- onLogout() {
- uni.showModal({
- title: '提示',
- content: '确定要退出登录吗?',
- success: (res) => {
- if (!res.confirm) return
- setToken('')
- try {
- uni.removeStorageSync(USER_KEY)
- } catch (e) {}
- this.user = {
- name: '',
- id: '',
- avatar: '',
- alias: '',
- orgName: ''
- }
- uni.reLaunch({ url: '/pages/login/index' })
- }
- })
- }
- }
- }
- </script>
- <style scoped>
- .profile-page {
- min-height: 100vh;
- background-color: #f5f5f5;
- padding: 24rpx;
- padding-bottom: calc(120rpx + constant(safe-area-inset-bottom));
- padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
- box-sizing: border-box;
- }
- .loading-bar {
- font-size: 24rpx;
- color: #999;
- margin-bottom: 16rpx;
- padding-left: 8rpx;
- }
- .card {
- background: #fff;
- border-radius: 16rpx;
- overflow: hidden;
- margin-bottom: 24rpx;
- }
- .row {
- display: flex;
- align-items: center;
- justify-content: space-between;
- min-height: 112rpx;
- padding: 0 32rpx;
- border-bottom: 1rpx solid #f0f0f0;
- }
- .row:last-child {
- border-bottom: none;
- }
- .row.no-arrow {
- border-bottom: none;
- }
- .label {
- font-size: 30rpx;
- color: #333;
- flex-shrink: 0;
- }
- .row-right {
- display: flex;
- align-items: center;
- gap: 16rpx;
- min-width: 0;
- }
- .value {
- font-size: 28rpx;
- color: #333;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- max-width: 400rpx;
- }
- .value.placeholder {
- color: #999;
- }
- .avatar-wrap {
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .hint {
- display: block;
- font-size: 24rpx;
- color: #999;
- line-height: 1.5;
- padding: 0 16rpx;
- }
- .logout-section {
- margin-top: 48rpx;
- padding: 0 0 24rpx;
- display: flex;
- flex-direction: column;
- gap: 24rpx;
- }
- .action-btn {
- background: #fff;
- border-radius: 16rpx;
- min-height: 96rpx;
- line-height: 96rpx;
- text-align: center;
- font-size: 32rpx;
- }
- .check-update-btn {
- color: #259653;
- }
- .change-pwd-btn {
- color: #333;
- }
- .logout-btn {
- background: #fff;
- border-radius: 16rpx;
- min-height: 96rpx;
- line-height: 96rpx;
- text-align: center;
- font-size: 32rpx;
- color: #e54d42;
- }
- </style>
|