重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,104 @@
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { runWithLoading } = require('../../utils/loading')
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
saving: false,
isLoggedIn: false,
userInfo: null,
form: {
verificationCode: '',
password: '',
confirmPassword: ''
}
}),
onShow() {
this.loadProfile()
},
handleBack() {
navigation.goBack('/pages/settings/index')
},
async loadProfile() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
this.setData({ loading: true })
try {
this.setData({
userInfo: await userApi.getUserInfo()
})
} catch (error) {
wx.showToast({ title: error.message || '账号信息加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
handleInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`form.${field}`]: event.detail.value
})
},
async sendCode() {
const phone = String(this.data.userInfo && this.data.userInfo.phone || '').trim()
if (!phone) {
wx.showToast({ title: '请先绑定手机号', icon: 'none' })
return
}
try {
await runWithLoading(() => userApi.sendVerificationCode({
phone,
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
}))
wx.showToast({ title: '验证码已发送', icon: 'none' })
} catch (error) {
wx.showToast({ title: error.message || '验证码发送失败', icon: 'none' })
}
},
async savePassword() {
const verificationCode = String(this.data.form.verificationCode || '').trim()
const password = String(this.data.form.password || '')
const confirmPassword = String(this.data.form.confirmPassword || '')
if (!verificationCode) {
wx.showToast({ title: '请输入验证码', icon: 'none' })
return
}
if (!passwordRegex.test(password)) {
wx.showToast({ title: '密码至少8位且包含字母和数字', icon: 'none' })
return
}
if (password !== confirmPassword) {
wx.showToast({ title: '两次密码不一致', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await runWithLoading(() => userApi.updatePassword({
password,
verificationCode
}))
auth.setNeedSetPassword(false)
wx.showToast({ title: '密码已更新', icon: 'none' })
navigation.goBack('/pages/settings/index')
} catch (error) {
wx.showToast({ title: error.message || '密码更新失败', icon: 'none' })
} finally {
this.setData({ saving: false })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,30 @@
<navigation-bar title="修改密码" showBack="{{true}}" fallbackPath="/pages/settings/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">Security</text>
<text class="hero-title">修改密码</text>
<text class="hero-desc">使用绑定手机号验证码完成密码更新�?/text>
</view>
<view class="page-card form-card">
<view class="field-block">
<text class="field-label">验证�?/text>
<view class="code-row">
<input class="field-input" value="{{form.verificationCode}}" data-field="verificationCode" bindinput="handleInput" placeholder="请输入验证码" placeholder-class="field-placeholder" />
<view class="ghost-btn" bindtap="sendCode">发��?/view>
</view>
</view>
<view class="field-block">
<text class="field-label">新密�?/text>
<input class="field-input" password value="{{form.password}}" data-field="password" bindinput="handleInput" placeholder="至少8位,含字母和数字" placeholder-class="field-placeholder" />
</view>
<view class="field-block">
<text class="field-label">确认密码</text>
<input class="field-input" password value="{{form.confirmPassword}}" data-field="confirmPassword" bindinput="handleInput" placeholder="再次输入新密�? placeholder-class="field-placeholder" />
</view>
<button class="primary-btn" loading="{{saving}}" bindtap="savePassword">更新密码</button>
</view>
</view>
</view>
@@ -0,0 +1,22 @@
.form-card {
margin-top: 22rpx;
padding: 28rpx;
}
.field-block + .field-block {
margin-top: 24rpx;
}
.code-row {
display: flex;
align-items: center;
gap: 16rpx;
}
.code-row .field-input {
flex: 1;
}
.primary-btn {
margin-top: 28rpx;
}