xiaohaizhao 11 meses atrás
pai
commit
35bb2a50c4

+ 11 - 8
components/Yl_FunTabs/index.js

@@ -47,17 +47,20 @@ Component({
         setActive() {
             const that = this,
                 active = this.data.active,
-                query = wx.createSelectorQuery().in(this)
-            query.select('#active' + active).boundingClientRect(function (res) {
-                let index = res.dataset.index,
-                    scrollLeft = res.left;
-                if (index >= 6) scrollLeft += ((index - 4) * res.width);
-                if (that.data.scrollLeft > scrollLeft && index >= 4) scrollLeft += (2 * res.width)
+                query = wx.createSelectorQuery().in(this);
+
+            query.select('#active' + active).boundingClientRect((res) => {
+                if (!res) return; // 防止未找到元素时报错
+                const tabWidth = res.width; // 获取 tab 的宽度
+                const screenWidth = wx.getSystemInfoSync().windowWidth; // 获取屏幕宽度(px)
+                const scrollLeft = Math.max(0, res.left + that.data.scrollLeft - (screenWidth / 2) + (tabWidth / 2)); // 居中计算并确保不小于 0
+
                 that.setData({
                     scrollLeft
-                })
+                });
             }).exec();
-            this.triggerEvent("onChenge", active)
+
+            this.triggerEvent("onChenge", active);
         },
         myTouchStart(e) {
             return;

+ 2 - 2
salesPanel/AnalysisOfTheProportionOfProductCategoriesInOrders/index.js

@@ -203,13 +203,13 @@ Component({
                     that.getList()
                 }, 200)
             };
-
+            console.log("data",data)
             let option = {
                 tooltip: {
                     trigger: 'item',
                     formatter: function (params) {
                         changeUnwriteoffamounttype(data[params.dataIndex]);
-                        return `${params.marker}${params.name}: ${params.value}`;
+                        return `${params.marker}${params.name}: ${params.value}%`;
                     },
                 },
                 legend: {