index.taro.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="nut-progress">
  3. <div
  4. class="nut-progress-outer"
  5. :id="'nut-progress-outer-taro-' + randRef"
  6. ref="progressOuter"
  7. :class="[showText && !textInside ? 'nut-progress-outer-part' : '', size ? 'nut-progress-' + size : '']"
  8. :style="{ height: height }"
  9. >
  10. <div :class="['nut-progress-inner', status == 'active' ? 'nut-active' : '']" :style="bgStyle">
  11. <div
  12. class="nut-progress-text nut-progress-insidetext"
  13. ref="insideText"
  14. :id="'nut-progress-insidetext-taro-' + randRef"
  15. :style="{
  16. lineHeight: height,
  17. left: `${percentage}%`,
  18. transform: `translate(-${+percentage}%,-50%)`,
  19. background: textBackground || strokeColor
  20. }"
  21. v-if="showText && textInside"
  22. >
  23. <span :style="textStyle">{{ percentage }}{{ isShowPercentage ? '%' : '' }}</span>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="nut-progress-text" :style="{ lineHeight: height }" v-if="showText && !textInside">
  28. <template v-if="status == 'text' || status == 'active'">
  29. <span :style="textStyle">{{ percentage }}{{ isShowPercentage ? '%' : '' }} </span>
  30. </template>
  31. <template v-else-if="status == 'icon'">
  32. <nut-icon size="16px" :name="iconName" :color="iconColor"></nut-icon>
  33. </template>
  34. </div>
  35. </div>
  36. </template>
  37. <script lang="ts">
  38. import { computed, onMounted, provide, reactive, nextTick, ref, watch } from 'vue';
  39. import { createComponent } from '../../utils/create';
  40. import Taro, { eventCenter, getCurrentInstance } from '@tarojs/taro';
  41. import { log } from 'lzutf8';
  42. const { create } = createComponent('progress');
  43. export default create({
  44. props: {
  45. percentage: {
  46. type: [Number, String],
  47. default: 0,
  48. required: true
  49. },
  50. size: {
  51. type: String,
  52. default: 'base'
  53. },
  54. status: {
  55. type: String,
  56. default: 'text'
  57. },
  58. strokeWidth: {
  59. type: [Number, String],
  60. default: ''
  61. },
  62. textInside: {
  63. type: Boolean,
  64. default: false
  65. },
  66. showText: {
  67. type: Boolean,
  68. default: true
  69. },
  70. strokeColor: {
  71. type: String,
  72. default: ''
  73. },
  74. textColor: {
  75. tyep: String,
  76. default: ''
  77. },
  78. textBackground: {
  79. tyep: String,
  80. default: ''
  81. },
  82. iconName: {
  83. type: String,
  84. default: 'checked'
  85. },
  86. iconColor: {
  87. type: String,
  88. default: '#439422'
  89. },
  90. isShowPercentage: {
  91. type: Boolean,
  92. default: true
  93. }
  94. },
  95. setup(props, { emit }) {
  96. const height = ref(props.strokeWidth + 'px');
  97. const progressOuter = ref<any>();
  98. const insideText = ref();
  99. const refRandomId = Math.random().toString(36).slice(-8);
  100. const randRef = ref(refRandomId);
  101. const bgStyle = computed(() => {
  102. return {
  103. width: props.percentage + '%',
  104. background: props.strokeColor || ''
  105. };
  106. });
  107. const textStyle = computed(() => {
  108. return {
  109. color: props.textColor || ''
  110. };
  111. });
  112. onMounted(() => {
  113. eventCenter.once((getCurrentInstance() as any).router.onReady, () => {});
  114. });
  115. return {
  116. height,
  117. bgStyle,
  118. textStyle,
  119. progressOuter,
  120. insideText,
  121. randRef
  122. };
  123. }
  124. });
  125. </script>