-
Notifications
You must be signed in to change notification settings - Fork 666
/
number_to_zh.vue
199 lines (196 loc) · 6.57 KB
/
number_to_zh.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<template>
<div class="number_to_zh">
<nya-container title="数字转中文">
<nya-input
v-model.trim="number"
class="ntz"
autofocus
label="输入数字开始转换"
placeholder="0"
autocomplete="off"
type="number"
/>
</nya-container>
<nya-container v-if="number!=''" title="结果">
<table>
<tbody>
<template v-for="chars in hans">
<template v-for="(value, index) in chars.data">
<tr :key="index+chars.lang+'0'">
<td rowspan="2">
{{ chars.lang == 'cn'?'简体':'繁体' }}{{ value.name }}
</td>
<td>{{ value.encode[0] }}</td>
</tr>
<tr :key="index+chars.lang+'1'">
<td>{{ value.encode[1] }}</td>
</tr>
</template>
</template>
</tbody>
</table>
</nya-container>
<nya-container title="中文转数字">
<div class="inputbtn">
<nya-input
v-model.trim="hanzi"
label="输入中文数字开始转换"
placeholder="零"
autocomplete="off"
type="text"
@keyup.enter="isZhNum"
/>
<button type="button" class="nya-btn" @click="isZhNum">
开始转换
</button>
</div>
</nya-container>
<nya-container v-show="numResult" title="转换成功">
<pre>{{ numResult }}</pre>
</nya-container>
<nya-container title="说明">
<ul class="nya-list">
<li>基于 nzh 把数字转换为大小写中文。</li>
<li>
超大数转换中文争议请访问 <a href="https://github.com/cnwhy/nzh#nzh" target="_blank" rel="noopener noreferrer">
nzh
</a>。
</li>
<li>中文转数字仅支持简体大小写汉字。</li>
</ul>
</nya-container>
</div>
</template>
<script>
import Nzh from 'nzh';
export default {
name: 'NumberToZh',
head() {
return this.$store.state.currentTool.head;
},
data() {
return {
number: '',
hanzi: '',
numResult: ''
};
},
computed: {
hans() {
const nzhcn = Nzh.cn;
const nzhhk = Nzh.hk;
let n = this.number;
let data = [
{
lang: 'cn',
data: [
{
name: '中文小写',
encode: [
nzhcn.encodeS(n),
nzhcn.encodeS(n, { tenMin: false })
]
},
{
name: '中文大写',
encode: [
nzhcn.encodeB(n),
nzhcn.encodeB(n, { tenMin: true })
]
},
{
name: '金额大写',
encode: [
nzhcn.toMoney(n, { outSymbol: false }),
nzhcn.toMoney(n, {
outSymbol: false,
complete: true
})
]
}
]
},
{
lang: 'hk',
data: [
{
name: '中文小写',
encode: [
nzhhk.encodeS(n),
nzhhk.encodeS(n, { tenMin: false })
]
},
{
name: '中文大写',
encode: [
nzhhk.encodeB(n),
nzhhk.encodeB(n, { tenMin: true })
]
},
{
name: '金额大写',
encode: [
nzhhk.toMoney(n, { outSymbol: false }),
nzhhk.toMoney(n, {
outSymbol: false,
complete: true
})
]
}
]
}
];
return data;
}
},
methods: {
isZhNum() {
if (!this.hanzi.length) {
this.$swal({
type: 'error',
title: '转换失败',
text: `ERROR: 你还没有输入`
});
return;
}
const regexlower = /^负?[零一二三四五六七八九十百千万亿]*点?[零一二三四五六七八九]*$/g;
const regexupper = /^负?[零壹贰叁肆伍陆柒捌玖拾佰仟万亿]*点?[零壹贰叁肆伍陆柒捌玖]*$/g;
if (regexlower.test(this.hanzi)) {
this.numResult = Nzh.cn.decodeS(this.hanzi);
} else if (regexupper.test(this.hanzi)) {
this.numResult = Nzh.cn.decodeB(this.hanzi);
} else {
this.$swal({
type: 'error',
title: '转换失败',
text: `ERROR: 请输入正确的大小写中文数字`
});
return;
}
}
}
};
</script>
<style lang='scss'>
.number_to_zh {
table {
color: #363636;
border-collapse: collapse;
border-spacing: 0;
width: 100%;
td {
&[rowspan='2'] {
text-align: center;
}
border: 0.0625rem solid #dbdbdb;
padding: 0.5em 0.75em;
video {
max-width: 100%;
}
}
}
.ntz {
width: 100%;
}
}
</style>