Browse Source

防止重复触发事件

lilei 4 năm trước cách đây
mục cha
commit
ed7914981c

+ 4 - 2
components/uni-cart-fix/uni-cart-fix.vue

@@ -18,8 +18,10 @@
 			},
 			methods: {
 				toCart() {
-					uni.navigateTo({
-						url:"/pages/cart/cart"
+					this.$bindClick(function(){
+						uni.navigateTo({
+							url:"/pages/cart/cart"
+						})
 					})
 				}
 			},

+ 7 - 5
components/uni-coods/uni-coods.vue

@@ -1,7 +1,7 @@
 <template>
 	<view class="goods-list">
 		<view class="goods-item" v-for="item in list" :key="item.id">
-			<view class="goods-imgs"  @click="toDetail(item)">
+			<view class="goods-imgs"  @tap="toDetail(item)">
 				<view v-if="item.inventoryQty == 0" class="goods-staus">已售罄</view>
 				<view v-if="item.delFlage == 0 || item.state == 0" class="goods-staus">已失效</view>
 				<u-lazy-load 
@@ -12,13 +12,13 @@
 				:error-img="errorImg">
 				</u-lazy-load>
 			</view>
-			<view class="name ellipsis-two"  @click="toDetail(item)">{{item.name}}</view>
+			<view class="name ellipsis-two"  @tap="toDetail(item)">{{item.name}}</view>
 			<view class="price">
 				<view>
 					<text>{{item.sellGold}}</text>
 					<u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
 				</view>
-				<view @click="addCart(item)" v-if="item.inventoryQty > 0">
+				<view @tap="addCart(item)" v-if="item.inventoryQty > 0">
 					<u-image mode="scaleToFill" width="45rpx" height="45rpx" src="/static/addCart.png"></u-image>
 				</view>
 			</view>
@@ -50,13 +50,15 @@
 				errorImg: '/static/imgError.png',
 				timer: null,
 				finger: {x:0,y:0},
-				linePos: null
+				linePos: null,
 			}
 		},
 		methods: {
 			// 加入购物车
 			addCart(item) {
-				uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
+				this.$bindClick(function(){
+					uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
+				})
 			},
 			// 商品详情
 			toDetail(item){

+ 10 - 0
main.js

@@ -38,6 +38,16 @@ Vue.prototype.$hasPermissions = function (value) {
  }
  return isExist;
 }
+// 防止重复触发事件
+Vue.prototype.$bindClick = function (fun) {
+	if(!store.state.vuex_isClick){
+		fun()
+		store.state.vuex_isClick = true
+		setTimeout(()=>{
+			store.state.vuex_isClick = false
+		},300)
+	}
+}
 const app = new Vue({
 	store,
     ...App

+ 6 - 3
pages/goods/goodsDetail.vue

@@ -48,8 +48,8 @@
 		</view>
 		<!-- 底部浮动按钮 -->
 		<view class="bottom-btns" v-if="goodContent&&goodContent.inventoryQty > 0&&goodContent.state==1">
-			<view><u-button :custom-style="addCartButton" type="warning" @click="addCart">加入购物车</u-button></view>
-			<view><u-button :custom-style="toOrderButton" type="error" @click="toOrder()">立即下单</u-button></view>
+			<view><u-button :custom-style="addCartButton" type="warning" @tap="addCart">加入购物车</u-button></view>
+			<view><u-button :custom-style="toOrderButton" type="error" @tap="toOrder()">立即下单</u-button></view>
 		</view>
 		<!-- 购物车 -->
 		<uni-cart-fix></uni-cart-fix>
@@ -103,8 +103,11 @@
 			},
 			// 加入购物车
 			addCart(){
+				let _this = this
 				let item = this.goodContent
-				uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:this.nums})
+				this.$bindClick(function(){
+					uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:_this.nums})
+				})
 			},
 			// 立即下单
 			toOrder(){

+ 2 - 2
pages/goods/index.vue

@@ -1,13 +1,13 @@
 <template>
 	<view class="content">
-		<u-swiper height="250" @click="clickBanner" :list="imageTopList"></u-swiper>
+		<u-swiper height="250" @tap="clickBanner" :list="imageTopList"></u-swiper>
 		<view class="t1">
 			<u-image height="40" src="/static/t1.png"></u-image>
 		</view>
 		<!-- 商品 -->
 		<view class="goods">
 			<view v-for="(item,index) in goodsList" :key="index" v-if="goodsList.length&&item.list.length">
-				<u-section :title="item.type.name" font-size="35" line-color="#01c9b2" sub-title="更多" @click="toGoods(item.type)"></u-section>
+				<u-section :title="item.type.name" font-size="35" line-color="#01c9b2" sub-title="更多" @tap="toGoods(item.type)"></u-section>
 				<view class="goods-list">
 					<uni-coods :goldLimit="item.type.goldLimit" :list="item.list"></uni-coods>
 				</view>

+ 4 - 4
pages/toOrder/index.vue

@@ -1,6 +1,6 @@
 <template>
 	<view class="cart-pages">
-		<view v-if="!userInfo.receiveAddress" @click="editAddress" class="noAddress">
+		<view v-if="!userInfo.receiveAddress" @tap="editAddress" class="noAddress">
 			<view>请输入收货地址</view>
 			<u-icon name="arrow-right" size="36"></u-icon>
 		</view>
@@ -12,7 +12,7 @@
 				 <view class="address">{{receiveAddress}}</view>
 				 <view>{{userInfo.receiverName +'&nbsp;&nbsp;&nbsp;' + userInfo.receiverPhone}}</view>
 			</view>
-			<view @click="editAddress">
+			<view @tap="editAddress">
 				<u-image height="50rpx" width="50rpx" src="/static/edit.png"></u-image>
 			</view>
 		</view>
@@ -54,7 +54,7 @@
 			  <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
 			</view>
 			<view>
-				<u-button size="mini" :loading="btnLoading" :custom-style="toOrderButton" type="error" @click="toSaveOrder">确认支付</u-button>
+				<u-button size="mini" :loading="btnLoading" :custom-style="toOrderButton" type="error" @tap="toSaveOrder">确认支付</u-button>
 			</view>
 		</view>
 		<!-- 提示用户设置支付密码 -->
@@ -92,7 +92,7 @@
 					placeholder="请输入支付密码" />
 				</view>
 				<view class="fot-btn">
-					<u-button :loading="payBtn" @click="toPay" type="error" >确认支付</u-button>
+					<u-button :loading="payBtn" @tap="toPay" type="error" >确认支付</u-button>
 				</view>
 			</view>
 		</u-popup>

+ 2 - 1
store/index.js

@@ -117,7 +117,8 @@ const store = new Vuex.Store({
 		vuex_kfMobile: '4008826012',
 		// 垃圾箱类型
 		vuex_rubbishType: [],
-		vuex_noLogin: false
+		vuex_noLogin: false,
+		vuex_isClick: false
 	},
 	mutations: {
 		$uStore(state, payload) {