yh-mobile-components 1.0.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/custom.scss +167 -0
- package/form/yhm-form.vue +174 -0
- package/form/yhmCheckbox.vue +60 -0
- package/form/yhmDateTime/chooseDate.vue +345 -0
- package/form/yhmDateTime/chooseTime.vue +45 -0
- package/form/yhmDateTime/inputDateTime.vue +262 -0
- package/form/yhmDatetime.vue +176 -0
- package/form/yhmInput.vue +36 -0
- package/form/yhmRadio.vue +59 -0
- package/form/yhmSelect.vue +88 -0
- package/form/yhmSwitch.vue +91 -0
- package/index.ts +26 -0
- package/info/yhmDropdownItem.vue +35 -0
- package/info/yhmInfo.vue +37 -0
- package/info/yhmInfoItem.vue +121 -0
- package/info/yhmList.vue +195 -0
- package/package.json +14 -0
- package/readme.md +47 -0
- package/types.ts +88 -0
package/custom.scss
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
$Blue: (
|
|
2
|
+
1: #f2f3ff,
|
|
3
|
+
2: #d9e1ff,
|
|
4
|
+
3: #b5c7ff,
|
|
5
|
+
4: #8eabff,
|
|
6
|
+
5: #618dff,
|
|
7
|
+
6: #366ef4,
|
|
8
|
+
7: #0052d9,
|
|
9
|
+
8: #003cab,
|
|
10
|
+
9: #002a7c,
|
|
11
|
+
10: #001a57,
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
$Red: (
|
|
15
|
+
1: #fff0ed,
|
|
16
|
+
2: #ffd8d2,
|
|
17
|
+
3: #ffb9b0,
|
|
18
|
+
4: #ff9285,
|
|
19
|
+
5: #f6685d,
|
|
20
|
+
6: #d54941,
|
|
21
|
+
7: #ad352f,
|
|
22
|
+
8: #881f1c,
|
|
23
|
+
9: #68070a,
|
|
24
|
+
10: #490002,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
$Orange: (
|
|
28
|
+
1: #fff1e9,
|
|
29
|
+
2: #ffd9c2,
|
|
30
|
+
3: #ffb98c,
|
|
31
|
+
4: #fa9550,
|
|
32
|
+
5: #e37318,
|
|
33
|
+
6: #be5a00,
|
|
34
|
+
7: #954500,
|
|
35
|
+
8: #713300,
|
|
36
|
+
9: #532300,
|
|
37
|
+
10: #3b1700,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
$Green: (
|
|
41
|
+
1: #e3f9e9,
|
|
42
|
+
2: #c6f3d7,
|
|
43
|
+
3: #92dab2,
|
|
44
|
+
4: #56c08d,
|
|
45
|
+
5: #2ba471,
|
|
46
|
+
6: #008858,
|
|
47
|
+
7: #006c45,
|
|
48
|
+
8: #005334,
|
|
49
|
+
9: #003b23,
|
|
50
|
+
10: #002515,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
$Gray: (
|
|
54
|
+
1: #f3f3f3,
|
|
55
|
+
2: #eeeeee,
|
|
56
|
+
3: #e8e8e8,
|
|
57
|
+
4: #dddddd,
|
|
58
|
+
5: #c6c6c6,
|
|
59
|
+
6: #a6a6a6,
|
|
60
|
+
7: #8b8b8b,
|
|
61
|
+
8: #777777,
|
|
62
|
+
9: #5e5e5e,
|
|
63
|
+
10: #4b4b4b,
|
|
64
|
+
11: #393939,
|
|
65
|
+
12: #2c2c2c,
|
|
66
|
+
13: #242424,
|
|
67
|
+
14: #181818,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
$Cyan: (
|
|
71
|
+
1: #e8f5ff,
|
|
72
|
+
2: #c4e8ff,
|
|
73
|
+
3: #85d3ff,
|
|
74
|
+
4: #41b8f2,
|
|
75
|
+
5: #029cd4,
|
|
76
|
+
6: #0080b0,
|
|
77
|
+
7: #00668e,
|
|
78
|
+
8: #004e6d,
|
|
79
|
+
9: #003850,
|
|
80
|
+
10: #002536,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
$Purple: (
|
|
84
|
+
1: #fbf0ff,
|
|
85
|
+
2: #eedcff,
|
|
86
|
+
3: #dcbfff,
|
|
87
|
+
4: #c69cff,
|
|
88
|
+
5: #ad75fe,
|
|
89
|
+
6: #8e56dd,
|
|
90
|
+
7: #7137bf,
|
|
91
|
+
8: #5610a4,
|
|
92
|
+
9: #3b007b,
|
|
93
|
+
10: #280057,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
$Yellow: (
|
|
97
|
+
1: #fff5e4,
|
|
98
|
+
2: #ffe7b5,
|
|
99
|
+
3: #ffd36d,
|
|
100
|
+
4: #f5ba18,
|
|
101
|
+
5: #d8a100,
|
|
102
|
+
6: #b38500,
|
|
103
|
+
7: #8b6600,
|
|
104
|
+
8: #654900,
|
|
105
|
+
9: #443000,
|
|
106
|
+
10: #2b1d00,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
$Pink: (
|
|
110
|
+
1: #fff0f6,
|
|
111
|
+
2: #ffd8eb,
|
|
112
|
+
3: #ffaedc,
|
|
113
|
+
4: #ff79cd,
|
|
114
|
+
5: #e851b3,
|
|
115
|
+
6: #c43695,
|
|
116
|
+
7: #a12279,
|
|
117
|
+
8: #800a5f,
|
|
118
|
+
9: #610046,
|
|
119
|
+
10: #43002f,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
:root {
|
|
123
|
+
@each $index, $color in $Blue {
|
|
124
|
+
--van-blue-#{$index}: #{$color};
|
|
125
|
+
}
|
|
126
|
+
@each $index, $color in $Red {
|
|
127
|
+
--van-red-#{$index}: #{$color};
|
|
128
|
+
}
|
|
129
|
+
@each $index, $color in $Orange {
|
|
130
|
+
--van-orange-#{$index}: #{$color};
|
|
131
|
+
}
|
|
132
|
+
@each $index, $color in $Green {
|
|
133
|
+
--van-green-#{$index}: #{$color};
|
|
134
|
+
}
|
|
135
|
+
@each $index, $color in $Gray {
|
|
136
|
+
--van-gray-#{$index}: #{$color};
|
|
137
|
+
}
|
|
138
|
+
@each $index, $color in $Cyan {
|
|
139
|
+
--van-cyan-#{$index}: #{$color};
|
|
140
|
+
}
|
|
141
|
+
@each $index, $color in $Purple {
|
|
142
|
+
--van-purple-#{$index}: #{$color};
|
|
143
|
+
}
|
|
144
|
+
@each $index, $color in $Yellow {
|
|
145
|
+
--van-yellow-#{$index}: #{$color};
|
|
146
|
+
}
|
|
147
|
+
@each $index, $color in $Pink {
|
|
148
|
+
--van-pink-#{$index}: #{$color};
|
|
149
|
+
}
|
|
150
|
+
--van-red: var(--van-red-6);
|
|
151
|
+
--van-blue: var(--van-blue-7);
|
|
152
|
+
--van-orange: var(--van-orange-5);
|
|
153
|
+
--van-orange-dark: var(--van-orange-7);
|
|
154
|
+
--van-orange-light: var(--van-orange-2);
|
|
155
|
+
--van-green: var(--van-green-5);
|
|
156
|
+
--van-cyan: var(--van-cyan-5);
|
|
157
|
+
--van-purple: var(--van-purple-6);
|
|
158
|
+
--van-yellow: var(--van-yellow-4);
|
|
159
|
+
--van-pink: var(--van-pink-5);
|
|
160
|
+
--van-text-color: var(--van-gray-14);
|
|
161
|
+
--van-text-color-2: var(--van-gray-8);
|
|
162
|
+
--van-text-color-3: var(--van-gray-5);
|
|
163
|
+
--van-primary-bg: var(--van-blue-2);
|
|
164
|
+
--van-success-bg: var(--van-green-2);
|
|
165
|
+
--van-danger-bg: var(--van-red-2);
|
|
166
|
+
--van-warning-bg: var(--van-orange-2);
|
|
167
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<style lang="scss">
|
|
2
|
+
.yhm-form-container {
|
|
3
|
+
padding: 16px 0;
|
|
4
|
+
.van-form {
|
|
5
|
+
margin-bottom: 16px;
|
|
6
|
+
}
|
|
7
|
+
.yhm-form-actions {
|
|
8
|
+
padding: 0 16px;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
</style>
|
|
12
|
+
<template>
|
|
13
|
+
<section class="yhm-form-container">
|
|
14
|
+
<van-form>
|
|
15
|
+
<template v-for="item in optionsConfig">
|
|
16
|
+
<component
|
|
17
|
+
:is="item.component"
|
|
18
|
+
v-bind="item.attrs"
|
|
19
|
+
:error="item.error"
|
|
20
|
+
:error-message="item.errorMessage"
|
|
21
|
+
:model-value="formData[item.name]"
|
|
22
|
+
@update:modelValue="handlerChange($event, item)"></component>
|
|
23
|
+
</template>
|
|
24
|
+
</van-form>
|
|
25
|
+
<div class="yhm-form-actions">
|
|
26
|
+
<slot></slot>
|
|
27
|
+
</div>
|
|
28
|
+
</section>
|
|
29
|
+
</template>
|
|
30
|
+
<script lang="ts" setup>
|
|
31
|
+
import { computed, watch, reactive, onMounted } from "vue";
|
|
32
|
+
import { ConfigFormItem, SwitchConfig } from "../types";
|
|
33
|
+
|
|
34
|
+
const props = defineProps<{
|
|
35
|
+
options: ConfigFormItem[];
|
|
36
|
+
formData: any;
|
|
37
|
+
verification: boolean;
|
|
38
|
+
}>();
|
|
39
|
+
|
|
40
|
+
interface ConfigItem {
|
|
41
|
+
component: string;
|
|
42
|
+
rex: ConfigFormItem["rex"];
|
|
43
|
+
rexMsg: ConfigFormItem["rexMsg"];
|
|
44
|
+
name: ConfigFormItem["name"];
|
|
45
|
+
defaultValue: ConfigFormItem["defaultValue"];
|
|
46
|
+
error: boolean;
|
|
47
|
+
errorMessage: string;
|
|
48
|
+
attrs: Record<string, any>;
|
|
49
|
+
itemChange?: (val, data) => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const optionsConfig = computed<ConfigItem[]>(() => {
|
|
53
|
+
return props.options.map((item) => {
|
|
54
|
+
let { label, required, name, defaultValue, disabled, placeholder, type, rexMsg, rex, itemChange, labelAlign, config } = item;
|
|
55
|
+
let error = false;
|
|
56
|
+
let errorMessage = "";
|
|
57
|
+
let component = "yhm-input";
|
|
58
|
+
switch (type) {
|
|
59
|
+
case "year":
|
|
60
|
+
case "month":
|
|
61
|
+
case "datetime":
|
|
62
|
+
case "date":
|
|
63
|
+
case "time":
|
|
64
|
+
component = "yhm-datetime";
|
|
65
|
+
if (!defaultValue) defaultValue = "";
|
|
66
|
+
break;
|
|
67
|
+
case "radio":
|
|
68
|
+
component = "yhm-radio";
|
|
69
|
+
if (!defaultValue) defaultValue = "";
|
|
70
|
+
break;
|
|
71
|
+
case "select":
|
|
72
|
+
component = "yhm-select";
|
|
73
|
+
if (!defaultValue) defaultValue = "";
|
|
74
|
+
break;
|
|
75
|
+
case "switch":
|
|
76
|
+
component = "yhm-switch";
|
|
77
|
+
if (!defaultValue) defaultValue = (config as SwitchConfig).activeValue || "";
|
|
78
|
+
break;
|
|
79
|
+
case "checkbox":
|
|
80
|
+
component = "yhm-checkbox";
|
|
81
|
+
if (!defaultValue) defaultValue = [];
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
component,
|
|
86
|
+
rex,
|
|
87
|
+
rexMsg,
|
|
88
|
+
name,
|
|
89
|
+
defaultValue,
|
|
90
|
+
error,
|
|
91
|
+
errorMessage,
|
|
92
|
+
attrs: {
|
|
93
|
+
label,
|
|
94
|
+
required,
|
|
95
|
+
disabled,
|
|
96
|
+
placeholder,
|
|
97
|
+
type,
|
|
98
|
+
labelAlign,
|
|
99
|
+
...config,
|
|
100
|
+
},
|
|
101
|
+
itemChange,
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const emits = defineEmits<{
|
|
107
|
+
(e: "update:verification", val: boolean);
|
|
108
|
+
}>();
|
|
109
|
+
|
|
110
|
+
const verificationResult = reactive<any>({});
|
|
111
|
+
|
|
112
|
+
watch(
|
|
113
|
+
() => verificationResult,
|
|
114
|
+
(val) => {
|
|
115
|
+
let vals = Object.values(val);
|
|
116
|
+
let flag = !(vals && vals.includes(true));
|
|
117
|
+
emits("update:verification", flag);
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
deep: true,
|
|
121
|
+
immediate: true,
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
function handlerChange(val, item) {
|
|
126
|
+
let {
|
|
127
|
+
name,
|
|
128
|
+
itemChange,
|
|
129
|
+
rex,
|
|
130
|
+
rexMsg,
|
|
131
|
+
attrs: { required },
|
|
132
|
+
} = item;
|
|
133
|
+
|
|
134
|
+
props.formData[name] = val;
|
|
135
|
+
|
|
136
|
+
if (itemChange && typeof itemChange === "function") {
|
|
137
|
+
itemChange(val, props.formData);
|
|
138
|
+
}
|
|
139
|
+
let valFlag = false;
|
|
140
|
+
if (val instanceof Array) {
|
|
141
|
+
valFlag = val.length > 0;
|
|
142
|
+
} else if (typeof val === "number") {
|
|
143
|
+
valFlag = !isNaN(val);
|
|
144
|
+
} else {
|
|
145
|
+
valFlag = !!val;
|
|
146
|
+
}
|
|
147
|
+
let flag = true;
|
|
148
|
+
if (rex && rex instanceof RegExp) {
|
|
149
|
+
flag = rex.test(val);
|
|
150
|
+
if (!flag) {
|
|
151
|
+
item.error = true;
|
|
152
|
+
item.errorMessage = rexMsg;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (rex === undefined && typeof required === "boolean" && required && !valFlag) {
|
|
156
|
+
flag = false;
|
|
157
|
+
item.error = true;
|
|
158
|
+
item.errorMessage = `${item.attrs.label}不能为空`;
|
|
159
|
+
}
|
|
160
|
+
if (flag) {
|
|
161
|
+
verificationResult[name] = false;
|
|
162
|
+
item.error = false;
|
|
163
|
+
item.errorMessage = "";
|
|
164
|
+
} else {
|
|
165
|
+
verificationResult[name] = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
onMounted(() => {
|
|
170
|
+
optionsConfig.value.forEach((option) => {
|
|
171
|
+
handlerChange(option.defaultValue || "", option);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
</script>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<van-field
|
|
3
|
+
class="yhm-radio-container"
|
|
4
|
+
v-bind="$attrs"
|
|
5
|
+
:disabled="disabled"
|
|
6
|
+
:error="error"
|
|
7
|
+
:error-message="errorMessage">
|
|
8
|
+
<template #input>
|
|
9
|
+
<div class="yhm-radio-list">
|
|
10
|
+
<van-checkbox-group
|
|
11
|
+
shape="square"
|
|
12
|
+
:disabled="disabled"
|
|
13
|
+
:model-value="modelValue"
|
|
14
|
+
@update:modelValue="changeHandler">
|
|
15
|
+
<van-checkbox
|
|
16
|
+
v-for="option in optionData"
|
|
17
|
+
:name="option.value">
|
|
18
|
+
{{ option.text }}
|
|
19
|
+
</van-checkbox>
|
|
20
|
+
</van-checkbox-group>
|
|
21
|
+
</div>
|
|
22
|
+
</template>
|
|
23
|
+
</van-field>
|
|
24
|
+
</template>
|
|
25
|
+
<script setup lang="ts">
|
|
26
|
+
import { vanOption } from "../types";
|
|
27
|
+
|
|
28
|
+
const props = withDefaults(
|
|
29
|
+
defineProps<{
|
|
30
|
+
error: boolean;
|
|
31
|
+
errorMessage: string;
|
|
32
|
+
modelValue?: any[];
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
optionData: vanOption[];
|
|
35
|
+
}>(),
|
|
36
|
+
{}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const emits = defineEmits<{
|
|
40
|
+
(e: "update:modelValue", val: any);
|
|
41
|
+
(e: "change", val: string);
|
|
42
|
+
}>();
|
|
43
|
+
|
|
44
|
+
function changeHandler(val) {
|
|
45
|
+
emits("update:modelValue", val);
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
<style lang="scss">
|
|
49
|
+
.yhm-radio-container {
|
|
50
|
+
.yhm-radio-list {
|
|
51
|
+
flex: 1;
|
|
52
|
+
.van-checkbox {
|
|
53
|
+
padding-bottom: 5px;
|
|
54
|
+
&:first-child {
|
|
55
|
+
padding-top: 5px;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
</style>
|