|
1 | 1 | <template>
|
2 |
| - <div class="nut-general-shell"> |
| 2 | + <div class="nut-addresslist-general"> |
3 | 3 | <item-contents
|
4 | 4 | :item="item"
|
5 |
| - @delIconClick="delShellClick" |
6 |
| - @editIconClick="editShellClick" |
| 5 | + @delIcon="delShellClick" |
| 6 | + @editIcon="editShellClick" |
7 | 7 | @itemClick="itemShellClick"
|
| 8 | + @touchstart="holddownstart" |
| 9 | + @touchend="holddownend" |
| 10 | + @touchmove="holddownmove" |
8 | 11 | >
|
9 | 12 | <template v-slot:contentTop>
|
10 | 13 | <slot name="contentInfo"></slot>
|
|
16 | 19 | <slot name="contentAddrs"></slot>
|
17 | 20 | </template>
|
18 | 21 | </item-contents>
|
| 22 | + <div class="nut-addresslist-general__mask" v-if="longPress && showMaskRef" @click="maskClick"> |
| 23 | + <slot name="longpressAll"> |
| 24 | + <div class="nut-addresslist-general__mask-copy" @click="copyCLick"> |
| 25 | + <div class="nut-addresslist-mask-contain"> 复制<br />地址 </div> |
| 26 | + </div> |
| 27 | + <div class="nut-addresslist-general__mask-set" @click="setDefault"> |
| 28 | + <div class="nut-addresslist-mask-contain"> 设置<br />默认 </div> |
| 29 | + </div> |
| 30 | + <div class="nut-addresslist-general__mask-del" @click="delClick"> |
| 31 | + <div class="nut-addresslist-mask-contain"> 删除<br />地址 </div> |
| 32 | + </div> |
| 33 | + </slot> |
| 34 | + </div> |
| 35 | + <div class="nut-addresslist__mask-bottom" v-if="showMaskRef" @click="hideMaskClick"></div> |
19 | 36 | </div>
|
20 | 37 | </template>
|
21 | 38 | <script lang="ts">
|
22 |
| -import { ref, watch, reactive, toRefs, onMounted, useSlots } from 'vue'; |
| 39 | +import { ref } from 'vue'; |
23 | 40 | import { createComponent } from '@/packages/utils/create';
|
24 |
| -const { componentName, create } = createComponent('general-shell'); |
| 41 | +const { create } = createComponent('addresslist-general'); |
25 | 42 | import ItemContents from './ItemContents.vue';
|
26 | 43 |
|
27 | 44 | export default create({
|
28 | 45 | props: {
|
29 | 46 | item: {
|
30 | 47 | type: Object,
|
31 | 48 | default: {}
|
| 49 | + }, |
| 50 | + longPress: { |
| 51 | + type: Boolean, |
| 52 | + default: false |
32 | 53 | }
|
33 | 54 | },
|
34 |
| - emits: ['handleDelIcon', 'handleEditIcon', 'handleItemContent', 'handelSwipeDel'], |
| 55 | + emits: ['delIcon', 'editIcon', 'itemClick', 'longDown', 'longCopy', 'longSet', 'longDel'], |
35 | 56 | components: {
|
36 | 57 | ItemContents
|
37 | 58 | },
|
38 | 59 |
|
39 |
| - setup(props: any, { emit, slots }) { |
40 |
| - const delShellClick = (event, item) => { |
41 |
| - emit('handleDelIcon', event, props.item); |
| 60 | + setup(props, { emit }) { |
| 61 | + let loop: any = null; |
| 62 | + const showMaskRef = ref(false); |
| 63 | +
|
| 64 | + const delShellClick = (event: Event) => { |
| 65 | + emit('delIcon', event, props.item); |
42 | 66 | event.stopPropagation();
|
43 | 67 | };
|
44 |
| - const editShellClick = (event, item) => { |
45 |
| - emit('handleEditIcon', event, props.item); |
| 68 | + const editShellClick = (event: Event) => { |
| 69 | + emit('editIcon', event, props.item); |
46 | 70 | event.stopPropagation();
|
47 | 71 | };
|
48 |
| - const itemShellClick = (event, item) => { |
49 |
| - emit('handleItemContent', event, props.item); |
| 72 | + const itemShellClick = (event: Event) => { |
| 73 | + emit('itemClick', event, props.item); |
50 | 74 | event.stopPropagation();
|
51 | 75 | };
|
52 |
| - const swipeDelClick = (event, item) => { |
53 |
| - emit('handelSwipeDel', event, props.item); |
| 76 | + const holdingFunc = (event: Event) => { |
| 77 | + loop = 0; |
| 78 | + showMaskRef.value = true; |
| 79 | + emit('longDown', event, props.item); |
| 80 | + }; |
| 81 | + // 长按功能实现 |
| 82 | + const holddownstart = (event: Event) => { |
| 83 | + loop = setTimeout(() => { |
| 84 | + holdingFunc(event); |
| 85 | + }, 300); |
| 86 | + }; |
| 87 | + const holddownmove = () => { |
| 88 | + // 滑动不触发长按 |
| 89 | + clearTimeout(loop); |
| 90 | + }; |
| 91 | + const holddownend = () => { |
| 92 | + // 删除定时器,防止重复注册 |
| 93 | + clearTimeout(loop); |
| 94 | + }; |
| 95 | + const hideMaskClick = () => { |
| 96 | + showMaskRef.value = false; |
| 97 | + }; |
| 98 | + const copyCLick = (event: Event) => { |
| 99 | + emit('longCopy', event, props.item); |
54 | 100 | event.stopPropagation();
|
55 | 101 | };
|
| 102 | + const setDefault = (event: Event) => { |
| 103 | + emit('longSet', event, props.item); |
| 104 | + event.stopPropagation(); |
| 105 | + }; |
| 106 | + const delClick = (event: Event) => { |
| 107 | + emit('longDel', event, props.item); |
| 108 | + event.stopPropagation(); |
| 109 | + }; |
| 110 | + const maskClick = (event: Event) => { |
| 111 | + if (loop != 0) { |
| 112 | + // 排除长按时触发点击的情况 |
| 113 | + showMaskRef.value = false; |
| 114 | + } |
| 115 | + event.stopPropagation(); |
| 116 | + event.preventDefault(); |
| 117 | + }; |
| 118 | +
|
56 | 119 | return {
|
57 | 120 | delShellClick,
|
58 | 121 | editShellClick,
|
59 | 122 | itemShellClick,
|
60 |
| - swipeDelClick |
| 123 | + holddownstart, |
| 124 | + holddownmove, |
| 125 | + holddownend, |
| 126 | + showMaskRef, |
| 127 | + delClick, |
| 128 | + copyCLick, |
| 129 | + hideMaskClick, |
| 130 | + setDefault, |
| 131 | + maskClick |
61 | 132 | };
|
62 | 133 | }
|
63 | 134 | });
|
|
0 commit comments