index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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="formData?.id" />
  13. <wd-cell title="参数分类" :value="formData?.category" />
  14. <wd-cell title="参数名称" :value="formData?.name" />
  15. <wd-cell title="参数键名" :value="formData?.key" />
  16. <wd-cell title="参数键值" :value="formData?.value" />
  17. <wd-cell title="是否可见">
  18. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="formData?.visible" />
  19. </wd-cell>
  20. <wd-cell title="系统内置">
  21. <dict-tag :type="DICT_TYPE.INFRA_CONFIG_TYPE" :value="formData?.type" />
  22. </wd-cell>
  23. <wd-cell title="备注" :value="formData?.remark ?? '-'" />
  24. <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
  25. </wd-cell-group>
  26. </view>
  27. <!-- 底部操作按钮 -->
  28. <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
  29. <view class="w-full flex gap-24rpx">
  30. <wd-button
  31. v-if="hasAccessByCodes(['infra:config:update'])"
  32. class="flex-1" type="warning" @click="handleEdit"
  33. >
  34. 编辑
  35. </wd-button>
  36. <wd-button
  37. v-if="hasAccessByCodes(['infra:config:delete'])"
  38. class="flex-1" type="error" :loading="deleting" @click="handleDelete"
  39. >
  40. 删除
  41. </wd-button>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script lang="ts" setup>
  47. import type { Config } from '@/api/infra/config'
  48. import { onMounted, ref } from 'vue'
  49. import { useToast } from 'wot-design-uni'
  50. import { deleteConfig, getConfig } from '@/api/infra/config'
  51. import { useAccess } from '@/hooks/useAccess'
  52. import { navigateBackPlus } from '@/utils'
  53. import { DICT_TYPE } from '@/utils/constants'
  54. import { formatDateTime } from '@/utils/date'
  55. const props = defineProps<{
  56. id?: number | any
  57. }>()
  58. definePage({
  59. style: {
  60. navigationBarTitleText: '',
  61. navigationStyle: 'custom',
  62. },
  63. })
  64. const { hasAccessByCodes } = useAccess()
  65. const toast = useToast()
  66. const formData = ref<Config>()
  67. const deleting = ref(false)
  68. /** 返回上一页 */
  69. function handleBack() {
  70. navigateBackPlus('/pages-infra/config/index')
  71. }
  72. /** 加载参数配置详情 */
  73. async function getDetail() {
  74. if (!props.id) {
  75. return
  76. }
  77. try {
  78. toast.loading('加载中...')
  79. formData.value = await getConfig(props.id)
  80. } finally {
  81. toast.close()
  82. }
  83. }
  84. /** 编辑参数配置 */
  85. function handleEdit() {
  86. uni.navigateTo({
  87. url: `/pages-infra/config/form/index?id=${props.id}`,
  88. })
  89. }
  90. /** 删除参数配置 */
  91. function handleDelete() {
  92. if (!props.id) {
  93. return
  94. }
  95. uni.showModal({
  96. title: '提示',
  97. content: '确定要删除该参数配置吗?',
  98. success: async (res) => {
  99. if (!res.confirm) {
  100. return
  101. }
  102. deleting.value = true
  103. try {
  104. await deleteConfig(props.id)
  105. toast.success('删除成功')
  106. setTimeout(() => {
  107. handleBack()
  108. }, 500)
  109. } finally {
  110. deleting.value = false
  111. }
  112. },
  113. })
  114. }
  115. /** 初始化 */
  116. onMounted(() => {
  117. getDetail()
  118. })
  119. </script>
  120. <style lang="scss" scoped>
  121. </style>