wd-loadmore.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <!--
  2. * @Author: weisheng
  3. * @Date: 2024-11-09 12:35:25
  4. * @LastEditTime: 2024-11-09 15:01:32
  5. * @LastEditors: weisheng
  6. * @Description:
  7. * @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/wd-loadmore/wd-loadmore.vue
  8. * 记得注释
  9. -->
  10. <template>
  11. <view :class="['wd-loadmore', customClass]" :style="customStyle" @click="reload">
  12. <wd-divider v-if="state === 'finished'">{{ finishedText || translate('finished') }}</wd-divider>
  13. <block v-if="state === 'error'">
  14. <text class="wd-loadmore__text">{{ errorText || translate('error') }}</text>
  15. <text class="wd-loadmore__text is-light">{{ translate('retry') }}</text>
  16. <wd-icon name="refresh" custom-class="wd-loadmore__refresh" />
  17. </block>
  18. <block v-if="state === 'loading'">
  19. <wd-loading v-bind="customLoadingProps" />
  20. <text class="wd-loadmore__text">{{ loadingText || translate('loading') }}</text>
  21. </block>
  22. </view>
  23. </template>
  24. <script lang="ts">
  25. export default {
  26. name: 'wd-loadmore',
  27. options: {
  28. virtualHost: true,
  29. addGlobalClass: true,
  30. styleIsolation: 'shared'
  31. }
  32. }
  33. </script>
  34. <script lang="ts" setup>
  35. import wdDivider from '../wd-divider/wd-divider.vue'
  36. import wdLoading from '../wd-loading/wd-loading.vue'
  37. import wdIcon from '../wd-icon/wd-icon.vue'
  38. import { computed, ref } from 'vue'
  39. import { useTranslate } from '../composables/useTranslate'
  40. import { loadmoreProps, type LoadMoreState } from './types'
  41. import type { LoadingProps } from '../wd-loading/types'
  42. import { isDef, isUndefined, omitBy } from '../common/util'
  43. const customLoadingProps = computed(() => {
  44. const loadingProps: Partial<LoadingProps> = isDef(props.loadingProps) ? omitBy(props.loadingProps, isUndefined) : {}
  45. loadingProps.customClass = `wd-loadmore__loading ${loadingProps.customClass || ''}`
  46. return loadingProps
  47. })
  48. const props = defineProps(loadmoreProps)
  49. const emit = defineEmits(['reload'])
  50. const { translate } = useTranslate('loadmore')
  51. const currentState = ref<LoadMoreState | null>(null)
  52. function reload() {
  53. if (props.state !== 'error') return
  54. currentState.value = 'loading'
  55. emit('reload')
  56. }
  57. </script>
  58. <style lang="scss" scoped>
  59. @import './index.scss';
  60. </style>