|
@@ -1,7 +1,13 @@
|
|
|
import type { CreateCrudOptionsRet, CreateCrudOptionsProps } from '@fast-crud/fast-crud';
|
|
|
+import type { FsUploaderFormRequestOptions } from '@fast-crud/fast-extends';
|
|
|
import dayjs from 'dayjs';
|
|
|
import { dict } from '@fast-crud/fast-crud';
|
|
|
-import { getArchives, getFile } from './api';
|
|
|
+import axios from 'axios';
|
|
|
+import { getServiceEnvConfig } from '~/.env-config';
|
|
|
+import type { AddArchivesParams } from './api';
|
|
|
+import { getArchives, getFile, addArchives, deleteArchives } from './api';
|
|
|
+const { url, proxyPattern } = getServiceEnvConfig(import.meta.env);
|
|
|
+const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'Y';
|
|
|
export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
|
|
return {
|
|
|
crudOptions: {
|
|
@@ -14,21 +20,41 @@ export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsPro
|
|
|
const { data } = await getArchives(query);
|
|
|
return { records: data, total: 0, currentPage: page.offset, pageSize: page.limit };
|
|
|
},
|
|
|
- addRequest: () => {
|
|
|
- return Promise.resolve(true);
|
|
|
+ addRequest: ({ form }) => {
|
|
|
+ if (!crudOptionsProps.context) {
|
|
|
+ return Promise.resolve(true);
|
|
|
+ }
|
|
|
+ if (!crudOptionsProps.context.studentNumber) {
|
|
|
+ crudOptionsProps.context.message.info('没有筛选人员的情况下 , 不允许上传档案!');
|
|
|
+ throw new Error('没有筛选人员的情况下 , 不允许上传档案');
|
|
|
+ }
|
|
|
+ return addArchives({
|
|
|
+ studentNumber: form.studentNumber,
|
|
|
+ filePath: form.filePath,
|
|
|
+ remarks: form.remarks,
|
|
|
+ filetype: form.filetype
|
|
|
+ });
|
|
|
},
|
|
|
editRequest: () => {
|
|
|
return Promise.resolve(true);
|
|
|
},
|
|
|
- delRequest: () => {
|
|
|
- return Promise.resolve(true);
|
|
|
+ delRequest: (ctx: { row: AddArchivesParams }) => {
|
|
|
+ const { row } = ctx;
|
|
|
+ if (!crudOptionsProps.context || !row.id) {
|
|
|
+ return Promise.resolve(true);
|
|
|
+ }
|
|
|
+ if (row.filetype === 'attendance' || row.filetype === 'scores' || row.filetype === 'prefile') {
|
|
|
+ crudOptionsProps.context.message.info('基础信息自动生成, 不能删除或者编辑!');
|
|
|
+ return Promise.resolve(true);
|
|
|
+ }
|
|
|
+ return deleteArchives(row.id);
|
|
|
}
|
|
|
},
|
|
|
rowHandle: {
|
|
|
show: true,
|
|
|
buttons: {
|
|
|
remove: {
|
|
|
- show: false
|
|
|
+ show: true
|
|
|
},
|
|
|
edit: {
|
|
|
show: false
|
|
@@ -58,7 +84,29 @@ export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsPro
|
|
|
show: false
|
|
|
},
|
|
|
actionbar: {
|
|
|
- show: false
|
|
|
+ show: true
|
|
|
+ },
|
|
|
+ form: {
|
|
|
+ wrapper: {
|
|
|
+ draggable: false,
|
|
|
+ onOpen: () => {
|
|
|
+ if (!crudOptionsProps.context) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!crudOptionsProps.context.studentNumber) {
|
|
|
+ crudOptionsProps.context.message.info('没有筛选人员的情况下 , 不允许上传档案!');
|
|
|
+ throw new Error('没有筛选人员的情况下 , 不允许上传档案');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onOpened: async context => {
|
|
|
+ if (crudOptionsProps.context) {
|
|
|
+ crudOptionsProps.context.archivesForm = context.form;
|
|
|
+ }
|
|
|
+ if (!context.form.studentNumber) {
|
|
|
+ context.form.studentNumber = crudOptionsProps.context?.studentNumber;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
search: {
|
|
|
show: false
|
|
@@ -82,6 +130,9 @@ export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsPro
|
|
|
type: 'text',
|
|
|
column: {
|
|
|
align: 'center'
|
|
|
+ },
|
|
|
+ form: {
|
|
|
+ show: false
|
|
|
}
|
|
|
},
|
|
|
filetype: {
|
|
@@ -90,13 +141,55 @@ export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsPro
|
|
|
dict: dict({
|
|
|
data: [
|
|
|
{ value: 'avatar', label: '头像' },
|
|
|
- { value: 'prefile', label: '个人资料' },
|
|
|
- { value: 'scores', label: '考核' },
|
|
|
- { value: 'attendance', label: '出勤' },
|
|
|
+ { value: 'prefile', disabled: true, label: '个人资料' },
|
|
|
+ { value: 'scores', disabled: true, label: '考核' },
|
|
|
+ { value: 'attendance', disabled: true, label: '出勤' },
|
|
|
{ value: 'other', label: '其他' }
|
|
|
]
|
|
|
})
|
|
|
},
|
|
|
+ filePath: {
|
|
|
+ title: '档案文件',
|
|
|
+ type: 'file-uploader',
|
|
|
+ form: {
|
|
|
+ component: {
|
|
|
+ limit: 1,
|
|
|
+ uploader: {
|
|
|
+ uploadRequest: async (props: FsUploaderFormRequestOptions) => {
|
|
|
+ if (!crudOptionsProps.context) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!crudOptionsProps.context.archivesForm.filetype) {
|
|
|
+ crudOptionsProps.context.message.info('请先选择类别, 在上传档案!');
|
|
|
+ throw new Error('请先选择类别, 在上传档案!');
|
|
|
+ }
|
|
|
+ const action = isHttpProxy
|
|
|
+ ? `${proxyPattern}/student/upload?fileType`
|
|
|
+ : `${url}/student/upload?fileType`;
|
|
|
+ const { file, onProgress } = props;
|
|
|
+ const data = new FormData();
|
|
|
+ data.append('file', file);
|
|
|
+ data.append('fileType', crudOptionsProps.context.archivesForm.filetype);
|
|
|
+ data.append('studentNumber', crudOptionsProps.context.archivesForm.studentNumber);
|
|
|
+ const res = await axios.post(action, data, {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'multipart/form-data'
|
|
|
+ },
|
|
|
+ timeout: 60000,
|
|
|
+ onUploadProgress(progress) {
|
|
|
+ onProgress({ percent: Math.round((progress.loaded / progress.total!) * 100) });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 上传完成后的结果,一般返回个url 或者key,具体看你的后台返回啥
|
|
|
+ return res.data.data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ column: {
|
|
|
+ show: false
|
|
|
+ }
|
|
|
+ },
|
|
|
remarks: {
|
|
|
title: '备注',
|
|
|
type: 'text',
|