Browse Source

Merge branch 'v2' of https://github.com/jdf2e/nutui into v2

dushoujun 5 years ago
parent
commit
3bd3c101fc

+ 42 - 23
src/packages/price/price.vue

@@ -1,23 +1,25 @@
 <template>
-    <div class="nut-price"  v-html="priceShow"><span></span></div>
+    <div class="nut-price" v-html="priceShow">
+        <span></span>
+    </div>
 </template>
 <script>
 export default {
-    name:'nut-price',
+    name: "nut-price",
     props: {
-        'price':{
-            type: [Number,String],
+        price: {
+            type: [Number, String],
             default: 0
         },
-        'needSymbol':{
+        needSymbol: {
             type: Boolean,
             default: true
         },
-        'decimalDigits':{
-            type: [Number,String],
+        decimalDigits: {
+            type: [Number, String],
             default: 2
         },
-        'thousands': {
+        thousands: {
             type: Boolean,
             default: false
         }
@@ -25,7 +27,9 @@ export default {
     computed: {
         priceShow() {
             let self = this;
-            let symbol = self.needSymbol?'<span class="price-symbol">¥</span>':'';
+            let symbol = self.needSymbol
+                ? '<span class="price-symbol">¥</span>'
+                : "";
             return symbol + self.formatToHump(self.price);
         }
     },
@@ -35,18 +39,31 @@ export default {
     methods: {
         //判断是否为小数点
         checkPoint(num) {
-            return (String(num)).indexOf('.') > 0;
+            return String(num).indexOf(".") > 0;
         },
 
         //将数字转换成驼峰形式
         formatToHump(num) {
             let self = this;
-            num = String(num).replace('¥','');
-            if(self.checkPoint(num)) {
-                let numArray = String(num).split('.');
-                return '<span class="price-big">'+self.formatThousands(numArray[0]) +'</span><span class="price-point">.</span><span class="price-small">' + self.formatDecimal(numArray[1]) + '</span>';
+            num = String(num).replace("¥", "");
+            if (self.checkPoint(num)) {
+                let numArray = Number(num).toFixed(this.decimalDigits);
+                numArray = String(numArray).split(".");
+                return (
+                    '<span class="price-big">' +
+                    self.formatThousands(numArray[0]) +
+                    '</span><span class="price-point">.</span><span class="price-small">' +
+                    self.formatDecimal(numArray[1]) +
+                    "</span>"
+                );
             } else {
-                return '<span class="price-big">'+ self.formatThousands(num) +'</span><span class="price-point">.</span><span class="price-small">' + self.formatDecimal(0) + '</span>';
+                return (
+                    '<span class="price-big">' +
+                    self.formatThousands(num) +
+                    '</span><span class="price-point">.</span><span class="price-small">' +
+                    self.formatDecimal(0) +
+                    "</span>"
+                );
             }
         },
 
@@ -54,21 +71,23 @@ export default {
         formatDecimal(decimalNum) {
             let self = this;
             let decimalDigits = self.decimalDigits;
-            let result = '0.' + String(decimalNum);
-            let resultFixed = (result/1).toFixed(decimalDigits);
-            return String(resultFixed).substring(2,resultFixed.length);
+            let result = "0." + String(decimalNum);
+            let resultFixed = (result / 1).toFixed(decimalDigits);
+            return String(resultFixed).substring(2, resultFixed.length);
         },
         //千分位显示
         formatThousands(num) {
             let self = this;
-            let result = '';
-            // let 
-            if(self.thousands) {
-                return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
+            let result = "";
+            // let
+            if (self.thousands) {
+                return (num || 0)
+                    .toString()
+                    .replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
             } else {
                 return num;
             }
         }
     }
-}
+};
 </script>

+ 23 - 5
src/packages/scroller/horizontal-scroll.vue

@@ -20,6 +20,10 @@ export default {
         scrollTo: {
             type: Number,
             default: 1
+        },
+	listWidth: {
+            type: Number,
+            default: 0
         }
     },
     watch: {
@@ -49,7 +53,10 @@ export default {
     },
     methods: {
         isShow() {
-            let wrapH = this.$refs.wrapper.clientWidth;
+            let wrapH = this.listWidth ? this.listWidth : 
+                (window.innerWidth ||
+                document.documentElement.clientWidth ||
+                document.body.clientWidth);
             let listH = this.$refs.list.offsetWidth;
             if (wrapH <= listH) {
                 this.isShowLoadMore =  true;
@@ -72,7 +79,10 @@ export default {
 
         setMove(move, type, time) {
             let updateMove = move + this.transformX;
-            let w = this.$refs.wrapper.clientWidth;
+            let w = this.listWidth ? this.listWidth :
+                (window.innerWidth ||
+                document.documentElement.clientWidth ||
+                document.body.clientWidth);
             let offsetWidth = this.$refs.list.offsetWidth;
             if (type === 'end') {
                 if (updateMove > 0) {
@@ -119,18 +129,25 @@ export default {
             if (!(Math.abs(move) > 20 && Math.abs(move) > Math.abs(moveY))) {
                 return false;
             } else {
-                let w = this.$refs.wrapper.clientWidth;
+                let w = this.listWidth ? this.listWidth :
+                    (window.innerWidth ||
+                    document.documentElement.clientWidth ||
+                    document.body.clientWidth);
                 let maxMove = -this.$refs.list.offsetWidth + w;
                 callback && callback(move, maxMove, moveY);
             }
         },
 
         touchMove(event) {
-            event.preventDefault();
+            //event.preventDefault();
             let changedTouches = event.changedTouches[0];
             this.touchParams.lastTime = event.timestamp || Date.now();
             let moveTime = this.touchParams.lastTime - this.touchParams.startTime;
             this.touchEvent(changedTouches, (move, maxMove, moveY) => {
+                event.preventDefault();
+                if (event.cancelable) {
+                    event.preventDefault();
+                }
                 if (move > 0 && this.isFirstShow) {
                     this.isFirstShow = false;
                 }
@@ -139,13 +156,14 @@ export default {
         },
 
         touchEnd(event) {
+            event.stopPropagation();
             let changedTouches = event.changedTouches[0];
             this.touchParams.lastTime = event.timestamp || Date.now();
             let moveTime = this.touchParams.lastTime - this.touchParams.startTime;
             this.touchEvent(changedTouches, (move, maxMove) => {
                 //if (moveTime <= 300) {
                 if (Math.abs(move) > 100) {
-                    move = move * 2;
+                   move = move * 1.5;
                 }
 
                 // 释放跳转之类

+ 8 - 5
src/packages/scroller/scroller.scss

@@ -2,20 +2,23 @@
 .nut-scroller{
     display: flex;
     height: 100%;
+    width: 100%;
     overflow: hidden;
 }
 // 横向滚动 
 .nut-hor-scroll{
     height: 100%;
     width: 100%;
-    // overflow: hidden;
+    overflow: hidden;
+    //touch-action: none; 
     .nut-hor-list{
         height: 100%;
-        touch-action: none;
+        width: auto;
         display: inline-flex;
-        flex-direction: row;
-        box-orient: horizontal;
-        box-direction: normal;
+        // display: flex;
+        // flex-direction: row;
+        // box-orient: horizontal;
+        // box-direction: normal;
     }
     .nut-hor-control{
         height: 100%;