| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <template>
- <view class="notice-container">
- <cwg-dropdown ref="dropdownRef" :menu-list="[]">
- <view class="pc-header-btn">
- <cwg-icon name="icon_my" color="#97A1C0" @click="openNotice" />
- </view>
- <template #btn>
- <view class="right-drawer">
- <view class="drawer-header">
- <image class="avatar" src="/static/images/avatars.png" mode="aspectFill" />
- <view class="user-info">
- <text class="name">{{ _displayName }}</text>
- <text class="cid">CID: <text class="cwg-cursor" @click="copy(_displayCid)">{{ _displayCid
- }}</text></text>
- </view>
- </view>
- <view class="menu-list">
- <view v-for="item in menuList" :key="item.id" class="menu-item"
- :class="{ active: _activePath === item.path }" @click="handleNavigate(item.path)">
- <cwg-icon :name="item.icon" :size="16" color="#fff" />
- <text v-t="item.name"></text>
- </view>
- </view>
- <view class="logout-wrap">
- <view class="logout-btn btn btn-danger" @click="handleLogout">
- <cwg-icon name="logout" :size="16" color="#ff9800" />
- <text v-t="'language.i6'"></text>
- </view>
- </view>
- </view>
- </template>
- </cwg-dropdown>
- </view>
- </template>
- <script setup lang="ts">
- import { ref, watch, onMounted } from 'vue'
- import { onLoad, onShow, onLaunch } from '@dcloudio/uni-app'
- import useRoute from '@/hooks/useRoute'
- import useUserStore from '@/stores/use-user-store'
- import { userApi } from '@/api/user'
- import { useI18n } from "vue-i18n"
- import useRouter from "@/hooks/useRouter"
- const { t } = useI18n()
- const router = useRouter()
- const dropdownRef = ref(null)
- const userStore = useUserStore()
- const route = useRoute()
- // 强制用 ref 让插槽能渲染
- const menuList = ref([])
- const _displayName = ref('--')
- const _displayCid = ref('--')
- const _activePath = ref('')
- // 复制文本
- const copy = (text: string) => {
- uni.setClipboardData({
- data: text,
- success: function () {
- uni.showToast({
- title: t('Btn.item8'),
- icon: 'none',
- duration: 2000
- });
- }
- });
- };
- // 初始化菜单
- function initMenu() {
- menuList.value = [
- { id: 1, path: '/pages/mine/info?type=1', name: 'PersonalManagement.Title.PersonalInformation', icon: 'crm-circle-user' },
- { id: 2, path: '/pages/mine/info?type=2', name: 'PersonalManagement.Title.BankInformation', icon: 'crm-building-columns' },
- { id: 3, path: '/pages/mine/info?type=3', name: 'PersonalManagement.Title.FileManagement', icon: 'crm-file' },
- { id: 4, path: '/pages/mine/info?type=4', name: 'PersonalManagement.Title.SecurityCenter', icon: 'crm-lock' },
- ]
- }
- // 强制同步用户信息
- function syncUserInfo() {
- const info = userStore.userInfo?.customInfo || {}
- const firstName = info.firstName || ''
- const lastName = info.lastName || ''
- _displayName.value = (firstName + ' ' + lastName).trim() || info.name || info.email || '--'
- _displayCid.value = info.cId || info.id || '--'
- }
- // 强制同步路径
- function syncPath() {
- _activePath.value = route.path + (route.query?.type ? `?type=${route.query.type}` : '')
- }
- onMounted(() => {
- initMenu()
- syncUserInfo()
- syncPath()
- })
- onShow(() => {
- initMenu()
- syncUserInfo()
- syncPath()
- })
- // 监听变化自动更新
- watch(() => userStore.userInfo, () => {
- syncUserInfo()
- }, { deep: true })
- watch(() => route, () => {
- syncPath()
- }, { deep: true })
- // 打开抽屉
- function openNotice() {
- // dropdownRef.value?.open()
- }
- // 关闭
- function close() {
- dropdownRef.value?.close()
- }
- // 跳转
- function handleNavigate(path) {
- router.push({ path })
- close()
- }
- // 登出
- async function handleLogout() {
- try {
- await userApi.logout()
- } catch (e) { }
- userStore.clearUserInfo()
- router.push('/pages/login/index')
- close()
- }
- defineExpose({ openNotice, close })
- </script>
- <style scoped lang="scss">
- @import "@/uni.scss";
- .notice-container {
- :deep(.cwg-dropdown-menu-container) {
- left: px2rpx(-280) !important;
- right: px2rpx(0) !important;
- }
- @media screen and (max-width: 991px) {
- :deep(.cwg-dropdown-menu-container) {
- left: px2rpx(-270) !important;
- max-width: px2rpx(400);
- }
- }
- .pc-header-btn {
- position: relative;
- }
- .right-drawer {
- width: px2rpx(300);
- background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
- display: flex;
- flex-direction: column;
- padding: 20px 16px;
- box-sizing: border-box;
- }
- .drawer-header {
- display: flex;
- align-items: center;
- gap: 12px;
- padding: 20px 16px;
- border-bottom: 1px solid #d9dde5;
- }
- .avatar {
- width: 76px;
- height: 76px;
- border-radius: 50%;
- background: #fff;
- }
- .user-info {
- display: flex;
- flex-direction: column;
- gap: 6px;
- }
- .name {
- font-size: 20px;
- font-weight: 600;
- color: var(--bs-heading-color);
- }
- .cid {
- font-size: 14px;
- color: #ef4444;
- }
- .menu-list {
- padding: 12px 0;
- }
- .menu-item {
- height: 48px;
- display: flex;
- align-items: center;
- gap: 10px;
- padding: 0 16px;
- color: var(--bs-heading-color);
- font-size: 16px;
- font-weight: 600;
- &:hover {
- background-color: rgba(0, 0, 0, 0.05);
- }
- }
- .menu-item.active {
- background: rgba(108, 133, 149, 0.12) !important;
- border-radius: 0.125rem;
- }
- .logout-wrap {
- margin-top: auto;
- padding: 20px 16px;
- margin-bottom: 20px;
- }
- .logout-btn {
- height: 44px;
- background-color: var(--bs-btn-bg);
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 8px;
- color: #fff;
- font-weight: 600;
- font-size: 16px;
- cursor: pointer;
- }
- }
- </style>
|