自定义代码优化

v1.2.0
于肖磊 2024-12-27 10:16:32 +08:00
parent 2c9c3de121
commit bff29037fe
1 changed files with 21 additions and 27 deletions

View File

@ -308,52 +308,45 @@ const del = (index: null | number) => {
});
}
};
// - 1
const previous_layer = (index: number) => {
if (diy_data.value.length > 0) {
const old_data = get_diy_index_data(index);
//
diy_data.value.splice(index, 1);
//
diy_data.value.splice(index - 1, 0, old_data);
set_show_tabs(index - 1);
if (diy_data.value.length > 0 && index > 0) {
moveItem(index, index - 1);
}
}
// + 1
const underlying_layer = (index: number) => {
if (diy_data.value.length > 0) {
const old_data = get_diy_index_data(index);
//
diy_data.value.splice(index, 1);
//
diy_data.value.splice(index + 1, 0, old_data);
//
set_show_tabs(index + 1);
if (diy_data.value.length > 0 && index < diy_data.value.length - 1) {
moveItem(index, index + 1);
}
}
//
const top_up = (index: number) => {
if (!isEmpty(diy_data.value[index])) {
const old_data = get_diy_index_data(index);
//
diy_data.value.splice(index, 1);
//
diy_data.value.splice(0, 0, old_data);
set_show_tabs(0);
moveItem(index, 0);
}
}
//
const bottom_up = (index: number) => {
if (!isEmpty(diy_data.value[index])) {
const old_data = get_diy_index_data(index);
const old_length = diy_data.value.length - 1;
moveItem(index, old_length);
}
}
const moveItem = (index: number, newIndex: number) => {
if (index < 0 || index >= diy_data.value.length || newIndex < 0 || newIndex >= diy_data.value.length) {
return;
}
try {
const old_data = get_diy_index_data(index);
//
diy_data.value.splice(index, 1);
//
diy_data.value.splice(old_length, 0, old_data);
set_show_tabs(old_length);
//
diy_data.value.splice(newIndex, 0, old_data);
set_show_tabs(newIndex);
} catch (error) {
console.error('Error moving item:', error);
}
}
@ -420,6 +413,7 @@ const drag_area_width = computed(() => center_width.value + 'px');
const draggable_container = ref(true);
let data = reactive<diy_content[]>([]);
//
watch(() => center_height.value, () => {
data = diy_data.value;
// DOM