Commit d20e1ce4ef2a62abb736f1cd8bbbbe5c331b4c67

Authored by ww
1 parent 04400b24

perf: manage device certificate auth token add refresh button

... ... @@ -26,3 +26,26 @@ export function buildShortUUID(prefix = ''): string {
26 26 unique++;
27 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 399 field: 'credentialsId',
400 400 required: true,
401 401 ifShow: false,
  402 + slot: 'credentialsId',
402 403 componentProps: {
403 404 maxLength: 36,
404 405 placeholder: '请输入访问令牌',
... ... @@ -598,6 +599,7 @@ export const TokenSchemas: FormSchema[] = [
598 599 field: 'credentialsId',
599 600 required: true,
600 601 ifShow: false,
  602 + slot: 'credentialsId',
601 603 componentProps: {
602 604 maxLength: 36,
603 605 placeholder: '请输入访问令牌',
... ...
... ... @@ -17,6 +17,14 @@
17 17 </Tooltip>
18 18 </div>
19 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 28 </BasicForm>
21 29 </BasicModal>
22 30 </template>
... ... @@ -29,7 +37,7 @@
29 37 import { saveDeviceToken } from '/@/api/device/deviceManager';
30 38 import { useMessage } from '/@/hooks/web/useMessage';
31 39 import { Input, Tooltip } from 'ant-design-vue';
32   - import { buildUUID } from '/@/utils/uuid';
  40 + import { buildUUID, randomString } from '/@/utils/uuid';
33 41 import { ReloadOutlined } from '@ant-design/icons-vue';
34 42 export default defineComponent({
35 43 components: {
... ... @@ -227,6 +235,10 @@
227 235 const handleCreateUUID = () => {
228 236 setFieldsValue({ clientId: buildUUID() });
229 237 };
  238 +
  239 + const handleCreateCredentialsId = () => {
  240 + setFieldsValue({ credentialsId: randomString() });
  241 + };
230 242 return {
231 243 registerModal,
232 244 registerForm,
... ... @@ -234,6 +246,7 @@
234 246 handleCancel,
235 247 handleOk,
236 248 handleCreateUUID,
  249 + handleCreateCredentialsId,
237 250 };
238 251 },
239 252 });
... ...
... ... @@ -16,6 +16,18 @@
16 16 </Tooltip>
17 17 </div>
18 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 31 </BasicForm>
20 32 <div>
21 33 <a-button @click="prevStep">上一步</a-button>
... ... @@ -29,7 +41,7 @@
29 41 import { BasicForm, useForm } from '/@/components/Form';
30 42 import { step2Schemas } from '../../config/data';
31 43 import { Icon } from '/@/components/Icon';
32   - import { buildUUID } from '/@/utils/uuid';
  44 + import { buildUUID, randomString } from '/@/utils/uuid';
33 45 export default defineComponent({
34 46 components: {
35 47 BasicForm,
... ... @@ -126,6 +138,10 @@
126 138 setFieldsValue({ clientId: buildUUID() });
127 139 };
128 140
  141 + const handleGenerateCredentialsId = () => {
  142 + setFieldsValue({ credentialsId: randomString() });
  143 + };
  144 +
129 145 return {
130 146 prevStep,
131 147 registerForm,
... ... @@ -135,6 +151,7 @@
135 151 resetFieldsValueAndStatus,
136 152 validateStep2Method,
137 153 handleGenerateClientId,
  154 + handleGenerateCredentialsId,
138 155 };
139 156 },
140 157 });
... ...
... ... @@ -63,7 +63,7 @@
63 63 <Empty
64 64 v-if="!deviceDetail?.deviceInfo?.address"
65 65 :image="locationImage"
66   - imageStyle="display: flex; justify-content: center; height: 150px;"
  66 + :imageStyle="{ display: 'flex', 'justify-content': 'center', height: '150px' }"
67 67 description="请添加设备地理位置"
68 68 />
69 69 </div>
... ...