index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../cell-group/index': {
  6. type: 'parent',
  7. },
  8. },
  9. properties: {
  10. prefixCls: {
  11. type: String,
  12. value: 'wux-cell',
  13. },
  14. disabled: {
  15. type: Boolean,
  16. value: false,
  17. },
  18. hoverClass: {
  19. type: String,
  20. value: 'default',
  21. },
  22. hoverStopPropagation: {
  23. type: Boolean,
  24. value: false,
  25. },
  26. hoverStartTime: {
  27. type: Number,
  28. value: 20,
  29. },
  30. hoverStayTime: {
  31. type: Number,
  32. value: 70,
  33. },
  34. lang: {
  35. type: String,
  36. value: 'en',
  37. },
  38. sessionFrom: {
  39. type: String,
  40. value: '',
  41. },
  42. sendMessageTitle: {
  43. type: String,
  44. value: '',
  45. },
  46. sendMessagePath: {
  47. type: String,
  48. value: '',
  49. },
  50. sendMessageImg: {
  51. type: String,
  52. value: '',
  53. },
  54. showMessageCard: {
  55. type: Boolean,
  56. value: false,
  57. },
  58. appParameter: {
  59. type: String,
  60. value: '',
  61. },
  62. thumb: {
  63. type: String,
  64. value: '',
  65. },
  66. title: {
  67. type: String,
  68. value: '',
  69. },
  70. label: {
  71. type: String,
  72. value: '',
  73. },
  74. extra: {
  75. type: String,
  76. value: '',
  77. },
  78. isLink: {
  79. type: Boolean,
  80. value: false,
  81. },
  82. openType: {
  83. type: String,
  84. value: 'navigateTo',
  85. },
  86. url: {
  87. type: String,
  88. value: '',
  89. },
  90. delta: {
  91. type: Number,
  92. value: 1,
  93. },
  94. },
  95. data: {
  96. isLast: false,
  97. },
  98. computed: {
  99. classes() {
  100. const { prefixCls, hoverClass, isLast, isLink, disabled } = this.data
  101. const wrap = classNames(prefixCls, {
  102. [`${prefixCls}--last`]: isLast,
  103. [`${prefixCls}--access`]: isLink,
  104. [`${prefixCls}--disabled`]: disabled,
  105. })
  106. const hd = `${prefixCls}__hd`
  107. const thumb = `${prefixCls}__thumb`
  108. const bd = `${prefixCls}__bd`
  109. const text = `${prefixCls}__text`
  110. const desc = `${prefixCls}__desc`
  111. const ft = `${prefixCls}__ft`
  112. const hover = hoverClass && hoverClass !== 'default' ? hoverClass : `${prefixCls}--hover`
  113. return {
  114. wrap,
  115. hd,
  116. thumb,
  117. bd,
  118. text,
  119. desc,
  120. ft,
  121. hover,
  122. }
  123. },
  124. },
  125. methods: {
  126. onTap() {
  127. if (!this.data.disabled) {
  128. this.triggerEvent('click')
  129. this.linkTo()
  130. }
  131. },
  132. bindgetuserinfo(e) {
  133. this.triggerEvent('getuserinfo', e.detail)
  134. },
  135. bindcontact(e) {
  136. this.triggerEvent('contact', e.detail)
  137. },
  138. bindgetphonenumber(e) {
  139. this.triggerEvent('getphonenumber', e.detail)
  140. },
  141. bindopensetting(e) {
  142. this.triggerEvent('opensetting', e.detail)
  143. },
  144. onError(e) {
  145. this.triggerEvent('error', e.detail)
  146. },
  147. linkTo() {
  148. const { url, isLink, openType, delta } = this.data
  149. const navigate = [
  150. 'navigateTo',
  151. 'redirectTo',
  152. 'switchTab',
  153. 'navigateBack',
  154. 'reLaunch',
  155. ]
  156. // openType 属性可选值为 navigateTo、redirectTo、switchTab、navigateBack、reLaunch
  157. if (!isLink || !url || !navigate.includes(openType)) {
  158. return false
  159. } else if (openType === 'navigateBack') {
  160. return wx[openType].call(wx, { delta })
  161. } else {
  162. return wx[openType].call(wx, { url })
  163. }
  164. },
  165. updateIsLastElement(isLast) {
  166. this.setData({ isLast })
  167. },
  168. },
  169. })