108 lines
2.2 KiB
Vue
108 lines
2.2 KiB
Vue
<template>
|
||
<view class="login-page">
|
||
<view class="login-header">
|
||
<image class="login-logo" src="/static/logo.png" mode="aspectFit" />
|
||
<text class="login-title">珠宝商城</text>
|
||
<text class="login-desc">登录后享受完整购物体验</text>
|
||
</view>
|
||
|
||
<view class="login-actions">
|
||
<button class="login-btn" :loading="loading" @click="handleLogin">
|
||
微信一键登录
|
||
</button>
|
||
<view class="login-skip" @click="goBack">
|
||
<text>暂不登录,先逛逛</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref } from 'vue'
|
||
import { autoLogin } from '../../utils/request'
|
||
import { useUserStore } from '../../store/user'
|
||
|
||
const loading = ref(false)
|
||
const userStore = useUserStore()
|
||
|
||
async function handleLogin() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
try {
|
||
await autoLogin()
|
||
await userStore.fetchProfile()
|
||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||
setTimeout(() => {
|
||
uni.navigateBack({ delta: 1, fail: () => {
|
||
uni.switchTab({ url: '/pages/index/index' })
|
||
}})
|
||
}, 500)
|
||
} catch {
|
||
uni.showToast({ title: '登录失败,请重试', icon: 'none' })
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function goBack() {
|
||
uni.navigateBack({ delta: 1, fail: () => {
|
||
uni.switchTab({ url: '/pages/index/index' })
|
||
}})
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.login-page {
|
||
min-height: 100vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #fff;
|
||
padding: 0 60rpx;
|
||
}
|
||
.login-header {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
margin-bottom: 120rpx;
|
||
}
|
||
.login-logo {
|
||
width: 160rpx;
|
||
height: 160rpx;
|
||
margin-bottom: 30rpx;
|
||
}
|
||
.login-title {
|
||
font-size: 40rpx;
|
||
font-weight: bold;
|
||
color: #333;
|
||
margin-bottom: 16rpx;
|
||
}
|
||
.login-desc {
|
||
font-size: 26rpx;
|
||
color: #999;
|
||
}
|
||
.login-actions {
|
||
width: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
}
|
||
.login-btn {
|
||
width: 100%;
|
||
height: 88rpx;
|
||
line-height: 88rpx;
|
||
background: #e4393c;
|
||
color: #fff;
|
||
font-size: 32rpx;
|
||
border-radius: 44rpx;
|
||
border: none;
|
||
text-align: center;
|
||
}
|
||
.login-skip {
|
||
margin-top: 32rpx;
|
||
font-size: 26rpx;
|
||
color: #999;
|
||
}
|
||
</style>
|