@ys-knife-crud/element-plus 0.0.1 → 0.0.2
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/README.md +328 -0
- package/dist/element-plus/src/index.d.ts +4 -1
- package/dist/element-plus/src/index.d.ts.map +1 -1
- package/dist/element-plus/src/modal/openDialog.d.ts +25 -0
- package/dist/element-plus/src/modal/openDialog.d.ts.map +1 -0
- package/dist/element-plus/src/modal/openModal.d.ts +5 -0
- package/dist/element-plus/src/modal/openModal.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1608 -1378
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -221,6 +221,334 @@ You normally don't need this — `actions` receive the `TableApi` automatically,
|
|
|
221
221
|
|
|
222
222
|
The package also exports the individual building blocks for when you need finer control than `YsTablePage`: `YsTable`, `YsFilterPanel` (+ `YsTextFilterItem` / `YsDateFilterItem` / `YsDateRangeFilterItem` / `YsEnumFilterItem` / `YsFilterItemLayout`), `YsCommandBar`, `YsTableActionMenuButton`, `YsMainPanel`, and the advanced-filter trio (`YsAdvancedFilterPanel` / `YsAdvancedValueEditor` / `YsAdvancedConditionGroup`). `YsTablePage` is the recommended starting point; drop down to the primitives only when its fixed layout doesn't fit.
|
|
223
223
|
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## `openModal` — code-driven dialogs
|
|
227
|
+
|
|
228
|
+
A small service that mounts **any component** inside an `ElDialog` from plain code — no `<el-dialog v-model="...">` declaration in the template, no boolean ref to maintain. It is useful for row-action edit forms, one-off confirm forms, and any dialog whose trigger lives in an event handler (`Action.execute`, a command-bar button, a context-menu item, …).
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import { openModal } from "@ys-knife-crud/element-plus";
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
> **Prerequisite — register the plugin.** The dialog is mounted imperatively, so it does **not** automatically inherit the calling component's app context. Install the plugin once at the app entry (`app.use(YsCrudElementPlus)`); otherwise `el-*` tags inside the dialog body render as unresolved custom elements and `inject()` returns `undefined`. See [App context](#app-context-inject--i18n--pinia) for details and the local-import fallback.
|
|
235
|
+
|
|
236
|
+
### Quick start
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
import { openModal } from "@ys-knife-crud/element-plus";
|
|
240
|
+
import UserEditForm from "./UserEditForm.vue";
|
|
241
|
+
|
|
242
|
+
openModal({
|
|
243
|
+
title: "编辑用户",
|
|
244
|
+
width: "600px",
|
|
245
|
+
component: UserEditForm,
|
|
246
|
+
props: { userId: 123 },
|
|
247
|
+
// footer buttons are data-driven: pass actions to show them,
|
|
248
|
+
// omit them (or pass []) for a footer-less dialog
|
|
249
|
+
actions: [
|
|
250
|
+
{ name: "cancel", desc: "取消", execute: (handle) => handle.close() },
|
|
251
|
+
{
|
|
252
|
+
name: "save",
|
|
253
|
+
desc: "保存",
|
|
254
|
+
type: "primary",
|
|
255
|
+
execute: async (handle) => {
|
|
256
|
+
await saveUser();
|
|
257
|
+
handle.close(); // closing is explicit — skip it (e.g. validation failed) to stay open
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
onCancel: () => console.log("cancelled via ✕ / ESC / overlay"),
|
|
262
|
+
onClosed: () => console.log("dialog destroyed"),
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
The content component only needs to render its body. An `onClose` listener is injected automatically, so `emit("close")` closes the dialog:
|
|
267
|
+
|
|
268
|
+
```vue
|
|
269
|
+
<!-- UserEditForm.vue -->
|
|
270
|
+
<script setup lang="ts">
|
|
271
|
+
import { ref } from "vue";
|
|
272
|
+
import type { FormInstance, FormRules } from "element-plus";
|
|
273
|
+
|
|
274
|
+
defineProps<{ userId: number }>();
|
|
275
|
+
const emit = defineEmits<{
|
|
276
|
+
(e: "close"): void;
|
|
277
|
+
(e: "saved", row: { name: string }): void;
|
|
278
|
+
}>();
|
|
279
|
+
|
|
280
|
+
const formRef = ref<FormInstance>();
|
|
281
|
+
const form = ref({ name: "" });
|
|
282
|
+
const rules: FormRules = { name: [{ required: true, message: "必填", trigger: "blur" }] };
|
|
283
|
+
|
|
284
|
+
// expose data/validation for the caller's footer actions (handle.getContentInstance())
|
|
285
|
+
defineExpose({
|
|
286
|
+
validate: () => formRef.value?.validate(),
|
|
287
|
+
getData: () => form.value,
|
|
288
|
+
});
|
|
289
|
+
</script>
|
|
290
|
+
|
|
291
|
+
<template>
|
|
292
|
+
<el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
|
|
293
|
+
<el-form-item label="姓名" prop="name">
|
|
294
|
+
<el-input v-model="form.name" />
|
|
295
|
+
</el-form-item>
|
|
296
|
+
</el-form>
|
|
297
|
+
</template>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Options (`ModalOptions`)
|
|
301
|
+
|
|
302
|
+
| Option | Type | Default | Description |
|
|
303
|
+
| --- | --- | --- | --- |
|
|
304
|
+
| `component` | `Component` | — **required** | The component rendered as the dialog body. |
|
|
305
|
+
| `props` | `P` | — | Props forwarded to `component`. An `onClose` listener is always injected in addition. Vue 3 treats `onXxx` entries as event listeners, so a body `emit("saved", row)` is received via `props: { onSaved: (row) => … }`. |
|
|
306
|
+
| `title` | `string` | `""` | Dialog title (passed to `el-dialog`). |
|
|
307
|
+
| `width` | `string \| number` | `"500px"` | Dialog width. |
|
|
308
|
+
| `height` | `string \| number` | — | Fixed dialog height. When omitted the dialog grows with its content (default). When set, the dialog has a fixed height and the body scrolls internally when content overflows — the dialog will not be stretched by its content. Numbers are treated as pixels; strings may carry any unit (`"600px"`, `"70vh"`). |
|
|
309
|
+
| `actions` | `ModalAction[]` | — | Footer action buttons (取消 / 确定, …) rendered from data, same shape conventions as core's `TableAction`. Passing a **non-empty array renders the footer**; omitting it (or `[]`) renders **no footer** — the body then owns its buttons. While an action's `execute` promise is pending, that button shows a loading spinner, the other buttons are disabled and ✕ is hidden. See [Footer actions](#footer-actions-modalaction). |
|
|
310
|
+
| `onCancel` | `() => void` | — | Fired on any cancel-style close **not triggered by a footer action**: the ✕ icon, ESC (if enabled), or modal-click (if enabled). |
|
|
311
|
+
| `onClosed` | `() => void` | — | Fired after the close transition finishes and the dialog DOM has been destroyed. |
|
|
312
|
+
| `closeOnClickModal` | `boolean` | `false` | Clicking the overlay closes the dialog. Disabled by default to avoid losing form input. |
|
|
313
|
+
| `closeOnPressEscape` | `boolean` | `false` | ESC closes the dialog. Disabled by default. |
|
|
314
|
+
| `maximizable` | `boolean` | `false` | Show a maximize/restore button in the header (left of ✕). Maximized dialogs fill the viewport (`width:100%`, `height:100vh`) with the body scrolling internally. See [Maximize / restore](#maximize--restore). |
|
|
315
|
+
| `defaultMaximized` | `boolean` | `false` | Open already maximized. Only effective when `maximizable: true`. |
|
|
316
|
+
| `appContext` | `AppContext` | plugin default | Explicit app context for `inject` / global components inside the dialog. Usually unnecessary when the plugin is installed. |
|
|
317
|
+
|
|
318
|
+
### Returned handle (`ModalHandle`)
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
const handle = openModal({ component: MyForm });
|
|
322
|
+
|
|
323
|
+
handle.close(); // close with transition, then destroy
|
|
324
|
+
handle.toggleMaximize(); // switch between maximized/restored (needs maximizable)
|
|
325
|
+
handle.isMaximized(); // boolean: current maximize state
|
|
326
|
+
handle.getContentInstance(); // the mounted body component instance,
|
|
327
|
+
// so you can call its defineExpose() methods
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Footer actions (`ModalAction`)
|
|
331
|
+
|
|
332
|
+
The built-in footer is **data-driven**: every entry in `actions` renders as an `el-button`, with the same shape conventions as core's `TableAction` — `name` is the key, `desc` is the visible button label (and `title` tooltip), `icon` / `type` map to the button like `Action.icon` does elsewhere.
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
import { openModal, type ModalAction } from "@ys-knife-crud/element-plus";
|
|
336
|
+
|
|
337
|
+
const actions: ModalAction[] = [
|
|
338
|
+
{ name: "cancel", desc: "取消", execute: (handle) => handle.close() },
|
|
339
|
+
{
|
|
340
|
+
name: "save",
|
|
341
|
+
desc: "保存",
|
|
342
|
+
type: "primary", // el-button type; 'default' / undefined → plain default button
|
|
343
|
+
// icon: EditPen, // same compatibility as Action.icon (component / VNode)
|
|
344
|
+
execute: async (handle, form) => {
|
|
345
|
+
// form is auto-typed as InstanceType<typeof UserEditForm> (non-null)
|
|
346
|
+
try {
|
|
347
|
+
await form.validate();
|
|
348
|
+
} catch {
|
|
349
|
+
return; // validation failed → don't close, the dialog stays open
|
|
350
|
+
}
|
|
351
|
+
await api.update(form.getData());
|
|
352
|
+
handle.close(); // closing is explicit — call it when the action succeeded
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
];
|
|
356
|
+
|
|
357
|
+
openModal({ component: UserEditForm, actions });
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Behavior:
|
|
361
|
+
|
|
362
|
+
- **A non-empty `actions` array renders the footer; omitting it (or `[]`) renders no footer** — the body component then owns its buttons and closes via `emit("close")`.
|
|
363
|
+
- `execute(handle, instance)` receives the [dialog handle](#returned-handle-modalhandle) and the mounted body component instance. The instance type is **auto-inferred from `component`** (e.g. `InstanceType<typeof UserEditForm>`) and is non-null (footer buttons are only clickable after the body mounts). Closing is **explicit** (`handle.close()`), which makes "keep the dialog open on validation failure" trivial — just don't call `close`.
|
|
364
|
+
- While `execute` returns a pending promise: that button shows `loading`, the other action buttons are disabled, the ✕ icon is hidden, and further clicks are ignored — no half-submitted close.
|
|
365
|
+
- `onCancel` is **not** called for footer actions; it only covers non-action close paths (✕ / ESC / overlay).
|
|
366
|
+
|
|
367
|
+
> A common alternative that avoids `getContentInstance()` is to omit `actions` and have the body component own its buttons, calling the API itself, then `emit("close")` on success.
|
|
368
|
+
|
|
369
|
+
### No actions (body owns the buttons)
|
|
370
|
+
|
|
371
|
+
For multi-step forms, dynamic button labels, or cases where the body already has a button bar, just omit `actions`:
|
|
372
|
+
|
|
373
|
+
```ts
|
|
374
|
+
openModal({
|
|
375
|
+
title: "详情",
|
|
376
|
+
component: DetailPanel,
|
|
377
|
+
props: { id },
|
|
378
|
+
// no actions → no built-in footer
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
The body can then render its own buttons and close via the injected `onClose`:
|
|
383
|
+
|
|
384
|
+
```vue
|
|
385
|
+
<template>
|
|
386
|
+
<div class="detail">…</div>
|
|
387
|
+
<div class="footer">
|
|
388
|
+
<el-button @click="emit('close')">关闭</el-button>
|
|
389
|
+
<el-button type="primary" @click="submitAndClose">保存</el-button>
|
|
390
|
+
</div>
|
|
391
|
+
</template>
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### `openDialog` — built-in 取消 / 确定 footer
|
|
395
|
+
|
|
396
|
+
`openDialog` is a thin convenience wrapper around `openModal` that provides a built-in **取消 / 确定** footer by default — you only supply `onConfirm`:
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
import { openDialog } from "@ys-knife-crud/element-plus";
|
|
400
|
+
|
|
401
|
+
openDialog({
|
|
402
|
+
title: "编辑用户",
|
|
403
|
+
width: "600px",
|
|
404
|
+
component: UserEditForm,
|
|
405
|
+
props: { userId: 123 },
|
|
406
|
+
onConfirm: async (_handle, form) => {
|
|
407
|
+
// form is auto-typed as InstanceType<typeof UserEditForm> (non-null)
|
|
408
|
+
const ok = await form.validate().catch(() => false);
|
|
409
|
+
if (!ok) return false; // validation failed → return false to keep the dialog open
|
|
410
|
+
await api.update(form.getData());
|
|
411
|
+
// returning undefined (or any non-false value) closes the dialog
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
Semantics:
|
|
417
|
+
|
|
418
|
+
- **取消** closes the dialog immediately. (Use `onCancel` only for non-button close paths like ✕ / ESC / overlay; the 取消 button does not fire it.)
|
|
419
|
+
- **确定** runs `onConfirm(handle, instance)`. While it is pending, 确定 shows `loading`, 取消 and ✕ are disabled/hidden. Return `false` (or a promise resolving to `false`) to **keep the dialog open**; any other return value closes it.
|
|
420
|
+
- `confirmText` / `cancelText` / `confirmType` customize the default 取消 / 确定 buttons.
|
|
421
|
+
- The footer buttons are fixed at 取消 / 确定. Need a different button set (e.g. three buttons, a custom action)? Use `openModal` with `actions`.
|
|
422
|
+
|
|
423
|
+
All other `openModal` options (`maximizable`, `closeOnClickModal`, `onClosed`, …) are available on `openDialog` as well.
|
|
424
|
+
|
|
425
|
+
### Fixed height
|
|
426
|
+
|
|
427
|
+
By default the dialog grows with its content. For content with a known height budget (a table with many rows, a long log panel, …), pass `height` to cap the dialog. Numbers are pixels; strings carry any unit:
|
|
428
|
+
|
|
429
|
+
```ts
|
|
430
|
+
openDialog({
|
|
431
|
+
title: "用户列表",
|
|
432
|
+
width: "900px",
|
|
433
|
+
height: 500, // or "600px" / "70vh"
|
|
434
|
+
component: UserTable,
|
|
435
|
+
maximizable: true,
|
|
436
|
+
});
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Behavior:
|
|
440
|
+
|
|
441
|
+
- **Without `height`** — the dialog height follows its content (default Element Plus behavior).
|
|
442
|
+
- **With `height`** — the dialog is fixed to that height. `.el-dialog__body` becomes `flex:1` with `overflow:auto`, so overflowing content scrolls inside the dialog instead of stretching it. Header and footer stay fixed.
|
|
443
|
+
- **With `maximizable`** — maximize still wins (`height: 100vh !important`); restoring returns to the `height` you set.
|
|
444
|
+
|
|
445
|
+
### Maximize / restore
|
|
446
|
+
|
|
447
|
+
For forms/detail panels whose content is cramped at the default width, set `maximizable: true` to show a maximize button in the header (immediately left of ✕). Clicking it toggles between the normal `width` size and a viewport-filling layout; clicking again restores.
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
openModal({
|
|
451
|
+
title: "订单详情",
|
|
452
|
+
width: "520px", // size when restored
|
|
453
|
+
component: OrderDetail,
|
|
454
|
+
props: { orderId },
|
|
455
|
+
maximizable: true, // show the maximize/restore button
|
|
456
|
+
// defaultMaximized: true, // optional: open already maximized
|
|
457
|
+
});
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
Behavior and layout:
|
|
461
|
+
|
|
462
|
+
- **Restored** — the dialog uses your `width` exactly like a normal dialog.
|
|
463
|
+
- **Maximized** — `width: 100%`, `height: 100vh`, top-aligned (no margin). The header and footer stay fixed while `.el-dialog__body` becomes `flex:1` with `overflow:auto`, so long content scrolls inside the dialog rather than the page.
|
|
464
|
+
- The button icon switches between a single frame (maximize) and overlapping frames (restore), with `title`/`aria-label` tooltips.
|
|
465
|
+
- The maximize state is internal to the service; the body component is not re-created on toggle (its state, e.g. partially filled form, is preserved).
|
|
466
|
+
|
|
467
|
+
You can also drive it programmatically through the returned handle:
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
const handle = openModal({ component: WideForm, maximizable: true });
|
|
471
|
+
|
|
472
|
+
// e.g. inside the body or an external toolbar:
|
|
473
|
+
if (!handle.isMaximized()) handle.toggleMaximize();
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
> The maximize button shares the same positioning context (`.el-dialog`) as Element Plus's built-in ✕, so the close button stays in exactly the same place whether or not `maximizable` is enabled.
|
|
477
|
+
|
|
478
|
+
### Using from a row action
|
|
479
|
+
|
|
480
|
+
The most common use in this library: an `Action.execute(row, table)` opens an edit form for the clicked row and refreshes the table after a successful save. Pass the row through `props`, and call `table.refresh()` (current page only) or `table.reload()` (back to page 1) after the dialog closes:
|
|
481
|
+
|
|
482
|
+
```ts
|
|
483
|
+
import { constActions, type RowActionsFunc } from "@ys-knife-crud/core";
|
|
484
|
+
import { openModal } from "@ys-knife-crud/element-plus";
|
|
485
|
+
import UserEditForm from "./UserEditForm.vue";
|
|
486
|
+
|
|
487
|
+
const rowActionsFunc: RowActionsFunc<UserRow> = constActions<UserRow>({
|
|
488
|
+
name: "edit",
|
|
489
|
+
desc: "编辑",
|
|
490
|
+
execute: (row, table) => {
|
|
491
|
+
openModal({
|
|
492
|
+
title: `编辑:${row.name}`,
|
|
493
|
+
component: UserEditForm,
|
|
494
|
+
// seed the form from the clicked row; the body initialises from props
|
|
495
|
+
props: { initialName: row.name, initialEmail: row.email },
|
|
496
|
+
actions: [
|
|
497
|
+
{ name: "cancel", desc: "取消", execute: (handle) => handle.close() },
|
|
498
|
+
{
|
|
499
|
+
name: "save",
|
|
500
|
+
desc: "保存",
|
|
501
|
+
type: "primary",
|
|
502
|
+
execute: async (handle, form) => {
|
|
503
|
+
try {
|
|
504
|
+
await form.validate();
|
|
505
|
+
} catch {
|
|
506
|
+
return; // stay open on validation failure
|
|
507
|
+
}
|
|
508
|
+
await updateUser(row.id, form.getData());
|
|
509
|
+
table.refresh(); // re-fetch the current page after saving
|
|
510
|
+
handle.close();
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
});
|
|
515
|
+
return Promise.resolve();
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
> `execute` is called outside the Vue component tree (it is just a callback), which is exactly why `openModal` captures the app context from the plugin install rather than from the call site. There is no `getCurrentInstance()` available inside `execute`.
|
|
521
|
+
|
|
522
|
+
### App context (inject / i18n / pinia)
|
|
523
|
+
|
|
524
|
+
Because the dialog is mounted imperatively, it does not automatically inherit the calling component's app context. After registering the plugin (`app.use(YsCrudElementPlus)`), the application context is captured during `install` and used by every `openModal` call, so `inject`, global components, directives, `ElConfigProvider` locale, Pinia, etc. work inside dialog bodies with no extra setup. If you use local imports without the plugin, capture the context **inside `setup`** and pass it explicitly — `getCurrentInstance()` returns `null` inside the later event handler:
|
|
525
|
+
|
|
526
|
+
```ts
|
|
527
|
+
// inside <script setup>: capture once, use in handlers
|
|
528
|
+
import { getCurrentInstance } from "vue";
|
|
529
|
+
|
|
530
|
+
const appContext = getCurrentInstance()!.appContext;
|
|
531
|
+
|
|
532
|
+
function openEdit() {
|
|
533
|
+
openModal({ component: MyForm, appContext });
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
**Troubleshooting — missing app context.** When neither the plugin nor an explicit `appContext` is available, `openModal` prints a console warning and the dialog body renders `el-*` tags as **unresolved custom elements** — inspecting the DOM shows literal `<el-form>` / `<el-input>` nodes instead of `<form class="el-form">`, and the inputs never appear. `inject()` inside the body also returns `undefined`. Fix it by installing the plugin in the app entry, or pass `appContext` as shown above.
|
|
538
|
+
|
|
539
|
+
### Notes & gotchas
|
|
540
|
+
|
|
541
|
+
- **Register the plugin (or pass `appContext`).** This is the single most common failure: imperative `render()` does not inherit the caller's component tree, so without an app context the dialog shell (`ElDialog`, imported directly by the service) works but every globally-registered component inside the **body** silently fails to resolve. See [App context](#app-context-inject--i18n--pinia).
|
|
542
|
+
- **Cleanup is automatic.** The service listens to `el-dialog`'s `closed` event and calls `render(null, container)` + removes the mount node after the leave transition. Reopening later creates a fresh instance — do not reuse the container yourself.
|
|
543
|
+
- **Teleport still applies.** `el-dialog` teleports to `<body>` as usual; the internal mount node is only the vnode anchor, so dialogs are not trapped inside an `overflow:hidden` parent.
|
|
544
|
+
- **`destroy-on-close` is always on.** Body component state is not retained across close/reopen; initialise from `props` synchronously (e.g. `reactive({ name: props.initialName ?? "" })`) or fetch by id in `onMounted`.
|
|
545
|
+
- **Footer buttons are opt-in via `actions`.** No `actions` (or an empty array) renders no footer — the body component owns its buttons and closes via `emit("close")`. `onCancel` only fires for non-action close paths (✕ / ESC / overlay), never for footer action clicks.
|
|
546
|
+
- **Prefer it for dialogs triggered from handlers.** For dialogs whose open state is naturally bound to template state (e.g. a panel-level edit dialog co-located with a table), a plain `<el-dialog v-model>` is still the simpler choice.
|
|
547
|
+
|
|
548
|
+
A runnable, eight-scenario demo (footer actions with async validation / no-actions body-owned buttons / `props.onXxx` event forwarding / `openDialog` with built-in 取消·确定 / maximizable toggle / open maximized by default / `openDialog` embedding `YsTablePage` / `openDialog` embedding `YsImportExcel`) lives in [`packages/element-plus-demo/src/pages/modal`](./packages/element-plus-demo/src/pages/modal); run `pnpm --filter @ys-knife-crud/element-plus-demo dev` and open **代码式弹窗(openModal)**.
|
|
549
|
+
|
|
550
|
+
---
|
|
551
|
+
|
|
224
552
|
## Relationship to other packages
|
|
225
553
|
|
|
226
554
|
```
|
|
@@ -14,7 +14,10 @@ import { default as YsAdvancedValueEditor } from './advancedFilter/advancedValue
|
|
|
14
14
|
import { default as YsAdvancedConditionGroup } from './advancedFilter/advancedConditionGroup.vue';
|
|
15
15
|
import { default as YsTablePage } from './tablepage/tablePage.vue';
|
|
16
16
|
import { default as YsImportExcel } from './importExcel/importExcel.vue';
|
|
17
|
-
|
|
17
|
+
import { openModal } from './modal/openModal';
|
|
18
|
+
import { openDialog } from './modal/openDialog';
|
|
19
|
+
export { YsTable, YsTableActionMenuButton, YsCommandBar, YsMainPanel, YsFilterPanel, YsTablePage, YsImportExcel, YsTextFilterItem, YsDateFilterItem, YsDateRangeFilterItem, YsEnumFilterItem, YsFilterItemLayout, YsAdvancedFilterPanel, YsAdvancedValueEditor, YsAdvancedConditionGroup, openModal, openDialog, };
|
|
20
|
+
export type { ModalOptions, ModalHandle, ModalAction, DialogOptions } from '../packages/vue/src/index.ts';
|
|
18
21
|
export type { EnumOption, EnumOptionsSource, } from '../packages/core/src/index.ts';
|
|
19
22
|
export { fromOptions, fromObjectItems, fromArray, fromBool, } from '../packages/core/src/index.ts';
|
|
20
23
|
export type YsTableProps = InstanceType<typeof YsTable>["$props"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,MAAM,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,OAAO,MAAM,mBAAmB,CAAC;AACxC,OAAO,uBAAuB,MAAM,wCAAwC,CAAC;AAC7E,OAAO,YAAY,MAAM,6BAA6B,CAAC;AACvD,OAAO,WAAW,MAAM,2BAA2B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AAC,QAAQ,CAAC,CAAC;AAC9F,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAAC,OAAO,gBAAgB,CAAC,CAAC,QAAQ,CAAC,CAAC;AACpF,MAAM,MAAM,uBAAuB,GAAG,YAAY,CAAC,OAAO,kBAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC;AACxF,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC,OAAO,qBAAqB,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC9F,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC,OAAO,qBAAqB,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC9F,MAAM,MAAM,6BAA6B,GAAG,YAAY,CAAC,OAAO,wBAAwB,CAAC,CAAC,QAAQ,CAAC,CAAC;AACpG,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC1E,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC;AAG9E,YAAY,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAGzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,EAAE,MAoBxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Component } from 'vue';
|
|
2
|
+
import { DialogOptions, ModalHandle } from '../../packages/vue/src/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* openDialog:openModal 的简化封装,固定提供「取消 / 确定」两个底部按钮。
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* openDialog({
|
|
8
|
+
* title: "编辑用户",
|
|
9
|
+
* component: UserEditForm,
|
|
10
|
+
* props: { userId: 123 },
|
|
11
|
+
* onConfirm: async (_handle, form) => {
|
|
12
|
+
* // form 自动推断为 InstanceType<typeof UserEditForm>,无需断言、无需判空
|
|
13
|
+
* const ok = await form.validate().catch(() => false);
|
|
14
|
+
* if (!ok) return false; // 校验失败不关闭
|
|
15
|
+
* await saveUser();
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* - 取消按钮默认直接关闭弹窗
|
|
21
|
+
* - 确定按钮执行 onConfirm;onConfirm 返回 false 时保持弹窗打开,其他情况关闭
|
|
22
|
+
* - 底部按钮固定为「取消 / 确定」,如需自定义按钮请使用 openModal 的 actions
|
|
23
|
+
*/
|
|
24
|
+
export declare function openDialog<P extends Record<string, unknown> = Record<string, unknown>, C extends Component = Component>(options: DialogOptions<P, C>): ModalHandle;
|
|
25
|
+
//# sourceMappingURL=openDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openDialog.d.ts","sourceRoot":"","sources":["../../../../src/modal/openDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EACH,KAAK,aAAa,EAElB,KAAK,WAAW,EACnB,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,CAAC,SAAS,SAAS,GAAG,SAAS,EACjC,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CA4B3C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Component } from 'vue';
|
|
2
|
+
import { setDefaultModalAppContext, ModalHandle, ModalOptions } from '../../packages/vue/src/index.ts';
|
|
3
|
+
export { setDefaultModalAppContext };
|
|
4
|
+
export declare function openModal<P extends Record<string, unknown> = Record<string, unknown>, C extends Component = Component>(options: ModalOptions<P, C>): ModalHandle;
|
|
5
|
+
//# sourceMappingURL=openModal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openModal.d.ts","sourceRoot":"","sources":["../../../../src/modal/openModal.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,SAAS,EAGjB,MAAM,KAAK,CAAC;AAEb,OAAO,EAEH,yBAAyB,EAGzB,KAAK,WAAW,EAChB,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAqHrC,wBAAgB,SAAS,CACrB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,CAAC,SAAS,SAAS,GAAG,SAAS,EACjC,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAoO1C"}
|