Commit aefa8a5c09dacb0a77e696d7e3395cdf5462ba0d

Authored by xp.Huang
2 parents 1d60a05b 4c79e9e4

Merge branch 'ft' into 'main_dev'

feat: 设备列表新增客户不能跳转和隐藏按钮

See merge request yunteng/thingskit-front!551
... ... @@ -19,31 +19,35 @@ export const step1Schemas: FormSchema[] = [
19 19 component: 'Input',
20 20 },
21 21 {
22   - field: 'name',
23   - label: '设备名称',
24   - required: true,
25   - component: 'Input',
26   - colProps: { span: 14 },
27   - componentProps: {
28   - placeholder: '设备名称',
29   - maxLength: 36,
30   - },
31   - },
32   - {
33 22 field: 'alias',
34 23 label: '别名 ',
35 24 component: 'Input',
36   - labelWidth: 60,
37   - colProps: { span: 10 },
38 25 componentProps: {
39 26 maxLength: 255,
40 27 },
41 28 },
42 29 {
43   - field: 'sn',
44   - label: 'SN码',
  30 + field: 'name',
  31 + label: '设备名称/SN码',
45 32 component: 'Input',
46   - required: true,
  33 + dynamicRules: () => {
  34 + return [
  35 + {
  36 + required: true,
  37 + validator: (_, value) => {
  38 + // 支持英文字母、数字、下划线(_)、中划线(-)、点号(.)、半角冒号(:)和特殊字符@,长度限制为4~32个字符
  39 + const reg = /^[A-Za-z0-9_\( \)\-\@\:\.]+$/;
  40 + const strLength = String(value).length as number;
  41 + if (!reg.test(value) || strLength > 32 || strLength < 4) {
  42 + return Promise.reject(
  43 + '请输入支持英文字母、数字、下划线(_)、中划线(-)、点号(.)、半角冒号(:)和特殊字符@,长度限制为4~32个字符'
  44 + );
  45 + }
  46 + return Promise.resolve();
  47 + },
  48 + },
  49 + ];
  50 + },
47 51 slot: 'snCode',
48 52 },
49 53 {
... ...
... ... @@ -10,6 +10,7 @@ import { Button } from 'ant-design-vue';
10 10 import { TypeEnum } from './data';
11 11 import { PageEnum } from '/@/enums/pageEnum';
12 12 import { useGo } from '/@/hooks/web/usePage';
  13 +import { useAuthDeviceDetail } from '../hook/useAuthDeviceDetail';
13 14
14 15 // 设备详情的描述
15 16 export const descSchema = (emit: EmitType): DescItem[] => {
... ... @@ -34,12 +35,14 @@ export const descSchema = (emit: EmitType): DescItem[] => {
34 35 label: '产品',
35 36 render(val) {
36 37 const go = useGo();
  38 + const { isCustomer } = useAuthDeviceDetail();
37 39 return h(
38 40 Button,
39 41 {
40 42 type: 'link',
41 43 style: { padding: 0 },
42   - onClick: () => go(PageEnum.DEVICE_PROFILE + '?name=' + String(val)),
  44 + onClick: () =>
  45 + !isCustomer ? go(PageEnum.DEVICE_PROFILE + '?name=' + String(val)) : '',
43 46 },
44 47 { default: () => val }
45 48 );
... ...
... ... @@ -5,6 +5,7 @@ import { DeviceTypeEnum, DeviceState, DeviceRecord } from '/@/api/device/model/d
5 5 import { deviceProfile } from '/@/api/device/deviceManager';
6 6 import { h } from 'vue';
7 7 import { Tag } from 'ant-design-vue';
  8 +import { handeleCopy } from '../../profiles/step/topic';
8 9
9 10 // 表格列数据
10 11 export const columns: BasicColumn[] = [
... ... @@ -24,9 +25,19 @@ export const columns: BasicColumn[] = [
24 25 dataIndex: 'name',
25 26 title: '设备名称/设备SN',
26 27 width: 200,
27   - align: 'left',
28 28 slots: { customRender: 'name', title: 'deviceTitle' },
29   - ellipsis: true,
  29 + customRender: ({ record }) => {
  30 + return h(
  31 + 'span',
  32 + {
  33 + style: { cursor: 'pointer', color: '#377dff' },
  34 + onClick: () => {
  35 + handeleCopy(record.name || record.alias);
  36 + },
  37 + },
  38 + record.name || record.alias
  39 + );
  40 + },
30 41 },
31 42 {
32 43 title: '设备类型',
... ...
... ... @@ -140,8 +140,8 @@
140 140 confirmLoading: true,
141 141 });
142 142 if (unref(isUpdate)) {
143   - console.log(currentDeviceData);
144 143 const editData = {
  144 + sn: 'XXXX',
145 145 ...unref(stepState),
146 146 customerId: currentDeviceData.customerId,
147 147 deviceInfo: {
... ... @@ -152,6 +152,7 @@
152 152 await createOrEditDevice(editData);
153 153 } else {
154 154 const createData = {
  155 + sn: 'XXXX',
155 156 ...unref(stepState),
156 157 deviceInfo: {
157 158 avatar: DeviceStep1Ref.value?.devicePic,
... ...
... ... @@ -363,7 +363,7 @@
363 363 const generateSN = async () => {
364 364 const data = await generateSNCode();
365 365 setFieldsValue({
366   - sn: data,
  366 + name: data,
367 367 });
368 368 };
369 369
... ...
... ... @@ -49,7 +49,7 @@
49 49 </div>
50 50 <Description @register="register" class="mt-4" :data="deviceDetail" />
51 51 </div>
52   - <div class="mt-4">
  52 + <div class="mt-4" v-if="!isCustomer">
53 53 <a-button type="primary" class="mr-4" @click="copyTbDeviceId">复制设备ID</a-button>
54 54 <a-button type="primary" class="mr-4" @click="copyDeviceToken">复制访问令牌</a-button>
55 55 <a-button type="primary" class="mr-4" @click="manageDeviceToken">管理设备凭证</a-button>
... ... @@ -83,6 +83,7 @@
83 83 import { Description, useDescription } from '/@/components/Description';
84 84 import { QuestionCircleOutlined } from '@ant-design/icons-vue';
85 85 import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';
  86 + import { useAuthDeviceDetail } from '../../hook/useAuthDeviceDetail';
86 87
87 88 import wz from '/@/assets/images/wz.png';
88 89 import { useAsyncQueue } from '../../../localtion/useAsyncQueue';
... ... @@ -116,6 +117,7 @@
116 117 const mapWrapRef = ref<HTMLDivElement>();
117 118
118 119 const { executeFlag, setTask } = useAsyncQueue();
  120 + const { isCustomer } = useAuthDeviceDetail();
119 121 const { toPromise } = useAsyncScript({ src: BAI_DU_MAP_URL });
120 122
121 123 async function initMap(longitude: number, latitude: number, address: string) {
... ... @@ -209,6 +211,7 @@
209 211 copyTopic,
210 212 remoteConnectiondGateway,
211 213 locationImage,
  214 + isCustomer,
212 215 };
213 216 },
214 217 });
... ...
  1 +import { getAuthCache } from '/@/utils/auth';
  2 +import { RoleEnum } from '/@/enums/roleEnum';
  3 +import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  4 +
  5 +//客户
  6 +export const useAuthDeviceDetail = () => {
  7 + const userInfo: any = getAuthCache(USER_INFO_KEY);
  8 +
  9 + const role: string = userInfo?.roles[0];
  10 +
  11 + const isCustomer = role === RoleEnum.CUSTOMER_USER;
  12 + return {
  13 + isCustomer,
  14 + };
  15 +};
... ...
... ... @@ -62,21 +62,9 @@
62 62 </Popover>
63 63 </div>
64 64 </template>
65   - <template #name="{ record }">
66   - <div>
67   - <Tooltip :title="record.alias || record.name" placement="topRight">
68   - {{ record.alias || record.name.slice(0, 13) }}
69   - </Tooltip>
70   - </div>
71   - <Tooltip title="设备SN码" placement="topRight">
72   - <a-button type="link" @click="copySN(record.sn)" style="padding: 0">
73   - {{ record.sn }}
74   - </a-button>
75   - </Tooltip>
76   - </template>
77 65 <template #deviceProfile="{ record }">
78 66 <Tag.CheckableTag
79   - @click="goDeviceProfile(record.deviceProfile.name)"
  67 + @click="!isCustomer ? goDeviceProfile(record.deviceProfile.name) : null"
80 68 style="white-space: normal; height: auto; cursor: pointer"
81 69 >
82 70 <span style="color: #377dff">{{ record.deviceProfile.name }}</span>
... ... @@ -201,7 +189,7 @@
201 189 } from '/@/api/device/model/deviceModel';
202 190 import { BasicTable, useTable, TableAction, TableImg } from '/@/components/Table';
203 191 import { columns, searchFormSchema } from './config/device.data';
204   - import { Tag, Tooltip, Popover, Popconfirm, Button } from 'ant-design-vue';
  192 + import { Tag, Popover, Popconfirm, Button } from 'ant-design-vue';
205 193 import {
206 194 deleteDevice,
207 195 devicePage,
... ... @@ -231,6 +219,7 @@
231 219 import { useRoute, useRouter } from 'vue-router';
232 220 import { useBatchOperation } from '/@/utils/useBatchOperation';
233 221 import { useSyncConfirm } from '/@/hooks/component/useSyncConfirm';
  222 + import { useAuthDeviceDetail } from './hook/useAuthDeviceDetail';
234 223
235 224 export default defineComponent({
236 225 name: 'DeviceManagement',
... ... @@ -244,7 +233,6 @@
244 233 DeviceDetailDrawer,
245 234 CustomerModal,
246 235 TableImg,
247   - Tooltip,
248 236 QuestionCircleOutlined,
249 237 Popover,
250 238 Authority,
... ... @@ -253,6 +241,7 @@
253 241 Button,
254 242 },
255 243 setup(_) {
  244 + const { isCustomer } = useAuthDeviceDetail();
256 245 const { createMessage } = useMessage();
257 246 const go = useGo();
258 247 const ROUTER = useRouter();
... ... @@ -515,6 +504,7 @@
515 504 handleBatchImport,
516 505 handleImportFinally,
517 506 handlePublicDevice,
  507 + isCustomer,
518 508 };
519 509 },
520 510 });
... ...
... ... @@ -4,7 +4,7 @@ import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
4 4 import { useMessage } from '/@/hooks/web/useMessage';
5 5 const { createMessage } = useMessage();
6 6
7   -const handeleCopy = (e) => {
  7 +export const handeleCopy = (e) => {
8 8 const { isSuccessRef } = useCopyToClipboard(JSON.parse(JSON.stringify(unref(e), null, 2)));
9 9 unref(isSuccessRef);
10 10 createMessage.success('复制成功!');
... ...