SwipeShell.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <nut-swipe>
  3. <div class="nut-swipe-shell">
  4. <item-contents
  5. :item="item"
  6. @delIconClick="delShellClick"
  7. @editIconClick="editShellClick"
  8. @itemClick="itemShellClick"
  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, watch, reactive, toRefs, onMounted, useSlots } from 'vue';
  32. import { createComponent } from '@/packages/utils/create';
  33. const { componentName, create } = createComponent('swipe-shell');
  34. // import { Swipe } from '@nutui/nutui';
  35. import ItemContents from './ItemContents.vue';
  36. export default create({
  37. props: {
  38. item: {
  39. type: Object,
  40. default: {}
  41. }
  42. },
  43. emits: ['handleDelIcon', 'handleEditIcon', 'handleItemContent', 'handelSwipeDel'],
  44. components: {
  45. ItemContents
  46. },
  47. setup(props: any, { emit, slots }) {
  48. let loop;
  49. const moveRef = ref(false);
  50. const delShellClick = (event, item) => {
  51. emit('handleDelIcon', event, props.item);
  52. event.stopPropagation();
  53. };
  54. const editShellClick = (event, item) => {
  55. emit('handleEditIcon', event, props.item);
  56. event.stopPropagation();
  57. };
  58. const itemShellClick = (event, item) => {
  59. if (moveRef.value) return;
  60. emit('handleItemContent', event, props.item);
  61. event.stopPropagation();
  62. };
  63. const swipeDelClick = (event, item) => {
  64. emit('handelSwipeDel', event, props.item);
  65. event.stopPropagation();
  66. };
  67. const swipestart = () => {
  68. moveRef.value = false;
  69. };
  70. const swipemove = () => {
  71. moveRef.value = true;
  72. };
  73. return {
  74. delShellClick,
  75. editShellClick,
  76. itemShellClick,
  77. swipeDelClick,
  78. swipestart,
  79. swipemove
  80. };
  81. }
  82. });
  83. </script>