Quellcode durchsuchen

书、书城改store

wjx vor 2 Wochen
Ursprung
Commit
4f3612f145

+ 17 - 16
src/pages/weComTask/components/filterUser/filterUserTooltip.tsx

@@ -3,6 +3,8 @@ import './global.less'
 import { businessPlanData, GENDER_TYPE } from "../../page/businessPlan/create/const"
 import { useAjax } from "@/Hook/useAjax"
 import { getAllBookApi, getBookPlatInfoAllApi } from "../../API/global"
+import weComTaskStore from '@/pages/weComTask/store'
+import { toJS } from 'mobx';
 
 const targetingData = [
     { key: 'msgTagIds', name: '智能标签' },
@@ -147,27 +149,26 @@ export const resetFilterUserData = (data: { [x: string]: any }): ContentProps =>
 const FilterUserTooltip: React.FC<Props> = (props) => {
 
     /**********************/
+    const { bookPlatForm, bookList } = toJS(weComTaskStore.data)
     const { data, configName, bookCityList, configType = 'USER_GROUP' } = props
     const [content, setContent] = useState<ContentProps>({})
 
-    const [bookPlatForm, setBookPlatForm] = useState<{ platformName: string, id: number, platformKey: string }[]>([])
-    const [bookList, setBookList] = useState<{ id: number, bookName: string, platformId: number }[]>([])
-    const getAllBook = useAjax(() => getAllBookApi()) //书
-    const getBookPlatInfoAll = useAjax(() => getBookPlatInfoAllApi()) //书城
+    // const getAllBook = useAjax(() => getAllBookApi()) //书
+    // const getBookPlatInfoAll = useAjax(() => getBookPlatInfoAllApi()) //书城
     /**********************/
 
-    useEffect(() => {
-        if (configType === 'USER_GROUP') {
-            getBookPlatInfoAll.run().then((res) => {
-                if (res?.data) setBookPlatForm(res.data)
-            })
-            getAllBook.run().then(res => {
-                if (res?.data) {
-                    setBookList(res.data)
-                }
-            })
-        }
-    }, [configType])
+    // useEffect(() => {
+    //     if (configType === 'USER_GROUP') {
+    //         getBookPlatInfoAll.run().then((res) => {
+    //             if (res?.data) setBookPlatForm(res.data)
+    //         })
+    //         getAllBook.run().then(res => {
+    //             if (res?.data) {
+    //                 setBookList(res.data)
+    //             }
+    //         })
+    //     }
+    // }, [configType])
 
     useEffect(() => {
         const currentTargetingData = configType === 'GROUP_GROUP' ? targetingGroupData : targetingData

+ 1 - 0
src/pages/weComTask/components/filterUser/index.less

@@ -22,6 +22,7 @@
         overflow: hidden;
         width: 100%;
         box-sizing: border-box;
+        cursor: help;
         background-color: rgba(0, 0, 0, 0.1);
 
         .filterUser_title {

+ 4 - 10
src/pages/weComTask/components/filterUser/index.tsx

@@ -5,10 +5,10 @@ import { PlusOutlined, PlusCircleOutlined, CloseOutlined, EditOutlined } from '@
 import useNewToken from '@/Hook/useNewToken';
 import SelectFilterUser from './selectFilterUser';
 import NewFilterUser from './newFiterUser';
-import { getBookPlatInfoAllApi } from '../../API/global';
-import { useAjax } from '@/Hook/useAjax';
 import dayjs from 'dayjs';
 import FilterUserTooltip from './filterUserTooltip';
+import weComTaskStore from '@/pages/weComTask/store'
+import { toJS } from 'mobx';
 
 interface FilterUserProps {
     configType: BUSINES_SPLAN_API.ConfigTypeProps
@@ -25,21 +25,15 @@ interface FilterUserProps {
 const FilterUser: React.FC<FilterUserProps> = ({ configType = 'USER_GROUP', value, onChange, isSHow }) => {
 
     /****************************************/
+    const { bookPlatForm } = toJS(weComTaskStore.data)
     const { token } = useNewToken()
 
     const [filterUserVisible, setFilterUserVisible] = useState<boolean>(false)
     const [addVisible, setAddVisible] = useState<boolean>(false)
-    const [bookCityList, setBookCityList] = useState<{ label: string, value: string }[]>([])
     const [modifyDta, setModifyDta] = useState<any>()
-
-    const getBookPlatInfoAll = useAjax(() => getBookPlatInfoAllApi())
     /****************************************/
 
-    useEffect(() => {
-        getBookPlatInfoAll.run().then(res => {
-            setBookCityList(res?.data?.map(item => ({ label: item.platformName, value: item.platformKey })))
-        })
-    }, [])
+    const bookCityList = bookPlatForm?.map(item => ({ label: item.platformName, value: item.platformKey }))
 
     return <div className={style.filterUser}>
         <div className={style.filterUser_box} style={isSHow ? { position: 'relative', zIndex: 5 } : {}}>

+ 21 - 20
src/pages/weComTask/components/mindTags/index.tsx

@@ -2,11 +2,10 @@ import { Alert, Checkbox, Input, Spin, Tabs } from 'antd';
 import React, { useEffect, useState } from 'react';
 import './global.less';
 import { businessPlanData } from '../../page/businessPlan/create/const';
-import { useAjax } from '@/Hook/useAjax';
-import { getAllBookApi, getBookPlatInfoAllApi } from '../../API/global';
 import { CheckCircleOutlined } from '@ant-design/icons';
 import useNewToken from '@/Hook/useNewToken';
-
+import weComTaskStore from '@/pages/weComTask/store'
+import { toJS } from 'mobx';
 
 interface Props {
     isSetTag?: boolean
@@ -23,26 +22,27 @@ interface Props {
 const MindTags: React.FC<Props> = ({ value, onChange, id, isSetTag }) => {
 
     /*****************************************/
+    const { bookPlatForm, bookList } = toJS(weComTaskStore.data)
     const { token } = useNewToken()
     const [mindTagValue, setMindTagValue] = useState<{ [x: string]: any }>(value || {})
-    const [books, setBooks] = useState<{ id: number, bookName: string, platformId: number }[]>([])
-    const [oldBooks, setOldBooks] = useState<{ id: number, bookName: string, platformId: number }[]>([])
+    const [books, setBooks] = useState<{ id: number, bookName: string, platformId: number }[]>(bookList || [])
+    const [oldBooks] = useState<{ id: number, bookName: string, platformId: number }[]>(bookList || [])
     const [book, setBook] = useState<string>()
 
-    const getBookPlatInfoAll = useAjax(() => getBookPlatInfoAllApi()) //书城
-    const getAllBook = useAjax(() => getAllBookApi()) //书
+    // const getBookPlatInfoAll = useAjax(() => getBookPlatInfoAllApi()) //书城
+    // const getAllBook = useAjax(() => getAllBookApi()) //书
     /*****************************************/
 
-    useEffect(() => {
-        getBookPlatInfoAll.run()
-        getAllBook.run().then(res => {
-            console.log(res);
-            if (res?.data) {
-                setOldBooks(res.data)
-                setBooks(res.data)
-            }
-        })
-    }, [])
+    // useEffect(() => {
+    //     getBookPlatInfoAll.run()
+    //     getAllBook.run().then(res => {
+    //         console.log(res);
+    //         if (res?.data) {
+    //             setOldBooks(res.data)
+    //             setBooks(res.data)
+    //         }
+    //     })
+    // }, [])
 
     useEffect(() => {
         if (value && JSON.stringify(value) !== JSON.stringify(mindTagValue)) {
@@ -60,7 +60,8 @@ const MindTags: React.FC<Props> = ({ value, onChange, id, isSetTag }) => {
     }, [mindTagValue?.bookCity])
 
     return <div id={id}>
-        <Spin spinning={getBookPlatInfoAll.loading || getAllBook.loading}>
+        {/* <Spin spinning={getBookPlatInfoAll.loading || getAllBook.loading}> */}
+        <Spin spinning={false}>
             <Tabs
                 defaultActiveKey="1"
                 tabPosition='left'
@@ -96,7 +97,7 @@ const MindTags: React.FC<Props> = ({ value, onChange, id, isSetTag }) => {
                                 <Alert message="勾选默认打上模板选择的书城类型" type="warning" />
                             </div>}
                             <div className='mindTags_content_scroll'>
-                                {getBookPlatInfoAll?.data?.data?.map(item => <div key={item.id} style={{ padding: '5px 0' }}>
+                                {bookPlatForm?.map(item => <div key={item.id} style={{ padding: '5px 0' }}>
                                     <Checkbox onChange={(e) => {
                                         const newValue = { ...mindTagValue, bookCity: item.id, product: e.target.checked ? undefined : mindTagValue?.product }
                                         if (!e.target.checked) {
@@ -151,4 +152,4 @@ const MindTags: React.FC<Props> = ({ value, onChange, id, isSetTag }) => {
     </div>
 };
 
-export default MindTags;
+export default React.memo(MindTags);

+ 3 - 1
src/pages/weComTask/entry/index.tsx

@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client';
 import reportWebVitals from '../../../reportWebVitals';
 import { Provider, observer, useLocalObservable } from "mobx-react";
 import globaStore from '@/store'
+import weComTaskStore from '@/pages/weComTask/store'
 import MainLayout from "@/layout";
 import { toJS } from "mobx";
 import '../../../global.less'
@@ -13,9 +14,10 @@ import { LoadingOutlined } from '@ant-design/icons'
 
 const Main = observer(() => {
 
-    const store = useLocalObservable(() => ({ globaStore }))
+    const store = useLocalObservable(() => ({ globaStore, weComTaskStore }))
     useEffect(() => {
         store.globaStore.userInit()//初始化用户信息
+        store.weComTaskStore.init()
     }, [])
     
     const menus = toJS(store.globaStore.data.menus)

+ 3 - 14
src/pages/weComTask/page/businessPlan/create/index.tsx

@@ -5,7 +5,6 @@ import { App, Button, Card, Empty, Input, Popconfirm, Select, Space, Spin, Table
 import MassSending from './components/massSending';
 import { useAjax } from '@/Hook/useAjax';
 import { MediaContentProps, welcomeMsgJobTypeApi } from '@/pages/weComTask/API/weMaterial/weMaterial';
-import { getAllBookApi, getBookPlatInfoAllApi } from '@/pages/weComTask/API/global';
 import SelectCorpUser from '../../corpUserManage/selectCorpUser';
 import { SearchOutlined, PlusOutlined, RedoOutlined, SaveOutlined, CheckOutlined } from '@ant-design/icons';
 import { getGroupData, getHighGroupData, getUserInDataData } from './const';
@@ -17,6 +16,7 @@ import SelectExternalAccount from '@/pages/weComTask/components/selectExternalAc
 import Welcome from './components/welcome';
 import UserInherit from './components/userInherit';
 import HighMassSending from './components/highMassSending';
+import { toJS } from 'mobx';
 
 export const DispatchTaskCreate = React.createContext<TASK_CREATE.DispatchTaskCreate | null>(null);
 /**
@@ -24,25 +24,22 @@ export const DispatchTaskCreate = React.createContext<TASK_CREATE.DispatchTaskCr
  * @param props 
  * @returns 
  */
-const Create: React.FC<any> = (props: { weGlobaStore: any }) => {
+const Create: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE.BookListProps[], bookPlatForm: TASK_CREATE.BookPlatFormProps[] } } }> = ({ weComTaskStore }) => {
 
     /***********************************************/
     const navigate = useNavigate();
+    const { bookList, bookPlatForm } = toJS(weComTaskStore.data)
 
     const [settings, setSettings] = useState<TASK_CREATE.SettingsProps>();
 
     console.log(settings)
     const { message, modal } = App.useApp()
-    const [bookPlatForm, setBookPlatForm] = useState<{ platformName: string, id: number, platformKey: string }[]>([])
-    const [bookList, setBookList] = useState<{ id: number, bookName: string, platformId: number }[]>([])
     const [msgJobTypeList, setMsgJobTypeList] = useState<{ value: string, label: string }[]>([])
     const [previewData, setPreviewData] = useState<TASK_CREATE.previewDataProps>({})
     const [subVisible, setSubVisible] = useState<boolean>(false) // 选择设置名称弹窗控制
     const [eaVisible, setEaVisible] = useState<boolean>(false)
 
-    const getAllBook = useAjax(() => getAllBookApi()) //书
     const welcomeMsgJobType = useAjax(() => welcomeMsgJobTypeApi())//获取欢迎语类型
-    const getBookPlatInfoAll = useAjax(() => getBookPlatInfoAllApi()) //书城
 
     const addTask = useAjax((params) => addTaskApi(params))
     /***********************************************/
@@ -55,14 +52,6 @@ const Create: React.FC<any> = (props: { weGlobaStore: any }) => {
     }, [])
 
     useEffect(() => {
-        getBookPlatInfoAll.run().then((res) => {
-            if (res?.data) setBookPlatForm(res.data)
-        })
-        getAllBook.run().then(res => {
-            if (res?.data) {
-                setBookList(res.data)
-            }
-        })
         welcomeMsgJobType.run().then(res => {
             if (res?.data) {
                 setMsgJobTypeList(Object.keys(res.data).map(key => ({ value: key, label: res.data[key] })))

+ 13 - 21
src/pages/weComTask/page/businessPlan/create/typings.d.ts

@@ -7,19 +7,13 @@ declare namespace TASK_CREATE {
         visible?: boolean;
         onClose?: () => void;
     }
+    type BookPlatFormProps = { platformName: string, id: number, platformKey: string }
+    type BookListProps = { id: number, bookName: string, platformId: number }
     interface DispatchTaskCreate {
         settings: TASK_CREATE.SettingsProps
         setSettings: React.Dispatch<React.SetStateAction<TASK_CREATE.SettingsProps>>
-        bookPlatForm: {
-            platformName: string;
-            id: number;
-            platformKey: string;
-        }[]
-        bookList: {
-            id: number;
-            bookName: string;
-            platformId: number;
-        }[]
+        bookPlatForm: BookPlatFormProps[]
+        bookList: BookListProps[]
         msgJobTypeList: {
             value: string;
             label: string;
@@ -54,14 +48,14 @@ declare namespace TASK_CREATE {
     interface UserInheritProps<T> extends DefaultProps, DefaultChangeProps<T> {
         value?: { [x: string]: any };
     }
-    interface corpUsersProps { 
-        corpUserId: string, 
-        name: string, 
-        corpName: string, 
-        corpId: string, 
-        welcomeMsgContent?: any[], 
-        groupMsgContent?: any[], 
-        highGroupMsgContent?: any[], 
+    interface corpUsersProps {
+        corpUserId: string,
+        name: string,
+        corpName: string,
+        corpId: string,
+        welcomeMsgContent?: any[],
+        groupMsgContent?: any[],
+        highGroupMsgContent?: any[],
         externalUserTransferContent?: any[],
         externalUserList?: any[]
     }
@@ -175,11 +169,9 @@ declare namespace TASK_CREATE {
     type CorpListProps = {
         corpId: string, corpName: string, weList: { corpUserId: string, name: string }[]
     }
-    type BookPlatFormProps = { platformName: string, id: number, platformKey: string }
-    type BookListProps = { id: number, bookName: string, platformId: number }
+
     interface DispatchTaskDetails {
         bookPlatForm: BookPlatFormProps[]
         bookList: BookListProps[]
-        corpList: CorpListProps[]
     }
 }

+ 0 - 5
src/pages/weComTask/page/businessPlan/taskList/components/highGroupTask/index.tsx

@@ -6,15 +6,11 @@ import { QuestionCircleFilled } from '@ant-design/icons';
 import PreviewTime from '@/pages/weComTask/components/previewTime';
 import FilterUserTooltip from '@/pages/weComTask/components/filterUser/filterUserTooltip';
 import LookMsg from '@/pages/weComTask/components/previewMsg/lookMsg';
-import useNewToken from '@/Hook/useNewToken';
 import GroupXfCorpTabls from './highGroupXfCorpTabls';
 import GroupTaskNotes from './highGroupTaskNotes';
-import { getMsgData } from '../../../create/components/massSending/showContent';
 import { DispatchTaskDetails } from '../../log';
 const { Text } = Typography;
 
-
-
 interface Props {
     groupSendTaskVOList: { [x: string]: any }[]
 }
@@ -180,7 +176,6 @@ export const ExpandedRow: React.FC<{ record: any }> = ({ record }) => {
 
     const { contentDTO, id, corpId } = record
     const [activeKey, setActiveKey] = useState<string>('2')
-    const { corpList } = useContext(DispatchTaskDetails)!;
 
     const data = contentDTO.map(item2 => {
         const { msgType, ...content } = item2

+ 5 - 37
src/pages/weComTask/page/businessPlan/taskList/index.tsx

@@ -5,46 +5,26 @@ import React, { useEffect, useState } from 'react';
 import taskListColumns from './tableConfig';
 import dayjs from 'dayjs';
 import { SearchOutlined } from '@ant-design/icons';
-import { api_corpUser_allOfUser, getAllBookApi, getBookPlatInfoAllApi } from '@/pages/weComTask/API/global';
 import Log from './log';
+import { inject, observer } from 'mobx-react';
+import { toJS } from 'mobx';
 
 /**
  * 任务列表
  * @returns 
  */
-const TaskList: React.FC = () => {
+const TaskList: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE.BookListProps[], bookPlatForm: TASK_CREATE.BookPlatFormProps[] } } }> = ({ weComTaskStore }) => {
 
     /***********************************************/
     const projectName = sessionStorage.getItem('CAMPCORP')
+    const { bookList, bookPlatForm } = toJS(weComTaskStore.data)
     const [queryForm, setQueryForm] = useState<BUSINES_SPLAN_API.GetProjectListProps>({ pageNum: 1, pageSize: 20, projectName })
     const [queryFormNew, setQueryFormNew] = useState<BUSINES_SPLAN_API.GetProjectListProps>({ pageNum: 1, pageSize: 20, projectName })
-    const [bookPlatForm, setBookPlatForm] = useState<TASK_CREATE.BookPlatFormProps[]>([])
-    const [bookList, setBookList] = useState<TASK_CREATE.BookListProps[]>([])
     const [logOpenData, setLogOpenData] = useState<{ visible: boolean, data: any }>({ visible: false, data: {} })
-    const [corpList, setCorpList] = useState<TASK_CREATE.CorpListProps[]>([])
 
-    const getAllBook = useAjax(() => getAllBookApi()) //书
-    const getBookPlatInfoAll = useAjax(() => getBookPlatInfoAllApi()) //书城
     const getProjectList = useAjax((params) => getProjectListApi(params))
-    const corpUser_allOfUser = useAjax((params) => api_corpUser_allOfUser(params))
     /***********************************************/
 
-    /** 人的企业 */
-    useEffect(() => {
-        if (sessionStorage.getItem('userId')) {
-            corpUser_allOfUser.run(sessionStorage.getItem('userId')).then(res => {
-                if (res?.data) {
-                    setCorpList(res?.data?.map((item: { t1: { corpId: any; corpName: any; }; t2: any; }) => ({
-                        ...item.t1,
-                        value: item.t1.corpId,
-                        label: item.t1.corpName,
-                        weList: item.t2
-                    })))
-                }
-            })
-        }
-    }, [])
-
     useEffect(() => {
         const projectName = sessionStorage.getItem('CAMPCORP')
         if (projectName) {
@@ -52,17 +32,6 @@ const TaskList: React.FC = () => {
         }
     }, [])
 
-    useEffect(() => {
-        getBookPlatInfoAll.run().then((res) => {
-            if (res?.data) setBookPlatForm(res.data)
-        })
-        getAllBook.run().then(res => {
-            if (res?.data) {
-                setBookList(res.data)
-            }
-        })
-    }, [])
-
     useEffect(() => {
         getProjectList.run(queryFormNew)
     }, [queryFormNew])
@@ -125,7 +94,6 @@ const TaskList: React.FC = () => {
         {/* 日志 */}
         {logOpenData.visible && <Log
             {...logOpenData}
-            corpList={corpList}
             bookPlatForm={bookPlatForm}
             bookList={bookList}
             onClose={() => {
@@ -135,4 +103,4 @@ const TaskList: React.FC = () => {
     </Card>
 };
 
-export default TaskList;
+export default inject('store')(observer((props: any) => TaskList(props.store)));

+ 2 - 3
src/pages/weComTask/page/businessPlan/taskList/log.tsx

@@ -12,7 +12,6 @@ interface Props {
     data: any,
     bookPlatForm: TASK_CREATE.BookPlatFormProps[]
     bookList: TASK_CREATE.BookListProps[]
-    corpList: TASK_CREATE.CorpListProps[]
     visible?: boolean,
     onClose?: () => void,
 }
@@ -23,7 +22,7 @@ export const DispatchTaskDetails = React.createContext<TASK_CREATE.DispatchTaskD
  * @param param0 
  * @returns 
  */
-const Log: React.FC<Props> = ({ data, bookPlatForm, bookList, corpList, visible, onClose }) => {
+const Log: React.FC<Props> = ({ data, bookPlatForm, bookList, visible, onClose }) => {
 
     /******************************************************/
     const [previewData, setPreviewData] = useState<{ welcomeMsgTemplateVO?: any, groupSendTaskVOList?: any[], externalUserTransferTasksVOList?: any[] }>({})
@@ -49,7 +48,7 @@ const Log: React.FC<Props> = ({ data, bookPlatForm, bookList, corpList, visible,
 
         <Spin spinning={getProjectLogList.loading}>
             <DispatchTaskDetails.Provider
-                value={{ bookPlatForm, bookList, corpList }}
+                value={{ bookPlatForm, bookList }}
             >
                 <Tabs
                     items={Object.keys(previewData).filter(key => key === 'welcomeMsgTemplateVO' ? previewData[key] : previewData[key]?.length).map(key => ({

+ 34 - 0
src/pages/weComTask/store/index.ts

@@ -0,0 +1,34 @@
+import { observable, runInAction } from "mobx";
+import { getAllBookApi, getBookPlatInfoAllApi } from "../API/global";
+/**
+ * 全局需要的搜索条件列表
+ * */
+const weComTaskStore: {
+  data: {
+    // 书
+    bookList: TASK_CREATE.BookListProps[];
+    // 书城
+    bookPlatForm: TASK_CREATE.BookPlatFormProps[];
+  };
+  /**初始化操作*/
+  init(): Promise<void>;
+} = {
+  data: {
+    bookList: [],
+    bookPlatForm: []
+  },
+  /**初始化操作*/
+  async init() {
+    const bookPlatForm = await getBookPlatInfoAllApi();
+    const book = await getAllBookApi();
+    runInAction(() => {
+      this.data = {
+        ...this.data,
+        bookList: book?.data || [],
+        bookPlatForm: bookPlatForm?.data || [],
+      };
+    });
+  },
+  
+};
+export default observable(weComTaskStore);