Skip to content

Commit 274f285

Browse files
author
fanxiaocheng
committed
添加g2组件
1 parent 56e6ce3 commit 274f285

31 files changed

+848
-59
lines changed

template/config/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
assetsPublicPath: '/',
3131
proxyTable: {
3232
'/api': {
33-
target: 'http://try6.edusoho.cn',
33+
target: 'http://t5.edusoho.cn',
3434
changeOrigin: true
3535
}
3636
},

template/src/assets/fonts/close-icon/iconfont.css

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Loading
Binary file not shown.
Binary file not shown.

template/src/assets/styles/main.less

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '~cd-vue/src/styles/index.less';
22

3-
@import '../fonts/cvp-icon.css';
3+
@import '../fonts/cvp-icon/cvp-icon.css';
4+
@import '../fonts/close-icon/iconfont.css';
45

56
@import './variables.less';
67
@import './mixins.less';

template/src/components/modal/index.vue

+42-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<transition name="modal" v-if="show">
33
<div class="modal-mask">
4-
<div class="modal-wrapper">
5-
<div class="modal-dialog">
6-
<div class="modal-header" :class="modalSize">
4+
<div :class="`modal-wrapper-${position}`" @click.self="maskClose">
5+
<div class="modal-dialog" :class="modalSize">
6+
<div class="modal-header">
77
<slot name="close">
8-
<i class="groupon-icon groupon-icon-guanbi" @click="closeClickListener"></i>
8+
<i class="iconfont icon-modal-close" @click="closeClickListener"></i>
99
</slot>
1010
<slot name="header">
1111
default header
@@ -36,8 +36,26 @@ export default {
3636
show: false
3737
}
3838
},
39-
props: ['closeBtn', 'size'],
39+
props: {
40+
size: {
41+
type: String,
42+
default: 'md',
43+
},
44+
position: {
45+
type: String,
46+
default: 'top',
47+
},
48+
maskCloseable: {
49+
type: Boolean,
50+
default: true,
51+
}
52+
},
4053
methods: {
54+
maskClose() {
55+
if(this.maskCloseable) {
56+
this.closeModal();
57+
}
58+
},
4159
closeClickListener() {
4260
this.closeModal();
4361
},
@@ -76,11 +94,22 @@ export default {
7694
transition: opacity .3s ease;
7795
}
7896
79-
.modal-wrapper {
97+
.modal-wrapper-center {
8098
display: table-cell;
8199
vertical-align: middle;
82100
}
83101
102+
.modal-wrapper-top {
103+
display: block;
104+
position: absolute;
105+
left: 0;
106+
top: 0;
107+
bottom: 0;
108+
right: 0;
109+
margin: auto;
110+
padding-top: 30px;
111+
}
112+
84113
.modal-dialog {
85114
width: 600px;
86115
margin: 0px auto;
@@ -98,10 +127,16 @@ export default {
98127
margin-top: 0;
99128
font-weight: 400;
100129
}
101-
.groupon-icon {
130+
.iconfont {
102131
position: absolute;
103132
right: 0;
104133
top: 0;
134+
cursor: pointer;
135+
opacity: .5;
136+
color: #000;
137+
&:hover {
138+
opacity: 1;
139+
}
105140
}
106141
}
107142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import DataSet from '@antv/data-set';
2+
// 等这次
3+
export default class BaseG2 {
4+
constructor(chart, data, config) {
5+
this.chart = chart;
6+
this.data = data;
7+
this.config = config;
8+
//
9+
this.key1 = '';
10+
this.key2 = '';
11+
this.number = 0; // 为了区分多条和单条折线图
12+
this.yKey = ''; // 规定多种数据时,采用'yKey'的值
13+
this.yVal = ''; // 规定多种数据时,采用'yVal'的值
14+
this.setData();
15+
}
16+
17+
setData() {
18+
for(let value in this.data[0]) {
19+
this.number++;
20+
this[`key${this.number}`] = value;
21+
}
22+
23+
if(this.number <= 2) {
24+
this.yKey = this.key2;
25+
}
26+
}
27+
28+
init() {
29+
this.setSource();
30+
this.setScale();
31+
this.setAxis();
32+
this.setTooltip();
33+
this.setEvents();
34+
if(this.setPositioin && typeof this.setPositioin === 'function') {
35+
this.setPositioin();
36+
}
37+
this.done();
38+
}
39+
40+
/*
41+
* 配置图形的数据源
42+
* https://antv.alipay.com/zh-cn/g2/3.x/api/chart.html#_source
43+
*/
44+
setSource() {
45+
const number = this.number;
46+
if(number >= 3) {
47+
// 处理折线图等有多条折线图的情况
48+
const ds = new DataSet();
49+
const dv = ds.createView().source(this.data);
50+
const fields = [];
51+
52+
this.yKey = 'yKey';
53+
this.yVal = 'yVal'; // 数据项超过2个时,将多个项目合并后统一命名为yVal
54+
for(let i = 2;i <= number; i++) {
55+
fields.push(this[`key${i}`]);
56+
}
57+
58+
dv.transform({
59+
type: 'fold',
60+
fields,
61+
key: this.yKey,
62+
value: this.yVal,
63+
});
64+
this.chart.source(dv, {
65+
[this.key1]: {
66+
range: [0, 1]
67+
}
68+
});
69+
} else {
70+
this.chart.source(this.data);
71+
}
72+
}
73+
74+
/*
75+
* 对指定的数据字段进行列定义
76+
* https://antv.alipay.com/zh-cn/g2/3.x/api/chart.html#_scale
77+
*/
78+
setScale() {
79+
if(this.config.scaleConfig) {
80+
this.chart.scale(this.config.scaleConfig || {});
81+
}
82+
}
83+
84+
/*
85+
* 配置坐标轴
86+
* https://antv.alipay.com/zh-cn/g2/3.x/api/chart.html#_axis
87+
*/
88+
setAxis() {
89+
const axisConfig = this.config.axisConfig;
90+
if(axisConfig) {
91+
for (const key in axisConfig) {
92+
this.chart.axis(key, axisConfig[key]);
93+
}
94+
}
95+
}
96+
97+
/*
98+
* 配置图例
99+
* https://antv.alipay.com/zh-cn/g2/3.x/api/chart.html#_legend
100+
*/
101+
setLegend() {
102+
const legendConfig = this.config.legendConfig;
103+
if(legendConfig) {
104+
for(const filed in legendConfig) {
105+
this.chart.legend(field, legendConfig[filed] || {});
106+
}
107+
}
108+
}
109+
110+
/*
111+
* 配置鼠标移到图形上时的弹层
112+
* https://antv.alipay.com/zh-cn/g2/3.x/api/chart.html#_tooltip
113+
*/
114+
setTooltip() {
115+
if(this.tooltipConfig) {
116+
this.chart.tooltip(this.tooltipConfig || {});
117+
}
118+
}
119+
120+
setEvents() {
121+
// 注册事件
122+
if(this.config['event']) {
123+
console.log('event注册');
124+
for(const name in this.config['event']) {
125+
this.chart.on(name, this.config['event'][name])
126+
}
127+
}
128+
}
129+
130+
done() {
131+
this.chart.render();
132+
}
133+
}

template/src/containers/components/g2/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Chart } from '@antv/g2';
2+
3+
// 创建唯一的 ID
4+
let uniqueId = 0;
5+
function generateUniqueId() {
6+
uniqueId += 1;
7+
return `el-g2-${uniqueId}`;
8+
}
9+
10+
export default function createG2(__operation) {
11+
return {
12+
data() {
13+
return {
14+
chart: null,
15+
chartId: generateUniqueId(),
16+
};
17+
},
18+
props: {
19+
height: {
20+
type: Number,
21+
default: 300,
22+
},
23+
data: {
24+
type: Array,
25+
default: function() {
26+
return [];
27+
}
28+
},
29+
config: {
30+
type: Object,
31+
default: function() {
32+
return {};
33+
}
34+
},
35+
title: String,
36+
},
37+
watch: {
38+
data: function(newData, oldData) {
39+
if (oldData && newData) {
40+
this.chart.changeData(newData);
41+
}
42+
},
43+
height: function(val, oldVal) {
44+
if (oldVal && val) {
45+
this.chart.changeHeight(val);
46+
}
47+
},
48+
},
49+
mounted() {
50+
this.initChart();
51+
},
52+
beforeDestroy() {
53+
this.chart.destroy();
54+
this.chart = null;
55+
this.chartId = null;
56+
},
57+
methods: {
58+
initChart() {
59+
const { height, data } = this;
60+
const chart = new Chart({
61+
id: this.chartId, // 这里还是需要用id,或者是如下的container
62+
height,
63+
forceFit: true,
64+
background: {
65+
fill: '#fff',
66+
},
67+
padding: this.config.padding || 50,
68+
});
69+
70+
this.chart = chart;
71+
__operation(chart, data, this.config);
72+
},
73+
},
74+
render(createElement) {
75+
return createElement('div', {
76+
attrs: {
77+
id: this.chartId,
78+
},
79+
});
80+
},
81+
};
82+
}

0 commit comments

Comments
 (0)