Commit 7056c89d71342725a759755df12ca71a74b3dd1a

Authored by fengtao
1 parent edb73b99

perf: 优化设备列表里的详情,任务,直接选中指定目标设备

1 1 <script lang="ts" setup>
  2 + import { ref } from 'vue';
2 3 import { TaskCard } from '/@/views/task/center/components/TaskCard';
3 4 import { formSchemas } from '/@/views/task/center/config';
4 5 import { getTaskCenterList } from '/@/api/task';
... ... @@ -29,6 +30,8 @@
29 30 },
30 31 });
31 32
  33 + const fromDeviceDetail = ref(true);
  34 +
32 35 const handleRunTask = (record: TaskRecordType) => {
33 36 openModal(true, record);
34 37 };
... ... @@ -50,7 +53,12 @@
50 53 />
51 54 </template>
52 55 </BasicCardList>
53   - <RunTaskModal :reload="reload" @register="registerRunTaskModal" />
  56 + <RunTaskModal
  57 + :tbDeviceId="tbDeviceId"
  58 + :fromOrigin="fromDeviceDetail"
  59 + :reload="reload"
  60 + @register="registerRunTaskModal"
  61 + />
54 62 </section>
55 63 <!-- </PageWrapper> -->
56 64 </template>
... ...
... ... @@ -14,6 +14,7 @@ export enum FormFieldsEnum {
14 14 TASK_TYPE = 'taskType',
15 15 TARGET_IDS = 'targetIds',
16 16 TASK_RECORD = 'taskRecord',
  17 + TB_DEVICE_ID = 'tbDeviceId',
17 18 }
18 19
19 20 export enum TargetType {
... ... @@ -61,6 +62,12 @@ export const formSchemas: FormSchema[] = [
61 62 },
62 63 },
63 64 {
  65 + field: FormFieldsEnum.TB_DEVICE_ID,
  66 + component: 'Input',
  67 + label: '',
  68 + show: false,
  69 + },
  70 + {
64 71 field: FormFieldsEnum.TARGET_IDS,
65 72 component: 'ApiSelect',
66 73 label: '指定目标设备',
... ... @@ -68,6 +75,7 @@ export const formSchemas: FormSchema[] = [
68 75 rules: [{ required: true, message: '请选择指定目标设备', type: 'array' }],
69 76 componentProps: ({ formModel }) => {
70 77 const record = JSON.parse(formModel[FormFieldsEnum.TASK_RECORD]) as TaskRecordType;
  78 + const tbDeviceId = formModel[FormFieldsEnum.TB_DEVICE_ID];
71 79 const isDevices = record.targetType === TaskTargetEnum.DEVICES;
72 80 const { executeTarget } = record;
73 81 const { organizationId, data } = executeTarget;
... ... @@ -79,6 +87,7 @@ export const formSchemas: FormSchema[] = [
79 87 return result.data.map((item) => ({
80 88 label: item.alias || item.name,
81 89 value: item.tbDeviceId,
  90 + disabled: tbDeviceId ? item.tbDeviceId !== tbDeviceId : false,
82 91 }));
83 92 } else {
84 93 const result = await getMeetTheConditionsDevice({
... ...
... ... @@ -4,30 +4,54 @@
4 4 import { BasicForm, useForm } from '/@/components/Form';
5 5 import { BasicModal, useModalInner } from '/@/components/Modal';
6 6 import { TaskTargetEnum, TaskTypeNameEnum } from '../../config';
7   - import { FormValue, TargetType, formSchemas } from './config';
  7 + import { FormFieldsEnum, FormValue, TargetNameType, TargetType, formSchemas } from './config';
8 8 import { unref } from 'vue';
9 9 import { immediateExecute } from '/@/api/task';
10 10 import { useMessage } from '/@/hooks/web/useMessage';
11 11 const props = defineProps<{
12 12 reload: Fn;
  13 + fromOrigin?: boolean;
  14 + tbDeviceId?: string;
13 15 }>();
14 16
15 17 defineEmits(['register']);
16 18
17 19 const dataSource = ref<TaskRecordType>();
18 20
  21 + const updateExecuteTargetType = (options: Recordable[]) => {
  22 + updateSchema({
  23 + field: FormFieldsEnum.EXECUTE_TARGET_TYPE,
  24 + componentProps: {
  25 + options,
  26 + },
  27 + });
  28 + };
  29 +
19 30 const [registerModal, { closeModal }] = useModalInner((record: TaskRecordType) => {
20 31 resetFields();
21 32 dataSource.value = record;
22 33 if (record) {
23 34 setFieldsValue({ taskRecord: JSON.stringify(record) } as FormValue);
  35 + // 如果是从设备详情里面的任务进来的
  36 + if (props.fromOrigin) {
  37 + setFieldsValue({ tbDeviceId: props.tbDeviceId } as FormValue);
  38 + setFieldsValue({ [FormFieldsEnum.EXECUTE_TARGET_TYPE]: TargetType.ASSIGN } as FormValue);
  39 + setFieldsValue({ [FormFieldsEnum.TARGET_IDS]: [props.tbDeviceId] } as FormValue);
  40 + updateExecuteTargetType([{ label: TargetNameType.ASSIGN, value: TargetType.ASSIGN }]);
  41 + } else {
  42 + updateExecuteTargetType([
  43 + { label: TargetNameType.ALL, value: TargetType.ALL },
  44 + { label: TargetNameType.ASSIGN, value: TargetType.ASSIGN },
  45 + ]);
  46 + }
24 47 }
25 48 });
26 49
27   - const [registerForm, { setFieldsValue, getFieldsValue, resetFields, validate }] = useForm({
28   - schemas: formSchemas,
29   - showActionButtonGroup: false,
30   - });
  50 + const [registerForm, { setFieldsValue, getFieldsValue, resetFields, validate, updateSchema }] =
  51 + useForm({
  52 + schemas: formSchemas,
  53 + showActionButtonGroup: false,
  54 + });
31 55
32 56 const composeData = (record: FormValue): ImmediateExecuteTaskType => {
33 57 const { executeTarget, targetIds } = record;
... ...