Commit fb743853 by liangyuhang

除了详情页需要登录,其他都不需要登录

parent 37bcd045
......@@ -4,20 +4,20 @@ import {getRequest} from './utils/http'
App({
onLaunch() {
//每次打开小程序时刷新token
let openId = wx.getStorageSync('openId');
if(openId){
// console.log(openId)
getRequest('/mobile/refreshToken?openId='+openId).then(res=>{
if(res){
console.log("刷新token")
wx.setStorageSync('token', res.data.data.token)
}
})
}else{
wx.reLaunch({
url: '/pages/login/login',
})
}
// let openId = wx.getStorageSync('openId');
// if(openId){
// // console.log(openId)
// getRequest('/mobile/refreshToken?openId='+openId).then(res=>{
// if(res){
// console.log("刷新token")
// wx.setStorageSync('token', res.data.data.token)
// }
// })
// }else{
// wx.reLaunch({
// url: '/pages/login/login',
// })
// }
},
globalData: {
// userInfo: null,
......
......@@ -51,8 +51,9 @@ Page({
setCrisisDynamicData(){
http.getRequest('/mobile/index/event/recently').then(res=>{
if(res){
// console.log(res)
this.setData({
crisisDynamic:res.data.data.list
crisisDynamic:res.data.data
})
}
})
......
......@@ -49,7 +49,7 @@ Page({
wx.showLoading({
title: '加载中...'
})
http.getRequest('/events?page='+this.data.page+'&size='+this.data.size+'&industry='+this.data.industry).then(res=>{
http.getRequest('/mobile/eventList?page='+this.data.page+'&size='+this.data.size+'&industry='+this.data.industry).then(res=>{
if(res.data.code==200){
// console.log(res)
this.setData({
......
......@@ -46,7 +46,7 @@ Page({
wx.showLoading({
title: '加载中...'
})
http.getRequest('/reports?page='+this.data.page+'&size='+this.data.size+'&category='+this.data.category).then(res=>{
http.getRequest('/mobile/reportList?page='+this.data.page+'&size='+this.data.size+'&category='+this.data.category).then(res=>{
if(res.data.code==200){
this.setData({
reportList:this.data.reportList.concat(res.data.data.list),
......
......@@ -86,7 +86,7 @@ Page({
},
// 获取热点危机
getHotSearch(){
http.getRequest('/search/event/online-top5').then(res=>{
http.getRequest('/mobile/search/event/online-top5').then(res=>{
// console.log(res)
if(res){
this.setData({
......
......@@ -68,7 +68,7 @@ Page({
},
//根据关键词查询事件列表
getEventListByKeyword(params){
http.getRequest('/search/events',params).then(res=>{
http.getRequest('/mobile/search/events',params).then(res=>{
// console.log(res)
if(res){
this.setData({
......@@ -80,7 +80,7 @@ Page({
},
//根据关键词查询报告列表
getReportListByKeyword(params){
http.getRequest('/search/reports',params).then(res=>{
http.getRequest('/mobile/search/reports',params).then(res=>{
// console.log(res)
if(res){
this.setData({
......
......@@ -12,6 +12,53 @@ Page({
headUrl:wx.getStorageSync('headUrl'),
roleId:wx.getStorageSync('roleId')
},
onGetPhoneNumber(e){
wx.showLoading({
title: '正在登录...'
})
if (e.detail.iv) {
wx.login({
success: res => {
// console.log(res)
let data = {
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
code: res.code
}
http.postRequest('/mobile/login',data).then(res=>{
wx.hideLoading()
if(res){
console.log(res)
wx.setStorageSync('token', res.data.data.token)
wx.setStorageSync('userName', res.data.data.userName)
wx.setStorageSync('headUrl', res.data.data.headUrl)
wx.setStorageSync('roleId', res.data.data.roleId)
wx.setStorageSync('isLogin',true)
this.setData({
token:res.data.data.token,
userName:res.data.data.userName,
headUrl:res.data.data.headUrl,
roleId:res.data.data.roleId,
isLogin:true
})
}
})
},
fail: err => {
// console.log('登录失败!')
wx.showToast({
title: '登录失败!',
icon: 'none'
})
}
})
} else {
wx.showToast({
title: '您已拒绝授权',
icon: 'none'
})
}
},
getUserProfile(e){
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
......@@ -25,10 +72,10 @@ Page({
})
},
logout(e){
wx.setStorageSync('token', '')
wx.setStorageSync('userName', '')
wx.setStorageSync('headUrl', '')
wx.setStorageSync('roleId', '')
wx.removeStorageSync('token')
wx.removeStorageSync('userName')
wx.removeStorageSync('headUrl')
wx.removeStorageSync('roleId')
wx.setStorageSync('isLogin',false)
this.setData({
token:'',
......
......@@ -54,6 +54,10 @@
<view wx:if="{{isLogin}}">
<button class="logout-btn" bindtap="logout">退出登录</button>
</view>
<view wx:else>
<button open-type="getPhoneNumber" bindgetphonenumber="onGetPhoneNumber" class="login-btn">点此登录</button>
</view>
</view>
......
......@@ -5,11 +5,11 @@ const imgURL = baseURL+'/app/'
const request = function(url,options){
wx.getStorageSync('token')
let token = wx.getStorageSync('token')
if(url!='/mobile/login' && !token){
wx.reLaunch({
url: '/pages/login/login',
})
}
// if(url!='/mobile/login' && !token){
// wx.reLaunch({
// url: '/pages/login/login',
// })
// }
return new Promise((resolve,reject)=>{
wx.request({
url:baseURL+url,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment