feat(组件): 抽屉组件支持调整宽度&描述组件按钮调整

This commit is contained in:
baiqi 2023-10-27 17:18:59 +08:00 committed by Craftsman
parent 56c2ddfb94
commit f38f3243ba
3 changed files with 51 additions and 11 deletions

View File

@ -57,9 +57,9 @@
</MsTag> </MsTag>
</div> </div>
</template> </template>
<a-button v-else-if="item.isButton" type="text" :size="item.buttonSize" @click="handleItemClick(item)"> <MsButton v-else-if="item.isButton" type="text" @click="handleItemClick(item)">
{{ item.value }} {{ item.value }}
</a-button> </MsButton>
<template v-else> <template v-else>
<slot name="value" :item="item"> <slot name="value" :item="item">
{{ item.value === undefined || item.value === null || item.value?.toString() === '' ? '-' : item.value }} {{ item.value === undefined || item.value === null || item.value?.toString() === '' ? '-' : item.value }}
@ -108,7 +108,6 @@
isTag?: boolean; // isTag?: boolean; //
showTagAdd?: boolean; // showTagAdd?: boolean; //
isButton?: boolean; isButton?: boolean;
buttonSize?: 'small' | 'mini' | 'large' | 'medium';
showCopy?: boolean; showCopy?: boolean;
copyTimer?: any | null; copyTimer?: any | null;
onClick?: () => void; onClick?: () => void;

View File

@ -2,7 +2,7 @@
<a-drawer <a-drawer
v-bind="props" v-bind="props"
v-model:visible="visible" v-model:visible="visible"
:width="props.width" :width="drawerWidth"
:footer="props.footer" :footer="props.footer"
:mask="props.mask" :mask="props.mask"
:class="[ :class="[
@ -10,9 +10,6 @@
props.mask ? '' : 'ms-drawer-no-mask', props.mask ? '' : 'ms-drawer-no-mask',
props.noContentPadding ? 'ms-drawer-no-content-padding' : '', props.noContentPadding ? 'ms-drawer-no-content-padding' : '',
]" ]"
:drawer-style="{
minWidth: props.minWidth,
}"
@cancel="handleCancel" @cancel="handleCancel"
@close="handleClose" @close="handleClose"
> >
@ -25,6 +22,9 @@
</div> </div>
</slot> </slot>
</template> </template>
<div class="handle" @mousedown="startResize">
<icon-drag-dot-vertical class="absolute left-[-3px] top-[50%] w-[14px]" size="14" />
</div>
<a-scrollbar class="overflow-y-auto" :style="{ height: `calc(100vh - ${contentExtraHeight}px)` }"> <a-scrollbar class="overflow-y-auto" :style="{ height: `calc(100vh - ${contentExtraHeight}px)` }">
<div class="ms-drawer-body"> <div class="ms-drawer-body">
<slot> <slot>
@ -91,8 +91,7 @@
cancelText?: string; cancelText?: string;
saveContinueText?: string; saveContinueText?: string;
showContinue?: boolean; showContinue?: boolean;
width: number | string; width: number;
minWidth?: string; //
noContentPadding?: boolean; // noContentPadding?: boolean; //
} }
@ -138,6 +137,42 @@
visible.value = false; visible.value = false;
emit('update:visible', false); emit('update:visible', false);
}; };
const resizing = ref(false); //
const drawerWidth = ref(props.width); //
/**
* 鼠标单击开始监听拖拽移动
*/
const startResize = (event: MouseEvent) => {
resizing.value = true;
const startX = event.clientX;
const initialWidth = drawerWidth.value;
//
const handleMouseMove = (_event: MouseEvent) => {
if (resizing.value) {
const newWidth = initialWidth + (startX - _event.clientX); // +
if (newWidth >= (props.width || 480) && newWidth <= window.innerWidth * 0.8) {
// width48080%
drawerWidth.value = newWidth;
}
}
};
//
const handleMouseUp = () => {
if (resizing.value) {
//
resizing.value = false;
window.removeEventListener('mousemove', handleMouseMove);
window.removeEventListener('mouseup', handleMouseUp);
}
};
window.addEventListener('mousemove', handleMouseMove);
window.addEventListener('mouseup', handleMouseUp);
};
</script> </script>
<style lang="less"> <style lang="less">
@ -177,4 +212,11 @@
@apply p-0; @apply p-0;
} }
} }
.handle {
@apply absolute left-0 top-0 flex h-full items-center;
width: 8px;
background-color: var(--color-neutral-3);
cursor: col-resize;
}
</style> </style>

View File

@ -29,8 +29,7 @@
</MsCard> </MsCard>
<MsDrawer <MsDrawer
v-model:visible="showDetailDrawer" v-model:visible="showDetailDrawer"
width="40vw" :width="480"
min-width="480px"
:title="activePool?.name" :title="activePool?.name"
:title-tag="activePool?.enable ? t('system.resourcePool.tableEnable') : t('system.resourcePool.tableDisable')" :title-tag="activePool?.enable ? t('system.resourcePool.tableEnable') : t('system.resourcePool.tableDisable')"
:title-tag-color="activePool?.enable ? 'green' : 'gray'" :title-tag-color="activePool?.enable ? 'green' : 'gray'"