Procházet zdrojové kódy

axios,post请求,同一接口不能请求两次,防抖函数的封装,将部分列表接口的请求改为get

miaofuhao %!s(int64=3) %!d(string=před) roky
rodič
revize
638ff2fa0e

+ 1 - 1
CallCenterWeb.UI/RMYY/src/api/systemSetup/roleSetting/orderTypeManage.js

4
 export function getOrderTypeLists(params) {
4
 export function getOrderTypeLists(params) {
5
   return request({
5
   return request({
6
     url: 'GongDanType/GetList',
6
     url: 'GongDanType/GetList',
7
-    method: 'post',
7
+    method: 'get',
8
     params
8
     params
9
   })
9
   })
10
 }
10
 }

+ 2 - 2
CallCenterWeb.UI/RMYY/src/api/trafficData/trafficData.js

4
 export function getCallRecords(params) {
4
 export function getCallRecords(params) {
5
   return request({
5
   return request({
6
     url: 'Callrecords/GetList',
6
     url: 'Callrecords/GetList',
7
-    method: 'post',
7
+    method: 'get',
8
     params
8
     params
9
   })
9
   })
10
 }
10
 }
32
     method: 'post',
32
     method: 'post',
33
     params
33
     params
34
   })
34
   })
35
-}
35
+}

+ 152 - 94
CallCenterWeb.UI/RMYY/src/utils/index.js

12
   myDate.getYear() // 获取当前年份(2位)
12
   myDate.getYear() // 获取当前年份(2位)
13
   const YY = myDate.getFullYear() // 获取完整的年份(4位,1970-????)
13
   const YY = myDate.getFullYear() // 获取完整的年份(4位,1970-????)
14
   let MM = myDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
14
   let MM = myDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
15
-  MM = MM > 9 ? MM : ('0' + MM)
15
+  MM = MM > 9 ? MM : '0' + MM
16
   let DD = myDate.getDate() // 获取当前日(1-31)
16
   let DD = myDate.getDate() // 获取当前日(1-31)
17
-  DD = DD > 9 ? DD : ('0' + DD)
17
+  DD = DD > 9 ? DD : '0' + DD
18
   let hh = myDate.getHours()
18
   let hh = myDate.getHours()
19
-  hh = hh > 9 ? hh : ('0' + hh)
19
+  hh = hh > 9 ? hh : '0' + hh
20
   let mm = myDate.getMinutes()
20
   let mm = myDate.getMinutes()
21
-  mm = mm > 9 ? mm : ('0' + mm)
21
+  mm = mm > 9 ? mm : '0' + mm
22
   let ss = myDate.getSeconds()
22
   let ss = myDate.getSeconds()
23
-  ss = ss > 9 ? ss : ('0' + ss)
23
+  ss = ss > 9 ? ss : '0' + ss
24
   return YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss
24
   return YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss
25
 }
25
 }
26
 
26
 
32
   myDate.getYear() // 获取当前年份(2位)
32
   myDate.getYear() // 获取当前年份(2位)
33
   const YY = myDate.getFullYear() // 获取完整的年份(4位,1970-????)
33
   const YY = myDate.getFullYear() // 获取完整的年份(4位,1970-????)
34
   let MM = myDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
34
   let MM = myDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
35
-  MM = MM > 9 ? MM : ('0' + MM)
35
+  MM = MM > 9 ? MM : '0' + MM
36
   let DD = myDate.getDate() // 获取当前日(1-31)
36
   let DD = myDate.getDate() // 获取当前日(1-31)
37
-  DD = DD > 9 ? DD : ('0' + DD)
37
+  DD = DD > 9 ? DD : '0' + DD
38
   return YY + '-' + MM + '-' + DD
38
   return YY + '-' + MM + '-' + DD
39
 }
39
 }
40
 
40
 
48
   start.getYear() // 获取当前年份(2位)
48
   start.getYear() // 获取当前年份(2位)
49
   const YY = start.getFullYear() // 获取完整的年份(4位,1970-????)
49
   const YY = start.getFullYear() // 获取完整的年份(4位,1970-????)
50
   let MM = start.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
50
   let MM = start.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
