This commit is contained in:
aixianling
2024-06-20 18:31:15 +08:00
parent 36c4466f09
commit 67aa5264ef
6 changed files with 104 additions and 21 deletions

View File

@@ -1,13 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<head>
<meta charset="UTF-8"/>
<link rel="icon" href="/favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

View File

@@ -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"

View File

@@ -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)

41
src/utils/fetch.js Normal file
View File

@@ -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

View File

@@ -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())
}
}
</script>

View File

@@ -21,6 +21,12 @@ export default defineConfig({
}
},
server: {
port: 9000
port: 9000,
proxy: {
'/api': {
target: 'http://10.0.97.209',
changeOrigin: true,
}
}
}
})