数据分析页面骨架
This commit is contained in:
@@ -11,44 +11,20 @@
|
||||
|
||||
<!-- 注册表单 -->
|
||||
<view class="form-content">
|
||||
<!-- 手机号 -->
|
||||
<!-- 邮箱 -->
|
||||
<view class="input-group">
|
||||
<view class="input-wrapper">
|
||||
<image src="/static/user/phone_1.png" class="input-icon" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="输入手机号码"
|
||||
:value="phone"
|
||||
@input="(e: any) => phone = e.detail.value"
|
||||
maxlength="11"
|
||||
placeholder="输入邮箱"
|
||||
:value="email"
|
||||
@input="(e: any) => email = e.detail.value"
|
||||
class="input-field"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 验证码 -->
|
||||
<view class="input-group">
|
||||
<view class="input-wrapper">
|
||||
<image src="/static/user/code_2.png" class="input-icon" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="填写验证码"
|
||||
:value="captcha"
|
||||
@input="(e: any) => captcha = e.detail.value"
|
||||
maxlength="6"
|
||||
class="input-field code-input"
|
||||
/>
|
||||
<button
|
||||
class="code-btn"
|
||||
:disabled="codeDisabled"
|
||||
:class="{ 'disabled': codeDisabled }"
|
||||
@click="getCode"
|
||||
>
|
||||
{{ codeText }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 密码 -->
|
||||
<view class="input-group">
|
||||
<view class="input-wrapper">
|
||||
@@ -115,61 +91,37 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { ensureUserProfile } from '@/utils/sapi.uts'
|
||||
|
||||
// 响应式数据
|
||||
const phone = ref<string>('')
|
||||
const captcha = ref<string>('')
|
||||
const email = ref<string>('')
|
||||
const password = ref<string>('')
|
||||
const confirmPassword = ref<string>('')
|
||||
const protocol = ref<boolean>(false)
|
||||
const inAnimation = ref<boolean>(false)
|
||||
const isLoading = ref<boolean>(false)
|
||||
const logoUrl = ref<string>('/static/logo.png')
|
||||
|
||||
// 验证码相关
|
||||
const codeDisabled = ref<boolean>(false)
|
||||
const codeText = ref<string>('获取验证码')
|
||||
const codeCountdown = ref<number>(0)
|
||||
let codeTimer: number | null = null
|
||||
|
||||
// 处理协议勾选变化
|
||||
const handleProtocolChange = (e: any) => {
|
||||
protocol.value = !protocol.value
|
||||
}
|
||||
|
||||
// 验证手机号
|
||||
const validatePhone = (): boolean => {
|
||||
if (phone.value.trim() === '') {
|
||||
// 验证邮箱
|
||||
const validateEmail = (): boolean => {
|
||||
if (email.value.trim() === '') {
|
||||
uni.showToast({
|
||||
title: '请填写手机号码',
|
||||
title: '请填写邮箱',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
if (!/^1[3-9]\d{9}$/.test(phone.value)) {
|
||||
// 基础邮箱格式校验(足够用于前端提示)
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value)) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的手机号码',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
const validateCaptcha = (): boolean => {
|
||||
if (captcha.value.trim() === '') {
|
||||
uni.showToast({
|
||||
title: '请填写验证码',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
if (!/^\d{6}$/.test(captcha.value)) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的验证码',
|
||||
title: '请输入正确的邮箱',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
@@ -223,47 +175,6 @@
|
||||
return true
|
||||
}
|
||||
|
||||
// 获取验证码
|
||||
const getCode = async () => {
|
||||
if (!protocol.value) {
|
||||
inAnimation.value = true
|
||||
uni.showToast({
|
||||
title: '请先阅读并同意协议',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!validatePhone()) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: 调用获取验证码接口
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 开始倒计时
|
||||
codeDisabled.value = true
|
||||
codeCountdown.value = 60
|
||||
codeText.value = `${codeCountdown.value}秒后重试`
|
||||
|
||||
codeTimer = setInterval(() => {
|
||||
codeCountdown.value--
|
||||
if (codeCountdown.value > 0) {
|
||||
codeText.value = `${codeCountdown.value}秒后重试`
|
||||
} else {
|
||||
codeDisabled.value = false
|
||||
codeText.value = '获取验证码'
|
||||
if (codeTimer != null) {
|
||||
clearInterval(codeTimer)
|
||||
codeTimer = null
|
||||
}
|
||||
}
|
||||
}, 1000) as unknown as number
|
||||
}
|
||||
|
||||
// 处理注册
|
||||
const handleRegister = async () => {
|
||||
// 检查协议
|
||||
@@ -277,10 +188,7 @@
|
||||
}
|
||||
|
||||
// 表单验证
|
||||
if (!validatePhone()) {
|
||||
return
|
||||
}
|
||||
if (!validateCaptcha()) {
|
||||
if (!validateEmail()) {
|
||||
return
|
||||
}
|
||||
if (!validatePassword()) {
|
||||
@@ -293,52 +201,27 @@
|
||||
isLoading.value = true
|
||||
|
||||
try {
|
||||
// TODO: 调用注册接口(手机号+验证码+密码)
|
||||
// 目前先使用邮箱注册作为临时方案
|
||||
// 注意:CRMEB 使用手机号注册,但 Supabase Auth 默认支持邮箱注册
|
||||
// 需要根据实际后端 API 调整
|
||||
|
||||
// 临时方案:使用手机号作为邮箱格式注册
|
||||
const email = `${phone.value}@phone.mall`
|
||||
|
||||
const result = await supa.signUp(email, password.value)
|
||||
|
||||
if (result != null && result.user != null) {
|
||||
// 创建用户资料
|
||||
const user = result.user as UTSJSONObject
|
||||
const authId = user.getString('id')
|
||||
|
||||
if (authId != null) {
|
||||
const userData = {
|
||||
auth_id: authId,
|
||||
phone: phone.value,
|
||||
email: email,
|
||||
username: phone.value,
|
||||
user_type: 1, // 默认消费者
|
||||
status: 1
|
||||
} as UTSJSONObject
|
||||
|
||||
try {
|
||||
await supa.from('ak_users').insert(userData).execute()
|
||||
} catch (profileErr) {
|
||||
console.error('创建用户资料失败:', profileErr)
|
||||
}
|
||||
}
|
||||
// 使用 Supabase Auth:邮箱 + 密码注册
|
||||
const result = await supa.signUp(email.value.trim(), password.value)
|
||||
const data = new UTSJSONObject(result as any)
|
||||
const user = data.getJSON('user')
|
||||
|
||||
uni.showToast({
|
||||
title: '注册成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 跳转到登录页
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}, 1500)
|
||||
} else {
|
||||
throw new Error('注册失败')
|
||||
// Supabase 可能开启了邮箱验证,此时 user 可能为空/或 session 为空
|
||||
if (user != null) {
|
||||
// 记录业务侧用户资料(ak_users),用于 app 内个人中心等页面读取
|
||||
await ensureUserProfile(user as UTSJSONObject)
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '注册成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}, 1500)
|
||||
} catch (err) {
|
||||
console.error('注册错误:', err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user