Skip to content

Commit 1c11a0c

Browse files
committed
feat: 集成echart
1 parent 7c57f50 commit 1c11a0c

15 files changed

+14663
-16396
lines changed

package-lock.json

Lines changed: 12197 additions & 13004 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"crypto-random-string": "^3.3.1",
3333
"css": "^3.0.0",
3434
"css-scoped": "^1.0.0",
35+
"echarts": "^5.4.3",
3536
"ejs": "^3.1.6",
3637
"element-plus": "^2.4.3",
3738
"escodegen": "^2.0.0",
@@ -47,6 +48,7 @@
4748
"split.js": "^1.6.2",
4849
"vant": "^3.3.7",
4950
"vue": "^3.3.10",
51+
"vue-echarts": "^6.6.2",
5052
"vue-github-button": "^1.3.0",
5153
"vue-template-compiler": "^2.6.14",
5254
"vuedraggable": "^4.1.0",
@@ -55,11 +57,6 @@
5557
"devDependencies": {
5658
"@babel/generator": "^7.11.6",
5759
"@rollup/plugin-dynamic-import-vars": "^1.4.1",
58-
"vite": "^2.6.14",
59-
"@vue/cli-plugin-babel": "^4.2.0",
60-
"@vue/cli-plugin-eslint": "^4.2.0",
61-
"@vue/cli-plugin-pwa": "^4.2.0",
62-
"@vue/cli-service": "^5.0.8",
6360
"@vue/eslint-config-airbnb": "^5.0.2",
6461
"babel-eslint": "^10.0.3",
6562
"eslint": "^6.7.2",
@@ -69,7 +66,8 @@
6966
"is-regexp": "^3.0.0",
7067
"lint-staged": "^9.5.0",
7168
"sass": "^1.25.0",
72-
"sass-loader": "^8.0.2"
69+
"sass-loader": "^8.0.2",
70+
"vite": "^2.6.14"
7371
},
7472
"eslintConfig": {
7573
"root": true,

src/components-v2/ToolsBar.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
</template>
4848

4949
<script>
50+
5051
export default {
5152
props: [],
52-
components: { },
53+
components: {
54+
},
5355
data() {
5456
return {
5557
previewMode: false,

src/components/AttributeInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div style="margin-top: 20px;">
1111
<div name="1" v-show="!editMode">
1212
<div>
13-
<div class="item" v-for="(item, index) in localAttributes" :key="item.key">
13+
<div class="item" v-for="(item, index) in localAttributes" :key="index">
1414
<el-input v-model="item.key" :placeholder="'key' + index" class="half-width" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"></el-input>
1515
<div class="split">:</div>
1616
<el-input v-model="item.value" type="textarea" :placeholder="'value' + index" class="half-width" style="flex-grow: 4;" :autosize="{ minRows: 2, maxRows: 4}"></el-input>

src/components/RawComponents.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</div>
5151
</nav>
5252

53-
<div style="overflow:scroll;padding:0 10px;">
53+
<div style="overflow:scroll;padding:0 10px;width: 100%;">
5454
<keep-alive>
5555
<component :is="currentSelectBrand.componentName" @mounted='onMouted(currentIndex)'></component>
5656
</keep-alive>
@@ -99,6 +99,14 @@ export default {
9999
}, {
100100
icon: ('https://static.imonkey.xueersi.com/download/vcc-resource/logo/quasar-n.png'),
101101
enable: false
102+
}, {
103+
icon: ('https://static.imonkey.xueersi.com/download/vcc-resource/logo/pie.png'),
104+
clickCallback: this.onSelectElement,
105+
className: "demonstration-echart",
106+
selectIndex: 0,
107+
componentName: 'echart',
108+
enable: true,
109+
titleArray: [],
102110
}, {
103111
icon: ('https://static.imonkey.xueersi.com/download/vcc-resource/logo/antd-n.svg'), // 组件库导航图标
104112
clickCallback: this.onSelectElement, // 图标点击回调
@@ -220,7 +228,8 @@ export default {
220228
// iview,
221229
// quasar,
222230
ele: defineAsyncComponent(() => import("../rawComponents/element/index.vue")),
223-
antd: defineAsyncComponent(() => import("../rawComponents/antd"))
231+
antd: defineAsyncComponent(() => import("../rawComponents/antd")),
232+
echart: defineAsyncComponent(() => import("../rawComponents/echart"))
224233
},
225234
226235
};

src/libs/main-panel.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class MainPanelProvider {
4949
let code = this.codeGenerator.outputVueCodeWithJsonObj(rawDataStructure);
5050

5151
// 将xxx: () => {} 转换为xxx(){}
52-
code = code.replace(/:\s*\(([\w\s]*)\)\s*=>/g,"\($1\)");
52+
code = code.replace(/:\s*\(([\w\s]*)\)\s*=>/g, "\($1\)");
5353

5454
// 生成展示代码
5555
let codeForShow = code.replace(/\s{1}lc_id=".+?"/g, '');
@@ -67,19 +67,19 @@ export class MainPanelProvider {
6767
const componentOptions = (new Function(`return ${newScript}`))();
6868

6969
componentOptions.template = template.content;
70-
70+
7171
if (this.editMode) {
7272
// 渲染当前代码
7373
const readyForMoutedElement = this.createMountedElement();
7474
createBaseAppAsync(componentOptions).then(app => {
7575
app.mount(readyForMoutedElement)
76-
// 开启编辑模式
76+
// 开启编辑模式,这个方式会导致正常渲染的事件被中断, 例如EChart的加载渲染。
7777
this.enableEditMode();
7878
});
79-
79+
8080
// 拍平数据结构
8181
this.flatDataStructure(rawDataStructure);
82-
82+
8383
} else {
8484
// 渲染当前代码
8585
createBaseAppAsync(componentOptions).then(app => app.mount(this.mountedEle));
@@ -280,11 +280,11 @@ export class MainPanelProvider {
280280
enableEditMode() {
281281
const renderControlPanel = this.getControlPanelRoot();
282282
// 加一个延迟的作用是:给el-table这种绘制需要时间的组件留出充足的时间,否则会造成el-table渲染不到页面上
283-
283+
284284
if (this.enableDelayTask) {
285285
clearTimeout(this.enableDelayTask);
286286
}
287-
287+
288288
this.enableDelayTask = setTimeout(() => {
289289
// 这种方式可以禁用原节点所有的事件
290290
const elClone = renderControlPanel.cloneNode(true);

src/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ import "element-plus/dist/index.css";
1313
import APP from "./App.vue";
1414
import loadCompontents from "@/libs/UIComponentInit.js";
1515

16+
import Chart from './rawComponents/echart/init';
17+
1618
/**
1719
* 创建实例基础方法
1820
* @param {*} renderComponent
1921
* @param {*} loadFinished
2022
* @returns
2123
*/
22-
function loadTemplate(renderComponent, loadFinished = () => {}) {
24+
function loadTemplate(renderComponent, loadFinished = () => { }) {
2325
const app = createApp(renderComponent);
2426
app.use(ElementPlus);
27+
app.component('VChart', Chart);
2528
loadCompontents().then((modules) => {
2629
for (let index = 0; index < modules.length; index++) {
2730
const module = modules[index];

src/map/data.index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/map/style.index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/map/template.index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rawComponents/echart/chart.vue

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<template lc_id="Bb1LYS7hJm">
2+
<div class="echart-class" lc_id="OT0KmxfA/e">
3+
<div style="font-size: 12px;">
4+
Tips: Vcc使用的是vue-echarts,因此实际使用时也需要将vue-echarts集成至项目中使用。
5+
另外由于渲染器本身的原因,在将eChart拖入到面板之后,<span style="color:red;">会有无法正常展示的问题</span>。
6+
代码本身是没有问题的,在预览模式下也可以正常渲染。
7+
</div>
8+
<v-chart
9+
class="chart"
10+
style="height: 300px; width: 500px"
11+
:option="echartPieOption"
12+
autoresize
13+
lc-mark
14+
lc_id="4C2wEjQs0u"
15+
></v-chart>
16+
<v-chart
17+
class="chart"
18+
style="height: 300px; width: 500px"
19+
:option="echartBarOption"
20+
autoresize
21+
lc-mark
22+
lc_id="zQ9T9YQOw3"
23+
></v-chart>
24+
</div>
25+
</template>
26+
<script>
27+
export default {
28+
data() {
29+
return {
30+
echartPieOption: {
31+
title: {
32+
text: 'Traffic Sources',
33+
left: 'center',
34+
},
35+
legend: {
36+
orient: 'vertical',
37+
left: 'left',
38+
data: ['Direct', 'Email', 'Ad Networks', 'Video Ads', 'Search Engines'],
39+
},
40+
series: [
41+
{
42+
name: 'Traffic Sources',
43+
type: 'pie',
44+
radius: '55%',
45+
center: ['50%', '60%'],
46+
data: [
47+
{ value: 335, name: 'Direct' },
48+
{ value: 310, name: 'Email' },
49+
{ value: 234, name: 'Ad Networks' },
50+
{ value: 135, name: 'Video Ads' },
51+
{ value: 1548, name: 'Search Engines' },
52+
],
53+
emphasis: {
54+
itemStyle: {
55+
shadowBlur: 10,
56+
shadowOffsetX: 0,
57+
shadowColor: 'rgba(0, 0, 0, 0.5)',
58+
},
59+
},
60+
},
61+
],
62+
},
63+
echartBarOption: {
64+
xAxis: {
65+
type: 'category',
66+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
67+
},
68+
yAxis: {
69+
type: 'value',
70+
},
71+
series: [
72+
{
73+
data: [120, 200, 150, 80, 70, 110, 130],
74+
type: 'bar',
75+
},
76+
],
77+
},
78+
};
79+
},
80+
mounted() {},
81+
provide: {},
82+
};
83+
</script>
84+
<style scoped>
85+
.echart-class {
86+
padding: 20px;
87+
display: flex;
88+
flex-direction: column;
89+
gap: 10px;
90+
}
91+
92+
.chart {
93+
height: 300px;
94+
width: 100% !important;
95+
border: 1px dashed #c6c6c6;
96+
border-radius: 5px;
97+
}
98+
</style>

src/rawComponents/echart/index.vue

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<template>
2+
<div class="echart-class">
3+
<Chart />
4+
</div>
5+
</template>
6+
7+
<script>
8+
import Chart from './chart.vue';
9+
import { deepLCEle } from '@/utils/initRawComponent';
10+
11+
export default {
12+
components: {
13+
Chart,
14+
},
15+
data() {
16+
return {};
17+
},
18+
mounted() {
19+
this.$emit('mounted');
20+
// 对所有拥有lc-mark的元素进行初始化
21+
deepLCEle(document.querySelector('.echart-class'), () => {});
22+
},
23+
provide: {},
24+
};
25+
</script>
26+
27+
<style scoped>
28+
.echart-class {
29+
padding: 20px;
30+
display: flex;
31+
flex-direction: column;
32+
gap: 10px;
33+
}
34+
35+
.chart {
36+
height: 300px;
37+
width: 100%;
38+
border: 1px dashed #c6c6c6;
39+
border-radius: 5px;
40+
}
41+
</style>

src/rawComponents/echart/init.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import { use } from 'echarts/core';
3+
import { CanvasRenderer } from 'echarts/renderers';
4+
import { PieChart, BarChart } from 'echarts/charts';
5+
import { TitleComponent, TooltipComponent, LegendComponent, GridComponent } from 'echarts/components';
6+
import VChart from 'vue-echarts';
7+
8+
use([CanvasRenderer, PieChart, BarChart, TitleComponent, TooltipComponent, LegendComponent, GridComponent]);
9+
10+
export default VChart;
11+
</script>

src/script/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ glob(
1414
{
1515
cwd: componentsPath,
1616
absolute: true,
17-
ignore: ["**/element/index.vue", "**/vant/index.vue", "**/iview/index.vue", "**/antd/index.vue"],
17+
ignore: ["**/element/index.vue", "**/vant/index.vue", "**/iview/index.vue", "**/antd/index.vue", "**/echart/index.vue"],
1818
},
1919
function (er, files) {
2020
console.info(`正在对${files.length}个文件进行编译...`);

0 commit comments

Comments
 (0)