cell.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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}-cell`;
  13. let Cell = class Cell extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.externalClasses = [
  17. `${prefix}-class`,
  18. `${prefix}-class-title`,
  19. `${prefix}-class-description`,
  20. `${prefix}-class-note`,
  21. `${prefix}-class-hover`,
  22. `${prefix}-class-image`,
  23. `${prefix}-class-left`,
  24. `${prefix}-class-left-icon`,
  25. `${prefix}-class-center`,
  26. `${prefix}-class-right`,
  27. `${prefix}-class-right-icon`,
  28. ];
  29. this.relations = {
  30. '../cell-group/cell-group': {
  31. type: 'parent',
  32. },
  33. };
  34. this.options = {
  35. multipleSlots: true,
  36. };
  37. this.properties = props;
  38. this.data = {
  39. prefix,
  40. classPrefix: name,
  41. isLastChild: false,
  42. };
  43. this.observers = {
  44. leftIcon(v) {
  45. this.setIcon('_leftIcon', v, '');
  46. },
  47. rightIcon(v) {
  48. this.setIcon('_rightIcon', v, '');
  49. },
  50. arrow(v) {
  51. this.setIcon('_arrow', v, 'chevron-right');
  52. },
  53. };
  54. }
  55. setIcon(name, value, defaultValue) {
  56. this.setData({
  57. [name]: calcIcon(value, defaultValue),
  58. });
  59. }
  60. onClick(e) {
  61. this.triggerEvent('click', e.detail);
  62. this.jumpLink();
  63. }
  64. jumpLink(urlKey = 'url', link = 'jumpType') {
  65. const url = this.data[urlKey];
  66. const jumpType = this.data[link];
  67. if (url) {
  68. wx[jumpType]({ url });
  69. }
  70. }
  71. };
  72. Cell = __decorate([
  73. wxComponent()
  74. ], Cell);
  75. export default Cell;