| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import {
- addPlanFile,
- addPlanItem,
- deletePlanItem,
- editPlanItem,
- getPlanItem,
- getPlanList,
- GetPlanListParams,
- PlanFilePatams,
- PlanItemDetail,
- PlanItemParams,
- PlanListResponse,
- } from '@/api/plan';
- import { ElMessage } from 'element-plus';
- import { defineStore } from 'pinia';
- export interface IncidentStateType {
- plans: PlanListResponse;
- planItemDetail: PlanItemDetail;
- loading: boolean;
- }
- export interface IncidentActionsType {
- toggleLoading(): void;
- getPlanList(params: GetPlanListParams): void;
- getPlanItem(id: string): void;
- addPlanItem(params: PlanItemParams): Promise<boolean>;
- editPlanItem(params: PlanItemParams): Promise<boolean>;
- deletePlanItem(id: string): Promise<boolean>;
- addPlanFile(params: PlanFilePatams): Promise<boolean>;
- }
- export default defineStore<'plan', IncidentStateType, {}, IncidentActionsType>(
- 'plan',
- {
- state: () => ({
- plans: {
- rows: [],
- total: 0,
- },
- planItemDetail: {},
- loading: false,
- }),
- actions: {
- toggleLoading() {
- this.loading = !this.loading;
- },
- async getPlanList(params) {
- try {
- this.toggleLoading();
- this.plans = await getPlanList(params);
- } finally {
- this.toggleLoading();
- }
- },
- async getPlanItem(id) {
- try {
- this.toggleLoading();
- const { data } = await getPlanItem(id);
- if (data) this.planItemDetail = data;
- } finally {
- this.toggleLoading();
- }
- },
- async addPlanItem(id) {
- try {
- this.toggleLoading();
- await addPlanItem(id);
- ElMessage.success({ message: '保存成功' });
- return true;
- } finally {
- this.toggleLoading();
- }
- },
- async editPlanItem(params) {
- try {
- this.toggleLoading();
- await editPlanItem(params);
- ElMessage.success({ message: '修改成功' });
- return true;
- } catch {
- ElMessage.error({ message: '修改失败' });
- return false;
- } finally {
- this.toggleLoading();
- }
- },
- async deletePlanItem(params) {
- try {
- this.toggleLoading();
- await deletePlanItem(params);
- ElMessage.success({ message: '删除成功' });
- return true;
- } catch {
- ElMessage.error({ message: '删除失败' });
- return false;
- } finally {
- this.toggleLoading();
- }
- },
- async addPlanFile(id) {
- try {
- await addPlanFile(id);
- ElMessage.success({ message: '导入成功' });
- return true;
- } finally {
- }
- },
- },
- },
- );
|