@didaoktv/didaoui-uniapp 2.12.0 → 2.14.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/README.md +7 -7
- package/components/dd-album/dd-album.vue +280 -228
- package/components/dd-avatar/dd-avatar.vue +132 -75
- package/components/dd-avatar-group/dd-avatar-group.vue +52 -30
- package/components/dd-barcode/dd-barcode.vue +884 -947
- package/components/dd-button/dd-button.vue +47 -21
- package/components/dd-canvas/dd-canvas.vue +1156 -985
- package/components/dd-car-keyboard/dd-car-keyboard.vue +12 -12
- package/components/dd-champion-card/dd-champion-card.vue +49 -21
- package/components/dd-checkbox-group/dd-checkbox-group.vue +2 -0
- package/components/dd-copy/dd-copy.vue +51 -56
- package/components/dd-cropper/dd-cropper.vue +1224 -1135
- package/components/dd-divider/dd-divider.vue +9 -2
- package/components/dd-fold/dd-fold.vue +133 -0
- package/components/dd-form/dd-form.vue +2 -0
- package/components/dd-icon/dd-icon.vue +1 -1
- package/components/dd-keyboard/dd-keyboard.vue +95 -46
- package/components/dd-link/dd-link.vue +72 -49
- package/components/dd-markdown/dd-markdown.vue +154 -154
- package/components/dd-number-keyboard/dd-number-keyboard.vue +109 -94
- package/components/dd-parse/dd-parse.vue +473 -442
- package/components/dd-poster/dd-poster.vue +579 -567
- package/components/dd-pull-refresh/dd-pull-refresh.vue +1 -9
- package/components/dd-qrcode/dd-qrcode.vue +431 -405
- package/components/dd-radio-group/dd-radio-group.vue +1 -1
- package/components/dd-segmented-tab/dd-segmented-tab.vue +22 -14
- package/components/dd-signature/dd-signature.vue +377 -357
- package/components/dd-step/dd-step.vue +1 -1
- package/components/dd-sticky/dd-sticky.vue +5 -10
- package/components/dd-swipe-action/dd-swipe-action.vue +1 -9
- package/components/dd-swipe-item/dd-swipe-item.vue +2 -0
- package/components/dd-swipeable-tab/dd-swipeable-tab.vue +1 -5
- package/components/dd-switch/dd-switch.vue +1 -1
- package/components/dd-text/dd-text.vue +304 -82
- package/components/dd-waterfall/dd-waterfall.vue +89 -0
- package/index.ts +8 -6
- package/libs/function/index.d.ts +88 -0
- package/libs/function/index.js +14 -0
- package/libs/function/test.d.ts +65 -0
- package/package.json +1 -1
- package/scss/_mixins.scss +8 -0
- package/scss/_theme-tokens.scss +7 -0
- package/scss/_variables.scss +283 -156
- package/components/dd-album/album.js +0 -19
- package/components/dd-album/props.js +0 -89
- package/components/dd-avatar/avatar.js +0 -19
- package/components/dd-avatar/props.js +0 -84
- package/components/dd-avatar-group/avatarGroup.js +0 -14
- package/components/dd-avatar-group/props.js +0 -57
- package/components/dd-keyboard/keyboard.js +0 -19
- package/components/dd-keyboard/props.js +0 -79
- package/components/dd-link/link.js +0 -17
- package/components/dd-link/props.js +0 -44
- package/components/dd-number-keyboard/numberKeyboard.js +0 -8
- package/components/dd-number-keyboard/props.js +0 -24
- package/components/dd-parse/props.js +0 -57
- package/components/dd-text/props.js +0 -120
- package/components/dd-text/text.js +0 -30
- package/components/dd-text/value.js +0 -87
- package/scss/_dd-shared.scss +0 -40
|
@@ -15,182 +15,182 @@
|
|
|
15
15
|
</view>
|
|
16
16
|
</template>
|
|
17
17
|
|
|
18
|
-
<script>
|
|
19
|
-
import {
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { ref, watch } from 'vue'
|
|
20
|
+
// @ts-ignore marked.esm.mjs 无类型声明
|
|
21
|
+
import { marked } from './marked.esm.mjs'
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
parsedContent: ''
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
watch: {
|
|
64
|
-
content: {
|
|
65
|
-
handler(newVal) {
|
|
66
|
-
this.parseMarkdown(newVal);
|
|
67
|
-
},
|
|
68
|
-
immediate: true
|
|
69
|
-
}
|
|
23
|
+
interface Props {
|
|
24
|
+
// markdown内容
|
|
25
|
+
content?: string
|
|
26
|
+
// 是否启用图片预览
|
|
27
|
+
previewImg?: boolean
|
|
28
|
+
// 是否允许外部链接被点击时自动打开
|
|
29
|
+
copyLink?: boolean | string
|
|
30
|
+
// 主域名,用于 dd-parse 处理相对链接
|
|
31
|
+
domain?: string
|
|
32
|
+
// 是否显示代码块行号
|
|
33
|
+
showLineNumber?: boolean
|
|
34
|
+
// 主题样式 'light' | 'dark'
|
|
35
|
+
theme?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
39
|
+
content: '',
|
|
40
|
+
previewImg: true,
|
|
41
|
+
copyLink: true,
|
|
42
|
+
domain: '',
|
|
43
|
+
showLineNumber: false,
|
|
44
|
+
theme: 'light',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits<{
|
|
48
|
+
(e: 'load', event: any): void
|
|
49
|
+
(e: 'ready', event: any): void
|
|
50
|
+
(e: 'imgtap', event: any): void
|
|
51
|
+
(e: 'linktap', event: any): void
|
|
52
|
+
(e: 'play', event: any): void
|
|
53
|
+
(e: 'error', event: any): void
|
|
54
|
+
}>()
|
|
55
|
+
|
|
56
|
+
const parsedContent = ref('')
|
|
57
|
+
|
|
58
|
+
watch(
|
|
59
|
+
() => props.content,
|
|
60
|
+
(newVal: string) => {
|
|
61
|
+
parseMarkdown(newVal)
|
|
70
62
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
parseMarkdown(content) {
|
|
74
|
-
if (!content) {
|
|
75
|
-
this.parsedContent = '';
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
63
|
+
{ immediate: true }
|
|
64
|
+
)
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// 应用主题样式
|
|
86
|
-
parsed = this.applyTheme(parsed);
|
|
87
|
-
|
|
88
|
-
this.parsedContent = parsed;
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
// 处理代码块
|
|
92
|
-
handleCodeBlock(html) {
|
|
93
|
-
// 添加代码块样式和行号
|
|
94
|
-
return html.replace(/<pre><code([^>]*)>([^<]+)<\/code><\/pre>/g, (match, lang, code) => {
|
|
95
|
-
const language = lang.match(/class="language-([^"]+)"/);
|
|
96
|
-
const langClass = language ? `language-${language[1]}` : '';
|
|
97
|
-
|
|
98
|
-
let result = `<pre class="dd-markdown-code ${langClass}">`;
|
|
99
|
-
|
|
100
|
-
if (this.showLineNumber) {
|
|
101
|
-
// 添加行号
|
|
102
|
-
const lines = code.split('\n').filter(line => line.trim() !== '');
|
|
103
|
-
result += '<span class="dd-markdown-line-numbers">';
|
|
104
|
-
lines.push('');
|
|
105
|
-
lines.forEach((_, index) => {
|
|
106
|
-
result += `<span class="dd-markdown-line-number">${index + 1}</span>`;
|
|
107
|
-
});
|
|
108
|
-
result += '</span>';
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
result += `<code class='code-lang ${langClass}'>${code}</code></pre>`;
|
|
112
|
-
return result;
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
// 应用主题样式
|
|
117
|
-
applyTheme(html) {
|
|
118
|
-
// 可以根据theme属性添加不同的样式类
|
|
119
|
-
return html;
|
|
120
|
-
},
|
|
121
|
-
emitLoad(event) {
|
|
122
|
-
this.$emit('load', event)
|
|
123
|
-
},
|
|
124
|
-
emitReady(event) {
|
|
125
|
-
this.$emit('ready', event)
|
|
126
|
-
},
|
|
127
|
-
emitImgtap(event) {
|
|
128
|
-
this.$emit('imgtap', event)
|
|
129
|
-
},
|
|
130
|
-
emitLinktap(event) {
|
|
131
|
-
this.$emit('linktap', event)
|
|
132
|
-
},
|
|
133
|
-
emitPlay(event) {
|
|
134
|
-
this.$emit('play', event)
|
|
135
|
-
},
|
|
136
|
-
emitError(event) {
|
|
137
|
-
this.$emit('error', event)
|
|
138
|
-
}
|
|
66
|
+
// 解析markdown内容
|
|
67
|
+
function parseMarkdown(content: string) {
|
|
68
|
+
if (!content) {
|
|
69
|
+
parsedContent.value = ''
|
|
70
|
+
return
|
|
139
71
|
}
|
|
140
|
-
|
|
72
|
+
|
|
73
|
+
// 使用marked解析markdown
|
|
74
|
+
let parsed = marked(content)
|
|
75
|
+
|
|
76
|
+
// 处理代码块
|
|
77
|
+
parsed = handleCodeBlock(parsed)
|
|
78
|
+
|
|
79
|
+
// 应用主题样式
|
|
80
|
+
parsed = applyTheme(parsed)
|
|
81
|
+
|
|
82
|
+
parsedContent.value = parsed
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 处理代码块
|
|
86
|
+
function handleCodeBlock(html: string) {
|
|
87
|
+
// 添加代码块样式和行号
|
|
88
|
+
return html.replace(/<pre><code([^>]*)>([^<]+)<\/code><\/pre>/g, (match, lang, code) => {
|
|
89
|
+
const language = lang.match(/class="language-([^"]+)"/)
|
|
90
|
+
const langClass = language ? `language-${language[1]}` : ''
|
|
91
|
+
|
|
92
|
+
let result = `<pre class="dd-markdown-code ${langClass}">`
|
|
93
|
+
|
|
94
|
+
if (props.showLineNumber) {
|
|
95
|
+
// 添加行号
|
|
96
|
+
const lines = code.split('\n').filter((line: any) => line.trim() !== '')
|
|
97
|
+
result += '<span class="dd-markdown-line-numbers">'
|
|
98
|
+
lines.push('')
|
|
99
|
+
lines.forEach((_: any, index: number) => {
|
|
100
|
+
result += `<span class="dd-markdown-line-number">${index + 1}</span>`
|
|
101
|
+
})
|
|
102
|
+
result += '</span>'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
result += `<code class='code-lang ${langClass}'>${code}</code></pre>`
|
|
106
|
+
return result
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 应用主题样式
|
|
111
|
+
function applyTheme(html: string) {
|
|
112
|
+
// 可以根据theme属性添加不同的样式类
|
|
113
|
+
return html
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function emitLoad(event: any) {
|
|
117
|
+
emit('load', event)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function emitReady(event: any) {
|
|
121
|
+
emit('ready', event)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function emitImgtap(event: any) {
|
|
125
|
+
emit('imgtap', event)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function emitLinktap(event: any) {
|
|
129
|
+
emit('linktap', event)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function emitPlay(event: any) {
|
|
133
|
+
emit('play', event)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function emitError(event: any) {
|
|
137
|
+
emit('error', event)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
defineExpose({ parsedContent, parseMarkdown, handleCodeBlock, applyTheme })
|
|
141
141
|
</script>
|
|
142
142
|
|
|
143
143
|
<style lang="scss" scoped>
|
|
144
144
|
@import '../../scss/variables';
|
|
145
|
-
|
|
145
|
+
@import '../../scss/mixins';
|
|
146
146
|
.dd-markdown {
|
|
147
147
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
148
|
-
font-size:
|
|
148
|
+
font-size: $dd-font-size-h4;
|
|
149
149
|
line-height: 1.6;
|
|
150
150
|
color: var(--dd-fg, #{$dd-fg});
|
|
151
|
-
padding:
|
|
151
|
+
padding: $dd-space-4;
|
|
152
152
|
word-wrap: break-word;
|
|
153
153
|
|
|
154
154
|
/* 标题样式 */
|
|
155
155
|
:deep(h1) {
|
|
156
|
-
font-size:
|
|
157
|
-
margin:
|
|
156
|
+
font-size: $dd-font-size-display;
|
|
157
|
+
margin: $dd-space-2 0;
|
|
158
158
|
font-weight: bold;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
:deep(h2) {
|
|
162
|
-
font-size:
|
|
163
|
-
margin:
|
|
162
|
+
font-size: $dd-font-size-h1;
|
|
163
|
+
margin: $dd-space-2 0;
|
|
164
164
|
font-weight: bold;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
:deep(h3) {
|
|
168
|
-
font-size:
|
|
169
|
-
margin:
|
|
168
|
+
font-size: $dd-font-size-h3;
|
|
169
|
+
margin: 14rpx 0;
|
|
170
170
|
font-weight: bold;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
:deep(h4) {
|
|
174
|
-
font-size:
|
|
175
|
-
margin:
|
|
174
|
+
font-size: $dd-font-size-h4;
|
|
175
|
+
margin: 14rpx 0;
|
|
176
176
|
font-weight: bold;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
:deep(h5) {
|
|
180
|
-
font-size:
|
|
181
|
-
margin:
|
|
180
|
+
font-size: 26rpx;
|
|
181
|
+
margin: 12rpx 0;
|
|
182
182
|
font-weight: bold;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
:deep(h6) {
|
|
186
|
-
font-size:
|
|
187
|
-
margin:
|
|
186
|
+
font-size: $dd-font-size-overline;
|
|
187
|
+
margin: 10rpx 0;
|
|
188
188
|
font-weight: bold;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/* 段落样式 */
|
|
192
192
|
:deep(p) {
|
|
193
|
-
margin:
|
|
193
|
+
margin: $dd-space-4 0;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
/* 链接样式 */
|
|
@@ -206,11 +206,11 @@ export default {
|
|
|
206
206
|
/* 列表样式 */
|
|
207
207
|
:deep(ul,
|
|
208
208
|
:deep ol) {
|
|
209
|
-
margin:
|
|
210
|
-
padding-left:
|
|
209
|
+
margin: $dd-space-4 0;
|
|
210
|
+
padding-left: $dd-space-6;
|
|
211
211
|
|
|
212
212
|
li {
|
|
213
|
-
margin:
|
|
213
|
+
margin: $dd-space-2 0;
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -224,8 +224,8 @@ export default {
|
|
|
224
224
|
|
|
225
225
|
/* 引用样式 */
|
|
226
226
|
:deep(blockquote) {
|
|
227
|
-
margin:
|
|
228
|
-
padding: 0
|
|
227
|
+
margin: $dd-space-2 0;
|
|
228
|
+
padding: 0 20rpx;
|
|
229
229
|
border-left: 4px solid var(--dd-border-default, #{$dd-border-default});
|
|
230
230
|
color: var(--dd-text-secondary, #{$dd-text-secondary});
|
|
231
231
|
}
|
|
@@ -233,10 +233,10 @@ export default {
|
|
|
233
233
|
/* 代码样式 */
|
|
234
234
|
:deep(&-code) {
|
|
235
235
|
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
|
236
|
-
font-size:
|
|
236
|
+
font-size: $dd-font-size-body;
|
|
237
237
|
background-color: var(--dd-surface-container, #{$dd-surface-container});
|
|
238
|
-
padding:
|
|
239
|
-
border-radius:
|
|
238
|
+
padding: 6rpx 12rpx;
|
|
239
|
+
border-radius: 6rpx;
|
|
240
240
|
display: flex;
|
|
241
241
|
}
|
|
242
242
|
:deep(.code-lang) {
|
|
@@ -246,12 +246,12 @@ export default {
|
|
|
246
246
|
|
|
247
247
|
:deep(pre) {
|
|
248
248
|
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
|
249
|
-
font-size:
|
|
249
|
+
font-size: $dd-font-size-body;
|
|
250
250
|
background-color: var(--dd-surface-container, #{$dd-surface-container});
|
|
251
|
-
padding:
|
|
251
|
+
padding: $dd-space-4;
|
|
252
252
|
overflow: auto;
|
|
253
|
-
border-radius:
|
|
254
|
-
margin:
|
|
253
|
+
border-radius: 12rpx;
|
|
254
|
+
margin: $dd-space-4 0;
|
|
255
255
|
|
|
256
256
|
:deep(code) {
|
|
257
257
|
background: none;
|
|
@@ -262,12 +262,12 @@ export default {
|
|
|
262
262
|
/* 表格样式 */
|
|
263
263
|
:deep(table) {
|
|
264
264
|
border-collapse: collapse;
|
|
265
|
-
margin:
|
|
265
|
+
margin: $dd-space-4 0;
|
|
266
266
|
width: 100%;
|
|
267
267
|
|
|
268
268
|
th,
|
|
269
269
|
td {
|
|
270
|
-
padding:
|
|
270
|
+
padding: 12rpx 26rpx;
|
|
271
271
|
border: 1px solid #dfe2e5;
|
|
272
272
|
}
|
|
273
273
|
|
|
@@ -285,14 +285,14 @@ export default {
|
|
|
285
285
|
max-width: 100%;
|
|
286
286
|
box-sizing: content-box;
|
|
287
287
|
background-color: #fff;
|
|
288
|
-
margin:
|
|
288
|
+
margin: $dd-space-4 0;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
/* 分割线样式 */
|
|
292
292
|
:deep(hr) {
|
|
293
293
|
height: 1px;
|
|
294
294
|
padding: 0;
|
|
295
|
-
margin:
|
|
295
|
+
margin: $dd-space-5 0;
|
|
296
296
|
background-color: var(--dd-rule, #{$dd-rule});
|
|
297
297
|
border: 0;
|
|
298
298
|
}
|
|
@@ -306,14 +306,14 @@ export default {
|
|
|
306
306
|
display: flex;
|
|
307
307
|
flex-direction: column;
|
|
308
308
|
align-items: flex-start;
|
|
309
|
-
padding-right:
|
|
310
|
-
margin-right:
|
|
309
|
+
padding-right: 20rpx;
|
|
310
|
+
margin-right: 20rpx;
|
|
311
311
|
border-right: 1px solid #ddd;
|
|
312
312
|
user-select: none;
|
|
313
313
|
|
|
314
314
|
.dd-markdown-line-number {
|
|
315
315
|
color: #999;
|
|
316
|
-
font-size:
|
|
316
|
+
font-size: $dd-font-size-body;
|
|
317
317
|
line-height: 1.6;
|
|
318
318
|
}
|
|
319
319
|
}
|
|
@@ -40,11 +40,10 @@
|
|
|
40
40
|
</view>
|
|
41
41
|
</template>
|
|
42
42
|
|
|
43
|
-
<script>
|
|
44
|
-
import {
|
|
45
|
-
import
|
|
46
|
-
import {
|
|
47
|
-
import { randomArray } from '../../libs/function/index';
|
|
43
|
+
<script setup lang="ts">
|
|
44
|
+
import { computed, ref } from 'vue'
|
|
45
|
+
import DdIcon from '../dd-icon/dd-icon.vue'
|
|
46
|
+
import { randomArray } from '../../libs/function/index.js';
|
|
48
47
|
/**
|
|
49
48
|
* keyboard 键盘组件
|
|
50
49
|
* @description
|
|
@@ -56,112 +55,128 @@
|
|
|
56
55
|
* @event {Function} backspace 点击退格键触发
|
|
57
56
|
* @example
|
|
58
57
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
// 是否让按键显示灰色,只在非乱序&&数字键盘&&且允许点按键的时候("."键 / 身份证"X"键)
|
|
104
|
-
btnBgGray() {
|
|
105
|
-
return index => {
|
|
106
|
-
if (!this.random && index == 9 && (this.mode != 'number' || (this.mode == 'number' && !this
|
|
107
|
-
.dotDisabled))) return true;
|
|
108
|
-
else return false;
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
created() {
|
|
113
|
-
},
|
|
114
|
-
emits: ["backspace", "change"],
|
|
115
|
-
methods: {
|
|
116
|
-
// 点击退格键(触摸路径:touchstart 立删 + 长按连删;鼠标路径:tap 单删,isTouch 防移动端触摸后 tap 二次删除)
|
|
117
|
-
backspaceTouchStart() {
|
|
118
|
-
this.isTouch = true
|
|
119
|
-
this.$emit('backspace');
|
|
120
|
-
clearInterval(this.timer); //再次清空定时器,防止重复注册定时器
|
|
121
|
-
this.timer = null;
|
|
122
|
-
this.timer = setInterval(() => {
|
|
123
|
-
this.$emit('backspace');
|
|
124
|
-
}, 250);
|
|
125
|
-
},
|
|
126
|
-
backspaceTap() {
|
|
127
|
-
if (this.isTouch) {
|
|
128
|
-
this.isTouch = false;
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
this.$emit('backspace');
|
|
132
|
-
},
|
|
133
|
-
clearTimer() {
|
|
134
|
-
clearInterval(this.timer);
|
|
135
|
-
this.timer = null;
|
|
136
|
-
},
|
|
137
|
-
// 获取键盘显示的内容
|
|
138
|
-
keyboardClick(val) {
|
|
139
|
-
// 允许键盘显示点模式和触发非点按键时,将内容转为数字类型
|
|
140
|
-
if (!this.dotDisabled && val != this.dot && val != this.cardX) val = Number(val);
|
|
141
|
-
this.$emit('change', val);
|
|
58
|
+
interface Props {
|
|
59
|
+
// 键盘的类型,number-数字键盘,card-身份证键盘
|
|
60
|
+
mode?: string
|
|
61
|
+
// 是否显示键盘的"."符号
|
|
62
|
+
dotDisabled?: boolean
|
|
63
|
+
// 是否打乱键盘按键的顺序
|
|
64
|
+
random?: boolean
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
68
|
+
mode: 'number',
|
|
69
|
+
dotDisabled: false,
|
|
70
|
+
random: false,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const emit = defineEmits<{
|
|
74
|
+
(e: 'backspace'): void;
|
|
75
|
+
(e: 'change', val: any): void;
|
|
76
|
+
}>()
|
|
77
|
+
|
|
78
|
+
const backspace = ref('backspace') // 退格键内容
|
|
79
|
+
const dot = ref('.') // 点
|
|
80
|
+
let timer: any = null // 长按多次删除的事件监听
|
|
81
|
+
const isTouch = ref(false) // 本次退格是否来自触摸(防 tap 重复删除)
|
|
82
|
+
const cardX = ref('X') // 身份证的X符号
|
|
83
|
+
|
|
84
|
+
// 空操作:模板 @touchmove.stop.prevent="noop"
|
|
85
|
+
const noop = (e: any) => { e && typeof e.stopPropagation === 'function' && e.stopPropagation() }
|
|
86
|
+
|
|
87
|
+
// 键盘需要显示的内容
|
|
88
|
+
const numList = computed(() => {
|
|
89
|
+
if (props.dotDisabled && props.mode == 'number') {
|
|
90
|
+
if (!props.random) {
|
|
91
|
+
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
|
92
|
+
} else {
|
|
93
|
+
return randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
|
|
94
|
+
}
|
|
95
|
+
} else if (!props.dotDisabled && props.mode == 'number') {
|
|
96
|
+
if (!props.random) {
|
|
97
|
+
return [1, 2, 3, 4, 5, 6, 7, 8, 9, dot.value, 0];
|
|
98
|
+
} else {
|
|
99
|
+
return randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, dot.value, 0]);
|
|
142
100
|
}
|
|
101
|
+
} else if (props.mode == 'card') {
|
|
102
|
+
if (!props.random) {
|
|
103
|
+
return [1, 2, 3, 4, 5, 6, 7, 8, 9, cardX.value, 0];
|
|
104
|
+
} else {
|
|
105
|
+
return randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, cardX.value, 0]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// 按键的样式,在非乱序&&数字键盘&&不显示点按钮时,index为9时,"0"键占位两个空间(flex 拉伸为 2 倍宽)
|
|
111
|
+
const itemStyle = computed(() => {
|
|
112
|
+
return (index: number) => {
|
|
113
|
+
let style: Record<string, any> = {};
|
|
114
|
+
if (props.mode == 'number' && props.dotDisabled && index == 9) style.flex = '2 1 30%';
|
|
115
|
+
return style;
|
|
116
|
+
};
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// 是否让按键显示灰色,只在非乱序&&数字键盘&&且允许点按键的时候("."键 / 身份证"X"键)
|
|
120
|
+
const btnBgGray = computed(() => {
|
|
121
|
+
return (index: number) => {
|
|
122
|
+
if (!props.random && index == 9 && (props.mode != 'number' || (props.mode == 'number' && !props
|
|
123
|
+
.dotDisabled))) return true;
|
|
124
|
+
else return false;
|
|
125
|
+
};
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
// 点击退格键(触摸路径:touchstart 立删 + 长按连删;鼠标路径:tap 单删,isTouch 防移动端触摸后 tap 二次删除)
|
|
129
|
+
function backspaceTouchStart() {
|
|
130
|
+
isTouch.value = true
|
|
131
|
+
emit('backspace');
|
|
132
|
+
clearInterval(timer); //再次清空定时器,防止重复注册定时器
|
|
133
|
+
timer = null;
|
|
134
|
+
timer = setInterval(() => {
|
|
135
|
+
emit('backspace');
|
|
136
|
+
}, 250);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function backspaceTap() {
|
|
140
|
+
if (isTouch.value) {
|
|
141
|
+
isTouch.value = false;
|
|
142
|
+
return;
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
emit('backspace');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function clearTimer() {
|
|
148
|
+
clearInterval(timer);
|
|
149
|
+
timer = null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 获取键盘显示的内容
|
|
153
|
+
function keyboardClick(val: any) {
|
|
154
|
+
// 允许键盘显示点模式和触发非点按键时,将内容转为数字类型
|
|
155
|
+
if (!props.dotDisabled && val != dot.value && val != cardX.value) val = Number(val);
|
|
156
|
+
emit('change', val);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
defineExpose({ numList, itemStyle, btnBgGray, backspace, dot, isTouch, cardX, backspaceTouchStart, backspaceTap, clearTimer, keyboardClick })
|
|
145
160
|
</script>
|
|
146
161
|
|
|
147
162
|
<style lang="scss" scoped>
|
|
148
163
|
@import '../../scss/variables';
|
|
149
|
-
@import '../../scss/
|
|
164
|
+
@import '../../scss/mixins';
|
|
150
165
|
$dd-number-keyboard-background-color: var(--dd-bg-section, #{$dd-bg-section}) !default;
|
|
151
|
-
$dd-number-keyboard-padding
|
|
166
|
+
$dd-number-keyboard-padding:$dd-space-2 10rpx $dd-space-2 10rpx !default;
|
|
152
167
|
$dd-number-keyboard-gap:6rpx !default;
|
|
153
168
|
$dd-number-keyboard-button-border-radius:$dd-radius-sm !default;
|
|
154
169
|
$dd-number-keyboard-button-height: 90rpx!default;
|
|
155
170
|
$dd-number-keyboard-button-background-color:var(--dd-surface-container-high, #{$dd-surface-container-high}) !default;
|
|
156
171
|
$dd-number-keyboard-button-box-shadow:0 2px 0px var(--dd-bg, #{$dd-bg}) !default;
|
|
157
|
-
$dd-number-keyboard-text-font-size
|
|
172
|
+
$dd-number-keyboard-text-font-size:$dd-font-size-h2 !default;
|
|
158
173
|
$dd-number-keyboard-text-font-weight:500 !default;
|
|
159
174
|
$dd-number-keyboard-text-color:var(--dd-text-primary, #{$dd-text-primary}) !default;
|
|
160
175
|
$dd-number-keyboard-gray-background-color:var(--dd-surface-container-highest, #{$dd-surface-container-highest}) !default;
|
|
161
176
|
$dd-number-keyboard-dd-keyboard-hover-background-color: var(--dd-surface-hover, #{$dd-surface-hover}) !default;
|
|
162
177
|
|
|
163
178
|
.dd-keyboard {
|
|
164
|
-
@include flex;
|
|
179
|
+
@include dd-flex;
|
|
165
180
|
flex-direction: row;
|
|
166
181
|
flex-wrap: wrap;
|
|
167
182
|
gap: $dd-number-keyboard-gap;
|
|
@@ -178,7 +193,7 @@
|
|
|
178
193
|
width: 100%;
|
|
179
194
|
height: $dd-number-keyboard-button-height;
|
|
180
195
|
background-color: $dd-number-keyboard-button-background-color;
|
|
181
|
-
@include flex;
|
|
196
|
+
@include dd-flex;
|
|
182
197
|
justify-content: center;
|
|
183
198
|
align-items: center;
|
|
184
199
|
border-radius: $dd-number-keyboard-button-border-radius;
|