workbench.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <script setup>
  2. import { computed, ref } from 'vue'
  3. import { onShow } from '@dcloudio/uni-app'
  4. import { useUserStore } from '@/stores/user'
  5. import { WORKBENCH_MODULES } from '@/config/workbench-menus'
  6. import { PAGE_PATHS, WORKBENCH_ROUTE_MAP } from '@/config/api'
  7. import { filterWorkbenchModules } from '@/utils/workbenchMenuFilter'
  8. import { getSafeAreaStyle } from '@/utils/safeArea'
  9. const safeAreaStyle = getSafeAreaStyle()
  10. const userStore = useUserStore()
  11. const modules = computed(() =>
  12. filterWorkbenchModules(WORKBENCH_MODULES, {
  13. menuAll: userStore.menuAll,
  14. menuCodes: userStore.menuCodes
  15. })
  16. )
  17. const loggingOut = ref(false)
  18. const displayName = computed(() => {
  19. const info = userStore.userInfo
  20. if (!info) return '未登录'
  21. return info.realName || info.username || '用户'
  22. })
  23. /** 三列宫格补齐空白格,避免末行空位露出网格底色 */
  24. const menuPadCount = (len) => {
  25. const rem = Number(len) % 3
  26. return rem === 0 ? 0 : 3 - rem
  27. }
  28. onShow(async () => {
  29. userStore.checkLoginStatus()
  30. if (!userStore.isLoggedIn) {
  31. uni.reLaunch({ url: PAGE_PATHS.login })
  32. return
  33. }
  34. await userStore.fetchMenuCodes()
  35. })
  36. const openMenu = (module, menu) => {
  37. if (!menu.enabled) {
  38. uni.showToast({ title: '本期暂未开放', icon: 'none' })
  39. return
  40. }
  41. const route = WORKBENCH_ROUTE_MAP[menu.code]
  42. if (route) {
  43. uni.navigateTo({ url: route })
  44. return
  45. }
  46. const title = encodeURIComponent(menu.name || '')
  47. const moduleTitle = encodeURIComponent(module.title || '')
  48. const code = encodeURIComponent(menu.code || '')
  49. uni.navigateTo({
  50. url: `${PAGE_PATHS.bizPlaceholder}?title=${title}&module=${moduleTitle}&code=${code}`
  51. })
  52. }
  53. const handleLogout = async () => {
  54. if (loggingOut.value) return
  55. loggingOut.value = true
  56. try {
  57. await userStore.logout()
  58. } finally {
  59. loggingOut.value = false
  60. }
  61. }
  62. </script>
  63. <template>
  64. <view class="mp-page mp-page--tab">
  65. <view class="sq-nav-header sq-nav-header--tall" :style="safeAreaStyle">
  66. <view class="sq-nav-header__nav">
  67. <view class="sq-nav-header__main">
  68. <view class="sq-nav-header__left sq-nav-header__left--stack">
  69. <text class="sq-nav-header__title">工作台</text>
  70. <text class="sq-nav-header__meta">选择业务模块,进入对应功能办理</text>
  71. </view>
  72. <view class="sq-nav-header__user">
  73. <text class="sq-nav-header__user-name">{{ displayName }}</text>
  74. <text
  75. class="sq-nav-header__logout"
  76. :class="{ 'sq-nav-header__logout--disabled': loggingOut }"
  77. @click="handleLogout"
  78. >
  79. {{ loggingOut ? '退出中…' : '退出登录' }}
  80. </text>
  81. </view>
  82. </view>
  83. <view /><!-- 胶囊占位 -->
  84. </view>
  85. </view>
  86. <view class="mp-section">
  87. <view
  88. v-for="mod in modules"
  89. :key="mod.key"
  90. class="mp-module-block"
  91. :class="'mp-module-block--' + mod.key"
  92. >
  93. <view class="mp-module-block__head">
  94. <text class="mp-module-block__icon">{{ mod.iconText }}</text>
  95. <view class="mp-module-block__title-wrap">
  96. <text class="mp-module-block__title">{{ mod.title }}</text>
  97. <text class="mp-module-block__desc">{{ mod.desc }}</text>
  98. </view>
  99. </view>
  100. <view class="mp-menu-grid">
  101. <view
  102. v-for="(menu, idx) in mod.menus"
  103. :key="menu.code || menu.name + idx"
  104. class="mp-menu-card"
  105. :class="{ 'mp-menu-card--disabled': !menu.enabled }"
  106. @click="openMenu(mod, menu)"
  107. >
  108. <view class="mp-menu-card__icon">{{ menu.icon || '' }}</view>
  109. <text class="mp-menu-card__name">{{ menu.name }}</text>
  110. </view>
  111. <view
  112. v-for="i in menuPadCount(mod.menus.length)"
  113. :key="'pad-' + mod.key + '-' + i"
  114. class="mp-menu-card mp-menu-card--pad"
  115. />
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. </template>