合伙人运营小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

icon.js 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  8. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  9. return new (P || (P = Promise))(function (resolve, reject) {
  10. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  11. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  12. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  13. step((generator = generator.apply(thisArg, _arguments || [])).next());
  14. });
  15. };
  16. import { SuperComponent, wxComponent } from '../common/src/index';
  17. import config from '../common/config';
  18. import props from './props';
  19. import { styles, addUnit, getRect } from '../common/utils';
  20. const { prefix } = config;
  21. const name = `${prefix}-icon`;
  22. let Icon = class Icon extends SuperComponent {
  23. constructor() {
  24. super(...arguments);
  25. this.externalClasses = [`${prefix}-class`];
  26. this.properties = props;
  27. this.data = {
  28. componentPrefix: prefix,
  29. classPrefix: name,
  30. isImage: false,
  31. iconStyle: undefined,
  32. };
  33. this.observers = {
  34. 'name, color, size, style'() {
  35. this.setIconStyle();
  36. },
  37. };
  38. this.methods = {
  39. onTap(event) {
  40. this.triggerEvent('click', event.detail);
  41. },
  42. setIconStyle() {
  43. return __awaiter(this, void 0, void 0, function* () {
  44. const { name, color, size, classPrefix } = this.data;
  45. const isImage = name.indexOf('/') !== -1;
  46. const sizeValue = addUnit(size);
  47. const colorStyle = color ? { color: color } : {};
  48. const fontStyle = size ? { 'font-size': sizeValue } : {};
  49. const iconStyle = Object.assign(Object.assign({}, colorStyle), fontStyle);
  50. if (isImage) {
  51. const { height } = yield getRect(this, `.${classPrefix}`);
  52. const iconSize = sizeValue || addUnit(height);
  53. iconStyle.width = iconSize;
  54. iconStyle.height = iconSize;
  55. }
  56. this.setData({
  57. isImage,
  58. iconStyle: `${styles(iconStyle)}`,
  59. });
  60. });
  61. },
  62. };
  63. }
  64. };
  65. Icon = __decorate([
  66. wxComponent()
  67. ], Icon);
  68. export default Icon;