feat: 更新物料管理模块功能
1. 新增采购计划草稿存储功能 2. 优化出入库单和备件管理界面 3. 完善表单验证和交互逻辑 4. 调整表格列对齐方式 5. 移除冗余的审批备注字段 ps:出入口页面未完成
This commit is contained in:
80
src/store/modules/procurementDraft.ts
Normal file
80
src/store/modules/procurementDraft.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import $cache from '@/plugins/cache';
|
||||
|
||||
// 草稿数据类型
|
||||
export interface ProcurementDraft {
|
||||
id: string;
|
||||
draftNumber: string;
|
||||
planName: string;
|
||||
saveTime: string;
|
||||
content: any;
|
||||
}
|
||||
|
||||
// 保存草稿到本地存储
|
||||
const saveDraftsToStorage = (drafts: ProcurementDraft[]) => {
|
||||
$cache.local.setJSON('procurementDrafts', drafts);
|
||||
};
|
||||
|
||||
// 从本地存储获取草稿
|
||||
const getDraftsFromStorage = (): ProcurementDraft[] => {
|
||||
const stored = $cache.local.getJSON('procurementDrafts');
|
||||
return stored && Array.isArray(stored) ? stored : [];
|
||||
};
|
||||
|
||||
export const useProcurementDraftStore = defineStore('procurementDraft', () => {
|
||||
const draftList = ref<ProcurementDraft[]>(getDraftsFromStorage());
|
||||
|
||||
// 保存草稿
|
||||
const saveDraft = (planName: string, content: any): ProcurementDraft => {
|
||||
const today = new Date();
|
||||
const dateStr = today.getFullYear() + '-' +
|
||||
String(today.getMonth() + 1).padStart(2, '0') + '-' +
|
||||
String(today.getDate()).padStart(2, '0');
|
||||
const randomNum = Math.floor(100 + Math.random() * 900);
|
||||
const draftNumber = `DRAFT-${dateStr}-${randomNum}`;
|
||||
|
||||
const newDraft: ProcurementDraft = {
|
||||
id: `draft_${Date.now()}_${randomNum}`,
|
||||
draftNumber,
|
||||
planName,
|
||||
saveTime: new Date().toLocaleString(),
|
||||
content: JSON.parse(JSON.stringify(content)) // 深拷贝内容
|
||||
};
|
||||
|
||||
// 添加到草稿列表并保存到本地存储
|
||||
draftList.value.unshift(newDraft);
|
||||
saveDraftsToStorage(draftList.value);
|
||||
|
||||
return newDraft;
|
||||
};
|
||||
|
||||
// 获取草稿列表
|
||||
const getDraftList = (): ProcurementDraft[] => {
|
||||
return draftList.value;
|
||||
};
|
||||
|
||||
// 获取单个草稿
|
||||
const getDraft = (draftId: string): ProcurementDraft | undefined => {
|
||||
return draftList.value.find(draft => draft.id === draftId);
|
||||
};
|
||||
|
||||
// 删除草稿
|
||||
const deleteDraft = (draftId: string): boolean => {
|
||||
const index = draftList.value.findIndex(draft => draft.id === draftId);
|
||||
if (index !== -1) {
|
||||
draftList.value.splice(index, 1);
|
||||
saveDraftsToStorage(draftList.value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
draftList,
|
||||
saveDraft,
|
||||
getDraftList,
|
||||
getDraft,
|
||||
deleteDraft
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user