自定义组内边距修改

v1.2.0
于肖磊 2024-12-27 18:06:33 +08:00
parent bff29037fe
commit 67b5ad1fd3
6 changed files with 103 additions and 14 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="w h re custom-other"> <div class="w h re custom-other">
<div v-for="(item, index) in list" :key="item.id" class="main-content" :style="{'left': percentage_count(item.location.x) , 'top': percentage_count(item.location.y), 'width': percentage_count(item.com_data.com_width), 'height': percentage_count(item.com_data.com_height), 'z-index': (customList.length - 1) - index}"> <div v-for="(item, index) in list" :key="item.id" class="main-content flex-row" :style="{'left': percentage_count(item.location.x) , 'top': percentage_count(item.location.y), 'width': percentage_count(item.com_data.com_width), 'height': percentage_count(item.com_data.com_height), 'z-index': (customList.length - 1) - index}">
<template v-if="item.key == 'text'"> <template v-if="item.key == 'text'">
<model-text :key="item.id" :value="item.com_data" :scale="scale" :source-list="sourceList" :is-custom="isCustom" :title-params="showData?.data_name || 'name'" :is-display-panel="true"></model-text> <model-text :key="item.id" :value="item.com_data" :scale="scale" :source-list="sourceList" :is-custom="isCustom" :title-params="showData?.data_name || 'name'" :is-display-panel="true"></model-text>
</template> </template>

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="w h" :style="style_container"> <div class="flex-1" :style="style_container">
<div :style="style_img_container"> <div :style="style_img_container">
<div :style="style_content_container"> <div :style="style_content_container">
<div class="w h re" :style="style_content_img_container"> <div class="w h re" :style="style_content_img_container">
@ -115,9 +115,9 @@ watchEffect(() => {
// //
const internal_spacing = data_style.margin_left + data_style.margin_right + data_style.padding_left + data_style.padding_right; const internal_spacing = data_style.margin_left + data_style.margin_right + data_style.padding_left + data_style.padding_right;
// //
const width = old_width - outer_spacing - internal_spacing - content_spacing; const new_width = old_width - outer_spacing - internal_spacing - content_spacing;
// //
custom_scale.value = width / old_width; custom_scale.value = new_width / old_width;
}); });
//#endregion //#endregion
// //

View File

