完成Salon小程序合规整改

This commit is contained in:
2026-10-22 00:27:12 +08:00
parent 1120f9d5a9
commit da1f2d2cba
99 changed files with 2815 additions and 702 deletions
+30
View File
@@ -40,6 +40,24 @@ module.exports = {
})
},
unbindPhone(verificationCode) {
return request({
url: '/user/unbind-phone',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data: { verificationCode }
})
},
sendUnbindPhoneCode() {
return request({
url: '/user/unbind-phone/send-code',
method: 'POST',
params: { __baseUrl: API_DOMAIN },
data: {}
})
},
sendBindPhoneCode(phone) {
return request({
url: '/user/send-verification-code',
@@ -47,5 +65,17 @@ module.exports = {
params: { __baseUrl: API_DOMAIN },
data: { phone, sceneCode: 'USER_BIND_PHONE' }
})
},
getAccountClosure() {
return request({ url: '/user/account-closure/me', params: { __baseUrl: API_DOMAIN } })
},
requestAccountClosure() {
return request({ url: '/user/account-closure', method: 'POST', params: { __baseUrl: API_DOMAIN }, data: {} })
},
withdrawAccountClosure() {
return request({ url: '/user/account-closure/me', method: 'DELETE', params: { __baseUrl: API_DOMAIN } })
}
}
+28 -2
View File
@@ -36,6 +36,10 @@ async function run() {
reset({ rememberMe: true, agreementVersions: { USER_TERMS: '1', PRIVACY_POLICY: '1' } })
let statusCalled = false
authApi.wechatStatus = async () => { statusCalled = true; return { status: 'READY' } }
authApi.getCurrentAgreements = async () => [
{ agreementType: 'USER_TERMS', version: '1' },
{ agreementType: 'PRIVACY_POLICY', version: '1' }
]
authApi.wechatQuickLogin = async () => ({ status: 'SUCCESS', accessToken: 'token', userInfo: { id: 1 } })
await appDefinition.runWechatBootstrap()
assert.deepStrictEqual(navigations, ['/pages/planning/index'])
@@ -47,14 +51,32 @@ async function run() {
reset({ rememberMe: false })
let quickLoginCalled = false
authApi.wechatStatus = async () => ({ status: 'READY' })
let agreementsRead = false
authApi.getCurrentAgreements = async () => { agreementsRead = true; return [] }
authApi.wechatQuickLogin = async () => { quickLoginCalled = true }
await appDefinition.runWechatBootstrap()
assert.deepStrictEqual(navigations, ['/pages/login/index'])
assert.strictEqual(quickLoginCalled, false)
assert.strictEqual(codeSequence, 1)
assert.strictEqual(agreementsRead, false)
assert.strictEqual(codeSequence, 0)
reset({ rememberMe: true, agreementVersions: { USER_TERMS: '1', PRIVACY_POLICY: '1' } })
let codeRequestedAfterVersionChange = false
authApi.getCurrentAgreements = async () => [
{ agreementType: 'USER_TERMS', version: '2' },
{ agreementType: 'PRIVACY_POLICY', version: '1' }
]
authApi.wechatQuickLogin = async () => { codeRequestedAfterVersionChange = true }
await appDefinition.runWechatBootstrap()
assert.deepStrictEqual(navigations, ['/pages/login/index'])
assert.strictEqual(codeRequestedAfterVersionChange, false)
assert.strictEqual(codeSequence, 0)
reset({ rememberMe: true, agreementVersions: { USER_TERMS: '1', PRIVACY_POLICY: '1' } })
authApi.getCurrentAgreements = async () => [
{ agreementType: 'USER_TERMS', version: '1' },
{ agreementType: 'PRIVACY_POLICY', version: '1' }
]
authApi.wechatQuickLogin = async () => { throw new Error('网络异常') }
await appDefinition.runWechatBootstrap()
assert.deepStrictEqual(navigations, ['/pages/login/index'])
@@ -62,6 +84,10 @@ async function run() {
assert.strictEqual(appDefinition.globalData.wechatLoginState.status, 'ERROR')
reset({ rememberMe: true, agreementVersions: { USER_TERMS: '1', PRIVACY_POLICY: '1' } })
authApi.getCurrentAgreements = async () => [
{ agreementType: 'USER_TERMS', version: '1' },
{ agreementType: 'PRIVACY_POLICY', version: '1' }
]
authApi.wechatQuickLogin = async () => ({ status: 'SELECT_SHOP', ticket: 'ticket', shops: [{ id: 2 }] })
await appDefinition.runWechatBootstrap()
assert.deepStrictEqual(navigations, ['/pages/login/index'])
+25 -2
View File
@@ -41,10 +41,20 @@ App({
try {
const preference = auth.getLoginPreference()
if (!preference || !preference.rememberMe) {
const status = await authApi.wechatStatus(await this.getWechatCode())
this.publishWechatLoginState(status)
auth.clearSession()
this.globalData.userInfo = null
this.publishWechatLoginState({ status: 'NEED_AGREEMENT' })
this.goLogin()
return
}
const agreements = await authApi.getCurrentAgreements()
const currentVersions = agreementVersions(agreements)
// 协议版本变化后必须重新征求同意,不能先交换 code 再补弹窗。
if (!hasMatchingAgreementVersions(preference.agreementVersions, currentVersions)) {
auth.clearSession()
this.globalData.userInfo = null
this.publishWechatLoginState({ status: 'NEED_AGREEMENT' })
this.goLogin()
return
}
@@ -124,3 +134,16 @@ App({
this.globalData.openEmployeeReview = false
}
})
function agreementVersions(agreements) {
return (Array.isArray(agreements) ? agreements : []).reduce((versions, item) => {
if (item && item.agreementType && item.version) versions[item.agreementType] = item.version
return versions
}, {})
}
function hasMatchingAgreementVersions(accepted, current) {
return Boolean(accepted && current && accepted.USER_TERMS && accepted.PRIVACY_POLICY
&& accepted.USER_TERMS === current.USER_TERMS
&& accepted.PRIVACY_POLICY === current.PRIVACY_POLICY)
}
+1
View File
@@ -19,6 +19,7 @@
"pages/profile/index",
"pages/profile-edit/index",
"pages/account-settings/index",
"pages/legal/index",
"pages/shop-settings/index",
"pages/export/index",
"pages/password/index",
@@ -12,10 +12,51 @@ Page({
codeLoading: false,
countdown: 0,
timer: null,
smsExpanded: false
smsExpanded: false,
unbindMode: false,
closureRequest: null
},
onShow() { this.loadProfile() },
onShow() { this.loadProfile(); this.loadClosureRequest() },
async loadClosureRequest() {
try {
const closureRequest = await userApi.getAccountClosure()
this.setData({ closureRequest: closureRequest || null })
} catch (error) {
this.setData({ closureRequest: null })
}
},
async requestClosure() {
const confirmed = await new Promise(resolve => wx.showModal({
title: '申请注销账号',
content: '申请提交后由管理人员处理。完成后会清理账号身份资料,必要业务记录仍按保存要求保留。你可以在处理前撤回。',
confirmText: '提交申请',
success: result => resolve(result.confirm),
fail: () => resolve(false)
}))
if (!confirmed) return
try {
const closureRequest = await userApi.requestAccountClosure()
this.setData({ closureRequest })
wx.showToast({ title: '注销申请已提交' })
} catch (error) {
wx.showToast({ title: error.message || '申请提交失败', icon: 'none' })
}
},
async withdrawClosure() {
const confirmed = await new Promise(resolve => wx.showModal({ title: '撤回注销申请', content: '确定撤回账号注销申请吗?', success: result => resolve(result.confirm), fail: () => resolve(false) }))
if (!confirmed) return
try {
await userApi.withdrawAccountClosure()
await this.loadClosureRequest()
wx.showToast({ title: '申请已撤回' })
} catch (error) {
wx.showToast({ title: error.message || '撤回失败', icon: 'none' })
}
},
async loadProfile(options = {}) {
this.setData({ loading: true })
@@ -39,7 +80,11 @@ Page({
},
toggleSms() {
this.setData({ smsExpanded: !this.data.smsExpanded })
this.setData({ smsExpanded: !this.data.smsExpanded, unbindMode: false })
},
beginUnbind() {
this.setData({ smsExpanded: true, unbindMode: true, 'smsForm.code': '' })
},
async bindWechatPhone(event) {
@@ -62,13 +107,14 @@ Page({
async sendCode() {
const phone = String(this.data.smsForm.phone || '')
if (!/^1[3-9]\d{9}$/.test(phone)) {
if (!this.data.unbindMode && !/^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)
if (this.data.unbindMode) await userApi.sendUnbindPhoneCode()
else await userApi.sendBindPhoneCode(phone)
this.startCountdown()
wx.showToast({ title: '验证码已发送' })
} catch (error) {
@@ -107,6 +153,33 @@ Page({
}
},
async unbindSmsPhone() {
const code = String(this.data.smsForm.code || '')
if (!/^\d{6}$/.test(code)) {
wx.showToast({ title: '请输入当前手机号收到的6位验证码', icon: 'none' }); return
}
const confirmed = await new Promise(resolve => wx.showModal({
title: '解绑手机号',
content: '解绑后手机号将从账号资料中删除,短信验证码仅用于验证当前手机号。确定继续吗?',
confirmText: '确认解绑',
success: result => resolve(result.confirm),
fail: () => resolve(false)
}))
if (!confirmed) return
this.setData({ binding: true })
try {
await userApi.unbindPhone(code)
profileCache.invalidate()
this.setData({ unbindMode: false, smsExpanded: false, 'smsForm.code': '' })
await this.loadProfile({ force: true })
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
@@ -3,14 +3,28 @@
<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>
<view class="privacy-note">手机号绑定为可选,不绑定不影响基础使用。仅用于账号找回和必要订单通知;不会用于营销。</view>
<button class="wechat-phone-btn" open-type="getPhoneNumber" loading="{{binding}}" bindgetphonenumber="bindWechatPhone">快速{{profile.phoneVerified == 1 ? '更换' : '绑定'}}手机号</button>
<view class="sms-entry" bindtap="toggleSms"><text>{{profile.phoneVerified == 1 ? '使用短信验证码更换' : '使用短信验证码绑定'}}</text><text class="sms-arrow {{smsExpanded ? 'expanded' : ''}}">›</text></view>
<view wx:if="{{smsExpanded}}" class="sms-panel">
<view class="field"><input value="{{smsForm.phone}}" data-field="phone" bindinput="onInput" type="number" maxlength="11" placeholder="请输入手机号" /></view>
<view wx:if="{{!unbindMode}}" class="field"><input value="{{smsForm.phone}}" data-field="phone" bindinput="onInput" type="number" maxlength="11" placeholder="请输入手机号" /></view>
<view wx:if="{{unbindMode}}" class="privacy-note">验证码将发送到当前绑定的{{profile.maskedPhone || '手机号'}},仅用于核验解绑操作。</view>
<view wx:if="{{!unbindMode}}" class="privacy-note">发送前再次确认:手机号仅用于账号找回和必要订单通知,不用于营销。</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>
<button wx:if="{{!unbindMode}}" class="sms-bind-btn" loading="{{binding}}" bindtap="bindSmsPhone">验证并绑定</button>
<button wx:if="{{unbindMode}}" class="sms-bind-btn" loading="{{binding}}" bindtap="unbindSmsPhone">验证并解绑</button>
</view>
<view wx:if="{{profile.phoneVerified == 1}}" class="sms-entry unbind-entry" bindtap="beginUnbind"><text>解绑当前手机号</text><text class="sms-arrow">›</text></view>
</view>
<view class="account-note">微信身份是账号登录标识,手机号是可选资料,不作为主账号 ID。</view>
<view class="card closure-card">
<view class="section-title">账号注销</view>
<view wx:if="{{closureRequest && (closureRequest.status === 'PENDING' || closureRequest.status === 'PROCESSING')}}" class="privacy-note">申请处理中,{{closureRequest.processingTargetText || '以管理人员审核和门店交接进度为准'}}</view>
<view wx:elif="{{closureRequest && closureRequest.status === 'APPROVED'}}" class="privacy-note">账号资料已完成清理。</view>
<view wx:elif="{{closureRequest && closureRequest.status === 'REJECTED'}}" class="privacy-note">上次申请未通过:{{closureRequest.reviewerNote || '请联系管理人员'}}</view>
<view wx:else class="privacy-note">可申请注销工作台账号。提交后可在管理人员处理前撤回。</view>
<button wx:if="{{closureRequest && closureRequest.status === 'PENDING'}}" class="closure-btn secondary" bindtap="withdrawClosure">撤回注销申请</button>
<button wx:elif="{{!closureRequest || closureRequest.status !== 'APPROVED'}}" class="closure-btn" bindtap="requestClosure">申请注销账号</button>
</view>
<view class="account-note">手机号仅用于账号安全与必要联系,不作为微信快捷登录标识。</view>
<button class="logout-btn" bindtap="logout">退出登录</button>
</view>
@@ -1,2 +1,16 @@
.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:#e5f4ed; color:#247b63; font-size:28rpx; font-weight:800; }.identity-copy { display:flex; flex:1; flex-direction:column; margin-left:18rpx; }.identity-title,.section-title { color:#17211f; font-size:28rpx; font-weight:800; }.identity-status { margin-top:6rpx; color:#71807a; 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:#f3f7f4; color:#71807a; 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:#247b63; color:#fff; font-size:26rpx; line-height:80rpx; }.sms-entry { display:flex; min-height:82rpx; align-items:center; margin-top:22rpx; border-top:1rpx solid #e5ebe7; color:#71807a; font-size:23rpx; }.sms-arrow { margin-left:auto; color:#95a198; font-size:36rpx; transition:transform 180ms ease; }.sms-arrow.expanded { transform:rotate(90deg); }.sms-panel { padding-top:2rpx; }.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:#247b63; }.account-note { margin:24rpx 18rpx; color:#71807a; font-size:21rpx; line-height:1.6; }.logout-btn { margin-top:52rpx; background:transparent; color:#a24f42; font-size:25rpx; }
.privacy-note {
margin: 12rpx 0;
color: #73817b;
font-size: 24rpx;
line-height: 1.6;
}
.unbind-entry {
color: #8a5555;
}
.closure-card { margin-top: 20rpx; padding: 28rpx; }
.closure-btn { height: 76rpx; margin-top: 18rpx; border-radius: 12rpx; background: #fff1ef; color: #9a5147; font-size: 24rpx; line-height: 76rpx; }
.closure-btn.secondary { background: #eef4f0; color: #426c57; }
+23
View File
@@ -0,0 +1,23 @@
const authApi = require('../../api/auth')
Page({
data: { loading: true, agreement: null },
onLoad(options) {
this.load(options && options.type)
},
async load(type) {
const agreementType = type === 'PRIVACY_POLICY' ? 'PRIVACY_POLICY' : 'USER_TERMS'
this.setData({ loading: true })
try {
const agreements = await authApi.getCurrentAgreements()
const agreement = (Array.isArray(agreements) ? agreements : []).find(item => item.agreementType === agreementType)
this.setData({ agreement: agreement || null })
} catch (error) {
wx.showToast({ title: error.message || '协议加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"navigationBarTitleText": "协议与隐私",
"navigationBarBackgroundColor": "#F3F7F4",
"navigationBarTextStyle": "black"
}
+9
View File
@@ -0,0 +1,9 @@
<view class="page legal-page">
<view wx:if="{{loading}}" class="legal-state">正在加载…</view>
<view wx:elif="{{agreement}}" class="legal-document card">
<text class="legal-title">{{agreement.title}}</text>
<text class="legal-version">版本 {{agreement.version}}</text>
<text class="legal-content" selectable>{{agreement.content}}</text>
</view>
<view wx:else class="legal-state">当前内容暂不可用,请稍后重试。</view>
</view>
+6
View File
@@ -0,0 +1,6 @@
.legal-page { padding: 24rpx; }
.legal-document { padding: 32rpx; }
.legal-title { display: block; color: #24332e; font-size: 36rpx; font-weight: 700; }
.legal-version { display: block; margin-top: 12rpx; color: #75827d; font-size: 24rpx; }
.legal-content { display: block; margin-top: 28rpx; color: #3e4c47; font-size: 28rpx; line-height: 1.9; white-space: pre-wrap; }
.legal-state { padding: 80rpx 24rpx; color: #71807a; text-align: center; }
+2
View File
@@ -32,6 +32,8 @@ Page({
{ title: '账号设置', url: '/pages/account-settings/index' },
{ title: '店铺设置', url: '/pages/shop-settings/index' },
{ title: '数据导出', url: '/pages/export/index' },
{ title: '用户协议', url: '/pages/legal/index?type=USER_TERMS' },
{ title: '隐私政策', url: '/pages/legal/index?type=PRIVACY_POLICY' },
{ title: '关于系统', url: '/pages/about/index' }
]
},
-36
View File
@@ -1,36 +0,0 @@
const DEVICE_ID_KEY = 'jayucloud-salon_device_id'
function createDeviceId() {
const randomText = Math.random().toString(36).slice(2, 10)
return `manager-mini-device-${Date.now()}-${randomText}`
}
function assertStorageApi() {
if (typeof wx === 'undefined' || typeof wx.getStorageSync !== 'function' || typeof wx.setStorageSync !== 'function') {
throw new Error('wx storage API is required to build request signature device id')
}
}
function readDeviceId() {
assertStorageApi()
return wx.getStorageSync(DEVICE_ID_KEY) || ''
}
function writeDeviceId(value) {
assertStorageApi()
wx.setStorageSync(DEVICE_ID_KEY, value)
}
function getDeviceId() {
const current = readDeviceId()
if (current) {
return current
}
const next = createDeviceId()
writeDeviceId(next)
return next
}
module.exports = {
getDeviceId
}
+1 -5
View File
@@ -1,9 +1,7 @@
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT, ENABLE_REQUEST_SIGNING } = require('./config')
const auth = require('./auth')
const { getDeviceId } = require('./device')
const { sha256Hex, hmacSha256Hex, buildCanonicalParams, buildJsonPayload, randomNonce } = require('./crypto')
const DEVICE_ID_HEADER = 'X-Device-Id'
const HEADER_TIMESTAMP = 'X-Timestamp'
const HEADER_NONCE = 'X-Nonce'
const HEADER_SIGNATURE = 'X-Signature'
@@ -123,9 +121,7 @@ function isAuthFreePath(url) {
}
function buildSignatureHeaders(options) {
const headers = {
[DEVICE_ID_HEADER]: getDeviceId()
}
const headers = {}
const method = String(options.method || 'GET').toUpperCase()
const accessToken = auth.getAccessToken()
if (accessToken && !isAuthFreePath(options.url)) {