功能:改造Salon小程序OpenID快捷登录

This commit is contained in:
2026-10-10 11:02:45 +08:00
parent dd3bcd40bc
commit 4bb8665aab
41 changed files with 1068 additions and 1304 deletions
+19 -1
View File
@@ -19,7 +19,7 @@ module.exports = {
register(data) {
return request({
url: '/user/workbench/register/phone',
url: '/user/workbench/register/wechat-mini',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data
@@ -99,6 +99,24 @@ module.exports = {
})
},
wechatStatus(wxCode) {
return request({
url: '/user/wechat-mini/status',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data: { wxCode }
})
},
wechatQuickLogin(data) {
return request({
url: '/user/wechat-mini/quick-login',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data
})
},
wechatPhoneLogin(data) {
return request({
url: '/user/wechat-mini/phone-login',
+27
View File
@@ -20,5 +20,32 @@ module.exports = {
},
data
})
},
bindWechatPhone(phoneCode) {
return request({
url: '/user/wechat-mini/bind-phone',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data: { phoneCode }
})
},
bindPhone(data) {
return request({
url: '/user/bind-phone',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data
})
},
sendBindPhoneCode(phone) {
return request({
url: '/user/send-verification-code',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data: { phone, sceneCode: 'USER_BIND_PHONE' }
})
}
}
+70 -1
View File
@@ -1,4 +1,5 @@
const auth = require('./utils/auth')
const authApi = require('./api/auth')
const { BRAND_CONFIG } = require('./utils/config')
App({
@@ -6,11 +7,73 @@ App({
appName: BRAND_CONFIG.appName,
shopName: BRAND_CONFIG.defaultShopName,
userInfo: null,
planningNeedRefresh: false
planningNeedRefresh: false,
wechatLoginState: null
},
onLaunch() {
this.bootstrapSession()
this.bootstrapWechatLogin()
},
getWechatCode() {
return new Promise((resolve, reject) => {
wx.login({
success: result => result.code ? resolve(result.code) : reject(new Error('未获取到微信登录凭证')),
fail: reject
})
})
},
async bootstrapWechatLogin() {
try {
const status = await authApi.wechatStatus(await this.getWechatCode())
this.publishWechatLoginState(status)
const preference = auth.getLoginPreference()
if (!preference.rememberMe || status.status !== 'READY') {
auth.clearSession()
this.globalData.userInfo = null
this.goLoginIfNeeded()
return
}
const result = await authApi.wechatQuickLogin({
wxCode: await this.getWechatCode(),
preferredShopId: preference.preferredShopId,
agreementAccepted: true,
agreementVersions: preference.agreementVersions || {},
clientType: 'WECHAT_MINI'
})
this.publishWechatLoginState(result)
if (result.status === 'SUCCESS' && result.accessToken) {
this.setSession(result)
wx.reLaunch({ url: '/pages/planning/index' })
return
}
wx.reLaunch({ url: '/pages/login/index' })
} catch (error) {
auth.clearSession()
this.globalData.userInfo = null
this.publishWechatLoginState({
status: 'ERROR',
message: error.message || '自动登录失败,请点击重试'
})
this.goLoginIfNeeded()
}
},
goLoginIfNeeded() {
const pages = getCurrentPages()
const current = pages.length ? pages[pages.length - 1].route : ''
if (current !== 'pages/login/index') wx.reLaunch({ url: '/pages/login/index' })
},
publishWechatLoginState(state) {
this.globalData.wechatLoginState = state
const pages = getCurrentPages()
const current = pages.length ? pages[pages.length - 1] : null
if (current && current.route === 'pages/login/index' && typeof current.setData === 'function') {
current.setData({ loginState: state })
}
},
bootstrapSession() {
@@ -29,5 +92,11 @@ App({
clearSession() {
auth.clearSession()
this.globalData.userInfo = null
},
logoutDevice() {
auth.clearDeviceLoginState()
this.globalData.userInfo = null
this.globalData.wechatLoginState = null
}
})
+1
View File
@@ -14,6 +14,7 @@
"pages/leave-management/index",
"pages/color-setting/index",
"pages/profile/index",
"pages/account-settings/index",
"pages/shop-settings/index",
"pages/export/index",
"pages/password/index",
@@ -0,0 +1,111 @@
const userApi = require('../../api/user')
const authApi = require('../../api/auth')
const auth = require('../../utils/auth')
Page({
data: {
profile: {},
loading: true,
binding: false,
smsForm: { phone: '', code: '' },
codeLoading: false,
countdown: 0,
timer: null
},
onShow() { this.loadProfile() },
async loadProfile() {
this.setData({ loading: true })
try {
const profile = await userApi.info()
this.setData({ profile, 'smsForm.phone': profile.phone || '' })
const app = getApp()
const session = auth.getSession()
app.setSession({ ...session, userInfo: { ...(session.userInfo || {}), ...profile } })
} catch (error) {
wx.showToast({ title: error.message || '账号信息加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
onInput(event) {
const field = event.currentTarget.dataset.field
const value = field === 'phone' ? String(event.detail.value || '').replace(/\D/g, '').slice(0, 11) : event.detail.value
this.setData({ [`smsForm.${field}`]: value })
},
async bindWechatPhone(event) {
const phoneCode = event.detail && event.detail.code
if (!phoneCode) {
wx.showToast({ title: '未获得手机号授权', icon: 'none' }); return
}
this.setData({ binding: true })
try {
await userApi.bindWechatPhone(phoneCode)
await this.loadProfile()
wx.showToast({ title: '手机号已绑定' })
} catch (error) {
wx.showToast({ title: error.message || '绑定失败', icon: 'none' })
} finally {
this.setData({ binding: false })
}
},
async sendCode() {
const phone = String(this.data.smsForm.phone || '')
if (!/^1[3-9]\d{9}$/.test(phone)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' }); return
}
if (this.data.codeLoading || this.data.countdown) return
this.setData({ codeLoading: true })
try {
await userApi.sendBindPhoneCode(phone)
this.startCountdown()
wx.showToast({ title: '验证码已发送' })
} catch (error) {
wx.showToast({ title: error.message || '验证码发送失败', icon: 'none' })
} finally {
this.setData({ codeLoading: false })
}
},
startCountdown() {
if (this.data.timer) clearInterval(this.data.timer)
this.setData({ countdown: 60 })
const timer = setInterval(() => {
const next = this.data.countdown - 1
if (next <= 0) { clearInterval(timer); this.setData({ countdown: 0, timer: null }); return }
this.setData({ countdown: next })
}, 1000)
this.setData({ timer })
},
async bindSmsPhone() {
const form = this.data.smsForm
if (!/^1[3-9]\d{9}$/.test(form.phone) || !/^\d{6}$/.test(String(form.code || ''))) {
wx.showToast({ title: '请输入正确手机号和6位验证码', icon: 'none' }); return
}
this.setData({ binding: true })
try {
await userApi.bindPhone({ phone: form.phone, verificationCode: form.code })
await this.loadProfile()
wx.showToast({ title: '手机号已绑定' })
} catch (error) {
wx.showToast({ title: error.message || '绑定失败', icon: 'none' })
} finally {
this.setData({ binding: false })
}
},
async logout() {
const confirmed = await new Promise(resolve => wx.showModal({ title: '退出登录', content: '退出后将关闭自动登录,并清除本机提醒设置。', success: result => resolve(result.confirm), fail: () => resolve(false) }))
if (!confirmed) return
try { await authApi.logout() } catch (error) {}
getApp().logoutDevice()
wx.reLaunch({ url: '/pages/login/index' })
},
onUnload() { if (this.data.timer) clearInterval(this.data.timer) }
})
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "账号设置"
}
@@ -0,0 +1,6 @@
<view class="page settings-page">
<view class="card identity-card"><view class="identity-mark">微</view><view class="identity-copy"><text class="identity-title">微信身份</text><text class="identity-status">已安全关联当前账号</text></view><text class="linked-badge">已关联</text></view>
<view class="card phone-card"><view class="section-title">手机号</view><view class="phone-status"><text>{{profile.phoneVerified == 1 ? (profile.maskedPhone || profile.phone) : '尚未绑定'}}</text><text class="status-tag {{profile.phoneVerified == 1 ? 'done' : ''}}">{{profile.phoneVerified == 1 ? '已验证' : '待绑定'}}</text></view><button class="wechat-phone-btn" open-type="getPhoneNumber" loading="{{binding}}" bindgetphonenumber="bindWechatPhone">微信一键{{profile.phoneVerified == 1 ? '更换' : '绑定'}}</button><view class="divider"><text>或使用短信验证码</text></view><view class="field"><input value="{{smsForm.phone}}" data-field="phone" bindinput="onInput" type="number" maxlength="11" placeholder="请输入手机号" /></view><view class="code-row"><input value="{{smsForm.code}}" data-field="code" bindinput="onInput" type="number" maxlength="6" placeholder="6位验证码" /><button bindtap="sendCode" disabled="{{codeLoading || countdown > 0}}">{{countdown > 0 ? countdown + 's' : '获取验证码'}}</button></view><button class="sms-bind-btn" loading="{{binding}}" bindtap="bindSmsPhone">验证并绑定</button></view>
<view class="account-note">手机号仅用于账号安全与必要联系,不作为微信快捷登录标识。</view>
<button class="logout-btn" bindtap="logout">退出登录</button>
</view>
@@ -0,0 +1,2 @@
.settings-page { padding-top:24rpx; }.identity-card { display:flex; align-items:center; padding:26rpx; }.identity-mark { display:flex; align-items:center; justify-content:center; width:68rpx; height:68rpx; border-radius:20rpx; background:#dcebe1; color:#35634d; font-size:28rpx; font-weight:800; }.identity-copy { display:flex; flex:1; flex-direction:column; margin-left:18rpx; }.identity-title,.section-title { color:#30483c; font-size:28rpx; font-weight:800; }.identity-status { margin-top:6rpx; color:#8a9a91; font-size:21rpx; }.linked-badge,.status-tag { padding:7rpx 14rpx; border-radius:999rpx; background:#e5f2e8; color:#397055; font-size:20rpx; }
.phone-card { margin-top:20rpx; padding:28rpx; }.phone-status { display:flex; align-items:center; justify-content:space-between; margin-top:20rpx; padding:20rpx; border-radius:14rpx; background:#f4f8f5; color:#425b4e; font-size:26rpx; }.status-tag { background:#fff0db; color:#9a682e; }.status-tag.done { background:#e5f2e8; color:#397055; }.wechat-phone-btn,.sms-bind-btn { height:80rpx; margin-top:22rpx; border-radius:14rpx; background:#35634d; color:#fff; font-size:26rpx; line-height:80rpx; }.divider { display:flex; align-items:center; justify-content:center; margin:28rpx 0 18rpx; color:#9aa79f; font-size:20rpx; }.field input,.code-row input { box-sizing:border-box; height:78rpx; padding:0 20rpx; border:1rpx solid #dde8e0; border-radius:12rpx; background:#f8faf8; }.code-row { display:flex; gap:12rpx; margin-top:14rpx; }.code-row input { min-width:0; flex:1; }.code-row button { width:190rpx; height:78rpx; padding:0; border-radius:12rpx; background:#e7f0ea; color:#426c57; font-size:23rpx; line-height:78rpx; }.sms-bind-btn { background:#eef4f0; color:#35634d; }.account-note { margin:24rpx 18rpx; color:#8e9c94; font-size:21rpx; line-height:1.6; }.logout-btn { margin-top:52rpx; background:transparent; color:#a24f42; font-size:25rpx; }
+99 -515
View File
@@ -1,595 +1,179 @@
const authApi = require('../../api/auth')
const auth = require('../../utils/auth')
const { BRAND_CONFIG } = require('../../utils/config')
const PHONE_REGEX = /^1[3-9]\d{9}$/
const LOGIN_PREFERENCE_KEY = 'fingertip_manager_login_preference'
function buildSession(data) {
const userInfo = data.userInfo || data.user || {}
return {
...data,
accessToken: data.accessToken || data.token,
userInfo,
shopName: data.shopName || userInfo.shopName || (data.shop && data.shop.shopName)
}
}
function getSelectableShopIds(session) {
const userInfo = session.userInfo || {}
if (Array.isArray(userInfo.shopIds)) {
return userInfo.shopIds
}
return Array.isArray(session.shopIds) ? session.shopIds : []
}
function getSelectableShopNames(session) {
const userInfo = session.userInfo || {}
if (Array.isArray(userInfo.shopNames)) {
return userInfo.shopNames
}
return Array.isArray(session.shopNames) ? session.shopNames : []
}
function buildShopOptions(session) {
const shopIds = getSelectableShopIds(session)
const shopNames = getSelectableShopNames(session)
return shopIds.map((shopId, index) => ({
id: shopId,
name: shopNames[index] || `店铺 ${shopId}`
function wxLoginCode() {
return new Promise((resolve, reject) => wx.login({
success: result => result.code ? resolve(result.code) : reject(new Error('未获取到微信登录凭证')),
fail: reject
}))
}
function buildShopOptionsFromSelection(selection) {
const shops = selection && Array.isArray(selection.shops) ? selection.shops : []
return shops.map(shop => ({
id: shop.id,
name: shop.shopName || shop.name || `店铺 ${shop.id}`,
description: selection && selection.message ? selection.message : ''
function shopOptions(result) {
return (Array.isArray(result.shops) ? result.shops : []).map(item => ({
id: item.id,
name: item.shopName || item.name || `门店 ${item.id}`
}))
}
function isShopSelectionRequiredError(error) {
const message = error && error.message ? error.message : ''
return message.indexOf('选择店铺') !== -1 || message.indexOf('请选择店铺') !== -1 || message.indexOf('请选择登录店铺') !== -1
}
function assertShopSession(session) {
const userInfo = session.userInfo || {}
if (!userInfo.shopId) {
throw new Error('请选择店铺后再进入管理师端')
}
return session
}
function getLoginPreference() {
try {
return wx.getStorageSync(LOGIN_PREFERENCE_KEY) || {}
} catch (error) {
return {}
}
}
function setLoginPreference(preference) {
wx.setStorageSync(LOGIN_PREFERENCE_KEY, preference || {})
}
function clearLoginPreference() {
wx.removeStorageSync(LOGIN_PREFERENCE_KEY)
}
Page({
data: {
loginView: 'entry',
loginMode: 'phone',
form: {
account: '',
password: '',
phone: '',
code: ''
},
appName: BRAND_CONFIG.appName,
loading: false,
codeLoading: false,
countdown: 0,
codeSent: false,
countdownTimer: null,
rememberMe: false,
agreementAccepted: false,
agreements: [],
agreementLoading: false,
agreementError: '',
selectedAgreement: {},
agreementModalVisible: false,
selectedAgreement: null,
rememberMe: false,
agreements: [],
appName: BRAND_CONFIG.appName,
loginState: null,
shopSelectVisible: false,
shopSelectMode: '',
shopOptions: [],
switchingShop: false,
wechatLoginTicket: ''
loginTicket: '',
switchingShop: false
},
onLoad() {
const preference = getLoginPreference()
if (preference.rememberMe) {
this.setData({
// 记住账号不代表默认使用密码登录,工作台优先引导手机号验证码登录。
loginMode: 'phone',
rememberMe: true,
'form.account': preference.account || '',
'form.phone': preference.phone || ''
})
}
this.setData({ rememberMe: !!auth.getLoginPreference().rememberMe })
this.consumeAppState()
this.loadAgreements()
},
onInput(event) {
const field = event.currentTarget.dataset.field
const value = field === 'phone'
? String(event.detail.value || '').replace(/\D/g, '').slice(0, 11)
: event.detail.value
this.setData({
[`form.${field}`]: value
})
},
onShow() { this.consumeAppState() },
switchLoginMode(event) {
const loginMode = event.currentTarget.dataset.mode
if (loginMode === 'entry') {
this.setData({ loginView: 'entry' })
return
}
if (loginMode === this.data.loginMode && this.data.loginView === 'form') {
return
}
this.setData({ loginMode, loginView: 'form' })
},
async sendLoginCode() {
if (!this.ensureAgreementAccepted()) {
return
}
const phone = String(this.data.form.phone || '').trim()
if (!PHONE_REGEX.test(phone)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
if (this.data.codeLoading || this.data.countdown > 0) {
return
}
this.setData({ codeLoading: true })
try {
await authApi.sendLoginCode(phone)
wx.showToast({ title: '验证码已发送' })
this.setData({ codeSent: true })
this.startCountdown()
} catch (error) {
wx.showToast({ title: error.message || '验证码发送失败', icon: 'none' })
} finally {
this.setData({ codeLoading: false })
}
consumeAppState() {
const state = getApp().globalData.wechatLoginState
if (state) this.setData({ loginState: state })
},
async loadAgreements() {
if (this.data.agreements.length) {
return this.data.agreements
}
if (this.data.agreementLoading) {
return this.data.agreements
}
if (this.data.agreementLoading || this.data.agreements.length) return
this.setData({ agreementLoading: true, agreementError: '' })
try {
const agreements = await authApi.getCurrentAgreements()
const normalizedAgreements = Array.isArray(agreements) ? agreements : []
this.setData({ agreements: normalizedAgreements })
return normalizedAgreements
this.setData({ agreements: Array.isArray(agreements) ? agreements : [] })
} catch (error) {
const agreementError = error.message || '协议内容加载失败,请稍后重试'
this.setData({ agreementError })
return []
this.setData({ agreementError: error.message || '协议加载失败' })
} finally {
this.setData({ agreementLoading: false })
}
},
toggleAgreement() {
this.setData({
agreementAccepted: !this.data.agreementAccepted
})
},
async openAgreement(event) {
const type = event.currentTarget.dataset.type
const agreements = await this.loadAgreements()
const selectedAgreement = agreements.find(item => item.agreementType === type)
if (!selectedAgreement) {
wx.showToast({ title: this.data.agreementError || '协议内容暂不可用', icon: 'none' })
return
}
this.setData({
selectedAgreement,
agreementModalVisible: true
})
},
closeAgreementModal() {
this.setData({
agreementModalVisible: false,
selectedAgreement: null
})
},
stopTap() {
},
toggleAgreement() { this.setData({ agreementAccepted: !this.data.agreementAccepted }) },
toggleRememberMe() {
const rememberMe = !this.data.rememberMe
this.setData({ rememberMe })
if (!rememberMe) {
clearLoginPreference()
}
if (!rememberMe) auth.clearLoginPreference()
},
saveLoginPreference() {
if (!this.data.rememberMe) {
clearLoginPreference()
async openAgreement(event) {
await this.loadAgreements()
const selectedAgreement = this.data.agreements.find(item => item.agreementType === event.currentTarget.dataset.type)
if (!selectedAgreement) {
wx.showToast({ title: this.data.agreementError || '协议暂不可用', icon: 'none' })
return
}
const form = this.data.form
setLoginPreference({
rememberMe: true,
loginMode: this.data.loginMode,
account: String(form.account || '').trim(),
phone: String(form.phone || '').trim()
})
this.setData({ selectedAgreement, agreementModalVisible: true })
},
buildAgreementPayload() {
closeAgreementModal() { this.setData({ agreementModalVisible: false, selectedAgreement: {} }) },
acceptAgreementModal() { this.setData({ agreementModalVisible: false, selectedAgreement: {}, agreementAccepted: true }) },
stopTap() {},
agreementPayload() {
const agreementVersions = {}
;(this.data.agreements || []).forEach(item => {
if (item && item.agreementType && item.version) {
agreementVersions[item.agreementType] = item.version
}
this.data.agreements.forEach(item => {
if (item.agreementType && item.version) agreementVersions[item.agreementType] = item.version
})
return {
agreementAccepted: !!this.data.agreementAccepted,
agreementVersions,
clientType: 'WECHAT_MINI'
}
return { agreementAccepted: true, agreementVersions, clientType: 'WECHAT_MINI' }
},
ensureAgreementAccepted() {
async ensureCanLogin() {
await this.loadAgreements()
if (!this.data.agreementAccepted) {
wx.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
await new Promise(resolve => wx.showModal({
title: '请先勾选协议',
content: '阅读并勾选用户协议和隐私政策后,才能使用快捷登录。',
showCancel: false,
complete: resolve
}))
return false
}
const versions = this.buildAgreementPayload().agreementVersions
const versions = this.agreementPayload().agreementVersions
if (!versions.USER_TERMS || !versions.PRIVACY_POLICY) {
wx.showToast({ title: this.data.agreementError || '协议版本加载中,请稍后再试', icon: 'none' })
wx.showToast({ title: this.data.agreementError || '协议版本加载中,请稍后重试', icon: 'none' })
return false
}
if (!this.data.rememberMe) {
const confirmed = await new Promise(resolve => wx.showModal({
title: '仅本次登录',
content: '未勾选“记住我”,下次打开小程序时需要重新点击快捷登录。',
confirmText: '继续登录',
success: result => resolve(result.confirm),
fail: () => resolve(false)
}))
if (!confirmed) return false
}
return true
},
async resolveLoginSession(data) {
const session = buildSession(data)
const userInfo = session.userInfo || {}
if (userInfo.shopId) {
return session
}
const shopOptions = buildShopOptions(session)
if (!shopOptions.length) {
throw new Error('当前账号没有可用店铺,无法进入管理师端')
}
if (shopOptions.length === 1) {
return this.loginForShop(shopOptions[0].id)
}
this.setData({
shopOptions,
shopSelectVisible: true,
shopSelectMode: 'login'
})
return null
},
openRegistrationFlow(data) {
const ticket = String(data.registrationTicket || '').trim()
const status = data.registrationStatus
if (status === 'PENDING_ADMIN' || status === 'PENDING_MANAGER') {
wx.showToast({ title: status === 'PENDING_ADMIN' ? '管理员审核中' : '店长审核中', icon: 'none', duration: 2500 })
return
}
if (!ticket) {
wx.showToast({ title: data.registrationRejectReason || '该手机号需要先完成身份注册', icon: 'none', duration: 2200 })
return
}
wx.showToast({ title: '手机号已验证,请完成身份注册', icon: 'none', duration: 1600 })
const query = [
`registrationTicket=${encodeURIComponent(ticket)}`,
`phone=${encodeURIComponent(data.phone || this.data.form.phone || '')}`,
data.wxCode ? `wxCode=${encodeURIComponent(data.wxCode)}` : '',
data.registrationApplicationId ? `applicationId=${encodeURIComponent(data.registrationApplicationId)}` : ''
].filter(Boolean).join('&')
setTimeout(() => wx.navigateTo({ url: `/pages/register/index?${query}` }), 700)
},
buildLoginRequestData(shopId) {
const form = this.data.form
if (this.data.loginMode === 'phone') {
return {
phone: String(form.phone || '').trim(),
verificationCode: String(form.code || '').trim(),
rememberMe: !!this.data.rememberMe,
...this.buildAgreementPayload(),
...(shopId ? { shopId } : {})
}
}
return {
account: form.account,
password: form.password,
rememberMe: !!this.data.rememberMe,
...this.buildAgreementPayload(),
...(shopId ? { shopId } : {})
}
},
requestLogin(shopId) {
const data = this.buildLoginRequestData(shopId)
return this.data.loginMode === 'phone'
? authApi.phoneLogin(data)
: authApi.login(data)
},
async loginForShop(shopId) {
return assertShopSession(buildSession(await this.requestLogin(shopId)))
},
async loadLoginShopOptions() {
const form = this.data.form
const selection = this.data.loginMode === 'phone'
? await authApi.getPhoneLoginShops(String(form.phone || '').trim())
: await authApi.getLoginShops(String(form.account || '').trim())
const shopOptions = buildShopOptionsFromSelection(selection)
if (!shopOptions.length) {
throw new Error((selection && selection.message) || '当前账号没有可用店铺,无法进入管理师端')
}
return shopOptions
},
async openLoginShopSelector() {
const shopOptions = await this.loadLoginShopOptions()
if (shopOptions.length === 1) {
await this.loginWithSelectedShop(shopOptions[0].id)
return
}
this.setData({
shopOptions,
shopSelectVisible: true,
shopSelectMode: 'login'
})
},
closeShopSelector() {
this.setData({
shopOptions: [],
shopSelectMode: '',
shopSelectVisible: false
})
},
async tryOpenLoginShopSelector() {
async quickLogin() {
if (this.data.loading || !(await this.ensureCanLogin())) return
this.setData({ loading: true })
try {
await this.openLoginShopSelector()
return true
const result = await authApi.wechatQuickLogin({ wxCode: await wxLoginCode(), ...this.agreementPayload() })
this.setData({ loginState: result })
await this.handleResult(result)
} catch (error) {
return false
this.setData({ loginState: { status: 'ERROR', message: error.message || '快捷登录失败,请重试' } })
} finally {
this.setData({ loading: false })
}
},
async selectLoginShop(event) {
if (this.data.switchingShop) {
async handleResult(result) {
if (result.status === 'SUCCESS' && result.accessToken) return this.finishLogin(result)
if (result.status === 'SELECT_SHOP') {
this.setData({ shopOptions: shopOptions(result), loginTicket: result.ticket, shopSelectVisible: true })
return
}
const shopId = event.currentTarget.dataset.id
if (!shopId) {
wx.showToast({ title: '请选择店铺', icon: 'none' })
if (result.status === 'NEED_REGISTRATION' && result.registrationTicket) {
const query = [
`registrationTicket=${encodeURIComponent(result.registrationTicket)}`,
result.registrationApplicationId ? `applicationId=${encodeURIComponent(result.registrationApplicationId)}` : ''
].filter(Boolean).join('&')
wx.navigateTo({ url: `/pages/register/index?${query}` })
return
}
wx.showToast({ title: result.message || '当前账号暂不能登录', icon: 'none', duration: 2500 })
},
async selectShop(event) {
if (this.data.switchingShop) return
this.setData({ switchingShop: true })
try {
if (this.data.shopSelectMode === 'login') {
await this.loginWithSelectedShop(shopId)
} else if (this.data.shopSelectMode === 'wechat') {
await this.loginWithWechatSelectedShop(shopId)
} else {
await this.switchSelectedShop(shopId)
}
const result = await authApi.wechatConfirmLogin({
ticket: this.data.loginTicket,
shopId: event.currentTarget.dataset.id,
...this.agreementPayload()
})
if (result.status !== 'SUCCESS' || !result.accessToken) throw new Error(result.message || '进入门店失败')
this.finishLogin(result)
} catch (error) {
wx.showToast({ title: error.message || '进入店铺失败', icon: 'none' })
wx.showToast({ title: error.message || '进入门店失败', icon: 'none' })
} finally {
this.setData({ switchingShop: false })
}
},
async loginWithSelectedShop(shopId) {
const session = await this.loginForShop(shopId)
const app = getApp()
app.setSession(session)
this.saveLoginPreference()
this.closeShopSelector()
wx.reLaunch({ url: '/pages/planning/index' })
},
async switchSelectedShop(shopId) {
const session = buildSession(await authApi.switchShop(shopId))
const app = getApp()
app.setSession(session)
this.closeShopSelector()
wx.reLaunch({ url: '/pages/planning/index' })
},
async loginWithWechatSelectedShop(shopId) {
const result = await authApi.wechatConfirmLogin({ ticket: this.data.wechatLoginTicket, shopId, ...this.buildAgreementPayload() })
if (result.status !== 'SUCCESS' || !result.accessToken) {
throw new Error(result.message || '进入店铺失败')
}
finishLogin(result) {
getApp().setSession(result)
this.closeShopSelector()
auth.setLoginPreference(this.data.rememberMe ? {
rememberMe: true,
preferredShopId: result.userInfo && result.userInfo.shopId,
agreementVersions: this.agreementPayload().agreementVersions
} : { rememberMe: false })
wx.reLaunch({ url: '/pages/planning/index' })
},
startCountdown() {
if (this.data.countdownTimer) {
clearInterval(this.data.countdownTimer)
}
this.setData({ countdown: 60 })
const timer = setInterval(() => {
const next = this.data.countdown - 1
if (next <= 0) {
clearInterval(timer)
this.setData({ countdown: 0, countdownTimer: null })
return
}
this.setData({ countdown: next })
}, 1000)
this.setData({ countdownTimer: timer })
},
onUnload() {
if (this.data.countdownTimer) {
clearInterval(this.data.countdownTimer)
}
},
async submit() {
if (this.data.loading) {
return
}
const form = this.data.form
if (this.data.loginMode === 'password' && (!form.account || !form.password)) {
wx.showToast({ title: '请填写账号和密码', icon: 'none' })
return
}
if (this.data.loginMode === 'phone' && (!PHONE_REGEX.test(String(form.phone || '').trim()) || !String(form.code || '').trim())) {
wx.showToast({ title: '请输入正确手机号和验证码', icon: 'none' })
return
}
await this.loadAgreements()
if (!this.ensureAgreementAccepted()) {
return
}
this.setData({ loading: true })
try {
const app = getApp()
const data = await this.requestLogin('')
if (this.data.loginMode === 'phone' && data && data.registrationRequired) {
this.openRegistrationFlow(data)
return
}
const session = await this.resolveLoginSession(data)
if (!session) {
return
}
app.setSession(assertShopSession(session))
this.saveLoginPreference()
wx.reLaunch({ url: '/pages/planning/index' })
} catch (error) {
if (String(error.message || '').indexOf('禁用') !== -1) {
await this.showRegistrationStatus()
return
}
if (isShopSelectionRequiredError(error)) {
try {
if (!this.data.shopSelectVisible) {
await this.openLoginShopSelector()
}
} catch (shopError) {
wx.showToast({ title: shopError.message || '店铺列表加载失败', icon: 'none' })
}
return
}
wx.showToast({ title: error.message || '登录失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
async showRegistrationStatus() {
try {
const phone = this.data.loginMode === 'phone' ? this.data.form.phone : this.data.form.account
const status = await authApi.getRegistrationStatus(String(phone || '').trim())
const statusText = {
PENDING_ADMIN: '管理员审核中',
PENDING_MANAGER: '店长审核中',
REJECTED: `申请已驳回:${status.rejectReason || '请修改资料后重新提交'}`,
APPROVED: '账号已审核,请稍后重试登录'
}[status.status] || '账号暂不可用'
wx.showToast({ title: statusText, icon: 'none', duration: 3000 })
} catch (statusError) {
wx.showToast({ title: statusError.message || '账号已被禁用', icon: 'none' })
}
},
async getWechatCode() {
const result = await new Promise((resolve, reject) => wx.login({ success: resolve, fail: reject }))
return result.code
},
goRegister(wxCode) {
const query = wxCode ? `?wxCode=${encodeURIComponent(wxCode)}` : ''
wx.navigateTo({ url: `/pages/register/index${query}` })
},
async wechatLogin() {
try {
const loginResult = await new Promise((resolve, reject) => {
wx.login({ success: resolve, fail: reject })
})
const result = await authApi.wechatAutoLogin(loginResult.code)
if (result.status === 'NEED_MANUAL_LOGIN') {
wx.showToast({ title: '新账号请先完成手机号注册和身份审核', icon: 'none', duration: 2500 })
const wxCode = await this.getWechatCode()
setTimeout(() => this.goRegister(wxCode), 900)
return
}
if (result.status !== 'SUCCESS' || !result.accessToken) {
throw new Error(result.message || '微信登录暂不可用')
}
getApp().setSession(result)
wx.reLaunch({ url: '/pages/planning/index' })
} catch (error) {
wx.showToast({ title: error.message || '微信快捷登录失败', icon: 'none' })
}
},
async wechatPhoneLogin(event) {
if (this.data.loading || !this.ensureAgreementAccepted()) {
return
}
const phoneCode = event && event.detail && event.detail.code
if (!phoneCode) {
wx.showToast({ title: '请授权手机号后登录', icon: 'none' })
return
}
this.setData({ loading: true })
try {
const wxCode = await this.getWechatCode()
const result = await authApi.wechatPhoneLogin({ wxCode, phoneCode, ...this.buildAgreementPayload() })
if (result.registrationRequired) {
this.openRegistrationFlow({ ...result, wxCode })
return
}
if (result.status === 'SELECT_SHOP') {
this.setData({ shopOptions: buildShopOptionsFromSelection(result), shopSelectVisible: true, shopSelectMode: 'wechat', wechatLoginTicket: result.ticket, switchingShop: false })
return
}
if (result.status !== 'SUCCESS' || !result.accessToken) {
throw new Error(result.message || '微信手机号登录暂不可用')
}
getApp().setSession(result)
wx.reLaunch({ url: '/pages/planning/index' })
} catch (error) {
wx.showToast({ title: error.message || '微信手机号登录失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
}
})
+4 -1
View File
@@ -1,3 +1,6 @@
{
"navigationBarTitleText": "登录"
"navigationBarTitleText": "登录",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"backgroundColor": "#FFFFFF"
}
+13 -17
View File
@@ -1,20 +1,16 @@
<view class="page no-tab auth-page">
<view class="topbar"><text class="topbar-title">登录 Salon</text></view>
<view wx:if="{{loginView === 'entry'}}" class="entry-view">
<view class="brand entry-brand"><image class="logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><text class="brand-name">{{appName}}</text><text class="brand-sub">门店工作台</text></view>
<view class="entry-actions"><button class="primary-btn entry-primary" open-type="getPhoneNumber" bindgetphonenumber="wechatPhoneLogin">快捷登录</button><button class="secondary-btn entry-secondary" data-mode="phone" bindtap="switchLoginMode">验证码登录</button><view class="entry-password" data-mode="password" bindtap="switchLoginMode">账号密码登录</view><view class="entry-register" bindtap="goRegister">注册账号 <text>›</text></view></view>
<view class="agreement-row entry-agreement" bindtap="toggleAgreement"><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="login-page">
<view class="login-main">
<view class="brand-area"><image class="login-logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><text class="brand-name">{{appName}}</text><text class="brand-sub">Salon 门店工作台</text></view>
<view wx:if="{{loginState && loginState.status !== 'READY' && loginState.status !== 'NEW_USER'}}" class="state-line"><text class="state-title">{{loginState.status === 'PENDING_REVIEW' ? '申请审核中' : loginState.status === 'REJECTED' ? '申请需要修改' : loginState.status === 'DISABLED' ? '账号暂不可用' : loginState.status === 'ERROR' ? '连接失败' : '账号状态'}}</text><text class="state-message">{{loginState.registrationRejectReason || loginState.message}}</text></view>
<view class="action-area">
<button class="quick-btn" loading="{{loading}}" disabled="{{loading || agreementLoading}}" bindtap="quickLogin"><text class="wechat-symbol">微</text><text>微信快捷登录</text></button>
<view class="remember-row" bindtap="toggleRememberMe"><view class="check {{rememberMe ? 'checked' : ''}}">{{rememberMe ? '✓' : ''}}</view><text>记住我,下次自动登录</text></view>
</view>
</view>
<view wx:if="{{loginView === 'form'}}" class="form-view">
<view class="form-heading"><view class="back-entry" data-mode="entry" bindtap="switchLoginMode">‹ <text>返回</text></view><view class="form-title">{{loginMode === 'phone' ? '手机号登录' : '账号密码登录'}}</view><view class="form-subtitle">{{loginMode === 'phone' ? '使用手机号验证码登录工作台' : '使用管理员提供的账号登录'}}</view></view>
<view wx:if="{{loginMode === 'password'}}" class="field compact-field"><text class="field-label">账号</text><input value="{{form.account}}" data-field="account" bindinput="onInput" placeholder="请输入账号" /></view>
<view wx:if="{{loginMode === 'password'}}" class="field compact-field"><text class="field-label">密码</text><input value="{{form.password}}" data-field="password" bindinput="onInput" password placeholder="请输入密码" /></view>
<view wx:if="{{loginMode === 'phone'}}" class="field compact-field"><text class="field-label">手机号</text><input value="{{form.phone}}" data-field="phone" bindinput="onInput" type="text" maxlength="11" placeholder="请输入手机号" /></view>
<view wx:if="{{loginMode === 'phone'}}" class="field compact-field"><text class="field-label">验证码</text><view class="code-row"><input class="code-input" value="{{form.code}}" data-field="code" bindinput="onInput" type="text" maxlength="6" placeholder="请输入验证码" /><button class="code-btn {{countdown > 0 ? 'counting' : ''}}" loading="{{codeLoading}}" disabled="{{codeLoading || countdown > 0}}" bindtap="sendLoginCode"><text wx:if="{{countdown > 0}}">重新获取 {{countdown}}s</text><text wx:else>{{codeSent ? '重新获取' : '获取验证码'}}</text></button></view></view>
<view class="agreement-row" bindtap="toggleAgreement"><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="{{agreementError}}" class="agreement-error" bindtap="loadAgreements">{{agreementError}},点此重试</view><view class="remember-row" bindtap="toggleRememberMe"><view class="agreement-check {{rememberMe ? 'checked' : ''}}">{{rememberMe ? '✓' : ''}}</view><view class="agreement-copy">记住我,保持登录更久</view></view><button class="primary-btn login-btn {{agreementAccepted ? '' : 'disabled'}}" loading="{{loading}}" disabled="{{loading || agreementLoading}}" bindtap="submit">{{agreementLoading ? '协议加载中...' : '登录'}}</button>
<view class="form-links"><view bindtap="switchLoginMode" data-mode="phone" wx:if="{{loginMode === 'password'}}">验证码登录</view><view bindtap="switchLoginMode" data-mode="password" wx:if="{{loginMode === 'phone'}}">账号密码登录</view><view bindtap="goRegister">注册账号</view></view>
<view class="agreement-footer">
<view class="agreement-line" bindtap="toggleAgreement"><view class="check small {{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="{{agreementError}}" class="agreement-error" bindtap="loadAgreements">{{agreementError}},点击重试</view>
</view>
<view wx:if="{{agreementModalVisible}}" class="agreement-mask" catchtouchmove="stopTap"><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><text>{{selectedAgreement.content || '暂无协议内容'}}</text></scroll-view><button class="primary-btn agreement-modal-close" bindtap="closeAgreementModal">我知道了</button></view></view>
<view wx:if="{{shopSelectVisible}}" class="shop-select-mask"><view class="shop-select-dialog"><view class="shop-select-header"><text class="shop-select-title">选择店铺</text><text class="shop-select-subtitle">请选择本次登录的店铺</text></view><scroll-view class="shop-option-list" scroll-y><view wx:for="{{shopOptions}}" wx:key="id" class="shop-option {{switchingShop ? 'disabled' : ''}}" data-id="{{item.id}}" bindtap="selectLoginShop"><view class="shop-option-icon">店</view><view class="shop-option-copy"><text class="shop-option-name">{{item.name}}</text><text class="shop-option-id">{{item.description || ('ID ' + item.id)}}</text></view></view></scroll-view><view wx:if="{{switchingShop}}" class="shop-switching">正在进入店铺...</view></view></view>
<view wx:if="{{agreementModalVisible}}" class="modal-mask" catchtouchmove="stopTap"><view class="agreement-sheet"><view class="sheet-handle"></view><text class="modal-title">{{selectedAgreement.title || '隐私保护提示'}}</text><text class="modal-version">版本 {{selectedAgreement.version || '-'}}</text><scroll-view class="modal-body" scroll-y><text>{{selectedAgreement.content || '暂无协议内容'}}</text></scroll-view><view class="sheet-actions"><button class="sheet-btn secondary" bindtap="closeAgreementModal">关闭</button><button class="sheet-btn primary" bindtap="acceptAgreementModal">同意并继续</button></view></view></view>
<view wx:if="{{shopSelectVisible}}" class="modal-mask center"><view class="shop-dialog"><text class="modal-title">选择本次登录门店</text><view wx:for="{{shopOptions}}" wx:key="id" class="shop-option" data-id="{{item.id}}" bindtap="selectShop"><view class="shop-icon">店</view><text>{{item.name}}</text><text class="shop-arrow">›</text></view><text wx:if="{{switchingShop}}" class="switching">正在进入门店…</text></view></view>
</view>
+3 -554
View File
@@ -1,554 +1,3 @@
.auth-page {
display: flex;
flex-direction: column;
justify-content: flex-start;
padding: 34rpx 28rpx 48rpx;
background: #f4f8f5;
}
.brand {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 24rpx;
}
.logo {
width: 112rpx;
height: 112rpx;
border-radius: 30rpx;
background: #e5eee9;
box-shadow: 0 16rpx 34rpx rgba(111, 143, 131, 0.24);
}
.brand-name {
margin-top: 24rpx;
color: #2e4a3d;
font-size: 42rpx;
font-weight: 800;
}
.brand-sub {
margin-top: 8rpx;
color: #7b8f82;
font-size: 23rpx;
}
.auth-card {
padding: 30rpx 24rpx 26rpx;
border: 1rpx solid #e1ebe3;
border-radius: 24rpx;
background: #fbfdfb;
box-shadow: 0 18rpx 46rpx rgba(55, 94, 72, .08);
}
.welcome-copy { color: #2e4a3d; font-size: 34rpx; font-weight: 800; }
.welcome-hint { margin-top: 8rpx; color: #87978c; font-size: 23rpx; }
.mode-tabs {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12rpx;
margin: 12rpx 0 10rpx;
padding: 8rpx;
border-radius: 12px;
background: #edf5ef;
}
.mode-tab {
display: flex;
align-items: center;
justify-content: center;
min-height: 64rpx;
border-radius: 10px;
color: #766f66;
font-size: 24rpx;
font-weight: 800;
}
.mode-tab.active {
background: #ffffff;
color: #3d6652;
box-shadow: 0 8rpx 18rpx rgba(58, 48, 34, 0.08);
}
.code-row {
display: flex;
align-items: center;
width: 100%;
min-width: 0;
gap: 14rpx;
}
.auth-card .field {
display: block;
min-height: 0;
padding: 0;
border: 0;
}
.auth-card .field-label {
display: block;
width: auto;
margin-bottom: 12rpx;
}
.auth-card .field input {
display: block;
box-sizing: border-box;
width: 100%;
height: 84rpx;
flex: none;
padding: 0 24rpx;
border: 1rpx solid #dfe9e1;
border-radius: 14rpx;
background: #f7faf7;
}
.code-input {
width: auto !important;
min-width: 0;
flex: 1 !important;
}
.code-btn {
width: 176rpx;
min-width: 176rpx;
max-width: 176rpx;
height: 68rpx;
flex: none;
padding: 0;
border: 1rpx solid #b9d0c0;
border-radius: 12rpx;
background: #edf5ef;
color: #6f8f83;
font-size: 24rpx;
font-weight: 700;
line-height: 68rpx;
text-align: center;
white-space: nowrap;
}
.code-btn.counting {
color: #aaa39a;
font-weight: 500;
}
.agreement-row,
.remember-row {
display: flex;
align-items: center;
gap: 14rpx;
margin-top: 22rpx;
color: #736c63;
font-size: 24rpx;
}
.remember-row {
margin-top: 18rpx;
}
.agreement-check {
display: flex;
align-items: center;
justify-content: center;
width: 34rpx;
min-width: 34rpx;
height: 34rpx;
border: 1rpx solid #bfb7ad;
border-radius: 8rpx;
color: #fffdf8;
font-size: 22rpx;
font-weight: 900;
}
.agreement-check.checked {
border-color: #6f8f83;
background: #6f8f83;
}
.agreement-copy {
flex: 1;
line-height: 1.45;
}
.agreement-link {
color: #55786d;
font-weight: 800;
}
.agreement-error {
margin-top: 16rpx;
color: #c36a6a;
font-size: 23rpx;
line-height: 1.5;
}
.login-btn {
margin-top: 28rpx;
}
.login-btn.disabled {
opacity: 0.56;
}
.auth-links {
display: flex;
justify-content: space-between;
margin-top: 18rpx;
}
.wechat-btn {
margin-top: 34rpx;
border: 1rpx solid #c9dbce;
background: #edf5ef;
color: #3d6652;
}
.shop-select-mask {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 20;
display: flex;
align-items: center;
justify-content: center;
padding: 48rpx;
background: rgba(36, 33, 29, 0.38);
}
.shop-select-dialog {
width: 100%;
max-height: 76vh;
padding: 28rpx;
border-radius: 8px;
background: #fffdf8;
box-shadow: 0 24rpx 64rpx rgba(58, 48, 34, 0.18);
}
.shop-select-header {
display: flex;
flex-direction: column;
gap: 8rpx;
margin-bottom: 22rpx;
}
.shop-select-title {
color: #24211d;
font-size: 32rpx;
font-weight: 900;
}
.shop-select-subtitle {
color: #928a80;
font-size: 24rpx;
}
.shop-option-list {
max-height: 520rpx;
}
.shop-option {
display: flex;
align-items: center;
gap: 18rpx;
min-height: 112rpx;
margin-bottom: 14rpx;
padding: 18rpx;
border: 1rpx solid #ece3d7;
border-radius: 8px;
background: #fbf7f0;
}
.shop-option.disabled {
opacity: 0.6;
}
.shop-option-icon {
display: flex;
align-items: center;
justify-content: center;
width: 72rpx;
min-width: 72rpx;
height: 72rpx;
border-radius: 8px;
background: #e5eee9;
color: #55786d;
font-size: 26rpx;
font-weight: 900;
}
.shop-option-copy {
display: flex;
min-width: 0;
flex: 1;
flex-direction: column;
gap: 8rpx;
}
.shop-option-name {
color: #2f2a25;
font-size: 28rpx;
font-weight: 800;
}
.shop-option-id {
color: #9a9288;
font-size: 22rpx;
}
.shop-switching {
margin-top: 12rpx;
color: #6f8f83;
font-size: 24rpx;
font-weight: 700;
text-align: center;
}
.agreement-mask {
position: fixed;
inset: 0;
z-index: 90;
display: flex;
align-items: center;
justify-content: center;
padding: 28rpx;
background: rgba(36, 33, 29, 0.42);
}
.agreement-modal {
width: 100%;
max-height: 82vh;
padding: 30rpx 28rpx;
border-radius: 24rpx;
background: #fffdf8;
box-shadow: 0 24rpx 64rpx rgba(58, 48, 34, 0.18);
}
.agreement-modal-title {
color: #24211d;
font-size: 32rpx;
font-weight: 900;
line-height: 1.35;
}
.agreement-modal-meta {
margin-top: 10rpx;
color: #928a80;
font-size: 22rpx;
}
.agreement-modal-body {
height: 640rpx;
max-height: 56vh;
margin-top: 22rpx;
padding: 20rpx;
border-radius: 18rpx;
background: #f3eee7;
color: #2f2a25;
font-size: 24rpx;
line-height: 1.85;
}
.agreement-modal-close {
margin-top: 22rpx;
}
/* 简洁登录布局沿用 Salon 现有绿色配色和控件语言。 */
.auth-page {
box-sizing: border-box;
min-height: 100vh;
padding: 0 36rpx 48rpx;
background: #f4f8f5;
}
.topbar {
display: flex;
align-items: center;
justify-content: center;
height: 96rpx;
border-bottom: 1rpx solid #e7eee9;
}
.topbar-title {
color: #2e4a3d;
font-size: 32rpx;
font-weight: 800;
}
.entry-view,
.form-view {
width: 100%;
max-width: 680rpx;
margin: 0 auto;
}
.entry-brand {
margin-top: 132rpx;
margin-bottom: 0;
}
.entry-brand .logo {
width: 128rpx;
height: 128rpx;
}
.entry-brand .brand-name {
margin-top: 22rpx;
font-size: 42rpx;
}
.entry-brand .brand-sub {
margin-top: 10rpx;
}
.entry-actions {
margin-top: 132rpx;
}
.entry-primary,
.entry-secondary {
width: 100%;
height: 92rpx;
margin: 0;
border-radius: 14rpx;
font-size: 29rpx;
line-height: 92rpx;
}
.entry-primary {
background: #6f8f83;
color: #fffdf8;
}
.entry-secondary {
margin-top: 22rpx;
border: 1rpx solid #9fbcac;
background: #fbfdfb;
color: #55786d;
}
.entry-password,
.entry-register {
color: #6f8f83;
font-size: 26rpx;
text-align: center;
}
.entry-password {
margin-top: 30rpx;
}
.entry-register {
margin-top: 24rpx;
color: #8b968f;
}
.entry-register text {
margin-left: 4rpx;
font-size: 32rpx;
}
.entry-agreement {
margin-top: 118rpx;
}
.form-view {
padding-top: 54rpx;
}
.form-heading {
position: relative;
margin-bottom: 72rpx;
text-align: center;
}
.back-entry {
position: absolute;
top: -8rpx;
left: 0;
color: #6f8f83;
font-size: 30rpx;
}
.back-entry text {
margin-left: 4rpx;
font-size: 24rpx;
}
.form-title {
color: #2e4a3d;
font-size: 42rpx;
font-weight: 800;
}
.form-subtitle {
margin-top: 12rpx;
color: #87978c;
font-size: 23rpx;
}
.compact-field {
margin-top: 28rpx;
}
.compact-field .field-label {
display: none;
}
.compact-field input {
box-sizing: border-box;
width: 100%;
height: 88rpx;
padding: 0 8rpx;
border-bottom: 1rpx solid #dce7df;
background: transparent;
color: #2e4a3d;
font-size: 29rpx;
}
.compact-field .code-row {
border-bottom: 1rpx solid #dce7df;
}
.compact-field .code-input {
height: 88rpx;
border-bottom: 0;
}
.compact-field .code-btn {
width: 190rpx;
min-width: 190rpx;
max-width: 190rpx;
height: 72rpx;
border: 0;
background: transparent;
color: #55786d;
line-height: 72rpx;
}
.form-view .agreement-row {
margin-top: 44rpx;
}
.form-view .remember-row {
margin-top: 20rpx;
}
.form-view .login-btn {
height: 88rpx;
margin-top: 38rpx;
border-radius: 14rpx;
line-height: 88rpx;
}
.form-links {
display: flex;
justify-content: center;
gap: 48rpx;
margin-top: 28rpx;
color: #6f8f83;
font-size: 24rpx;
}
.login-page { box-sizing:border-box; display:flex; min-height:calc(100vh - 88rpx); flex-direction:column; padding:0 56rpx 38rpx; background:#fff; }.login-main { display:flex; flex:1; flex-direction:column; }.brand-area { display:flex; flex-direction:column; align-items:center; padding-top:190rpx; }.login-logo { width:196rpx; height:196rpx; border-radius:46rpx; }.brand-name { margin-top:26rpx; color:#202522; font-size:40rpx; font-weight:800; letter-spacing:3rpx; }.brand-sub { margin-top:10rpx; color:#9a9f9c; font-size:22rpx; letter-spacing:4rpx; }.action-area { margin-top:118rpx; }.quick-btn { display:flex; align-items:center; justify-content:center; height:92rpx; border-radius:999rpx; background:#2f8f78; color:#fff; font-size:30rpx; font-weight:500; line-height:92rpx; box-shadow:0 10rpx 20rpx rgba(47,143,120,.16); }.quick-btn::after { border:0; }.wechat-symbol { display:flex; align-items:center; justify-content:center; width:38rpx; height:38rpx; margin-right:14rpx; border:2rpx solid rgba(255,255,255,.9); border-radius:50%; font-size:18rpx; font-weight:800; line-height:38rpx; }.remember-row { display:flex; align-items:center; justify-content:center; margin-top:30rpx; color:#737a76; font-size:23rpx; }.check { display:flex; align-items:center; justify-content:center; width:32rpx; height:32rpx; margin-right:12rpx; border:2rpx solid #b7bdb9; border-radius:50%; color:#fff; font-size:19rpx; }.check.small { width:28rpx; height:28rpx; flex:none; margin-right:8rpx; border-radius:7rpx; }.check.checked { border-color:#2f8f78; background:#2f8f78; }.state-line { display:flex; flex-direction:column; align-items:center; margin-top:34rpx; }.state-title { color:#765b32; font-size:24rpx; font-weight:700; }.state-message { margin-top:7rpx; color:#9a8260; font-size:20rpx; text-align:center; }.agreement-footer { padding-top:50rpx; }.agreement-line { display:flex; align-items:flex-start; justify-content:center; }.agreement-copy { color:#a0a4a1; font-size:20rpx; line-height:1.55; text-align:center; }.agreement-link { color:#6b7570; }.agreement-error { margin-top:10rpx; color:#ad6954; font-size:19rpx; text-align:center; }
.modal-mask { position:fixed; z-index:20; inset:0; display:flex; align-items:flex-end; background:rgba(0,0,0,.56); }.modal-mask.center { align-items:center; justify-content:center; padding:36rpx; }.agreement-sheet { box-sizing:border-box; width:100%; max-height:74vh; padding:16rpx 42rpx 48rpx; border-radius:28rpx 28rpx 0 0; background:#fff; }.sheet-handle { width:72rpx; height:8rpx; margin:0 auto 34rpx; border-radius:999rpx; background:#e4e5e4; }.modal-title { display:block; color:#222724; font-size:34rpx; font-weight:800; }.modal-version { display:block; margin-top:10rpx; color:#a1a5a2; font-size:21rpx; }.modal-body { height:38vh; margin-top:24rpx; color:#707773; font-size:25rpx; line-height:1.75; white-space:pre-wrap; }.sheet-actions { display:flex; gap:24rpx; margin-top:30rpx; }.sheet-btn { height:88rpx; flex:1; border-radius:14rpx; font-size:29rpx; line-height:88rpx; }.sheet-btn.secondary { background:#f3f3f3; color:#242824; }.sheet-btn.primary { background:#19be72; color:#fff; }.shop-dialog { box-sizing:border-box; width:100%; padding:34rpx; border-radius:24rpx; background:#fff; }.shop-option { display:flex; align-items:center; margin-top:20rpx; padding:22rpx; border-radius:16rpx; background:#f3f8f5; color:#344b40; font-size:26rpx; }.shop-icon { display:flex; align-items:center; justify-content:center; width:52rpx; height:52rpx; margin-right:16rpx; border-radius:14rpx; background:#dbe9df; color:#35634d; font-weight:800; }.shop-arrow { margin-left:auto; color:#82948a; font-size:34rpx; }.switching { display:block; margin-top:20rpx; color:#82948a; text-align:center; }
@media (max-height:700px) { .brand-area { padding-top:90rpx; }.action-area { margin-top:70rpx; }.login-logo { width:160rpx; height:160rpx; } }
+73 -1
View File
@@ -1,5 +1,8 @@
const planningApi = require('../../api/planning')
const dateUtil = require('../../utils/date')
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const { uploadProfileImage } = require('../../utils/upload')
function canCreateAppointment() {
const app = getApp()
@@ -82,7 +85,11 @@ Page({
pendingCount: 0,
canCreateAppointment: true,
loading: false,
calendarError: ''
calendarError: '',
phoneBannerVisible: false,
profilePromptVisible: false,
profileSaving: false,
profileForm: { nickname: '', avatar: '' }
},
onLoad() {
@@ -99,6 +106,71 @@ Page({
wx.removeStorageSync('planningNeedRefresh')
this.loadCalendar()
}
this.refreshAccountPrompts()
},
async refreshAccountPrompts() {
try {
const profile = await userApi.info()
const session = auth.getSession()
getApp().setSession({ ...session, userInfo: { ...(session.userInfo || {}), ...profile } })
const today = dateUtil.formatDate(new Date())
const dismissed = wx.getStorageSync(auth.PHONE_BANNER_DISMISSED_KEY)
const missingNickname = !String(profile.nickname || '').trim() || String(profile.nickname).startsWith('微信用户')
const skipped = wx.getStorageSync(auth.PROFILE_PROMPT_SKIPPED_KEY) === '1'
this.setData({
phoneBannerVisible: Number(profile.phoneVerified) !== 1 && dismissed !== today,
profilePromptVisible: !skipped && (missingNickname || !profile.avatar),
profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar: profile.avatar || '' }
})
} catch (error) {
// 资料提醒失败不影响规划数据。
}
},
openAccountSettings() { wx.navigateTo({ url: '/pages/account-settings/index' }) },
dismissPhoneBanner() {
wx.setStorageSync(auth.PHONE_BANNER_DISMISSED_KEY, dateUtil.formatDate(new Date()))
this.setData({ phoneBannerVisible: false })
},
onNicknameInput(event) { this.setData({ 'profileForm.nickname': event.detail.value }) },
async chooseWechatAvatar(event) {
const filePath = event.detail && event.detail.avatarUrl
if (!filePath) return
this.setData({ profileSaving: true })
try {
const avatar = await uploadProfileImage(filePath)
this.setData({ 'profileForm.avatar': avatar })
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
this.setData({ profileSaving: false })
}
},
skipProfilePrompt() {
wx.setStorageSync(auth.PROFILE_PROMPT_SKIPPED_KEY, '1')
this.setData({ profilePromptVisible: false })
},
async saveWechatProfile() {
const nickname = String(this.data.profileForm.nickname || '').trim()
if (!nickname || !this.data.profileForm.avatar) {
wx.showToast({ title: '请选择头像并填写昵称', icon: 'none' }); return
}
this.setData({ profileSaving: true })
try {
await userApi.updateInfo({ nickname, avatar: this.data.profileForm.avatar })
this.setData({ profilePromptVisible: false })
wx.showToast({ title: '资料已保存' })
} catch (error) {
wx.showToast({ title: error.message || '资料保存失败', icon: 'none' })
} finally {
this.setData({ profileSaving: false })
}
},
switchView(event) {
+13
View File
@@ -1,4 +1,8 @@
<view class="page planning-page">
<view wx:if="{{phoneBannerVisible}}" class="phone-banner">
<view class="phone-banner-track" bindtap="openAccountSettings"><text>绑定手机号,便于账号安全验证与重要通知</text><text>点击前往账号设置</text></view>
<view class="phone-banner-close" catchtap="dismissPhoneBanner">×</view>
</view>
<view class="card control-card">
<view class="date-row">
<view class="date-side">
@@ -26,6 +30,15 @@
</scroll-view>
</view>
<view wx:if="{{profilePromptVisible}}" class="profile-prompt-mask">
<view class="profile-prompt">
<text class="profile-prompt-title">完善你的工作名片</text><text class="profile-prompt-desc">头像和昵称会用于门店协作展示,可暂时跳过。</text>
<button class="wechat-avatar" open-type="chooseAvatar" bindchooseavatar="chooseWechatAvatar"><image wx:if="{{profileForm.avatar}}" src="{{profileForm.avatar}}" mode="aspectFill"></image><text wx:else>选择头像</text></button>
<input class="wechat-nickname" type="nickname" value="{{profileForm.nickname}}" bindinput="onNicknameInput" placeholder="填写微信昵称" />
<button class="profile-save" loading="{{profileSaving}}" bindtap="saveWechatProfile">保存资料</button><button class="profile-skip" bindtap="skipProfilePrompt">暂时跳过</button>
</view>
</view>
<view wx:if="{{calendarError}}" class="calendar-error-card">
<view class="calendar-error-copy">
<text class="calendar-error-title">规划数据加载失败</text>
@@ -2,6 +2,9 @@
padding-top: 18rpx;
}
.phone-banner { display:flex; align-items:center; margin-bottom:18rpx; padding:16rpx 18rpx; border-radius:14rpx; background:#fff2d8; color:#815f2b; overflow:hidden; }.phone-banner-track { display:flex; flex:1; width:0; gap:50rpx; white-space:nowrap; animation:phoneBannerScroll 10s linear infinite; font-size:22rpx; }.phone-banner-close { position:relative; z-index:2; margin-left:18rpx; padding:6rpx; background:#fff2d8; font-size:32rpx; }.profile-prompt-mask { position:fixed; z-index:30; inset:0; display:flex; align-items:center; justify-content:center; padding:40rpx; background:rgba(25,41,33,.55); }.profile-prompt { box-sizing:border-box; display:flex; width:100%; flex-direction:column; align-items:center; padding:36rpx; border-radius:24rpx; background:#fff; }.profile-prompt-title { color:#30483c; font-size:32rpx; font-weight:800; }.profile-prompt-desc { margin-top:10rpx; color:#89988f; font-size:22rpx; text-align:center; }.wechat-avatar { display:flex; align-items:center; justify-content:center; width:128rpx; height:128rpx; margin-top:28rpx; padding:0; border-radius:50%; background:#e6f0e9; color:#416c56; font-size:22rpx; overflow:hidden; }.wechat-avatar image { width:100%; height:100%; }.wechat-nickname { box-sizing:border-box; width:100%; height:80rpx; margin-top:24rpx; padding:0 22rpx; border:1rpx solid #dce8df; border-radius:13rpx; background:#f7faf8; }.profile-save { width:100%; height:80rpx; margin-top:22rpx; border-radius:14rpx; background:#35634d; color:#fff; line-height:80rpx; }.profile-skip { margin-top:12rpx; background:transparent; color:#7e8e85; font-size:23rpx; }
@keyframes phoneBannerScroll { from { transform:translateX(0); } to { transform:translateX(-48%); } }
.today-btn {
display: flex;
align-items: center;
+3 -1
View File
@@ -44,9 +44,9 @@ Page({
},
menus: [
{ title: '个人信息', action: 'editProfile' },
{ title: '账号设置', url: '/pages/account-settings/index' },
{ title: '店铺设置', url: '/pages/shop-settings/index' },
{ title: '数据导出', url: '/pages/export/index' },
{ title: '修改密码', url: '/pages/password/index' },
{ title: '关于系统', url: '/pages/about/index' }
]
},
@@ -146,6 +146,8 @@ Page({
nickname: profile.nickname || '',
avatar: profile.avatar || '',
phone: profile.phone || currentUserInfo.phone || '',
phoneVerified: profile.phoneVerified,
maskedPhone: profile.maskedPhone || '',
contactPhone: profile.contactPhone || '',
wechatId: profile.wechatId || '',
signature: profile.signature || '',
+41 -71
View File
@@ -1,112 +1,82 @@
const authApi = require('../../api/auth')
const PHONE_REGEX = /^1[3-9]\d{9}$/
Page({
data: {
step: 1,
role: 'manager',
passwordMode: false,
form: { phone: '', code: '', password: '', confirmPassword: '', shopName: '', shopAddress: '', shopId: '' },
wxCode: '',
form: { shopName: '', shopAddress: '', shopId: '' },
registrationTicket: '',
applicationId: '',
phoneVerified: false,
shopOptions: [],
shopIndex: 0,
selectedShopName: '',
loading: false,
codeLoading: false,
countdown: 0,
codeSent: false,
countdownTimer: null,
agreementAccepted: false
ticketInvalid: false
},
async onLoad(options) {
const registrationTicket = options && options.registrationTicket ? options.registrationTicket : ''
this.setData({
wxCode: options && options.wxCode ? options.wxCode : '',
registrationTicket,
applicationId: options && options.applicationId ? options.applicationId : '',
phoneVerified: Boolean(registrationTicket),
'form.phone': options && options.phone ? options.phone : '',
step: registrationTicket ? 2 : 1
ticketInvalid: !registrationTicket
})
try {
const shopOptions = await authApi.getAvailableRegistrationShops()
this.setData({ shopOptions: Array.isArray(shopOptions) ? shopOptions : [] })
const shops = await authApi.getAvailableRegistrationShops()
this.setData({
shopOptions: (Array.isArray(shops) ? shops : []).map(item => ({
id: item.id,
name: item.shopName || item.name,
address: item.address || ''
}))
})
} catch (error) {
this.setData({ shopOptions: [] })
}
},
onInput(event) {
const field = event.currentTarget.dataset.field
const value = field === 'phone'
? String(event.detail.value || '').replace(/\D/g, '').slice(0, 11)
: event.detail.value
this.setData({ [`form.${field}`]: value })
},
togglePasswordMode() { this.setData({ passwordMode: !this.data.passwordMode }) },
toggleAgreement() { this.setData({ agreementAccepted: !this.data.agreementAccepted }) },
async sendCode() {
if (!this.data.agreementAccepted) { wx.showToast({ title: '请先同意用户协议和隐私政策', icon: 'none' }); return }
const phone = String(this.data.form.phone || '').trim()
if (!PHONE_REGEX.test(phone)) { wx.showToast({ title: '请输入正确手机号', icon: 'none' }); return }
if (this.data.codeLoading || this.data.countdown > 0) return
this.setData({ codeLoading: true })
try { await authApi.sendCode(phone); wx.showToast({ title: '验证码已发送' }); this.setData({ codeSent: true }); this.startCountdown() } catch (error) { wx.showToast({ title: error.message || '发送失败', icon: 'none' }) } finally { this.setData({ codeLoading: false }) }
},
continueFromPhone() {
const form = this.data.form
if (!PHONE_REGEX.test(String(form.phone || '').trim()) || !/^\d{6}$/.test(String(form.code || '').trim())) { wx.showToast({ title: '请输入正确手机号和6位验证码', icon: 'none' }); return }
if (this.data.passwordMode && (!form.password || form.password !== form.confirmPassword)) { wx.showToast({ title: '请确认两次密码一致', icon: 'none' }); return }
this.setData({ step: 2 })
},
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
selectRole(event) { this.setData({ role: event.currentTarget.dataset.role }) },
continueFromRole() { this.setData({ step: 3 }) },
continueFromRole() { if (!this.data.ticketInvalid) this.setData({ step: 2 }) },
selectShop(event) {
const index = Number(event.detail.value)
const shop = this.data.shopOptions[index]
if (!shop) return
this.setData({ shopIndex: index, selectedShopName: shop.name, 'form.shopId': shop.id })
if (shop) this.setData({ shopIndex: index, selectedShopName: shop.name, 'form.shopId': shop.id })
},
goBackStep() { this.setData({ step: Math.max(1, this.data.step - 1) }) },
async getCurrentWxCode() {
const result = await new Promise((resolve, reject) => wx.login({ success: resolve, fail: reject }))
return result.code
},
goBackStep() { this.setData({ step: 1 }) },
async submit() {
const form = this.data.form
if (this.data.role === 'manager' && !String(form.shopName || '').trim()) { wx.showToast({ title: '请输入店铺名称', icon: 'none' }); return }
if (this.data.role === 'staff' && !form.shopId) { wx.showToast({ title: '请选择要加入的店铺', icon: 'none' }); return }
if (!this.data.registrationTicket) {
wx.showToast({ title: '注册票据已失效,请返回重新快捷登录', icon: 'none' })
return
}
if (this.data.role === 'manager' && !String(form.shopName || '').trim()) {
wx.showToast({ title: '请输入店铺名称', icon: 'none' }); return
}
if (this.data.role === 'staff' && !form.shopId) {
wx.showToast({ title: '请选择要加入的店铺', icon: 'none' }); return
}
this.setData({ loading: true })
try {
const wxCode = this.data.registrationTicket ? await this.getCurrentWxCode() : this.data.wxCode
await authApi.register({ phone: form.phone, verificationCode: this.data.registrationTicket ? undefined : form.code, registrationTicket: this.data.registrationTicket || undefined, applicationId: this.data.applicationId || undefined, password: form.password, confirmPassword: form.confirmPassword, shopName: form.shopName, shopAddress: form.shopAddress, shopId: form.shopId, roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF', agreementAccepted: true, wxCode })
this.setData({ step: 4 })
} catch (error) { wx.showToast({ title: error.message || '提交失败', icon: 'none' }) } finally { this.setData({ loading: false }) }
await authApi.register({
registrationTicket: this.data.registrationTicket,
applicationId: this.data.applicationId || undefined,
shopName: String(form.shopName || '').trim(),
shopAddress: String(form.shopAddress || '').trim(),
shopId: form.shopId || undefined,
roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF',
agreementAccepted: true
})
this.setData({ step: 3, registrationTicket: '' })
} catch (error) {
wx.showToast({ title: error.message || '提交失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
startCountdown() {
if (this.data.countdownTimer) clearInterval(this.data.countdownTimer)
this.setData({ countdown: 60 })
const timer = setInterval(() => { const next = this.data.countdown - 1; if (next <= 0) { clearInterval(timer); this.setData({ countdown: 0, countdownTimer: null }); return } this.setData({ countdown: next }) }, 1000)
this.setData({ countdownTimer: timer })
},
onUnload() { if (this.data.countdownTimer) clearInterval(this.data.countdownTimer) },
back() { wx.navigateBack() }
back() { wx.reLaunch({ url: '/pages/login/index' }) }
})
+7 -14
View File
@@ -1,16 +1,9 @@
<view class="page no-tab auth-page">
<view class="auth-header"><image class="logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><view class="header-copy"><text class="brand-name">Salon</text><text class="brand-sub">门店工作台 · 创建你的工作身份</text></view></view>
<view class="progress-row"><view class="progress-step {{step >= 1 ? 'active' : ''}}"><text>1</text><label>验证手机</label></view><view class="progress-line {{step >= 2 ? 'active' : ''}}"></view><view class="progress-step {{step >= 2 ? 'active' : ''}}"><text>2</text><label>选择身份</label></view><view class="progress-line {{step >= 3 ? 'active' : ''}}"></view><view class="progress-step {{step >= 3 ? 'active' : ''}}"><text>3</text><label>提交审核</label></view></view>
<view wx:if="{{step === 1}}" class="card form-card">
<view class="section-title">验证手机号</view><view class="section-desc">手机号将作为你的工作台登录账号</view>
<view class="field"><text class="field-label">手机号</text><input value="{{form.phone}}" data-field="phone" bindinput="onInput" type="number" maxlength="11" disabled="{{phoneVerified}}" placeholder="请输入手机号" /><text wx:if="{{phoneVerified}}" class="verified-tip">手机号已验证</text></view>
<view class="field"><text class="field-label">验证码</text><view class="code-row"><input class="code-input" value="{{form.code}}" data-field="code" bindinput="onInput" type="number" placeholder="请输入6位验证码" /><button class="code-btn {{countdown > 0 ? 'counting' : ''}}" loading="{{codeLoading}}" disabled="{{codeLoading || countdown > 0}}" bindtap="sendCode"><text wx:if="{{countdown > 0}}">{{countdown}}s 后重发</text><text wx:else>{{codeSent ? '重新获取' : '获取验证码'}}</text></button></view></view>
<view class="agreement-row" bindtap="toggleAgreement"><view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view><view class="agreement-copy">我已阅读并同意《用户协议》和《隐私政策》</view></view><view class="secondary-entry" bindtap="togglePasswordMode">使用密码注册 <text>›</text></view>
<view wx:if="{{passwordMode}}" class="password-panel"><view class="field"><text class="field-label">设置密码</text><input value="{{form.password}}" data-field="password" bindinput="onInput" password placeholder="至少8位密码" /></view><view class="field"><text class="field-label">确认密码</text><input value="{{form.confirmPassword}}" data-field="confirmPassword" bindinput="onInput" password placeholder="再次输入密码" /></view></view>
<button class="primary-btn" loading="{{loading}}" bindtap="continueFromPhone">继续</button>
</view>
<view wx:if="{{step === 2}}" class="card form-card"><view class="section-title">你要加入哪种工作身份?</view><view class="section-desc">不同身份需要由不同的负责人审核</view><view class="role-list"><view class="role-option {{role === 'manager' ? 'selected' : ''}}" data-role="manager" bindtap="selectRole"><view class="role-icon">店</view><view class="role-copy"><text class="role-title">店长</text><text class="role-desc">创建并负责一家 Salon 门店</text></view><text class="role-mark">{{role === 'manager' ? '✓' : '○'}}</text></view><view class="role-option {{role === 'staff' ? 'selected' : ''}}" data-role="staff" bindtap="selectRole"><view class="role-icon">员</view><view class="role-copy"><text class="role-title">店员</text><text class="role-desc">加入已有门店协同工作</text></view><text class="role-mark">{{role === 'staff' ? '✓' : '○'}}</text></view></view><button class="primary-btn" bindtap="continueFromRole">继续</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
<view wx:if="{{step === 3}}" class="card form-card"><view class="section-title">{{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}</view><view class="section-desc">{{role === 'manager' ? '提交后由管理员审核,审核通过后即可登录' : '提交后由对应店长审核,审核通过后即可登录'}}</view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" /></view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺地址</text><input value="{{form.shopAddress}}" data-field="shopAddress" bindinput="onInput" placeholder="请输入门店所在地址" /></view><view wx:if="{{role === 'staff'}}" class="field"><text class="field-label">选择店铺</text><picker range="{{shopOptions}}" range-key="name" value="{{shopIndex}}" bindchange="selectShop"><view class="picker-value {{selectedShopName ? 'filled' : ''}}">{{selectedShopName || '请选择要加入的店铺'}}</view></picker></view><view wx:if="{{role === 'staff'}}" class="notice">店员申请会发送给所选店铺的店长审核</view><button class="primary-btn" loading="{{loading}}" bindtap="submit">提交审核</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
<view wx:if="{{step === 4}}" class="card result-card"><view class="result-icon">✓</view><view class="section-title">申请已提交</view><view class="section-desc">{{role === 'manager' ? '管理员审核通过后,你就可以登录 Salon 工作台。' : '店长审核通过后,你就可以登录 Salon 工作台。'}}</view><view class="result-status">当前状态:<text>等待审核</text></view><button class="primary-btn" bindtap="back">返回登录</button></view>
<view class="safe-note">注册并不代表立即获得工作台权限,审核通过后才可登录。</view>
<view class="auth-header"><image class="logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><view class="header-copy"><text class="brand-name">Salon</text><text class="brand-sub">用微信身份申请门店工作权限</text></view></view>
<view class="progress-row"><view class="progress-step {{step >= 1 ? 'active' : ''}}"><text>1</text><label>选择身份</label></view><view class="progress-line {{step >= 2 ? 'active' : ''}}"></view><view class="progress-step {{step >= 2 ? 'active' : ''}}"><text>2</text><label>门店资料</label></view><view class="progress-line {{step >= 3 ? 'active' : ''}}"></view><view class="progress-step {{step >= 3 ? 'active' : ''}}"><text>3</text><label>等待审核</label></view></view>
<view wx:if="{{ticketInvalid}}" class="card result-card"><view class="result-icon">!</view><view class="section-title">申请入口已失效</view><view class="section-desc">请返回登录页重新点击微信快捷登录,获取新的申请凭证。</view><button class="primary-btn" bindtap="back">返回登录</button></view>
<view wx:elif="{{step === 1}}" class="card form-card"><view class="section-title">选择工作身份</view><view class="section-desc">无需手机号和密码,审核人会根据你的身份处理申请</view><view class="role-list"><view class="role-option {{role === 'manager' ? 'selected' : ''}}" data-role="manager" bindtap="selectRole"><view class="role-icon">店</view><view class="role-copy"><text class="role-title">店长</text><text class="role-desc">创建并负责一家 Salon 门店</text></view><text class="role-mark">{{role === 'manager' ? '✓' : '○'}}</text></view><view class="role-option {{role === 'staff' ? 'selected' : ''}}" data-role="staff" bindtap="selectRole"><view class="role-icon">员</view><view class="role-copy"><text class="role-title">店员</text><text class="role-desc">加入已有门店协同工作</text></view><text class="role-mark">{{role === 'staff' ? '✓' : '○'}}</text></view></view><button class="primary-btn" bindtap="continueFromRole">继续</button></view>
<view wx:elif="{{step === 2}}" class="card form-card"><view class="section-title">{{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}</view><view class="section-desc">{{role === 'manager' ? '提交后由平台管理员审核' : '提交后由对应店长审核'}}</view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" /></view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺地址</text><input value="{{form.shopAddress}}" data-field="shopAddress" bindinput="onInput" placeholder="请输入门店地址" /></view><view wx:if="{{role === 'staff'}}" class="field"><text class="field-label">选择店铺</text><picker range="{{shopOptions}}" range-key="name" value="{{shopIndex}}" bindchange="selectShop"><view class="picker-value {{selectedShopName ? 'filled' : ''}}">{{selectedShopName || '请选择要加入的店铺'}}</view></picker></view><view wx:if="{{role === 'staff'}}" class="notice">审核通过前不会获得门店业务权限</view><button class="primary-btn" loading="{{loading}}" bindtap="submit">提交审核</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
<view wx:elif="{{step === 3}}" class="card result-card"><view class="result-icon">✓</view><view class="section-title">申请已提交</view><view class="section-desc">{{role === 'manager' ? '平台管理员审核通过后,即可使用快捷登录。' : '店长审核通过后,即可使用快捷登录。'}}</view><view class="result-status">当前状态:<text>等待审核</text></view><button class="primary-btn" bindtap="back">返回登录</button></view>
<view class="safe-note">OpenID 仅用于识别你的微信身份,不会在页面中展示。</view>
</view>
+29 -1
View File
@@ -1,4 +1,7 @@
const SESSION_KEY = 'fingertip_manager_session'
const LOGIN_PREFERENCE_KEY = 'jayucloud_salon_login_preference'
const PHONE_BANNER_DISMISSED_KEY = 'jayucloud_salon_phone_banner_dismissed'
const PROFILE_PROMPT_SKIPPED_KEY = 'jayucloud_salon_profile_prompt_skipped'
function getSession() {
try {
@@ -21,9 +24,34 @@ function getAccessToken() {
return session.accessToken || session.token || ''
}
function getLoginPreference() {
try { return wx.getStorageSync(LOGIN_PREFERENCE_KEY) || {} } catch (error) { return {} }
}
function setLoginPreference(preference) {
wx.setStorageSync(LOGIN_PREFERENCE_KEY, preference || {})
}
function clearLoginPreference() {
wx.removeStorageSync(LOGIN_PREFERENCE_KEY)
}
function clearDeviceLoginState() {
clearSession()
clearLoginPreference()
wx.removeStorageSync(PHONE_BANNER_DISMISSED_KEY)
wx.removeStorageSync(PROFILE_PROMPT_SKIPPED_KEY)
}
module.exports = {
getSession,
setSession,
clearSession,
getAccessToken
getAccessToken,
getLoginPreference,
setLoginPreference,
clearLoginPreference,
clearDeviceLoginState,
PHONE_BANNER_DISMISSED_KEY,
PROFILE_PROMPT_SKIPPED_KEY
}