uni-swipe-action-item.vue 9.8 KB

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