p-pc-ui 1.2.5 → 1.2.7

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.
@@ -0,0 +1,83 @@
1
+ <script setup lang="ts">
2
+ import { ref, reactive, onMounted } from 'vue'
3
+ import { Button as AButton, Tooltip as ATooltip } from 'ant-design-vue'
4
+
5
+ const {
6
+ color = '#fff',
7
+ bgColor = '#735ffa',
8
+ borderColor = '#fff',
9
+ loading = false,
10
+ disabled = false,
11
+ tooltip = '',
12
+ rounded = 100,
13
+ click = null,
14
+ width = 160,
15
+ height = 48,
16
+ } = defineProps<{
17
+ loading?: boolean
18
+ bgColor?: string
19
+ color?: string
20
+ borderColor?: string
21
+ disabled?: boolean
22
+ tooltip?: any
23
+ rounded?: number | string
24
+ click?: Function
25
+ width?: number | string
26
+ height?: number | string
27
+ }>()
28
+
29
+ const builtInLoading = ref(false)
30
+ const emits = defineEmits(['click', 'loading'])
31
+
32
+ const useDebounceFn = (fn: Function, delay = 300) => {
33
+ let timer: ReturnType<typeof setTimeout> | null = null
34
+
35
+ return (...args: any[]) => {
36
+ if (timer) clearTimeout(timer) // 每次都清除之前的定时器
37
+ timer = setTimeout(() => {
38
+ fn(...args)
39
+ }, delay)
40
+ }
41
+ }
42
+
43
+ const btnClick = useDebounceFn(async () => {
44
+ builtInLoading.value = true
45
+ try {
46
+ if (disabled) {
47
+ return
48
+ }
49
+ // 同时兼容两种调用方式
50
+ click && (await click())
51
+ emits('click')
52
+ } catch (err) {
53
+ } finally {
54
+ builtInLoading.value = false
55
+ }
56
+ }, 200)
57
+ </script>
58
+
59
+ <template>
60
+
61
+ <a-tooltip color="var(--secondary-color-light)" :overlayInnerStyle="{ color: '#fff' }" :title="tooltip"
62
+ v-bind="$attrs">
63
+ <a-button @click="btnClick" :loading="loading || builtInLoading" class="font-semibold"
64
+ :class="disabled ? 'cursor-not-allowed' : 'hover:opacity-80 active:opacity-100'" :style="{
65
+ background: disabled ? '#b5b5b5' : bgColor,
66
+ color: disabled ? '#fff' : color,
67
+ ...(!disabled && { border: `1px solid ${borderColor}` }),
68
+ borderRadius: rounded + 'px',
69
+ minWidth: width + 'px',
70
+ minHeight: height + 'px',
71
+ }">
72
+ <slot></slot>
73
+ </a-button>
74
+
75
+ </a-tooltip>
76
+
77
+ </template>
78
+
79
+ <style lang="scss">
80
+ .ant-btn-default:not(:disabled):hover {
81
+ border-color: #cecece !important;
82
+ }
83
+ </style>
@@ -0,0 +1,119 @@
1
+
2
+ type FieldRule = { msg?: string, required?: boolean, min?: number, max?: number, decimal?: number }
3
+
4
+ interface Base<K extends string = string> {
5
+ key: K,
6
+ label: string,
7
+ default?: any,
8
+ placeholder?: string,
9
+ fieldType?: 'string' | 'number' | 'array' | 'date',
10
+ fieldRules?: FieldRule[];
11
+ visibleHook?: Function,
12
+ tooltip?: string,
13
+ hideLabel?: boolean
14
+ colon?: boolean,
15
+ labelSpan?: number,
16
+ valueSpan?: number,
17
+ labelAlign?: 'left' | 'right'
18
+ }
19
+
20
+
21
+ export interface Input<K extends string = string> extends Base<K> {
22
+ type: 'input',
23
+ prefix?: any,
24
+ suffix?: any
25
+ }
26
+
27
+ export interface InputNumber<K extends string = string> extends Base<K> {
28
+ type: 'number',
29
+ prefix?: any,
30
+ suffix?: any
31
+ }
32
+
33
+ export interface InputPassword<K extends string = string> extends Base<K> {
34
+ type: 'password',
35
+ prefix?: any,
36
+ }
37
+
38
+ export interface InputCode<K extends string = string> extends Base<K> {
39
+ type: 'code',
40
+ interval: number,
41
+ codeName: string,
42
+ sendNoticeFunc: Function
43
+ activityFunc?: Function
44
+ prefix?: any,
45
+ suffix?: any,
46
+ sendStatus?: 'waitSend' | 'sending' | 'end',
47
+ }
48
+
49
+
50
+
51
+ type LoadOptionsData = () => Promise<{ label: string, value: any }[]>
52
+
53
+
54
+ interface SelectBase<K extends string = string> extends Base<K> {
55
+ type: 'select' | 'treeSelect' | 'radio',
56
+ fieldNames?: {
57
+ label?: string;
58
+ value?: string;
59
+ };
60
+ isMultiple?: boolean
61
+ }
62
+
63
+ type GetOptionList =
64
+ | { optionList: any[]; mapPath?: never; loadDataFunc?: LoadOptionsData }
65
+ | { optionList?: any[]; mapPath: string[], loadDataFunc?: LoadOptionsData }
66
+ | { optionList?: any[]; mapPath?: string[], loadDataFunc: LoadOptionsData }
67
+
68
+ export type Select<K extends string = string> = SelectBase<K> & GetOptionList;
69
+
70
+
71
+ interface UploadBase<K extends string = string> extends Base<K> {
72
+ uploadType: 'pic' | 'file',
73
+ maxCount?: number,
74
+ }
75
+
76
+ export interface UploadOss<K extends string = string> extends UploadBase<K> {
77
+ type: 'uploadOss',
78
+ getOssToken: ({file_name}) => Promise<any>,
79
+ baseOssUrl: string,
80
+ }
81
+
82
+
83
+ export interface Upload<K extends string = string> extends UploadBase<K> {
84
+ type: 'upload',
85
+ }
86
+
87
+ export interface Textarea<K extends string = string> extends Base<K> {
88
+ type: 'textarea',
89
+ }
90
+
91
+ export interface DatePicker<K extends string = string> extends Base<K> {
92
+ type: 'datePicker',
93
+ }
94
+
95
+
96
+ export interface Component<K extends string = string> extends Base<K> {
97
+ type: 'component',
98
+ component: any
99
+ }
100
+
101
+ export interface Editor<K extends string = string> extends Base<K> {
102
+ type: 'editor',
103
+ getOssToken: ({ file_name: string }) => Promise<any>,
104
+ baseOssUrl?: string,
105
+ }
106
+
107
+
108
+ export type FormDataItem<K extends string = string> =
109
+ | Input<K>
110
+ | InputNumber<K>
111
+ | InputPassword<K>
112
+ | InputCode<K>
113
+ | Select<K>
114
+ | Upload<K>
115
+ | UploadOss<K>
116
+ | Textarea<K>
117
+ | DatePicker<K>
118
+ | Component<K>
119
+ | Editor<K>