2 天以前 8f3bf7050e65fdbe55eaad74fde307c57dab960e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<template>
  <view class="yd-page-container">
    <!-- 顶部导航栏 -->
    <wd-navbar
      title="学生详情"
      left-arrow placeholder safe-area-inset-top fixed
      @click-left="handleBack"
    />
 
    <!-- 详情内容 -->
    <view>
      <wd-cell-group border>
        <wd-cell title="编号" :value="formData?.id ?? '-'" />
        <wd-cell title="名字" :value="formData?.name ?? '-'" />
        <wd-cell title="简介" :value="formData?.description ?? '-'" />
        <wd-cell title="出生日期" :value="formatDateTime(formData?.birthday) || '-'" />
        <wd-cell title="性别">
          <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="formData?.sex" />
        </wd-cell>
        <wd-cell title="是否有效">
          <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="formData?.enabled" />
        </wd-cell>
        <wd-cell title="头像" :value="formData?.avatar ?? '-'" />
        <wd-cell title="附件" :value="formData?.video ?? '-'" />
        <wd-cell title="备注" :value="formData?.memo ?? '-'" />
        <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
      </wd-cell-group>
    </view>
 
    <!-- 底部操作按钮 -->
    <view class="yd-detail-footer">
      <view class="yd-detail-footer-actions">
        <wd-button
          v-if="hasAccessByCodes(['infra:student:update'])"
          class="flex-1" type="warning" @click="handleEdit"
        >
          编辑
        </wd-button>
        <wd-button
          v-if="hasAccessByCodes(['infra:student:delete'])"
          class="flex-1" type="error" :loading="deleting" @click="handleDelete"
        >
          删除
        </wd-button>
      </view>
    </view>
  </view>
</template>
 
<script lang="ts" setup>
import type { Student } from '@/api/infra/demo'
import { onUnload } from '@dcloudio/uni-app'
import { onMounted, ref } from 'vue'
import { useToast } from '@wot-ui/ui/components/wd-toast'
import { deleteStudent, getStudent } from '@/api/infra/demo'
import { useAccess } from '@/hooks/useAccess'
import { delay, navigateBackPlus } from '@/utils'
import { DICT_TYPE } from '@/utils/constants'
import { formatDateTime } from '@/utils/date'
 
const props = defineProps<{
  id?: number | any
}>()
 
definePage({
  style: {
    navigationBarTitleText: '',
    navigationStyle: 'custom',
  },
})
 
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const formData = ref<Student>() // 详情数据
const deleting = ref(false) // 删除状态
 
/** 返回上一页 */
function handleBack() {
  navigateBackPlus('/pages-infra/demo/index')
}
 
/** 加载学生详情 */
async function getDetail() {
  if (!props.id || deleting.value) {
    return
  }
  try {
    toast.loading('加载中...')
    formData.value = await getStudent(props.id)
  } finally {
    toast.close()
  }
}
 
/** 编辑学生 */
function handleEdit() {
  uni.navigateTo({
    url: `/pages-infra/demo/form/index?id=${props.id}`,
  })
}
 
/** 删除学生 */
function handleDelete() {
  if (!props.id) {
    return
  }
  uni.showModal({
    title: '提示',
    content: '确定要删除该学生吗?',
    success: async (res) => {
      if (!res.confirm) {
        return
      }
      deleting.value = true
      try {
        await deleteStudent(props.id)
        toast.success('删除成功')
        uni.$emit('infra:demo:reload')
        delay(handleBack)
      } finally {
        deleting.value = false
      }
    },
  })
}
 
/** 初始化 */
onMounted(() => {
  uni.$on('infra:demo:reload', getDetail)
  getDetail()
})
 
/** 卸载 */
onUnload(() => {
  uni.$off('infra:demo:reload', getDetail)
})
</script>
 
<style lang="scss" scoped>
</style>