|
@@ -27,6 +27,7 @@ type baseSizeType = {
|
|
|
// 窗口模式的尺寸
|
|
|
winWidth: number;
|
|
|
winHeight: number;
|
|
|
+ winMinWidth: number;
|
|
|
minWidth: number;
|
|
|
minHeight: number;
|
|
|
maxHeight: number;
|
|
@@ -52,14 +53,15 @@ const getSizeToUnit = (num: number, unit = 'px') => {
|
|
|
|
|
|
/**
|
|
|
* @params classList 可拖动地方的class值,也为唯一值
|
|
|
- * @params boxClass 容器class值必须为唯一值,这个class和useid拼接 作为缓存主键
|
|
|
+ * @params boxClass 容器class值必须为唯一值
|
|
|
* @params dragShow 弹窗是否显示
|
|
|
- * @params userId 当前用户id
|
|
|
+ * @params initSize 默认尺寸
|
|
|
*/
|
|
|
export default function useDrag(
|
|
|
classList: string[],
|
|
|
boxClass: string,
|
|
|
- dragShow: Ref<boolean>
|
|
|
+ dragShow: Ref<boolean>,
|
|
|
+ initSize?: any
|
|
|
) {
|
|
|
const windowInfo = reactive({
|
|
|
// 小窗口 侧边大窗口
|
|
@@ -130,6 +132,7 @@ export default function useDrag(
|
|
|
// 窗口模式的尺寸
|
|
|
winWidth: 1010,
|
|
|
winHeight: 650,
|
|
|
+ winMinWidth: 800,
|
|
|
minWidth: 400,
|
|
|
minHeight: 640,
|
|
|
maxHeight: window.innerHeight,
|
|
@@ -137,8 +140,8 @@ export default function useDrag(
|
|
|
borderRadius: 12,
|
|
|
transformX: window.innerWidth - 400 - initPos.right,
|
|
|
transformY: (window.innerHeight - 640) / 2,
|
|
|
- height: 640,
|
|
|
- width: 400
|
|
|
+ height: initSize?.height || 640,
|
|
|
+ width: initSize?.width || 400
|
|
|
});
|
|
|
const dragStyles = reactive({
|
|
|
maxHeight: getSizeToUnit(baseSize.maxHeight),
|
|
@@ -158,6 +161,16 @@ export default function useDrag(
|
|
|
baseSize.windowWidth - baseSize.minWidth - initPos.right;
|
|
|
baseSize.transformY = translateY;
|
|
|
dragStyles.maxHeight = getSizeToUnit(baseSize.maxHeight);
|
|
|
+
|
|
|
+ // 初始化定位
|
|
|
+ if (initSize?.defaultPosition === 'center') {
|
|
|
+ // alert(initSize.width)
|
|
|
+ const transformX = (window.innerWidth - (initSize.width || 400)) / 2;
|
|
|
+ const transformY = (baseSize.windowHeight - (initSize.height || 640)) / 2;
|
|
|
+ console.log({ transformX, transformY });
|
|
|
+ baseSize.transformX = transformX;
|
|
|
+ baseSize.transformY = transformY;
|
|
|
+ }
|
|
|
});
|
|
|
// watch(dragShow, () => {
|
|
|
// if (dragShow.value) {
|
|
@@ -446,7 +459,9 @@ function drag(
|
|
|
clientHeight - parentElementRect.height - baseSize.layoutTopHeight;
|
|
|
|
|
|
const maxResizeLeft =
|
|
|
- clientWidth - baseSize.minWidth - (clientWidth - parentElementRect.right);
|
|
|
+ clientWidth -
|
|
|
+ baseSize.winMinWidth -
|
|
|
+ (clientWidth - parentElementRect.right);
|
|
|
const maxResizeTop =
|
|
|
clientHeight - baseSize.minHeight - baseSize.layoutTopHeight;
|
|
|
const minLeft = 0;
|
|
@@ -477,7 +492,7 @@ function drag(
|
|
|
const suffix = Math.ceil(
|
|
|
baseWidth + moveX - (baseSize.width + baseSize.transformX)
|
|
|
);
|
|
|
- if (suffix > 0 || baseSize.width > baseSize.minWidth) {
|
|
|
+ if (suffix > 0 || baseSize.width > baseSize.winMinWidth) {
|
|
|
baseSize.width =
|
|
|
baseSize.width + suffix >= baseSize.maxWidth
|
|
|
? baseSize.maxWidth
|
|
@@ -500,7 +515,7 @@ function drag(
|
|
|
? maxResizeLeft
|
|
|
: moveX;
|
|
|
const suffix = baseSize.transformX - moveX;
|
|
|
- if (suffix > 0 || baseSize.width > baseSize.minWidth) {
|
|
|
+ if (suffix > 0 || baseSize.width > baseSize.winMinWidth) {
|
|
|
if (baseSize.width + suffix <= baseSize.maxWidth) {
|
|
|
baseSize.transformX = moveX;
|
|
|
baseSize.width = baseSize.width + suffix;
|