提交 c2eb20d8 authored 作者: leon's avatar leon

文件上传修改。医院新增

上级 491924b2
...@@ -16,7 +16,7 @@ VITE_DROP_CONSOLE=false ...@@ -16,7 +16,7 @@ VITE_DROP_CONSOLE=false
VITE_GLOB_API_URL=http://192.168.101.69:8087 VITE_GLOB_API_URL=http://192.168.101.69:8087
# File upload address, optional # File upload address, optional
VITE_GLOB_UPLOAD_URL=/upload VITE_GLOB_UPLOAD_URL=http://192.168.101.69:8087/v1/sys/upload
# Interface prefix # Interface prefix
VITE_GLOB_API_URL_PREFIX= VITE_GLOB_API_URL_PREFIX=
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';
import { getAppEnvConfig } from '/@/utils/env';
const { VITE_GLOB_UPLOAD_URL } = getAppEnvConfig();
/**
* 上传
*/
export const upload = (params: UploadFileParams) => defHttp.uploadFile({ url: VITE_GLOB_UPLOAD_URL }, params);
...@@ -14,12 +14,7 @@ ...@@ -14,12 +14,7 @@
:cancelButtonProps="{ disabled: isUploadingRef }" :cancelButtonProps="{ disabled: isUploadingRef }"
> >
<template #centerFooter> <template #centerFooter>
<a-button <a-button @click="handleStartUpload" color="success" :disabled="!getIsSelectFile" :loading="isUploadingRef">
@click="handleStartUpload"
color="success"
:disabled="!getIsSelectFile"
:loading="isUploadingRef"
>
{{ getUploadBtnText }} {{ getUploadBtnText }}
</a-button> </a-button>
</template> </template>
...@@ -57,10 +52,9 @@ ...@@ -57,10 +52,9 @@
// utils // utils
import { checkImgType, getBase64WithFile } from './helper'; import { checkImgType, getBase64WithFile } from './helper';
import { buildUUID } from '/@/utils/uuid'; import { buildUUID } from '/@/utils/uuid';
import { isFunction } from '/@/utils/is';
import { warn } from '/@/utils/log';
import FileList from './FileList.vue'; import FileList from './FileList.vue';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { upload } from '/@/api/system/upload';
export default defineComponent({ export default defineComponent({
components: { BasicModal, Upload, Alert, FileList }, components: { BasicModal, Upload, Alert, FileList },
...@@ -96,24 +90,19 @@ ...@@ -96,24 +90,19 @@
const getIsSelectFile = computed(() => { const getIsSelectFile = computed(() => {
return ( return (
fileListRef.value.length > 0 && fileListRef.value.length > 0 && !fileListRef.value.every((item) => item.status === UploadResultStatus.SUCCESS)
!fileListRef.value.every((item) => item.status === UploadResultStatus.SUCCESS)
); );
}); });
const getOkButtonProps = computed(() => { const getOkButtonProps = computed(() => {
const someSuccess = fileListRef.value.some( const someSuccess = fileListRef.value.some((item) => item.status === UploadResultStatus.SUCCESS);
(item) => item.status === UploadResultStatus.SUCCESS,
);
return { return {
disabled: isUploadingRef.value || fileListRef.value.length === 0 || !someSuccess, disabled: isUploadingRef.value || fileListRef.value.length === 0 || !someSuccess,
}; };
}); });
const getUploadBtnText = computed(() => { const getUploadBtnText = computed(() => {
const someError = fileListRef.value.some( const someError = fileListRef.value.some((item) => item.status === UploadResultStatus.ERROR);
(item) => item.status === UploadResultStatus.ERROR,
);
return isUploadingRef.value return isUploadingRef.value
? t('component.upload.uploading') ? t('component.upload.uploading')
: someError : someError
...@@ -174,26 +163,21 @@ ...@@ -174,26 +163,21 @@
// } // }
async function uploadApiByItem(item: FileItem) { async function uploadApiByItem(item: FileItem) {
const { api } = props;
if (!api || !isFunction(api)) {
return warn('upload api must exist and be a function');
}
try { try {
const uploadApi = props.api || upload;
item.status = UploadResultStatus.UPLOADING; item.status = UploadResultStatus.UPLOADING;
const { data } = await props.api?.( const { data } = await uploadApi({
{
data: { data: {
...(props.uploadParams || {}), ...(props.uploadParams || {}),
}, },
file: item.file, file: item.file,
name: props.name, name: props.name,
filename: props.filename, filename: props.filename,
}, });
function onUploadProgress(progressEvent: ProgressEvent) { if (!data || data.code !== 0) {
const complete = ((progressEvent.loaded / progressEvent.total) * 100) | 0; throw new Error('上传失败' + data?.message);
item.percent = complete; }
}, item.percent = 100;
);
item.status = UploadResultStatus.SUCCESS; item.status = UploadResultStatus.SUCCESS;
item.responseData = data; item.responseData = data;
return { return {
...@@ -219,8 +203,7 @@ ...@@ -219,8 +203,7 @@
try { try {
isUploadingRef.value = true; isUploadingRef.value = true;
// 只上传不是成功状态的 // 只上传不是成功状态的
const uploadFileList = const uploadFileList = fileListRef.value.filter((item) => item.status !== UploadResultStatus.SUCCESS) || [];
fileListRef.value.filter((item) => item.status !== UploadResultStatus.SUCCESS) || [];
const data = await Promise.all( const data = await Promise.all(
uploadFileList.map((item) => { uploadFileList.map((item) => {
return uploadApiByItem(item); return uploadApiByItem(item);
...@@ -251,7 +234,7 @@ ...@@ -251,7 +234,7 @@
for (const item of fileListRef.value) { for (const item of fileListRef.value) {
const { status, responseData } = item; const { status, responseData } = item;
if (status === UploadResultStatus.SUCCESS && responseData) { if (status === UploadResultStatus.SUCCESS && responseData) {
fileList.push(responseData.url); fileList.push(responseData.result);
} }
} }
// 存在一个上传成功的即可保存 // 存在一个上传成功的即可保存
......
...@@ -32,7 +32,7 @@ export const basicProps = { ...@@ -32,7 +32,7 @@ export const basicProps = {
api: { api: {
type: Function as PropType<PromiseFn>, type: Function as PropType<PromiseFn>,
default: null, default: null,
required: true, required: false,
}, },
name: { name: {
type: String as PropType<string>, type: String as PropType<string>,
......
...@@ -39,15 +39,15 @@ ...@@ -39,15 +39,15 @@
try { try {
const values = await validate(); const values = await validate();
setDrawerProps({ confirmLoading: true }); setDrawerProps({ confirmLoading: true });
const { const { ...rest } = values;
...rest rest.licensePic = rest.licensePic?.join(',');
} = values;
const action = !unref(isUpdate) ? HospitalApi.add : HospitalApi.update; const action = !unref(isUpdate) ? HospitalApi.add : HospitalApi.update;
const data = !unref(isUpdate) const data = !unref(isUpdate)
? { ? {
...rest, ...rest,
} }
: Object.assign({}, : Object.assign(
{},
{ {
...rest, ...rest,
id: unref(entityId), id: unref(entityId),
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
</a-alert> </a-alert>
</template> </template>
<template #toolbar> <template #toolbar>
<a-button v-auth="'AUTH_SYSTEM_HOSPITAL:ADD'" type="primary" @click="handleCreate"> 新增</a-button> <a-button v-auth="'AUTH_SYSTEM_HOSPITAL:ADD'" type="primary" @click="handleCreate"> 新增医院</a-button>
<a-button v-auth="'AUTH_SYSTEM_HOSPITAL:IMPORT'" type="primary" @click="handleImport"> 批量导入医院</a-button>
</template> </template>
<template #bodyCell="{ column, record, text }"> <template #bodyCell="{ column, record, text }">
<template v-if="column.dataIndex === 'id'"> <template v-if="column.dataIndex === 'id'">
...@@ -136,6 +137,9 @@ ...@@ -136,6 +137,9 @@
return handledParams return handledParams
} }
//todo 批量导入医院
const handleImport = () => {}
const handleCreate = () => { const handleCreate = () => {
openDrawer(true, { openDrawer(true, {
isUpdate: false, isUpdate: false,
......
...@@ -6,25 +6,23 @@ ...@@ -6,25 +6,23 @@
* @Date: 2022-06-28 11:50:00 * @Date: 2022-06-28 11:50:00
*/ */
import { BasicColumn } from '/@/components/Table' import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table' import { FormSchema } from '/@/components/Table';
export enum StatusEnum { export enum StatusEnum {
PENDING_REVIEW = '待审核', YES = '启用',
PASSED = '已通过', NO = '禁用',
REJECT = '拒绝',
FORBIDDEN = '禁用',
} }
export const StatusEnumOptions: any[] = [] export const StatusEnumOptions: any[] = [];
for (const key in StatusEnum) { for (const key in StatusEnum) {
StatusEnumOptions.push({ StatusEnumOptions.push({
value: key, value: key,
label: StatusEnum[key], label: StatusEnum[key],
}) });
} }
const colProps = { xs: { span: 24 }, sm: { span: 24 }, lg: { span: 8 } } const colProps = { xs: { span: 24 }, sm: { span: 24 }, lg: { span: 8 } };
const colPropsInDrawer = { span: 24 } const colPropsInDrawer = { span: 24 };
export const schema = { export const schema = {
model: 'Hospital', model: 'Hospital',
...@@ -86,7 +84,7 @@ export const schema = { ...@@ -86,7 +84,7 @@ export const schema = {
}, },
colProps, colProps,
component: 'Input', component: 'Input',
rules: [{ required: true, message: '请输入医院简称!' }], rules: [{ required: false, message: '请输入医院简称!' }],
}, },
table: {}, table: {},
}, },
...@@ -116,7 +114,7 @@ export const schema = { ...@@ -116,7 +114,7 @@ export const schema = {
}, },
colProps, colProps,
component: 'Input', component: 'Input',
rules: [{ required: true, message: '请输入税率!' }], rules: [{ required: false, message: '请输入税率!' }],
}, },
table: {}, table: {},
}, },
...@@ -137,16 +135,16 @@ export const schema = { ...@@ -137,16 +135,16 @@ export const schema = {
}, },
{ {
field: 'mobile', field: 'mobile',
label: '手机号', label: '电话',
defaultValue: undefined, defaultValue: undefined,
form: { form: {
componentProps: { componentProps: {
allowClear: false, allowClear: false,
placeholder: '手机号', placeholder: '电话',
}, },
colProps, colProps,
component: 'Input', component: 'Input',
rules: [{ required: true, message: '请输入手机号!' }], rules: [{ required: false, message: '请输入电话!' }],
}, },
table: {}, table: {},
}, },
...@@ -166,7 +164,7 @@ export const schema = { ...@@ -166,7 +164,7 @@ export const schema = {
}, },
{ {
field: 'level', field: 'level',
label: '等级', label: '医院等级',
defaultValue: 1, defaultValue: 1,
form: { form: {
componentProps: { componentProps: {
...@@ -175,59 +173,64 @@ export const schema = { ...@@ -175,59 +173,64 @@ export const schema = {
}, },
colProps, colProps,
component: 'InputNumber', component: 'InputNumber',
rules: [{ required: true, message: '请输入等级!' }], rules: [{ required: false, message: '请输入等级!' }],
}, },
table: {}, table: {},
}, },
{ {
field: 'licenseNumber', field: 'licenseNumber',
label: '工商营业执照代码', label: '营业执照代码',
defaultValue: undefined, defaultValue: undefined,
form: { form: {
componentProps: { componentProps: {
allowClear: true, allowClear: true,
placeholder: '工商营业执照代码', placeholder: '营业执照代码',
}, },
colProps, colProps,
component: 'Input', component: 'Input',
rules: [{ required: true, message: '请输入代码!' }],
}, },
table: {}, table: {},
}, },
{ {
field: 'licensePic', field: 'licensePic',
label: '工商营业执照图片', label: '营业执照图片',
defaultValue: undefined, defaultValue: undefined,
form: { form: {
componentProps: { componentProps: {
allowClear: true, allowClear: true,
placeholder: '工商营业执照图片', placeholder: '营业执照图片',
maxNumber: 1,
multiple: false,
}, },
colProps, colProps,
component: 'Upload', component: 'Upload',
rules: [{ required: true, message: '请上传' }],
}, },
table: {}, table: {},
}, },
{ {
field: 'licenseExpireTime', field: 'licenseExpireTime',
label: '有效期', label: '执照有效期',
defaultValue: undefined, defaultValue: undefined,
form: { form: {
colProps, colProps,
component: 'DatePicker', component: 'DatePicker',
componentProps: { componentProps: {
allowClear: false, allowClear: false,
placeholder: '有效期', placeholder: '执照有效期',
format: 'YYYY-MM-DD HH:mm:ss', format: 'YYYY-MM-DD',
showTime: true, valueFormat: 'YYYY-MM-DD HH:mm:ss',
showTime: false,
}, },
rules: [{ required: true, message: '请输入有效期!' }], rules: [{ required: true, message: '请输入执照有效期!' }],
}, },
table: {}, table: {},
}, },
{ {
field: 'status', field: 'status',
label: '状态', label: '状态',
defaultValue: 'PENDING_REVIEW', defaultValue: 'YES',
form: { form: {
componentProps: { componentProps: {
allowClear: false, allowClear: false,
...@@ -240,8 +243,8 @@ export const schema = { ...@@ -240,8 +243,8 @@ export const schema = {
}, },
table: { table: {
customRender: ({ text }) => { customRender: ({ text }) => {
const option = StatusEnumOptions.find((item) => item.value === text) const option = StatusEnumOptions.find((item) => item.value === text);
return option ? option.label : text return option ? option.label : text;
}, },
}, },
}, },
...@@ -310,7 +313,7 @@ export const schema = { ...@@ -310,7 +313,7 @@ export const schema = {
table: {}, table: {},
}, },
], ],
} };
const queryFields = [ const queryFields = [
'distributorId', 'distributorId',
...@@ -329,9 +332,8 @@ const queryFields = [ ...@@ -329,9 +332,8 @@ const queryFields = [
'editorName', 'editorName',
'createTime', 'createTime',
'updateTime', 'updateTime',
] ];
const editFields = [ const editFields = [
'distributorId',
'name', 'name',
'abbreviationName', 'abbreviationName',
'code', 'code',
...@@ -344,7 +346,7 @@ const editFields = [ ...@@ -344,7 +346,7 @@ const editFields = [
'licensePic', 'licensePic',
'licenseExpireTime', 'licenseExpireTime',
'status', 'status',
] ];
const tableFields = [ const tableFields = [
'distributorId', 'distributorId',
'name', 'name',
...@@ -363,7 +365,7 @@ const tableFields = [ ...@@ -363,7 +365,7 @@ const tableFields = [
'editorName', 'editorName',
'createTime', 'createTime',
'updateTime', 'updateTime',
] ];
const descriptionFields = [ const descriptionFields = [
'id', 'id',
'distributorId', 'distributorId',
...@@ -383,7 +385,7 @@ const descriptionFields = [ ...@@ -383,7 +385,7 @@ const descriptionFields = [
'editorName', 'editorName',
'createTime', 'createTime',
'updateTime', 'updateTime',
] ];
export const searchFormSchema: FormSchema[] = schema.properties export const searchFormSchema: FormSchema[] = schema.properties
.filter((item) => queryFields.includes(item.field)) .filter((item) => queryFields.includes(item.field))
...@@ -396,7 +398,7 @@ export const searchFormSchema: FormSchema[] = schema.properties ...@@ -396,7 +398,7 @@ export const searchFormSchema: FormSchema[] = schema.properties
rules: rules.filter((r) => !r.required), rules: rules.filter((r) => !r.required),
...formProps, ...formProps,
} as FormSchema), } as FormSchema),
) );
export const formSchema: FormSchema[] = schema.properties export const formSchema: FormSchema[] = schema.properties
.filter((item) => editFields.includes(item.field)) .filter((item) => editFields.includes(item.field))
...@@ -409,7 +411,7 @@ export const formSchema: FormSchema[] = schema.properties ...@@ -409,7 +411,7 @@ export const formSchema: FormSchema[] = schema.properties
...form, ...form,
colProps: colPropsInDrawer, colProps: colPropsInDrawer,
} as FormSchema), } as FormSchema),
) );
export const columns: BasicColumn[] = schema.properties export const columns: BasicColumn[] = schema.properties
.filter((item) => tableFields.includes(item.field)) .filter((item) => tableFields.includes(item.field))
...@@ -420,7 +422,7 @@ export const columns: BasicColumn[] = schema.properties ...@@ -420,7 +422,7 @@ export const columns: BasicColumn[] = schema.properties
title: label, title: label,
...table, ...table,
} as BasicColumn), } as BasicColumn),
) );
export const descriptionColumns: BasicColumn[] = schema.properties export const descriptionColumns: BasicColumn[] = schema.properties
.filter((item) => descriptionFields.includes(item.field)) .filter((item) => descriptionFields.includes(item.field))
...@@ -431,4 +433,4 @@ export const descriptionColumns: BasicColumn[] = schema.properties ...@@ -431,4 +433,4 @@ export const descriptionColumns: BasicColumn[] = schema.properties
title: label, title: label,
...table, ...table,
} as BasicColumn), } as BasicColumn),
) );
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论