insertData.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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; margin-right: 5px"
  17. />
  18. <span style="font-size: 16px">{{$t('ManualEntryPage.tit_insert_data')}}</span>
  19. </div>
  20. <div class="down-min">
  21. <dataLoading :loading="isLoading"/>
  22. <div class="section-item">
  23. <h3><!-- 下载导入模板 -->{{$t('ManualEntryPage.down_tem')}}</h3>
  24. <div class="templete-wrap">
  25. <div class="item" v-for="tem in templateList" :key="tem.name">
  26. <a :href="tem.url" download="模板">
  27. <el-button type="primary" icon="el-icon-download">{{tem.name}}</el-button>
  28. </a>
  29. <div>
  30. <img :src="tem.previewImg" alt="" width="150" style="display:block;margin:10px 0;">
  31. <span class="editsty" @click="handlePreviewImg(tem)"><!-- 查看大图 -->{{$t('ManualEntryPage.view_big_img')}}</span>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. <div class="section-item">
  37. <h3><!-- 导入数据 -->{{$t('ManualEntryPage.tit_insert_data')}}</h3>
  38. <el-upload
  39. class="upload-demo"
  40. :before-upload="beforeUploadFile"
  41. multiple
  42. :limit="3"
  43. :headers="headerConfig"
  44. :file-list="fileList"
  45. :on-success="handleSuccess"
  46. :on-progress="handleStarting"
  47. :action="action"
  48. accept=".xlsx"
  49. :data="params"
  50. :name="name"
  51. :show-file-list="false"
  52. >
  53. <el-button type="primary" icon="el-icon-upload">{{$t('ManualEntryPage.tit_insert_data')}}</el-button>
  54. </el-upload>
  55. </div>
  56. </div>
  57. <div class="down-tip-txt">
  58. <span>{{$t('ManualEntryPage.step_one')}}</span>
  59. <span>{{$t('ManualEntryPage.step_two')}}</span>
  60. <span>{{$t('ManualEntryPage.step_three')}}
  61. <a
  62. style="display: inline; color: #0052D9"
  63. :href="downloadErrorlist"
  64. download
  65. >{{$t('ManualEntryPage.down_fail_list')}}</a
  66. >。</span
  67. >
  68. </div>
  69. <el-image-viewer
  70. v-if="showImgViewer"
  71. :on-close="()=>{this.previewList=[];this.showImgViewer = false}"
  72. :url-list="previewList"
  73. />
  74. </el-dialog>
  75. </template>
  76. <script>
  77. import { dataInterence } from "api/api.js";
  78. import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
  79. export default {
  80. name: "",
  81. components: { ElImageViewer },
  82. props: {
  83. isShowinsert: {
  84. type: Boolean,
  85. },
  86. },
  87. data() {
  88. return {
  89. action: process.env.VUE_APP_API_ROOT + "/entry/import/data", //上传文件
  90. downloadErrorlist:
  91. process.env.VUE_APP_API_ROOT +
  92. "/entry/import/failList" +
  93. `?${localStorage.getItem("auth")}`, //失败列表下载
  94. name: "EntryFile",
  95. templateList: [
  96. {
  97. name:/* "模板1" */this.$t('ManualEntryPage.tem_msg',{index:1}),
  98. url: process.env.VUE_APP_API_ROOT + "/entry/template?Source=1",
  99. previewImg: require('@/assets/img/data_m/tem1.png')
  100. },
  101. {
  102. name:/* "模板2" */this.$t('ManualEntryPage.tem_msg',{index:2}),
  103. url: process.env.VUE_APP_API_ROOT + "/entry/template?Source=2",
  104. previewImg: require('@/assets/img/data_m/tem2.png')
  105. },
  106. ],
  107. params: {},
  108. headerConfig: {
  109. Authorization: localStorage.getItem("auth"),
  110. },
  111. isLoading: false,
  112. fileList: [],
  113. showImgViewer: false,
  114. previewList: []
  115. };
  116. },
  117. methods: {
  118. cancelHandle() {
  119. this.$emit('update:isShowinsert',false)
  120. },
  121. // 校验文件和大小
  122. beforeUploadFile(file) {
  123. let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
  124. let size = file.size / 1024 / 1024; //M
  125. if (extension !== "xlsx" && extension !== "xls") {
  126. this.$message.warning("只能上传后缀是.xlsx和.xls的文件");
  127. return false;
  128. }
  129. if (size > 10) {
  130. this.$message.warning(/* "文件大小不得超过10M" */this.$t('ManualEntryPage.upload_size_msg'));
  131. return false;
  132. }
  133. },
  134. handleStarting() {
  135. this.isLoading = true;
  136. },
  137. // 上传成功之后
  138. handleSuccess(result) {
  139. //兼容下结构
  140. let res = this.$parseData({
  141. headers: {
  142. dk: sessionStorage.getItem('dk')||""
  143. },
  144. data: result
  145. });
  146. if (res.Ret === 200) {
  147. // 0成功 1部分失败 -1全部失败
  148. let str = `
  149. <h2 style="margin-bottom:30px">${this.$t('MsgPrompt.upload_success_msg')}</h2>
  150. <p> ${this.$t('ManualEntryPage.upload_tip_msg',{success_count:res.Data.SuccessCount})}</p>
  151. `;
  152. // 本次共成功导入${res.Data.SuccessCount}条数据
  153. if (res.Data.Status === 1) {
  154. // this.$message.warning('部分导入失败')
  155. str = `
  156. <h2 style="margin-bottom:30px">${this.$t('MsgPrompt.upload_some_msg')}</h2>
  157. <p>${this.$t('ManualEntryPage.upload_tip_msg2',{success_count:res.Data.SuccessCount,fail_count:res.Data.FailCount})}</p>
  158. <a style="display:inline;color:#5882EF;" href="${this.downloadErrorlist}" download>${this.$t('ManualEntryPage.down_fail_list2')}</a>
  159. `;
  160. } else if (res.Data.Status === -1) {
  161. // this.$message.success("导入成功!");
  162. str = `
  163. <h2 style="margin-bottom:30px">${this.$t('MsgPrompt.upload_fail_msg')}</h2>
  164. <a style="display:inline;color:#5882EF;" href="${this.downloadErrorlist}" download>${this.$t('ManualEntryPage.down_fail_list2')}</a>
  165. `;
  166. }
  167. this.$alert(str, "", {
  168. dangerouslyUseHTMLString: true,
  169. center: true,
  170. showConfirmButton: false,
  171. });
  172. this.$emit("importSuccess");
  173. } else {
  174. this.$message.warning(res.Msg);
  175. }
  176. this.isLoading = false;
  177. },
  178. handlePreviewImg(item) {
  179. this.previewList=[item.previewImg]
  180. this.showImgViewer=true
  181. }
  182. },
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .dialog-cont {
  187. max-width: 800px;
  188. .down-min {
  189. position: relative;
  190. /* display: flex;
  191. align-items: center;
  192. justify-content: center; */
  193. /* text-align: center; */
  194. margin: 20px 0 50px;
  195. .arrow-ico {
  196. width: 140px;
  197. height: 14px;
  198. display: block;
  199. background: url("~@/assets/img/data_m/arrow_ico.png") no-repeat center;
  200. background-size: 100%;
  201. margin: 0 50px;
  202. }
  203. .icon {
  204. width: 100px;
  205. height: 100px;
  206. display: block;
  207. margin-bottom: 36px;
  208. &.down_ico {
  209. background: url("~@/assets/img/data_m/down_ico.png") no-repeat center;
  210. background-size: cover;
  211. }
  212. &.up_ico {
  213. background: url("~@/assets/img/data_m/up_ico.png") no-repeat center;
  214. background-size: cover;
  215. }
  216. }
  217. }
  218. .down-tip-txt {
  219. font-size: 14px;
  220. color: #1f2e4d;
  221. line-height: 25px;
  222. padding-bottom: 10px;
  223. span {
  224. display: block;
  225. margin-bottom: 18px;
  226. }
  227. }
  228. .section-item {
  229. padding: 20px 0;
  230. &:first-child {
  231. border-bottom: 1px solid #C8CDD9;
  232. }
  233. h3 {
  234. font-size: 16px;
  235. margin-bottom: 20px;
  236. }
  237. .templete-wrap {
  238. display: flex;
  239. gap: 20px;
  240. }
  241. }
  242. }
  243. </style>