2024-08-12 02:18:11 +00:00
|
|
|
<template>
|
|
|
|
|
<VueDraggable v-model="from" :animation="500" target=".sort-target" handle=".icon-drag" :scroll="true" :on-sort="on_sort">
|
|
|
|
|
<TransitionGroup type="transition" tag="ul" name="fade" class="sort-target flex-col gap-x-20">
|
2024-11-25 08:58:35 +00:00
|
|
|
<li v-for="(item, index) in from" :key="index" :class="[`flex gap-y-16 re ${ className }`, props.modelType == 'nav-group' && modelIndex === index ? 'nav-index-select' : '']" @click="on_click(item, index)">
|
2024-10-16 07:12:57 +00:00
|
|
|
<icon name="drag" size="16" class="cursor-move" />
|
2024-08-12 02:18:11 +00:00
|
|
|
<slot :row="item" :index="index" />
|
2024-11-26 02:22:34 +00:00
|
|
|
<!-- 底部第一个不显示删除按钮 -->
|
|
|
|
|
<div v-if="!(props.modelType === 'footer' && index === 0)" class="abs c-pointer top-de-6 right-de-6 remove-icon" @click.stop="remove(index)">
|
2024-10-16 07:36:51 +00:00
|
|
|
<icon v-if="type == 'card'" name="close-fillup" size="18" color="c" />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="c-pointer do-not-trigger" @click.stop="remove(index)">
|
|
|
|
|
<icon v-if="type == 'line'" name="delete-o" size="18" color="6" />
|
|
|
|
|
</div>
|
2024-10-15 09:32:51 +00:00
|
|
|
<el-dropdown v-if="isShowEdit" placement="bottom">
|
2024-10-16 07:36:51 +00:00
|
|
|
<icon name="more-o" size="18" color="primary"></icon>
|
2024-10-15 09:32:51 +00:00
|
|
|
<template #dropdown>
|
|
|
|
|
<el-dropdown-menu>
|
|
|
|
|
<el-dropdown-item @click.stop="edit(index)">编辑</el-dropdown-item>
|
|
|
|
|
<el-dropdown-item @click.stop="replace(index)">替换</el-dropdown-item>
|
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dropdown>
|
2024-08-12 02:18:11 +00:00
|
|
|
</li>
|
|
|
|
|
</TransitionGroup>
|
|
|
|
|
</VueDraggable>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { VueDraggable } from 'vue-draggable-plus';
|
2024-10-15 09:32:51 +00:00
|
|
|
const emits = defineEmits(['click', 'remove', 'edit', 'onSort', 'replace']);
|
2024-08-12 02:18:11 +00:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
data: any; // 拖拽列表数据
|
|
|
|
|
type?: string; // card: 卡片区域 line: 一行
|
|
|
|
|
spaceCol?: number; // 上下间距
|
|
|
|
|
iconPosition?: string; // top/bottom/center
|
2024-08-21 08:28:19 +00:00
|
|
|
isShowEdit?: boolean;
|
2024-11-25 08:58:35 +00:00
|
|
|
modelType?: string;
|
|
|
|
|
modelIndex?: number;
|
2024-08-12 02:18:11 +00:00
|
|
|
}
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
|
type: () => 'line',
|
2024-08-21 08:28:19 +00:00
|
|
|
isShowEdit: false,
|
2024-08-12 02:18:11 +00:00
|
|
|
spaceCol: () => 5,
|
|
|
|
|
iconPosition: 'center',
|
2024-11-25 08:58:35 +00:00
|
|
|
modelType: 'outer',
|
|
|
|
|
modelIndex: 0,
|
2024-08-12 02:18:11 +00:00
|
|
|
});
|
|
|
|
|
const className = ref('');
|
|
|
|
|
if (props.type == 'card') {
|
|
|
|
|
className.value += `card-background box-shadow-sm pt-${props.spaceCol} pb-${props.spaceCol}`;
|
|
|
|
|
if (props.iconPosition == 'top') {
|
|
|
|
|
className.value += '';
|
|
|
|
|
} else if (props.iconPosition == 'bottom') {
|
|
|
|
|
className.value += ' align-e';
|
|
|
|
|
} else {
|
|
|
|
|
className.value += ' align-c';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 不是卡片类型的设置居中显示
|
|
|
|
|
className.value = 'align-c';
|
|
|
|
|
}
|
2024-08-22 03:49:41 +00:00
|
|
|
watch(
|
|
|
|
|
() => props.data,
|
|
|
|
|
() => {
|
|
|
|
|
from.value = props.data;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
const from = ref(props.data);
|
2024-08-21 10:39:14 +00:00
|
|
|
|
2024-08-12 02:18:11 +00:00
|
|
|
const on_click = (item: any, index: number) => {
|
|
|
|
|
emits('click', item, index);
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-15 09:32:51 +00:00
|
|
|
// 删除
|
2024-08-12 02:18:11 +00:00
|
|
|
const remove = (index: number) => {
|
|
|
|
|
emits('remove', index);
|
|
|
|
|
};
|
2024-10-15 09:32:51 +00:00
|
|
|
// 编辑
|
2024-08-21 08:28:19 +00:00
|
|
|
const edit = (index: number) => {
|
|
|
|
|
emits('edit', index);
|
|
|
|
|
};
|
2024-10-15 09:32:51 +00:00
|
|
|
// 替换
|
|
|
|
|
const replace = (index: number) => {
|
|
|
|
|
emits('replace', index);
|
|
|
|
|
};
|
2024-08-12 02:18:11 +00:00
|
|
|
// 拖拽更新之后用户更新数据
|
|
|
|
|
const on_sort = () => {
|
2024-08-22 03:49:41 +00:00
|
|
|
emits('onSort', from.value);
|
2024-08-12 02:18:11 +00:00
|
|
|
};
|
|
|
|
|
</script>
|
2024-11-25 08:58:35 +00:00
|
|
|
<style lang="scss" scoped>
|
2024-08-12 02:18:11 +00:00
|
|
|
.card-background {
|
|
|
|
|
background: #fff;
|
|
|
|
|
padding-left: 1.6rem;
|
|
|
|
|
padding-right: 2rem;
|
2024-11-25 08:58:35 +00:00
|
|
|
border-radius: 4px;
|
2024-08-12 02:18:11 +00:00
|
|
|
}
|
2024-10-16 07:36:51 +00:00
|
|
|
|
2024-08-12 02:18:11 +00:00
|
|
|
.cursor-move {
|
|
|
|
|
color: #ddd;
|
|
|
|
|
cursor: move;
|
|
|
|
|
}
|
2024-11-25 08:58:35 +00:00
|
|
|
.remove-icon {
|
|
|
|
|
display: flex;
|
|
|
|
|
background: #fff;
|
|
|
|
|
border-radius: 100%;
|
|
|
|
|
line-height: 1.8rem;
|
|
|
|
|
}
|
|
|
|
|
.nav-index-select {
|
|
|
|
|
box-shadow: 0rem 0 0rem 0.1rem #409eff;
|
|
|
|
|
/* border: 1px solid #409eff; */
|
|
|
|
|
}
|
2024-08-12 02:18:11 +00:00
|
|
|
</style>
|