EditMoreConfigured.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <script setup lang="ts">
  2. import { tryOnMounted } from '@vueuse/core';
  3. import { useRequest } from 'alova/client';
  4. import { batchUpdateDeviceManageMethod, getDeviceManageDetailMethod, updateDeviceManageMethod } from '@/request/api/device.api';
  5. import { notification } from 'ant-design-vue';
  6. import { AioFlowConfig, type FlowRequestData } from '@/pages/aio/flow-config/index';
  7. import type { DeviceManageModel } from '@/model/device.model';
  8. const flowData = ref<FlowRequestData>();
  9. const loading = ref(false);
  10. // const defaultModel: DeviceManageModel = {};
  11. const props = defineProps<{ data: DeviceManageModel[] }>();
  12. const emits = defineEmits<{
  13. submit: [data?: DeviceManageModel];
  14. submitSingle: [];
  15. }>();
  16. // 批量修改
  17. const { loading: submitting, send: submit } = useRequest(batchUpdateDeviceManageMethod, { immediate: false }).onSuccess(() => {
  18. emits('submit');
  19. notification.success({ message: '修改成功' });
  20. });
  21. // 单个修改
  22. const { loading: submittingSingle, send: submitSingle } = useRequest(updateDeviceManageMethod, { immediate: false }).onSuccess(() => {
  23. emits('submitSingle');
  24. notification.success({ message: '修改成功' });
  25. });
  26. // 右侧设备列表
  27. const tableData = computed<DeviceManageModel[]>(() => {
  28. const src = props.data as any;
  29. if (Array.isArray(src)) return src;
  30. if (src && Array.isArray(src.data)) return src.data;
  31. return src ? [src] : [];
  32. });
  33. // 设备ID增删在批量配置不需要
  34. let ids = ref<string[]>([]);
  35. tryOnMounted(async () => {
  36. if (props.data && Array.isArray(props.data) && props.data.length > 1) {
  37. props.data?.forEach((item: any) => {
  38. ids.value.push(item.id);
  39. });
  40. flowData.value = mock();
  41. } else if (props.data && props.data.length === 1) {
  42. flowData.value = (await getDeviceManageDetailMethod({ id: props.data[0].id })) as FlowRequestData;
  43. }
  44. });
  45. // 初始化数据
  46. const mock = () => {
  47. return {
  48. tabletProcessModules: ['patient_file', 'tongueface_upload', 'tongueface_analysis', 'health_analysis'],
  49. tabletFileFields: ['phone:required', 'sex', 'age', 'isEasyAllergy'],
  50. tabletRequiredPageOperationElements: [
  51. 'health_analysis_report_page_appletbutton'
  52. ],
  53. technicalSupporter: '',
  54. };
  55. };
  56. const flowRef = useTemplateRef<InstanceType<typeof AioFlowConfig>>('flow');
  57. // 保存
  58. const save = async () => {
  59. // 改为仅透传提交事件,由父级统一关闭弹窗,避免重复 close 导致内部状态异常
  60. await flowRef.value!.validate(/* 传入 false 不展示错误信息 */ true);
  61. if (Array.isArray(props.data) && props.data.length > 1) {
  62. await submit({ ...flowData.value, ids: ids.value });
  63. } else if (Array.isArray(props.data) && props.data.length === 1) {
  64. await submitSingle({ ...flowData.value, id: props.data[0].id } as DeviceManageModel);
  65. }
  66. };
  67. const reset = () => {
  68. flowRef.value?.update();
  69. };
  70. </script>
  71. <template>
  72. <div class="two-pane h-full">
  73. <div class="left form-container flex flex-col">
  74. <!-- 流程配置 -->
  75. <div class="flex-auto content-container">
  76. <div class="title">流程配置</div>
  77. <!-- validate 方法通过后会自动更新 -->
  78. <AioFlowConfig ref="flow" :loading="loading" v-model:request-data="flowData"></AioFlowConfig>
  79. </div>
  80. <!-- 保存和重置 -->
  81. <div class="button-container">
  82. <vxe-button type="reset" content="重置" @click="reset()"></vxe-button>
  83. <vxe-button type="submit" status="primary" content="保存" @click="save()" :loading="submitting || submittingSingle"></vxe-button>
  84. </div>
  85. </div>
  86. <!-- 右侧设备列表 -->
  87. <div class="right table-container flex flex-col">
  88. <div class="table-title flex-none">待配置设备</div>
  89. <div class="table-wrapper flex-auto">
  90. <table class="simple-table">
  91. <thead>
  92. <tr>
  93. <th>设备ID</th>
  94. <th>组织</th>
  95. <th>机构名称</th>
  96. </tr>
  97. </thead>
  98. <tbody>
  99. <tr v-for="item in tableData" :key="item.id">
  100. <td>{{ item.warrant }}</td>
  101. <td>{{ item.orgName }}</td>
  102. <td>{{ item.institutionName }}</td>
  103. </tr>
  104. </tbody>
  105. </table>
  106. </div>
  107. </div>
  108. </div>
  109. </template>
  110. <style scoped lang="scss">
  111. .content-container {
  112. width: 100%;
  113. //height: 600px;
  114. display: flex;
  115. flex-direction: column;
  116. > div:not(.title) {
  117. flex: auto;
  118. }
  119. > .title {
  120. flex: none;
  121. padding: 12px;
  122. font-size: 16px;
  123. font-weight: 800;
  124. }
  125. }
  126. .two-pane {
  127. display: flex;
  128. gap: 24px;
  129. }
  130. .left {
  131. flex: 1;
  132. }
  133. .right {
  134. width: 30%;
  135. min-width: 420px;
  136. }
  137. .table-title {
  138. font-weight: 600;
  139. margin-bottom: 8px;
  140. }
  141. .table-wrapper {
  142. border: 1px solid #eee;
  143. //height: 100%;
  144. overflow: auto;
  145. }
  146. .simple-table {
  147. width: 100%;
  148. border-collapse: collapse;
  149. }
  150. .simple-table th,
  151. .simple-table td {
  152. border-bottom: 1px solid #f0f0f0;
  153. padding: 8px 12px;
  154. text-align: left;
  155. }
  156. .form-container {
  157. //padding: 20px;
  158. }
  159. .section-divider {
  160. height: 1px;
  161. background-color: #d9d9d9;
  162. margin-bottom: 15px;
  163. }
  164. .button-container {
  165. flex: none;
  166. display: flex;
  167. justify-content: center;
  168. align-items: center;
  169. gap: 16px;
  170. padding-top: 20px;
  171. }
  172. </style>