From 352a97d5c155c9635ef1ca11b569dabb09730798 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?=
 <1262327911@qq.com>
Date: Mon, 19 Sep 2022 17:32:19 +0800
Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=BB=A4=E9=95=9C?=
 =?UTF-8?q?=E6=A8=A1=E7=B3=8A=E9=97=AE=E9=A2=98=EF=BC=8C=E9=BB=98=E8=AE=A4?=
 =?UTF-8?q?=E4=B8=8D=E5=BC=80=E5=90=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/components/Pages/ChartItemSetting/StylesSetting.vue | 6 ++++++
 src/packages/index.d.ts                                 | 4 ++++
 src/packages/public/publicConfig.ts                     | 2 ++
 src/store/modules/chartEditStore/chartEditStore.d.ts    | 2 ++
 src/store/modules/chartEditStore/chartEditStore.ts      | 2 ++
 src/utils/style.ts                                      | 3 ++-
 src/views/chart/ContentEdit/index.vue                   | 9 +++++++--
 src/views/preview/index.vue                             | 2 +-
 8 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/components/Pages/ChartItemSetting/StylesSetting.vue b/src/components/Pages/ChartItemSetting/StylesSetting.vue
index f14076b8..bf63eab8 100644
--- a/src/components/Pages/ChartItemSetting/StylesSetting.vue
+++ b/src/components/Pages/ChartItemSetting/StylesSetting.vue
@@ -5,6 +5,9 @@
   </div>
 
   <collapse-item :name="isCanvas ? '滤镜' : '滤镜 / 变换'">
+    <template #header>
+      <n-switch v-if="isCanvas" v-model:value="chartStyles.filterShow" size="small"></n-switch>
+    </template>
     <setting-item-box name="色相" :alone="true">
       <setting-item :name="`值:${chartStyles.hueRotate}deg`">
         <!-- 透明度 -->
@@ -121,6 +124,9 @@
         ></n-input-number>
       </setting-item>
     </setting-item-box>
+
+    <!-- 提示 -->
+    <n-tag v-show="isCanvas" type="warning"> 若预览时大屏模糊,可以尝试关闭滤镜进行修复 </n-tag>
   </collapse-item>
 </template>
 
diff --git a/src/packages/index.d.ts b/src/packages/index.d.ts
index 4333373a..04931c06 100644
--- a/src/packages/index.d.ts
+++ b/src/packages/index.d.ts
@@ -38,6 +38,9 @@ interface EchartsDataType {
 
 // 滤镜/变换枚举
 export enum FilterEnum {
+  // 是否启用
+  FILTERS_SHOW = 'filterShow',
+
   // 透明度
   OPACITY = 'opacity',
   // 饱和度
@@ -65,6 +68,7 @@ export interface PublicConfigType {
   isGroup: boolean
   attr: { x: number; y: number; w: number; h: number; zIndex: number; offsetX: number; offsetY: number; }
   styles: {
+    [FilterEnum.FILTERS_SHOW]: boolean
     [FilterEnum.OPACITY]: number
     [FilterEnum.SATURATE]: number
     [FilterEnum.CONTRAST]: number
diff --git a/src/packages/public/publicConfig.ts b/src/packages/public/publicConfig.ts
index 30122bed..ddcc2056 100644
--- a/src/packages/public/publicConfig.ts
+++ b/src/packages/public/publicConfig.ts
@@ -43,6 +43,8 @@ export class PublicConfigClass implements PublicConfigType {
   public attr = { ...chartInitConfig, zIndex: -1 }
   // 基本样式
   public styles = {
+    // 使用滤镜
+    filterShow: true,
     // 色相
     hueRotate: 0,
     // 饱和度
diff --git a/src/store/modules/chartEditStore/chartEditStore.d.ts b/src/store/modules/chartEditStore/chartEditStore.d.ts
index 1defbb77..b0748378 100644
--- a/src/store/modules/chartEditStore/chartEditStore.d.ts
+++ b/src/store/modules/chartEditStore/chartEditStore.d.ts
@@ -59,6 +59,8 @@ export enum EditCanvasConfigEnum {
 }
 
 export interface EditCanvasConfigType {
+  // 滤镜-启用
+  [FilterEnum.FILTERS_SHOW]: boolean
   // 滤镜-色相
   [FilterEnum.HUE_ROTATE]: number
   // 滤镜-饱和度
diff --git a/src/store/modules/chartEditStore/chartEditStore.ts b/src/store/modules/chartEditStore/chartEditStore.ts
index bd2f70ba..d2cd8d8f 100644
--- a/src/store/modules/chartEditStore/chartEditStore.ts
+++ b/src/store/modules/chartEditStore/chartEditStore.ts
@@ -79,6 +79,8 @@ export const useChartEditStore = defineStore({
       width: 1920,
       // 默认高度
       height: 1080,
+      // 启用滤镜
+      filterShow: false,
       // 色相
       hueRotate: 0,
       // 饱和度
diff --git a/src/utils/style.ts b/src/utils/style.ts
index c692fdc4..d8bc200c 100644
--- a/src/utils/style.ts
+++ b/src/utils/style.ts
@@ -15,7 +15,8 @@ export const animationsClass = (animations: string[]) => {
 }
 
 // * 滤镜
-export const getFilterStyle = (styles: StylesType | EditCanvasConfigType) => {
+export const getFilterStyle = (styles?: StylesType | EditCanvasConfigType) => {
+  if(!styles) return {}
   const { opacity, saturate, contrast, hueRotate, brightness } = styles
   return {
     opacity: opacity,
diff --git a/src/views/chart/ContentEdit/index.vue b/src/views/chart/ContentEdit/index.vue
index 25e4d173..9043444d 100644
--- a/src/views/chart/ContentEdit/index.vue
+++ b/src/views/chart/ContentEdit/index.vue
@@ -19,7 +19,7 @@
         <!-- 滤镜预览 -->
         <div
           :style="{
-            ...getFilterStyle(chartEditStore.getEditCanvasConfig),
+            ...getFilterStyle(filterShow ? chartEditStore.getEditCanvasConfig : undefined),
             ...rangeStyle
           }"
         >
@@ -54,7 +54,7 @@
                 :themeColor="themeColor"
                 :style="{
                   ...useSizeStyle(item.attr),
-                  ...getFilterStyle(item.styles),
+                  ...getFilterStyle(filterShow ? item.styles : undefined),
                   ...getTransformStyle(item.styles)
                 }"
               ></component>
@@ -146,6 +146,11 @@ const themeColor = computed(() => {
   return chartColors[chartThemeColor]
 })
 
+// 是否展示渲染
+const filterShow = computed(() => {
+  return chartEditStore.getEditCanvasConfig.filterShow
+})
+
 // 背景
 const rangeStyle = computed(() => {
   // 设置背景色和图片背景
diff --git a/src/views/preview/index.vue b/src/views/preview/index.vue
index fbe74eca..75431eb7 100644
--- a/src/views/preview/index.vue
+++ b/src/views/preview/index.vue
@@ -42,7 +42,7 @@ const localStorageInfo: ChartEditStorageType = getSessionStorageInfo() as ChartE
 const previewRefStyle = computed(() => {
   return {
     ...getEditCanvasConfigStyle(localStorageInfo.editCanvasConfig),
-    ...getFilterStyle(localStorageInfo.editCanvasConfig)
+    ...getFilterStyle(localStorageInfo.editCanvasConfig.filterShow ? localStorageInfo.editCanvasConfig : undefined)
   }
 })