consumer模块完成90%,前端完成supabase对接

This commit is contained in:
2026-02-03 17:11:50 +08:00
parent b6200cda28
commit 8a535e3f38
69 changed files with 5020 additions and 33273 deletions

View File

@@ -18,13 +18,14 @@
<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 sendCode = () => {
const sendCode = async () => {
if (counting.value) return
if (!email.value || !email.value.includes('@')) {
uni.showToast({
@@ -34,24 +35,46 @@ const sendCode = () => {
return
}
counting.value = true
count.value = 60
uni.showLoading({ title: '发送中...' })
const timer = setInterval(() => {
count.value--
if (count.value <= 0) {
clearInterval(timer)
counting.value = false
}
}, 1000)
uni.showToast({
title: '验证码已发送',
icon: 'none'
})
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' })
}
}
const handleSubmit = () => {
const handleSubmit = async () => {
if (!email.value || !code.value) {
uni.showToast({
title: '请填写完整信息',
@@ -60,27 +83,48 @@ const handleSubmit = () => {
return
}
// TODO: Call API to bind email
uni.showLoading({ title: '提交中...' })
setTimeout(() => {
uni.hideLoading()
uni.showToast({
title: '绑定成功',
icon: 'success'
})
// 更新本地存储的用户信息
const userInfo = uni.getStorageSync('userInfo')
if (userInfo) {
// @ts-ignore
userInfo.email = email.value
uni.setStorageSync('userInfo', userInfo)
}
setTimeout(() => {
uni.navigateBack()
}, 1500)
}, 1000)
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' })
}
}
</script>