gi-component 0.0.4 → 0.0.5
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/index.d.ts +59 -5
- package/dist/index.es.js +62 -3
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/packages/components/table/src/TableColumn.vue +4 -11
- package/packages/components/table/src/type.ts +4 -4
- package/packages/hooks/index.ts +1 -0
- package/packages/hooks/useTable.ts +90 -1
- package/packages/index.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ import { PublicProps } from 'vue';
|
|
|
20
20
|
import { Ref } from 'vue';
|
|
21
21
|
import { Slots } from 'vue';
|
|
22
22
|
import { SplitterPanelProps } from 'element-plus';
|
|
23
|
-
import { TableColumnCtx } from 'element-plus';
|
|
24
23
|
import { TableColumnInstance } from 'element-plus';
|
|
25
24
|
import { TableProps as TableProps_2 } from 'element-plus';
|
|
26
25
|
import { TabPaneName } from 'element-plus';
|
|
@@ -257,6 +256,15 @@ declare type __VLS_WithTemplateSlots_6<T, S> = T & {
|
|
|
257
256
|
};
|
|
258
257
|
};
|
|
259
258
|
|
|
259
|
+
declare type Api<T> = (params: PaginationParams) => Promise<ApiResult<PageResult<T[]>>> | Promise<ApiResult<T[]>>;
|
|
260
|
+
|
|
261
|
+
declare interface ApiResult<T> {
|
|
262
|
+
code: number;
|
|
263
|
+
data: T;
|
|
264
|
+
message: string;
|
|
265
|
+
success: boolean;
|
|
266
|
+
}
|
|
267
|
+
|
|
260
268
|
declare interface ButtonProps extends Partial<Omit<ButtonProps_2, 'type'>> {
|
|
261
269
|
type?: 'add' | 'edit' | 'delete' | 'search' | 'reset' | 'upload' | 'download' | 'print' | '' | ButtonProps_2['type'];
|
|
262
270
|
}
|
|
@@ -509,6 +517,8 @@ suffix: boolean;
|
|
|
509
517
|
|
|
510
518
|
declare const _default_9: __VLS_WithTemplateSlots_5<typeof __VLS_component_5, __VLS_TemplateResult_5["slots"]>;
|
|
511
519
|
|
|
520
|
+
declare type DefaultRow = Record<PropertyKey, any>;
|
|
521
|
+
|
|
512
522
|
declare interface DefOption {
|
|
513
523
|
queryParams: Record<string, any>;
|
|
514
524
|
}
|
|
@@ -672,6 +682,12 @@ declare interface InputSearchProps {
|
|
|
672
682
|
|
|
673
683
|
declare const model: ModelRef<string | undefined, string, string | undefined, string | undefined>;
|
|
674
684
|
|
|
685
|
+
declare interface Options<T, U> {
|
|
686
|
+
onSuccess?: () => void;
|
|
687
|
+
immediate?: boolean;
|
|
688
|
+
rowKey?: keyof T;
|
|
689
|
+
}
|
|
690
|
+
|
|
675
691
|
declare interface PageLayoutProps {
|
|
676
692
|
size?: SplitterPanelProps['size'];
|
|
677
693
|
bordered?: boolean;
|
|
@@ -682,6 +698,16 @@ declare interface PageLayoutProps {
|
|
|
682
698
|
bodyStyle?: CSSProperties;
|
|
683
699
|
}
|
|
684
700
|
|
|
701
|
+
declare interface PageResult<T> {
|
|
702
|
+
list: T[];
|
|
703
|
+
total: number;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
declare interface PaginationParams {
|
|
707
|
+
page: number;
|
|
708
|
+
size: number;
|
|
709
|
+
}
|
|
710
|
+
|
|
685
711
|
declare interface ResponsiveValue {
|
|
686
712
|
/**
|
|
687
713
|
* @zh >= 1600px 响应式配置
|
|
@@ -715,10 +741,15 @@ declare interface ResponsiveValue {
|
|
|
715
741
|
xs?: number;
|
|
716
742
|
}
|
|
717
743
|
|
|
718
|
-
export declare interface TableColumnItem extends Omit<TableColumnInstance['$props'], never> {
|
|
744
|
+
export declare interface TableColumnItem<T extends DefaultRow = DefaultRow> extends Omit<TableColumnInstance['$props'], never> {
|
|
719
745
|
slotName?: string;
|
|
720
746
|
children?: TableColumnItem[];
|
|
721
|
-
render?: (scope:
|
|
747
|
+
render?: (scope: {
|
|
748
|
+
$index: number;
|
|
749
|
+
cellIndex: number;
|
|
750
|
+
column: TableColumnItem<T>;
|
|
751
|
+
row: T;
|
|
752
|
+
}) => VNode | VNode[] | string;
|
|
722
753
|
}
|
|
723
754
|
|
|
724
755
|
export declare type TableInstance = InstanceType<typeof default_4>;
|
|
@@ -728,13 +759,15 @@ export declare interface TableProps extends ExtractPropTypes<TableProps_2<Record
|
|
|
728
759
|
pagination?: Partial<PaginationProps>;
|
|
729
760
|
}
|
|
730
761
|
|
|
731
|
-
declare type
|
|
762
|
+
export declare type TabsInstance = InstanceType<typeof _default_4>;
|
|
763
|
+
|
|
764
|
+
export declare type TabsOptionItem = {
|
|
732
765
|
label: string;
|
|
733
766
|
name: string;
|
|
734
767
|
disabled?: boolean;
|
|
735
768
|
};
|
|
736
769
|
|
|
737
|
-
declare interface TabsProps extends Partial<Pick<TabsProps_2, 'type' | 'stretch'>> {
|
|
770
|
+
export declare interface TabsProps extends Partial<Pick<TabsProps_2, 'type' | 'stretch'>> {
|
|
738
771
|
type?: TabsProps_2['type'];
|
|
739
772
|
options?: TabsOptionItem[];
|
|
740
773
|
size?: 'small' | 'medium';
|
|
@@ -745,6 +778,27 @@ export declare function useBemClass(): {
|
|
|
745
778
|
b: (name?: string) => string;
|
|
746
779
|
};
|
|
747
780
|
|
|
781
|
+
export declare function useTable<T extends U, U = T>(api: Api<T>, options: Options<T, U>): {
|
|
782
|
+
/** 表格数据 */
|
|
783
|
+
tableData: Ref<U[], U[]>;
|
|
784
|
+
/** 获取表格数据 */
|
|
785
|
+
getTableData: () => Promise<void>;
|
|
786
|
+
/** 分页数据 */
|
|
787
|
+
pagination: {
|
|
788
|
+
currentPage: number;
|
|
789
|
+
pageSize: number;
|
|
790
|
+
total: number;
|
|
791
|
+
onCurrentChange: (size: number) => void;
|
|
792
|
+
onSizeChange: (size: number) => void;
|
|
793
|
+
};
|
|
794
|
+
/** 加载状态 */
|
|
795
|
+
loading: Ref<boolean, boolean>;
|
|
796
|
+
/** 搜索 */
|
|
797
|
+
search: () => void;
|
|
798
|
+
/** 刷新 */
|
|
799
|
+
refresh: () => void;
|
|
800
|
+
};
|
|
801
|
+
|
|
748
802
|
declare const visible: ModelRef<boolean, string, boolean, boolean>;
|
|
749
803
|
|
|
750
804
|
export { }
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, createElementBlock, openBlock, createElementVNode, getCurrentInstance, useAttrs, computed, resolveComponent, createBlock, mergeProps, unref, withCtx, renderSlot, createTextVNode, toDisplayString, useSlots, normalizeClass, createCommentVNode, normalizeStyle, mergeModels, useModel,
|
|
1
|
+
import { defineComponent, createElementBlock, openBlock, createElementVNode, getCurrentInstance, ref, reactive, useAttrs, computed, resolveComponent, createBlock, mergeProps, unref, withCtx, renderSlot, createTextVNode, toDisplayString, useSlots, normalizeClass, createCommentVNode, normalizeStyle, mergeModels, useModel, createSlots, resolveDynamicComponent, createVNode, createApp, h, Fragment, renderList, watch, onMounted, onUpdated, onUnmounted, inject, toRefs, watchEffect, provide, toRaw, normalizeProps, guardReactiveProps, useTemplateRef } from "vue";
|
|
2
2
|
import * as El from "element-plus";
|
|
3
3
|
import El__default, { ElMessage } from "element-plus";
|
|
4
4
|
/*! Element Plus Icons Vue v2.3.2 */
|
|
@@ -194,6 +194,62 @@ function useBemClass() {
|
|
|
194
194
|
const b = (name = "") => `${prefix}-${name ? `${name}` : ""}`;
|
|
195
195
|
return { b };
|
|
196
196
|
}
|
|
197
|
+
function useTable(api, options) {
|
|
198
|
+
const { onSuccess, immediate = true, rowKey = "id" } = options || {};
|
|
199
|
+
const loading = ref(false);
|
|
200
|
+
const tableData = ref([]);
|
|
201
|
+
const pagination = reactive({
|
|
202
|
+
currentPage: 1,
|
|
203
|
+
pageSize: 20,
|
|
204
|
+
total: 0,
|
|
205
|
+
onCurrentChange: (size) => {
|
|
206
|
+
pagination.currentPage = size;
|
|
207
|
+
getTableData();
|
|
208
|
+
},
|
|
209
|
+
onSizeChange: (size) => {
|
|
210
|
+
pagination.pageSize = size;
|
|
211
|
+
getTableData();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
function setTotal(total) {
|
|
215
|
+
pagination.total = total;
|
|
216
|
+
}
|
|
217
|
+
async function getTableData() {
|
|
218
|
+
try {
|
|
219
|
+
loading.value = true;
|
|
220
|
+
const res = await api({ page: pagination.currentPage, size: pagination.pageSize });
|
|
221
|
+
const data = !Array.isArray(res.data) ? res.data.list : res.data;
|
|
222
|
+
tableData.value = data;
|
|
223
|
+
const total = !Array.isArray(res.data) ? res.data.total : data.length;
|
|
224
|
+
setTotal(total);
|
|
225
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
226
|
+
} finally {
|
|
227
|
+
loading.value = false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
immediate && getTableData();
|
|
231
|
+
function search() {
|
|
232
|
+
pagination.currentPage = 1;
|
|
233
|
+
getTableData();
|
|
234
|
+
}
|
|
235
|
+
function refresh() {
|
|
236
|
+
getTableData();
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
/** 表格数据 */
|
|
240
|
+
tableData,
|
|
241
|
+
/** 获取表格数据 */
|
|
242
|
+
getTableData,
|
|
243
|
+
/** 分页数据 */
|
|
244
|
+
pagination,
|
|
245
|
+
/** 加载状态 */
|
|
246
|
+
loading,
|
|
247
|
+
/** 搜索 */
|
|
248
|
+
search,
|
|
249
|
+
/** 刷新 */
|
|
250
|
+
refresh
|
|
251
|
+
};
|
|
252
|
+
}
|
|
197
253
|
const _sfc_main$d = /* @__PURE__ */ defineComponent({
|
|
198
254
|
__name: "button",
|
|
199
255
|
props: {
|
|
@@ -1928,7 +1984,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
1928
1984
|
_ctx.column.render ? {
|
|
1929
1985
|
name: "default",
|
|
1930
1986
|
fn: withCtx((scope) => [
|
|
1931
|
-
|
|
1987
|
+
typeof _ctx.column.render(scope) === "string" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
1988
|
+
createTextVNode(toDisplayString(_ctx.column.render(scope)), 1)
|
|
1989
|
+
], 64)) : (openBlock(), createBlock(resolveDynamicComponent(_ctx.column.render(scope)), { key: 1 }))
|
|
1932
1990
|
]),
|
|
1933
1991
|
key: "0"
|
|
1934
1992
|
} : _ctx.column.slotName ? {
|
|
@@ -2246,6 +2304,7 @@ export {
|
|
|
2246
2304
|
createDialog,
|
|
2247
2305
|
createSelectDialog,
|
|
2248
2306
|
index as default,
|
|
2249
|
-
useBemClass
|
|
2307
|
+
useBemClass,
|
|
2308
|
+
useTable
|
|
2250
2309
|
};
|
|
2251
2310
|
//# sourceMappingURL=index.es.js.map
|