stepsNav.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="nav_box">
  3. <scroll-view :scroll-x="scrollable" :scroll-left="scrollLeft" scroll-with-animation
  4. class="u-tabs__wrapper__scroll-view" :show-scrollbar="false" ref="u-tabs__wrapper__scroll-view">
  5. <uniSteps :options="stepsList" :active="activeIndex" @selectStep="selectStep"></uniSteps>
  6. </scroll-view>
  7. </view>
  8. </template>
  9. <script>
  10. import uniSteps from './uni-steps.vue'
  11. export default {
  12. components: {
  13. uniSteps
  14. },
  15. props: {
  16. stepsList: {
  17. type: Array,
  18. default: () => []
  19. },
  20. taskId: {
  21. type: String,
  22. default: ''
  23. }
  24. },
  25. data() {
  26. return {
  27. scrollable: true,
  28. scrollLeft: 0,
  29. activeIndex: 0,
  30. }
  31. },
  32. watch: {
  33. taskId: {
  34. immediate: true,
  35. deep: true,
  36. handler(newVal) {
  37. this.activeIndex = this.getIndexOfElementInArray(this.stepsList, newVal)
  38. this.scrollLeft = 84 * this.activeIndex + 10
  39. }
  40. }
  41. },
  42. methods: {
  43. selectStep(item) {
  44. this.$emit('selectStep', item)
  45. },
  46. getIndexOfElementInArray(array, target) {
  47. for (let i = 0; i < array.length; i++) {
  48. if (array[i].taskId === target) {
  49. return i; // 返回第一次出现target的索引位置
  50. }
  51. }
  52. return -1; // 未找到目标值时返回-1
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .nav_box {
  59. width: 100%;
  60. height: 130rpx;
  61. overflow-y: scroll;
  62. }
  63. </style>