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 phone = ref('')
const code = ref('')
const counting = ref(false)
const count = ref(60)
const sendCode = () => {
const sendCode = async () => {
if (counting.value) return
if (!phone.value || phone.value.length !== 11) {
uni.showToast({
@@ -34,24 +35,47 @@ 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 {
// 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' })
}
}
const handleSubmit = () => {
const handleSubmit = async () => {
if (!phone.value || !code.value) {
uni.showToast({
title: '请填写完整信息',
@@ -60,27 +84,48 @@ const handleSubmit = () => {
return
}
// TODO: Call API to bind phone
uni.showLoading({ title: '提交中...' })
setTimeout(() => {
uni.hideLoading()
uni.showToast({
title: '绑定成功',
icon: 'success'
})
// 更新本地存储的用户信息
const userInfo = uni.getStorageSync('userInfo')
if (userInfo) {
// @ts-ignore
userInfo.phone = phone.value
uni.setStorageSync('userInfo', userInfo)
}
setTimeout(() => {
uni.navigateBack()
}, 1500)
}, 1000)
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' })
}
}
</script>