<script setup>
import useUserStore from '@/store/user'
import { showToast, showLoadingToast, closeToast } from 'vant'
import testJson from '@/utils/test.json';
import { loginBySgy } from '@/api/account'
const userStore = useUserStore()
onLaunch(async () => {
    // #ifdef H5-SGY
    // if (import.meta.env.VITE_APP_ENV === 'production') {
    //     userStore.logout()
    //     fastLoginBySgy()
    //     return
    // } else {
    //     if (userStore.logout) await signIn2();
    // }
    // #endif
});

onShow(() => {
    console.log('App Show');
});

onHide(() => {
    console.log('App Hide');
});

const sgyLoginParams = ref({
    appid: import.meta.env.VITE_APP_SGY_APPID,
    type: "sgy",
    encryptDataMap: {},
    systemcode: import.meta.env.VITE_APP_SYSTEM_CODE
})
// 登录
const signIn2 = async () => {
    showLoadingToast({
        title: '加载中...',
        mask: true,
    });
    sgyLoginParams.value.encryptDataMap = testJson
    const res = await loginBySgy(sgyLoginParams.value)
    console.log(res)
    userStore.login(res)
    closeToast()
};


const fastLoginBySgy = () => {
    xma.xh.getUserProfile({
        range: ['ACCOUNT', 'MOBILE'],
        async success(info) {
            showLoadingToast({
                message: '登录中',
                forbidClick: true,
                duration: 0
            })
            sgyLoginParams.value.encryptDataMap = info.data
            const res = await loginBySgy(sgyLoginParams.value)
            userStore.login(res)
            closeToast()
        }
    });
}
</script>
<style></style>
