Просмотр исходного кода

fix: 修复级联第三极数据在某些情况没有加载

lanjianrong 4 лет назад
Родитель
Сommit
eec4aff234

+ 1 - 1
package.json

@@ -57,7 +57,7 @@
     "@icon-park/react": "^1.3.3",
     "@umijs/route-utils": "^1.0.33",
     "ahooks": "^2.10.0",
-    "antd": "^4.17.3",
+    "antd": "4.18.2",
     "antd-img-crop": "^3.16.0",
     "classnames": "^2.2.6",
     "crypto-js": "^4.0.0",

+ 1 - 0
src/components/LazyCascader/LazyCascader.jsx

@@ -29,6 +29,7 @@ const CLazyCascader = props => {
   )
   const [cValue, setValue] = useState(value || defaultValue)
   useEffect(() => {
+    // console.log('options', options)
     if (!options.length) {
       dispatch({
         type: 'district/fetch'

+ 29 - 13
src/models/district.js

@@ -35,25 +35,41 @@ export default {
       const currProvince = yield select(state =>
         state.district.data.find(item => item.id === provinceId)
       )
+      const currCity = currProvince?.children?.find(item => item.id === cityId)
       // 判断市的数据是否拉取过了
-      if (currProvince && !currProvince.children?.length) {
-        const { code = -1, data = [] } = yield call(queryDistrict, { parentId: provinceId })
-        if (code === consts.RET_CODE.SUCCESS) {
+      if (currProvince) {
+        if (!currCity) {
+          const { code = -1, data = [] } = yield call(queryDistrict, { parentId: provinceId })
+          if (code === consts.RET_CODE.SUCCESS) {
+            const response = yield call(queryDistrict, { parentId: cityId })
+            if (response?.code === consts.RET_CODE.SUCCESS) {
+              const newData = data.map(item => {
+                const newItem = { ...item }
+                if (item.id === cityId) {
+                  newItem.children = response.data
+                }
+                return newItem
+              })
+              yield put({
+                type: 'changeState',
+                payload: {
+                  data: newData,
+                  parentId: provinceId,
+                  level: 1
+                }
+              })
+            }
+          }
+        } else if (currCity && !currCity.children) {
+          // 说明city存在,但是对应的children不存在
           const response = yield call(queryDistrict, { parentId: cityId })
           if (response?.code === consts.RET_CODE.SUCCESS) {
-            const newData = data.map(item => {
-              const newItem = { ...item }
-              if (item.id === cityId) {
-                newItem.children = response.data
-              }
-              return newItem
-            })
             yield put({
               type: 'changeState',
               payload: {
-                data: newData,
-                parentId: provinceId,
-                level: 1
+                data: response.data,
+                parentId: cityId,
+                level: 2
               }
             })
           }

+ 0 - 1
src/pages/Customer/Company/components/CompanyDetail/TabList.jsx

@@ -31,7 +31,6 @@ const CompanyTabList = ({
   business,
   updateKey
 }) => {
-  console.log('111')
   const dispatch = useDispatch()
   const { toggleDrawer, setDrawerProps } = useModal()
   const { TabPane } = Tabs