fix: first commit

This commit is contained in:
听云的猫 2025-06-17 22:58:16 +08:00
parent 4b6a6eb8ef
commit 8aa2997e9d
2 changed files with 35 additions and 137 deletions

BIN
dist.zip Normal file

Binary file not shown.

View File

@ -9,11 +9,8 @@
export default { export default {
name: 'JilinCityBar', name: 'JilinCityBar',
props: { props: {
chartHeight: { type: String, default: '220px' }, chartHeight: {type: String, default: '220px'},
interval: { type: Number, default: 2500 }, // (ms) interval: {type: Number, default: 2500} // (ms)
districtName: { type: String, default: null }, //
districtData: { type: Object, default: () => ({}) }, //
dataType: { type: String, default: 'patents' } // patents()research()conversion()
}, },
data() { data() {
return { return {
@ -21,65 +18,25 @@ export default {
timer: null, timer: null,
pageSize: 4, pageSize: 4,
cursor: 0, cursor: 0,
// 使 /* —— 数据 —— */
defaultXData: [ xData: [
'朝阳区', '南关区', '宽城区', '二道区', '长春市', '吉林市', '四平市', '辽源市',
'绿园区', '双阳区', '九台区', '农安县' '通化市', '白山市', '松原市', '白城市', '延边自治州'
], ],
defaultValues: [220, 180, 190, 170, 185, 120, 140, 130] values: [22, 10, 120, 2222, 1111, 3333, 123, 871, 61]
}; };
}, },
computed: {
// props
xData() {
return Object.keys(this.districtData).length > 0 ? Object.keys(this.districtData) : this.defaultXData;
},
values() {
if (Object.keys(this.districtData).length === 0) {
return this.defaultValues;
}
// dataType
return this.xData.map(district => {
if (this.districtData[district]) {
return this.districtData[district][this.dataType] || 0;
}
return 0;
});
},
//
chartTitle() {
switch(this.dataType) {
case 'research':
return '研究机构数量';
case 'conversion':
return '专利转化数量';
default:
return '专利数量';
}
},
//
highlightIndex() {
return this.districtName ? this.xData.indexOf(this.districtName) : -1;
}
},
watch: { watch: {
chartHeight() { chartHeight() {
this.myChart && this.myChart.resize(); this.myChart && this.myChart.resize();
},
districtName() {
this.updateChart();
},
dataType() {
this.updateChart();
} }
}, },
mounted() { mounted() {
this.initChart(); this.initChart();
}, },
beforeDestroy() { beforeDestroy() {
clearInterval(this.timer); clearInterval(this.timer);
}, },
methods: { methods: {
@ -89,9 +46,9 @@ export default {
const g = this.$echarts.graphic; const g = this.$echarts.graphic;
const L = g.extendShape({ const L = g.extendShape({
shape: { x: 0, y: 0 }, shape: {x: 0, y: 0},
buildPath(ctx, s) { buildPath(ctx, s) {
const { x, y, xAxisPoint } = s; const {x, y, xAxisPoint} = s;
ctx.moveTo(x + dx, y) ctx.moveTo(x + dx, y)
.lineTo(x - 9 + dx, y - 9) .lineTo(x - 9 + dx, y - 9)
.lineTo(xAxisPoint[0] - 9 + dx, xAxisPoint[1] - 9) .lineTo(xAxisPoint[0] - 9 + dx, xAxisPoint[1] - 9)
@ -100,9 +57,9 @@ export default {
} }
}); });
const R = g.extendShape({ const R = g.extendShape({
shape: { x: 0, y: 0 }, shape: {x: 0, y: 0},
buildPath(ctx, s) { buildPath(ctx, s) {
const { x, y, xAxisPoint } = s; const {x, y, xAxisPoint} = s;
ctx.moveTo(x + dx, y) ctx.moveTo(x + dx, y)
.lineTo(xAxisPoint[0] + dx, xAxisPoint[1]) .lineTo(xAxisPoint[0] + dx, xAxisPoint[1])
.lineTo(xAxisPoint[0] + 12 + dx, xAxisPoint[1] - 6) .lineTo(xAxisPoint[0] + 12 + dx, xAxisPoint[1] - 6)
@ -111,9 +68,9 @@ export default {
} }
}); });
const T = g.extendShape({ const T = g.extendShape({
shape: { x: 0, y: 0 }, shape: {x: 0, y: 0},
buildPath(ctx, s) { buildPath(ctx, s) {
const { x, y } = s; const {x, y} = s;
ctx.moveTo(x + dx, y) ctx.moveTo(x + dx, y)
.lineTo(x + 12 + dx, y - 6) .lineTo(x + 12 + dx, y - 6)
.lineTo(x + 3 + dx, y - 15) .lineTo(x + 3 + dx, y - 15)
@ -121,9 +78,9 @@ export default {
.closePath(); .closePath();
} }
}); });
g.registerShape('CubeLeft', L); g.registerShape('CubeLeft', L);
g.registerShape('CubeRight', R); g.registerShape('CubeRight', R);
g.registerShape('CubeTop', T); g.registerShape('CubeTop', T);
}, },
/* ---------- 初始化 ---------- */ /* ---------- 初始化 ---------- */
@ -133,80 +90,30 @@ export default {
this.render(); // this.render(); //
if (this.xData.length > this.pageSize) this.startScroll(); if (this.xData.length > this.pageSize) this.startScroll();
}, },
/* ---------- 更新图表 ---------- */
updateChart() {
if (this.myChart) {
//
clearInterval(this.timer);
//
if (this.highlightIndex >= 0) {
// 使
const startIdx = Math.max(0, Math.min(this.highlightIndex, this.xData.length - this.pageSize));
this.cursor = startIdx;
this.myChart.setOption({
dataZoom: [{
startValue: startIdx,
endValue: startIdx + this.pageSize - 1
}]
});
}
//
this.myChart.setOption({
xAxis: [{
data: this.xData
}],
series: [
{
data: this.values,
itemStyle: {
color: (params) => {
// 使
if (this.highlightIndex === params.dataIndex) {
return '#FFE777'; //
}
return undefined; // 使
}
}
},
{
data: this.values
}
]
});
//
if (this.xData.length > this.pageSize) this.startScroll();
}
},
/* ---------- 配置 & 渲染 ---------- */ /* ---------- 配置 & 渲染 ---------- */
render() { render() {
const TEAL_LIGHT = '#86F3CE'; const TEAL_LIGHT = '#86F3CE';
const TEAL_DEEP = '#1EAF9A'; const TEAL_DEEP = '#1EAF9A';
const HIGHLIGHT_COLOR = '#FFE777'; //
const option = { const option = {
backgroundColor: 'transparent', backgroundColor: 'transparent',
animationDurationUpdate: 600, animationDurationUpdate: 600,
animationEasingUpdate: 'cubicOut', animationEasingUpdate: 'cubicOut',
grid: { left: 30, right: 30, bottom: 20, top: 40, containLabel: true }, grid: {left: 30, right: 30, bottom: 20, top: 40, containLabel: true},
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { type: 'shadow' }, axisPointer: {type: 'shadow'},
formatter: d => formatter: d =>
`${d[0].axisValue}<br/> `${d[0].axisValue}<br/>
<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:${d[0].color || TEAL_LIGHT}"></span> <span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:${TEAL_LIGHT}"></span>
${this.chartTitle} <span style="padding-left:13px;">${d[0].value}</span>` 数量 <span style="padding-left:13px;">${d[0].value}</span>`
}, },
legend: { legend: {
data: [{ name: this.chartTitle, itemStyle: {color: TEAL_LIGHT}}], data: [{name: '数量', itemStyle: {color: TEAL_LIGHT}}],
textStyle: {fontSize: 14, color: '#A7C4F6'}, textStyle: {fontSize: 14, color: '#A7C4F6'},
itemWidth: 10, itemHeight: 8, top: '1%', right: '3%' itemWidth: 10, itemHeight: 8, top: '1%', right: '3%'
}, },
@ -239,17 +146,10 @@ export default {
series: [ series: [
{ {
type: 'custom', type: 'custom',
name: this.chartTitle, name: '数量',
renderItem: (p, api) => { renderItem: (p, api) => {
const loc = api.coord([api.value(0), api.value(1)]); const loc = api.coord([api.value(0), api.value(1)]);
const axis = api.coord([api.value(0), 0]); const axis = api.coord([api.value(0), 0]);
// - 使
const isHighlight = this.highlightIndex === api.dataIndex();
const topColor = isHighlight ? HIGHLIGHT_COLOR : TEAL_LIGHT;
const deepColor = isHighlight ? '#E5C848' : TEAL_DEEP;
const sideColor = isHighlight ? '#B19A3A' : '#157B6E';
return { return {
type: 'group', type: 'group',
children: [ children: [
@ -258,8 +158,8 @@ export default {
shape: {x: loc[0], y: loc[1], xAxisPoint: axis}, shape: {x: loc[0], y: loc[1], xAxisPoint: axis},
style: { style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: deepColor}, {offset: 0, color: TEAL_DEEP},
{offset: 1, color: sideColor} {offset: 1, color: '#157B6E'}
]) ])
} }
}, },
@ -268,15 +168,15 @@ export default {
shape: {x: loc[0], y: loc[1], xAxisPoint: axis}, shape: {x: loc[0], y: loc[1], xAxisPoint: axis},
style: { style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: topColor}, {offset: 0, color: TEAL_LIGHT},
{offset: 1, color: deepColor} {offset: 1, color: TEAL_DEEP}
]) ])
} }
}, },
{ {
type: 'CubeTop', type: 'CubeTop',
shape: {x: loc[0], y: loc[1], xAxisPoint: axis}, shape: {x: loc[0], y: loc[1], xAxisPoint: axis},
style: {fill: topColor} style: {fill: TEAL_LIGHT}
} }
] ]
}; };
@ -295,7 +195,7 @@ export default {
type: 'bar', type: 'bar',
data: this.values, data: this.values,
itemStyle: {color: 'transparent'}, itemStyle: {color: 'transparent'},
name: this.chartTitle name: '数量'
} }
] ]
}; };
@ -305,8 +205,6 @@ export default {
/* ---------- 平滑滚动 ---------- */ /* ---------- 平滑滚动 ---------- */
startScroll() { startScroll() {
clearInterval(this.timer); //
const len = this.xData.length; const len = this.xData.length;
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.cursor = (this.cursor + 1) % len; this.cursor = (this.cursor + 1) % len;