index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <div class="body">
  3. <div class="content">
  4. <!-- 头部内容 -->
  5. <div class="header">
  6. <div class="img"></div>
  7. </div>
  8. <!-- 分割盒子 -->
  9. <div class="line"></div>
  10. <!-- 文件解析内容区域 -->
  11. <div class="box">
  12. <div class="box_header">文件解析</div>
  13. <div class="box_info">智能解析钉钉考勤表的工具</div>
  14. <div class="box_info2">快速、在线、无限制</div>
  15. <div class="form">
  16. <!-- 上传文件区域 -->
  17. <!-- 默认展示页面区域 -->
  18. <el-upload
  19. class="upload-demo"
  20. v-if="showPage == 1"
  21. :drag="hasDrag"
  22. action="none"
  23. :auto-upload="false"
  24. :limit="1"
  25. accept=".xls,.xlsx"
  26. :on-change="handleUpload"
  27. :on-exceed="handleExceed"
  28. >
  29. <div class="choose">选择文件</div>
  30. <div class="message">或拖放文件到这</div>
  31. <div class="tips">tips:只能上传xls/xlsx文件</div>
  32. </el-upload>
  33. <!-- 上传时展示的页面区域 -->
  34. <div class="upload-demo" v-if="showPage == 2">
  35. <div class="choose2">{{ info }}</div>
  36. <div class="message2">
  37. <el-progress
  38. type="line"
  39. text-inside
  40. :stroke-width="26"
  41. :percentage="percentage"
  42. ></el-progress>
  43. </div>
  44. <div class="form_name">
  45. <span>{{ form_name }}</span>
  46. <i class="el-icon-close" @click="handleRemove"></i>
  47. </div>
  48. </div>
  49. <!-- 解析时展示的页面区域 -->
  50. <div class="upload-demo" v-if="showPage == 3">
  51. <div class="choose2">您的任务正在处理,请稍等</div>
  52. <div class="message2">
  53. <el-progress
  54. type="line"
  55. text-inside
  56. :stroke-width="26"
  57. :percentage="parsePercentage"
  58. ></el-progress>
  59. </div>
  60. <div class="form_name">{{ form_name }}</div>
  61. </div>
  62. <!-- 解析完成时展示的区域 -->
  63. <div class="upload-demo" v-if="showPage == 4">
  64. <div class="choose2">您的任务处理完成,用时:{{ time_s }}秒</div>
  65. <div class="form_name">{{ form_name }}</div>
  66. <div class="handle">
  67. <el-button type="primary" icon="el-icon-download">下载</el-button>
  68. <el-button
  69. type="success"
  70. icon="el-icon-view"
  71. @click="handlePreview"
  72. >预览</el-button
  73. >
  74. <el-button type="danger" @click="handleRestart"
  75. >重新开始</el-button
  76. >
  77. </div>
  78. </div>
  79. <!-- 开始按钮 -->
  80. <div class="start" @click="handleStart">开始</div>
  81. </div>
  82. <!-- 设置按钮区域 -->
  83. <div class="button" @click="handleSet"></div>
  84. </div>
  85. <!-- 弹窗区域 -->
  86. <el-drawer
  87. :visible.sync="drawer"
  88. :with-header="false"
  89. :wrapperClosable="false"
  90. size="20%"
  91. >
  92. <div class="drawer_title">设置</div>
  93. <div class="drawer_body">
  94. <div class="drawer_item">
  95. 墨轩湖每日打卡次数为<input v-model="clockIn_mo" type="text" />次
  96. </div>
  97. <div class="drawer_item">
  98. 黄家湖每日打卡次数为<input v-model="clockIn_huang" type="text" />次
  99. </div>
  100. </div>
  101. <div class="drawer_foot">
  102. <el-button class="foot_button" @click="handleClose">取消</el-button>
  103. <el-button class="foot_button" type="primary">保存</el-button>
  104. </div>
  105. </el-drawer>
  106. <!-- 预览表格弹窗 -->
  107. <el-dialog title="预览" :visible.sync="dialogVisible" fullscreen center>
  108. <Form />
  109. </el-dialog>
  110. </div>
  111. </div>
  112. </template>
  113. <script>
  114. import Form from "../Form";
  115. export default {
  116. name: "Home",
  117. components: { Form },
  118. data() {
  119. return {
  120. // 控制页面的切换
  121. showPage: 1,
  122. // 控制弹窗显示隐藏
  123. drawer: false,
  124. // 是否支持拖拽文件上传
  125. hasDrag: true,
  126. // 上传时显示的文字
  127. info: "上传中,请稍等",
  128. // 上传文件进度条数据
  129. percentage: 0,
  130. // 解析文件进度条数据
  131. parsePercentage: 0,
  132. // 定时器
  133. timer: null,
  134. // 文件名称
  135. form_name: "考勤表",
  136. // 墨轩湖打卡次数
  137. clockIn_mo: 4,
  138. // 黄家湖打卡次数
  139. clockIn_huang: 3,
  140. time_s: 1,
  141. // 预览表格弹窗
  142. dialogVisible: false,
  143. };
  144. },
  145. methods: {
  146. // 点击设置按钮回调
  147. handleSet() {
  148. this.drawer = true;
  149. },
  150. // 点击开始按钮回调
  151. handleStart() {
  152. if (this.showPage == 2 && this.percentage == 100) {
  153. this.showPage = 3;
  154. this.timer = setInterval(() => {
  155. this.parsePercentage += 20;
  156. this.time_s += 1;
  157. if (this.parsePercentage >= 100) {
  158. this.parsePercentage = 100;
  159. clearInterval(this.timer);
  160. this.showPage = 4;
  161. }
  162. }, 1000);
  163. } else if (this.showPage == 3) {
  164. this.$message.error("解析中,请勿重复点击");
  165. } else {
  166. this.$message.error("请先上传文件");
  167. }
  168. },
  169. // 文件上传回调
  170. async handleUpload(file) {
  171. if (file) {
  172. this.form_name = file.name;
  173. this.hasDrag = false;
  174. this.showPage = 2;
  175. let formData = new FormData();
  176. formData.append("file", file.raw);
  177. let config = {
  178. onUploadProgress: (progressEvent) => {
  179. // 计算出当前进度
  180. this.percentage =
  181. (progressEvent.loaded / progressEvent.total).toFixed(2) * 100;
  182. },
  183. headers: {
  184. "Content-Type": "multipart/form-data",
  185. "admin_token":
  186. "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjMsImlhdCI6MTY2Mzc0MjY3OCwiZXhwIjoxNjY0OTUyMjc4fQ.tRT4VbTcITCIEp1LfZgXuQpXG9gbK0tq1ljvUI7nW-4",
  187. },
  188. };
  189. let res = await this.$axios.post(
  190. "/api/tuitionpayment/payableinfo/importByExcel",
  191. formData,
  192. config
  193. );
  194. // console.log(res);
  195. if (res.data.success) {
  196. this.info = "上传完成,请点击开始按钮开始解析";
  197. } else {
  198. this.$message.error(res.data.message);
  199. this.percentage = 0;
  200. this.info = res.data.message;
  201. }
  202. } else {
  203. this.$message.error("请先导入文件");
  204. return false;
  205. }
  206. },
  207. // 删除列表文件时的回调
  208. handleRemove() {
  209. this.hasDrag = true;
  210. this.showPage = 1;
  211. this.info = "上传中,请稍等";
  212. this.percentage = 0;
  213. },
  214. // 预览按钮回调
  215. handlePreview() {
  216. this.dialogVisible = true;
  217. },
  218. // 重新开始按钮回调
  219. handleRestart() {
  220. this.hasDrag = true;
  221. this.showPage = 1;
  222. this.info = "上传中,请稍等";
  223. this.percentage = 0;
  224. this.parsePercentage = 0;
  225. },
  226. // 文件超出个数限制时的钩子
  227. handleExceed() {
  228. this.$message.error("只能同时上传一个文件");
  229. },
  230. // 关闭弹窗回调
  231. handleClose() {
  232. this.drawer = false;
  233. },
  234. },
  235. };
  236. </script>
  237. <style lang="scss" scoped>
  238. .body {
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. width: 100vw;
  243. height: 100vh;
  244. background-color: #eee;
  245. .content {
  246. width: 1540px;
  247. height: 870px;
  248. background-color: #fff;
  249. .header {
  250. display: flex;
  251. align-items: center;
  252. height: 125px;
  253. .img {
  254. margin-left: 115px;
  255. width: 280px;
  256. height: 80px;
  257. background: url(@/assets/logo.jpg) no-repeat center;
  258. background-size: 80% 80%;
  259. }
  260. }
  261. .line {
  262. height: 5px;
  263. border: 1px solid #949494;
  264. }
  265. .box {
  266. position: relative;
  267. height: 740px;
  268. .box_header {
  269. height: 100px;
  270. line-height: 100px;
  271. text-align: center;
  272. font-size: 28px;
  273. font-weight: bold;
  274. }
  275. .box_info {
  276. height: 30px;
  277. text-align: center;
  278. }
  279. .box_info2 {
  280. height: 60px;
  281. line-height: 60px;
  282. text-align: center;
  283. }
  284. .form {
  285. height: 550px;
  286. .upload-demo {
  287. display: flex;
  288. flex-direction: column;
  289. align-items: center;
  290. margin: 0 auto;
  291. width: 1214px;
  292. height: 358px;
  293. border: 2px dashed #0040ff;
  294. .choose {
  295. margin: 0 auto;
  296. margin-top: 80px;
  297. width: 110px;
  298. height: 45px;
  299. line-height: 45px;
  300. text-align: center;
  301. border-radius: 5px;
  302. color: #fff;
  303. background-color: #0040ff;
  304. }
  305. .choose2 {
  306. margin: 0 auto;
  307. margin-top: 80px;
  308. height: 45px;
  309. line-height: 45px;
  310. text-align: center;
  311. font-size: 30px;
  312. font-weight: bold;
  313. color: #000;
  314. }
  315. .message {
  316. margin: 0 auto;
  317. margin-top: 45px;
  318. width: 200px;
  319. height: 45px;
  320. line-height: 45px;
  321. text-align: center;
  322. color: #000;
  323. }
  324. .message2 {
  325. margin: 0 auto;
  326. margin-top: 45px;
  327. width: 330px;
  328. }
  329. .tips {
  330. margin-top: 10px;
  331. color: #606266;
  332. }
  333. .form_name {
  334. margin-top: 45px;
  335. font-size: 10px;
  336. color: #606266;
  337. span {
  338. margin-right: 5px;
  339. }
  340. i {
  341. cursor: pointer;
  342. }
  343. }
  344. .handle {
  345. display: flex;
  346. justify-content: space-evenly;
  347. margin-top: 45px;
  348. width: 400px;
  349. height: 45px;
  350. line-height: 45px;
  351. }
  352. }
  353. .start {
  354. margin-top: 15px;
  355. margin-left: 1270px;
  356. width: 110px;
  357. height: 45px;
  358. line-height: 45px;
  359. text-align: center;
  360. border-radius: 15px;
  361. color: #fff;
  362. font-weight: bold;
  363. background-color: #ff6900;
  364. cursor: pointer;
  365. }
  366. }
  367. .button {
  368. position: absolute;
  369. top: 60px;
  370. right: 0;
  371. width: 40px;
  372. height: 40px;
  373. border-radius: 5px;
  374. background: #1890ff url(@/assets/set.png) no-repeat center;
  375. background-size: 60% 60%;
  376. cursor: pointer;
  377. }
  378. }
  379. .drawer_title {
  380. flex: 1;
  381. margin-left: 10px;
  382. font-size: 20px;
  383. font-weight: bold;
  384. line-height: 200%;
  385. }
  386. .drawer_body {
  387. flex: 15;
  388. .drawer_item {
  389. margin: 10px 0 10px 10px;
  390. input {
  391. margin: 0 5px;
  392. width: 20px;
  393. text-align: center;
  394. }
  395. }
  396. }
  397. .drawer_foot {
  398. flex: 2;
  399. text-align: center;
  400. border-top: 1px solid #000;
  401. .foot_button {
  402. margin-top: 25px;
  403. }
  404. }
  405. }
  406. }
  407. // 调整文件拖拽区域的大小
  408. ::v-deep .el-upload-dragger {
  409. width: 1214px;
  410. height: 358px;
  411. border: none;
  412. }
  413. ::v-deep .el-drawer__body {
  414. display: flex;
  415. flex-direction: column;
  416. }
  417. </style>