index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const warn = (msg, getValue) => {
  2. console.warn(msg);
  3. console.log('接受到的值为:', getValue);
  4. };
  5. Component({
  6. externalClasses: ['i-class'],
  7. options: {
  8. multipleSlots: true
  9. },
  10. relations: {
  11. '../cell-group/index': {
  12. type: 'parent'
  13. }
  14. },
  15. properties: {
  16. // 左侧标题
  17. title: {
  18. type: String
  19. },
  20. // 标题下方的描述信息
  21. label: {
  22. type: String
  23. },
  24. // 右侧内容
  25. value: {
  26. type: String
  27. },
  28. // 只有点击 footer 区域才触发 tab 事件
  29. onlyTapFooter: {
  30. type: Boolean
  31. },
  32. // 是否展示右侧箭头并开启尝试以 url 跳转
  33. isLink: {
  34. type: null,
  35. value: ''
  36. },
  37. // 链接类型,可选值为 navigateTo,redirectTo,switchTab,reLaunch
  38. linkType: {
  39. type: String,
  40. value: 'navigateTo'
  41. },
  42. url: {
  43. type: String,
  44. value: ''
  45. }
  46. },
  47. data: {
  48. isLastCell: true
  49. },
  50. methods: {
  51. navigateTo () {
  52. const { url } = this.data;
  53. const type = typeof this.data.isLink;
  54. this.triggerEvent('click', {});
  55. if (!this.data.isLink || !url || url === 'true' || url === 'false') return;
  56. if (type !== 'boolean' && type !== 'string') {
  57. warn('isLink 属性值必须是一个字符串或布尔值', this.data.isLink);
  58. return;
  59. }
  60. if (['navigateTo', 'redirectTo', 'switchTab', 'reLaunch'].indexOf(this.data.linkType) === -1) {
  61. warn('linkType 属性可选值为 navigateTo,redirectTo,switchTab,reLaunch', this.data.linkType);
  62. return;
  63. }
  64. wx[this.data.linkType].call(wx, {url});
  65. },
  66. handleTap () {
  67. if (!this.data.onlyTapFooter) {
  68. this.navigateTo();
  69. }
  70. },
  71. updateIsLastCell (isLastCell) {
  72. this.setData({ isLastCell });
  73. }
  74. }
  75. });