添加请求重复拦截

msb_beta
ch 3 years ago
parent 55381c3fea
commit a703ad6a04

File diff suppressed because one or more lines are too long

@ -1,30 +0,0 @@
/*
* @Author: ch
* @Date: 2022-03-29 16:47:32
* @LastEditors: ch
* @LastEditTime: 2022-04-14 10:14:40
* @Description: file content
*/
import Enum from "@/common/plugins/enum"
const DictOrderStatus = new Enum([
{key : '1', name : '待支付', value: 'awaitPay'},
{key : '2', name : '已关闭', value: 'close'},
{key : '3', name : '待发货', value: 'awaitSend'},
{key : '4', name : '已发货', value: 'finishSend'},
{key : '6', name : '已收货', value: 'finishReceiving'},
{key : '7', name : '已完成', value: 'end'}
])
const DictSaleAfterStatus = {
"1":"已申请",
"2":"已关闭",
"3":"待退货",
"4":"退货中",
"5":"退款中",
"6":"退款成功",
"7":"退款失败"
}
export {
DictOrderStatus,
DictSaleAfterStatus
}

@ -1,10 +0,0 @@
import Enum from '../enum'
/**
* 枚举类优惠券适用范围
* ApplyRangeEnum
*/
export default new Enum([
{ key: 'ALL', name: '全部商品', value: 10 },
{ key: 'SOME_GOODS', name: '指定商品', value: 20 }
])

@ -1,10 +0,0 @@
import Enum from '../enum'
/**
* 枚举类优惠券类型
* CouponTypeEnum
*/
export default new Enum([
{ key: 'FULL_DISCOUNT', name: '满减券', value: 10 },
{ key: 'DISCOUNT', name: '折扣券', value: 20 }
])

@ -1,10 +0,0 @@
import Enum from '../enum'
/**
* 枚举类优惠券到期类型
* ExpireTypeEnum
*/
export default new Enum([
{ key: 'RECEIVE', name: '领取后', value: 10 },
{ key: 'FIXED_TIME', name: '固定时间', value: 20 }
])

@ -1,5 +0,0 @@
import ApplyRangeEnum from './ApplyRange'
import ExpireTypeEnum from './ExpireType'
import CouponTypeEnum from './CouponType'
export { ApplyRangeEnum, CouponTypeEnum, ExpireTypeEnum }

@ -1,85 +0,0 @@
/**
* 枚举类
* Enum.IMAGE.name => "图片"
* Enum.getNameByKey('IMAGE') => "图片"
* Enum.getValueByKey('IMAGE') => 10
* Enum.getNameByValue(10) => "图片"
* Enum.getData() => [{key: "IMAGE", name: "图片", value: 10}]
*/
class Enum {
constructor (param) {
const keyArr = []
const valueArr = []
if (!Array.isArray(param)) {
throw new Error('param is not an array!')
}
param.map(element => {
if (!element.key || !element.name) {
return
}
// 保存key值组成的数组方便A.getName(name)类型的调用
keyArr.push(element.key)
valueArr.push(element.value)
// 根据key生成不同属性值以便A.B.name类型的调用
this[element.key] = element
if (element.key !== element.value) {
this[element.value] = element
}
})
// 保存源数组
this.data = param
this.keyArr = keyArr
this.valueArr = valueArr
// 防止被修改
// Object.freeze(this)
}
// 根据key得到对象
keyOf (key) {
return this.data[this.keyArr.indexOf(key)]
}
// 根据key得到对象
valueOf (key) {
return this.data[this.valueArr.indexOf(key)]
}
// 根据key获取name值
getNameByKey (key) {
const prop = this.keyOf(key)
if (!prop) {
throw new Error('No enum constant' + key)
}
return prop.name
}
// 根据value获取name值
getNameByValue (value) {
const prop = this.valueOf(value)
if (!prop) {
throw new Error('No enum constant' + value)
}
return prop.name
}
// 根据key获取value值
getValueByKey (key) {
const prop = this.keyOf(key)
if (!prop) {
throw new Error('No enum constant' + key)
}
return prop.key
}
// 返回源数组
getData () {
return this.data
}
}
export default Enum

