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