index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view class="page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="菜单详情"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 详情内容 -->
  10. <view>
  11. <wd-cell-group border>
  12. <wd-cell title="菜单名称" :value="formData?.name || '-'" />
  13. <wd-cell title="菜单类型">
  14. <dict-tag :type="DICT_TYPE.SYSTEM_MENU_TYPE" :value="formData?.type" />
  15. </wd-cell>
  16. <wd-cell title="上级菜单" :value="parentMenuName" />
  17. <wd-cell title="显示排序" :value="String(formData?.sort ?? '-')" />
  18. <wd-cell title="路由地址" :value="formData?.path || '-'" />
  19. <wd-cell v-if="formData?.type === SystemMenuTypeEnum.MENU" title="组件路径" :value="formData?.component || '-'" />
  20. <wd-cell v-if="formData?.type === SystemMenuTypeEnum.MENU" title="组件名称" :value="formData?.componentName || '-'" />
  21. <wd-cell v-if="formData?.type !== SystemMenuTypeEnum.DIR" title="权限标识" :value="formData?.permission || '-'" />
  22. <wd-cell title="菜单状态">
  23. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="formData?.status" />
  24. </wd-cell>
  25. <wd-cell v-if="formData?.type !== SystemMenuTypeEnum.BUTTON" title="显示状态">
  26. <wd-tag v-if="formData?.visible" type="success" plain>
  27. 显示
  28. </wd-tag>
  29. <wd-tag v-else type="warning" plain>
  30. 隐藏
  31. </wd-tag>
  32. </wd-cell>
  33. <wd-cell v-if="formData?.type === SystemMenuTypeEnum.MENU" title="缓存状态">
  34. <wd-tag v-if="formData?.keepAlive" type="success" plain>
  35. 缓存
  36. </wd-tag>
  37. <wd-tag v-else type="default" plain>
  38. 不缓存
  39. </wd-tag>
  40. </wd-cell>
  41. <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
  42. </wd-cell-group>
  43. </view>
  44. <!-- 底部操作按钮 -->
  45. <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
  46. <view class="w-full flex gap-24rpx">
  47. <wd-button class="flex-1" type="warning" @click="handleEdit">
  48. 编辑
  49. </wd-button>
  50. <wd-button class="flex-1" type="error" :loading="deleting" @click="handleDelete">
  51. 删除
  52. </wd-button>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script lang="ts" setup>
  58. import type { Menu } from '@/api/system/menu'
  59. import { onMounted, ref } from 'vue'
  60. import { useToast } from 'wot-design-uni'
  61. import { deleteMenu, getMenu, getSimpleMenuList } from '@/api/system/menu'
  62. import { navigateBackPlus } from '@/utils'
  63. import { DICT_TYPE, SystemMenuTypeEnum } from '@/utils/constants'
  64. import { formatDateTime } from '@/utils/date'
  65. const props = defineProps<{
  66. id: number | any
  67. }>()
  68. definePage({
  69. style: {
  70. navigationBarTitleText: '',
  71. navigationStyle: 'custom',
  72. },
  73. })
  74. const toast = useToast()
  75. const formData = ref<Menu>()
  76. const deleting = ref(false)
  77. const parentMenuName = ref('-')
  78. /** 返回上一页 */
  79. function handleBack() {
  80. navigateBackPlus('/pages-system/menu/index')
  81. }
  82. /** 加载菜单详情 */
  83. async function getDetail() {
  84. if (!props.id) {
  85. return
  86. }
  87. toast.loading('加载中...')
  88. try {
  89. formData.value = await getMenu(props.id)
  90. // 获取上级菜单名称
  91. if (formData.value?.parentId === 0) {
  92. parentMenuName.value = '主类目'
  93. } else if (formData.value?.parentId) {
  94. // TODO @芋艿:后续这里可以优化,由后端返回 menuName;
  95. const menuList = await getSimpleMenuList()
  96. const parent = menuList.find(item => item.id === formData.value?.parentId)
  97. parentMenuName.value = parent?.name || '-'
  98. }
  99. } finally {
  100. toast.close()
  101. }
  102. }
  103. /** 编辑菜单 */
  104. function handleEdit() {
  105. uni.navigateTo({
  106. url: `/pages-system/menu/form/index?id=${props.id}`,
  107. })
  108. }
  109. /** 删除菜单 */
  110. function handleDelete() {
  111. if (!props.id) {
  112. return
  113. }
  114. uni.showModal({
  115. title: '提示',
  116. content: '确定要删除该菜单吗?',
  117. success: async (res) => {
  118. if (!res.confirm) {
  119. return
  120. }
  121. deleting.value = true
  122. try {
  123. await deleteMenu(props.id)
  124. toast.success('删除成功')
  125. setTimeout(() => {
  126. handleBack()
  127. }, 500)
  128. } finally {
  129. deleting.value = false
  130. }
  131. },
  132. })
  133. }
  134. /** 初始化 */
  135. onMounted(() => {
  136. getDetail()
  137. })
  138. </script>
  139. <style lang="scss" scoped>
  140. </style>