workbench.vue 4.2 KB

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