Commit 47d21696 by liangyuhang

重新封装request,添加登录页

parent a59abf8d
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
"pages/search-page/search-page", "pages/search-page/search-page",
"pages/search-result/search-result", "pages/search-result/search-result",
"pages/event-detail/event-detail", "pages/event-detail/event-detail",
"pages/out/out" "pages/out/out",
"pages/login/login"
], ],
"window": { "window": {
...@@ -46,5 +47,6 @@ ...@@ -46,5 +47,6 @@
] ]
}, },
"style": "v2", "style": "v2",
"sitemapLocation": "sitemap.json" "sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
border-bottom: 1px solid #e3e4e4; border-bottom: 1px solid #e3e4e4;
} }
.list .image-box{ .list .image-box{
width: 150rpx; width: 200rpx;
text-align:center; text-align:center;
} }
.list .image-box image{ .list .image-box image{
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
} }
.r .title{ .r .title{
font-weight: bold; font-weight: bold;
font-size: 30rpx; font-size: 28rpx;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.r .score{ .r .score{
position: absolute; position: absolute;
font-size: 28rpx; font-size: 26rpx;
color: #A0A0A0; color: #999;
top: 50rpx; top: 50rpx;
left: 0; left: 0;
} }
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
} }
.r .time{ .r .time{
position: absolute; position: absolute;
font-size: 28rpx; font-size: 26rpx;
color: #A0A0A0; color: #999;
bottom: 15rpx; bottom: 15rpx;
right: 0; right: 0;
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
border-bottom: 1px solid #e3e4e4; border-bottom: 1px solid #e3e4e4;
} }
.list .image-box{ .list .image-box{
width: 150rpx; width: 200rpx;
text-align:center; text-align:center;
} }
.list .image-box image{ .list .image-box image{
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
} }
.r .title{ .r .title{
font-weight: bold; font-weight: bold;
font-size: 30rpx; font-size: 28rpx;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.r .score{ .r .score{
position: absolute; position: absolute;
font-size: 28rpx; font-size: 26rpx;
color: #A0A0A0; color: #999;
top: 50rpx; top: 50rpx;
left: 0; left: 0;
} }
...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
} }
.r .time{ .r .time{
position: absolute; position: absolute;
font-size: 28rpx; font-size: 26rpx;
color: #A0A0A0; color: #999;
bottom: 15rpx; bottom: 15rpx;
right: 0; right: 0;
} }
\ No newline at end of file
...@@ -149,37 +149,19 @@ function getOption(list,times){ ...@@ -149,37 +149,19 @@ function getOption(list,times){
name: '正', name: '正',
data: posCountList, data: posCountList,
type: 'line', type: 'line',
smooth: true, smooth: true
markLine: {
data: [
{ type: 'max', name: '峰值' },
{ type: 'average', name: '均值' }
]
}
}, },
{ {
name: '中', name: '中',
data: neuCountList, data: neuCountList,
type: 'line', type: 'line',
smooth: true, smooth: true
markLine: {
data: [
{ type: 'max', name: '峰值' },
{ type: 'average', name: '均值' }
]
}
}, },
{ {
name: '负', name: '负',
data: negCountList, data: negCountList,
type: 'line', type: 'line',
smooth: true, smooth: true
markLine: {
data: [
{ type: 'max', name: '峰值' },
{ type: 'average', name: '均值' }
]
}
}, },
] ]
}; };
......
...@@ -44,7 +44,7 @@ Page({ ...@@ -44,7 +44,7 @@ Page({
}, },
getVenation(){ getVenation(){
http.getRequest('/events/'+this.data.eventId+'/venation').then(res=>{ http.getRequest('/events/'+this.data.eventId+'/venation').then(res=>{
if(res.data.success){ if(res){
this.setData({ this.setData({
venation:res.data.data venation:res.data.data
}) })
...@@ -58,7 +58,7 @@ Page({ ...@@ -58,7 +58,7 @@ Page({
}, },
getOverview(){ getOverview(){
http.getRequest('/events/'+this.data.eventId+'/overview').then(res=>{ http.getRequest('/events/'+this.data.eventId+'/overview').then(res=>{
if(res.data.success){ if(res){
this.setData({ this.setData({
overview:res.data.data overview:res.data.data
}) })
...@@ -72,7 +72,7 @@ Page({ ...@@ -72,7 +72,7 @@ Page({
}, },
getDetail(){ getDetail(){
http.getRequest('/events/'+this.data.eventId+'/detail').then(res=>{ http.getRequest('/events/'+this.data.eventId+'/detail').then(res=>{
if(res.data.success){ if(res){
this.setData({ this.setData({
detail:res.data.data, detail:res.data.data,
hasCollect:res.data.data.hasCollect hasCollect:res.data.data.hasCollect
...@@ -87,7 +87,7 @@ Page({ ...@@ -87,7 +87,7 @@ Page({
}, },
getLine(){ getLine(){
http.getRequest('/events/'+this.data.eventId+'/spread/line').then(res=>{ http.getRequest('/events/'+this.data.eventId+'/spread/line').then(res=>{
if(res.data.success){ if(res){
this.setData({ this.setData({
line: res.data.data line: res.data.data
}) })
...@@ -103,7 +103,7 @@ Page({ ...@@ -103,7 +103,7 @@ Page({
collect(e){ collect(e){
var _eventId=e.currentTarget.dataset.id; var _eventId=e.currentTarget.dataset.id;
http.postRequest('/collects/event/'+_eventId).then(res=>{ http.postRequest('/collects/event/'+_eventId).then(res=>{
if(res.data.success){ if(res){
this.setData({ this.setData({
hasCollect:true hasCollect:true
}) })
...@@ -118,7 +118,7 @@ Page({ ...@@ -118,7 +118,7 @@ Page({
cancelCollect(e){ cancelCollect(e){
var _eventId=e.currentTarget.dataset.id; var _eventId=e.currentTarget.dataset.id;
http.deleteRequest('/collects/event/'+_eventId).then(res=>{ http.deleteRequest('/collects/event/'+_eventId).then(res=>{
if(res.data.success){ if(res){
this.setData({ this.setData({
hasCollect:false hasCollect:false
}) })
......
...@@ -125,5 +125,28 @@ Page({ ...@@ -125,5 +125,28 @@ Page({
wx.navigateTo({ wx.navigateTo({
url: '/pages/out/out?url='+_url url: '/pages/out/out?url='+_url
}) })
} },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
// 重置关键数据
this.setData({
crisisDynamic:[],
crisisField:[],
crisisArticle:[],
crisisReport:[],
showBanner:true
})
// 重新发起请求
var _this = this;
setTimeout(function() {
_this.setCrisisDynamicData();
_this.setCrisisFieldData();
_this.setCrisisArticleData();
_this.setCrisisReportData();
wx.stopPullDownRefresh() //停止下拉刷新
}, 200);
},
}) })
...@@ -46,13 +46,17 @@ ...@@ -46,13 +46,17 @@
<swiper indicator-dots="true" autoplay="true" class="carousel" circular="true"> <swiper indicator-dots="true" autoplay="true" class="carousel" circular="true">
<block wx:for="{{crisisDynamic}}" wx:key="index"> <block wx:for="{{crisisDynamic}}" wx:key="index">
<swiper-item bindtap="toEventDetail" data-id="{{item.id}}"> <swiper-item bindtap="toEventDetail" data-id="{{item.id}}">
<image class="dynamic_img" src="https://d1icd6shlvmxi6.cloudfront.net/gsc/L5VHPP/e9/83/b8/e983b88902ca4085bcbc34d714ac6904/images/首页/u22.svg?pageId=794f4729-ba77-4770-92d6-71dfe84a18c1" mode="scaleToFill" /> <image class="dynamic_img" src="https://d1icd6shlvmxi6.cloudfront.net/gsc/L5VHPP/e9/83/b8/e983b88902ca4085bcbc34d714ac6904/images/首页/u22.svg?pageId=794f4729-ba77-4770-92d6-71dfe84a18c1" mode="scaleToFill" lazy-load="true" />
<image class="dynamic_img2" src="https://d1icd6shlvmxi6.cloudfront.net/gsc/L5VHPP/e9/83/b8/e983b88902ca4085bcbc34d714ac6904/images/%E9%A6%96%E9%A1%B5/u21.png?pageId=794f4729-ba77-4770-92d6-71dfe84a18c1" mode="scaleToFill" /> <image class="dynamic_img2" src="https://d1icd6shlvmxi6.cloudfront.net/gsc/L5VHPP/e9/83/b8/e983b88902ca4085bcbc34d714ac6904/images/%E9%A6%96%E9%A1%B5/u21.png?pageId=794f4729-ba77-4770-92d6-71dfe84a18c1" mode="scaleToFill" lazy-load="true"/>
<text class="dynamic_title">{{item.title}}</text> <view class="dynamic_title">{{item.title}}</view>
<text class="dynamic_level">{{item.crisisLevelZh}}风险</text> <view class="dynamic_level">{{item.crisisLevelZh}}风险</view>
<text class="dynamic_introduction">摘要:{{item.introduction}}</text> <view class="dynamic_introduction">摘要:{{item.introduction}}</view>
<text class="dynamic_brand">{{item.priBrand}}</text> <view class="dynamic_tag">
<text class="dynamic_tag">{{item.priCrisisTags}}</text> <view class="brand">{{item.priBrand}}</view>
<block wx:for="{{item.priCrisisTags}}" wx:key="index">
<view class="crisis">{{item}}</view>
</block>
</view>
</swiper-item> </swiper-item>
</block> </block>
</swiper> </swiper>
......
...@@ -103,11 +103,13 @@ ...@@ -103,11 +103,13 @@
/* 危机动态 */ /* 危机动态 */
.carousel{ .carousel{
padding: 30rpx;
position: relative; position: relative;
padding: 0 30rpx;
margin-top: 30rpx;
} }
.carousel .dynamic_img{ .carousel .dynamic_img{
position: absolute; position: absolute;
border-radius: 5px;
} }
.carousel .dynamic_title{ .carousel .dynamic_title{
position: absolute; position: absolute;
...@@ -126,6 +128,8 @@ ...@@ -126,6 +128,8 @@
padding: 5rpx 25rpx; padding: 5rpx 25rpx;
background-color: #f87653; background-color: #f87653;
text-align: center; text-align: center;
border-bottom-left-radius: 5px;
border-top-right-radius: 5px;
} }
.carousel .dynamic_introduction{ .carousel .dynamic_introduction{
position: absolute; position: absolute;
...@@ -137,23 +141,23 @@ ...@@ -137,23 +141,23 @@
text-overflow: ellipsis; text-overflow: ellipsis;
line-clamp: 1; line-clamp: 1;
} }
.carousel .dynamic_brand{ .carousel .dynamic_tag{
position: absolute; position: absolute;
bottom: 50rpx; bottom: 50rpx;
left: 30rpx; left: 30rpx;
font-size: 26rpx;
text-align: center;
display: flex;
}
.carousel .dynamic_tag .brand{
padding: 5rpx 25rpx; padding: 5rpx 25rpx;
background-color: #BAB7B6; background-color: #BAB7B6;
font-size: 26rpx; margin-right: 20rpx;
text-align: center;
} }
.carousel .dynamic_tag{ .carousel .dynamic_tag .crisis{
position: absolute;
bottom: 50rpx;
left: 200rpx;
padding: 5rpx 25rpx; padding: 5rpx 25rpx;
background-color: #BAB7B6; background-color: #BAB7B6;
font-size: 26rpx; margin-right: 20rpx;
text-align: center;
} }
/* 聚焦领域 */ /* 聚焦领域 */
...@@ -233,9 +237,6 @@ ...@@ -233,9 +237,6 @@
font-size: 24rpx; font-size: 24rpx;
} }
/* 危机复盘 */ /* 危机复盘 */
.article-content{ .article-content{
padding: 0 30rpx; padding: 0 30rpx;
...@@ -259,8 +260,8 @@ ...@@ -259,8 +260,8 @@
width: 400rpx; width: 400rpx;
} }
.article .content .article-title{ .article .content .article-title{
font-weight: bold;
font-size: 28rpx; font-size: 28rpx;
font-weight: bold;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
...@@ -335,12 +336,12 @@ ...@@ -335,12 +336,12 @@
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
width: 100%; width: 100%;
font-weight: 28rpx; font-size: 28rpx;
font-weight: bold; font-weight: bold;
} }
.content .report-introduction{ .content .report-introduction{
position: absolute; position: absolute;
top: 50rpx; top: 40rpx;
left: 0; left: 0;
color: #999; color: #999;
font-size: 24rpx; font-size: 24rpx;
......
// pages/login/login.js
var http = require('../../utils/http')
Page({
/**
* 页面的初始数据
*/
data: {
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
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
})
wx.reLaunch({
url: '/pages/index/index',
})
}
})
},
fail: err => {
// console.log('登录失败!')
wx.showToast({
title: '登录失败!',
icon: 'none'
})
}
})
} else {
wx.showToast({
title: '您已拒绝授权',
icon: 'none'
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/login/login.wxml-->
<view class="container">
<view class="userinfo">
<block wx:if="{{canIUseOpenData}}">
<view class="userinfo-avatar" bindtap="bindViewTap">
<open-data type="userAvatarUrl"></open-data>
</view>
<open-data type="userNickName"></open-data>
</block>
</view>
<button open-type="getPhoneNumber" bindgetphonenumber="onGetPhoneNumber" class="login-btn">点此登录</button>
</view>
/* pages/login/login.wxss */
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
color: #aaa;
margin-bottom: 30rpx;
}
.userinfo-avatar {
overflow: hidden;
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
\ No newline at end of file
...@@ -55,7 +55,7 @@ Page({ ...@@ -55,7 +55,7 @@ Page({
getEventListByKeyword(params){ getEventListByKeyword(params){
http.getRequest('/search/events',params).then(res=>{ http.getRequest('/search/events',params).then(res=>{
// console.log(res) // console.log(res)
if(res.data.success){ if(res){
this.setData({ this.setData({
list:res.data.data.list, list:res.data.data.list,
total:res.data.data.total total:res.data.data.total
...@@ -72,7 +72,7 @@ Page({ ...@@ -72,7 +72,7 @@ Page({
getReportListByKeyword(params){ getReportListByKeyword(params){
http.getRequest('/search/reports',params).then(res=>{ http.getRequest('/search/reports',params).then(res=>{
// console.log(res) // console.log(res)
if(res.data.success){ if(res){
this.setData({ this.setData({
list:res.data.data.list, list:res.data.data.list,
total:res.data.data.total total:res.data.data.total
......
...@@ -89,6 +89,9 @@ Page({ ...@@ -89,6 +89,9 @@ Page({
roleId:'', roleId:'',
isLogin:false isLogin:false
}) })
wx.reLaunch({
url: '/pages/login/login',
})
}, },
todo(){ todo(){
wx.showToast({ wx.showToast({
......
...@@ -2,86 +2,79 @@ ...@@ -2,86 +2,79 @@
const baseURL = 'http://192.168.0.194:8088' const baseURL = 'http://192.168.0.194:8088'
const imgURL = baseURL+'/app/' const imgURL = baseURL+'/app/'
function wxPromisify(fn) { const request = function(url,options){
return function (obj = {}) { wx.getStorageSync('token')
return new Promise((resolve, reject) => { let token = wx.getStorageSync('token')
obj.success = function (res) { if(url!='/mobile/login' && !token){
//成功 wx.reLaunch({
wx.hideNavigationBarLoading() url: '/pages/login/login',
resolve(res)
}
obj.fail = function (res) {
//失败
reject(res)
wx.hideNavigationBarLoading()
console.log(res)
}
fn(obj)
}) })
} }
return new Promise((resolve,reject)=>{
wx.request({
url:baseURL+url,
method:options.method,
data:options.data,
header:{
'Content-Type': 'application/json',
'token': token
},
success: (res) => {
if (res) {
resolve(res)
} else {
reject(res.data.message)
wx.showToast({
title: res.data.message,
icon: 'none'
})
}
wx.hideNavigationBarLoading()
},
fail: (err) => {
reject(err)
wx.showToast({
title: '服务器出了点小差!',
icon: 'none'
})
wx.hideNavigationBarLoading()
}
})
})
} }
//get // get
export const getRequest = (url, data) => { export const getRequest = (url, data) => {
var getRequest = wxPromisify(wx.request);
wx.showNavigationBarLoading() wx.showNavigationBarLoading()
// wx.showLoading({ return request(url,{
// title: '加载中...', method:"GET",
// }) data
return getRequest({
url: baseURL+url,
method: 'GET',
data: data,
header: {
'Content-Type': 'application/json',
'token': wx.getStorageSync('token')
},
}) })
} }
//post // post
export const postRequest = (url, data) => { export const postRequest = (url, data) => {
var postRequest = wxPromisify(wx.request)
wx.showNavigationBarLoading() wx.showNavigationBarLoading()
return postRequest({ return request(url,{
url: baseURL+url, method:"POST",
method: 'POST', data
data: data,
header: {
"content-type": "application/json",
'token': wx.getStorageSync('token')
},
}) })
} }
//put // put
export const putRequest = (url, data) => { export const putRequest = (url, data) => {
var putRequest = wxPromisify(wx.request)
wx.showNavigationBarLoading() wx.showNavigationBarLoading()
return putRequest({ return request(url,{
url: baseURL+url, method:"PUT",
method: 'PUT', data
data: data,
header: {
"content-type": "application/json",
'token': wx.getStorageSync('token')
},
}) })
} }
//delete // delete
export const deleteRequest = (url, data) => { export const deleteRequest = (url, data) => {
var deleteRequest = wxPromisify(wx.request)
wx.showNavigationBarLoading() wx.showNavigationBarLoading()
return deleteRequest({ return request(url,{
url: baseURL+url, method:"DELETE",
method: "DELETE", data
data: data,
header: {
"content-type": "application/json",
'token': wx.getStorageSync('token')
},
}) })
} }
\ No newline at end of file
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