Browse Source

[修复] table左滑回不去的问题(组件scroll-left赋值问题)

[修复] table有多个的时候只有第一个能滚动(table类名一样,导致dom查找时只能取到第一个,已加入随机唯一class标识)
[优化] 供应商申请报价搜索框样式
master
邓平艺 5 years ago
parent
commit
dd6abda8ba
  1. 34
      canteen/components/wyb-table/wyb-table.vue
  2. 33
      supplier/components/wyb-table/wyb-table.vue
  3. 2
      supplier/pages/offer/index.vue

34
canteen/components/wyb-table/wyb-table.vue

@ -1,5 +1,5 @@
<template>
<view class="wyb-table-box">
<view class="wyb-table-box" :class="randomClass">
<view v-if="loading" class="wyb-table-loading-box" :style="{
'max-width': width === 'auto' ? screenWidth : width,
'max-height': height === 'auto' ? '300rpx' : height,
@ -206,7 +206,6 @@
<script>
import Pinyin from './js/characterToPinyin.js'
import {isEqual} from './js/objEqual.js'
let timer = null;
export default {
data() {
return {
@ -226,6 +225,8 @@
checkType: this.enableCheck,
data: []
},
timer: null,
randomClass: "x"+ Math.random().toString(32).substr(2),
chars: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
}
},
@ -766,24 +767,41 @@
}
this.autoScrollView();
},
destroyed(){
if(this.timer){
clearInterval(this.timer);
this.timer = null;
}
},
methods: {
// input
autoScrollView(){
try{
// #ifdef H5
if(this.$props.scrollToInput){
let that = this;
if(that.$props.scrollToInput){
setTimeout(function(){
// dom .wyb-table-scroll-view .wyb-table-content .wyb-table-content-line .wyb-table-content-item input
let tabView = document.querySelector('.wyb-table-scroll-view'); // table
let tabView = document.querySelector('.'+ that.randomClass +' .wyb-table-scroll-view'); // table
let tabContent = tabView.querySelector('.wyb-table-content'); // tablecontent
let contentLine = tabContent.querySelector('.wyb-table-content-line'); //
let contentItem = contentLine.querySelector('.wyb-table-content-item input'); //
let offsetWidth = contentItem.offsetParent.offsetWidth;
let offsetLeft = contentItem.offsetParent.offsetLeft - offsetWidth - 20;
timer = setInterval(function(){
let offsetLeft = contentItem.offsetParent.offsetLeft;
let scrollLeft = offsetLeft - offsetWidth - 20;
if(that.timer){
clearInterval(that.timer);
that.timer = null;
}
if(scrollLeft <= 0){
return; // input
}
that.timer = setInterval(function(){
let currentScrollLeft = tabView.scrollLeft;
tabView.scrollLeft += 2;
if(tabView.scrollLeft >= offsetLeft){
clearInterval(timer);
if((tabView.scrollLeft >= scrollLeft) || currentScrollLeft == tabView.scrollLeft){
clearInterval(that.timer); // scrollLeft
that.timer = null;
}
}, 2);
}, 1000)

33
supplier/components/wyb-table/wyb-table.vue

@ -1,5 +1,5 @@
<template>
<view class="wyb-table-box">
<view class="wyb-table-box" :class="randomClass">
<!-- loading加载框 -->
<view v-if="loading" class="wyb-table-loading-box" :style="{
'max-width': width === 'auto' ? screenWidth : width,
@ -230,6 +230,8 @@
checkType: this.enableCheck,
data: []
},
timer: null,
randomClass: "x"+ Math.random().toString(32).substr(2),
chars: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
}
},
@ -814,24 +816,41 @@
}
this.autoScrollView();
},
destroyed(){
if(this.timer){
clearInterval(this.timer);
this.timer = null;
}
},
methods: {
// input
autoScrollView(){
try{
// #ifdef H5
if(this.$props.scrollToInput){
let that = this;
if(that.$props.scrollToInput){
setTimeout(function(){
// dom .wyb-table-scroll-view .wyb-table-content .wyb-table-content-line .wyb-table-content-item input
let tabView = document.querySelector('.wyb-table-scroll-view'); // table
let tabView = document.querySelector('.'+ that.randomClass +' .wyb-table-scroll-view'); // table
let tabContent = tabView.querySelector('.wyb-table-content'); // tablecontent
let contentLine = tabContent.querySelector('.wyb-table-content-line'); //
let contentItem = contentLine.querySelector('.wyb-table-content-item input'); //
let offsetWidth = contentItem.offsetParent.offsetWidth;
let offsetLeft = contentItem.offsetParent.offsetLeft - offsetWidth - 20;
timer = setInterval(function(){
let offsetLeft = contentItem.offsetParent.offsetLeft;
let scrollLeft = offsetLeft - offsetWidth - 20;
if(that.timer){
clearInterval(that.timer);
that.timer = null;
}
if(scrollLeft <= 0){
return; // input
}
that.timer = setInterval(function(){
let currentScrollLeft = tabView.scrollLeft;
tabView.scrollLeft += 2;
if(tabView.scrollLeft >= offsetLeft){
clearInterval(timer);
if((tabView.scrollLeft >= scrollLeft) || currentScrollLeft == tabView.scrollLeft){
clearInterval(that.timer); // scrollLeft
that.timer = null;
}
}, 2);
}, 1000)

2
supplier/pages/offer/index.vue

@ -476,7 +476,7 @@
color: #777;
}
.search-self {
background: rgb(228,228,228);
background: #f2f2f2;
padding: 10rpx 0 10rpx 20rpx;
border-radius: 40rpx;
font-size: 28rpx;

Loading…
Cancel
Save