Browse Source

单品列表

xiaohaizhao 1 year ago
parent
commit
f5969cf0c7

+ 315 - 0
pages/index/cloud/product.vue

@@ -0,0 +1,315 @@
+<template>
+    <view>
+        <u-tabs :list="types" :activeStyle="{ fontWeight: 'bold', color: '#C30D23' }" lineColor="#C30D23"
+            keyName="classname" @change="changeClass1">
+            <view slot="right" class="nav-search" hover-class="navigator-hover" @click="changeSearchShow(searchShow)">
+                <view class="iconfont icon-sousuo" :style="{ color: searchShow ? '#C30D23' : '#999999' }" />
+            </view>
+        </u-tabs>
+        <u-transition :show="searchShow">
+            <view class="My_search-box">
+                <My_search :value="content.where.condition" @onSearch="onSearch">
+                    <view class="cancel" v-if="content.where.condition" hover-class="navigator-hover" @click="onSearch('')">
+                        取消
+                    </view>
+                    <view v-else style="width: 5px;" />
+                </My_search>
+            </view>
+        </u-transition>
+        <view class="tabs2-box" v-if="tabs2.length">
+            <v-tabs v-model="tabs2Active" field="classname" :pills="true" height="28px" pillsBorderRadius="14px"
+                pillsColor="#FFFFFF" bgColor="none" color="#FFFFFF" activeColor="#C30D23" lineScale="20px" :tabs="tabs2"
+                @change="changeClass2" />
+        </view>
+        <view class="tabs3-box" v-if="tabs3.length">
+            <v-tabs v-model="tabs3Active" field="classname" :pills="true" height="24px" pillsBorderRadius="12px"
+                pillsColor="#C30D23" pillsUnColor="#eee" bgColor="none" itemMargin="0 4px 0 0" color="#333333"
+                activeColor="#FFFFFF" lineScale="10px" :tabs="tabs3" @change="changeClass3" />
+        </view>
+        <view class="list">
+            <view class="head">
+                <view class="crumbs u-line-1">
+                    <text class="crumb" v-for="item in crumbs" :key="item.classname">{{ item.classname }}</text>
+                </view>
+                <view class="total">共{{ total }}件</view>
+            </view>
+            <My_listbox ref="List" @getlist="getList" :bottomHeight="70">
+                <view class="list-box">
+                    <view class="item" v-for="item in list" :key="item.sa_fadid" hover-class="navigator-hover">
+                        <image class="image" :src="item.cover" mode="aspectFill" lazy-load="true" />
+                        <view class="title u-line-1">
+                            {{ item.name }}
+                        </view>
+                    </view>
+                </view>
+            </My_listbox>
+        </view>
+    </view>
+</template>
+
+<script>
+export default {
+    name: "product",
+    data() {
+        return {
+            types: [],
+
+            tabs2: [],
+            tabs2Active: 0,
+
+            tabs3: [],
+            tabs3Active: 0,
+
+            crumbs: [],
+            list: [],
+            "content": {
+                "where": {
+                    "condition": "",
+                    "isonsale": 1,
+                    "begindate_create": "",
+                    "enddate_create": "",
+                    "begindate_onsale": "",
+                    "enddate_onsale": "",
+                }
+            },
+            total: 0,
+            searchShow: false,
+            searchShowAntiShake: null,
+            sa_fadclassid: "",
+        }
+    },
+    methods: {
+        init(callBack) {
+            this.$Http.basic({
+                "id": "20240418112002",
+                "content": {
+                    "parentid": 0,
+                    "where": { "isenable": 1 }
+                }
+            }).then(res => {
+                console.log("获取单品分类", res)
+                this.types = res.data;
+                if (res.data.length) this.changeClass1(res.data[0]).then(res => {
+                    callBack()
+                })
+            })
+        },
+        changeClass1(item) {
+            if (this.sa_fadclassid == item.sa_fadclassid) return;
+            this.sa_fadclassid = item.sa_fadclassid;
+            this.crumbs = [item, {
+                classname: '全部',
+                sa_fadclassid: item.sa_fadclassid
+            }];
+            if (item.children.length && item.children[0].classname != '全部') item.children.unshift({
+                classname: "全部",
+                sa_fadclassid: item.sa_fadclassid,
+                children: []
+            });
+            this.tabs2 = item.children;
+            this.tabs2Active = 0;
+
+            this.tabs3 = [];
+            this.tabs3Active = 0;
+
+            return this.getList(true);
+        },
+        changeClass2(index) {
+            let item = this.tabs2[index];
+            if (this.sa_fadclassid == item.sa_fadclassid) return;
+            this.sa_fadclassid = item.sa_fadclassid;
+            this.crumbs = [this.crumbs[0], item];
+            if (item.classname != '全部') this.crumbs.push({
+                classname: '全部',
+                sa_fadclassid: item.sa_fadclassid,
+                children: []
+            })
+            if (item.children.length && item.children[0].classname != '全部') item.children.unshift({
+                classname: "全部",
+                sa_fadclassid: item.sa_fadclassid
+            });
+
+            this.tabs3 = item.children || [];
+            this.tabs3Active = 0;
+
+            this.getList(true);
+        },
+        changeClass3(index) {
+            let item = this.tabs3[index];
+            if (this.sa_fadclassid == item.sa_fadclassid) return;
+            this.sa_fadclassid = item.sa_fadclassid;
+            this.crumbs[2] = item;
+            this.getList(true);
+        },
+        getList(init = false) {
+            return new Promise((resolve, reject) => {
+                if (this.paging(this.content, init)) return resolve();
+                this.content.where.sa_fadclassids = [[this.crumbs[this.crumbs.length - 1].sa_fadclassid]];
+                console.log(this.crumbs[this.crumbs.length - 1].sa_fadclassid)
+                this.$Http.basic({
+                    "id": "20240418141302",
+                    content: this.content
+                }).then(res => {
+                    this.$refs.List.setHeight()
+                    this.$refs.List.RefreshToComplete()
+                    console.log("获取产品列表", res)
+                    resolve();
+                    if (this.cutoff(res.msg)) return;
+                    res.data = res.data.map(v => {
+                        v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos.find(s => s.usetype == "sa_fad") || v.attinfos[0]) : ''
+                        return v
+                    })
+                    this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
+                    this.content = this.$refs.List.paging(this.content, res)
+                    this.total = res.total;
+                })
+            })
+        },
+        onSearch(condition) {
+            if (condition == this.content.where.condition) return;
+            this.content.where.condition = condition;
+            this.getList(true);
+        },
+        changeSearchShow(searchShow) {
+            this.searchShow = !searchShow;
+            clearTimeout(this.searchShowAntiShake)
+            this.searchShowAntiShake = setTimeout(() => {
+                this.$refs.List.setHeight();
+            }, 350)
+        }
+    },
+}
+</script>
+
+<style lang="scss">
+.nav-search {
+    display: flex;
+    align-items: center;
+    padding: 0 15px;
+    height: 44px;
+    border-radius: 8px;
+    margin-right: 5px;
+}
+
+.My_search-box {
+    background: #fff;
+    width: 100vw;
+    padding: 5px;
+    padding-left: 10px;
+    box-sizing: border-box;
+
+    .cancel {
+        line-height: 30px;
+        margin-left: 10px;
+        padding: 0 10px;
+        font-family: Source Han Sans SC, Source Han Sans SC;
+        font-size: 14px;
+        color: #666666;
+        border-radius: 4px;
+    }
+}
+
+.tabs2-box,
+.tabs3-box {
+    padding-left: 10px;
+    box-sizing: border-box;
+}
+
+.tabs2-box {
+    display: flex;
+    align-items: center;
+    background: linear-gradient(90deg, #202E42 0%, #3D405F 100%);
+    height: 40px;
+    width: 100vw;
+}
+
+.tabs3-box {
+    background: #fff;
+    padding-top: 8px;
+    height: 30px;
+    width: 100vw;
+}
+
+
+.list-box {
+    display: flex;
+    flex-wrap: wrap;
+    justify-content: space-between;
+
+    .item {
+        width: 173px;
+        height: 207px;
+        margin-top: 10px;
+        border-radius: 5px;
+        overflow: hidden;
+        flex-shrink: 0;
+
+        .image {
+            width: 173px;
+            height: 172px;
+            background: #F5F5F5;
+            border-radius: 5px;
+        }
+
+
+        .title {
+            width: 100%;
+            height: 25px;
+            line-height: 20px;
+            font-family: PingFang SC, PingFang SC;
+            font-size: 14px;
+            color: #333333;
+            margin-top: 10px;
+            text-align: center;
+        }
+    }
+
+}
+
+.list {
+    width: 100vw;
+    padding: 10px;
+    box-sizing: border-box;
+    background: #fff;
+
+    .head {
+        display: flex;
+        align-items: center;
+        justify-content: space-between;
+        height: 17px;
+        line-height: 17px;
+
+        .crumbs {
+            flex: 1;
+            width: 0;
+
+            .crumb {
+                flex-shrink: 0;
+                font-size: 12px;
+                font-family: PingFang SC, PingFang SC;
+            }
+
+            .crumb::after {
+                content: ">";
+                padding: 0 2px;
+            }
+
+            .crumb:last-child {
+                font-weight: bold;
+            }
+
+            .crumb:last-child::after {
+                content: "";
+            }
+        }
+
+        .total {
+            flex-shrink: 0;
+            font-family: Source Han Sans SC, Source Han Sans SC;
+            font-size: 12px;
+            color: #999999;
+            margin-left: 20px;
+        }
+    }
+}
+</style>

+ 11 - 0
pages/index/index/casePages/imgs.vue

@@ -134,4 +134,15 @@ body {
         }
     }
 }
