Commit fb743853 by liangyuhang

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

parent 37bcd045
...@@ -4,20 +4,20 @@ import {getRequest} from './utils/http' ...@@ -4,20 +4,20 @@ import {getRequest} from './utils/http'
App({ App({
onLaunch() { onLaunch() {
//每次打开小程序时刷新token //每次打开小程序时刷新token
let openId = wx.getStorageSync('openId'); // let openId = wx.getStorageSync('openId');
if(openId){ // if(openId){
// console.log(openId) // // console.log(openId)
getRequest('/mobile/refreshToken?openId='+openId).then(res=>{ // getRequest('/mobile/refreshToken?openId='+openId).then(res=>{
if(res){ // if(res){
console.log("刷新token") // console.log("刷新token")
wx.setStorageSync('token', res.data.data.token) // wx.setStorageSync('token', res.data.data.token)
} // }
}) // })
}else{ // }else{
wx.reLaunch({ // wx.reLaunch({
url: '/pages/login/login', // url: '/pages/login/login',
}) // })
} // }
}, },
globalData: { globalData: {
// userInfo: null, // userInfo: null,
......
...@@ -51,8 +51,9 @@ Page({ ...@@ -51,8 +51,9 @@ Page({
setCrisisDynamicData(){ setCrisisDynamicData(){
http.getRequest('/mobile/index/event/recently').then(res=>{ http.getRequest('/mobile/index/event/recently').then(res=>{
if(res){ if(res){
// console.log(res)
this.setData({ this.setData({
crisisDynamic:res.data.data.list crisisDynamic:res.data.data
}) })
} }
}) })
......
...@@ -49,7 +49,7 @@ Page({ ...@@ -49,7 +49,7 @@ Page({
wx.showLoading({ wx.showLoading({
title: '加载中...' 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){ if(res.data.code==200){
// console.log(res) // console.log(res)
this.setData({ this.setData({
......
...@@ -46,7 +46,7 @@ Page({ ...@@ -46,7 +46,7 @@ Page({
wx.showLoading({ wx.showLoading({
title: '加载中...' 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){ if(res.data.code==200){
this.setData({ this.setData({
reportList:this.data.reportList.concat(res.data.data.list), reportList:this.data.reportList.concat(res.data.data.list),
......
...@@ -86,7 +86,7 @@ Page({ ...@@ -86,7 +86,7 @@ Page({
}, },
// 获取热点危机 // 获取热点危机
getHotSearch(){ getHotSearch(){
http.getRequest('/search/event/online-top5').then(res=>{ http.getRequest('/mobile/search/event/online-top5').then(res=>{
// console.log(res) // console.log(res)
if(res){ if(res){
this.setData({ this.setData({
......
...@@ -68,7 +68,7 @@ Page({ ...@@ -68,7 +68,7 @@ Page({
}, },
//根据关键词查询事件列表 //根据关键词查询事件列表
getEventListByKeyword(params){ getEventListByKeyword(params){
http.getRequest('/search/events',params).then(res=>{ http.getRequest('/mobile/search/events',params).then(res=>{
// console.log(res) // console.log(res)
if(res){ if(res){
this.setData({ this.setData({
...@@ -80,7 +80,7 @@ Page({ ...@@ -80,7 +80,7 @@ Page({
}, },
//根据关键词查询报告列表 //根据关键词查询报告列表
getReportListByKeyword(params){ getReportListByKeyword(params){
http.getRequest('/search/reports',params).then(res=>{ http.getRequest('/mobile/search/reports',params).then(res=>{
// console.log(res) // console.log(res)
if(res){ if(res){
this.setData({ this.setData({
......
...@@ -12,6 +12,53 @@ Page({ ...@@ -12,6 +12,53 @@ Page({
headUrl:wx.getStorageSync('headUrl'), headUrl:wx.getStorageSync('headUrl'),
roleId:wx.getStorageSync('roleId') 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){ getUserProfile(e){
wx.getUserProfile({ wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
...@@ -25,10 +72,10 @@ Page({ ...@@ -25,10 +72,10 @@ Page({
}) })
}, },
logout(e){ logout(e){
wx.setStorageSync('token', '') wx.removeStorageSync('token')
wx.setStorageSync('userName', '') wx.removeStorageSync('userName')
wx.setStorageSync('headUrl', '') wx.removeStorageSync('headUrl')
wx.setStorageSync('roleId', '') wx.removeStorageSync('roleId')
wx.setStorageSync('isLogin',false) wx.setStorageSync('isLogin',false)
this.setData({ this.setData({
token:'', token:'',
......
...@@ -54,6 +54,10 @@ ...@@ -54,6 +54,10 @@
<view wx:if="{{isLogin}}"> <view wx:if="{{isLogin}}">
<button class="logout-btn" bindtap="logout">退出登录</button> <button class="logout-btn" bindtap="logout">退出登录</button>
</view> </view>
<view wx:else>
<button open-type="getPhoneNumber" bindgetphonenumber="onGetPhoneNumber" class="login-btn">点此登录</button>
</view>
</view> </view>
......
...@@ -5,11 +5,11 @@ const imgURL = baseURL+'/app/' ...@@ -5,11 +5,11 @@ const imgURL = baseURL+'/app/'
const request = function(url,options){ const request = function(url,options){
wx.getStorageSync('token') wx.getStorageSync('token')
let token = wx.getStorageSync('token') let token = wx.getStorageSync('token')
if(url!='/mobile/login' && !token){ // if(url!='/mobile/login' && !token){
wx.reLaunch({ // wx.reLaunch({
url: '/pages/login/login', // url: '/pages/login/login',
}) // })
} // }
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
wx.request({ wx.request({
url:baseURL+url, 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