gerson
2024-09-07 f10ba0bb7199e3b6bd6ed55dde682ba13de2fa19
src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
@@ -159,10 +159,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 +172,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 +180,8 @@
         });
      }
   });
   return jsonConfigList;
};
const updateSqlAndRs = (id?, sqlValue?: string) => {
@@ -231,6 +233,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 +271,7 @@
      ElMessage.warning('暂无SQL配置');
      return;
   }
   configList.value =
   const originConfig =
      xmlJson.async_rs?.map(
         (item) =>
            ({
@@ -251,13 +283,18 @@
      ) ?? [];
   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>