51
-  MM = MM > 9 ? MM : ('0' + MM)
51
+  MM = MM > 9 ? MM : '0' + MM
52
   let DD = start.getDate() // 获取当前日(1-31)
52
   let DD = start.getDate() // 获取当前日(1-31)
53
-  DD = DD > 9 ? DD : ('0' + DD)
53
+  DD = DD > 9 ? DD : '0' + DD
54
   return YY + '-' + MM + '-' + DD
54
   return YY + '-' + MM + '-' + DD
55
 }
55
 }
56
 
56
 
62
   myDate.getYear() // 获取当前年份(2位)
62
   myDate.getYear() // 获取当前年份(2位)
63
   const YY = myDate.getFullYear() // 获取完整的年份(4位,1970-????)
63
   const YY = myDate.getFullYear() // 获取完整的年份(4位,1970-????)
64
   let MM = myDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
64
   let MM = myDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
65
-  MM = MM > 9 ? MM : ('0' + MM)
65
+  MM = MM > 9 ? MM : '0' + MM
66
   let DD = myDate.getDate() // 获取当前日(1-31)
66
   let DD = myDate.getDate() // 获取当前日(1-31)
67
-  DD = DD > 9 ? DD : ('0' + DD)
67
+  DD = DD > 9 ? DD : '0' + DD
68
   return YY + '-' + MM + '-01'
68
   return YY + '-' + MM + '-01'
69
 }
69
 }
70
 /**
70
 /**
73
 export function getLastDay(year, month) {
73
 export function getLastDay(year, month) {
74
   var order_month = month
74
   var order_month = month
75
   var new_year = year // 取当前的年份
75
   var new_year = year // 取当前的年份
76
-  var new_month = month++// 取下一个月的第一天,方便计算(最后一天不固定)
76
+  var new_month = month++ // 取下一个月的第一天,方便计算(最后一天不固定)
77
   if (month > 12) {
77
   if (month > 12) {
78
     new_month -= 12 // 月份减
78
     new_month -= 12 // 月份减
79
     new_year++ // 年份增
79
     new_year++ // 年份增
80
   }
80
   }
81
   var new_date = new Date(new_year, new_month, 1) // 取当年当月中的第一天
81
   var new_date = new Date(new_year, new_month, 1) // 取当年当月中的第一天
82
   console.log(month)
82
   console.log(month)
83
-  return year + '-' + order_month + '-' + (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate()// 获取当月最后一天日期
83
+  return (
84
+    year +
85
+    '-' +
86
+    order_month +
87
+    '-' +
88
+    new Date(new_date.getTime() - 1000 * 60 * 60 * 24).getDate()
89
+  ) // 获取当月最后一天日期
84
 }
90
 }
85
 /**
91
 /**
86
  * 超期变红
92
  * 超期变红
89
  */
95
  */
90
 export function endtimeFilter(status) {
96
 export function endtimeFilter(status) {
91
   const d = status.replace(/-/g, '/')
97
   const d = status.replace(/-/g, '/')
92
-  let curDate = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate()
98
+  let curDate =
99
+    new Date().getFullYear() +
100
+    '-' +
101
+    (new Date().getMonth() + 1) +
102
+    '-' +
103
+    new Date().getDate()
93
   curDate = curDate.replace(/-/g, '/')
104
   curDate = curDate.replace(/-/g, '/')
94
   let str = ''
105
   let str = ''
95
   if (Date.parse(d) >= Date.parse(curDate)) {
106
   if (Date.parse(d) >= Date.parse(curDate)) {
114
   }
125
   }
115
   const date = new Date(timestamp)
126
   const date = new Date(timestamp)
116
   const Y = date.getFullYear() + '-'
127
   const Y = date.getFullYear() + '-'
117
-  const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
118
-  const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' '
119
-  const h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':'
120
-  const m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':'
121
-  const s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
128
+  const M =
129
+    (date.getMonth() + 1 < 10
130
+      ? '0' + (date.getMonth() + 1)
131
+      : date.getMonth() + 1) + '-'
132
+  const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
133
+  const h =
134
+    (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
135
+  const m =
136
+    (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
137
+  const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
122
   return Y + M + D + h + m + s
138
   return Y + M + D + h + m + s
123
 }
139
 }
124
 
140
 
149
   }
165
   }
150
   const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
