功能:改造Salon小程序OpenID快捷登录
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user