hy-app 0.3.2 → 0.3.4
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/components/hy-action-sheet/index.scss +1 -1
- package/components/hy-address-picker/index.scss +1 -1
- package/components/hy-avatar/hy-avatar.vue +10 -13
- package/components/hy-avatar/index.scss +2 -2
- package/components/hy-back-top/index.scss +2 -2
- package/components/hy-badge/index.scss +1 -1
- package/components/hy-button/index.scss +3 -3
- package/components/hy-calendar/header.vue +11 -11
- package/components/hy-calendar/index.scss +26 -26
- package/components/hy-calendar/month.vue +18 -19
- package/components/hy-card/hy-card.vue +10 -12
- package/components/hy-card/index.scss +12 -10
- package/components/hy-cell/hy-cell.vue +13 -13
- package/components/hy-cell/index.scss +16 -16
- package/components/hy-checkbox/hy-checkbox.vue +10 -10
- package/components/hy-checkbox/index.scss +25 -24
- package/components/hy-code-input/hy-code-input.vue +314 -314
- package/components/hy-code-input/index.scss +1 -1
- package/components/hy-config-provider/index.scss +3 -2
- package/components/hy-count-down/index.scss +1 -1
- package/components/hy-count-to/index.scss +1 -1
- package/components/hy-divider/index.scss +1 -1
- package/components/hy-dropdown/index.scss +1 -1
- package/components/hy-dropdown-item/index.scss +1 -1
- package/components/hy-empty/hy-empty.vue +15 -12
- package/components/hy-empty/icon.ts +32 -58
- package/components/hy-empty/index.scss +3 -3
- package/components/hy-empty/typing.d.ts +48 -35
- package/components/hy-float-button/index.scss +1 -1
- package/components/hy-folding-panel/index.scss +1 -1
- package/components/hy-form/hy-form.vue +3 -2
- package/components/hy-form-group/index.scss +1 -1
- package/components/hy-form-item/index.scss +41 -41
- package/components/hy-grid/index.scss +1 -1
- package/components/hy-icon/index.scss +1 -1
- package/components/hy-image/index.scss +1 -1
- package/components/hy-input/hy-input.vue +2 -2
- package/components/hy-input/index.scss +1 -1
- package/components/hy-line/index.scss +1 -1
- package/components/hy-line-progress/index.scss +1 -1
- package/components/hy-list/index.scss +1 -1
- package/components/hy-loading/index.scss +1 -1
- package/components/hy-menu/index.scss +1 -1
- package/components/hy-modal/index.scss +1 -1
- package/components/hy-navbar/index.scss +1 -1
- package/components/hy-notice-bar/hy-column-notice.vue +2 -2
- package/components/hy-notice-bar/hy-row-notice.vue +1 -1
- package/components/hy-notice-bar/index.scss +7 -1
- package/components/hy-notify/index.scss +1 -1
- package/components/hy-number-step/index.scss +1 -1
- package/components/hy-overlay/index.scss +1 -1
- package/components/hy-pagination/index.scss +1 -1
- package/components/hy-picker/index.scss +1 -1
- package/components/hy-popover/index.scss +4 -4
- package/components/hy-popup/index.scss +1 -1
- package/components/hy-price/index.scss +1 -1
- package/components/hy-qrcode/index.scss +1 -1
- package/components/hy-radio/index.scss +1 -1
- package/components/hy-read-more/index.scss +1 -1
- package/components/hy-scroll-list/index.scss +1 -1
- package/components/hy-search/hy-search.vue +2 -9
- package/components/hy-search/index.scss +1 -1
- package/components/hy-signature/index.scss +1 -1
- package/components/hy-slider/hy-slider.vue +1 -1
- package/components/hy-slider/index.scss +1 -1
- package/components/hy-steps/index.scss +1 -1
- package/components/hy-submit-bar/index.scss +1 -1
- package/components/hy-subsection/index.scss +1 -1
- package/components/hy-swipe-action/index.scss +1 -1
- package/components/hy-swiper/index.scss +1 -1
- package/components/hy-switch/index.scss +1 -1
- package/components/hy-tabBar/index.scss +1 -1
- package/components/hy-tabs/index.scss +1 -1
- package/components/hy-tag/hy-tag.vue +2 -2
- package/components/hy-tag/index.scss +14 -13
- package/components/hy-text/index.scss +1 -1
- package/components/hy-textarea/index.scss +7 -1
- package/components/hy-toast/index.scss +1 -1
- package/components/hy-tooltip/index.scss +1 -1
- package/components/hy-upload/hy-upload.vue +5 -12
- package/components/hy-upload/index.scss +1 -1
- package/components/hy-upload/typing.d.ts +21 -0
- package/components/hy-warn/index.scss +1 -1
- package/components/hy-watermark/index.scss +1 -1
- package/index.scss +3 -2
- package/libs/css/common.scss +1 -1
- package/libs/css/mixin.scss +16 -13
- package/{theme.scss → libs/css/theme.scss} +2 -0
- package/libs/css/{vars.css → vars.scss} +2 -0
- package/package.json +6 -3
- package/typing/modules/common.d.ts +2 -0
- package/web-types.json +1 -1
- package/components/avatar.zip +0 -0
|
@@ -1,314 +1,314 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="hy-code-input">
|
|
3
|
-
<view
|
|
4
|
-
:class="itemClass(index)"
|
|
5
|
-
:style="[itemStyle(index)]"
|
|
6
|
-
v-for="(item, index) in codeLength"
|
|
7
|
-
:key="index"
|
|
8
|
-
>
|
|
9
|
-
<view
|
|
10
|
-
class="hy-code-input--item__dot"
|
|
11
|
-
v-if="dot && current > index"
|
|
12
|
-
:style="{ color: color }"
|
|
13
|
-
></view>
|
|
14
|
-
<text
|
|
15
|
-
v-else
|
|
16
|
-
class="hy-code-input--item__text"
|
|
17
|
-
:style="{
|
|
18
|
-
fontSize: addUnit(fontSize),
|
|
19
|
-
fontWeight: bold ? 'bold' : 'normal',
|
|
20
|
-
color: color,
|
|
21
|
-
}"
|
|
22
|
-
>
|
|
23
|
-
{{ codeArray[index] }}
|
|
24
|
-
</text>
|
|
25
|
-
</view>
|
|
26
|
-
<input
|
|
27
|
-
:disabled="disabledKeyboard"
|
|
28
|
-
type="number"
|
|
29
|
-
:focus="focus"
|
|
30
|
-
:value="inputValue"
|
|
31
|
-
:maxlength="maxlength"
|
|
32
|
-
:adjustPosition="adjustPosition"
|
|
33
|
-
class="hy-code-input__input"
|
|
34
|
-
@input="inputHandler"
|
|
35
|
-
:style="{
|
|
36
|
-
height: boxSize,
|
|
37
|
-
}"
|
|
38
|
-
@focus="isFocus = true"
|
|
39
|
-
@blur="isFocus = false"
|
|
40
|
-
/>
|
|
41
|
-
</view>
|
|
42
|
-
</template>
|
|
43
|
-
|
|
44
|
-
<script lang="ts">
|
|
45
|
-
export default {
|
|
46
|
-
name: "hy-code-input",
|
|
47
|
-
options: {
|
|
48
|
-
addGlobalClass: true,
|
|
49
|
-
virtualHost: true,
|
|
50
|
-
styleIsolation: "shared",
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
</script>
|
|
54
|
-
|
|
55
|
-
<script setup lang="ts">
|
|
56
|
-
import { computed, nextTick, onUnmounted, ref, watch } from "vue";
|
|
57
|
-
import type { CSSProperties, PropType } from "vue";
|
|
58
|
-
import type { ICodeInputEmits } from "./typing";
|
|
59
|
-
import { addUnit, getPx } from "../../utils";
|
|
60
|
-
import type { InputOnInputEvent } from "@uni-helper/uni-types";
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 一般用于验证用户短信验证码的场景,也可以结合华玥的键盘组件使用
|
|
64
|
-
* @displayName hy-code-input
|
|
65
|
-
*/
|
|
66
|
-
defineOptions({});
|
|
67
|
-
|
|
68
|
-
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
69
|
-
const props = defineProps({
|
|
70
|
-
/** 获取值 */
|
|
71
|
-
modelValue: {
|
|
72
|
-
type: [String, Number],
|
|
73
|
-
required: true,
|
|
74
|
-
},
|
|
75
|
-
/** 键盘弹起时,是否自动上推页面 */
|
|
76
|
-
adjustPosition: {
|
|
77
|
-
type: Boolean,
|
|
78
|
-
default: true,
|
|
79
|
-
},
|
|
80
|
-
/** 最大输入长度 */
|
|
81
|
-
maxlength: {
|
|
82
|
-
type: Number,
|
|
83
|
-
default: 6,
|
|
84
|
-
},
|
|
85
|
-
/** 显示border */
|
|
86
|
-
border: {
|
|
87
|
-
type: Boolean,
|
|
88
|
-
default: true,
|
|
89
|
-
},
|
|
90
|
-
/** 是否用圆点填充 */
|
|
91
|
-
dot: {
|
|
92
|
-
type: Boolean,
|
|
93
|
-
default: false,
|
|
94
|
-
},
|
|
95
|
-
/**
|
|
96
|
-
* 示模式,box-盒子模式,line-底部横线模式
|
|
97
|
-
* @values box,line
|
|
98
|
-
* */
|
|
99
|
-
mode: {
|
|
100
|
-
type: String,
|
|
101
|
-
default: "box",
|
|
102
|
-
},
|
|
103
|
-
/** 是否细边框 */
|
|
104
|
-
hairline: {
|
|
105
|
-
type: Boolean,
|
|
106
|
-
default: false,
|
|
107
|
-
},
|
|
108
|
-
/** 字符间的距离 */
|
|
109
|
-
space: {
|
|
110
|
-
type: Number,
|
|
111
|
-
default: 10,
|
|
112
|
-
},
|
|
113
|
-
/** 是否自动获取焦点 */
|
|
114
|
-
focus: {
|
|
115
|
-
type: Boolean,
|
|
116
|
-
default: false,
|
|
117
|
-
},
|
|
118
|
-
/** 字体是否加粗 */
|
|
119
|
-
bold: {
|
|
120
|
-
type: Boolean,
|
|
121
|
-
default: false,
|
|
122
|
-
},
|
|
123
|
-
/** 字体颜色 */
|
|
124
|
-
color: String,
|
|
125
|
-
/** 字体大小,单位px */
|
|
126
|
-
fontSize: {
|
|
127
|
-
type: [String, Number],
|
|
128
|
-
default: 18,
|
|
129
|
-
},
|
|
130
|
-
/** 输入框的大小,宽等于高 */
|
|
131
|
-
size: {
|
|
132
|
-
type: [String, Number],
|
|
133
|
-
default: 35,
|
|
134
|
-
},
|
|
135
|
-
/** 是否隐藏原生键盘,如果想用自定义键盘的话,需设置此参数为true */
|
|
136
|
-
disabledKeyboard: {
|
|
137
|
-
type: Boolean,
|
|
138
|
-
default: false,
|
|
139
|
-
},
|
|
140
|
-
/** 边框和线条颜色 */
|
|
141
|
-
borderColor: String,
|
|
142
|
-
/** 是否禁止输入"."符号 */
|
|
143
|
-
disabledDot: {
|
|
144
|
-
type: Boolean,
|
|
145
|
-
default: true,
|
|
146
|
-
},
|
|
147
|
-
/** 定义需要用到的外部样式 */
|
|
148
|
-
customStyle: {
|
|
149
|
-
type: Object as PropType<CSSProperties>,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
const emit = defineEmits<ICodeInputEmits>();
|
|
153
|
-
|
|
154
|
-
const current = ref(0);
|
|
155
|
-
const inputValue = ref("");
|
|
156
|
-
const isFocus = ref(props.focus);
|
|
157
|
-
let timer: ReturnType<typeof setInterval>;
|
|
158
|
-
const opacity = ref(1);
|
|
159
|
-
const borderWidth = computed(() => (props.hairline ? "0.5px" : "2px"));
|
|
160
|
-
const lineHeight = computed(() => (props.hairline ? "2px" : "4px"));
|
|
161
|
-
const boxSize = addUnit(props.size);
|
|
162
|
-
|
|
163
|
-
watch(
|
|
164
|
-
() => props.modelValue,
|
|
165
|
-
(newValue: string | number) => {
|
|
166
|
-
inputValue.value = String(newValue).substring(0, props.maxlength);
|
|
167
|
-
current.value = newValue.toString().length;
|
|
168
|
-
},
|
|
169
|
-
{ immediate: true },
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
watch(
|
|
173
|
-
() => isFocus.value,
|
|
174
|
-
(newValue) => {
|
|
175
|
-
// #ifdef APP-NVUE
|
|
176
|
-
if (newValue) {
|
|
177
|
-
timer = setInterval(() => {
|
|
178
|
-
opacity.value = Math.abs(opacity.value - 1);
|
|
179
|
-
}, 600);
|
|
180
|
-
} else {
|
|
181
|
-
clearInterval(timer);
|
|
182
|
-
}
|
|
183
|
-
// #endif
|
|
184
|
-
},
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
onUnmounted(() => {
|
|
188
|
-
// #ifdef APP-NVUE
|
|
189
|
-
clearInterval(timer);
|
|
190
|
-
// #endif
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
// 根据长度,循环输入框的个数,因为头条小程序数值不能用于v-for
|
|
194
|
-
const codeLength = computed(() => {
|
|
195
|
-
return new Array(Number(props.maxlength));
|
|
196
|
-
});
|
|
197
|
-
// 循环item的样式
|
|
198
|
-
const itemStyle = computed(() => {
|
|
199
|
-
return (index: number) => {
|
|
200
|
-
const style: CSSProperties = {
|
|
201
|
-
width: boxSize,
|
|
202
|
-
height: boxSize,
|
|
203
|
-
};
|
|
204
|
-
if (props.borderColor) {
|
|
205
|
-
style["--hy-border-color"] = props.borderColor;
|
|
206
|
-
}
|
|
207
|
-
// 盒子模式下,需要额外进行处理
|
|
208
|
-
if (props.mode === "box" && props.border) {
|
|
209
|
-
// 设置盒子的边框,如果是细边框,则设置为1px宽度
|
|
210
|
-
style.borderWidth = borderWidth.value;
|
|
211
|
-
style.borderStyle = "solid";
|
|
212
|
-
style.borderColor = props.borderColor;
|
|
213
|
-
// 如果盒子间距为0的话
|
|
214
|
-
if (getPx(props.space) === 0) {
|
|
215
|
-
// 给第一和最后一个盒子设置圆角
|
|
216
|
-
if (index === 0) {
|
|
217
|
-
style.borderTopLeftRadius = "6px";
|
|
218
|
-
style.borderBottomLeftRadius = "6px";
|
|
219
|
-
}
|
|
220
|
-
if (index === codeLength.value.length - 1) {
|
|
221
|
-
style.borderTopRightRadius = "6px";
|
|
222
|
-
style.borderBottomRightRadius = "6px";
|
|
223
|
-
}
|
|
224
|
-
// 最后一个盒子的右边框需要保留
|
|
225
|
-
if (index !== codeLength.value.length - 1) {
|
|
226
|
-
style.borderRight = "none";
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (index !== codeLength.value.length - 1) {
|
|
231
|
-
// 设置验证码字符之间的距离,通过margin-right设置,最后一个字符,无需右边框
|
|
232
|
-
style.marginRight = addUnit(props.space);
|
|
233
|
-
} else {
|
|
234
|
-
// 最后一个盒子的有边框需要保留
|
|
235
|
-
style.marginRight = 0;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return style;
|
|
239
|
-
};
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
const itemClass = computed(() => {
|
|
243
|
-
return (index: number) => {
|
|
244
|
-
return [
|
|
245
|
-
"hy-code-input--item",
|
|
246
|
-
props.border
|
|
247
|
-
? `hy-code-input--item__${props.mode}`
|
|
248
|
-
: "hy-code-input--item__not",
|
|
249
|
-
current.value > index &&
|
|
250
|
-
getPx(props.space) != 0 &&
|
|
251
|
-
props.border &&
|
|
252
|
-
`hy-code-input--item__${props.mode}__border`,
|
|
253
|
-
isFocus.value &&
|
|
254
|
-
current.value === index &&
|
|
255
|
-
getPx(props.space) != 0 &&
|
|
256
|
-
(props.border
|
|
257
|
-
? `hy-code-input--item__${props.mode}__active`
|
|
258
|
-
: "hy-code-input--item__not__active"),
|
|
259
|
-
];
|
|
260
|
-
};
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* @description 将输入的值,转为数组,给item历遍时,根据当前的索引显示数组的元素
|
|
265
|
-
*/
|
|
266
|
-
const codeArray = computed(() => {
|
|
267
|
-
return String(inputValue.value).split("");
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* @description 监听输入框的值发生变化
|
|
272
|
-
* */
|
|
273
|
-
const inputHandler = (e: InputOnInputEvent) => {
|
|
274
|
-
const value = e.detail.value;
|
|
275
|
-
inputValue.value = value;
|
|
276
|
-
// 是否允许输入“.”符号
|
|
277
|
-
if (props.disabledDot) {
|
|
278
|
-
nextTick(() => {
|
|
279
|
-
inputValue.value = value.replace(".", "");
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
// 未达到maxlength之前,发送change事件,达到后发送finish事件
|
|
283
|
-
emit("change", value);
|
|
284
|
-
// 修改通过v-model双向绑定的值
|
|
285
|
-
emit("update:modelValue", value);
|
|
286
|
-
// 达到用户指定输入长度时,发出完成事件
|
|
287
|
-
if (String(value).length >= Number(props.maxlength)) {
|
|
288
|
-
emit("finish", value);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
</script>
|
|
292
|
-
|
|
293
|
-
<style scoped lang="scss">
|
|
294
|
-
@import "./index.scss";
|
|
295
|
-
@import "../../libs/css/mixin.scss";
|
|
296
|
-
@import "../../theme
|
|
297
|
-
@include b(code-input) {
|
|
298
|
-
@include m(item) {
|
|
299
|
-
&__box {
|
|
300
|
-
&__active {
|
|
301
|
-
width: v-bind(boxSize);
|
|
302
|
-
height: v-bind(boxSize);
|
|
303
|
-
border-width: v-bind(borderWidth);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
&__line {
|
|
307
|
-
&::after {
|
|
308
|
-
height: v-bind(lineHeight);
|
|
309
|
-
background-color: $hy-border-color;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-code-input">
|
|
3
|
+
<view
|
|
4
|
+
:class="itemClass(index)"
|
|
5
|
+
:style="[itemStyle(index)]"
|
|
6
|
+
v-for="(item, index) in codeLength"
|
|
7
|
+
:key="index"
|
|
8
|
+
>
|
|
9
|
+
<view
|
|
10
|
+
class="hy-code-input--item__dot"
|
|
11
|
+
v-if="dot && current > index"
|
|
12
|
+
:style="{ color: color }"
|
|
13
|
+
></view>
|
|
14
|
+
<text
|
|
15
|
+
v-else
|
|
16
|
+
class="hy-code-input--item__text"
|
|
17
|
+
:style="{
|
|
18
|
+
fontSize: addUnit(fontSize),
|
|
19
|
+
fontWeight: bold ? 'bold' : 'normal',
|
|
20
|
+
color: color,
|
|
21
|
+
}"
|
|
22
|
+
>
|
|
23
|
+
{{ codeArray[index] }}
|
|
24
|
+
</text>
|
|
25
|
+
</view>
|
|
26
|
+
<input
|
|
27
|
+
:disabled="disabledKeyboard"
|
|
28
|
+
type="number"
|
|
29
|
+
:focus="focus"
|
|
30
|
+
:value="inputValue"
|
|
31
|
+
:maxlength="maxlength"
|
|
32
|
+
:adjustPosition="adjustPosition"
|
|
33
|
+
class="hy-code-input__input"
|
|
34
|
+
@input="inputHandler"
|
|
35
|
+
:style="{
|
|
36
|
+
height: boxSize,
|
|
37
|
+
}"
|
|
38
|
+
@focus="isFocus = true"
|
|
39
|
+
@blur="isFocus = false"
|
|
40
|
+
/>
|
|
41
|
+
</view>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script lang="ts">
|
|
45
|
+
export default {
|
|
46
|
+
name: "hy-code-input",
|
|
47
|
+
options: {
|
|
48
|
+
addGlobalClass: true,
|
|
49
|
+
virtualHost: true,
|
|
50
|
+
styleIsolation: "shared",
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<script setup lang="ts">
|
|
56
|
+
import { computed, nextTick, onUnmounted, ref, watch } from "vue";
|
|
57
|
+
import type { CSSProperties, PropType } from "vue";
|
|
58
|
+
import type { ICodeInputEmits } from "./typing";
|
|
59
|
+
import { addUnit, getPx } from "../../utils";
|
|
60
|
+
import type { InputOnInputEvent } from "@uni-helper/uni-types";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 一般用于验证用户短信验证码的场景,也可以结合华玥的键盘组件使用
|
|
64
|
+
* @displayName hy-code-input
|
|
65
|
+
*/
|
|
66
|
+
defineOptions({});
|
|
67
|
+
|
|
68
|
+
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
69
|
+
const props = defineProps({
|
|
70
|
+
/** 获取值 */
|
|
71
|
+
modelValue: {
|
|
72
|
+
type: [String, Number],
|
|
73
|
+
required: true,
|
|
74
|
+
},
|
|
75
|
+
/** 键盘弹起时,是否自动上推页面 */
|
|
76
|
+
adjustPosition: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
default: true,
|
|
79
|
+
},
|
|
80
|
+
/** 最大输入长度 */
|
|
81
|
+
maxlength: {
|
|
82
|
+
type: Number,
|
|
83
|
+
default: 6,
|
|
84
|
+
},
|
|
85
|
+
/** 显示border */
|
|
86
|
+
border: {
|
|
87
|
+
type: Boolean,
|
|
88
|
+
default: true,
|
|
89
|
+
},
|
|
90
|
+
/** 是否用圆点填充 */
|
|
91
|
+
dot: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: false,
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* 示模式,box-盒子模式,line-底部横线模式
|
|
97
|
+
* @values box,line
|
|
98
|
+
* */
|
|
99
|
+
mode: {
|
|
100
|
+
type: String,
|
|
101
|
+
default: "box",
|
|
102
|
+
},
|
|
103
|
+
/** 是否细边框 */
|
|
104
|
+
hairline: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
default: false,
|
|
107
|
+
},
|
|
108
|
+
/** 字符间的距离 */
|
|
109
|
+
space: {
|
|
110
|
+
type: Number,
|
|
111
|
+
default: 10,
|
|
112
|
+
},
|
|
113
|
+
/** 是否自动获取焦点 */
|
|
114
|
+
focus: {
|
|
115
|
+
type: Boolean,
|
|
116
|
+
default: false,
|
|
117
|
+
},
|
|
118
|
+
/** 字体是否加粗 */
|
|
119
|
+
bold: {
|
|
120
|
+
type: Boolean,
|
|
121
|
+
default: false,
|
|
122
|
+
},
|
|
123
|
+
/** 字体颜色 */
|
|
124
|
+
color: String,
|
|
125
|
+
/** 字体大小,单位px */
|
|
126
|
+
fontSize: {
|
|
127
|
+
type: [String, Number],
|
|
128
|
+
default: 18,
|
|
129
|
+
},
|
|
130
|
+
/** 输入框的大小,宽等于高 */
|
|
131
|
+
size: {
|
|
132
|
+
type: [String, Number],
|
|
133
|
+
default: 35,
|
|
134
|
+
},
|
|
135
|
+
/** 是否隐藏原生键盘,如果想用自定义键盘的话,需设置此参数为true */
|
|
136
|
+
disabledKeyboard: {
|
|
137
|
+
type: Boolean,
|
|
138
|
+
default: false,
|
|
139
|
+
},
|
|
140
|
+
/** 边框和线条颜色 */
|
|
141
|
+
borderColor: String,
|
|
142
|
+
/** 是否禁止输入"."符号 */
|
|
143
|
+
disabledDot: {
|
|
144
|
+
type: Boolean,
|
|
145
|
+
default: true,
|
|
146
|
+
},
|
|
147
|
+
/** 定义需要用到的外部样式 */
|
|
148
|
+
customStyle: {
|
|
149
|
+
type: Object as PropType<CSSProperties>,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
const emit = defineEmits<ICodeInputEmits>();
|
|
153
|
+
|
|
154
|
+
const current = ref(0);
|
|
155
|
+
const inputValue = ref("");
|
|
156
|
+
const isFocus = ref(props.focus);
|
|
157
|
+
let timer: ReturnType<typeof setInterval>;
|
|
158
|
+
const opacity = ref(1);
|
|
159
|
+
const borderWidth = computed(() => (props.hairline ? "0.5px" : "2px"));
|
|
160
|
+
const lineHeight = computed(() => (props.hairline ? "2px" : "4px"));
|
|
161
|
+
const boxSize = addUnit(props.size);
|
|
162
|
+
|
|
163
|
+
watch(
|
|
164
|
+
() => props.modelValue,
|
|
165
|
+
(newValue: string | number) => {
|
|
166
|
+
inputValue.value = String(newValue).substring(0, props.maxlength);
|
|
167
|
+
current.value = newValue.toString().length;
|
|
168
|
+
},
|
|
169
|
+
{ immediate: true },
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
watch(
|
|
173
|
+
() => isFocus.value,
|
|
174
|
+
(newValue) => {
|
|
175
|
+
// #ifdef APP-NVUE
|
|
176
|
+
if (newValue) {
|
|
177
|
+
timer = setInterval(() => {
|
|
178
|
+
opacity.value = Math.abs(opacity.value - 1);
|
|
179
|
+
}, 600);
|
|
180
|
+
} else {
|
|
181
|
+
clearInterval(timer);
|
|
182
|
+
}
|
|
183
|
+
// #endif
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
onUnmounted(() => {
|
|
188
|
+
// #ifdef APP-NVUE
|
|
189
|
+
clearInterval(timer);
|
|
190
|
+
// #endif
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// 根据长度,循环输入框的个数,因为头条小程序数值不能用于v-for
|
|
194
|
+
const codeLength = computed(() => {
|
|
195
|
+
return new Array(Number(props.maxlength));
|
|
196
|
+
});
|
|
197
|
+
// 循环item的样式
|
|
198
|
+
const itemStyle = computed(() => {
|
|
199
|
+
return (index: number) => {
|
|
200
|
+
const style: CSSProperties = {
|
|
201
|
+
width: boxSize,
|
|
202
|
+
height: boxSize,
|
|
203
|
+
};
|
|
204
|
+
if (props.borderColor) {
|
|
205
|
+
style["--hy-border-color"] = props.borderColor;
|
|
206
|
+
}
|
|
207
|
+
// 盒子模式下,需要额外进行处理
|
|
208
|
+
if (props.mode === "box" && props.border) {
|
|
209
|
+
// 设置盒子的边框,如果是细边框,则设置为1px宽度
|
|
210
|
+
style.borderWidth = borderWidth.value;
|
|
211
|
+
style.borderStyle = "solid";
|
|
212
|
+
style.borderColor = props.borderColor;
|
|
213
|
+
// 如果盒子间距为0的话
|
|
214
|
+
if (getPx(props.space) === 0) {
|
|
215
|
+
// 给第一和最后一个盒子设置圆角
|
|
216
|
+
if (index === 0) {
|
|
217
|
+
style.borderTopLeftRadius = "6px";
|
|
218
|
+
style.borderBottomLeftRadius = "6px";
|
|
219
|
+
}
|
|
220
|
+
if (index === codeLength.value.length - 1) {
|
|
221
|
+
style.borderTopRightRadius = "6px";
|
|
222
|
+
style.borderBottomRightRadius = "6px";
|
|
223
|
+
}
|
|
224
|
+
// 最后一个盒子的右边框需要保留
|
|
225
|
+
if (index !== codeLength.value.length - 1) {
|
|
226
|
+
style.borderRight = "none";
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (index !== codeLength.value.length - 1) {
|
|
231
|
+
// 设置验证码字符之间的距离,通过margin-right设置,最后一个字符,无需右边框
|
|
232
|
+
style.marginRight = addUnit(props.space);
|
|
233
|
+
} else {
|
|
234
|
+
// 最后一个盒子的有边框需要保留
|
|
235
|
+
style.marginRight = 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return style;
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const itemClass = computed(() => {
|
|
243
|
+
return (index: number) => {
|
|
244
|
+
return [
|
|
245
|
+
"hy-code-input--item",
|
|
246
|
+
props.border
|
|
247
|
+
? `hy-code-input--item__${props.mode}`
|
|
248
|
+
: "hy-code-input--item__not",
|
|
249
|
+
current.value > index &&
|
|
250
|
+
getPx(props.space) != 0 &&
|
|
251
|
+
props.border &&
|
|
252
|
+
`hy-code-input--item__${props.mode}__border`,
|
|
253
|
+
isFocus.value &&
|
|
254
|
+
current.value === index &&
|
|
255
|
+
getPx(props.space) != 0 &&
|
|
256
|
+
(props.border
|
|
257
|
+
? `hy-code-input--item__${props.mode}__active`
|
|
258
|
+
: "hy-code-input--item__not__active"),
|
|
259
|
+
];
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @description 将输入的值,转为数组,给item历遍时,根据当前的索引显示数组的元素
|
|
265
|
+
*/
|
|
266
|
+
const codeArray = computed(() => {
|
|
267
|
+
return String(inputValue.value).split("");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @description 监听输入框的值发生变化
|
|
272
|
+
* */
|
|
273
|
+
const inputHandler = (e: InputOnInputEvent) => {
|
|
274
|
+
const value = e.detail.value;
|
|
275
|
+
inputValue.value = value;
|
|
276
|
+
// 是否允许输入“.”符号
|
|
277
|
+
if (props.disabledDot) {
|
|
278
|
+
nextTick(() => {
|
|
279
|
+
inputValue.value = value.replace(".", "");
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// 未达到maxlength之前,发送change事件,达到后发送finish事件
|
|
283
|
+
emit("change", value);
|
|
284
|
+
// 修改通过v-model双向绑定的值
|
|
285
|
+
emit("update:modelValue", value);
|
|
286
|
+
// 达到用户指定输入长度时,发出完成事件
|
|
287
|
+
if (String(value).length >= Number(props.maxlength)) {
|
|
288
|
+
emit("finish", value);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
</script>
|
|
292
|
+
|
|
293
|
+
<style scoped lang="scss">
|
|
294
|
+
@import "./index.scss";
|
|
295
|
+
@import "../../libs/css/mixin.scss";
|
|
296
|
+
@import "../../libs/css/theme";
|
|
297
|
+
@include b(code-input) {
|
|
298
|
+
@include m(item) {
|
|
299
|
+
&__box {
|
|
300
|
+
&__active {
|
|
301
|
+
width: v-bind(boxSize);
|
|
302
|
+
height: v-bind(boxSize);
|
|
303
|
+
border-width: v-bind(borderWidth);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
&__line {
|
|
307
|
+
&::after {
|
|
308
|
+
height: v-bind(lineHeight);
|
|
309
|
+
background-color: $hy-border-color;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
</style>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
@use "../../libs/css/mixin.scss" as *;
|
|
2
|
-
@use "../../theme
|
|
2
|
+
@use "../../libs/css/theme" as *;
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
@include b(config-provider) {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
/* #ifndef H5 */
|
|
12
12
|
height: 100vh;
|
|
13
13
|
/* #endif */
|
|
14
|
-
overflow: auto;
|
|
14
|
+
overflow-y: auto;
|
|
15
|
+
overflow-x: hidden;
|
|
15
16
|
background-color: $hy-background;
|
|
16
17
|
color: $hy-text-color;
|
|
17
18
|
}
|