60 lines
1.0 KiB
Vue
60 lines
1.0 KiB
Vue
<template>
|
|
<view class="main">
|
|
<view class="" style="width: 80%;margin: 0 auto;">
|
|
<up-button type="primary" @click="login" text="登录"></up-button>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import {
|
|
loginByCode
|
|
} from "@/comm/api.js"
|
|
import {
|
|
setToken,
|
|
getToken
|
|
} from "@/utils/Auth.js"
|
|
async function login() {
|
|
const __this = this
|
|
uni.login({
|
|
provider: "weixin",
|
|
async success(e) {
|
|
console.log(e.code)
|
|
try {
|
|
const resp = await loginByCode({
|
|
code: e.code
|
|
})
|
|
console.log(resp, "resp")
|
|
uni.showToast({
|
|
icon: "none",
|
|
title: "登录成功"
|
|
})
|
|
setToken(resp.token)
|
|
setTimeout(() => {
|
|
uni.switchTab({
|
|
url: "/pages/user/user"
|
|
})
|
|
}, 800)
|
|
} catch (err) {
|
|
console.log(err,"errorCatch")
|
|
uni.showToast({
|
|
icon: "none",
|
|
title: "登录失败"
|
|
})
|
|
}
|
|
}
|
|
,
|
|
fail(err) {
|
|
console.log(err,"error")
|
|
}
|
|
})
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.main {
|
|
height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
</style> |