uni-swipe-action-item.vue 9.5 KB

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