523 lines
12 KiB
Plaintext
523 lines
12 KiB
Plaintext
<template>
|
|
<view class="page">
|
|
<scroll-view class="scroll" scroll-y="true" show-scrollbar="false">
|
|
<view class="top-actions">
|
|
<button class="lang-btn" @click="toggleLanguage">
|
|
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
|
|
</button>
|
|
</view>
|
|
|
|
<view class="hero">
|
|
<view class="brand-row">
|
|
<view class="brand-mark"></view>
|
|
<view class="brand-text">
|
|
<text class="brand-name">Mall</text>
|
|
<text class="brand-slogan">正品保障 · 省心售后</text>
|
|
</view>
|
|
</view>
|
|
<view class="title-block">
|
|
<text class="page-title">{{ $t('user.login.title') }}</text>
|
|
<text class="page-subtitle">{{ $t('user.login.subtitle') }}</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="card">
|
|
<form @submit="onSubmit">
|
|
<view class="field" :class="{ 'field-error': emailError }">
|
|
<text class="label">{{ $t('user.login.email') }}</text>
|
|
<view class="input-wrap">
|
|
<input class="input" name="email" type="text" :value="email" :placeholder="$t('user.login.email_placeholder')" @blur="validateEmail" />
|
|
</view>
|
|
<text v-if="emailError" class="support error">{{ emailError }}</text>
|
|
</view>
|
|
|
|
<view class="field" :class="{ 'field-error': passwordError }">
|
|
<text class="label">{{ $t('user.login.password') }}</text>
|
|
<view class="input-wrap">
|
|
<input class="input" name="password" :type="showPassword ? 'text' : 'password'" :value="password" :placeholder="$t('user.login.password_placeholder')" @blur="validatePassword" />
|
|
<view class="suffix" @click="showPassword = !showPassword">
|
|
<text class="suffix-text">{{ showPassword ? '隐藏' : '显示' }}</text>
|
|
</view>
|
|
</view>
|
|
<text v-if="passwordError" class="support error">{{ passwordError }}</text>
|
|
</view>
|
|
|
|
<view class="row">
|
|
<view class="remember">
|
|
<checkbox value="rememberMe" color="#FF4D4F" />
|
|
<text class="remember-text">{{ $t('user.login.remember_me') }}</text>
|
|
</view>
|
|
<text class="link" @click="navigateToForgotPassword">{{ $t('user.login.forgot_password') }}</text>
|
|
</view>
|
|
|
|
<button form-type="submit" class="primary" :disabled="isLoading" :loading="isLoading">
|
|
{{ $t('user.login.login_button') }}
|
|
</button>
|
|
|
|
<text v-if="generalError" class="support error center">{{ generalError }}</text>
|
|
</form>
|
|
|
|
<view class="divider">
|
|
<view class="divider-line"></view>
|
|
<text class="divider-text">{{ $t('user.login.or_login_with') }}</text>
|
|
<view class="divider-line"></view>
|
|
</view>
|
|
|
|
<view class="social-row">
|
|
<button class="social wechat" @click="socialLogin('WeChat')"><text class="social-label">微信</text></button>
|
|
<button class="social qq" @click="socialLogin('QQ')"><text class="social-label">QQ</text></button>
|
|
<button class="social sms" @click="socialLogin('SMS')"><text class="social-label">短信</text></button>
|
|
</view>
|
|
|
|
<view class="footer">
|
|
<text class="footer-text">{{ $t('user.login.no_account') }}</text>
|
|
<text class="footer-link" @click="navigateToRegister">{{ $t('user.login.register_now') }}</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="trust">
|
|
<text class="trust-text">登录即代表你同意用户协议与隐私政策</text>
|
|
</view>
|
|
</scroll-view>
|
|
</view>
|
|
</template>
|
|
|
|
<script lang="uts">
|
|
import {HOME_REDIRECT,TABORPAGE} from '@/ak/config.uts'
|
|
import type { AkReqOptions, AkReqResponse, AkReqError } from '@/uni_modules/ak-req/index.uts';
|
|
import supa from '@/components/supadb/aksupainstance.uts';
|
|
import { getCurrentUser, logout } from '@/utils/store.uts';
|
|
import { switchLocale, getCurrentLocale } from '@/utils/utils.uts';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
// email: "akoo@163.com",
|
|
// password: "Hf2152111",
|
|
email: "am@163.com",
|
|
password: "kookoo",
|
|
emailError: "",
|
|
passwordError: "",
|
|
generalError: "",
|
|
isLoading: false,
|
|
showPassword: false,
|
|
rememberMe: false,
|
|
currentLocale: getCurrentLocale()
|
|
};
|
|
},
|
|
onLoad() {
|
|
// Try to restore saved email if "remember me" was selected
|
|
// this.tryRestoreEmail();
|
|
console.log('akkkk')
|
|
// 启动后若已登录,直接进入商城消费者端首页
|
|
try {
|
|
const sessionInfo = supa.getSession();
|
|
if (sessionInfo != null && sessionInfo.user != null) {
|
|
// 已登录 -> 直接进入 tabBar 首页
|
|
console.log('login onLoad: found session, go consumer/index')
|
|
uni.switchTab({ url: '/pages/mall/consumer/index' });
|
|
return;
|
|
}
|
|
} catch (e) {}
|
|
}, methods: {
|
|
|
|
toggleLanguage() {
|
|
const newLocale = this.currentLocale === 'zh-CN' ? 'en-US' : 'zh-CN';
|
|
switchLocale(newLocale);
|
|
this.currentLocale = newLocale;
|
|
|
|
uni.showToast({
|
|
title: this.$t('user.login.language_switched'),
|
|
icon: 'success'
|
|
});
|
|
}, tryRestoreEmail() {
|
|
|
|
try {
|
|
const savedEmail = uni.getStorageSync('rememberEmail') as string;
|
|
if (savedEmail.trim() !== "") {
|
|
this.email = savedEmail;
|
|
this.rememberMe = true;
|
|
}
|
|
} catch (e) {
|
|
console.error("Error restoring email:", e);
|
|
}
|
|
},
|
|
onSubmit(e : UniFormSubmitEvent) {
|
|
this.handleLogin();
|
|
},
|
|
validateEmail() {
|
|
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
if (this.email.trim() === "") {
|
|
this.emailError = this.$t('user.login.email_required');
|
|
return false;
|
|
} else if (!emailRegex.test(this.email)) {
|
|
this.emailError = this.$t('user.login.email_invalid');
|
|
return false;
|
|
} else {
|
|
this.emailError = '';
|
|
return true;
|
|
}
|
|
}, validatePassword() {
|
|
if (this.password.trim() === "") {
|
|
this.passwordError = this.$t('user.login.password_required');
|
|
return false;
|
|
} else if (this.password.length < 6) {
|
|
this.passwordError = this.$t('user.login.password_too_short');
|
|
return false;
|
|
} else {
|
|
this.passwordError = '';
|
|
return true;
|
|
}
|
|
},
|
|
validateForm() {
|
|
const emailValid = this.validateEmail();
|
|
const passwordValid = this.validatePassword();
|
|
return emailValid && passwordValid;
|
|
},
|
|
async handleLogin() {
|
|
this.generalError = '';
|
|
// 清除旧用户数据
|
|
logout();
|
|
if (!this.validateForm()) {
|
|
return;
|
|
}
|
|
this.isLoading = true;
|
|
try {
|
|
// Save email if remember me is checked
|
|
if (this.rememberMe) {
|
|
uni.setStorageSync('rememberEmail', this.email);
|
|
} else {
|
|
uni.removeStorageSync('rememberEmail');
|
|
} // Call signin method from Supabase
|
|
const result = await supa.signIn(
|
|
this.email,
|
|
this.password);
|
|
if (result.user !== null) {
|
|
// 获取并更新当前用户,确保数据已生效
|
|
const profile = await getCurrentUser();
|
|
if (profile==null) throw new Error(this.$t('user.login.profile_update_failed'));
|
|
// 登录成功提示
|
|
uni.showToast({ title: this.$t('user.login.login_success'), icon: 'success' });
|
|
// 跳转至商城消费者端首页(类似京东:默认消费者)
|
|
uni.switchTab({ url: '/pages/mall/consumer/index' });
|
|
return;
|
|
} else {
|
|
throw new Error(this.$t('user.login.login_failed'));
|
|
}
|
|
} catch (err) {
|
|
console.error("Login error:", err);
|
|
|
|
// Show error dialog to user
|
|
let errorMessage = this.$t('user.login.login_failed');
|
|
if (err !== null && typeof err === 'object') {
|
|
const error = err as Error;
|
|
if (error.message !== null && error.message.trim() !== '') {
|
|
errorMessage = error.message;
|
|
}
|
|
}
|
|
|
|
uni.showModal({
|
|
title: this.$t('user.login.error_title'),
|
|
content: errorMessage,
|
|
showCancel: false,
|
|
confirmText: this.$t('user.login.confirm'),
|
|
success: () => {
|
|
// Clear any existing error states
|
|
this.generalError = '';
|
|
this.emailError = '';
|
|
this.passwordError = '';
|
|
}
|
|
});
|
|
} finally {
|
|
this.isLoading = false;
|
|
}
|
|
},
|
|
socialLogin(provider : string) {
|
|
// This would be implemented to handle OAuth login with different providers
|
|
uni.showToast({
|
|
title: `${provider} ${this.$t('user.login.coming_soon')}`,
|
|
icon: 'none'
|
|
});
|
|
},
|
|
navigateToRegister() {
|
|
uni.navigateTo({
|
|
url: '/pages/user/register'
|
|
});
|
|
},
|
|
navigateToForgotPassword() {
|
|
uni.navigateTo({
|
|
url: '/pages/user/forgot-password'
|
|
});
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<style>
|
|
.page {
|
|
min-height: 100vh;
|
|
background: #f7f8fa;
|
|
}
|
|
|
|
.scroll {
|
|
min-height: 100vh;
|
|
background: radial-gradient(900rpx 700rpx at 20% 10%, rgba(255, 77, 79, 0.16), rgba(255, 77, 79, 0) 60%),
|
|
linear-gradient(180deg, #ffffff 0%, #f7f8fa 45%, #f7f8fa 100%);
|
|
}
|
|
|
|
.top-actions {
|
|
position: relative;
|
|
padding: 24rpx 24rpx 0;
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.lang-btn {
|
|
width: 76rpx;
|
|
height: 76rpx;
|
|
border-radius: 38rpx;
|
|
background: rgba(255, 255, 255, 0.9);
|
|
border: 1rpx solid rgba(0, 0, 0, 0.06);
|
|
color: #111;
|
|
font-size: 26rpx;
|
|
line-height: 76rpx;
|
|
text-align: center;
|
|
box-shadow: 0 10rpx 24rpx rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.hero {
|
|
padding: 26rpx 24rpx 14rpx;
|
|
}
|
|
|
|
.brand-row {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.brand-mark {
|
|
width: 72rpx;
|
|
height: 72rpx;
|
|
border-radius: 20rpx;
|
|
background: linear-gradient(135deg, #ff4d4f 0%, #ff8a65 100%);
|
|
box-shadow: 0 12rpx 26rpx rgba(255, 77, 79, 0.28);
|
|
}
|
|
|
|
.brand-text {
|
|
margin-left: 18rpx;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.brand-name {
|
|
font-size: 40rpx;
|
|
font-weight: 700;
|
|
color: #111;
|
|
letter-spacing: 1rpx;
|
|
}
|
|
|
|
.brand-slogan {
|
|
margin-top: 6rpx;
|
|
font-size: 24rpx;
|
|
color: rgba(0, 0, 0, 0.55);
|
|
}
|
|
|
|
.title-block {
|
|
margin-top: 26rpx;
|
|
}
|
|
|
|
.page-title {
|
|
font-size: 46rpx;
|
|
font-weight: 700;
|
|
color: #111;
|
|
}
|
|
|
|
.page-subtitle {
|
|
margin-top: 10rpx;
|
|
font-size: 26rpx;
|
|
color: rgba(0, 0, 0, 0.55);
|
|
}
|
|
|
|
.card {
|
|
margin: 18rpx 24rpx 0;
|
|
padding: 26rpx 22rpx;
|
|
background: rgba(255, 255, 255, 0.96);
|
|
border-radius: 20rpx;
|
|
border: 1rpx solid rgba(0, 0, 0, 0.06);
|
|
box-shadow: 0 16rpx 36rpx rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.field {
|
|
margin-bottom: 18rpx;
|
|
}
|
|
|
|
.label {
|
|
font-size: 24rpx;
|
|
color: rgba(0, 0, 0, 0.78);
|
|
margin-bottom: 10rpx;
|
|
display: block;
|
|
}
|
|
|
|
.input-wrap {
|
|
position: relative;
|
|
display: flex;
|
|
align-items: center;
|
|
background: #f6f7f9;
|
|
border: 2rpx solid rgba(0, 0, 0, 0.06);
|
|
border-radius: 14rpx;
|
|
padding: 0 14rpx;
|
|
}
|
|
|
|
.field-error .input-wrap {
|
|
border-color: rgba(255, 77, 79, 0.55);
|
|
background: rgba(255, 77, 79, 0.06);
|
|
}
|
|
|
|
.input {
|
|
flex: 1;
|
|
height: 84rpx;
|
|
font-size: 28rpx;
|
|
color: #111;
|
|
padding: 0 6rpx;
|
|
}
|
|
|
|
.suffix {
|
|
height: 84rpx;
|
|
padding: 0 10rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.suffix-text {
|
|
font-size: 24rpx;
|
|
color: rgba(0, 0, 0, 0.55);
|
|
}
|
|
|
|
.support {
|
|
margin-top: 10rpx;
|
|
font-size: 22rpx;
|
|
color: rgba(0, 0, 0, 0.52);
|
|
}
|
|
|
|
.error {
|
|
color: #ff4d4f;
|
|
}
|
|
|
|
.center {
|
|
text-align: center;
|
|
width: 100%;
|
|
display: block;
|
|
}
|
|
|
|
.row {
|
|
margin: 8rpx 0 18rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.remember {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.remember-text {
|
|
margin-left: 8rpx;
|
|
font-size: 24rpx;
|
|
color: rgba(0, 0, 0, 0.6);
|
|
}
|
|
|
|
.link {
|
|
font-size: 24rpx;
|
|
color: #ff4d4f;
|
|
}
|
|
|
|
.primary {
|
|
width: 100%;
|
|
height: 92rpx;
|
|
border-radius: 18rpx;
|
|
background: linear-gradient(135deg, #ff4d4f 0%, #ff7a45 100%);
|
|
color: #fff;
|
|
font-size: 30rpx;
|
|
font-weight: 600;
|
|
box-shadow: 0 16rpx 32rpx rgba(255, 77, 79, 0.24);
|
|
}
|
|
|
|
.primary:disabled {
|
|
background: #d9d9d9;
|
|
box-shadow: none;
|
|
}
|
|
|
|
.divider {
|
|
margin-top: 22rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 14rpx;
|
|
}
|
|
|
|
.divider-line {
|
|
flex: 1;
|
|
height: 1rpx;
|
|
background: rgba(0, 0, 0, 0.08);
|
|
}
|
|
|
|
.divider-text {
|
|
font-size: 22rpx;
|
|
color: rgba(0, 0, 0, 0.45);
|
|
}
|
|
|
|
.social-row {
|
|
margin-top: 18rpx;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
gap: 16rpx;
|
|
}
|
|
|
|
.social {
|
|
flex: 1;
|
|
height: 76rpx;
|
|
border-radius: 14rpx;
|
|
background: #ffffff;
|
|
border: 1rpx solid rgba(0, 0, 0, 0.08);
|
|
box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.04);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.social-label {
|
|
font-size: 24rpx;
|
|
color: rgba(0, 0, 0, 0.7);
|
|
}
|
|
|
|
.footer {
|
|
margin-top: 22rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.footer-text {
|
|
font-size: 24rpx;
|
|
color: rgba(0, 0, 0, 0.55);
|
|
}
|
|
|
|
.footer-link {
|
|
margin-left: 8rpx;
|
|
font-size: 24rpx;
|
|
color: #ff4d4f;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.trust {
|
|
padding: 18rpx 24rpx 36rpx;
|
|
}
|
|
|
|
.trust-text {
|
|
font-size: 22rpx;
|
|
color: rgba(0, 0, 0, 0.4);
|
|
text-align: center;
|
|
}
|
|
</style> |