| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 | <template>  <!-- 在微信小程序 app vue端 h5 使用wxs 实现-->  <!-- #ifdef APP-VUE || MP-WEIXIN || H5 -->  <view class="uni-swipe">    <!--  #ifdef MP-WEIXIN || VUE3 -->    <view :change:prop="wxsswipe.showWatch" :data-disabled="disabled" :data-threshold="threshold" :prop="is_show"          class="uni-swipe_box" @touchend="wxsswipe.touchend" @touchmove="wxsswipe.touchmove"          @touchstart="wxsswipe.touchstart">      <!-- #endif -->      <!--  #ifndef MP-WEIXIN || VUE3 -->      <view :change:prop="renderswipe.showWatch" :data-disabled="disabled+''" :data-threshold="threshold" :prop="is_show"            class="uni-swipe_box" @touchend="renderswipe.touchend" @touchmove="renderswipe.touchmove"            @touchstart="renderswipe.touchstart">        <!-- #endif -->        <!-- 在微信小程序 app vue端 h5 使用wxs 实现-->        <view class="uni-swipe_button-group button-group--left">          <slot name="left">            <view v-for="(item,index) in leftOptions" :key="index" :style="{					  backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD'					}" class="uni-swipe_button button-hock" @touchend="appTouchEnd($event,index,item,'left')"                  @touchstart="appTouchStart"                  @click.stop="onClickForPC(index,item,'left')">              <text :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'}"                    class="uni-swipe_button-text">                {{ item.text }}              </text>            </view>          </slot>        </view>        <view class="uni-swipe_text--center">          <slot></slot>        </view>        <view class="uni-swipe_button-group button-group--right">          <slot name="right">            <view v-for="(item,index) in rightOptions" :key="index" :style="{					  backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD'					}" class="uni-swipe_button button-hock" @touchend="appTouchEnd($event,index,item,'right')"                  @touchstart="appTouchStart"                  @click.stop="onClickForPC(index,item,'right')">              <text :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'}"                    class="uni-swipe_button-text">                {{ item.text }}              </text>            </view>          </slot>        </view>      </view>    </view>    <!-- #endif -->    <!-- app nvue端 使用 bindingx -->    <!-- #ifdef APP-NVUE -->    <view ref="selector-box--hock" class="uni-swipe" @horizontalpan="touchstart" @touchend="touchend">      <view ref='selector-left-button--hock' class="uni-swipe_button-group button-group--left">        <slot name="left">          <view v-for="(item,index) in leftOptions" :key="index" :style="{				  backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD'				}" class="uni-swipe_button button-hock" @click.stop="onClick(index,item,'left')">            <text                :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF', fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'}"                class="uni-swipe_button-text">              {{ item.text }}            </text>          </view>        </slot>      </view>      <view ref='selector-right-button--hock' class="uni-swipe_button-group button-group--right">        <slot name="right">          <view v-for="(item,index) in rightOptions" :key="index" :style="{				  backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD'				}" class="uni-swipe_button button-hock" @click.stop="onClick(index,item,'right')">            <text                :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'}"                class="uni-swipe_button-text">              {{ item.text }}            </text>          </view>        </slot>      </view>      <view ref='selector-content--hock' class="uni-swipe_box">        <slot></slot>      </view>    </view>    <!-- #endif -->    <!-- 其他平台使用 js ,长列表性能可能会有影响-->    <!-- #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ -->    <view class="uni-swipe">      <view :class="{ani:ani}" :style="{transform:moveLeft}" class="uni-swipe_box" @touchend="touchend"            @touchmove="touchmove" @touchstart="touchstart">        <view :class="[elClass]" class="uni-swipe_button-group button-group--left">          <slot name="left">            <view v-for="(item,index) in leftOptions" :key="index" :style="{					  backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',					  fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'					}" class="uni-swipe_button button-hock" @touchend="appTouchEnd($event,index,item,'left')"                  @touchstart="appTouchStart">              <text :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"                    class="uni-swipe_button-text">{{ item.text }}              </text>            </view>          </slot>        </view>        <slot></slot>        <view :class="[elClass]" class="uni-swipe_button-group button-group--right">          <slot name="right">            <view v-for="(item,index) in rightOptions" :key="index" :style="{					  backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',					  fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'					}" class="uni-swipe_button button-hock" @touchend="appTouchEnd($event,index,item,'right')"                  @touchstart="appTouchStart">              <text :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"                    class="uni-swipe_button-text">{{ item.text }}              </text>            </view>          </slot>        </view>      </view>    </view>    <!-- #endif --></template><script lang="wxs" module="wxsswipe" src="./wx.wxs"></script><script lang="renderjs" module="renderswipe">	import render from './render.js'	export default {		mounted(e, ins, owner) {			this.state = {}		},		methods: {			showWatch(newVal, oldVal, ownerInstance, instance) {				render.showWatch(newVal, oldVal, ownerInstance, instance, this)			},			touchstart(e, ownerInstance) {				render.touchstart(e, ownerInstance, this)			},			touchmove(e, ownerInstance) {				render.touchmove(e, ownerInstance, this)			},			touchend(e, ownerInstance) {				render.touchend(e, ownerInstance, this)			}		}	}</script><script>import mpwxs from './mpwxs'import bindingx from './bindingx.js'import mpother from './mpother'/** * SwipeActionItem 滑动操作子组件 * @description 通过滑动触发选项的容器 * @tutorial https://ext.dcloud.net.cn/plugin?id=181 * @property {Boolean} show = [left|right|none]  开启关闭组件,auto-close = false 时生效 * @property {Boolean} disabled = [true|false]    是否禁止滑动 * @property {Boolean} autoClose = [true|false]  滑动打开当前组件,是否关闭其他组件 * @property {Number}  threshold          滑动缺省值 * @property {Array} leftOptions          左侧选项内容及样式 * @property {Array} rgihtOptions          右侧选项内容及样式 * @event {Function} click              点击选项按钮时触发事件,e = {content,index} ,content(点击内容)、index(下标) * @event {Function} change            组件打开或关闭时触发,left\right\none */export default {  mixins: [mpwxs, bindingx, mpother],  emits: ['click', 'change'],  props: {    // 控制开关    show: {      type: String,      default: 'none'    },    // 禁用    disabled: {      type: Boolean,      default: false    },    // 是否自动关闭    autoClose: {      type: Boolean,      default: true    },    // 滑动缺省距离    threshold: {      type: Number,      default: 20    },    // 左侧按钮内容    leftOptions: {      type: Array,      default() {        return []      }    },    // 右侧按钮内容    rightOptions: {      type: Array,      default() {        return []      }    }  },  // #ifndef VUE3  // TODO vue2  destroyed() {    if (this.__isUnmounted) return    this.uninstall()  },  // #endif  // #ifdef VUE3  // TODO vue3  unmounted() {    this.__isUnmounted = true    this.uninstall()  },  // #endif  methods: {    uninstall() {      if (this.swipeaction) {        this.swipeaction.children.forEach((item, index) => {          if (item === this) {            this.swipeaction.children.splice(index, 1)          }        })      }    },    /**     * 获取父元素实例     */    getSwipeAction(name = 'uniSwipeAction') {      let parent = this.$parent;      let parentName = parent.$options.name;      while (parentName !== name) {        parent = parent.$parent;        if (!parent) return false;        parentName = parent.$options.name;      }      return parent;    }  }}</script><style lang="scss">.uni-swipe {  position: relative;  /* #ifndef APP-NVUE */  overflow: hidden;  /* #endif */}.uni-swipe_box {  /* #ifndef APP-NVUE */  display: flex;  flex-shrink: 0;  // touch-action: none;  /* #endif */  position: relative;}.uni-swipe_content {  // border: 1px red solid;}.uni-swipe_text--center {  width: 100%;  /* #ifndef APP-NVUE */  cursor: grab;  /* #endif */}.uni-swipe_button-group {  /* #ifndef APP-NVUE */  box-sizing: border-box;  display: flex;  /* #endif */  flex-direction: row;  position: absolute;  top: 0;  bottom: 0;  /* #ifdef H5 */  cursor: pointer;  /* #endif */}.button-group--left {  left: 0;  transform: translateX(-100%)}.button-group--right {  right: 0;  transform: translateX(100%)}.uni-swipe_button {  /* #ifdef APP-NVUE */  flex: 1;  /* #endif */  /* #ifndef APP-NVUE */  display: flex;  /* #endif */  flex-direction: row;  justify-content: center;  align-items: center;  padding: 0 20px;}.uni-swipe_button-text {  /* #ifndef APP-NVUE */  flex-shrink: 0;  /* #endif */  font-size: 14px;}.ani {  transition-property: transform;  transition-duration: 0.3s;  transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);}/* #ifdef MP-ALIPAY */.movable-area {  /* width: 100%; */  height: 45px;}.movable-view {  display: flex;  /* justify-content: center; */  position: relative;  flex: 1;  height: 45px;  z-index: 2;}.movable-view-button {  display: flex;  flex-shrink: 0;  flex-direction: row;  height: 100%;  background: #C0C0C0;}/* .transition {  transition: all 0.3s;} */.movable-view-box {  flex-shrink: 0;  height: 100%;  background-color: #fff;}/* #endif */</style>
 |