Commit 195ab9cb4d567a06bdd7d0311dc524c697fbd9b2

Authored by xp.Huang
2 parents 226aff84 897143e4

Merge branch 'ww' into 'main'

perf: resolve repeat fetch && fix bug

See merge request huang/yun-teng-iot-front!455
@@ -69,6 +69,7 @@ export interface ComponentInfo { @@ -69,6 +69,7 @@ export interface ComponentInfo {
69 icon: string; 69 icon: string;
70 value?: string | number; 70 value?: string | number;
71 updateTime?: number; 71 updateTime?: number;
  72 + showDeviceName: boolean;
72 } 73 }
73 74
74 export interface DataSource { 75 export interface DataSource {
@@ -14,7 +14,7 @@ enum Api { @@ -14,7 +14,7 @@ enum Api {
14 * @description: Get user menu based on id 14 * @description: Get user menu based on id
15 */ 15 */
16 16
17 -export const getMenuList = (args) => { 17 +export const getMenuList = (args?: number) => {
18 const userStore = useUserStore(); 18 const userStore = useUserStore();
19 let url = Api.GetMenuList; 19 let url = Api.GetMenuList;
20 try { 20 try {
@@ -94,3 +94,9 @@ export function forgetPasswordApi(data) { @@ -94,3 +94,9 @@ export function forgetPasswordApi(data) {
94 data, 94 data,
95 }); 95 });
96 } 96 }
  97 +
  98 +export const getUserToken = (id: string) => {
  99 + return defHttp.get<Record<'token' | 'refreshToken', string>>({
  100 + url: `/third/login/id/${id}`,
  101 + });
  102 +};
@@ -80,6 +80,9 @@ export const step1Schemas: FormSchema[] = [ @@ -80,6 +80,9 @@ export const step1Schemas: FormSchema[] = [
80 gatewayId: null, 80 gatewayId: null,
81 }); 81 });
82 }, 82 },
  83 + showSearch: true,
  84 + filterOption: (inputValue: string, option: Record<'label' | 'value', string>) =>
  85 + option.label.includes(inputValue),
83 }; 86 };
84 }, 87 },
85 }, 88 },
@@ -90,6 +90,7 @@ export const searchFormSchema: FormSchema[] = [ @@ -90,6 +90,7 @@ export const searchFormSchema: FormSchema[] = [
90 { label: '直连设备', value: DeviceTypeEnum.DIRECT_CONNECTION }, 90 { label: '直连设备', value: DeviceTypeEnum.DIRECT_CONNECTION },
91 { label: '网关子设备', value: DeviceTypeEnum.SENSOR }, 91 { label: '网关子设备', value: DeviceTypeEnum.SENSOR },
92 ], 92 ],
  93 + placeholder: '请选择设备类型',
93 }, 94 },
94 colProps: { span: 6 }, 95 colProps: { span: 6 },
95 }, 96 },
@@ -103,13 +104,14 @@ export const searchFormSchema: FormSchema[] = [ @@ -103,13 +104,14 @@ export const searchFormSchema: FormSchema[] = [
103 { label: '在线', value: DeviceState.ONLINE }, 104 { label: '在线', value: DeviceState.ONLINE },
104 { label: '离线', value: DeviceState.OFFLINE }, 105 { label: '离线', value: DeviceState.OFFLINE },
105 ], 106 ],
  107 + placeholder: '请选择设备状态',
106 }, 108 },
107 colProps: { span: 6 }, 109 colProps: { span: 6 },
108 }, 110 },
109 { 111 {
110 field: 'deviceProfileId', 112 field: 'deviceProfileId',
111 label: '产品', 113 label: '产品',
112 - component: 'ApiSearchSelect', 114 + component: 'ApiSelect',
113 colProps: { span: 6 }, 115 colProps: { span: 6 },
114 componentProps: () => { 116 componentProps: () => {
115 return { 117 return {
@@ -118,26 +120,9 @@ export const searchFormSchema: FormSchema[] = [ @@ -118,26 +120,9 @@ export const searchFormSchema: FormSchema[] = [
118 valueField: 'id', 120 valueField: 'id',
119 resultField: 'data', 121 resultField: 'data',
120 placeholder: '请选择产品', 122 placeholder: '请选择产品',
121 - api: async () => {  
122 - const data = await deviceProfile({ params: '' });  
123 - const returnData = data.map((m) => {  
124 - return {  
125 - name: m.name,  
126 - id: m.id,  
127 - };  
128 - });  
129 - return returnData;  
130 - },  
131 - searchApi: async (params: Recordable) => {  
132 - const data = await deviceProfile({ textSearch: params.text });  
133 - const returnData = data.map((m) => {  
134 - return {  
135 - name: m.name,  
136 - id: m.id,  
137 - };  
138 - });  
139 - return returnData;  
140 - }, 123 + api: deviceProfile,
  124 + filterOption: (inputValue: string, option: Record<'label' | 'value', string>) =>
  125 + option.label.includes(inputValue),
141 }; 126 };
142 }, 127 },
143 }, 128 },
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 @open-gateway-device="handleOpenGatewayDevice" 16 @open-gateway-device="handleOpenGatewayDevice"
17 /> 17 />
18 </TabPane> 18 </TabPane>
19 - <TabPane key="modelOfMatter" tab="物模型"> 19 + <TabPane key="modelOfMatter" tab="物模型数据">
20 <ModelOfMatter :deviceDetail="deviceDetail" /> 20 <ModelOfMatter :deviceDetail="deviceDetail" />
21 </TabPane> 21 </TabPane>
22 <!-- <TabPane key="2" tab="实时数据" v-if="deviceDetail?.deviceType !== 'GATEWAY'"> 22 <!-- <TabPane key="2" tab="实时数据" v-if="deviceDetail?.deviceType !== 'GATEWAY'">
@@ -287,7 +287,7 @@ @@ -287,7 +287,7 @@
287 setTableData(items); 287 setTableData(items);
288 const { setFieldsValue, resetFields } = getForm(); 288 const { setFieldsValue, resetFields } = getForm();
289 setFieldsValue({ 289 setFieldsValue({
290 - deviceProfileId: deviceProfileId.value, 290 + deviceProfileId: deviceProfileId.value || null,
291 }); 291 });
292 if (onCloseVal.value == 1) { 292 if (onCloseVal.value == 1) {
293 resetFields(); 293 resetFields();
@@ -74,7 +74,7 @@ @@ -74,7 +74,7 @@
74 74
75 const dataSource = ref<ProfileRecord[]>([]); 75 const dataSource = ref<ProfileRecord[]>([]);
76 76
77 - const colNumber = ref(4); 77 + const colNumber = ref(5);
78 78
79 const getSelectAllFlag = computed(() => { 79 const getSelectAllFlag = computed(() => {
80 return unref(dataSource).every((item) => item.checked); 80 return unref(dataSource).every((item) => item.checked);
@@ -16,6 +16,14 @@ @@ -16,6 +16,14 @@
16 <TableAction 16 <TableAction
17 :actions="[ 17 :actions="[
18 { 18 {
  19 + label: '进入',
  20 + icon: 'ant-design:login-outlined',
  21 + tooltip: '以租户管理员身份登录',
  22 + onClick: handleLoginTenantAdmin.bind(null, record),
  23 + },
  24 + ]"
  25 + :drop-down-actions="[
  26 + {
19 label: '短信通知', 27 label: '短信通知',
20 icon: 'ant-design:send-outlined', 28 icon: 'ant-design:send-outlined',
21 tooltip: '发送通知短信', 29 tooltip: '发送通知短信',
@@ -94,6 +102,12 @@ @@ -94,6 +102,12 @@
94 import { MessageTypeEnum, SendResetPasswordEmailMsg } from '/@/api/tenant/tenantInfo'; 102 import { MessageTypeEnum, SendResetPasswordEmailMsg } from '/@/api/tenant/tenantInfo';
95 import { useMessage } from '/@/hooks/web/useMessage'; 103 import { useMessage } from '/@/hooks/web/useMessage';
96 import { Authority } from '/@/components/Authority'; 104 import { Authority } from '/@/components/Authority';
  105 + import { getMyInfo, getPermCode, getUserToken } from '/@/api/sys/user';
  106 + import { useUserStore } from '/@/store/modules/user';
  107 + import { usePermissionStore } from '/@/store/modules/permission';
  108 + import { RoleEnum } from '/@/enums/roleEnum';
  109 + import { useGo } from '/@/hooks/web/usePage';
  110 + import { PageEnum } from '/@/enums/pageEnum';
97 111
98 export default defineComponent({ 112 export default defineComponent({
99 name: 'TenantAdminDrawer', 113 name: 'TenantAdminDrawer',
@@ -198,10 +212,15 @@ @@ -198,10 +212,15 @@
198 fixed: 'right', 212 fixed: 'right',
199 }, 213 },
200 }); 214 });
  215 +
  216 + let firstEnterFlag = true;
201 //默认传递页面数据 217 //默认传递页面数据
202 const [tenantAdminDrawer, { closeDrawer }] = useDrawerInner(async (data) => { 218 const [tenantAdminDrawer, { closeDrawer }] = useDrawerInner(async (data) => {
203 tenantId.value = data.record.tenantId; 219 tenantId.value = data.record.tenantId;
204 - reload(); 220 + !firstEnterFlag && reload();
  221 + if (firstEnterFlag) {
  222 + firstEnterFlag = false;
  223 + }
205 }); 224 });
206 225
207 //提交按钮 226 //提交按钮
@@ -213,6 +232,24 @@ @@ -213,6 +232,24 @@
213 reload(); 232 reload();
214 } 233 }
215 234
  235 + const userStore = useUserStore();
  236 + const permissionStore = usePermissionStore();
  237 + const go = useGo();
  238 + async function handleLoginTenantAdmin(record: { tbUser: string; id: string }) {
  239 + try {
  240 + const { token, refreshToken } = await getUserToken(record.id);
  241 + userStore.storeToken(token, refreshToken);
  242 + const userInfo = await getMyInfo();
  243 + const permissionList = await getPermCode();
  244 + permissionStore.setPermCodeList(permissionList);
  245 + userStore.setUserInfo(userInfo);
  246 + userStore.setRoleList(userInfo.roles as RoleEnum[]);
  247 + go(PageEnum.BASE_HOME);
  248 + } catch (error) {
  249 + } finally {
  250 + }
  251 + }
  252 +
216 return { 253 return {
217 tenantAdminDrawer, 254 tenantAdminDrawer,
218 handleCreateTenantAdmin, 255 handleCreateTenantAdmin,
@@ -225,6 +262,7 @@ @@ -225,6 +262,7 @@
225 handleDelete, 262 handleDelete,
226 handleResetPassword, 263 handleResetPassword,
227 handleSendMsg, 264 handleSendMsg,
  265 + handleLoginTenantAdmin,
228 }; 266 };
229 }, 267 },
230 }); 268 });
@@ -72,7 +72,9 @@ @@ -72,7 +72,9 @@
72 > 72 >
73 <Tooltip :title="item.deviceName" placement="topLeft"> 73 <Tooltip :title="item.deviceName" placement="topLeft">
74 <div class="flex p-1"> 74 <div class="flex p-1">
75 - <div class="truncate font-bold">{{ item.deviceRename || item.deviceName }}</div> 75 + <div v-if="item.componentInfo.showDeviceName" class="truncate font-bold">
  76 + {{ item.deviceRename || item.deviceName }}
  77 + </div>
