From 43afd76610f859ceb63c06ff3a6eee5202c561c2 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 6 Feb 2024 12:00:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=BB=84=E9=87=91=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E9=A1=B9=E9=9A=8F=E6=9C=BA=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/generate-utils.ts | 26 ++++++++ src/views/perfManage/goldTarget/index.vue | 77 +++++++---------------- 2 files changed, 48 insertions(+), 55 deletions(-) create mode 100644 src/utils/generate-utils.ts diff --git a/src/utils/generate-utils.ts b/src/utils/generate-utils.ts new file mode 100644 index 00000000..57e009e5 --- /dev/null +++ b/src/utils/generate-utils.ts @@ -0,0 +1,26 @@ +/** + * 随机生成颜色代码 + * @returns #f716ed + */ +export function generateColorHEX(): string { + const str = Math.floor(Math.random() * (256 * 256 * 256 - 1)).toString(16); + return `#${str}`; +} + +// +/** + * 生成随机的 RGB 颜色 + * @returns rgb(24 144 255) / rgba(0,0,0,.85) + */ +export function generateColorRGBA(hasAlpha: boolean = false) { + const red = Math.floor(Math.random() * 256); + const green = Math.floor(Math.random() * 256); + const blue = Math.floor(Math.random() * 256); + + if (hasAlpha) { + const alpha = Math.floor(Math.random() * 100); + return `rgb(${red}, ${green}, ${blue}, 0.${alpha})`; + } + + return `rgb(${red}, ${green}, ${blue})`; +} diff --git a/src/views/perfManage/goldTarget/index.vue b/src/views/perfManage/goldTarget/index.vue index 3f3a84e2..434bc733 100644 --- a/src/views/perfManage/goldTarget/index.vue +++ b/src/views/perfManage/goldTarget/index.vue @@ -28,6 +28,7 @@ import { getKPITitle, listKPIData } from '@/api/perfManage/goldTarget'; import { parseDateToStr } from '@/utils/date-utils'; import { writeSheet } from '@/utils/execl-utils'; import saveAs from 'file-saver'; +import { generateColorRGBA } from '@/utils/generate-utils'; const neInfoStore = useNeInfoStore(); const { t, currentLocale } = useI18n(); @@ -335,58 +336,6 @@ function fnRanderChart() { observer.observe(container); } -/**面积颜色 */ -const areaStyleColor = [ - { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { - offset: 0, - color: 'rgba(22, 119, 255, .5)', - }, - { - offset: 1, - color: 'rgba(22, 119, 255, 0)', - }, - ]), - }, - { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { - offset: 0, - color: 'rgba(82, 196, 26, .5)', - }, - { - offset: 1, - color: 'rgba(82, 196, 26, 0)', - }, - ]), - }, - { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { - offset: 0, - color: 'rgba(250, 173, 20, .5)', - }, - { - offset: 1, - color: 'rgba(250, 173, 20, 0)', - }, - ]), - }, - { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { - offset: 0, - color: 'rgba(255, 77, 79, 0.5)', - }, - { - offset: 1, - color: 'rgba(255, 77, 79, 0)', - }, - ]), - }, -]; - /**图表数据渲染 */ function fnRanderChartData() { if (kpiChart.value == null && tableState.data.length <= 0) { @@ -408,15 +357,27 @@ function fnRanderChartData() { ) { continue; } + const color = generateColorRGBA(); yDatas.push({ name: `${columns.title}`, type: 'line', symbol: 'none', sampling: 'lttb', itemStyle: { - color: 'rgb(255, 70, 131)', + color: color, + }, + areaStyle: { + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ + { + offset: 0, + color: color.replace(')', ',0.8)'), + }, + { + offset: 1, + color: color.replace(')', ',0.3)'), + }, + ]), }, - areaStyle: areaStyleColor[i % columnsLen], data: [], }); tableColumnsKeyArr.push(`${columns.key}`); @@ -467,6 +428,12 @@ function fnRanderChartData() { color: '#646A73', }, icon: 'circle', + selected: { + // 选中'系列1' + 系列1: true, + // 不选中'系列2' + 系列2: false, + }, }, grid: { left: '10%', @@ -524,7 +491,7 @@ onMounted(() => { // 查询当前小时 const nowDate: Date = new Date(); nowDate.setMinutes(0, 0, 0); - queryRangePicker.value[0] = parseDateToStr(nowDate); + queryRangePicker.value[0] = '2024-01-30 00:00:00'; // parseDateToStr(nowDate); nowDate.setMinutes(59, 59, 59); queryRangePicker.value[1] = parseDateToStr(nowDate); fnGetListTitle();