YM
2024-03-26 1c64c10f8dd88018c0d30de79237f3128173f118
调整登录
5个文件已修改
5个文件已添加
371 ■■■■ 已修改文件
.vscode/settings.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app.json 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
assets/js/config.js 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
assets/js/login.js 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
assets/request/index.js 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/bindInfo/index.js 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/bindInfo/index.json 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/bindInfo/index.wxml 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/bindInfo/index.wxss 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.js 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vscode/settings.json
@@ -32,7 +32,7 @@
  },
  "editor.tabSize": 2,
  "[wxml]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
    "editor.defaultFormatter": "wechat.miniprogram.wxml-language-features"
  },
  "[css]": {
    "editor.defaultFormatter": "HookyQR.beautify"
app.json
@@ -12,7 +12,8 @@
    "pages/personalCenter/feedBackSubmit/index",
    "pages/personalCenter/certificate/index",
    "pages/testLogin/index",
    "pages/bookServices/assort/index"
    "pages/bookServices/assort/index",
    "pages/bindInfo/index"
  ],
  "subPackages": [
    {
assets/js/config.js
@@ -1,8 +1,18 @@
// export const requestCtx = "http://182.92.203.7:3001"; // 请求地址
<<<<<<< Updated upstream
export const appId = 27;
// export const requestCtx = "http://jsysf.bnuic.com"; // 请求地址
export const requestCtx = "https://jsek.bnuic.com"  // 请求地址
// export const appId = 3;
=======
// export const appId = 27;
export const requestCtx = "https://jsek.bnuic.com"; // 请求地址
export const appId = 3;
// export const epubUrl = "http://182.92.203.7:3007/epubReadMobile/";
export const epubUrl = "http://jsysf.bnuic.com/epubReadMobile/#/";
>>>>>>> Stashed changes
export const requestTimeOut = 300000; // 请求超时时间
export const tokenKey = "jsek-token";
export const userInfoKey = "website-front-userInfo"; // 用户信息key 
@@ -18,11 +28,7 @@
export const reg_tel =
  /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; // 电话号正则
export const reg_telphone = /^0\d{2}-\d{8}$|^0\d{3}-\d{7}$/; //座机号正则
export const fontUrl = "http://192.168.3.132:5173";
// export const fontUrl = "http://182.92.203.7:3007/jsek/website";
// export const fontUrl = "http://jsysf.bnuic.com/website";
export const epubUrl = "http://182.92.203.7:3007/epubReadMobile/";
// export const epubUrl = "http://jsysf.bnuic.com/epubReadMobile/#/";
const config = {
  requestCtx,
@@ -34,7 +40,6 @@
  digitalCourses,
  digitalTextbooks,
  seminar,
  fontUrl,
  reg_tel,
  reg_telphone,
  epubUrl
assets/js/login.js
New file
@@ -0,0 +1,63 @@
import { setSessionGuid } from "./userAction"
export const checkLoginInfo = (app, callback) => {
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
        wx.login({
            success: (res) => {
                wx.getUserInfo({
                    success: (infoRes) => {
                        app.MG.identity.checkWeChatAppAccount({
                            code: res.code,
                            appCode: app.config.appRefCode,
                            encryptedData: infoRes.encryptedData,
                            iv: infoRes.iv
                        }).then(loginRes => {
                            if (!loginRes) {
                                wx.navigateTo({
                                    url: "/pages/bindInfo/index?code=" + res.code,
                                });
                            } else {
                                wx.login({
                                    success: (res) => {
                                        app.MG.identity.loginByWeChatAppCode({
                                            code: res.code,
                                            appRefCode: app.config.appRefCode,
                                            platform: "weChatAppCustom",
                                            encryptedData: infoRes.encryptedData,
                                            iv: infoRes.iv
                                        }).then(res => {
                                            if (res && res.status == "Ok") {
                                                wx.setStorageSync(app.config.tokenKey, res.token);
                                                setSessionGuid()
                                                callback(res.token)
                                            } else {
                                                console.log(res);
                                                callback(false)
                                            }
                                        })
                                    },
                                    fail: (err) => {
                                        console.log(err);
                                        callback(false)
                                    }
                                })
                            }
                        })
                    },
                    fail: (err) => {
                        console.log(err);
                        callback(false)
                    }
                })
            },
            fail: (err) => {
                console.log(err);
                callback(false)
            }
        })
    } else {
        callback(token)
    }
}
assets/request/index.js
@@ -37,9 +37,10 @@
              backUrl: urlargs
            }
            currentUrl = JSON.stringify(currentUrl)
            wx.reLaunch({
              url: urlargs ? '/pages/home/home?backUrl=' + encodeURIComponent(currentUrl) : '/pages/home/home'
            })
            // 不去首页登录,直接调用公共登录方法
            // wx.reLaunch({
            //   url: urlargs ? '/pages/home/home?backUrl=' + encodeURIComponent(currentUrl) : '/pages/home/home'
            // })
          }
        } else {
          wx.showToast({
@@ -47,11 +48,6 @@
            icon: 'none'
          })
          reject(res.data.message)
          wx.login({
            success: (res) => {
              console.log(res)
            },
          })
        }
      },
      fail: (res) => {
pages/bindInfo/index.js
New file
@@ -0,0 +1,150 @@
// pages/index/bindInfo/index.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    avatarUrl: "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0",
    nickName: "",
    wxCode: null,
  },
  onChooseAvatar(res) {
    wx.compressImage({
      src: res.detail.avatarUrl, // 图片路径
      quality: 50, // 压缩质量
      compressedWidth: 80,
      compressedHeight: 80,
      success: (compressRes) => {
        wx.getFileSystemManager().readFile({
          filePath: compressRes.tempFilePath, //选择图片返回的相对路径
          encoding: 'base64', //编码格式
          success: base64Res => { //成功的回调
            this.setData({
              avatarUrl: 'data:image/png;base64,' + base64Res.data,
            });
          }
        })
      }
    })
  },
  formSubmit() {
    if (this.data.nickName == "") {
      return wx.showToast({
        icon: "error",
        title: "昵称不能为空!",
      });
    }
    wx.getUserInfo({
      success: (infoRes) => {
        wx.login({
          success: (res) => {
            app.MG.identity.loginByWeChatAppCode({
              code: res.code,
              appRefCode: app.config.appRefCode,
              platform: "weChatApp",
              icon: this.data.avatarUrl,
              encryptedData: infoRes.encryptedData,
              iv: infoRes.iv,
              name: this.data.nickName,
            }).then(res => {
              if (res && res.status == "Ok") {
                wx.setStorageSync(app.config.tokenKey, res.token);
                this.getUserInfo()
              }
            })
          },
        })
      }
    })
  },
  // 获取登录用户身份
  getUserInfo() {
    app.MG.identity.getCurrentAppUser().then(res => {
      // console.log(res, "userInfo");
      // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认)
      if (res) {
        let defaultUser = {};
        // let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword')
        let WeChatInfo = res.infoList.find((item) => item.type === "WeChat");
        let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone')
        if (WeChatInfo) {
          defaultUser = {
            nickName: WeChatInfo.name,
            avatarUrl: WeChatInfo.icon,
            weChatId: WeChatInfo.id
          }
        }
        if (phoneNumber) {
          defaultUser.phoneNumber = phoneNumber.credential
        }
        this.setData({
          userInfo: defaultUser,
          loading: false
        })
        wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo));
      }
      wx.switchTab({
        url: '/pages/index/index'
      })
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options, "options");
    this.setData({
      wxCode: options.code
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },
})
pages/bindInfo/index.json
New file
@@ -0,0 +1,3 @@
{
  "usingComponents": {}
}
pages/bindInfo/index.wxml
New file
@@ -0,0 +1,21 @@
<view>
  <view class="avatar-wrap">
    <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
      <image class="avatar" src="{{avatarUrl}}"></image>
    </button>
    <view class="keynote">
      提示:未上传头像,将使用默认图片
    </view>
  </view>
  <form catchsubmit="formSubmit">
    <view class="fromItem">
        <view>
            昵称
        </view>
        <input type="nickname" class="nickNameInput" placeholder="请输入昵称" model:value="{{nickName}}"/>
    </view>
    <view class="submit" >
        <button type="primary" formType="submit" size="default">确认</button>
    </view>
  </form>
