link.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. `${prefix}-class`,
  18. `${prefix}-class-hover`,
  19. `${prefix}-class-prefix-icon`,
  20. `${prefix}-class-content`,
  21. `${prefix}-class-suffix-icon`,
  22. ];
  23. this.properties = props;
  24. this.options = {
  25. multipleSlots: true,
  26. };
  27. this.data = {
  28. prefix,
  29. classPrefix: name,
  30. };
  31. this.observers = {
  32. 'theme, status, size, underline, navigatorProps'() {
  33. this.setClass();
  34. },
  35. prefixIcon(v) {
  36. this.setData({
  37. _prefixIcon: calcIcon(v),
  38. });
  39. },
  40. suffixIcon(v) {
  41. this.setData({
  42. _suffixIcon: calcIcon(v),
  43. });
  44. },
  45. };
  46. this.lifetimes = {
  47. attached() {
  48. this.setClass();
  49. },
  50. };
  51. this.methods = {
  52. setClass() {
  53. const { theme, size, underline, navigatorProps, disabled } = this.properties;
  54. const classList = [name, `${name}--${theme}`, `${name}--${size}`];
  55. if (underline) {
  56. classList.push(`${name}--underline`);
  57. }
  58. if ((navigatorProps && !navigatorProps.url) || disabled) {
  59. classList.push(`${name}--disabled`);
  60. }
  61. this.setData({
  62. className: classList.join(' '),
  63. });
  64. },
  65. onSuccess(e) {
  66. this.triggerEvent('success', e);
  67. },
  68. onFail(e) {
  69. this.triggerEvent('fail', e);
  70. },
  71. onComplete(e) {
  72. this.triggerEvent('complete', e);
  73. },
  74. };
  75. }
  76. };
  77. Link = __decorate([
  78. wxComponent()
  79. ], Link);
  80. export default Link;