فهرست منبع

fix: 处理统计下value在options还未设置前就填充上

lanjianrong 4 سال پیش
والد
کامیت
2eead27e04
1فایلهای تغییر یافته به همراه10 افزوده شده و 5 حذف شده
  1. 10 5
      src/pages/Statistic/components/OptionSelect.tsx

+ 10 - 5
src/pages/Statistic/components/OptionSelect.tsx

@@ -45,20 +45,24 @@ const OptionSelect: React.FC<OptionSelectProps> = ({ multiple = true, type, onCh
   const { optionType, dataIds } = authOptions?.[type] || {}
 
   const [state, setState] = useState({
+    loading: false,
     optionType: optionType || (multiple ? statisticOptionMap.STAFF : statisticOptionMap.SINGLE_STAFF),
-    dataIds,
+    dataIds: null,
     department: [],
     staff: []
   })
 
   useEffect(() => {
+    setState({ ...state, loading: true })
     const queryStaffAndDepartment = async () => {
       const { code = -1, data: { department = [], staff = [] } = {} } = await queryUsageSelectOptions()
       if (code === consts.RET_CODE.SUCCESS) {
         setState({
           ...state,
           department,
-          staff
+          staff,
+          dataIds,
+          loading: false
         })
       }
     }
@@ -82,7 +86,7 @@ const OptionSelect: React.FC<OptionSelectProps> = ({ multiple = true, type, onCh
 
   const treeOptions = useMemo(() => {
     const base = {
-      className: 'min-w-180px',
+      className: 'min-w-45',
       dropdownMatchSelectWidth: true,
       onChange: value => trySetOpIds(value),
       treeDefaultExpandAll: true,
@@ -96,7 +100,8 @@ const OptionSelect: React.FC<OptionSelectProps> = ({ multiple = true, type, onCh
     if ([statisticOptionMap.STAFF, statisticOptionMap.SINGLE_STAFF].includes(state.optionType)) {
       base.showCheckedStrategy = 'SHOW_PARENT'
 
-      base.treeData = state.optionType === statisticOptionMap.SINGLE_STAFF ? generateTree(state.staff) : state.staff
+      base.treeData =
+        state.optionType === statisticOptionMap.SINGLE_STAFF ? generateTree(state.staff) : state.staff
     }
 
     if ([statisticOptionMap.DEPARTMENT, statisticOptionMap.SINGLE_DEPARTMENT].includes(state.optionType)) {
@@ -122,7 +127,7 @@ const OptionSelect: React.FC<OptionSelectProps> = ({ multiple = true, type, onCh
           onChange={val => setState({ ...state, optionType: val, dataIds: [] })}
         />
       </span>
-      <TreeSelect value={state.dataIds} {...treeOptions} />
+      <TreeSelect value={state.dataIds} {...treeOptions} loading={state.loading} />
     </div>
   )
 }