提交 5bf95bfe 编写于 作者: zhujiamin's avatar zhujiamin

feat: 删除重发

上级 23938f3a
{
"name": "vite-project",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview --host 0.0.0.0",
"lint": "eslint 'src/**/*.ts' 'src/**/*.vue'",
"lint:style": "stylelint 'src/**/*.scss'"
},
"dependencies": {
"@floating-ui/dom": "^1.0.11",
"@ibiz-template-plugin/jsjcy-kq-web": "^0.0.1-beta.1",
"@ibiz-template/command": "^0.0.1-beta.50",
"@ibiz-template/controller": "^0.0.1-beta.69",
"@ibiz-template/core": "^0.0.1-beta.69",
"@ibiz-template/model": "^0.0.1-beta.69",
"@ibiz-template/runtime": "^0.0.1-beta.69",
"@ibiz-template/service": "^0.0.1-beta.69",
"@ibiz-template/theme": "^0.0.1-beta.69",
"@ibiz-template/vue-util": "^0.0.1-beta.69",
"@ibiz/dynamic-model-api": "^2.1.17",
"@riophae/vue-treeselect": "^0.4.0",
"dayjs": "^1.11.7",
"echarts": "^5.4.2",
"element-ui": "^2.15.13",
"lodash-es": "^4.17.21",
"path-browserify": "^1.0.1",
"pinia": "^2.0.28",
"qs": "^6.11.0",
"qx-util": "^0.4.8",
"ramda": "^0.28.0",
"view-design": "^4.7.0",
"vite-plugin-style-import": "1.4.1",
"vue": "^2.7.14",
"vue-router": "^3.6.5"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@types/lodash-es": "^4.17.7",
"@types/node": "^18.11.15",
"@types/path-browserify": "^1.0.0",
"@types/qs": "^6.9.7",
"@types/ramda": "^0.28.20",
"@types/systemjs": "^6.13.0",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"@vitejs/plugin-legacy": "^3.0.1",
"@vitejs/plugin-vue2": "^2.2.0",
"@vitejs/plugin-vue2-jsx": "^1.1.0",
"@vue/babel-helper-vue-jsx-merge-props": "^1.4.0",
"eslint": "^8.29.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.8.0",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"postcss": "^8.4.21",
"postcss-scss": "^4.0.6",
"prettier": "^2.8.7",
"rollup-plugin-visualizer": "^5.8.3",
"sass": "^1.56.2",
"stylelint": "^14.16.0",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recess-order": "^3.0.0",
"stylelint-config-standard": "^29.0.0",
"stylelint-config-standard-scss": "^6.1.0",
"stylelint-scss": "^4.3.0",
"terser": "^5.16.1",
"typescript": "^4.9.4",
"vite": "^4.2.1",
"vite-plugin-eslint": "^1.8.1",
"vue-eslint-parser": "^9.1.1",
"vue-tsc": "^1.2.0"
},
"lint-staged": {
"*.{ts,vue}": "eslint --fix",
"*.scss": "stylelint --custom-syntax=postcss-scss"
}
}
.am-pie-threed-echarts {
width: 100%;
height: 600px;
/* stylelint-disable-next-line selector-id-pattern */
#myChart {
width: 100%;
height: 100%;
}
}
import { defineComponent, ref, onMounted } from 'vue';
import * as am4core from '@amcharts/amcharts4/core';
import * as am4charts from '@amcharts/amcharts4/charts';
// eslint-disable-next-line camelcase
import am4themes_animated from '@amcharts/amcharts4/themes/animated';
import './am-pie-threed-echarts.scss';
export const AmPie3D = defineComponent({
name: 'Pie3D',
props: {
pieData: {
type: Array<IData>,
default: () => [],
},
},
setup(_props) {
const pieChart = ref(null);
onMounted(() => {
// Set theme
am4core.useTheme(am4themes_animated);
// Create chart instance
const chart = am4core.create('myChart', am4charts.PieChart3D);
// 角度
chart.angle = 50;
// 厚度
chart.depth = 20;
// Add data
chart.data = [
{
category: 'Lithuania',
value: 501.9,
sliced: true,
color: am4core.color('#F44336'),
},
{
category: 'Czechia',
value: 301.9,
sliced: true,
color: am4core.color('#4CAF50'),
},
{
category: 'Ireland',
value: 201.1,
sliced: true,
color: am4core.color('#2196F3'),
},
{
category: 'Germany',
value: 165.8,
sliced: true,
color: am4core.color('#FFC107'),
},
{
category: 'Australia',
value: 139.9,
sliced: true,
color: am4core.color('#9C27B0'),
},
{
category: 'Austria',
value: 128.3,
sliced: true,
},
{
category: 'UK',
value: 99,
sliced: true,
},
{
category: 'Belgium',
value: 60,
sliced: true,
},
{
category: 'The Netherlands',
value: 50,
sliced: true,
},
];
// Add and configure Series
const pieSeries = chart.series.push(new am4charts.PieSeries3D());
pieSeries.dataFields.value = 'value';
pieSeries.dataFields.category = 'category';
pieSeries.slices.template.stroke = am4core.color('#fff');
pieSeries.slices.template.strokeWidth = 2;
pieSeries.slices.template.strokeOpacity = 1;
// 设置图例
chart.legend = new am4charts.Legend();
chart.legend.position = 'right';
// 设置 isActive 属性为数据项的 sliced 属性
pieSeries.slices.template.propertyFields.isActive = 'sliced';
// 设置颜色字段为 "color"
pieSeries.slices.template.propertyFields.fill = 'color';
});
return {
pieChart,
};
},
render() {
return (
<div class='am-pie-threed-echarts'>
<div id='myChart' ref='pieChart' />
</div>
);
},
});
.chart-wrapper {
width: 100%;
height: 600px;
/* stylelint-disable-next-line selector-id-pattern */
#myChart {
width: 100%;
height: 100%;
}
}
/* eslint-disable no-unused-expressions */
import { defineComponent, ref, onMounted, watch } from 'vue';
import * as echarts from 'echarts';
import 'echarts-gl';
import './pie-threed-echarts.scss';
export const Pie3D = defineComponent({
name: 'Pie3D',
props: {
toption: {
type: Array<IData>,
default: () => [],
},
tdata: {
type: String,
default: '',
},
tname: {
type: String,
default: '',
},
isShow: {
type: Boolean,
default: true,
},
distance: {
type: Number,
default: 300,
},
alpha: {
type: Number,
default: 40,
},
autoRotate: {
type: Boolean,
default: false,
},
},
setup(props) {
const pieChart = ref(null);
// 生成扇形的曲面参数方程,根据传入的
// startRatio(浮点数): 当前扇形起始比例,取值区间 [0, endRatio)
// endRatio(浮点数): 当前扇形结束比例,取值区间 (startRatio, 1]
// isSelected(布尔值):是否选中,效果参照二维饼图选中效果(单选)
// isHovered(布尔值): 是否放大,效果接近二维饼图高亮(放大)效果(未能实现阴影)
// k(0~1之间的浮点数):用于参数方程的一个参数,取值 0~1 之间,通过「内径/外径」的值换算而来。
function getParametricEquation(
startRatio: number,
endRatio: number,
isSelected: boolean,
isHovered: boolean,
k: number,
h: number,
) {
// 计算
const midRatio = (startRatio + endRatio) / 2;
const startRadian = startRatio * Math.PI * 2;
const endRadian = endRatio * Math.PI * 2;
const midRadian = midRatio * Math.PI * 2;
// 如果只有一个扇形,则不实现选中效果。
if (startRatio === 0 && endRatio === 1) {
// eslint-disable-next-line no-param-reassign
isSelected = false;
}
// 通过扇形内径/外径的值,换算出辅助参数 k(默认值 1/3)
// eslint-disable-next-line no-param-reassign
k = typeof k !== 'undefined' ? k : 1 / 3;
// 计算选中效果分别在 x 轴、y 轴方向上的位移(未选中,则位移均为 0)
const offsetX = isSelected ? Math.cos(midRadian) * 0.3 : 0;
const offsetY = isSelected ? Math.sin(midRadian) * 0.3 : 0;
// 计算高亮效果的放大比例(未高亮,则比例为 1)
const hoverRate = isHovered ? 1.05 : 1;
// 返回曲面参数方程
return {
u: {
min: -Math.PI,
max: Math.PI * 3,
step: Math.PI / 32,
},
v: {
min: 0,
max: Math.PI * 2,
step: Math.PI / 20,
},
x(u: number, v: number) {
if (u < startRadian) {
return (
offsetX +
Math.cos(startRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
if (u > endRadian) {
return (
offsetX + Math.cos(endRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
return offsetX + Math.cos(u) * (1 + Math.cos(v) * k) * hoverRate;
},
y(u: number, v: number) {
if (u < startRadian) {
return (
offsetY +
Math.sin(startRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
if (u > endRadian) {
return (
offsetY + Math.sin(endRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
return offsetY + Math.sin(u) * (1 + Math.cos(v) * k) * hoverRate;
},
z(u: number, v: number) {
if (u < -Math.PI * 0.5) {
return Math.sin(u);
}
if (u > Math.PI * 2.5) {
return Math.sin(u) * h * 0.1;
}
return Math.sin(v) > 0 ? 1 * h * 0.1 : -1;
},
};
}
// 生成模拟3d饼图的配置项
// 根据传入的
// pieData(object):饼图数据
// internalDiameterRatio(0~1之间的浮点数):内径/外径的值(默认值 1/2),当该值等于 0 时,为普通饼图
// 备注:饼图数据格式示意如下
// [{
// name: '数据1',
// value: 10
// }, {
// // 数据项名称
// name: '数据2',
// value : 56,
// itemStyle:{
// // 透明度
// opacity: 0.5,
// // 扇形颜色
// color: 'green'
// }
// }]
function getPie3D(pieData: IData[], internalDiameterRatio: number) {
const series = [];
let sumValue = 0;
let startValue = 0;
let endValue = 0;
const legendData = [];
const k =
typeof internalDiameterRatio !== 'undefined'
? (1 - internalDiameterRatio) / (1 + internalDiameterRatio)
: 1 / 3;
// 为每一个饼图数据,生成一个 series-surface 配置
for (let i = 0; i < pieData.length; i++) {
sumValue += pieData[i].value;
const seriesItem: IData = {
name:
typeof pieData[i].name === 'undefined'
? `series${i}`
: pieData[i].name,
type: 'surface',
parametric: true,
wireframe: {
show: false,
},
pieData: pieData[i],
pieStatus: {
selected: false,
hovered: false,
k,
},
};
if (typeof pieData[i].itemStyle !== 'undefined') {
const itemStyle: IData = {};
typeof pieData[i].itemStyle.color !== 'undefined'
? (itemStyle.color = pieData[i].itemStyle.color)
: null;
typeof pieData[i].itemStyle.opacity !== 'undefined'
? (itemStyle.opacity = pieData[i].itemStyle.opacity)
: null;
seriesItem.itemStyle = itemStyle;
}
series.push(seriesItem);
}
// 新增标签 series
const labelSeries: IData = {
name: 'labelSeries', // 自己根据场景修改
type: 'pie',
hoverAnimation: false, // 悬停不放大
label: {
position: 'outside',
formatter(params: IData) {
return `${params.name} ${params.value}`;
},
},
labelLine: {
showAbove: true,
length: 120, // 视觉引导线第一段的长度
length2: 50, // 视觉引导项第二段的长度
lineStyle: {
color: '#000', // 改变标示线的颜色
width: 1,
type: 'solid', // 线的类型
},
},
startAngle: -40, // 起始角度,支持范围[0, 360]。
clockwise: false, // 饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式
radius: ['50%', '50%'],
center: ['50%', '48%'],
data: [],
itemStyle: {
opacity: 1, // 这里必须是1,不然2d的图会覆盖在表面
},
};
// 使用上一次遍历时,计算出的数据和 sumValue,调用 getParametricEquation 函数,
// 向每个 series-surface 传入不同的参数方程 series-surface.parametricEquation,也就是实现每一个扇形。
for (let i = 0; i < series.length; i++) {
endValue = startValue + series[i].pieData.value;
series[i].pieData.startRatio = startValue / sumValue;
series[i].pieData.endRatio = endValue / sumValue;
series[i].parametricEquation = getParametricEquation(
series[i].pieData.startRatio,
series[i].pieData.endRatio,
true,
false,
k,
// series[i].pieData.value,
50,
);
startValue = endValue;
legendData.push(series[i].name);
// 判断增加 label 效果
labelSeries.data.push({
name: series[i].name,
value: series[i].pieData.value,
itemStyle: {
color: '#000',
},
});
}
// 补充一个透明的圆环,用于支撑高亮功能的近似实现。
series.push({
name: 'mouseoutSeries',
type: 'surface',
parametric: true,
wireframe: {
show: false,
},
itemStyle: {
opacity: 0,
},
parametricEquation: {
u: {
min: 0,
max: Math.PI * 2,
step: Math.PI / 20,
},
v: {
min: 0,
max: Math.PI,
step: Math.PI / 20,
},
x(u: number, v: number) {
return Math.sin(v) * Math.sin(u) + Math.sin(u);
},
y(u: number, v: number) {
return Math.sin(v) * Math.cos(u) + Math.cos(u);
},
z(u: number, v: number) {
return Math.cos(v) > 0 ? 0.1 : -0.1;
},
},
});
// 将 labelSeries 添加进去
series.push(labelSeries);
// 准备待返回的配置项,把准备好的 legendData、series 传入。
const option = {
// animation: false,
legend: {
orient: 'vertical',
data: legendData,
textStyle: {
color: '#000',
fontSize: 15,
},
itemWidth: 12,
itemHeight: 12,
icon: 'roundRect',
left: 'right',
top: '30%', // 居右显示
},
tooltip: {
formatter: (params: IData) => {
if (
params.seriesName !== 'mouseoutSeries' &&
params.seriesName !== 'labelSeries'
) {
return `${
params.seriesName
}<br/><span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${
params.color
};"></span>${option.series[params.seriesIndex].pieData.value}`;
}
},
},
xAxis3D: {
min: -1,
max: 1,
},
yAxis3D: {
min: -1,
max: 1,
},
zAxis3D: {
min: -1,
max: 1,
},
grid3D: {
show: false,
boxHeight: 10,
viewControl: {
// 3d效果可以放大、旋转等,请自己去查看官方配置
alpha: props.alpha,
rotateSensitivity: 0,
zoomSensitivity: 0,
panSensitivity: 0,
autoRotate: props.autoRotate, // 自动旋转
distance: props.distance,
},
// 后处理特效可以为画面添加高光、景深、环境光遮蔽(SSAO)、调色等效果。可以让整个画面更富有质感。
// postEffect: {
// // 配置这项会出现锯齿,请自己去查看官方配置有办法解决
// enable: true,
// bloom: {
// enable: true,
// bloomIntensity: 0.1,
// },
// SSAO: {
// enable: true,
// quality: 'medium',
// radius: 2,
// },
// },
},
series,
};
return option;
}
// 渲染echarts图
const initEcharts = () => {
if (pieChart.value) {
const myChart = echarts.init(pieChart.value);
// 传入数据生成 option
const option = getPie3D(props.toption, 0);
console.log(111, option);
myChart.setOption(option);
// // 监听鼠标事件,实现饼图选中效果(单选),近似实现高亮(放大)效果。
// let selectedIndex: '' | number = '';
// let hoveredIndex: '' | number = '';
// // 监听点击事件,实现选中效果(单选)
// myChart.on('click', function (params: IData) {
// // 从 option.series 中读取重新渲染扇形所需的参数,将是否选中取反。
// const isSelected =
// !option.series[params.seriesIndex].pieStatus.selected;
// const isHovered = option.series[params.seriesIndex].pieStatus.hovered;
// const k = option.series[params.seriesIndex].pieStatus.k;
// const startRatio =
// option.series[params.seriesIndex].pieData.startRatio;
// const endRatio = option.series[params.seriesIndex].pieData.endRatio;
// // 如果之前选中过其他扇形,将其取消选中(对 option 更新)
// if (selectedIndex !== '' && selectedIndex !== params.seriesIndex) {
// option.series[selectedIndex].parametricEquation =
// getParametricEquation(
// option.series[selectedIndex].pieData.startRatio,
// option.series[selectedIndex].pieData.endRatio,
// false,
// false,
// k,
// option.series[selectedIndex].pieData.value,
// );
// option.series[selectedIndex].pieStatus.selected = false;
// }
// option.series[params.seriesIndex].pieStatus.selected = isSelected;
// // 如果本次是选中操作,记录上次选中的扇形对应的系列号 seriesIndex
// isSelected ? (selectedIndex = params.seriesIndex) : null;
// // 对当前点击的扇形,执行选中/取消选中操作(对 option 更新)
// option.series[params.seriesIndex].parametricEquation =
// getParametricEquation(
// startRatio,
// endRatio,
// isSelected,
// isHovered,
// k,
// option.series[selectedIndex as number].pieData.value,
// );
// // 使用更新后的 option,渲染图表
// myChart.setOption(option);
// });
// // 准备重新渲染扇形所需的参数
// let isSelected;
// let isHovered;
// let startRatio;
// let endRatio;
// let k;
// // 监听 mouseover,近似实现高亮(放大)效果
// myChart.on('mouseover', function (params: IData) {
// // 如果触发 mouseover 的扇形当前已高亮,则不做操作
// if (hoveredIndex === params.seriesIndex) {
// // 否则进行高亮及必要的取消高亮操作
// } else {
// // 如果当前有高亮的扇形,取消其高亮状态(对 option 更新)
// if (hoveredIndex !== '') {
// // 从 option.series 中读取重新渲染扇形所需的参数,将是否高亮设置为 false。
// isSelected = option.series[hoveredIndex].pieStatus.selected;
// isHovered = false;
// startRatio = option.series[hoveredIndex].pieData.startRatio;
// endRatio = option.series[hoveredIndex].pieData.endRatio;
// k = option.series[hoveredIndex].pieStatus.k;
// // 对当前点击的扇形,执行取消高亮操作(对 option 更新)
// option.series[hoveredIndex].parametricEquation =
// getParametricEquation(
// startRatio,
// endRatio,
// isSelected,
// isHovered,
// k,
// option.series[hoveredIndex].pieData.value,
// );
// option.series[hoveredIndex].pieStatus.hovered = isHovered;
// // 将此前记录的上次选中的扇形对应的系列号 seriesIndex 清空
// hoveredIndex = '';
// }
// // 如果触发 mouseover 的扇形不是透明圆环,将其高亮(对 option 更新)
// if (params.seriesName !== 'mouseoutSeries') {
// // 从 option.series 中读取重新渲染扇形所需的参数,将是否高亮设置为 true。
// isSelected = option.series[params.seriesIndex].pieStatus.selected;
// isHovered = true;
// startRatio = option.series[params.seriesIndex].pieData.startRatio;
// endRatio = option.series[params.seriesIndex].pieData.endRatio;
// k = option.series[params.seriesIndex].pieStatus.k;
// // 对当前点击的扇形,执行高亮操作(对 option 更新)
// option.series[params.seriesIndex].parametricEquation =
// getParametricEquation(
// startRatio,
// endRatio,
// isSelected,
// isHovered,
// k,
// option.series[params.seriesIndex].pieData.value + 5,
// );
// option.series[params.seriesIndex].pieStatus.hovered = isHovered;
// // 记录上次高亮的扇形对应的系列号 seriesIndex
// hoveredIndex = params.seriesIndex;
// }
// // 使用更新后的 option,渲染图表
// myChart.setOption(option);
// }
// });
// // 修正取消高亮失败的 bug
// myChart.on('globalout', function () {
// if (hoveredIndex !== '') {
// // 从 option.series 中读取重新渲染扇形所需的参数,将是否高亮设置为 true。
// isSelected = option.series[hoveredIndex].pieStatus.selected;
// isHovered = false;
// k = option.series[hoveredIndex].pieStatus.k;
// startRatio = option.series[hoveredIndex].pieData.startRatio;
// endRatio = option.series[hoveredIndex].pieData.endRatio;
// // 对当前点击的扇形,执行取消高亮操作(对 option 更新)
// option.series[hoveredIndex].parametricEquation =
// getParametricEquation(
// startRatio,
// endRatio,
// isSelected,
// isHovered,
// k,
// option.series[hoveredIndex].pieData.value,
// );
// option.series[hoveredIndex].pieStatus.hovered = isHovered;
// // 将此前记录的上次选中的扇形对应的系列号 seriesIndex 清空
// hoveredIndex = '';
// }
// // 使用更新后的 option,渲染图表
// myChart.setOption(option);
// });
}
};
watch(
() => props.toption,
_newVal => {
initEcharts();
},
);
onMounted(() => {
initEcharts();
});
window.addEventListener('resize', () => {
if (document.getElementById('myChart')) {
const chart = echarts.getInstanceByDom(
document.getElementById('myChart')!,
);
chart?.resize();
}
});
return {
pieChart,
getPie3D,
getParametricEquation,
};
},
render() {
return (
<div class='chart-wrapper'>
<div id='myChart' ref='pieChart' />
</div>
);
},
});
import { VueConstructor } from 'vue';
import { PluginFactory } from './plugin';
export default {
install(_v: VueConstructor) {
// 自定义插件注入
const plugin = ibiz.plugin as PluginFactory;
plugin.appPlugins.push('@ibiz-template-plugin/sy-web@0.0.1');
},
};
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册