功能:同步小程序流程

This commit is contained in:
xiaowang
2026-05-23 18:45:41 +08:00
parent 844516988b
commit 30ae763e18
117 changed files with 8823 additions and 76 deletions
+232
View File
@@ -1,31 +1,111 @@
/**
* Purpose: authApi supports index.js by holding or executing the auth api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const authApi = require('../../api/auth')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const { runWithLoading } = require('../../utils/loading')
/**
* Purpose: ACCOUNT_REGEX supports index.js by holding or executing the account regex page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const ACCOUNT_REGEX = /[^A-Za-z0-9]/g
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: redirect supports index.js by holding or executing the redirect page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
redirect: '',
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: '',
/**
* Purpose: password supports index.js by holding or executing the password page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
password: '',
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: ''
},
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: '',
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: '',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: '',
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
this._lookupTicket = 0
this.setData({
/**
* Purpose: redirect supports index.js by holding or executing the redirect page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
redirect: options && options.redirect ? options.redirect : ''
})
@@ -34,12 +114,20 @@ Page({
}
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
}
},
/**
* Purpose: handleInputChange supports index.js by holding or executing the handle input change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleInputChange(event) {
const field = event.currentTarget.dataset.field
let value = event.detail.value
@@ -57,17 +145,33 @@ Page({
})
},
/**
* Purpose: handleShopChange supports index.js by holding or executing the handle shop change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleShopChange(event) {
const index = Number(event.detail.value)
const shop = this.data.loginShops[index]
this.setData({
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: index,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: shop ? shop.shopName || '' : '',
'form.shopId': shop ? shop.id : ''
})
},
/**
* Purpose: resetAccountState supports index.js by holding or executing the reset account state page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
resetAccountState() {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
@@ -76,17 +180,49 @@ Page({
this._lookupTicket += 1
this.setData({
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: '',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: '',
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: '',
'form.shopId': ''
})
},
/**
* Purpose: scheduleAccountLookup supports index.js by holding or executing the schedule account lookup page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
scheduleAccountLookup(account) {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
@@ -99,6 +235,10 @@ Page({
}, 420)
},
/**
* Purpose: applyLoginShopSelection supports index.js by holding or executing the apply login shop selection page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
applyLoginShopSelection(selection) {
const shops = Array.isArray(selection && selection.shops) ? selection.shops : []
const allowShoplessLogin = Boolean(selection && selection.allowShoplessLogin)
@@ -113,13 +253,29 @@ Page({
}
this.setData({
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: shops,
allowShoplessLogin,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: (selection && selection.message) || '',
loginShopIndex,
loginShopDisplayName,
'form.shopId': shopId,
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: shops.length || allowShoplessLogin ? '该账号可用于后台登录' : '当前账号暂时不可用于后台登录',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: shops.length || allowShoplessLogin ? 'success' : 'warning'
})
},
@@ -141,18 +297,50 @@ Page({
return
}
this.setData({
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: '',
'form.shopId': '',
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: error.message || '该后台账号不存在或不可登录',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: 'error'
})
}
},
/**
* Purpose: validateForm supports index.js by holding or executing the validate form page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
validateForm() {
const form = this.data.form
if (!form.account) {
@@ -171,38 +359,82 @@ Page({
const errorMessage = this.validateForm()
if (errorMessage) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: errorMessage,
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: true
})
try {
const payload = await runWithLoading(() => authApi.login({
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: this.data.form.account,
/**
* Purpose: password supports index.js by holding or executing the password page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
password: this.data.form.password,
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: this.data.form.shopId || undefined
}))
await getApp().setAdminSession(payload)
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '登录成功',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
await navigation.redirectAfterLogin(this.data.redirect)
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '登录失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false
})
}