main.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div>
  3. <containerTitle :title="title"></containerTitle>
  4. <basic-container>
  5. <avue-crud
  6. ref="crud"
  7. :option="option"
  8. v-model="form"
  9. :data="fileData"
  10. @row-save="rowSave"
  11. @row-update="rowUpdate"
  12. @row-del="rowDel"
  13. :upload-after="uploadAfter"
  14. @saveColumn="saveColumn"
  15. :cell-style="cellStyle"
  16. >
  17. <template slot="menuLeft">
  18. <el-button
  19. type="primary"
  20. icon="el-icon-plus"
  21. size="small"
  22. @click.stop="$refs.crud.rowAdd()"
  23. :disabled="disabled"
  24. >上传</el-button
  25. >
  26. </template>
  27. <template slot="menu" slot-scope="{ row, index }">
  28. <el-button
  29. size="small"
  30. icon="el-icon-edit"
  31. type="text"
  32. @click="$refs.crud.rowEdit(row, index)"
  33. :disabled="disabled"
  34. >编 辑</el-button
  35. >
  36. <el-button
  37. size="small"
  38. icon="el-icon-delete"
  39. type="text"
  40. @click="rowDel(row, index)"
  41. :disabled="disabled"
  42. >删 除</el-button
  43. >
  44. </template>
  45. </avue-crud>
  46. </basic-container>
  47. </div>
  48. </template>
  49. <script>
  50. import option from "./config/uploadList.json";
  51. import { updateListRemove } from "@/api/uploadFile/upload-file";
  52. export default {
  53. name: "uploadfile",
  54. data() {
  55. return {
  56. form: {},
  57. fileData: [],
  58. option: {}
  59. };
  60. },
  61. props: {
  62. title: {
  63. type: String,
  64. default: "附件上传"
  65. },
  66. orderFilesList: {
  67. type: Array
  68. },
  69. disabled: {
  70. type: Boolean
  71. },
  72. delUrl: {
  73. type: String
  74. }
  75. },
  76. async created() {
  77. this.option = await this.getColumnData(this.getColumnName(35), option);
  78. },
  79. methods: {
  80. cellStyle() {
  81. return "padding:0;height:40px;";
  82. },
  83. //新增附件上传保存触发
  84. rowSave(row, done, loading) {
  85. this.fileData.push(row);
  86. done();
  87. },
  88. //修改附件上传触发
  89. rowUpdate(row, index, done, loading) {
  90. done(row);
  91. },
  92. //删除附件上传触发
  93. rowDel(row, index, donerowDel) {
  94. this.$confirm("确定将选择数据删除?", {
  95. confirmButtonText: "确定",
  96. cancelButtonText: "取消",
  97. type: "warning"
  98. }).then(() => {
  99. if (row.id) {
  100. updateListRemove(row.id, this.delUrl).then(res => {
  101. this.$message({
  102. type: "success",
  103. message: "删除成功!"
  104. });
  105. this.fileData.splice(index, 1);
  106. });
  107. } else {
  108. this.$message({
  109. type: "success",
  110. message: "删除成功!"
  111. });
  112. this.fileData.splice(index, 1);
  113. }
  114. });
  115. },
  116. uploadAfter(res, done) {
  117. if (res.originalName) {
  118. this.form.fileName = this.form.fileName
  119. ? this.form.fileName
  120. : res.originalName;
  121. }
  122. done();
  123. },
  124. //提交数据的返回值
  125. submitData() {
  126. return this.fileData;
  127. },
  128. async saveColumn() {
  129. const inSave = await this.saveColumnData(
  130. this.getColumnName(35),
  131. this.option
  132. );
  133. if (inSave) {
  134. this.$message.success("保存成功");
  135. //关闭窗口
  136. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  137. }
  138. }
  139. },
  140. watch: {
  141. orderFilesList: function(rows) {
  142. this.fileData = rows;
  143. }
  144. }
  145. };
  146. </script>
  147. <style scoped lang="scss"></style>