Explorar o código

多个下拉组件使用api 级联选择时修复问题

wu hai 5 meses
pai
achega
4cb943e9aa

+ 22 - 1
src/components/Dataset-filter/util.js

@@ -126,7 +126,28 @@ export const getAPIData = (filter, enumId, formAllVar, componentList, type, apiP
             //api返回值变量
             if (i.varType[0] === 4) {
               const sessionValue = sessionStorage.getItem(`API_${i.varType[1]}`)
-              if (sessionValue) formVarObj[i.key] = sessionValue
+              if (sessionValue){
+                formVarObj[i.key] = sessionValue
+              } else {
+                // 当编辑时 还没有在session存入api返回值 所以需要手动去查询
+                let isTreeSelect = filter.__config__.jnpfKey === 'treeSelect' || filter.__config__.jnpfKey === 'cascader'
+                // 查询当前绑定的api返回值变量组件
+                let f = loopComponentList.filter((item) => item.__config__.ApiReturn && item.__config__.ApiReturn.length && item.__config__.ApiReturn.find((z) => z.varName === i.varType[1]))
+                if (f && f.length) {
+                  let scheme = f[0]
+                  let itemOptions
+                  isTreeSelect ? (itemOptions = scheme.options) : (itemOptions = scheme.__slot__.options)
+                  let selectRow = itemOptions.find((o) => o[scheme.__config__.apiProps.value] === scheme.__config__.defaultValue)
+                  if (selectRow) {
+                    for (const cur of scheme.__config__.ApiReturn) {
+                      // 储存全局变量
+                      sessionStorage.setItem(`API_${cur.varName}`, selectRow[cur.keyName])
+                    }
+                    let s = scheme.__config__.ApiReturn.find((x)=>{return x.varName === i.varType[1]})
+                    formVarObj[i.key] = selectRow[s.keyName]
+                  }
+                }
+              }
               // let obnj = {}
               // //查询当前表单配置API返回值变量的组件
               // let list = loopComponentList

+ 1 - 1
src/components/Generator/components/InputTable/index.vue

@@ -275,7 +275,7 @@ export default {
                 } catch {}
               })
             } else {
-              await getAPIData(cur.__slot__, config.propsUrl, config.ApiParams, this.tableData, '', config.apiProps).then(async (res) => {
+              await getAPIData(cur, config.propsUrl, config.ApiParams, this.tableData, '', config.apiProps).then(async (res) => {
                 await this.$set(cur.__slot__, 'options', res)
               })
             }

+ 1 - 1
src/components/Generator/parser/Parser.vue

@@ -595,7 +595,7 @@ export default {
                 } catch {}
               })
             } else {
-              getAPIData(cur.__slot__, config.propsUrl, config.ApiParams, componentList, '', config.apiProps).then((res) => {
+              getAPIData(cur, config.propsUrl, config.ApiParams, componentList, '', config.apiProps).then((res) => {
                 this.$set(cur.__slot__, 'options', res)
               })
             }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2 - 2
src/utils/request.js