@peng_kai/kit 0.0.10 → 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.
@@ -11,8 +11,8 @@ const emits = defineEmits<{
11
11
  </script>
12
12
 
13
13
  <template>
14
- <div class="flex w-min">
15
- <AButton class="mr-2 filter-btn" type="primary" :loading="props.loading" @click="emits('filter')">
14
+ <div class="flex-none flex w-min ml-auto">
15
+ <AButton class="mr-2 filter-btn" type="primary" htmlType="submit" :loading="props.loading" @click="emits('filter')">
16
16
  查询
17
17
  </AButton>
18
18
  <AButton :disabled="props.loading" @click="emits('reset')">
@@ -1,4 +1,5 @@
1
1
  export { default as FilterDrawer } from './FilterDrawer.vue'
2
2
  export { default as FilterReset } from './FilterReset.vue'
3
3
  export { default as FilterParam, paramTypes} from './FilterParam.vue'
4
- export { useFilterParams } from './useFilterParams'
4
+ export { useFilterParams } from './useFilterParams'
5
+ export { useFilterInfiniteQuery, useFilterPaginationQuery } from './useFilterQuery'
@@ -1,14 +1,15 @@
1
1
  import { extendRef } from '@vueuse/core'
2
2
  import { reactive } from "vue";
3
3
 
4
- const defaultPageParams: any = { page: 1, page_size: 10 }
4
+ type PageParams = { page?: string | number; page_size?: string | number }
5
+ const defaultPageParams: PageParams = { page: 1, page_size: 10 }
5
6
 
6
7
  export function useFilterParams<R extends Api.Request, AP extends Api.GetParam<R>, BP extends AP>(
7
8
  _api: R,
8
9
  buildParams: () => BP,
9
- pageParams: Pick<AP, 'page' | 'page_size'> = defaultPageParams,
10
+ pageParams = defaultPageParams,
10
11
  ) {
11
- const params = reactive({ ...pageParams, ...buildParams() } as AP & BP)
12
+ const params = reactive({ ...pageParams, ...buildParams() } as AP & BP & PageParams)
12
13
  const update = (newParams?: Partial<AP>) => {
13
14
  Object.assign(params, { ...buildParams(), ...newParams })
14
15
  }
@@ -0,0 +1,31 @@
1
+ import { useFilterParams } from './useFilterParams'
2
+ import { useInfiniteQuery, useQuery } from '@tanstack/vue-query'
3
+
4
+ /**
5
+
6
+ */
7
+ export function useFilterPaginationQuery<Api extends Api.Request, P extends Api.GetParam<Api>>(apiFn: Api, paramsFn: () => P) {
8
+ type Data = Api.GetData<Api>
9
+
10
+ const filterParams = useFilterParams(apiFn, paramsFn)
11
+ const filterQuery = useQuery({
12
+ keepPreviousData: true,
13
+ queryKey: [apiFn.id, 'pagination', filterParams],
14
+ queryFn: () => (apiFn(filterParams) as Promise<Data>),
15
+ })
16
+
17
+ return [filterQuery, filterParams] as const
18
+ }
19
+
20
+ export function useFilterInfiniteQuery<Api extends Api.Request, P extends Api.GetParam<Api>>(apiFn: Api, paramsFn: () => P) {
21
+ type Data = Api.GetData<Api>
22
+
23
+ const filterParams = useFilterParams(apiFn, paramsFn)
24
+ const filterQuery = useInfiniteQuery({
25
+ keepPreviousData: true,
26
+ queryKey: [apiFn.id, 'infinite', filterParams],
27
+ queryFn: ctx => (apiFn({ ...filterParams, ...ctx.pageParam }) as Promise<Data>),
28
+ })
29
+
30
+ return [filterQuery, filterParams] as const
31
+ }
@@ -0,0 +1,108 @@
1
+ /*
2
+ 通过为 antd 组件添加 class 的方式覆盖其默认样式
3
+ 格式:antd-cover__xxx
4
+ */
5
+
6
+ // 表单气泡 help 提示
7
+ .ant-form.antd-cover__bubble-help-form {
8
+ .ant-form-show-help {
9
+ position: relative;
10
+
11
+ + div {
12
+ display: none;
13
+ }
14
+
15
+ > div {
16
+ position: absolute;
17
+ z-index: 2;
18
+ top: 7px;
19
+ left: -10px;
20
+ max-width: 70%;
21
+ box-sizing: border-box;
22
+ padding: 6px 8px;
23
+ border-radius: 5px;
24
+ background-color: rgb(0 0 0 / 75%);
25
+
26
+ // box-shadow: 0 0 5px 0 rgb(0 0 0 / 50%);
27
+ color: #fff !important;
28
+ filter: drop-shadow(0 0 5px rgb(0 0 0 / 50%));
29
+ line-height: 1.4em;
30
+ pointer-events: none;
31
+
32
+ // 气泡箭头
33
+ &::after {
34
+ position: absolute;
35
+ top: -7.7px;
36
+ left: 10px;
37
+ width: 16px;
38
+ height: 16px;
39
+ background-color: rgb(0 0 0 / 75%);
40
+ clip-path: path('M 0 8 A 4 4 0 0 0 2.82842712474619 6.82842712474619 L 6.585786437626905 3.0710678118654755 A 2 2 0 0 1 9.414213562373096 3.0710678118654755 L 13.17157287525381 6.82842712474619 A 4 4 0 0 0 16 8 Z');
41
+ content: "";
42
+ }
43
+ }
44
+ }
45
+
46
+ .ant-form-margin-offset {
47
+ display: none;
48
+ }
49
+ }
50
+
51
+ // 弹窗的基本款样式
52
+ .ant-modal-wrap.antd-cover__basic-modal {
53
+ --padding-size: 22px;
54
+
55
+ // --min-body-height: ;
56
+ // --max-body-height: ;
57
+ // --body-height: ;
58
+
59
+ .ant-modal-content {
60
+ padding: 0;
61
+ }
62
+
63
+ .ant-modal-header {
64
+ display: flex;
65
+ min-height: 56px;
66
+ align-items: center;
67
+ padding: 0 var(--padding-size);
68
+ border-bottom: 1px solid var(--antd-colorBorderSecondary);
69
+ margin: 0;
70
+ }
71
+
72
+ .ant-modal-body {
73
+ height: var(--body-height, auto);
74
+ min-height: var(--min-body-height, auto);
75
+ max-height: var(--max-body-height, auto);
76
+ padding: var(--padding-size);
77
+ overflow-y: auto;
78
+
79
+ &:empty {
80
+ height: var(--min-body-height, 150px);
81
+ }
82
+ }
83
+
84
+ .ant-modal-footer {
85
+ display: flex;
86
+ min-height: 56px;
87
+ align-items: center;
88
+ justify-content: center;
89
+ padding: 0 var(--padding-size);
90
+ border-top: 1px solid var(--antd-colorBorderSecondary);
91
+ margin: 0;
92
+ }
93
+ }
94
+
95
+ // 查询器基本样式
96
+ .ant-form.ant-form__filter {
97
+ display: flex;
98
+ flex-wrap: wrap;
99
+ --uno: 'gap-4 mb-4';
100
+
101
+ .ant-form-item {
102
+ margin-bottom: 0;
103
+ min-width: 220px;
104
+ width: 250px;
105
+ max-width: 280px;
106
+ flex: 1 1 auto;
107
+ }
108
+ }
@@ -0,0 +1,43 @@
1
+ :root {
2
+ // table 组件头部圆角设为 0
3
+ .ant-table-wrapper {
4
+ .ant-table .ant-table-header,
5
+ table,
6
+ .ant-table-container table > thead > tr:first-child > *:first-child,
7
+ .ant-table-container table > thead > tr:first-child > *:last-child {
8
+ border-radius: 0;
9
+ }
10
+
11
+ .ant-pagination {
12
+ margin-bottom: 0;
13
+ }
14
+ }
15
+
16
+
17
+ // 隐藏在 sticky 模式下的滚动条
18
+ .ant-table-sticky-scroll {
19
+ display: none;
20
+ }
21
+
22
+ // 卡片
23
+ .ant-card .ant-card-actions > li > span {
24
+ cursor: inherit;
25
+ }
26
+
27
+ // Tab 溢出出现下列框时
28
+ .ant-tabs-dropdown-menu-title-content {
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: space-between;
32
+ }
33
+
34
+ // 表格
35
+ .ant-table-wrapper {
36
+ .ant-table-row-expand-icon-collapsed::before {
37
+ height: 1.5px;
38
+ }
39
+ .ant-table-row-expand-icon-collapsed::after {
40
+ width: 1.5px;
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,30 @@
1
+ @import './classCover.scss';
2
+ @import './globalCover.scss';
3
+
4
+ @media (pointer: fine) {
5
+ * {
6
+ scrollbar-color: rgb(0 0 0 / 50%) transparent;
7
+ scrollbar-width: thin;
8
+
9
+ /* overflow-y: overlay; */
10
+ }
11
+
12
+ ::-webkit-scrollbar {
13
+ width: 6px;
14
+ height: 6px;
15
+ background-color: transparent;
16
+ }
17
+
18
+ ::-webkit-scrollbar-thumb {
19
+ border-radius: 10px;
20
+ background-color: rgb(0 0 0 / 20%);
21
+ }
22
+
23
+ ::-webkit-scrollbar-thumb:hover {
24
+ background-color: rgb(0 0 0 / 60%);
25
+ }
26
+ }
27
+
28
+ :root {
29
+ font-family: var(--antd-fontFamily);
30
+ }
@@ -0,0 +1,6 @@
1
+ export const shortcuts = [
2
+ // 页面板块
3
+ ['page-section', 'p-4 bg-$antd-colorBgContainer'],
4
+ // 用于 FormItem 在 flex布局下的自适应
5
+ [/^fiw-(.*?)_(.*?)_(.*?)$/, ([, w1, w2, w3]) => `min-w-${w1} w-${w2} max-w-${w3} flex-auto`],
6
+ ]
@@ -5,9 +5,13 @@ import type { ComputedRef, UnwrapRef } from 'vue'
5
5
  import { GROUP_SEP, buildGroupFieldName, getGroupIndex } from './useAntdForm.helpers'
6
6
 
7
7
  export { useAntdForm }
8
- export type { TField }
8
+ export type { TField, RecordToSchemas }
9
9
 
10
- function useAntdForm<F extends Record<string, TField>, S extends GetFormState<F>, STF = S>(
10
+ function useAntdForm<
11
+ F extends Record<string, TField>,
12
+ S extends GetFormState<F>,
13
+ STF = S
14
+ >(
11
15
  schemas: F,
12
16
  _options?: {
13
17
  transform?: (state: S) => STF
@@ -82,10 +86,15 @@ function useAntdForm<F extends Record<string, TField>, S extends GetFormState<F>
82
86
  }
83
87
  }
84
88
 
85
- interface TField {
86
- value: any
89
+ interface TField<V = any> {
90
+ value: V
87
91
  rules?: RuleObject[]
88
92
  }
93
+
94
+ type RecordToSchemas<T extends Record<string, unknown>> = {
95
+ [K in keyof T]: TField<T[K]>
96
+ }
97
+
89
98
  type GetFormState<C extends Record<string, TField>> = {
90
99
  [K in keyof C]: UnwrapRef<C[K]['value']>;
91
- }
100
+ }
@@ -7,7 +7,7 @@ import type { ComponentProps } from 'vue-component-type-helpers'
7
7
  export function useAntdTable<
8
8
  UQRR extends UseQueryReturnType<any, any>,
9
9
  QP extends Partial<{ page?: string | number; page_size?: string | number }>,
10
- >(uqrt: UQRR, queryParams: QP) {
10
+ >(uqrt: UQRR, queryParams: QP = ({} as any)) {
11
11
  type RecordType = GetRecordType<UQRR>
12
12
  type LocalTableProps = TableProps<RecordType>
13
13
  type LocalColumnsType = NonNullable<LocalTableProps['columns']>
package/antd/index.ts CHANGED
@@ -4,4 +4,4 @@ export { useAntdTable } from './hooks/useAntdTable'
4
4
  export { useAntdForm } from './hooks/useAntdForm'
5
5
  export { createAntdModal } from './hooks/createAntdModal'
6
6
  export { default as InputNumberRange } from './components/InputNumberRange.vue'
7
- export type { TField } from './hooks/useAntdForm.ts'
7
+ export type { TField, RecordToSchemas } from './hooks/useAntdForm.ts'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/request/type.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  declare namespace Api {
2
- type Request = (reqData: any, options?: Options) => Promise<any>
2
+ type Request = ((reqData: any, options?: Options) => Promise<any>) & { id: string }
3
3
  // type RequestPagination = (reqData: Partial<PageParam>, options?: Options) => Promise<PaginationData<any>>;
4
4
  interface PageParam {
5
5
  page: number