diff --git a/JC-Salon-WeChat/app.json b/JC-Salon-WeChat/app.json index 9b532a96..20f2b2a6 100644 --- a/JC-Salon-WeChat/app.json +++ b/JC-Salon-WeChat/app.json @@ -15,6 +15,7 @@ "pages/leave-management/index", "pages/color-setting/index", "pages/profile/index", + "pages/profile-edit/index", "pages/account-settings/index", "pages/shop-settings/index", "pages/export/index", diff --git a/JC-Salon-WeChat/pages/planning/index.js b/JC-Salon-WeChat/pages/planning/index.js index 2bb2e458..91e54162 100644 --- a/JC-Salon-WeChat/pages/planning/index.js +++ b/JC-Salon-WeChat/pages/planning/index.js @@ -3,6 +3,7 @@ const dateUtil = require('../../utils/date') const userApi = require('../../api/user') const auth = require('../../utils/auth') const { uploadProfileImage } = require('../../utils/upload') +const { normalizeAvatar } = require('../../utils/profile-card') function canCreateAppointment() { const app = getApp() @@ -117,11 +118,12 @@ Page({ 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 avatar = normalizeAvatar(profile.avatar) 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 || '' } + profilePromptVisible: !skipped && (missingNickname || !avatar), + profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar } }) } catch (error) { // 资料提醒失败不影响规划数据。 diff --git a/JC-Salon-WeChat/pages/profile-edit/index.js b/JC-Salon-WeChat/pages/profile-edit/index.js new file mode 100644 index 00000000..48873846 --- /dev/null +++ b/JC-Salon-WeChat/pages/profile-edit/index.js @@ -0,0 +1,140 @@ +const userApi = require('../../api/user') +const auth = require('../../utils/auth') +const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload') +const { buildProfileCard, normalizeAvatar } = require('../../utils/profile-card') +const { BRAND_CONFIG } = require('../../utils/config') + +function resolveRoleText(type) { + const role = Number(type) + if (role === 2) return '店长' + if (role === 3) return '美甲师' + if (role === 4) return '管理员' + return '管理端' +} + +function buildPageState(profile, fallbackShopName) { + const source = profile || {} + const card = buildProfileCard(source, fallbackShopName) + return { + profile: source, + avatarText: card.avatarText, + roleText: resolveRoleText(source.type), + shopName: card.shopName, + form: { + nickname: source.nickname || '', + avatar: normalizeAvatar(source.avatar), + contactPhone: source.contactPhone || '', + wechatId: source.wechatId || '', + signature: source.signature || '' + } + } +} + +Page({ + data: { + loading: true, + saving: false, + avatarUploading: false, + profile: {}, + avatarText: '用', + roleText: '管理端', + shopName: BRAND_CONFIG.defaultShopName, + form: { nickname: '', avatar: '', contactPhone: '', wechatId: '', signature: '' } + }, + + onLoad() { + const app = getApp() + const state = buildPageState(app.globalData.userInfo || {}, app.globalData.shopName || BRAND_CONFIG.defaultShopName) + this.setData(state) + }, + + onShow() { + this.loadProfile() + }, + + async loadProfile() { + this.setData({ loading: true }) + try { + const profile = await userApi.info() + this.syncProfileToSession(profile) + } catch (error) { + wx.showToast({ title: error.message || '个人信息加载失败', icon: 'none' }) + } finally { + this.setData({ loading: false }) + } + }, + + syncProfileToSession(profile) { + const app = getApp() + const session = auth.getSession() + const current = session.userInfo || app.globalData.userInfo || {} + const next = { + ...current, + ...profile, + nickname: profile.nickname || '', + avatar: profile.avatar || '', + contactPhone: profile.contactPhone || '', + wechatId: profile.wechatId || '', + signature: profile.signature || '', + shopName: profile.shopName || current.shopName || session.shopName || app.globalData.shopName || '' + } + app.setSession({ ...session, shopName: next.shopName || session.shopName, userInfo: next }) + this.setData(buildPageState(next, app.globalData.shopName || BRAND_CONFIG.defaultShopName)) + }, + + onInput(event) { + this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) + }, + + async chooseAvatar() { + if (this.data.avatarUploading || this.data.saving) return + try { + const filePath = await chooseImageFilePath() + if (!filePath) return + this.setData({ avatarUploading: true }) + const avatar = await uploadProfileImage(filePath) + this.setData({ 'form.avatar': avatar }) + } catch (error) { + wx.showToast({ title: error.message || '头像上传失败', icon: 'none' }) + } finally { + this.setData({ avatarUploading: false }) + } + }, + + removeAvatar() { + if (!this.data.avatarUploading && !this.data.saving) this.setData({ 'form.avatar': '' }) + }, + + async save() { + if (this.data.saving || this.data.avatarUploading) return + const form = this.data.form + const nickname = String(form.nickname || '').trim() + const contactPhone = String(form.contactPhone || '').trim() + if (!nickname) { + wx.showToast({ title: '请填写昵称', icon: 'none' }) + return + } + if (contactPhone && !/^1[3-9]\d{9}$/.test(contactPhone)) { + wx.showToast({ title: '请输入正确联系电话', icon: 'none' }) + return + } + this.setData({ saving: true }) + try { + await userApi.updateInfo({ + nickname, + avatar: form.avatar || '', + contactPhone, + wechatId: String(form.wechatId || '').trim(), + signature: String(form.signature || '').trim() + }) + const profile = await userApi.info() + this.syncProfileToSession(profile) + wx.showToast({ title: '已保存', icon: 'success' }) + setTimeout(() => wx.navigateBack(), 350) + } catch (error) { + wx.showToast({ title: error.message || '保存失败', icon: 'none' }) + } finally { + this.setData({ saving: false }) + } + } +}) diff --git a/JC-Salon-WeChat/pages/profile-edit/index.json b/JC-Salon-WeChat/pages/profile-edit/index.json new file mode 100644 index 00000000..d39c5f00 --- /dev/null +++ b/JC-Salon-WeChat/pages/profile-edit/index.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "个人信息" +} diff --git a/JC-Salon-WeChat/pages/profile-edit/index.wxml b/JC-Salon-WeChat/pages/profile-edit/index.wxml new file mode 100644 index 00000000..d1a1706f --- /dev/null +++ b/JC-Salon-WeChat/pages/profile-edit/index.wxml @@ -0,0 +1,33 @@ + + 正在加载个人信息... + + + + + {{avatarText}} + + + 个人头像 + 上传清晰头像,方便门店成员识别 + + + + + + 基本资料 + + 昵称 + 联系电话 + 微信号 + 个性签名