@ -1,10 +0,0 @@
import Enum from '../enum'
/**
* 枚举类订单发货状态
* DeliveryStatusEnum
*/
export default new Enum([
{ key: 'NOT_DELIVERED', name: '未发货', value: 10 },
{ key: 'DELIVERED', name: '已发货', value: 20 }
])

@ -1,9 +0,0 @@
import Enum from '../enum'
/**
* 枚举类配送方式
* DeliveryTypeEnum
*/
export default new Enum([
{ key: 'EXPRESS', name: '快递配送', value: 10 }
])

@ -1,11 +0,0 @@
import Enum from '../enum'
/**
* 枚举类订单来源
* OrderSourceEnum
*/
export default new Enum([
{ key: 'MASTER', name: '普通订单', value: 10 },
{ key: 'BARGAIN', name: '砍价订单', value: 20 },
{ key: 'SHARP', name: '秒杀订单', value: 30 }
])

@ -1,12 +0,0 @@
import Enum from '../enum'
/**
* 枚举类订单状态
* OrderStatusEnum
*/
export default new Enum([
{ key: 'NORMAL', name: '进行中', value: 10 },
{ key: 'CANCELLED', name: '已取消', value: 20 },
{ key: 'APPLY_CANCEL', name: '待取消', value: 21 },
{ key: 'COMPLETED', name: '已完成', value: 30 }
])

@ -1,10 +0,0 @@
import Enum from '../enum'
/**
* 枚举类订单支付状态
* PayStatusEnum
*/
export default new Enum([
{ key: 'PENDING', name: '待支付', value: 10 },
{ key: 'SUCCESS', name: '已支付', value: 20 }
])

@ -1,10 +0,0 @@
import Enum from '../enum'
/**
* 枚举类订单支付方式
* PayTypeEnum
*/
export default new Enum([
{ key: 'BALANCE', name: '余额支付', value: 10 },
{ key: 'WECHAT', name: '微信支付', value: 20 }
])

@ -1,10 +0,0 @@
import Enum from '../enum'
/**
* 枚举类订单收货状态
* ReceiptStatusEnum
*/
export default new Enum([
{ key: 'NOT_RECEIVED', name: '未收货', value: 10 },
{ key: 'RECEIVED', name: '已收货', value: 20 }
])

@ -1,17 +0,0 @@
import DeliveryStatusEnum from './DeliveryStatus'
import DeliveryTypeEnum from './DeliveryType'
import OrderSourceEnum from './OrderSource'
import OrderStatusEnum from './OrderStatus'
import PayStatusEnum from './PayStatus'
import PayTypeEnum from './PayType'
import ReceiptStatusEnum from './ReceiptStatus'
export {
DeliveryStatusEnum,
DeliveryTypeEnum,
OrderSourceEnum,
OrderStatusEnum,
PayStatusEnum,
PayTypeEnum,
ReceiptStatusEnum
}

@ -1,11 +0,0 @@
import Enum from '../../enum'
/**
* 枚举类商家审核状态
* AuditStatusEnum
*/
export default new Enum([
{ key: 'WAIT', name: '待审核', value: 0 },
{ key: 'REVIEWED', name: '已同意', value: 10 },
{ key: 'REJECTED', name: '已拒绝', value: 20 }
])

@ -1,12 +0,0 @@
import Enum from '../../enum'
/**
* 枚举类售后单状态
* RefundStatusEnum
*/
export default new Enum([
{ key: 'NORMAL', name: '进行中', value: 0 },
{ key: 'REJECTED', name: '已拒绝', value: 10 },
{ key: 'COMPLETED', name: '已完成', value: 20 },
{ key: 'CANCELLED', name: '已取消', value: 30 }
])

