rt-sim-training-client/src/views/uploadPdf/edit.vue

237 lines
8.5 KiB
Vue
Raw Normal View History

2021-05-14 18:31:46 +08:00
<template>
<el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" center class="uploadDialog">
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
2021-05-17 17:20:26 +08:00
<div class="fileError">{{ message }}</div>
2021-05-14 18:31:46 +08:00
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
<el-button @click="handleClose">{{ $t('global.cancel') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { postUploadFile, putUploadFile } from '@/api/pdf';
2021-05-17 17:20:26 +08:00
// import { getPublishMapDetailById, getPublishMapVersionById } from '@/api/jmap/map';
// import { dbReadData, dbAddData, dbUpdateData } from '@/utils/indexedDb';
2021-05-14 18:31:46 +08:00
// uploadFile
import { meansUrl } from '@/api/upload';
export default {
name: 'TrainingDetailEdit',
props: {
type: {
type: String,
required: true
}
},
data() {
return {
dialogVisible: false,
formModel: {
upload: '',
filePath: '',
2021-05-17 17:20:26 +08:00
fileType: 'DRAWING',
fileName:''
2021-05-14 18:31:46 +08:00
},
fileList: [],
formData: '',
id: '',
2021-05-17 17:20:26 +08:00
message:''
// deviceTypeList: [
// { label: '区段', value: 'sectionList', code: 'SECTION' },
// { label: '道岔', value: 'switchList', code: 'SWITCH' },
// { label: '信号机', value: 'signalList', code: 'SIGNAL' },
// { label: '车站', value: 'stationList', code: 'STATION' },
// { label: '站台', value: 'stationStandList', code: 'STAND' },
// { label: '屏蔽门', value: 'psdList', code: 'PSD' },
// { label: '列车', value: 'trainList', code: 'TRAIN' }
// ],
2021-05-14 18:31:46 +08:00
};
},
computed: {
action() {
return `${process.env.VUE_APP_UPLOAD_API}${meansUrl}`;
},
form() {
const form = {
labelWidth: '120px',
items: [
2021-05-17 17:20:26 +08:00
// { prop: 'mapId', label: '选择线路:', type:'select', options: this.mapList, optionValue:'id', optionLabel:'name', change: true, onChange: this.handleMap },
// { prop: 'deviceTypes', label: '选择设备类型:', type:'select', options: this.deviceTypeList, optionValue:'value', optionLabel:'label', change: true, onChange: this.handleDevice },
// { prop: 'deviceIds', label: '选择设备:', type:'select', multiple: true, options: this.deviceCodesList, optionValue:'code', optionLabel:'name' },
{ prop: 'fileName', label: '文件名:', type:'text', show:true, rightWidth:true, required:true },
{ prop: 'upload', label: '上传:', type:'uploadPicture', fileList: this.fileList, show: this.type == 'ADD', action: this.action, onChange: this.onChange, onSuccess: this.onSuccess }
2021-05-14 18:31:46 +08:00
]
};
return form;
},
rules() {
const crules = {
2021-05-17 17:20:26 +08:00
fileName: [
{ required: true, message: '文件名不能为空', trigger: 'blur'}
2021-05-14 18:31:46 +08:00
]
2021-05-17 17:20:26 +08:00
// upload: [
// { required: true, message: '请上传文件', trigger: 'onChange' }
// ]
2021-05-14 18:31:46 +08:00
};
return crules;
},
title() {
if (this.type === 'ADD') {
return '上传PDF';
} else {
2021-05-17 17:20:26 +08:00
return '更新PDF';
2021-05-14 18:31:46 +08:00
}
}
},
methods: {
async show(data) {
this.dialogVisible = true;
if (this.type != 'ADD') {
this.id = data.id;
this.formModel = {
upload: '',
2021-05-17 17:20:26 +08:00
fileName:data.fileName,
2021-05-14 18:31:46 +08:00
filePath: data.filePath
};
} else {
this.formModel = {
upload: '',
2021-05-17 17:20:26 +08:00
filePath: '',
fileName:''
2021-05-14 18:31:46 +08:00
};
}
},
2021-05-17 17:20:26 +08:00
// async handleMap(mapId) {
// if (mapId) {
// if (mapId != this.rowData.mapId) {
// this.formModel.deviceIds = [];
// this.formModel.deviceTypes = '';
// }
// return new Promise(async (resolve, reject) => {
// const resp = await getPublishMapVersionById(mapId);
// const version = resp.data;
// dbReadData('mapData', mapId, version, async (mapData, version) =>{
// if (mapData && mapData.version == version) {
// this.graphDataNew = mapData.graphDataNew;
// resolve();
// } else if (mapData) {
// const res = await getPublishMapDetailById(mapId);
// this.graphDataNew = res.data.graphDataNew;
// dbUpdateData('mapData', res.data);
// resolve();
// } else {
// const res = await getPublishMapDetailById(mapId);
// this.graphDataNew = res.data.graphDataNew;
// dbAddData('mapData', res.data);
// resolve();
// }
// });
// });
// } else {
// this.formModel.deviceIds = [];
// this.formModel.mapId = '';
// this.formModel.deviceTypes = '';
// }
// },
// handleDevice(type) {
// if (type) {
// if (type != this.rowData.deviceTypes) {
// this.formModel.deviceIds = [];
// }
// this.deviceCodesList = this.graphDataNew[type].map(el => {
// return {
// code: el.code,
// name: `${el.name}(${el.code})`
// };
// });
// } else {
// this.formModel.deviceIds = [];
// }
// },
2021-05-14 18:31:46 +08:00
// uploadFile(file) {
// this.formData.append('file', file.file);
// },
onSuccess(res, file) {
this.formModel.filePath = res.data;
2021-05-17 17:20:26 +08:00
this.message = '';
2021-05-14 18:31:46 +08:00
},
doSave() {
const self = this;
this.$refs.dataform.validateForm(() => {
if (self.type == 'ADD') {
2021-05-17 17:20:26 +08:00
if (this.formModel.filePath) {
self.create();
} else {
this.message = '请上传文件';
return false;
}
2021-05-14 18:31:46 +08:00
} else {
self.update();
}
});
},
create() {
const self = this;
const data = {
fileType: 'DRAWING',
2021-05-17 17:20:26 +08:00
filePath: this.formModel.filePath,
fileName:this.formModel.fileName
2021-05-14 18:31:46 +08:00
};
postUploadFile(data).then((res) => {
self.$message.success('上传PDF成功!');
self.handleClose();
self.$emit('reloadTable');
}).catch(error => {
console.log(error);
2021-05-17 17:20:26 +08:00
self.$message.error(`上传PDF失败:${error.message}`);
2021-05-14 18:31:46 +08:00
});
},
update() {
const self = this;
const data = {
id: this.id,
fileType: 'DRAWING',
2021-05-17 17:20:26 +08:00
fileName:this.formModel.fileName,
2021-05-14 18:31:46 +08:00
filePath: this.formModel.filePath
};
putUploadFile(data).then(() => {
2021-05-17 17:20:26 +08:00
self.$message.success('更新PDF成功!');
2021-05-14 18:31:46 +08:00
self.handleClose();
self.$emit('reloadTable');
}).catch(error => {
2021-05-17 17:20:26 +08:00
self.$message.error(`更新PDF失败:${error.message}`);
2021-05-14 18:31:46 +08:00
});
},
handleClose() {
2021-05-17 17:20:26 +08:00
this.message = '';
2021-05-14 18:31:46 +08:00
this.formModel = {
2021-05-17 17:20:26 +08:00
upload: '',
filePath: '',
fileName:''
2021-05-14 18:31:46 +08:00
};
this.$refs.dataform.resetForm();
this.dialogVisible = false;
}
}
};
</script>
<style lang="scss" scoped>
.uploadDialog{
/deep/ {
.el-select--medium{
width: 300px;
}
}
}
2021-05-17 17:20:26 +08:00
.fileError{
color: red;
font-size: 13px;
margin-left: 122px;
vertical-align: top;
display: inline-block;
margin-top: -10px;
}
2021-05-14 18:31:46 +08:00
</style>