index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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?.name" />
  13. <wd-cell title="岗位编码" :value="formData?.code" />
  14. <wd-cell title="显示顺序" :value="formData?.sort" />
  15. <wd-cell title="状态">
  16. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="formData?.status" />
  17. </wd-cell>
  18. <wd-cell title="备注" :value="formData?.remark || '-'" />
  19. <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime)" />
  20. </wd-cell-group>
  21. </view>
  22. <!-- 底部操作按钮 -->
  23. <view class="yd-detail-footer">
  24. <view class="yd-detail-footer-actions">
  25. <wd-button
  26. v-if="hasAccessByCodes(['system:post:update'])"
  27. class="flex-1" type="warning" @click="handleEdit"
  28. >
  29. 编辑
  30. </wd-button>
  31. <wd-button
  32. v-if="hasAccessByCodes(['system:post:delete'])"
  33. class="flex-1" type="error" :loading="deleting" @click="handleDelete"
  34. >
  35. 删除
  36. </wd-button>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script lang="ts" setup>
  42. import type { Post } from '@/api/system/post'
  43. import { onMounted, ref } from 'vue'
  44. import { useToast } from 'wot-design-uni'
  45. import { deletePost, getPost } from '@/api/system/post'
  46. import { useAccess } from '@/hooks/useAccess'
  47. import { navigateBackPlus } from '@/utils'
  48. import { DICT_TYPE } from '@/utils/constants'
  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<Post>()
  62. const deleting = ref(false)
  63. /** 返回上一页 */
  64. function handleBack() {
  65. navigateBackPlus('/pages-system/post/index')
  66. }
  67. /** 加载岗位详情 */
  68. async function getDetail() {
  69. if (!props.id) {
  70. return
  71. }
  72. try {
  73. toast.loading('加载中...')
  74. formData.value = await getPost(props.id)
  75. } finally {
  76. toast.close()
  77. }
  78. }
  79. /** 编辑岗位 */
  80. function handleEdit() {
  81. uni.navigateTo({
  82. url: `/pages-system/post/form/index?id=${props.id}`,
  83. })
  84. }
  85. /** 删除岗位 */
  86. function handleDelete() {
  87. if (!props.id) {
  88. return
  89. }
  90. uni.showModal({
  91. title: '提示',
  92. content: '确定要删除该岗位吗?',
  93. success: async (res) => {
  94. if (!res.confirm) {
  95. return
  96. }
  97. deleting.value = true
  98. try {
  99. await deletePost(props.id)
  100. toast.success('删除成功')
  101. setTimeout(() => {
  102. handleBack()
  103. }, 500)
  104. } finally {
  105. deleting.value = false
  106. }
  107. },
  108. })
  109. }
  110. /** 初始化 */
  111. onMounted(() => {
  112. getDetail()
  113. })
  114. </script>
  115. <style lang="scss" scoped>
  116. </style>