index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { defineComponent, PropType } from 'vue'
  2. import styles from './index.module.less'
  3. import empty from '@common/images/icon_nodata.png'
  4. import { Button, Empty, Image } from 'vant'
  5. import { postMessage } from '@/helpers/native-message'
  6. export const getAssetsHomeFile = (fileName: string) => {
  7. const path = `./images/${fileName}`
  8. const modules = import.meta.globEager('./images/*')
  9. return modules[path].default
  10. }
  11. export default defineComponent({
  12. name: 'o-empty',
  13. props: {
  14. tips: {
  15. type: String
  16. },
  17. type: {
  18. // 空 | 达人认证 | 音乐人认证 | 直播认证
  19. type: String as PropType<
  20. 'empty' | 'error' | 'network' | 'search' | 'emptyContent' | 'notFond'
  21. >,
  22. default: 'empty'
  23. },
  24. classImgSize: {
  25. type: String as PropType<'CERT' | 'SMALL'>,
  26. default: ''
  27. },
  28. imageSize: {
  29. type: Number,
  30. default: 0
  31. },
  32. plain: {
  33. type: Boolean,
  34. default: false
  35. },
  36. btnStatus: {
  37. type: Boolean,
  38. default: false
  39. },
  40. buttonText: {
  41. type: String,
  42. default: '我知道了'
  43. },
  44. onClick: Function
  45. },
  46. methods: {
  47. onResult() {
  48. if (this.onClick) {
  49. this.onClick()
  50. } else {
  51. postMessage({ api: 'back', content: {} })
  52. }
  53. }
  54. },
  55. computed: {
  56. image() {
  57. let image = null as any
  58. switch (this.type) {
  59. case 'emptyContent':
  60. image = getAssetsHomeFile('emptyContent.png')
  61. break
  62. case 'error':
  63. image = 'error'
  64. break
  65. case 'network':
  66. image = getAssetsHomeFile('network.png')
  67. break
  68. case 'search':
  69. image = 'search'
  70. break
  71. case 'notFond':
  72. image = getAssetsHomeFile('notFond.png')
  73. break
  74. default:
  75. image = getAssetsHomeFile('empty.png')
  76. break
  77. }
  78. return image
  79. }
  80. },
  81. render() {
  82. return (
  83. <div class={[styles['col-result'], 'col-result-container']}>
  84. <Empty
  85. image={this.image}
  86. imageSize={this.imageSize || ''}
  87. class={styles[this.classImgSize]}
  88. description={this.tips}
  89. />
  90. {this.btnStatus ? (
  91. <Button
  92. class={styles.btn}
  93. round
  94. block
  95. type="primary"
  96. plain={this.plain}
  97. onClick={this.onResult}
  98. >
  99. {this.buttonText}
  100. </Button>
  101. ) : null}
  102. </div>
  103. )
  104. }
  105. })