/*
* @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}`));
标签:prompt,runInAction,模版,改查,mobx,params,res,const,id From: https://www.cnblogs.com/Simoon/p/18367737