+
+.tab-item {
+    flex-shrink: 0;
+    height: 24px;
+    line-height: 24px;
+    padding: 0 5px;
+    background: #F2F2F2;
+    border-radius: 12px;
+    margin-right: 5px;
+    font-size: 12px;
+}
 </style>

+ 0 - 1
pages/index/index/casePages/tabs.vue

@@ -141,7 +141,6 @@ export default {
     background: #F2F2F2;
     border-radius: 12px;
     margin-right: 5px;
-    font-size: 12px;
 }
 
 .tab-item-active {

+ 138 - 0
uni_modules/v-tabs/changelog.md

@@ -0,0 +1,138 @@
+### 2.1.5(2023-11-02)
+1.[修复]修复`change`和`v-model`绑定的值不同步
+2.[修复]暂时停用`activeFontSize`选项
+3.[修改]修改默认激活的文字不加粗
+## 2.1.4(2023-10-12)
+1. [修改]修改计算方式
+2. [新增]外部可以通过`this.$refs.tabs.update()`方法主动更新
+## 2.1.3(2023-09-11)
+1. [新增]支持自定义插槽模式,具体可以查看示例代码使用方式。[gitee demo](https://github.com/xfjpeter/uni-plugins/blob/3e2bd062163f664889122fd74b8bd6ccad6a97f1/pages/tabs/tabs.vue#L47C10-L50C16) 或 [github demo](https://github.com/xfjpeter/uni-plugins/blob/3e2bd062163f664889122fd74b8bd6ccad6a97f1/pages/tabs/tabs.vue#L47C10-L50C16)
+
+## 2.1.2(2023-06-12)
+1. [新增]添加`z-index`参数控制层级大小,默认1993
+2. [说明]以后该插件只更新`uni_modules`方式的,`zip`方式的不提供更新了
+## 2.1.1(2022-09-16)
+1. 将插件更新为`uni_modules`方式
+## 2.1.0(2022-08-12)
+
+1. 增加`disable`参数,控制是否可以点击,只能应用在数组对象中,见[disabled 的用法](#112-当tabs使用的数组对象的方式特定参数需要注意一下)
+
+```js
+export default {
+  data() {
+    return {
+      tabs: [{ id: 1, name: '' }]
+    }
+  }
+}
+```
+
+## 2.0.10(2022-01-27)
+
+1. 更新属性line-animation设置为false可以不要动画,这是好多朋友问到,特此加上
+
+## 2.0.9(2020-10-12)
+
+1. 修复 v-tabs 第一次可能出现第一个标签显示不完整的情况
+2. 修改了 pages/tabs/order 示例文件
+
+## 2.0.8(2020-09-21)
+
+1. 修复添加 fixed 属性后,滚动条无效
+2. 修复选项很少的情况下,下划线计算计算错误
+3. 新增 paddingItem 属性,设置选项左右边距(上下边距需要设置 height 属性,或者设置 padding 属性)
+
+## 2.0.7(2020-09-17)
+
+1. 紧急修复 bug,横向滑动不了的情况
+
+## 2.0.6(2020-09-16)
+
+1. 新增 fixed 属性,是否固定在顶部,示例地址:pages/tabs/tabs-static
+2. 优化之前的页面结构
+
+## 2.0.5(2020-09-09)
+
+1. 修复 width 错误,dom 加载的时候没有及时获取到 data 属性导致的 。
+
+## 2.0.4(2020-08-29)
+
+1. 优化异步改变 tabs 后,下划线不初始化问题
+2. github 地址上有图 2 的源码,需要的自行下载,页面路径:pages/tabs/order.vue
+
+## 2.0.3(2020-08-20)
+
+1. 优化 节点查询 和 选中渲染
+2. 优化支付宝中 createSelectorQuery() 的影响
+
+**特别说明:**
+
+> 支付宝中平铺方法和其他方法不能在一个页面中出现,不然有一个显示错误(具体什么原因没查到,有好心的人发现了,望告知一下,感谢
+
+## 2.0.2(2020-08-19)
+
+1. 优化 change 事件触发机制
+
+## 2.0.1(2020-08-16)
+
+1. 修改默认高度为 70rpx
+2. 新增属性 bgColor,可设置背景颜色,默认 #fff
+3. 新增整个 tab 的 padding 属性,默认 0
+
+## 2.0.0(2020-08-13)
+
+1. 全新的 v-tabs 2.0
+2. 支持 H5 小程序 APP
+3. 属性高度可配置
+
+## 1.3.2(2020-07-21)
+
+1. 新增 auto 的配置,是否平铺 tab
+2. 修复文档上的错误示例(感谢 lushgwe@163.com 的反馈)
+
+## 1.3.0(2020-07-05)
+
+1. 新增 padding 的可配置
+2. 修复 v-model 双向绑定问题
+3. 修复初始化下划线没定位的为题
+
+## 1.2.0(2020-06-19)
+
+1. 添加注释
+2. 修复 bug
+
+## 1.1.8(2020-06-11)
+
+1. 添加 change 事件
+2. 修复插件内容问题
+3. 修复下划线不居中问题
+
+## 1.1.6(2020-06-11)
+
+1. 添加 change 事件
+2. 修复插件内容问题
+
+## 1.1.4(2020-06-11)
+
+1. 添加 change 事件
+2. 修复插件内容问题
+
+## 1.1.2(2020-06-11)
+
+1. 添加 change 事件
+
+## 1.1.1(2020-06-09)
+
+1. 修复小程序端选中的下划线不显示问题
+2. 新增 tab 高度设置
+3. lineHeight 修改为只支持 String 方式
+
+## 1.1.0(2020-06-09)
+
+1. 修复小程序端选中的下划线不显示问题
+2. 新增 tab 高度设置
+3. lineHeight 修改为只支持 String 方式
+
+## 1.0.0(2020-06-04)
+
+1. 更新插件1.0.0

+ 103 - 0
uni_modules/v-tabs/components/v-tabs/props.js

@@ -0,0 +1,103 @@
+export default {
+  value: {
+    type: Number,
+    default: 0
+  },
+  tabs: {
+    type: Array,
+    default () {
+      return []
+    }
+  },
+  bgColor: {
+    type: String,
+    default: '#fff'
+  },
+  padding: {
+    type: String,
+    default: '0'
+  },
+  color: {
+    type: String,
+    default: '#333'
+  },
+  activeColor: {
+    type: String,
+    default: '#2979ff'
+  },
+  fontSize: {
+    type: String,
+    default: '28rpx'
+  },
+  activeFontSize: {
+    type: String,
+    default: '32rpx'
+  },
+  bold: {
+    type: Boolean,
+    default: false
+  },
+  scroll: {
+    type: Boolean,
+    default: true
+  },
+  height: {
+    type: String,
+    default: '70rpx'
+  },
+  lineColor: {
+    type: String,
+    default: '#2979ff'
+  },
+  lineHeight: {
+    type: [String, Number],
+    default: '10rpx'
+  },
+  lineScale: {
+    type: Number,
+    default: 0.5
+  },
+  lineRadius: {
+    type: String,
+    default: '10rpx'
+  },
+  pills: {
+    type: Boolean,
+    default: false
+  },
+  pillsColor: {
+    type: String,
+    default: '#2979ff'
+  },
+  pillsUnColor: {
+    type: String,
+    default: ""
+  },
+  pillsBorderRadius: {
+    type: String,
+    default: '10rpx'
+  },
+  field: {
+    type: String,
+    default: ''
+  },
+  fixed: {
+    type: Boolean,
+    default: false
+  },
+  paddingItem: {
+    type: String,
+    default: '0 22rpx'
+  },
+  lineAnimation: {
+    type: Boolean,
+    default: true
+  },
+  itemMargin: {
+    type: String,
+  },
+  zIndex: {
+    type: Number,
+    default: 1993
+  }
+}

+ 12 - 0
uni_modules/v-tabs/components/v-tabs/utils.js

@@ -0,0 +1,12 @@
+export function startMicroTask(callback) {
+  if (typeof queueMicrotask === 'function') {
+    queueMicrotask(callback)
+  } else if (typeof MutationObserver === 'function') {
+    const node = document.createElement('div')
+    const observer = new MutationObserver(callback)
+    observer.observe(node, { childList: true })
+    node.textContent = 'xfjpeter'
+  } else {
+    setTimeout(callback, 0)
+  }
+}

+ 269 - 0
uni_modules/v-tabs/components/v-tabs/v-tabs.vue

@@ -0,0 +1,269 @@
+<template>
+  <view class="v-tabs">
+    <scroll-view :id="getDomId" :scroll-x="scroll" :scroll-left="scroll ? scrollLeft : 0" :scroll-with-animation="scroll"
+      :style="{ position: fixed ? 'fixed' : 'relative', zIndex }">
+      <view class="v-tabs__container" :style="{
+        display: scroll ? 'inline-flex' : 'flex',
+        whiteSpace: scroll ? 'nowrap' : 'normal',
+        background: bgColor,
+        height,
+        padding
+      }">
+        <view :class="['v-tabs__container-item', { disabled: !!v.disabled }, { active: current == i }]"
+          v-for="(v, i) in tabs" :key="i" :style="{
+            color: current == i ? activeColor : color,
+            fontSize: current == i ? fontSize : fontSize,
+            fontWeight: bold && current == i ? 'bold' : '',
+            justifyContent: !scroll ? 'center' : '',
+            flex: scroll ? '' : 1,
+            padding: paddingItem,
+            background: current == i ? '' : pillsUnColor,
+            borderRadius: pillsBorderRadius,
+            margin: itemMargin,
+          }" @click="change(i)">
+          <slot :row="v" :index="i">{{ field ? v[field] : v }}</slot>
+        </view>
+        <template v-if="!!tabs.length">
+          <view v-if="!pills" :class="['v-tabs__container-line', { animation: lineAnimation }]" :style="{
+            background: lineColor,
+            width: lineWidth + 'px',
+            height: lineHeight,
+            borderRadius: lineRadius,
+            transform: `translate3d(${lineLeft}px, 0, 0)`
+          }" />
+          <view v-else :class="['v-tabs__container-pills', { animation: lineAnimation }]" :style="{
+            background: pillsColor,
+            width: currentWidth + 'px',
+            transform: `translate3d(${pillsLeft}px, 0, 0)`,
+            borderRadius: pillsBorderRadius,
+            height
+          }" />
+        </template>
+      </view>
+    </scroll-view>
+    <!-- fixed 的站位高度 -->
+    <view class="v-tabs__placeholder" :style="{ height: fixed ? height : '0', padding }"></view>
+  </view>
+</template>
+
+<script>
+import { startMicroTask } from './utils'
+import props from './props'
+/**
+ * v-tabs
+ * @property {Number} value 选中的下标
+ * @property {Array} tabs tabs 列表
+ * @property {String} bgColor = '#fff' 背景颜色
+ * @property {String} color = '#333' 默认颜色
+ * @property {String} activeColor = '#2979ff' 选中文字颜色
+ * @property {String} fontSize = '28rpx' 默认文字大小
+ * @property {String} activeFontSize = '28rpx' 选中文字大小
+ * @property {Boolean} bold = [true | false] 选中文字是否加粗
+ * @property {Boolean} scroll = [true | false] 是否滚动
+ * @property {String} height = '60rpx' tab 的高度
+ * @property {String} lineHeight = '10rpx' 下划线的高度
+ * @property {String} lineColor = '#2979ff' 下划线的颜色
+ * @property {Number} lineScale = 0.5 下划线的宽度缩放比例
+ * @property {String} lineRadius = '10rpx' 下划线圆角
+ * @property {Boolean} pills = [true | false] 是否胶囊样式
+ * @property {String} pillsColor = '#2979ff' 胶囊背景色
+ * @property {String} pillsBorderRadius = '10rpx' 胶囊圆角大小
+ * @property {String} field 如果是对象,显示的键名
+ * @property {Boolean} fixed = [true | false] 是否固定
+ * @property {String} paddingItem = '0 22rpx' 选项的边距
+ * @property {Boolean} lineAnimation = [true | false] 下划线是否有动画
+ * @property {Number} zIndex = 1993 默认层级
+ *
+ * @event {Function(current)} change 改变标签触发
+ */
+export default {
+  name: 'VTabs',
+  props,
+  data() {
+    return {
+      lineWidth: 30,
+      currentWidth: 0, // 当前选项的宽度
+      lineLeft: 0, // 滑块距离左侧的位置
+      pillsLeft: 0, // 胶囊距离左侧的位置
+      scrollLeft: 0, // 距离左边的位置
+      container: { width: 0, height: 0, left: 0, right: 0 }, // 容器的宽高,左右距离
+      current: 0, // 当前选中项
+      scrollWidth: 0 // 可以滚动的宽度
+    }
+  },
+  computed: {
+    getDomId() {
+      const len = 16
+      const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678' /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
+      const maxPos = $chars.length
+      let pwd = ''
+      for (let i = 0; i < len; i++) {
+        pwd += $chars.charAt(Math.floor(Math.random() * maxPos))
+      }
+      return `xfjpeter_${pwd}`
+    }
+  },
+  watch: {
+    value: {
+      immediate: true,
+      handler(newVal) {
+        this.current = newVal
+        this.$nextTick(this.update)
+      }
+    }
+  },
+  methods: {
+    // 切换事件
+    change(index) {
+      const isDisabled = !!this.tabs[index].disabled
+      if (this.current !== index && !isDisabled) {
+        this.current = index
+        this.$emit('input', index)
+        this.$emit('change', index)
+      }
+    },
+    createQueryHandler() {
+      const query = uni
+        .createSelectorQuery()
+        // #ifndef MP-ALIPAY
+        .in(this)
+      // #endif
+
+      return query
+    },
+    update() {
+      const _this = this
+      startMicroTask(() => {
+        // 没有列表的时候,不执行
+        if (!this.tabs.length) return
+        _this
+          .createQueryHandler()
+          .select(`#${this.getDomId}`)
+          .boundingClientRect(data => {
+            const { width, height, left, right } = data || {}
+            // 获取容器的相关属性
+            this.container = { width, height, left, right: right - width }
+            _this.calcScrollWidth()
+            _this.setScrollLeft()
+            _this.setLine()
+          })
+          .exec()
+      })
+    },
+    // 计算可以滚动的宽度
+    calcScrollWidth(callback) {
+      const view = this.createQueryHandler().select(`#${this.getDomId}`)
+      view.fields({ scrollOffset: true })
+      view
+        .scrollOffset(res => {
+          if (typeof callback === 'function') {
+            callback(res)
+          } else {
+            // 获取滚动条的宽度
+            this.scrollWidth = res.scrollWidth
+          }
+        })
+        .exec()
+    },
+    // 设置滚动条滚动的进度
+    setScrollLeft() {
+      this.calcScrollWidth(res => {
+        // 动态读取 scrollLeft
+        let scrollLeft = res.scrollLeft
+        this.createQueryHandler()
+          .select(`#${this.getDomId} .v-tabs__container-item.active`)
+          .boundingClientRect(data => {
+            if (!data) return
+            // 除开当前选项外容器的一半宽度
+            let curHalfWidth = (this.container.width - data.width) / 2
+            let scrollDiff = this.scrollWidth - this.container.width
+            // 在原有滚动条的基础上 + (当前元素距离左侧的距离 - 计算的一半宽度) - 容器的外边距之类的
+            scrollLeft += data.left - curHalfWidth - this.container.left
+            // 已经滚动在左侧了
+            if (scrollLeft < 0) scrollLeft = 0
+            // 已经超出右侧了
+            else if (scrollLeft > scrollDiff) scrollLeft = scrollDiff
+            this.scrollLeft = scrollLeft
+          })
+          .exec()
+      })
+    },
+    setLine() {
+      this.calcScrollWidth(res => {
+        const scrollLeft = res.scrollLeft
+        this.createQueryHandler()
+          .select(`#${this.getDomId} .v-tabs__container-item.active`)
+          .boundingClientRect(data => {
+            if (!data) return
+            if (this.pills) {
+              this.currentWidth = data.width
+              this.pillsLeft = scrollLeft + data.left - this.container.left
+            } else {
+              this.lineWidth = data.width * this.lineScale
+              this.lineLeft = scrollLeft + data.left + (data.width - data.width * this.lineScale) / 2 - this.container.left
+            }
+          })
+          .exec()
+      })
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+.v-tabs {
+  width: 100%;
+  box-sizing: border-box;
+  overflow: hidden;
+
+  /* #ifdef H5 */
+  ::-webkit-scrollbar {
+    display: none;
+  }
+
+  /* #endif */
+
+  &__container {
+    min-width: 100%;
+    position: relative;
+    display: inline-flex;
+    align-items: center;
+    white-space: nowrap;
+    overflow: hidden;
+
+    &-item {
+      flex-shrink: 0;
+      display: flex;
+      align-items: center;
+      height: 100%;
+      position: relative;
+      z-index: 10;
+      transition: all 0.3s;
+      white-space: nowrap;
+
+      &.disabled {
+        opacity: 0.5;
+        color: #999;
+      }
+    }
+
+    &-line {
+      position: absolute;
+      left: 0;
+      bottom: 0;
+    }
+
+    &-pills {
+      position: absolute;
+      z-index: 9;
+    }
+
+    &-line,
+    &-pills {
+      &.animation {
+        transition: all 0.3s linear;
+      }
+    }
+  }
+}
+</style>

+ 83 - 0
uni_modules/v-tabs/package.json

@@ -0,0 +1,83 @@
+{
+  "id": "v-tabs",
+  "displayName": "自定义 tab 选项卡 2",
+  "version": "2.1.5",
+  "description": "自定义 tab ,支持多种样式,支持 h5 小程序 app",
+  "keywords": [
+    "v-tabs",
+    "tab",
+    "选项卡"
+],
+  "repository": "https://github.com/xfjpeter/uni-plugins",
+  "engines": {
+    "HBuilderX": "^3.1.0"
+  },
+  "dcloudext": {
+    "type": "component-vue",
+    "sale": {
+      "regular": {
+        "price": "0.00"
+      },
+      "sourcecode": {
+        "price": "0.00"
+      }
+    },
+    "contact": {
+      "qq": "1207791534"
+    },
+    "declaration": {
+      "ads": "无",
+      "data": "无",
+      "permissions": "无"
+    },
+    "npmurl": ""
+  },
+  "uni_modules": {
+    "dependencies": [],
+    "encrypt": [],
+    "platforms": {
+      "cloud": {
+        "tcb": "y",
+        "aliyun": "y"
+      },
+      "client": {
+        "Vue": {
+          "vue2": "y",
+          "vue3": "n"
+        },
+        "App": {
+          "app-vue": "y",
+          "app-nvue": "n"
+        },
+        "H5-mobile": {
+          "Safari": "y",
+          "Android Browser": "y",
+          "微信浏览器(Android)": "y",
+          "QQ浏览器(Android)": "y"
+        },
+        "H5-pc": {
+          "Chrome": "y",
+          "IE": "n",
+          "Edge": "y",
+          "Firefox": "y",
+          "Safari": "y"
+        },
+        "小程序": {
+          "微信": "y",
+          "阿里": "y",
+          "百度": "y",
+          "字节跳动": "y",
+          "QQ": "y",
+          "钉钉": "y",
+          "快手": "y",
+          "飞书": "y",
+          "京东": "y"
+        },
+        "快应用": {
+          "华为": "u",
+          "联盟": "u"
+        }
+      }
+    }
+  }
+}

+ 257 - 0
uni_modules/v-tabs/readme.md

@@ -0,0 +1,257 @@
+## 插件说明
+
+> 这是 `v-tabs` 插件的升级版本,参数上有很大变动,支持 `H5` `小程序` `手机端`,如果是在之前的插件上升级的话,请注意参数的变更,触发的事件没有变更。
+
+## 使用说明
+
+### 1、最基本用法
+
+- 视图文件
+
+```html
+<v-tabs v-model="current" :tabs="tabs" @change="changeTab"></v-tabs>
+```
+
+- 脚本文件
+
+```js
+export default {
+  data() {
+    return {
+      current: 0,
+      tabs: ['军事', '国内', '新闻新闻', '军事', '国内', '新闻', '军事', '国内', '新闻']
+    }
+  },
+  methods: {
+    changeTab(index) {
+      console.log('当前选中的项:' + index)
+    }
+  }
+}
+```
+
+### 2、平铺整个屏幕
+
+- 视图文件
+
+```html
+<v-tabs v-model="activeTab" :scroll="false" :tabs="['全部', '进行中', '已完成']"></v-tabs>
+```
+
+- 脚本文件
+
+```js
+export default {
+  data() {
+    return {
+      activeTab: 0
+    }
+  }
+}
+```
+
+### 3、胶囊用法
+
+- 视图文件
+
+```html
+<v-tabs v-model="current" :tabs="tabs" :pills="true" line-height="0" activeColor="#fff" @change="changeTab"></v-tabs>
+```
+
+- 脚本文件
+
+```js
+data() {
+  return {
+    current: 2,
+    tabs: [
+        '军事',
+        '国内',
+        '新闻新闻',
+        '军事',
+        '国内',
+        '新闻',
+        '军事',
+        '国内',
+        '新闻',
+      ],
+  },
+  methods: {
+    changeTab(index) {
+      console.log('当前选中索引:' + index)
+    }
+  }
+}
+```
+
+## 文档说明
+
+### 1、属性说明
+
+|       参数        |  类型   |  默认值   |                                   说明                                    |
+| :---------------: | :-----: | :-------: | :-----------------------------------------------------------------------: |
+|       tabs        |  Array  |    []     |                              控制 tab 的列表                              |
+|       value       | Number  |     0     |                            必传(双向绑定的值)                             |
+|       color       | String  |  '#333'   |                               默认文字颜色                                |
+|    activeColor    | String  | '#2979ff' |                              选中文字的颜色                               |
+|     fontSize      | String  |  '28rpx'  |                      默认文字大小(rpx 或 px)(弃用)                      |
+|       bold        | Boolean |   true    |                              是否加粗选中项                               |
+|      scroll       | Boolean |   true    |                      是否显示滚动条,平铺设置 false                       |
+|      height       | String  |  '70rpx'  |                            tab 高度(rpx 或 px)                            |
+|    lineHeight     | String  |  '10rpx'  |                            滑块高度(rpx 或 px)                            |
+|     lineColor     | String  | '#2979ff' |                                滑块的颜色                                 |
+|     lineScale     | Number  |    0.5    |                              滑块宽度缩放值                               |
+|    lineRadius     | String  |  '10rpx'  |                          滑块圆角宽度(rpx 或 px)                          |
+|       pills       | Boolean |   false   |                               是否开启胶囊                                |
+|    pillsColor     | String  | '#2979ff' |                          胶囊背景颜色(rpx 或 px)                          |
+| pillsBorderRadius | String  |  '10rpx'  |                          胶囊圆角宽度(rpx 或 px)                          |
+|       field       | String  |    ''     |                 如果 tabs 子项是对象,输入需要展示的键名                  |
+|      bgColor      | String  |  '#fff'   |                     背景色,支持 linear-gradient 渐变                     |
+|      padding      | String  |    '0'    |                           整个 tab padding 属性                           |
+|       fixed       | Boolean |   false   |                              是否固定在顶部                               |
+|    paddingItem    | String  | '0 22rpx' |                选项的边距(设置上下不生效,需要设置高度)                 |
+|   lineAnimation   | Boolean |   true    | 是否需要 line 和 pills 的动画,在隐藏页面后默认移动到第一个的时候比较实用 |
+|      zIndex       | Number  |   1993    |                         控制 tab 的层级,默认1993                         |
+
+### 1.1 `tabs`参数展开说明
+
+#### 1.1.1 当`tabs`仅仅是单纯的数组时候,没有什么特别的地方
+
+```js
+export default {
+  data() {
+    return {
+      tabs: ['全部', '待付款', '待消费', '已完成', '已评价', '已过期', '已退款']
+    }
+  }
+}
+```
+
+#### 1.1.2 当`tabs`使用的数组对象的方式,特定参数需要注意一下
+
+- `disabled` 参数,可以控制按钮是否可以点击
+
+```js
+export default {
+  data() {
+    return {
+      tabs: [
+        { id: 1, name: '待付款', disabled: false },
+        { id: 2, name: '待收货', disabled: false },
+        { id: 3, name: '待评价', disabled: false },
+        { id: 4, name: '退款/售后', disabled: true },
+        { id: 5, name: '我的订单', disabled: false }
+      ]
+    }
+  }
+}
+```
+
+### 2、事件说明
+
+|  名称  | 参数  |                说明                |
+| :----: | :---: | :--------------------------------: |
+| change | index | 改变选中项触发, index 选中项的下标 |
+
+## 更新日志
+
+### 2.1.5(2023-11-02)
+1.[修复]修复`change`和`v-model`绑定的值不同步
+2.[修复]暂时停用`activeFontSize`选项
+3.[修改]修改默认激活的文字不加粗
+
+### 2.1.4(2023-10-12)
+1. [修改]修改计算方式
+2. [新增]外部可以通过`this.$refs.tabs.update()`方法主动更新
+
+### 2.1.3(2023-09-11)
+1. [新增]支持自定义插槽模式,具体可以查看示例代码使用方式。[gitee demo](https://github.com/xfjpeter/uni-plugins/blob/master/pages/tabs/tabs.vue#L47-L50) 或 [github demo](https://github.com/xfjpeter/uni-plugins/blob/master/pages/tabs/tabs.vue#L47-L50)
+
+### 2.1.2(2023-06-12)
+1. [新增]添加`z-index`参数控制层级大小,默认1993
+2. [说明]以后该插件只更新`uni_modules`方式的,`zip`方式的不提供更新了,如果需要的请到 [gitee uni-plugins](https://gitee.com/xfjpeter/uni-plugins) 或 [github uni-plugins](https://github.com/xfjpeter/uni-plugins)下载源码,自行使用
+
+### 2.1.1(2022-09-16)
+
+1. 将插件更新为`uni_modules`方式
+
+### 2022-08-12
+
+1. 增加`disable`参数,控制是否可以点击,只能应用在数组对象中,见[disabled 的用法](#112-当tabs使用的数组对象的方式特定参数需要注意一下)
+
+```js
+export default {
+  data() {
+    return {
+      tabs: [{ id: 1, name: '' }]
+    }
+  }
+}
+```
+
+### 2022-01-27
+
+1. 更新属性`line-animation`设置为`false`可以不要动画,这是好多朋友问到,特此加上
+
+### 2020-09-24
+
+1. 修复 `v-tabs` 第一次可能出现第一个标签显示不完整的情况
+2. 修改了 `pages/tabs/order` 示例文件
+
+### 2020-09-21
+
+1. 修复添加 `fixed` 属性后,滚动条无效
+2. 修复选项很少的情况下,下划线计算计算错误
+3. 新增 `paddingItem` 属性,设置选项左右边距(上下边距需要设置 `height` 属性,或者设置 `padding` 属性)
+
+**写在最后:**
+欢迎各位老铁反馈 bug ,本人后端 PHP 一枚,只是应为感兴趣前端,自己琢磨,自己搞。如果你在使用的过程中有什么不合理,需要优化的,都可以在下面评论(或加我 QQ: 1207791534),本人看见后回复、修正,感谢。
+
+### 2020-09-17
+
+1. 紧急修复 bug,横向滑动不了的情况
+
+### 2020-09-16
+
+1. 新增 `fixed` 属性,是否固定在顶部,示例地址:`pages/tabs/tabs-static`
+2. 优化之前的页面结构
+
+**注意:**
+
+1. 使用 `padding` 属性的时候,尽量不要左右边距,会导致下划线位置不对
+2. 如果不绑定 `v-model` 会导致 `change` 事件改变的时候,下划线不跟随问题
+
+### 2020-09-09
+
+1. 修复 `width` 错误,dom 加载的时候没有及时获取到 `data` 属性导致的。
+
+### 2020-08-29
+
+1. 优化异步改变 `tabs` 后,下划线不初始化问题
+2. `github` 地址上有图 2 的源码,需要的自行下载,页面路径:`pages/tabs/order`
+
+### 2020-08-20
+
+1. 优化 `节点查询` 和 `选中渲染`
+2. 优化支付宝中 `createSelectorQuery()` 的影响
+
+### 2020-08-19
+
+1. 优化 `change` 事件触发机制
+
+### 2020-08-16
+
+1. 修改默认高度为 `70rpx`
+2. 新增属性 `bgColor`,可设置背景颜色,默认 `#fff`
+3. 新增整个 `tab` 的 `padding` 属性,默认 `0`
+
+### 2020-08-13
+
+1. 全新的 `v-tabs 2.0`
+2. 支持 `H5` `小程序` `APP`
+3. 属性高度可配置
+
+## 预览
+
+![v-tabs 2.0.1.gif](https://tva1.sinaimg.cn/large/007S8ZIlgy1ghsv40mj76g30ai0i2tsd.gif)
+![v-tabs 2.0.2.gif](https://img-cdn-aliyun.dcloud.net.cn/stream/plugin_screens/42f3a920-a674-11ea-8a24-ffee00625e2e_1.png?v=1597912963)