@neatui/vue 2.11.0 → 2.12.0
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/package.json +1 -1
- package/src/components/basic/LayerView/Layer.vue +0 -16
- package/src/components/display/Calendar.vue +14 -14
- package/src/components/display/CalendarReg.vue +14 -14
- package/src/components/display/Tree.vue +6 -6
- package/src/components/form/Cascader.vue +20 -20
- package/src/components/form/DatePicker.vue +8 -9
- package/src/components/form/DateRangePicker@v3.vue +5 -5
- package/src/components/form/DateRangeView@v3.vue +9 -9
- package/src/components/form/DateView.vue +14 -14
- package/src/components/form/DateView@v2.vue +14 -14
- package/src/components/form/DateView@v3.vue +17 -15
- package/src/components/form/Input@v3.vue +2 -2
- package/src/components/form/MoreSelect@v3.vue +27 -8
- package/src/components/form/MoreSelectList.vue +1 -1
- package/src/components/form/MoreSelectPanel@v3.vue +4 -4
- package/src/components/form/MoreSelectPicker.vue +1 -1
- package/src/components/form/MoreSelectTags.vue +1 -1
- package/src/components/form/PageMoreSelect.vue +15 -15
- package/src/components/form/PageSelect.vue +17 -17
- package/src/components/form/SearchMoreSelect.vue +1 -1
- package/src/components/form/SearchSelect@v3.vue +4 -4
- package/src/components/form/Select@v3.vue +9 -6
- package/src/components/form/SelectList.vue +8 -8
- package/src/components/form/SelectPicker.vue +7 -7
- package/src/components/form/SelectTags.vue +7 -7
- package/src/components/form/SelectTree/SelectTree@v1.vue +6 -6
- package/src/components/form/Switch.vue +33 -58
- package/src/components/form/Textarea@v2.vue +275 -0
- package/src/components/form/TimeView.vue +14 -14
- package/src/components/form/Upload.vue +52 -9
- package/src/components/form/date.ts +321 -0
- package/src/components/form/index.ts +2 -2
- package/src/components/form/number.ts +3 -0
- package/src/components/form/type.ts +224 -0
- package/src/components/loader/FormLoader/FormLoader@v2.vue +20 -20
- package/src/components/loader/FormLoader/FormLoader@v3.vue.backup +372 -291
- package/src/components/loader/FormLoader/FormRender@v3.vue.backup +4 -0
- package/src/components/loader/FormLoader/NodeLoader.vue +85 -0
- package/src/components/loader/FormLoader@v1/FormLoader.vue +1 -1
- package/src/components/loader/FormLoader@v1/FormRender.vue +49 -24
- package/src/components/loader/LayerLoader/LayerLoader.vue +1 -1
- package/src/components/loader/LimitLoader/LimitLoader@v3.vue +1 -1
- package/src/components/loader/MoveLoader/MoveLoader.vue +8 -8
- package/src/components/loader/TableLoader/TableRender.vue +1 -1
- package/src/components/loader/index.ts +1 -1
- package/src/components/tools/Pagination@a.vue +1 -1
- package/tsconfig.json +1 -1
- package/src/components/loader/FormLoader/index.ts +0 -2
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div :ui-form="`@a type:select sz
|
|
2
|
+
<div :ui-form="`@a type:select${sz ? 'sz:' + sz : ''}`" :ui-form-open="state.show ? 'show' : ''">
|
|
3
3
|
<IFollowView ref="ifollow" tipBoxClass="ny-sm nx-no" tipBoxStyle="min-width: 100%" @onshow="onshow" @onhide="onhide">
|
|
4
4
|
<Input
|
|
5
5
|
v-bind="{ placeholder, rules, theme, sz, co, block, ready, type, tips, disabled, readonly: true, clearable: false, verify, prefix, suffix, interacted }"
|
|
6
6
|
v-model="state.selectd.label"
|
|
7
7
|
:interacted="interacted"
|
|
8
8
|
>
|
|
9
|
-
<template #suffix
|
|
9
|
+
<template #suffix>
|
|
10
|
+
<i v-if="clearable && modelValue && !readonly && !disabled" ui-form-clean="" @click.stop="remove"></i>
|
|
11
|
+
<i ui-form-select=""></i>
|
|
12
|
+
</template>
|
|
10
13
|
</Input>
|
|
11
14
|
<template #tips v-if="!readonly && !disabled">
|
|
12
15
|
<div v-if="search" class="ny-sm nx-sl">
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
</template>
|
|
17
20
|
</Input>
|
|
18
21
|
</div>
|
|
19
|
-
<ul v-if="
|
|
22
|
+
<ul v-if="state.filter?.length" ui-scroll=":y s" class="nx-sm lh-sl" style="min-width: 100%; max-height: 16em">
|
|
20
23
|
<template v-for="(item, idx) of state.filter" :key="idx">
|
|
21
24
|
<li v-if="item.disabled" class="ux-hover nx-sm ny-ss r-ss o-ms nowrap" :class="item.value === state.selectd?.value ? 'co-main' : ''">
|
|
22
25
|
<del>{{ item.label || item }}</del>
|
|
@@ -47,7 +50,7 @@
|
|
|
47
50
|
|
|
48
51
|
<script setup lang="ts">
|
|
49
52
|
import { reactive, ref, computed } from 'vue';
|
|
50
|
-
import { Input } from '
|
|
53
|
+
import { Input } from '.';
|
|
51
54
|
import { IFollowView } from '../basic';
|
|
52
55
|
const ifollow: any = ref(null);
|
|
53
56
|
|
|
@@ -139,14 +142,14 @@
|
|
|
139
142
|
minlength: null,
|
|
140
143
|
disabled: false,
|
|
141
144
|
readonly: false,
|
|
142
|
-
clearable:
|
|
145
|
+
clearable: true,
|
|
143
146
|
verify: false,
|
|
144
147
|
prefix: () => [],
|
|
145
148
|
suffix: () => [],
|
|
146
149
|
interacted: false,
|
|
147
150
|
});
|
|
148
151
|
|
|
149
|
-
const change = ({ value =
|
|
152
|
+
const change = ({ value = null }: any = {}) => {
|
|
150
153
|
emits('update:modelValue', value);
|
|
151
154
|
emits('change', value);
|
|
152
155
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<ul v-if="props.options?.length" class="my-sm-sub lh-ss">
|
|
3
3
|
<li
|
|
4
|
-
class="hover:bg-main-ss n-sl r-ss b-solid b-xs"
|
|
5
|
-
:class="`${item.value === mv ? 'bk-main-ml bg-main-ss' : 'bk-case'}`"
|
|
4
|
+
class="hover:bg-main-o-ss n-sl r-ss b-solid b-xs"
|
|
5
|
+
:class="`${item.value === mv ? 'bk-main-o-ml bg-main-o-ss' : 'bk-case'}`"
|
|
6
6
|
v-for="(item, idx) of props.options"
|
|
7
7
|
:key="idx"
|
|
8
8
|
@click="mv = item.value === mv ? '' : item.value"
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
placeholder: { type: String, default: '' },
|
|
28
28
|
options: {
|
|
29
29
|
type: Array as () => any[],
|
|
30
|
-
default: () => []
|
|
30
|
+
default: () => [],
|
|
31
31
|
},
|
|
32
32
|
modelValue: {
|
|
33
33
|
type: [String, Number],
|
|
34
|
-
default: ''
|
|
34
|
+
default: '',
|
|
35
35
|
},
|
|
36
36
|
rules: {
|
|
37
37
|
type: Array,
|
|
38
|
-
default: () => []
|
|
39
|
-
}
|
|
38
|
+
default: () => [],
|
|
39
|
+
},
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
// eslint-disable-next-line vue/no-dupe-keys
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
() => props.modelValue,
|
|
48
48
|
(value: any) => {
|
|
49
49
|
mv.value = value;
|
|
50
|
-
}
|
|
50
|
+
},
|
|
51
51
|
);
|
|
52
52
|
watch(
|
|
53
53
|
() => mv.value,
|
|
54
54
|
(value: any) => {
|
|
55
55
|
emits('update:modelValue', value);
|
|
56
|
-
}
|
|
56
|
+
},
|
|
57
57
|
);
|
|
58
58
|
</script>
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
|
|
30
30
|
<script setup lang="ts">
|
|
31
31
|
import { reactive, ref, computed } from 'vue';
|
|
32
|
-
import { Input } from '
|
|
32
|
+
import { Input } from '.';
|
|
33
33
|
import { IPickerView, IScrollView } from '../basic';
|
|
34
34
|
import { watch } from 'vue';
|
|
35
35
|
const ipicker: any = ref(null);
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
placeholder: { type: String, default: '' },
|
|
44
44
|
options: {
|
|
45
45
|
type: Array as () => any[],
|
|
46
|
-
default: () => []
|
|
46
|
+
default: () => [],
|
|
47
47
|
},
|
|
48
48
|
modelValue: {
|
|
49
49
|
type: [String, Number],
|
|
50
|
-
default: ''
|
|
50
|
+
default: '',
|
|
51
51
|
},
|
|
52
52
|
rules: {
|
|
53
53
|
type: Array,
|
|
54
|
-
default: () => []
|
|
55
|
-
}
|
|
54
|
+
default: () => [],
|
|
55
|
+
},
|
|
56
56
|
});
|
|
57
57
|
// 内部数据
|
|
58
58
|
const mv: any = ref(props.modelValue);
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
(v: any) => {
|
|
62
62
|
mv.value = v;
|
|
63
63
|
},
|
|
64
|
-
{ deep: true, immediate: true }
|
|
64
|
+
{ deep: true, immediate: true },
|
|
65
65
|
);
|
|
66
66
|
const state = reactive({
|
|
67
67
|
view: 0,
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return _value;
|
|
77
|
-
})
|
|
77
|
+
}),
|
|
78
78
|
});
|
|
79
79
|
// 更新
|
|
80
80
|
const change = ({ value = null }: any = {}) => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<div v-if="props.options?.length" class="mr-sm-sub mb-sm-sub">
|
|
3
3
|
<span
|
|
4
4
|
class="lh-ss ny-sm nx-ms r-xl dib"
|
|
5
|
-
:class="`${mv == item.value ? 'bg-main-sm co-main' : 'bg-weak'}`"
|
|
5
|
+
:class="`${mv == item.value ? 'bg-main-o-sm co-main' : 'bg-weak'}`"
|
|
6
6
|
v-for="(item, idx) of props.options"
|
|
7
7
|
:key="idx"
|
|
8
8
|
@click="mv = item.value === mv ? '' : item.value"
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
placeholder: { type: String, default: '' },
|
|
25
25
|
options: {
|
|
26
26
|
type: Array as () => any[],
|
|
27
|
-
default: () => []
|
|
27
|
+
default: () => [],
|
|
28
28
|
},
|
|
29
29
|
modelValue: {
|
|
30
30
|
type: [String, Number],
|
|
31
|
-
default: ''
|
|
31
|
+
default: '',
|
|
32
32
|
},
|
|
33
33
|
rules: {
|
|
34
34
|
type: Array,
|
|
35
|
-
default: () => []
|
|
36
|
-
}
|
|
35
|
+
default: () => [],
|
|
36
|
+
},
|
|
37
37
|
});
|
|
38
38
|
// 内部数据
|
|
39
39
|
const mv: any = ref(props.modelValue);
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
() => props.modelValue,
|
|
42
42
|
(value: any) => {
|
|
43
43
|
mv.value = value;
|
|
44
|
-
}
|
|
44
|
+
},
|
|
45
45
|
);
|
|
46
46
|
watch(
|
|
47
47
|
() => mv.value,
|
|
48
48
|
(value: any) => {
|
|
49
49
|
emits('update:modelValue', value);
|
|
50
|
-
}
|
|
50
|
+
},
|
|
51
51
|
);
|
|
52
52
|
</script>
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
<script setup lang="ts">
|
|
42
42
|
import { reactive, ref, computed, watch } from 'vue';
|
|
43
|
-
import { Input } from '
|
|
43
|
+
import { Input } from '..';
|
|
44
44
|
import { IFollowView } from '../../basic';
|
|
45
45
|
import { TreeView } from '../../display';
|
|
46
46
|
import { findByJson, filterJson } from '@fekit/utils';
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
verify: false,
|
|
145
145
|
prefix: () => [],
|
|
146
146
|
suffix: () => [],
|
|
147
|
-
interacted: false
|
|
147
|
+
interacted: false,
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
const state: any = reactive({
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
return (props.chain ? _item.chain : _item.label) || '';
|
|
159
159
|
}),
|
|
160
160
|
filter: [],
|
|
161
|
-
value: ''
|
|
161
|
+
value: '',
|
|
162
162
|
});
|
|
163
163
|
watch(
|
|
164
164
|
() => state.value,
|
|
@@ -167,7 +167,7 @@
|
|
|
167
167
|
change(value);
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
|
-
{ deep: true }
|
|
170
|
+
{ deep: true },
|
|
171
171
|
);
|
|
172
172
|
watch(
|
|
173
173
|
[() => state.search, () => props.options],
|
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
state.filter = props.options;
|
|
179
179
|
}
|
|
180
180
|
},
|
|
181
|
-
{ deep: true, immediate: true }
|
|
181
|
+
{ deep: true, immediate: true },
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
const change = (value: any = '') => {
|
|
@@ -221,7 +221,7 @@
|
|
|
221
221
|
select,
|
|
222
222
|
remove,
|
|
223
223
|
change,
|
|
224
|
-
cancel
|
|
224
|
+
cancel,
|
|
225
225
|
});
|
|
226
226
|
</script>
|
|
227
227
|
.. ..
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<label ui-form="@a type:switch"
|
|
3
|
-
<input type="checkbox"
|
|
2
|
+
<label ui-form="@a type:switch">
|
|
3
|
+
<input type="checkbox" v-model="internalValue" :disabled="disabled" />
|
|
4
4
|
<slot>
|
|
5
5
|
<span>{{ text }}</span>
|
|
6
6
|
</slot>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
</template>
|
|
9
9
|
|
|
10
10
|
<script setup lang="ts">
|
|
11
|
-
import { ref, watch,
|
|
11
|
+
import { ref, watch, PropType } from 'vue';
|
|
12
12
|
|
|
13
13
|
const props = defineProps({
|
|
14
14
|
theme: { type: String, default: '@a' },
|
|
@@ -17,79 +17,54 @@
|
|
|
17
17
|
block: { type: Boolean, default: true },
|
|
18
18
|
// 值
|
|
19
19
|
modelValue: {
|
|
20
|
-
type: [Number, Boolean],
|
|
20
|
+
type: [Number, Boolean, String],
|
|
21
21
|
default: false,
|
|
22
22
|
},
|
|
23
|
-
// 类型
|
|
24
|
-
type: {
|
|
25
|
-
type: String,
|
|
26
|
-
default: 'text',
|
|
27
|
-
},
|
|
28
23
|
text: {
|
|
29
24
|
type: String,
|
|
30
25
|
default: '',
|
|
31
26
|
},
|
|
32
|
-
// 提示文案
|
|
33
|
-
tips: {
|
|
34
|
-
type: String,
|
|
35
|
-
default: '',
|
|
36
|
-
},
|
|
37
|
-
// 内容占位
|
|
38
|
-
placeholder: {
|
|
39
|
-
type: String,
|
|
40
|
-
default: '',
|
|
41
|
-
},
|
|
42
|
-
// 最大长度
|
|
43
|
-
maxlength: {
|
|
44
|
-
type: Number,
|
|
45
|
-
default: null,
|
|
46
|
-
},
|
|
47
|
-
// 最小长度
|
|
48
|
-
minlength: {
|
|
49
|
-
type: Number,
|
|
50
|
-
default: null,
|
|
51
|
-
},
|
|
52
27
|
// 是否禁用
|
|
53
28
|
disabled: {
|
|
54
29
|
type: Boolean,
|
|
55
30
|
default: false,
|
|
56
31
|
},
|
|
57
|
-
|
|
58
|
-
readonly: {
|
|
59
|
-
type: Boolean,
|
|
60
|
-
default: false,
|
|
61
|
-
},
|
|
62
|
-
// 是否显示清除按钮
|
|
63
|
-
clearable: {
|
|
64
|
-
type: Boolean,
|
|
65
|
-
default: true,
|
|
66
|
-
},
|
|
67
|
-
// 校验规则
|
|
68
|
-
rules: {
|
|
69
|
-
type: Array,
|
|
70
|
-
default: () => [],
|
|
71
|
-
},
|
|
72
|
-
// 是否是示校验图标
|
|
73
|
-
verify: {
|
|
74
|
-
type: Boolean,
|
|
75
|
-
default: false,
|
|
76
|
-
},
|
|
77
|
-
prefix: {
|
|
78
|
-
type: Array as PropType<any[]>,
|
|
79
|
-
default: () => [],
|
|
80
|
-
},
|
|
81
|
-
suffix: {
|
|
32
|
+
map: {
|
|
82
33
|
type: Array as PropType<any[]>,
|
|
83
|
-
default: () => [],
|
|
34
|
+
default: () => [false, true],
|
|
84
35
|
},
|
|
85
36
|
});
|
|
86
37
|
|
|
87
|
-
const
|
|
88
|
-
|
|
38
|
+
const emit = defineEmits(['update:modelValue']);
|
|
39
|
+
|
|
40
|
+
// 内部值(始终是布尔值)
|
|
41
|
+
const internalValue = ref(false);
|
|
42
|
+
|
|
43
|
+
// 计算内部值
|
|
44
|
+
const getInternalValue = (externalValue: any) => {
|
|
45
|
+
const index = props.map.indexOf(externalValue);
|
|
46
|
+
return index === 0 ? true : index === 1 ? false : Boolean(externalValue);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 计算外部值
|
|
50
|
+
const getExternalValue = (internalValue: boolean) => {
|
|
51
|
+
return internalValue ? props.map[0] : props.map[1];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// 初始化内部值
|
|
55
|
+
internalValue.value = getInternalValue(props.modelValue);
|
|
56
|
+
|
|
57
|
+
// 监听外部值变化
|
|
89
58
|
watch(
|
|
90
59
|
() => props.modelValue,
|
|
91
60
|
(newValue) => {
|
|
92
|
-
|
|
61
|
+
internalValue.value = getInternalValue(newValue);
|
|
93
62
|
},
|
|
94
63
|
);
|
|
64
|
+
|
|
65
|
+
// 监听内部值变化,向父组件发送映射后的值
|
|
66
|
+
watch(internalValue, (newValue) => {
|
|
67
|
+
const externalValue = getExternalValue(newValue);
|
|
68
|
+
emit('update:modelValue', externalValue);
|
|
69
|
+
});
|
|
95
70
|
</script>
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:ui-form="`${theme} sz:${sz} ${state.error.co} type:textarea ${block ? ' :block' : ''} ${disabled ? 'disabled' : ''} ${readonly ? 'readonly' : ''}`"
|
|
4
|
+
@click="emits('click', $event)"
|
|
5
|
+
>
|
|
6
|
+
<div :ui-form-tips="state.error.ontips">{{ state.error.tips }}</div>
|
|
7
|
+
<div ui-form-prefix="">
|
|
8
|
+
<template v-for="(item, idx) in prefix" :key="idx">
|
|
9
|
+
<div v-if="isObject(item)" v-bind="item.attrs" v-on="event(item, props.modelValue)">
|
|
10
|
+
<div v-html="isFunction(item.value) ? item.value(props.modelValue) : item.value"></div>
|
|
11
|
+
</div>
|
|
12
|
+
<div v-else v-html="isFunction(item) ? item(props.modelValue) : item"></div>
|
|
13
|
+
</template>
|
|
14
|
+
<slot name="prefix"></slot>
|
|
15
|
+
</div>
|
|
16
|
+
<slot>
|
|
17
|
+
<textarea
|
|
18
|
+
ref="el"
|
|
19
|
+
:title="props.modelValue"
|
|
20
|
+
:value="props.modelValue"
|
|
21
|
+
:placeholder="placeholder"
|
|
22
|
+
:disabled="disabled"
|
|
23
|
+
:readonly="readonly"
|
|
24
|
+
:rows="rows"
|
|
25
|
+
ui-scroll=":y"
|
|
26
|
+
dir="auto"
|
|
27
|
+
@focus="emits('focus', $event, state)"
|
|
28
|
+
@input="input($event)"
|
|
29
|
+
@change="emits('change', $event, state)"
|
|
30
|
+
@blur="blur($event)"
|
|
31
|
+
></textarea>
|
|
32
|
+
</slot>
|
|
33
|
+
<div ui-form-suffix="">
|
|
34
|
+
<i ui-form-clean="" v-if="clearable && props.modelValue && !readonly && !disabled" @click.stop="clear"></i>
|
|
35
|
+
<slot name="suffix"></slot>
|
|
36
|
+
<template v-for="(item, idx) in suffix" :key="idx">
|
|
37
|
+
<div v-if="isObject(item)" v-bind="item.attrs" v-on="event(item, props.modelValue)">
|
|
38
|
+
<div v-html="isFunction(item.value) ? item.value(props.modelValue) : item.value"></div>
|
|
39
|
+
</div>
|
|
40
|
+
<div v-else v-html="isFunction(item) ? item(props.modelValue) : item"></div>
|
|
41
|
+
</template>
|
|
42
|
+
</div>
|
|
43
|
+
<i v-if="verify && state.interacted" :ui-form-verify="state.error.verify"></i>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script setup lang="ts">
|
|
48
|
+
import { reactive, watch, ref, nextTick, onMounted } from 'vue';
|
|
49
|
+
import { isObject, isFunction } from '@fekit/utils';
|
|
50
|
+
|
|
51
|
+
const emits = defineEmits(['update:modelValue', 'click', 'blur', 'focus', 'change', 'input', 'clear']);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 入参说明
|
|
55
|
+
*
|
|
56
|
+
* modelValue 值
|
|
57
|
+
* theme 主题
|
|
58
|
+
* sz 尺寸
|
|
59
|
+
* co 颜色
|
|
60
|
+
* block 撑满
|
|
61
|
+
* ready 准备就绪
|
|
62
|
+
* tips 提示文案
|
|
63
|
+
* placeholder 内容占位
|
|
64
|
+
* maxlength 最大长度
|
|
65
|
+
* minlength 最小长度
|
|
66
|
+
* disabled 是否禁用
|
|
67
|
+
* readonly 是否只读
|
|
68
|
+
* clearable 是否显示清除按钮
|
|
69
|
+
* rules 校验规则
|
|
70
|
+
* verify 是否是示校验图标 2=tips 3=text 4=icon 5=tips+text 6=text+icon 7=text+icon
|
|
71
|
+
* prefix 前缀内容
|
|
72
|
+
* suffix 后缀内容
|
|
73
|
+
* interacted 用户是否交互
|
|
74
|
+
* autoHeight 是否自动调整高度
|
|
75
|
+
* rows 初始行数
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
// 类型
|
|
79
|
+
interface Props {
|
|
80
|
+
modelValue?: string | number;
|
|
81
|
+
placeholder?: string;
|
|
82
|
+
rules?: Array<object>;
|
|
83
|
+
theme?: string;
|
|
84
|
+
sz?: '' | 'xs' | 's' | 'm' | 'l' | 'xl';
|
|
85
|
+
co?: string;
|
|
86
|
+
block?: boolean;
|
|
87
|
+
ready?: boolean;
|
|
88
|
+
tips?: string;
|
|
89
|
+
maxlength?: null | number;
|
|
90
|
+
minlength?: null | number;
|
|
91
|
+
disabled?: boolean;
|
|
92
|
+
readonly?: boolean;
|
|
93
|
+
clearable?: boolean;
|
|
94
|
+
verify?: boolean;
|
|
95
|
+
prefix?: Array<any>;
|
|
96
|
+
suffix?: Array<any>;
|
|
97
|
+
interacted?: boolean;
|
|
98
|
+
autoHeight?: boolean;
|
|
99
|
+
rows?: number;
|
|
100
|
+
}
|
|
101
|
+
const props: any = withDefaults(defineProps<Props>(), {
|
|
102
|
+
modelValue: '',
|
|
103
|
+
placeholder: '',
|
|
104
|
+
rules: () => [],
|
|
105
|
+
theme: '@a',
|
|
106
|
+
sz: '',
|
|
107
|
+
co: '',
|
|
108
|
+
block: true,
|
|
109
|
+
ready: false,
|
|
110
|
+
tips: '',
|
|
111
|
+
maxlength: null,
|
|
112
|
+
minlength: null,
|
|
113
|
+
disabled: false,
|
|
114
|
+
readonly: false,
|
|
115
|
+
clearable: true,
|
|
116
|
+
verify: false,
|
|
117
|
+
prefix: () => [],
|
|
118
|
+
suffix: () => [],
|
|
119
|
+
interacted: false,
|
|
120
|
+
// textarea 特有属性默认值
|
|
121
|
+
autoHeight: false,
|
|
122
|
+
rows: 3,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const state: any = reactive({
|
|
126
|
+
// 用户是否交互
|
|
127
|
+
interacted: false,
|
|
128
|
+
// 值
|
|
129
|
+
value: props.modelValue,
|
|
130
|
+
// 错误
|
|
131
|
+
error: {},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// textarea 元素引用
|
|
135
|
+
const el: any = ref(null);
|
|
136
|
+
|
|
137
|
+
// 自动高度功能
|
|
138
|
+
const fAutoHeight = () => {
|
|
139
|
+
nextTick(() => {
|
|
140
|
+
if (props.autoHeight && el.value) {
|
|
141
|
+
el.value.style.height = 'auto';
|
|
142
|
+
el.value.style.height = el.value.scrollHeight + 1 + 'px';
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// 外部传入交互标识,主要用于外部没有输入但点击了提交
|
|
148
|
+
watch(
|
|
149
|
+
() => props.interacted,
|
|
150
|
+
(interacted: any) => {
|
|
151
|
+
if (interacted) {
|
|
152
|
+
state.interacted = interacted;
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{ deep: true, immediate: true },
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// 校验
|
|
159
|
+
watch(
|
|
160
|
+
[() => state.interacted, () => props.modelValue],
|
|
161
|
+
async () => {
|
|
162
|
+
if (state.interacted) {
|
|
163
|
+
// 提示文案
|
|
164
|
+
let tips = '';
|
|
165
|
+
// 错误类型
|
|
166
|
+
let type = '';
|
|
167
|
+
// 验证结果
|
|
168
|
+
let verify = '';
|
|
169
|
+
|
|
170
|
+
if (props.modelValue) {
|
|
171
|
+
// 有值
|
|
172
|
+
let hasError = false;
|
|
173
|
+
// 遍历校验规则
|
|
174
|
+
for (const rule of props.rules) {
|
|
175
|
+
if (rule && rule.validator) {
|
|
176
|
+
const yes = !(await rule.validator(props.modelValue));
|
|
177
|
+
if (yes) {
|
|
178
|
+
tips = rule.msg;
|
|
179
|
+
type = rule.type;
|
|
180
|
+
hasError = true;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
verify = hasError ? 'no' : 'ok';
|
|
186
|
+
} else {
|
|
187
|
+
// 无值
|
|
188
|
+
let hasError = false;
|
|
189
|
+
// 遍历校验规则
|
|
190
|
+
for (const rule of props.rules) {
|
|
191
|
+
if (rule) {
|
|
192
|
+
tips = rule.msg;
|
|
193
|
+
type = rule.type;
|
|
194
|
+
if (rule.required) {
|
|
195
|
+
hasError = true;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
verify = hasError ? 'no' : '';
|
|
201
|
+
}
|
|
202
|
+
if (verify !== 'no' && props.tips) {
|
|
203
|
+
tips = props.tips;
|
|
204
|
+
}
|
|
205
|
+
// 是否显示提示
|
|
206
|
+
const ontips = (verify === 'no' && tips) || props.tips ? 'show' : '';
|
|
207
|
+
// 状态颜色
|
|
208
|
+
const co = verify === 'no' ? 'co:' + type : props.co ? 'co:' + props.co : '';
|
|
209
|
+
state.error = { tips, ontips, verify, co };
|
|
210
|
+
} else {
|
|
211
|
+
state.error = { tips: props.tips, ontips: props.tips ? 'show' : '', verify: '', co: '' };
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{ deep: true, immediate: true },
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// 清空
|
|
218
|
+
function clear() {
|
|
219
|
+
emits('update:modelValue', null);
|
|
220
|
+
emits('clear');
|
|
221
|
+
}
|
|
222
|
+
// 输入
|
|
223
|
+
const input = (e: any) => {
|
|
224
|
+
// 用户交互
|
|
225
|
+
if (!state.interacted) {
|
|
226
|
+
setTimeout(() => {
|
|
227
|
+
state.interacted = true;
|
|
228
|
+
}, 50);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// 长度限制
|
|
232
|
+
const value = e?.target?.value || '';
|
|
233
|
+
if (props.maxlength && value.length > props.maxlength) {
|
|
234
|
+
e.target.value = props.modelValue;
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
// 输入事件
|
|
238
|
+
emits('input', e, state);
|
|
239
|
+
emits('update:modelValue', value || null);
|
|
240
|
+
|
|
241
|
+
// 自动高度
|
|
242
|
+
fAutoHeight();
|
|
243
|
+
};
|
|
244
|
+
// 失焦
|
|
245
|
+
const blur = (e: any) => {
|
|
246
|
+
if (!state.interacted) {
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
state.interacted = true;
|
|
249
|
+
}, 50);
|
|
250
|
+
}
|
|
251
|
+
emits('blur', e, state);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// 事件处理
|
|
255
|
+
const event: any = (item: any, data: any): object => {
|
|
256
|
+
const _event: any = {};
|
|
257
|
+
if (isObject(item.event)) {
|
|
258
|
+
for (const key in item.event) {
|
|
259
|
+
const fun = item.event[key];
|
|
260
|
+
if (isFunction(fun)) {
|
|
261
|
+
_event[key] = (...args: any) => {
|
|
262
|
+
return fun({ data }, ...args);
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return { ..._event };
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// 组件挂载后初始化自动高度
|
|
271
|
+
onMounted(() => {
|
|
272
|
+
// 自动高度
|
|
273
|
+
fAutoHeight();
|
|
274
|
+
});
|
|
275
|
+
</script>
|