yangyin
2024-09-09 77286f9747a37e4a8a8713f1b7f2195652092795
src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
@@ -77,9 +77,10 @@
import * as supervisorApi from '/@/api/supervisorAdmin';
import { updateSqlApi } from '/@/api/supervisorAdmin';
import { useCompRef } from '/@/utils/types';
import { SupervisorPublished } from '../types';
const props = defineProps(['supervisor']);
const emit = defineEmits(['backLastPage']);
const emit = defineEmits(['backLastPage', 'updatePublished']);
const log = console.log;
const jsonCode = ref(codeExample.jsonCode);
const dockCode = ref(codeExample.dockCode);
@@ -159,10 +160,10 @@
};
const configList = ref<AmisDockConfig[]>([]);
const parseJSONData = (obj: any) => {
   const apiDataList = configList.value;
const parseJSONData = (obj: any, apiDataList) => {
   // 先清空
   configList.value = [];
   const jsonConfigList = [];
   travelObj(obj, (key, value, path) => {
      if (key === 'api') {
         // const url = value.url;
@@ -172,7 +173,7 @@
         const asyncId = foundItem?.asyncId ?? randomStr;
         const recordId = foundItem?.recordId ?? randomStr;
         // const recordId = uniqueId()
         configList.value.push({
         jsonConfigList.push({
            asyncId: asyncId,
            recordId: recordId,
            type: AmisDockType.Api,
@@ -180,6 +181,8 @@
         });
      }
   });
   return jsonConfigList;
};
const updateSqlAndRs = (id?, sqlValue?: string) => {
@@ -221,7 +224,9 @@
      {
         loading: false,
      }
   );
   ).then(() => {
      emit('updatePublished', props.supervisor.id, SupervisorPublished.N);
   });
};
const sqlCodeChange = debounce((val) => {
@@ -231,6 +236,36 @@
const sqlList = ref([]);
const rsTableRef = ref<TableInstance>(null);
let xmlJson = null;
// 检查是否需要更新 rs
const checkRsUpdate = (originData: AmisDockConfig[], currentData: AmisDockConfig[]) => {
   // 都为空,不需要更新
   if ((!originData || originData.length === 0) && (!currentData || currentData.length === 0)) {
      return false;
   }
   // 存在一方为空,需要更新
   if (!originData || !currentData) {
      return true;
   }
   // 长度不一致,需要更新
   if (originData.length !== currentData.length) {
      return true;
   }
   return originData.some((originItem) => {
      const id = originItem.asyncId;
      const currentItem = currentData.find((item) => item.asyncId === id);
      // 没找到对应项,需要更新
      if (!currentItem) {
         return true;
      }
      // 对象项值不相等,需要更新
      return Object.keys(currentItem).some((item) => originItem[item] !== currentItem[item]);
   });
};
onMounted(async () => {
   xmlJson = await supervisorApi.getLowCodeJson({
      id: props.supervisor.id,
@@ -239,7 +274,7 @@
      ElMessage.warning('暂无SQL配置');
      return;
   }
   configList.value =
   const originConfig =
      xmlJson.async_rs?.map(
         (item) =>
            ({
@@ -251,13 +286,16 @@
      ) ?? [];
   sqlList.value = xmlJson.sql ?? null;
   parseJSONData(xmlJson.amis_json);
   configList.value = parseJSONData(xmlJson.amis_json, originConfig);
   if (configList.value.length > 0) {
      rsTableRef.value.setCurrentRow(configList.value[0]);
      // dockRowChange(configList.value[0]);
   }
   // 自动更新Rs
   updateSqlAndRs();
   if (checkRsUpdate(originConfig, configList.value)) {
      // 自动更新Rs
      updateSqlAndRs();
   }
});
</script>