diff --git a/common/mixin/image-longpress.js b/common/mixin/image-longpress.js new file mode 100644 index 0000000..148f474 --- /dev/null +++ b/common/mixin/image-longpress.js @@ -0,0 +1,38 @@ +/** + * 微信小程序图片长按识别二维码 mixin + * 自动为页面中的所有 image 组件添加 show-menu-by-longpress 属性 + */ +export default { + data() { + return { + // 需要排除的图片类名(不需要长按识别的) + excludeImageClass: ['no-longpress', 'swiper-image', 'banner-image'] + } + }, + mounted() { + // #ifdef MP-WEIXIN + this.$nextTick(() => { + this.addLongpressToImages() + }) + // #endif + }, + methods: { + /** + * 为页面中的所有 image 添加长按识别支持 + */ + addLongpressToImages() { + // 获取当前页面所有 image 组件 + const images = document.querySelectorAll && document.querySelectorAll('image') + if (images) { + images.forEach(img => { + // 检查是否需要排除 + const className = img.className || '' + const shouldExclude = this.excludeImageClass.some(cls => className.includes(cls)) + if (!shouldExclude) { + img.setAttribute('show-menu-by-longpress', 'true') + } + }) + } + } + } +} diff --git a/components-diy/diy-article.vue b/components-diy/diy-article.vue index 71b3888..f3d1f4d 100644 --- a/components-diy/diy-article.vue +++ b/components-diy/diy-article.vue @@ -12,7 +12,7 @@ + @error="imgError(index)" show-menu-by-longpress/> {{ item.article_title }} diff --git a/components-diy/diy-audio.vue b/components-diy/diy-audio.vue index 316c3e7..8629a2b 100644 --- a/components-diy/diy-audio.vue +++ b/components-diy/diy-audio.vue @@ -17,7 +17,7 @@ - + {{ value.text }} diff --git a/components-diy/diy-bargain.vue b/components-diy/diy-bargain.vue index ef68915..5c39456 100644 --- a/components-diy/diy-bargain.vue +++ b/components-diy/diy-bargain.vue @@ -10,7 +10,7 @@ :style="{ fontSize: value.titleStyle.fontSize * 2 + 'rpx', color: value.titleStyle.textColor, fontWeight: value.titleStyle.fontWeight ? 'bold' : '' }"> {{ value.titleStyle.leftText }} - + 低至0元免费拿 + @error="imageError(index)" show-menu-by-longpress/> @@ -41,7 +41,7 @@ + :src="$util.img('public/uniapp/bargain/progress_bar_01.png')" show-menu-by-longpress/> @@ -89,7 +89,7 @@ + @error="imageError(index)" :lazy-load="true" show-menu-by-longpress/> @@ -134,7 +134,7 @@ + @error="imageError(dataIndex)" :lazy-load="true" show-menu-by-longpress/> diff --git a/components-diy/diy-category-item.vue b/components-diy/diy-category-item.vue index 2f78391..14509db 100644 --- a/components-diy/diy-category-item.vue +++ b/components-diy/diy-category-item.vue @@ -2,7 +2,7 @@ - + @@ -11,7 +11,7 @@ - + {{ one.category_name }} @@ -25,7 +25,7 @@ - + {{ two.category_name }} @@ -102,11 +102,11 @@ - + + mode="widthFix" show-menu-by-longpress/> @@ -158,7 +158,7 @@ - + - + diff --git a/components-diy/diy-fenxiao-goods-list.vue b/components-diy/diy-fenxiao-goods-list.vue index 812d82c..aab5fd8 100644 --- a/components-diy/diy-fenxiao-goods-list.vue +++ b/components-diy/diy-fenxiao-goods-list.vue @@ -5,7 +5,7 @@ :class="[value.ornament.type]" :style="goodsItemCss"> + :src="$util.img(item.goods_image, { size: 'mid' })" mode="widthFix" @error="imgError(index)" show-menu-by-longpress/> diff --git a/components-diy/diy-goods-brand.vue b/components-diy/diy-goods-brand.vue index 54845df..c4f5209 100644 --- a/components-diy/diy-goods-brand.vue +++ b/components-diy/diy-goods-brand.vue @@ -9,7 +9,7 @@ + :style="itemCss" show-menu-by-longpress/> diff --git a/components-diy/diy-goods-list.vue b/components-diy/diy-goods-list.vue index 3c3f931..452354b 100644 --- a/components-diy/diy-goods-list.vue +++ b/components-diy/diy-goods-list.vue @@ -49,9 +49,9 @@ + :src="$util.img('public/uniapp/index/VIP.png')" show-menu-by-longpress/> + :src="$util.img('public/uniapp/index/discount.png')" show-menu-by-longpress/> + :src="$util.img('public/uniapp/index/VIP.png')" show-menu-by-longpress/> + :src="$util.img('public/uniapp/index/discount.png')" show-menu-by-longpress/> + :src="$util.img('public/uniapp/index/VIP.png')" show-menu-by-longpress/> + :src="$util.img('public/uniapp/index/discount.png')" show-menu-by-longpress/> + mode="widthFix" show-menu-by-longpress/> {{ goodsValue.labelStyle.title }} diff --git a/components-diy/diy-groupbuy.vue b/components-diy/diy-groupbuy.vue index 0550dc1..813bc87 100644 --- a/components-diy/diy-groupbuy.vue +++ b/components-diy/diy-groupbuy.vue @@ -7,7 +7,7 @@ + @error="imageError(index)" show-menu-by-longpress> + @error="imageError(index)" show-menu-by-longpress/> + @error="imageError(dataIndex)" show-menu-by-longpress/> + mode="aspectFill" show-menu-by-longpress/> + mode="aspectFill" show-menu-by-longpress/> {{ item.category_name }} @@ -73,9 +73,9 @@ :key="index" @tap.stop="toCateGoodsList(item.category_id_2, 2)"> + mode="aspectFill" show-menu-by-longpress/> + mode="aspectFill" show-menu-by-longpress/> {{ item.category_name }} @@ -88,7 +88,7 @@ :key="index" v-if="index >= (page - 1) * 10 && index < page * 10" @tap.stop="toCateGoodsList(item.category_id_2, 2)"> - + {{ item.category_name }} @@ -104,19 +104,19 @@ + :src="$util.img(cateList[pageIndex].image_adv)" mode="widthFix" show-menu-by-longpress/> + @error="imgError(index)" show-menu-by-longpress/> {{ goodsTag(item) }} - + @@ -133,11 +133,11 @@ + mode="widthFix" show-menu-by-longpress/> + mode="widthFix" show-menu-by-longpress/> diff --git a/components-diy/diy-kefu.vue b/components-diy/diy-kefu.vue index 6f1b0d8..b3498fb 100644 --- a/components-diy/diy-kefu.vue +++ b/components-diy/diy-kefu.vue @@ -3,7 +3,7 @@ - + diff --git a/components-diy/diy-listmenu.vue b/components-diy/diy-listmenu.vue index 302bcf4..a6e6b78 100644 --- a/components-diy/diy-listmenu.vue +++ b/components-diy/diy-listmenu.vue @@ -1,7 +1,7 @@