// index.ts
|
// 获取应用实例
|
const app = getApp()
|
|
Page({
|
data: {
|
isShow: false,
|
userInfo: {},
|
hasUserInfo: false,
|
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
canIUseGetUserProfile: false,
|
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
|
},
|
// 事件处理函数
|
bindViewTap() {
|
wx.navigateTo({
|
url: '../logs/logs',
|
})
|
},
|
// getPhoneNumber: function (e) {
|
// console.log(e.detail.errMsg)
|
// console.log(e.detail.iv)
|
// console.log(e.detail.encryptedData)
|
// },
|
|
onLoad() {
|
try {
|
var value = wx.getStorageSync('token')
|
if (value) { // 说明已登录 跳转 页面
|
console.log("获取缓存:" + value)
|
var role = wx.getStorageSync('role')
|
var info = wx.getStorageSync('info')
|
console.log("获取缓存:" + role)
|
if (role == 0) {
|
wx.switchTab({
|
url: '../user/index'
|
})
|
// wx.redirectTo(
|
// {
|
// url: '../user/index'
|
// }
|
// )
|
}
|
if (role == 1) {
|
wx.switchTab({
|
url: '../user/index'
|
})
|
// wx.redirectTo(
|
// {
|
// url: '../user/index'
|
// }
|
// )
|
}
|
wx.switchTab({
|
url: '../user/index'
|
})
|
// wx.navigateTo({
|
// url: '../user/index'
|
// })
|
} else {// 未登录 显示 微信授权页面
|
this.setData({
|
isShow: true
|
})
|
}
|
} catch (e) {
|
}
|
},
|
getPhoneNumber: function (e) {
|
console.log("Pcode", e.detail.code)
|
// 用户拒绝授权
|
if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
|
wx.showToast({
|
icon: "none",
|
title: '请允许获取手机号,否则功能不可用!',
|
})
|
return
|
}
|
console.log("Pcode", e.detail.code)
|
wx.login({
|
success: (res) => {
|
console.log("code", res.code)
|
wx.setStorageSync('uesrCode', res.code)
|
wx.setStorageSync('userPhoneNumberCode',e.detail.code)
|
|
wx.request({
|
url:app.globalData.url+"/wx/checkIdentity",
|
data: {
|
"code": res.code,
|
"phoneNumberCode": e.detail.code
|
},
|
method: "GET",
|
success:(res)=>{
|
wx.setStorageSync('phone', res.data.msg)
|
if (res.data.data==2) {
|
wx.switchTab({
|
url: '../user/index'
|
})
|
// wx.redirectTo(
|
// { url: '../user/index'
|
// // url: '../user/pubulicty/index'
|
// // url: '../user/loginInfo/index'
|
// }
|
// )
|
}else if(res.data.data==0){
|
wx.switchTab({
|
url: '../user/index'
|
})
|
// wx.redirectTo(
|
// {
|
// url: '../user/index'
|
// }
|
// )
|
}else{
|
wx.switchTab({
|
url: '../user/index'
|
})
|
// wx.redirectTo(
|
// {url: '../user/index'
|
// // url: '../manager/index'
|
// }
|
// )
|
}
|
}
|
})
|
// wx.request({
|
// url: app.globalData.url+"/wx/login",
|
// data: {
|
// "code": res.code,
|
// "phoneNumberCode": e.detail.code
|
// },
|
// method: "GET",
|
// success: (res) => {
|
// // 如果用户已经注册直接进入 未注册进入宣传 role == 0用户 1警员
|
// wx.setStorageSync('token', res.data.data.token)
|
// wx.setStorageSync('role', res.data.data.role)
|
// wx.setStorageSync('id', res.data.data.id)
|
// wx.setStorageSync('card',res.data.data.time)
|
// console.log(res.data.data.id)
|
// if (res.data.data.role == 0) {
|
// var info=wx.getStorageSync('card')
|
// if (info) {
|
// wx.redirectTo(
|
// {
|
// url: '../user/index'
|
// }
|
// )
|
// } else {
|
// wx.redirectTo(
|
// {
|
// url: '../user/pubulicty/index'
|
// // url: '../user/loginInfo/index'
|
// }
|
// )
|
// }
|
// }
|
// if (res.data.data.role == 1) {
|
// wx.redirectTo(
|
// {
|
// url: '../manager/index'
|
// }
|
// )
|
// }
|
// }
|
|
// })
|
}
|
})
|
},
|
// getUserProfile() {
|
// // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
|
// wx.getUserProfile({
|
// desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
// success: (res) => {
|
// console.log(res)
|
// this.setData({
|
// userInfo: res.userInfo,
|
// hasUserInfo: true
|
// })
|
// console.log(this.data.userInfo)
|
// }
|
// })
|
// },
|
// getUserInfo(e: any) {
|
// // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
|
// console.log(e)
|
// this.setData({
|
// userInfo: e.detail.userInfo,
|
// hasUserInfo: true
|
// })
|
|
})
|