BatchImport.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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="progressFlag" :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>用时 00:02:32</p>
  65. <p>成功上传 <span class="color-green">{{resultData.success_count}}</span> 条记录,失败 <span class="color-red">{{resultData.cur_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.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="resultData.execute_report_file_url">下载模板</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: [""],
  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. };
  118. },
  119. watch: {},
  120. computed: {
  121. url() {
  122. let userInfor = getToken();
  123. let access_token = "";
  124. if (userInfor) {
  125. let user = JSON.parse(getToken());
  126. access_token = user.access_token;
  127. }
  128. return (
  129. process.env.VUE_APP_BASE_API +
  130. "/FileServer/WebFileUpload?AccessToken=" +
  131. access_token +
  132. "&SecurityLevel=High"
  133. );
  134. },
  135. },
  136. methods: {
  137. handleChangeTabs(value){
  138. this.tabsIndex = value
  139. },
  140. closeDialog(){
  141. this.$emit("closeDialog")
  142. },
  143. handlebeforeUpload(file) {
  144. if (file.size > 100 * 1024 * 1024) {
  145. this.$message.warning('上传文件大小不能超过100M');
  146. return false; // 必须返回false
  147. }
  148. this.alreadyFile = true
  149. },
  150. handleSuccess(response, file, fileList) {
  151. if (response.status == 1) {
  152. this.progressFlag = false
  153. this.file_id = response.file_info_list[0].file_id
  154. this.uploadFlag = true
  155. this.fileList = fileList
  156. this.fileList.forEach((item) => {
  157. if (item.size > 1000 * 1000) {
  158. if (item.size / 1000 / 1000 / 1000 > 1) {
  159. item.fileSize =
  160. (item.size / 1000 / 1000 / 1000).toFixed(2) + "GB";
  161. } else {
  162. item.fileSize =
  163. (item.size / 1000 / 1000).toFixed(2) + "MB";
  164. }
  165. } else {
  166. item.fileSize = (item.size / 1000).toFixed(2) + "KB";
  167. }
  168. });
  169. } else {
  170. this.fileList = [];
  171. this.file_id = ''
  172. this.uploadFlag = false
  173. this.$message.warning(response.msg);
  174. this.alreadyFile = false
  175. this.progressFlag = false
  176. this.percentage = 0
  177. this.alreadyUpload = ''
  178. }
  179. },
  180. handleErmoveFile(){
  181. if(this.progressFlag){
  182. this.$message.warning('文件还未上传成功,不可删除');
  183. return false
  184. }
  185. this.file_id = ''
  186. this.uploadFlag = false
  187. this.fileList = []
  188. this.alreadyFile = false
  189. this.progressFlag = false
  190. this.isStop = false
  191. this.percentage = 0
  192. this.alreadyUpload = ''
  193. this.resultData = null
  194. this.sameUser = 'false'
  195. this.coverUser = []
  196. this.$forceUpdate()
  197. },
  198. uploadVideoProcess(event, file, fileList) {
  199. this.fileList = fileList
  200. this.progressFlag = true; // 显示进度条
  201. this.percentage = parseInt(event.percent); // 动态获取文件上传进度
  202. if (file.size > 1000 * 1000) {
  203. if (file.size / 1000 / 1000 / 1000 > 1) {
  204. this.alreadyUpload =
  205. (file.size / 1000 / 1000 / 1000 / 100*this.percentage).toFixed(2) + "GB";
  206. this.realFileSize = (file.size / 1000 / 1000 / 1000).toFixed(2) + "GB";
  207. } else {
  208. this.alreadyUpload =
  209. (file.size / 1000 / 1000 / 100*this.percentage).toFixed(2) + "MB";
  210. this.realFileSize =
  211. (file.size / 1000 / 1000).toFixed(2) + "MB";
  212. }
  213. } else {
  214. this.alreadyUpload = (file.size / 1000 / 100*this.percentage).toFixed(2) + "KB";
  215. this.realFileSize = (file.size / 1000).toFixed(2) + "KB";
  216. }
  217. if (this.percentage >= 100) {
  218. this.percentage = 100
  219. }
  220. },
  221. // 开始上传
  222. handleUpload(){
  223. if(this.resultData&&this.resultData.is_finish==='true'){
  224. this.$message.warning('已经解析过该文件');
  225. return false
  226. }
  227. if(!this.file_id){
  228. this.$message.warning('请先上传文件');
  229. return false
  230. }
  231. this.loading = true
  232. this.progressFlag = false
  233. this.uploadFlag = false
  234. let MethodName = "/OrgServer/Manager/DataImport/CreateSysUserImportTask";
  235. let data = {
  236. file_id: this.file_id,
  237. is_cover_while_exit_same_user: this.sameUser,
  238. is_update_password_while_cover_user: this.coverUser.indexOf('1')>-1?'true':'false'
  239. }
  240. getLogin(MethodName, data)
  241. .then((res) => {
  242. if(res.status===1){
  243. this.loading = false
  244. this.uploading = true
  245. this.isStop = false
  246. this.timer = setInterval(() => {
  247. if (this.resultData&&this.resultData.is_finish==='true') {
  248. clearInterval(this.timer);
  249. this.timer = null;
  250. this.uploading = false
  251. if(this.coverUser.indexOf('2')>-1){
  252. window.open(this.resultData.archive_file_url, "_blank");
  253. }
  254. }else{
  255. this.handleTaskStatus()
  256. }
  257. }, 1000);
  258. }else{
  259. this.loading = false
  260. this.uploading = false
  261. this.uploadFlag = true
  262. this.isStop = true
  263. clearInterval(this.timer);
  264. }
  265. })
  266. .catch(() => {
  267. clearInterval(this.timer);
  268. this.uploading = false
  269. this.uploadFlag = true
  270. this.isStop = true
  271. this.loading = false
  272. });
  273. },
  274. // 导入任务执行状态
  275. handleTaskStatus(){
  276. let MethodName = "/OrgServer/Manager/DataImport/GetSysUserImportTaskExecuteStatus";
  277. let data = {
  278. is_query_execute_log: 'true',
  279. execute_log_query_top_n: 9999999
  280. }
  281. getLogin(MethodName, data)
  282. .then((res) => {
  283. if(res.status===1){
  284. this.resultData = res
  285. this.execute_log_list = JSON.parse(JSON.stringify(this.resultData.execute_log_list)).reverse()
  286. }
  287. })
  288. .catch(() => {
  289. this.uploading = false
  290. this.loading = false
  291. });
  292. },
  293. // 中断任务
  294. handleInterruptTask(){
  295. this.loading = true
  296. let MethodName = "/OrgServer/Manager/DataImport/InterruptSysUserImportTask";
  297. getLogin(MethodName, {})
  298. .then((res) => {
  299. if(res.status===1){
  300. this.isStop = true
  301. this.loading = false
  302. }
  303. })
  304. .catch(() => {
  305. this.loading = false
  306. });
  307. },
  308. // 导出日志
  309. handleExportLog(){
  310. let href = this.resultData.execute_report_file_url
  311. window.open(href, "_blank");
  312. }
  313. },
  314. created() {
  315. },
  316. mounted() {
  317. },
  318. beforeDestroy() {
  319. },
  320. };
  321. </script>
  322. <style lang="scss" scoped>
  323. .batch-box{
  324. height: 358px;
  325. background: #FFFFFF;
  326. &-top{
  327. height: 56px;
  328. border-bottom: 1px solid rgba(0,0,0,0.08);
  329. }
  330. &-center{
  331. height: 233px;
  332. overflow: auto;
  333. }
  334. &-bottom{
  335. height: 64px;
  336. border-top: 1px solid rgba(0,0,0,0.08);
  337. display: flex;
  338. justify-content: space-between;
  339. align-items: center;
  340. padding: 16px 24px;
  341. .btn-box{
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. .el-button{
  346. font-size: 14px;
  347. padding: 5px 16px;
  348. height: 32px;
  349. .svg-icon,.el-icon-refresh-right{
  350. margin-right: 8px;
  351. }
  352. &.el-button--warning{
  353. background: #FF802B;
  354. border: none;
  355. }
  356. }
  357. }
  358. }
  359. .tabs{
  360. display: flex;
  361. padding: 12px 0;
  362. justify-content: center;
  363. a{
  364. font-size: 14px;
  365. line-height: 22px;
  366. color: #4E5969;
  367. border-radius: 100px;
  368. padding: 5px 16px;
  369. margin-right: 12px;
  370. &:hover{
  371. background: #F2F3F5;
  372. }
  373. &.active{
  374. background: #F2F3F5;
  375. font-weight: 500;
  376. color: #165DFF;
  377. }
  378. }
  379. }
  380. .downLoad{
  381. color: #000;
  382. font-size: 14px;
  383. line-height: 22px;
  384. &:hover{
  385. color: #165DFF;
  386. }
  387. }
  388. .upload-box{
  389. background: #F5F5F5;
  390. padding: 24px;
  391. height: 233px;
  392. }
  393. .file-top{
  394. height: 88px;
  395. padding: 24px 24px 0 24px;
  396. background: #F5F5F5;
  397. display: flex;
  398. .file-content{
  399. flex: 1;
  400. display: flex;
  401. .file{
  402. margin-left: 16px;
  403. flex: 1;
  404. b{
  405. font-size: 12px;
  406. font-style: normal;
  407. font-weight: 600;
  408. line-height: 14px;
  409. color: #242634;
  410. }
  411. }
  412. p{
  413. margin: 0 0 8px 0;
  414. font-size: 14px;
  415. font-weight: 500;
  416. line-height: 16px;
  417. color: #242634;
  418. }
  419. }
  420. .el-icon-error{
  421. width: 16px;
  422. height: 16px;
  423. color: #CCCCCC;
  424. cursor: pointer;
  425. margin: 11px 0 0 14px;
  426. }
  427. }
  428. .file-bottom{
  429. padding: 24px 24px 0 24px;
  430. p{
  431. margin: 0 0 8px 0;
  432. font-size: 14px;
  433. line-height: 22px;
  434. color: #4E5969;
  435. }
  436. .el-radio-group,.el-checkbox-group{
  437. padding: 5px 0;
  438. margin-bottom: 8px;
  439. }
  440. .el-radio{
  441. margin-right: 24px;
  442. }
  443. .el-checkbox{
  444. margin-right: 16px;
  445. }
  446. .el-checkbox:last-of-type{
  447. margin-right: 0;
  448. }
  449. }
  450. .el-progress{
  451. margin-bottom: 8px;
  452. }
  453. .file-uploading{
  454. display: flex;
  455. justify-content: space-between;
  456. font-size: 12px;
  457. line-height: 14px;
  458. color: #242634;
  459. .progress{
  460. font-weight: 600;
  461. }
  462. }
  463. .log-box{
  464. background: #F5F5F5;
  465. padding: 8px 16px;
  466. min-height: 233px;
  467. p{
  468. font-size: 14px;
  469. font-weight: 400;
  470. line-height: 22px;
  471. margin: 0;
  472. color: #000;
  473. }
  474. .border{
  475. border-bottom: 1px dashed #000;
  476. margin: 16px 0;
  477. }
  478. }
  479. }
  480. </style>
  481. <style lang="scss">
  482. .upload-box{
  483. .el-upload,.el-upload-dragger{
  484. width: 100%;
  485. }
  486. .el-upload-dragger{
  487. background: #F5F5F5;
  488. border-radius: 24px;
  489. padding: 24px;
  490. border: 2px dashed var(--grey-03, #E2E6EA);
  491. display: flex;
  492. align-items: center;
  493. font-weight: 400;
  494. line-height: 22px;
  495. font-size: 14px;
  496. color: #000;
  497. span{
  498. display: block;
  499. font-size: 12px;
  500. color: #86909C;
  501. font-size: 12px;
  502. line-height: 20px;
  503. word-break: break-word;
  504. }
  505. }
  506. }
  507. </style>