功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -16,6 +16,10 @@ const {
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
|
||||
/**
|
||||
* auth page logic.
|
||||
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
|
||||
*/
|
||||
Page({
|
||||
data: Object.assign(createKeyboardSafeData({
|
||||
cursorSpacing: 108
|
||||
@@ -54,6 +58,10 @@ Page({
|
||||
miniShopDisplayName: '',
|
||||
miniShopNewUser: false,
|
||||
miniShopSubmitting: false,
|
||||
agreementAccepted: false,
|
||||
agreements: [],
|
||||
agreementModalVisible: false,
|
||||
selectedAgreement: null,
|
||||
form: {
|
||||
account: '',
|
||||
password: '',
|
||||
@@ -71,6 +79,10 @@ Page({
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
onLoad(options) {
|
||||
this.ensureKeyboardSafe()
|
||||
this.setData({
|
||||
@@ -79,20 +91,33 @@ Page({
|
||||
})
|
||||
this.detectWechatMiniCapability()
|
||||
this.loadShopOptions()
|
||||
this.loadAgreements()
|
||||
this.consumePendingWechatMiniLogin()
|
||||
this.waitForPendingWechatMiniAutoLogin()
|
||||
},
|
||||
|
||||
/**
|
||||
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
onShow() {
|
||||
this.ensureKeyboardSafe()
|
||||
this.consumePendingWechatMiniLogin()
|
||||
},
|
||||
|
||||
/**
|
||||
* `onHide` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
onHide() {
|
||||
resetKeyboardSafe(this)
|
||||
detachKeyboardSafe(this)
|
||||
},
|
||||
|
||||
/**
|
||||
* `onUnload` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
onUnload() {
|
||||
resetKeyboardSafe(this)
|
||||
detachKeyboardSafe(this)
|
||||
@@ -100,6 +125,10 @@ Page({
|
||||
|
||||
noop() {},
|
||||
|
||||
/**
|
||||
* `ensureKeyboardSafe` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
ensureKeyboardSafe() {
|
||||
attachKeyboardSafe(this, {
|
||||
cursorSpacing: 108,
|
||||
@@ -107,14 +136,26 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleKeyboardFocus` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleKeyboardFocus(event) {
|
||||
handleKeyboardFocus(this, event)
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleKeyboardBlur` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleKeyboardBlur() {
|
||||
handleKeyboardBlur(this)
|
||||
},
|
||||
|
||||
/**
|
||||
* `detectWechatMiniCapability` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
detectWechatMiniCapability() {
|
||||
let supported = false
|
||||
let disabledReason = ''
|
||||
@@ -122,6 +163,10 @@ Page({
|
||||
try {
|
||||
supported = wx.canIUse('button.open-type.getPhoneNumber')
|
||||
const systemInfo = wx.getSystemInfoSync()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (systemInfo && systemInfo.platform === 'devtools') {
|
||||
supported = false
|
||||
disabledReason = '当前环境无法使用微信手机号登录,请使用账号密码或验证码登录'
|
||||
@@ -130,6 +175,10 @@ Page({
|
||||
supported = false
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!supported && !disabledReason) {
|
||||
disabledReason = '当前环境无法使用微信手机号登录,请使用账号密码或验证码登录'
|
||||
}
|
||||
@@ -140,6 +189,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `waitForPendingWechatMiniAutoLogin` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
waitForPendingWechatMiniAutoLogin() {
|
||||
const app = getApp()
|
||||
if (
|
||||
@@ -167,13 +220,25 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `consumePendingWechatMiniLogin` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
consumePendingWechatMiniLogin() {
|
||||
const app = getApp()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!app || typeof app.consumePendingWechatMiniLogin !== 'function') {
|
||||
return
|
||||
}
|
||||
|
||||
const pending = app.consumePendingWechatMiniLogin()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (pending && pending.status === 'SELECT_SHOP') {
|
||||
this.openMiniShopSelector(pending)
|
||||
}
|
||||
@@ -193,6 +258,87 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async loadAgreements() {
|
||||
try {
|
||||
const agreements = await authApi.getCurrentAgreements()
|
||||
this.setData({
|
||||
agreements: Array.isArray(agreements) ? agreements : []
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: '协议内容加载失败,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
buildAgreementPayload() {
|
||||
const agreementVersions = {}
|
||||
;(this.data.agreements || []).forEach((item) => {
|
||||
if (item && item.agreementType && item.version) {
|
||||
agreementVersions[item.agreementType] = item.version
|
||||
}
|
||||
})
|
||||
return {
|
||||
agreementAccepted: !!this.data.agreementAccepted,
|
||||
agreementVersions,
|
||||
clientType: 'WECHAT_MINI'
|
||||
}
|
||||
},
|
||||
|
||||
ensureAgreementAccepted() {
|
||||
if (!this.data.agreementAccepted) {
|
||||
wx.showToast({
|
||||
title: '请先阅读并同意用户协议和隐私政策',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
const versions = this.buildAgreementPayload().agreementVersions
|
||||
if (!versions.USER_TERMS || !versions.PRIVACY_POLICY) {
|
||||
wx.showToast({
|
||||
title: '协议版本加载中,请稍后再试',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
handleAgreementToggle() {
|
||||
this.setData({
|
||||
agreementAccepted: !this.data.agreementAccepted
|
||||
})
|
||||
},
|
||||
|
||||
openAgreement(event) {
|
||||
const type = event.currentTarget.dataset.type
|
||||
const selectedAgreement = (this.data.agreements || []).find((item) => item.agreementType === type)
|
||||
if (!selectedAgreement) {
|
||||
wx.showToast({
|
||||
title: '协议内容暂不可用',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedAgreement,
|
||||
agreementModalVisible: true
|
||||
})
|
||||
},
|
||||
|
||||
closeAgreementModal() {
|
||||
this.setData({
|
||||
agreementModalVisible: false,
|
||||
selectedAgreement: null
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleTabChange` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleTabChange(event) {
|
||||
const tab = event.currentTarget.dataset.tab
|
||||
resetKeyboardSafe(this)
|
||||
@@ -210,6 +356,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleLoginTypeChange` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleLoginTypeChange(event) {
|
||||
const type = event.currentTarget.dataset.type
|
||||
resetKeyboardSafe(this)
|
||||
@@ -227,6 +377,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleShowTraditionalLogin` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleShowTraditionalLogin() {
|
||||
resetKeyboardSafe(this)
|
||||
this.setData({
|
||||
@@ -235,6 +389,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleToggleResetPanel` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleToggleResetPanel() {
|
||||
resetKeyboardSafe(this)
|
||||
this.setData({
|
||||
@@ -242,6 +400,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleInputChange` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const value = event.detail.value
|
||||
@@ -249,7 +411,15 @@ Page({
|
||||
[`form.${field}`]: value
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (field === 'account') {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.activeTab === 'login') {
|
||||
patch.loginAccountStatusText = ''
|
||||
patch.loginAccountStatusType = ''
|
||||
@@ -267,7 +437,15 @@ Page({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (field === 'phone') {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.activeTab === 'register') {
|
||||
patch.registerPhoneStatusText = ''
|
||||
patch.registerPhoneStatusType = ''
|
||||
@@ -284,6 +462,10 @@ Page({
|
||||
this.setData(patch)
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleResetInputChange` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleResetInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
@@ -291,6 +473,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleRegisterShopChange` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleRegisterShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.shops[index]
|
||||
@@ -301,6 +487,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleLoginShopChange` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleLoginShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.loginShops[index]
|
||||
@@ -311,6 +501,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleMiniShopChange` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleMiniShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.miniShops[index]
|
||||
@@ -320,7 +514,15 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleCloseMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleCloseMiniShopSelector() {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.miniShopSubmitting) {
|
||||
return
|
||||
}
|
||||
@@ -329,7 +531,15 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleResumeMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleResumeMiniShopSelector() {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!this.data.miniShopTicket || !this.data.miniShops.length) {
|
||||
return
|
||||
}
|
||||
@@ -342,15 +552,27 @@ Page({
|
||||
async handleAccountBlur() {
|
||||
this.handleKeyboardBlur()
|
||||
const account = this.data.form.account.trim()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!account) {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.activeTab === 'register') {
|
||||
await this.checkRegisterAccountAvailability()
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.loginType !== 'password') {
|
||||
return
|
||||
}
|
||||
@@ -364,10 +586,18 @@ Page({
|
||||
async handlePhoneBlur() {
|
||||
this.handleKeyboardBlur()
|
||||
const phone = this.data.form.phone.trim()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!phone) {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.activeTab === 'register') {
|
||||
if (phoneRegex.test(phone)) {
|
||||
await this.checkRegisterPhoneAvailability()
|
||||
@@ -382,6 +612,10 @@ Page({
|
||||
await this.loadLoginShopsByPhone()
|
||||
},
|
||||
|
||||
/**
|
||||
* `applyLoginShopSelection` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
applyLoginShopSelection(selection) {
|
||||
const shops = Array.isArray(selection && selection.shops) ? selection.shops : []
|
||||
const allowLoginShopless = Boolean(selection && selection.allowShoplessLogin)
|
||||
@@ -389,6 +623,10 @@ Page({
|
||||
let loginShopDisplayName = ''
|
||||
let shopId = ''
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!allowLoginShopless && shops.length === 1) {
|
||||
loginShopIndex = 0
|
||||
loginShopDisplayName = shops[0].shopName || ''
|
||||
@@ -482,6 +720,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `startCountdown` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
startCountdown(fieldName) {
|
||||
this.setData({
|
||||
[fieldName]: 60
|
||||
@@ -493,6 +735,10 @@ Page({
|
||||
[fieldName]: nextValue
|
||||
})
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (nextValue <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
@@ -500,6 +746,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleSendCode() {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.countdown > 0) {
|
||||
return
|
||||
}
|
||||
@@ -513,8 +763,16 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.activeTab === 'register') {
|
||||
const phoneAvailable = await this.checkRegisterPhoneAvailability()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!phoneAvailable) {
|
||||
wx.showToast({
|
||||
title: this.data.registerPhoneStatusText || '该手机号已被注册',
|
||||
@@ -525,7 +783,10 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => userApi.sendVerificationCode({ phone }))
|
||||
await runWithLoading(() => userApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: this.data.activeTab === 'register' ? 'USER_REGISTER_SMS_CODE' : 'USER_LOGIN_SMS_CODE'
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@@ -540,6 +801,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleSendForgotCode() {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.forgotCountdown > 0) {
|
||||
return
|
||||
}
|
||||
@@ -554,7 +819,10 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => authApi.sendVerificationCode({ phone }))
|
||||
await runWithLoading(() => authApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: 'USER_RESET_PASSWORD_SMS_CODE'
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@@ -568,8 +836,16 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `validateLoginForm` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
validateLoginForm() {
|
||||
const form = this.data.form
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.loginType === 'password') {
|
||||
if (!form.account.trim() || !form.password) {
|
||||
return '请输入账号和密码'
|
||||
@@ -578,6 +854,10 @@ Page({
|
||||
return '请输入正确的手机号和验证码'
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!this.data.allowLoginShopless && this.data.loginShops.length && !form.shopId) {
|
||||
return '请选择登录门店'
|
||||
}
|
||||
@@ -599,12 +879,24 @@ Page({
|
||||
if (!form.verificationCode.trim()) {
|
||||
return '请输入验证码'
|
||||
}
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!form.password || form.password.length < 6) {
|
||||
return '密码至少 6 位'
|
||||
}
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (form.password !== form.confirmPassword) {
|
||||
return '两次输入的密码不一致'
|
||||
}
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!form.shopId) {
|
||||
return '请选择门店'
|
||||
}
|
||||
@@ -614,6 +906,10 @@ Page({
|
||||
this.checkRegisterPhoneAvailability()
|
||||
])
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!accountAvailable || !phoneAvailable) {
|
||||
return '请先处理注册信息中的占用问题'
|
||||
}
|
||||
@@ -622,30 +918,45 @@ Page({
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
if (!this.ensureAgreementAccepted()) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (this.data.activeTab === 'login') {
|
||||
const loginError = this.validateLoginForm()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (loginError) {
|
||||
throw new Error(loginError)
|
||||
}
|
||||
|
||||
let payload
|
||||
await runWithLoading(async () => {
|
||||
const agreementPayload = this.buildAgreementPayload()
|
||||
payload = this.data.loginType === 'phone'
|
||||
? await authApi.phoneLogin({
|
||||
phone: this.data.form.phone.trim(),
|
||||
verificationCode: this.data.form.verificationCode.trim(),
|
||||
shopId: this.data.form.shopId || undefined
|
||||
shopId: this.data.form.shopId || undefined,
|
||||
...agreementPayload
|
||||
})
|
||||
: await authApi.login({
|
||||
account: this.data.form.account.trim(),
|
||||
password: this.data.form.password,
|
||||
rememberMe: true,
|
||||
shopId: this.data.form.shopId || undefined
|
||||
shopId: this.data.form.shopId || undefined,
|
||||
...agreementPayload
|
||||
})
|
||||
})
|
||||
|
||||
@@ -654,6 +965,10 @@ Page({
|
||||
}
|
||||
|
||||
const registerError = await this.validateRegisterForm()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (registerError) {
|
||||
throw new Error(registerError)
|
||||
}
|
||||
@@ -664,7 +979,8 @@ Page({
|
||||
nickname: this.data.form.nickname.trim(),
|
||||
phone: this.data.form.phone.trim(),
|
||||
verificationCode: this.data.form.verificationCode.trim(),
|
||||
shopId: this.data.form.shopId
|
||||
shopId: this.data.form.shopId,
|
||||
...this.buildAgreementPayload()
|
||||
}))
|
||||
|
||||
wx.showToast({
|
||||
@@ -708,6 +1024,10 @@ Page({
|
||||
})
|
||||
return
|
||||
}
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!form.newPassword || form.newPassword.length < 6) {
|
||||
wx.showToast({
|
||||
title: '新密码至少 6 位',
|
||||
@@ -750,6 +1070,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleWechatMiniUnavailableTap` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
handleWechatMiniUnavailableTap() {
|
||||
wx.showToast({
|
||||
title: this.data.wechatMiniDisabledReason || '请使用账号密码或验证码登录',
|
||||
@@ -758,12 +1082,24 @@ Page({
|
||||
},
|
||||
|
||||
async handleWechatMiniPhoneLogin(event) {
|
||||
if (!this.ensureAgreementAccepted()) {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!this.data.wechatMiniSupported || this.data.wechatMiniLoading) {
|
||||
this.handleWechatMiniUnavailableTap()
|
||||
return
|
||||
}
|
||||
|
||||
const detail = event.detail || {}
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!detail.code) {
|
||||
wx.showToast({
|
||||
title: this.resolveWechatAuthorizeError(detail),
|
||||
@@ -781,7 +1117,8 @@ Page({
|
||||
const result = await runWithLoading(() => authApi.wechatMiniPhoneLogin({
|
||||
wxCode,
|
||||
phoneCode: detail.code,
|
||||
preferredShopId: authStore.getPreferredMiniLoginShopId() || undefined
|
||||
preferredShopId: authStore.getPreferredMiniLoginShopId() || undefined,
|
||||
...this.buildAgreementPayload()
|
||||
}))
|
||||
await this.handleWechatMiniResult(result)
|
||||
} catch (error) {
|
||||
@@ -797,7 +1134,15 @@ Page({
|
||||
},
|
||||
|
||||
async handleConfirmMiniShopLogin() {
|
||||
if (!this.ensureAgreementAccepted()) {
|
||||
return
|
||||
}
|
||||
|
||||
const shop = this.data.miniShops[this.data.miniShopIndex]
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!this.data.miniShopTicket) {
|
||||
wx.showToast({
|
||||
title: '登录票据已失效,请重新发起微信登录',
|
||||
@@ -805,6 +1150,10 @@ Page({
|
||||
})
|
||||
return
|
||||
}
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!shop || !shop.id) {
|
||||
wx.showToast({
|
||||
title: '请选择门店',
|
||||
@@ -820,8 +1169,13 @@ Page({
|
||||
try {
|
||||
const result = await runWithLoading(() => authApi.confirmWechatMiniLogin({
|
||||
ticket: this.data.miniShopTicket,
|
||||
shopId: shop.id
|
||||
shopId: shop.id,
|
||||
...this.buildAgreementPayload()
|
||||
}))
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!result || result.status !== 'SUCCESS') {
|
||||
throw new Error((result && result.message) || '确认登录失败')
|
||||
}
|
||||
@@ -839,6 +1193,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `resolveWechatAuthorizeError` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
resolveWechatAuthorizeError(detail) {
|
||||
const errMsg = String((detail && detail.errMsg) || '')
|
||||
if (errMsg.includes('user deny') || errMsg.includes('user cancel')) {
|
||||
@@ -850,8 +1208,16 @@ Page({
|
||||
return '未获取到微信手机号授权,请稍后重试。'
|
||||
},
|
||||
|
||||
/**
|
||||
* `requestWechatMiniCode` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
requestWechatMiniCode() {
|
||||
const app = getApp()
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (app && typeof app.requestWechatMiniCode === 'function') {
|
||||
return app.requestWechatMiniCode()
|
||||
}
|
||||
@@ -859,6 +1225,10 @@ Page({
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
success: res => {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (res && res.code) {
|
||||
resolve(res.code)
|
||||
return
|
||||
@@ -871,15 +1241,27 @@ Page({
|
||||
},
|
||||
|
||||
async handleWechatMiniResult(result) {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!result) {
|
||||
throw new Error('微信登录未返回结果')
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (result.status === 'SUCCESS') {
|
||||
await this.finishLogin(result, result.newUser ? '注册并登录成功' : '登录成功')
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (result.status === 'SELECT_SHOP') {
|
||||
this.openMiniShopSelector(result)
|
||||
return
|
||||
@@ -891,9 +1273,17 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `openMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
openMiniShopSelector(result) {
|
||||
resetKeyboardSafe(this)
|
||||
const shops = Array.isArray(result && result.shops) ? result.shops : []
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (!shops.length) {
|
||||
wx.showToast({
|
||||
title: result && result.message ? result.message : '暂无可选门店,请稍后重试',
|
||||
@@ -917,6 +1307,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `clearMiniShopSelector` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
clearMiniShopSelector() {
|
||||
this.setData({
|
||||
showMiniShopSelector: false,
|
||||
@@ -951,10 +1345,22 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `buildAuthHelperText` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
buildAuthHelperText(activeTab, loginType) {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (activeTab === 'register') {
|
||||
return '注册前请先选门店'
|
||||
}
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (loginType === 'phone') {
|
||||
return '未注册手机号会先选门店'
|
||||
}
|
||||
|
||||
@@ -37,6 +37,16 @@
|
||||
</button>
|
||||
|
||||
<text class="wechat-login-hint">{{wechatMiniSupported ? '单门店可直接登录' : wechatMiniDisabledReason}}</text>
|
||||
|
||||
<view class="agreement-row wechat-agreement" bindtap="handleAgreementToggle">
|
||||
<view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view>
|
||||
<view class="agreement-copy">
|
||||
<text>我已阅读并同意</text>
|
||||
<text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text>
|
||||
<text>和</text>
|
||||
<text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{miniShopTicket && !showMiniShopSelector}}" class="hint-card mini-login-resume">
|
||||
@@ -216,7 +226,17 @@
|
||||
<text class="aux-link" bindtap="handleToggleResetPanel">忘记密码?</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="primary-btn submit-btn" bindtap="handleSubmit">{{activeTab === 'login' ? '立即登录' : '完成注册'}}</view>
|
||||
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="agreement-row" bindtap="handleAgreementToggle">
|
||||
<view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view>
|
||||
<view class="agreement-copy">
|
||||
<text>我已阅读并同意</text>
|
||||
<text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text>
|
||||
<text>和</text>
|
||||
<text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="primary-btn submit-btn {{agreementAccepted ? '' : 'disabled'}}" bindtap="handleSubmit">{{activeTab === 'login' ? '立即登录' : '完成注册'}}</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{showResetPanel}}" class="page-card reset-card">
|
||||
@@ -303,10 +323,31 @@
|
||||
|
||||
<view wx:if="{{miniShopNewUser}}" class="hint-card mini-shop-note">首次登录会自动注册并绑定手机号。</view>
|
||||
|
||||
<view class="agreement-row mini-shop-agreement" bindtap="handleAgreementToggle">
|
||||
<view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view>
|
||||
<view class="agreement-copy">
|
||||
<text>我已阅读并同意</text>
|
||||
<text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text>
|
||||
<text>和</text>
|
||||
<text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mini-shop-actions">
|
||||
<view class="secondary-btn mini-shop-action" bindtap="handleCloseMiniShopSelector">稍后再选</view>
|
||||
<view class="primary-btn mini-shop-action" bindtap="handleConfirmMiniShopLogin">{{miniShopSubmitting ? '确认中...' : '确认登录'}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{agreementModalVisible}}" class="agreement-mask" catchtouchmove="noop">
|
||||
<view class="agreement-modal">
|
||||
<view class="agreement-modal-title">{{selectedAgreement.title || '协议详情'}}</view>
|
||||
<view class="agreement-modal-meta">版本:{{selectedAgreement.version || '-'}}</view>
|
||||
<scroll-view class="agreement-modal-body" scroll-y="true">
|
||||
<text>{{selectedAgreement.content || '暂无协议内容'}}</text>
|
||||
</scroll-view>
|
||||
<view class="primary-btn agreement-modal-close" bindtap="closeAgreementModal">我知道了</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -238,6 +238,110 @@
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.submit-btn.disabled {
|
||||
opacity: 0.52;
|
||||
}
|
||||
|
||||
.agreement-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 14rpx;
|
||||
margin-top: 22rpx;
|
||||
color: #7a6871;
|
||||
font-size: 23rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.agreement-check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 34rpx;
|
||||
height: 34rpx;
|
||||
margin-top: 2rpx;
|
||||
border: 2rpx solid #d9b8c4;
|
||||
border-radius: 10rpx;
|
||||
color: #ffffff;
|
||||
font-size: 22rpx;
|
||||
font-weight: 800;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.agreement-check.checked {
|
||||
border-color: #c6597d;
|
||||
background: #c6597d;
|
||||
}
|
||||
|
||||
.agreement-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.agreement-link {
|
||||
color: #c6597d;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.mini-shop-agreement {
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.wechat-agreement {
|
||||
width: 100%;
|
||||
margin-top: 18rpx;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.agreement-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 80;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 28rpx;
|
||||
background: rgba(45, 36, 48, 0.42);
|
||||
}
|
||||
|
||||
.agreement-modal {
|
||||
width: 100%;
|
||||
max-width: 690rpx;
|
||||
max-height: 82vh;
|
||||
padding: 30rpx 28rpx;
|
||||
border-radius: 32rpx;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.agreement-modal-title {
|
||||
font-size: 32rpx;
|
||||
line-height: 1.35;
|
||||
font-weight: 800;
|
||||
color: #2d2430;
|
||||
}
|
||||
|
||||
.agreement-modal-meta {
|
||||
margin-top: 10rpx;
|
||||
font-size: 22rpx;
|
||||
color: #9a8590;
|
||||
}
|
||||
|
||||
.agreement-modal-body {
|
||||
height: 640rpx;
|
||||
max-height: 56vh;
|
||||
margin-top: 22rpx;
|
||||
padding: 20rpx;
|
||||
border-radius: 22rpx;
|
||||
background: #fff7f8;
|
||||
color: #5a4a52;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.85;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.agreement-modal-close {
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.mini-shop-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
|
||||
Reference in New Issue
Block a user