@peng_kai/kit 0.0.8 → 0.0.10

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.
@@ -1,47 +1,47 @@
1
- <script setup lang="ts">
2
- import { computed } from "vue";
3
- import { Form, InputNumber as AInputNumber } from 'ant-design-vue'
4
-
5
- const props = withDefaults(
6
- defineProps<{
7
- value: [number, number]
8
- min?: number
9
- max?: number
10
- }>(),
11
- {
12
- min: Number.NEGATIVE_INFINITY,
13
- max: Number.POSITIVE_INFINITY,
14
- },
15
- )
16
- const emits = defineEmits<{
17
- (e: 'update:value', value: [number, number]): void
18
- }>()
19
-
20
- const formItemContext = Form.useInjectFormItemContext()
21
- const minValue = computed({
22
- get() {
23
- return props.value[0]
24
- },
25
- set(value) {
26
- emits('update:value', [value, props.value[1]])
27
- formItemContext.onFieldChange()
28
- },
29
- })
30
- const maxValue = computed({
31
- get() {
32
- return props.value[1]
33
- },
34
- set(value) {
35
- emits('update:value', [props.value[0], value])
36
- formItemContext.onFieldChange()
37
- },
38
- })
39
- </script>
40
-
41
- <template>
42
- <div class="flex items-center">
43
- <AInputNumber v-model:value="minValue" class="w-full" :min="props.min" :max="props.max" />
44
- <span>&nbsp;~&nbsp;</span>
45
- <AInputNumber v-model:value="maxValue" class="w-full" :min="props.min" :max="props.max" />
46
- </div>
47
- </template>
1
+ <script setup lang="ts">
2
+ import { computed } from "vue";
3
+ import { Form, InputNumber as AInputNumber } from 'ant-design-vue'
4
+
5
+ const props = withDefaults(
6
+ defineProps<{
7
+ value: [number, number]
8
+ min?: number
9
+ max?: number
10
+ }>(),
11
+ {
12
+ min: Number.NEGATIVE_INFINITY,
13
+ max: Number.POSITIVE_INFINITY,
14
+ },
15
+ )
16
+ const emits = defineEmits<{
17
+ (e: 'update:value', value: [number, number]): void
18
+ }>()
19
+
20
+ const formItemContext = Form.useInjectFormItemContext()
21
+ const minValue = computed({
22
+ get() {
23
+ return props.value[0]
24
+ },
25
+ set(value) {
26
+ emits('update:value', [value, props.value[1]])
27
+ formItemContext.onFieldChange()
28
+ },
29
+ })
30
+ const maxValue = computed({
31
+ get() {
32
+ return props.value[1]
33
+ },
34
+ set(value) {
35
+ emits('update:value', [props.value[0], value])
36
+ formItemContext.onFieldChange()
37
+ },
38
+ })
39
+ </script>
40
+
41
+ <template>
42
+ <div class="flex items-center">
43
+ <AInputNumber v-model:value="minValue" class="w-full" :min="props.min" :max="props.max" />
44
+ <span>&nbsp;~&nbsp;</span>
45
+ <AInputNumber v-model:value="maxValue" class="w-full" :min="props.min" :max="props.max" />
46
+ </div>
47
+ </template>
@@ -1,73 +1,73 @@
1
- import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue'
2
- import { defineComponent, isProxy, reactive, toRefs, toRef, h } from 'vue'
3
- import type { Component } from 'vue'
4
- import type { ButtonProps, DrawerProps } from 'ant-design-vue'
5
- import type { ComponentProps } from 'vue-component-type-helpers'
6
- import type { Writable } from 'type-fest'
7
- import { useComponentRef } from '../../vue'
8
-
9
- const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true }
10
-
11
- interface IComponentConfig<Comp extends Component> {
12
- is: Comp
13
- props?: Writable<ComponentProps<Comp>>
14
- }
15
-
16
- export function useAntdDrawer<Comp extends Component>(
17
- comp: IComponentConfig<Comp> | Comp,
18
- drawerProps = defaultDrawerProps,
19
- ) {
20
- const _comp = ({ props: {}, ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>
21
- const compProps = reactive(_comp.props)
22
- const compRef = useComponentRef(_comp.is)
23
- const _drawerProps: DrawerProps = reactive({
24
- ...defaultDrawerProps,
25
- ...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
26
- })
27
-
28
- const open = (newBodyProps?: Partial<typeof compProps>, newAntdModalProps?: Omit<Partial<DrawerProps>, 'open'>) => {
29
- Object.assign(_drawerProps, newAntdModalProps)
30
- Object.assign(compProps, newBodyProps)
31
- _drawerProps.open = true
32
- }
33
- const close = () => {
34
- _drawerProps.open = false
35
- }
36
-
37
- const DrawerExtra = defineComponent({
38
- setup() {
39
- const cancelBtnProps: ButtonProps = reactive({ onClick: close })
40
- const confirmBtnProps: ButtonProps = reactive({
41
- type: 'primary',
42
- loading: toRef(() => (compRef as any)?.loading),
43
- onClick: () => (compRef as any)?.confirm?.(),
44
- })
45
-
46
- return { cancelBtnProps, confirmBtnProps }
47
- },
48
- render() {
49
- const { cancelBtnProps, confirmBtnProps } = this
50
-
51
- return h(ASpace, {}, () => [
52
- h(AButton, cancelBtnProps, () => '取消'),
53
- h(AButton, confirmBtnProps, () => '确定'),
54
- ])
55
- },
56
- })
57
- const PresetComponent = defineComponent({
58
- render() {
59
- return h(ADrawer, _drawerProps, {
60
- default: () => h(_comp.is, compProps as any),
61
- })
62
- },
63
- })
64
-
65
- _drawerProps.extra = _drawerProps.extra === undefined ? h(DrawerExtra) : _drawerProps.extra
66
- _drawerProps['onUpdate:open'] = (visiable) => {
67
- _drawerProps.open = visiable
68
- }
69
- (compProps as any).ref = compRef;
70
- (compProps as any).onClose = close
71
-
72
- return { PresetComponent, drawerProps: _drawerProps, open, close }
73
- }
1
+ import { Button as AButton, Drawer as ADrawer, Space as ASpace } from 'ant-design-vue'
2
+ import { defineComponent, isProxy, reactive, toRefs, toRef, h } from 'vue'
3
+ import type { Component } from 'vue'
4
+ import type { ButtonProps, DrawerProps } from 'ant-design-vue'
5
+ import type { ComponentProps } from 'vue-component-type-helpers'
6
+ import type { Writable } from 'type-fest'
7
+ import { useComponentRef } from '../../vue'
8
+
9
+ const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true }
10
+
11
+ interface IComponentConfig<Comp extends Component> {
12
+ is: Comp
13
+ props?: Writable<ComponentProps<Comp>>
14
+ }
15
+
16
+ export function useAntdDrawer<Comp extends Component>(
17
+ comp: IComponentConfig<Comp> | Comp,
18
+ drawerProps = defaultDrawerProps,
19
+ ) {
20
+ const _comp = ({ props: {}, ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>
21
+ const compProps = reactive(_comp.props)
22
+ const compRef = useComponentRef(_comp.is)
23
+ const _drawerProps: DrawerProps = reactive({
24
+ ...defaultDrawerProps,
25
+ ...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
26
+ })
27
+
28
+ const open = (newBodyProps?: Partial<typeof compProps>, newAntdModalProps?: Omit<Partial<DrawerProps>, 'open'>) => {
29
+ Object.assign(_drawerProps, newAntdModalProps)
30
+ Object.assign(compProps, newBodyProps)
31
+ _drawerProps.open = true
32
+ }
33
+ const close = () => {
34
+ _drawerProps.open = false
35
+ }
36
+
37
+ const DrawerExtra = defineComponent({
38
+ setup() {
39
+ const cancelBtnProps: ButtonProps = reactive({ onClick: close })
40
+ const confirmBtnProps: ButtonProps = reactive({
41
+ type: 'primary',
42
+ loading: toRef(() => (compRef as any)?.loading),
43
+ onClick: () => (compRef as any)?.confirm?.(),
44
+ })
45
+
46
+ return { cancelBtnProps, confirmBtnProps }
47
+ },
48
+ render() {
49
+ const { cancelBtnProps, confirmBtnProps } = this
50
+
51
+ return h(ASpace, {}, () => [
52
+ h(AButton, cancelBtnProps, () => '取消'),
53
+ h(AButton, confirmBtnProps, () => '确定'),
54
+ ])
55
+ },
56
+ })
57
+ const PresetComponent = defineComponent({
58
+ render() {
59
+ return h(ADrawer, _drawerProps, {
60
+ default: () => h(_comp.is, compProps as any),
61
+ })
62
+ },
63
+ })
64
+
65
+ _drawerProps.extra = _drawerProps.extra === undefined ? h(DrawerExtra) : _drawerProps.extra
66
+ _drawerProps['onUpdate:open'] = (visiable) => {
67
+ _drawerProps.open = visiable
68
+ }
69
+ (compProps as any).ref = compRef;
70
+ (compProps as any).onClose = close
71
+
72
+ return { PresetComponent, drawerProps: _drawerProps, open, close }
73
+ }
@@ -1,70 +1,70 @@
1
- import { computed } from 'vue'
2
- import type { UseQueryReturnType } from '@tanstack/vue-query'
3
- import type { Table, TableProps } from 'ant-design-vue'
4
- import type { ColumnType } from 'ant-design-vue/es/table/interface'
5
- import type { ComponentProps } from 'vue-component-type-helpers'
6
-
7
- export function useAntdTable<
8
- UQRR extends UseQueryReturnType<any, any>,
9
- QP extends Partial<{ page?: string | number; page_size?: string | number }>,
10
- >(uqrt: UQRR, queryParams: QP) {
11
- type RecordType = GetRecordType<UQRR>
12
- type LocalTableProps = TableProps<RecordType>
13
- type LocalColumnsType = NonNullable<LocalTableProps['columns']>
14
-
15
- const { data, isFetching, isLoading } = uqrt
16
-
17
- const onPaginationChange: ComponentProps<typeof Table>['onChange'] = (pagination) => {
18
- const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current
19
- Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 })
20
- }
21
- const defineColumns = (columnsFn: () => LocalColumnsType) => computed(columnsFn)
22
-
23
- const tableProps = computed<LocalTableProps>(() => {
24
- const { list, pagination } = data.value ?? {}
25
-
26
- return {
27
- dataSource: list,
28
- pagination: {
29
- disabled: isFetching.value,
30
- current: Number(queryParams.page ?? 1),
31
- pageSize: Number(queryParams.page_size ?? 10),
32
- total: pagination?.total ?? 0,
33
- },
34
- loading: isLoading.value,
35
- scroll: { x: 'max-content' },
36
- sticky: true,
37
- onChange: onPaginationChange as any,
38
- }
39
- })
40
- const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
41
- get(_, p) {
42
- return p
43
- },
44
- })
45
- const bodyCellType = {} as {
46
- index: number
47
- text: any
48
- value: any
49
- record: RecordType
50
- column: ColumnType<RecordType>
51
- }
52
-
53
- return {
54
- /** ATable 的预设 Props */
55
- tableProps,
56
- /** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
57
- dataIndexs,
58
- /** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
59
- bodyCellType,
60
- /** 【类型辅助】用于定义出类型精确的 columns */
61
- defineColumns,
62
- onPaginationChange,
63
- }
64
- }
65
-
66
- type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
67
- ? D extends Api.PageData
68
- ? NonNullable<D['list']>[0]
69
- : never
70
- : never
1
+ import { computed } from 'vue'
2
+ import type { UseQueryReturnType } from '@tanstack/vue-query'
3
+ import type { Table, TableProps } from 'ant-design-vue'
4
+ import type { ColumnType } from 'ant-design-vue/es/table/interface'
5
+ import type { ComponentProps } from 'vue-component-type-helpers'
6
+
7
+ export function useAntdTable<
8
+ UQRR extends UseQueryReturnType<any, any>,
9
+ QP extends Partial<{ page?: string | number; page_size?: string | number }>,
10
+ >(uqrt: UQRR, queryParams: QP) {
11
+ type RecordType = GetRecordType<UQRR>
12
+ type LocalTableProps = TableProps<RecordType>
13
+ type LocalColumnsType = NonNullable<LocalTableProps['columns']>
14
+
15
+ const { data, isFetching, isLoading } = uqrt
16
+
17
+ const onPaginationChange: ComponentProps<typeof Table>['onChange'] = (pagination) => {
18
+ const page = queryParams.page_size !== pagination.pageSize ? 1 : pagination.current
19
+ Object.assign(queryParams, { page, page_size: pagination.pageSize ?? 10 })
20
+ }
21
+ const defineColumns = (columnsFn: () => LocalColumnsType) => computed(columnsFn)
22
+
23
+ const tableProps = computed<LocalTableProps>(() => {
24
+ const { list, pagination } = data.value ?? {}
25
+
26
+ return {
27
+ dataSource: list,
28
+ pagination: {
29
+ disabled: isFetching.value,
30
+ current: Number(queryParams.page ?? 1),
31
+ pageSize: Number(queryParams.page_size ?? 10),
32
+ total: pagination?.total ?? 0,
33
+ },
34
+ loading: isLoading.value,
35
+ scroll: { x: 'max-content' },
36
+ sticky: true,
37
+ onChange: onPaginationChange as any,
38
+ }
39
+ })
40
+ const dataIndexs = new Proxy({} as Record<keyof RecordType, string>, {
41
+ get(_, p) {
42
+ return p
43
+ },
44
+ })
45
+ const bodyCellType = {} as {
46
+ index: number
47
+ text: any
48
+ value: any
49
+ record: RecordType
50
+ column: ColumnType<RecordType>
51
+ }
52
+
53
+ return {
54
+ /** ATable 的预设 Props */
55
+ tableProps,
56
+ /** 【类型辅助】基于接口数据类型推导出的 dataIndex,供 columns 的 dataIndex 使用 */
57
+ dataIndexs,
58
+ /** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
59
+ bodyCellType,
60
+ /** 【类型辅助】用于定义出类型精确的 columns */
61
+ defineColumns,
62
+ onPaginationChange,
63
+ }
64
+ }
65
+
66
+ type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
67
+ ? D extends Api.PageData
68
+ ? NonNullable<D['list']>[0]
69
+ : never
70
+ : never
@@ -1 +1 @@
1
- export { default as InfiniteQuery } from './src/InfiniteQuery.vue'
1
+ export { default as InfiniteQuery } from './src/InfiniteQuery.vue'