insertData.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <el-dialog
  3. :title="$t('ManualEntryPage.tit_insert_data')"
  4. :visible.sync="isShowinsert"
  5. :close-on-click-modal="false"
  6. :modal-append-to-body="false"
  7. center
  8. v-dialogDrag
  9. @close="cancelHandle"
  10. custom-class="dialog-cont"
  11. width="40%"
  12. >
  13. <div slot="title" style="display: flex; alignitems: center">
  14. <img
  15. :src="$icons.imp"
  16. style="color: #fff; width: 16px; height: 16px; marginright: 5px"
  17. />
  18. <span style="fontsize: 16px">{{$t('ManualEntryPage.tit_insert_data')}}</span>
  19. </div>
  20. <div class="down-min">
  21. <dataLoading :loading="isLoading"/>
  22. <div class="download-ico">
  23. <a :href="downloadTemplate" download="模板">
  24. <i class="icon down_ico"></i>
  25. <span style="color: #5882ef; cursor: pointer">{{$t('ManualEntryPage.down_tem')}}</span>
  26. </a>
  27. <!-- <a :href="downloadTemplate" download="模板" style="color:#5882EF;cursor:pointer;">下载模板</a> -->
  28. </div>
  29. <i class="arrow-ico"></i>
  30. <div class="import-ico">
  31. <el-upload
  32. class="upload-demo"
  33. :before-upload="beforeUploadFile"
  34. multiple
  35. :limit="3"
  36. :headers="headerConfig"
  37. :file-list="fileList"
  38. :on-success="handleSuccess"
  39. :on-progress="handleStarting"
  40. :action="action"
  41. accept=".xlsx"
  42. :data="params"
  43. :name="name"
  44. :show-file-list="false"
  45. >
  46. <i class="icon up_ico"></i>
  47. <span style="color: #5882ef; cursor: pointer">{{$t('ManualEntryPage.tit_insert_data')}}</span>
  48. <!-- <el-button type="primary">导入</el-button> -->
  49. </el-upload>
  50. </div>
  51. </div>
  52. <div class="down-tip-txt">
  53. <span>{{$t('ManualEntryPage.step_one')}}</span>
  54. <span>{{$t('ManualEntryPage.step_two')}}</span>
  55. <span>{{$t('ManualEntryPage.step_three')}}
  56. <a
  57. style="display: inline; color: #5882ef"
  58. :href="downloadErrorlist"
  59. download
  60. >{{$t('ManualEntryPage.down_fail_list')}}</a
  61. >。</span
  62. >
  63. </div>
  64. </el-dialog>
  65. </template>
  66. <script>
  67. import { dataInterence } from "api/api.js";
  68. export default {
  69. name: "",
  70. props: {
  71. isShowinsert: {
  72. type: Boolean,
  73. },
  74. source: {
  75. type: String,
  76. },
  77. },
  78. data() {
  79. return {
  80. action: process.env.VUE_APP_API_ROOT + "/entry/import/data", //上传文件
  81. downloadTemplate: process.env.VUE_APP_API_ROOT + "/entry/template", //模板下载
  82. downloadErrorlist:
  83. process.env.VUE_APP_API_ROOT +
  84. "/entry/import/failList" +
  85. `?${localStorage.getItem("auth")}`, //失败列表下载
  86. name: "EntryFile",
  87. params: {},
  88. headerConfig: {
  89. Authorization: localStorage.getItem("auth"),
  90. },
  91. isLoading: false,
  92. fileList: []
  93. };
  94. },
  95. watch: {
  96. source: {
  97. handler(nval) {
  98. if (nval === "targetList") {
  99. this.action = process.env.VUE_APP_API_ROOT + "/entry/target/import";
  100. this.downloadTemplate =
  101. process.env.VUE_APP_API_ROOT + "/entry/target/template";
  102. this.downloadErrorlist =
  103. process.env.VUE_APP_API_ROOT +
  104. "/entry/import_target/failList" +
  105. `?${localStorage.getItem("auth")}`;
  106. this.name = "ImportTargetFile";
  107. }
  108. },
  109. immediate: true,
  110. },
  111. },
  112. methods: {
  113. cancelHandle() {
  114. this.$emit("cancelHandle", 2);
  115. },
  116. // 校验文件和大小
  117. beforeUploadFile(file) {
  118. let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
  119. let size = file.size / 1024 / 1024; //M
  120. if (extension !== "xlsx" && extension !== "xls") {
  121. this.$message.warning("只能上传后缀是.xlsx和.xls的文件");
  122. return false;
  123. }
  124. if (size > 10) {
  125. this.$message.warning(/* "文件大小不得超过10M" */this.$t('ManualEntryPage.upload_size_msg'));
  126. return false;
  127. }
  128. },
  129. handleStarting() {
  130. this.isLoading = true;
  131. },
  132. // 上传成功之后
  133. handleSuccess(result) {
  134. //兼容下结构
  135. let res = this.$parseData({
  136. headers: {
  137. dk: sessionStorage.getItem('dk')||""
  138. },
  139. data: result
  140. });
  141. if (res.Ret === 200) {
  142. // 0成功 1部分失败 -1全部失败
  143. let str = `
  144. <h2 style="margin-bottom:30px">上传成功</h2>
  145. <p>本次共成功导入${res.Data.SuccessCount}条数据</p>
  146. `;
  147. if (res.Data.Status === 1) {
  148. // this.$message.warning('部分导入失败')
  149. str = `
  150. <h2 style="margin-bottom:30px">部分数据上传成功!</h2>
  151. <p>本次共成功导入${res.Data.SuccessCount}条数据,失败${res.Data.FailCount}条</p>
  152. <a style="display:inline;color:#5882EF;" href="${this.downloadErrorlist}" download>下载失败列表</a>
  153. `;
  154. } else if (res.Data.Status === -1) {
  155. // this.$message.success("导入成功!");
  156. str = `
  157. <h2 style="margin-bottom:30px">上传失败!</h2>
  158. <a style="display:inline;color:#5882EF;" href="${this.downloadErrorlist}" download>下载失败列表</a>
  159. `;
  160. }
  161. this.$alert(str, "", {
  162. dangerouslyUseHTMLString: true,
  163. center: true,
  164. showConfirmButton: false,
  165. });
  166. this.$emit("importSuccess");
  167. } else {
  168. this.$message.warning(res.Msg);
  169. }
  170. this.isLoading = false;
  171. },
  172. // 下载模板
  173. // downLoad() {
  174. // dataInterence.downTemplate().then(res => {})
  175. // },
  176. },
  177. created() {},
  178. mounted() {},
  179. };
  180. </script>
  181. <style lang="scss" scoped>
  182. .dialog-cont {
  183. max-width: 800px;
  184. .down-min {
  185. position: relative;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. text-align: center;
  190. margin: 100px 0 90px;
  191. .arrow-ico {
  192. width: 140px;
  193. height: 14px;
  194. display: block;
  195. background: url("~@/assets/img/data_m/arrow_ico.png") no-repeat center;
  196. background-size: 100%;
  197. margin: 0 50px;
  198. }
  199. .icon {
  200. width: 100px;
  201. height: 100px;
  202. display: block;
  203. margin-bottom: 36px;
  204. &.down_ico {
  205. background: url("~@/assets/img/data_m/down_ico.png") no-repeat center;
  206. background-size: cover;
  207. }
  208. &.up_ico {
  209. background: url("~@/assets/img/data_m/up_ico.png") no-repeat center;
  210. background-size: cover;
  211. }
  212. }
  213. }
  214. .down-tip-txt {
  215. font-size: 14px;
  216. color: #1f2e4d;
  217. line-height: 25px;
  218. padding-bottom: 10px;
  219. span {
  220. display: block;
  221. margin-bottom: 18px;
  222. }
  223. }
  224. }
  225. </style>