166
   const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
151
     let value = formatObj[key]
167
     let value = formatObj[key]
152
-    if (key === 'a') return ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'][value - 1]
168
+    if (key === 'a')
169
+      return [
170
+        '星期一',
171
+        '星期二',
172
+        '星期三',
173
+        '星期四',
174
+        '星期五',
175
+        '星期六',
176
+        '星期日'
177
+      ][value - 1]
153
     if (result.length > 0 && value < 10) {
178
     if (result.length > 0 && value < 10) {
154
       value = '0' + value
179
       value = '0' + value
155
     }
180
     }
164
 export function secondToDuring(ss) {
189
 export function secondToDuring(ss) {
165
   let days = parseInt(ss / (60 * 60 * 24))
190
   let days = parseInt(ss / (60 * 60 * 24))
166
   let hours = parseInt((ss % (60 * 60 * 24)) / (60 * 60))
191
   let hours = parseInt((ss % (60 * 60 * 24)) / (60 * 60))
167
-  let minutes = parseInt((ss % (60 * 60)) / (60))
192
+  let minutes = parseInt((ss % (60 * 60)) / 60)
168
   let seconds = ss % 60
193
   let seconds = ss % 60
169
-  days = days > 0 ? (days + '天') : ''
170
-  hours = hours > 0 ? (hours + '小时') : ''
171
-  minutes = minutes > 0 ? (minutes + '分') : ''
172
-  seconds = seconds >= 0 ? (seconds + '秒') : ''
194
+  days = days > 0 ? days + '天' : ''
195
+  hours = hours > 0 ? hours + '小时' : ''
196
+  minutes = minutes > 0 ? minutes + '分' : ''
197
+  seconds = seconds >= 0 ? seconds + '秒' : ''
173
   return days + hours + minutes + seconds
198
   return days + hours + minutes + seconds
174
 }
199
 }
175
 
200
 
197
 
222
 
198
   if (diff < 30) {
223
   if (diff < 30) {
199
     return '刚刚'
224
     return '刚刚'
200
-  } else if (diff < 3600) { // less 1 hour
225
+  } else if (diff < 3600) {
226
+    // less 1 hour
201
     return Math.ceil(diff / 60) + '分钟前'
227
     return Math.ceil(diff / 60) + '分钟前'
202
   } else if (diff < 3600 * 24) {
228
   } else if (diff < 3600 * 24) {
203
     return Math.ceil(diff / 3600) + '小时前'
229
     return Math.ceil(diff / 3600) + '小时前'
207
   if (option) {
233
   if (option) {
208
     return formatTime(time, option)
234
     return formatTime(time, option)
209
   } else {
235
   } else {
210
-    return d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
236
+    return (
237
+      d.getMonth() +
238
+      1 +
239
+      '月' +
240
+      d.getDate() +
241
+      '日' +
242
+      d.getHours() +
243
+      '时' +
244
+      d.getMinutes() +
245
+      '分'
246
+    )
211
   }
247
   }
212
 }
248
 }
213
 
249
 
214
 // 格式化 日期选择器的 带快捷选项
250
 // 格式化 日期选择器的 带快捷选项
215
 export const pickerOptions = {
251
 export const pickerOptions = {
216
-  shortcuts: [{
217
-    text: '最近一周',
218
-    onClick(picker) {
219
-      const end = new Date()
220
-      const start = new Date()
221
-      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
222
-      picker.$emit('pick', [start, end])
223
-    }
224
-  },
225
-  {
226
-    text: '最近一个月',
227
-    onClick(picker) {
228
-      const start = new Date()
229
-      const end = new Date()
230
-      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
231
-      picker.$emit('pick', [start, end])
232
-    }
233
-  },
234
-  {
235
-    text: '最近三个月',
236
-    onClick(picker) {
237
-      const start = new Date()
238
-      const end = new Date()
239
-      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
240
-      picker.$emit('pick', [start, end])
252
+  shortcuts: [
253
+    {
254
+      text: '最近一周',
255
+      onClick(picker) {
256
+        const end = new Date()
257
+        const start = new Date()
258
+        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
259
+        picker.$emit('pick', [start, end])
260
+      }
261
+    },
262
+    {
263
+      text: '最近一个月',
264
+      onClick(picker) {
265
+        const start = new Date()
266
+        const end = new Date()
267
+        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
268
+        picker.$emit('pick', [start, end])
269
+      }
270
+    },
271
+    {
272
+      text: '最近三个月',
273
+      onClick(picker) {
274
+        const start = new Date()
275
+        const end = new Date()
276
+        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
277
+        picker.$emit('pick', [start, end])
278
+      }
241
     }
279
     }
242
-  }
243
   ]
280
   ]
244
 }
281
 }
