cwg-right-drawer.vue 8.6 KB

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