Initial commit of akmon project
This commit is contained in:
686
pages/user/center.uvue
Normal file
686
pages/user/center.uvue
Normal file
@@ -0,0 +1,686 @@
|
||||
<template>
|
||||
<view class="page-wrapper">
|
||||
<!-- Top section with language switch -->
|
||||
<view class="top-section"> <view class="language-switch">
|
||||
<button class="language-btn" @click="toggleLanguage">
|
||||
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Main content section -->
|
||||
<view class="main-section">
|
||||
<scroll-view direction="vertical" class="user-center-container">
|
||||
<!-- Header with user info -->
|
||||
<view class="user-header">
|
||||
<view class="user-info">
|
||||
<image class="user-avatar" :src="userAvatar" mode="aspectFill"></image>
|
||||
<view class="user-details">
|
||||
<text class="user-name">{{ profile.username ?? $t('user.center.unnamed') }}</text>
|
||||
<view class="edit-profile-link" @click="navigateToProfile">
|
||||
<text class="edit-text">{{ $t('user.center.edit_profile') }}</text>
|
||||
<text class="edit-icon">✏️</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- User stats -->
|
||||
<view class="stats-container">
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ userStats.trainings }}</text>
|
||||
<text class="stat-label">{{ $t('user.center.trainings') }}</text>
|
||||
</view>
|
||||
<view class="stat-divider"></view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ userStats.points }}</text>
|
||||
<text class="stat-label">{{ $t('user.center.points') }}</text>
|
||||
</view>
|
||||
<view class="stat-divider"></view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ userStats.streak }}</text>
|
||||
<text class="stat-label">{{ $t('user.center.streak') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Main menu sections -->
|
||||
<view class="menu-sections">
|
||||
<!-- Training section -->
|
||||
<view class="menu-section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">{{ $t('user.center.training') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section-items">
|
||||
<view class="menu-item" @click="navigateTo('/pages/training/records')"> <view class="menu-icon training-records">📊</view>
|
||||
<text class="menu-text">{{ $t('user.center.training_records') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
<view class="menu-item" @click="navigateTo('/pages/training/plans')">
|
||||
<view class="menu-icon training-plans">📋</view>
|
||||
<text class="menu-text">{{ $t('user.center.training_plans') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
|
||||
<view class="menu-item" @click="navigateTo('/pages/training/reports')">
|
||||
<view class="menu-icon reports">📈</view>
|
||||
<text class="menu-text">{{ $t('user.center.reports') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Account section -->
|
||||
<view class="menu-section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">{{ $t('user.center.account') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section-items"> <view class="menu-item" @click="navigateTo('/pages/user/profile')">
|
||||
<view class="menu-icon profile">👤</view>
|
||||
<text class="menu-text">{{ $t('user.center.profile') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
|
||||
<view class="menu-item" @click="navigateTo('/pages/user/devices')">
|
||||
<view class="menu-icon devices">📱</view>
|
||||
<text class="menu-text">{{ $t('user.center.devices') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
|
||||
<view class="menu-item" @click="navigateTo('/pages/user/notifications')">
|
||||
<view class="menu-icon notifications">🔔</view>
|
||||
<text class="menu-text">{{ $t('user.center.notifications') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Settings section -->
|
||||
<view class="menu-section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">{{ $t('user.center.settings') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section-items"> <view class="menu-item" @click="navigateTo('/pages/settings/app')">
|
||||
<view class="menu-icon app-settings">⚙️</view>
|
||||
<text class="menu-text">{{ $t('user.center.app_settings') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
|
||||
<view class="menu-item" @click="navigateTo('/pages/settings/about')">
|
||||
<view class="menu-icon about">ℹ️</view>
|
||||
<text class="menu-text">{{ $t('user.center.about') }}</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
</view>
|
||||
</view> <!-- Logout button -->
|
||||
<button class="logout-button" @click="showLogoutConfirm">
|
||||
{{ $t('user.center.logout') }}
|
||||
</button>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- Bottom section -->
|
||||
<view class="bottom-section">
|
||||
<!-- Footer content or spacing -->
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="uts">
|
||||
import { AkReqOptions, AkReqResponse, AkReqError } from '@/uni_modules/ak-req/index.uts';
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import type { UserProfile,UserStats } from './types.uts';
|
||||
import { setUserProfile } from '@/utils/store.uts';
|
||||
import { AkSupaSelectOptions } from '@/components/supadb/aksupa.uts'
|
||||
import { switchLocale, getCurrentLocale } from '@/utils/utils.uts';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
isLoading: true,
|
||||
userStats: {
|
||||
trainings: 0,
|
||||
points: 0,
|
||||
streak: 0
|
||||
} as UserStats,
|
||||
profile: {
|
||||
username: '',
|
||||
email: ''
|
||||
} as UserProfile,
|
||||
userAvatar: '/static/default-avatar.png',
|
||||
currentLocale: getCurrentLocale()
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
},
|
||||
onShow() {
|
||||
this.loadProfile();
|
||||
this.loadUserStats();
|
||||
}, methods: {
|
||||
toggleLanguage() {
|
||||
const newLocale = this.currentLocale === 'zh-CN' ? 'en-US' : 'zh-CN';
|
||||
switchLocale(newLocale);
|
||||
this.currentLocale = newLocale;
|
||||
|
||||
uni.showToast({
|
||||
title: this.$t('user.center.language_switched'),
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
async loadUserStats() {
|
||||
// 这里可以根据 userStore.profile.id 拉取真实数据
|
||||
this.userStats = {
|
||||
trainings: 12,
|
||||
points: 480,
|
||||
streak: 5
|
||||
};
|
||||
|
||||
},
|
||||
async loadProfile() {
|
||||
const user = supa.user;
|
||||
if (user==null || user.email=='') {
|
||||
console.log('null user:',user)
|
||||
this.profile.email = '';
|
||||
return;
|
||||
}
|
||||
const filter = `id.eq.${user.id}`;
|
||||
const options = { single: true } as AkSupaSelectOptions;
|
||||
const { data, error } = await supa.select('ak_users', filter, options);
|
||||
// 判断 data 是否为数组且为空
|
||||
if(Array.isArray(data) && data.length> 0) {
|
||||
console.log(data)
|
||||
let prodata= data[0] as UTSJSONObject;
|
||||
this.profile = {
|
||||
id: user.id as string,
|
||||
username: prodata.getString("username")??"",
|
||||
email: prodata.getString("email")??"",
|
||||
gender: prodata.getString("gender"),
|
||||
birthday: prodata.getString("birthday"),
|
||||
height_cm: prodata.getNumber("height_cm"),
|
||||
weight_kg: prodata.getNumber("weight_kg"),
|
||||
bio: prodata.getString("bio"),
|
||||
avatar_url: prodata.getString("avatar_url")??'/static/logo.png',
|
||||
preferred_language: prodata.getString("preferred_language"),
|
||||
}
|
||||
this.userAvatar = this.profile.avatar_url!!;
|
||||
|
||||
}
|
||||
else {
|
||||
this.profile.id= user.getString("id");
|
||||
this.profile.username = user.getString("username")??"";
|
||||
this.profile.email = user.getString("email")??"";
|
||||
let newProfile = new UTSJSONObject(this.profile);
|
||||
const insertResult = await supa.from('ak_users').insert(newProfile).execute();
|
||||
console.log(insertResult)
|
||||
if (insertResult.error==null) {
|
||||
setUserProfile(this.profile);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
navigateToProfile() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/profile'
|
||||
});
|
||||
},
|
||||
navigateTo(url: string) {
|
||||
const implementedPages = ['/pages/user/profile'];
|
||||
if (implementedPages.includes(url)) {
|
||||
uni.navigateTo({ url });
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: 'Coming soon',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
showLogoutConfirm() {
|
||||
uni.showModal({
|
||||
title: this.$t('user.center.logout_confirm_title'),
|
||||
content: this.$t('user.center.logout_confirm_message'),
|
||||
cancelText: this.$t('user.center.cancel'),
|
||||
confirmText: this.$t('user.center.confirm'),
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.handleLogout();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
async handleLogout() {
|
||||
try {
|
||||
await supa.signOut();
|
||||
uni.showToast({
|
||||
title: this.$t('user.center.logout_success'),
|
||||
icon: 'success'
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login'
|
||||
});
|
||||
}, 1000);
|
||||
} catch (err) {
|
||||
console.error('Logout error:', err);
|
||||
uni.showToast({
|
||||
title: this.$t('user.center.logout_error'),
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* Page wrapper for full screen utilization */
|
||||
.page-wrapper {
|
||||
/* #ifdef APP-PLUS */ display: flex;
|
||||
flex-direction: column;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS *//* #endif */
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
/* Top section - Fixed header */
|
||||
.top-section {
|
||||
/* #ifdef APP-PLUS */
|
||||
flex: 0 0 auto;
|
||||
height: 100rpx;
|
||||
/* #endif */ /* #ifndef APP-PLUS */
|
||||
height: 120rpx;
|
||||
/* #endif */
|
||||
position: relative;
|
||||
background-image: linear-gradient(to right, #2196f3, #03a9f4);
|
||||
}
|
||||
|
||||
/* Main content section - Scrollable */
|
||||
.main-section {
|
||||
/* #ifdef APP-PLUS */
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
flex-grow: 1;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Bottom section - Fixed footer */
|
||||
.bottom-section {
|
||||
/* #ifdef APP-PLUS */
|
||||
flex: 0 0 auto;
|
||||
height: 50rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 60rpx;
|
||||
/* #endif */
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.user-center-container {
|
||||
/* #ifdef APP-PLUS */ /* #endif */
|
||||
/* #ifndef APP-PLUS *//* #endif */
|
||||
background-color: #f8f9fa;
|
||||
/* #ifdef APP-PLUS */
|
||||
padding-bottom: 40rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding-bottom: 50rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Language switch button */
|
||||
.language-switch {
|
||||
position: absolute;
|
||||
/* #ifdef APP-PLUS */
|
||||
top: 20rpx;
|
||||
right: 30rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
top: 30rpx;
|
||||
right: 40rpx;
|
||||
/* #endif */
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
/* User header */
|
||||
.user-header {
|
||||
background-image: linear-gradient(to right, #2196f3, #03a9f4);
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 30rpx 30rpx 25rpx;
|
||||
border-bottom-left-radius: 25rpx;
|
||||
border-bottom-right-radius: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 60rpx 40rpx 30rpx;
|
||||
border-bottom-left-radius: 30rpx;
|
||||
border-bottom-right-radius: 30rpx;
|
||||
/* #endif */
|
||||
color: #fff;
|
||||
box-shadow: 0 10rpx 20rpx rgba(3, 169, 244, 0.2);
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 90rpx;
|
||||
height: 90rpx;
|
||||
border-radius: 45rpx;
|
||||
border: 3rpx solid #fff;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 60rpx;
|
||||
border: 4rpx solid #fff;
|
||||
/* #endif */
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.user-details {
|
||||
flex: 1;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-left: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-left: 30rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.user-name {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-bottom: 8rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 36rpx;
|
||||
margin-bottom: 10rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.edit-profile-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.edit-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.edit-icon {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-left: 5rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-left: 6rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Stats container */
|
||||
.stats-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-top: 30rpx;
|
||||
border-radius: 12rpx;
|
||||
padding: 15rpx 0;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-top: 40rpx;
|
||||
border-radius: 15rpx;
|
||||
padding: 20rpx 0;
|
||||
/* #endif */
|
||||
background-color: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 32rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-top: 4rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-top: 6rpx;
|
||||
/* #endif */
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.stat-divider {
|
||||
width: 2rpx;
|
||||
background-color: rgba(255, 255, 255, 0.3);
|
||||
/* #ifdef APP-PLUS */
|
||||
margin: 8rpx 0;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin: 10rpx 0;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Menu sections */
|
||||
.menu-sections {
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 30rpx 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 40rpx 30rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.menu-section {
|
||||
background-color: #fff;
|
||||
/* #ifdef APP-PLUS */
|
||||
border-radius: 15rpx;
|
||||
margin-bottom: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
border-radius: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
/* #endif */
|
||||
overflow: hidden;
|
||||
box-shadow: 0 5rpx 15rpx rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.section-header {
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 30rpx;
|
||||
/* #endif */
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 22rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.section-items {
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 0 10rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 0 15rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 20rpx 10rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 30rpx 15rpx;
|
||||
/* #endif */
|
||||
border-bottom: 2rpx solid #f8f8f8;
|
||||
}
|
||||
|
||||
.menu-item:last-child {
|
||||
border-bottom: none;
|
||||
flex-direction: row;
|
||||
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 45rpx;
|
||||
height: 45rpx;
|
||||
border-radius: 22rpx;
|
||||
margin-right: 15rpx;
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
border-radius: 30rpx;
|
||||
margin-right: 20rpx;
|
||||
font-size: 30rpx;
|
||||
/* #endif */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.menu-text {
|
||||
flex: 1;
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 22rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.menu-arrow {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 36rpx;
|
||||
/* #endif */
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
/* Menu icons with different colors */
|
||||
.training-records {
|
||||
background-color: #e3f2fd;
|
||||
}
|
||||
|
||||
.training-plans {
|
||||
background-color: #e8f5e9;
|
||||
}
|
||||
|
||||
.reports {
|
||||
background-color: #f3e5f5;
|
||||
}
|
||||
|
||||
.profile {
|
||||
background-color: #e1f5fe;
|
||||
}
|
||||
|
||||
.devices {
|
||||
background-color: #fffde7;
|
||||
}
|
||||
|
||||
.notifications {
|
||||
background-color: #fff3e0;
|
||||
}
|
||||
|
||||
.app-settings {
|
||||
background-color: #e0f2f1;
|
||||
}
|
||||
|
||||
.about {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* Logout button */
|
||||
.logout-button {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 70rpx;
|
||||
font-size: 26rpx;
|
||||
margin: 20rpx 0 15rpx;
|
||||
border-radius: 35rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 90rpx;
|
||||
font-size: 32rpx;
|
||||
margin: 30rpx 0 20rpx;
|
||||
border-radius: 45rpx;
|
||||
/* #endif */
|
||||
background-color: #fff; color: #f44336;
|
||||
font-weight: normal;
|
||||
border: 2rpx solid #fce4ec;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Center row utility class */
|
||||
.center-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center; /* 如有需<E69C89>?*/
|
||||
}
|
||||
|
||||
.language-btn {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
border-radius: 30rpx;
|
||||
font-size: 22rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
font-size: 28rpx;
|
||||
/* #endif */ background-color: rgba(33, 150, 243, 0.8);
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.3);
|
||||
text-align: center;
|
||||
box-shadow: 0 4rpx 12rpx rgba(33, 150, 243, 0.3);
|
||||
}
|
||||
</style>
|
||||
495
pages/user/forgot-password.uvue
Normal file
495
pages/user/forgot-password.uvue
Normal file
@@ -0,0 +1,495 @@
|
||||
<template>
|
||||
<!-- Single scrollable container for tablet optimization -->
|
||||
<scroll-view class="forgot-password-container" scroll-y="true" show-scrollbar="false">
|
||||
<!-- Language switch positioned absolutely -->
|
||||
<view class="language-switch">
|
||||
<button class="language-btn" @click="toggleLanguage">
|
||||
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- Main content wrapper -->
|
||||
<view class="content-wrapper">
|
||||
<!-- Logo and title section -->
|
||||
<view class="logo-section">
|
||||
<text class="app-title">Akmon</text>
|
||||
<text class="page-title">{{ $t('user.forgot_password.title') }}</text>
|
||||
<text class="page-subtitle">{{ $t('user.forgot_password.subtitle') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Form container with content inside -->
|
||||
<view class="form-container">
|
||||
<view v-if="!resetEmailSent">
|
||||
<form @submit="onSubmit">
|
||||
<!-- Email input -->
|
||||
<view class="input-group" :class="{ 'input-error': emailError }">
|
||||
<text class="input-label">{{ $t('user.forgot_password.email') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
name="email"
|
||||
type="text"
|
||||
v-model="email"
|
||||
:placeholder="$t('user.forgot_password.email_placeholder')"
|
||||
@blur="validateEmail"
|
||||
/>
|
||||
<text v-if="emailError" class="error-text">{{ emailError }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Submit button -->
|
||||
<button form-type="submit" class="submit-button" :disabled="isLoading" :loading="isLoading">
|
||||
{{ $t('user.forgot_password.submit_button') }}
|
||||
</button>
|
||||
|
||||
<!-- General error message -->
|
||||
<text v-if="generalError" class="general-error">{{ generalError }}</text>
|
||||
</form>
|
||||
|
||||
<!-- Login option -->
|
||||
<view class="login-option">
|
||||
<text class="login-text">{{ $t('user.forgot_password.remember_password') }}</text>
|
||||
<text class="login-link" @click="navigateToLogin">{{ $t('user.forgot_password.login') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Success message -->
|
||||
<view v-else class="success-container">
|
||||
<view class="success-icon">✓</view>
|
||||
<text class="success-title">{{ $t('user.forgot_password.email_sent_title') }}</text>
|
||||
<text class="success-message">{{ $t('user.forgot_password.email_sent_message') }}</text>
|
||||
<button class="back-button" @click="navigateToLogin">
|
||||
{{ $t('user.forgot_password.back_to_login') }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script lang="uts">
|
||||
import supa from '@/components/supadb/aksupainstance.uts';
|
||||
import { switchLocale, getCurrentLocale } from '@/utils/utils.uts';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
email: "",
|
||||
emailError: "",
|
||||
generalError: "",
|
||||
isLoading: false,
|
||||
resetEmailSent: false,
|
||||
currentLocale: getCurrentLocale()
|
||||
};
|
||||
}, methods: {
|
||||
toggleLanguage() {
|
||||
const newLocale = this.currentLocale === 'zh-CN' ? 'en-US' : 'zh-CN';
|
||||
switchLocale(newLocale);
|
||||
this.currentLocale = newLocale;
|
||||
|
||||
uni.showToast({
|
||||
title: this.$t('user.forgot_password.language_switched'),
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
onSubmit(e: UniFormSubmitEvent) {
|
||||
this.handleResetRequest();
|
||||
},
|
||||
validateEmail() {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (this.email == null || this.email === "") {
|
||||
this.emailError = this.$t('user.forgot_password.email_required');
|
||||
return false;
|
||||
} else if (!emailRegex.test(this.email)) {
|
||||
this.emailError = this.$t('user.forgot_password.email_invalid');
|
||||
return false;
|
||||
} else {
|
||||
this.emailError = '';
|
||||
return true;
|
||||
}
|
||||
},
|
||||
async handleResetRequest() {
|
||||
this.generalError = '';
|
||||
if (!this.validateEmail()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
try {
|
||||
// Call Supabase password reset method
|
||||
const result = await supa.resetPassword(this.email);
|
||||
|
||||
// Show success view
|
||||
this.resetEmailSent = true;
|
||||
|
||||
} catch (err) {
|
||||
console.error("Password reset error:", err);
|
||||
|
||||
// Format error message
|
||||
if (typeof err === 'object' && err !== null) {
|
||||
const errObj = err as UniError;
|
||||
if (typeof errObj.message === 'string') {
|
||||
// If we have a specific error message from Supabase
|
||||
this.generalError = errObj.message;
|
||||
} else {
|
||||
this.generalError = this.$t('user.forgot_password.unknown_error');
|
||||
}
|
||||
} else {
|
||||
this.generalError = this.$t('user.forgot_password.unknown_error');
|
||||
}
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
navigateToLogin() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/login'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* Single scrollable container for tablet optimization */
|
||||
.forgot-password-container {
|
||||
height: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 40rpx;
|
||||
/* #endif */
|
||||
background-color: #f8f9fa;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Content wrapper for centered layout */
|
||||
.content-wrapper {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
padding-bottom: 40rpx;
|
||||
/* 确保内容足够高以触发滚动 */
|
||||
/* #ifdef APP-PLUS */
|
||||
min-height: 800rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
min-height: 1000rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Language switch button - positioned absolutely */
|
||||
.language-switch {
|
||||
position: absolute;
|
||||
/* #ifdef APP-PLUS */
|
||||
top: 30rpx;
|
||||
right: 30rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
top: 40rpx;
|
||||
right: 40rpx;
|
||||
/* #endif */
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.language-btn {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
border-radius: 25rpx;
|
||||
font-size: 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
font-size: 28rpx;
|
||||
/* #endif */ background-color: rgba(33, 150, 243, 0.8); color: #fff;
|
||||
font-weight: normal;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.3);
|
||||
text-align: center;
|
||||
box-shadow: 0 4rpx 12rpx rgba(33, 150, 243, 0.3);
|
||||
}
|
||||
|
||||
/* Logo and title section */
|
||||
.logo-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-top: 60rpx;
|
||||
margin-bottom: 30rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-top: 80rpx;
|
||||
margin-bottom: 40rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.app-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 36rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 32rpx;
|
||||
margin-top: 12rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 48rpx;
|
||||
margin-top: 20rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.page-subtitle {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-top: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-top: 10rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Form container */
|
||||
.form-container {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
max-width: 500rpx;
|
||||
padding: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
max-width: 680rpx;
|
||||
padding: 40rpx;
|
||||
/* #endif */
|
||||
background-color: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Input groups */
|
||||
.input-group {
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-bottom: 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-bottom: 30rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.input-label {
|
||||
/* #ifdef APP-PLUS */ font-size: 20rpx;
|
||||
margin-bottom: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-bottom: 10rpx;
|
||||
/* #endif */
|
||||
font-weight: normal;
|
||||
color: #333;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 60rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 22rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 90rpx;
|
||||
padding: 0 30rpx;
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
border-radius: 10rpx;
|
||||
border: 2rpx solid #ddd;
|
||||
background-color: #f9f9f9;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.input-error .input-field {
|
||||
border-color: #f44336;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-top: 4rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-top: 6rpx;
|
||||
/* #endif */
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
/* Submit button */
|
||||
.submit-button {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 60rpx;
|
||||
font-size: 24rpx;
|
||||
margin: 12rpx 0;
|
||||
border-radius: 30rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 90rpx;
|
||||
font-size: 32rpx;
|
||||
margin: 20rpx 0; border-radius: 45rpx;
|
||||
/* #endif */
|
||||
background-image: linear-gradient(to right, #2196f3, #03a9f4); color: #fff;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
box-shadow: 0 10rpx 20rpx rgba(3, 169, 244, 0.2);
|
||||
}
|
||||
|
||||
.submit-button:disabled {
|
||||
background: #ccc;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* General error */
|
||||
.general-error {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
color: #f44336;
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-top: 12rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-top: 20rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Login option */
|
||||
.login-option {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-top: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-top: 40rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.login-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-right: 5rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-right: 8rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.login-link {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx; /* #endif */
|
||||
color: #2196f3;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
/* Success container */
|
||||
.success-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 12rpx 0;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 20rpx 0;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.success-icon {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 75rpx;
|
||||
height: 75rpx;
|
||||
font-size: 38rpx;
|
||||
margin-bottom: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
font-size: 60rpx;
|
||||
margin-bottom: 30rpx;
|
||||
/* #endif */
|
||||
background-color: #4caf50;
|
||||
color: white;
|
||||
/* #ifdef APP-PLUS */
|
||||
border-radius: 75rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
border-radius: 120rpx;
|
||||
/* #endif */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.success-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-bottom: 12rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 36rpx;
|
||||
margin-bottom: 20rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-bottom: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-bottom: 40rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.back-button {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 60rpx;
|
||||
font-size: 24rpx;
|
||||
border-radius: 30rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 90rpx;
|
||||
font-size: 32rpx;
|
||||
border-radius: 45rpx;
|
||||
/* #endif */
|
||||
background-color: #f0f0f0; color: #333;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
690
pages/user/login.uvue
Normal file
690
pages/user/login.uvue
Normal file
@@ -0,0 +1,690 @@
|
||||
<template>
|
||||
<view class="page-wrapper">
|
||||
<scroll-view class="login-container" scroll-y="true" show-scrollbar="false">
|
||||
<!-- Language switch button -->
|
||||
<view class="language-switch">
|
||||
<button class="language-btn" @click="toggleLanguage">
|
||||
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- Unified content container -->
|
||||
<view class="content-wrapper">
|
||||
<!-- Logo section -->
|
||||
<view class="logo-section">
|
||||
<text class="app-title">Trainning Monitor</text>
|
||||
<text class="page-title">{{ $t('user.login.title') }}</text>
|
||||
<text class="page-subtitle">{{ $t('user.login.subtitle') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Form container -->
|
||||
<view class="form-container">
|
||||
<form @submit="onSubmit">
|
||||
<!-- Email input -->
|
||||
<view class="input-group" :class="{ 'input-error': emailError }">
|
||||
<text class="input-label">{{ $t('user.login.email') }}</text>
|
||||
<input class="input-field" name="email" type="text" :value="email"
|
||||
:placeholder="$t('user.login.email_placeholder')" @blur="validateEmail" />
|
||||
<text v-if="emailError" class="error-text">{{ emailError }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Password input -->
|
||||
<view class="input-group" :class="{ 'input-error': passwordError }">
|
||||
<text class="input-label">{{ $t('user.login.password') }}</text>
|
||||
<view class="password-input-container">
|
||||
<input class="input-field" name="password" :type="showPassword ? 'text' : 'password'"
|
||||
:value="password" :placeholder="$t('user.login.password_placeholder')"
|
||||
@blur="validatePassword" />
|
||||
<view class="password-toggle" @click="showPassword = !showPassword">
|
||||
<text class="toggle-icon">{{ showPassword ? '👁' : '🙈' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="passwordError" class="error-text">{{ passwordError }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Additional options -->
|
||||
<view class="options-row">
|
||||
<view class="remember-me">
|
||||
<checkbox value="rememberMe" color="#2196f3" />
|
||||
<text class="remember-me-text">{{ $t('user.login.remember_me') }}</text>
|
||||
</view>
|
||||
<text class="forgot-password" @click="navigateToForgotPassword">
|
||||
{{ $t('user.login.forgot_password') }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- Login button -->
|
||||
<button form-type="submit" class="login-button" :disabled="isLoading" :loading="isLoading">
|
||||
{{ $t('user.login.login_button') }}
|
||||
</button>
|
||||
|
||||
<!-- General error message -->
|
||||
<text v-if="generalError" class="general-error">{{ generalError }}</text>
|
||||
</form>
|
||||
|
||||
<!-- Social login options -->
|
||||
<view class="social-login">
|
||||
<text class="social-login-text">{{ $t('user.login.or_login_with') }}</text>
|
||||
<view class="social-buttons">
|
||||
<button class="social-button wechat" @click="socialLogin('WeChat')">
|
||||
<text class="social-icon">🟩</text>
|
||||
</button>
|
||||
<button class="social-button qq" @click="socialLogin('QQ')">
|
||||
<text class="social-icon">🔵</text>
|
||||
</button>
|
||||
<button class="social-button sms" @click="socialLogin('SMS')">
|
||||
<text class="social-icon">✉️</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Register option -->
|
||||
<view class="register-option">
|
||||
<text class="register-text">{{ $t('user.login.no_account') }}</text>
|
||||
<text class="register-link"
|
||||
@click="navigateToRegister">{{ $t('user.login.register_now') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</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')
|
||||
}, 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' });
|
||||
// 跳转至运动页面
|
||||
if(TABORPAGE)
|
||||
{
|
||||
uni.switchTab({ url: HOME_REDIRECT });
|
||||
}
|
||||
else{
|
||||
uni.navigateTo({ url: HOME_REDIRECT });
|
||||
}
|
||||
|
||||
|
||||
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 wrapper for full screen */
|
||||
.page-wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
.login-container {
|
||||
width: 100%;
|
||||
background-image: linear-gradient(to bottom right, #f8f9fa, #e9ecef);
|
||||
}
|
||||
|
||||
/* Content wrapper - single scrollable container */
|
||||
.content-wrapper {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 20rpx 15rpx;
|
||||
min-height: 800rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 30rpx 25rpx;
|
||||
min-height: 1000rpx;
|
||||
/* #endif */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Language switch button - adjusted for single container */
|
||||
.language-switch {
|
||||
position: absolute;
|
||||
/* #ifdef APP-PLUS */
|
||||
top: 30rpx;
|
||||
right: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
top: 40rpx;
|
||||
right: 35rpx;
|
||||
/* #endif */
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.language-btn {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
border-radius: 25rpx;
|
||||
font-size: 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 70rpx;
|
||||
height: 70rpx;
|
||||
border-radius: 35rpx;
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
background-color: rgba(33, 150, 243, 0.8);
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.3);
|
||||
text-align: center;
|
||||
box-shadow: 0 3rpx 10rpx rgba(33, 150, 243, 0.3);
|
||||
}
|
||||
|
||||
/* Logo section - very compact */
|
||||
.logo-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin: 15rpx 0 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin: 25rpx 0 30rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.app-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 36rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 32rpx;
|
||||
margin-top: 8rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 48rpx;
|
||||
margin-top: 15rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.page-subtitle {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-top: 4rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-top: 8rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Form container - optimized for tablets */
|
||||
.form-container {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
max-width: 620rpx;
|
||||
padding: 18rpx;
|
||||
margin: 0 auto;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
max-width: 560rpx;
|
||||
padding: 32rpx;
|
||||
margin: 0 auto;
|
||||
/* #endif */
|
||||
background-color: #ffffff;
|
||||
border-radius: 12rpx;
|
||||
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Input groups - more compact */
|
||||
.input-group {
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-bottom: 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-bottom: 25rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.input-label {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-bottom: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 26rpx;
|
||||
margin-bottom: 8rpx;
|
||||
/* #endif */
|
||||
font-weight: normal;
|
||||
color: #333;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 60rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 22rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 80rpx;
|
||||
padding: 0 25rpx;
|
||||
font-size: 26rpx;
|
||||
/* #endif */
|
||||
border-radius: 8rpx;
|
||||
border: 2rpx solid #ddd;
|
||||
background-color: #f9f9f9;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.input-error .input-field {
|
||||
border-color: #f44336;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-top: 5rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-top: 6rpx;
|
||||
/* #endif */
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
/* Password input */
|
||||
.password-input-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.password-toggle {
|
||||
position: absolute;
|
||||
/* #ifdef APP-PLUS */
|
||||
right: 12rpx;
|
||||
top: 16rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
right: 18rpx;
|
||||
top: 22rpx;
|
||||
/* #endif */
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.toggle-icon {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 26rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Options row - more compact */
|
||||
.options-row {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin: 10rpx 0 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin: 15rpx 0 25rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.remember-me {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.remember-me-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-left: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-left: 8rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.forgot-password {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
/* Login button - more compact */
|
||||
.login-button {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 60rpx;
|
||||
font-size: 24rpx;
|
||||
margin: 12rpx 0;
|
||||
border-radius: 30rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 80rpx;
|
||||
font-size: 30rpx;
|
||||
margin: 18rpx 0; border-radius: 40rpx;
|
||||
/* #endif */
|
||||
background-image: linear-gradient(to right, #2196f3, #03a9f4);
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
box-shadow: 0 8rpx 16rpx rgba(3, 169, 244, 0.2);
|
||||
}
|
||||
|
||||
.login-button:disabled {
|
||||
background: #ccc;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* General error */
|
||||
.general-error {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
color: #f44336;
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-top: 10rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-top: 15rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Social login - very compact */
|
||||
.social-login {
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-top: 15rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-top: 25rpx;
|
||||
/* #endif */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.social-login-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-bottom: 10rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-bottom: 15rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
.social-buttons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.social-buttons .social-button {
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-left: 10rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-left: 12rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.social-buttons .social-button:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.social-button {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
border-radius: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 70rpx;
|
||||
height: 70rpx;
|
||||
border-radius: 35rpx;
|
||||
/* #endif */
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.social-icon {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 32rpx;
|
||||
/* #endif */
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.google {
|
||||
background-color: #db4437;
|
||||
}
|
||||
|
||||
.facebook {
|
||||
background-color: #4267B2;
|
||||
}
|
||||
|
||||
.apple {
|
||||
background-color: #000;
|
||||
}
|
||||
|
||||
.wechat {
|
||||
background-color: #1aad19;
|
||||
}
|
||||
|
||||
.qq {
|
||||
background-color: #498ad5;
|
||||
}
|
||||
|
||||
.sms {
|
||||
background-color: #ffb300;
|
||||
}
|
||||
|
||||
/* Register option - compact */
|
||||
.register-option {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-top: 15rpx;
|
||||
margin-bottom: 5rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-top: 25rpx;
|
||||
margin-bottom: 10rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.register-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-right: 4rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-right: 6rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.register-link {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
color: #2196f3;
|
||||
font-weight: normal;
|
||||
}
|
||||
</style>
|
||||
1070
pages/user/profile.uvue
Normal file
1070
pages/user/profile.uvue
Normal file
File diff suppressed because it is too large
Load Diff
634
pages/user/register.uvue
Normal file
634
pages/user/register.uvue
Normal file
@@ -0,0 +1,634 @@
|
||||
<template>
|
||||
<!-- Single scrollable container for tablet optimization -->
|
||||
<scroll-view class="register-container" scroll-y="true" show-scrollbar="false"> <!-- Language switch positioned absolutely -->
|
||||
<view class="language-switch">
|
||||
<button class="language-btn" @click="toggleLanguage">
|
||||
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- Main content wrapper -->
|
||||
<view class="content-wrapper">
|
||||
<!-- Logo and title section -->
|
||||
<view class="logo-section">
|
||||
<text class="app-title">Akmon</text>
|
||||
<text class="page-title">{{ $t('user.register.title') }}</text>
|
||||
<text class="page-subtitle">{{ $t('user.register.subtitle') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Form container with all content inside -->
|
||||
<view class="form-container">
|
||||
<form @submit="onSubmit">
|
||||
<!-- Email input -->
|
||||
<view class="input-group" :class="{ 'input-error': emailError }">
|
||||
<text class="input-label">{{ $t('user.register.email') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
name="email"
|
||||
type="text"
|
||||
v-model="email"
|
||||
:placeholder="$t('user.register.email_placeholder')"
|
||||
@blur="validateEmail"
|
||||
/>
|
||||
<text v-if="emailError" class="error-text">{{ emailError }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Password input -->
|
||||
<view class="input-group" :class="{ 'input-error': passwordError }">
|
||||
<text class="input-label">{{ $t('user.register.password') }}</text>
|
||||
<view class="password-input-container">
|
||||
<input
|
||||
class="input-field"
|
||||
name="password"
|
||||
:type="showPassword ? 'text' : 'password'"
|
||||
v-model="password"
|
||||
:placeholder="$t('user.register.password_placeholder')"
|
||||
@blur="validatePassword" /> <view class="password-toggle" @click="togglePasswordVisibility">
|
||||
<text class="toggle-icon">{{ showPassword ? '👁' : '🙈' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="passwordError" class="error-text">{{ passwordError }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Confirm Password input -->
|
||||
<view class="input-group" :class="{ 'input-error': confirmPasswordError }">
|
||||
<text class="input-label">{{ $t('user.register.confirm_password') }}</text>
|
||||
<view class="password-input-container">
|
||||
<input
|
||||
class="input-field"
|
||||
name="confirmPassword"
|
||||
:type="showConfirmPassword ? 'text' : 'password'"
|
||||
v-model="confirmPassword"
|
||||
:placeholder="$t('user.register.confirm_password_placeholder')"
|
||||
@blur="validateConfirmPassword" /> <view class="password-toggle" @click="toggleConfirmPasswordVisibility">
|
||||
<text class="toggle-icon">{{ showConfirmPassword ? '👁' : '🙈' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="confirmPasswordError" class="error-text">{{ confirmPasswordError }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Username input (optional) -->
|
||||
<view class="input-group" :class="{ 'input-error': usernameError }">
|
||||
<text class="input-label">{{ $t('user.register.username') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
name="username"
|
||||
type="text"
|
||||
v-model="username"
|
||||
:placeholder="$t('user.register.username_placeholder')"
|
||||
@blur="validateUsername"
|
||||
/>
|
||||
<text v-if="usernameError" class="error-text">{{ usernameError }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Terms and conditions -->
|
||||
<view class="checkbox-container" :class="{ 'input-error': termsError }">
|
||||
<checkbox :checked="agreeTerms" @click="agreeTerms = !agreeTerms" color="#2196f3" />
|
||||
<view class="terms-text">
|
||||
<text>{{ $t('user.register.agree_terms_part1') }} </text>
|
||||
<text class="terms-link" @click="showTerms">{{ $t('user.register.terms_link') }}</text>
|
||||
<text>{{ $t('user.register.agree_terms_part2') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="termsError" class="error-text terms-error">{{ termsError }}</text>
|
||||
|
||||
<!-- Register button -->
|
||||
<button form-type="submit" class="register-button" :disabled="isLoading" :loading="isLoading">
|
||||
{{ $t('user.register.button') }}
|
||||
</button>
|
||||
|
||||
<!-- General error message -->
|
||||
<text v-if="generalError" class="general-error">{{ generalError }}</text>
|
||||
</form>
|
||||
|
||||
<!-- Login option -->
|
||||
<view class="login-option">
|
||||
<text class="login-text">{{ $t('user.register.already_account') }}</text>
|
||||
<text class="login-link" @click="navigateToLogin">{{ $t('user.register.login') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script lang="uts">
|
||||
import type { AkReqOptions, AkReqResponse, AkReqError } from '@/uni_modules/ak-req/index.uts';
|
||||
import supa from '@/components/supadb/aksupainstance.uts';
|
||||
import { switchLocale, getCurrentLocale } from '@/utils/utils.uts';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
email: "",
|
||||
password: "",
|
||||
confirmPassword: "",
|
||||
username: "",
|
||||
emailError: "",
|
||||
passwordError: "",
|
||||
confirmPasswordError: "",
|
||||
usernameError: "",
|
||||
termsError: "",
|
||||
generalError: "",
|
||||
isLoading: false,
|
||||
showPassword: false,
|
||||
showConfirmPassword: false,
|
||||
agreeTerms: false,
|
||||
currentLocale: getCurrentLocale()
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
toggleLanguage() {
|
||||
const newLocale = this.currentLocale === 'zh-CN' ? 'en-US' : 'zh-CN';
|
||||
switchLocale(newLocale);
|
||||
this.currentLocale = newLocale;
|
||||
|
||||
uni.showToast({
|
||||
title: this.$t('user.register.language_switched'),
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
onSubmit(e: UniFormSubmitEvent) {
|
||||
this.handleRegister();
|
||||
},
|
||||
togglePasswordVisibility() {
|
||||
this.showPassword = !this.showPassword;
|
||||
},
|
||||
toggleConfirmPasswordVisibility() {
|
||||
this.showConfirmPassword = !this.showConfirmPassword; },
|
||||
validateEmail() {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (this.email.trim() === "") {
|
||||
this.emailError = this.$t('user.register.email_required');
|
||||
return false;
|
||||
} else if (!emailRegex.test(this.email)) {
|
||||
this.emailError = this.$t('user.register.email_invalid');
|
||||
return false;
|
||||
} else {
|
||||
this.emailError = '';
|
||||
return true;
|
||||
}
|
||||
},
|
||||
validatePassword() {
|
||||
if (this.password.trim() === "") {
|
||||
this.passwordError = this.$t('user.register.password_required');
|
||||
return false;
|
||||
} else if (this.password.length < 6) {
|
||||
this.passwordError = this.$t('user.register.password_too_short');
|
||||
return false;
|
||||
} else {
|
||||
this.passwordError = '';
|
||||
this.validateConfirmPassword(); // Re-validate confirm password when password changes
|
||||
return true;
|
||||
}
|
||||
},
|
||||
validateConfirmPassword() {
|
||||
if (this.confirmPassword.trim() === "") {
|
||||
this.confirmPasswordError = this.$t('user.register.confirm_password_required');
|
||||
return false;
|
||||
} else if (this.confirmPassword !== this.password) {
|
||||
this.confirmPasswordError = this.$t('user.register.passwords_not_match');
|
||||
return false;
|
||||
} else {
|
||||
this.confirmPasswordError = '';
|
||||
return true;
|
||||
}
|
||||
},
|
||||
validateUsername() {
|
||||
if (this.username.trim() !== "" && this.username.length < 3) {
|
||||
this.usernameError = this.$t('user.register.username_too_short');
|
||||
return false;
|
||||
} else {
|
||||
this.usernameError = '';
|
||||
return true;
|
||||
}
|
||||
},
|
||||
validateTerms() {
|
||||
if (!this.agreeTerms) {
|
||||
this.termsError = this.$t('user.register.terms_required');
|
||||
return false;
|
||||
} else {
|
||||
this.termsError = '';
|
||||
return true;
|
||||
}
|
||||
},
|
||||
validateForm() {
|
||||
const emailValid = this.validateEmail();
|
||||
const passwordValid = this.validatePassword();
|
||||
const confirmPasswordValid = this.validateConfirmPassword();
|
||||
const usernameValid = this.validateUsername();
|
||||
const termsValid = this.validateTerms();
|
||||
|
||||
return emailValid && passwordValid && confirmPasswordValid && usernameValid && termsValid; },
|
||||
randomPasswordHash(password: String): String {
|
||||
const salt = Math.random().toString(36).substring(2, 10);
|
||||
const base = password + salt + Date.now();
|
||||
return btoa(base);
|
||||
},
|
||||
async handleRegister() {
|
||||
this.generalError = '';
|
||||
if (!this.validateForm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
try {
|
||||
console.log('register: attempting to create account for', this.email);
|
||||
|
||||
// Call signup method from supa
|
||||
const result = await supa.signUp(
|
||||
this.email, this.password
|
||||
);
|
||||
|
||||
if (result!=null && result.user!=null) {
|
||||
// Show success message
|
||||
uni.showToast({
|
||||
title: this.$t('user.register.success'),
|
||||
icon: 'success'
|
||||
});
|
||||
const user=result.get("user") as UTSJSONObject;
|
||||
const auth_id =user.get("id")
|
||||
// Create user profile in ak_users table
|
||||
const userData = {
|
||||
auth_id: auth_id,
|
||||
// auth_id:1,
|
||||
email: this.email,
|
||||
username: this.username ?? this.email.split('@')[0],
|
||||
password_hash: this.randomPasswordHash(this.password)
|
||||
// preferred_language: this.$locale
|
||||
} as UTSJSONObject;
|
||||
|
||||
try {
|
||||
await supa.insert('ak_users', userData );
|
||||
} catch (profileErr) {
|
||||
console.error('Failed to create user profile:', profileErr);
|
||||
// Continue anyway, as auth account was created
|
||||
}
|
||||
|
||||
// Redirect to login page after registration
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/user/login'
|
||||
});
|
||||
}, 1500);
|
||||
} else {
|
||||
throw new Error(this.$t('user.register.failed'));
|
||||
}
|
||||
} catch (err) {
|
||||
const errObj = err as UniError; // or UtsError
|
||||
if (typeof errObj.message === 'string') {
|
||||
this.generalError = errObj.message;
|
||||
} else {
|
||||
this.generalError = this.$t('user.register.unknown_error');
|
||||
}
|
||||
}
|
||||
this.isLoading = false;
|
||||
},
|
||||
navigateToLogin() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/login'
|
||||
});
|
||||
},
|
||||
showTerms() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/terms'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* Single scrollable container for tablet optimization */
|
||||
.register-container {
|
||||
width: 100%; /* #ifdef APP-PLUS */
|
||||
padding: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 40rpx;
|
||||
/* #endif */
|
||||
background-color: #f8f9fa;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Content wrapper for centered layout */
|
||||
.content-wrapper {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
padding-bottom: 40rpx;
|
||||
/* 确保内容足够高以触发滚动 */
|
||||
/* #ifdef APP-PLUS */
|
||||
min-height: 1000rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
min-height: 1200rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Language switch button - positioned absolutely */
|
||||
.language-switch {
|
||||
position: absolute;
|
||||
/* #ifdef APP*/
|
||||
top: 30rpx;
|
||||
right: 50rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
top: 40rpx;
|
||||
right: 40rpx;
|
||||
/* #endif */
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.language-btn {
|
||||
/* #ifdef APP-PLUS */
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
border-radius: 25rpx;
|
||||
font-size: 18rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
font-size: 28rpx;
|
||||
/* #endif */ background-color: rgba(33, 150, 243, 0.8);
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.3);
|
||||
text-align: center;
|
||||
box-shadow: 0 4rpx 12rpx rgba(33, 150, 243, 0.3);
|
||||
}
|
||||
|
||||
/* Logo and title section */
|
||||
.logo-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-top: 60rpx;
|
||||
margin-bottom: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-top: 80rpx;
|
||||
margin-bottom: 40rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.app-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 36rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 32rpx;
|
||||
margin-top: 12rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 48rpx;
|
||||
margin-top: 20rpx;
|
||||
/* #endif */
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.page-subtitle {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-top: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-top: 10rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Form container */
|
||||
.form-container {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
max-width: 500rpx;
|
||||
padding: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
max-width: 680rpx;
|
||||
padding: 40rpx;
|
||||
/* #endif */
|
||||
background-color: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Input groups */
|
||||
.input-group {
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-bottom: 15rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-bottom: 30rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.input-label {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-bottom: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-bottom: 10rpx;
|
||||
/* #endif */
|
||||
font-weight: 400;
|
||||
color: #333;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 60rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 22rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 90rpx;
|
||||
padding: 0 30rpx;
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
border-radius: 10rpx;
|
||||
border: 2rpx solid #ddd;
|
||||
background-color: #f9f9f9;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.input-error .input-field {
|
||||
border-color: #f44336;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-top: 4rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-top: 6rpx;
|
||||
/* #endif */
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
/* Password input */
|
||||
.password-input-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.password-toggle {
|
||||
position: absolute;
|
||||
/* #ifdef APP-PLUS */
|
||||
right: 12rpx;
|
||||
top: 17rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
right: 20rpx;
|
||||
top: 25rpx;
|
||||
/* #endif */
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.toggle-icon {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 30rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Checkbox for terms */
|
||||
.checkbox-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-bottom: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-bottom: 10rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.terms-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 18rpx;
|
||||
margin-left: 6rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 26rpx;
|
||||
margin-left: 10rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
flex: 1;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.terms-link {
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
.terms-error {
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-bottom: 12rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-bottom: 20rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Register button */
|
||||
.register-button {
|
||||
width: 100%;
|
||||
/* #ifdef APP-PLUS */
|
||||
height: 60rpx;
|
||||
font-size: 24rpx;
|
||||
margin: 12rpx 0;
|
||||
border-radius: 30rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
height: 90rpx;
|
||||
font-size: 32rpx;
|
||||
margin: 20rpx 0; border-radius: 45rpx;
|
||||
/* #endif */
|
||||
background-image: linear-gradient(to right, #2196f3, #03a9f4);
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
box-shadow: 0 10rpx 20rpx rgba(3, 169, 244, 0.2);
|
||||
}
|
||||
|
||||
.register-button[disabled] {
|
||||
background: #ccc;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* General error */
|
||||
.general-error {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
color: #f44336;
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-top: 12rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-top: 20rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
/* Login option */
|
||||
.login-option {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
/* #ifdef APP-PLUS */
|
||||
margin-top: 25rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
margin-top: 40rpx;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.login-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-right: 5rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
margin-right: 8rpx;
|
||||
/* #endif */
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.login-link {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
color: #2196f3;
|
||||
font-weight: normal;
|
||||
}
|
||||
</style>
|
||||
31
pages/user/types.uts
Normal file
31
pages/user/types.uts
Normal file
@@ -0,0 +1,31 @@
|
||||
// 用户基础信息类型
|
||||
export type UserProfile ={
|
||||
id?: string;
|
||||
username: string;
|
||||
email: string;
|
||||
gender?: string;
|
||||
birthday?: string;
|
||||
height_cm?: number;
|
||||
weight_kg?: number;
|
||||
bio?: string;
|
||||
avatar_url?: string;
|
||||
preferred_language?: string;
|
||||
role?:string;
|
||||
school_id?: string; // 所属学校ID
|
||||
grade_id?: string; // 所属年级ID
|
||||
class_id?: string; // 所属班级ID
|
||||
}
|
||||
|
||||
// 语言选项类型 - 对应 ak_languages 表
|
||||
export type LanguageOption = {
|
||||
id: string; // UUID
|
||||
code: string; // 语言代码,如 'zh-CN', 'en-US'
|
||||
name: string; // 英文名称
|
||||
native_name: string; // 本地语言名称
|
||||
}
|
||||
|
||||
export type UserStats = {
|
||||
trainings: number;
|
||||
points: number;
|
||||
streak: number;
|
||||
}
|
||||
Reference in New Issue
Block a user