功能:改造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) {
|
||||
|
||||
Reference in New Issue
Block a user