BatchImport.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <div class="batch-box">
  3. <div class="batch-box-top tabs">
  4. <a :class="[tabsIndex===0?'active':'']" @click="handleChangeTabs(0)">批量上传</a>
  5. <a :class="[tabsIndex===1?'active':'']" @click="handleChangeTabs(1)">日志</a>
  6. </div>
  7. <div class="batch-box-center">
  8. <template v-if="tabsIndex===0">
  9. <div class="upload-box" v-if="!alreadyFile">
  10. <el-upload
  11. class="upload-demo"
  12. :accept="'.xls,.xlsx'"
  13. :limit="1"
  14. :on-progress="uploadVideoProcess"
  15. :before-upload="handlebeforeUpload"
  16. :on-success="handleSuccess"
  17. drag
  18. :action="url"
  19. :show-file-list="false"
  20. multiple>
  21. <div class="el-upload__text">
  22. 点击或拖拽文件到此处上传
  23. <span>只有 xlsx, xls 格式文件可以上传,文件大小不得超过 100MB</span>
  24. </div>
  25. </el-upload>
  26. </div>
  27. <template v-else>
  28. <div class="file-top">
  29. <div class="file-content">
  30. <svg-icon icon-class="xlsx"></svg-icon>
  31. <div class="file">
  32. <p v-if="fileList[0]&&fileList[0].name">{{fileList[0].name}}</p>
  33. <el-progress v-if="resultData" :percentage="percentage" :show-text="false"></el-progress>
  34. <b v-if="fileList[0]&&fileList[0].fileSize&&!progressFlag&&!uploading&&!resultData">{{fileList[0].fileSize}}</b>
  35. <!-- <div class="file-uploading" v-if="progressFlag">
  36. <span class="progress" v-if="realFileSize">{{'上传文件 '+alreadyUpload+'/'+realFileSize}}</span>
  37. <span>{{percentage}}%</span>
  38. </div> -->
  39. <div class="file-uploading" v-if="resultData">
  40. <span class="progress">{{'导入数据 '+resultData.cur_count+'/'+resultData.total_count}}</span>
  41. <span class="color-green" v-if="resultData.is_finish==='true'">完成</span>
  42. <span class="color-red" v-if="resultData.is_finish==='false'&&resultData.is_end==='true'">网络链接已中断</span>
  43. </div>
  44. </div>
  45. </div>
  46. <i class="el-icon-error" @click="handleErmoveFile"></i>
  47. </div>
  48. <div class="file-bottom">
  49. <p>批量上传内容与系统中有重复时</p>
  50. <el-radio-group v-model="sameUser" :disabled="uploading||(resultData&&resultData.is_finish==='true')">
  51. <el-radio label="false">跳过</el-radio>
  52. <el-radio label="true">覆盖</el-radio>
  53. </el-radio-group>
  54. <el-checkbox-group v-model="coverUser" :disabled="uploading||(resultData&&resultData.is_finish==='true')">
  55. <el-checkbox label="1">覆盖时忽略密码</el-checkbox>
  56. <el-checkbox label="2">上传完成后自动导出密码文件</el-checkbox>
  57. </el-checkbox-group>
  58. </div>
  59. </template>
  60. </template>
  61. <template v-else>
  62. <div class="log-box" v-if="resultData">
  63. <p>上传文件 {{fileList[0].name}}</p>
  64. <p>用时 {{realFormatSecond(uploadTime+resultData.execute_duration)}}</p>
  65. <p>成功上传 <span class="color-green">{{resultData.success_count}}</span> 条记录,失败 <span class="color-red">{{resultData.error_count}}</span> 条</p>
  66. <div class="border"></div>
  67. <p :class="[item.is_success==='true'?'color-green':'color-red']" v-for="(item,index) in execute_log_list" :key="index">
  68. {{item.row_count + ' '+ (item.is_success==='false'?item.error_info:'上传成功')}}
  69. </p>
  70. </div>
  71. </template>
  72. </div>
  73. <div class="batch-box-bottom">
  74. <template v-if="tabsIndex===0">
  75. <a class="downLoad" target="_blank" :href="exportUrl">下载模板</a>
  76. <div class="btn-box">
  77. <el-button @click="closeDialog" size="small">取消</el-button>
  78. <el-button type="primary" :key="3" :disabled="!uploadFlag&&!file_id||(resultData&&resultData.is_finish==='true')" v-if="!uploading&&!isStop&&(resultData&&resultData.is_finish==='true'||!resultData)" @click="handleUpload" v-loading="loading"><svg-icon icon-class="upload"></svg-icon>开始上传</el-button>
  79. <el-button type="primary" v-if="uploading&&!isStop" v-loading="loading" @click="handleInterruptTask"><svg-icon icon-class="pause-fill"></svg-icon>暂停</el-button>
  80. <el-button type="warning" v-if="isStop" v-loading="loading" @click="handleUpload"><i class="el-icon-refresh-right"></i>重试</el-button>
  81. </div>
  82. </template>
  83. <template v-else>
  84. <div class="btn-box" style="flex:1">
  85. <el-button :key="1" type="primary" :disabled="!(resultData&&resultData.is_finish==='true')" @click="handleExportLog"><svg-icon icon-class="upload"></svg-icon>导出日志</el-button>
  86. </div>
  87. </template>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import { getToken } from "../../utils/auth";
  93. import { getLogin } from "@/api/ajax";
  94. export default {
  95. components: {},
  96. name: "batchImport",
  97. props: ["exportUrl"],
  98. data() {
  99. return {
  100. tabsIndex: 0,
  101. alreadyFile: false, // 上传了需要解析的文件
  102. file_id: '',
  103. uploadFlag: false, // 是否可以点击开始上传按钮
  104. uploading: false, // 上传中
  105. isStop: false, // 暂停
  106. fileList: [],
  107. sameUser: 'false', // 存在相同的用户是否覆盖, true 覆盖,false 跳过。
  108. coverUser: [], // 覆盖用户时是否更新用户密码, true 更新,false 不更新。
  109. progressFlag:false,
  110. percentage:0,
  111. alreadyUpload:'', // 已经上传的大小
  112. realFileSize: '', // 文件真实大小
  113. loading: false,
  114. timer: null,
  115. resultData: null, // 上传结果数据
  116. execute_log_list: [], // 日志列表
  117. uploadTime: 0,
  118. uploadTimer: null,
  119. id:this.$route.query.id?this.$route.query.id:''
  120. };
  121. },
  122. watch: {},
  123. computed: {
  124. url() {
  125. let userInfor = getToken();
  126. let access_token = "";
  127. if (userInfor) {
  128. let user = JSON.parse(getToken());
  129. access_token = user.access_token;
  130. }
  131. return (
  132. process.env.VUE_APP_BASE_API +
  133. "/FileServer/WebFileUpload?AccessToken=" +
  134. access_token +
  135. "&SecurityLevel=High"
  136. );
  137. },
  138. },
  139. methods: {
  140. handleChangeTabs(value){
  141. this.tabsIndex = value
  142. },
  143. closeDialog(){
  144. this.$emit("closeDialog")
  145. },
  146. handlebeforeUpload(file) {
  147. if (file.size > 100 * 1024 * 1024) {
  148. this.$message.warning('上传文件大小不能超过100M');
  149. return false; // 必须返回false
  150. }
  151. this.alreadyFile = true
  152. this.uploadTimer = setInterval(() => {
  153. this.uploadTime++
  154. }, 1000);
  155. },
  156. handleSuccess(response, file, fileList) {
  157. if (response.status == 1) {
  158. this.progressFlag = false
  159. clearInterval(this.uploadTimer);
  160. this.file_id = response.file_info_list[0].file_id
  161. this.uploadFlag = true
  162. this.fileList = fileList
  163. this.fileList.forEach((item) => {
  164. if (item.size > 1000 * 1000) {
  165. if (item.size / 1000 / 1000 / 1000 > 1) {
  166. item.fileSize =
  167. (item.size / 1000 / 1000 / 1000).toFixed(2) + "GB";
  168. } else {
  169. item.fileSize =
  170. (item.size / 1000 / 1000).toFixed(2) + "MB";
  171. }
  172. } else {
  173. item.fileSize = (item.size / 1000).toFixed(2) + "KB";
  174. }
  175. });
  176. } else {
  177. this.fileList = [];
  178. this.file_id = ''
  179. this.uploadFlag = false
  180. this.$message.warning(response.msg);
  181. this.alreadyFile = false
  182. this.progressFlag = false
  183. this.percentage = 0
  184. this.alreadyUpload = ''
  185. this.uploadTime = 0
  186. clearInterval(this.uploadTimer);
  187. }
  188. },
  189. handleErmoveFile(){
  190. if(this.progressFlag){
  191. this.$message.warning('文件还未上传成功,不可删除');
  192. return false
  193. }
  194. this.file_id = ''
  195. this.uploadFlag = false
  196. this.fileList = []
  197. this.alreadyFile = false
  198. this.progressFlag = false
  199. this.isStop = false
  200. this.percentage = 0
  201. this.alreadyUpload = ''
  202. this.resultData = null
  203. this.sameUser = 'false'
  204. this.coverUser = []
  205. this.uploadTime = 0
  206. },
  207. uploadVideoProcess(event, file, fileList) {
  208. this.fileList = fileList
  209. this.progressFlag = true; // 显示进度条
  210. this.percentage = parseInt(event.percent); // 动态获取文件上传进度
  211. if (file.size > 1000 * 1000) {
  212. if (file.size / 1000 / 1000 / 1000 > 1) {
  213. this.alreadyUpload =
  214. (file.size / 1000 / 1000 / 1000 / 100*this.percentage).toFixed(2) + "GB";
  215. this.realFileSize = (file.size / 1000 / 1000 / 1000).toFixed(2) + "GB";
  216. } else {
  217. this.alreadyUpload =
  218. (file.size / 1000 / 1000 / 100*this.percentage).toFixed(2) + "MB";
  219. this.realFileSize =
  220. (file.size / 1000 / 1000).toFixed(2) + "MB";
  221. }
  222. } else {
  223. this.alreadyUpload = (file.size / 1000 / 100*this.percentage).toFixed(2) + "KB";
  224. this.realFileSize = (file.size / 1000).toFixed(2) + "KB";
  225. }
  226. if (this.percentage >= 100) {
  227. this.percentage = 100
  228. }
  229. },
  230. // 开始上传
  231. handleUpload(){
  232. if(this.resultData&&this.resultData.is_finish==='true'){
  233. this.$message.warning('已经解析过该文件');
  234. return false
  235. }
  236. if(!this.file_id){
  237. this.$message.warning('请先上传文件');
  238. return false
  239. }
  240. this.percentage = 0
  241. this.loading = true
  242. this.progressFlag = false
  243. this.uploadFlag = false
  244. let MethodName = "/OrgServer/Manager/DataImport/CreatePersonImportTask";
  245. let data = {
  246. file_id: this.file_id,
  247. org_id: this.id,
  248. is_cover_while_exit_same_user: this.sameUser,
  249. is_update_password_while_cover_user: this.coverUser.indexOf('1')>-1?'true':'false'
  250. }
  251. getLogin(MethodName, data)
  252. .then((res) => {
  253. if(res.status===1){
  254. this.loading = false
  255. this.uploading = true
  256. this.isStop = false
  257. this.timer = setInterval(() => {
  258. if (this.resultData&&this.resultData.is_finish==='true') {
  259. clearInterval(this.timer);
  260. this.timer = null;
  261. this.uploading = false
  262. this.percentage = parseInt(this.resultData.cur_count/this.resultData.total_count)*100
  263. if(this.coverUser.indexOf('2')>-1){
  264. window.open(this.resultData.archive_file_url, "_blank");
  265. }
  266. }else{
  267. this.handleTaskStatus()
  268. }
  269. }, 1000);
  270. }else{
  271. this.loading = false
  272. this.uploading = false
  273. this.uploadFlag = true
  274. this.isStop = true
  275. clearInterval(this.timer);
  276. }
  277. })
  278. .catch(() => {
  279. clearInterval(this.timer);
  280. this.uploading = false
  281. this.uploadFlag = true
  282. this.isStop = true
  283. this.loading = false
  284. });
  285. },
  286. // 导入任务执行状态
  287. handleTaskStatus(){
  288. let MethodName = "/OrgServer/Manager/DataImport/GetPersonImportTaskExecuteStatus";
  289. let data = {
  290. is_query_execute_log: 'true',
  291. execute_log_query_top_n: 9999999
  292. }
  293. getLogin(MethodName, data)
  294. .then((res) => {
  295. if(res.status===1){
  296. this.resultData = res
  297. this.execute_log_list = JSON.parse(JSON.stringify(this.resultData.execute_log_list)).reverse()
  298. }
  299. })
  300. .catch(() => {
  301. this.uploading = false
  302. this.loading = false
  303. });
  304. },
  305. // 中断任务
  306. handleInterruptTask(){
  307. this.loading = true
  308. let MethodName = "/OrgServer/Manager/DataImport/InterruptPersonImportTask";
  309. getLogin(MethodName, {})
  310. .then((res) => {
  311. if(res.status===1){
  312. this.isStop = true
  313. this.loading = false
  314. }
  315. })
  316. .catch(() => {
  317. this.loading = false
  318. });
  319. },
  320. // 导出日志
  321. handleExportLog(){
  322. let href = this.resultData.execute_report_file_url
  323. window.open(href, "_blank");
  324. },
  325. // 将整数转换成 时:分:秒的格式
  326. realFormatSecond(value) {
  327. let theTime = parseInt(value); // 秒
  328. let theTime1 = 0; // 分
  329. let theTime2 = 0; // 小时
  330. if (theTime > 60) {
  331. theTime1 = parseInt(theTime / 60);
  332. theTime = parseInt(theTime % 60);
  333. if (theTime1 > 60) {
  334. theTime2 = parseInt(theTime1 / 60);
  335. theTime1 = parseInt(theTime1 % 60);
  336. }
  337. }
  338. let result = String(parseInt(theTime));
  339. if (result < 10) {
  340. result = "0" + result;
  341. }
  342. if (theTime1 > 0) {
  343. result = String(parseInt(theTime1)) + ":" + result;
  344. if (theTime1 < 10) {
  345. result = "0" + result;
  346. }
  347. } else {
  348. result = "00:" + result;
  349. }
  350. if (theTime2 > 0) {
  351. result = String(parseInt(theTime2)) + ":" + result;
  352. if (theTime2 < 10) {
  353. result = "0" + result;
  354. }
  355. } else {
  356. result = "00:" + result;
  357. }
  358. return result;
  359. },
  360. },
  361. created() {
  362. },
  363. mounted() {
  364. },
  365. beforeDestroy() {
  366. },
  367. };
  368. </script>
  369. <style lang="scss" scoped>
  370. .batch-box{
  371. height: 358px;
  372. background: #FFFFFF;
  373. &-top{
  374. height: 56px;
  375. border-bottom: 1px solid rgba(0,0,0,0.08);
  376. }
  377. &-center{
  378. height: 233px;
  379. overflow: auto;
  380. }
  381. &-bottom{
  382. height: 64px;
  383. border-top: 1px solid rgba(0,0,0,0.08);
  384. display: flex;
  385. justify-content: space-between;
  386. align-items: center;
  387. padding: 16px 24px;
  388. .btn-box{
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. .el-button{
  393. font-size: 14px;
  394. padding: 5px 16px;
  395. height: 32px;
  396. .svg-icon,.el-icon-refresh-right{
  397. margin-right: 8px;
  398. }
  399. &.el-button--warning{
  400. background: #FF802B;
  401. border: none;
  402. }
  403. }
  404. }
  405. }
  406. .tabs{
  407. display: flex;
  408. padding: 12px 0;
  409. justify-content: center;
  410. a{
  411. font-size: 14px;
  412. line-height: 22px;
  413. color: #4E5969;
  414. border-radius: 100px;
  415. padding: 5px 16px;
  416. margin-right: 12px;
  417. &:hover{
  418. background: #F2F3F5;
  419. }
  420. &.active{
  421. background: #F2F3F5;
  422. font-weight: 500;
  423. color: #165DFF;
  424. }
  425. }
  426. }
  427. .downLoad{
  428. color: #000;
  429. font-size: 14px;
  430. line-height: 22px;
  431. &:hover{
  432. color: #165DFF;
  433. }
  434. }
  435. .upload-box{
  436. background: #F5F5F5;
  437. padding: 24px;
  438. height: 233px;
  439. }
  440. .file-top{
  441. height: 88px;
  442. padding: 24px 24px 0 24px;
  443. background: #F5F5F5;
  444. display: flex;
  445. .file-content{
  446. flex: 1;
  447. display: flex;
  448. .file{
  449. margin-left: 16px;
  450. flex: 1;
  451. b{
  452. font-size: 12px;
  453. font-style: normal;
  454. font-weight: 600;
  455. line-height: 14px;
  456. color: #242634;
  457. }
  458. }
  459. p{
  460. margin: 0 0 8px 0;
  461. font-size: 14px;
  462. font-weight: 500;
  463. line-height: 16px;
  464. color: #242634;
  465. }
  466. }
  467. .el-icon-error{
  468. width: 16px;
  469. height: 16px;
  470. color: #CCCCCC;
  471. cursor: pointer;
  472. margin: 11px 0 0 14px;
  473. }
  474. }
  475. .file-bottom{
  476. padding: 24px 24px 0 24px;
  477. p{
  478. margin: 0 0 8px 0;
  479. font-size: 14px;
  480. line-height: 22px;
  481. color: #4E5969;
  482. }
  483. .el-radio-group,.el-checkbox-group{
  484. padding: 5px 0;
  485. margin-bottom: 8px;
  486. }
  487. .el-radio{
  488. margin-right: 24px;
  489. }
  490. .el-checkbox{
  491. margin-right: 16px;
  492. }
  493. .el-checkbox:last-of-type{
  494. margin-right: 0;
  495. }
  496. }
  497. .el-progress{
  498. margin-bottom: 8px;
  499. }
  500. .file-uploading{
  501. display: flex;
  502. justify-content: space-between;
  503. font-size: 12px;
  504. line-height: 14px;
  505. color: #242634;
  506. .progress{
  507. font-weight: 600;
  508. }
  509. }
  510. .log-box{
  511. background: #F5F5F5;
  512. padding: 8px 16px;
  513. min-height: 233px;
  514. p{
  515. font-size: 14px;
  516. font-weight: 400;
  517. line-height: 22px;
  518. margin: 0;
  519. color: #000;
  520. }
  521. .border{
  522. border-bottom: 1px dashed #000;
  523. margin: 16px 0;
  524. }
  525. }
  526. }
  527. </style>
  528. <style lang="scss">
  529. .upload-box{
  530. .el-upload,.el-upload-dragger{
  531. width: 100%;
  532. }
  533. .el-upload-dragger{
  534. background: #F5F5F5;
  535. border-radius: 24px;
  536. padding: 24px;
  537. border: 2px dashed var(--grey-03, #E2E6EA);
  538. display: flex;
  539. align-items: center;
  540. font-weight: 400;
  541. line-height: 22px;
  542. font-size: 14px;
  543. color: #000;
  544. span{
  545. display: block;
  546. font-size: 12px;
  547. color: #86909C;
  548. font-size: 12px;
  549. line-height: 20px;
  550. word-break: break-word;
  551. }
  552. }
  553. }
  554. </style>