76 </div> 78 </div>
77 </Tooltip> 79 </Tooltip>
78 </div> 80 </div>
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
33 return decode((ROUTE.params as DataComponentRouteParams).boardId as string); 33 return decode((ROUTE.params as DataComponentRouteParams).boardId as string);
34 }); 34 });
35 35
36 - const frontId = ref(FrontComponent.TEXT_COMPONENT_1); 36 + const frontId = ref();
37 37
38 const isEdit = ref(false); 38 const isEdit = ref(false);
39 39
@@ -48,6 +48,7 @@ @@ -48,6 +48,7 @@
48 const [register, { closeModal, changeOkLoading }] = useModalInner( 48 const [register, { closeModal, changeOkLoading }] = useModalInner(
49 (data: { isEdit: boolean; record?: DataBoardLayoutInfo }) => { 49 (data: { isEdit: boolean; record?: DataBoardLayoutInfo }) => {
50 componentRecord.value = data.record || ({} as unknown as DataBoardLayoutInfo); 50 componentRecord.value = data.record || ({} as unknown as DataBoardLayoutInfo);
  51 + if (!unref(isEdit)) frontId.value = FrontComponent.TEXT_COMPONENT_1;
51 frontId.value = 52 frontId.value =
52 (data.record?.record?.frontId as FrontComponent) || FrontComponent.TEXT_COMPONENT_1; 53 (data.record?.record?.frontId as FrontComponent) || FrontComponent.TEXT_COMPONENT_1;
53 isEdit.value = data.isEdit || false; 54 isEdit.value = data.isEdit || false;
1 <script lang="ts" setup> 1 <script lang="ts" setup>
2 - import { ref, onMounted, unref } from 'vue'; 2 + import { ref, onMounted, unref, computed } from 'vue';
3 import { FrontComponent } from '../../../const/const'; 3 import { FrontComponent } from '../../../const/const';
4 import { DataSourceField, dataSourceSchema } from '../../config/basicConfiguration'; 4 import { DataSourceField, dataSourceSchema } from '../../config/basicConfiguration';
5 import { DeviceTypeEnum } from '/@/api/device/model/deviceModel'; 5 import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';
@@ -7,12 +7,18 @@ @@ -7,12 +7,18 @@
7 import BasicForm from '/@/components/Form/src/BasicForm.vue'; 7 import BasicForm from '/@/components/Form/src/BasicForm.vue';
8 const formEl = ref<Nullable<FormActionType>>(null); 8 const formEl = ref<Nullable<FormActionType>>(null);
9 9
10 - defineProps<{ 10 + const props = defineProps<{
11 frontId?: FrontComponent; 11 frontId?: FrontComponent;
12 }>(); 12 }>();
13 13
14 defineExpose({ formActionType: formEl }); 14 defineExpose({ formActionType: formEl });
15 15
  16 + const getDataSchema = computed(() => {
  17 + const { frontId } = props;
  18 + if (!frontId) return [];
  19 + return dataSourceSchema(frontId);
  20 + });
  21 +
16 onMounted(() => { 22 onMounted(() => {
17 unref(formEl)?.setFieldsValue({ [DataSourceField.DEVICE_TYPE]: DeviceTypeEnum.SENSOR }); 23 unref(formEl)?.setFieldsValue({ [DataSourceField.DEVICE_TYPE]: DeviceTypeEnum.SENSOR });
18 }); 24 });
@@ -21,7 +27,7 @@ @@ -21,7 +27,7 @@
21 <template> 27 <template>
22 <BasicForm 28 <BasicForm
23 ref="formEl" 29 ref="formEl"
24 - :schemas="dataSourceSchema($props.frontId)" 30 + :schemas="getDataSchema"
25 class="w-full flex-1 data-source-form" 31 class="w-full flex-1 data-source-form"
26 :show-action-button-group="false" 32 :show-action-button-group="false"
27 :row-props="{ 33 :row-props="{
@@ -61,6 +61,7 @@ @@ -61,6 +61,7 @@
61 icon: value.icon || null, 61 icon: value.icon || null,
62 iconColor: value.iconColor || null, 62 iconColor: value.iconColor || null,
63 unit: value.unit || null, 63 unit: value.unit || null,
  64 + showDeviceName: value.showDeviceName,
64 gradientInfo: [ 65 gradientInfo: [
65 { key: Gradient.FIRST, value: value.firstPhaseValue, color: value.firstPhaseColor }, 66 { key: Gradient.FIRST, value: value.firstPhaseValue, color: value.firstPhaseColor },
66 { key: Gradient.SECOND, value: value.secondPhaseValue, color: value.secondPhaseColor }, 67 { key: Gradient.SECOND, value: value.secondPhaseValue, color: value.secondPhaseColor },
@@ -149,6 +149,7 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { @@ -149,6 +149,7 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
149 const { setFieldsValue } = formActionType; 149 const { setFieldsValue } = formActionType;
150 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID]; 150 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
151 const deviceType = formModel[DataSourceField.DEVICE_TYPE]; 151 const deviceType = formModel[DataSourceField.DEVICE_TYPE];
  152 + if (![deviceType, deviceProfileId].every(Boolean)) return {};
152 return { 153 return {
153 api: async () => { 154 api: async () => {
154 if (!deviceType) return []; 155 if (!deviceType) return [];
@@ -253,6 +254,7 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { @@ -253,6 +254,7 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
253 componentProps({ formModel }) { 254 componentProps({ formModel }) {
254 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID]; 255 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
255 const transportType = formModel[DataSourceField.TRANSPORT_TYPE]; 256 const transportType = formModel[DataSourceField.TRANSPORT_TYPE];
  257 + if (![deviceProfileId, transportType].every(Boolean)) return {};
256 return { 258 return {
257 api: async () => { 259 api: async () => {
258 try { 260 try {
@@ -12,6 +12,7 @@ export interface VisualOptionParams { @@ -12,6 +12,7 @@ export interface VisualOptionParams {
12 [visualOptionField.FIRST_PHASE_VALUE]: string; 12 [visualOptionField.FIRST_PHASE_VALUE]: string;
13 [visualOptionField.SECOND_PHASE_VALUE]: string; 13 [visualOptionField.SECOND_PHASE_VALUE]: string;
14 [visualOptionField.THIRD_PHASE_VALUE]: string; 14 [visualOptionField.THIRD_PHASE_VALUE]: string;
  15 + [visualOptionField.SHOW_DEVICE_NAME]: string;
15 } 16 }
16 17
17 export enum visualOptionField { 18 export enum visualOptionField {
@@ -25,6 +26,7 @@ export enum visualOptionField { @@ -25,6 +26,7 @@ export enum visualOptionField {
25 FIRST_PHASE_VALUE = 'firstPhaseValue', 26 FIRST_PHASE_VALUE = 'firstPhaseValue',
26 SECOND_PHASE_VALUE = 'secondPhaseValue', 27 SECOND_PHASE_VALUE = 'secondPhaseValue',
27 THIRD_PHASE_VALUE = 'thirdPhaseValue', 28 THIRD_PHASE_VALUE = 'thirdPhaseValue',
  29 + SHOW_DEVICE_NAME = 'showDeviceName',
28 } 30 }
29 31
30 export const modeOne: FormSchema[] = [ 32 export const modeOne: FormSchema[] = [
@@ -37,6 +39,11 @@ export const modeOne: FormSchema[] = [ @@ -37,6 +39,11 @@ export const modeOne: FormSchema[] = [
37 defaultValue: '#000', 39 defaultValue: '#000',
38 }, 40 },
39 }, 41 },
  42 + {
  43 + field: visualOptionField.SHOW_DEVICE_NAME,
  44 + label: '显示设备名称',
  45 + component: 'Checkbox',
  46 + },
40 ]; 47 ];
41 48
42 export const modeTwo: FormSchema[] = [ 49 export const modeTwo: FormSchema[] = [
@@ -78,6 +85,11 @@ export const modeTwo: FormSchema[] = [ @@ -78,6 +85,11 @@ export const modeTwo: FormSchema[] = [
78 }; 85 };
79 }, 86 },
80 }, 87 },
  88 + {
  89 + field: visualOptionField.SHOW_DEVICE_NAME,
  90 + label: '显示设备名称',
  91 + component: 'Checkbox',
  92 + },
81 ]; 93 ];
82 94
83 export const modeThree: FormSchema[] = [ 95 export const modeThree: FormSchema[] = [
@@ -156,6 +168,11 @@ export const modeThree: FormSchema[] = [ @@ -156,6 +168,11 @@ export const modeThree: FormSchema[] = [
156 }; 168 };
157 }, 169 },
158 }, 170 },
  171 + {
  172 + field: visualOptionField.SHOW_DEVICE_NAME,
  173 + label: '显示设备名称',
  174 + component: 'Checkbox',
  175 + },
159 ]; 176 ];
160 177
161 export const modeFour: FormSchema[] = [ 178 export const modeFour: FormSchema[] = [
@@ -176,6 +193,11 @@ export const modeFour: FormSchema[] = [ @@ -176,6 +193,11 @@ export const modeFour: FormSchema[] = [
176 placeholder: '请输入数值单位', 193 placeholder: '请输入数值单位',
177 }, 194 },
178 }, 195 },
  196 + {
  197 + field: visualOptionField.SHOW_DEVICE_NAME,
  198 + label: '显示设备名称',
  199 + component: 'Checkbox',
  200 + },
179 ]; 201 ];
180 202
181 export const modeFive: FormSchema[] = [ 203 export const modeFive: FormSchema[] = [
@@ -209,6 +231,11 @@ export const modeFive: FormSchema[] = [ @@ -209,6 +231,11 @@ export const modeFive: FormSchema[] = [
209 }; 231 };
210 }, 232 },
211 }, 233 },
  234 + {
  235 + field: visualOptionField.SHOW_DEVICE_NAME,
  236 + label: '显示设备名称',
  237 + component: 'Checkbox',
  238 + },
212 ]; 239 ];
213 240
214 export const schemasMap = new Map<FrontComponent, FormSchema[]>(); 241 export const schemasMap = new Map<FrontComponent, FormSchema[]>();