index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <uni-shadow-root class="vant-progress-index"><view class="van-progress custom-class" :style="computed.rootStyle({ strokeWidth, trackColor })">
  3. <view class="van-progress__portion" :style="computed.portionStyle({ percentage, inactive, color })">
  4. <view v-if="showPivot && computed.pivotText(pivotText, percentage)" :style="computed.pivotStyle({ textColor, pivotColor, inactive, color, right })" class="van-progress__pivot">
  5. {{ computed.pivotText(pivotText, percentage) }}
  6. </view>
  7. </view>
  8. </view></uni-shadow-root>
  9. </template>
  10. <wxs src="../wxs/utils.wxs" module="utils"></wxs><wxs src="./index.wxs" module="computed"></wxs>
  11. <script>
  12. global['__wxRoute'] = 'vant/progress/index'
  13. import { VantComponent } from '../common/component';
  14. import { BLUE } from '../common/color';
  15. import { getRect } from '../common/utils';
  16. VantComponent({
  17. props: {
  18. inactive: Boolean,
  19. percentage: {
  20. type: Number,
  21. observer: 'setLeft',
  22. },
  23. pivotText: String,
  24. pivotColor: String,
  25. trackColor: String,
  26. showPivot: {
  27. type: Boolean,
  28. value: true,
  29. },
  30. color: {
  31. type: String,
  32. value: BLUE,
  33. },
  34. textColor: {
  35. type: String,
  36. value: '#fff',
  37. },
  38. strokeWidth: {
  39. type: null,
  40. value: 4,
  41. },
  42. },
  43. data: {
  44. right: 0,
  45. },
  46. mounted() {
  47. this.setLeft();
  48. },
  49. methods: {
  50. setLeft() {
  51. Promise.all([
  52. getRect(this, '.van-progress'),
  53. getRect(this, '.van-progress__pivot'),
  54. ]).then(([portion, pivot]) => {
  55. if (portion && pivot) {
  56. this.setData({
  57. right: (pivot.width * (this.data.percentage - 100)) / 100,
  58. });
  59. }
  60. });
  61. },
  62. },
  63. });
  64. export default global['__wxComponents']['vant/progress/index']
  65. </script>
  66. <style platform="mp-weixin">
  67. @import '../common/index.css';.van-progress{background:var(--progress-background-color,#ebedf0);border-radius:var(--progress-height,4px);height:var(--progress-height,4px);position:relative}.van-progress__portion{background:var(--progress-color,#1989fa);border-radius:inherit;height:100%;left:0;position:absolute}.van-progress__pivot{background-color:var(--progress-pivot-background-color,#1989fa);border-radius:1em;box-sizing:border-box;color:var(--progress-pivot-text-color,#fff);font-size:var(--progress-pivot-font-size,10px);line-height:var(--progress-pivot-line-height,1.6);min-width:3.6em;padding:var(--progress-pivot-padding,0 5px);position:absolute;text-align:center;top:50%;transform:translateY(-50%);word-break:keep-all}
  68. </style>