accessoryList.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="10" class="mb8">
  4. <el-col :span="1.5">
  5. <el-button
  6. type="info"
  7. plain
  8. icon="el-icon-upload2"
  9. size="small"
  10. @click="uploadAccessory"
  11. >上传</el-button
  12. >
  13. </el-col>
  14. </el-row>
  15. <el-table v-loading="loading" :data="accessoryList">
  16. <el-table-column
  17. type="index"
  18. label="序号"
  19. width="55"
  20. align="center"
  21. />
  22. <el-table-column label="名称" align="center" prop="fileName" />
  23. <el-table-column label="上传者" align="center" prop="createByName" />
  24. <el-table-column label="上传时间" align="center" prop="createTime" />
  25. <el-table-column
  26. label="操作"
  27. align="center"
  28. class-name="small-padding fixed-width"
  29. >
  30. <template slot-scope="scope">
  31. <el-row>
  32. <el-col :span="1.5">
  33. <el-button
  34. size="small"
  35. type="danger"
  36. plain
  37. icon="el-icon-delete"
  38. @click="deleteAccessory(scope.row.id)"
  39. >删除</el-button
  40. >
  41. </el-col>
  42. <el-col :span="1.5">
  43. <el-button
  44. type="success"
  45. plain
  46. icon="el-icon-download"
  47. size="small"
  48. @click="downloadAccessory(scope.row)"
  49. >下载</el-button
  50. >
  51. </el-col>
  52. </el-row>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <pagination
  57. v-show="total>0"
  58. :total="total"
  59. :page.sync="queryParams.pageNum"
  60. :limit.sync="queryParams.pageSize"
  61. @pagination="getList"
  62. />
  63. <el-dialog
  64. :title="upload.title"
  65. :visible.sync="upload.open"
  66. width="400px"
  67. append-to-body
  68. >
  69. <el-upload
  70. ref="upload"
  71. :limit="1"
  72. accept=".xlsx, .xls, .doc, .docx, .word, .wordx, .png, .jpg, .gif, .txt"
  73. :headers="upload.headers"
  74. :action="upload.url + '?boId=' + bo.id"
  75. :disabled="upload.isUploading"
  76. :on-progress="handleFileUploadProgress"
  77. :on-success="handleFileSuccess"
  78. :auto-upload="false"
  79. drag
  80. >
  81. <i class="el-icon-upload"></i>
  82. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  83. </el-upload>
  84. <div slot="footer">
  85. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  86. <el-button @click="upload.open = false">取 消</el-button>
  87. </div>
  88. </el-dialog>
  89. </div>
  90. </template>
  91. <script>
  92. import { listAccessory, delAccessory, addAccessory} from "@/api/business/spd/bo/accessory";
  93. import { getToken } from "@/utils/auth";
  94. import axios from "axios";
  95. export default {
  96. name: "accessoryList",
  97. props:["source","bo","boAuthority"],
  98. data() {
  99. return {
  100. // 遮罩层
  101. loading: true,
  102. // 总条数
  103. total: 0,
  104. // 表格数据
  105. contactList: [],
  106. // 查询参数
  107. queryParams: {
  108. pageNum: 1,
  109. pageSize: 10,
  110. boId: null,
  111. name: null,
  112. code: null,
  113. customer: null,
  114. params:{},
  115. },
  116. // 上传参数
  117. upload: {
  118. // 是否显示弹出层
  119. open: false,
  120. // 弹出层标题
  121. title: "",
  122. // 是否禁用上传
  123. isUploading: false,
  124. // 上传类型
  125. flag: "",
  126. // 设置上传的请求头部
  127. headers: { Authorization: "Bearer " + getToken() },
  128. // 上传的地址
  129. url: process.env.VUE_APP_BASE_API + "/mk/bo/accessory/upload",
  130. },
  131. };
  132. },
  133. created() {
  134. this.queryParams.boId = this.bo.id;
  135. this.queryParams.params = {"post":this.boAuthority.post};
  136. this.getList();
  137. },
  138. methods: {
  139. /** 查询附件列表 */
  140. getList() {
  141. this.loading = true;
  142. listAccessory(this.queryParams).then(response => {
  143. this.accessoryList = response.rows;
  144. this.total = response.total;
  145. this.loading = false;
  146. });
  147. },
  148. //上传附件公共方法
  149. uploadAccessory() {
  150. this.upload.open = true;
  151. },
  152. // 提交上传文件
  153. submitFileForm() {
  154. this.$refs.upload.submit();
  155. },
  156. // 文件上传中处理
  157. handleFileUploadProgress(event, file, fileList) {
  158. this.upload.isUploading = true;
  159. },
  160. // 文件上传成功处理
  161. handleFileSuccess(response, file, fileList) {
  162. this.upload.open = false;
  163. this.upload.isUploading = false;
  164. this.$refs.upload.clearFiles();
  165. this.$alert(
  166. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  167. response.msg +
  168. "</div>",
  169. "上传结果",
  170. { dangerouslyUseHTMLString: true }
  171. );
  172. this.getList();
  173. },
  174. //下载附件
  175. downloadAccessory(row) {
  176. console.log('row',row);
  177. var resUrl = "https://sy.derom.com/document-center/fastdfs/download?id=" + row.urlId;
  178. axios
  179. .create({
  180. timeout: 3000,
  181. responseType: "blob", // 响应类型, 将响应数据转换为二进制数据
  182. headers: {},
  183. })
  184. .get(resUrl)
  185. .then((res) => {
  186. console.log(res);
  187. // 地址转换
  188. let url = window.URL.createObjectURL(res.data);
  189. const a = document.createElement("a");
  190. a.setAttribute("href", url);
  191. a.setAttribute("download", row.fileName);
  192. document.body.append(a);
  193. a.click();
  194. document.body.removeChild(a);
  195. });
  196. },
  197. //删除附件
  198. deleteAccessory(id) {
  199. this.$modal
  200. .confirm("是否确认删除?")
  201. .then(function () {})
  202. .then(() => {
  203. delAccessory(id).then((res) => {
  204. if (res.code == 200) {
  205. this.$modal.msgSuccess("删除成功");
  206. this.getList();
  207. } else {
  208. this.$modal.msgSuccess("删除失败");
  209. }
  210. });
  211. })
  212. .catch(() => {});
  213. },
  214. }
  215. };
  216. </script>