修复异常

This commit is contained in:
aixianling
2024-06-21 15:59:59 +08:00
parent 4cb1d29054
commit bdff7b020f
3 changed files with 46 additions and 28 deletions

View File

@@ -1,6 +1,5 @@
const init = () => new Promise(resolve => { const init = () => new Promise(resolve => {
const {axios, $glob} = window const {axios, $glob} = window
let getAuthing = false let getAuthing = false
const getToken = () => { const getToken = () => {
getAuthing = true getAuthing = true
@@ -21,11 +20,20 @@ const init = () => new Promise(resolve => {
config.headers['h-token'] = $glob.token config.headers['h-token'] = $glob.token
return config return config
} }
window.$wait = (t = 500) => new Promise(resolve => setTimeout(resolve, t)) window.$waitFor = (target, t = 500) => new Promise(resolve => {
http.interceptors.request.use(async config => { const interval = setInterval(() => {
while (getAuthing) { if (target) {
await $wait() clearInterval(interval)
resolve(target)
}
}, t)
if (target) {
clearInterval(interval)
resolve(target)
} }
})
http.interceptors.request.use(async config => {
await $waitFor(!getAuthing)
if (!$glob.token && !getAuthing) { if (!$glob.token && !getAuthing) {
await getToken() await getToken()
} }
@@ -33,6 +41,9 @@ const init = () => new Promise(resolve => {
}) })
http.interceptors.response.use(res => { http.interceptors.response.use(res => {
if (res?.data) { if (res?.data) {
if (res.data?.code == 6004) {
return getToken().then(() => http.request(res.config))
}
return res.data return res.data
} else if (res?.code == 401) { } else if (res?.code == 401) {
return getToken().then(() => http.request(res.config)) return getToken().then(() => http.request(res.config))
@@ -42,4 +53,4 @@ const init = () => new Promise(resolve => {
window.$http = http window.$http = http
resolve() resolve()
}) })
await init() export default init()

View File

@@ -1,4 +1,5 @@
<script> <script>
const {groupCodeList = ["20010073"]} = window?.$glob?.params || {}
export default { export default {
name: "AppStoresTable", name: "AppStoresTable",
label: "多店监控", label: "多店监控",
@@ -38,6 +39,11 @@ export default {
data() { data() {
return { return {
height: '600px', height: '600px',
search: {
type: '1',
categoryId: '104',
hourNum: "12"
},
stores: [], stores: [],
cameras: [], cameras: [],
storeKeyGoods: [], storeKeyGoods: [],
@@ -81,26 +87,24 @@ export default {
}, },
methods: { methods: {
getData() { getData() {
this.stores = this.stores.map(store => { this.stores = this.stores.map(({storeName, storeCode, storeCameraVOList = []}) => {
const cameraStore = this.cameras.find(e => e.storeCode == store) const keyGoods = this.storeKeyGoods.filter(e => e.storeCode == storeCode)
const {storeName = "仟吉门店", storeCameraVOList: camera = []} = cameraStore const categorySale = this.categorySales.filter(e => e.storeCode == storeCode)
const keyGoods = this.storeKeyGoods.filter(e => e.storeCode == store) return {storeCode, storeName, camera: storeCameraVOList.map(e => e.url), keyGoods, categorySale}
const categorySale = this.categorySales.filter(e => e.storeCode == store)
return {storeName, camera: camera.map(e => e.url), keyGoods, categorySale}
}) })
}, },
getCameras() { getCameras() {
return $http.post("/api/store/camera/list", { return $http.post("/data-boot/la/screen/multipleStoreBoard/storeCamera", {
storeCodes: this.stores ...this.search, groupCodeList
}).then(res => { }).then(res => {
if (res?.data) { if (res?.data) {
this.cameras = res.data?.records || [] this.stores = res.data?.records || []
} }
}) })
}, },
getStoreKeyGoods() { getStoreKeyGoods() {
return $http.post("/api/store/camera/list", { return $http.post("/data-boot/la/screen/multipleStoreBoard/storeKeyGoods", {
storeCodes: this.stores ...this.search, groupCodeList
}).then(res => { }).then(res => {
if (res?.data) { if (res?.data) {
this.storeKeyGoods = res.data this.storeKeyGoods = res.data
@@ -108,21 +112,25 @@ export default {
}) })
}, },
getCategorySales() { getCategorySales() {
return $http.post("/api/store/camera/list", { return $http.post("/data-boot/la/screen/multipleStoreBoard/categorySale", {
storeCodes: this.stores ...this.search, groupCodeList
}).then(res => { }).then(res => {
if (res?.data) { if (res?.data) {
this.categorySales = res.data this.categorySales = res.data
} }
}) })
}, },
gotoDetail(store) {
$glob.query = {storeCode: store.storeCode}
$glob.group = "9f299712-5549-413b-a93b-7c3e3b5bfadb"
},
}, },
async mounted() { mounted() {
this.height = `${this.$el.clientHeight}px` this.height = `${this.$el.clientHeight}px`
this.stores = JSON.parse(window.$glob.stores || "[]") setTimeout(() => {
while (!$http) await $wait() const {$http, $waitFor} = window
Promise.all([this.getCameras(), this.getStoreKeyGoods(), this.getCategorySales()]).then(() => this.getData()) $waitFor($http).then(() => Promise.all([this.getCameras(), this.getStoreKeyGoods(), this.getCategorySales()])).then(() => this.getData())
}, 2000)
} }
} }
</script> </script>
@@ -132,8 +140,8 @@ export default {
<el-carousel indicator-position="none" :height="height" :autoplay="false"> <el-carousel indicator-position="none" :height="height" :autoplay="false">
<el-carousel-item v-for="(group,i) in storeList" :key="i"> <el-carousel-item v-for="(group,i) in storeList" :key="i">
<div class="layout"> <div class="layout">
<div class="store" v-for="store in group" :key="store.id"> <div class="store" v-for="store in group" :key="store.storeCode">
<div class="header" v-text="store.storeName"/> <div class="header" v-text="store.storeName" @click="gotoDetail(store)"/>
<el-carousel indicator-position="none" height="250px"> <el-carousel indicator-position="none" height="250px">
<el-carousel-item v-for="(url,j) in store.camera" :key="[i,j].join('_')"> <el-carousel-item v-for="(url,j) in store.camera" :key="[i,j].join('_')">
<hls-player :url="url"/> <hls-player :url="url"/>
@@ -156,7 +164,6 @@ export default {
</div> </div>
</el-carousel-item> </el-carousel-item>
</el-carousel> </el-carousel>
</section> </section>
</template> </template>

View File

@@ -23,7 +23,7 @@ export default defineConfig({
server: { server: {
port: 9000, port: 9000,
proxy: { proxy: {
'/api': { '/data-boot': {
target: 'http://10.0.97.209', target: 'http://10.0.97.209',
changeOrigin: true, changeOrigin: true,
} }