<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { useUserStore } from "@/stores";
import { getPermissions, login } from "@/api/base/client";
const { proxy } = getCurrentInstance() as any;
const {$isResolve} = proxy
onLaunch(async () => {
  const userStore = useUserStore()
  const code = await getLoginCode()
  const { token, info_status } = await login({ code: code as string, platform: 1 })
  userStore.setLoginInfo(info_status, token)
  const { list } = await getPermissions();
  userStore.setPermissionsList(list)
  await $isResolve()
});

const getLoginCode = () => {
  return new Promise((resolve, reject) => {
    uni.login({
      success: async (res: { code: string, errMsg?: string }) => {
        if (res.code) {
          return resolve(res.code)
        } else {
          uni.showModal({
            title: '登录失败！',
            showCancel: false,
            content: `${res.errMsg}`
          })
          return reject()
        }
      }
    })
  })
}
onShow(() => {
  console.log("App Show");
});
onHide(() => {
  console.log("App Hide");
});
</script>
<style>
@import "@/static/style/iconfont/my.css";

page {
  background-color: #edf0f9;
}



</style>
