excelPop.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div>
  3. <div class="swq">
  4. <img
  5. style="width: 182px; height: 168px"
  6. src="@/assets/images/dr.png"
  7. alt=""
  8. />
  9. </div>
  10. <div style="padding-left: 100px">
  11. <p>第一步:下载excel导入模板</p>
  12. <p style="padding-left: 50px">
  13. <i class="el-icon-upload"></i
  14. ><span class="dowmStys" @click="getDowm">下载模板</span>
  15. </p>
  16. <p>第二步:点击“上传Excel”</p>
  17. <label for="mobles2" class="el-button el-button--primary el-button--mini"
  18. >上传Excel</label
  19. ><input
  20. style="display: none"
  21. type="file"
  22. id="mobles2"
  23. ref="input2"
  24. @change="importMobleadd"
  25. />
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import * as baseUrls from "@/utils/request.js";
  31. export default {
  32. data() {
  33. return {};
  34. },
  35. methods: {
  36. getDowm() {
  37. let url =
  38. baseUrls.BASE_IMG_URL + "/oss/images/file/20220518/1652865393160.xlsx" +
  39. `?time=${this.$methodsTools.getNewTime()}`;;
  40. let link = document.createElement("a");
  41. let fileName = "导入模板" + ".xlsx";
  42. document.body.appendChild(link);
  43. link.href = url;
  44. link.dowmload = fileName;
  45. link.click();
  46. link.remove();
  47. },
  48. importMobleadd(e) {
  49. var self = this;
  50. var file = e.target.files[0];
  51. let formData = new FormData();
  52. formData.append("file", file);
  53. this.$api
  54. .importDatabankimportDataBackList(formData)
  55. .then((res) => {
  56. console.log(res)
  57. if (res.data.fullStatus == "全部成功") {
  58. self.$emit("backData",res.data.questionList)
  59. self.$message.success("全部导入成功");
  60. } else {
  61. let url = baseUrls.baseURL + "common/download?fileName=" + res.data.errorExcel.msg;
  62. let link = document.createElement("a");
  63. let fileName = "导入模板" + ".xlsx";
  64. document.body.appendChild(link);
  65. link.href = url;
  66. link.dowmload = fileName;
  67. link.click();
  68. link.remove();
  69. if(res.data.fullStatus == '部分成功'){
  70. self.$emit("backData",res.data.questionList)
  71. self.$message.warning("部分导入成功,请打开文档查看错误原因");
  72. }else{
  73. self.$message.error("导入失败,请打开文档查看错误原因");
  74. }
  75. }
  76. })
  77. .finally(() => {
  78. e.target.value = "";
  79. });
  80. },
  81. },
  82. };
  83. </script>
  84. <style lang="less" scoped>
  85. .swq {
  86. text-align: center;
  87. border-bottom: 1px solid #eee;
  88. }
  89. .dowmStys {
  90. color: blue;
  91. cursor: pointer;
  92. }
  93. </style>