@veltra/desktop 1.7.13 → 1.7.16
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/batch-edit/batch-edit-form.js +9 -3
- package/dist/components/batch-edit/batch-edit-form.js.map +1 -1
- package/dist/components/batch-edit/batch-edit-list.js +2 -1
- package/dist/components/batch-edit/batch-edit-list.js.map +1 -1
- package/dist/components/batch-edit/batch-edit.js +57 -30
- package/dist/components/batch-edit/batch-edit.js.map +1 -1
- package/dist/components/batch-edit/style.d.ts +1 -0
- package/dist/components/batch-edit/style.js +1 -0
- package/dist/components/batch-edit/style2.css +14 -0
- package/dist/components/batch-edit/use-dialog-effect.js +20 -0
- package/dist/components/batch-edit/use-dialog-effect.js.map +1 -0
- package/dist/components/batch-edit/use-edit-state.js +22 -3
- package/dist/components/batch-edit/use-edit-state.js.map +1 -1
- package/dist/components/batch-edit/use-handlers.js +5 -0
- package/dist/components/batch-edit/use-handlers.js.map +1 -1
- package/dist/components/batch-edit/use-shortcut-key.js +5 -2
- package/dist/components/batch-edit/use-shortcut-key.js.map +1 -1
- package/dist/components/button/button.js +2 -2
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/file-viewer/file-viewer.js +21 -14
- package/dist/components/file-viewer/file-viewer.js.map +1 -1
- package/dist/components/file-viewer/helper.js +2 -0
- package/dist/components/file-viewer/helper.js.map +1 -1
- package/dist/components/file-viewer/previewers/ofd-previewer.js +196 -0
- package/dist/components/file-viewer/previewers/ofd-previewer.js.map +1 -0
- package/dist/components/file-viewer/style2.css +27 -0
- package/dist/components/form-item/style2.css +17 -2
- package/dist/components/table-editor/style2.css +48 -5
- package/dist/components/table-editor/table-editor.js +228 -63
- package/dist/components/table-editor/table-editor.js.map +1 -1
- package/dist/components/tip/style2.css +63 -0
- package/dist/components/tip/tip.js +6 -1
- package/dist/components/tip/tip.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/packages/ofd-core/dist/color.js +69 -0
- package/dist/packages/ofd-core/dist/color.js.map +1 -0
- package/dist/packages/ofd-core/dist/ctm.js +55 -0
- package/dist/packages/ofd-core/dist/ctm.js.map +1 -0
- package/dist/packages/ofd-core/dist/error.js +14 -0
- package/dist/packages/ofd-core/dist/error.js.map +1 -0
- package/dist/packages/ofd-core/dist/font.js +384 -0
- package/dist/packages/ofd-core/dist/font.js.map +1 -0
- package/dist/packages/ofd-core/dist/index.js +6 -0
- package/dist/packages/ofd-core/dist/number.js +13 -0
- package/dist/packages/ofd-core/dist/number.js.map +1 -0
- package/dist/packages/ofd-core/dist/page-objects.js +181 -0
- package/dist/packages/ofd-core/dist/page-objects.js.map +1 -0
- package/dist/packages/ofd-core/dist/parse.js +65 -0
- package/dist/packages/ofd-core/dist/parse.js.map +1 -0
- package/dist/packages/ofd-core/dist/render.js +361 -0
- package/dist/packages/ofd-core/dist/render.js.map +1 -0
- package/dist/packages/ofd-core/dist/xml.js +199 -0
- package/dist/packages/ofd-core/dist/xml.js.map +1 -0
- package/dist/packages/ofd-core/dist/zip.js +93 -0
- package/dist/packages/ofd-core/dist/zip.js.map +1 -0
- package/dist/style.d.ts +1 -1
- package/dist/style.js +1 -1
- package/dist/types/batch-edit.d.ts +6 -0
- package/dist/types/file-viewer.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/table-editor.d.ts +28 -7
- package/dist/types/tip.d.ts +5 -1
- package/package.json +8 -7
- package/src/components/batch-edit/__test__/batch-edit.test.ts +191 -4
- package/src/components/batch-edit/batch-edit-form.vue +17 -3
- package/src/components/batch-edit/batch-edit-list.vue +2 -1
- package/src/components/batch-edit/batch-edit.vue +22 -4
- package/src/components/batch-edit/style.scss +20 -0
- package/src/components/batch-edit/style.ts +1 -0
- package/src/components/batch-edit/use-dialog-effect.ts +9 -3
- package/src/components/batch-edit/use-edit-state.ts +32 -4
- package/src/components/batch-edit/use-handlers.ts +10 -0
- package/src/components/batch-edit/use-shortcut-key.ts +6 -2
- package/src/components/button/button.vue +3 -2
- package/src/components/file-viewer/__test__/helper.test.ts +13 -0
- package/src/components/file-viewer/file-viewer.vue +23 -16
- package/src/components/file-viewer/helper.ts +2 -0
- package/src/components/file-viewer/previewers/ofd-previewer.vue +216 -0
- package/src/components/file-viewer/style.scss +33 -0
- package/src/components/form-item/style.scss +11 -1
- package/src/components/table-editor/__test__/table-editor.test.ts +479 -0
- package/src/components/table-editor/style.scss +57 -5
- package/src/components/table-editor/table-editor.vue +286 -38
- package/src/components/tip/style.scss +15 -0
- package/src/components/tip/tip.vue +1 -1
- package/src/types/batch-edit.ts +6 -0
- package/src/types/file-viewer.ts +1 -1
- package/src/types/table-editor.ts +29 -7
- package/src/types/tip.ts +6 -1
|
@@ -5,6 +5,7 @@ import _sfc_main$3 from "../button/button.js";
|
|
|
5
5
|
import _sfc_main$4 from "../kbd/kbd.js";
|
|
6
6
|
import { BatchEditDIKey } from "./di.js";
|
|
7
7
|
import { FORM_ACTION_HEADER_MAP } from "./form-action-header.js";
|
|
8
|
+
import { useDialogEffect } from "./use-dialog-effect.js";
|
|
8
9
|
import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, guardReactiveProps, inject, normalizeClass, normalizeProps, openBlock, renderSlot, resolveDynamicComponent, shallowRef, toDisplayString, toRef, unref, vShow, withCtx, withDirectives } from "vue";
|
|
9
10
|
import { bem } from "@veltra/utils";
|
|
10
11
|
import { Close, Save } from "@veltra/icons/normal";
|
|
@@ -17,6 +18,11 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
17
18
|
const batchEditCtx = inject(BatchEditDIKey);
|
|
18
19
|
const { cls, props, state, handleClose, handleSave, staticFeatures, dynamicFeatures, syncing } = batchEditCtx;
|
|
19
20
|
const focused = toRef(batchEditCtx, "focused");
|
|
21
|
+
useDialogEffect({ closeForm: handleClose });
|
|
22
|
+
/** 快捷键提示是否可见:面板模式随聚焦显隐;弹框模式弹框打开期间快捷键始终可用 */
|
|
23
|
+
const shortcutActive = computed(() => {
|
|
24
|
+
return props.formMode === "dialog" ? state.formVisible : focused.value;
|
|
25
|
+
});
|
|
20
26
|
const formComponentRef = shallowRef();
|
|
21
27
|
__expose({
|
|
22
28
|
el: toRef(() => formComponentRef.value?.el),
|
|
@@ -47,9 +53,9 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
47
53
|
});
|
|
48
54
|
const headerInfo = computed(() => FORM_ACTION_HEADER_MAP[state.formActionType]);
|
|
49
55
|
return (_ctx, _cache) => {
|
|
50
|
-
return openBlock(), createElementBlock(Fragment, null, [createCommentVNode("
|
|
56
|
+
return openBlock(), createElementBlock(Fragment, null, [createCommentVNode(" 面板模式:表单常驻挂载(快照只在挂载时对传入的 model 拍一次),仅用 v-show 控制显隐;\n 弹框模式:表单随弹框挂载 / 卸载,model 初始快照由 use-edit-state 维护 "), !!unref(props).model ? withDirectives((openBlock(), createElementBlock("aside", {
|
|
51
57
|
key: 0,
|
|
52
|
-
class: normalizeClass(unref(cls).e("form"))
|
|
58
|
+
class: normalizeClass([unref(cls).e("form"), unref(bem).is("dialog", unref(props).formMode === "dialog")])
|
|
53
59
|
}, [
|
|
54
60
|
createElementVNode("header", { class: normalizeClass(unref(cls).e("form-header")) }, [
|
|
55
61
|
createElementVNode("span", { class: normalizeClass([unref(cls).e("form-icon"), unref(bem).is(unref(state).formActionType)]) }, [createVNode(unref(_sfc_main$1), null, {
|
|
@@ -106,7 +112,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
106
112
|
})]),
|
|
107
113
|
_: 3
|
|
108
114
|
}, 8, ["class"]),
|
|
109
|
-
createElementVNode("footer", { class: normalizeClass(unref(cls).e("form-footer")) }, [createElementVNode("span", { class: normalizeClass(unref(cls).e("form-hint")) }, [unref(props).readonly ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createTextVNode(" 只读模式 ")], 64)) : createCommentVNode("v-if", true), createElementVNode("span", { class: normalizeClass({ [unref(bem).is("concealed")]: !
|
|
115
|
+
createElementVNode("footer", { class: normalizeClass(unref(cls).e("form-footer")) }, [createElementVNode("span", { class: normalizeClass(unref(cls).e("form-hint")) }, [unref(props).readonly ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createTextVNode(" 只读模式 ")], 64)) : createCommentVNode("v-if", true), createElementVNode("span", { class: normalizeClass({ [unref(bem).is("concealed")]: !shortcutActive.value }) }, [
|
|
110
116
|
!(unref(state).formActionType === "update" && unref(props).quickEdit) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createVNode(unref(_sfc_main$4), null, {
|
|
111
117
|
default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("Ctrl + S", -1)])]),
|
|
112
118
|
_: 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit-form.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-form.vue"],"sourcesContent":["<template>\n <!--
|
|
1
|
+
{"version":3,"file":"batch-edit-form.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-form.vue"],"sourcesContent":["<template>\n <!-- 面板模式:表单常驻挂载(快照只在挂载时对传入的 model 拍一次),仅用 v-show 控制显隐;\n 弹框模式:表单随弹框挂载 / 卸载,model 初始快照由 use-edit-state 维护 -->\n <aside\n :class=\"[cls.e('form'), bem.is('dialog', props.formMode === 'dialog')]\"\n v-if=\"!!props.model\"\n v-show=\"state.formVisible\"\n >\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')\">\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:update=\"handleFieldUpdate\"\n >\n <slot\n v-bind=\"{\n row: state.row,\n parentRow: state.parentRow,\n formActionType: state.formActionType,\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')]: !shortcutActive }\">\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'\nimport { useDialogEffect } from './use-dialog-effect'\n\ndefineOptions({ name: 'UBatchEditForm' })\n\nconst batchEditCtx = inject(BatchEditDIKey)!\n\nconst { cls, props, state, handleClose, handleSave, staticFeatures, dynamicFeatures, syncing } =\n batchEditCtx\n\nconst focused = toRef(batchEditCtx, 'focused')\n\n// 弹框模式下,弹框自身关闭(遮罩点击 / 右上角关闭)时同步走 handleClose,不保存\nuseDialogEffect({ closeForm: handleClose })\n\n/** 快捷键提示是否可见:面板模式随聚焦显隐;弹框模式弹框打开期间快捷键始终可用 */\nconst shortcutActive = computed(() => {\n return props.formMode === 'dialog' ? state.formVisible : focused.value\n})\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 handleFieldUpdate(field: string, value: any) {\n // 编程方式重置/回显期间不写回行数据,避免默认值污染源数据\n if (syncing.value) return\n\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 (\n staticFeatures.value.has('createChild') || dynamicFeatures.value.createChild?.(state.parentRow)\n )\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</script>\n"],"mappings":";;;;;;;;;;;;;;;;;EAiGA,MAAM,eAAe,OAAO,cAAc;EAE1C,MAAM,EAAE,KAAK,OAAO,OAAO,aAAa,YAAY,gBAAgB,iBAAiB,YACnF;EAEF,MAAM,UAAU,MAAM,cAAc,SAAS;EAG7C,gBAAgB,EAAE,WAAW,YAAY,CAAC;;EAG1C,MAAM,iBAAiB,eAAe;GACpC,OAAO,MAAM,aAAa,WAAW,MA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AAA,mBAAA,QAAA,IAAA;KACA,YAAkB,MAAA,WAAA,GAAA,MAAA;MAAX,SAAA,cAAG,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CAAH,gBAAA,OAAG,EAAA,CAAA,EAAA,CAAA;;;KAAQ,OAAA,OAAA,OAAA,KAAA,gBAAA,QACpB,EAAA;IAGF,GAAA,CAAA,CAAA,GAAA,CAAA,GAAA,mBAWM,OAAA,EAXA,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,cAAA,CAAA,EAAA,GAChB,CAAA,YAAyF,MAAA,WAAA,GAAA;KAA/E,MAAK;KAAQ,MAAA;KAAM,SAAS,MAAA,KAAA,CAAK,CAAC;KAAU,SAAO,MAAA,WAAA;;KAAa,SAAA,cAAI,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CAAJ,gBAAA,QAAI,EAAA,CAAA,EAAA,CAAA;;IAEtE,GAAA,GAAA,CAAA,WAAA,SAAA,CAAA,GAAA,YAAA,SADR,UAAA,GAAA,YAQE,MAAA,WAAA,GAAA;;KANA,MAAK;KACL,MAAK;KACL,OAAM;KACL,MAAM,MAAA,IAAA;KACN,SAAS,MAAA,KAAA,CAAK,CAAC;KACf,SAAO,MAAA,UAAA;;;;;;GAlEN,GAAA,CAAA,IAAA,CAAA,CAAA,OAAA,MAAA,KAAA,CAAK,CAAC,WAAW,CAAA,CAAA,IAAA,mBAAA,QAAA,IAAA,CAAA,GAAA,IAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit-list.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-list.vue"],"sourcesContent":["<template>\n <u-table\n v-bind=\"tableProps\"\n :slots=\"slots\"\n :class=\"[cls.e('table')]\"\n :columns=\"columns\"\n highlight-current\n :current=\"state.row\"\n @update:current=\"handleUpdateCurrentRow\"\n @update:checked=\"emit('update:checked', $event)\"\n @update:selected=\"emit('update:selected', $event)\"\n >\n <template #column:__action__=\"{ row }\">\n <u-action-group :class=\"cls.e('row-actions')\" :max=\"5\" @click.stop circle>\n <u-action\n v-if=\"allowed('create', row)\"\n :icon=\"InsertToPrev\"\n title=\"在上方插入\"\n @run=\"handleInsertToPrev(row)\"\n />\n <u-action\n v-if=\"allowed('create', row)\"\n :icon=\"InsertToNext\"\n title=\"在下方插入\"\n @run=\"handleInsertToNext(row)\"\n />\n <u-action\n v-if=\"!!props.tree && allowed('createChild', row)\"\n :icon=\"AddChild\"\n title=\"添加子级\"\n @run=\"handleInsertChild(row)\"\n />\n <u-action\n v-if=\"canDelete(row)\"\n :icon=\"Delete\"\n type=\"danger\"\n title=\"删除\"\n @run=\"handleDelete(row)\"\n v-bind=\"props.actionsProps?.delete\"\n />\n </u-action-group>\n </template>\n\n <!-- 新增按钮 -->\n <template #append v-if=\"showCreateBtn\">\n <div :class=\"cls.e('add')\">\n <u-button\n :class=\"cls.e('add-btn')\"\n :icon=\"Plus\"\n :loading=\"state.loading\"\n type=\"primary\"\n plain\n @click.stop=\"handleCreate\"\n >\n 新增一行\n </u-button>\n </div>\n </template>\n </u-table>\n</template>\n\n<script setup lang=\"ts\">\nimport { o } from '@cat-kit/core'\nimport { AddChild, Delete, InsertToNext, InsertToPrev, Plus } from '@veltra/icons/normal'\nimport { computed, inject, type Slots } from 'vue'\n\nimport type { BatchEditFeature, TableRow } from '../../types'\nimport { UAction, UActionGroup } from '../action'\nimport { UButton } from '../button'\nimport { UTable } from '../table'\nimport { BatchEditDIKey } from './di'\n\ndefineOptions({ name: 'UBatchEditList' })\n\ndefineProps<{ slots: Slots }>()\n\nconst {\n cls,\n state,\n props,\n emit,\n staticFeatures,\n dynamicFeatures,\n handleCreate,\n handleDelete,\n handleInsertToNext,\n handleInsertToPrev,\n handleInsertChild\n} = inject(BatchEditDIKey)!\n\nconst tableProps = computed(() => {\n return o(props as Record<string, any>).omit([\n 'model',\n 'columns',\n 'cols',\n 'readonly',\n 'deleteMethod',\n 'saveMethod',\n 'features',\n 'mode',\n 'beforeCreate'\n ])\n})\n\nconst hasNot = (value: BatchEditFeature[]) => value.every((v) => !staticFeatures.value.has(v))\n\nconst allowed = (feature: BatchEditFeature, row?: TableRow) => {\n return staticFeatures.value.has(feature) || !!dynamicFeatures.value[feature]?.(row)\n}\n\nconst columns = computed(() => {\n if (props.readonly || hasNot(['create', 'delete', 'createChild', 'update'])) return props.columns\n\n return (props.columns ?? []).concat({\n name: '操作',\n key: '__action__',\n align: 'center',\n width: 180,\n fixed: 'right',\n resizable: false\n })\n})\n\nfunction handleUpdateCurrentRow(row?: TableRow) {\n if (allowed('update', row)) {\n state.row = row\n }\n}\n\nfunction canDelete(row: TableRow) {\n return !props.readonly && allowed('delete', row)\n}\n\nconst showCreateBtn = computed(() => {\n if (props.readonly) return false\n\n const hasFeature = staticFeatures.value.has('create') || dynamicFeatures.value.create?.()\n const createActionVisible = state.formActionType === 'create' && state.formVisible\n return hasFeature && !createActionVisible\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;EA4EA,MAAM,EACJ,KACA,OACA,OACA,MACA,gBACA,iBACA,cACA,cACA,oBACA,oBACA,sBACE,OAAO,cAAc;EAEzB,MAAM,aAAa,eAAe;GAChC,OAAO,EAAE,KAA4B,CAAC,CAAC,KAAK;IAC1C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACF,CAAC;EACH,CAAC;EAED,MAAM,UAAU,UAA8B,MAAM,OAAO,MAAM,CAAC,eAAe,MAAM,IAAI,CAAC,CAAC;EAE7F,MAAM,WAAW,SAA2B,QAAmB;GAC7D,OAAO,eAAe,MAAM,IAAI,OAAO,KAAK,CAAC,CAAC,gBAAgB,MAAM,QAAQ,GAAG,GAAG;EACpF;EAEA,MAAM,UAAU,eAAe;GAC7B,IAAI,MAAM,YAAY,OAAO;IAAC;IAAU;IAAU;IAAe;GAAQ,CAAC,GAAG,OAAO,MAAM;GAE1F,QAAQ,MAAM,WAAW,CAAC,EAAA,CAAG,OAAO;IAClC,MAAM;IACN,KAAK;IACL,OAAO;IACP,OAAO;IACP,OAAO;IACP,WAAW;GACb,CAAC;EACH,CAAC;EAED,SAAS,uBAAuB,KAAgB;GAC9C,IAAI,QAAQ,UAAU,GAAG,GACvB,MAAM,MAAM;EAEhB;EAEA,SAAS,UAAU,KAAe;GAChC,OAAO,CAAC,MAAM,YAAY,QAAQ,UAAU,GAAG;EACjD;EAEA,MAAM,gBAAgB,eAAe;GACnC,IAAI,MAAM,UAAU,OAAO;GAE3B,MAAM,aAAa,eAAe,MAAM,IAAI,QAAQ,KAAK,gBAAgB,MAAM,SAAS;GACxF,MAAM,sBAAsB,MAAM,mBAAmB,YAAY,MAAM;GACvE,OAAO,cAAc,CAAC;EACxB,CAAC;;
|
|
1
|
+
{"version":3,"file":"batch-edit-list.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit-list.vue"],"sourcesContent":["<template>\n <u-table\n v-bind=\"tableProps\"\n :slots=\"slots\"\n :class=\"[cls.e('table')]\"\n :columns=\"columns\"\n highlight-current\n :current=\"state.row\"\n @update:current=\"handleUpdateCurrentRow\"\n @update:checked=\"emit('update:checked', $event)\"\n @update:selected=\"emit('update:selected', $event)\"\n >\n <template #column:__action__=\"{ row }\">\n <u-action-group :class=\"cls.e('row-actions')\" :max=\"5\" @click.stop circle>\n <u-action\n v-if=\"allowed('create', row)\"\n :icon=\"InsertToPrev\"\n title=\"在上方插入\"\n @run=\"handleInsertToPrev(row)\"\n />\n <u-action\n v-if=\"allowed('create', row)\"\n :icon=\"InsertToNext\"\n title=\"在下方插入\"\n @run=\"handleInsertToNext(row)\"\n />\n <u-action\n v-if=\"!!props.tree && allowed('createChild', row)\"\n :icon=\"AddChild\"\n title=\"添加子级\"\n @run=\"handleInsertChild(row)\"\n />\n <u-action\n v-if=\"canDelete(row)\"\n :icon=\"Delete\"\n type=\"danger\"\n title=\"删除\"\n @run=\"handleDelete(row)\"\n v-bind=\"props.actionsProps?.delete\"\n />\n </u-action-group>\n </template>\n\n <!-- 新增按钮 -->\n <template #append v-if=\"showCreateBtn\">\n <div :class=\"cls.e('add')\">\n <u-button\n :class=\"cls.e('add-btn')\"\n :icon=\"Plus\"\n :loading=\"state.loading\"\n type=\"primary\"\n plain\n @click.stop=\"handleCreate\"\n >\n 新增一行\n </u-button>\n </div>\n </template>\n </u-table>\n</template>\n\n<script setup lang=\"ts\">\nimport { o } from '@cat-kit/core'\nimport { AddChild, Delete, InsertToNext, InsertToPrev, Plus } from '@veltra/icons/normal'\nimport { computed, inject, type Slots } from 'vue'\n\nimport type { BatchEditFeature, TableRow } from '../../types'\nimport { UAction, UActionGroup } from '../action'\nimport { UButton } from '../button'\nimport { UTable } from '../table'\nimport { BatchEditDIKey } from './di'\n\ndefineOptions({ name: 'UBatchEditList' })\n\ndefineProps<{ slots: Slots }>()\n\nconst {\n cls,\n state,\n props,\n emit,\n staticFeatures,\n dynamicFeatures,\n handleCreate,\n handleDelete,\n handleInsertToNext,\n handleInsertToPrev,\n handleInsertChild\n} = inject(BatchEditDIKey)!\n\nconst tableProps = computed(() => {\n return o(props as Record<string, any>).omit([\n 'model',\n 'columns',\n 'cols',\n 'readonly',\n 'deleteMethod',\n 'saveMethod',\n 'features',\n 'mode',\n 'beforeCreate',\n 'formMode'\n ])\n})\n\nconst hasNot = (value: BatchEditFeature[]) => value.every((v) => !staticFeatures.value.has(v))\n\nconst allowed = (feature: BatchEditFeature, row?: TableRow) => {\n return staticFeatures.value.has(feature) || !!dynamicFeatures.value[feature]?.(row)\n}\n\nconst columns = computed(() => {\n if (props.readonly || hasNot(['create', 'delete', 'createChild', 'update'])) return props.columns\n\n return (props.columns ?? []).concat({\n name: '操作',\n key: '__action__',\n align: 'center',\n width: 180,\n fixed: 'right',\n resizable: false\n })\n})\n\nfunction handleUpdateCurrentRow(row?: TableRow) {\n if (allowed('update', row)) {\n state.row = row\n }\n}\n\nfunction canDelete(row: TableRow) {\n return !props.readonly && allowed('delete', row)\n}\n\nconst showCreateBtn = computed(() => {\n if (props.readonly) return false\n\n const hasFeature = staticFeatures.value.has('create') || dynamicFeatures.value.create?.()\n const createActionVisible = state.formActionType === 'create' && state.formVisible\n return hasFeature && !createActionVisible\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;EA4EA,MAAM,EACJ,KACA,OACA,OACA,MACA,gBACA,iBACA,cACA,cACA,oBACA,oBACA,sBACE,OAAO,cAAc;EAEzB,MAAM,aAAa,eAAe;GAChC,OAAO,EAAE,KAA4B,CAAC,CAAC,KAAK;IAC1C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACF,CAAC;EACH,CAAC;EAED,MAAM,UAAU,UAA8B,MAAM,OAAO,MAAM,CAAC,eAAe,MAAM,IAAI,CAAC,CAAC;EAE7F,MAAM,WAAW,SAA2B,QAAmB;GAC7D,OAAO,eAAe,MAAM,IAAI,OAAO,KAAK,CAAC,CAAC,gBAAgB,MAAM,QAAQ,GAAG,GAAG;EACpF;EAEA,MAAM,UAAU,eAAe;GAC7B,IAAI,MAAM,YAAY,OAAO;IAAC;IAAU;IAAU;IAAe;GAAQ,CAAC,GAAG,OAAO,MAAM;GAE1F,QAAQ,MAAM,WAAW,CAAC,EAAA,CAAG,OAAO;IAClC,MAAM;IACN,KAAK;IACL,OAAO;IACP,OAAO;IACP,OAAO;IACP,WAAW;GACb,CAAC;EACH,CAAC;EAED,SAAS,uBAAuB,KAAgB;GAC9C,IAAI,QAAQ,UAAU,GAAG,GACvB,MAAM,MAAM;EAEhB;EAEA,SAAS,UAAU,KAAe;GAChC,OAAO,CAAC,MAAM,YAAY,QAAQ,UAAU,GAAG;EACjD;EAEA,MAAM,gBAAgB,eAAe;GACnC,IAAI,MAAM,UAAU,OAAO;GAE3B,MAAM,aAAa,eAAe,MAAM,IAAI,QAAQ,KAAK,gBAAgB,MAAM,SAAS;GACxF,MAAM,sBAAsB,MAAM,mBAAmB,YAAY,MAAM;GACvE,OAAO,cAAc,CAAC;EACxB,CAAC;;GA3IC,OAAA,UAAA,GAAA,YAyDU,MAAA,WAAA,GAzD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A,YAAA,CAAY,CAAC,GAAG;MACd,GAAA,MAAA,KAAA,CAAK,CAAC,cAAc,MAAM,GAAA,MAAA,IAAA,CAAA,QAAA,OAAA,CAAA,KAAA,mBAAA,QAAA,IAAA;;;;;GAMhB,GAAA,CAAA,cAAA,QAAA;IAAb,MAAA;IACT,IAAA,cAWM,CAXN,mBAWM,OAAA,EAXA,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,KAAA,CAAA,EAAA,GAChB,CAAA,YASW,MAAA,WAAA,GAAA;KARR,OAAK,eAAE,MAAA,GAAA,CAAG,CAAC,EAAC,SAAA,CAAA;KACZ,MAAM,MAAA,IAAA;KACN,SAAS,MAAA,KAAA,CAAK,CAAC;KAChB,MAAK;KACL,OAAA;KACC,SAAK,cAAO,MAAA,YAAA,GAAY,CAAA,MAAA,CAAA;;KAC1B,SAAA,cAED,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CAFC,gBAAA,UAED,EAAA,CAAA,EAAA,CAAA"}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import _sfc_main$1 from "../layout/layout.js";
|
|
2
|
+
import _sfc_main$2 from "../dialog/dialog.js";
|
|
2
3
|
import { BatchEditDIKey } from "./di.js";
|
|
3
|
-
import _sfc_main$
|
|
4
|
-
import _sfc_main$
|
|
4
|
+
import _sfc_main$3 from "./batch-edit-form.js";
|
|
5
|
+
import _sfc_main$4 from "./batch-edit-list.js";
|
|
5
6
|
import { useEditState } from "./use-edit-state.js";
|
|
6
7
|
import { useFeatures } from "./use-features.js";
|
|
7
8
|
import { useHandlers } from "./use-handlers.js";
|
|
8
9
|
import { useShortcutKey } from "./use-shortcut-key.js";
|
|
9
|
-
import { computed, createBlock, createCommentVNode, createVNode, defineComponent, guardReactiveProps, normalizeClass, normalizeProps, openBlock, provide, renderSlot, unref, useSlots, useTemplateRef, withCtx } from "vue";
|
|
10
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, guardReactiveProps, mergeProps, normalizeClass, normalizeProps, openBlock, provide, renderSlot, unref, useSlots, useTemplateRef, withCtx, withKeys, withModifiers } from "vue";
|
|
10
11
|
import { bem } from "@veltra/utils";
|
|
11
12
|
//#region src/components/batch-edit/batch-edit.vue
|
|
12
13
|
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
13
14
|
name: "UBatchEdit",
|
|
15
|
+
inheritAttrs: false,
|
|
14
16
|
__name: "batch-edit",
|
|
15
17
|
props: {
|
|
16
18
|
model: {},
|
|
17
19
|
title: {},
|
|
18
20
|
cols: { default: () => ["1fr", "420px"] },
|
|
19
21
|
readonly: { type: Boolean },
|
|
22
|
+
formMode: { default: "panel" },
|
|
20
23
|
quickEdit: { type: Boolean },
|
|
21
24
|
beforeCreate: {},
|
|
22
25
|
labelWidth: {},
|
|
@@ -84,7 +87,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
84
87
|
state
|
|
85
88
|
});
|
|
86
89
|
const cols = computed(() => {
|
|
87
|
-
return state.formVisible ? props.cols : void 0;
|
|
90
|
+
return props.formMode === "panel" && state.formVisible ? props.cols : void 0;
|
|
88
91
|
});
|
|
89
92
|
provide(BatchEditDIKey, {
|
|
90
93
|
cls,
|
|
@@ -98,34 +101,58 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
98
101
|
...handlers
|
|
99
102
|
});
|
|
100
103
|
return (_ctx, _cache) => {
|
|
101
|
-
return openBlock(),
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
105
|
+
createVNode(unref(_sfc_main$1), mergeProps({
|
|
106
|
+
class: unref(cls).b,
|
|
107
|
+
cols: cols.value,
|
|
108
|
+
rows: "minmax(0, 1fr) ",
|
|
109
|
+
gap: "8px",
|
|
110
|
+
resizable: "",
|
|
111
|
+
tabindex: "-1",
|
|
112
|
+
onFocusin: unref(handleFocusIn),
|
|
113
|
+
onFocusout: unref(handleFocusOut),
|
|
114
|
+
onKeydownCapture: unref(handleKeydown)
|
|
115
|
+
}, _ctx.$attrs), {
|
|
116
|
+
default: withCtx(() => [
|
|
117
|
+
createCommentVNode(" 编辑列表 "),
|
|
118
|
+
createVNode(_sfc_main$4, { slots }),
|
|
119
|
+
createCommentVNode(" 编辑表单 "),
|
|
120
|
+
props.formMode === "panel" ? (openBlock(), createBlock(_sfc_main$3, {
|
|
121
|
+
key: 0,
|
|
122
|
+
ref: "form"
|
|
123
|
+
}, {
|
|
124
|
+
default: withCtx((scoped) => [renderSlot(_ctx.$slots, "form", normalizeProps(guardReactiveProps(scoped)))]),
|
|
125
|
+
_: 3
|
|
126
|
+
}, 512)) : createCommentVNode("v-if", true)
|
|
127
|
+
]),
|
|
128
|
+
_: 3
|
|
129
|
+
}, 16, [
|
|
130
|
+
"class",
|
|
131
|
+
"cols",
|
|
132
|
+
"onFocusin",
|
|
133
|
+
"onFocusout",
|
|
134
|
+
"onKeydownCapture"
|
|
135
|
+
]),
|
|
136
|
+
createCommentVNode(" 弹框模式:表单经 UDialog 呈现(teleport 到 body),快捷键监听落在弹框上,Esc 与弹框自带的 keyup.esc 去重 "),
|
|
137
|
+
props.formMode === "dialog" ? (openBlock(), createBlock(unref(_sfc_main$2), {
|
|
138
|
+
key: 0,
|
|
139
|
+
modelValue: unref(state).formVisible,
|
|
140
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(state).formVisible = $event),
|
|
141
|
+
class: normalizeClass(unref(cls).e("form-dialog")),
|
|
142
|
+
onKeydownCapture: unref(handleKeydown),
|
|
143
|
+
onKeyup: _cache[1] || (_cache[1] = withKeys(withModifiers(() => {}, ["stop"]), ["esc"]))
|
|
144
|
+
}, {
|
|
145
|
+
default: withCtx(() => [createVNode(_sfc_main$3, { ref: "form" }, {
|
|
117
146
|
default: withCtx((scoped) => [renderSlot(_ctx.$slots, "form", normalizeProps(guardReactiveProps(scoped)))]),
|
|
118
147
|
_: 3
|
|
119
|
-
}, 512)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
|
|
127
|
-
"onKeydownCapture"
|
|
128
|
-
]);
|
|
148
|
+
}, 512)]),
|
|
149
|
+
_: 3
|
|
150
|
+
}, 8, [
|
|
151
|
+
"modelValue",
|
|
152
|
+
"class",
|
|
153
|
+
"onKeydownCapture"
|
|
154
|
+
])) : createCommentVNode("v-if", true)
|
|
155
|
+
], 64);
|
|
129
156
|
};
|
|
130
157
|
}
|
|
131
158
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-edit.js","names":[],"sources":["../../../src/components/batch-edit/batch-edit.vue"],"sourcesContent":["<template>\n <u-layout\n :class=\"cls.b\"\n :cols=\"cols\"\n rows=\"minmax(0, 1fr) \"\n gap=\"8px\"\n resizable\n tabindex=\"-1\"\n @focusin=\"handleFocusIn\"\n @focusout=\"handleFocusOut\"\n @keydown.capture=\"handleKeydown\"\n >\n <!-- 编辑列表 -->\n <BatchEditList :slots=\"slots\" />\n\n <!-- 编辑表单 -->\n <BatchEditForm ref=\"form\" v-slot=\"scoped\">\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-layout>\n</template>\n\n<script lang=\"ts\" setup>\nimport { bem } from '@veltra/utils'\nimport { computed, provide, useTemplateRef } from 'vue'\n\nimport type { BatchEditEmits, BatchEditProps, BatchEditSlots, FormExposed } from '../../types'\nimport { ULayout } from '../layout'\nimport BatchEditForm from './batch-edit-form.vue'\nimport BatchEditList from './batch-edit-list.vue'\nimport { BatchEditDIKey } from './di'\nimport { useEditState } from './use-edit-state'\nimport { useFeatures } from './use-features'\nimport { useHandlers } from './use-handlers'\nimport { useShortcutKey } from './use-shortcut-key'\n\ndefineOptions({ name: 'UBatchEdit' })\n\nconst props = withDefaults(defineProps<BatchEditProps>(), {
|
|
1
|
+
{"version":3,"file":"batch-edit.js","names":["$attrs"],"sources":["../../../src/components/batch-edit/batch-edit.vue"],"sourcesContent":["<template>\n <u-layout\n :class=\"cls.b\"\n :cols=\"cols\"\n rows=\"minmax(0, 1fr) \"\n gap=\"8px\"\n resizable\n tabindex=\"-1\"\n @focusin=\"handleFocusIn\"\n @focusout=\"handleFocusOut\"\n @keydown.capture=\"handleKeydown\"\n v-bind=\"$attrs\"\n >\n <!-- 编辑列表 -->\n <BatchEditList :slots=\"slots\" />\n\n <!-- 编辑表单 -->\n <BatchEditForm v-if=\"props.formMode === 'panel'\" ref=\"form\" v-slot=\"scoped\">\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-layout>\n\n <!-- 弹框模式:表单经 UDialog 呈现(teleport 到 body),快捷键监听落在弹框上,Esc 与弹框自带的 keyup.esc 去重 -->\n <u-dialog\n v-if=\"props.formMode === 'dialog'\"\n v-model=\"state.formVisible\"\n :class=\"cls.e('form-dialog')\"\n @keydown.capture=\"handleKeydown\"\n @keyup.esc.stop\n >\n <BatchEditForm ref=\"form\" v-slot=\"scoped\">\n <slot name=\"form\" v-bind=\"scoped\" />\n </BatchEditForm>\n </u-dialog>\n</template>\n\n<script lang=\"ts\" setup>\nimport { bem } from '@veltra/utils'\nimport { computed, provide, useTemplateRef } from 'vue'\n\nimport type { BatchEditEmits, BatchEditProps, BatchEditSlots, FormExposed } from '../../types'\nimport { UDialog } from '../dialog'\nimport { ULayout } from '../layout'\nimport BatchEditForm from './batch-edit-form.vue'\nimport BatchEditList from './batch-edit-list.vue'\nimport { BatchEditDIKey } from './di'\nimport { useEditState } from './use-edit-state'\nimport { useFeatures } from './use-features'\nimport { useHandlers } from './use-handlers'\nimport { useShortcutKey } from './use-shortcut-key'\n\ndefineOptions({ name: 'UBatchEdit', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<BatchEditProps>(), {\n cols: () => ['1fr', '420px'],\n formMode: 'panel'\n})\n\nconst emit = defineEmits<BatchEditEmits>()\n\nconst slots = defineSlots<BatchEditSlots>()\n\nconst cls = bem('batch-edit')\n\nconst formRef = useTemplateRef<FormExposed>('form')\n\nconst { state, resetState, syncing } = useEditState({ props, formRef })\n\nconst { staticFeatures, dynamicFeatures } = useFeatures({ props })\n\nconst handlers = useHandlers({ props, emit, state, resetState, formRef })\n\n// 快捷键处理\nconst { handleFocusIn, handleFocusOut, handleKeydown, focused } = useShortcutKey({\n props,\n onSave: handlers.handleSave,\n onClose: handlers.handleClose,\n state\n})\n\nconst cols = computed(() => {\n return props.formMode === 'panel' && state.formVisible ? props.cols : undefined\n})\n\nprovide(BatchEditDIKey, {\n cls,\n props,\n emit,\n state,\n staticFeatures,\n dynamicFeatures,\n focused,\n syncing,\n ...handlers\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDA,MAAM,QAAQ;EAKd,MAAM,OAAO;EAEb,MAAM,QAAQ,SAAA;EAEd,MAAM,MAAM,IAAI,YAAY;EAE5B,MAAM,UAAU,eAA4B,MAAM;EAElD,MAAM,EAAE,OAAO,YAAY,YAAY,aAAa;GAAE;GAAO;EAAQ,CAAC;EAEtE,MAAM,EAAE,gBAAgB,oBAAoB,YAAY,EAAE,MAAM,CAAC;EAEjE,MAAM,WAAW,YAAY;GAAE;GAAO;GAAM;GAAO;GAAY;EAAQ,CAAC;EAGxE,MAAM,EAAE,eAAe,gBAAgB,eAAe,YAAY,eAAe;GAC/E;GACA,QAAQ,SAAS;GACjB,SAAS,SAAS;GAClB;EACF,CAAC;EAED,MAAM,OAAO,eAAe;GAC1B,OAAO,MAAM,aAAa,WAAW,MAAM,cAAc,MAAM,OAAO,KAAA;EACxE,CAAC;EAED,QAAQ,gBAAgB;GACtB;GACA;GACA;GACA;GACA;GAC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height: min(600px, 80vh);
|
|
58
|
+
background-color: transparent;
|
|
59
|
+
border-radius: 0;
|
|
60
|
+
box-shadow: none;
|
|
61
|
+
}
|
|
56
62
|
.u-batch-edit__form-header {
|
|
57
63
|
display: flex;
|
|
58
64
|
align-items: center;
|
|
@@ -152,3 +158,11 @@
|
|
|
152
158
|
gap: 8px;
|
|
153
159
|
flex-shrink: 0;
|
|
154
160
|
}
|
|
161
|
+
|
|
162
|
+
.u-batch-edit__form-dialog {
|
|
163
|
+
width: 560px;
|
|
164
|
+
max-width: calc(100vw - 32px);
|
|
165
|
+
}
|
|
166
|
+
.u-batch-edit__form-dialog .u-dialog__header {
|
|
167
|
+
display: none;
|
|
168
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DialogDIKey } from "../dialog/di.js";
|
|
2
|
+
import { inject, watch } from "vue";
|
|
3
|
+
//#region src/components/batch-edit/use-dialog-effect.ts
|
|
4
|
+
/**
|
|
5
|
+
* 在表单上的副作用。
|
|
6
|
+
* 包括:关闭表单
|
|
7
|
+
*
|
|
8
|
+
* sync 触发:弹框关闭会随即卸载表单组件,默认 pre 时序下 watcher 可能随组件卸载被丢弃
|
|
9
|
+
*/
|
|
10
|
+
function useDialogEffect(options) {
|
|
11
|
+
const dialogCtx = inject(DialogDIKey, void 0);
|
|
12
|
+
if (!dialogCtx) return;
|
|
13
|
+
watch(dialogCtx.visible, (visible) => {
|
|
14
|
+
!visible && options.closeForm?.();
|
|
15
|
+
}, { flush: "sync" });
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useDialogEffect };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=use-dialog-effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-dialog-effect.js","names":[],"sources":["../../../src/components/batch-edit/use-dialog-effect.ts"],"sourcesContent":["import { inject, watch } from 'vue'\n\nimport { DialogDIKey } from '../dialog/di'\n\ninterface Options {\n /** 关闭表单 */\n closeForm: () => void\n}\n\n/**\n * 在表单上的副作用。\n * 包括:关闭表单\n *\n * sync 触发:弹框关闭会随即卸载表单组件,默认 pre 时序下 watcher 可能随组件卸载被丢弃\n */\nexport function useDialogEffect(options: Options) {\n const dialogCtx = inject(DialogDIKey, undefined)\n if (!dialogCtx) return\n\n watch(\n dialogCtx.visible,\n (visible) => {\n !visible && options.closeForm?.()\n },\n { flush: 'sync' }\n )\n}\n"],"mappings":";;;;;;;;;AAeA,SAAgB,gBAAgB,SAAkB;CAChD,MAAM,YAAY,OAAO,aAAa,KAAA,CAAS;CAC/C,IAAI,CAAC,WAAW;CAEhB,MACE,UAAU,UACT,YAAY;EACX,CAAC,WAAW,QAAQ,YAAY;CAClC,GACA,EAAE,OAAO,OAAO,CAClB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nextTick, shallowReactive, shallowRef, watch } from "vue";
|
|
2
|
-
import { o } from "@cat-kit/core";
|
|
2
|
+
import { copy, o } from "@cat-kit/core";
|
|
3
3
|
//#region src/components/batch-edit/use-edit-state.ts
|
|
4
4
|
function useEditState(options) {
|
|
5
5
|
const { props, formRef } = options;
|
|
@@ -13,8 +13,27 @@ function useEditState(options) {
|
|
|
13
13
|
const state = shallowReactive({ ...defaultState });
|
|
14
14
|
/** 是否正在以编程方式重置/回显表单,此期间禁止 quick-edit 回写行数据 */
|
|
15
15
|
const syncing = shallowRef(false);
|
|
16
|
+
/**
|
|
17
|
+
* model 初始快照。
|
|
18
|
+
* 面板模式由常驻挂载的 UForm 自行维护快照;dialog 模式表单随弹框卸载,
|
|
19
|
+
* UForm 快照会在每次打开时按已回显的 model 重拍,故这里单独保留一份供恢复
|
|
20
|
+
*/
|
|
21
|
+
const initialModel = shallowRef();
|
|
22
|
+
watch(() => props.model, (model) => {
|
|
23
|
+
initialModel.value = props.formMode === "dialog" && model ? copy(model) : void 0;
|
|
24
|
+
}, { immediate: true });
|
|
25
|
+
/** 重置表单数据到 model 初始快照 */
|
|
26
|
+
function resetModel() {
|
|
27
|
+
if (props.formMode !== "dialog") {
|
|
28
|
+
formRef.value?.reset();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
formRef.value?.clearValidate();
|
|
32
|
+
if (!props.model || !initialModel.value) return;
|
|
33
|
+
for (const key of Object.keys(initialModel.value)) o(props.model).set(key, copy(initialModel.value[key]));
|
|
34
|
+
}
|
|
16
35
|
function resetState() {
|
|
17
|
-
|
|
36
|
+
resetModel();
|
|
18
37
|
if (state.row) state.row.isCurrent = false;
|
|
19
38
|
Object.keys(state).forEach((key) => {
|
|
20
39
|
delete state[key];
|
|
@@ -23,7 +42,7 @@ function useEditState(options) {
|
|
|
23
42
|
}
|
|
24
43
|
watch(() => state.row, (row) => {
|
|
25
44
|
syncing.value = true;
|
|
26
|
-
|
|
45
|
+
resetModel();
|
|
27
46
|
if (row) {
|
|
28
47
|
if (props.model) o(props.model).deepExtend(row.data);
|
|
29
48
|
state.formActionType = props.readonly ? "view" : "update";
|
|
@@ -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, shallowRef, 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 /** 是否正在以编程方式重置/回显表单,此期间禁止 quick-edit 回写行数据 */\n const syncing = shallowRef(false)\n\n
|
|
1
|
+
{"version":3,"file":"use-edit-state.js","names":[],"sources":["../../../src/components/batch-edit/use-edit-state.ts"],"sourcesContent":["import { copy, o } from '@cat-kit/core'\nimport { nextTick, shallowReactive, shallowRef, 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 /** 是否正在以编程方式重置/回显表单,此期间禁止 quick-edit 回写行数据 */\n const syncing = shallowRef(false)\n\n /**\n * model 初始快照。\n * 面板模式由常驻挂载的 UForm 自行维护快照;dialog 模式表单随弹框卸载,\n * UForm 快照会在每次打开时按已回显的 model 重拍,故这里单独保留一份供恢复\n */\n const initialModel = shallowRef<Record<string, any>>()\n\n watch(\n () => props.model,\n (model) => {\n initialModel.value = props.formMode === 'dialog' && model ? copy(model) : undefined\n },\n { immediate: true }\n )\n\n /** 重置表单数据到 model 初始快照 */\n function resetModel() {\n if (props.formMode !== 'dialog') {\n formRef.value?.reset()\n return\n }\n\n formRef.value?.clearValidate()\n if (!props.model || !initialModel.value) return\n for (const key of Object.keys(initialModel.value)) {\n o(props.model).set(key, copy(initialModel.value[key]))\n }\n }\n\n function resetState() {\n resetModel()\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 syncing.value = true\n\n // 先重置回 model 初始快照,再同步回显行数据。\n // 同一 tick 内的连续写入会被表单字段 watcher 合并,\n // 重置产生的默认值不会触发 field:update 回写行数据\n resetModel()\n\n if (row) {\n if (props.model) {\n o(props.model).deepExtend(row.data)\n }\n state.formActionType = props.readonly ? 'view' : 'update'\n state.formVisible = true\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n } else {\n resetState()\n }\n\n nextTick(() => {\n syncing.value = false\n })\n }\n )\n\n return { state, resetState, syncing }\n}\n"],"m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AEA,OAAO;EAAE;EAAO;EAAY;CAAQ;AACtC"}
|
|
@@ -109,6 +109,10 @@ function useHandlers(options) {
|
|
|
109
109
|
if (result) item = result;
|
|
110
110
|
}
|
|
111
111
|
insert(item);
|
|
112
|
+
if (props.formMode === "dialog") {
|
|
113
|
+
resetState();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
112
116
|
const next = last(state.indexPath) + 1;
|
|
113
117
|
state.indexPath = [...state.indexPath.slice(0, -1), next];
|
|
114
118
|
formRef.value?.reset();
|
|
@@ -122,6 +126,7 @@ function useHandlers(options) {
|
|
|
122
126
|
row && Object.keys(item).forEach((key) => {
|
|
123
127
|
o(row.data).set(key, o(item).get(key));
|
|
124
128
|
});
|
|
129
|
+
if (props.formMode === "dialog") resetState();
|
|
125
130
|
});
|
|
126
131
|
const handleDelete = runWithLoading(async (row) => {
|
|
127
132
|
const { deleteMethod } = props;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-handlers.js","names":[],"sources":["../../../src/components/batch-edit/use-handlers.ts"],"sourcesContent":["import { copy, 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 copy(props.model ?? {})\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 emit('create')\n })\n }\n\n function handleInsertToPrev(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n emit('create-prev', row)\n }\n\n function handleInsertToNext(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes.slice(0, -1), row.index + 1]\n emit('create-next', row)\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 emit('create-child', row)\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 const result = await deleteMethod([row.data])\n if (result === false) {\n return\n }\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,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IAAI;GACtD,IAAI,YAAY;IACd,MAAM,SAAS,MAAM,WAAW,MAAM,MAAM,gBAAgB,MAAM,WAAW,IAAI;IACjF,IAAI,QACF,OAAO;GAEX;GACA,OAAO,IAAI;GAGX,MAAM,OAAO,KAAK,MAAM,SAAS,IAAI;GACrC,MAAM,YAAY,CAAC,GAAG,MAAM,UAAU,MAAM,GAAG,EAAE,GAAG,IAAI;GACxD,QAAQ,OAAO,MAAM;GACrB;EACF;EAGA,IAAI,YAAY;GACd,MAAM,SAAS,MAAM,WAAW,MAAM,MAAM,gBAAgB,MAAM,WAAW,IAAI;GACjF,IAAI,QACF,OAAO;EAEX;EAEA,MAAM,EAAE,QAAQ;EAChB,OACE,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,QAAQ;GACjC,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC;EACvC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-handlers.js","names":[],"sources":["../../../src/components/batch-edit/use-handlers.ts"],"sourcesContent":["import { copy, 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 copy(props.model ?? {})\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 emit('create')\n })\n }\n\n function handleInsertToPrev(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes]\n emit('create-prev', row)\n }\n\n function handleInsertToNext(row: TableRow) {\n resetState()\n state.formActionType = 'create'\n state.formVisible = true\n state.parentRow = row.parent\n state.depth = row.depth\n state.indexPath = [...row.indexes.slice(0, -1), row.index + 1]\n emit('create-next', row)\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 emit('create-child', row)\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 if (props.formMode === 'dialog') {\n resetState()\n return\n }\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 if (props.formMode === 'dialog') {\n resetState()\n }\n })\n\n const handleDelete = runWithLoading(async (row: TableRow) => {\n const { deleteMethod } = props\n\n if (deleteMethod) {\n const result = await deleteMethod([row.data])\n if (result === false) {\n return\n }\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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O,CAAC;EAG1B,IAAI,MAAM,QAAQ,KAChB,WAAW;EAGb,KAAK,eAAe,IAAI;CAC1B,CAAC;CAED,SAAS,cAAc;EACrB,WAAW;CACb;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -22,12 +22,15 @@ function useShortcutKey(options) {
|
|
|
22
22
|
onSave();
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* 键盘快捷键:
|
|
26
26
|
* - Esc 关闭表单
|
|
27
27
|
* - ⌘/Ctrl + S 保存(快速编辑模式下编辑行时除外)
|
|
28
|
+
*
|
|
29
|
+
* 面板模式仅组件获焦时生效;弹框模式表单被 teleport 到 body,
|
|
30
|
+
* 组件聚焦状态覆盖不到,改为弹框打开期间生效
|
|
28
31
|
*/
|
|
29
32
|
function handleKeydown(e) {
|
|
30
|
-
if (!focused.value) return;
|
|
33
|
+
if (!(props.formMode === "dialog" ? state.formVisible : focused.value)) return;
|
|
31
34
|
if (props.readonly && e.key !== "Escape") return;
|
|
32
35
|
if (e.key === "Escape") return runEscape(e);
|
|
33
36
|
if (!(e.metaKey || e.ctrlKey)) return;
|
|
@@ -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 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 *
|
|
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 * 面板模式仅组件获焦时生效;弹框模式表单被 teleport 到 body,\n * 组件聚焦状态覆盖不到,改为弹框打开期间生效\n */\n function handleKeydown(e: KeyboardEvent) {\n const active = props.formMode === 'dialog' ? state.formVisible : focused.value\n if (!active) 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;;;;;;;;;CAUA,SAAS,cAAc,GAAkB;EAEvC,IAAI,EADW,MAAM,aAAa,WAAW,MAAM,cAAc,QAAQ,QAC5D;EACb,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"}
|
|
@@ -47,8 +47,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
47
47
|
];
|
|
48
48
|
});
|
|
49
49
|
const ripple = computed(() => {
|
|
50
|
-
if (props.disabled || props.loading
|
|
51
|
-
if (props.plain && props.type) return bem.is(`ripple-${props.type}`);
|
|
50
|
+
if (props.disabled || props.loading) return false;
|
|
51
|
+
if ((props.plain || props.text) && props.type) return bem.is(`ripple-${props.type}`);
|
|
52
52
|
return true;
|
|
53
53
|
});
|
|
54
54
|
const handleClick = (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":[],"sources":["../../../src/components/button/button.vue"],"sourcesContent":["<template>\n <button :class=\"classList\" type=\"button\" ref=\"buttonRef\" v-ripple=\"ripple\" @click=\"handleClick\">\n <!-- 加载图标 -->\n <u-icon v-if=\"loading\" :class=\"[bem.is('loading')]\" :size=\"iconSize\">\n <component :is=\"loadingIcon\" />\n </u-icon>\n\n <!-- 左侧图标 -->\n <u-icon v-if=\"!!icon && iconPosition === 'left' && !loading\" :size=\"iconSize\">\n <component :is=\"icon\" />\n </u-icon>\n\n <slot />\n\n <!-- 右侧图标 -->\n <u-icon v-if=\"!!icon && iconPosition === 'right'\" :size=\"iconSize\">\n <component :is=\"icon\" />\n </u-icon>\n </button>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFallbackProps } from '@veltra/compositions'\nimport { vRipple } from '@veltra/directives'\nimport { Loading } from '@veltra/icons'\nimport { bem } from '@veltra/utils'\nimport { computed, shallowRef } from 'vue'\n\nimport type { ButtonEmits, ButtonProps, _ButtonExposed, ComponentSize } from '../../types'\nimport { UIcon } from '../icon'\n\ndefineOptions({ name: 'UButton' })\n\nconst props = withDefaults(defineProps<ButtonProps>(), {\n iconPosition: 'left',\n loadingIcon: () => Loading,\n disabled: false,\n propagate: true\n})\n\nconst { size } = useFallbackProps([props], { size: 'default' as ComponentSize })\n\nconst emit = defineEmits<ButtonEmits>()\n\nconst cls = bem('button')\n\nconst classList = computed(() => {\n return [\n cls.b,\n cls.m(size.value),\n props.type && cls.m('color-' + props.type),\n bem.is('circle', props.circle),\n bem.is('disabled', props.disabled),\n bem.is('loading', props.loading),\n bem.is('plain', props.plain),\n bem.is('text', props.text)\n ]\n})\n\nconst ripple = computed(() => {\n if (props.disabled || props.loading
|
|
1
|
+
{"version":3,"file":"button.js","names":[],"sources":["../../../src/components/button/button.vue"],"sourcesContent":["<template>\n <button :class=\"classList\" type=\"button\" ref=\"buttonRef\" v-ripple=\"ripple\" @click=\"handleClick\">\n <!-- 加载图标 -->\n <u-icon v-if=\"loading\" :class=\"[bem.is('loading')]\" :size=\"iconSize\">\n <component :is=\"loadingIcon\" />\n </u-icon>\n\n <!-- 左侧图标 -->\n <u-icon v-if=\"!!icon && iconPosition === 'left' && !loading\" :size=\"iconSize\">\n <component :is=\"icon\" />\n </u-icon>\n\n <slot />\n\n <!-- 右侧图标 -->\n <u-icon v-if=\"!!icon && iconPosition === 'right'\" :size=\"iconSize\">\n <component :is=\"icon\" />\n </u-icon>\n </button>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFallbackProps } from '@veltra/compositions'\nimport { vRipple } from '@veltra/directives'\nimport { Loading } from '@veltra/icons'\nimport { bem } from '@veltra/utils'\nimport { computed, shallowRef } from 'vue'\n\nimport type { ButtonEmits, ButtonProps, _ButtonExposed, ComponentSize } from '../../types'\nimport { UIcon } from '../icon'\n\ndefineOptions({ name: 'UButton' })\n\nconst props = withDefaults(defineProps<ButtonProps>(), {\n iconPosition: 'left',\n loadingIcon: () => Loading,\n disabled: false,\n propagate: true\n})\n\nconst { size } = useFallbackProps([props], { size: 'default' as ComponentSize })\n\nconst emit = defineEmits<ButtonEmits>()\n\nconst cls = bem('button')\n\nconst classList = computed(() => {\n return [\n cls.b,\n cls.m(size.value),\n props.type && cls.m('color-' + props.type),\n bem.is('circle', props.circle),\n bem.is('disabled', props.disabled),\n bem.is('loading', props.loading),\n bem.is('plain', props.plain),\n bem.is('text', props.text)\n ]\n})\n\nconst ripple = computed(() => {\n if (props.disabled || props.loading) return false\n // plain / text 变体无底色,波纹用类型色才能看清\n if ((props.plain || props.text) && props.type) {\n return bem.is(`ripple-${props.type}`)\n }\n return true\n})\n\nconst handleClick = (e: MouseEvent) => {\n if (props.disabled || props.loading) {\n e.stopPropagation()\n return\n }\n\n !props.propagate && e.stopPropagation()\n\n emit('click', e)\n}\n\nconst buttonRef = shallowRef<HTMLButtonElement>()\n\nconst exposed: _ButtonExposed = { el: buttonRef }\n\ndefineExpose(exposed)\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCA,MAAM,QAAQ;EAOd,MAAM,EAAE,SAAS,iBAAiB,CAAC,KAAK,GAAG,EAAE,MAAM,UAA2B,CAAC;EAE/E,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