@vuetkit/components 0.0.9 → 0.0.11
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 +4 -0
- package/dist/index.d.ts +29 -3
- package/dist/index.js +155 -5
- package/package.json +3 -2
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RequestService } from "@vuetkit/core";
|
|
2
|
-
import { ComponentSize, FormRules, MessageProps, MessageType } from "element-plus";
|
|
3
|
-
import { Component } from "vue";
|
|
2
|
+
import { ComponentSize, 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 {
|
|
@@ -76,6 +77,31 @@ type FormReturnType<T extends object> = [Component, {
|
|
|
76
77
|
setData: (newData: T) => void;
|
|
77
78
|
}];
|
|
78
79
|
declare function setDeepProperty(data: Recordable, propArr: string[], value: unknown): void;
|
|
80
|
+
declare function useForm(options: undefined): [null, Recordable];
|
|
79
81
|
declare function useForm<T extends object>(options: FormOptions<T>): FormReturnType<T>;
|
|
80
82
|
//#endregion
|
|
81
|
-
|
|
83
|
+
//#region src/table/useTable/index.d.ts
|
|
84
|
+
type DefaultRow = Record<PropertyKey, any>;
|
|
85
|
+
interface TableColumnOptions<T extends DefaultRow> extends TableColumnProps<T> {
|
|
86
|
+
render?: (row: T) => VNode | string;
|
|
87
|
+
children?: TableColumnOptions<T>[];
|
|
88
|
+
prop?: string;
|
|
89
|
+
}
|
|
90
|
+
interface PaginationOptions extends Partial<PaginationProps> {
|
|
91
|
+
wrapStyle?: CSSProperties;
|
|
92
|
+
}
|
|
93
|
+
interface TableOptions<T extends DefaultRow> extends TableProps<T> {
|
|
94
|
+
columns: TableColumnOptions<T>[];
|
|
95
|
+
service?: RequestService;
|
|
96
|
+
params?: MaybeRef<unknown> | unknown;
|
|
97
|
+
formatData?: (res: unknown) => T[];
|
|
98
|
+
align?: 'left' | 'center' | 'right';
|
|
99
|
+
headerAlign?: 'left' | 'center' | 'right';
|
|
100
|
+
paginationConfig?: boolean | PaginationOptions;
|
|
101
|
+
tableWrapStyle?: CSSProperties;
|
|
102
|
+
searchFormConfig?: FormOptions<T>;
|
|
103
|
+
}
|
|
104
|
+
type TableReturn = [Component];
|
|
105
|
+
declare function useTable<T extends DefaultRow>(options: TableOptions<T>): TableReturn;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { AsyncConfirmOptions, CustomRender, DefaultComponentKey, FormItemType, FormOptions, FormReturnType, FormRuleFn, FormSchema, PaginationOptions, Recordable, TableColumnOptions, TableOptions, TableReturn, setDeepProperty, useAsyncConfirm, 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, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect, ElUpload } from "element-plus";
|
|
3
|
-
import { isFunc } from "@vuetkit/shared";
|
|
4
|
-
import { computed, defineComponent, h, nextTick, onMounted, ref, useTemplateRef } from "vue";
|
|
2
|
+
import { ElButton, ElCascader, ElCheckbox, ElCol, ElColorPicker, ElDatePicker, ElForm, ElFormItem, ElInput, ElInputNumber, ElInputOtp, ElMention, ElMessage, ElMessageBox, ElPagination, ElRadio, ElRate, ElRow, ElSelect, ElSelectV2, ElSlider, ElSwitch, ElTable, ElTableColumn, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect, ElUpload, vLoading } from "element-plus";
|
|
3
|
+
import { isFunc, realObj } from "@vuetkit/shared";
|
|
4
|
+
import { computed, defineComponent, h, nextTick, onMounted, reactive, ref, toValue, useTemplateRef, watch, withDirectives } from "vue";
|
|
5
5
|
//#region src/feedback/useMessage/index.ts
|
|
6
6
|
const DEFAULT_DURATION = 3e3;
|
|
7
7
|
const DEFAULT_SHOW_CLOSE = true;
|
|
@@ -112,7 +112,9 @@ function setDeepProperty(data, propArr, value) {
|
|
|
112
112
|
temp[propArr[propArr.length - 1]] = value;
|
|
113
113
|
}
|
|
114
114
|
function useForm(options) {
|
|
115
|
-
|
|
115
|
+
var _options$schemas;
|
|
116
|
+
if (!options || !((_options$schemas = options.schemas) === null || _options$schemas === void 0 ? void 0 : _options$schemas.length)) return [null, {}];
|
|
117
|
+
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
118
|
const components = {};
|
|
117
119
|
if (customComponent) Object.assign(components, defaultComponent, customComponent);
|
|
118
120
|
else Object.assign(components, defaultComponent);
|
|
@@ -270,4 +272,152 @@ function useForm(options) {
|
|
|
270
272
|
}];
|
|
271
273
|
}
|
|
272
274
|
//#endregion
|
|
273
|
-
|
|
275
|
+
//#region src/table/useTable/index.ts
|
|
276
|
+
function useTable(options) {
|
|
277
|
+
const { columns = [], service, params, formatData, align, headerAlign, paginationConfig, searchFormConfig, tableWrapStyle = {}, data = [], ...rest } = options;
|
|
278
|
+
if ((paginationConfig || searchFormConfig) && !realObj(toValue(params))) throw new Error("params must be an object when paginationConfig or searchFormConfig is provided");
|
|
279
|
+
return [defineComponent((props, { slots }) => {
|
|
280
|
+
const pageInfo = reactive({
|
|
281
|
+
pageSize: 10,
|
|
282
|
+
currentPage: 1
|
|
283
|
+
});
|
|
284
|
+
const [SearchForm, { reset, getData }] = searchFormConfig ? useForm(searchFormConfig) : [null, {
|
|
285
|
+
reset: () => {},
|
|
286
|
+
getData: () => ({})
|
|
287
|
+
}];
|
|
288
|
+
const requestParams = computed(() => {
|
|
289
|
+
if (paginationConfig) return {
|
|
290
|
+
...toValue(params) || {},
|
|
291
|
+
...searchFormConfig ? (getData === null || getData === void 0 ? void 0 : getData()) || {} : {},
|
|
292
|
+
currentPage: pageInfo.currentPage,
|
|
293
|
+
pageSize: pageInfo.pageSize
|
|
294
|
+
};
|
|
295
|
+
if (searchFormConfig) return {
|
|
296
|
+
...toValue(params) || {},
|
|
297
|
+
...(getData === null || getData === void 0 ? void 0 : getData()) || {}
|
|
298
|
+
};
|
|
299
|
+
return toValue(params);
|
|
300
|
+
});
|
|
301
|
+
const { data: asyncRequestData, loading, execute } = useRequest(service, {
|
|
302
|
+
manual: false,
|
|
303
|
+
defaultParams: requestParams.value,
|
|
304
|
+
formatData
|
|
305
|
+
});
|
|
306
|
+
const renderTableItemNodes = (column) => {
|
|
307
|
+
var _column$children;
|
|
308
|
+
if (isFunc(column.render)) return { default: ({ row }) => column.render(row) };
|
|
309
|
+
const tableItemNodes = [];
|
|
310
|
+
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));
|
|
311
|
+
return tableItemNodes.length ? () => tableItemNodes : void 0;
|
|
312
|
+
};
|
|
313
|
+
const renderTableItem = (column) => {
|
|
314
|
+
const { align: columnAlign, headerAlign: columnHeaderAlign } = column;
|
|
315
|
+
const tableItemAlign = columnAlign || align || "left";
|
|
316
|
+
const tableItemHeaderAlign = columnHeaderAlign || headerAlign || "left";
|
|
317
|
+
return h(ElTableColumn, {
|
|
318
|
+
...column,
|
|
319
|
+
align: tableItemAlign,
|
|
320
|
+
headerAlign: tableItemHeaderAlign
|
|
321
|
+
}, renderTableItemNodes(column));
|
|
322
|
+
};
|
|
323
|
+
const renderTableItems = (columns) => {
|
|
324
|
+
return columns.filter(Boolean).map((column) => {
|
|
325
|
+
return renderTableItem(column);
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
function executeRequest() {
|
|
329
|
+
if (service) execute(requestParams.value);
|
|
330
|
+
}
|
|
331
|
+
onMounted(() => {
|
|
332
|
+
if (service) execute();
|
|
333
|
+
});
|
|
334
|
+
const handleReset = () => {
|
|
335
|
+
reset === null || reset === void 0 || reset();
|
|
336
|
+
executeRequest();
|
|
337
|
+
};
|
|
338
|
+
const handleSearch = () => {
|
|
339
|
+
executeRequest();
|
|
340
|
+
};
|
|
341
|
+
const defaultPaginationLayout = "total, sizes, prev, pager, next, jumper";
|
|
342
|
+
const defaultPaginationWrapStyle = {
|
|
343
|
+
display: "flex",
|
|
344
|
+
justifyContent: "flex-end",
|
|
345
|
+
alignItems: "center",
|
|
346
|
+
margin: "20px"
|
|
347
|
+
};
|
|
348
|
+
watch(() => toValue(params), () => {
|
|
349
|
+
executeRequest();
|
|
350
|
+
}, { deep: true });
|
|
351
|
+
watch(() => [pageInfo.currentPage, pageInfo.pageSize], () => {
|
|
352
|
+
executeRequest();
|
|
353
|
+
});
|
|
354
|
+
const tableData = computed(() => {
|
|
355
|
+
if (paginationConfig) {
|
|
356
|
+
var _asyncRequestData$val;
|
|
357
|
+
return ((_asyncRequestData$val = asyncRequestData.value) === null || _asyncRequestData$val === void 0 ? void 0 : _asyncRequestData$val.data) || [];
|
|
358
|
+
}
|
|
359
|
+
return asyncRequestData.value || data || [];
|
|
360
|
+
});
|
|
361
|
+
const tableTotal = computed(() => {
|
|
362
|
+
var _asyncRequestData$val2;
|
|
363
|
+
return ((_asyncRequestData$val2 = asyncRequestData.value) === null || _asyncRequestData$val2 === void 0 ? void 0 : _asyncRequestData$val2.total) || 0;
|
|
364
|
+
});
|
|
365
|
+
const renderTable = () => {
|
|
366
|
+
return withDirectives(h(ElTable, {
|
|
367
|
+
...rest,
|
|
368
|
+
...props,
|
|
369
|
+
data: tableData.value
|
|
370
|
+
}, {
|
|
371
|
+
default: () => {
|
|
372
|
+
const tableNodes = [];
|
|
373
|
+
if (columns.length) tableNodes.push(...renderTableItems(columns));
|
|
374
|
+
if (slots.actions) tableNodes.push(slots.actions());
|
|
375
|
+
return tableNodes;
|
|
376
|
+
},
|
|
377
|
+
append: slots === null || slots === void 0 ? void 0 : slots.append,
|
|
378
|
+
empty: slots === null || slots === void 0 ? void 0 : slots.empty
|
|
379
|
+
}), [[vLoading, loading.value]]);
|
|
380
|
+
};
|
|
381
|
+
const renderPagination = () => {
|
|
382
|
+
return h("div", { style: paginationConfig === true ? defaultPaginationWrapStyle : (paginationConfig === null || paginationConfig === void 0 ? void 0 : paginationConfig.wrapStyle) || defaultPaginationWrapStyle }, [h(ElPagination, {
|
|
383
|
+
"currentPage": pageInfo.currentPage,
|
|
384
|
+
"pageSize": pageInfo.pageSize,
|
|
385
|
+
"total": tableTotal.value,
|
|
386
|
+
...paginationConfig === true ? {} : paginationConfig,
|
|
387
|
+
"layout": paginationConfig === true ? defaultPaginationLayout : (paginationConfig === null || paginationConfig === void 0 ? void 0 : paginationConfig.layout) || defaultPaginationLayout,
|
|
388
|
+
"onUpdate:currentPage": (val) => {
|
|
389
|
+
pageInfo.currentPage = val;
|
|
390
|
+
},
|
|
391
|
+
"onUpdate:pageSize": (val) => {
|
|
392
|
+
pageInfo.pageSize = val;
|
|
393
|
+
}
|
|
394
|
+
})]);
|
|
395
|
+
};
|
|
396
|
+
function renderSearchForm() {
|
|
397
|
+
return h(SearchForm, {}, { footer: () => {
|
|
398
|
+
return h(ElFormItem, {}, () => [h(ElButton, {
|
|
399
|
+
type: "default",
|
|
400
|
+
size: (searchFormConfig === null || searchFormConfig === void 0 ? void 0 : searchFormConfig.size) || "small",
|
|
401
|
+
onClick: handleReset
|
|
402
|
+
}, () => "Reset"), h(ElButton, {
|
|
403
|
+
type: "primary",
|
|
404
|
+
size: (searchFormConfig === null || searchFormConfig === void 0 ? void 0 : searchFormConfig.size) || "small",
|
|
405
|
+
onClick: handleSearch
|
|
406
|
+
}, () => "Search")]);
|
|
407
|
+
} });
|
|
408
|
+
}
|
|
409
|
+
function renderTableWrapChildNodes() {
|
|
410
|
+
const childNodes = [];
|
|
411
|
+
if (searchFormConfig) childNodes.push(renderSearchForm());
|
|
412
|
+
if (slots === null || slots === void 0 ? void 0 : slots.header) childNodes.push(slots.header());
|
|
413
|
+
childNodes.push(renderTable());
|
|
414
|
+
if (paginationConfig) childNodes.push(renderPagination());
|
|
415
|
+
return childNodes;
|
|
416
|
+
}
|
|
417
|
+
return () => {
|
|
418
|
+
return h("div", { style: { ...tableWrapStyle || {} } }, renderTableWrapChildNodes());
|
|
419
|
+
};
|
|
420
|
+
})];
|
|
421
|
+
}
|
|
422
|
+
//#endregion
|
|
423
|
+
export { setDeepProperty, useAsyncConfirm, 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.11",
|
|
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.11",
|
|
25
|
+
"@vuetkit/shared": "0.0.11"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsdown --config-loader tsx"
|