From 67aa5264efe3a6f56393ade0c973ef6a564dd82a Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 20 Jun 2024 18:31:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 19 ++++++------- package.json | 1 + src/main.js | 4 +++ src/utils/fetch.js | 41 ++++++++++++++++++++++++++++ src/views/AppStoresTable.vue | 52 ++++++++++++++++++++++++++++-------- vite.config.js | 8 +++++- 6 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 src/utils/fetch.js diff --git a/index.html b/index.html index 030a6ff..7447130 100644 --- a/index.html +++ b/index.html @@ -1,13 +1,14 @@ - - - - + + + + Vite App - - -
- - + + +
+ + + diff --git a/package.json b/package.json index fa1713c..78325ee 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "preview": "vite preview --port 4173" }, "dependencies": { + "axios": "^1.7.2", "element-ui": "^2.15.14", "vue": "^2.7.7", "vue-router": "^3.5.4" diff --git a/src/main.js b/src/main.js index 2029a4f..2986f2e 100644 --- a/src/main.js +++ b/src/main.js @@ -4,8 +4,12 @@ import router from './router' import './assets/main.css' import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; +import axios from 'axios' Vue.use(ElementUI); + +window.axios = axios +window.$glob = {} new Vue({ router, render: (h) => h(App) diff --git a/src/utils/fetch.js b/src/utils/fetch.js new file mode 100644 index 0000000..bc27044 --- /dev/null +++ b/src/utils/fetch.js @@ -0,0 +1,41 @@ +const {axios, $glob} = window + +let getAuthing = false +const getToken = () => { + getAuthing = true + return axios.post("http://10.0.97.209/data-boot/na/sys/login", { + t: Date.now(), + userAcc: "kengee", + password: "kengee@123", + uuid: "", + captcha: "" + }).then(res => { + if (res?.data?.data) { + $glob.token = res.data.data.token + } + }).finally(() => getAuthing = false) +} +const http = axios.create({baseURL: '/'}) +const addToken = (config) => { + config.headers['h-token'] = $glob.token + return config +} +window.$wait = (t = 500) => new Promise(resolve => setTimeout(resolve, t)) +http.interceptors.request.use(async config => { + while (getAuthing) { + await $wait() + } + if (!$glob.token && !getAuthing) { + await getToken() + } + return addToken(config) +}) +http.interceptors.response.use(res => { + if (res?.data) { + return res.data + } else if (res?.code == 401) { + return getToken().then(() => http.request(res.config)) + } + return res +}) +window.$http = http diff --git a/src/views/AppStoresTable.vue b/src/views/AppStoresTable.vue index d8c77d4..62613a9 100644 --- a/src/views/AppStoresTable.vue +++ b/src/views/AppStoresTable.vue @@ -39,6 +39,9 @@ export default { return { height: '600px', stores: [], + cameras: [], + storeKeyGoods: [], + categorySales: [], columns: { 品类销售情况: [ {label: "品类", prop: "secondCategoryName"}, @@ -60,6 +63,7 @@ export default { } }, computed: { + refs: v => v.$parent.getItemRefs(), storeList: v => { const list = [] let group = [] @@ -77,22 +81,48 @@ export default { }, methods: { getData() { - const refs = this.$parent.getItemRefs(); - const cameras = refs['c82d439e-a316-4d0e-8792-d2513a950f11'].dataChart - const storeKeyGoods = refs['6f6e3050-b084-4694-83c0-0d351346f426'].dataChart - const categorySales = refs['58fd4d5f-2ac3-444c-8a2c-361b8c8c3e6e'].dataChart - this.stores = JSON.parse(window.$glob.stores || "[]").map(store => { - const cameraStore = cameras.find(e => e.storeCode == store) + this.stores = this.stores.map(store => { + const cameraStore = this.cameras.find(e => e.storeCode == store) const {storeName = "仟吉门店", storeCameraVOList: camera = []} = cameraStore - const keyGoods = storeKeyGoods.filter(e => e.storeCode == store) - const categorySale = categorySales.filter(e => e.storeCode == store) + const keyGoods = this.storeKeyGoods.filter(e => e.storeCode == store) + const categorySale = this.categorySales.filter(e => e.storeCode == store) return {storeName, camera: camera.map(e => e.url), keyGoods, categorySale} }) - } + }, + getCameras() { + return $http.post("/api/store/camera/list", { + storeCodes: this.stores + }).then(res => { + if (res?.data) { + this.cameras = res.data?.records || [] + } + }) + }, + getStoreKeyGoods() { + return $http.post("/api/store/camera/list", { + storeCodes: this.stores + }).then(res => { + if (res?.data) { + this.storeKeyGoods = res.data + } + }) + }, + getCategorySales() { + return $http.post("/api/store/camera/list", { + storeCodes: this.stores + }).then(res => { + if (res?.data) { + this.categorySales = res.data + } + }) + }, + }, - mounted() { + async mounted() { this.height = `${this.$el.clientHeight}px` - this.getData() + this.stores = JSON.parse(window.$glob.stores || "[]") + while (!$http) await $wait() + Promise.all([this.getCameras(), this.getStoreKeyGoods(), this.getCategorySales()]).then(() => this.getData()) } } diff --git a/vite.config.js b/vite.config.js index 8253658..56fc56c 100644 --- a/vite.config.js +++ b/vite.config.js @@ -21,6 +21,12 @@ export default defineConfig({ } }, server: { - port: 9000 + port: 9000, + proxy: { + '/api': { + target: 'http://10.0.97.209', + changeOrigin: true, + } + } } })