fix(api):update store

This commit is contained in:
wang_yp 2024-09-19 23:30:29 +08:00
parent 3e877a15b5
commit cc4b544b2e
29 changed files with 205 additions and 225 deletions

View File

@ -1,11 +1,11 @@
import { inject, observer } from "mobx-react"; import { inject, observer } from "mobx-react";
// import Home from "./pages/home/home";
import { Modal } from "antd"; import { Modal } from "antd";
import { Store } from "antd/lib/form/interface"; import { Store } from "antd/lib/form/interface";
import { Outlet } from "react-router"; import { Outlet } from "react-router";
import SimpleForm from "./components/form/simple_form"; import SimpleForm from "./components/form/simple_form";
import { FormInstance } from "antd/lib/form"; import { FormInstance } from "antd/lib/form";
import React from "react"; import React from "react";
import MyComponent from "./components/errorComp";
const App = (props: Store) => { const App = (props: Store) => {
const { usrStore } = props; const { usrStore } = props;
const formRef = React.useRef<FormInstance>(null); const formRef = React.useRef<FormInstance>(null);
@ -34,7 +34,10 @@ const App = (props: Store) => {
const onFinishFailed = () => {}; const onFinishFailed = () => {};
return ( return (
<> <>
<Outlet /> <MyComponent>
<Outlet />
</MyComponent>
<Modal <Modal
title="登录" title="登录"
className="owner_model" className="owner_model"

View File

@ -2,7 +2,7 @@ import React from "react";
interface MyComponentProps { interface MyComponentProps {
hasError?: boolean; hasError?: boolean;
chi?: React.ReactNode; children?: React.ReactNode;
} }
interface MyComponentState { interface MyComponentState {
@ -19,7 +19,7 @@ interface MyComponentProps {
render() { render() {
// 现在你可以安全地访问 this.state.hasError // 现在你可以安全地访问 this.state.hasError
return <div>{this.state.hasError ? 'Error' : this.props.chi}</div>; return <div>{this.state.hasError ? 'Error' : this.props.children}</div>;
} }
} }

View File

@ -13,6 +13,7 @@ export interface SimpleFormData {
subBtnName?: string, subBtnName?: string,
formName: string, formName: string,
colProps: number, colProps: number,
span?: number,
initialValues?: Object | null | undefined, initialValues?: Object | null | undefined,
onFinish: Function, onFinish: Function,
formRef?: React.RefObject<FormInstance<any>>, formRef?: React.RefObject<FormInstance<any>>,

View File

@ -7,7 +7,7 @@ export const FormSelect = (v: FormDatas) => {
const [list, setList] = useState([]); const [list, setList] = useState([]);
useEffect(() => { useEffect(() => {
baseHttp baseHttp
.get(`${v.selectUrl}/?pageSize=100&pageNum=1` ?? "", "") .get(`${v.selectUrl}/?size=100&offset=1` ?? "", "")
.then((res) => { .then((res) => {
setList(res.data.record ?? []); setList(res.data.record ?? []);
}); });

View File

@ -20,8 +20,8 @@ const SimpleForm = (props: SimpleFormData) => {
name={props.formName} name={props.formName}
ref={props.formRef} ref={props.formRef}
form={form} form={form}
labelCol={{ span: 4 }} labelCol={{ span: props.span??4 }}
wrapperCol={{ span: 8 }} wrapperCol={{ span: props.colProps }}
layout="horizontal" layout="horizontal"
initialValues={{ menubar: true }} initialValues={{ menubar: true }}
onFinish={onFinish} onFinish={onFinish}

View File

@ -0,0 +1,40 @@
export const folderConfig = [
{
type: "input",
label: "所属档案分类",
name: "ac_identity",
value: "",
},
{
type: "input",
label: "文件夹名称",
name: "folder_name",
value: "",
},
{
type: "input",
label: "文件夹描述",
name: "folder_desc",
value: "",
},
];
// 档案配置
export const catConfig = [
{
type: "input",
label: "所属档案分类名称",
name: "ac_identity",
value: "",
},
];
// 档案配置
export const archiveConfig = [
{
type: "input",
label: "所属档案分类",
name: "ac_identity",
value: "",
},
];

View File

@ -5,9 +5,9 @@ import { Store } from "antd/lib/form/interface";
import SimpleForm from "@/components/form/simple_form"; import SimpleForm from "@/components/form/simple_form";
import React from "react"; import React from "react";
import FolderTwoTone from "@ant-design/icons/FolderOpenTwoTone"; import FolderTwoTone from "@ant-design/icons/FolderOpenTwoTone";
import { folderConfig, catConfig, archiveConfig } from "./archives_conf";
const Archives = (props: Store) => { const Archives = (props: Store) => {
const { archivesStore } = props; const { folderStore, acStore } = props;
const [isModalOpen, setIsModalOpen] = useState<boolean>(false); const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [projectConfig, setProjectConfig] = useState<any>([]); const [projectConfig, setProjectConfig] = useState<any>([]);
const formRef = React.useRef<FormInstance>(null); const formRef = React.useRef<FormInstance>(null);
@ -17,76 +17,78 @@ const Archives = (props: Store) => {
let data = values; let data = values;
data.head_img = values.head_img[0].url; data.head_img = values.head_img[0].url;
if (!tagId) { if (!tagId) {
archivesStore.add(data); folderStore.add(data);
} else { } else {
archivesStore.putItem(tagId, data); folderStore.putItem(tagId, data);
} }
setIsModalOpen(false); setIsModalOpen(false);
}; };
useEffect(() => { useEffect(() => {
archivesStore.getlist("folder/list"); folderStore.getlist();
}, [archivesStore]); acStore.getlist();
const defaultConfig = [ }, [folderStore, acStore]);
{
type: "input", // 添加事件
label: "所属档案分类", const addHandler = () => {
name: "ac_identity", setProjectConfig(folderConfig);
value: "", setIsModalOpen(true);
}, };
{
type: "input", // 取消
label: "文件夹名称", const cancelHandler = () => {
name: "folder_name", setId(null);
value: "", setIsModalOpen(false);
}, };
{
type: "input", // 文件夹点击
label: "文件夹描述", const folderHandle = () => {};
name: "folder_desc", const addCatHandler = () => {
value: "", setProjectConfig(catConfig);
}, setIsModalOpen(true);
]; };
const addArchivesHandler = () => {
setProjectConfig(archiveConfig);
setIsModalOpen(true);
};
const onFinishFailed = () => {}; const onFinishFailed = () => {};
return ( return (
<div className="contentBox"> <div className="contentBox">
<Space direction="vertical" size="middle" style={{ display: "flex" }}> <Space direction="vertical" size="middle" style={{ display: "flex" }}>
<Space direction="horizontal" size={"middle"}> <Space direction="horizontal" size={"middle"}>
<Button <Button type="default" onClick={addHandler}>
type="default"
onClick={() => { </Button>
setProjectConfig(defaultConfig); <Button type="default" onClick={addCatHandler}>
setId(null);
setIsModalOpen(true); </Button>
}} <Button type="default" onClick={addArchivesHandler}>
>
</Button> </Button>
</Space> </Space>
<Flex wrap gap="25px" justify="start"> <Flex wrap gap="25px" justify="start">
{Array.from({ length: archivesStore.list?.length??0 }, (_, i) => ( {Array.from({ length: folderStore.list?.length ?? 0 }, (_, i) => (
<div key={i}> <div key={i} onClick={folderHandle}>
<FolderTwoTone rotate={-270} style={{ fontSize: "120px" }} /> <FolderTwoTone rotate={-270} style={{ fontSize: "120px" }} />
<p>{archivesStore.list[i].folder_name}</p> <p>{folderStore.list[i].folder_name}</p>
</div> </div>
))} ))}
</Flex> </Flex>
<Modal <Modal
title={!tagId ? "添加文件夹" : "编辑文件夹"} title={!tagId ? "添加文件夹" : "编辑文件夹"}
width={800} width={600}
open={isModalOpen} open={isModalOpen}
afterClose={() => formRef.current?.resetFields()} afterClose={() => formRef.current?.resetFields()}
onOk={() => formRef.current?.submit()} onOk={() => formRef.current?.submit()}
onCancel={() => { onCancel={cancelHandler}
setId(null);
setIsModalOpen(false);
}}
> >
<SimpleForm <SimpleForm
formRef={formRef} formRef={formRef}
createCallback={() => {}} createCallback={() => {}}
formName="card_basic" formName="card_basic"
colProps={4} colProps={12}
span={6}
subBtnName="提交" subBtnName="提交"
formDatas={projectConfig} formDatas={projectConfig}
onFinish={onFinish} onFinish={onFinish}
@ -99,4 +101,6 @@ const Archives = (props: Store) => {
); );
}; };
export default inject("archivesStore")(observer(Archives)); export default inject(...["archivesStore", "folderStore", "acStore"])(
observer(Archives)
);

View File

@ -3,7 +3,6 @@ import { inject, observer } from "mobx-react";
import type { ColumnsType } from "antd/es/table"; import type { ColumnsType } from "antd/es/table";
import BTable from "@/components/b_table"; import BTable from "@/components/b_table";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import UserConfig from "@/service/apiConfig/user_config";
import { UserDataType } from "@/model/userModel"; import { UserDataType } from "@/model/userModel";
import { Store } from "antd/lib/form/interface"; import { Store } from "antd/lib/form/interface";
import SimpleForm from "@/components/form/simple_form"; import SimpleForm from "@/components/form/simple_form";
@ -73,7 +72,7 @@ const Dep = (props: Store) => {
setIsModalOpen(false); setIsModalOpen(false);
}; };
useEffect(() => { useEffect(() => {
depStore.getlist(UserConfig.LIST); depStore.getlist();
}, [depStore]); }, [depStore]);
const defaultConfig = [ const defaultConfig = [
{ {

View File

@ -3,7 +3,6 @@ import { inject, observer } from "mobx-react";
import type { ColumnsType } from "antd/es/table"; import type { ColumnsType } from "antd/es/table";
import BTable from "@/components/b_table"; import BTable from "@/components/b_table";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import UserConfig from "@/service/apiConfig/user_config";
import { UserDataType } from "@/model/userModel"; import { UserDataType } from "@/model/userModel";
import { Store } from "antd/lib/form/interface"; import { Store } from "antd/lib/form/interface";
import SimpleForm from "@/components/form/simple_form"; import SimpleForm from "@/components/form/simple_form";
@ -63,7 +62,7 @@ const Tag = (props: Store) => {
setIsModalOpen(false); setIsModalOpen(false);
}; };
useEffect(() => { useEffect(() => {
tagStore.getlist(UserConfig.LIST); tagStore.getlist();
}, [tagStore]); }, [tagStore]);
const defaultConfig = [ const defaultConfig = [
{ {

View File

@ -3,7 +3,6 @@ import { inject, observer } from "mobx-react";
import type { ColumnsType } from "antd/es/table"; import type { ColumnsType } from "antd/es/table";
import BTable from "@/components/b_table"; import BTable from "@/components/b_table";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import UserConfig from "@/service/apiConfig/user_config";
import { UserDataType } from "@/model/userModel"; import { UserDataType } from "@/model/userModel";
import { Store } from "antd/lib/form/interface"; import { Store } from "antd/lib/form/interface";
import "./user.less"; import "./user.less";
@ -105,7 +104,7 @@ const User = (props: Store) => {
setIsModalOpen(false); setIsModalOpen(false);
}; };
useEffect(() => { useEffect(() => {
usrStore.getlist(UserConfig.LIST); usrStore.getlist();
}, [usrStore]); }, [usrStore]);
const defaultConfig = [ const defaultConfig = [
{ {

View File

@ -1,8 +0,0 @@
class ActiveConfig {
static LIST = "active"
static LISTPo = "active"
static ADD = "active"
static DELETE = "active"
static EDIT = "active"
}
export default ActiveConfig;

View File

@ -1,8 +0,0 @@
class ActivityConfig {
static LIST = "activity/list"
static LISTPo = "activity"
static ADD = "activity"
static DELETE = "activity"
static EDIT = "activity"
}
export default ActivityConfig;

View File

@ -1,7 +0,0 @@
class ActivityTypeConfig {
static LIST = "activityType/list"
static ADD = "activityType"
static DELETE = "activityType"
static EDIT = "activityType"
}
export default ActivityTypeConfig;

View File

@ -1,16 +0,0 @@
class AppConfig {
static LIST = "app/list"
static LISTPo = "app"
static ADD = "app"
static DELETE = "app"
static EDIT = "app"
static XIAOMIAPPPUSH = "app/push/xiaomi/" // 小米推送配置信息
static VIVOAPPPUSH = "app/push/vivo/" // vivo推送配置信息
static OPPOAPPPUSH = "app/push/oppo/" // oppo推送配置信息
static HUAWEIAPPPUSH = "app/push/huawei/" // huawei推送配置信息
static IOSAPPPUSH = "app/push/ios/" // ios推送配置信息
static WechatConfig = "app/wechatConfig/" // 微信配置信息
static ALCONFIG = "app/alConfig/" // 微信配置信息
}
export default AppConfig;

View File

@ -1,25 +0,0 @@
class CardConfig {
static LIST = "card_admin"
static LISTPo = "composition_admin"
static ADD = "card"
static DELETE = "card"
static EDIT = "card"
}
class characterConfig {
static LIST = "character"
static ADD = "character"
static DELETE = "character"
static EDIT = "character"
}
class currentEvenConfig {
static LIST = "currentEvent"
static ADD = "currentEvent"
static DELETE = "currentEvent"
static EDIT = "currentEvent"
}
// eslint-disable-next-line import/no-anonymous-default-export
export default { CardConfig, characterConfig,currentEvenConfig };

View File

@ -1,8 +0,0 @@
class componsitionConfig {
static LIST = "apis/v1/composition_admin"
static ADD = "apis/v1/composition"
static DELETE = "apis/v1/composition"
static EDIT = "apis/v1/composition"
}
export default componsitionConfig;

View File

@ -1,8 +0,0 @@
class DynamicConfig {
static LIST: string = "dynamic/list"
static ADD: string = "dynamic"
static DELETE: string = "dynamic"
static EDIT: string = "dynamic"
}
export default DynamicConfig;

View File

@ -1,8 +0,0 @@
class MerchantsConfig {
static LIST: string = "merchants/list"
static ADD: string = "merchants"
static DELETE: string = "merchants"
static EDIT: string = "merchants"
}
export default MerchantsConfig;

View File

@ -1,8 +0,0 @@
class productUnit {
static LIST: string = "productUnit/list"
static ADD: string = "productUnit"
static DELETE: string = "productUnit"
static EDIT: string = "productUnit"
}
export default productUnit;

View File

@ -1,8 +0,0 @@
class ProjectConfig {
static LIST: string = "project/list"
static ADD: string = "project"
static DELETE: string = "project"
static EDIT: string = "project"
}
export default ProjectConfig;

View File

@ -1,8 +0,0 @@
class ProjectType {
static LIST: string = "productType/list"
static ADD: string = "productType"
static DELETE: string = "productType"
static EDIT: string = "productType"
}
export default ProjectType;

View File

@ -1,7 +0,0 @@
class SystemConfig {
static BannerList: string = "system/banner"
static AddImages: string = "system/image"
static AddBanner: string = "system/banner"
}
export default SystemConfig;

View File

@ -1,9 +0,0 @@
class UserConfig {
static LOGINURI: string = "anth/login"
static LIST: string = "userMgmt/user/list"
static ADD: string = "user"
static DELETE: string = "user"
static EDIT: string = "user"
}
export default UserConfig;

View File

@ -4,7 +4,7 @@ import BaseStore from "./baseStore";
import { TagDataType } from "@/model/userModel"; import { TagDataType } from "@/model/userModel";
class ArchivesConfig { class ArchivesConfig {
static LIST: string = "archives/folder/list" static LIST: string = "archives/list"
static ADD: string = "archives" static ADD: string = "archives"
static DELETE: string = "archives" static DELETE: string = "archives"
static EDIT: string = "archives" static EDIT: string = "archives"
@ -15,7 +15,5 @@ class ArchivesStore extends BaseStore<TagDataType> {
makeObservable(this, {}) makeObservable(this, {})
} }
} }
const archivesStore = new ArchivesStore()
// eslint-disable-next-line import/no-anonymous-default-export export default archivesStore;
export default new ArchivesStore();

View File

@ -0,0 +1,20 @@
import { makeObservable } from "mobx";
// 用户信息
import BaseStore from "./baseStore";
import { TagDataType } from "@/model/userModel";
class ArchivesCategoryConfig {
static LIST: string = "archives/category/list"
static ADD: string = "archives/category"
static DELETE: string = "archives/category"
static EDIT: string = "archives/category"
}
class ArchivesCategoryStore extends BaseStore<TagDataType> {
constructor() {
super(ArchivesCategoryConfig)
makeObservable(this, {})
}
}
const acStore = new ArchivesCategoryStore()
export default acStore;

View File

@ -11,7 +11,7 @@ interface BaseStoreInterface<T> {
total: number total: number
page: Pages page: Pages
setPages(pages: Pages): any setPages(pages: Pages): any
listStatus:boolean | null | undefined listStatus: boolean | null | undefined
} }
class BaseStore<B> implements BaseStoreInterface<B> { class BaseStore<B> implements BaseStoreInterface<B> {
@ -27,15 +27,19 @@ class BaseStore<B> implements BaseStoreInterface<B> {
total: observable, total: observable,
page: observable, page: observable,
add: action, add: action,
listStatus:observable, listStatus: observable,
}) })
this.urlConfig = urlConfig; this.urlConfig = urlConfig;
} }
// 删除 // 删除
async deleteItem(id: number) { async deleteItem(id: number) {
await baseHttp.delete(this.urlConfig.DELETE + "/" + id, {}) try {
this.getlist() await baseHttp.delete(this.urlConfig.DELETE + "/" + id, {})
this.getlist()
} catch (error) {
}
} }
// 分页 // 分页
setPages(page: Pages) { setPages(page: Pages) {
@ -44,42 +48,55 @@ class BaseStore<B> implements BaseStoreInterface<B> {
} }
// 添加 // 添加
async add(param: any) { async add(param: any) {
await baseHttp.post(this.urlConfig.ADD, param) try {
this.getlist(); await baseHttp.post(this.urlConfig.ADD, param)
this.getlist()
} catch (error) {
}
} }
// 更新 // 更新
async putItem(id: string, param: any) { async putItem(id: string, param: any) {
await baseHttp.put(this.urlConfig.EDIT + "/" + id, param) try {
this.getlist() await baseHttp.put(this.urlConfig.EDIT + "/" + id, param)
this.getlist()
} catch (error) {
}
} }
// 获取列表 // 获取列表
async getlist() { async getlist() {
this.listStatus = true; this.listStatus = true;
let res = await baseHttp.get(this.urlConfig.LIST, { try {
size: this.page?.Size | 20, let res = await baseHttp.get(this.urlConfig.LIST, {
offset: this.page?.Offset | 1, size: this.page?.Size | 20,
}); offset: this.page?.Offset | 1,
let data: Array<B> = [] });
if (!res.data.record) { let data: Array<B> = []
if (!res.data.record) {
runInAction(() => {
this.list = data;
})
this.listStatus = false;
return;
}
for (let i = 0; i < res.data.record.length; i++) {
data.push({
key: res.data.record[i].id,
...res.data.record[i]
})
}
runInAction(() => { runInAction(() => {
this.list = data; this.list = data;
this.total = res.data.count
}) })
this.listStatus = false; this.listStatus = false;
return; } catch (error) {
this.listStatus = false;
console.log(error);
} }
for (let i = 0; i < res.data.record.length; i++) {
data.push({
key: res.data.record[i].id,
...res.data.record[i]
})
}
runInAction(() => {
this.list = data;
this.total = res.data.count
})
this.listStatus = false;
} }
list!: Array<B>; list!: Array<B>;
item!: B | null | string item!: B | null | string

20
src/store/folder.ts Normal file
View File

@ -0,0 +1,20 @@
import { makeObservable } from "mobx";
// 用户信息
import BaseStore from "./baseStore";
import { TagDataType } from "@/model/userModel";
class FolderConfig {
static LIST: string = "archives/folder/list"
static ADD: string = "archives/folder"
static DELETE: string = "archives/folder"
static EDIT: string = "archives/folder"
}
class FolderStore extends BaseStore<TagDataType> {
constructor() {
super(FolderConfig)
makeObservable(this, {})
}
}
const folderStore = new FolderStore()
export default folderStore;

View File

@ -2,12 +2,16 @@ import usrStore from '@/store/user'
import tagStore from '@/store/tag' import tagStore from '@/store/tag'
import depStore from '@/store/dep' import depStore from '@/store/dep'
import archivesStore from '@/store/archives' import archivesStore from '@/store/archives'
import folderStore from '@/store/folder';
import acStore from '@/store/archives_category';
const store = { const store = {
usrStore, usrStore,
tagStore, tagStore,
depStore, depStore,
archivesStore archivesStore,
folderStore,
acStore
}; };
export default store; export default store;

View File

@ -1,10 +1,15 @@
import UserConfig from "@/service/apiConfig/user_config";
import { action, computed, makeObservable, observable } from "mobx"; import { action, computed, makeObservable, observable } from "mobx";
// 用户信息 // 用户信息
import baseHttp from "@/service/base"; import baseHttp from "@/service/base";
import BaseStore from "../baseStore"; import BaseStore from "./baseStore";
import { UserDataType, UserInfos } from "@/model/userModel"; import { UserDataType, UserInfos } from "@/model/userModel";
class UserConfig {
static LOGINURI: string = "anth/login"
static LIST: string = "userMgmt/user/list"
static ADD: string = "user"
static DELETE: string = "user"
static EDIT: string = "user"
}
class UserStore extends BaseStore<UserDataType> { class UserStore extends BaseStore<UserDataType> {
_userinfo: UserInfos = {}; // 用户信息 _userinfo: UserInfos = {}; // 用户信息
isNeedLogin: boolean = false; // 是否需要登录 isNeedLogin: boolean = false; // 是否需要登录
@ -49,6 +54,5 @@ class UserStore extends BaseStore<UserDataType> {
this.isNeedLogin = false; this.isNeedLogin = false;
} }
} }
const userStore = new UserStore();
// eslint-disable-next-line import/no-anonymous-default-export export default userStore;
export default new UserStore();