245
 
282
 
274
   },
311
   },
275
   // 原样式输出内容
312
   // 原样式输出内容
276
   content(con) {
313
   content(con) {
277
-    if (con === 'null' || con === 'undefined' || con === null || con === undefined || con === '') {
314
+    if (
315
+      con === 'null' ||
316
+      con === 'undefined' ||
317
+      con === null ||
318
+      con === undefined ||
319
+      con === ''
320
+    ) {
278
       con = '暂无内容'
321
       con = '暂无内容'
279
     } else {
322
     } else {
280
-      con = con.replace(/[ ]/g, '&nbsp;').replace(/\ +/g, '&nbsp;').replace(/\r\n/g, '<br />').replace(/\n/g, '<br />')
323
+      con = con
324
+        .replace(/[ ]/g, '&nbsp;')
325
+        .replace(/\ +/g, '&nbsp;')
326
+        .replace(/\r\n/g, '<br />')
327
+        .replace(/\n/g, '<br />')
281
     }
328
     }
282
     return con
329
     return con
283
   }
330
   }
295
 // GUID 的格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”,其中的 x 是 0-9 或 a-f 范围内的一个32位十六进制数
342
 // GUID 的格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”,其中的 x 是 0-9 或 a-f 范围内的一个32位十六进制数
296
 export function guid() {
343
 export function guid() {
297
   return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
344
   return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
298
-    const r = Math.random() * 16 | 0
299
-    const v = c === 'x' ? r : (r & 0x3 | 0x8)
345
+    const r = (Math.random() * 16) | 0
346
+    const v = c === 'x' ? r : (r & 0x3) | 0x8
300
     return v.toString(16)
347
     return v.toString(16)
301
   })
348
   })
302
 }
349
 }
326
 /**
373
 /**
327
  * 防抖动 节流
374
  * 防抖动 节流
328
  */
375
  */
329
-// scroll 事件本身会触发页面的重新渲染,同时 scroll 事件的 handler 又会被高频度的触发,
330
-// 因此事件的 handler 内部不应该有复杂操作,例如 DOM 操作就不应该放在事件处理中。
331
-// 针对此类高频度触发事件问题(例如页面 scroll ,屏幕 resize,监听用户输入等),有两种常用的解决方法,防抖和节流。
332
-export function debounce(func, wait, immediate) {
333
-  let timeout, args, context, timestamp, result
334
-  const later = function() {
335
-    // 据上一次触发时间间隔
336
-    const last = +new Date() - timestamp
376
+// 例子 debounceList = debounce(getList, 5000)先声明
377
+// 后debounceList()调用,每个页面声明一次即可,调用可多次
378
+export function debounce(fn, delay, immediate = false, resultCallback) {
379
+  // 1.定义一个定时器, 保存上一次的定时器
380
+  let timer = null
381
+  let isInvoke = false
337
 
382
 
338
-    // 上次被包装函数被调用时间间隔last小于设定时间间隔wait
339
-    if (last < wait && last > 0) {
340
-      timeout = setTimeout(later, wait - last)
341
-    } else {
342
-      timeout = null
343
-      // 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
344
-      if (!immediate) {
345
-        result = func.apply(context, args)
346
-        if (!timeout) context = args = null
383
+  // 2.真正执行的函数
384
+  const _debounce = function(...args) {
385
+    return new Promise((resolve, reject) => {
386
+      // 取消上一次的定时器
387
+      if (timer) clearTimeout(timer)
388
+
389
+      // 判断是否需要立即执行
390
+      if (immediate && !isInvoke) {
391
+        const result = fn.apply(this, args)
392
+        if (resultCallback) resultCallback(result)
393
+        resolve(result)
394
+        isInvoke = true
395
+      } else {
396
+        // 延迟执行
397
+        timer = setTimeout(() => {
398
+          // 外部传入的真正要执行的函数
399
+          const result = fn.apply(this, args)
400
+          if (resultCallback) resultCallback(result)
401
+          resolve(result)
402
+          isInvoke = false
403
+          timer = null
404
+        }, delay)
347
       }
405
       }
348
-    }
406
+    })
349
   }
407
   }
350
-  return function(...args) {
351
-    context = this
352
-    timestamp = +new Date()
353
-    const callNow = immediate && !timeout
354
-    // 如果延时不存在,重新设定延时
355
-    if (!timeout) timeout = setTimeout(later, wait)
356
-    if (callNow) {
357
-      result = func.apply(context, args)
358
-      context = args = null
359
-    }
360
-    return result
408
+
409
+  // 封装取消功能
410
+  _debounce.cancel = function() {
411
+    if (timer) clearTimeout(timer)
412
+    timer = null
413
+    isInvoke = false
361
   }
414
   }
415
+
416
+  return _debounce
362
 }
417
 }
