Commit 6b873133 by 严立

LL - toast,dialog组件替换完成。

parent 976728d8
import mui from './component/m-init.js'
import iBase64 from './npm/base64.js'
import iMiment from './npm/miment.js'
import iUtils from './utils/utils.js'
import iRule from './utils/rule/rule.js'
import iRequest from './utils/request/corvus.js'
import iEnvironmental from './environmental.js'
App({
......@@ -56,9 +56,6 @@ App({
success: (response) => {
let funcResponse = response.data
this.globalData.appStatus = Boolean(Number(funcResponse[0].value))
// 测试数据
this.globalData.appStatus = true
console.log(this.globalData.appStatus)
}
})
},
......@@ -416,16 +413,25 @@ App({
},
// s3 新增函数
pageScroll: function (funcEvent, funcPage) {
// 优化滚动事件触发频率
let funcNow = new Date().getTime()
if (funcNow - this.scrollTimestamp < 40) return
this.scrollTimestamp = funcNow
request: function (funcOption) {
return iRequest(funcOption)
},
pageScroll: function (funcEvent, funcPage) {
// 滚动触发函数
function execute () {
funcPage.setData({
navScroll: funcEvent.scrollTop
})
if (funcPage.eventPageScroll) funcPage.eventPageScroll(funcEvent)
}
// 优化滚动事件触发频率,funcFrequency 毫秒内只会触发一次。
let funcFrequency = 25
clearTimeout(this.scrollTimestamp)
this.scrollTimestamp = setTimeout(() => {
execute()
clearTimeout(this.scrollTimestamp)
}, funcFrequency)
},
})
\ No newline at end of file
......@@ -24,7 +24,6 @@ Component({
value: ''
},
// 样式索引,如果不想使用变换效果,传值 -1 即可。
styleIndex: {
type: Number,
value: 0
......@@ -40,7 +39,7 @@ Component({
// 滚动达到多少时进行样式替换。
changeHeight: {
type: String,
value: '50rpx'
value: '100rpx'
},
iconBack: {
......@@ -98,12 +97,20 @@ Component({
},
},
pageLifetimes: {
show: function () {
this.computeNavHeight()
},
},
// 属性监听
observers: {
'scrollHeight': function (funcValue) {
if (this.data.styleIndex === -1) return
this.eventScroll(funcValue)
},
'styleIndex': function(funcValue) {
this.setNavStyle(funcValue)
},
},
// 自定方法
......@@ -279,6 +286,35 @@ Component({
},
/**
* 计算当前页面导航栏高度
* @function
* @param
* @returns
*/
computeNavHeight: function () {
// 导航栏没有 logo 的场景,使用系统高度。
if (this.data.currentStyle.logo === '') {
wx.setStorageSync('navHeight', this.data.currentStyle.statusHeight + this.data.currentStyle.titleHeight)
return
}
// 导航栏拥有 logo 的场景,需要判断 logo 是否超出原有导航栏高度。
let funcLogoFillTop = 0
let funcLogoFillHeight = 0
let funcRegExp = this.data.logoFillCss.match(/(?<=top: )[0-9.]+/g)
if (funcRegExp) funcLogoFillTop = Number(funcRegExp[0])
funcRegExp = this.data.logoFillCss.match(/(?<=height: )[0-9.]+/g)
if (funcRegExp) funcLogoFillHeight = Number(funcRegExp[0])
if (funcLogoFillTop === 0) {
wx.setStorageSync('navHeight', this.data.currentStyle.statusHeight + this.data.currentStyle.titleHeight)
} else {
wx.setStorageSync('navHeight', funcLogoFillTop + funcLogoFillHeight)
}
},
/**
* 返回按钮事件
* @function
* @param
......@@ -289,7 +325,6 @@ Component({
let funcPageLength = getCurrentPages().length
if (funcPageLength > 1) wx.navigateBack({ delta: 1 })
this.triggerEvent('navBack', { back: 1 })
console.log('onBack')
},
/**
......
<m-nav titleText="动态详情" scrollHeight="{{navScroll}}" changeHeight="10rpx"></m-nav>
<m-nav titleText="动态详情" styleIndex="{{1}}"></m-nav>
<view class="container">
<view class="title row con-s">
......
import iPoint from './js/point.js'
let App = getApp()
let logicData = {
option: {}
}
......@@ -14,6 +12,7 @@ Page({
mapCss: '',
arrowCss: '',
cssPoint: 'font-size: ' + 24 * wx.getStorageSync('unitProportion') + 'px;',
pointDetail: './image/card/01.png',
winPointDetail: false,
pointInfo: iPoint,
......
......@@ -16,12 +16,16 @@
<!-- 默认样式 -->
<image class="point-info-arrow" src="./image/icon/point-arrow-inactive.png" style="{{arrowCss}}" hidden="{{item.isActive}}"></image>
<image class="icon-inactive" src="{{item.icon}}" style="{{pointIconCss}}" hidden="{{item.isActive}}"></image>
<button class="button-inactive" hidden="{{item.isActive}}">{{item.name}}</button>
<button class="button-inactive row ac" hidden="{{item.isActive}}">
<text style="{{cssPoint}}">{{item.name}}</text>
</button>
<!-- 选择样式 -->
<image class="point-info-arrow" src="./image/icon/point-arrow-active.png" style="{{arrowCss}}" hidden="{{!item.isActive}}"></image>
<image class="icon-active" src="{{item.icon}}" style="{{pointIconCss}}" hidden="{{!item.isActive}}"></image>
<button class="button-active" hidden="{{!item.isActive}}">{{item.name}}</button>
<button class="button-active row ac" hidden="{{!item.isActive}}">
<text style="{{cssPoint}}">{{item.name}}</text>
</button>
</view>
</block>
</view>
......
......@@ -50,13 +50,15 @@
color: #000000;
}
.point-info {
overflow: hidden;
}
.point-info button {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
font-size: 10px;
}
/* 景点详情卡片 */
......
<m-nav scrollHeight="{{navScroll}}" changeHeight="650rpx" styleIndex="{{4}}" isOccupy="{{false}}"></m-nav>
<view class="container">
<view id="banner" class="banner">
<swiper autoplay circular class="banner-swiper" indicator-dots="{{false}}" interval="5000" duration="500" bindchange="onSwiperChange">
<view class="banner">
<swiper autoplay circular class="banner-swiper" indicator-dots="{{false}}" interval="5000" duration="500" bindchange="eventSwiperChange">
<block wx:for="{{banner}}" wx:for-index="index" wx:for-item="item" wx:key="index">
<swiper-item class="banner-swiper-item" data-item="{{item}}" bindtap="bannerClick">
<image class="banner-swiper-image" src="{{item.img}}"></image>
<swiper-item class="banner-swiper-item" data-item="{{item}}" bindtap="onBanner">
<image class="banner-swiper-image" src="{{item.cover}}"></image>
</swiper-item>
</block>
</swiper>
......@@ -17,37 +17,40 @@
<view class="banner-wave">
<image src="/image/ornament-0.png" mode="widthFix"></image>
</view>
<view class="banner-notice login-notice row align-c" bindtap="onLogin" wx:if="{{!isLogin}}">
<view class="row align-c">
<image src="/image/wechat.png"></image>
<image src="./image/login.png"></image>
</view>
<view class="row con-b align-c">
<view class="notice-bar row con-e" bind:tap="noticClick">
<text>消费积分 业主特权</text>
<view class="location-container">
<!-- 微信登录 -->
<view class="sign-in row ac" bindtap="onSignIn" wx:if="{{!isLogin}}">
<view class="row ac">
<image class="sign-in-icon" src="/image/wechat.png"></image>
<image class="sign-in-title" src="./image/login.png"></image>
</view>
<image class="banner-image" src="{{imageBase + 'more-g.png'}}" bindtap="onNotice"></image>
<view class="row cb ac">
<text class="sign-in-content">消费积分 业主特权</text>
<image class="arrow-more" src="{{imageBase + 'more-g.png'}}"></image>
</view>
</view>
<!-- 最新动态 -->
<view class="notice row ac">
<view class="row ac" bindtap="onNotice">
<view class="row ac">
<image class="notice-icon" src="./image/inform.png"></image>
<image class="notice-title" src="./image/title-news.png"></image>
</view>
<view class="row cb ac">
<swiper vertical="{{true}}">
<swiper-item class="row ac" wx:for="{{noticeTitles}}" wx:for-item="item" wx:for-index="index" wx:key="index">
<text data-item="{{item}}" bindtap="onNoticeDetail">{{item}}</text>
<block wx:for="{{notice}}" wx:for-item="item" wx:for-index="index" wx:key="index">
<swiper-item class="row ac">
<text data-item="{{item}}" bindtap="onNoticeDetail">{{item.title}}</text>
</swiper-item>
</block>
</swiper>
<image class="arrow-more" src="{{imageBase + 'more-g.png'}}" bindtap="onNotice"></image>
</view>
<image class="arrow-more" src="{{imageBase + 'more-g.png'}}" bindtap="onNoticeList"></image>
</view>
</view>
<view class="detail {{!isLogin ? 'login-detail' : ''}}">
<view class="detail">
<!-- 预约公告 -->
<view class="night row con-b" bindtap="onAppointmentInto">
<image src="{{resourcesBase + 'home/into.png'}}" mode="aspectFit"></image>
......@@ -78,9 +81,10 @@
</view>
</view>
<view class="footer">
<block wx:for="{{footerImage}}" wx:key="brandId">
<view class="history">
<block wx:for="{{history}}" wx:key="brandId">
<image src="{{item.cover}}" bindtap="onToHistory" data-index="{{index}}"></image>
</block>
</view>
</view>
</view>
\ No newline at end of file
......@@ -14,7 +14,6 @@
.banner {
z-index: 1;
position: relative;
width: 750rpx;
height: 870rpx;
......@@ -51,16 +50,56 @@
height: 150rpx;
}
/* 最新动态 */
.notice {
/* 主页内容与 banner 元素重合 */
.location-container {
z-index: 3;
position: relative;
top: 620rpx;
left: 40rpx;
top: -90rpx;
margin-bottom: -90rpx;
}
/* 微信登录 */
.sign-in {
z-index: 3;
width: 670rpx;
height: 108rpx;
margin-bottom: 40rpx;
margin: 0 40rpx 40rpx 40rpx;
padding: 0 32rpx;
box-shadow: 0px 16rpx 48rpx 0 rgba(0, 0, 0, .05);
border-radius: 4rpx;
background: #FFFFFF;
}
.sign-in-icon {
width: 40rpx;
height: 40rpx;
margin-right: 12rpx;
}
.sign-in-title {
width: 122rpx;
height: 30rpx;
margin-left: 2rpx;
}
.sign-in-content {
width: 382rpx;
height: 36rpx;
margin-right: 16rpx;
text-align: right;
font-size: 26rpx;
font-weight: 400;
line-height: 36rpx;
color: #8A8C8F;
}
/* 最新动态 */
.notice {
z-index: 3;
width: 670rpx;
height: 108rpx;
margin: 0 40rpx 40rpx 40rpx;
padding: 0 32rpx;
box-shadow: 0px 16rpx 48rpx 0 rgba(0, 0, 0, .05);
border-radius: 4rpx;
......@@ -95,14 +134,9 @@
}
.detail {
margin-top: 60rpx;
padding: 0 40rpx;
}
.login-detail {
margin-top: 208rpx;
}
.detail-item {
margin-top: 58rpx;
}
......@@ -309,16 +343,16 @@
background: #808080;
}
.footer {
.history {
margin-top: 88rpx;
}
.footer image {
.history image {
display: block;
width: 750rpx;
height: 1148rpx;
margin-bottom: 40rpx;
}
.footer image:last-child {
.history image:last-child {
margin-bottom: 0rpx;
}
\ No newline at end of file
<m-toast></m-toast>
<m-nav titleText="夜间入园预约" scrollHeight="{{navScroll}}" changeHeight="10rpx" styleIndex="{{2}}" isOccupy="{{false}}"></m-nav>
<m-nav titleText="夜间入园预约" scrollHeight="{{navScroll}}" styleIndex="{{2}}" isOccupy="{{false}}"></m-nav>
<view class="appointment-complete row con-c align-c" wx:if="{{appointmentComplete}}">
<view class="appointment-complete-tip">
......
let App = getApp()
Page({
data: {
appStatus: App.globalData.appStatus,
......@@ -290,6 +289,8 @@ Page({
setUserInfo: function () {
let funcUserInfo = wx.getStorageSync('userInfo')
console.log(funcUserInfo)
// 已为登录状态
if (funcUserInfo.isSignIn) {
funcUserInfo.phone = this.toHide(funcUserInfo.phone)
......
<m-nav wx:if="userInfo.userType === 0" titleText="我的" scrollHeight="{{navScroll}}" styleIndex="{{0}}" isOccupy="{{false}}" iconBack=""></m-nav>
<m-nav wx:if="userInfo.userType === 1" titleText="我的" scrollHeight="{{navScroll}}" styleIndex="{{2}}" isOccupy="{{false}}" iconBack=""></m-nav>
<m-nav titleText="我的" scrollHeight="{{navScroll}}" styleIndex="{{userInfo.userType === 0 ? 0 : 2}}" isOccupy="{{false}}" iconBack=""></m-nav>
<view class="container con-s">
<view class="mine" wx:if="{{type !== 1}}">
......
......@@ -5,7 +5,7 @@ Page({
imageBase: App.globalData.appImageBase,
resourcesBase: App.globalData.appResourcesBase,
navScroll: 0,
option: {},
// 弹出控制
......@@ -32,6 +32,8 @@ Page({
isBlack: false,
cssTabContentTop: wx.getStorageSync('navHeight'),
sideHeight: 550,
winSide: true,
......@@ -555,6 +557,12 @@ Page({
'isMore': false,
'isDetail': false,
}
// 没有评论也没有图片,使用默认文本。
if (funcItem.content === '' && funcItem.userAlbum.length === 0) {
funcItem.content = '此用户没有填写评价。'
}
funcItem.star = Math.floor((funcItem.scoreService + funcItem.scoreCommodity + funcItem.scoreEnvironmental) / 3)
funcList.push(funcItem)
}
......@@ -566,7 +574,6 @@ Page({
const funcQuery = wx.createSelectorQuery()
funcQuery.selectAll('.evaluate-item-content-mark').boundingClientRect()
funcQuery.exec((response) => {
console.log(response)
let funcContentHeight = 88 * wx.getStorageSync('unitProportion')
let funcEvaluate = this.data.detailEvaluate
......@@ -580,9 +587,6 @@ Page({
this.setData({
detailEvaluate: funcEvaluate
})
console.log('funcEvaluate')
console.log(funcEvaluate)
})
}
})
......@@ -717,7 +721,8 @@ Page({
* @param {object} - funcEvent
* @returns
*/
setSideButton: function(funcEvent) {
eventPageScroll: function(funcEvent) {
// 右侧返回顶部按钮控制
if (funcEvent.scrollTop >= this.data.sideHeight) {
if (this.data.winSide) {
this.setData({
......
......@@ -166,11 +166,11 @@
</view>
<!-- 简介,评价 -->
<view class="selection-content row">
<view class="row align-c {{contentType === 'detail' ? 'selection-content-item-active' : 'selection-content-item'}}" data-type="detail" bindtap="onSelectionContent">
<view class="tab-content row" style="{{ 'top: ' + cssTabContentTop + 'px;'}}">
<view class="tab-content-item row align-c {{contentType === 'detail' ? 'tab-content-active' : ''}}" data-type="detail" bindtap="onSelectionContent">
<text>简介</text>
</view>
<view class="row align-c {{contentType === 'evaluate' ? 'selection-content-item-active' : 'selection-content-item'}}" data-type="evaluate" bindtap="onSelectionContent">
<view class="tab-content-item row align-c {{contentType === 'evaluate' ? 'tab-content-active' : ''}}" data-type="evaluate" bindtap="onSelectionContent">
<text>评价</text>
</view>
</view>
......@@ -224,24 +224,16 @@
</view>
</view>
<!-- 评论隐藏样式 -->
<view class="evaluate-item-content" wx:if="{{!item.isDetail}}">
<view>
<!-- 评论 -->
<view class="{{!item.isDetail ? 'evaluate-item-content' : 'evaluate-item-content-whole'}}" hidden="{{!item.content}}">
<text class="evaluate-item-content-mark">{{item.content}}</text>
</view>
<view wx:if="{{item.isMore}}" class="evaluate-item-content-more row con-e align-e" data-item="{{item}}" data-index="{{index}}" bindtap="onEvaluateMore">
<text>全文</text>
</view>
</view>
<!-- 评论展开样式 -->
<view class="evaluate-item-content-whole" wx:if="{{item.isDetail}}">
<view>
<text>{{item.content}}</text>
</view>
<view wx:if="{{!item.isDetail && item.isMore && item.content}}" class="evaluate-item-content-more row ac" data-item="{{item}}" data-index="{{index}}" bindtap="onEvaluateMore">
<text>全文</text>
</view>
<view class="evaluate-item-album">
<view class="evaluate-item-album" wx:if="{{item.userAlbum.length}}">
<block wx:for="{{item.userAlbum}}" wx:for-index="indexAlbum" wx:for-item="itemAlbum" wx:key="indexAlbum">
<image wx:if="{{indexAlbum < 4}}" src="{{itemAlbum}}" data-index="{{indexAlbum}}" data-item="{{item}}" bindtap="onEvaluateAlbum"></image>
</block>
......@@ -373,16 +365,12 @@
</view>
</view>
<!-- <view class="movie-footer">
<image src="/image/movie-bottom.png"></image>
</view> -->
<!-- 简介,评价 -->
<view class="selection-content movie-border row">
<view class="row align-c {{contentType === 'detail' ? 'selection-content-item-active-movie' : 'selection-content-item'}}" data-type="detail" bindtap="onSelectionContent">
<view class="tab-content movie-border row">
<view class="tab-content-item row align-c {{contentType === 'detail' ? 'tab-content-active-movie' : ''}}" data-type="detail" bindtap="onSelectionContent">
<text>简介</text>
</view>
<view class="row align-c {{contentType === 'evaluate' ? 'selection-content-item-active-movie' : 'selection-content-item'}}" data-type="evaluate" bindtap="onSelectionContent">
<view class="tab-content-item row align-c {{contentType === 'evaluate' ? 'tab-content-active-movie' : ''}}" data-type="evaluate" bindtap="onSelectionContent">
<text>评价</text>
</view>
</view>
......
......@@ -4,7 +4,6 @@
}
.banner {
z-index: 1;
position: relative;
width: 750rpx;
height: 800rpx;
......@@ -26,7 +25,7 @@
}
.banner-wave {
z-index: 2;
z-index: 1;
position: relative;
top: 740rpx;
left: 0;
......@@ -68,8 +67,8 @@
}
/* 立即报名 */
.operation {
z-index: 3;
position: fixed;
left: 0;
bottom: 0;
......@@ -122,7 +121,6 @@
}
/* 二期整理样式 */
.commodity-movie {
position: relative;
}
......@@ -164,7 +162,8 @@
}
.movie-border {
border-bottom: 0.5px #3a3a40 solid !important;
background: #1C1C25 !important;
border-bottom: 1px #3a3a40 solid !important;
}
.commodity-other image {
......@@ -525,7 +524,7 @@
/* 分享弹窗 */
.container-share {
z-index: 1;
z-index: 7;
position: fixed;
top: 0;
left: 0;
......@@ -582,16 +581,20 @@
}
/* 简介,评论 */
.selection-content {
.tab-content {
z-index: 2;
position: sticky;
top: 64px;
left: 0;
width: 750rpx;
height: 64rpx;
margin-top: 80rpx;
padding: 0 40rpx;
border-bottom: 0.5px #e2e7ef solid;
background: #FFFFFF;
}
.selection-content-item {
.tab-content-item {
width: 60rpx;
height: 64rpx;
margin-right: 64rpx;
......@@ -601,7 +604,7 @@
color: #656e7b;
}
.selection-content-item-active {
.tab-content-active {
width: 60rpx;
height: 64rpx;
margin-right: 64rpx;
......@@ -612,7 +615,7 @@
color: #15191f;
}
.selection-content-item-active-movie {
.tab-content-active-movie {
width: 60rpx;
height: 64rpx;
margin-right: 64rpx;
......@@ -684,7 +687,7 @@
.evaluate-item {
position: relative;
width: 670rpx;
min-height: 292rpx;
min-height: 204rpx;
margin: 48rpx 40rpx 0 40rpx;
border-bottom: 0.5px solid #e2e7ef;
}
......@@ -754,7 +757,6 @@
display: -webkit-box;
position: relative;
width: 670rpx;
min-height: 88rpx;
max-height: 132rpx;
margin-top: 32rpx;
font-size: 26rpx;
......@@ -778,13 +780,8 @@
}
.evaluate-item-content-more {
position: absolute;
bottom: 0;
right: 18rpx;
width: 106rpx;
height: 44rpx;
background: #fff;
text-align: right;
margin-top: 8rpx;
font-size: 26rpx;
font-weight: 400;
line-height: 32rpx;
......@@ -795,12 +792,12 @@
bottom: 0;
right: 18rpx;
width: 106rpx;
height: 44rpx;
height: 26rpx;
background: #1c1c25;
text-align: right;
font-size: 26rpx;
font-weight: 400;
line-height: 44rpx;
line-height: 26rpx;
}
.evaluate-item-content-more text {
......@@ -813,7 +810,7 @@
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
padding: 32rpx 0 48rpx 0;
margin: 32rpx 0 48rpx 0;
border-bottom: 0.5px #e2e7ef solid;
}
......@@ -853,7 +850,7 @@
/* 评论相册样式 */
.full-screen-album {
z-index: 9;
z-index: 7;
position: fixed;
top: 0;
left: 0;
......@@ -873,7 +870,6 @@
}
/* 价格样式 */
.detail-price-discount {
width: 90rpx;
height: 36rpx;
......
<m-nav titleText="{{navTitle}}" scrollHeight="{{navScroll}}" changeHeight="10rpx" styleIndex="{{1}}"></m-nav>
<m-nav titleText="{{navTitle}}" scrollHeight="{{navScroll}}" styleIndex="{{1}}"></m-nav>
<view class="container">
<view class="detail">
......
import iOption from '../option.js'
import iInterceptors from './interceptors.js'
import iOption from './option.js'
import interceptor from './interceptor.js'
/**
* Corvus
* @constructor
* @param {object} option - { base: '', method: 'post', header: {}, timeout: 10000, dataType: '', responseType: ''}
* @return
* 检查传参格式,数值有效性。
* @function
* @param {object} - funcEvent
* @returns
*/
function Corvus (option) {
let This = this
// 默认配置参数
This.option = {
base: iOption.baseUrl,
method: 'post',
header: { 'content-type': 'application/json' },
timeout: 5000,
dataType: 'json',
responseType: 'text'
}
if (Object.prototype.toString.call(option) === '[object Object]') {
This.option = Object.assign(This.option, option)
}
// 对实例参数做正确性校验
// 请求方式存在,且为post或者get之一,则设置。
if (This.option.method !== 'post' && This.option.method !== 'get') {
console.log('[corvus] "method" is invalid!')
function inspectOption (funcOption) {
// 配置参数必须是对象类型。
if (Object.prototype.toString.call(funcOption) !== '[object Object]') {
console.log('[request] "option" is invalid!')
return
}
// 请求头部存在,且不为空对象,则设置
if (Object.prototype.toString.call(This.option.header) !== '[object Object]') {
console.log('[Corvus] "header" is invalid!')
// 请求方式必须是post或者get之一
if (funcOption.method && ['get', 'post'].indexOf(funcOption.method) >= 0) {
console.log('[request] "method" is invalid!')
return
}
// 基础路径存在,则设置
if (!This.option.base || Object.prototype.toString.call(This.option.base) !== '[object String]') {
console.log('[corvus] "baseURL" is invalid!')
// 请求头部必须是对象类型
if (funcOption.header && Object.prototype.toString.call(funcOption.header) !== '[object Object]') {
console.log('[request] "header" is invalid!')
return
}
}
Corvus.prototype.request = function (option) {
let This = this
option = Object.assign(JSON.parse(JSON.stringify(This.option)), option)
option = iInterceptors.request(option)
let funcPromise = new Promise(function (funcResolve, funcReject) {
function request (funcOption) {
if (inspectOption(funcOption)) return
// { 'Content-Type': 'application/x-www-form-urlencoded;' }
// { 'Content-Type': 'multipart/form-data;' }
// { 'Content-Type': 'application/json;' }
// { 'Content-Type': 'text/plain;' }
let funcDefaultOption = {
base: iOption.baseUrl,
method: 'post',
header: { 'content-type': 'application/json' },
timeout: 5000,
dataType: 'json',
responseType: 'text'
}
// 合并默认配置
funcOption = Object.assign(funcDefaultOption, funcOption)
// 请求之前修改配置
funcOption = interceptor.request(funcOption)
let funcPromise = new Promise((funcResolve, funcReject) => {
wx.request({
url: option.base + option.url,
header: option.header,
method: option.method,
data: option.params,
success: function (funcResult) {
if (iInterceptors.response(option, funcResult)) {
funcResolve(funcResult)
url: funcOption.base + funcOption.url,
header: funcOption.header,
method: funcOption.method,
data: funcOption.params,
success: (funcResponse) => {
// 网络请求成功
let funcInterceptor = interceptor.response(funcOption, funcResponse)
if (funcInterceptor.success) {
funcResolve(funcInterceptor.response)
} else {
funcReject(funcInterceptor.response)
}
},
fail: function (funcResult) {
iInterceptors.response(option, funcResult)
funcReject('[axios] "request end!')
fail: (funcResponse) => {
// 网络请求失败
interceptor.response(funcOption, funcResponse)
funcReject('[request] "request end!')
},
})
})
return funcPromise
}
export default new Corvus()
\ No newline at end of file
export default request
\ No newline at end of file
/**
* xmlHttpResqust 表头设置函数
* @function
* @param {object} funXmlHttpRequest
* @param {string} funType - 发送数据类型标识
* @returns
*/
let output = function (funType) {
switch (funType) {
case 'form':
return { 'Content-Type': 'application/x-www-form-urlencoded;' }
case 'formData':
return { 'Content-Type': 'multipart/form-data;' }
case 'json':
return { 'Content-Type': 'application/json;' }
default:
return { 'Content-Type': 'text/plain;' }
}
}
export default output
\ No newline at end of file
......@@ -2,8 +2,7 @@ import iMd5 from '../md5.js'
let Output = {
/**
* 请求拦截器。对请求进行配置修改或者拦截。
* 此处为全局拦截器,所有实例对象均会触发。实例的自定义拦截逻辑需要在interceptors.request函数中定义。
* 请求拦截器,对请求进行配置修改或者拦截。
* @function
* @param {object} option - 请求的url以及params
* @returns {object || boolean}
......@@ -30,58 +29,49 @@ let Output = {
/**
* 响应拦截器。对响应数据做统一处理。
* 此处为全局拦截器,所有实例对象均会触发。实例的自定义拦截逻辑需要在interceptors.response函数中定义。
* @function
* @param {object} funResult - 响应回来的数据
* @returns {object || undefined}
*/
response: function (funcOption, funcResult) {
response: function (funcOption, funcResponse) {
// console.log('■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■')
// console.log('api: ', funcOption.url)
// console.log('params: ', funcOption.params)
// console.log('status: ', funcResponse.statusCode)
// console.log('data: ', funcResponse.data ? funcResponse.data : funcResponse)
// console.log('■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■')
// 请求错误处理
if (funcResponse.errMsg === 'request:fail ') {
return false
}
console.log('api: ', funcOption.url)
console.log('params: ', funcOption.params)
console.log('status: ', funcResult.statusCode)
console.log('data: ', funcResult.data ? funcResult.data : funcResult)
console.log('■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■')
return
// 服务器错误处理
if (funcResponse.statusCode === 504) {
return false
}
console.log('funcResult', funcResult)
// 请求正常
// 此处可以根据后台返回数据,格式化返回数据。
if (funcResponse.statusCode === 200) {
switch (funcResponse.data.code) {
case 101:
let App = getApp()
break
if (funcResult.errMsg === 'request:fail ') {
wx.hideLoading()
App.imState.mutations({
stateWinTip: true,
stateTipContent: '哎呀,好像没网了,请检查网络。'
})
return false
case 200:
return {
success: true,
response: {
code: funcResponse.data.code,
data: funcResponse.data.data,
message: funcResponse.data.msg
}
if (funcOption.url !== 'api/app/weixin/v1/pay/findStatus' && funcOption.url !== 'api/app/weixin/v1/pay/findStatus') {
wx.hideLoading()
}
if (funcResult.statusCode === 504) {
App.imState.mutations({
stateWinTip: true,
stateTipContent: '服务器错误'
})
return false
break
}
if (funcResult.data.code === 101) {
App.imState.mutations({
stateWinTip: true,
stateTipContent: '登录失效,请重新登录'
})
let funcTimer = setTimeout(function () {
clearTimeout(funcTimer)
wx.redirectTo({
url: '../sign-in/sign-in'
})
}, 2000)
return false
}
return true
},
}
......
const output = {
// 测试环境
baseUrl: 'https://sm-web2.meiqicloud.com/api/',
// 正式环境
// baseUrl: 'https://xsslc.cndrealty.com/',
}
export default output
\ 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 sign in to comment