cwg-right-drawer.vue 8.7 KB

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