Commit cbb7678a authored by guxukai's avatar guxukai

chore: query-wrapper完善

parent de4d639c
<template> <template>
<div></div> <g-query-wrapper :error="userError" :data="userData" :run="userRun" :loading="userLoading" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useAuth } from '@shared/store/modules/auth' import { useAuth } from '@shared/store/modules/auth'
...@@ -18,7 +18,8 @@ const { ...@@ -18,7 +18,8 @@ const {
loading: userLoading, loading: userLoading,
error: userError, error: userError,
run: userRun, run: userRun,
} = useRequest(() => } = useRequest(
() =>
UserToken.get({ UserToken.get({
token: authStore.loginInfo.token, token: authStore.loginInfo.token,
}).then(res => { }).then(res => {
...@@ -42,5 +43,6 @@ const { ...@@ -42,5 +43,6 @@ const {
} }
return res return res
}), }),
{ manual: true },
) )
</script> </script>
<template> <template>
<div> <div>
<slot v-if="!loading" /> <slot v-if="!loading && !error && !hasError" />
<div v-if="loading">数据获取中...</div>
<div v-if="error">
{{ error }}
</div>
<div v-if="hasError">
{{ data.message }}
</div>
<div v-if="error || hasError">
<el-button @click="run">重新请求</el-button>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { GATEWAY_CODE } from '@shared/http/constants'
import { HttpResponse } from '@shared/http/HttpResponse'
import { PropType } from 'vue'
const props = defineProps({ const props = defineProps({
loading: { loading: {
type: Boolean, type: Boolean,
...@@ -13,6 +27,7 @@ const props = defineProps({ ...@@ -13,6 +27,7 @@ const props = defineProps({
required: false, required: false,
}, },
data: { data: {
type: Object as PropType<HttpResponse>,
required: false, required: false,
}, },
run: { run: {
...@@ -20,4 +35,5 @@ const props = defineProps({ ...@@ -20,4 +35,5 @@ const props = defineProps({
required: true, required: true,
}, },
}) })
const hasError = props.data && props.data?.code !== GATEWAY_CODE.success
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment