n20-common-lib 2.9.91 → 2.9.92

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n20-common-lib",
3
- "version": "2.9.91",
3
+ "version": "2.9.92",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -84,56 +84,44 @@ function verifyDn(dnList, dn) {
84
84
  }
85
85
 
86
86
  // 签名
87
- export async function getSign(plain, dn) {
88
- if (dn === undefined) {
89
- dn = getDN()
90
- }
87
+ export async function getSign(plain, dn = getDN()) {
88
+ // 验证DN参数
91
89
  if (!dn) {
92
90
  Message.error('签名参数DN错误!')
93
91
  return false
94
92
  }
95
93
 
96
- let plainText = ''
97
- if (typeof plain === 'object') {
98
- plainText = JSON.stringify(plain)
99
- } else {
100
- plainText = plain
101
- }
94
+ // 处理签名文本
95
+ const plainText = typeof plain === 'object' ? JSON.stringify(plain) : plain
96
+
97
+ // 获取并验证证书信息
102
98
  const checkRes = await getCertInfo(dn)
99
+
100
+ // 证书验证错误处理
101
+ const errorMessages = {
102
+ 'dnListEmpty': '没有匹配到证书!',
103
+ 'dnIsEmpty': 'DN参数为空!',
104
+ 'Empty': '当前Ukey不匹配!'
105
+ }
103
106
 
104
- if (
105
- checkRes === -1 ||
106
- ['dnListEmpty', 'dnIsEmpty', 'Empty'].includes(checkRes)
107
- ) {
108
- switch (checkRes) {
109
- case 'dnListEmpty':
110
- Message.warning('没有匹配到证书!')
111
- break
112
- case 'dnIsEmpty':
113
- Message.warning('DN参数为空!')
114
- break
115
- case 'Empty':
116
- Message.warning('当前Ukey不匹配!')
117
- break
118
- default:
119
- Message.warning('没有匹配到证书!')
120
- }
107
+ if (checkRes === -1 || Object.keys(errorMessages).includes(checkRes)) {
108
+ Message.warning(errorMessages[checkRes] || '没有匹配到证书!')
121
109
  return ''
122
110
  }
123
- let answer
124
- await MessageBox.prompt('请输入PIN码', '提示', {
125
- confirmButtonText: '确定',
126
- cancelButtonText: '取消',
127
- closeOnClickModal: false,
128
- inputType: 'password'
129
- }).then(({ value }) => {
130
- performSign(plainText, value).then((signedData) => {
131
- answer = signedData
132
- })
133
- })
134
- // 签名
135
111
 
136
- return answer
112
+ // 获取PIN码并执行签名
113
+ try {
114
+ const { value: pin } = await MessageBox.prompt('请输入PIN码', '提示', {
115
+ confirmButtonText: '确定',
116
+ cancelButtonText: '取消',
117
+ closeOnClickModal: false,
118
+ inputType: 'password'
119
+ })
120
+
121
+ return await performSign(plainText, pin)
122
+ } catch (error) {
123
+ return Promise.reject(error)
124
+ }
137
125
  }
138
126
 
139
127
  /**