@ -1,10 +0,0 @@
import Enum from '../../enum'
/**
* 枚举类售后类型
* RefundTypeEnum
*/
export default new Enum([
{ key: 'RETURN', name: '退货退款', value: 10 },
{ key: 'EXCHANGE', name: '换货', value: 20 }
])

@ -1,9 +0,0 @@
import AuditStatusEnum from './AuditStatus'
import RefundStatusEnum from './RefundStatus'
import RefundTypeEnum from './RefundType'
export {
AuditStatusEnum,
RefundStatusEnum,
RefundTypeEnum
}

@ -1,27 +0,0 @@
import Enum from '../enum'
/**
* 枚举类设置项索引
* SettingKeyEnum
*/
export default new Enum([{
key: 'REGISTER',
name: '账户注册设置',
value: 'register'
},
{
key: 'PAGE_CATEGORY_TEMPLATE',
name: '分类页模板',
value: 'page_category_template'
},
{
key: 'POINTS',
name: '积分设置',
value: 'points'
},
{
key: 'RECHARGE',
name: '充值设置',
value: 'recharge'
}
])

@ -1,11 +0,0 @@
import Enum from '../../../enum'
/**
* 枚举类地址类型
* PageCategoryStyleEnum
*/
export default new Enum([
{ key: 'ONE_LEVEL_BIG', name: '一级分类[大图]', value: 10 },
{ key: 'ONE_LEVEL_SMALL', name: '一级分类[小图]', value: 11 },
{ key: 'TWO_LEVEL', name: '二级分类', value: 20 }
])

