123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- // pages/mine/index.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- toolHeight: app.globalData.statusBarHeight,
- loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
- roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : [],
- avatar: '',
- name: '',
- phone: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- wx.login({
- success: (res) => {
- console.log(res.code)
- }
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- const roleCodeList = wx.getStorageSync('roleCodeList')
- let loginStatus = wx.getStorageSync('loginStatus')
- this.setData({
- roleCodeList: roleCodeList ? roleCodeList : [],
- loginStatus: loginStatus ? loginStatus : false,
- avatar: wx.getStorageSync('avatar') ? wx.getStorageSync('avatar') : '/images/headerImg.png',
- name: wx.getStorageSync('name') ? wx.getStorageSync('name') : '未填写',
- phone: wx.getStorageSync('phone') ? wx.getStorageSync('phone') : '手机号',
- })
- // let selected = 2
- // //动态tabbar
- // if (roleCodeList == 'bizAdmin') {
- // this.getTabBar().setData({
- // list: app.globalData.allList[0].list2,
- // })
- // selected = 4
- // } else if (roleCodeList == 'send') {
- // this.getTabBar().setData({
- // list: app.globalData.allList[0].list3,
- // })
- // selected = 1
- // } else if (roleCodeList == 'sale') {
- // this.getTabBar().setData({
- // list: app.globalData.allList[0].list4,
- // })
- // } else if (roleCodeList == 'customer') {
- // this.getTabBar().setData({
- // list: app.globalData.allList[0].list5,
- // })
- // } else if (roleCodeList == 'driver' || roleCodeList == '') {
- // this.getTabBar().setData({
- // list: app.globalData.allList[0].list1,
- // })
- // }
- // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
- // this.getTabBar().setData({
- // selected: selected
- // })
- // }
- },
- //获取用户信息
- getInfo: function () {
- },
- //绑定微信
- bindingWX: function () {
- let _this = this;
- if (this.data.loginStatus) {
- wx.showModal({
- title: '提示',
- content: '确定绑定该微信账号?',
- success: function (res) {
- if (res.confirm) {
- wx.login({
- success: (res) => {
- app.request.POST({
- url: app.API.bindingWX,
- params: {
- 'id': wx.getStorageSync('id'),
- 'js_code': res.code
- },
- page: _this,
- isLoadingTxt: '绑定中...',
- isSubmitting: true,
- successFun: true
- }).then(res => {
- wx.showToast({
- title: '绑定成功',
- icon: 'success',
- duration: 2000,
- complete: function () {
- setTimeout(() => {
- wx.navigateBack()
- }, 1500) //延迟时间
- }
- })
- })
- },
- })
- }
- }
- })
- } else {
- wx.showToast({
- title: '您还未登录!',
- icon: 'none',
- duration: 1500,
- mask: true
- })
- }
- },
- toLogin: function () { //跳转至账号登录页面
- wx.navigateTo({
- url: '../login/index?page=mine',
- })
- },
- // 菜单页面跳转
- toLink: function (e) {
- if (this.data.loginStatus) {
- wx.navigateTo({
- url: e.currentTarget.dataset.url,
- })
- } else {
- wx.showToast({
- icon: 'none',
- title: '登录后可操作',
- duration: 1500
- })
- }
- },
- //退出登录
- logout: function (e) {
- let _this = this
- if (this.data.loginStatus) {
- wx.showModal({
- title: '提示',
- content: '确定退出登录?',
- success: function (res) {
- if (res.confirm) {
- app.request.GET({
- url: app.API.logout,
- page: _this,
- successFun: true
- }).then(res => {
- wx.clearStorageSync()
- _this.setData({
- loginStatus: false
- })
- _this.onShow()
- // _this.getTabBar().setData({
- // list: app.globalData.allList[0].list1,
- // })
- wx.showToast({
- title: '退出成功',
- icon: 'success',
- duration: 2000,
- complete: function () {
- setTimeout(function () {
- // wx.reLaunch({
- // url: '/pages/login/index',
- // })
- }, 1500) //延迟时间
- }
- })
- })
- }
- }
- })
- } else {
- app.util.checkForm('登录后可操作')
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|