<template>
  <view class="SignMultiple">
    <view class="urlIndex">
      <view class="urlTitle">
        <view class="urlWelcome">
          <view style="font-size: 26px">Welcome</view>
          <view class="urlHibiscus">
            <view class="contact">
              <image
                src='https://img12.360buyimg.com/imagetools/jfs/t1/196430/38/8105/14329/60c806a4Ed506298a/e6de9fb7b8490f38.png'
                mode="scaleToFill"
                class="image"
              />
              <text>欢迎</text>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view class="SignItem">
      <view class="Cancel">
        <nut-button block type="success" @click="onLogin">一键授权</nut-button>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import "./login.scss";
import Taro, { useLoad } from "@tarojs/taro";
import api from "@/request/index";



useLoad(() => {});
const onLogin = () => {
  Taro.login({
    success:  (res) => {
      if(res.code){
        api.post<LoginUserInfo>("/login", {
          clientType: 'MINI_PROGRAM',
          loginParams: {
            code:res.code
          }
        }).then(async (resp)=>{
            await Taro.setStorage({
            key: "token",
            data: resp.data,
            success(res) {
              Taro.switchTab({
                url: '/pages/projectManager/index/index'
              })
            },
          })
        }).catch((error)=>{
          if(error.code === 402){
            Taro.navigateTo({
              url: "/pages/register/register",
            });
          }
        })
      }
    },
  });





};
</script>
