SwipeShell.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <nut-swipe>
  3. <div class="nut-address-list-swipe">
  4. <item-contents
  5. :item="item"
  6. @delIcon="delClick"
  7. @editIcon="editClick"
  8. @itemClick="itemClick"
  9. @touchmove="swipemove"
  10. @touchstart="swipestart"
  11. >
  12. <template v-slot:contentTop>
  13. <slot name="contentInfo"></slot>
  14. </template>
  15. <template v-slot:contentIcon>
  16. <slot name="contentIcons"></slot>
  17. </template>
  18. <template v-slot:contentAddr>
  19. <slot name="contentAddrs"></slot>
  20. </template>
  21. </item-contents>
  22. </div>
  23. <template #right>
  24. <slot name="swiperightbtn">
  25. <nut-button shape="square" style="height: 100%" type="danger" @click="swipeDelClick">删除</nut-button>
  26. </slot>
  27. </template>
  28. </nut-swipe>
  29. </template>
  30. <script lang="ts">
  31. import { ref } from 'vue';
  32. import { createComponent } from '@/packages/utils/create';
  33. const { create } = createComponent('addresslist-swipe');
  34. import ItemContents from './ItemContents.vue';
  35. export default /* @__PURE__ */ create({
  36. props: {
  37. item: {
  38. type: Object,
  39. default: {}
  40. }
  41. },
  42. emits: ['delIcon', 'editIcon', 'itemClick', 'swipeDel'],
  43. components: {
  44. ItemContents
  45. },
  46. setup(props, { emit }) {
  47. const moveRef = ref(false);
  48. const delClick = (event: Event) => {
  49. emit('delIcon', event, props.item);
  50. event.stopPropagation();
  51. };
  52. const editClick = (event: Event) => {
  53. emit('editIcon', event, props.item);
  54. event.stopPropagation();
  55. };
  56. const itemClick = (event: Event) => {
  57. if (moveRef.value) return;
  58. emit('itemClick', event, props.item);
  59. event.stopPropagation();
  60. };
  61. const swipeDelClick = (event: Event) => {
  62. emit('swipeDel', event, props.item);
  63. event.stopPropagation();
  64. };
  65. const swipestart = () => {
  66. moveRef.value = false;
  67. };
  68. const swipemove = () => {
  69. moveRef.value = true;
  70. };
  71. return {
  72. delClick,
  73. editClick,
  74. itemClick,
  75. swipeDelClick,
  76. swipestart,
  77. swipemove
  78. };
  79. }
  80. });
  81. </script>