@ -1,3 +0,0 @@
import PageCategoryStyleEnum from './Style'
export { PageCategoryStyleEnum }

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-17 16:36:59
* @LastEditors: ch
* @LastEditTime: 2022-04-13 13:36:15
* @LastEditTime: 2022-04-19 18:46:25
* @Description: 针对uniapp request请求做了一次封装使用思维参考axios
*
*
@ -46,6 +46,9 @@
class MsbUniRequest {
constructor (option){
this.baseUrl = '';
this.header = {
repeat : true
}
this.hook = {
request : null,
success : null,
@ -54,6 +57,7 @@ class MsbUniRequest {
}
method(option){
option.header = {...this.header,...option.header};
option.url = this.baseUrl + option.url;
if(this.hook.request && !option.header){
option = this.hook.request(option);
@ -68,12 +72,12 @@ class MsbUniRequest {
uni.request(option).then(res => {
const response = res[1];
if(response.statusCode >= 200 && response.statusCode < 400){
resolve(this.hook.success ? this.hook.success(response) : response);
resolve(this.hook.success ? this.hook.success(response, option) : response);
return false;
}
reject(this.hook.error ? this.hook.error(response) : response);
reject(this.hook.error ? this.hook.error(response, option) : response);
}).catch(error => {
reject(this.hook.error ? this.hook.error(error) : error);
reject(this.hook.error ? this.hook.error(error, option) : error);
});
});
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-17 17:42:32
* @LastEditors: ch
* @LastEditTime: 2022-04-19 11:33:34
* @LastEditTime: 2022-04-19 18:54:15
* @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法
*/
@ -16,7 +16,13 @@ const BASE_URL = {
'release' : '',
'prod' : ''
};
const successIntercept = (response) =>{
/**
* 接口返回成功结果统一处理
* @param {*} response
* @param {*} option
*/
const successIntercept = (response, option) =>{
clearRepeat(option)
if(response.statusCode === 200){
const result = response.data;
if(result.code === 'SUCCESS'){
@ -30,41 +36,86 @@ const successIntercept = (response) =>{
}
return response;
}
const errorIntercept = (error) =>{
/**
* 接口返回错误结果统一处理
* @param {*} error
* @param {*} option
*/
const errorIntercept = (error, option) =>{
clearRepeat(option)
return {message:error.errMsg,code:error.statusCode}
}
//正在执行的请求标识
let repeatFlag = [];
/**
* 验证是否重复请求没有则添加一条到标记
* @param {*} option
*/
const repeatVerify = (option)=>{
if(repeatFlag.includes(JSON.stringify(option))){
return Promise.reject({message:'请勿频繁操作'});
}
repeatFlag.push(JSON.stringify(option));
return false;
};
/**
* 清除请求标记
* @param {*} option
*/
const clearRepeat = (option) =>{
repeatFlag = repeatFlag.filter( i => {
return i !== JSON.stringify(option)
});
}
// 不需要token的接口封装
const MsbRequest = new MsbUniRequest();
MsbRequest.baseUrl = BASE_URL[ENV];
MsbRequest.use('request', (option) => {
if(option.header.repeat){
// 如果当前请求不允许重复调用,则检查重复请求,当前接口有正在请求则不发起请求
const isRepeatVerify = repeatVerify(option);
if(isRepeatVerify){
return isRepeatVerify;
}
}
return option;
})
MsbRequest.use('success', successIntercept);
MsbRequest.use('error', errorIntercept);
// 不需要token的接口封装
// 需要token的接口封装
const MsbRequestTk = new MsbUniRequest();
MsbRequestTk.baseUrl = BASE_URL[ENV];
MsbRequestTk.use('request', (option) => {
const token = $store.state.token;
if(!token){
// 登录状态处理没有token直接跳转至登录
const pages = getCurrentPages();
const page = pages[pages.length - 1];
page.$Router.replace({path : '/login',query:{h : page.__page__.path}})
page.$Router.replace('/login');
return Promise.reject({message:'要先登录才能操作哦~'});
}else{
option.header = {...option.header, Authorization:$store.state.token}
option.header = {...option.header, Authorization:$store.state.token};
if(option.header.repeat){
// 如果当前请求不允许重复调用,则检查重复请求,当前接口有正在请求则不发起请求
const isRepeatVerify = repeatVerify(option);
if(isRepeatVerify){
return isRepeatVerify;
}
}
return option;
}
})
MsbRequestTk.use('success', successIntercept);
MsbRequestTk.use('error', errorIntercept);
export {
MsbRequest,
MsbRequestTk

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-20 16:45:27
* @LastEditors: ch
* @LastEditTime: 2022-04-12 16:47:49
* @LastEditTime: 2022-04-19 18:08:43
* @Description: file content
-->
<template>
@ -22,7 +22,7 @@ export default {
loadingStatus : 'loading',
listData : [],
params : {
length : 10,
length : 15,
pageIndex : 1
}
}

@ -2,11 +2,12 @@
* @Author: ch
* @Date: 2022-04-19 16:19:32
* @LastEditors: ch
* @LastEditTime: 2022-04-19 17:29:48
* @LastEditTime: 2022-04-19 17:54:49
* @Description: file content
-->
<template>
<u-modal :show="show" :content="content" showCancelButton
:cancelText="cancelText" :confirmText="confirmText"
@confirm="myConfirm" @cancel="myCancel"/>
</template>
<script>
@ -16,7 +17,7 @@ export default {
type : String,
default : ''
},
confirmTxt : {
confirmText : {
type : String,
default : '确认'
},
@ -24,7 +25,7 @@ export default {
type : Function,
default: function(){}
},
cancelTxt : {
cancelText : {
type : String,
default : '取消'
},

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 15:09:06
* @LastEditors: ch
* @LastEditTime: 2022-04-19 17:20:30
* @LastEditTime: 2022-04-19 17:55:28
* @Description: file content
-->
<template>
@ -28,8 +28,14 @@ export default {
},
methods:{
logout(){
this.$store.commit('SET_TOKEN');
this.$Router.replace('/login')
this.$msb.confirm({
content : '是否退出登录?',
cancelText : '再看看',
confirm : ()=>{
this.$store.commit('SET_TOKEN');
this.$Router.replace('/login');
}
})
}
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-21 10:31:54
* @LastEditors: ch
* @LastEditTime: 2022-04-12 10:28:58
* @LastEditTime: 2022-04-19 18:09:02
* @Description: file content
-->
<template>
@ -48,7 +48,7 @@ export default {
loadingStatus : 'loading',
listData : [],
params : {
length : 10,
length : 15,
pageIndex : 1,
name : this.$Route.query.search,
categoryId : this.$Route.query.categoryId,

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 10:58:24
* @LastEditors: ch
* @LastEditTime: 2022-04-19 17:37:49
* @LastEditTime: 2022-04-19 18:10:45
* @Description: file content
-->
<template>
@ -59,7 +59,6 @@
<script>
import BsEmpty from '@/components/BsEmpty.vue';
import UiButton from '@/components/UiButton.vue';
import { DictOrderStatus } from '@/common/dicts/order';
import { ApiGetOrderList, ApiPutOrderReceive } from '@/common/api/order';
import BsPay from '../../components/BsPay.vue';

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-28 17:16:44
* @LastEditors: ch
* @LastEditTime: 2022-04-11 18:05:06
* @LastEditTime: 2022-04-19 18:06:43
* @Description: file content
-->
<template>
@ -14,6 +14,9 @@
<UiButton class="btn" type="primaryLine" @click="$Router.replaceAll('/')"></UiButton>
<UiButton class="btn" type="solid" @click="$Router.replace(`/orderDetail?id=${$Route.query.ordId}`)"></UiButton>
</view>
<view class="recommend-title">为您推荐</view>
<BsChoiceGoods></BsChoiceGoods>
</view>
</template>
<script>
@ -47,4 +50,26 @@ page{
display: flex;
justify-content: space-between;
}
.recommend-title{
font-size: $font-size-lg;
text-align: center;
margin: 51rpx auto 30rpx auto;
display: flex;
align-items: center;
justify-content: space-between;
width: 500rpx;
&::after,&::before{
display: inline-block;
content: '';
width: 160rpx;
height: 2rpx;
background: linear-gradient(90deg, $color-grey3 0%, rgba(204, 204, 204, 0) 100%);
}
&::before{
background: linear-gradient(270deg, $color-grey3 0%, rgba(204, 204, 204, 0) 100%);
}
}
</style>

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-31 17:53:43
* @LastEditors: ch
* @LastEditTime: 2022-04-14 15:01:49
* @LastEditTime: 2022-04-19 18:12:04
* @Description: file content
-->
<template>
@ -13,8 +13,6 @@
</view>
</template>
<script>
import {DictOrderStatus } from '@/common/dicts/order'
import Enum from "@/common/plugins/enum"
export default {
props : {
data : {

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-22 10:58:24
* @LastEditors: ch
* @LastEditTime: 2022-04-15 15:30:57
* @LastEditTime: 2022-04-19 18:10:51
* @Description: file content
-->
<template>
@ -40,7 +40,6 @@
<script>
import BsEmpty from '@/components/BsEmpty.vue';
import UiButton from '@/components/UiButton.vue';
import { DictOrderStatus } from '@/common/dicts/order';
import { ApiGetSaleAfterOrderList } from '@/common/api/order';
export default {

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-21 18:08:07
* @LastEditors: ch
* @LastEditTime: 2022-04-13 09:47:45
* @LastEditTime: 2022-04-19 18:08:48
* @Description: file content
-->
<template>
@ -56,7 +56,7 @@ export default {
timeList : [],
goodsList : [],
pageIndex : 1,
length : 10,
length : 15,
activityTime : {},
loadingStatus : 'loading',
isLast : false

Loading…
Cancel
Save