link.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 && !['navigateBack', 'exit'].includes(navigatorProps.openType)) ||
  59. disabled) {
  60. classList.push(`${name}--disabled`);
  61. }
  62. this.setData({
  63. className: classList.join(' '),
  64. });
  65. },
  66. onSuccess(e) {
  67. this.triggerEvent('success', e);
  68. },
  69. onFail(e) {
  70. this.triggerEvent('fail', e);
  71. },
  72. onComplete(e) {
  73. this.triggerEvent('complete', e);
  74. },
  75. };
  76. }
  77. };
  78. Link = __decorate([
  79. wxComponent()
  80. ], Link);
  81. export default Link;