@vuetkit/components 0.0.10 → 0.0.12
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 +1 -0
- package/dist/index.d.ts +27 -25
- package/dist/index.js +161 -11
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ Collection of business development Composable Components for Vue3 + ElementPlus
|
|
|
10
10
|
|
|
11
11
|
- [useMessage](/components/src/feedback/useMessage/)
|
|
12
12
|
- [useAsyncConfirm](/components/src/feedback/useAsyncConfirm/)
|
|
13
|
+
- [useDialog](/components/src/feedback/useDialog/)
|
|
13
14
|
|
|
14
15
|
### Form
|
|
15
16
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RequestService } from "@vuetkit/core";
|
|
2
|
-
import { ComponentSize, FormRules, MessageProps, MessageType,
|
|
3
|
-
import { Component, VNode } from "vue";
|
|
2
|
+
import { ComponentSize, DialogProps, FormRules, MessageProps, MessageType, PaginationProps, TableProps } from "element-plus";
|
|
3
|
+
import { CSSProperties, Component, MaybeRef, VNode } from "vue";
|
|
4
|
+
import { TableColumnProps } from "element-plus/es/components/table/src/table-column/defaults.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/feedback/useAsyncConfirm/index.d.ts
|
|
6
7
|
interface AsyncConfirmOptions {
|
|
@@ -19,6 +20,16 @@ declare function useAsyncConfirm(confirmService: RequestService, options: AsyncC
|
|
|
19
20
|
confirm: (params?: unknown) => void;
|
|
20
21
|
};
|
|
21
22
|
//#endregion
|
|
23
|
+
//#region src/feedback/useDialog/index.d.ts
|
|
24
|
+
interface DialogOptions extends DialogProps {
|
|
25
|
+
title?: string;
|
|
26
|
+
}
|
|
27
|
+
type DialogReturn = [Component, {
|
|
28
|
+
open: () => void;
|
|
29
|
+
close: () => void;
|
|
30
|
+
}];
|
|
31
|
+
declare function useDialog(options: DialogOptions): DialogReturn;
|
|
32
|
+
//#endregion
|
|
22
33
|
//#region src/feedback/useMessage/index.d.ts
|
|
23
34
|
declare function useMessage(options?: MessageProps): {
|
|
24
35
|
success: (message: string) => import("element-plus").MessageHandler;
|
|
@@ -76,40 +87,31 @@ type FormReturnType<T extends object> = [Component, {
|
|
|
76
87
|
setData: (newData: T) => void;
|
|
77
88
|
}];
|
|
78
89
|
declare function setDeepProperty(data: Recordable, propArr: string[], value: unknown): void;
|
|
90
|
+
declare function useForm(options: undefined): [null, Recordable];
|
|
79
91
|
declare function useForm<T extends object>(options: FormOptions<T>): FormReturnType<T>;
|
|
80
92
|
//#endregion
|
|
81
93
|
//#region src/table/useTable/index.d.ts
|
|
82
94
|
type DefaultRow = Record<PropertyKey, any>;
|
|
83
|
-
interface
|
|
95
|
+
interface TableColumnOptions<T extends DefaultRow> extends TableColumnProps<T> {
|
|
84
96
|
render?: (row: T) => VNode | string;
|
|
85
|
-
children?:
|
|
97
|
+
children?: TableColumnOptions<T>[];
|
|
86
98
|
prop?: string;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
fixed?: boolean | 'left' | 'right';
|
|
91
|
-
align?: 'left' | 'center' | 'right';
|
|
92
|
-
headerAlign?: 'left' | 'center' | 'right';
|
|
93
|
-
className?: string;
|
|
94
|
-
labelClassName?: string;
|
|
95
|
-
showOverflowTooltip?: boolean;
|
|
96
|
-
sortable?: boolean | string;
|
|
97
|
-
sortMethod?: (a: T, b: T) => number;
|
|
98
|
-
sortBy?: string | string[];
|
|
99
|
-
sortOrders?: ('ascending' | 'descending')[];
|
|
100
|
-
resizable?: boolean;
|
|
101
|
-
formatter?: (row: T, column: TableColumnCtx<T>, cellValue: any, index: number) => any;
|
|
102
|
-
type?: 'selection' | 'index' | 'expand';
|
|
103
|
-
selectable?: (row: T, index: number) => boolean;
|
|
104
|
-
reserveSelection?: boolean;
|
|
105
|
-
index?: number | ((index: number) => number);
|
|
99
|
+
}
|
|
100
|
+
interface PaginationOptions extends Partial<PaginationProps> {
|
|
101
|
+
wrapStyle?: CSSProperties;
|
|
106
102
|
}
|
|
107
103
|
interface TableOptions<T extends DefaultRow> extends TableProps<T> {
|
|
108
|
-
columns:
|
|
104
|
+
columns: TableColumnOptions<T>[];
|
|
105
|
+
service?: RequestService;
|
|
106
|
+
params?: MaybeRef<unknown> | unknown;
|
|
107
|
+
formatData?: (res: unknown) => T[];
|
|
109
108
|
align?: 'left' | 'center' | 'right';
|
|
110
109
|
headerAlign?: 'left' | 'center' | 'right';
|
|
110
|
+
paginationConfig?: boolean | PaginationOptions;
|
|
111
|
+
tableWrapStyle?: CSSProperties;
|
|
112
|
+
searchFormConfig?: FormOptions<T>;
|
|
111
113
|
}
|
|
112
114
|
type TableReturn = [Component];
|
|
113
115
|
declare function useTable<T extends DefaultRow>(options: TableOptions<T>): TableReturn;
|
|
114
116
|
//#endregion
|
|
115
|
-
export { AsyncConfirmOptions, CustomRender, DefaultComponentKey, FormItemType, FormOptions, FormReturnType, FormRuleFn, FormSchema, Recordable,
|
|
117
|
+
export { AsyncConfirmOptions, CustomRender, DefaultComponentKey, FormItemType, FormOptions, FormReturnType, FormRuleFn, FormSchema, PaginationOptions, Recordable, TableColumnOptions, TableOptions, TableReturn, setDeepProperty, useAsyncConfirm, useDialog, useForm, useMessage, useTable };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRequest } from "@vuetkit/core";
|
|
2
|
-
import { ElCascader, ElCheckbox, ElCol, ElColorPicker, ElDatePicker, ElForm, ElFormItem, ElInput, ElInputNumber, ElInputOtp, ElMention, ElMessage, ElMessageBox, ElRadio, ElRate, ElRow, ElSelect, ElSelectV2, ElSlider, ElSwitch, ElTable, ElTableColumn, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect, ElUpload } from "element-plus";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { ElButton, ElCascader, ElCheckbox, ElCol, ElColorPicker, ElDatePicker, ElDialog, ElForm, ElFormItem, ElInput, ElInputNumber, ElInputOtp, ElMention, ElMessage, ElMessageBox, ElPagination, ElRadio, ElRate, ElRow, ElScrollbar, ElSelect, ElSelectV2, ElSlider, ElSwitch, ElTable, ElTableColumn, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect, ElUpload, vLoading } from "element-plus";
|
|
3
|
+
import { computed, defineComponent, h, nextTick, onMounted, reactive, ref, toValue, useTemplateRef, watch, withDirectives } from "vue";
|
|
4
|
+
import { isFunc, realObj } from "@vuetkit/shared";
|
|
5
5
|
//#region src/feedback/useMessage/index.ts
|
|
6
6
|
const DEFAULT_DURATION = 3e3;
|
|
7
7
|
const DEFAULT_SHOW_CLOSE = true;
|
|
@@ -80,6 +80,50 @@ function useAsyncConfirm(confirmService, options) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
//#endregion
|
|
83
|
+
//#region src/feedback/useDialog/index.ts
|
|
84
|
+
function useDialog(options) {
|
|
85
|
+
const { title = "Dialog Title" } = options;
|
|
86
|
+
const showDialog = ref(false);
|
|
87
|
+
const DialogComp = defineComponent((props, { slots }) => {
|
|
88
|
+
return () => {
|
|
89
|
+
return h(ElDialog, {
|
|
90
|
+
title,
|
|
91
|
+
"modelValue": showDialog.value,
|
|
92
|
+
"update:modelValue": (val) => showDialog.value = val,
|
|
93
|
+
...props,
|
|
94
|
+
"before-close": () => {
|
|
95
|
+
showDialog.value = false;
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
default: () => {
|
|
99
|
+
return h(ElScrollbar, { maxHeight: "60vh" }, () => {
|
|
100
|
+
var _slots$default;
|
|
101
|
+
return h("div", { style: { marginRight: "15px" } }, (_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots));
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
footer: () => {
|
|
105
|
+
var _slots$footer;
|
|
106
|
+
return (_slots$footer = slots.footer) === null || _slots$footer === void 0 ? void 0 : _slots$footer.call(slots);
|
|
107
|
+
},
|
|
108
|
+
header: () => {
|
|
109
|
+
var _slots$header;
|
|
110
|
+
return (_slots$header = slots.header) === null || _slots$header === void 0 ? void 0 : _slots$header.call(slots);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
const open = () => {
|
|
116
|
+
showDialog.value = true;
|
|
117
|
+
};
|
|
118
|
+
const close = () => {
|
|
119
|
+
showDialog.value = false;
|
|
120
|
+
};
|
|
121
|
+
return [DialogComp, {
|
|
122
|
+
open,
|
|
123
|
+
close
|
|
124
|
+
}];
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
83
127
|
//#region src/form/useForm/index.ts
|
|
84
128
|
const defaultComponent = {
|
|
85
129
|
"input": ElInput,
|
|
@@ -112,7 +156,9 @@ function setDeepProperty(data, propArr, value) {
|
|
|
112
156
|
temp[propArr[propArr.length - 1]] = value;
|
|
113
157
|
}
|
|
114
158
|
function useForm(options) {
|
|
115
|
-
|
|
159
|
+
var _options$schemas;
|
|
160
|
+
if (!options || !((_options$schemas = options.schemas) === null || _options$schemas === void 0 ? void 0 : _options$schemas.length)) return [null, {}];
|
|
161
|
+
const { schemas = [], rules = {}, colSpan = 24, defaultData, disabled = false, inline = false, size, rowGutter = 20, labelWidth, labelSuffix = "", labelPosition = "left", "validate-on-rule-change": validateOnRuleChange = true, enterCallback, customComponent, "scrollTo-error": scrollToError = false, "scroll-into-view-options": scrollIntoViewOptions = true, "status-icon": statusIcon = false, "require-asterisk-position": requireAsteriskPosition = "left", "show-message": showMessage = true, "inline-message": inlineMessage = false } = options;
|
|
116
162
|
const components = {};
|
|
117
163
|
if (customComponent) Object.assign(components, defaultComponent, customComponent);
|
|
118
164
|
else Object.assign(components, defaultComponent);
|
|
@@ -272,14 +318,41 @@ function useForm(options) {
|
|
|
272
318
|
//#endregion
|
|
273
319
|
//#region src/table/useTable/index.ts
|
|
274
320
|
function useTable(options) {
|
|
275
|
-
const { columns, align, headerAlign, ...rest } = options;
|
|
321
|
+
const { columns = [], service, params, formatData, align, headerAlign, paginationConfig, searchFormConfig, tableWrapStyle = {}, data = [], ...rest } = options;
|
|
322
|
+
if ((paginationConfig || searchFormConfig) && !realObj(toValue(params))) throw new Error("params must be an object when paginationConfig or searchFormConfig is provided");
|
|
276
323
|
return [defineComponent((props, { slots }) => {
|
|
324
|
+
const pageInfo = reactive({
|
|
325
|
+
pageSize: 10,
|
|
326
|
+
currentPage: 1
|
|
327
|
+
});
|
|
328
|
+
const [SearchForm, { reset, getData }] = searchFormConfig ? useForm(searchFormConfig) : [null, {
|
|
329
|
+
reset: () => {},
|
|
330
|
+
getData: () => ({})
|
|
331
|
+
}];
|
|
332
|
+
const requestParams = computed(() => {
|
|
333
|
+
if (paginationConfig) return {
|
|
334
|
+
...toValue(params) || {},
|
|
335
|
+
...searchFormConfig ? (getData === null || getData === void 0 ? void 0 : getData()) || {} : {},
|
|
336
|
+
currentPage: pageInfo.currentPage,
|
|
337
|
+
pageSize: pageInfo.pageSize
|
|
338
|
+
};
|
|
339
|
+
if (searchFormConfig) return {
|
|
340
|
+
...toValue(params) || {},
|
|
341
|
+
...(getData === null || getData === void 0 ? void 0 : getData()) || {}
|
|
342
|
+
};
|
|
343
|
+
return toValue(params);
|
|
344
|
+
});
|
|
345
|
+
const { data: asyncRequestData, loading, execute } = useRequest(service, {
|
|
346
|
+
manual: false,
|
|
347
|
+
defaultParams: requestParams.value,
|
|
348
|
+
formatData
|
|
349
|
+
});
|
|
277
350
|
const renderTableItemNodes = (column) => {
|
|
278
351
|
var _column$children;
|
|
279
352
|
if (isFunc(column.render)) return { default: ({ row }) => column.render(row) };
|
|
280
353
|
const tableItemNodes = [];
|
|
281
354
|
if (column === null || column === void 0 || (_column$children = column.children) === null || _column$children === void 0 ? void 0 : _column$children.length) tableItemNodes.push(...renderTableItems(column.children));
|
|
282
|
-
return () => tableItemNodes;
|
|
355
|
+
return tableItemNodes.length ? () => tableItemNodes : void 0;
|
|
283
356
|
};
|
|
284
357
|
const renderTableItem = (column) => {
|
|
285
358
|
const { align: columnAlign, headerAlign: columnHeaderAlign } = column;
|
|
@@ -296,10 +369,48 @@ function useTable(options) {
|
|
|
296
369
|
return renderTableItem(column);
|
|
297
370
|
});
|
|
298
371
|
};
|
|
299
|
-
|
|
300
|
-
|
|
372
|
+
function executeRequest() {
|
|
373
|
+
if (service) execute(requestParams.value);
|
|
374
|
+
}
|
|
375
|
+
onMounted(() => {
|
|
376
|
+
if (service) execute();
|
|
377
|
+
});
|
|
378
|
+
const handleReset = () => {
|
|
379
|
+
reset === null || reset === void 0 || reset();
|
|
380
|
+
executeRequest();
|
|
381
|
+
};
|
|
382
|
+
const handleSearch = () => {
|
|
383
|
+
executeRequest();
|
|
384
|
+
};
|
|
385
|
+
const defaultPaginationLayout = "total, sizes, prev, pager, next, jumper";
|
|
386
|
+
const defaultPaginationWrapStyle = {
|
|
387
|
+
display: "flex",
|
|
388
|
+
justifyContent: "flex-end",
|
|
389
|
+
alignItems: "center",
|
|
390
|
+
margin: "20px"
|
|
391
|
+
};
|
|
392
|
+
watch(() => toValue(params), () => {
|
|
393
|
+
executeRequest();
|
|
394
|
+
}, { deep: true });
|
|
395
|
+
watch(() => [pageInfo.currentPage, pageInfo.pageSize], () => {
|
|
396
|
+
executeRequest();
|
|
397
|
+
});
|
|
398
|
+
const tableData = computed(() => {
|
|
399
|
+
if (paginationConfig) {
|
|
400
|
+
var _asyncRequestData$val;
|
|
401
|
+
return ((_asyncRequestData$val = asyncRequestData.value) === null || _asyncRequestData$val === void 0 ? void 0 : _asyncRequestData$val.data) || [];
|
|
402
|
+
}
|
|
403
|
+
return asyncRequestData.value || data || [];
|
|
404
|
+
});
|
|
405
|
+
const tableTotal = computed(() => {
|
|
406
|
+
var _asyncRequestData$val2;
|
|
407
|
+
return ((_asyncRequestData$val2 = asyncRequestData.value) === null || _asyncRequestData$val2 === void 0 ? void 0 : _asyncRequestData$val2.total) || 0;
|
|
408
|
+
});
|
|
409
|
+
const renderTable = () => {
|
|
410
|
+
return withDirectives(h(ElTable, {
|
|
301
411
|
...rest,
|
|
302
|
-
...props
|
|
412
|
+
...props,
|
|
413
|
+
data: tableData.value
|
|
303
414
|
}, {
|
|
304
415
|
default: () => {
|
|
305
416
|
const tableNodes = [];
|
|
@@ -309,9 +420,48 @@ function useTable(options) {
|
|
|
309
420
|
},
|
|
310
421
|
append: slots === null || slots === void 0 ? void 0 : slots.append,
|
|
311
422
|
empty: slots === null || slots === void 0 ? void 0 : slots.empty
|
|
312
|
-
});
|
|
423
|
+
}), [[vLoading, loading.value]]);
|
|
424
|
+
};
|
|
425
|
+
const renderPagination = () => {
|
|
426
|
+
return h("div", { style: paginationConfig === true ? defaultPaginationWrapStyle : (paginationConfig === null || paginationConfig === void 0 ? void 0 : paginationConfig.wrapStyle) || defaultPaginationWrapStyle }, [h(ElPagination, {
|
|
427
|
+
"currentPage": pageInfo.currentPage,
|
|
428
|
+
"pageSize": pageInfo.pageSize,
|
|
429
|
+
"total": tableTotal.value,
|
|
430
|
+
...paginationConfig === true ? {} : paginationConfig,
|
|
431
|
+
"layout": paginationConfig === true ? defaultPaginationLayout : (paginationConfig === null || paginationConfig === void 0 ? void 0 : paginationConfig.layout) || defaultPaginationLayout,
|
|
432
|
+
"onUpdate:currentPage": (val) => {
|
|
433
|
+
pageInfo.currentPage = val;
|
|
434
|
+
},
|
|
435
|
+
"onUpdate:pageSize": (val) => {
|
|
436
|
+
pageInfo.pageSize = val;
|
|
437
|
+
}
|
|
438
|
+
})]);
|
|
439
|
+
};
|
|
440
|
+
function renderSearchForm() {
|
|
441
|
+
return h(SearchForm, {}, { footer: () => {
|
|
442
|
+
return h(ElFormItem, {}, () => [h(ElButton, {
|
|
443
|
+
type: "default",
|
|
444
|
+
size: (searchFormConfig === null || searchFormConfig === void 0 ? void 0 : searchFormConfig.size) || "small",
|
|
445
|
+
onClick: handleReset
|
|
446
|
+
}, () => "Reset"), h(ElButton, {
|
|
447
|
+
type: "primary",
|
|
448
|
+
size: (searchFormConfig === null || searchFormConfig === void 0 ? void 0 : searchFormConfig.size) || "small",
|
|
449
|
+
onClick: handleSearch
|
|
450
|
+
}, () => "Search")]);
|
|
451
|
+
} });
|
|
452
|
+
}
|
|
453
|
+
function renderTableWrapChildNodes() {
|
|
454
|
+
const childNodes = [];
|
|
455
|
+
if (searchFormConfig) childNodes.push(renderSearchForm());
|
|
456
|
+
if (slots === null || slots === void 0 ? void 0 : slots.header) childNodes.push(slots.header());
|
|
457
|
+
childNodes.push(renderTable());
|
|
458
|
+
if (paginationConfig) childNodes.push(renderPagination());
|
|
459
|
+
return childNodes;
|
|
460
|
+
}
|
|
461
|
+
return () => {
|
|
462
|
+
return h("div", { style: { ...tableWrapStyle || {} } }, renderTableWrapChildNodes());
|
|
313
463
|
};
|
|
314
464
|
})];
|
|
315
465
|
}
|
|
316
466
|
//#endregion
|
|
317
|
-
export { setDeepProperty, useAsyncConfirm, useForm, useMessage, useTable };
|
|
467
|
+
export { setDeepProperty, useAsyncConfirm, useDialog, useForm, useMessage, useTable };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuetkit/components",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"description": "Collection of business development components for Vue3 projects",
|
|
6
6
|
"author": "Kalu5",
|
|
7
7
|
"license": "MIT",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"vue": "^3.5.35"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@vuetkit/
|
|
24
|
+
"@vuetkit/core": "0.0.12",
|
|
25
|
+
"@vuetkit/shared": "0.0.12"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsdown --config-loader tsx"
|