"use strict";

/*
 * @Author: codingfly
 * @Description: 
 * @Date: 2021-10-12 11:39:33
 * @LastEditTime: 2021-10-12 13:08:20
 * @FilePath: \ui_model\src\icon\other\wechat\wechat.js
 */
Component({
  properties: {
    // zhengque | fenge | tag | shouye | caidan | zanting | bofang | zhibozhong | shoucang1 | zan1 | shijian | zhuanlan | zhizhen | time | bukanjian | kanjian | jiankang | rili | zhibo | chuangzuo | yisheng | weixin | eye | zan | shoucang | shuaxin | tongzhi | home | yiyuan | keshi | mobile | left | filter | jia | album | biaoqing | voice | xiangji | xingxing | tip | jianshao | zengjia | right | home-solid | monitor | notice | add | clear | clear2 | yes | search | down | loading2 | loading
    name: {
      type: String
    },
    // string | string[]
    color: {
      type: null,
      observer: function observer(color) {
        this.setData({
          colors: this.fixColor(),
          isStr: typeof color === 'string'
        });
      }
    },
    size: {
      type: Number,
      value: 18,
      observer: function observer(size) {
        this.setData({
          svgSize: size
        });
      }
    }
  },
  data: {
    colors: '',
    svgSize: 18,
    quot: '"',
    isStr: true
  },
  methods: {
    fixColor: function fixColor() {
      var color = this.data.color;
      var hex2rgb = this.hex2rgb;

      if (typeof color === 'string') {
        return color.indexOf('#') === 0 ? hex2rgb(color) : color;
      }

      return color.map(function (item) {
        return item.indexOf('#') === 0 ? hex2rgb(item) : item;
      });
    },
    hex2rgb: function hex2rgb(hex) {
      var rgb = [];
      hex = hex.substr(1);

      if (hex.length === 3) {
        hex = hex.replace(/(.)/g, '$1$1');
      }

      hex.replace(/../g, function (color) {
        rgb.push(parseInt(color, 0x10));
        return color;
      });
      return 'rgb(' + rgb.join(',') + ')';
    }
  }
});