@ -68,7 +68,7 @@
<DraggableContainer v-if="draggable_container" style="z-index:0" :reference-line-visible="true" :disabled="false" reference-line-color="#ddd" @selectstart.prevent @contextmenu.prevent @dragstart.prevent> <DraggableContainer v-if="draggable_container" style="z-index:0" :reference-line-visible="true" :disabled="false" reference-line-color="#ddd" @selectstart.prevent @contextmenu.prevent @dragstart.prevent>
<!-- @mouseover="on_choose(index)" --> <!-- @mouseover="on_choose(index)" -->
<Vue3DraggableResizable v-for="(item, index) in diy_data" :key="item.id" v-model:w="item.com_data.com_width" v-model:h="item.com_data.com_height" :min-w="0" :min-h="0" :class="{'plug-in-show-component-line': is_show_component_line, 'plug-in-show-tabs': item.show_tabs == '1', 'vdr-handle-z-index': item.com_data.bottom_up == '1' }" :style="{ 'z-index': (diy_data.length - 1) - index }" :init-w="item.com_data.com_width" :init-h="item.com_data.com_height" :x="item.location.x" :y="item.location.y" :parent="true" :draggable="is_draggable" @mousedown.stop="on_choose(index, item.show_tabs)" @click.stop="on_choose(index, item.show_tabs)" @drag-end="dragEndHandle($event, index)" @resizing="resizingHandle($event, item.key, index)" @resize-end="resizingHandle($event, item.key, index)"> <Vue3DraggableResizable v-for="(item, index) in diy_data" :key="item.id" v-model:w="item.com_data.com_width" v-model:h="item.com_data.com_height" :min-w="0" :min-h="0" :class="{'plug-in-show-component-line': is_show_component_line, 'plug-in-show-tabs': item.show_tabs == '1', 'vdr-handle-z-index': item.com_data.bottom_up == '1' }" :style="{ 'z-index': (diy_data.length - 1) - index }" :init-w="item.com_data.com_width" :init-h="item.com_data.com_height" :x="item.location.x" :y="item.location.y" :parent="true" :draggable="is_draggable" @mousedown.stop="on_choose(index, item.show_tabs)" @click.stop="on_choose(index, item.show_tabs)" @drag-end="dragEndHandle($event, index)" @resizing="resizingHandle($event, item.key, index)" @resize-end="resizingHandle($event, item.key, index)">
<div :class="['main-content', { 'plug-in-border': item.show_tabs == '1' }]"> <div :class="['main-content flex-row', { 'plug-in-border': item.show_tabs == '1' }]">
<template v-if="item.key == 'text'"> <template v-if="item.key == 'text'">
<model-text :key="item.id" :value="item.com_data" :source-list="props.sourceList" :is-custom="isCustom" :title-params="showData?.data_name || 'name'" :options="options"></model-text> <model-text :key="item.id" :value="item.com_data" :source-list="props.sourceList" :is-custom="isCustom" :title-params="showData?.data_name || 'name'" :options="options"></model-text>
</template> </template>
@ -111,10 +111,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { cloneDeep, isEmpty, property } from 'lodash'; import { cloneDeep, isEmpty, property } from 'lodash';
import { get_math, adjustPosition } from '@/utils'; import { get_math, adjustPosition, getPlatform } from '@/utils';
import { defaultComData, isRectangleIntersecting } from "./index-default"; import { defaultComData, isRectangleIntersecting } from "./index-default";
import { SortableEvent, VueDraggable } from 'vue-draggable-plus'; import { SortableEvent, VueDraggable } from 'vue-draggable-plus';
import { commonStore } from '@/store'; import { commonStore, DataSourceStore } from '@/store';
const common_store = commonStore(); const common_store = commonStore();
// //
const app = getCurrentInstance(); const app = getCurrentInstance();
@ -431,7 +431,7 @@ watch(() => center_height.value, () => {
staging_y: item.location.staging_y, staging_y: item.location.staging_y,
}, },
com_data: { com_data: {
// //
...Object.assign({}, cloneDeep((defaultComData as any)[`${item.key}_com_data`]), item.com_data), ...Object.assign({}, cloneDeep((defaultComData as any)[`${item.key}_com_data`]), item.com_data),
com_height: item.com_data.staging_height, com_height: item.com_data.staging_height,
data_source_field: { data_source_field: {
@ -799,7 +799,35 @@ const rect_style = computed(() => {
}; };
}); });
//#endregion //#endregion
//#region //#region 退
// window mac
const platform = getPlatform();
// 退
const data_source_store = DataSourceStore();
const pressedKeys = new Set(); // 使 Set
const handle_keydown = (e: KeyboardEvent) => {
//
const default_list = ['textarea', 'input'];
//
if (e.target instanceof HTMLElement && default_list.includes(e.target?.localName)) {
return;
}
// 使 key code keyCode
const key = e.key.toLowerCase(); //
// Set
pressedKeys.add(key);
// A B
if ((pressedKeys.has('control') && pressedKeys.has('z') && platform == 'Windows') || (pressedKeys.has('meta') && pressedKeys.has('z') && platform == 'Mac')) {
// 退
if (!data_source_store.is_children_custom && props.configType == 'custom') {
console.log('同时按下了A和B键', props.configType); //
} else if (data_source_store.is_children_custom && props.configType == 'custom-group') {
console.log('同时按下了A和B键', props.configType); //
}
}
//
e.preventDefault();
}
const handleKeyUp = (e: KeyboardEvent) => { const handleKeyUp = (e: KeyboardEvent) => {
// //
const default_list = ['textarea', 'input']; const default_list = ['textarea', 'input'];
@ -820,11 +848,27 @@ const handleKeyUp = (e: KeyboardEvent) => {
} else if (e.key === 'ArrowRight') { // } else if (e.key === 'ArrowRight') { //
x = 1; x = 1;
} }
// // 退
e.preventDefault(); if (!data_source_store.is_children_custom && props.configType == 'custom') {
// //
if (key_code.includes(e.key)) { const key = e.key.toLowerCase();
data_handling(x, y); pressedKeys.delete(key);
//
e.preventDefault();
//
if (key_code.includes(e.key)) {
data_handling(x, y);
}
} else if (data_source_store.is_children_custom && props.configType == 'custom-group') {
//
const key = e.key.toLowerCase();
pressedKeys.delete(key);
//
e.preventDefault();
//
if (key_code.includes(e.key)) {
data_handling(x, y);
}
} }
}; };
/** /**
@ -885,11 +929,16 @@ const handleKeyUp = (e: KeyboardEvent) => {
}; };
// coordinate current_size () max_size // coordinate current_size () max_size
const isWithinBounds = (coordinate:number, current_size: number, max_size: number) => coordinate >= 0 && coordinate + current_size <= max_size; const isWithinBounds = (coordinate:number, current_size: number, max_size: number) => coordinate >= 0 && coordinate + current_size <= max_size;
//
onMounted(() => { onMounted(() => {
document.addEventListener('keydown', handle_keydown);
// //
document.addEventListener('keyup', handleKeyUp); document.addEventListener('keyup', handleKeyUp);
}); });
onUnmounted(() => { onUnmounted(() => {
document.removeEventListener('keyup', handleKeyUp);
// //
document.removeEventListener('keyup', handleKeyUp); document.removeEventListener('keyup', handleKeyUp);
}); });

View File

@ -130,6 +130,8 @@ const custom_edit = (type: string, id?: string, father_list?: any, list?: any, w
custom_list.value = cloneDeep(form.value.custom_list); custom_list.value = cloneDeep(form.value.custom_list);
// //
center_height.value = cloneDeep(form.value.height); center_height.value = cloneDeep(form.value.height);
//
data_source_store.set_is_children_custom(false);
} else { } else {
drag_group_key.value = Math.random().toString(36).substring(2); drag_group_key.value = Math.random().toString(36).substring(2);
// //
@ -143,10 +145,14 @@ const custom_edit = (type: string, id?: string, father_list?: any, list?: any, w
// //
center_group_width.value = width || 0; center_group_width.value = width || 0;
center_group_height.value = height || 0; center_group_height.value = height || 0;
//
data_source_store.set_is_children_custom(true);
} }
}; };
// //
const accomplish = (type: string, list: any) => { const accomplish = (type: string, list: any) => {
//
data_source_store.set_is_children_custom(false);
// //
if (type == 'custom') { if (type == 'custom') {
form.value.custom_list = list; form.value.custom_list = list;

View File

@ -13,6 +13,7 @@ export const DataSourceStore = defineStore('dataSource', () => {
data: data_list[]; data: data_list[];
type: string; type: string;
}; };
const is_children_custom = ref(false);
// 上传是否需要调接口判断 // 上传是否需要调接口判断
const is_data_source_api = ref(false); const is_data_source_api = ref(false);
// 数据源 // 数据源
@ -27,10 +28,16 @@ export const DataSourceStore = defineStore('dataSource', () => {
is_data_source_api.value = bool; is_data_source_api.value = bool;
}; };
const set_is_children_custom = (bool: boolean) => {
is_children_custom.value = bool;
};
return { return {
is_children_custom,
data_source_list, data_source_list,
is_data_source_api, is_data_source_api,
set_data_source, set_data_source,
set_is_data_source_api, set_is_data_source_api,
set_is_children_custom,
}; };
}); });

View File

@ -534,3 +534,30 @@ export const adjustPosition = (x: number, y: number, width:number, height:number
// 返回调整后的元素位置坐标 // 返回调整后的元素位置坐标
return { x, y }; return { x, y };
} }
export const getPlatform = () => {
// 检查 navigator.platform 是否存在且不为空
if (!navigator || !navigator.platform) {
return 'Unknown';
}
const platform = navigator.platform.toLowerCase();
// 使用正则表达式进行平台匹配
const platformMap = [
{ regex: /^win/, name: 'Windows' },
{ regex: /^mac/, name: 'Mac' },
{ regex: /^linux/, name: 'Linux' },
{ regex: /android/, name: 'Android' },
{ regex: /ios/, name: 'iOS' }
];
for (const { regex, name } of platformMap) {
if (regex.test(platform)) {
return name;
}
}
return 'Unknown';
}