| | |
| | | }; |
| | | |
| | | 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; |
| | |
| | | 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, |
| | |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | return jsonConfigList; |
| | | }; |
| | | |
| | | const updateSqlAndRs = (id?, sqlValue?: string) => { |
| | |
| | | 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, |
| | |
| | | ElMessage.warning('暂无SQL配置'); |
| | | return; |
| | | } |
| | | configList.value = |
| | | const originConfig = |
| | | xmlJson.async_rs?.map( |
| | | (item) => |
| | | ({ |
| | |
| | | ) ?? []; |
| | | 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> |