2025-03-05 09:22:29 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import Layout from "@/layout/index.vue"
|
|
|
|
import { useUserStore } from "@/pinia/stores/user"
|
|
|
|
import { useDark } from "@@/composables/useDark"
|
2025-03-17 08:30:57 +08:00
|
|
|
import { useWxStore } from "@/pinia/stores/wx"
|
2025-04-18 09:01:44 +08:00
|
|
|
import { tokenLogin } from '@/common/apis/ab98'
|
|
|
|
import { useAb98UserStore } from '@/pinia/stores/ab98-user'
|
2025-05-09 15:25:17 +08:00
|
|
|
import { useProductStore } from "./pinia/stores/product"
|
2025-03-05 09:22:29 +08:00
|
|
|
|
|
|
|
// const userStore = useUserStore()
|
2025-05-09 15:25:17 +08:00
|
|
|
const wxStore = useWxStore();
|
|
|
|
const route = useRoute();
|
|
|
|
const router = useRouter();
|
|
|
|
const ab98UserStore = useAb98UserStore();
|
|
|
|
const productStore = useProductStore();
|
2025-03-05 09:22:29 +08:00
|
|
|
|
|
|
|
const { isDark, initDark } = useDark()
|
|
|
|
|
|
|
|
const isLoading = false;
|
|
|
|
// const isLoading = computed(() => userStore.token && !userStore.username)
|
|
|
|
|
|
|
|
// watch(
|
|
|
|
// () => userStore.token,
|
|
|
|
// (newVal) => {
|
|
|
|
// newVal && userStore.getInfo()
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// immediate: true
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
|
|
|
|
initDark()
|
2025-03-17 08:30:57 +08:00
|
|
|
onMounted(() => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
console.log('urlParams', urlParams);
|
|
|
|
const code = urlParams.get('code') || undefined;
|
|
|
|
const state = urlParams.get('state') || undefined;
|
2025-04-02 09:33:47 +08:00
|
|
|
const corpid = urlParams.get('corpid') || undefined;
|
2025-04-03 09:03:47 +08:00
|
|
|
const isAdmin = urlParams.get('isAdmin') || undefined;
|
2025-04-28 17:13:31 +08:00
|
|
|
|
2025-04-18 09:01:44 +08:00
|
|
|
if (state && state.indexOf('token') !== -1) {
|
|
|
|
const token = state.split('token_')[1];
|
2025-04-18 10:24:01 +08:00
|
|
|
if (token) {
|
|
|
|
ab98UserStore.setTokenLogin(token);
|
2025-04-18 09:01:44 +08:00
|
|
|
|
2025-04-28 17:13:31 +08:00
|
|
|
watch(
|
|
|
|
() => wxStore.userid,
|
|
|
|
(newVal) => {
|
|
|
|
if (newVal && !ab98UserStore.isLogin) {
|
|
|
|
tokenLogin(ab98UserStore.tokenLogin, newVal).then(res => {
|
|
|
|
if (res?.code === 0 && res.data?.success) {
|
|
|
|
ab98UserStore.setTel(res.data.tel)
|
|
|
|
ab98UserStore.setUserInfo(res.data)
|
|
|
|
ab98UserStore.setIsLogin(true)
|
|
|
|
router.push('/')
|
|
|
|
}
|
|
|
|
})
|
2025-04-18 10:24:01 +08:00
|
|
|
}
|
2025-04-28 17:13:31 +08:00
|
|
|
},
|
|
|
|
{ immediate: true }
|
|
|
|
)
|
2025-04-18 10:24:01 +08:00
|
|
|
}
|
2025-04-18 09:01:44 +08:00
|
|
|
}
|
|
|
|
|
2025-04-03 09:03:47 +08:00
|
|
|
if (isAdmin == '1') {
|
2025-04-28 17:13:31 +08:00
|
|
|
wxStore.setIsCabinetAdmin(true);
|
2025-04-03 09:03:47 +08:00
|
|
|
}
|
2025-03-17 08:30:57 +08:00
|
|
|
if (code || state) {
|
2025-04-02 09:33:47 +08:00
|
|
|
wxStore.handleWxCallback({ corpid, code, state })
|
2025-03-17 08:30:57 +08:00
|
|
|
}
|
|
|
|
})
|
2025-03-05 09:22:29 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<van-config-provider :theme="isDark ? 'dark' : 'light'" un-h-full>
|
|
|
|
<van-loading v-if="isLoading" un-h-full un-flex-center>
|
|
|
|
加载中...
|
|
|
|
</van-loading>
|
|
|
|
<Layout v-else />
|
|
|
|
</van-config-provider>
|
|
|
|
</template>
|