Codex Assistant
昨天 afeeed281e60466b576fbe74d339634cc5d07b82
wx/pages/profile/personal-info.js
@@ -157,10 +157,17 @@
          title: '获取中...'
        })
        
        // TODO: 调用后端API解密手机号
        // 调用后端API解密手机号
        const app = getApp()
        const sessionKey = app.globalData.sessionKey
        if (!sessionKey) {
          throw new Error('SessionKey不存在,请重新登录')
        }
        const mutation = `
          mutation DecryptPhoneNumber($encryptedData: String!, $iv: String!) {
            decryptPhoneNumber(encryptedData: $encryptedData, iv: $iv) {
          mutation DecryptPhoneNumber($encryptedData: String!, $iv: String!, $sessionKey: String!) {
            decryptPhoneNumber(encryptedData: $encryptedData, iv: $iv, sessionKey: $sessionKey) {
              phoneNumber
            }
          }
@@ -168,7 +175,8 @@
        
        const variables = {
          encryptedData: e.detail.encryptedData,
          iv: e.detail.iv
          iv: e.detail.iv,
          sessionKey: sessionKey
        }
        
        const result = await graphqlRequest(mutation, variables)
@@ -229,10 +237,13 @@
      return
    }
    if (!userInfo.phone) {
      wx.showToast({
        title: '请获取手机号',
        icon: 'none'
    // 强制要求授权电话号码
    if (!userInfo.phone || userInfo.phone.trim() === '') {
      wx.showModal({
        title: '需要授权手机号',
        content: '根据平台规定,必须授权手机号码才能保存用户信息。请先获取手机号码授权。',
        showCancel: false,
        confirmText: '我知道了'
      })
      return
    }
@@ -284,15 +295,17 @@
        // 保存到本地存储
        wx.setStorageSync('userInfo', app.globalData.userInfo)
        wx.showToast({
        // 显示保存成功提示,并提醒需要重新登录
        wx.showModal({
          title: '保存成功',
          icon: 'success'
          content: '用户信息已保存成功。为了获取最新的关联信息(如参赛者、评委、员工身份),系统将重新登录。',
          showCancel: false,
          confirmText: '确定',
          success: () => {
            // 强制重新登录以获取最新的用户关联信息
            this.forceRelogin()
          }
        })
        // 延迟返回上一页
        setTimeout(() => {
          wx.navigateBack()
        }, 1500)
      } else {
        throw new Error('保存失败')
      }
@@ -385,5 +398,56 @@
  // 获取文件扩展名
  getFileExtension(fileName) {
    return fileName.split('.').pop().toLowerCase()
  },
  // 强制重新登录
  forceRelogin() {
    wx.showLoading({
      title: '重新登录中...'
    })
    try {
      // 清除本地存储的登录信息
      wx.removeStorageSync('token')
      wx.removeStorageSync('userInfo')
      wx.removeStorageSync('sessionKey')
      // 清除全局数据
      app.globalData.token = null
      app.globalData.userInfo = null
      app.globalData.sessionKey = null
      console.log('已清除本地登录信息,准备重新登录')
      // 重新调用登录流程
      app.login()
      // 延迟一段时间后隐藏loading并返回上一页
      setTimeout(() => {
        wx.hideLoading()
        wx.showToast({
          title: '重新登录完成',
          icon: 'success'
        })
        // 返回上一页
        setTimeout(() => {
          wx.navigateBack()
        }, 1000)
      }, 2000)
    } catch (error) {
      console.error('强制重新登录失败:', error)
      wx.hideLoading()
      wx.showToast({
        title: '重新登录失败',
        icon: 'none'
      })
      // 即使失败也返回上一页
      setTimeout(() => {
        wx.navigateBack()
      }, 1500)
    }
  }
})