363
 
418
 
364
 // 首字母转大写
419
 // 首字母转大写
365
 export function firstToUpper(str) {
420
 export function firstToUpper(str) {
366
-  return str.replace(/( |^)[a-z]/g, (L) => L.toUpperCase())
421
+  return str.replace(/( |^)[a-z]/g, L => L.toUpperCase())
367
 }
422
 }
368
 
423
 
369
 // 导出
424
 // 导出
370
 export function exportExcel(exporParams, getListExpt) {
425
 export function exportExcel(exporParams, getListExpt) {
371
   return new Promise(resolve => {
426
   return new Promise(resolve => {
372
     getListExpt(exporParams).then(response => {
427
     getListExpt(exporParams).then(response => {
373
-      const headerDispostion = response.headers['content-disposition'] || response.headers['Content-Disposition'] || ''
428
+      const headerDispostion =
429
+        response.headers['content-disposition'] ||
430
+        response.headers['Content-Disposition'] ||
431
+        ''
374
       if (headerDispostion) {
432
       if (headerDispostion) {
375
         const content = response.data
433
         const content = response.data
376
         const blob = new Blob([content])
434
         const blob = new Blob([content])
377
         // let fileName = '报表数据.xls'
435
         // let fileName = '报表数据.xls'
378
         let fileName = headerDispostion.split(';')[1].split('=')[1]
436
         let fileName = headerDispostion.split(';')[1].split('=')[1]
379
         var explorer = navigator.userAgent
437
         var explorer = navigator.userAgent
380
-        if (explorer.indexOf('MSIE') >= 0 || explorer.indexOf('Chrome') >= 0) { // IE和google浏览器
438
+        if (explorer.indexOf('MSIE') >= 0 || explorer.indexOf('Chrome') >= 0) {
439
+          // IE和google浏览器
381
           fileName = decodeURIComponent(fileName)
440
           fileName = decodeURIComponent(fileName)
382
         } else {
441
         } else {
383
           fileName = decodeURI(escape(fileName))
442
           fileName = decodeURI(escape(fileName))
405
 }
464
 }
406
 
465
 
407
 /**
466
 /**
408
-     * 将一维的扁平数组转换为多层级对象
409
-     * @param  {[type]} list 一维数组,数组中每一个元素需包含id和pid两个属性
410
-     * @return {[type]} tree 多层级树状结构
411
-     */
467
+ * 将一维的扁平数组转换为多层级对象
468
+ * @param  {[type]} list 一维数组,数组中每一个元素需包含id和pid两个属性
469
+ * @return {[type]} tree 多层级树状结构
470
+ */
412
 export function buildTree(list) {
471
 export function buildTree(list) {
413
   const temp = {}
472
   const temp = {}
414
   const tree = {}
473
   const tree = {}
492
   })
551
   })
493
   return accessedRouters
552
   return accessedRouters
494
 }
553
 }
495
-

+ 96 - 28
CallCenterWeb.UI/RMYY/src/utils/request.js

4
 import store from '../store'
4
 import store from '../store'
5
 import { getToken } from '@/utils/auth'
5
 import { getToken } from '@/utils/auth'
6
 
6
 
7
+// 正在进行中的请求列表
8
+const reqList = []
9
+/**
10
+ * 阻止重复请求
11
+ * @param {array} reqList - 请求缓存列表
12
+ * @param {string} url - 当前请求地址
13
+ * @param {function} cancel - 请求中断函数
14
+ * @param {string} errorMessage - 请求中断时需要显示的错误信息
15
+ */
16
+const stopRepeatRequest = function(reqList, url, cancel, errorMessage) {
17
+  const errorMsg = errorMessage || ''
18
+  for (let i = 0; i < reqList.length; i++) {
19
+    if (reqList[i] === url) {
20
+      cancel(errorMsg)
21
+      return
22
+    }
23
+  }
24
+  reqList.push(url)
25
+}
26
+
27
+/**
28
+ * 允许某个请求可以继续进行
29
+ * @param {array} reqList 全部请求列表
30
+ * @param {string} url 请求地址
31
+ */
32
+const allowRequest = function(reqList, url) {
33
+  for (let i = 0; i < reqList.length; i++) {
34
+    if (reqList[i] === url) {
35
+      reqList.splice(i, 1)
36
+      break
37
+    }
38
+  }
39
+}
40
+
7
 // const baseURL = process.env.BASE_API
41
 // const baseURL = process.env.BASE_API
8
 // 创建axios实例
42
 // 创建axios实例
9
 const service = axios.create({
43
 const service = axios.create({
16
   // 只能用在 'PUT', 'POST' 和 'PATCH' 这几个请求方法
50
   // 只能用在 'PUT', 'POST' 和 'PATCH' 这几个请求方法
17
   // 后面数组中的函数必须返回一个字符串,或 ArrayBuffer,或 Stream
51
   // 后面数组中的函数必须返回一个字符串,或 ArrayBuffer,或 Stream
18
   // 解决axios默认发送数据时,数据格式是Request Payload的问题
52
   // 解决axios默认发送数据时,数据格式是Request Payload的问题
19
-  transformRequest: [function(data) {
20
-    // 对 data 进行任意转换处理
21
-    return qs.stringify(data)
22
-  }],
53
+  transformRequest: [
54
+    function(data) {
55
+      // 对 data 进行任意转换处理
56
+      return qs.stringify(data)
57
+    }
58
+  ],
23
 
59
 
24
   // `paramsSerializer` 是一个负责 `params` 序列化的函数
60
   // `paramsSerializer` 是一个负责 `params` 序列化的函数
25
   // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
61
   // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
28
   // return qs.stringify({ids: [1, 2, 3]}, {arrayFormat: 'brackets'})  // 形式:ids[]=1&ids[]=2&ids[]=3
64
   // return qs.stringify({ids: [1, 2, 3]}, {arrayFormat: 'brackets'})  // 形式:ids[]=1&ids[]=2&ids[]=3
29
   // return qs.stringify({ids: [1, 2, 3]}, {arrayFormat: 'repeat'})  // 形式: ids=1&ids=2&id=3
65
   // return qs.stringify({ids: [1, 2, 3]}, {arrayFormat: 'repeat'})  // 形式: ids=1&ids=2&id=3
30
   paramsSerializer: function(params) {
66
   paramsSerializer: function(params) {
31
-      return qs.stringify(params, {arrayFormat: 'repeat'})    // 形式:ids=1&ids=2&id=3
32
-  },
33
-
67
+    return qs.stringify(params, { arrayFormat: 'repeat' }) // 形式:ids=1&ids=2&id=3
68
+  }
34
 })
69
 })
35
 // request拦截器
70
 // request拦截器
36
-service.interceptors.request.use(config => {
37
-  if (store.getters.token) {
38
-    config.headers['Authorization'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
71
+service.interceptors.request.use(
72
+  config => {
73
+    if (store.getters.token) {
74
+      config.headers['Authorization'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
75
+    }
76
+    let cancel
77
+    if (config.method === 'post') {
78
+      // 设置cancelToken对象
79
+      config.cancelToken = new axios.CancelToken(function(c) {
80
+        cancel = c
81
+      })
82
+      // 阻止重复请求。当上个请求未完成时,相同的请求不会进行
83
+      stopRepeatRequest(reqList, config.url, cancel, `${config.url} 请求被中断`)
84
+      // stopRepeatRequest(reqList, config.url, cancel, `请求被中断`)
85
+    }
86
+
87
+    return config
88
+  },
89
+  error => {
90
+    // Do something with request error
91
+    Promise.reject(error)
39
   }
92
   }
40
-  return config
41
-}, error => {
42
-  // Do something with request error
43
-  console.log(error) // for debug
44
-  Promise.reject(error)
45
-})
93
+)
46
 
94
 
47
 // respone拦截器
95
 // respone拦截器
48
 service.interceptors.response.use(
96
 service.interceptors.response.use(
49
   response => {
97
   response => {
50
     /**
98
     /**
51
-		* state为非"success"时抛错
52
-		*/
99
+     * state为非"success"时抛错
100
+     */
101
+    // 增加延迟,相同请求不得在短时间内重复发送
102
+    if (response.config.method === 'post') {
103
+      setTimeout(() => {
104
+        const replaceList = response.config.url.split('/')
105
+        const newUrl =
106
+          replaceList[replaceList.length - 2] +
107
+          '/' +
108
+          replaceList[replaceList.length - 1]
109
+        allowRequest(reqList, newUrl)
110
+      }, 1000)
111
+    }
53
     const res = response.data
112
     const res = response.data
54
-
55
     if (res.state && res.state.toLowerCase() !== 'success') {
113
     if (res.state && res.state.toLowerCase() !== 'success') {
56
       Message({
114
       Message({
57
         message: res.message,
115
         message: res.message,
59
         duration: 5 * 1000
117
         duration: 5 * 1000
60
       })
118
       })
61
       // 50008:非法的token; 50012:其他客户端登录了;  "notoken":Token 过期了
119
       // 50008:非法的token; 50012:其他客户端登录了;  "notoken":Token 过期了
62
-      if (res.state.toLowerCase() === 50008 || res.state.toLowerCase() === 50012 || res.state.toLowerCase() === 'notoken') {
63
-        MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
64
-          confirmButtonText: '重新登录',
65
-          cancelButtonText: '取消',
66
-          type: 'warning'
67
-        }).then(() => {
120
+      if (
121
+        res.state.toLowerCase() === 50008 ||
122
+        res.state.toLowerCase() === 50012 ||
123
+        res.state.toLowerCase() === 'notoken'
124
+      ) {
125
+        MessageBox.confirm(
126
+          '你已被登出,可以取消继续留在该页面,或者重新登录',
127
+          '确定登出',
128
+          {
129
+            confirmButtonText: '重新登录',
130
+            cancelButtonText: '取消',
131
+            type: 'warning'
132
+          }
133
+        ).then(() => {
68
           store.dispatch('FedLogOut').then(() => {
134
           store.dispatch('FedLogOut').then(() => {
69
             location.reload() // 为了重新实例化vue-router对象 避免bug
135
             location.reload() // 为了重新实例化vue-router对象 避免bug
70
           })
136
           })
80
   },
146
   },
81
   error => {
147
   error => {
82
     console.log('err:' + error) // for debug
148
     console.log('err:' + error) // for debug
83
-    console.log(error) // for debug
84
     if (error && error.response) {
149
     if (error && error.response) {
85
-      switch (error.response.status) { // 跨域存在获取不到状态码的情况
150
+      switch (
151
+        error.response.status // 跨域存在获取不到状态码的情况
152
+      ) {
86
         case 400:
153
         case 400:
87
           error.message = `请求错误(400):${error.response.config.url}`
154
           error.message = `请求错误(400):${error.response.config.url}`
88
           break
155
           break
134
           error.message = `连接错误:${error.response.status}`
201
           error.message = `连接错误:${error.response.status}`
135
           break
202
           break
136
       }
203
       }
204
+    } else if (error.message.indexOf('请求被中断') !== -1) {
205
+      error.message = '请勿重复请求!'
137
     } else {
206
     } else {
138
       error.message = '网络出现问题,请稍后重试!'
207
       error.message = '网络出现问题,请稍后重试!'
139
     }
208
     }
140
-
141
     Message({
209
     Message({
142
       message: error.message,
210
       message: error.message,
143
       type: 'error',
211
       type: 'error',