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 {
name: 'JilinCityBar',
props: {
chartHeight: { type: String, default: '220px' },
interval: { type: Number, default: 2500 }, // (ms)
districtName: { type: String, default: null }, //
districtData: { type: Object, default: () => ({}) }, //
dataType: { type: String, default: 'patents' } // patents()research()conversion()
chartHeight: {type: String, default: '220px'},
interval: {type: Number, default: 2500} // (ms)
},
data() {
return {
@ -22,57 +19,17 @@ export default {
pageSize: 4,
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: {
chartHeight() {
this.myChart && this.myChart.resize();
},
districtName() {
this.updateChart();
},
dataType() {
this.updateChart();
}
},
mounted() {
@ -89,9 +46,9 @@ export default {
const g = this.$echarts.graphic;
const L = g.extendShape({
shape: { x: 0, y: 0 },
shape: {x: 0, y: 0},
buildPath(ctx, s) {
const { x, y, xAxisPoint } = s;
const {x, y, xAxisPoint} = s;
ctx.moveTo(x + dx, y)
.lineTo(x - 9 + dx, y - 9)
.lineTo(xAxisPoint[0] - 9 + dx, xAxisPoint[1] - 9)
@ -100,9 +57,9 @@ export default {
}
});
const R = g.extendShape({
shape: { x: 0, y: 0 },
shape: {x: 0, y: 0},
buildPath(ctx, s) {
const { x, y, xAxisPoint } = s;
const {x, y, xAxisPoint} = s;
ctx.moveTo(x + dx, y)
.lineTo(xAxisPoint[0] + dx, xAxisPoint[1])
.lineTo(xAxisPoint[0] + 12 + dx, xAxisPoint[1] - 6)
@ -111,9 +68,9 @@ export default {
}
});
const T = g.extendShape({
shape: { x: 0, y: 0 },
shape: {x: 0, y: 0},
buildPath(ctx, s) {
const { x, y } = s;
const {x, y} = s;
ctx.moveTo(x + dx, y)
.lineTo(x + 12 + dx, y - 6)
.lineTo(x + 3 + dx, y - 15)
@ -121,9 +78,9 @@ export default {
.closePath();
}
});
g.registerShape('CubeLeft', L);
g.registerShape('CubeLeft', L);
g.registerShape('CubeRight', R);
g.registerShape('CubeTop', T);
g.registerShape('CubeTop', T);
},
/* ---------- 初始化 ---------- */
@ -134,79 +91,29 @@ export default {
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() {
const TEAL_LIGHT = '#86F3CE';
const TEAL_DEEP = '#1EAF9A';
const HIGHLIGHT_COLOR = '#FFE777'; //
const TEAL_DEEP = '#1EAF9A';
const option = {
backgroundColor: 'transparent',
animationDurationUpdate: 600,
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: {
trigger: 'axis',
axisPointer: { type: 'shadow' },
axisPointer: {type: 'shadow'},
formatter: d =>
`${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>
${this.chartTitle} <span style="padding-left:13px;">${d[0].value}</span>`
<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:${TEAL_LIGHT}"></span>
数量 <span style="padding-left:13px;">${d[0].value}</span>`
},
legend: {
data: [{ name: this.chartTitle, itemStyle: {color: TEAL_LIGHT}}],
data: [{name: '数量', itemStyle: {color: TEAL_LIGHT}}],
textStyle: {fontSize: 14, color: '#A7C4F6'},
itemWidth: 10, itemHeight: 8, top: '1%', right: '3%'
},
@ -239,17 +146,10 @@ export default {
series: [
{
type: 'custom',
name: this.chartTitle,
name: '数量',
renderItem: (p, api) => {
const loc = api.coord([api.value(0), api.value(1)]);
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 {
type: 'group',
children: [
@ -258,8 +158,8 @@ export default {
shape: {x: loc[0], y: loc[1], xAxisPoint: axis},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: deepColor},
{offset: 1, color: sideColor}
{offset: 0, color: TEAL_DEEP},
{offset: 1, color: '#157B6E'}
])
}
},
@ -268,15 +168,15 @@ export default {
shape: {x: loc[0], y: loc[1], xAxisPoint: axis},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: topColor},
{offset: 1, color: deepColor}
{offset: 0, color: TEAL_LIGHT},
{offset: 1, color: TEAL_DEEP}
])
}
},
{
type: 'CubeTop',
shape: {x: loc[0], y: loc[1], xAxisPoint: axis},
style: {fill: topColor}
style: {fill: TEAL_LIGHT}
}
]
};
@ -295,7 +195,7 @@ export default {
type: 'bar',
data: this.values,
itemStyle: {color: 'transparent'},
name: this.chartTitle
name: '数量'
}
]
};
@ -305,8 +205,6 @@ export default {
/* ---------- 平滑滚动 ---------- */
startScroll() {
clearInterval(this.timer); //
const len = this.xData.length;
this.timer = setInterval(() => {
this.cursor = (this.cursor + 1) % len;