123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import {
- post,
- } from '../../utils/http';
- import {
- objToParam,
- } from '../../utils/util';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userInfo: null,
- prePage: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options)
- if(options.prePage) {
- this.setData({
- prePage: options.prePage
- })
- }
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- /**
- * 获取用户信息
- */
- getUserInfo(e) {
- wx.getUserProfile({
- desc: 'desc',
- success: (res) => {
- this.setData({
- userInfo: JSON.parse(res.rawData)
- })
- console.log(JSON.parse(res.rawData))
- }
- })
- },
- /**
- * 获取用户手机号
- */
- getPhoneNumber(e) {
- let that = this;
- wx.login({
- success(res) {
- post('api/login', {
- js_code: res.code,
- avatar_url: that.data.userInfo.avatarUrl,
- nickname: that.data.userInfo.nickName,
- iv: e.detail.iv,
- encrypted_data: e.detail.encryptedData,
- wx_data: JSON.stringify(that.data.userInfo)
- }, (res) => {
- console.log(res)
- if(res.data.status == 0) {
- wx.showToast({
- title: '未绑定角色,请联系管理员处理!',
- icon: 'none'
- })
- return;
- }
- wx.setStorageSync('token', res.data.token);
- wx.setStorageSync('userInfo', res.data)
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- setTimeout(() => {
- if(that.data.prePage == 1) {
- wx.navigateBack()
- } else {
- let sceneData = getApp().globalData.sceneData
- wx.reLaunch({
- url: `/${sceneData.path}?${objToParam(sceneData.query)}`,
- })
- // wx.switchTab({
- // url: '/pages/home/home',
- // })
- }
- }, 1500);
- })
- }
- })
-
- },
- /**
- * 跳转去用户协议
- */
- goToAgree(e) {
- wx.navigateTo({
- url: '/pages/agreement/agreement?agree=' + e.currentTarget.dataset.agree,
- })
- }
- })
|