index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="yd-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="String(formData?.id ?? '-')" />
  13. <wd-cell title="字典类型" :value="String(formData?.dictType ?? '-')" />
  14. <wd-cell title="字典标签" :value="String(formData?.label ?? '-')" />
  15. <wd-cell title="字典键值" :value="String(formData?.value ?? '-')" />
  16. <wd-cell title="字典排序" :value="String(formData?.sort ?? '-')" />
  17. <wd-cell title="状态">
  18. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="formData?.status" />
  19. </wd-cell>
  20. <wd-cell title="颜色类型">
  21. <view v-if="formData?.colorType" class="rounded-4rpx px-8rpx py-2rpx text-24rpx text-white" :style="{ backgroundColor: getColorStyle(formData.colorType) }">
  22. {{ formData.colorType }}
  23. </view>
  24. <text v-else>-</text>
  25. </wd-cell>
  26. <wd-cell title="CSS Class">
  27. <view v-if="formData?.cssClass" class="rounded-4rpx px-8rpx py-2rpx text-24rpx text-white" :style="{ backgroundColor: formData.cssClass }">
  28. {{ formData.cssClass }}
  29. </view>
  30. <text v-else>-</text>
  31. </wd-cell>
  32. <wd-cell title="备注" :value="String(formData?.remark ?? '-')" />
  33. <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
  34. </wd-cell-group>
  35. </view>
  36. <!-- 底部操作按钮 -->
  37. <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
  38. <view class="w-full flex gap-24rpx">
  39. <wd-button
  40. v-if="hasAccessByCodes(['system:dict:update'])"
  41. class="flex-1" type="warning" @click="handleEdit"
  42. >
  43. 编辑
  44. </wd-button>
  45. <wd-button
  46. v-if="hasAccessByCodes(['system:dict:delete'])"
  47. class="flex-1" type="error" :loading="deleting" @click="handleDelete"
  48. >
  49. 删除
  50. </wd-button>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script lang="ts" setup>
  56. import type { DictData } from '@/api/system/dict/data'
  57. import { onMounted, ref } from 'vue'
  58. import { useToast } from 'wot-design-uni'
  59. import { deleteDictData, getDictData } from '@/api/system/dict/data'
  60. import { useAccess } from '@/hooks/useAccess'
  61. import { navigateBackPlus } from '@/utils'
  62. import { DICT_TYPE } from '@/utils/constants'
  63. import { formatDateTime } from '@/utils/date'
  64. const props = defineProps<{
  65. id?: number | any
  66. }>()
  67. definePage({
  68. style: {
  69. navigationBarTitleText: '',
  70. navigationStyle: 'custom',
  71. },
  72. })
  73. const { hasAccessByCodes } = useAccess()
  74. const toast = useToast()
  75. const formData = ref<DictData>()
  76. const deleting = ref(false)
  77. /** 颜色类型映射 */
  78. const colorMap: Record<string, string> = {
  79. processing: '#1890ff',
  80. success: '#52c41a',
  81. default: '#d9d9d9',
  82. warning: '#faad14',
  83. error: '#ff4d4f',
  84. pink: '#eb2f96',
  85. red: '#f5222d',
  86. orange: '#fa8c16',
  87. green: '#52c41a',
  88. cyan: '#13c2c2',
  89. blue: '#1890ff',
  90. purple: '#722ed1',
  91. }
  92. /** 获取颜色样式 */
  93. function getColorStyle(colorType: string) {
  94. return colorMap[colorType] || colorType
  95. }
  96. /** 返回上一页 */
  97. function handleBack() {
  98. navigateBackPlus('/pages-system/dict/index')
  99. }
  100. /** 加载详情 */
  101. async function getDetail() {
  102. if (!props.id) {
  103. return
  104. }
  105. try {
  106. toast.loading('加载中...')
  107. formData.value = await getDictData(props.id)
  108. } finally {
  109. toast.close()
  110. }
  111. }
  112. /** 编辑 */
  113. function handleEdit() {
  114. uni.navigateTo({
  115. url: `/pages-system/dict/data/form/index?id=${props.id}`,
  116. })
  117. }
  118. /** 删除 */
  119. function handleDelete() {
  120. if (!props.id) {
  121. return
  122. }
  123. uni.showModal({
  124. title: '提示',
  125. content: '确定要删除该字典数据吗?',
  126. success: async (res) => {
  127. if (!res.confirm) {
  128. return
  129. }
  130. deleting.value = true
  131. try {
  132. await deleteDictData(props.id)
  133. toast.success('删除成功')
  134. setTimeout(() => {
  135. handleBack()
  136. }, 500)
  137. } finally {
  138. deleting.value = false
  139. }
  140. },
  141. })
  142. }
  143. /** 初始化 */
  144. onMounted(() => {
  145. getDetail()
  146. })
  147. </script>
  148. <style lang="scss" scoped>
  149. </style>