index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/libs/classNames'
  3. import { props } from './props'
  4. baseComponent({
  5. properties: props,
  6. computed: {
  7. classes: ['prefixCls, buttons', function(prefixCls, btns) {
  8. const wrap = classNames(prefixCls)
  9. const button = btns.map((button) => {
  10. const wrap = classNames(`${prefixCls}__button`, {
  11. [`${prefixCls}__button--disabled`]: button.disabled,
  12. [`${button.className}`]: button.className,
  13. })
  14. const hover = button.hoverClass && button.hoverClass !== 'default' ? button.hoverClass : `${prefixCls}__button--hover`
  15. return {
  16. wrap,
  17. hover,
  18. }
  19. })
  20. const bd = `${prefixCls}__bd`
  21. const icon = `${prefixCls}__icon`
  22. const title = `${prefixCls}__title`
  23. const buttons = `${prefixCls}__buttons`
  24. return {
  25. wrap,
  26. button,
  27. bd,
  28. icon,
  29. title,
  30. buttons,
  31. }
  32. }],
  33. },
  34. methods: {
  35. /**
  36. * 点击按钮触发事件
  37. */
  38. onTap(e) {
  39. const { buttons } = this.data
  40. const { index } = e.currentTarget.dataset
  41. const value = this.data.buttons[index]
  42. if (value.disabled) return
  43. this.triggerEvent('click', { index, value, buttons })
  44. },
  45. bindgetuserinfo(e) {
  46. this.triggerEvent('getuserinfo', {...e.detail, ...e.currentTarget.dataset })
  47. },
  48. bindcontact(e) {
  49. this.triggerEvent('contact', {...e.detail, ...e.currentTarget.dataset })
  50. },
  51. bindgetphonenumber(e) {
  52. this.triggerEvent('getphonenumber', {...e.detail, ...e.currentTarget.dataset })
  53. },
  54. bindopensetting(e) {
  55. this.triggerEvent('opensetting', {...e.detail, ...e.currentTarget.dataset })
  56. },
  57. bindlaunchapp(e) {
  58. this.triggerEvent('launchapp', {...e.detail, ...e.currentTarget.dataset })
  59. },
  60. bindchooseavatar(e) {
  61. this.triggerEvent('chooseavatar', {...e.detail, ...e.currentTarget.dataset })
  62. },
  63. onError(e) {
  64. this.triggerEvent('error', {...e.detail, ...e.currentTarget.dataset })
  65. },
  66. },
  67. })