Skip to content

Commit d41394c

Browse files
authored
fix:修复首页 dashboard echarts 页面变化导致的变性, 修复 vite.config.js 中 proxy 代理 https 时的 bug (#1623)
add : 添加 “@vueuse/core” 的依赖,添加全局 hooks (use-windows-resize)使用方法查看 dashboard 页面
1 parent 756f73b commit d41394c

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@vue-office/docx": "^1.3.0",
1515
"@vue-office/excel": "^1.4.5",
1616
"@vue-office/pdf": "^1.5.3",
17+
"@vueuse/core": "^10.7.2",
1718
"@wangeditor/editor": "^5.1.23",
1819
"@wangeditor/editor-for-vue": "^5.1.12",
1920
"axios": "^1.4.0",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 监听 window 的 resize 事件,返回当前窗口的宽高
2+
import { shallowRef } from 'vue'
3+
import { tryOnMounted, useEventListener } from '@vueuse/core'
4+
5+
const width = shallowRef(0)
6+
const height = shallowRef(0)
7+
8+
export const useWindowResize = (cb) => {
9+
const onResize = () => {
10+
width.value = window.innerWidth
11+
height.value = window.innerHeight
12+
if (cb && typeof cb === 'function') {
13+
cb(width.value, height.value)
14+
}
15+
}
16+
17+
tryOnMounted(onResize)
18+
useEventListener('resize', onResize, { passive: true })
19+
return {
20+
width,
21+
height,
22+
}
23+
}

web/src/view/dashboard/dashboardCharts/echartsLine.vue

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
</template>
1212
<script setup>
1313
import * as echarts from 'echarts'
14-
import { nextTick, onMounted, onUnmounted, ref, shallowRef } from 'vue'
15-
// import 'echarts/theme/macarons'
16-
14+
import { nextTick, onMounted, onUnmounted, ref } from 'vue'
15+
import { useWindowResize } from '@/hooks/use-windows-resize'
1716
var dataAxis = []
1817
for (var i = 1; i < 13; i++) {
1918
dataAxis.push(`${i}`)
@@ -35,19 +34,29 @@ var data = [
3534
var yMax = 500
3635
var dataShadow = []
3736
38-
// eslint-disable-next-line no-redeclare
39-
for (var i = 0; i < data.length; i++) {
37+
for (let i = 0; i < data.length; i++) {
4038
dataShadow.push(yMax)
4139
}
4240
43-
const chart = shallowRef(null)
41+
let chart = null
4442
const echart = ref(null)
43+
44+
useWindowResize(() => {
45+
if (!chart) {
46+
return
47+
}
48+
chart.resize()
49+
})
50+
4551
const initChart = () => {
46-
chart.value = echarts.init(echart.value /* 'macarons' */)
52+
if (chart) {
53+
chart = null
54+
}
55+
chart = echarts.init(echart.value)
4756
setOptions()
4857
}
4958
const setOptions = () => {
50-
chart.value.setOption({
59+
chart.setOption({
5160
grid: {
5261
left: '40',
5362
right: '20',
@@ -107,11 +116,11 @@ onMounted(async() => {
107116
})
108117
109118
onUnmounted(() => {
110-
if (!chart.value) {
119+
if (!chart) {
111120
return
112121
}
113-
chart.value.dispose()
114-
chart.value = null
122+
chart.dispose()
123+
chart = null
115124
})
116125
</script>
117126
<style lang="scss" scoped>

web/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default ({
6666
// detail: https://cli.vuejs.org/config/#devserver-proxy
6767
[process.env.VITE_BASE_API]: { // 需要代理的路径 例如 '/api'
6868
target: `${process.env.VITE_BASE_PATH}:${process.env.VITE_SERVER_PORT}/`, // 代理到 目标路径
69-
changeOrigin: false,
69+
changeOrigin: true,
7070
rewrite: path => path.replace(new RegExp('^' + process.env.VITE_BASE_API), ''),
7171
}
7272
},

0 commit comments

Comments
 (0)