Commit d20e1ce4ef2a62abb736f1cd8bbbbe5c331b4c67
1 parent
04400b24
perf: manage device certificate auth token add refresh button
Showing
5 changed files
with
58 additions
and
3 deletions
@@ -26,3 +26,26 @@ export function buildShortUUID(prefix = ''): string { | @@ -26,3 +26,26 @@ export function buildShortUUID(prefix = ''): string { | ||
26 | unique++; | 26 | unique++; |
27 | return prefix + '_' + random + unique + String(time); | 27 | return prefix + '_' + random + unique + String(time); |
28 | } | 28 | } |
29 | + | ||
30 | +export function getlowerCaseChars() { | ||
31 | + return Array.from({ length: 26 }).map((_, index) => String.fromCharCode(index + 97)); | ||
32 | +} | ||
33 | + | ||
34 | +export function getUpperCaseChars() { | ||
35 | + return Array.from({ length: 26 }).map((_, index) => String.fromCharCode(index + 65)); | ||
36 | +} | ||
37 | + | ||
38 | +export function randomString(length = 20) { | ||
39 | + const upperCaseChars = getUpperCaseChars(); | ||
40 | + const lowerCaseChars = getlowerCaseChars(); | ||
41 | + const numberChars = Array.from({ length: 10 }).map((_, index) => index); | ||
42 | + const allChars = [...numberChars, ...upperCaseChars, ...lowerCaseChars].sort( | ||
43 | + () => 0.5 - Math.random() | ||
44 | + ); | ||
45 | + | ||
46 | + const rangeFn = () => (Math.random() * 63) | 0; | ||
47 | + | ||
48 | + return Array.from({ length }) | ||
49 | + .map(() => allChars[rangeFn()]) | ||
50 | + .join(''); | ||
51 | +} |
@@ -399,6 +399,7 @@ export const step2Schemas: FormSchema[] = [ | @@ -399,6 +399,7 @@ export const step2Schemas: FormSchema[] = [ | ||
399 | field: 'credentialsId', | 399 | field: 'credentialsId', |
400 | required: true, | 400 | required: true, |
401 | ifShow: false, | 401 | ifShow: false, |
402 | + slot: 'credentialsId', | ||
402 | componentProps: { | 403 | componentProps: { |
403 | maxLength: 36, | 404 | maxLength: 36, |
404 | placeholder: '请输入访问令牌', | 405 | placeholder: '请输入访问令牌', |
@@ -598,6 +599,7 @@ export const TokenSchemas: FormSchema[] = [ | @@ -598,6 +599,7 @@ export const TokenSchemas: FormSchema[] = [ | ||
598 | field: 'credentialsId', | 599 | field: 'credentialsId', |
599 | required: true, | 600 | required: true, |
600 | ifShow: false, | 601 | ifShow: false, |
602 | + slot: 'credentialsId', | ||
601 | componentProps: { | 603 | componentProps: { |
602 | maxLength: 36, | 604 | maxLength: 36, |
603 | placeholder: '请输入访问令牌', | 605 | placeholder: '请输入访问令牌', |
@@ -17,6 +17,14 @@ | @@ -17,6 +17,14 @@ | ||
17 | </Tooltip> | 17 | </Tooltip> |
18 | </div> | 18 | </div> |
19 | </template> | 19 | </template> |
20 | + <template #credentialsId="{ field, model }"> | ||
21 | + <div class="flex items-center"> | ||
22 | + <Input v-model:value="model[field]" placeholder="请输入访问令牌" /> | ||
23 | + <Tooltip title="刷新访问令牌"> | ||
24 | + <ReloadOutlined class="ml-3 !text-blue-600" @click="handleCreateCredentialsId" /> | ||
25 | + </Tooltip> | ||
26 | + </div> | ||
27 | + </template> | ||
20 | </BasicForm> | 28 | </BasicForm> |
21 | </BasicModal> | 29 | </BasicModal> |
22 | </template> | 30 | </template> |
@@ -29,7 +37,7 @@ | @@ -29,7 +37,7 @@ | ||
29 | import { saveDeviceToken } from '/@/api/device/deviceManager'; | 37 | import { saveDeviceToken } from '/@/api/device/deviceManager'; |
30 | import { useMessage } from '/@/hooks/web/useMessage'; | 38 | import { useMessage } from '/@/hooks/web/useMessage'; |
31 | import { Input, Tooltip } from 'ant-design-vue'; | 39 | import { Input, Tooltip } from 'ant-design-vue'; |
32 | - import { buildUUID } from '/@/utils/uuid'; | 40 | + import { buildUUID, randomString } from '/@/utils/uuid'; |
33 | import { ReloadOutlined } from '@ant-design/icons-vue'; | 41 | import { ReloadOutlined } from '@ant-design/icons-vue'; |
34 | export default defineComponent({ | 42 | export default defineComponent({ |
35 | components: { | 43 | components: { |
@@ -227,6 +235,10 @@ | @@ -227,6 +235,10 @@ | ||
227 | const handleCreateUUID = () => { | 235 | const handleCreateUUID = () => { |
228 | setFieldsValue({ clientId: buildUUID() }); | 236 | setFieldsValue({ clientId: buildUUID() }); |
229 | }; | 237 | }; |
238 | + | ||
239 | + const handleCreateCredentialsId = () => { | ||
240 | + setFieldsValue({ credentialsId: randomString() }); | ||
241 | + }; | ||
230 | return { | 242 | return { |
231 | registerModal, | 243 | registerModal, |
232 | registerForm, | 244 | registerForm, |
@@ -234,6 +246,7 @@ | @@ -234,6 +246,7 @@ | ||
234 | handleCancel, | 246 | handleCancel, |
235 | handleOk, | 247 | handleOk, |
236 | handleCreateUUID, | 248 | handleCreateUUID, |
249 | + handleCreateCredentialsId, | ||
237 | }; | 250 | }; |
238 | }, | 251 | }, |
239 | }); | 252 | }); |
@@ -16,6 +16,18 @@ | @@ -16,6 +16,18 @@ | ||
16 | </Tooltip> | 16 | </Tooltip> |
17 | </div> | 17 | </div> |
18 | </template> | 18 | </template> |
19 | + <template #credentialsId="{ model, field }"> | ||
20 | + <div class="flex justify-center items-center"> | ||
21 | + <Input v-model:value="model[field]" placeholder="请输入访问令牌" /> | ||
22 | + <Tooltip title="刷新访问令牌"> | ||
23 | + <Icon | ||
24 | + class="ml-3 cursor-pointer !text-blue-600" | ||
25 | + icon="ant-design:reload-outlined" | ||
26 | + @click="handleGenerateCredentialsId" | ||
27 | + /> | ||
28 | + </Tooltip> | ||
29 | + </div> | ||
30 | + </template> | ||
19 | </BasicForm> | 31 | </BasicForm> |
20 | <div> | 32 | <div> |
21 | <a-button @click="prevStep">上一步</a-button> | 33 | <a-button @click="prevStep">上一步</a-button> |
@@ -29,7 +41,7 @@ | @@ -29,7 +41,7 @@ | ||
29 | import { BasicForm, useForm } from '/@/components/Form'; | 41 | import { BasicForm, useForm } from '/@/components/Form'; |
30 | import { step2Schemas } from '../../config/data'; | 42 | import { step2Schemas } from '../../config/data'; |
31 | import { Icon } from '/@/components/Icon'; | 43 | import { Icon } from '/@/components/Icon'; |
32 | - import { buildUUID } from '/@/utils/uuid'; | 44 | + import { buildUUID, randomString } from '/@/utils/uuid'; |
33 | export default defineComponent({ | 45 | export default defineComponent({ |
34 | components: { | 46 | components: { |
35 | BasicForm, | 47 | BasicForm, |
@@ -126,6 +138,10 @@ | @@ -126,6 +138,10 @@ | ||
126 | setFieldsValue({ clientId: buildUUID() }); | 138 | setFieldsValue({ clientId: buildUUID() }); |
127 | }; | 139 | }; |
128 | 140 | ||
141 | + const handleGenerateCredentialsId = () => { | ||
142 | + setFieldsValue({ credentialsId: randomString() }); | ||
143 | + }; | ||
144 | + | ||
129 | return { | 145 | return { |
130 | prevStep, | 146 | prevStep, |
131 | registerForm, | 147 | registerForm, |
@@ -135,6 +151,7 @@ | @@ -135,6 +151,7 @@ | ||
135 | resetFieldsValueAndStatus, | 151 | resetFieldsValueAndStatus, |
136 | validateStep2Method, | 152 | validateStep2Method, |
137 | handleGenerateClientId, | 153 | handleGenerateClientId, |
154 | + handleGenerateCredentialsId, | ||
138 | }; | 155 | }; |
139 | }, | 156 | }, |
140 | }); | 157 | }); |
@@ -63,7 +63,7 @@ | @@ -63,7 +63,7 @@ | ||
63 | <Empty | 63 | <Empty |
64 | v-if="!deviceDetail?.deviceInfo?.address" | 64 | v-if="!deviceDetail?.deviceInfo?.address" |
65 | :image="locationImage" | 65 | :image="locationImage" |
66 | - imageStyle="display: flex; justify-content: center; height: 150px;" | 66 | + :imageStyle="{ display: 'flex', 'justify-content': 'center', height: '150px' }" |
67 | description="请添加设备地理位置" | 67 | description="请添加设备地理位置" |
68 | /> | 68 | /> |
69 | </div> | 69 | </div> |