index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. const defaultIcon = {
  4. type: 'success',
  5. size: 93,
  6. color: '#33cd5f',
  7. }
  8. const getIcon = (icon) => {
  9. if (icon !== null && typeof icon === 'object') {
  10. return Object.assign({}, defaultIcon, icon)
  11. } else if (typeof icon === 'string') {
  12. return Object.assign({}, defaultIcon, {
  13. type: icon,
  14. })
  15. }
  16. return defaultIcon
  17. }
  18. baseComponent({
  19. properties: {
  20. prefixCls: {
  21. type: String,
  22. value: 'wux-result',
  23. },
  24. icon: {
  25. type: null,
  26. value: defaultIcon,
  27. observer(newVal) {
  28. this.setData({
  29. resultIcon: getIcon(newVal),
  30. })
  31. },
  32. },
  33. title: {
  34. type: String,
  35. value: '',
  36. },
  37. label: {
  38. type: String,
  39. value: '',
  40. },
  41. buttons: {
  42. type: Array,
  43. value: [],
  44. },
  45. extra: {
  46. type: String,
  47. value: '',
  48. },
  49. fixed: {
  50. type: Boolean,
  51. value: false,
  52. },
  53. },
  54. data: {
  55. resultIcon: null,
  56. },
  57. computed: {
  58. classes() {
  59. const { prefixCls, fixed } = this.data
  60. const wrap = classNames(prefixCls, {
  61. [`${prefixCls}--fixed`]: fixed,
  62. })
  63. const hd = `${prefixCls}__hd`
  64. const icon = `${prefixCls}__icon`
  65. const bd = `${prefixCls}__bd`
  66. const title = `${prefixCls}__title`
  67. const desc = `${prefixCls}__desc`
  68. const buttons = `${prefixCls}__buttons`
  69. const ft = `${prefixCls}__ft`
  70. return {
  71. wrap,
  72. hd,
  73. icon,
  74. bd,
  75. title,
  76. desc,
  77. buttons,
  78. ft,
  79. }
  80. },
  81. },
  82. methods: {
  83. onClick(e) {
  84. this.triggerEvent('click', e.currentTarget.dataset)
  85. },
  86. bindgetuserinfo(e) {
  87. this.triggerEvent('getuserinfo', {...e.detail, ...e.currentTarget.dataset })
  88. },
  89. bindcontact(e) {
  90. this.triggerEvent('contact', {...e.detail, ...e.currentTarget.dataset })
  91. },
  92. bindgetphonenumber(e) {
  93. this.triggerEvent('getphonenumber', {...e.detail, ...e.currentTarget.dataset })
  94. },
  95. bindopensetting(e) {
  96. this.triggerEvent('opensetting', {...e.detail, ...e.currentTarget.dataset })
  97. },
  98. onError(e) {
  99. this.triggerEvent('error', {...e.detail, ...e.currentTarget.dataset })
  100. },
  101. },
  102. attached() {
  103. this.setData({
  104. resultIcon: getIcon(this.data.icon),
  105. })
  106. },
  107. })