Parcourir la source

refactor: 使用repeating-conic-gradient简化代码

Burt il y a 2 ans
Parent
commit
ad7b990413
1 fichiers modifiés avec 4 ajouts et 7 suppressions
  1. 4 7
      src/pages/lottery/big-wheel.vue

+ 4 - 7
src/pages/lottery/big-wheel.vue

@@ -85,13 +85,10 @@ const totalRunAngle = computed(() => {
 
 // 计算绘制转盘背景
 const bgColor = (() => {
-  const _len = prizeList.length
-  const colorList = ['#5352b3', '#363589']
-  let colorVal = ''
-  for (let i = 0; i < _len; i++) {
-    colorVal += `${colorList[i % 2]} ${rotateAngle.value * i}deg ${rotateAngle.value * (i + 1)}deg,`
-  }
-  return `background: conic-gradient(${colorVal.slice(0, -1)});`
+  const [c1, c2] = ['#5352b3', '#363589']
+  // repeating-conic-gradient(red 0 15deg, blue  15deg 30deg);
+  return `background: repeating-conic-gradient(${c1} 0 ${rotateAngle.value}deg,
+  ${c2} ${rotateAngle.value}deg ${2 * rotateAngle.value}deg);`
 })()
 
 const styleObj = ref(bgColor)