From cd1cdef0c1d99ddbf2d2bd22082d610fdccff487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 26 Jul 2019 12:01:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=A4=B4=E5=83=8F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6;badge=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/avatar/index.js | 78 ----------------------------- src/avatar/index.wc | 116 +++++++++++++++++++++++++++++++++++++++----- src/badge/index.wc | 18 +++++++ 3 files changed, 121 insertions(+), 91 deletions(-) delete mode 100644 src/avatar/index.js diff --git a/src/avatar/index.js b/src/avatar/index.js deleted file mode 100644 index 5c849bc..0000000 --- a/src/avatar/index.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * - * @authors yutent (yutent@doui.cc) - * @date 2017-03-17 20:55:57 - * - */ - -'use strict' - -function arraySum(arr) { - var sum = 0 - arr.forEach(function(it) { - sum += +it - }) - return sum -} - -// 1216fc0c668c09ade029ceae6db87f97cf560e21 -export const create = (hash, size) => { - if (!hash) return this.defafultImg - - if (!size || size < 100) { - size = 100 - } - - var cv = document.createElement('canvas'), - ct = cv.getContext('2d'), - bg = hash.slice(-3), - color = hash.slice(-9, -6), - fixColor = color, - lens = hash.slice(0, 8).match(/([\w]{1})/g), - pos1 = hash.slice(8, 16).match(/([\w]{1})/g), - pos2 = hash.slice(16, 24).match(/([\w]{1})/g), - step = size / 10 - - cv.width = size - cv.height = size - - lens = lens.map(c => { - c = parseInt(c, 16) - return c % 8 - }) - pos1 = pos1.map(c => { - c = parseInt(c, 16) - return c % 4 - }) - pos2 = pos2.map(c => { - c = parseInt(c, 16) - return c % 4 - }) - fixColor = arraySum(lens) > 32 ? bg : color - - ct.fillStyle = '#' + bg - ct.fillRect(0, 0, size, size) - - for (var i = 1; i < 9; i++) { - var xl = lens[i - 1], - xp1 = pos1[i - 1], - xp2 = pos2[i - 1] - - if (xl + xp1 > 8) { - xl = 8 - xp1 - } - ct.fillStyle = '#' + color - ct.fillRect((xp1 + 1) * step, i * step, xl * step, step) - - ct.fillStyle = '#' + color - ct.fillRect((9 - xp1 - xl) * step, i * step, xl * step, step) - - ct.fillStyle = '#' + fixColor - ct.fillRect((xp2 + 1) * step, i * step, step, step) - - ct.fillStyle = '#' + fixColor - ct.fillRect((8 - xp2) * step, i * step, step, step) - } - - return cv.toDataURL() -} diff --git a/src/avatar/index.wc b/src/avatar/index.wc index cbc9c35..2241413 100644 --- a/src/avatar/index.wc +++ b/src/avatar/index.wc @@ -14,8 +14,7 @@ line-height: 1; font-size: var(--size, 32px); border-radius: 4px; - background: nth($cp, 2); - color: nth($cd, 1); + color: #fff; user-select: none; -moz-user-select: none; @@ -40,6 +39,28 @@ } } +:host([color='red']) { + background: #ff5061; +} +:host([color='teal']) { + background: #3fc2a7; +} +:host([color='purple']) { + background: #ac61ce; +} +:host([color='green']) { + background: #58d68d; +} +:host([color='orange']) { + background: #ffb618; +} +:host([color='dark']) { + background: #62778d; +} +:host([color='blue']) { + background: #66b1ff; +} + :host([size='large']) { width: 50px; height: 50px; @@ -64,6 +85,82 @@