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 69 icon: string;
70 70 value?: string | number;
71 71 updateTime?: number;
  72 + showDeviceName: boolean;
72 73 }
73 74
74 75 export interface DataSource {
... ...
... ... @@ -14,7 +14,7 @@ enum Api {
14 14 * @description: Get user menu based on id
15 15 */
16 16
17   -export const getMenuList = (args) => {
  17 +export const getMenuList = (args?: number) => {
18 18 const userStore = useUserStore();
19 19 let url = Api.GetMenuList;
20 20 try {
... ...
... ... @@ -94,3 +94,9 @@ export function forgetPasswordApi(data) {
94 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 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 90 { label: '直连设备', value: DeviceTypeEnum.DIRECT_CONNECTION },
91 91 { label: '网关子设备', value: DeviceTypeEnum.SENSOR },
92 92 ],
  93 + placeholder: '请选择设备类型',
93 94 },
94 95 colProps: { span: 6 },
95 96 },
... ... @@ -103,13 +104,14 @@ export const searchFormSchema: FormSchema[] = [
103 104 { label: '在线', value: DeviceState.ONLINE },
104 105 { label: '离线', value: DeviceState.OFFLINE },
105 106 ],
  107 + placeholder: '请选择设备状态',
106 108 },
107 109 colProps: { span: 6 },
108 110 },
109 111 {
110 112 field: 'deviceProfileId',
111 113 label: '产品',
112   - component: 'ApiSearchSelect',
  114 + component: 'ApiSelect',
113 115 colProps: { span: 6 },
114 116 componentProps: () => {
115 117 return {
... ... @@ -118,26 +120,9 @@ export const searchFormSchema: FormSchema[] = [
118 120 valueField: 'id',
119 121 resultField: 'data',
120 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 16 @open-gateway-device="handleOpenGatewayDevice"
17 17 />
18 18 </TabPane>
19   - <TabPane key="modelOfMatter" tab="物模型">
  19 + <TabPane key="modelOfMatter" tab="物模型数据">
20 20 <ModelOfMatter :deviceDetail="deviceDetail" />
21 21 </TabPane>
22 22 <!-- <TabPane key="2" tab="实时数据" v-if="deviceDetail?.deviceType !== 'GATEWAY'">
... ...
... ... @@ -287,7 +287,7 @@
287 287 setTableData(items);
288 288 const { setFieldsValue, resetFields } = getForm();
289 289 setFieldsValue({
290   - deviceProfileId: deviceProfileId.value,
  290 + deviceProfileId: deviceProfileId.value || null,
291 291 });
292 292 if (onCloseVal.value == 1) {
293 293 resetFields();
... ...
... ... @@ -74,7 +74,7 @@
74 74
75 75 const dataSource = ref<ProfileRecord[]>([]);
76 76
77   - const colNumber = ref(4);
  77 + const colNumber = ref(5);
78 78
79 79 const getSelectAllFlag = computed(() => {
80 80 return unref(dataSource).every((item) => item.checked);
... ...
... ... @@ -16,6 +16,14 @@
16 16 <TableAction
17 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 27 label: '短信通知',
20 28 icon: 'ant-design:send-outlined',
21 29 tooltip: '发送通知短信',
... ... @@ -94,6 +102,12 @@
94 102 import { MessageTypeEnum, SendResetPasswordEmailMsg } from '/@/api/tenant/tenantInfo';
95 103 import { useMessage } from '/@/hooks/web/useMessage';
96 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 112 export default defineComponent({
99 113 name: 'TenantAdminDrawer',
... ... @@ -198,10 +212,15 @@
198 212 fixed: 'right',
199 213 },
200 214 });
  215 +
  216 + let firstEnterFlag = true;
201 217 //默认传递页面数据
202 218 const [tenantAdminDrawer, { closeDrawer }] = useDrawerInner(async (data) => {
203 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 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 253 return {
217 254 tenantAdminDrawer,
218 255 handleCreateTenantAdmin,
... ... @@ -225,6 +262,7 @@
225 262 handleDelete,
226 263 handleResetPassword,
227 264 handleSendMsg,
  265 + handleLoginTenantAdmin,
228 266 };
229 267 },
230 268 });
... ...
... ... @@ -72,7 +72,9 @@
72 72 >
73 73 <Tooltip :title="item.deviceName" placement="topLeft">
74 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 78 </div>
77 79 </Tooltip>
78 80 </div>
... ...
... ... @@ -33,7 +33,7 @@
33 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 38 const isEdit = ref(false);
39 39
... ... @@ -48,6 +48,7 @@
48 48 const [register, { closeModal, changeOkLoading }] = useModalInner(
49 49 (data: { isEdit: boolean; record?: DataBoardLayoutInfo }) => {
50 50 componentRecord.value = data.record || ({} as unknown as DataBoardLayoutInfo);
  51 + if (!unref(isEdit)) frontId.value = FrontComponent.TEXT_COMPONENT_1;
51 52 frontId.value =
52 53 (data.record?.record?.frontId as FrontComponent) || FrontComponent.TEXT_COMPONENT_1;
53 54 isEdit.value = data.isEdit || false;
... ...
1 1 <script lang="ts" setup>
2   - import { ref, onMounted, unref } from 'vue';
  2 + import { ref, onMounted, unref, computed } from 'vue';
3 3 import { FrontComponent } from '../../../const/const';
4 4 import { DataSourceField, dataSourceSchema } from '../../config/basicConfiguration';
5 5 import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';
... ... @@ -7,12 +7,18 @@
7 7 import BasicForm from '/@/components/Form/src/BasicForm.vue';
8 8 const formEl = ref<Nullable<FormActionType>>(null);
9 9
10   - defineProps<{
  10 + const props = defineProps<{
11 11 frontId?: FrontComponent;
12 12 }>();
13 13
14 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 22 onMounted(() => {
17 23 unref(formEl)?.setFieldsValue({ [DataSourceField.DEVICE_TYPE]: DeviceTypeEnum.SENSOR });
18 24 });
... ... @@ -21,7 +27,7 @@
21 27 <template>
22 28 <BasicForm
23 29 ref="formEl"
24   - :schemas="dataSourceSchema($props.frontId)"
  30 + :schemas="getDataSchema"
25 31 class="w-full flex-1 data-source-form"
26 32 :show-action-button-group="false"
27 33 :row-props="{
... ...
... ... @@ -61,6 +61,7 @@
61 61 icon: value.icon || null,
62 62 iconColor: value.iconColor || null,
63 63 unit: value.unit || null,
  64 + showDeviceName: value.showDeviceName,
64 65 gradientInfo: [
65 66 { key: Gradient.FIRST, value: value.firstPhaseValue, color: value.firstPhaseColor },
66 67 { key: Gradient.SECOND, value: value.secondPhaseValue, color: value.secondPhaseColor },
... ...
... ... @@ -149,6 +149,7 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
149 149 const { setFieldsValue } = formActionType;
150 150 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
151 151 const deviceType = formModel[DataSourceField.DEVICE_TYPE];
  152 + if (![deviceType, deviceProfileId].every(Boolean)) return {};
152 153 return {
153 154 api: async () => {
154 155 if (!deviceType) return [];
... ... @@ -253,6 +254,7 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
253 254 componentProps({ formModel }) {
254 255 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
255 256 const transportType = formModel[DataSourceField.TRANSPORT_TYPE];
  257 + if (![deviceProfileId, transportType].every(Boolean)) return {};
256 258 return {
257 259 api: async () => {
258 260 try {
... ...
... ... @@ -12,6 +12,7 @@ export interface VisualOptionParams {
12 12 [visualOptionField.FIRST_PHASE_VALUE]: string;
13 13 [visualOptionField.SECOND_PHASE_VALUE]: string;
14 14 [visualOptionField.THIRD_PHASE_VALUE]: string;
  15 + [visualOptionField.SHOW_DEVICE_NAME]: string;
15 16 }
16 17
17 18 export enum visualOptionField {
... ... @@ -25,6 +26,7 @@ export enum visualOptionField {
25 26 FIRST_PHASE_VALUE = 'firstPhaseValue',
26 27 SECOND_PHASE_VALUE = 'secondPhaseValue',
27 28 THIRD_PHASE_VALUE = 'thirdPhaseValue',
  29 + SHOW_DEVICE_NAME = 'showDeviceName',
28 30 }
29 31
30 32 export const modeOne: FormSchema[] = [
... ... @@ -37,6 +39,11 @@ export const modeOne: FormSchema[] = [
37 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 49 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 95 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 178 export const modeFour: FormSchema[] = [
... ... @@ -176,6 +193,11 @@ export const modeFour: FormSchema[] = [
176 193 placeholder: '请输入数值单位',
177 194 },
178 195 },
  196 + {
  197 + field: visualOptionField.SHOW_DEVICE_NAME,
  198 + label: '显示设备名称',
  199 + component: 'Checkbox',
  200 + },
179 201 ];
180 202
181 203 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 241 export const schemasMap = new Map<FrontComponent, FormSchema[]>();
... ...