|
|
|
@ -31,9 +31,7 @@ export default { |
|
|
|
props: { |
|
|
|
isSelfService: { |
|
|
|
type: Boolean, |
|
|
|
default: function() { |
|
|
|
return false |
|
|
|
} |
|
|
|
default: false |
|
|
|
} |
|
|
|
}, |
|
|
|
data() { |
|
|
|
@ -43,70 +41,87 @@ export default { |
|
|
|
dayOutNum: 0, |
|
|
|
monthNum: 0, |
|
|
|
totalNum: 0, |
|
|
|
otherDoorOther: null |
|
|
|
otherDoorOther: null, |
|
|
|
abortController: null, |
|
|
|
isPageHide: false |
|
|
|
} |
|
|
|
}, |
|
|
|
created() { |
|
|
|
// 获取数据 |
|
|
|
this.getInitIntoNum() |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
// 每15秒获取一次 |
|
|
|
document.addEventListener('visibilitychange', this.handleVisibility) |
|
|
|
this.startPoll() |
|
|
|
}, |
|
|
|
beforeDestroy() { |
|
|
|
this.stopPoll() |
|
|
|
if (this.abortController) { |
|
|
|
this.abortController.abort() |
|
|
|
} |
|
|
|
document.removeEventListener('visibilitychange', this.handleVisibility) |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
handleVisibility() { |
|
|
|
this.isPageHide = document.hidden |
|
|
|
if (this.isPageHide) { |
|
|
|
this.stopPoll() |
|
|
|
} else { |
|
|
|
this.startPoll() |
|
|
|
} |
|
|
|
}, |
|
|
|
startPoll() { |
|
|
|
this.stopPoll() |
|
|
|
this.timer = setInterval(() => { |
|
|
|
this.getInitIntoNum() |
|
|
|
}, 15000) |
|
|
|
}, |
|
|
|
beforeDestroy() { |
|
|
|
// 销毁定时器 |
|
|
|
this.$once('hook:beforeDestroy', () => { |
|
|
|
stopPoll() { |
|
|
|
if (this.timer) { |
|
|
|
clearInterval(this.timer) |
|
|
|
}) |
|
|
|
this.timer = null |
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
getInitIntoNum() { |
|
|
|
// http://192.168.99.118:8080/#/?doorCodes=D001&D002&D007&startTime=2023-01-01&endTime=2023-08-31 |
|
|
|
// this.otherDoorOther = window.location.href.split('?')[1]?.split('=')[1] |
|
|
|
const currentURL = window.location.href |
|
|
|
console.log(currentURL) |
|
|
|
if (currentURL.indexOf('?') !== -1) { |
|
|
|
const query = currentURL.split('?')[1] |
|
|
|
console.log(query) |
|
|
|
console.log(query.indexOf('startTime')) |
|
|
|
if (query.indexOf('startTime') !== -1 || query.indexOf('endTime') !== -1) { |
|
|
|
const paramsUrl = query.split('&') |
|
|
|
console.log(paramsUrl) |
|
|
|
let startTimeIndex = -1 |
|
|
|
for (let i = 0; i < paramsUrl.length; i++) { |
|
|
|
const [key] = paramsUrl[i].split('=') |
|
|
|
if (key === 'startTime' || key === 'endTime') { |
|
|
|
startTimeIndex = i |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
// 去除 startTime 参数及其后面的参数 |
|
|
|
const filteredParams = startTimeIndex >= 0 ? paramsUrl.slice(0, startTimeIndex) : params |
|
|
|
const newQueryString = filteredParams.join('&') |
|
|
|
this.otherDoorOther = newQueryString.split('=')[1] |
|
|
|
} else { |
|
|
|
this.otherDoorOther = query.split('=')[1] |
|
|
|
// 【修复】hash模式,#?后面的参数串 |
|
|
|
const fullUrl = window.location.href |
|
|
|
const hashContent = fullUrl.split('#')[1] || '' |
|
|
|
let queryStr = '' |
|
|
|
if (hashContent.includes('?')) { |
|
|
|
queryStr = hashContent.split('?')[1] |
|
|
|
} |
|
|
|
console.log('queryStr', queryStr) |
|
|
|
|
|
|
|
let otherDoorOther = null |
|
|
|
if (queryStr) { |
|
|
|
// 找到 &startTime= / &endTime= 的位置,在此截断,前面全部属于doorCodes值 |
|
|
|
let cutIndex = Infinity |
|
|
|
const markers = ['&startTime=', '&endTime='] |
|
|
|
for (const m of markers) { |
|
|
|
const idx = queryStr.indexOf(m) |
|
|
|
if (idx !== -1 && idx < cutIndex) { |
|
|
|
cutIndex = idx |
|
|
|
} |
|
|
|
} |
|
|
|
let doorCodesRaw |
|
|
|
if (cutIndex !== Infinity) { |
|
|
|
doorCodesRaw = queryStr.substring(0, cutIndex) |
|
|
|
} else { |
|
|
|
this.otherDoorOther = null |
|
|
|
doorCodesRaw = queryStr |
|
|
|
} |
|
|
|
// 去掉 doorCodes= 前缀 |
|
|
|
if (doorCodesRaw.startsWith('doorCodes=')) { |
|
|
|
doorCodesRaw = doorCodesRaw.replace('doorCodes=', '') |
|
|
|
} |
|
|
|
if (doorCodesRaw) { |
|
|
|
otherDoorOther = doorCodesRaw.replace(/&/g, '、') |
|
|
|
} |
|
|
|
} |
|
|
|
this.otherDoorOther = otherDoorOther |
|
|
|
console.log('otherDoorOther', otherDoorOther) |
|
|
|
|
|
|
|
const startTime = this.$route.query.startTime |
|
|
|
const endTime = this.$route.query.endTime |
|
|
|
|
|
|
|
console.log('otherDoorOther', this.otherDoorOther) |
|
|
|
|
|
|
|
if (this.otherDoorOther && this.otherDoorOther !== '' && this.otherDoorOther.indexOf('&')) { |
|
|
|
this.otherDoorOther = this.otherDoorOther.replace(/\&/g, '、') |
|
|
|
} else { |
|
|
|
this.otherDoorOther = null |
|
|
|
} |
|
|
|
|
|
|
|
console.log('otherDoorOther2', this.otherDoorOther) |
|
|
|
|
|
|
|
let params |
|
|
|
if (!this.isSelfService) { |
|
|
|
params = { |
|
|
|
@ -121,7 +136,14 @@ export default { |
|
|
|
endTime: endTime |
|
|
|
} |
|
|
|
} |
|
|
|
FetchInitIntoNum(params).then((res) => { |
|
|
|
|
|
|
|
// 增加请求取消(如果你的axios封装支持signal就打开,不支持注释掉abort相关) |
|
|
|
if (this.abortController) this.abortController.abort() |
|
|
|
this.abortController = new AbortController() |
|
|
|
|
|
|
|
FetchInitIntoNum(params, { |
|
|
|
signal: this.abortController?.signal |
|
|
|
}).then((res) => { |
|
|
|
if (res.errCode === 0) { |
|
|
|
this.dayNum = res.data.dayPeopleNum |
|
|
|
this.monthNum = res.data.monthPeopleNum |
|
|
|
@ -130,6 +152,11 @@ export default { |
|
|
|
} else { |
|
|
|
this.$message.error('接口错误') |
|
|
|
} |
|
|
|
}).catch(err => { |
|
|
|
// abort取消的请求不弹报错 |
|
|
|
if (err.name !== 'AbortError') { |
|
|
|
console.error('进馆人数接口异常', err) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|