uni-swipe-action-item.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <!-- 在微信小程序 app vue端 h5 使用wxs 实现-->
  3. <!-- #ifdef APP-VUE || MP-WEIXIN || H5 -->
  4. <view class="uni-swipe">
  5. <view
  6. class="uni-swipe_box"
  7. :data-threshold="threshold"
  8. :data-disabled="disabled"
  9. :change:prop="swipe.sizeReady"
  10. :prop="btn"
  11. @touchstart="swipe.touchstart"
  12. @touchmove="swipe.touchmove"
  13. @touchend="swipe.touchend"
  14. >
  15. <!-- 在微信小程序 app vue端 h5 使用wxs 实现-->
  16. <view class="uni-swipe_button-group button-group--left">
  17. <slot name="left">
  18. <view
  19. v-for="(item,index) in leftOptions"
  20. :data-button="btn"
  21. :key="index"
  22. :style="{
  23. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  24. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  25. }"
  26. class="uni-swipe_button button-hock"
  27. @touchstart="appTouchStart"
  28. @touchend="appTouchEnd($event,index,item,'left')"
  29. ><text
  30. class="uni-swipe_button-text"
  31. :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"
  32. >{{ item.text }}</text></view>
  33. </slot>
  34. </view>
  35. <slot></slot>
  36. <view class="uni-swipe_button-group button-group--right">
  37. <slot name="right">
  38. <view
  39. v-for="(item,index) in rightOptions"
  40. :data-button="btn"
  41. :key="index"
  42. :style="{
  43. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  44. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  45. }"
  46. class="uni-swipe_button button-hock"
  47. @touchstart="appTouchStart"
  48. @touchend="appTouchEnd($event,index,item,'right')"
  49. ><text
  50. class="uni-swipe_button-text"
  51. :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"
  52. >{{ item.text }}</text></view>
  53. </slot>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- #endif -->
  58. <!-- app nvue端 使用 bindingx -->
  59. <!-- #ifdef APP-NVUE -->
  60. <view
  61. ref="selector-box--hock"
  62. class="uni-swipe"
  63. @horizontalpan="touchstart"
  64. @touchend="touchend"
  65. >
  66. <view
  67. ref='selector-left-button--hock'
  68. class="uni-swipe_button-group button-group--left"
  69. >
  70. <slot name="left">
  71. <view
  72. v-for="(item,index) in leftOptions"
  73. :data-button="btn"
  74. :key="index"
  75. :style="{
  76. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  77. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  78. }"
  79. class="uni-swipe_button button-hock"
  80. @click.stop="onClick(index,item,'left')"
  81. ><text
  82. class="uni-swipe_button-text"
  83. :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"
  84. >{{ item.text }}</text></view>
  85. </slot>
  86. </view>
  87. <view
  88. ref='selector-right-button--hock'
  89. class="uni-swipe_button-group button-group--right"
  90. >
  91. <slot name="right">
  92. <view
  93. v-for="(item,index) in rightOptions"
  94. :data-button="btn"
  95. :key="index"
  96. :style="{
  97. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  98. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  99. }"
  100. class="uni-swipe_button button-hock"
  101. @click.stop="onClick(index,item,'right')"
  102. ><text
  103. class="uni-swipe_button-text"
  104. :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"
  105. >{{ item.text }}</text></view>
  106. </slot>
  107. </view>
  108. <view
  109. ref='selector-content--hock'
  110. class="uni-swipe_box"
  111. >
  112. <slot></slot>
  113. </view>
  114. </view>
  115. <!-- #endif -->
  116. <!-- 其他平台使用 js ,长列表性能可能会有影响-->
  117. <!-- #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
  118. <view class="uni-swipe">
  119. <view
  120. class="uni-swipe_box"
  121. @touchstart="touchstart"
  122. @touchmove="touchmove"
  123. @touchend="touchend"
  124. :style="{transform:moveLeft}"
  125. :class="{ani:ani}"
  126. >
  127. <view class="uni-swipe_button-group button-group--left">
  128. <slot name="left">
  129. <view
  130. v-for="(item,index) in leftOptions"
  131. :data-button="btn"
  132. :key="index"
  133. :style="{
  134. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  135. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  136. }"
  137. class="uni-swipe_button button-hock"
  138. @touchstart="appTouchStart"
  139. @touchend="appTouchEnd($event,index,item,'left')"
  140. ><text
  141. class="uni-swipe_button-text"
  142. :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"
  143. >{{ item.text }}</text></view>
  144. </slot>
  145. </view>
  146. <slot></slot>
  147. <view class="uni-swipe_button-group button-group--right">
  148. <slot name="right">
  149. <view
  150. v-for="(item,index) in rightOptions"
  151. :data-button="btn"
  152. :key="index"
  153. :style="{
  154. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  155. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  156. }"
  157. @touchstart="appTouchStart"
  158. @touchend="appTouchEnd($event,index,item,'right')"
  159. class="uni-swipe_button button-hock"
  160. ><text
  161. class="uni-swipe_button-text"
  162. :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}"
  163. >{{ item.text }}</text></view>
  164. </slot>
  165. </view>
  166. </view>
  167. </view>
  168. <!-- #endif -->
  169. </template>
  170. <script
  171. src="./index.wxs"
  172. module="swipe"
  173. lang="wxs"
  174. ></script>
  175. <script>
  176. // #ifdef APP-VUE|| MP-WEIXIN || H5
  177. import mpwxs from './mpwxs'
  178. // #endif
  179. // #ifdef APP-NVUE
  180. import bindingx from './bindingx.js'
  181. // #endif
  182. // #ifndef APP-PLUS|| MP-WEIXIN || H5
  183. import mixins from './mpother'
  184. // #endif
  185. /**
  186. * SwipeActionItem 滑动操作子组件
  187. * @description 通过滑动触发选项的容器
  188. * @tutorial https://ext.dcloud.net.cn/plugin?id=181
  189. * @property {Boolean} show = [left|right|none] 开启关闭组件,auto-close = false 时生效
  190. * @property {Boolean} disabled = [true|false] 是否禁止滑动
  191. * @property {Boolean} autoClose = [true|false] 滑动打开当前组件,是否关闭其他组件
  192. * @property {Number} threshold 滑动缺省值
  193. * @property {Array} leftOptions 左侧选项内容及样式
  194. * @property {Array} rgihtOptions 右侧选项内容及样式
  195. * @event {Function} click 点击选项按钮时触发事件,e = {content,index} ,content(点击内容)、index(下标)
  196. * @event {Function} change 组件打开或关闭时触发,left\right\none
  197. */
  198. export default {
  199. // #ifdef APP-VUE|| MP-WEIXIN||H5
  200. mixins: [mpwxs],
  201. // #endif
  202. // #ifdef APP-NVUE
  203. mixins: [bindingx],
  204. // #endif
  205. // #ifndef APP-PLUS|| MP-WEIXIN || H5
  206. mixins: [mixins],
  207. // #endif
  208. props: {
  209. // 控制开关
  210. show: {
  211. type: String,
  212. default: 'none'
  213. },
  214. // 禁用
  215. disabled: {
  216. type: Boolean,
  217. default: false
  218. },
  219. // 是否自动关闭
  220. autoClose: {
  221. type: Boolean,
  222. default: true
  223. },
  224. // 滑动缺省距离
  225. threshold: {
  226. type: Number,
  227. default: 20
  228. },
  229. // 左侧按钮内容
  230. leftOptions: {
  231. type: Array,
  232. default () {
  233. return []
  234. }
  235. },
  236. // 右侧按钮内容
  237. rightOptions: {
  238. type: Array,
  239. default () {
  240. return []
  241. }
  242. }
  243. },
  244. inject: ['swipeaction']
  245. }
  246. </script>
  247. <style
  248. lang="scss"
  249. scoped
  250. >
  251. .uni-swipe {
  252. position: relative;
  253. /* #ifndef APP-NVUE */
  254. overflow: hidden;
  255. /* #endif */
  256. }
  257. .uni-swipe_box {
  258. /* #ifndef APP-NVUE */
  259. display: flex;
  260. flex-shrink: 0;
  261. /* #endif */
  262. position: relative;
  263. }
  264. .uni-swipe_content {
  265. // border: 1px red solid;
  266. }
  267. .uni-swipe_button-group {
  268. /* #ifndef APP-NVUE */
  269. box-sizing: border-box;
  270. display: flex;
  271. /* #endif */
  272. flex-direction: row;
  273. position: absolute;
  274. top: 0;
  275. bottom: 0;
  276. }
  277. .button-group--left {
  278. left: 0;
  279. transform: translateX(-100%)
  280. }
  281. .button-group--right {
  282. right: 0;
  283. transform: translateX(100%)
  284. }
  285. .uni-swipe_button {
  286. /* #ifdef APP-NVUE */
  287. flex: 1;
  288. /* #endif */
  289. /* #ifndef APP-NVUE */
  290. display: flex;
  291. /* #endif */
  292. flex-direction: row;
  293. justify-content: center;
  294. align-items: center;
  295. padding: 0 20px;
  296. }
  297. .uni-swipe_button-text {
  298. /* #ifndef APP-NVUE */
  299. flex-shrink: 0;
  300. /* #endif */
  301. font-size: 14px;
  302. }
  303. .ani {
  304. transition-property: transform;
  305. transition-duration: 0.3s;
  306. transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  307. }
  308. /* #ifdef MP-ALIPAY */
  309. .movable-area {
  310. /* width: 100%; */
  311. height: 45px;
  312. }
  313. .movable-view {
  314. display: flex;
  315. /* justify-content: center; */
  316. position: relative;
  317. flex: 1;
  318. height: 45px;
  319. z-index: 2;
  320. }
  321. .movable-view-button {
  322. display: flex;
  323. flex-shrink: 0;
  324. flex-direction: row;
  325. height: 100%;
  326. background: #C0C0C0;
  327. }
  328. /* .transition {
  329. transition: all 0.3s;
  330. } */
  331. .movable-view-box {
  332. flex-shrink: 0;
  333. height: 100%;
  334. background-color: #fff;
  335. }
  336. /* #endif */
  337. </style>