feat:对接首页数据

This commit is contained in:
zjc
2025-03-11 16:02:49 +08:00
parent a63ace50c4
commit 999d99b68c
5 changed files with 79 additions and 16 deletions

58
__unconfig_vite.config.js Normal file
View File

@@ -0,0 +1,58 @@
let __unconfig_data;
let __unconfig_stub = function (data = {}) { __unconfig_data = data };
__unconfig_stub.default = (data = {}) => { __unconfig_data = data };
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
const __unconfig_default = defineConfig({
plugins: [
vue(),
vueJsx(),
AutoImport({
imports: ['vue'],
dts: 'src/auto-import.d.ts',
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver()]
})
// vueDevTools(),
],
base: '/largeScreen/',
server: {
hmr: true,
host: '0.0.0.0'
// proxy: {
// '/': {
// // 目标服务器的地址
// target: 'http://36.138.38.16:8001',
// changeOrigin: true
// }
// }
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
extensions: ['.js', '.vue']
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "@/styles/screen.scss" as *;',
javascriptEnabled: true
}
}
}
})
if (typeof __unconfig_default === "function") __unconfig_default(...[{"command":"serve","mode":"development"}]);export default __unconfig_data;

View File

@@ -3,21 +3,21 @@ import * as echarts from 'echarts'
import { guid } from '@/utils/util' import { guid } from '@/utils/util'
export function useEchart() { export function useEchart() {
let chart = ref(null) let chart = null
let id = ref(guid()) let id = ref(guid())
const initChart = () => { const initChart = () => {
const dom = document.getElementById(id.value) const dom = document.getElementById(id.value)
chart.value = echarts.init(dom) chart = echarts.init(dom)
} }
const setOption = (params, update = false) => { const setOption = (params, update = false) => {
chart.value.setOption(params, update) chart.setOption(params, update)
} }
const dispose = () => { const dispose = () => {
chart.value.dispose() chart.dispose()
chart.value = null chart = null
} }
const resize = () => { const resize = () => {
chart.value.resize() if (chart) chart.resize()
} }
onMounted(() => { onMounted(() => {
initChart() initChart()

View File

@@ -34,7 +34,7 @@
return props.list.map((item) => { return props.list.map((item) => {
return { return {
...item, ...item,
value: item.occupiedPercentage, value: item.occupiedSpaces,
itemStyle: { itemStyle: {
color: { color: {
type: 'linear', type: 'linear',
@@ -61,7 +61,7 @@
return props.list.map((item) => { return props.list.map((item) => {
return { return {
...item, ...item,
value: item.occupiedPercentage, value: item.occupiedSpaces,
itemStyle: { itemStyle: {
color: '#fff', color: '#fff',
opacity: 1 opacity: 1
@@ -70,7 +70,7 @@
}) })
} }
const getYAxisData = () => { const getYAxisData = () => {
return props.list.map((item) => item.occupied) return props.list.map((item) => item.occupiedSpaces)
} }
const init = () => { const init = () => {
if (!params) { if (!params) {
@@ -91,22 +91,23 @@
}, },
xAxis: [ xAxis: [
{ {
type: 'value',
max: 100,
show: false,
splitLine: { splitLine: {
show: false show: false
}, }
type: 'value',
show: false
} }
], ],
yAxis: [ yAxis: [
{ {
type: 'category',
splitLine: { splitLine: {
show: false show: false
}, },
axisLine: { axisLine: {
show: false show: false
}, },
type: 'category',
axisTick: { axisTick: {
show: false show: false
}, },
@@ -146,6 +147,7 @@
{ {
name: '', name: '',
type: 'bar', type: 'bar',
max: 100,
barWidth: fitChartSize(8), barWidth: fitChartSize(8),
showBackground: true, showBackground: true,
borderRadius: [0, 0, 0, 0], borderRadius: [0, 0, 0, 0],

View File

@@ -38,6 +38,7 @@
() => dataRes.value, () => dataRes.value,
(val) => { (val) => {
if (val) { if (val) {
console.log(val, '首页接受数据')
switch (val.type) { switch (val.type) {
case 'userPortrait': case 'userPortrait':
homeStore.setUserPortraitData(val.data) homeStore.setUserPortraitData(val.data)

View File

@@ -98,10 +98,12 @@
} }
watch( watch(
() => [props.dataList, chart.value], () => props.dataList,
() => { () => {
if (props.dataList.length > 0 && chart.value) { if (props.dataList.length > 0) {
init() setTimeout(() => {
init()
}, 1000)
} }
}, },
{ immediate: true } { immediate: true }