consumer模块完成度95%,能编译在安卓端运行,在解决数据获取和页面布局问题
This commit is contained in:
@@ -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' })
|
||||
|
||||
Reference in New Issue
Block a user