index.vue 3.5 KB

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