mobx模版(增删改查)
/*
* @Author: Simoon.jia
* @Date: 2024-04-09 11:06:16
* @LastEditors: Simoon.jia
* @LastEditTime: 2024-07-22 16:59:57
* @Description: 描述
*/
import { observable, action, runInAction } from 'mobx';
import {
fetchDictionaryList,
fetchdeleteDictionary,
fetchCustomerDetail,
fetchUpdateDictionary,
fetchInsertCustomer,
fetchImportCustomer,
fetchCusotmerTypeList,
fetchSignTypeList,
fetchProjectList,
fetchExportFile
} from '../api';
import prompt from '@/utils/prompt';
class EventOrderStore {
@observable loading = false;
@observable dictionaryList = []; //通知规则列表
@observable dictionaryDetailInfo = false; //弹窗信息(显隐)
@observable pageCurrent = {}; //分页
@observable editLoading = { delete: false, update: false }; //loading
// 更新state
@action
updateState = (key, value) => {
runInAction(() => {
this[key] = value;
});
};
//获取列表
@action
getDictionaryList = (params) => {
runInAction(() => {
this.loading = true
})
fetchDictionaryList(params).then((res) => {
runInAction(() => {
if (res?.code === 100000) {
const { total, pages, current, size } = res?.data
this.pageCurrent = {
total: total || 0,
pages: pages || 1,
current: current || 1,
size: size || 20
}
const data = (res?.data?.records || []).map((item) => {
const content = (item?.content || [])?.map(c => c.name).join('、')
return { ...item, content }
});
this.dictionaryList = data || []
} else {
this.dictionaryList = [];
prompt.error(res?.msg || '接口异常');
}
this.loading = false
});
});
};
//根据id删除记录
@action
deleteDictionary = (params, callback) => {
fetchdeleteDictionary(params).then((res) => {
runInAction(() => {
if (res?.code === 100000) {
prompt.success('删除成功');
callback()
} else {
prompt.error(res?.msg || '接口异常');
callback()
}
});
});
};
//根据id获取详情
@action
getDictionaryDetail = (params) => {
fetchCustomerDetail(params).then((res) => {
runInAction(() => {
if (res?.code === 100000) {
this.dictionaryDetailInfo = res?.data || [];
} else {
this.dictionaryDetailInfo = [];
prompt.error(res?.msg || '接口异常');
}
});
});
// runInAction(() => {
// this.dictionaryDetailInfo = {
// id: 'test',
// dictName: '翻斗花园字典',
// dictData: [{ id: 123, dictLabel: '牛壮壮' }, { id: 222, dictLabel: '1' }, { id: 333, dictLabel: '2' }]
// }
// })
};
//更新
@action
updateDictionary = (params, callback) => {
this.editLoading.update = true
fetchUpdateDictionary(params).then((res) => {
runInAction(() => {
this.editLoading.update = false
if (res?.code === 100000) {
prompt.success('更新成功');
callback()
} else {
prompt.error(res?.msg || '接口异常');
}
});
});
};
//新增
@action
insertDictionary = (params, callback) => {
this.editLoading.update = true
fetchInsertCustomer(params).then((res) => {
runInAction(() => {
this.editLoading.update = false
if (res?.code === 100000) {
prompt.success('新增成功');
callback()
} else {
prompt.error(res?.msg || '接口异常');
}
});
});
};
}
export default new EventOrderStore();
附赠api.js模版
import { fetchGet, fetchPost } from '@/utils/fetch';
// 条件查询表格信息
export const fetchDictionaryList = (params) =>
fetchGet('/dict/page/list', { params });
// 查询详情
export const fetchCustomerDetail = (params) =>
fetchGet(`/dict/getDetails/${params?.id}`);
// 更新
export const fetchUpdateDictionary = (params) =>
fetchPost('/dict/update', { body: params });
// 新增
export const fetchInsertCustomer = (params) =>
fetchPost('/dict/add', { body: params });
// 删除
export const fetchdeleteDictionary = (params) =>
fetchGet(`/dict/delete/${params?.id}`));
分类:
mobx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-08-19 Css变量