合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.2 KiB

1 week ago
  1. <template>
  2. <view class="l-loading" :class="classes">
  3. <!-- #ifndef APP-ANDROID || APP-IOS -->
  4. <view class="l-loading__ball" v-if="type == 'ball'" :style="[spinnerStyle]"></view>
  5. <view class="l-loading__circular" v-if="type == 'circular'" :style="[spinnerStyle]"></view>
  6. <view class="l-loading__spinner" v-if="type == 'spinner'" :style="[spinnerStyle]">
  7. <view class="l-loading__dot" v-for="item in 12" :key="item" :style="{'--l-loading-dot': item}"></view>
  8. </view>
  9. <!-- #endif -->
  10. <!-- #ifdef APP-ANDROID || APP-IOS -->
  11. <view class="l-loading__view" ref="loadingRef" :style="spinnerStyle"></view>
  12. <!-- #endif -->
  13. <text class="l-loading__text" v-if="$slots['default'] != null || text !==''" :style="textStyle">
  14. <slot>{{text}}</slot>
  15. </text>
  16. </view>
  17. </template>
  18. <script lang="uts" setup>
  19. // #ifdef APP
  20. // import {useLoading} from './useLoading'
  21. import {useLoading} from '@/uni_modules/lime-loading'
  22. // #endif
  23. /**
  24. * LimeLoading 加载
  25. * @description 加载
  26. * @tutorial https://ext.dcloud.net.cn/plugin?name=lime-loading
  27. * @property {String} color loading颜色
  28. * @property {String} type loading类型,默认circular
  29. * @value circular 圆环
  30. * @value spinner 菊花
  31. * @property {String} size 尺寸
  32. * @property {String} text 文案
  33. * @property {String} textColor 文案颜色
  34. * @property {String} textSize 文案字体大小
  35. * @property {Boolean} vertical 是否垂直
  36. * @property {Boolean} inheritColor 是否继续颜色
  37. */
  38. const name = 'l-loading'
  39. defineOptions({
  40. name: 'l-loading'
  41. })
  42. const props = defineProps({
  43. color: {
  44. type: String,
  45. // #ifdef APP
  46. default: '#1677ff' // '#c9c9c9'
  47. // #endif
  48. },
  49. type: {
  50. type: String,
  51. default: 'circular'
  52. },
  53. size: {
  54. type: String,
  55. // #ifdef APP
  56. default: '40rpx',
  57. // #endif
  58. },
  59. text: {
  60. type: String,
  61. default: ''
  62. },
  63. textColor: {
  64. type: String,
  65. default: ''
  66. },
  67. textSize: {
  68. type: String,
  69. default: ''
  70. },
  71. vertical: {
  72. type: Boolean,
  73. default: false
  74. },
  75. })
  76. const classes = computed<Map<string,any>>(():Map<string,any> => {
  77. const cls = new Map<string,any>()
  78. cls.set(name + '--' + props.type, true)
  79. if (props.vertical) {
  80. cls.set('is-vertical', props.vertical)
  81. } else {
  82. cls.set('is-horizontal', !props.vertical)
  83. }
  84. return cls
  85. })
  86. const spinnerStyle = computed<Map<string,any>>(():Map<string,any> => {
  87. const style = new Map<string,any>()
  88. style.set('width', props.size)
  89. style.set('height', props.size)
  90. // #ifndef APP
  91. style.set('color', props.color)
  92. // #endif
  93. return style
  94. })
  95. const textStyle = computed<Map<string,any>>(():Map<string,any> => {
  96. const style = new Map<string,any>()
  97. if (props.textColor !== '') {
  98. style.set('color', props.textColor)
  99. }
  100. if (props.textSize !== '') {
  101. style.set('font-size', props.textSize)
  102. }
  103. return style
  104. })
  105. // #ifdef APP
  106. const loadingRef = ref<UniElement|null>(null)
  107. // const {state, color} = useLoading(loadingRef, props.type, props.color, 1)
  108. const loading = useLoading(loadingRef)
  109. loading.type = props.type;
  110. loading.play()
  111. // state.value = true
  112. watchEffect(()=>{
  113. if(props.color != ''){
  114. // color.value = props.color
  115. loading.color = props.color;
  116. }
  117. })
  118. // #endif
  119. </script>
  120. <style lang="scss">
  121. @import './index-u.scss';
  122. </style>