UploadPaperDialog.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <el-dialog
  3. class="file-upload-view"
  4. :visible.sync="modalIsShow"
  5. :title="`上传${curConfig.title}`"
  6. top="10vh"
  7. width="710px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="visibleChange"
  12. >
  13. <div class="file-upload-body">
  14. <el-form label-position="left">
  15. <el-form-item :label="`${curConfig.title}:`">
  16. <upload-file-view
  17. input-width="270px"
  18. :format="curConfig.format"
  19. :upload-url="uploadUrl"
  20. @upload-error="uplaodError"
  21. @upload-success="uploadSuccess"
  22. ref="UploadFileView"
  23. ></upload-file-view>
  24. <el-button @click="toPreview" style="margin-left: 10px;"
  25. >预览</el-button
  26. >
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. <div slot="footer" style="text-align: right">
  31. <el-button type="primary" @click="confirm">保存</el-button>
  32. <el-button @click="cancel">返回</el-button>
  33. </div>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. import UploadFileView from "../components/UploadFileView";
  38. import { attachmentPreview } from "../../login/api";
  39. export default {
  40. name: "file-upload-view",
  41. components: { UploadFileView },
  42. props: {
  43. paperAttachment: {
  44. type: Object,
  45. default() {
  46. return {};
  47. }
  48. },
  49. uploadType: {
  50. type: String,
  51. default: "paper",
  52. validator(val) {
  53. return ["paper", "paperConfirm"].includes(val);
  54. }
  55. }
  56. },
  57. data() {
  58. return {
  59. modalIsShow: false,
  60. attachment: {},
  61. config: {
  62. paper: { title: "试卷文件", format: ["pdf"] },
  63. paperConfirm: {
  64. title: "试卷审核确认书文件",
  65. format: ["jpg", "png"]
  66. }
  67. },
  68. curConfig: {},
  69. // import
  70. uploadUrl: "/api/print/basic/sys/saveAttachment"
  71. };
  72. },
  73. methods: {
  74. visibleChange() {
  75. this.$refs.UploadFileView.setAttachmentName(
  76. `${this.paperAttachment.filename || ""}`
  77. );
  78. this.attachment = { ...this.paperAttachment };
  79. this.curConfig = this.config[this.uploadType];
  80. },
  81. // upload-handler
  82. uplaodError(errorData) {
  83. this.$notify.error({
  84. title: "错误提示",
  85. message: errorData.message
  86. });
  87. },
  88. uploadSuccess(res) {
  89. this.$message.success("上传成功!");
  90. this.attachment = Object.assign(this.attachment, {
  91. attachmentId: res.data.id,
  92. filename: `${res.data.name}${res.data.type}`
  93. });
  94. },
  95. cancel() {
  96. this.modalIsShow = false;
  97. },
  98. open() {
  99. this.modalIsShow = true;
  100. },
  101. confirm() {
  102. this.$emit("confirm", this.attachment, this.uploadType);
  103. this.cancel();
  104. },
  105. async toPreview() {
  106. if (!this.attachment.attachmentId) {
  107. this.$message.error("请先上传附件!");
  108. return;
  109. }
  110. const data = await attachmentPreview(this.attachment.attachmentId);
  111. window.open(data.path);
  112. }
  113. }
  114. };
  115. </script>
  116. <style lang="css" scoped>
  117. .file-upload-body {
  118. min-height: 150px;
  119. }
  120. </style>