Ver código fonte

refactor(portraitManagement): 重构五边形组组件边框渲染逻辑

合并四边渐变和路径为单个渐变与路径,移除冗余的边渲染函数,简化代码
huoyi 1 mês atrás
pai
commit
d05d12ca71

+ 9 - 61
src/views/portraitManagement/components/PentagonGroup.vue

@@ -8,28 +8,17 @@
8 8
     >
9 9
       <svg class="pentagon-svg" viewBox="0 0 300 200" preserveAspectRatio="none">
10 10
         <defs>
11
-          <linearGradient :id="`topGradient-${index}`" x1="0%" y1="0%" x2="100%" y2="0%">
12
-            <stop offset="0%" :stop-color="item.edgeGradients?.top?.start || '#0f46fa'" />
13
-            <stop offset="100%" :stop-color="item.edgeGradients?.top?.end || '#bd03fb'" />
14
-          </linearGradient>
15
-          <linearGradient :id="`rightGradient-${index}`" x1="0%" y1="0%" x2="0%" y2="100%">
16
-            <stop offset="0%" :stop-color="item.edgeGradients?.right?.start || '#bd03fb'" />
17
-            <stop offset="100%" :stop-color="item.edgeGradients?.right?.end || '#0f46fa'" />
18
-          </linearGradient>
19
-          <linearGradient :id="`bottomGradient-${index}`" x1="100%" y1="0%" x2="0%" y2="0%">
20
-            <stop offset="0%" :stop-color="item.edgeGradients?.bottom?.start || '#0f46fa'" />
21
-            <stop offset="100%" :stop-color="item.edgeGradients?.bottom?.end || '#bd03fb'" />
22
-          </linearGradient>
23
-          <linearGradient :id="`leftGradient-${index}`" x1="0%" y1="100%" x2="0%" y2="0%">
24
-            <stop offset="0%" :stop-color="item.edgeGradients?.left?.start || '#bd03fb'" />
25
-            <stop offset="100%" :stop-color="item.edgeGradients?.left?.end || '#0f46fa'" />
26
-          </linearGradient>
27 11
           <linearGradient :id="`bgGradient-${index}`" x1="0%" y1="0%" x2="100%" y2="100%">
28 12
             <stop offset="0%" :stop-color="item.bgGradientStart || 'rgba(33,33,58,0.95)'" />
29 13
             <stop offset="100%" :stop-color="item.bgGradientEnd || 'rgba(15,70,250,0.15)'" />
30 14
           </linearGradient>
15
+          <linearGradient :id="`borderGradient-${index}`" x1="0%" y1="0%" x2="100%" y2="100%">
16
+            <stop offset="0%" :stop-color="item.edgeGradients?.top?.start || '#0f46fa'" />
17
+            <stop offset="50%" :stop-color="item.edgeGradients?.right?.start || '#bd03fb'" />
18
+            <stop offset="100%" :stop-color="item.edgeGradients?.bottom?.start || '#7eff7e'" />
19
+          </linearGradient>
31 20
           <filter :id="`glow-${index}`">
32
-            <feGaussianBlur stdDeviation="3" result="coloredBlur" />
21
+            <feGaussianBlur stdDeviation="2" result="coloredBlur" />
33 22
             <feMerge>
34 23
               <feMergeNode in="coloredBlur" />
35 24
               <feMergeNode in="SourceGraphic" />
@@ -41,30 +30,9 @@
41 30
           :fill="`url(#bgGradient-${index})`"
42 31
         />
43 32
         <path
44
-          :d="getTopEdge(item.vertices, item.isMiddle, index)"
45
-          :fill="none"
46
-          :stroke="`url(#topGradient-${index})`"
47
-          stroke-width="3"
48
-          :filter="`url(#glow-${index})`"
49
-        />
50
-        <path
51
-          :d="getRightEdge(item.vertices, item.isMiddle, index)"
52
-          :fill="none"
53
-          :stroke="`url(#rightGradient-${index})`"
54
-          stroke-width="3"
55
-          :filter="`url(#glow-${index})`"
56
-        />
57
-        <path
58
-          :d="getBottomEdge(item.vertices, item.isMiddle, index)"
59
-          :fill="none"
60
-          :stroke="`url(#bottomGradient-${index})`"
61
-          stroke-width="3"
62
-          :filter="`url(#glow-${index})`"
63
-        />
64
-        <path
65
-          :d="getLeftEdge(item.vertices, item.isMiddle, index)"
66
-          :fill="none"
67
-          :stroke="`url(#leftGradient-${index})`"
33
+          :d="getQuadPath(item.vertices, item.isMiddle, index)"
34
+          fill="none"
35
+          :stroke="`url(#borderGradient-${index})`"
68 36
           stroke-width="3"
69 37
           :filter="`url(#glow-${index})`"
70 38
         />
@@ -137,26 +105,6 @@ const getQuadPath = (vertices, isMiddle, index) => {
137 105
   const v = getVertices(vertices, isMiddle, index)
138 106
   return `M ${v.topLeft.x} ${v.topLeft.y} L ${v.topRight.x} ${v.topRight.y} L ${v.bottomRight.x} ${v.bottomRight.y} L ${v.bottomLeft.x} ${v.bottomLeft.y} Z`
139 107
 }
140
-
141
-const getTopEdge = (vertices, isMiddle, index) => {
142
-  const v = getVertices(vertices, isMiddle, index)
143
-  return `M ${v.topLeft.x} ${v.topLeft.y} L ${v.topRight.x} ${v.topRight.y}`
144
-}
145
-
146
-const getRightEdge = (vertices, isMiddle, index) => {
147
-  const v = getVertices(vertices, isMiddle, index)
148
-  return `M ${v.topRight.x} ${v.topRight.y} L ${v.bottomRight.x} ${v.bottomRight.y}`
149
-}
150
-
151
-const getBottomEdge = (vertices, isMiddle, index) => {
152
-  const v = getVertices(vertices, isMiddle, index)
153
-  return `M ${v.bottomRight.x} ${v.bottomRight.y} L ${v.bottomLeft.x} ${v.bottomLeft.y}`
154
-}
155
-
156
-const getLeftEdge = (vertices, isMiddle, index) => {
157
-  const v = getVertices(vertices, isMiddle, index)
158
-  return `M ${v.bottomLeft.x} ${v.bottomLeft.y} L ${v.topLeft.x} ${v.topLeft.y}`
159
-}
160 108
 </script>
161 109
 
162 110
 <style lang="scss" scoped>