Selaa lähdekoodia

新颜色算法

龚成明 3 vuotta sitten
vanhempi
commit
e182865233
1 muutettua tiedostoa jossa 7 lisäystä ja 4 poistoa
  1. 7 4
      src/plugins/kit/HashKit.js

+ 7 - 4
src/plugins/kit/HashKit.js

@@ -20,12 +20,15 @@ export default class HashKit {
 
   static generateColorByHash(hash) {
     const hashSub = hash.substring(2, 5)
-    let color = '#cbd'
+    let color = '#eee'
 
     if (hashSub !== 'eth') {
-      let bit1 = Math.max(parseInt(hashSub[0], 16), 9)
-      let bit2 = Math.max(parseInt(hashSub[1], 16), 9)
-      let bit3 = Math.max(parseInt(hashSub[2], 16), 9)
+      let bit1 = parseInt(hashSub[0], 16)
+      bit1 = bit1 < 8 ? bit1 + 8 : bit1
+      let bit2 = parseInt(hashSub[1], 16)
+      bit2 = bit2 < 8 ? bit2 + 8 : bit2
+      let bit3 = parseInt(hashSub[2], 16)
+      bit3 = bit3 < 8 ? bit3 + 8 : bit3
 
       color = '#' + bit1.toString(16) + bit2.toString(16) + bit3.toString(16)
     }