Commit 47d21696 by liangyuhang

重新封装request,添加登录页

parent a59abf8d
......@@ -7,7 +7,8 @@
"pages/search-page/search-page",
"pages/search-result/search-result",
"pages/event-detail/event-detail",
"pages/out/out"
"pages/out/out",
"pages/login/login"
],
"window": {
......@@ -46,5 +47,6 @@
]
},
"style": "v2",
"sitemapLocation": "sitemap.json"
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
border-bottom: 1px solid #e3e4e4;
}
.list .image-box{
width: 150rpx;
width: 200rpx;
text-align:center;
}
.list .image-box image{
......@@ -22,15 +22,15 @@
}
.r .title{
font-weight: bold;
font-size: 30rpx;
font-size: 28rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.r .score{
position: absolute;
font-size: 28rpx;
color: #A0A0A0;
font-size: 26rpx;
color: #999;
top: 50rpx;
left: 0;
}
......@@ -46,8 +46,8 @@
}
.r .time{
position: absolute;
font-size: 28rpx;
color: #A0A0A0;
font-size: 26rpx;
color: #999;
bottom: 15rpx;
right: 0;
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
border-bottom: 1px solid #e3e4e4;
}
.list .image-box{
width: 150rpx;
width: 200rpx;
text-align:center;
}
.list .image-box image{
......@@ -22,15 +22,15 @@
}
.r .title{
font-weight: bold;
font-size: 30rpx;
font-size: 28rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.r .score{
position: absolute;
font-size: 28rpx;
color: #A0A0A0;
font-size: 26rpx;
color: #999;
top: 50rpx;
left: 0;
}
......@@ -45,8 +45,8 @@
}
.r .time{
position: absolute;
font-size: 28rpx;
color: #A0A0A0;
font-size: 26rpx;
color: #999;
bottom: 15rpx;
right: 0;
}
\ No newline at end of file
......@@ -149,37 +149,19 @@ function getOption(list,times){
name: '正',
data: posCountList,
type: 'line',
smooth: true,
markLine: {
data: [
{ type: 'max', name: '峰值' },
{ type: 'average', name: '均值' }
]
}
smooth: true
},
{
name: '中',
data: neuCountList,
type: 'line',
smooth: true,
markLine: {
data: [
{ type: 'max', name: '峰值' },
{ type: 'average', name: '均值' }
]
}
smooth: true
},
{
name: '负',
data: negCountList,
type: 'line',
smooth: true,
markLine: {
data: [
{ type: 'max', name: '峰值' },
{ type: 'average', name: '均值' }
]
}
smooth: true
},
]
};
......
......@@ -44,7 +44,7 @@ Page({
},
getVenation(){
http.getRequest('/events/'+this.data.eventId+'/venation').then(res=>{
if(res.data.success){
if(res){
this.setData({
venation:res.data.data
})
......@@ -58,7 +58,7 @@ Page({
},
getOverview(){
http.getRequest('/events/'+this.data.eventId+'/overview').then(res=>{
if(res.data.success){
if(res){
this.setData({
overview:res.data.data
})
......@@ -72,7 +72,7 @@ Page({
},
getDetail(){
http.getRequest('/events/'+this.data.eventId+'/detail').then(res=>{
if(res.data.success){
if(res){
this.setData({
detail:res.data.data,
hasCollect:res.data.data.hasCollect
......@@ -87,7 +87,7 @@ Page({
},
getLine(){
http.getRequest('/events/'+this.data.eventId+'/spread/line').then(res=>{
if(res.data.success){
if(res){
this.setData({
line: res.data.data
})
......@@ -103,7 +103,7 @@ Page({
collect(e){
var _eventId=e.currentTarget.dataset.id;
http.postRequest('/collects/event/'+_eventId).then(res=>{
if(res.data.success){
if(res){
this.setData({
hasCollect:true
})
......@@ -118,7 +118,7 @@ Page({
cancelCollect(e){
var _eventId=e.currentTarget.dataset.id;
http.deleteRequest('/collects/event/'+_eventId).then(res=>{
if(res.data.success){
if(res){
this.setData({
hasCollect:false
})
......
......@@ -125,5 +125,28 @@ Page({
wx.navigateTo({
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 @@
<swiper indicator-dots="true" autoplay="true" class="carousel" circular="true">
<block wx:for="{{crisisDynamic}}" wx:key="index">
<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_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" />
<text class="dynamic_title">{{item.title}}</text>
<text class="dynamic_level">{{item.crisisLevelZh}}风险</text>
<text class="dynamic_introduction">摘要:{{item.introduction}}</text>
<text class="dynamic_brand">{{item.priBrand}}</text>
<text class="dynamic_tag">{{item.priCrisisTags}}</text>
<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" lazy-load="true"/>
<view class="dynamic_title">{{item.title}}</view>
<view class="dynamic_level">{{item.crisisLevelZh}}风险</view>
<view class="dynamic_introduction">摘要:{{item.introduction}}</view>
<view class="dynamic_tag">
<view class="brand">{{item.priBrand}}</view>
<block wx:for="{{item.priCrisisTags}}" wx:key="index">
<view class="crisis">{{item}}</view>
</block>
</view>
</swiper-item>
</block>
</swiper>
......
......@@ -103,11 +103,13 @@
/* 危机动态 */
.carousel{
padding: 30rpx;
position: relative;
padding: 0 30rpx;
margin-top: 30rpx;
}
.carousel .dynamic_img{
position: absolute;
border-radius: 5px;
}
.carousel .dynamic_title{
position: absolute;
......@@ -126,6 +128,8 @@
padding: 5rpx 25rpx;
background-color: #f87653;
text-align: center;
border-bottom-left-radius: 5px;
border-top-right-radius: 5px;
}
.carousel .dynamic_introduction{
position: absolute;
......@@ -137,23 +141,23 @@
text-overflow: ellipsis;
line-clamp: 1;
}
.carousel .dynamic_brand{
position: absolute;
bottom: 50rpx;
left: 30rpx;
.carousel .dynamic_tag{
position: absolute;
bottom: 50rpx;
left: 30rpx;
font-size: 26rpx;
text-align: center;
display: flex;
}
.carousel .dynamic_tag .brand{
padding: 5rpx 25rpx;
background-color: #BAB7B6;
font-size: 26rpx;
text-align: center;
margin-right: 20rpx;
}
.carousel .dynamic_tag{
position: absolute;
bottom: 50rpx;
left: 200rpx;
.carousel .dynamic_tag .crisis{
padding: 5rpx 25rpx;
background-color: #BAB7B6;
font-size: 26rpx;
text-align: center;
margin-right: 20rpx;
}
/* 聚焦领域 */
......@@ -233,9 +237,6 @@
font-size: 24rpx;
}
/* 危机复盘 */
.article-content{
padding: 0 30rpx;
......@@ -259,8 +260,8 @@
width: 400rpx;
}
.article .content .article-title{
font-weight: bold;
font-size: 28rpx;
font-weight: bold;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
......@@ -335,12 +336,12 @@
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
font-weight: 28rpx;
font-size: 28rpx;
font-weight: bold;
}
.content .report-introduction{
position: absolute;
top: 50rpx;
top: 40rpx;
left: 0;
color: #999;
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({
getEventListByKeyword(params){
http.getRequest('/search/events',params).then(res=>{
// console.log(res)
if(res.data.success){
if(res){
this.setData({
list:res.data.data.list,
total:res.data.data.total
......@@ -72,7 +72,7 @@ Page({
getReportListByKeyword(params){
http.getRequest('/search/reports',params).then(res=>{
// console.log(res)
if(res.data.success){
if(res){
this.setData({
list:res.data.data.list,
total:res.data.data.total
......
......@@ -89,6 +89,9 @@ Page({
roleId:'',
isLogin:false
})
wx.reLaunch({
url: '/pages/login/login',
})
},
todo(){
wx.showToast({
......
......@@ -2,86 +2,79 @@
const baseURL = 'http://192.168.0.194:8088'
const imgURL = baseURL+'/app/'
function wxPromisify(fn) {
return function (obj = {}) {
return new Promise((resolve, reject) => {
obj.success = function (res) {
//成功
wx.hideNavigationBarLoading()
resolve(res)
}
obj.fail = function (res) {
//失败
reject(res)
wx.hideNavigationBarLoading()
console.log(res)
}
fn(obj)
const request = function(url,options){
wx.getStorageSync('token')
let token = wx.getStorageSync('token')
if(url!='/mobile/login' && !token){
wx.reLaunch({
url: '/pages/login/login',
})
}
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) => {
var getRequest = wxPromisify(wx.request);
wx.showNavigationBarLoading()
// wx.showLoading({
// title: '加载中...',
// })
return getRequest({
url: baseURL+url,
method: 'GET',
data: data,
header: {
'Content-Type': 'application/json',
'token': wx.getStorageSync('token')
},
return request(url,{
method:"GET",
data
})
}
//post
// post
export const postRequest = (url, data) => {
var postRequest = wxPromisify(wx.request)
wx.showNavigationBarLoading()
return postRequest({
url: baseURL+url,
method: 'POST',
data: data,
header: {
"content-type": "application/json",
'token': wx.getStorageSync('token')
},
return request(url,{
method:"POST",
data
})
}
//put
// put
export const putRequest = (url, data) => {
var putRequest = wxPromisify(wx.request)
wx.showNavigationBarLoading()
return putRequest({
url: baseURL+url,
method: 'PUT',
data: data,
header: {
"content-type": "application/json",
'token': wx.getStorageSync('token')
},
return request(url,{
method:"PUT",
data
})
}
//delete
// delete
export const deleteRequest = (url, data) => {
var deleteRequest = wxPromisify(wx.request)
wx.showNavigationBarLoading()
return deleteRequest({
url: baseURL+url,
method: "DELETE",
data: data,
header: {
"content-type": "application/json",
'token': wx.getStorageSync('token')
},
return request(url,{
method:"DELETE",
data
})
}
\ 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