link.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. import { setIcon } from '../common/utils';
  11. const { prefix } = config;
  12. const name = `${prefix}-link`;
  13. let Link = class Link extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.externalClasses = [];
  17. this.properties = props;
  18. this.data = {
  19. prefix,
  20. classPrefix: name,
  21. };
  22. this.observers = {
  23. 'theme, status, size, underline, navigatorProps'() {
  24. this.setClass();
  25. },
  26. prefixIcon(prefixIcon) {
  27. const obj = setIcon('prefixIcon', prefixIcon, '');
  28. this.setData(Object.assign({}, obj));
  29. },
  30. suffixIcon(suffixIcon) {
  31. const obj = setIcon('suffixIcon', suffixIcon, '');
  32. this.setData(Object.assign({}, obj));
  33. },
  34. };
  35. this.lifetimes = {
  36. attached() {
  37. this.setClass();
  38. },
  39. };
  40. this.methods = {
  41. setClass() {
  42. const { theme, status, size, underline, navigatorProps } = this.properties;
  43. const classList = [name, `${name}--${status}-${theme}`, `${name}--${size}`];
  44. if (underline) {
  45. classList.push(`${name}--underline`);
  46. }
  47. if ((navigatorProps && !navigatorProps.url) || status === 'disabled') {
  48. classList.push(`${name}--disabled`);
  49. }
  50. this.setData({
  51. className: classList.join(' '),
  52. });
  53. },
  54. onSuccess(e) {
  55. this.triggerEvent('success', e);
  56. },
  57. onFail(e) {
  58. this.triggerEvent('fail', e);
  59. },
  60. onComplete(e) {
  61. this.triggerEvent('complete', e);
  62. },
  63. };
  64. }
  65. };
  66. Link = __decorate([
  67. wxComponent()
  68. ], Link);
  69. export default Link;