Liuyi
2024-09-29 0560eed4a389f806dc3254a526e929e8476c868a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<script setup>
    import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
    import { wxLoginApi } from './api/index.js'
    onLaunch(() => {
        if(!uni.getStorageSync('openId')){
            wx.login({
                success:async (res1)=>{
                    uni.setStorageSync('code',res1.code)
                    await wxLoginApi({code:res1.code}).then((res2) =>{
                    uni.setStorageSync('openId',res2.data.userId)
                    uni.setStorageSync('token',res2.data.token)
                  })
                },
                fail:(e) =>{
                    console.log(e)
                }
            })
        }
    });
    onShow(() => {
      console.log("App Show");
    });
    onHide(() => {
      console.log("App Hide");
    });
</script>
 
<style lang='scss'>
</style>