link.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 { calcIcon } 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(v) {
  27. this.setData({
  28. _prefixIcon: calcIcon(v),
  29. });
  30. },
  31. suffixIcon(v) {
  32. this.setData({
  33. _suffixIcon: calcIcon(v),
  34. });
  35. },
  36. };
  37. this.lifetimes = {
  38. attached() {
  39. this.setClass();
  40. },
  41. };
  42. this.methods = {
  43. setClass() {
  44. const { theme, status, size, underline, navigatorProps } = this.properties;
  45. const classList = [name, `${name}--${status}-${theme}`, `${name}--${size}`];
  46. if (underline) {
  47. classList.push(`${name}--underline`);
  48. }
  49. if ((navigatorProps && !navigatorProps.url) || status === 'disabled') {
  50. classList.push(`${name}--disabled`);
  51. }
  52. this.setData({
  53. className: classList.join(' '),
  54. });
  55. },
  56. onSuccess(e) {
  57. this.triggerEvent('success', e);
  58. },
  59. onFail(e) {
  60. this.triggerEvent('fail', e);
  61. },
  62. onComplete(e) {
  63. this.triggerEvent('complete', e);
  64. },
  65. };
  66. }
  67. };
  68. Link = __decorate([
  69. wxComponent()
  70. ], Link);
  71. export default Link;