cwg-right-drawer.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="notice-container">
  3. <cwg-dropdown ref="dropdownRef" :menu-list="[]">
  4. <view class="pc-header-btn">
  5. <cwg-icon name="icon_my" color="#97A1C0" @click="openNotice" />
  6. </view>
  7. <template #btn>
  8. <view class="dropdown-menu dropdown-menu-end w-225px mt-1 show">
  9. <view class="d-flex align-items-center p-2">
  10. <view class="avatar avatar-sm rounded-circle">
  11. <image class="avatar1" src="/static/images/vu/logo.png" mode="aspectFill" />
  12. </view>
  13. <view class="ms-2">
  14. <view class="fw-bold text-dark text-ellipsis mb-2">{{ _displayName }}</view>
  15. <view class="text-body d-block lh-sm text-ellipsis mb-2">{{ _email }}</view>
  16. <text class="cid">CID: <text class="cwg-cursor" @click="copy(_displayCid)">{{ _displayCid
  17. }}</text></text>
  18. </view>
  19. </view>
  20. <view>
  21. <view class="dropdown-divider my-1"></view>
  22. </view>
  23. <view v-for="item in menuList" :key="item.id">
  24. <view class="dropdown-item user-menu-item d-flex align-items-center gap-2 cursor-pointer"
  25. @click="handleNavigate(item.path)">
  26. <cwg-icon :name="item.icon" :size="16" color="#000" />
  27. <text v-t="item.name"></text>
  28. </view>
  29. </view>
  30. <view>
  31. <view class="dropdown-divider my-1"></view>
  32. </view>
  33. <view>
  34. <view class="dropdown-item d-flex align-items-center gap-2 text-danger cursor-pointer"
  35. @click="handleLogout">
  36. <cwg-icon name="logout" :size="16" color="#FF401C" />
  37. <text v-t="'language.i6'"></text>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. </cwg-dropdown>
  43. </view>
  44. </template>
  45. <script setup lang="ts">
  46. import { ref, watch, onMounted, computed } from 'vue'
  47. import { onLoad, onShow, onLaunch } from '@dcloudio/uni-app'
  48. import useRoute from '@/hooks/useRoute'
  49. import useUserStore from '@/stores/use-user-store'
  50. import { userApi } from '@/api/user'
  51. import { useI18n } from "vue-i18n"
  52. import useRouter from "@/hooks/useRouter"
  53. import useGlobalStore from '@/stores/use-global-store'
  54. const globalStore = useGlobalStore()
  55. const isDark = computed(() => globalStore.theme === 'dark')
  56. const { t } = useI18n()
  57. const router = useRouter()
  58. const dropdownRef = ref(null)
  59. const userStore = useUserStore()
  60. const route = useRoute()
  61. // 强制用 ref 让插槽能渲染
  62. const menuList = ref([])
  63. const _displayName = ref('--')
  64. const _displayCid = ref('--')
  65. const _activePath = ref('')
  66. const _email = ref('--')
  67. // 复制文本
  68. const copy = (text: string) => {
  69. uni.setClipboardData({
  70. data: text,
  71. success: function () {
  72. uni.showToast({
  73. title: t('Btn.item8'),
  74. icon: 'none',
  75. duration: 2000
  76. });
  77. }
  78. });
  79. };
  80. // 初始化菜单
  81. function initMenu() {
  82. menuList.value = [
  83. { id: 1, path: '/pages/mine/info?type=1', name: 'PersonalManagement.Title.PersonalInformation', icon: 'crm-circle-user' },
  84. { id: 2, path: '/pages/mine/info?type=2', name: 'PersonalManagement.Title.BankInformation', icon: 'crm-building-columns' },
  85. { id: 3, path: '/pages/mine/info?type=3', name: 'PersonalManagement.Title.FileManagement', icon: 'crm-file' },
  86. { id: 4, path: '/pages/mine/info?type=4', name: 'PersonalManagement.Title.SecurityCenter', icon: 'crm-lock' },
  87. ]
  88. }
  89. // 强制同步用户信息
  90. function syncUserInfo() {
  91. const info = userStore.userInfo?.customInfo || {}
  92. const firstName = info.firstName || ''
  93. const lastName = info.lastName || ''
  94. _displayName.value = (firstName + ' ' + lastName).trim() || info.name || info.email || '--'
  95. _displayCid.value = info.cId || info.id || '--'
  96. _email.value = info.email || '--'
  97. }
  98. // 强制同步路径
  99. function syncPath() {
  100. _activePath.value = route.path + (route.query?.type ? `?type=${route.query.type}` : '')
  101. }
  102. onMounted(() => {
  103. initMenu()
  104. syncUserInfo()
  105. syncPath()
  106. })
  107. onShow(() => {
  108. initMenu()
  109. syncUserInfo()
  110. syncPath()
  111. })
  112. // 监听变化自动更新
  113. watch(() => userStore.userInfo, () => {
  114. syncUserInfo()
  115. }, { deep: true })
  116. watch(() => route, () => {
  117. syncPath()
  118. }, { deep: true })
  119. // 打开抽屉
  120. function openNotice() {
  121. // dropdownRef.value?.open()
  122. }
  123. // 关闭
  124. function close() {
  125. dropdownRef.value?.close()
  126. }
  127. // 跳转
  128. function handleNavigate(path) {
  129. router.push({ path })
  130. close()
  131. }
  132. // 登出
  133. async function handleLogout() {
  134. try {
  135. await userApi.logout()
  136. } catch (e) { }
  137. userStore.clearUserInfo()
  138. uni.setStorageSync('logoutToSystem', 1)
  139. // uni.$emit('updateSystemList')
  140. router.push('/pages/login/index')
  141. close()
  142. }
  143. defineExpose({ openNotice, close })
  144. </script>
  145. <style scoped lang="scss">
  146. @import "@/uni.scss";
  147. .notice-container {
  148. .text-ellipsis {
  149. display: block !important;
  150. white-space: normal !important;
  151. word-wrap: break-word !important;
  152. word-break: break-all !important;
  153. overflow: visible !important;
  154. text-overflow: unset !important;
  155. }
  156. :deep(.cwg-dropdown-menu-container) {
  157. left: px2rpx(-190) !important;
  158. right: px2rpx(0) !important;
  159. .menu {
  160. border: 0;
  161. overflow: visible;
  162. }
  163. }
  164. @media screen and (max-width: 991px) {
  165. :deep(.cwg-dropdown-menu-container) {
  166. left: px2rpx(-190) !important;
  167. max-width: px2rpx(400);
  168. }
  169. }
  170. .pc-header-btn {
  171. position: relative;
  172. }
  173. .user-menu-item {
  174. color: var(--bs-emphasis-color);
  175. text {
  176. color: var(--bs-emphasis-color);
  177. }
  178. }
  179. .right-drawer {
  180. width: px2rpx(300);
  181. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  182. display: flex;
  183. flex-direction: column;
  184. padding: px2rpx(20) px2rpx(16);
  185. box-sizing: border-box;
  186. }
  187. .drawer-header {
  188. display: flex;
  189. align-items: center;
  190. gap: px2rpx(12);
  191. padding: px2rpx(20);
  192. border-bottom: 1px solid #d9dde5;
  193. }
  194. .avatar1 {
  195. width: px2rpx(40);
  196. height: px2rpx(40);
  197. border-radius: 50%;
  198. // background: #fff;
  199. }
  200. .user-info {
  201. display: flex;
  202. flex-direction: column;
  203. gap: px2rpx(6);
  204. }
  205. .name {
  206. font-size: px2rpx(22);
  207. font-weight: 600;
  208. color: var(--bs-heading-color);
  209. }
  210. .cid {
  211. font-size: px2rpx(14);
  212. color: #ef4444;
  213. }
  214. .menu-list {
  215. padding: px2rpx(12) 0;
  216. }
  217. .menu-item {
  218. height: px2rpx(48);
  219. display: flex;
  220. align-items: center;
  221. gap: px2rpx(10);
  222. padding: 0 px2rpx(16);
  223. color: var(--bs-heading-color);
  224. font-size: px2rpx(16);
  225. font-weight: 600;
  226. &:hover {
  227. background-color: rgba(0, 0, 0, 0.05);
  228. }
  229. }
  230. .menu-item.active {
  231. background: rgba(108, 133, 149, 0.12) !important;
  232. border-radius: 0.125rem;
  233. }
  234. .logout-wrap {
  235. margin-top: auto;
  236. padding: px2rpx(20);
  237. margin-bottom: px2rpx(20);
  238. }
  239. .logout-btn {
  240. height: px2rpx(44);
  241. background-color: var(--bs-btn-bg);
  242. display: flex;
  243. align-items: center;
  244. justify-content: center;
  245. gap: px2rpx(8);
  246. color: #fff;
  247. font-weight: 600;
  248. font-size: px2rpx(16);
  249. cursor: pointer;
  250. }
  251. }
  252. </style>