2022-12-05 23:01:12 +08:00
|
|
|
import http from '/admin/support/http'
|
2022-12-07 19:28:57 +08:00
|
|
|
import { Ref, ref } from 'vue'
|
|
|
|
import { isFunction } from '../../support/helper'
|
2022-12-05 23:01:12 +08:00
|
|
|
|
2022-12-10 18:29:42 +08:00
|
|
|
export function useShow(path: string, id: string | number, fillData: null | Ref = null) {
|
|
|
|
const loading = ref<boolean>(true)
|
2022-12-07 19:28:57 +08:00
|
|
|
|
2022-12-10 18:29:42 +08:00
|
|
|
const data = ref<object>()
|
2022-12-07 19:28:57 +08:00
|
|
|
|
2022-12-10 18:29:42 +08:00
|
|
|
// 后置钩子
|
|
|
|
const afterShow = ref()
|
2022-12-07 19:28:57 +08:00
|
|
|
|
|
|
|
http.get(path + '/' + id).then(r => {
|
|
|
|
loading.value = false
|
|
|
|
data.value = r.data.data
|
|
|
|
if (fillData) {
|
|
|
|
fillData.value = r.data.data
|
|
|
|
|
|
|
|
if (isFunction(afterShow.value)) {
|
|
|
|
afterShow.value(fillData)
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 23:01:12 +08:00
|
|
|
})
|
2022-12-07 19:28:57 +08:00
|
|
|
|
|
|
|
return { data, loading, afterShow }
|
2022-12-05 23:01:12 +08:00
|
|
|
}
|