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,29 +18,31 @@ const { ...@@ -18,29 +18,31 @@ const {
loading: userLoading, loading: userLoading,
error: userError, error: userError,
run: userRun, run: userRun,
} = useRequest(() => } = useRequest(
UserToken.get({ () =>
token: authStore.loginInfo.token, UserToken.get({
}).then(res => { token: authStore.loginInfo.token,
if (res.code === GATEWAY_CODE.success) { }).then(res => {
userStore.$patch({ userInfo: res.data }) if (res.code === GATEWAY_CODE.success) {
//超管跳转 userStore.$patch({ userInfo: res.data })
if (authStore.loginInfo.id === 10000000) { //超管跳转
authStore.$patch({ if (authStore.loginInfo.id === 10000000) {
consoleInfo: { authStore.$patch({
consoleName: '超管', consoleInfo: {
consoleObjectId: '1', consoleName: '超管',
consoleTypeId: '1', consoleObjectId: '1',
}, consoleTypeId: '1',
}) },
window.location.replace(`${origin}/super/proxy`) })
return window.location.replace(`${origin}/super/proxy`)
return
}
//其余跳转
authStore.$reset()
window.location.replace(`${origin}/account/proxy`)
} }
//其余跳转 return res
authStore.$reset() }),
window.location.replace(`${origin}/account/proxy`) { manual: true },
}
return res
}),
) )
</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