Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b71200cb97 |
@@ -1,92 +1,92 @@
|
|||||||
import config from './config'
|
import config from './config'
|
||||||
import Qs from 'qs'
|
import Qs from 'qs'
|
||||||
let arr = []
|
let arr = []
|
||||||
export default (options = {}) => {
|
export default (options = {}) => {
|
||||||
if (options.data == undefined) {
|
if (options.data == undefined) {
|
||||||
options.data = {}
|
options.data = {}
|
||||||
}
|
}
|
||||||
options.debounce = options.debounce === undefined ? true : options.debounce
|
options.debounce = options.debounce === undefined ? true : options.debounce
|
||||||
// 防止接口重复点击
|
// 防止接口重复点击
|
||||||
if (options.debounce) {
|
if (options.debounce) {
|
||||||
if (arr.indexOf(options.url) === -1) {
|
if (arr.indexOf(options.url) === -1) {
|
||||||
arr.push(options.url)
|
arr.push(options.url)
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
reject({
|
reject({
|
||||||
code: -1,
|
code: -1,
|
||||||
msg: '请勿重复提交',
|
msg: '请勿重复提交',
|
||||||
data: options.url,
|
data: options.url,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Promise((reslove, reject) => {
|
return new Promise((reslove, reject) => {
|
||||||
let url = options.url.indexOf('http') === -1 ? config.domain + options.url : options.url
|
let url = options.url.indexOf('http') === -1 ? config.domain + options.url : options.url
|
||||||
if (options.params) {
|
if (options.params) {
|
||||||
url = url + '?' + Qs.stringify(options.params)
|
url = url + '?' + Qs.stringify(options.params)
|
||||||
}
|
}
|
||||||
uni.request({
|
uni.request({
|
||||||
url,
|
url,
|
||||||
timeout: 1000 *10,
|
timeout: 1000 *30,
|
||||||
data: {
|
data: {
|
||||||
...options.data,
|
...options.data,
|
||||||
},
|
},
|
||||||
header: {
|
header: {
|
||||||
// 'Content-Type': 'application/json;charset=UTF-8',
|
// 'Content-Type': 'application/json;charset=UTF-8',
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||||
Authorization: uni.getStorageSync('access_token'),
|
Authorization: uni.getStorageSync('access_token'),
|
||||||
...options.header,
|
...options.header,
|
||||||
},
|
},
|
||||||
method: options.method || 'GET',
|
method: options.method || 'GET',
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
if (arr.indexOf(options.url) > -1) {
|
if (arr.indexOf(options.url) > -1) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
arr.splice(arr.indexOf(options.url), 1)
|
arr.splice(arr.indexOf(options.url), 1)
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
if (res.data.resultCode !== 10000 && res.data.code !== 'A0000') {
|
if (res.data.resultCode !== 10000 && res.data.code !== 'A0000') {
|
||||||
errHandler(res.data)
|
errHandler(res.data)
|
||||||
reject(res.data)
|
reject(res.data)
|
||||||
} else {
|
} else {
|
||||||
reslove(res.data)
|
reslove(res.data)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
if (arr.indexOf(options.url) > -1) {
|
if (arr.indexOf(options.url) > -1) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
arr.splice(arr.indexOf(options.url), 1)
|
arr.splice(arr.indexOf(options.url), 1)
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
reject(err)
|
reject(err)
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
title: '网络异常,请稍后再试',
|
title: '网络异常,请稍后再试',
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误处理
|
* 错误处理
|
||||||
* @param {Number} code 错误码
|
* @param {Number} code 错误码
|
||||||
*/
|
*/
|
||||||
function errHandler(res) {
|
function errHandler(res) {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
switch (res.code) {
|
switch (res.code) {
|
||||||
case 'A0024':
|
case 'A0024':
|
||||||
uni.reLaunch({ url: '/pages/user/login' })
|
uni.reLaunch({ url: '/pages/user/login' })
|
||||||
break
|
break
|
||||||
case 'A0202':
|
case 'A0202':
|
||||||
uni.reLaunch({ url: '/pages/user/login' })
|
uni.reLaunch({ url: '/pages/user/login' })
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res.message || res.msg || '网络异常,请稍后再试',
|
title: res.message || res.msg || '网络异常,请稍后再试',
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,21 @@ function getToday() {
|
|||||||
const day = String(today.getDate()).padStart(2, '0');
|
const day = String(today.getDate()).padStart(2, '0');
|
||||||
return `${year}-${month}-${day}`;
|
return `${year}-${month}-${day}`;
|
||||||
}
|
}
|
||||||
|
// 获取当天日期 往前推30天
|
||||||
|
function getBeforeDays(days = 30) {
|
||||||
|
const today = new Date();
|
||||||
|
// 计算往前推N天的时间戳(1天=86400000毫秒)
|
||||||
|
const beforeDate = new Date(today.getTime() - days * 24 * 60 * 60 * 1000);
|
||||||
|
return formatDate(beforeDate);
|
||||||
|
}
|
||||||
|
function formatDate(date) {
|
||||||
|
const year = date.getFullYear();
|
||||||
|
// 月份从0开始,补零到2位
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
// 日期补零到2位
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
}
|
||||||
|
|
||||||
// 获取3个月前的日期
|
// 获取3个月前的日期
|
||||||
function getThreeMonthsAgo() {
|
function getThreeMonthsAgo() {
|
||||||
@@ -317,5 +332,6 @@ export default {
|
|||||||
refreshPrePage,
|
refreshPrePage,
|
||||||
getDictData,
|
getDictData,
|
||||||
getToday,
|
getToday,
|
||||||
|
getBeforeDays,
|
||||||
getThreeMonthsAgo
|
getThreeMonthsAgo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
"/api" : {
|
"/api" : {
|
||||||
"https" : true,
|
"https" : true,
|
||||||
"target" : "https://pqmcn.com:8092/api",
|
"target" : "https://pqmcn.com:8092/api",
|
||||||
// "target" : "http://192.168.1.62:10215",
|
// "target" : "http://192.168.1.103:10215",
|
||||||
"changOrigin" : true,
|
"changOrigin" : true,
|
||||||
"pathRewrite" : {
|
"pathRewrite" : {
|
||||||
"/api" : ""
|
"/api" : ""
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -112,7 +112,7 @@ export default {
|
|||||||
this.store = this.DataSource('/cs-harmonic-boot/eventUser/queryEventpage')
|
this.store = this.DataSource('/cs-harmonic-boot/eventUser/queryEventpage')
|
||||||
this.store.params.type = this.type
|
this.store.params.type = this.type
|
||||||
this.store.params.deviceId = this.deviceId
|
this.store.params.deviceId = this.deviceId
|
||||||
this.store.params.startTime = this.$util.getThreeMonthsAgo()
|
this.store.params.startTime = this.$util.getBeforeDays()
|
||||||
this.store.params.endTime = this.$util.getToday()
|
this.store.params.endTime = this.$util.getToday()
|
||||||
this.store.loadedCallback = () => {
|
this.store.loadedCallback = () => {
|
||||||
this.store.data.forEach((item) => {
|
this.store.data.forEach((item) => {
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export default {
|
|||||||
console.log(dictData)
|
console.log(dictData)
|
||||||
this.store = this.DataSource('/cs-harmonic-boot/eventUser/queryEventpage')
|
this.store = this.DataSource('/cs-harmonic-boot/eventUser/queryEventpage')
|
||||||
this.store.params.type = this.type
|
this.store.params.type = this.type
|
||||||
this.store.params.startTime = this.$util.getThreeMonthsAgo()
|
this.store.params.startTime = this.$util.getBeforeDays()
|
||||||
this.store.params.endTime = this.$util.getToday()
|
this.store.params.endTime = this.$util.getToday()
|
||||||
this.store.loadedCallback = () => {
|
this.store.loadedCallback = () => {
|
||||||
console.log(111, this.store.data)
|
console.log(111, this.store.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user