This commit is contained in:
PQZ 2025-04-24 18:19:21 +08:00
commit 2f03910ae4
12 changed files with 315 additions and 165 deletions

View File

@ -162,6 +162,14 @@ export function getOrderList(params) {
}) })
} }
export function prepayment(data) {
return request({
url: '/payApi/prepayment',
method: 'get',
params: data
})
}
export function saveOrder(data) { export function saveOrder(data) {
return request({ return request({
url: '/member/order/uniSaveOrder', url: '/member/order/uniSaveOrder',
@ -184,4 +192,4 @@ export function saveBlack(data) {
method: 'post', method: 'post',
data: data data: data
}) })
} }

View File

@ -119,29 +119,29 @@
position: relative; position: relative;
.item-top { .item-top {
padding-top: 25rpx; padding-top: 13rpx;
flex-shrink: 0; flex-shrink: 0;
width: 150rpx; width: 150rpx;
height: 130rpx; height: 130rpx;
.dl-image { .dl-image {
height: 45rpx; height: 53rpx;
width: 45rpx; width: 53rpx;
} }
.dl-vip { .dl-vip {
position: absolute; position: absolute;
height: 25rpx; height: 20rpx;
top: -10rpx; top: 0rpx;
right: -24px; right: -21px;
} }
} }
.item-bottom { .item-bottom {
width: 100%; width: 100%;
font-size: 28rpx; font-size: 26rpx;
position: absolute; position: absolute;
bottom: 10rpx; bottom: 30rpx;
} }
.item-active { .item-active {

View File

@ -1,7 +1,8 @@
// 应用全局配置 // 应用全局配置
module.exports = { module.exports = {
// baseUrl: 'https://notice.lighting-it.cn', //baseUrl: 'https://notice.lighting-it.cn',
baseUrl: 'http://localhost:8080', baseUrl: 'https://www.ddtg.site/noticeApi',
//baseUrl: 'http://192.168.1.31:8099',
// 应用信息 // 应用信息
appInfo: { appInfo: {
// 应用名称 // 应用名称

View File

@ -4,13 +4,12 @@ import store from './store' // store
import plugins from './plugins' // plugins import plugins from './plugins' // plugins
import './permission' // permission import './permission' // permission
Vue.use(plugins) Vue.use(plugins)
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$store = store Vue.prototype.$store = store
App.mpType = 'app' App.mpType = 'app'
const app = new Vue({ const app = new Vue({
...App ...App
}) })
app.$mount() app.$mount()

View File

@ -18,12 +18,13 @@
</view> </view>
</view> </view>
<!-- 菜单 --> <!-- 菜单 -->
<view class="dl-menu-box"> <view class="dl-menu-box" style="padding-top: 10rpx;">
<view v-for="(item,index) in menus" @click="itemClick(index,item)" class="dl-menu" <view v-for="(item,index) in menus" @click="itemClick(index,item)" class="dl-menu-dom">
:class="index==menuIndex?'dl-menu click':'dl-menu'">{{item}}</view> <view :class="index==menuIndex?'dl-menu click':'dl-menu'">{{item}}</view>
</view>
</view> </view>
<!-- 筛选条件 --> <!-- 筛选条件 -->
<view class="dl-menu-box" style="padding-bottom: 20rpx;"> <view class="dl-menu-box" style="padding-bottom: 20rpx;padding-left: 15rpx;padding-right: 15rpx;">
<view :class="[0==chooseCondition?'dl-focus dl-search-box':'dl-search-box']" @click="choosePlat(0)" <view :class="[0==chooseCondition?'dl-focus dl-search-box':'dl-search-box']" @click="choosePlat(0)"
:key="chooseCondition"> :key="chooseCondition">
<text>{{queryParams.platformName}}</text> <text>{{queryParams.platformName}}</text>
@ -65,6 +66,9 @@
<image class="dl-go-view" src="@/static/index/go-view.png" mode="aspectFit"></image> <image class="dl-go-view" src="@/static/index/go-view.png" mode="aspectFit"></image>
</view> </view>
</view> </view>
<!-- 通告列表 --> <!-- 通告列表 -->
<view class="dl-item-box"> <view class="dl-item-box">
<scroll-view style="height: 100%;" scroll-y="true" @scrolltolower="onReachBottomCus" refresher-enabled <scroll-view style="height: 100%;" scroll-y="true" @scrolltolower="onReachBottomCus" refresher-enabled
@ -180,6 +184,7 @@
getUserType getUserType
} from '@/utils/common.js' } from '@/utils/common.js'
import constant from '@/utils/constant'; import constant from '@/utils/constant';
import store from '@/store'
export default { export default {
components: { components: {
@ -291,12 +296,9 @@
* 选择平台 * 选择平台
*/ */
async choosePlat(index) { async choosePlat(index) {
this.$emit("openVip")
return
if (index == 2) { if (index == 2) {
// //
if (!this.checkIfHasRights(rightsCode.subscribeSelect)) { if (!await this.checkIfHasRights(rightsCode.subscribeSelect)) {
this.$emit("openVip")
return return
} }
this.$refs.showRight2.open() this.$refs.showRight2.open()
@ -348,13 +350,13 @@
} else if ('最新' == item) { } else if ('最新' == item) {
// //
// //
if (!this.checkIfHasRights(rightsCode.highNewNotice)) { if (!await this.checkIfHasRights(rightsCode.highNewNotice)) {
return return
} }
this.queryParams.sortBy = "new" this.queryParams.sortBy = "new"
} else if ('高奖励' == item) { } else if ('高奖励' == item) {
// //
if (!this.checkIfHasRights(rightsCode.highNewNotice)) { if (!await this.checkIfHasRights(rightsCode.highNewNotice)) {
return return
} }
this.queryParams.sortBy = "money" this.queryParams.sortBy = "money"
@ -370,7 +372,7 @@
*/ */
async goSeach() { async goSeach() {
// //
if (!this.checkIfHasRights(rightsCode.searchNotice)) { if (!await this.checkIfHasRights(rightsCode.searchNotice)) {
return return
} }
this.showSearch = true this.showSearch = true
@ -382,7 +384,7 @@
async checkIfHasRights(rigthsCode) { async checkIfHasRights(rigthsCode) {
let res = await hasRights(rigthsCode) let res = await hasRights(rigthsCode)
if (!res) { if (!res) {
toast('请开通会员') this.$emit("openVip")
return false return false
} }
return true return true
@ -454,25 +456,34 @@
*/ */
goDetail(item) { goDetail(item) {
let userInfo = getJSONData(constant.userInfo) let userInfo = getJSONData(constant.userInfo)
let userType = getUserType() if (!userInfo) {
let param = { store.dispatch('LogOut').then(res => {
userId: userInfo.userId, uni.reLaunch({
userType: userType, url: '/pages/login'
noticeId: item.id, })
rightsCode: 'unlock_notice', })
deplete: 1 } else {
}
dealMemberRights(param).then(res => { let userType = getUserType()
if (res.code == 200) { let param = {
this.$tab.navigateTo(`/pages/notice/detail?id=${item.id}`) userId: userInfo.userId,
userType: userType,
noticeId: item.id,
rightsCode: 'unlock_notice',
deplete: 1
} }
}).catch((e) => { dealMemberRights(param).then(res => {
uni.showToast({ if (res.code == 200) {
icon: 'error', this.$tab.navigateTo(`/pages/notice/detail?id=${item.id}`)
duration: 2000, }
title: e }).catch((e) => {
}); uni.showToast({
}) icon: 'error',
duration: 2000,
title: e
});
})
}
}, },
/**扣除解锁通告权益*/ /**扣除解锁通告权益*/
@ -509,7 +520,7 @@
display: flex; display: flex;
position: relative; position: relative;
z-index: 10; z-index: 10;
padding: 55rpx 10rpx 0 15rpx; padding: 25rpx 10rpx 0 15rpx;
border-bottom: 1px solid #F4F4F4; border-bottom: 1px solid #F4F4F4;
@ -521,15 +532,15 @@
position: relative; position: relative;
.dl-image { .dl-image {
width: 50rpx; width: 40rpx;
height: 50rpx; height: 40rpx;
} }
.dl-vip { .dl-vip {
position: absolute; position: absolute;
height: 25rpx; height: 20rpx;
top: -10rpx; top: -10rpx;
right: -22px; right: -20px;
} }
} }
@ -551,18 +562,26 @@
width: 100%; width: 100%;
padding-top: 20rpx; padding-top: 20rpx;
.dl-menu { .dl-menu-dom {
flex-grow: 1; width: 100%;
font-size: 30rpx; display: flex;
margin: 0 20rpx; align-items: center;
padding-bottom: 20rpx; justify-content: center;
text-align: center;
.dl-menu {
font-size: 30rpx;
margin: 0 20rpx;
padding-bottom: 10rpx;
text-align: center;
}
} }
.click { .click {
font-size: 32rpx !important;
color: #FF434E; color: #FF434E;
font-weight: bold; font-weight: bold;
border-bottom: 2px solid #FF434E; border-bottom: 3px solid #FF434E;
} }
.dl-search-box { .dl-search-box {
@ -571,9 +590,9 @@
flex-grow: 1; flex-grow: 1;
font-size: 30rpx; font-size: 30rpx;
margin: 0 15rpx; margin: 0 15rpx;
padding: 15rpx 25rpx; padding: 10rpx 25rpx;
background-color: #F7F7F7; background-color: #F7F7F7;
border-radius: 30rpx; border-radius: 40rpx;
align-items: center; align-items: center;
justify-content: left; justify-content: left;
display: flex; display: flex;
@ -591,8 +610,8 @@
.dl-vip { .dl-vip {
position: absolute; position: absolute;
width: 50rpx; width: 50rpx;
height: 25rpx; height: 20rpx;
top: -16rpx; top: -12rpx;
right: -5px; right: -5px;
} }
} }
@ -610,7 +629,7 @@
align-items: center; align-items: center;
border-radius: 35rpx; border-radius: 35rpx;
justify-content: center; justify-content: center;
height: 100rpx; height: 85rpx;
width: 100%; width: 100%;
background: url('/static/index/member-bg.png'); background: url('/static/index/member-bg.png');
background-size: 100% 100%; background-size: 100% 100%;
@ -645,7 +664,7 @@
} }
.dl-item-box { .dl-item-box {
height: calc(100vh - var(--status-bar-height) - var(--window-bottom) - 586rpx); height: calc(100vh - var(--status-bar-height) - var(--window-bottom) - 505rpx);
isplay: flex; isplay: flex;
flex-direction: column; flex-direction: column;
} }

View File

@ -21,16 +21,16 @@
<image class="dl-icon" src="@/static/index/xing.png" mode="aspectFit"></image> <image class="dl-icon" src="@/static/index/xing.png" mode="aspectFit"></image>
<view class="dl-content">类型{{item.bloggerTypesText||'无限制'}}</view> <view class="dl-content">类型{{item.bloggerTypesText||'无限制'}}</view>
</view> </view>
<view class="text-item" style="padding-top: 10rpx;"> <view class="text-item" style="padding-top: 16rpx;">
<view class="item-box" style="width: 40%;"> <view class="item-box" style="flex: 1;">
<image class="dl-icon2" :src="imageUrl+item.avatar" mode="aspectFit"></image> <image class="dl-icon2" :src="imageUrl+item.avatar" mode="aspectFit"></image>
<view class="dl-item-right">{{item.userNickName}}</view> <view class="dl-item-right">{{item.userNickName}}</view>
</view> </view>
<view class="item-box"> <view class="item-box" style="width: 28%;">
<image class="dl-icon3" src="@/static/index/person.png" mode="aspectFit"></image> <image class="dl-icon3" src="@/static/index/person.png" mode="aspectFit"></image>
<view class="dl-item-right dl-number">{{item.reportNum}}</view> <view class="dl-item-right dl-number">{{item.reportNum}}</view>
</view> </view>
<view class="item-box"> <view class="item-box" style="width: 28%;">
<image class="dl-icon3" src="@/static/index/eye.png" mode="aspectFit"></image> <image class="dl-icon3" src="@/static/index/eye.png" mode="aspectFit"></image>
<view class="dl-item-right dl-number">{{item.viewNum}}</view> <view class="dl-item-right dl-number">{{item.viewNum}}</view>
</view> </view>
@ -63,15 +63,15 @@
<view class="dl-content">类型{{dataObj.bloggerTypesText}}</view> <view class="dl-content">类型{{dataObj.bloggerTypesText}}</view>
</view> </view>
<view class="text-item" style="padding-top: 10rpx;"> <view class="text-item" style="padding-top: 10rpx;">
<view class="item-box" style="width: 40%;"> <view class="item-box">
<image class="dl-icon2" :src="imageUrl+dataObj.avatar" mode="aspectFit"></image> <image class="dl-icon2" :src="imageUrl+dataObj.avatar" mode="aspectFit"></image>
<view class="dl-item-right">{{dataObj.userNickName}}</view> <view class="dl-item-right">{{dataObj.userNickName}}</view>
</view> </view>
<view class="item-box"> <view class="item-box" style="width: 25%;">
<image class="dl-icon3" src="@/static/index/person.png" mode="aspectFit"></image> <image class="dl-icon3" src="@/static/index/person.png" mode="aspectFit"></image>
<view class="dl-item-right dl-number">{{dataObj.reportNum}}</view> <view class="dl-item-right dl-number">{{dataObj.reportNum}}</view>
</view> </view>
<view class="item-box"> <view class="item-box" style="width: 25%;">
<image class="dl-icon3" src="@/static/index/eye.png" mode="aspectFit"></image> <image class="dl-icon3" src="@/static/index/eye.png" mode="aspectFit"></image>
<view class="dl-item-right dl-number">{{dataObj.viewNum}}</view> <view class="dl-item-right dl-number">{{dataObj.viewNum}}</view>
</view> </view>
@ -138,7 +138,7 @@
.dl-notice-box { .dl-notice-box {
font-size: 29rpx; font-size: 29rpx;
width: 100%; width: 100%;
padding: 18rpx; padding: 18rpx 18rpx 10rpx 18rpx;
background-color: white; background-color: white;
border-radius: 30rpx; border-radius: 30rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
@ -157,6 +157,7 @@
} }
.dl-text { .dl-text {
font-size: 30rpx;
margin-left: 10rpx; margin-left: 10rpx;
flex: 1; flex: 1;
overflow: hidden; overflow: hidden;
@ -190,11 +191,12 @@
.dl-icon { .dl-icon {
flex: none; flex: none;
width: 40rpx; width: 25rpx;
height: 44rpx; height: 30rpx;
} }
.dl-content { .dl-content {
font-size: 24rpx;
flex: 1; flex: 1;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
@ -205,14 +207,13 @@
.item-box { .item-box {
display: flex; display: flex;
width: 100%;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
.dl-icon2 { .dl-icon2 {
flex: none; flex: none;
width: 40rpx; width: 40rpx;
height: 44rpx; height: 40rpx;
border-radius: 50%; border-radius: 50%;
} }
@ -224,6 +225,7 @@
} }
.dl-item-right { .dl-item-right {
font-size: 26rpx;
flex: 1; flex: 1;
padding-left: 10rpx; padding-left: 10rpx;
min-width: 100rpx; min-width: 100rpx;
@ -234,7 +236,8 @@
} }
.dl-number { .dl-number {
font-size: 26rpx; color: #929292;
font-size: 24rpx;
margin-right: 5rpx; margin-right: 5rpx;
} }
} }
@ -243,11 +246,11 @@
.right-image { .right-image {
flex: none; flex: none;
width: 220rpx; width: 180rpx;
height: 220rpx; height: 180rpx;
border-radius: 20rpx; border-radius: 20rpx;
} }
} }
} }
} }
</style> </style>

View File

@ -121,13 +121,13 @@
* 菜单切换 * 菜单切换
* @param {Object} code * @param {Object} code
*/ */
changeMenu(code) { async changeMenu(code) {
this.nowUserType = getUserType() this.nowUserType = getUserType()
if ("fabu" == code) { if ("fabu" == code) {
this.$tab.navigateTo('/pages/notice/public-notice') this.$tab.navigateTo('/pages/notice/public-notice')
} else { } else {
if (code == 'dingyue') { if (code == 'dingyue') {
if (!this.checkIfHasRights(rightsCode.subscribeSelect)) { if (!await this.checkIfHasRights(rightsCode.subscribeSelect)) {
return return
} }
} }
@ -141,7 +141,7 @@
async checkIfHasRights(rigthsCode) { async checkIfHasRights(rigthsCode) {
let res = await hasRights(rigthsCode) let res = await hasRights(rigthsCode)
if (!res) { if (!res) {
toast('请开通会员') this.openVip()
return false return false
} }
return true return true
@ -218,4 +218,4 @@
width: 70vw; width: 70vw;
} }
} }
</style> </style>

View File

@ -28,7 +28,14 @@
</view> </view>
</view> </view>
<!-- 购买 --> <!-- 购买 -->
<!-- #ifdef H5 -->
<view class="buy-button" @click="toOrder()">立即开通</view> <view class="buy-button" @click="toOrder()">立即开通</view>
<!-- #endif -->
<!-- 调整h5 -->
<!-- #ifdef MP-WEIXIN -->
<view class="buy-button" @click="openVip()">立即开通</view>
<!-- #endif -->
<!-- 协议 --> <!-- 协议 -->
<view class="xieyi-box"> <view class="xieyi-box">
开通即代表您已阅读并同意<text 开通即代表您已阅读并同意<text
@ -74,7 +81,8 @@
rightList rightList
} from '@/api/business/base.js' } from '@/api/business/base.js'
import { import {
saveOrder saveOrder,
prepayment
} from '@/api/business/member.js' } from '@/api/business/member.js'
import { import {
getToken getToken
@ -174,31 +182,62 @@
}, },
onLoad(options) { onLoad(options) {
this.initData(options.userType);
//urlsearch //urlsearch
let search = location.search.slice(1); let search = location.search.slice(1);
let arr = search.split("&"); let arr = search.split("&");
let result = {}; let result = {};
arr.forEach(function(item) { arr.forEach(function(item) {
let itemArr = item.split('='); let itemArr = item.split('=');
result[itemArr[0]] = itemArr[1]; result[itemArr[0]] = itemArr[1];
}) })
let userTypeTemp = options.userType
this.initData(userTypeTemp);
if (result.code) { if (result.code) {
userTypeTemp = result.state
let that = this
getWebAccessTokenAndOpenid(result.code).then(res => { getWebAccessTokenAndOpenid(result.code).then(res => {
that.$store.dispatch('GzhLogin', res).then(() => {
gzhLogin(res) that.initData(userTypeTemp);
that.loginSuccess()
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
})
}) })
} else { } else {
this.toLogin(options.userType) this.toLogin(userTypeTemp)
} }
}, },
methods: { methods: {
openVip() {
//
wx.openOfficialAccountProfile({
username: 'tonggaokuaijie', //
success: res => {},
fail: res => {}
})
},
binderror() {
},
bindload() {
},
//
loginSuccess(result) {
//
this.$store.dispatch('GetInfo').then(res => {
})
},
toLogin(userType) { toLogin(userType) {
/*#ifdef APP-PLUS*/ /*#ifdef APP-PLUS*/
// App // App
@ -223,7 +262,8 @@
}, },
/**初始化*/ /**初始化*/
initData(userType) { initData(userType) {
if (getToken()) {
if (getToken() && userType) {
this.userType = userType this.userType = userType
this.getCardList(userType); this.getCardList(userType);
this.getRightsList(userType); this.getRightsList(userType);
@ -283,9 +323,12 @@
// //
handleUserAgrement(site) { handleUserAgrement(site) {
this.$tab.navigateTo(`/pages/common/richview/index?title=${site.title}&code=${site.code}`) this.$tab.navigateTo(`/pages/common/richview/index?title=${site.title}&code=${site.code}`)
},
toOpenH5() {
}, },
/**生成订单*/ /**生成订单*/
toOrder() { async toOrder() {
let data = { let data = {
userType: this.userType, userType: this.userType,
orderType: '01', orderType: '01',
@ -302,14 +345,17 @@
if (this.memberCardList[this.chooseCardIndex].priceList[this.choosePriceIndex].title === '月付会员') { if (this.memberCardList[this.chooseCardIndex].priceList[this.choosePriceIndex].title === '月付会员') {
data.goodsCycle = '01' data.goodsCycle = '01'
} }
let that = this
saveOrder(data).then(res => { saveOrder(data).then(res => {
if (res.code == 200) { if (res.code == 200) {
uni.showToast({ //
icon: 'success', let payData = {
duration: 2000, orderNo: res.data.orderNo
title: '保存成功' }
}); prepayment(payData).then(paymentData => {
uni.navigateBack() that.wxpay(paymentData)
})
// uni.navigateBack()
} }
}).catch((e) => { }).catch((e) => {
uni.showToast({ uni.showToast({
@ -319,6 +365,58 @@
}); });
}) })
}, },
// WeixinJSBridge
wxpay(data) {
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
}
} else {
this.onBridgeReady(data);
}
},
onBridgeReady(data) {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
//
"appId": data.appId, //
"timeStamp": data.timeStamp, //
"nonceStr": data.nonceStr, //
"package": data.packageVal, //prepay_id
"signType": data.signType, //RSA
"paySign": data.paySign //
},
function(res) {
//
if (res.err_msg == "get_brand_wcpay_request:ok") {
// 使,
//res.err_msgok
}
//
if (res.err_msg == "get_brand_wcpay_request:cancel") {
}
//
if (res.err_msg == "get_brand_wcpay_request:fail") {
}
/**
* 其它
* 1请检查预支付会话标识prepay_id是否已失效
* 2请求的appid与下单接口的appid是否一致
* */
if (res.err_msg == "调用支付JSAPI缺少参数total_fee") {
}
});
}
} }
} }
</script> </script>

View File

@ -258,8 +258,8 @@
formatNumberWithUnits(number) { formatNumberWithUnits(number) {
return formatNumberWithUnits(number) return formatNumberWithUnits(number)
}, },
getRightsCode() { async getRightsCode() {
let info = hasRights(rightsCode.manyCardReport) let info = await hasRights(rightsCode.manyCardReport)
if (!info) { if (!info) {
this.rightInfo.manyCardReport = false this.rightInfo.manyCardReport = false
} else { } else {
@ -319,9 +319,9 @@
}); });
}) })
}, },
submit(isSuper) { async submit(isSuper) {
if (isSuper == '1') { if (isSuper == '1') {
let flag = hasRights(rightsCode.superReport) let flag = await hasRights(rightsCode.superReport)
if (!flag) { if (!flag) {
uni.showToast({ uni.showToast({
title: '无超级报名权益', title: '无超级报名权益',

BIN
static/VIP.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

View File

@ -4,6 +4,9 @@ import constant from '@/utils/constant'
import { import {
changeUserType changeUserType
} from '@/utils/common.js' } from '@/utils/common.js'
import {
gzhLogin
} from '@/api/wxApi'
import { import {
login, login,
wxLogin, wxLogin,
@ -69,6 +72,20 @@ const user = {
}) })
}) })
}, },
// 公众号登录
GzhLogin({
commit
}, data) {
return new Promise((resolve, reject) => {
gzhLogin(data).then(res => {
setToken(res.token)
commit('SET_TOKEN', res.token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// 登录 // 登录
Login({ Login({
commit commit
@ -144,4 +161,4 @@ const user = {
} }
} }
export default user export default user

View File

@ -1,73 +1,78 @@
import store from '@/store' import store from '@/store'
import config from '@/config' import config from '@/config'
import { getToken } from '@/utils/auth' import {
getToken
} from '@/utils/auth'
import errorCode from '@/utils/errorCode' import errorCode from '@/utils/errorCode'
import { toast, showConfirm, tansParams } from '@/utils/common' import {
toast,
showConfirm,
tansParams
} from '@/utils/common'
let timeout = 10000 let timeout = 10000
const baseUrl = config.baseUrl const baseUrl = config.baseUrl
const request = config => { const request = config => {
// 是否需要设置 token // 是否需要设置 token
const isToken = (config.headers || {}).isToken === false const isToken = (config.headers || {}).isToken === false
config.header = config.header || {} config.header = config.header || {}
if (getToken() && !isToken) { if (getToken() && !isToken) {
config.header['Authorization'] = 'Bearer ' + getToken() config.header['Authorization'] = 'Bearer ' + getToken()
} }
// get请求映射params参数 // get请求映射params参数
if (config.params) { if (config.params) {
let url = config.url + '?' + tansParams(config.params) let url = config.url + '?' + tansParams(config.params)
url = url.slice(0, -1) url = url.slice(0, -1)
config.url = url config.url = url
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
method: config.method || 'get', method: config.method || 'get',
timeout: config.timeout || timeout, timeout: config.timeout || timeout,
url: config.baseUrl || baseUrl + config.url, url: config.baseUrl || baseUrl + config.url,
data: config.data, data: config.data,
header: config.header, header: config.header,
dataType: 'json' dataType: 'json'
}).then(response => { }).then(response => {
let [error, res] = response let [error, res] = response
if (error) { if (error) {
toast('后端接口连接异常') toast('后端接口连接异常')
reject('后端接口连接异常') reject('后端接口连接异常')
return return
} }
const code = res.data.code || 200 const code = res.data.code || 200
const msg = errorCode[code] || res.data.msg || errorCode['default'] const msg = errorCode[code] || res.data.msg || errorCode['default']
if (code === 401) { if (code === 401) {
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => { store.dispatch('LogOut').then(res => {
if (res.confirm) { uni.reLaunch({
store.dispatch('LogOut').then(res => { url: '/pages/login'
uni.reLaunch({ url: '/pages/login' }) })
}) })
} } else if (code === 500) {
}) toast(msg)
reject('无效的会话,或者会话已过期,请重新登录。') reject(msg)
} else if (code === 500) { } else if (code !== 200) {
toast(msg) toast(msg)
reject(msg) reject(msg)
} else if (code !== 200) { }
toast(msg) resolve(res.data)
reject(msg) })
} .catch(error => {
resolve(res.data) let {
}) message
.catch(error => { } = error
let { message } = error if (message === 'Network Error') {
if (message === 'Network Error') { message = '后端接口连接异常'
message = '后端接口连接异常' } else if (message.includes('timeout')) {
} else if (message.includes('timeout')) { message = '系统接口请求超时'
message = '系统接口请求超时' } else if (message.includes('Request failed with status code')) {
} else if (message.includes('Request failed with status code')) { message = '系统接口' + message.substr(message.length - 3) + '异常'
message = '系统接口' + message.substr(message.length - 3) + '异常' }
} toast(message)
toast(message) reject(error)
reject(error) })
}) })
})
} }
export default request export default request