AppDeployDeviceUpload.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <el-dialog
  3. class="modify-device"
  4. :visible.sync="modalIsShow"
  5. title="上传设备信息"
  6. top="10vh"
  7. width="600px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="rules"
  17. label-width="70px"
  18. >
  19. <el-form-item prop="deviceInfo" label="文件:">
  20. <UploadFetchFile
  21. ref="UploadFetchFile"
  22. input-width="365px"
  23. :format="[]"
  24. :disabled="isSubmit"
  25. @file-change="deviceFileChange"
  26. @valid-change="validChange"
  27. />
  28. </el-form-item>
  29. <el-form-item label="备注:">
  30. <el-input
  31. v-model.trim="modalForm.remark"
  32. type="textarea"
  33. placeholder="请输入备注"
  34. clearable
  35. ></el-input>
  36. </el-form-item>
  37. </el-form>
  38. <div slot="footer">
  39. <el-button type="danger" @click="cancel" plain>取消</el-button>
  40. <el-button type="primary" :disabled="isSubmit" @click="submit"
  41. >确认</el-button
  42. >
  43. </div>
  44. </el-dialog>
  45. </template>
  46. <script>
  47. import { appDeployDeviceSave } from "../api";
  48. import UploadFetchFile from "../../../components/UploadFetchFile.vue";
  49. const initModalForm = {
  50. id: "",
  51. remark: "",
  52. deviceInfo: null,
  53. md5: "",
  54. };
  55. export default {
  56. name: "modify-device",
  57. components: { UploadFetchFile },
  58. props: {
  59. deployId: {
  60. type: [String, Number],
  61. },
  62. },
  63. data() {
  64. return {
  65. modalIsShow: false,
  66. isSubmit: false,
  67. modalForm: {
  68. ...initModalForm,
  69. },
  70. rules: {
  71. deviceInfo: [
  72. {
  73. required: true,
  74. message: "请选择要上传的文件",
  75. trigger: "change",
  76. },
  77. ],
  78. },
  79. };
  80. },
  81. methods: {
  82. visibleChange() {
  83. this.modalForm = { ...initModalForm };
  84. this.modalForm.id = this.deployId;
  85. this.$nextTick(() => {
  86. this.$refs.UploadFetchFile.setAttachmentName("");
  87. });
  88. },
  89. cancel() {
  90. this.modalIsShow = false;
  91. },
  92. open() {
  93. this.modalIsShow = true;
  94. },
  95. deviceFileChange({ file, md5 }) {
  96. this.modalForm.md5 = md5;
  97. this.modalForm.deviceInfo = file;
  98. this.$refs.modalFormComp.validateField("deviceInfo", () => {});
  99. },
  100. validChange(res) {
  101. if (!res.success)
  102. this.$notify.error({ title: "错误提示", message: res.message });
  103. },
  104. async submit() {
  105. const valid = await this.$refs.modalFormComp.validate();
  106. if (!valid) return;
  107. if (this.isSubmit) return;
  108. this.isSubmit = true;
  109. const result = await appDeployDeviceSave(this.modalForm).catch(() => {});
  110. this.isSubmit = false;
  111. if (!result) return;
  112. this.$message.success("上传成功!");
  113. this.$emit("modified");
  114. this.cancel();
  115. },
  116. },
  117. };
  118. </script>