| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <template>
- <view class="nav_box">
- <scroll-view :scroll-x="scrollable" :scroll-left="scrollLeft" scroll-with-animation
- class="u-tabs__wrapper__scroll-view" :show-scrollbar="false" ref="u-tabs__wrapper__scroll-view">
- <uniSteps :options="stepsList" :active="activeIndex" @selectStep="selectStep"></uniSteps>
- </scroll-view>
- </view>
- </template>
- <script>
- import uniSteps from './uni-steps.vue'
- export default {
- components: {
- uniSteps
- },
- props: {
- stepsList: {
- type: Array,
- default: () => []
- },
- taskId: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- scrollable: true,
- scrollLeft: 0,
- activeIndex: 0,
- }
- },
- watch: {
- taskId: {
- immediate: true,
- deep: true,
- handler(newVal) {
- this.activeIndex = this.getIndexOfElementInArray(this.stepsList, newVal)
- this.scrollLeft = 84 * this.activeIndex + 10
- }
- }
- },
- methods: {
- selectStep(item) {
- this.$emit('selectStep', item)
- },
- getIndexOfElementInArray(array, target) {
- for (let i = 0; i < array.length; i++) {
- if (array[i].taskId === target) {
- return i; // 返回第一次出现target的索引位置
- }
- }
- return -1; // 未找到目标值时返回-1
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .nav_box {
- width: 100%;
- height: 130rpx;
- overflow-y: scroll;
- }
- </style>
|