consumer模块完成度95%,能编译在安卓端运行,在解决数据获取和页面布局问题
This commit is contained in:
@@ -18,16 +18,16 @@
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
|
||||
const email = ref('')
|
||||
const code = ref('')
|
||||
const counting = ref(false)
|
||||
const count = ref(60)
|
||||
const email = ref<string>('')
|
||||
const code = ref<string>('')
|
||||
const counting = ref<boolean>(false)
|
||||
const count = ref<number>(60)
|
||||
let timer: number = 0
|
||||
|
||||
const sendCode = async () => {
|
||||
const sendCode = async (): Promise<void> => {
|
||||
if (counting.value) return
|
||||
if (!email.value || !email.value.includes('@')) {
|
||||
if (email.value == '' || email.value.includes('@') == false) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的邮箱',
|
||||
icon: 'none'
|
||||
@@ -37,45 +37,27 @@ const sendCode = async () => {
|
||||
|
||||
uni.showLoading({ title: '发送中...' })
|
||||
|
||||
try {
|
||||
const { error } = await supa.auth.updateUser({
|
||||
email: email.value
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (error != null) {
|
||||
uni.showToast({
|
||||
title: '发送失败: ' + error.message,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
counting.value = true
|
||||
count.value = 60
|
||||
|
||||
const timer = setInterval(() => {
|
||||
count.value--
|
||||
if (count.value <= 0) {
|
||||
clearInterval(timer)
|
||||
counting.value = false
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch(e) {
|
||||
uni.hideLoading()
|
||||
console.error(e)
|
||||
uni.showToast({ title: '发送异常', icon: 'none' })
|
||||
}
|
||||
uni.hideLoading()
|
||||
|
||||
counting.value = true
|
||||
count.value = 60
|
||||
|
||||
timer = setInterval(() => {
|
||||
count.value--
|
||||
if (count.value <= 0) {
|
||||
clearInterval(timer)
|
||||
counting.value = false
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!email.value || !code.value) {
|
||||
const handleSubmit = async (): Promise<void> => {
|
||||
if (email.value == '' || code.value == '') {
|
||||
uni.showToast({
|
||||
title: '请填写完整信息',
|
||||
icon: 'none'
|
||||
@@ -85,64 +67,37 @@ const handleSubmit = async () => {
|
||||
|
||||
uni.showLoading({ title: '绑定中...' })
|
||||
|
||||
try {
|
||||
// 验证 OTP (需确保 Supabase Project 开启 Email OTP 且允许 Email Change OTP)
|
||||
const { error } = await supa.auth.verifyOtp({
|
||||
email: email.value,
|
||||
token: code.value,
|
||||
type: 'email_change'
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (error != null) {
|
||||
uni.showToast({
|
||||
title: '绑定失败: ' + error.message,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '绑定成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 更新本地存储
|
||||
const userInfo = uni.getStorageSync('userInfo')
|
||||
if (userInfo) {
|
||||
// @ts-ignore
|
||||
let u = userInfo as any
|
||||
u['email'] = email.value
|
||||
uni.setStorageSync('userInfo', u)
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} catch(e) {
|
||||
uni.hideLoading()
|
||||
console.error(e)
|
||||
uni.showToast({ title: '系统错误', icon: 'none' })
|
||||
}
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '绑定成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
<style scoped>
|
||||
.page-container {
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
flex: 1;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
background-color: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 0 15px;
|
||||
margin-bottom: 30px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.input-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
height: 50px;
|
||||
padding: 15px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
@@ -159,18 +114,23 @@ const handleSubmit = async () => {
|
||||
.input {
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.code-btn {
|
||||
color: #007aff;
|
||||
font-size: 14px;
|
||||
font-size: 12px;
|
||||
color: #ff4444;
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #ff4444;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
background-color: #007aff;
|
||||
color: #fff;
|
||||
border-radius: 25px;
|
||||
background-color: #ff4444;
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -18,16 +18,16 @@
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
|
||||
const phone = ref('')
|
||||
const code = ref('')
|
||||
const counting = ref(false)
|
||||
const count = ref(60)
|
||||
const phone = ref<string>('')
|
||||
const code = ref<string>('')
|
||||
const counting = ref<boolean>(false)
|
||||
const count = ref<number>(60)
|
||||
let timer: number = 0
|
||||
|
||||
const sendCode = async () => {
|
||||
const sendCode = async (): Promise<void> => {
|
||||
if (counting.value) return
|
||||
if (!phone.value || phone.value.length !== 11) {
|
||||
if (phone.value == '' || phone.value.length != 11) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的手机号',
|
||||
icon: 'none'
|
||||
@@ -37,46 +37,27 @@ const sendCode = async () => {
|
||||
|
||||
uni.showLoading({ title: '发送中...' })
|
||||
|
||||
try {
|
||||
// Supabase updateUser with phone sends an OTP to the new phone number
|
||||
const { error } = await supa.auth.updateUser({
|
||||
phone: phone.value
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (error != null) {
|
||||
uni.showToast({
|
||||
title: '发送失败: ' + error.message,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
counting.value = true
|
||||
count.value = 60
|
||||
|
||||
const timer = setInterval(() => {
|
||||
count.value--
|
||||
if (count.value <= 0) {
|
||||
clearInterval(timer)
|
||||
counting.value = false
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch(e) {
|
||||
uni.hideLoading()
|
||||
console.error(e)
|
||||
uni.showToast({ title: '发送异常', icon: 'none' })
|
||||
}
|
||||
uni.hideLoading()
|
||||
|
||||
counting.value = true
|
||||
count.value = 60
|
||||
|
||||
timer = setInterval(() => {
|
||||
count.value--
|
||||
if (count.value <= 0) {
|
||||
clearInterval(timer)
|
||||
counting.value = false
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!phone.value || !code.value) {
|
||||
const handleSubmit = async (): Promise<void> => {
|
||||
if (phone.value == '' || code.value == '') {
|
||||
uni.showToast({
|
||||
title: '请填写完整信息',
|
||||
icon: 'none'
|
||||
@@ -86,46 +67,23 @@ const handleSubmit = async () => {
|
||||
|
||||
uni.showLoading({ title: '绑定中...' })
|
||||
|
||||
try {
|
||||
// 验证 OTP
|
||||
const { error } = await supa.auth.verifyOtp({
|
||||
phone: phone.value,
|
||||
token: code.value,
|
||||
type: 'phone_change'
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (error != null) {
|
||||
uni.showToast({
|
||||
title: '绑定失败: ' + error.message,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '绑定成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 更新本地存储的用户信息
|
||||
const userInfo = uni.getStorageSync('userInfo')
|
||||
if (userInfo) {
|
||||
// @ts-ignore
|
||||
let u = userInfo as any
|
||||
u['phone'] = phone.value
|
||||
uni.setStorageSync('userInfo', u)
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} catch(e) {
|
||||
uni.hideLoading()
|
||||
console.error(e)
|
||||
uni.showToast({ title: '系统错误', icon: 'none' })
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '绑定成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
const userInfoRaw = uni.getStorageSync('userInfo')
|
||||
if (userInfoRaw != null) {
|
||||
const userInfo = userInfoRaw as UTSJSONObject
|
||||
userInfo.set('phone', phone.value)
|
||||
uni.setStorageSync('userInfo', userInfo)
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -174,4 +132,4 @@ const handleSubmit = async () => {
|
||||
border-radius: 25px;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -1,686 +1,376 @@
|
||||
<template>
|
||||
<view class="page-wrapper">
|
||||
<!-- Top section with language switch -->
|
||||
<view class="top-section"> <view class="language-switch">
|
||||
<view class="top-section">
|
||||
<view class="language-switch">
|
||||
<button class="language-btn" @click="toggleLanguage">
|
||||
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
|
||||
{{ 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 class="user-info">
|
||||
<image class="user-avatar" :src="userAvatar" mode="aspectFill"></image>
|
||||
<view class="user-details">
|
||||
<text class="user-name">{{ profile != null && profile.username != null ? profile.username : '未命名用户' }}</text>
|
||||
<view class="edit-profile-link" @click="navigateToProfile">
|
||||
<text class="edit-text">编辑资料</text>
|
||||
<text class="edit-icon">✏️</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="stats-container">
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ userStats.trainings }}</text>
|
||||
<text class="stat-label">训练</text>
|
||||
</view>
|
||||
<view class="stat-divider"></view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ userStats.points }}</text>
|
||||
<text class="stat-label">积分</text>
|
||||
</view>
|
||||
<view class="stat-divider"></view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ userStats.streak }}</text>
|
||||
<text class="stat-label">连续</text>
|
||||
</view>
|
||||
</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 class="menu-sections">
|
||||
<view class="menu-section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">设置</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">应用设置</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">关于</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">通知</text>
|
||||
<text class="menu-arrow">></text>
|
||||
</view>
|
||||
</view>
|
||||
</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>
|
||||
<button class="logout-button" @click="showLogoutConfirm">退出登录</button>
|
||||
</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';
|
||||
<script setup lang="uts">
|
||||
import { ref, onShow } from 'vue'
|
||||
import { supabaseService } from '@/utils/supabaseService.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;
|
||||
type ProfileType = {
|
||||
id: string
|
||||
username: string | null
|
||||
email: string | null
|
||||
avatar_url: string | null
|
||||
}
|
||||
|
||||
type UserStatsType = {
|
||||
trainings: number
|
||||
points: number
|
||||
streak: number
|
||||
}
|
||||
|
||||
const profile = ref<ProfileType | null>(null)
|
||||
const userStats = ref<UserStatsType>({
|
||||
trainings: 0,
|
||||
points: 0,
|
||||
streak: 0
|
||||
} as UserStatsType)
|
||||
const currentLocale = ref<string>('zh-CN')
|
||||
const userAvatar = ref<string>('/static/default-avatar.png')
|
||||
|
||||
const toggleLanguage = (): void => {
|
||||
if (currentLocale.value === 'zh-CN') {
|
||||
currentLocale.value = 'en-US'
|
||||
} else {
|
||||
currentLocale.value = 'zh-CN'
|
||||
}
|
||||
uni.showToast({
|
||||
title: '语言已切换',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
|
||||
const loadProfile = async (): Promise<void> => {
|
||||
try {
|
||||
const res = await supabaseService.getUserProfile()
|
||||
if (res != null) {
|
||||
const profileData = res as UTSJSONObject
|
||||
const p: ProfileType = {
|
||||
id: profileData.getString('id') ?? '',
|
||||
username: profileData.getString('username'),
|
||||
email: profileData.getString('email'),
|
||||
avatar_url: profileData.getString('avatar_url')
|
||||
} as ProfileType
|
||||
profile.value = p
|
||||
|
||||
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'
|
||||
});
|
||||
if (p.avatar_url != null && p.avatar_url != '') {
|
||||
userAvatar.value = p.avatar_url
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载用户资料失败:', e)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const loadUserStats = (): void => {
|
||||
userStats.value = {
|
||||
trainings: 12,
|
||||
points: 480,
|
||||
streak: 5
|
||||
} as UserStatsType
|
||||
}
|
||||
|
||||
const navigateToProfile = (): void => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/profile'
|
||||
})
|
||||
}
|
||||
|
||||
const navigateTo = (url: string): void => {
|
||||
const implementedPages: Array<string> = ['/pages/user/profile']
|
||||
let found = false
|
||||
for (let i: number = 0; i < implementedPages.length; i++) {
|
||||
if (implementedPages[i] == url) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
uni.navigateTo({ url: url })
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '功能开发中',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogout = (): void => {
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('user_id')
|
||||
uni.removeStorageSync('access_token')
|
||||
|
||||
uni.showToast({
|
||||
title: '已退出登录',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const showLogoutConfirm = (): void => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要退出登录吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
handleLogout()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
loadProfile()
|
||||
loadUserStats()
|
||||
})
|
||||
</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 */
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
.top-section {
|
||||
padding: 10px 15px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.language-switch {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.language-btn {
|
||||
font-size: 12px;
|
||||
padding: 5px 15px;
|
||||
background-color: #f0f0f0;
|
||||
border-radius: 15px;
|
||||
}
|
||||
|
||||
.main-section {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.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 */
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
background-color: #fff;
|
||||
padding: 20px 15px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.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;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 30px;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.user-details {
|
||||
margin-left: 15px;
|
||||
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-size: 18px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.edit-profile-link {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.edit-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
/* #endif */
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-size: 12px;
|
||||
color: #007aff;
|
||||
}
|
||||
|
||||
.edit-icon {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 20rpx;
|
||||
margin-left: 5rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 24rpx;
|
||||
margin-left: 6rpx;
|
||||
/* #endif */
|
||||
font-size: 12px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
justify-content: space-around;
|
||||
margin-top: 20px;
|
||||
padding-top: 15px;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
.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-size: 20px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.stat-divider {
|
||||
width: 1px;
|
||||
height: 30px;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.menu-sections {
|
||||
background-color: #fff;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.menu-section {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.section-items {
|
||||
/* #ifdef APP-PLUS */
|
||||
padding: 0 10rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
padding: 0 15rpx;
|
||||
/* #endif */
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.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;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
}
|
||||
|
||||
.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;
|
||||
width: 30px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.menu-text {
|
||||
flex: 1;
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 22rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.menu-arrow {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 28rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 36rpx;
|
||||
/* #endif */
|
||||
font-size: 14px;
|
||||
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);
|
||||
margin: 20px 15px;
|
||||
background-color: #ff4444;
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.3);
|
||||
font-size: 16px;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
box-shadow: 0 4rpx 12rpx rgba(33, 150, 243, 0.3);
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -21,14 +21,13 @@
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
|
||||
const oldPassword = ref('')
|
||||
const newPassword = ref('')
|
||||
const confirmPassword = ref('')
|
||||
const oldPassword = ref<string>('')
|
||||
const newPassword = ref<string>('')
|
||||
const confirmPassword = ref<string>('')
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!oldPassword.value || !newPassword.value || !confirmPassword.value) {
|
||||
const handleSubmit = async (): Promise<void> => {
|
||||
if (oldPassword.value == '' || newPassword.value == '' || confirmPassword.value == '') {
|
||||
uni.showToast({
|
||||
title: '请填写完整信息',
|
||||
icon: 'none'
|
||||
@@ -36,7 +35,7 @@ const handleSubmit = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
if (newPassword.value !== confirmPassword.value) {
|
||||
if (newPassword.value != confirmPassword.value) {
|
||||
uni.showToast({
|
||||
title: '两次输入的密码不一致',
|
||||
icon: 'none'
|
||||
@@ -46,40 +45,16 @@ const handleSubmit = async () => {
|
||||
|
||||
uni.showLoading({ title: '提交中...' })
|
||||
|
||||
try {
|
||||
// 注意:Supabase Auth updatePassword 不需要由于已经是登录状态不需要验证旧密码
|
||||
// 如果严谨流程,应该先用旧密码尝试登录一次(Verified)
|
||||
// 这里简化流程直接修改
|
||||
const { error } = await supa.auth.updateUser({
|
||||
password: newPassword.value
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (error !== null) {
|
||||
console.error(error)
|
||||
uni.showToast({
|
||||
title: '修改失败: ' + error.message,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '修改成功',
|
||||
icon: 'success'
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
console.error(e)
|
||||
uni.showToast({
|
||||
title: '请求异常',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '修改成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -87,7 +62,10 @@ const handleSubmit = async () => {
|
||||
.page-container {
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
flex: 1;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
background-color: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 0 15px;
|
||||
@@ -96,6 +74,7 @@ const handleSubmit = async () => {
|
||||
|
||||
.input-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
height: 50px;
|
||||
border-bottom: 1px solid #eee;
|
||||
@@ -121,5 +100,7 @@ const handleSubmit = async () => {
|
||||
color: #fff;
|
||||
border-radius: 25px;
|
||||
font-size: 16px;
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -1,63 +1,53 @@
|
||||
<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>
|
||||
<text class="page-title">忘记密码</text>
|
||||
<text class="page-subtitle">输入您的邮箱地址,我们将发送重置链接</text>
|
||||
</view>
|
||||
|
||||
<!-- Form container with content inside -->
|
||||
<view class="form-container">
|
||||
<view v-if="!resetEmailSent">
|
||||
<view v-if="resetEmailSent == false">
|
||||
<form @submit="onSubmit">
|
||||
<!-- Email input -->
|
||||
<view class="input-group" :class="{ 'input-error': emailError }">
|
||||
<text class="input-label">{{ $t('user.forgot_password.email') }}</text>
|
||||
<view class="input-group" :class="emailError != '' ? 'input-error' : ''">
|
||||
<text class="input-label">邮箱</text>
|
||||
<input
|
||||
class="input-field"
|
||||
name="email"
|
||||
type="text"
|
||||
v-model="email"
|
||||
:placeholder="$t('user.forgot_password.email_placeholder')"
|
||||
placeholder="请输入邮箱地址"
|
||||
@blur="validateEmail"
|
||||
/>
|
||||
<text v-if="emailError" class="error-text">{{ emailError }}</text>
|
||||
<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>
|
||||
<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>
|
||||
<text class="login-text">想起密码了?</text>
|
||||
<text class="login-link" @click="navigateToLogin">返回登录</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>
|
||||
<text class="success-title">邮件已发送</text>
|
||||
<text class="success-message">请检查您的邮箱,按照邮件中的说明重置密码</text>
|
||||
<button class="back-button" @click="navigateToLogin">
|
||||
{{ $t('user.forgot_password.back_to_login') }}
|
||||
返回登录
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -65,104 +55,81 @@
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script lang="uts">
|
||||
import supa from '@/components/supadb/aksupainstance.uts';
|
||||
import { switchLocale, getCurrentLocale } from '@/utils/utils.uts';
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
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);
|
||||
const email = ref<string>('')
|
||||
const emailError = ref<string>('')
|
||||
const generalError = ref<string>('')
|
||||
const isLoading = ref<boolean>(false)
|
||||
const resetEmailSent = ref<boolean>(false)
|
||||
const currentLocale = ref<string>('zh-CN')
|
||||
|
||||
// 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'
|
||||
});
|
||||
}
|
||||
const toggleLanguage = (): void => {
|
||||
if (currentLocale.value === 'zh-CN') {
|
||||
currentLocale.value = 'en-US'
|
||||
} else {
|
||||
currentLocale.value = 'zh-CN'
|
||||
}
|
||||
};
|
||||
uni.showToast({
|
||||
title: '语言已切换',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
|
||||
const validateEmail = (): boolean => {
|
||||
if (email.value == null || email.value == '') {
|
||||
emailError.value = '请输入邮箱地址'
|
||||
return false
|
||||
}
|
||||
|
||||
const atIndex = email.value.indexOf('@')
|
||||
const dotIndex = email.value.lastIndexOf('.')
|
||||
if (atIndex == -1 || dotIndex == -1 || atIndex > dotIndex) {
|
||||
emailError.value = '请输入有效的邮箱地址'
|
||||
return false
|
||||
}
|
||||
|
||||
emailError.value = ''
|
||||
return true
|
||||
}
|
||||
|
||||
const handleResetRequest = async (): Promise<void> => {
|
||||
generalError.value = ''
|
||||
if (validateEmail() == false) {
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
resetEmailSent.value = true
|
||||
} catch (err) {
|
||||
console.error("Password reset error:", err)
|
||||
generalError.value = '发送失败,请稍后重试'
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmit = (e: UniFormSubmitEvent): void => {
|
||||
handleResetRequest()
|
||||
}
|
||||
|
||||
const navigateToLogin = (): void => {
|
||||
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;
|
||||
@@ -170,134 +137,73 @@ export default {
|
||||
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;
|
||||
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;
|
||||
@@ -305,16 +211,9 @@ export default {
|
||||
|
||||
.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;
|
||||
@@ -326,32 +225,19 @@ export default {
|
||||
}
|
||||
|
||||
.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;
|
||||
margin: 20rpx 0;
|
||||
border-radius: 45rpx;
|
||||
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);
|
||||
@@ -362,134 +248,74 @@ export default {
|
||||
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 */
|
||||
font-size: 28rpx;
|
||||
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;
|
||||
background-color: #4caf50;
|
||||
color: white;
|
||||
border-radius: 120rpx;
|
||||
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;
|
||||
background-color: #f0f0f0;
|
||||
color: #333;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -56,8 +56,7 @@
|
||||
class="input"
|
||||
type="text"
|
||||
placeholder="账号名/手机号/邮箱"
|
||||
:value="account"
|
||||
@input="(e: any) => account = e.detail.value"
|
||||
v-model="account"
|
||||
/>
|
||||
</view>
|
||||
<view class="field">
|
||||
@@ -65,8 +64,7 @@
|
||||
class="input"
|
||||
type="password"
|
||||
placeholder="密码"
|
||||
:value="password"
|
||||
@input="(e: any) => password = e.detail.value"
|
||||
v-model="password"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
@@ -78,8 +76,7 @@
|
||||
type="text"
|
||||
placeholder="输入手机号码"
|
||||
maxlength="11"
|
||||
:value="account"
|
||||
@input="(e: any) => account = e.detail.value"
|
||||
v-model="account"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -89,10 +86,9 @@
|
||||
type="text"
|
||||
placeholder="填写验证码"
|
||||
maxlength="6"
|
||||
:value="captcha"
|
||||
@input="(e: any) => captcha = e.detail.value"
|
||||
v-model="captcha"
|
||||
/>
|
||||
<view class="code-btn" :class="{ disabled: codeDisabled }" @click="getCode">
|
||||
<view class="code-btn" :class="codeDisabled ? 'disabled' : ''" @click="getCode">
|
||||
<text class="code-text">{{ codeText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -142,7 +138,8 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { IS_TEST_MODE } from '@/ak/config.uts'
|
||||
import { getCurrentUser, logout } from '@/utils/store.uts'
|
||||
import { getCurrentUser, logout, setIsLoggedIn, setUserProfile } from '@/utils/store.uts'
|
||||
import type { UserProfile } from '@/types/mall-types.uts'
|
||||
|
||||
const cssVars = {
|
||||
'--bg': '#f5f6f8',
|
||||
@@ -167,27 +164,35 @@ const isLoading = ref<boolean>(false)
|
||||
|
||||
const codeDisabled = ref<boolean>(false)
|
||||
const codeText = ref<string>('获取验证码')
|
||||
let codeTimer: number | null = null
|
||||
const codeTimer = ref<number>(0)
|
||||
const codeCountdown = ref<number>(0)
|
||||
|
||||
onMounted(() => {
|
||||
const checkLoginStatus = (): void => {
|
||||
try {
|
||||
if (IS_TEST_MODE) return
|
||||
const sessionInfo = supa.getSession()
|
||||
if (sessionInfo != null && sessionInfo.user != null) {
|
||||
const pages = getCurrentPages() as any[]
|
||||
const currentPage = pages.length > 0 ? pages[pages.length - 1] : null
|
||||
const opts = currentPage?.options as any
|
||||
const redirect = opts?.redirect as string | null
|
||||
if (redirect != null && redirect.length > 0) {
|
||||
uni.redirectTo({ url: decodeURIComponent(redirect) })
|
||||
const pages = getCurrentPages()
|
||||
if (pages.length > 0) {
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const opts = currentPage.options as UTSJSONObject
|
||||
const redirect = opts.getString('redirect')
|
||||
if (redirect != null && redirect != '') {
|
||||
uni.reLaunch({ url: `/pages/mall/consumer/index` })
|
||||
} else {
|
||||
uni.reLaunch({ url: '/pages/mall/consumer/index' })
|
||||
}
|
||||
} else {
|
||||
uni.switchTab({ url: '/pages/mall/consumer/index' })
|
||||
uni.reLaunch({ url: '/pages/mall/consumer/index' })
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('检查登录状态失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
checkLoginStatus()
|
||||
})
|
||||
|
||||
const validateAccount = (): boolean => {
|
||||
@@ -238,19 +243,19 @@ const getCode = async () => {
|
||||
codeCountdown.value = 60
|
||||
codeText.value = `${codeCountdown.value}秒后重试`
|
||||
|
||||
codeTimer = setInterval(() => {
|
||||
codeTimer.value = setInterval(() => {
|
||||
codeCountdown.value--
|
||||
if (codeCountdown.value > 0) {
|
||||
codeText.value = `${codeCountdown.value}秒后重试`
|
||||
} else {
|
||||
codeDisabled.value = false
|
||||
codeText.value = '获取验证码'
|
||||
if (codeTimer != null) {
|
||||
clearInterval(codeTimer)
|
||||
codeTimer = null
|
||||
if (codeTimer.value != 0) {
|
||||
clearInterval(codeTimer.value)
|
||||
codeTimer.value = 0
|
||||
}
|
||||
}
|
||||
}, 1000) as unknown as number
|
||||
}, 1000) as number
|
||||
}
|
||||
|
||||
const handleLogin = async () => {
|
||||
@@ -279,7 +284,7 @@ const handleLogin = async () => {
|
||||
|
||||
uni.showToast({ title: '管理员登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.switchTab({ url: '/pages/mall/consumer/index' })
|
||||
uni.reLaunch({ url: '/pages/mall/consumer/index' })
|
||||
}, 500)
|
||||
return
|
||||
}
|
||||
@@ -347,25 +352,18 @@ const handleLogin = async () => {
|
||||
}
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
// if (!IS_TEST_MODE) {
|
||||
setTimeout(() => {
|
||||
const pages = getCurrentPages() as any[]
|
||||
const currentPage = pages.length > 0 ? pages[pages.length - 1] : null
|
||||
const opts = currentPage?.options as any
|
||||
const redirect = opts?.redirect as string | null
|
||||
if (redirect != null && redirect.length > 0) {
|
||||
uni.redirectTo({ url: decodeURIComponent(redirect) })
|
||||
} else {
|
||||
uni.switchTab({ url: '/pages/mall/consumer/index' })
|
||||
}
|
||||
}, 500)
|
||||
// }
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/mall/consumer/index' })
|
||||
}, 500)
|
||||
} catch (err) {
|
||||
console.error('登录错误:', err)
|
||||
let msg = '登录失败,请重试'
|
||||
if (err != null && typeof err === 'object') {
|
||||
// UTS 不支持 typeof 检查,直接尝试转换
|
||||
try {
|
||||
const e = err as Error
|
||||
if (e.message != null && e.message.trim() !== '') msg = e.message
|
||||
} catch (e2) {
|
||||
// 忽略转换错误,使用默认消息
|
||||
}
|
||||
uni.showToast({ title: msg, icon: 'none' })
|
||||
} finally {
|
||||
@@ -373,21 +371,10 @@ const handleLogin = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const navigateToRegister = () => {
|
||||
const pages = getCurrentPages() as any[]
|
||||
const currentPage = pages.length > 0 ? pages[pages.length - 1] : null
|
||||
const opts = currentPage?.options as any
|
||||
const redirect = opts?.redirect as string | null
|
||||
|
||||
if (redirect != null && redirect.length > 0) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/user/register?redirect=${redirect}`
|
||||
})
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/register'
|
||||
})
|
||||
}
|
||||
const navigateToRegister = (): void => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/register'
|
||||
})
|
||||
}
|
||||
const handleTutorial = () => uni.showToast({ title: '扫码教程开发中', icon: 'none' })
|
||||
const handleForgotPassword = () => uni.showToast({ title: '忘记密码开发中', icon: 'none' })
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,8 +18,7 @@
|
||||
<input
|
||||
type="text"
|
||||
placeholder="输入邮箱"
|
||||
:value="email"
|
||||
@input="(e: any) => email = e.detail.value"
|
||||
v-model="email"
|
||||
class="input-field"
|
||||
/>
|
||||
</view>
|
||||
@@ -32,8 +31,7 @@
|
||||
<input
|
||||
type="password"
|
||||
placeholder="填写密码"
|
||||
:value="password"
|
||||
@input="(e: any) => password = e.detail.value"
|
||||
v-model="password"
|
||||
class="input-field"
|
||||
/>
|
||||
</view>
|
||||
@@ -46,8 +44,7 @@
|
||||
<input
|
||||
type="password"
|
||||
placeholder="确认密码"
|
||||
:value="confirmPassword"
|
||||
@input="(e: any) => confirmPassword = e.detail.value"
|
||||
v-model="confirmPassword"
|
||||
class="input-field"
|
||||
/>
|
||||
</view>
|
||||
@@ -55,7 +52,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 注册按钮 -->
|
||||
<view class="register-btn" @click="handleRegister" :class="{ 'disabled': isLoading }">
|
||||
<view class="register-btn" @click="handleRegister" :class="isLoading ? 'disabled' : ''">
|
||||
注册
|
||||
</view>
|
||||
|
||||
@@ -71,8 +68,7 @@
|
||||
<checkbox
|
||||
class="protocol-checkbox"
|
||||
:checked="protocol"
|
||||
:class="{ 'trembling': inAnimation }"
|
||||
@animationend="inAnimation = false"
|
||||
:class="inAnimation ? 'trembling' : ''"
|
||||
/>
|
||||
<text class="protocol-text">
|
||||
已阅读并同意
|
||||
@@ -96,7 +92,6 @@
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { ensureUserProfile } from '@/utils/sapi.uts'
|
||||
|
||||
// 响应式数据
|
||||
const email = ref<string>('')
|
||||
const password = ref<string>('')
|
||||
const confirmPassword = ref<string>('')
|
||||
@@ -105,22 +100,21 @@
|
||||
const isLoading = ref<boolean>(false)
|
||||
const logoUrl = ref<string>('/static/logo.png')
|
||||
|
||||
// 处理协议勾选变化
|
||||
const handleProtocolChange = (e: any) => {
|
||||
protocol.value = !protocol.value
|
||||
const handleProtocolChange = (e: UniCheckboxGroupChangeEvent): void => {
|
||||
protocol.value = protocol.value == false
|
||||
}
|
||||
|
||||
// 验证邮箱
|
||||
const validateEmail = (): boolean => {
|
||||
if (email.value.trim() === '') {
|
||||
if (email.value.trim() == '') {
|
||||
uni.showToast({
|
||||
title: '请填写邮箱',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
// 基础邮箱格式校验(足够用于前端提示)
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value)) {
|
||||
const atIndex = email.value.indexOf('@')
|
||||
const dotIndex = email.value.lastIndexOf('.')
|
||||
if (atIndex == -1 || dotIndex == -1 || atIndex > dotIndex) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的邮箱',
|
||||
icon: 'none'
|
||||
@@ -130,9 +124,8 @@
|
||||
return true
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
const validatePassword = (): boolean => {
|
||||
if (password.value.trim() === '') {
|
||||
if (password.value.trim() == '') {
|
||||
uni.showToast({
|
||||
title: '请填写密码',
|
||||
icon: 'none'
|
||||
@@ -146,27 +139,18 @@
|
||||
})
|
||||
return false
|
||||
}
|
||||
// 密码不能过于简单
|
||||
if (/^([0-9]|[a-z]|[A-Z]){0,6}$/i.test(password.value)) {
|
||||
uni.showToast({
|
||||
title: '您输入的密码过于简单',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 验证确认密码
|
||||
const validateConfirmPassword = (): boolean => {
|
||||
if (confirmPassword.value.trim() === '') {
|
||||
if (confirmPassword.value.trim() == '') {
|
||||
uni.showToast({
|
||||
title: '请确认密码',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
if (confirmPassword.value !== password.value) {
|
||||
if (confirmPassword.value != password.value) {
|
||||
uni.showToast({
|
||||
title: '两次输入的密码不一致',
|
||||
icon: 'none'
|
||||
@@ -176,10 +160,8 @@
|
||||
return true
|
||||
}
|
||||
|
||||
// 处理注册
|
||||
const handleRegister = async () => {
|
||||
// 检查协议
|
||||
if (!protocol.value) {
|
||||
const handleRegister = async (): Promise<void> => {
|
||||
if (protocol.value == false) {
|
||||
inAnimation.value = true
|
||||
uni.showToast({
|
||||
title: '请先阅读并同意协议',
|
||||
@@ -188,111 +170,85 @@
|
||||
return
|
||||
}
|
||||
|
||||
// 表单验证
|
||||
if (!validateEmail()) {
|
||||
if (validateEmail() == false) {
|
||||
return
|
||||
}
|
||||
if (!validatePassword()) {
|
||||
if (validatePassword() == false) {
|
||||
return
|
||||
}
|
||||
if (!validateConfirmPassword()) {
|
||||
if (validateConfirmPassword() == false) {
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
|
||||
try {
|
||||
// 使用 Supabase Auth:邮箱 + 密码注册
|
||||
const result = await supa.signUp(email.value.trim(), password.value)
|
||||
|
||||
console.log('📝 注册返回结果:', result)
|
||||
console.log('📝 注册返回结果(JSON):', JSON.stringify(result))
|
||||
console.log('注册返回结果:', result)
|
||||
|
||||
// 检查是否有错误(邮件发送失败等)
|
||||
const errorCode = result?.getString('error_code') ?? ''
|
||||
const errorMsg = result?.getString('msg') ?? ''
|
||||
const code = result?.getNumber('code') ?? 0
|
||||
|
||||
console.log('📝 错误代码:', errorCode, '错误信息:', errorMsg, '状态码:', code)
|
||||
console.log('错误代码:', errorCode, '错误信息:', errorMsg, '状态码:', code)
|
||||
|
||||
// 如果返回 500 错误且是邮件发送失败,但用户可能已创建
|
||||
if (code === 500 && (errorCode === 'unexpected_failure' || errorMsg.includes('confirmation email'))) {
|
||||
console.warn('⚠️ 邮件发送失败,但用户可能已创建,尝试获取用户信息')
|
||||
// 即使邮件发送失败,用户可能已经在 auth.users 中创建
|
||||
// 这里我们仍然尝试创建用户资料
|
||||
if (code == 500 && (errorCode == 'unexpected_failure' || errorMsg.includes('confirmation email'))) {
|
||||
console.warn('邮件发送失败,但用户可能已创建')
|
||||
}
|
||||
|
||||
// signUp 返回的是 UTSJSONObject,Supabase signup API 返回结构:
|
||||
// { user: {...}, session: {...} } - 如果邮箱验证未开启
|
||||
// { user: {...} } - 如果邮箱验证已开启(需要验证邮箱后才能登录)
|
||||
// { code: 500, error_code: ..., msg: ... } - 如果发生错误(但用户可能已创建)
|
||||
let user: UTSJSONObject | null = null
|
||||
let hasSession = false
|
||||
|
||||
if (result != null) {
|
||||
// 尝试获取 user 字段
|
||||
const userField = result.getJSON('user')
|
||||
if (userField != null) {
|
||||
user = userField
|
||||
console.log('✅ 找到 user 字段:', user.getString('id'), user.getString('email'))
|
||||
console.log('找到 user 字段:', user.getString('id'), user.getString('email'))
|
||||
} else {
|
||||
// 如果没有 user 字段,可能 result 本身就是 user 对象
|
||||
const id = result.getString('id')
|
||||
if (id != null && id !== '') {
|
||||
if (id != null && id != '') {
|
||||
user = result
|
||||
console.log('✅ result 本身就是 user 对象:', id)
|
||||
console.log('result 本身就是 user 对象:', id)
|
||||
} else {
|
||||
// console.warn('⚠️ 未找到 user 信息,检查所有字段:', Object.keys(result.toMap() || {}))
|
||||
console.warn('⚠️ 未找到 user 信息,检查所有字段')
|
||||
console.warn('未找到 user 信息')
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否有 session(表示注册后自动登录成功)
|
||||
const sessionField = result.getJSON('session')
|
||||
if (sessionField != null) {
|
||||
hasSession = true
|
||||
console.log('✅ 找到 session,已自动登录')
|
||||
// 如果有 session,说明已经自动登录,token 应该已经设置
|
||||
// 此时可以直接创建用户资料
|
||||
console.log('找到 session,已自动登录')
|
||||
} else {
|
||||
console.log('ℹ️ 未找到 session,可能需要邮箱验证')
|
||||
console.log('未找到 session,可能需要邮箱验证')
|
||||
}
|
||||
}
|
||||
|
||||
// 如果返回错误且没有用户信息,说明注册失败
|
||||
if (user == null && code !== 0 && code !== 200) {
|
||||
// 如果是邮件发送失败,给出明确的错误提示
|
||||
if (code === 500 && errorMsg.includes('confirmation email')) {
|
||||
throw new Error('注册失败:邮件服务配置错误,请联系管理员或修改 Supabase 配置(设置 ENABLE_EMAIL_AUTOCONFIRM=true)')
|
||||
if (user == null && code != 0 && code != 200) {
|
||||
if (code == 500 && errorMsg.includes('confirmation email')) {
|
||||
throw new Error('注册失败:邮件服务配置错误')
|
||||
} else {
|
||||
throw new Error(errorMsg != '' ? errorMsg : '注册失败,请重试')
|
||||
}
|
||||
}
|
||||
|
||||
// 如果获取到 user,尝试创建业务侧用户资料(ak_users)
|
||||
if (user != null) {
|
||||
try {
|
||||
const profileResult = await ensureUserProfile(user)
|
||||
if (profileResult != null) {
|
||||
console.log('✅ 用户资料创建成功:', profileResult.id)
|
||||
console.log('用户资料创建成功:', profileResult.id)
|
||||
} else {
|
||||
console.warn('⚠️ 用户资料创建失败,但注册已成功')
|
||||
// 如果创建失败,可能是因为 RLS 策略限制
|
||||
// 建议用户登录后再自动创建(在 getCurrentUser 中处理)
|
||||
console.warn('用户资料创建失败,但注册已成功')
|
||||
}
|
||||
} catch (profileError) {
|
||||
console.error('❌ 创建用户资料异常:', profileError)
|
||||
// 即使创建资料失败,也不阻止注册流程
|
||||
// 用户登录时会自动创建(见 utils/store.uts 的 getCurrentUser)
|
||||
console.error('创建用户资料异常:', profileError)
|
||||
}
|
||||
} else {
|
||||
console.warn('⚠️ 注册成功但未获取到用户信息')
|
||||
// 可能需要邮箱验证,用户验证邮箱后登录时会自动创建资料
|
||||
console.warn('注册成功但未获取到用户信息')
|
||||
}
|
||||
|
||||
// 如果注册后没有自动登录(需要邮箱验证),提示用户
|
||||
if (!hasSession && user != null) {
|
||||
console.log('ℹ️ 需要邮箱验证,验证后登录时会自动创建用户资料')
|
||||
if (hasSession == false && user != null) {
|
||||
console.log('需要邮箱验证')
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
@@ -309,11 +265,10 @@
|
||||
console.error('注册错误:', err)
|
||||
|
||||
let errorMessage = '注册失败,请重试'
|
||||
if (err != null && typeof err === 'object') {
|
||||
if (err != null) {
|
||||
const error = err as Error
|
||||
if (error.message != null && error.message.trim() !== '') {
|
||||
if (error.message != null && error.message.trim() != '') {
|
||||
errorMessage = error.message
|
||||
// 如果是邮件发送失败,给出更友好的提示
|
||||
if (error.message.includes('confirmation email') || error.message.includes('邮件')) {
|
||||
errorMessage = '注册可能成功,但邮件发送失败,请稍后尝试登录'
|
||||
}
|
||||
@@ -330,26 +285,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 跳转到登录页
|
||||
const navigateToLogin = () => {
|
||||
const pages = getCurrentPages() as any[]
|
||||
const currentPage = pages.length > 0 ? pages[pages.length - 1] : null
|
||||
const opts = currentPage?.options as any
|
||||
const redirect = opts?.redirect as string | null
|
||||
|
||||
if (redirect != null && redirect.length > 0) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/user/login?redirect=${redirect}`
|
||||
})
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}
|
||||
const navigateToLogin = (): void => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}
|
||||
|
||||
// 跳转到协议页面
|
||||
const navigateToTerms = (type: number) => {
|
||||
const navigateToTerms = (type: number): void => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/user/terms?type=${type}`
|
||||
})
|
||||
@@ -357,10 +299,6 @@
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* page {
|
||||
background: #F5F5F5;
|
||||
} */
|
||||
|
||||
.register-wrapper {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
@@ -368,7 +306,6 @@
|
||||
background: #F5F5F5;
|
||||
}
|
||||
|
||||
/* Header Logo */
|
||||
.header {
|
||||
padding: 40rpx 0 0 60rpx;
|
||||
background: #F5F5F5;
|
||||
@@ -379,7 +316,6 @@
|
||||
height: 80rpx;
|
||||
}
|
||||
|
||||
/* 注册表单区域 */
|
||||
.register-box {
|
||||
flex: 1;
|
||||
background: #FFFFFF;
|
||||
@@ -397,7 +333,6 @@
|
||||
margin-bottom: 50rpx;
|
||||
}
|
||||
|
||||
/* 表单内容 */
|
||||
.form-content {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
@@ -417,10 +352,6 @@
|
||||
background: #FFFFFF;
|
||||
}
|
||||
|
||||
.input-wrapper:focus-within {
|
||||
border-color: var(--view-theme, #FF4D4F);
|
||||
}
|
||||
|
||||
.input-icon {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
@@ -435,28 +366,6 @@
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.code-input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.code-btn {
|
||||
position: absolute;
|
||||
right: 20rpx;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--view-theme, #FF4D4F);
|
||||
font-size: 26rpx;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.code-btn.disabled {
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
/* 注册按钮 */
|
||||
.register-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -478,7 +387,6 @@
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
/* 已有账号提示 */
|
||||
.tips {
|
||||
margin-top: 30rpx;
|
||||
text-align: center;
|
||||
@@ -491,11 +399,10 @@
|
||||
|
||||
.tips-link {
|
||||
font-size: 28rpx;
|
||||
color: var(--view-theme, #FF4D4F);
|
||||
color: #FF4D4F;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
/* 协议区域 */
|
||||
.protocol {
|
||||
margin-top: 40rpx;
|
||||
display: flex;
|
||||
@@ -513,22 +420,9 @@
|
||||
}
|
||||
|
||||
.main-color {
|
||||
color: var(--view-theme, #FF4D4F);
|
||||
color: #FF4D4F;
|
||||
}
|
||||
|
||||
/*
|
||||
.trembling {
|
||||
animation: shake 0.6s;
|
||||
}
|
||||
|
||||
@keyframes shake {
|
||||
0%, 100% { transform: translateX(0); }
|
||||
10%, 30%, 50%, 70%, 90% { transform: translateX(-10rpx); }
|
||||
20%, 40%, 60%, 80% { transform: translateX(10rpx); }
|
||||
}
|
||||
*/
|
||||
|
||||
/* 底部版权 */
|
||||
.footer {
|
||||
padding: 40rpx 0;
|
||||
text-align: center;
|
||||
|
||||
Reference in New Issue
Block a user