</view>
pages/bindInfo/index.wxss
New file
@@ -0,0 +1,42 @@
/* pages/index/bindInfo/index.wxss *//* pages/fillInAvatarNickname/fillInAvatarNickname.wxss */
.avatar-wrap {
  padding-top: 40px;
  padding-bottom: 40rpx;
}
.avatar-wrapper {
  padding: 0;
  width: 56px;
  margin-bottom: 0;
}
.avatar {
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 auto;
}
.keynote {
  font-size: 25rpx;
  color: #333;
  line-height: 50rpx;
  margin: 0 auto;
  margin-top: 20rpx;
  text-align: center;
}
.container {
  display: flex;
}
.fromItem {
  display: flex;
  align-items: center;
  padding: 20rpx;
  border: 1px solid #eee;
}
.nickNameInput {
  padding-left: 100rpx;
}
.submit {
  width: 400rpx;
  margin: 0 auto;
  margin-top: 200rpx;
}
pages/home/home.js
@@ -1,6 +1,6 @@
import { fetchHome } from '../../services/home/home';
import moment from 'moment'
import { setSessionGuid } from "../../assets/js/userAction"
import { checkLoginInfo } from '../../assets/js/login';
const app = getApp()
Page({
  data: {
@@ -58,7 +58,13 @@
        backUrl: backUrl.backUrl
      })
    }
    this.getTestLoginInfo()
    // checkLoginInfo(app, (data) => {
    //   if (data) {
    //     this.getCurrentUserInfo();
    //   }
    // })
    this.init();
  },
  onReachBottom() {
@@ -82,53 +88,6 @@
        'baseRefresh.value': false,
      })
    }, 500);
  },
  // 获取测试登录时的token
  getTestLoginInfo() {
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      wx.login({
        success: (res) => {
          wx.getUserInfo({
            success: (infoRes) => {
              app.MG.identity.checkWeChatAppAccount({
                code: res.code,
                appCode: app.config.appRefCode,
                encryptedData: infoRes.encryptedData,
                iv: infoRes.iv
              }).then(loginRes => {
                if (!loginRes) {
                  // wx.navigateTo({
                  //   url: "/pages/index/bindInfo/index?code=" + res.code,
                  // });
                } else {
                  wx.login({
                    success: (res) => {
                      app.MG.identity.loginByWeChatAppCode({
                        code: res.code,
                        appRefCode: app.config.appRefCode,
                        platform: "weChatApp",
                        encryptedData: infoRes.encryptedData,
                        iv: infoRes.iv
                      }).then(res => {
                        if (res && res.status == "Ok") {
                          wx.setStorageSync(app.config.tokenKey, res.token);
                          setSessionGuid()
                          this.getCurrentUserInfo()
                        }
                      })
                    },
                  })
                }
              })
            }
          })
        },
      })
    } else {
      this.getShoppingCartList();
    }
  },
  getCurrentUserInfo() {
@@ -163,7 +122,6 @@
          url: '/pages/home/home'
        })
      }
    });
  },
  getBannerList() {