diff --git a/README.md b/README.md
index d83742d..14c4098 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,18 @@
## 一、项目描述
- [**React 版本请点击这里查看,全新界面超级好看!!!(o ゚ v ゚)ノ**](https://gitee.com/MTrun/react-big-screen)
-- 一个基于 vue、datav、Echart 框架的 " **数据大屏项目** ",通过 vue 组件实现数据动态刷新渲染,内部图表可实现自由替换。部分图表使用 DataV 自带组件,可进行更改,详情请点击下方 DataV 文档。
+- 一个基于 Vue、Datav、Echart 框架的 " **数据大屏项目** ",通过 Vue 组件实现数据动态刷新渲染,内部图表可实现自由替换。部分图表使用 DataV 自带组件,可进行更改,详情请点击下方 DataV 文档。
- 项目需要全屏展示(按 F11)。
-- 项目部分区域使用了全局注册方式,增加了打包体积,在实际运用中请使用**按需引入**。
+- 项目部分区域使用了全局注册方式,增加了打包体积,在实际运用中请使用 **按需引入**。
- 拉取项目之后,建议按照自己的功能区域重命名文件,现以简单的位置进行区分。
-- 项目环境:vue-cli-3.0、webpack-4.0、npm-6.13、node-v12.16。
+- 项目环境:Vue-cli-3.0、Webpack-4.0、Npm-6.13、Node-v12.16。
- 请拉取 master 分支的代码,其余是开发分支。
友情链接:
1. [Vue 官方文档](https://cn.vuejs.org/v2/guide/instance.html)
2. [DataV 官方文档](http://datav.jiaminghi.com/guide/)
-3. [echarts 实例](https://echarts.apache.org/examples/zh/index.html),[echarts API文档](https://echarts.apache.org/zh/api.html#echarts)
+3. [echarts 实例](https://echarts.apache.org/examples/zh/index.html),[echarts API 文档](https://echarts.apache.org/zh/api.html#echarts)
4. [项目 gitee 地址(国内速度快)](https://gitee.com/MTrun/big-screen-vue-datav)
项目展示
@@ -20,89 +20,91 @@
## 二、主要文件介绍
-| 文件 | 作用/功能 |
-| ------------------- | --------------------------------------------------- |
-| main.js | 主目录文件,引入Echart/DataV等文件 |
-| utils | 工具函数与 mixins 函数等 |
-| views/ index.vue | 项目主结构 |
-| views/其余文件 | 界面各个区域组件(按照位置来命名)ajax 接口请求位置 |
-| assets | 静态资源目录,放置 logo 与背景图片 |
-| assets / style.scss | 通用 CSS 文件,全局项目快捷样式调节 |
-| assets / index.scss | Index 界面的 CSS 文件 |
-| components/echart | 所有 echart 图表(按照位置来命名) |
-| common/flexible.js | flexible 插件代码(适配屏幕尺寸,定制化修改) |
+| 文件 | 作用/功能 |
+| ------------------- | --------------------------------------------------------------------- |
+| main.js | 主目录文件,引入 Echart/DataV 等文件 |
+| utils | 工具函数与 mixins 函数等 |
+| views/ index.vue | 项目主结构 |
+| views/其余文件 | 界面各个区域组件(按照位置来命名) |
+| assets | 静态资源目录,放置 logo 与背景图片 |
+| assets / style.scss | 通用 CSS 文件,全局项目快捷样式调节 |
+| assets / index.scss | Index 界面的 CSS 文件 |
+| components/echart | 所有 echart 图表(按照位置来命名) |
+| common/... | 全局封装的 ECharts 和 flexible 插件代码(适配屏幕尺寸,可定制化修改) |
## 三、使用介绍
### 启动项目
-需要提前安装好`nodejs`与`npm`,下载项目后在项目主目录下运行`npm/cnpm install`拉取依赖包,然后使用 `vue-cli` 或者直接使用命令`npm run serve`,就可以启动项目,启动项目后需要手动全屏(按 F11)。
+需要提前安装好 `nodejs` 与 `npm`,下载项目后在项目主目录下运行 `npm/cnpm install` 拉取依赖包。安装完依赖包之后然后使用 `vue-cli` 或者直接使用命令`npm run serve`,就可以启动项目,启动项目后需要手动全屏(按 F11)。如果编译项目的时候提示没有 DataV 框架的依赖,输入 `npm install @jiaminghi/data-view` 或者 `yarn add @jiaminghi/data-view` 进行手动安装。
-### 请求数据
+### 封装组件渲染图表
- 现在的项目未使用前后端数据请求,建议使用 axios 进行数据请求,在 main.js 位置进行全局配置,在 views/xx.vue 文件里进行前后端数据请求。
+所有的 ECharts 图表都是基于 `common/echart/index.vue` 封装组件创建的,已经对数据和屏幕改动进行了监听,能够动态渲染图表数据和大小。在监听窗口小大的模块,使用了节流函数来节约浏览器性能。
-- axios 的 main.js 配置参考范例(因人而异)
+项目配置了默认的 ECharts 图表样式,文件地址:`common/echart/theme.json`。
-```js
-import axios from 'axios';
+封装的渲染图表组件支持传入以下参数,可根据业务需求自行添加/删除。
-//把方法放到vue的原型上,这样就可以全局使用了
-Vue.prototype.$http = axios.create({
- //设置20秒超时时间
- timeout: 20000,
- baseURL: 'http://172.0.0.1:80080', //这里写后端地址
-});
-```
+参数名称 | 类型 | 作用/功能 |
+| -------------------| --------- | ------------------------------|
+| id | String | 唯一 id,渲染图表的节点 |
+| className | String | class样式名称 |
+| options | Object | ECharts 配置 |
+| height | String | 图表高度 |
+| width | String | 图表宽度 |
-- 在 vue 页面中调用 axios 方法并通过 props 传给 echarts 图表子组件
+### 动态渲染图表
-```js
+动态渲染图表案例为 `components` 目录下各个图表组件,index 文件负责数据获取和处理,chart 文件负责监听和数据渲染。
+
+chart 文件的主要逻辑为:
+
+```html
+
+
+
+
+
+
+
```
-### 动态渲染图表
+### 复用图表组件
- 在`components/echart`下的文件,比如`drawPie()`是渲染函数,`echartData`是需要动态渲染的数据,当外界通过`props`传入新数据,我们可以使用`watch()`方法去监听,一但数据变化就调用`this.drawPie()`并触发内部的`.setOption`函数,重新渲染一次图表。
+复用图表组件案例为中间部分的 `任务通过率与任务达标率` 模块,两个图表类似,区别在于颜色和主要渲染数据。只需要传入对应的唯一 id 和样式,然后在复用的组件 `components/echart/center/centerChartRate` 里进行接收并在对应位置赋值即可。
-```js
-//这里是子组件内部
-
-props: ["listData"],
-watch: {
- listData(newValue) {
- this.echartData= newValue;
- this.drawPie();
- },
- },
-methods: {
- drawPie() {
- .....
- '渲染节点名称'.setOption(option);
- }
- }
-```
-
-### 复用图表组件
-
- 因为 Echart 图表是根据`id/class`去获取 Dom 节点并进行渲染的,所以我们只要传入唯一的 id 值与需要的数据就可以进行复用。如中间部分的`任务通过率与任务达标率`组件就是采用复用的方式。
-
-如:在调用处`views/center.vue`里去定义好数据并传入组件(项目里的所有`id`都不能重复!!!)
+如:在调用处 `views/center.vue` 里去定义好数据并传入组件(项目里的所有 `id` 都不能重复!!!)
```js
//组件调用
@@ -135,12 +137,10 @@ data() {
}
```
-然后在复用的组件`components/echart/center/centerChartRate`里进行接收并在用到的地方赋值。
-
### 更换边框
- 边框是使用了 DataV 自带的组件,只需要去 views 目录下去寻找对应的位置去查找并替换就可以,具体的种类请去 DavaV 官网查看
- 如:
+边框是使用了 DataV 自带的组件,只需要去 views 目录下去寻找对应的位置去查找并替换就可以,具体的种类请去 DavaV 官网查看
+如:
```html
@@ -150,15 +150,15 @@ data() {
### 更换图表
- 直接进入 `components/echart` 下的文件修改成你要的 echarts 模样,可以去[echarts 官方社区](https://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~author=all)里面查看案例。
+直接进入 `components/echart` 下的文件修改成你要的 echarts 模样,可以去[echarts 官方社区](https://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~author=all)里面查看案例。
-### Mixins 注入的
+### Mixins 解决自适应适配功能
- 使用 mixins 注入解决了图表重复书写响应式适配的代码,如果要更换(新增)图形,需要将`echarts.init()`函数赋值给`this.chart`,然后 mixins 才会自动帮你注入响应式功能。
+使用 mixins 注入解决了界面大小变动图表自适应适配的功能,函数在 `utils/resizeMixins.js` 中,应用在 `common/echart/index.vue` 的封装渲染组件,主要是对 `this.chart` 进行了功能注入。
### 屏幕适配
- 本项目借助了 flexible 插件,通过改变 rem 的值来进行适配,原设计为 1920px。 ,适配区间为:1366px ~ 2560px,本项目有根据实际情况进行源文件的更改,小屏幕(如:宽为 1366px)需要自己舍弃部分动态组件进行适配,如'动态文字变换组件'会影响布局,需要手动换成一般节点,
+本项目借助了 flexible 插件,通过改变 rem 的值来进行适配,原设计为 1920px。 ,适配区间为:1366px ~ 2560px,本项目有根据实际情况进行源文件的更改,小屏幕(如:宽为 1366px)需要自己舍弃部分动态组件进行适配,如'动态文字变换组件'会影响布局,需要手动换成一般节点,
```js
// flexible文件位置: `common/flexible.js`,修改部分如下
@@ -177,13 +177,31 @@ function refreshRem() {
}
```
+### 请求数据
+
+现在的项目未使用前后端数据请求,建议使用 axios 进行数据请求,在 main.js 位置进行全局配置。
+
+- axios 的 main.js 配置参考范例(因人而异)
+
+```js
+import axios from 'axios';
+
+//把方法放到vue的原型上,这样就可以全局使用了
+Vue.prototype.$http = axios.create({
+ //设置20秒超时时间
+ timeout: 20000,
+ baseURL: 'http://172.0.0.1:80080', //这里写后端地址
+});
+```
+
## 四、更新情况
1. 增加了 Echart 组件复用的功能,如:中间任务达标率的两个百分比图使用的是同一个组件。
2. 修复了头部右侧的图案条不对称的问题。
3. 修复屏幕适配问题,更换了所有的尺寸单位,统一使用 rem。
4. 使用 Mixins 注入图表响应式代码。
-5. vue-awesome 改成按需引入的方式
+5. vue-awesome 改成按需引入的方式。
+6. 封装渲染函数,抽离了数据使逻辑更加清晰。
## 五、其余
diff --git a/src/common/echarts/index.vue b/src/common/echart/index.vue
similarity index 69%
rename from src/common/echarts/index.vue
rename to src/common/echart/index.vue
index 07055dc..b6ad8eb 100644
--- a/src/common/echarts/index.vue
+++ b/src/common/echart/index.vue
@@ -1,13 +1,13 @@
-
+
-
-
\ No newline at end of file
diff --git a/src/components/echart/bottom/bottomLeftChart/chart.vue b/src/components/echart/bottom/bottomLeftChart/chart.vue
new file mode 100644
index 0000000..9caf326
--- /dev/null
+++ b/src/components/echart/bottom/bottomLeftChart/chart.vue
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/bottom/bottomLeftChart/index.vue b/src/components/echart/bottom/bottomLeftChart/index.vue
new file mode 100644
index 0000000..1a78ba5
--- /dev/null
+++ b/src/components/echart/bottom/bottomLeftChart/index.vue
@@ -0,0 +1,141 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/bottom/bottomRightChart.vue b/src/components/echart/bottom/bottomRightChart.vue
deleted file mode 100644
index 4edc269..0000000
--- a/src/components/echart/bottom/bottomRightChart.vue
+++ /dev/null
@@ -1,403 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/echart/bottom/bottomRightChart/chart.vue b/src/components/echart/bottom/bottomRightChart/chart.vue
new file mode 100644
index 0000000..df0230f
--- /dev/null
+++ b/src/components/echart/bottom/bottomRightChart/chart.vue
@@ -0,0 +1,361 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/bottom/bottomRightChart/index.vue b/src/components/echart/bottom/bottomRightChart/index.vue
new file mode 100644
index 0000000..789fec8
--- /dev/null
+++ b/src/components/echart/bottom/bottomRightChart/index.vue
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/center/centerChartRate.vue b/src/components/echart/center/centerChartRate.vue
deleted file mode 100644
index 7f664d0..0000000
--- a/src/components/echart/center/centerChartRate.vue
+++ /dev/null
@@ -1,102 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/echart/center/centerChartRate/index.vue b/src/components/echart/center/centerChartRate/index.vue
new file mode 100644
index 0000000..fe811f7
--- /dev/null
+++ b/src/components/echart/center/centerChartRate/index.vue
@@ -0,0 +1,104 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/centerLeft/centerLeft1Chart/chart.vue b/src/components/echart/centerLeft/centerLeft1Chart/chart.vue
new file mode 100644
index 0000000..a8e20c7
--- /dev/null
+++ b/src/components/echart/centerLeft/centerLeft1Chart/chart.vue
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/centerLeft/centerLeft1Chart/index.vue b/src/components/echart/centerLeft/centerLeft1Chart/index.vue
new file mode 100644
index 0000000..3763944
--- /dev/null
+++ b/src/components/echart/centerLeft/centerLeft1Chart/index.vue
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/centerLeft/centerLeft2Chart/chart.vue b/src/components/echart/centerLeft/centerLeft2Chart/chart.vue
new file mode 100644
index 0000000..627f63d
--- /dev/null
+++ b/src/components/echart/centerLeft/centerLeft2Chart/chart.vue
@@ -0,0 +1,115 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/centerLeft/centerLeft2Chart/index.vue b/src/components/echart/centerLeft/centerLeft2Chart/index.vue
new file mode 100644
index 0000000..56e845f
--- /dev/null
+++ b/src/components/echart/centerLeft/centerLeft2Chart/index.vue
@@ -0,0 +1,121 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/centerLeft/centreLeft1Chart.vue b/src/components/echart/centerLeft/centreLeft1Chart.vue
deleted file mode 100644
index c407d50..0000000
--- a/src/components/echart/centerLeft/centreLeft1Chart.vue
+++ /dev/null
@@ -1,82 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/echart/centerLeft/centreLeft2Chart.vue b/src/components/echart/centerLeft/centreLeft2Chart.vue
deleted file mode 100644
index fd58ed8..0000000
--- a/src/components/echart/centerLeft/centreLeft2Chart.vue
+++ /dev/null
@@ -1,200 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/echart/centerRight/centerRight2Chart.vue b/src/components/echart/centerRight/centerRight2Chart.vue
deleted file mode 100644
index 796f791..0000000
--- a/src/components/echart/centerRight/centerRight2Chart.vue
+++ /dev/null
@@ -1,164 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/echart/centerRight/centerRightChart/chart.vue b/src/components/echart/centerRight/centerRightChart/chart.vue
new file mode 100644
index 0000000..f8fae6a
--- /dev/null
+++ b/src/components/echart/centerRight/centerRightChart/chart.vue
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/echart/centerRight/centerRightChart/index.vue b/src/components/echart/centerRight/centerRightChart/index.vue
new file mode 100644
index 0000000..cdab9a7
--- /dev/null
+++ b/src/components/echart/centerRight/centerRightChart/index.vue
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/utils/resizeMixins.js b/src/utils/resizeMixins.js
index 0c95809..cdefacf 100644
--- a/src/utils/resizeMixins.js
+++ b/src/utils/resizeMixins.js
@@ -4,7 +4,7 @@ const resizeChartMethod = '$__resizeChartMethod';
export default {
data() {
- // 在组件内部将图表init的引用映射到chart属性上
+ // 在组件内部将图表 init 的引用映射到 chart 属性上
return {
chart: null,
};
@@ -13,7 +13,7 @@ export default {
window.addEventListener('resize', this[resizeChartMethod], false);
},
activated() {
- // 防止keep-alive之后图表变形
+ // 防止 keep-alive 之后图表变形
if (this.chart) {
this.chart.resize()
}
@@ -22,11 +22,12 @@ export default {
window.removeEventListener('reisze', this[resizeChartMethod]);
},
methods: {
- // 通过lodash的防抖函数来控制resize的频率
+ // 通过 lodash 的防抖函数来控制 resize 的频率
[resizeChartMethod]: debounce(function() {
if (this.chart) {
+ console.log('修改');
this.chart.resize();
}
- }, 100),
+ }, 300),
},
};
diff --git a/src/views/bottomRight.vue b/src/views/bottomRight.vue
index 2217ad3..e38316a 100644
--- a/src/views/bottomRight.vue
+++ b/src/views/bottomRight.vue
@@ -8,7 +8,7 @@
diff --git a/src/views/centerLeft1.vue b/src/views/centerLeft1.vue
index 46ed4c6..a7e8cd5 100644
--- a/src/views/centerLeft1.vue
+++ b/src/views/centerLeft1.vue
@@ -31,7 +31,7 @@