@veltra/desktop 1.2.25 → 1.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/action/action-group.vue.d.ts +2 -2
- package/dist/components/action/action.vue.d.ts +1 -1
- package/dist/components/batch-edit/batch-edit-form.js +10 -5
- package/dist/components/batch-edit/batch-edit-form.js.map +1 -1
- package/dist/components/batch-edit/use-edit-state.js +1 -0
- package/dist/components/batch-edit/use-edit-state.js.map +1 -1
- package/dist/components/batch-edit/use-handlers.js +3 -0
- package/dist/components/batch-edit/use-handlers.js.map +1 -1
- package/dist/components/batch-edit/use-shortcut-key.js +2 -0
- package/dist/components/batch-edit/use-shortcut-key.js.map +1 -1
- package/dist/components/checkbox/checkbox-button.vue.d.ts +1 -1
- package/dist/components/date-panel/date-panel.vue.d.ts +1 -1
- package/dist/components/date-picker/date-picker.vue.d.ts +1 -1
- package/dist/components/date-range-picker/date-range-picker.vue.d.ts +1 -1
- package/dist/components/number-range-input/number-range-input.js +23 -16
- package/dist/components/number-range-input/number-range-input.js.map +1 -1
- package/dist/components/table/allocate-column-widths.js +32 -0
- package/dist/components/table/allocate-column-widths.js.map +1 -0
- package/dist/components/table/use-col-resize.js +2 -10
- package/dist/components/table/use-col-resize.js.map +1 -1
- package/package.json +6 -6
- package/src/components/batch-edit/batch-edit-form.vue +11 -5
- package/src/components/batch-edit/use-edit-state.ts +3 -0
- package/src/components/batch-edit/use-handlers.ts +5 -0
- package/src/components/batch-edit/use-shortcut-key.ts +2 -0
- package/src/components/number-range-input/__test__/number-range-input.test.ts +100 -0
- package/src/components/number-range-input/number-range-input.vue +28 -16
- package/src/components/table/__test__/col-width.test.ts +77 -0
- package/src/components/table/allocate-column-widths.ts +38 -0
- package/src/components/table/use-col-resize.ts +2 -19
|
@@ -6,11 +6,11 @@ type __VLS_Slots = {
|
|
|
6
6
|
default?: () => VNode[];
|
|
7
7
|
};
|
|
8
8
|
declare const __VLS_base: import("vue").DefineComponent<ActionGroupProps, _ActionGroupExposed, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ActionGroupProps> & Readonly<{}>, {
|
|
9
|
-
type: import("@veltra/utils").ColorType;
|
|
10
9
|
text: boolean;
|
|
11
10
|
size: "small" | "default" | "large";
|
|
12
|
-
|
|
11
|
+
type: import("@veltra/utils").ColorType;
|
|
13
12
|
max: number;
|
|
13
|
+
circle: boolean;
|
|
14
14
|
loading: boolean;
|
|
15
15
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
16
16
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -12,9 +12,9 @@ declare const __VLS_base: import("vue").DefineComponent<ActionProps, {}, {}, {},
|
|
|
12
12
|
}, string, import("vue").PublicProps, Readonly<ActionProps> & Readonly<{
|
|
13
13
|
onRun?: (() => any) | undefined;
|
|
14
14
|
}>, {
|
|
15
|
-
type: ButtonType;
|
|
16
15
|
text: boolean;
|
|
17
16
|
size: import("@veltra/utils").ComponentSize;
|
|
17
|
+
type: ButtonType;
|
|
18
18
|
circle: boolean;
|
|
19
19
|
loading: boolean;
|
|
20
20
|
inDropdown: boolean;
|
|
@@ -7,7 +7,7 @@ import { BatchEditDIKey } from "./di.js";
|
|
|
7
7
|
import { FORM_ACTION_HEADER_MAP } from "./form-action-header.js";
|
|
8
8
|
import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, guardReactiveProps, inject, normalizeClass, normalizeProps, openBlock, renderSlot, resolveDynamicComponent, shallowRef, toDisplayString, toRef, unref, withCtx } from "vue";
|
|
9
9
|
import { bem } from "@veltra/utils";
|
|
10
|
-
import { Close } from "@veltra/icons/normal";
|
|
10
|
+
import { Close, Save } from "@veltra/icons/normal";
|
|
11
11
|
import { o } from "@cat-kit/core";
|
|
12
12
|
//#region src/components/batch-edit/batch-edit-form.vue
|
|
13
13
|
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
@@ -119,6 +119,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
119
119
|
}),
|
|
120
120
|
_cache[3] || (_cache[3] = createTextVNode(" 关闭 ", -1))
|
|
121
121
|
], 2)], 2), createElementVNode("div", { class: normalizeClass(unref(cls).e("form-actions")) }, [createVNode(unref(_sfc_main$3), {
|
|
122
|
+
size: "small",
|
|
122
123
|
text: "",
|
|
123
124
|
loading: unref(state).loading,
|
|
124
125
|
onClick: unref(handleClose)
|
|
@@ -128,12 +129,16 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
128
129
|
}, 8, ["loading", "onClick"]), showSaveBtn.value ? (openBlock(), createBlock(unref(_sfc_main$3), {
|
|
129
130
|
key: 0,
|
|
130
131
|
type: "primary",
|
|
132
|
+
size: "small",
|
|
133
|
+
title: "保存",
|
|
134
|
+
icon: unref(Save),
|
|
131
135
|
loading: unref(state).loading,
|
|
132
136
|
onClick: unref(handleSave)
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
}, null, 8, [
|
|
138
|
+
"icon",
|
|
139
|
+
"loading",
|
|
140
|
+
"onClick"
|
|
141
|
+
])) : createCommentVNode("v-if", true)], 2)], 2)
|
|
137
142
|
], 2)) : createCommentVNode("v-if", true);
|
|
138
143
|
};
|
|
139
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit-form.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-form.vue"],"sourcesContent":["<template>\n <aside :class=\"cls.e('form')\" v-if=\"state.formVisible && !!props.model\">\n <header :class=\"cls.e('form-header')\">\n <span :class=\"[cls.e('form-icon'), bem.is(state.formActionType)]\">\n <u-icon>\n <component :is=\"headerInfo.icon\" />\n </u-icon>\n </span>\n <div :class=\"cls.e('form-title')\">\n <h3 :class=\"cls.e('form-title-text')\">{{ headerInfo.title }}</h3>\n </div>\n <u-button\n :class=\"cls.e('form-close')\"\n :icon=\"Close\"\n text\n circle\n size=\"small\"\n title=\"关闭\"\n @click=\"handleClose\"\n />\n </header>\n\n <u-scroll always :class=\"cls.e('form-body')\" :key=\"bodyKey\">\n <transition name=\"fade\" appear mode=\"out-in\">\n <u-form\n ref=\"formComponentRef\"\n :model=\"props.model\"\n :readonly=\"props.readonly\"\n :label-width=\"props.labelWidth\"\n @field:change=\"handleFieldChange\"\n >\n <slot\n v-bind=\"{\n row: state.row,\n depth: state.depth,\n indexes: state.indexPath,\n index: state.row?.index\n }\"\n />\n </u-form>\n </transition>\n </u-scroll>\n\n <footer :class=\"cls.e('form-footer')\">\n <span :class=\"cls.e('form-hint')\">\n <template v-if=\"props.readonly\"> 只读模式 </template>\n\n <span :class=\"{ [bem.is('concealed')]: !focused }\">\n <template v-if=\"!(state.formActionType === 'update' && props.quickEdit)\">\n <u-kbd>Ctrl + S</u-kbd> 保存 ·\n </template>\n <u-kbd>Esc</u-kbd> 关闭\n </span>\n </span>\n\n <div :class=\"cls.e('form-actions')\">\n <u-button text :loading=\"state.loading\" @click=\"handleClose\"> 取消 </u-button>\n <u-button
|
|
1
|
+
{"version":3,"file":"batch-edit-form.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-form.vue"],"sourcesContent":["<template>\n <aside :class=\"cls.e('form')\" v-if=\"state.formVisible && !!props.model\">\n <header :class=\"cls.e('form-header')\">\n <span :class=\"[cls.e('form-icon'), bem.is(state.formActionType)]\">\n <u-icon>\n <component :is=\"headerInfo.icon\" />\n </u-icon>\n </span>\n <div :class=\"cls.e('form-title')\">\n <h3 :class=\"cls.e('form-title-text')\">{{ headerInfo.title }}</h3>\n </div>\n <u-button\n :class=\"cls.e('form-close')\"\n :icon=\"Close\"\n text\n circle\n size=\"small\"\n title=\"关闭\"\n @click=\"handleClose\"\n />\n </header>\n\n <u-scroll always :class=\"cls.e('form-body')\" :key=\"bodyKey\">\n <transition name=\"fade\" appear mode=\"out-in\">\n <u-form\n ref=\"formComponentRef\"\n :model=\"props.model\"\n :readonly=\"props.readonly\"\n :label-width=\"props.labelWidth\"\n @field:change=\"handleFieldChange\"\n >\n <slot\n v-bind=\"{\n row: state.row,\n depth: state.depth,\n indexes: state.indexPath,\n index: state.row?.index\n }\"\n />\n </u-form>\n </transition>\n </u-scroll>\n\n <footer :class=\"cls.e('form-footer')\">\n <span :class=\"cls.e('form-hint')\">\n <template v-if=\"props.readonly\"> 只读模式 </template>\n\n <span :class=\"{ [bem.is('concealed')]: !focused }\">\n <template v-if=\"!(state.formActionType === 'update' && props.quickEdit)\">\n <u-kbd>Ctrl + S</u-kbd> 保存 ·\n </template>\n <u-kbd>Esc</u-kbd> 关闭\n </span>\n </span>\n\n <div :class=\"cls.e('form-actions')\">\n <u-button size=\"small\" text :loading=\"state.loading\" @click=\"handleClose\"> 取消 </u-button>\n <u-button\n v-if=\"showSaveBtn\"\n type=\"primary\"\n size=\"small\"\n title=\"保存\"\n :icon=\"Save\"\n :loading=\"state.loading\"\n @click=\"handleSave\"\n />\n </div>\n </footer>\n </aside>\n</template>\n\n<script lang=\"ts\" setup>\nimport { o } from '@cat-kit/core'\nimport { Close, Save } from '@veltra/icons/normal'\nimport { bem } from '@veltra/utils'\nimport { computed, inject, shallowRef, toRef } from 'vue'\n\nimport type { _FormExposed, FormExposed } from '../../types/form'\nimport { UButton } from '../button'\nimport { UForm } from '../form'\nimport { UIcon } from '../icon'\nimport { UKbd } from '../kbd'\nimport { UScroll } from '../scroll'\nimport { BatchEditDIKey } from './di'\nimport { FORM_ACTION_HEADER_MAP } from './form-action-header'\n\ndefineOptions({ name: 'UBatchEditForm' })\n\nconst batchEditCtx = inject(BatchEditDIKey)!\n\nconst { cls, props, state, handleClose, handleSave, staticFeatures, dynamicFeatures } = batchEditCtx\n\nconst focused = toRef(batchEditCtx, 'focused')\n\nconst formComponentRef = shallowRef<FormExposed>()\n\ndefineExpose<_FormExposed>({\n el: toRef(() => formComponentRef.value?.el),\n validate: () => formComponentRef.value?.validate() ?? Promise.resolve(true),\n clearValidate: () => formComponentRef.value?.clearValidate(),\n reset: () => formComponentRef.value?.reset()\n})\n\nfunction handleFieldChange(field: string, value: any) {\n if (state.row && props.quickEdit) {\n o(state.row.data).set(field, value)\n }\n}\n\nconst creatable = computed(() => {\n if (state.formActionType !== 'create') return false\n return staticFeatures.value.has('create') || dynamicFeatures.value.create?.(state.row)\n})\n\nconst creatableChild = computed(() => {\n if (state.formActionType !== 'createChild') return false\n return staticFeatures.value.has('createChild') || dynamicFeatures.value.createChild?.(state.row)\n})\n\nconst updatable = computed(() => {\n if (state.formActionType !== 'update') return false\n return staticFeatures.value.has('update') || dynamicFeatures.value.update?.(state.row)\n})\n\nconst showSaveBtn = computed(() => {\n if (props.readonly) return false\n if (props.quickEdit && state.formActionType === 'update') return false\n return creatable.value || updatable.value || creatableChild.value\n})\n\nconst headerInfo = computed(() => FORM_ACTION_HEADER_MAP[state.formActionType])\n\n/** 通过 row 切换 / 类型切换驱动表单内容淡出淡入 */\nconst bodyKey = computed(() => {\n return `${state.formActionType}-${state.row?.uid ?? 'create'}-${state.parentRow?.uid ?? 'root'}`\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;EAwFA,MAAM,eAAe,OAAO,cAAc;EAE1C,MAAM,EAAE,KAAK,OAAO,OAAO,aAAa,YAAY,gBAAgB,oBAAoB;EAExF,MAAM,UAAU,MAAM,cAAc,SAAS;EAE7C,MAAM,mBAAmB,WAAwB;EAEjD,SAA2B;GACzB,IAAI,YAAY,iBAAiB,OAAO,EAAE;GAC1C,gBAAgB,iBAAiB,OAAO,SAAS,KAAK,QAAQ,QAAQ,IAAI;GAC1E,qBAAqB,iBAAiB,OAAO,cAAc;GAC3D,aAAa,iBAAiB,OAAO,MAAM;EAC7C,CAAC;EAED,SAAS,kBAAkB,OAAe,OAAY;GACpD,IAAI,MAAM,OAAO,MAAM,WACrB,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC,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IAAA;KACN,SAAS,MAAA,KAAA,CAAK,CAAC;KACf,SAAO,MAAA,UAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-edit-state.js","names":[],"sources":["../../../src/components/batch-edit/use-edit-state.ts"],"sourcesContent":["import { o } from '@cat-kit/core'\nimport { nextTick, shallowReactive, watch, type ShallowRef } from 'vue'\n\nimport type { BatchEditProps, BatchEditStates, FormExposed } from '../../types'\n\ninterface Options {\n props: BatchEditProps\n formRef: ShallowRef<FormExposed | null>\n}\n\nexport function useEditState(options: Options) {\n const { props, formRef } = options\n\n const defaultState: BatchEditStates = {\n depth: -1,\n formVisible: false,\n formActionType: 'create',\n loading: false,\n indexPath: []\n }\n\n const state = shallowReactive({ ...defaultState })\n\n function resetState() {\n if (state.row) {\n state.row.isCurrent = false\n }\n\n Object.keys(state).forEach((key) => {\n delete state[key]\n })\n\n Object.assign(state, defaultState)\n }\n\n watch(\n () => state.row,\n (row) => {\n formRef.value?.reset()\n\n if (row) {\n /** 延迟设置 model,防止表单初始状态丢失 */\n nextTick(() => {\n if (props.model) {\n o(props.model).deepExtend(row.data)\n }\n })\n state.formActionType = props.readonly ? 'view' : 'update'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n\n return\n }\n\n resetState()\n }\n )\n\n return { state, resetState }\n}\n"],"mappings":";;;AAUA,SAAgB,aAAa,SAAkB;CAC7C,MAAM,EAAE,OAAO,YAAY;CAE3B,MAAM,eAAgC;EACpC,OAAO;EACP,aAAa;EACb,gBAAgB;EAChB,SAAS;EACT,WAAW,CAAC;CACd;CAEA,MAAM,QAAQ,gBAAgB,EAAE,GAAG,aAAa,CAAC;CAEjD,SAAS,aAAa;
|
|
1
|
+
{"version":3,"file":"use-edit-state.js","names":[],"sources":["../../../src/components/batch-edit/use-edit-state.ts"],"sourcesContent":["import { o } from '@cat-kit/core'\nimport { nextTick, shallowReactive, watch, type ShallowRef } from 'vue'\n\nimport type { BatchEditProps, BatchEditStates, FormExposed } from '../../types'\n\ninterface Options {\n props: BatchEditProps\n formRef: ShallowRef<FormExposed | null>\n}\n\nexport function useEditState(options: Options) {\n const { props, formRef } = options\n\n const defaultState: BatchEditStates = {\n depth: -1,\n formVisible: false,\n formActionType: 'create',\n loading: false,\n indexPath: []\n }\n\n const state = shallowReactive({ ...defaultState })\n\n function resetState() {\n // 销毁表单前先重置,避免下次 v-if 重挂载时 Form 拍到脏 model\n formRef.value?.reset()\n\n if (state.row) {\n state.row.isCurrent = false\n }\n\n Object.keys(state).forEach((key) => {\n delete state[key]\n })\n\n Object.assign(state, defaultState)\n }\n\n watch(\n () => state.row,\n (row) => {\n formRef.value?.reset()\n\n if (row) {\n /** 延迟设置 model,防止表单初始状态丢失 */\n nextTick(() => {\n if (props.model) {\n o(props.model).deepExtend(row.data)\n }\n })\n state.formActionType = props.readonly ? 'view' : 'update'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n\n return\n }\n\n resetState()\n }\n )\n\n return { state, resetState }\n}\n"],"mappings":";;;AAUA,SAAgB,aAAa,SAAkB;CAC7C,MAAM,EAAE,OAAO,YAAY;CAE3B,MAAM,eAAgC;EACpC,OAAO;EACP,aAAa;EACb,gBAAgB;EAChB,SAAS;EACT,WAAW,CAAC;CACd;CAEA,MAAM,QAAQ,gBAAgB,EAAE,GAAG,aAAa,CAAC;CAEjD,SAAS,aAAa;EAEpB,QAAQ,OAAO,MAAM;EAErB,IAAI,MAAM,KACR,MAAM,IAAI,YAAY;EAGxB,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,QAAQ;GAClC,OAAO,MAAM;EACf,CAAC;EAED,OAAO,OAAO,OAAO,YAAY;CACnC;CAEA,YACQ,MAAM,MACX,QAAQ;EACP,QAAQ,OAAO,MAAM;EAErB,IAAI,KAAK;;GAEP,eAAe;IACb,IAAI,MAAM,OACR,EAAE,MAAM,KAAK,CAAC,CAAC,WAAW,IAAI,IAAI;GAEtC,CAAC;GACD,MAAM,iBAAiB,MAAM,WAAW,SAAS;GACjD,MAAM,cAAc;GACpB,MAAM,QAAQ,IAAI;GAClB,MAAM,YAAY,CAAC,GAAG,IAAI,OAAO;GAEjC;EACF;EAEA,WAAW;CACb,CACF;CAEA,OAAO;EAAE;EAAO;CAAW;AAC7B"}
|
|
@@ -103,6 +103,9 @@ function useHandlers(options) {
|
|
|
103
103
|
if (result) item = result;
|
|
104
104
|
}
|
|
105
105
|
insert(item);
|
|
106
|
+
const next = last(state.indexPath) + 1;
|
|
107
|
+
state.indexPath = [...state.indexPath.slice(0, -1), next];
|
|
108
|
+
formRef.value?.reset();
|
|
106
109
|
return;
|
|
107
110
|
}
|
|
108
111
|
if (saveMethod) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-handlers.js","names":[],"sources":["../../../src/components/batch-edit/use-handlers.ts"],"sourcesContent":["import { last, o } from '@cat-kit/core'\nimport { computed, nextTick, type ShallowRef } from 'vue'\n\nimport type {\n TableRow,\n BatchEditEmits,\n BatchEditProps,\n BatchEditStates,\n FormExposed\n} from '../../types'\n\n/** 按索引路径在原始数据树中定位节点(等价于历史 Forest.visit 路径访问) */\nfunction visitDataByIndexPath<T extends Record<string, unknown>>(\n roots: T[],\n indexPath: number[],\n childrenKey: string\n): T | undefined {\n if (!indexPath.length) return undefined\n let currentList: T[] | undefined = roots\n let node: T | undefined\n for (let i = 0; i < indexPath.length; i++) {\n const idx = indexPath[i]!\n if (!currentList) return undefined\n node = currentList[idx]\n if (node === undefined) return undefined\n if (i < indexPath.length - 1) {\n const next = node[childrenKey]\n currentList = Array.isArray(next) ? (next as T[]) : undefined\n }\n }\n return node\n}\n\ninterface Options {\n props: BatchEditProps\n emit: BatchEditEmits\n state: BatchEditStates\n formRef: ShallowRef<FormExposed | null>\n resetState: () => void\n}\n\nexport interface EditReturned {\n handleSave: () => Promise<void>\n handleClose: () => void\n handleCreate: () => void\n handleDelete: (row: TableRow) => Promise<void>\n handleInsertToNext: (row: TableRow) => void\n handleInsertToPrev: (row: TableRow) => void\n handleInsertChild: (row: TableRow) => void\n}\n\nexport function useHandlers(options: Options): EditReturned {\n const { props, emit, state, resetState, formRef } = options\n\n const childrenKey = computed(() => {\n return typeof props.tree === 'string' ? props.tree : 'children'\n })\n\n function getInsertData(): Record<string, any> {\n return o(props.model ?? {}).copy()\n }\n\n /**\n * 插入数据\n * @param item 数据\n */\n function insert(item: Record<string, any>) {\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data ?? [], state.indexPath.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (!children) {\n parent[childrenKey.value] = [item]\n } else {\n children.splice(last(state.indexPath), 0, item)\n }\n } else {\n data.splice(last(state.indexPath), 0, item)\n }\n\n emit('update:data', data)\n\n return item\n }\n\n /**\n * 点击新增按钮\n */\n function handleCreate() {\n const { data } = props\n\n resetState()\n\n nextTick(() => {\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = 1\n state.indexPath = [data?.length ?? 0]\n })\n }\n\n function handleInsertToPrev(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n }\n\n function handleInsertToNext(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes.slice(0, -1), row.index + 1]\n }\n\n function handleInsertChild(row: TableRow) {\n resetState()\n state.formActionType = 'createChild'\n state.formVisible = true\n state.parentRow = row\n state.depth = row.depth + 1\n row.expanded = true\n state.indexPath = [...row.indexes, row.children?.length ?? 0]\n }\n\n function runWithLoading<Arg extends any[]>(fn: (...args: Arg) => Promise<void> | void) {\n return async (...args: Arg) => {\n state.loading = true\n if (state.row) {\n state.row.operating = true\n }\n try {\n await fn.apply(null, args)\n } catch (error) {\n console.error(error)\n }\n state.loading = false\n if (state.row) {\n state.row.operating = false\n }\n }\n }\n\n /** 保存 */\n const handleSave = runWithLoading(async () => {\n const { model, saveMethod } = props\n const valid = await formRef.value?.validate()\n if (!model || !valid) return\n\n let item = getInsertData()\n\n // 新增\n if (state.formActionType === 'create' || state.formActionType === 'createChild') {\n await props.beforeCreate?.(item, state.parentRow?.data)\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n insert(item)\n return\n }\n\n // 普通模式下的编辑\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n\n const { row } = state\n row &&\n Object.keys(item).forEach((key) => {\n o(row.data).set(key, o(item).get(key))\n })\n })\n\n const handleDelete = runWithLoading(async (row: TableRow) => {\n const { deleteMethod } = props\n\n if (deleteMethod) {\n await deleteMethod([row.data])\n }\n\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data, row.indexes.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (children) {\n children.splice(row.index, 1)\n } else {\n console.error('行路径不正确')\n }\n } else {\n data.splice(row.index, 1)\n }\n\n if (state.row === row) {\n resetState()\n }\n\n emit('update:data', data)\n })\n\n function handleClose() {\n resetState()\n }\n\n return {\n handleDelete,\n handleInsertChild,\n handleInsertToNext,\n handleInsertToPrev,\n handleCreate,\n handleClose,\n handleSave\n }\n}\n"],"mappings":";;;;AAYA,SAAS,qBACP,OACA,WACA,aACe;CACf,IAAI,CAAC,UAAU,QAAQ,OAAO,KAAA;CAC9B,IAAI,cAA+B;CACnC,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,MAAM,UAAU;EACtB,IAAI,CAAC,aAAa,OAAO,KAAA;EACzB,OAAO,YAAY;EACnB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,IAAI,IAAI,UAAU,SAAS,GAAG;GAC5B,MAAM,OAAO,KAAK;GAClB,cAAc,MAAM,QAAQ,IAAI,IAAK,OAAe,KAAA;EAC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C;CAC/D;CAEA,SAAS,kBAAkB,KAAe;EACxC,WAAW;EACX,MAAM,iBAAiB;EACvB,MAAM,cAAc;EACpB,MAAM,YAAY;EAClB,MAAM,QAAQ,IAAI,QAAQ;EAC1B,IAAI,WAAW;EACf,MAAM,YAAY,CAAC,GAAG,IAAI,SAAS,IAAI,UAAU,UAAU,CAAC;CAC9D;CAEA,SAAS,eAAkC,IAA4C;EACrF,OAAO,OAAO,GAAG,SAAc;GAC7B,MAAM,UAAU;GAChB,IAAI,MAAM,KACR,MAAM,IAAI,YAAY;GAExB,IAAI;IACF,MAAM,GAAG,MAAM,MAAM,IAAI;GAC3B,SAAS,OAAO;IACd,QAAQ,MAAM,KAAK;GACrB;GACA,MAAM,UAAU;GAChB,IAAI,MAAM,KACR,MAAM,IAAI,YAAY;EAE1B;CACF;;CAGA,MAAM,aAAa,eAAe,YAAY;EAC5C,MAAM,EAAE,OAAO,eAAe;EAC9B,MAAM,QAAQ,MAAM,QAAQ,OAAO,SAAS;EAC5C,IAAI,CAAC,SAAS,CAAC,OAAO;EAEtB,IAAI,OAAO,cAAc;EAGzB,IAAI,MAAM,mBAAmB,YAAY,MAAM,mBAAmB,eAAe;GAC/E,MAAM,MAAM,eAAe,MAAM,MAAM,WAAW,IAAI;GACtD,IAAI,YAAY;IACd,MAAM,SAAS,MAAM,WAAW,MAAM,MAAM,gBAAgB,MAAM,WAAW,IAAI;IACjF,IAAI,QACF,OAAO;GAEX;GACA,OAAO,IAAI;
|
|
1
|
+
{"version":3,"file":"use-handlers.js","names":[],"sources":["../../../src/components/batch-edit/use-handlers.ts"],"sourcesContent":["import { last, o } from '@cat-kit/core'\nimport { computed, nextTick, type ShallowRef } from 'vue'\n\nimport type {\n TableRow,\n BatchEditEmits,\n BatchEditProps,\n BatchEditStates,\n FormExposed\n} from '../../types'\n\n/** 按索引路径在原始数据树中定位节点(等价于历史 Forest.visit 路径访问) */\nfunction visitDataByIndexPath<T extends Record<string, unknown>>(\n roots: T[],\n indexPath: number[],\n childrenKey: string\n): T | undefined {\n if (!indexPath.length) return undefined\n let currentList: T[] | undefined = roots\n let node: T | undefined\n for (let i = 0; i < indexPath.length; i++) {\n const idx = indexPath[i]!\n if (!currentList) return undefined\n node = currentList[idx]\n if (node === undefined) return undefined\n if (i < indexPath.length - 1) {\n const next = node[childrenKey]\n currentList = Array.isArray(next) ? (next as T[]) : undefined\n }\n }\n return node\n}\n\ninterface Options {\n props: BatchEditProps\n emit: BatchEditEmits\n state: BatchEditStates\n formRef: ShallowRef<FormExposed | null>\n resetState: () => void\n}\n\nexport interface EditReturned {\n handleSave: () => Promise<void>\n handleClose: () => void\n handleCreate: () => void\n handleDelete: (row: TableRow) => Promise<void>\n handleInsertToNext: (row: TableRow) => void\n handleInsertToPrev: (row: TableRow) => void\n handleInsertChild: (row: TableRow) => void\n}\n\nexport function useHandlers(options: Options): EditReturned {\n const { props, emit, state, resetState, formRef } = options\n\n const childrenKey = computed(() => {\n return typeof props.tree === 'string' ? props.tree : 'children'\n })\n\n function getInsertData(): Record<string, any> {\n return o(props.model ?? {}).copy()\n }\n\n /**\n * 插入数据\n * @param item 数据\n */\n function insert(item: Record<string, any>) {\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data ?? [], state.indexPath.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (!children) {\n parent[childrenKey.value] = [item]\n } else {\n children.splice(last(state.indexPath), 0, item)\n }\n } else {\n data.splice(last(state.indexPath), 0, item)\n }\n\n emit('update:data', data)\n\n return item\n }\n\n /**\n * 点击新增按钮\n */\n function handleCreate() {\n const { data } = props\n\n resetState()\n\n nextTick(() => {\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = 1\n state.indexPath = [data?.length ?? 0]\n })\n }\n\n function handleInsertToPrev(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n }\n\n function handleInsertToNext(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes.slice(0, -1), row.index + 1]\n }\n\n function handleInsertChild(row: TableRow) {\n resetState()\n state.formActionType = 'createChild'\n state.formVisible = true\n state.parentRow = row\n state.depth = row.depth + 1\n row.expanded = true\n state.indexPath = [...row.indexes, row.children?.length ?? 0]\n }\n\n function runWithLoading<Arg extends any[]>(fn: (...args: Arg) => Promise<void> | void) {\n return async (...args: Arg) => {\n state.loading = true\n if (state.row) {\n state.row.operating = true\n }\n try {\n await fn.apply(null, args)\n } catch (error) {\n console.error(error)\n }\n state.loading = false\n if (state.row) {\n state.row.operating = false\n }\n }\n }\n\n /** 保存 */\n const handleSave = runWithLoading(async () => {\n const { model, saveMethod } = props\n const valid = await formRef.value?.validate()\n if (!model || !valid) return\n\n let item = getInsertData()\n\n // 新增\n if (state.formActionType === 'create' || state.formActionType === 'createChild') {\n await props.beforeCreate?.(item, state.parentRow?.data)\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n insert(item)\n\n // 推进插入点,便于连续新增;并重置表单到初始默认值\n const next = last(state.indexPath) + 1\n state.indexPath = [...state.indexPath.slice(0, -1), next]\n formRef.value?.reset()\n return\n }\n\n // 普通模式下的编辑\n if (saveMethod) {\n const result = await saveMethod(item, state.formActionType, state.parentRow?.data)\n if (result) {\n item = result\n }\n }\n\n const { row } = state\n row &&\n Object.keys(item).forEach((key) => {\n o(row.data).set(key, o(item).get(key))\n })\n })\n\n const handleDelete = runWithLoading(async (row: TableRow) => {\n const { deleteMethod } = props\n\n if (deleteMethod) {\n await deleteMethod([row.data])\n }\n\n const data = [...(props.data ?? [])]\n\n const parent = visitDataByIndexPath(data, row.indexes.slice(0, -1), childrenKey.value)\n\n if (parent) {\n const children = parent[childrenKey.value]\n if (children) {\n children.splice(row.index, 1)\n } else {\n console.error('行路径不正确')\n }\n } else {\n data.splice(row.index, 1)\n }\n\n if (state.row === row) {\n resetState()\n }\n\n emit('update:data', data)\n })\n\n function handleClose() {\n resetState()\n }\n\n return {\n handleDelete,\n handleInsertChild,\n handleInsertToNext,\n handleInsertToPrev,\n handleCreate,\n handleClose,\n handleSave\n }\n}\n"],"mappings":";;;;AAYA,SAAS,qBACP,OACA,WACA,aACe;CACf,IAAI,CAAC,UAAU,QAAQ,OAAO,KAAA;CAC9B,IAAI,cAA+B;CACnC,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,MAAM,UAAU;EACtB,IAAI,CAAC,aAAa,OAAO,KAAA;EACzB,OAAO,YAAY;EACnB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,IAAI,IAAI,UAAU,SAAS,GAAG;GAC5B,MAAM,OAAO,KAAK;GAClB,cAAc,MAAM,QAAQ,IAAI,IAAK,OAAe,KAAA;EACtD;CACF;CACA,OAAO;AACT;AAoBA,SAAgB,YAAY,SAAgC;CAC1D,MAAM,EAAE,OAAO,MAAM,OAAO,YAAY,YAAY;CAEpD,MAAM,cAAc,eAAe;EACjC,OAAO,OAAO,MAAM,SAAS,WAAW,MAAM,OAAO;CACvD,CAAC;CAED,SAAS,gBAAqC;EAC5C,OAAO,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK;CACnC;;;;;CAMA,SAAS,OAAO,MAA2B;EACzC,MAAM,OAAO,CAAC,GAAI,MAAM,QAAQ,CAAC,CAAE;EAEnC,MAAM,SAAS,qBAAqB,QAAQ,CAAC,GAAG,MAAM,UAAU,MAAM,GAAG,EAAE,GAAG,YAAY,KAAK;EAE/F,IAAI,QAAQ;GACV,MAAM,WAAW,OAAO,YAAY;GACpC,IAAI,CAAC,UACH,OAAO,YAAY,SAAS,CAAC,IAAI;QAEjC,SAAS,OAAO,KAAK,MAAM,SAAS,GAAG,GAAG,IAAI;EAElD,OACE,KAAK,OAAO,KAAK,MAAM,SAAS,GAAG,GAAG,IAAI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ACb;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -10,7 +10,9 @@ function useShortcutKey(options) {
|
|
|
10
10
|
if (!e.currentTarget.contains(e.relatedTarget)) focused.value = false;
|
|
11
11
|
}
|
|
12
12
|
function runEscape(e) {
|
|
13
|
+
if (!state.formVisible) return;
|
|
13
14
|
e.preventDefault();
|
|
15
|
+
e.stopPropagation();
|
|
14
16
|
onClose();
|
|
15
17
|
}
|
|
16
18
|
function runSave(e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-shortcut-key.js","names":[],"sources":["../../../src/components/batch-edit/use-shortcut-key.ts"],"sourcesContent":["import { shallowRef } from 'vue'\n\nimport type { BatchEditProps, BatchEditStates } from '../../types'\n\ninterface Options {\n props: BatchEditProps\n onSave: () => void\n onClose: () => void\n state: BatchEditStates\n}\nexport function useShortcutKey(options: Options) {\n const { props, onClose, onSave, state } = options\n const focused = shallowRef(false)\n\n function handleFocusIn() {\n focused.value = true\n }\n\n function handleFocusOut(e: FocusEvent) {\n const root = e.currentTarget as HTMLElement\n if (!root.contains(e.relatedTarget as Node | null)) {\n focused.value = false\n }\n }\n\n function runEscape(e: KeyboardEvent) {\n e.preventDefault()\n onClose()\n }\n\n function runSave(e: KeyboardEvent) {\n if (!state.formVisible) return\n if (props.quickEdit && state.formActionType === 'update') return\n e.preventDefault()\n onSave()\n }\n\n /**\n * 键盘快捷键(仅组件获焦时生效):\n * - Esc 关闭表单\n * - ⌘/Ctrl + S 保存(快速编辑模式下编辑行时除外)\n */\n function handleKeydown(e: KeyboardEvent) {\n if (!focused.value) return\n if (props.readonly && e.key !== 'Escape') return\n\n if (e.key === 'Escape') return runEscape(e)\n\n const meta = e.metaKey || e.ctrlKey\n if (!meta) return\n\n const key = e.key.toLowerCase()\n\n if (key === 's') return runSave(e)\n }\n\n return { focused, handleFocusIn, handleFocusOut, handleKeydown }\n}\n"],"mappings":";;AAUA,SAAgB,eAAe,SAAkB;CAC/C,MAAM,EAAE,OAAO,SAAS,QAAQ,UAAU;CAC1C,MAAM,UAAU,WAAW,KAAK;CAEhC,SAAS,gBAAgB;EACvB,QAAQ,QAAQ;CAClB;CAEA,SAAS,eAAe,GAAe;EAErC,IAAI,CADS,EAAE,cACL,SAAS,EAAE,aAA4B,GAC/C,QAAQ,QAAQ;CAEpB;CAEA,SAAS,UAAU,GAAkB;EACnC,EAAE,eAAe;EACjB,QAAQ;CACV;CAEA,SAAS,QAAQ,GAAkB;EACjC,IAAI,CAAC,MAAM,aAAa;EACxB,IAAI,MAAM,aAAa,MAAM,mBAAmB,UAAU;EAC1D,EAAE,eAAe;EACjB,OAAO;CACT;;;;;;CAOA,SAAS,cAAc,GAAkB;EACvC,IAAI,CAAC,QAAQ,OAAO;EACpB,IAAI,MAAM,YAAY,EAAE,QAAQ,UAAU;EAE1C,IAAI,EAAE,QAAQ,UAAU,OAAO,UAAU,CAAC;EAG1C,IAAI,EADS,EAAE,WAAW,EAAE,UACjB;EAIX,IAFY,EAAE,IAAI,YAEZ,MAAM,KAAK,OAAO,QAAQ,CAAC;CACnC;CAEA,OAAO;EAAE;EAAS;EAAe;EAAgB;CAAc;AACjE"}
|
|
1
|
+
{"version":3,"file":"use-shortcut-key.js","names":[],"sources":["../../../src/components/batch-edit/use-shortcut-key.ts"],"sourcesContent":["import { shallowRef } from 'vue'\n\nimport type { BatchEditProps, BatchEditStates } from '../../types'\n\ninterface Options {\n props: BatchEditProps\n onSave: () => void\n onClose: () => void\n state: BatchEditStates\n}\nexport function useShortcutKey(options: Options) {\n const { props, onClose, onSave, state } = options\n const focused = shallowRef(false)\n\n function handleFocusIn() {\n focused.value = true\n }\n\n function handleFocusOut(e: FocusEvent) {\n const root = e.currentTarget as HTMLElement\n if (!root.contains(e.relatedTarget as Node | null)) {\n focused.value = false\n }\n }\n\n function runEscape(e: KeyboardEvent) {\n if (!state.formVisible) return\n e.preventDefault()\n e.stopPropagation()\n onClose()\n }\n\n function runSave(e: KeyboardEvent) {\n if (!state.formVisible) return\n if (props.quickEdit && state.formActionType === 'update') return\n e.preventDefault()\n onSave()\n }\n\n /**\n * 键盘快捷键(仅组件获焦时生效):\n * - Esc 关闭表单\n * - ⌘/Ctrl + S 保存(快速编辑模式下编辑行时除外)\n */\n function handleKeydown(e: KeyboardEvent) {\n if (!focused.value) return\n if (props.readonly && e.key !== 'Escape') return\n\n if (e.key === 'Escape') return runEscape(e)\n\n const meta = e.metaKey || e.ctrlKey\n if (!meta) return\n\n const key = e.key.toLowerCase()\n\n if (key === 's') return runSave(e)\n }\n\n return { focused, handleFocusIn, handleFocusOut, handleKeydown }\n}\n"],"mappings":";;AAUA,SAAgB,eAAe,SAAkB;CAC/C,MAAM,EAAE,OAAO,SAAS,QAAQ,UAAU;CAC1C,MAAM,UAAU,WAAW,KAAK;CAEhC,SAAS,gBAAgB;EACvB,QAAQ,QAAQ;CAClB;CAEA,SAAS,eAAe,GAAe;EAErC,IAAI,CADS,EAAE,cACL,SAAS,EAAE,aAA4B,GAC/C,QAAQ,QAAQ;CAEpB;CAEA,SAAS,UAAU,GAAkB;EACnC,IAAI,CAAC,MAAM,aAAa;EACxB,EAAE,eAAe;EACjB,EAAE,gBAAgB;EAClB,QAAQ;CACV;CAEA,SAAS,QAAQ,GAAkB;EACjC,IAAI,CAAC,MAAM,aAAa;EACxB,IAAI,MAAM,aAAa,MAAM,mBAAmB,UAAU;EAC1D,EAAE,eAAe;EACjB,OAAO;CACT;;;;;;CAOA,SAAS,cAAc,GAAkB;EACvC,IAAI,CAAC,QAAQ,OAAO;EACpB,IAAI,MAAM,YAAY,EAAE,QAAQ,UAAU;EAE1C,IAAI,EAAE,QAAQ,UAAU,OAAO,UAAU,CAAC;EAG1C,IAAI,EADS,EAAE,WAAW,EAAE,UACjB;EAIX,IAFY,EAAE,IAAI,YAEZ,MAAM,KAAK,OAAO,QAAQ,CAAC;CACnC;CAEA,OAAO;EAAE;EAAS;EAAe;EAAgB;CAAc;AACjE"}
|
|
@@ -17,9 +17,9 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
|
|
|
17
17
|
"onUpdate:modelValue"?: ((checked: boolean) => any) | undefined;
|
|
18
18
|
onChange?: ((checked: boolean) => any) | undefined;
|
|
19
19
|
}>, {
|
|
20
|
-
type: import("@veltra/utils").ColorType;
|
|
21
20
|
disabled: boolean;
|
|
22
21
|
readonly: boolean;
|
|
22
|
+
type: import("@veltra/utils").ColorType;
|
|
23
23
|
round: boolean;
|
|
24
24
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
25
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -7,8 +7,8 @@ declare const __VLS_export: import("vue").DefineComponent<DatePanelProps, {}, {}
|
|
|
7
7
|
"onSelect:range-date"?: ((rangeDate?: [import("@cat-kit/core").Dater, import("@cat-kit/core").Dater] | undefined) => any) | undefined;
|
|
8
8
|
"onSelect:date"?: ((date: import("@cat-kit/core").Dater) => any) | undefined;
|
|
9
9
|
}>, {
|
|
10
|
-
type: "date" | "month" | "year";
|
|
11
10
|
size: import("@veltra/utils").ComponentSize;
|
|
11
|
+
type: "date" | "month" | "year";
|
|
12
12
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
13
|
declare const _default: typeof __VLS_export;
|
|
14
14
|
//#endregion
|
|
@@ -5,11 +5,11 @@ declare const __VLS_export: import("vue").DefineComponent<DatePickerProps, {}, {
|
|
|
5
5
|
}, string, import("vue").PublicProps, Readonly<DatePickerProps> & Readonly<{
|
|
6
6
|
"onUpdate:modelValue"?: ((value?: string | number | Date | undefined) => any) | undefined;
|
|
7
7
|
}>, {
|
|
8
|
-
type: "date" | "month" | "year";
|
|
9
8
|
placeholder: string;
|
|
10
9
|
clearable: boolean;
|
|
11
10
|
disabled: boolean;
|
|
12
11
|
readonly: boolean;
|
|
12
|
+
type: "date" | "month" | "year";
|
|
13
13
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
14
|
declare const _default: typeof __VLS_export;
|
|
15
15
|
//#endregion
|
|
@@ -5,11 +5,11 @@ declare const __VLS_export: import("vue").DefineComponent<DateRangePickerProps,
|
|
|
5
5
|
}, string, import("vue").PublicProps, Readonly<DateRangePickerProps> & Readonly<{
|
|
6
6
|
"onUpdate:modelValue"?: ((value?: [string, string] | undefined) => any) | undefined;
|
|
7
7
|
}>, {
|
|
8
|
-
type: "date" | "month" | "year";
|
|
9
8
|
placeholder: [string, string];
|
|
10
9
|
clearable: boolean;
|
|
11
10
|
disabled: boolean;
|
|
12
11
|
readonly: boolean;
|
|
12
|
+
type: "date" | "month" | "year";
|
|
13
13
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
14
|
declare const _default: typeof __VLS_export;
|
|
15
15
|
//#endregion
|
|
@@ -87,10 +87,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
87
87
|
const endRef = useModel(__props, "end");
|
|
88
88
|
let syncGuard = false;
|
|
89
89
|
function normalizeFromSplit(s, e) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (nextS !== void 0 && nextE !== void 0 && nextS > nextE) nextE = nextS;
|
|
93
|
-
return [nextS, nextE];
|
|
90
|
+
if (s !== void 0 && e !== void 0 && s > e) return [s, s];
|
|
91
|
+
return [s, e];
|
|
94
92
|
}
|
|
95
93
|
watch(model, (t) => {
|
|
96
94
|
if (syncGuard) return;
|
|
@@ -145,10 +143,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
145
143
|
return model.value?.[0];
|
|
146
144
|
},
|
|
147
145
|
set(v) {
|
|
148
|
-
|
|
149
|
-
let nextEnd = end;
|
|
150
|
-
if (v !== void 0 && end !== void 0 && v > end) nextEnd = v;
|
|
151
|
-
model.value = [v, nextEnd];
|
|
146
|
+
model.value = [v, (model.value ?? [void 0, void 0])[1]];
|
|
152
147
|
}
|
|
153
148
|
});
|
|
154
149
|
const endModel = computed({
|
|
@@ -156,10 +151,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
156
151
|
return model.value?.[1];
|
|
157
152
|
},
|
|
158
153
|
set(v) {
|
|
159
|
-
|
|
160
|
-
let nextStart = start;
|
|
161
|
-
if (v !== void 0 && start !== void 0 && v < start) nextStart = v;
|
|
162
|
-
model.value = [nextStart, v];
|
|
154
|
+
model.value = [(model.value ?? [void 0, void 0])[0], v];
|
|
163
155
|
}
|
|
164
156
|
});
|
|
165
157
|
function formatNumberPart(num) {
|
|
@@ -182,8 +174,23 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
182
174
|
const sep = props.separator ?? "~";
|
|
183
175
|
return `${p}${s === void 0 ? "—" : formatNumberPart(s)} ${sep} ${e === void 0 ? "—" : formatNumberPart(e)}${sfx}`;
|
|
184
176
|
});
|
|
185
|
-
function
|
|
186
|
-
|
|
177
|
+
function handleStartChange() {
|
|
178
|
+
const [start, end] = model.value ?? [void 0, void 0];
|
|
179
|
+
let next = [start, end];
|
|
180
|
+
if (start !== void 0 && end !== void 0 && start > end) {
|
|
181
|
+
next = [end, end];
|
|
182
|
+
model.value = next;
|
|
183
|
+
}
|
|
184
|
+
emit("change", next);
|
|
185
|
+
}
|
|
186
|
+
function handleEndChange() {
|
|
187
|
+
const [start, end] = model.value ?? [void 0, void 0];
|
|
188
|
+
let next = [start, end];
|
|
189
|
+
if (start !== void 0 && end !== void 0 && end < start) {
|
|
190
|
+
next = [start, start];
|
|
191
|
+
model.value = next;
|
|
192
|
+
}
|
|
193
|
+
emit("change", next);
|
|
187
194
|
}
|
|
188
195
|
return (_ctx, _cache) => {
|
|
189
196
|
return !unref(readonly) ? (openBlock(), createElementBlock("div", mergeProps({ key: 0 }, _ctx.$attrs, { class: className.value }), [
|
|
@@ -194,7 +201,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
194
201
|
disabled: unref(disabled),
|
|
195
202
|
readonly: unref(readonly),
|
|
196
203
|
size: unref(size)
|
|
197
|
-
}, numberInputBind.value, { onChange:
|
|
204
|
+
}, numberInputBind.value, { onChange: handleStartChange }), null, 16, [
|
|
198
205
|
"modelValue",
|
|
199
206
|
"placeholder",
|
|
200
207
|
"disabled",
|
|
@@ -209,7 +216,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
209
216
|
disabled: unref(disabled),
|
|
210
217
|
readonly: unref(readonly),
|
|
211
218
|
size: unref(size)
|
|
212
|
-
}, numberInputBind.value, { onChange:
|
|
219
|
+
}, numberInputBind.value, { onChange: handleEndChange }), null, 16, [
|
|
213
220
|
"modelValue",
|
|
214
221
|
"placeholder",
|
|
215
222
|
"disabled",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-range-input.js","names":["$attrs"],"sources":["../../../src/components/number-range-input/number-range-input.vue"],"sourcesContent":["<template>\n <div v-if=\"!readonly\" v-bind=\"$attrs\" :class=\"className\">\n <u-number-input\n v-model=\"startModel\"\n :placeholder=\"startPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"emitChange\"\n />\n <span :class=\"cls.e('separator')\">{{ separator }}</span>\n <u-number-input\n v-model=\"endModel\"\n :placeholder=\"endPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"emitChange\"\n />\n </div>\n\n <template v-else>\n {{ readonlyText || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { n, $n, o } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, FORM_EMPTY_CONTENT } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { computed, getCurrentInstance, nextTick, onMounted, watch } from 'vue'\n\nimport type { NumberRangeInputEmits, NumberRangeInputProps, NumberRangeTuple } from '../../types'\nimport { UNumberInput } from '../number-input'\n\ndefineOptions({ name: 'UNumberRangeInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<NumberRangeInputProps>(), {\n startPlaceholder: '请输入',\n endPlaceholder: '请输入',\n separator: '~',\n clearable: true,\n disabled: undefined,\n readonly: undefined\n})\n\nconst emit = defineEmits<NumberRangeInputEmits>()\n\nconst inst = getCurrentInstance()\n\nfunction splitBound(): boolean {\n const p = inst?.vnode.props\n if (!p) return false\n return 'start' in p || 'onUpdate:start' in p || 'end' in p || 'onUpdate:end' in p\n}\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst cls = bem('number-range-input')\n\nconst className = computed(() => {\n return [cls.b, cls.m(size.value)]\n})\n\nconst model = defineModel<NumberRangeTuple>({ default: () => [undefined, undefined] })\n\nconst startRef = defineModel<number | undefined>('start')\nconst endRef = defineModel<number | undefined>('end')\n\nlet syncGuard = false\n\nfunction normalizeFromSplit(s: number | undefined, e: number | undefined): NumberRangeTuple {\n let nextS = s\n let nextE = e\n if (nextS !== undefined && nextE !== undefined && nextS > nextE) nextE = nextS\n return [nextS, nextE]\n}\n\nwatch(\n model,\n (t) => {\n if (syncGuard) return\n syncGuard = true\n const tuple = t ?? [undefined, undefined]\n if (startRef.value !== tuple[0]) startRef.value = tuple[0]\n if (endRef.value !== tuple[1]) endRef.value = tuple[1]\n nextTick(() => {\n syncGuard = false\n })\n },\n { deep: true }\n)\n\nwatch(\n [startRef, endRef],\n () => {\n if (!splitBound() || syncGuard) return\n syncGuard = true\n const normalized = normalizeFromSplit(startRef.value, endRef.value)\n const cur = model.value ?? [undefined, undefined]\n if (cur[0] !== normalized[0] || cur[1] !== normalized[1]) {\n model.value = normalized\n }\n nextTick(() => {\n syncGuard = false\n })\n },\n { deep: true }\n)\n\nonMounted(() => {\n if (!splitBound()) return\n const cur = model.value ?? [undefined, undefined]\n const hasModel = cur[0] !== undefined || cur[1] !== undefined\n if (hasModel) return\n const normalized = normalizeFromSplit(startRef.value, endRef.value)\n if (cur[0] !== normalized[0] || cur[1] !== normalized[1]) {\n syncGuard = true\n model.value = normalized\n nextTick(() => {\n syncGuard = false\n })\n }\n})\n\nconst numberInputBind = computed(() => {\n return o(props).pick([\n 'clearable',\n 'prefix',\n 'suffix',\n 'step',\n 'min',\n 'max',\n 'currency',\n 'precision',\n 'minPrecision',\n 'maxPrecision',\n 'multiple'\n ])\n})\n\nconst startModel = computed({\n get(): number | undefined {\n return model.value?.[0]\n },\n set(v: number | undefined) {\n const cur = model.value ?? [undefined, undefined]\n const end = cur[1]\n let nextEnd = end\n if (v !== undefined && end !== undefined && v > end) nextEnd = v\n model.value = [v, nextEnd]\n }\n})\n\nconst endModel = computed({\n get(): number | undefined {\n return model.value?.[1]\n },\n set(v: number | undefined) {\n const cur = model.value ?? [undefined, undefined]\n const start = cur[0]\n let nextStart = start\n if (v !== undefined && start !== undefined && v < start) nextStart = v\n model.value = [nextStart, v]\n }\n})\n\nfunction formatNumberPart(num: number): string {\n const { currency, precision, minPrecision, maxPrecision, multiple } = props\n\n const displayValue = multiple ? $n.div(num, multiple) : num\n\n return currency\n ? n(displayValue).currency('CNY', { precision, minPrecision, maxPrecision })\n : n(displayValue).fixed(precision ?? { minPrecision, maxPrecision })\n}\n\nconst readonlyText = computed(() => {\n const [s, e] = model.value ?? [undefined, undefined]\n if (s === undefined && e === undefined) return ''\n const p = props.prefix ?? ''\n const sfx = props.suffix ?? ''\n const sep = props.separator ?? '~'\n const a = s === undefined ? '—' : formatNumberPart(s)\n const b = e === undefined ? '—' : formatNumberPart(e)\n return `${p}${a} ${sep} ${b}${sfx}`\n})\n\nfunction emitChange(): void {\n emit('change', model.value ?? [undefined, undefined])\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCA,MA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AjD,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,WAAA,CAAA,EAAA,GAAA,gBAAkB,QAAA,SAAS,GAAA,CAAA;IAC9C,YAQE,MAAA,WAAA,GARF,WAQE;iBAPS,SAAA;kEAAA,SAAQ,QAAA;KAChB,aAAa,QAAA;KACb,UAAU,MAAA,QAAA;KACV,UAAU,MAAA,QAAA;KACV,MAAM,MAAA,IAAA;OACC,gBAAA,OAAe,EACtB,UAAQ,WAAU,CAAA,GAAA,MAAA,IAAA;KAAA;KAAA;KAAA;KAAA;KAAA;IAAA,CAAA;2BAIvB,mBAEW,UAAA,EAAA,KAAA,EAAA,GAAA,CAAA,gBAAA,gBADN,aAAA,SAAgB,MAAA,kBAAA,CAAkB,GAAA,CAAA,CAAA,GAAA,EAAA"}
|
|
1
|
+
{"version":3,"file":"number-range-input.js","names":["$attrs"],"sources":["../../../src/components/number-range-input/number-range-input.vue"],"sourcesContent":["<template>\n <div v-if=\"!readonly\" v-bind=\"$attrs\" :class=\"className\">\n <u-number-input\n v-model=\"startModel\"\n :placeholder=\"startPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"handleStartChange\"\n />\n <span :class=\"cls.e('separator')\">{{ separator }}</span>\n <u-number-input\n v-model=\"endModel\"\n :placeholder=\"endPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"handleEndChange\"\n />\n </div>\n\n <template v-else>\n {{ readonlyText || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { n, $n, o } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, FORM_EMPTY_CONTENT } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { computed, getCurrentInstance, nextTick, onMounted, watch } from 'vue'\n\nimport type { NumberRangeInputEmits, NumberRangeInputProps, NumberRangeTuple } from '../../types'\nimport { UNumberInput } from '../number-input'\n\ndefineOptions({ name: 'UNumberRangeInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<NumberRangeInputProps>(), {\n startPlaceholder: '请输入',\n endPlaceholder: '请输入',\n separator: '~',\n clearable: true,\n disabled: undefined,\n readonly: undefined\n})\n\nconst emit = defineEmits<NumberRangeInputEmits>()\n\nconst inst = getCurrentInstance()\n\nfunction splitBound(): boolean {\n const p = inst?.vnode.props\n if (!p) return false\n return 'start' in p || 'onUpdate:start' in p || 'end' in p || 'onUpdate:end' in p\n}\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst cls = bem('number-range-input')\n\nconst className = computed(() => {\n return [cls.b, cls.m(size.value)]\n})\n\nconst model = defineModel<NumberRangeTuple>({ default: () => [undefined, undefined] })\n\nconst startRef = defineModel<number | undefined>('start')\nconst endRef = defineModel<number | undefined>('end')\n\nlet syncGuard = false\n\nfunction normalizeFromSplit(s: number | undefined, e: number | undefined): NumberRangeTuple {\n // 外部 split 写入无法区分哪一侧后改,统一将越界的 end 抬到 start\n if (s !== undefined && e !== undefined && s > e) return [s, s]\n return [s, e]\n}\n\nwatch(\n model,\n (t) => {\n if (syncGuard) return\n syncGuard = true\n const tuple = t ?? [undefined, undefined]\n if (startRef.value !== tuple[0]) startRef.value = tuple[0]\n if (endRef.value !== tuple[1]) endRef.value = tuple[1]\n nextTick(() => {\n syncGuard = false\n })\n },\n { deep: true }\n)\n\nwatch(\n [startRef, endRef],\n () => {\n if (!splitBound() || syncGuard) return\n syncGuard = true\n const normalized = normalizeFromSplit(startRef.value, endRef.value)\n const cur = model.value ?? [undefined, undefined]\n if (cur[0] !== normalized[0] || cur[1] !== normalized[1]) {\n model.value = normalized\n }\n nextTick(() => {\n syncGuard = false\n })\n },\n { deep: true }\n)\n\nonMounted(() => {\n if (!splitBound()) return\n const cur = model.value ?? [undefined, undefined]\n const hasModel = cur[0] !== undefined || cur[1] !== undefined\n if (hasModel) return\n const normalized = normalizeFromSplit(startRef.value, endRef.value)\n if (cur[0] !== normalized[0] || cur[1] !== normalized[1]) {\n syncGuard = true\n model.value = normalized\n nextTick(() => {\n syncGuard = false\n })\n }\n})\n\nconst numberInputBind = computed(() => {\n return o(props).pick([\n 'clearable',\n 'prefix',\n 'suffix',\n 'step',\n 'min',\n 'max',\n 'currency',\n 'precision',\n 'minPrecision',\n 'maxPrecision',\n 'multiple'\n ])\n})\n\nconst startModel = computed({\n get(): number | undefined {\n return model.value?.[0]\n },\n set(v: number | undefined) {\n // 输入过程只更新单侧,交叉约束放到 change(失焦)时处理\n const cur = model.value ?? [undefined, undefined]\n model.value = [v, cur[1]]\n }\n})\n\nconst endModel = computed({\n get(): number | undefined {\n return model.value?.[1]\n },\n set(v: number | undefined) {\n const cur = model.value ?? [undefined, undefined]\n model.value = [cur[0], v]\n }\n})\n\nfunction formatNumberPart(num: number): string {\n const { currency, precision, minPrecision, maxPrecision, multiple } = props\n\n const displayValue = multiple ? $n.div(num, multiple) : num\n\n return currency\n ? n(displayValue).currency('CNY', { precision, minPrecision, maxPrecision })\n : n(displayValue).fixed(precision ?? { minPrecision, maxPrecision })\n}\n\nconst readonlyText = computed(() => {\n const [s, e] = model.value ?? [undefined, undefined]\n if (s === undefined && e === undefined) return ''\n const p = props.prefix ?? ''\n const sfx = props.suffix ?? ''\n const sep = props.separator ?? '~'\n const a = s === undefined ? '—' : formatNumberPart(s)\n const b = e === undefined ? '—' : formatNumberPart(e)\n return `${p}${a} ${sep} ${b}${sfx}`\n})\n\nfunction handleStartChange(): void {\n const [start, end] = model.value ?? [undefined, undefined]\n // 失焦时只校正刚改的一侧:start > end 时把 start 压回 end\n let next: NumberRangeTuple = [start, end]\n if (start !== undefined && end !== undefined && start > end) {\n next = [end, end]\n model.value = next\n }\n emit('change', next)\n}\n\nfunction handleEndChange(): void {\n const [start, end] = model.value ?? [undefined, undefined]\n // 失焦时只校正刚改的一侧:end < start 时把 end 抬回 start\n let next: NumberRangeTuple = [start, end]\n if (start !== undefined && end !== undefined && end < start) {\n next = [start, start]\n model.value = next\n }\n emit('change', next)\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCA,MAAM,QAAQ;EASd,MAAM,OAAO;EAEb,MAAM,OAAO,mBAAmB;EAEhC,SAAS,aAAsB;GAC7B,MAAM,IAAI,MAAM,MAAM;GACtB,IAAI,CAAC,GAAG,OAAO;GACf,OAAO,WAAW,KAAK,oBAAoB,KAAK,SAAS,KAAK,kBAAkB;EAClF;EAEA,MAAM,EAAE,cAAc,kBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,CAAC,GAAG,KAAK,GAAG;GAClF,MAAM;GACN,UAAU;GACV,UAAU;EACZ,CAAC;EAED,MAAM,MAAM,IAAI,oBAAoB;EAEpC,MAAM,YAAY,eAAe;GAC/B,OAAO,CAAC,IAAI,GAAG,IAAI,EAAE,KAAK,KAAK,CAAC;EAClC,CAAC;EAED,MAAM,QAAQ,SAA6B,SAAA,YAA0C;EAErF,MAAM,WAAW,SAA+B,SAAC,OAAO;EACxD,MAAM,SAAS,SAA+B,SAAC,KAAK;EAEpD,IAAI,YAAY;EAEhB,SAAS,mBAAmB,GAAuB,GAAyC;GAE1F,IAAI,MAAM,KAAA,KAAa,MAAM,KAAA,KAAa,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;GAC7D,OAAO,CAAC,GAAG,CAAC;EACd;EAEA,MACE,QACC,MAAM;GACL,IAAI,WAAW;GACf,YAAY;GACZ,MAAM,QAAQ,KAAK,CAAC,KAAA,GAAW,KAAA,CAAS;GACxC,IAAI,SAAS,UAAU,MAAM,IAAI,SAAS,QAAQ,MAAM;GACxD,IAAI,OAAO,UAAU,MAAM,IAAI,OAAO,QAAQ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,OAAO,KAAK;IACpB,MAAM,QAAQ;GAChB;GACA,KAAK,UAAU,IAAI;EACrB;;WAlNc,MAAA,QAAA,KAAA,UAAA,GAAZ,mBAoBM,OApBN,WAoBM,EAAA,KAAA,EAAA,GApBwBA,KAAAA,QAAM,EAAG,OAAO,UAAA,MAAS,CAAA,GAAA;IACrD,YAQE,MAAA,WAAA,GARF,WAQE;iBAPS,WAAA;kEAAA,WAAU,QAAA;KAClB,aAAa,QAAA;KACb,UAAU,MAAA,QAAA;KACV,UAAU,MAAA,QAAA;KACV,MAAM,MAAA,IAAA;OACC,gBAAA,OAAe,EACtB,UAAQ,kBAAiB,CAAA,GAAA,MAAA,IAAA;KAAA;KAAA;KAAA;KAAA;KAAA;IAAA,CAAA;IAE5B,mBAAwD,QAAA,EAAjD,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,WAAA,CAAA,EAAA,GAAA,gBAAkB,QAAA,SAAS,GAAA,CAAA;IAC9C,YAQE,MAAA,WAAA,GARF,WAQE;iBAPS,SAAA;kEAAA,SAAQ,QAAA;KAChB,aAAa,QAAA;KACb,UAAU,MAAA,QAAA;KACV,UAAU,MAAA,QAAA;KACV,MAAM,MAAA,IAAA;OACC,gBAAA,OAAe,EACtB,UAAQ,gBAAe,CAAA,GAAA,MAAA,IAAA;KAAA;KAAA;KAAA;KAAA;KAAA;IAAA,CAAA;2BAI5B,mBAEW,UAAA,EAAA,KAAA,EAAA,GAAA,CAAA,gBAAA,gBADN,aAAA,SAAgB,MAAA,kBAAA,CAAkB,GAAA,CAAA,CAAA,GAAA,EAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/components/table/allocate-column-widths.ts
|
|
2
|
+
/**
|
|
3
|
+
* 按容器宽度分配叶子列宽。
|
|
4
|
+
*
|
|
5
|
+
* - `explicitWidth` 列:保持配置/拖拽锁定的宽度
|
|
6
|
+
* - `fixed` 且未显式设宽的列:保持 `minWidth`,不参与剩余宽度均分
|
|
7
|
+
* - 其余未显式设宽的列:均分容器剩余宽度
|
|
8
|
+
*/
|
|
9
|
+
function allocateLeafColumnWidths(leafColumns, containerWidth) {
|
|
10
|
+
if (!containerWidth || !leafColumns.length) return;
|
|
11
|
+
const growColumns = leafColumns.filter((column) => !column.explicitWidth && !column.fixed);
|
|
12
|
+
const fixedFlexColumns = leafColumns.filter((column) => !column.explicitWidth && column.fixed);
|
|
13
|
+
fixedFlexColumns.forEach((column) => {
|
|
14
|
+
column.data.width = void 0;
|
|
15
|
+
});
|
|
16
|
+
const explicitWidthTotal = leafColumns.filter((column) => column.explicitWidth).reduce((acc, cur) => acc + (cur.width ?? cur.minWidth), 0);
|
|
17
|
+
const growBaseTotal = growColumns.reduce((acc, cur) => acc + cur.minWidth, 0);
|
|
18
|
+
const fixedFlexBaseTotal = fixedFlexColumns.reduce((acc, cur) => acc + cur.minWidth, 0);
|
|
19
|
+
const totalBase = explicitWidthTotal + growBaseTotal + fixedFlexBaseTotal;
|
|
20
|
+
if (growColumns.length > 0 && totalBase < containerWidth) {
|
|
21
|
+
const allocatedWidth = (containerWidth - totalBase) / growColumns.length;
|
|
22
|
+
growColumns.forEach((column) => {
|
|
23
|
+
column.width = column.minWidth + allocatedWidth;
|
|
24
|
+
});
|
|
25
|
+
} else growColumns.forEach((column) => {
|
|
26
|
+
column.data.width = void 0;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { allocateLeafColumnWidths };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=allocate-column-widths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allocate-column-widths.js","names":[],"sources":["../../../src/components/table/allocate-column-widths.ts"],"sourcesContent":["import type { ColumnNode } from './node/col'\n\n/**\n * 按容器宽度分配叶子列宽。\n *\n * - `explicitWidth` 列:保持配置/拖拽锁定的宽度\n * - `fixed` 且未显式设宽的列:保持 `minWidth`,不参与剩余宽度均分\n * - 其余未显式设宽的列:均分容器剩余宽度\n */\nexport function allocateLeafColumnWidths(leafColumns: ColumnNode[], containerWidth: number): void {\n if (!containerWidth || !leafColumns.length) return\n\n const growColumns = leafColumns.filter((column) => !column.explicitWidth && !column.fixed)\n // fixed 且未显式设宽:清掉可能被旧算法撑大的残留 width,回落到 minWidth\n const fixedFlexColumns = leafColumns.filter((column) => !column.explicitWidth && column.fixed)\n\n fixedFlexColumns.forEach((column) => {\n column.data.width = undefined\n })\n\n const explicitWidthTotal = leafColumns\n .filter((column) => column.explicitWidth)\n .reduce((acc, cur) => acc + (cur.width ?? cur.minWidth!), 0)\n const growBaseTotal = growColumns.reduce((acc, cur) => acc + cur.minWidth!, 0)\n const fixedFlexBaseTotal = fixedFlexColumns.reduce((acc, cur) => acc + cur.minWidth!, 0)\n const totalBase = explicitWidthTotal + growBaseTotal + fixedFlexBaseTotal\n\n if (growColumns.length > 0 && totalBase < containerWidth) {\n const allocatedWidth = (containerWidth - totalBase) / growColumns.length\n growColumns.forEach((column) => {\n column.width = column.minWidth! + allocatedWidth\n })\n } else {\n growColumns.forEach((column) => {\n column.data.width = undefined\n })\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,yBAAyB,aAA2B,gBAA8B;CAChG,IAAI,CAAC,kBAAkB,CAAC,YAAY,QAAQ;CAE5C,MAAM,cAAc,YAAY,QAAQ,WAAW,CAAC,OAAO,iBAAiB,CAAC,OAAO,KAAK;CAEzF,MAAM,mBAAmB,YAAY,QAAQ,WAAW,CAAC,OAAO,iBAAiB,OAAO,KAAK;CAE7F,iBAAiB,SAAS,WAAW;EACnC,OAAO,KAAK,QAAQ,KAAA;CACtB,CAAC;CAED,MAAM,qBAAqB,YACxB,QAAQ,WAAW,OAAO,aAAa,CAAC,CACxC,QAAQ,KAAK,QAAQ,OAAO,IAAI,SAAS,IAAI,WAAY,CAAC;CAC7D,MAAM,gBAAgB,YAAY,QAAQ,KAAK,QAAQ,MAAM,IAAI,UAAW,CAAC;CAC7E,MAAM,qBAAqB,iBAAiB,QAAQ,KAAK,QAAQ,MAAM,IAAI,UAAW,CAAC;CACvF,MAAM,YAAY,qBAAqB,gBAAgB;CAEvD,IAAI,YAAY,SAAS,KAAK,YAAY,gBAAgB;EACxD,MAAM,kBAAkB,iBAAiB,aAAa,YAAY;EAClE,YAAY,SAAS,WAAW;GAC9B,OAAO,QAAQ,OAAO,WAAY;EACpC,CAAC;CACH,OACE,YAAY,SAAS,WAAW;EAC9B,OAAO,KAAK,QAAQ,KAAA;CACtB,CAAC;AAEL"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TableResizeKey } from "./di.js";
|
|
2
|
+
import { allocateLeafColumnWidths } from "./allocate-column-widths.js";
|
|
2
3
|
import { nextTick, provide, shallowRef, watchEffect } from "vue";
|
|
3
4
|
//#region src/components/table/use-col-resize.ts
|
|
4
5
|
function useColResize(options) {
|
|
@@ -13,16 +14,7 @@ function useColResize(options) {
|
|
|
13
14
|
function correctColumnStyle() {
|
|
14
15
|
const containerWidth = scrollRef.value?.containerRef?.clientWidth;
|
|
15
16
|
if (!containerWidth || !leafColumns.value.length) return;
|
|
16
|
-
|
|
17
|
-
const totalBase = leafColumns.value.filter((column) => column.explicitWidth).reduce((acc, cur) => acc + (cur.width ?? cur.minWidth), 0) + flexColumns.reduce((acc, cur) => acc + cur.minWidth, 0);
|
|
18
|
-
if (flexColumns.length > 0 && totalBase < containerWidth) {
|
|
19
|
-
const allocatedWidth = (containerWidth - totalBase) / flexColumns.length;
|
|
20
|
-
flexColumns.forEach((column) => {
|
|
21
|
-
column.width = column.minWidth + allocatedWidth;
|
|
22
|
-
});
|
|
23
|
-
} else flexColumns.forEach((column) => {
|
|
24
|
-
column.data.width = void 0;
|
|
25
|
-
});
|
|
17
|
+
allocateLeafColumnWidths(leafColumns.value, containerWidth);
|
|
26
18
|
const fixedLeft = leafColumns.value.filter((column) => column.fixed === "left");
|
|
27
19
|
const fixedRight = leafColumns.value.filter((column) => column.fixed === "right");
|
|
28
20
|
fixedLeft.reduce((acc, cur) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-col-resize.js","names":[],"sources":["../../../src/components/table/use-col-resize.ts"],"sourcesContent":["import { nextTick, provide, shallowRef, watchEffect, type ShallowRef } from 'vue'\n\nimport type { ScrollExposed } from '../../types'\nimport { TableResizeKey } from './di'\nimport type { ColumnNode } from './node/col'\n\ninterface Options {\n scrollRef: ShallowRef<ScrollExposed | undefined>\n leafColumns: ShallowRef<ColumnNode[]>\n}\n\ninterface UseColResizeReturned {\n resizeLineRef: ShallowRef<HTMLElement | undefined>\n colgroupRef: ShallowRef<HTMLElement | undefined>\n showResizeLine: ShallowRef<boolean>\n handleResizeMousedown: (e: MouseEvent, resizeColumn: ColumnNode) => void\n}\n\nexport function useColResize(options: Options): UseColResizeReturned {\n const { scrollRef, leafColumns } = options\n\n const showResizeLine = shallowRef(false)\n\n const resizeLineRef = shallowRef<HTMLElement>()\n const colgroupRef = shallowRef<HTMLElement>()\n const headerRef = shallowRef<HTMLElement>()\n\n /**\n * 修正列样式\n */\n function correctColumnStyle() {\n // 获取表格容器宽度\n const containerWidth = scrollRef.value?.containerRef?.clientWidth\n\n if (!containerWidth || !leafColumns.value.length) return\n\n
|
|
1
|
+
{"version":3,"file":"use-col-resize.js","names":[],"sources":["../../../src/components/table/use-col-resize.ts"],"sourcesContent":["import { nextTick, provide, shallowRef, watchEffect, type ShallowRef } from 'vue'\n\nimport type { ScrollExposed } from '../../types'\nimport { allocateLeafColumnWidths } from './allocate-column-widths'\nimport { TableResizeKey } from './di'\nimport type { ColumnNode } from './node/col'\n\ninterface Options {\n scrollRef: ShallowRef<ScrollExposed | undefined>\n leafColumns: ShallowRef<ColumnNode[]>\n}\n\ninterface UseColResizeReturned {\n resizeLineRef: ShallowRef<HTMLElement | undefined>\n colgroupRef: ShallowRef<HTMLElement | undefined>\n showResizeLine: ShallowRef<boolean>\n handleResizeMousedown: (e: MouseEvent, resizeColumn: ColumnNode) => void\n}\n\nexport function useColResize(options: Options): UseColResizeReturned {\n const { scrollRef, leafColumns } = options\n\n const showResizeLine = shallowRef(false)\n\n const resizeLineRef = shallowRef<HTMLElement>()\n const colgroupRef = shallowRef<HTMLElement>()\n const headerRef = shallowRef<HTMLElement>()\n\n /**\n * 修正列样式\n */\n function correctColumnStyle() {\n // 获取表格容器宽度\n const containerWidth = scrollRef.value?.containerRef?.clientWidth\n\n if (!containerWidth || !leafColumns.value.length) return\n\n allocateLeafColumnWidths(leafColumns.value, containerWidth)\n\n const fixedLeft = leafColumns.value.filter((column) => column.fixed === 'left')\n const fixedRight = leafColumns.value.filter((column) => column.fixed === 'right')\n\n fixedLeft.reduce((acc, cur) => {\n cur.style.left = acc\n return acc + (cur.width ?? cur.minWidth!)\n }, 0)\n\n fixedRight.reduceRight((acc, cur) => {\n cur.style.right = acc\n return acc + (cur.width ?? cur.minWidth!)\n }, 0)\n }\n\n watchEffect(correctColumnStyle)\n\n function updateResizeLine(transformX: number): void {\n if (!resizeLineRef.value) return\n resizeLineRef.value.style.transform = `translateX(${transformX}px)`\n }\n\n // 表格相对于页面左边缘的偏移量,\n // 此处作为缓存以减少频繁地调用 getBoundingClientRect 方法\n let containerLeft = 0\n let originX = 0\n let originWidth = 0\n let currentResizeColumn: ColumnNode | null = null\n\n function handleResizeMousedown(e: MouseEvent, resizeColumn: ColumnNode): void {\n const tableEl = scrollRef.value?.el\n if (!tableEl) return\n\n showResizeLine.value = true\n currentResizeColumn = resizeColumn\n originX = e.pageX\n originWidth = resizeColumn.width ?? 0\n\n const { left } = tableEl.getBoundingClientRect()\n containerLeft = left\n\n nextTick(() => {\n updateResizeLine(e.pageX - left)\n })\n\n document.addEventListener('mousemove', handleResizeMousemove)\n document.addEventListener('mouseup', handleResizeMouseup)\n }\n\n function handleResizeMousemove(e: MouseEvent): void {\n updateResizeLine(e.pageX - containerLeft)\n }\n\n function handleResizeMouseup(e: MouseEvent): void {\n currentResizeColumn!.width = Math.max(\n originWidth + e.pageX - originX,\n currentResizeColumn!.minWidth!\n )\n currentResizeColumn!.explicitWidth = true\n\n showResizeLine.value = false\n currentResizeColumn = null\n correctColumnStyle()\n\n document.removeEventListener('mouseup', handleResizeMouseup)\n document.removeEventListener('mousemove', handleResizeMousemove)\n }\n\n provide(TableResizeKey, { handleResizeMousedown, headerRef })\n\n return { resizeLineRef, colgroupRef, showResizeLine, handleResizeMousedown }\n}\n"],"mappings":";;;;AAmBA,SAAgB,aAAa,SAAwC;CACnE,MAAM,EAAE,WAAW,gBAAgB;CAEnC,MAAM,iBAAiB,WAAW,KAAK;CAEvC,MAAM,gBAAgB,WAAwB;CAC9C,MAAM,cAAc,WAAwB;CAC5C,MAAM,YAAY,WAAwB;;;;CAK1C,SAAS,qBAAqB;EAE5B,MAAM,iBAAiB,UAAU,OAAO,cAAc;EAEtD,IAAI,CAAC,kBAAkB,CAAC,YAAY,MAAM,QAAQ;EAElD,yBAAyB,YAAY,OAAO,cAAc;EAE1D,MAAM,YAAY,YAAY,MAAM,QAAQ,WAAW,OAAO,UAAU,MAAM;EAC9E,MAAM,aAAa,YAAY,MAAM,QAAQ,WAAW,OAAO,UAAU,OAAO;EAEhF,UAAU,QAAQ,KAAK,QAAQ;GAC7B,IAAI,MAAM,OAAO;GACjB,OAAO,OAAO,IAAI,SAAS,IAAI;EACjC,GAAG,CAAC;EAEJ,WAAW,aAAa,KAAK,QAAQ;GACnC,IAAI,MAAM,QAAQ;GAClB,OAAO,OAAO,IAAI,SAAS,IAAI;EACjC,GAAG,CAAC;CACN;CAEA,YAAY,kBAAkB;CAE9B,SAAS,iBAAiB,YAA0B;EAClD,IAAI,CAAC,cAAc,OAAO;EAC1B,cAAc,MAAM,MAAM,YAAY,cAAc,WAAW;CACjE;CAIA,IAAI,gBAAgB;CACpB,IAAI,UAAU;CACd,IAAI,cAAc;CAClB,IAAI,sBAAyC;CAE7C,SAAS,sBAAsB,GAAe,cAAgC;EAC5E,MAAM,UAAU,UAAU,OAAO;EACjC,IAAI,CAAC,SAAS;EAEd,eAAe,QAAQ;EACvB,sBAAsB;EACtB,UAAU,EAAE;EACZ,cAAc,aAAa,SAAS;EAEpC,MAAM,EAAE,SAAS,QAAQ,sBAAsB;EAC/C,gBAAgB;EAEhB,eAAe;GACb,iBAAiB,EAAE,QAAQ,IAAI;EACjC,CAAC;EAED,SAAS,iBAAiB,aAAa,qBAAqB;EAC5D,SAAS,iBAAiB,WAAW,mBAAmB;CAC1D;CAEA,SAAS,sBAAsB,GAAqB;EAClD,iBAAiB,EAAE,QAAQ,aAAa;CAC1C;CAEA,SAAS,oBAAoB,GAAqB;EAChD,oBAAqB,QAAQ,KAAK,IAChC,cAAc,EAAE,QAAQ,SACxB,oBAAqB,QACvB;EACA,oBAAqB,gBAAgB;EAErC,eAAe,QAAQ;EACvB,sBAAsB;EACtB,mBAAmB;EAEnB,SAAS,oBAAoB,WAAW,mBAAmB;EAC3D,SAAS,oBAAoB,aAAa,qBAAqB;CACjE;CAEA,QAAQ,gBAAgB;EAAE;EAAuB;CAAU,CAAC;CAE5D,OAAO;EAAE;EAAe;EAAa;EAAgB;CAAsB;AAC7E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltra/desktop",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.27",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"src"
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"@cat-kit/core": ">=1.1.8",
|
|
58
58
|
"@cat-kit/excel": ">=1.0.0",
|
|
59
59
|
"@cat-kit/fe": "^1.1.8",
|
|
60
|
-
"@veltra/compositions": "1.2.
|
|
61
|
-
"@veltra/directives": "1.2.
|
|
62
|
-
"@veltra/icons": "1.2.
|
|
63
|
-
"@veltra/styles": "1.2.
|
|
64
|
-
"@veltra/utils": "1.2.
|
|
60
|
+
"@veltra/compositions": "1.2.27",
|
|
61
|
+
"@veltra/directives": "1.2.27",
|
|
62
|
+
"@veltra/icons": "1.2.27",
|
|
63
|
+
"@veltra/styles": "1.2.27",
|
|
64
|
+
"@veltra/utils": "1.2.27",
|
|
65
65
|
"vue": ">=3.5.39"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
@@ -54,10 +54,16 @@
|
|
|
54
54
|
</span>
|
|
55
55
|
|
|
56
56
|
<div :class="cls.e('form-actions')">
|
|
57
|
-
<u-button text :loading="state.loading" @click="handleClose"> 取消 </u-button>
|
|
58
|
-
<u-button
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
<u-button size="small" text :loading="state.loading" @click="handleClose"> 取消 </u-button>
|
|
58
|
+
<u-button
|
|
59
|
+
v-if="showSaveBtn"
|
|
60
|
+
type="primary"
|
|
61
|
+
size="small"
|
|
62
|
+
title="保存"
|
|
63
|
+
:icon="Save"
|
|
64
|
+
:loading="state.loading"
|
|
65
|
+
@click="handleSave"
|
|
66
|
+
/>
|
|
61
67
|
</div>
|
|
62
68
|
</footer>
|
|
63
69
|
</aside>
|
|
@@ -65,7 +71,7 @@
|
|
|
65
71
|
|
|
66
72
|
<script lang="ts" setup>
|
|
67
73
|
import { o } from '@cat-kit/core'
|
|
68
|
-
import { Close } from '@veltra/icons/normal'
|
|
74
|
+
import { Close, Save } from '@veltra/icons/normal'
|
|
69
75
|
import { bem } from '@veltra/utils'
|
|
70
76
|
import { computed, inject, shallowRef, toRef } from 'vue'
|
|
71
77
|
|
|
@@ -22,6 +22,9 @@ export function useEditState(options: Options) {
|
|
|
22
22
|
const state = shallowReactive({ ...defaultState })
|
|
23
23
|
|
|
24
24
|
function resetState() {
|
|
25
|
+
// 销毁表单前先重置,避免下次 v-if 重挂载时 Form 拍到脏 model
|
|
26
|
+
formRef.value?.reset()
|
|
27
|
+
|
|
25
28
|
if (state.row) {
|
|
26
29
|
state.row.isCurrent = false
|
|
27
30
|
}
|
|
@@ -163,6 +163,11 @@ export function useHandlers(options: Options): EditReturned {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
insert(item)
|
|
166
|
+
|
|
167
|
+
// 推进插入点,便于连续新增;并重置表单到初始默认值
|
|
168
|
+
const next = last(state.indexPath) + 1
|
|
169
|
+
state.indexPath = [...state.indexPath.slice(0, -1), next]
|
|
170
|
+
formRef.value?.reset()
|
|
166
171
|
return
|
|
167
172
|
}
|
|
168
173
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { createApp, h, nextTick, ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
import type { NumberRangeTuple } from '../../../types'
|
|
5
|
+
import UNumberRangeInput from '../number-range-input.vue'
|
|
6
|
+
|
|
7
|
+
function mountNumberRangeInput(initial: NumberRangeTuple) {
|
|
8
|
+
const host = document.createElement('div')
|
|
9
|
+
document.body.appendChild(host)
|
|
10
|
+
|
|
11
|
+
const model = ref<NumberRangeTuple>([...initial])
|
|
12
|
+
const changes: NumberRangeTuple[] = []
|
|
13
|
+
|
|
14
|
+
const app = createApp({
|
|
15
|
+
render() {
|
|
16
|
+
return h(UNumberRangeInput, {
|
|
17
|
+
modelValue: model.value,
|
|
18
|
+
'onUpdate:modelValue': (value: NumberRangeTuple) => {
|
|
19
|
+
model.value = value
|
|
20
|
+
},
|
|
21
|
+
onChange: (value: NumberRangeTuple) => {
|
|
22
|
+
changes.push(value)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
app.mount(host)
|
|
29
|
+
|
|
30
|
+
const inputs = () => host.querySelectorAll<HTMLInputElement>('input')
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
host,
|
|
34
|
+
model,
|
|
35
|
+
changes,
|
|
36
|
+
inputs,
|
|
37
|
+
async setInputValue(index: 0 | 1, value: string) {
|
|
38
|
+
const input = inputs()[index]
|
|
39
|
+
if (!input) throw new Error(`input[${index}] not found`)
|
|
40
|
+
input.value = value
|
|
41
|
+
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
42
|
+
await nextTick()
|
|
43
|
+
},
|
|
44
|
+
async blurInput(index: 0 | 1) {
|
|
45
|
+
const input = inputs()[index]
|
|
46
|
+
if (!input) throw new Error(`input[${index}] not found`)
|
|
47
|
+
input.dispatchEvent(new Event('change', { bubbles: true }))
|
|
48
|
+
input.dispatchEvent(new FocusEvent('blur', { bubbles: true }))
|
|
49
|
+
await nextTick()
|
|
50
|
+
},
|
|
51
|
+
unmount() {
|
|
52
|
+
app.unmount()
|
|
53
|
+
host.remove()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('NumberRangeInput', () => {
|
|
59
|
+
it('does not rewrite the other side while typing an intermediate value', async () => {
|
|
60
|
+
const { model, setInputValue, unmount } = mountNumberRangeInput([50, 80])
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
// 结束框键入 2(意图输入 20),输入过程中 start 不应被改写
|
|
64
|
+
await setInputValue(1, '2')
|
|
65
|
+
expect(model.value).toEqual([50, 2])
|
|
66
|
+
} finally {
|
|
67
|
+
unmount()
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('clamps the edited end back to start on change when end < start', async () => {
|
|
72
|
+
const { model, changes, setInputValue, blurInput, unmount } = mountNumberRangeInput([80, 100])
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await setInputValue(1, '10')
|
|
76
|
+
expect(model.value).toEqual([80, 10])
|
|
77
|
+
|
|
78
|
+
await blurInput(1)
|
|
79
|
+
expect(model.value).toEqual([80, 80])
|
|
80
|
+
expect(changes.at(-1)).toEqual([80, 80])
|
|
81
|
+
} finally {
|
|
82
|
+
unmount()
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('clamps the edited start back to end on change when start > end', async () => {
|
|
87
|
+
const { model, changes, setInputValue, blurInput, unmount } = mountNumberRangeInput([50, 80])
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await setInputValue(0, '90')
|
|
91
|
+
expect(model.value).toEqual([90, 80])
|
|
92
|
+
|
|
93
|
+
await blurInput(0)
|
|
94
|
+
expect(model.value).toEqual([80, 80])
|
|
95
|
+
expect(changes.at(-1)).toEqual([80, 80])
|
|
96
|
+
} finally {
|
|
97
|
+
unmount()
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
:readonly="readonly"
|
|
8
8
|
:size="size"
|
|
9
9
|
v-bind="numberInputBind"
|
|
10
|
-
@change="
|
|
10
|
+
@change="handleStartChange"
|
|
11
11
|
/>
|
|
12
12
|
<span :class="cls.e('separator')">{{ separator }}</span>
|
|
13
13
|
<u-number-input
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
:readonly="readonly"
|
|
18
18
|
:size="size"
|
|
19
19
|
v-bind="numberInputBind"
|
|
20
|
-
@change="
|
|
20
|
+
@change="handleEndChange"
|
|
21
21
|
/>
|
|
22
22
|
</div>
|
|
23
23
|
|
|
@@ -79,10 +79,9 @@ const endRef = defineModel<number | undefined>('end')
|
|
|
79
79
|
let syncGuard = false
|
|
80
80
|
|
|
81
81
|
function normalizeFromSplit(s: number | undefined, e: number | undefined): NumberRangeTuple {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return [nextS, nextE]
|
|
82
|
+
// 外部 split 写入无法区分哪一侧后改,统一将越界的 end 抬到 start
|
|
83
|
+
if (s !== undefined && e !== undefined && s > e) return [s, s]
|
|
84
|
+
return [s, e]
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
watch(
|
|
@@ -153,11 +152,9 @@ const startModel = computed({
|
|
|
153
152
|
return model.value?.[0]
|
|
154
153
|
},
|
|
155
154
|
set(v: number | undefined) {
|
|
155
|
+
// 输入过程只更新单侧,交叉约束放到 change(失焦)时处理
|
|
156
156
|
const cur = model.value ?? [undefined, undefined]
|
|
157
|
-
|
|
158
|
-
let nextEnd = end
|
|
159
|
-
if (v !== undefined && end !== undefined && v > end) nextEnd = v
|
|
160
|
-
model.value = [v, nextEnd]
|
|
157
|
+
model.value = [v, cur[1]]
|
|
161
158
|
}
|
|
162
159
|
})
|
|
163
160
|
|
|
@@ -167,10 +164,7 @@ const endModel = computed({
|
|
|
167
164
|
},
|
|
168
165
|
set(v: number | undefined) {
|
|
169
166
|
const cur = model.value ?? [undefined, undefined]
|
|
170
|
-
|
|
171
|
-
let nextStart = start
|
|
172
|
-
if (v !== undefined && start !== undefined && v < start) nextStart = v
|
|
173
|
-
model.value = [nextStart, v]
|
|
167
|
+
model.value = [cur[0], v]
|
|
174
168
|
}
|
|
175
169
|
})
|
|
176
170
|
|
|
@@ -195,7 +189,25 @@ const readonlyText = computed(() => {
|
|
|
195
189
|
return `${p}${a} ${sep} ${b}${sfx}`
|
|
196
190
|
})
|
|
197
191
|
|
|
198
|
-
function
|
|
199
|
-
|
|
192
|
+
function handleStartChange(): void {
|
|
193
|
+
const [start, end] = model.value ?? [undefined, undefined]
|
|
194
|
+
// 失焦时只校正刚改的一侧:start > end 时把 start 压回 end
|
|
195
|
+
let next: NumberRangeTuple = [start, end]
|
|
196
|
+
if (start !== undefined && end !== undefined && start > end) {
|
|
197
|
+
next = [end, end]
|
|
198
|
+
model.value = next
|
|
199
|
+
}
|
|
200
|
+
emit('change', next)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function handleEndChange(): void {
|
|
204
|
+
const [start, end] = model.value ?? [undefined, undefined]
|
|
205
|
+
// 失焦时只校正刚改的一侧:end < start 时把 end 抬回 start
|
|
206
|
+
let next: NumberRangeTuple = [start, end]
|
|
207
|
+
if (start !== undefined && end !== undefined && end < start) {
|
|
208
|
+
next = [start, start]
|
|
209
|
+
model.value = next
|
|
210
|
+
}
|
|
211
|
+
emit('change', next)
|
|
200
212
|
}
|
|
201
213
|
</script>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import type { TableColumn } from '../../../types'
|
|
4
|
+
import { allocateLeafColumnWidths } from '../allocate-column-widths'
|
|
5
|
+
import { ColumnNode } from '../node/col'
|
|
6
|
+
|
|
7
|
+
function createLeaf(column: TableColumn): ColumnNode {
|
|
8
|
+
return new ColumnNode(column, 0, 0)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('allocateLeafColumnWidths', () => {
|
|
12
|
+
it('fixed right 操作列未设 width 时保持 minWidth,不吞剩余空间', () => {
|
|
13
|
+
const name = createLeaf({ key: 'name', name: '姓名', width: 200 })
|
|
14
|
+
const age = createLeaf({ key: 'age', name: '年龄', width: 200 })
|
|
15
|
+
const action = createLeaf({ key: 'action', name: '操作', fixed: 'right' })
|
|
16
|
+
// 模拟旧算法曾把操作列撑大
|
|
17
|
+
action.data.width = 800
|
|
18
|
+
|
|
19
|
+
allocateLeafColumnWidths([name, age, action], 1000)
|
|
20
|
+
|
|
21
|
+
expect(name.width).toBe(200)
|
|
22
|
+
expect(age.width).toBe(200)
|
|
23
|
+
expect(action.data.width).toBeUndefined()
|
|
24
|
+
expect(action.width).toBe(100)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('多个非 fixed 无 width 列均分剩余宽度', () => {
|
|
28
|
+
const a = createLeaf({ key: 'a', name: 'A', width: 200 })
|
|
29
|
+
const b = createLeaf({ key: 'b', name: 'B' })
|
|
30
|
+
const c = createLeaf({ key: 'c', name: 'C' })
|
|
31
|
+
|
|
32
|
+
// totalBase = 200 + 100 + 100 = 400,剩余 600,每列 +300
|
|
33
|
+
allocateLeafColumnWidths([a, b, c], 1000)
|
|
34
|
+
|
|
35
|
+
expect(a.width).toBe(200)
|
|
36
|
+
expect(b.width).toBe(400)
|
|
37
|
+
expect(c.width).toBe(400)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('fixed left 未设 width 时同样不参与均分', () => {
|
|
41
|
+
const name = createLeaf({ key: 'name', name: '姓名', fixed: 'left' })
|
|
42
|
+
const age = createLeaf({ key: 'age', name: '年龄' })
|
|
43
|
+
const score = createLeaf({ key: 'score', name: '分数' })
|
|
44
|
+
|
|
45
|
+
// totalBase = 100 + 100 + 100 = 300,剩余 700 只分给 age/score
|
|
46
|
+
allocateLeafColumnWidths([name, age, score], 1000)
|
|
47
|
+
|
|
48
|
+
expect(name.data.width).toBeUndefined()
|
|
49
|
+
expect(name.width).toBe(100)
|
|
50
|
+
expect(age.width).toBe(450)
|
|
51
|
+
expect(score.width).toBe(450)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('explicitWidth 列宽度不变', () => {
|
|
55
|
+
const locked = createLeaf({ key: 'locked', name: '锁定', width: 180 })
|
|
56
|
+
locked.explicitWidth = true
|
|
57
|
+
const grow = createLeaf({ key: 'grow', name: '弹性' })
|
|
58
|
+
|
|
59
|
+
allocateLeafColumnWidths([locked, grow], 500)
|
|
60
|
+
|
|
61
|
+
expect(locked.width).toBe(180)
|
|
62
|
+
// totalBase = 180 + 100 = 280,剩余 220 全给 grow
|
|
63
|
+
expect(grow.width).toBe(320)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('无剩余空间时 grow 列回落到 minWidth', () => {
|
|
67
|
+
const a = createLeaf({ key: 'a', name: 'A', width: 400 })
|
|
68
|
+
const b = createLeaf({ key: 'b', name: 'B' })
|
|
69
|
+
b.data.width = 300
|
|
70
|
+
|
|
71
|
+
allocateLeafColumnWidths([a, b], 450)
|
|
72
|
+
|
|
73
|
+
expect(a.width).toBe(400)
|
|
74
|
+
expect(b.data.width).toBeUndefined()
|
|
75
|
+
expect(b.width).toBe(100)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ColumnNode } from './node/col'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 按容器宽度分配叶子列宽。
|
|
5
|
+
*
|
|
6
|
+
* - `explicitWidth` 列:保持配置/拖拽锁定的宽度
|
|
7
|
+
* - `fixed` 且未显式设宽的列:保持 `minWidth`,不参与剩余宽度均分
|
|
8
|
+
* - 其余未显式设宽的列:均分容器剩余宽度
|
|
9
|
+
*/
|
|
10
|
+
export function allocateLeafColumnWidths(leafColumns: ColumnNode[], containerWidth: number): void {
|
|
11
|
+
if (!containerWidth || !leafColumns.length) return
|
|
12
|
+
|
|
13
|
+
const growColumns = leafColumns.filter((column) => !column.explicitWidth && !column.fixed)
|
|
14
|
+
// fixed 且未显式设宽:清掉可能被旧算法撑大的残留 width,回落到 minWidth
|
|
15
|
+
const fixedFlexColumns = leafColumns.filter((column) => !column.explicitWidth && column.fixed)
|
|
16
|
+
|
|
17
|
+
fixedFlexColumns.forEach((column) => {
|
|
18
|
+
column.data.width = undefined
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const explicitWidthTotal = leafColumns
|
|
22
|
+
.filter((column) => column.explicitWidth)
|
|
23
|
+
.reduce((acc, cur) => acc + (cur.width ?? cur.minWidth!), 0)
|
|
24
|
+
const growBaseTotal = growColumns.reduce((acc, cur) => acc + cur.minWidth!, 0)
|
|
25
|
+
const fixedFlexBaseTotal = fixedFlexColumns.reduce((acc, cur) => acc + cur.minWidth!, 0)
|
|
26
|
+
const totalBase = explicitWidthTotal + growBaseTotal + fixedFlexBaseTotal
|
|
27
|
+
|
|
28
|
+
if (growColumns.length > 0 && totalBase < containerWidth) {
|
|
29
|
+
const allocatedWidth = (containerWidth - totalBase) / growColumns.length
|
|
30
|
+
growColumns.forEach((column) => {
|
|
31
|
+
column.width = column.minWidth! + allocatedWidth
|
|
32
|
+
})
|
|
33
|
+
} else {
|
|
34
|
+
growColumns.forEach((column) => {
|
|
35
|
+
column.data.width = undefined
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { nextTick, provide, shallowRef, watchEffect, type ShallowRef } from 'vue'
|
|
2
2
|
|
|
3
3
|
import type { ScrollExposed } from '../../types'
|
|
4
|
+
import { allocateLeafColumnWidths } from './allocate-column-widths'
|
|
4
5
|
import { TableResizeKey } from './di'
|
|
5
6
|
import type { ColumnNode } from './node/col'
|
|
6
7
|
|
|
@@ -34,25 +35,7 @@ export function useColResize(options: Options): UseColResizeReturned {
|
|
|
34
35
|
|
|
35
36
|
if (!containerWidth || !leafColumns.value.length) return
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
const fixedWidthTotal = leafColumns.value
|
|
39
|
-
.filter((column) => column.explicitWidth)
|
|
40
|
-
.reduce((acc, cur) => acc + (cur.width ?? cur.minWidth!), 0)
|
|
41
|
-
const flexBaseTotal = flexColumns.reduce((acc, cur) => acc + cur.minWidth!, 0)
|
|
42
|
-
const totalBase = fixedWidthTotal + flexBaseTotal
|
|
43
|
-
|
|
44
|
-
// 仅未显式指定 width 的列参与剩余宽度均分;指定了 width 的列保持该宽度。
|
|
45
|
-
if (flexColumns.length > 0 && totalBase < containerWidth) {
|
|
46
|
-
const allocatedWidth = (containerWidth - totalBase) / flexColumns.length
|
|
47
|
-
|
|
48
|
-
flexColumns.forEach((column) => {
|
|
49
|
-
column.width = column.minWidth! + allocatedWidth
|
|
50
|
-
})
|
|
51
|
-
} else {
|
|
52
|
-
flexColumns.forEach((column) => {
|
|
53
|
-
column.data.width = undefined
|
|
54
|
-
})
|
|
55
|
-
}
|
|
38
|
+
allocateLeafColumnWidths(leafColumns.value, containerWidth)
|
|
56
39
|
|
|
57
40
|
const fixedLeft = leafColumns.value.filter((column) => column.fixed === 'left')
|
|
58
41
|
const fixedRight = leafColumns.value.filter((column) => column.fixed === 'right')
|