自定义注释优化

v1.2.0
于肖磊 2024-12-27 10:10:51 +08:00
parent 7d165b815c
commit 2c9c3de121
9 changed files with 79 additions and 39 deletions

View File

@ -17,7 +17,7 @@
<model-panel :key="item.id" :value="item.com_data" :scale="scale" :source-list="sourceList" :is-custom="isCustom" :is-display-panel="true"></model-panel>
</template>
<template v-else-if="item.key == 'custom-group'">
<model-custom-group :key="item.id" :value="item.com_data" :scale="scale" :source-list="sourceList" :data-height="item.com_data.com_height" :data-width="item.com_data.com_width" :is-custom="isCustom" :is-display-panel="true"></model-custom-group>
<model-custom-group :key="item.id" :value="item.com_data" :scale="scale" :source-list="sourceList" :data-height="item.com_data.custom_height" :data-width="item.com_data.com_width" :is-custom="isCustom" :is-display-panel="true"></model-custom-group>
</template>
</div>
</div>

View File

@ -1,5 +1,5 @@
<template>
<div :style="style_container">
<div class="w h" :style="style_container">
<div :style="style_img_container">
<div :style="style_content_container">
<div class="w h re" :style="style_content_img_container">
@ -93,7 +93,7 @@ const props = defineProps({
const form = computed(() => props.value);
const new_style = computed(() => props.value.data_style);
//
const style_container = computed(() => common_styles_computer(new_style.value.common_style));
const style_container = computed(() => common_styles_computer(new_style.value.common_style) + 'overflow: auto;');
const style_img_container = computed(() => common_img_computer(new_style.value.common_style));
//
const style_content_container = computed(() => common_styles_computer(new_style.value.data_content_style));

View File

@ -40,7 +40,7 @@ const props = defineProps({
});
//
const form = computed(() => props.value);
//
const icon_class = computed(() => {
if (!isEmpty(form.value.icon_class)) {
return form.value.icon_class;
@ -69,7 +69,7 @@ const icon_class = computed(() => {
}
}
});
//
const data_handling = (data_source_id: string) => {
//
let icon = get_nested_property(props.sourceList, data_source_id);
@ -79,7 +79,7 @@ const data_handling = (data_source_id: string) => {
}
return icon;
}
//
const com_style = computed(() => {
let style = `${ set_count() } ${ gradient_handle(form.value.color_list, form.value.direction) } ${ radius_computer(form.value.bg_radius, props.scale) };transform: rotate(${form.value.icon_rotate}deg);${ padding_computer(form.value.icon_padding, props.scale) };`;
if (form.value.border_show == '1') {
@ -94,6 +94,7 @@ const com_style = computed(() => {
}
return style;
});
//
const set_count = () => {
if (props.isDisplayPanel) {
return '';

View File

@ -39,7 +39,7 @@ const props = defineProps({
});
//
const form = computed(() => props.value);
//
const img = computed(() => {
if (!isEmpty(form.value.img[0])) {
return form.value.img[0];
@ -69,7 +69,7 @@ const img = computed(() => {
}
}
});
//
const data_handling = (data_source_id: string) => {
// ,使reduce
let image_url = get_nested_property(props.sourceList, data_source_id);
@ -83,11 +83,11 @@ const data_handling = (data_source_id: string) => {
}
return image_url;
}
//
const image_style = computed(() => {
return `${ set_count() };transform: rotate(${form.value.img_rotate}deg); ${ radius_computer(form.value.img_radius, props.scale) };`;
});
//
const border_style = computed(() => {
let style = ``;
if (form.value.border_show == '1') {
@ -95,6 +95,7 @@ const border_style = computed(() => {
}
return style;
});
//
const set_count = () => {
if (props.isDisplayPanel) {
return `width: ${ percentage_count(form.value.img_width, form.value.com_width) }; height: ${ percentage_count(form.value.img_height, form.value.com_height) };`;

View File

@ -21,7 +21,7 @@ const props = defineProps({
});
//
const form = computed(() => props.value);
//
const border_style = computed(() => {
if (form.value.line_settings === 'horizontal') {
return `${set_count()} margin: 5px 0;border-bottom: ${form.value.line_size * props.scale}px ${form.value.line_style} ${form.value.line_color};`;
@ -29,6 +29,7 @@ const border_style = computed(() => {
return `${set_count()} margin: 0 5px;border-right: ${form.value.line_size * props.scale}px ${form.value.line_style} ${form.value.line_color};`;
}
});
//
const set_count = () => {
if (form.value.line_settings === 'horizontal') {
return `width: ${form.value.com_width}px;`;

View File

@ -30,7 +30,7 @@ const props = defineProps({
});
//
const form = computed(() => props.value);
//
const com_style = computed(() => {
let style = `${ set_count() } ${ gradient_handle(form.value.color_list, form.value.direction) } ${ radius_computer(form.value.bg_radius, props.scale) }; transform: rotate(${form.value.panel_rotate}deg);`;
if (form.value.border_show == '1') {
@ -38,7 +38,7 @@ const com_style = computed(() => {
}
return style;
});
//
const com_img_style = computed(() => {
const data = {
background_img: form.value?.background_img || [],
@ -46,6 +46,7 @@ const com_img_style = computed(() => {
}
return background_computer(data);
});
//
const set_count = () => {
if (props.isDisplayPanel) {
return '';

View File

@ -111,7 +111,7 @@ const text_title = computed(() => {
}
return text;
}
//
const data_handling = (data_source_id: string) => {
let text_title = get_nested_property(props.sourceList, data_source_id);
//
@ -124,7 +124,7 @@ const data_handling = (data_source_id: string) => {
}
return text_title;
}
//
const text_style = computed(() => {
let style = `font-size: ${ form.value.text_size * props.scale }px;line-height: ${ (typeof form.value.line_text_size === "number" ? form.value.line_text_size : form.value.text_size) * props.scale}px;color: ${ form.value.text_color }; text-align: ${ form.value.text_location }; transform: rotate(${form.value.text_rotate}deg);text-decoration: ${ form.value.text_option };${ padding_computer(form.value.text_padding, props.scale) };`;
if (form.value.text_weight == 'italic') {
@ -134,7 +134,7 @@ const text_style = computed(() => {
}
return style;
});
//
const com_style = computed(() => {
let style = `${ set_count() } ${ gradient_handle(form.value.color_list, form.value.direction) } ${ radius_computer(form.value.bg_radius, props.scale) }`;
if (form.value.border_show == '1') {
@ -146,6 +146,7 @@ const com_style = computed(() => {
}
return style;
});
//
const set_count = () => {
if (props.isDisplayPanel) {
return '';

View File

@ -85,7 +85,7 @@
<model-panel :key="item.id" :value="item.com_data" :source-list="props.sourceList" :is-custom="isCustom"></model-panel>
</template>
<template v-else-if="item.key == 'custom-group'">
<model-custom-group :key="item.id" :value="item.com_data" :source-list="props.sourceList" :data-height="item.com_data.com_height" :data-width="item.com_data.com_width" :is-custom="isCustom"></model-custom-group>
<model-custom-group :key="item.id" :value="item.com_data" :source-list="props.sourceList" :data-height="item.com_data.custom_height" :data-width="item.com_data.com_width" :is-custom="isCustom"></model-custom-group>
</template>
</div>
</Vue3DraggableResizable>
@ -111,7 +111,7 @@
</template>
<script setup lang="ts">
import { cloneDeep, isEmpty, property } from 'lodash';
import { get_math } from '@/utils';
import { get_math, adjustPosition } from '@/utils';
import { defaultComData, isRectangleIntersecting } from "./index-default";
import { SortableEvent, VueDraggable } from 'vue-draggable-plus';
import { commonStore } from '@/store';
@ -174,7 +174,7 @@ const components = reactive([
},
{
key: 'custom-group',
name: '自定义组',
name: '组',
is_show: props.configType == 'custom' ? true : false,
new_name: '',
com_data: defaultComData.custom_group_com_data,
@ -182,6 +182,7 @@ const components = reactive([
],
},
]);
//
const url_computer = (name: string) => {
const new_url = ref(common_store.common.config.attachment_host + `/static/diy/images/custom/${name}.png`).value;
return new_url;
@ -240,6 +241,7 @@ const outerClick = (e: any) => {
edit_index.value = -1;
}
};
//
const double_click = (index: number) => {
edit_index.value = index;
edit_processing(index);
@ -409,7 +411,7 @@ const cancel = () => {
emits('rightUpdate', {});
};
//#endregion
//#region
//#region
const center_height = defineModel('height', { type: Number, default: 0 });
const center_width = defineModel('width', { type: Number, default: 390 });
@ -474,19 +476,24 @@ const dragStart = (item: any, event: any) => {
//
hot_list.data = [];
};
//
const dragEnd = () => {
draggedItem.value = {};
};
//
const drop = (event: any) => {
if (draggedItem.value) {
//
const com_width = draggedItem.value.com_data.com_width;
const com_height = draggedItem.value.com_data.com_height;
//
let location_x = event.offsetX;
let location_y = event.offsetY;
// 使
// 使使
const { x: adjustedX, y: adjustedY } = adjustPosition(location_x, location_y, com_width, com_height, 390, center_height.value);
// key
// key
const list = diy_data.value.filter(item => item.key == draggedItem.value.key);
//
const newItem = {
...draggedItem.value,
new_name: list.length > 0 ? draggedItem.value.name + list.length : draggedItem.value.name, //
@ -500,26 +507,16 @@ const drop = (event: any) => {
};
// z-index
diy_data.value.unshift(newItem);
// 0
// 0
set_show_tabs(0);
}
};
function adjustPosition(x: number, y: number, width:number, height:number, maxWidth:number, maxHeight:number) {
const halfWidth = width / 2;
const halfHeight = height / 2;
//
x = Math.max(0, Math.min(maxWidth - width, x - halfWidth));
y = Math.max(0, Math.min(maxHeight - height, y - halfHeight));
return { x, y };
}
//#endregion
//#region
const dragEndHandle = (item: any, index: number) => {
diy_data.value[index].location = { x: item.x, y: item.y, record_x: item.x, record_y: item.y, staging_y: item.y };
};
// {x: number, y: number, w: number, h: number}
// {x: number, y: number, w: number, h: number}
const resizingHandle = (new_location: any, key: string, index: number) => {
const { x, y, w, h } = new_location;
//
@ -558,7 +555,7 @@ const handleAuxiliaryLine = (com_data: any, w: number, h: number ) => {
}
};
//#endregion
//#region
//#region x y
const hot_list = reactive({ data: [] as hotListData[] });
const hot_list_index = ref(0);
const imgBoxRef = ref<HTMLElement | null>(null);
@ -695,7 +692,7 @@ const start_drag_area_box = (index: number, event: MouseEvent) => {
};
};
// drag-btn
// drag-btn,
const start_drag_btn_br = (index: number, event: MouseEvent) => {
start_drag_btn(index, event, 'br');
};
@ -812,7 +809,7 @@ const rect_style = computed(() => {
const handleKeyUp = (e: KeyboardEvent) => {
//
const default_list = ['textarea', 'input'];
//
//
if (e.target instanceof HTMLElement && default_list.includes(e.target?.localName)) {
return;
}
@ -829,25 +826,36 @@ const handleKeyUp = (e: KeyboardEvent) => {
} else if (e.key === 'ArrowRight') { //
x = 1;
}
//
e.preventDefault();
//
if (key_code.includes(e.key)) {
data_handling(x, y);
}
};
const data_handling = (x: number, y: number) => {
// ,
/**
* 数据处理函数用于处理操作键盘上下左右操作后的数据更新
* 判断是否生成了多个组件同时拖拽的盒子如果有则更新盒子和盒子有交集的组件, 如果内容没有盒子则只更新当前选中的
* hot_list: 存放盒子的数组因为目前最多只能生成一个盒子所以直接取第一个盒子即可
* @param {number} x 键盘上下左右操作在x轴上的变化量
* @param {number} y 键盘上下左右操作在y轴上的变化量
*/
const data_handling = (x: number, y: number) => {
// ,,
if (hot_list.data.length > 0) {
//
const { drag_start, drag_end } = hot_list.data[0];
// x
if (isWithinBounds(drag_start.x + x, drag_end.width, 390)) {
hot_list.data[0].drag_start.x += x;
}
// y
if (isWithinBounds(drag_start.y + y, drag_end.height, center_height.value)) {
hot_list.data[0].drag_start.y += y;
}
// ,
const rect1 = { x: drag_start.x, y: drag_start.y, width: drag_end.width, height: drag_end.height }
//
diy_data.value.forEach(item => {
const rect2 = { x: item.location.x, y: item.location.y, width: item.com_data.com_width, height: item.com_data.com_height };
// 10
@ -864,6 +872,7 @@ const data_handling = (x: number, y: number) => {
}
});
} else {
//
diy_data.value.forEach(item => {
//
if (item.show_tabs == '1') {
@ -891,6 +900,7 @@ onUnmounted(() => {
document.removeEventListener('keyup', handleKeyUp);
});
//#endregion
//
defineExpose({
diy_data,
});

View File

@ -509,3 +509,28 @@ export const online_url = async (directory: string = '') => {
return attachemnt_host + directory;
}
};
/**
* 使
* @param x
* @param y
* @param width
* @param height
* @param maxWidth
* @param maxHeight
* @returns
*/
export const adjustPosition = (x: number, y: number, width:number, height:number, maxWidth:number, maxHeight:number) => {
// 计算元素的半宽度和半高度,用于后续计算元素的最终位置
const halfWidth = width / 2;
const halfHeight = height / 2;
// 确保元素不会超出屏幕范围
// 对于横坐标x使用Math.max和Math.min函数限制其值在0到(maxWidth - width)之间
// 对于纵坐标y使用Math.max和Math.min函数限制其值在0到(maxHeight - height)之间
x = Math.max(0, Math.min(maxWidth - width, x - halfWidth));
y = Math.max(0, Math.min(maxHeight - height, y - halfHeight));
// 返回调整后的元素位置坐标
return { x, y };
}