index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template>
  2. <div class="app-container apkfile">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
  4. <el-form-item label="关键字" prop="subName" label-width="95px">
  5. <el-input
  6. v-model="queryParams.versionName"
  7. placeholder="版本名称"
  8. clearable
  9. size="small"
  10. />
  11. </el-form-item>
  12. <el-form-item label="设备类型" prop="onepcType" label-width="75px">
  13. <el-select v-model="queryParams.onepcType" placeholder="请选择设备类型" clearable size="small">
  14. <el-option label="管控一体机" value="1" />
  15. <el-option label="考试一体机" value="2" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item style="float: right;">
  19. <el-col :span="1.5">
  20. <p class="add-button-one-90"
  21. style="margin-left:10px;"
  22. @click="upPage"
  23. >上传APK</p>
  24. </el-col>
  25. </el-form-item>
  26. <el-form-item>
  27. <p class="inquire-button-one" @click="handleQuery">查询</p>
  28. <p class="reset-button-one" @click="resetQuery">重置</p>
  29. </el-form-item>
  30. </el-form>
  31. <el-table v-loading="loading" :data="logList">
  32. <el-table-column label="版本名称" align="left" prop="versionName" />
  33. <el-table-column label="版本号" align="left" prop="version" />
  34. <el-table-column label="设备类型" align="left" prop="onepcType" >
  35. <template slot-scope="scope">
  36. <p>{{scope.row.onepcType==1?'管控一体机':(scope.row.onepcType==2?'考试一体机':'')}}</p>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="说明信息" align="left" prop="apkInfo" :show-overflow-tooltip="true"/>
  40. <el-table-column label="APK大小" align="left" prop="fileData" >
  41. <template slot-scope="scope" v-if="scope.row.fileData">
  42. <p>{{scope.row.fileData.size}}</p>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="创建人" align="left" prop="createBy" />
  46. <el-table-column label="创建时间" align="left" prop="createTime" />
  47. <el-table-column label="操作" align="left" width="160">
  48. <template slot-scope="scope">
  49. <div style="display: flex;justify-content: flex-start;">
  50. <p style="color: #0183fa;cursor: pointer" @click="handleClick('',scope.row,'download')">下载</p>
  51. <p style="color: #0183fa;cursor: pointer;margin-left: 20px" @click="handleClick('',scope.row,'edit')">编辑</p>
  52. <p style="color: #0183fa;cursor: pointer;margin-left: 20px" @click="handleClick('',scope.row,'delete')">删除</p>
  53. </div>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <pagination :page-sizes="[20, 30, 40, 50]"
  58. v-show="total>0"
  59. :total="total"
  60. layout="total, prev, pager, next, sizes, jumper"
  61. :page.sync="queryParams.pageNum"
  62. :limit.sync="queryParams.pageSize"
  63. @pagination="getList"
  64. />
  65. <!--上传APK-->
  66. <el-dialog title="上传APK" class="dialog-up-data-box" :visible.sync="openUp" v-if="openUp" width="570px" append-to-body :close-on-click-modal="false">
  67. <div class="dialog-up-data-min-box scrollbar-box">
  68. <el-form v-loading="loading" :rules="apkRules" :model="upForm" ref="upForm" :inline="true" v-show="showSearch">
  69. <el-form-item label="版本名称" prop="versionName" label-width="90px">
  70. <el-input
  71. v-model="upForm.versionName"
  72. maxLength="20"
  73. placeholder="请输入版本名称"
  74. clearable
  75. style="width: 300px"
  76. />
  77. </el-form-item>
  78. <el-form-item label="版本编号" prop="version" label-width="90px">
  79. <el-input
  80. v-model="upForm.version"
  81. maxLength="20"
  82. placeholder="请输入版本编号"
  83. clearable
  84. style="width: 300px"
  85. />
  86. </el-form-item>
  87. <el-form-item label="版本描述" prop="apkInfo" label-width="90px">
  88. <el-input
  89. type="textarea"
  90. v-model="upForm.apkInfo"
  91. maxLength="800"
  92. placeholder="请输入版本描述"
  93. clearable
  94. :rows="5"
  95. show-word-limit
  96. style="width: 300px;"
  97. />
  98. </el-form-item>
  99. <el-form-item label="类型" prop="onepcType" style="display: block" label-width="90px">
  100. <el-radio v-model="upForm.onepcType" label="1">管控一体机</el-radio>
  101. <el-radio v-model="upForm.onepcType" label="2">考试一体机</el-radio>
  102. </el-form-item>
  103. <el-form-item label="安装包" prop="apkFileUpload" label-width="90px">
  104. <uploader
  105. :autoStart="false"
  106. :options="options"
  107. ref="uploader"
  108. :file-list="fileList"
  109. :file-status-text="statusText"
  110. class="uploader-example"
  111. @file-complete="fileComplete"
  112. @complete="complete"
  113. @file-success="fileSuccess"
  114. @files-added="filesAdded">
  115. <uploader-unsupport></uploader-unsupport>
  116. <uploader-drop>
  117. <i class="el-icon-upload"></i>
  118. <div class="el-upload__text">将文件拖到此处,或 <uploader-btn :single="true" :attrs="attrs">点击上传</uploader-btn></div>
  119. </uploader-drop>
  120. <div class="text-box" v-if="fileData.name">
  121. <p>{{fileData.name}}</p>
  122. <p>{{fileData.size}}</p>
  123. <p>{{fileData.text}}</p>
  124. </div>
  125. </uploader>
  126. </el-form-item>
  127. </el-form>
  128. </div>
  129. <div slot="footer" class="dialog-footer">
  130. <el-button type="primary" @click="submitFormUp">确 定</el-button>
  131. <el-button @click="cancelUp">取 消</el-button>
  132. </div>
  133. </el-dialog>
  134. </div>
  135. </template>
  136. <script>
  137. import {
  138. listLog,
  139. apkUploadList,
  140. getApkUploadList,
  141. addApkUpload,
  142. apkUploadDelete,
  143. editApkList
  144. } from '@/api/laboratory/apkfile'
  145. import { getToken } from "@/utils/auth";
  146. import axios from 'axios'
  147. import SparkMD5 from 'spark-md5'
  148. import { delSensor } from '@/api/laboratory/subject'
  149. let httpHeader=window.location.href.split('://')[0]+'://'
  150. export default {
  151. name: "Log",
  152. data() {
  153. return {
  154. headers: {
  155. Authorization: "Bearer " + getToken()
  156. },
  157. // 遮罩层
  158. loading: true,
  159. // 显示搜索条件
  160. showSearch: true,
  161. // 总条数
  162. total: 0,
  163. // apk需要对应升级的日志表格数据
  164. logList: [],
  165. // 查询参数
  166. queryParams: {
  167. pageNum: 1,
  168. pageSize:20,
  169. searchValue: null,
  170. versionName: null,
  171. onepcType: null,
  172. },
  173. openUp:false,
  174. //文件列表
  175. fileList:[],
  176. options: {
  177. target: httpHeader+this.judgmentNetworkReturnAddress()+"/base/file/upload/chunk",
  178. // 开启服务端分片校验功能
  179. testChunks: true,
  180. single: true,
  181. fileParameterName: 'file',
  182. headers: {
  183. Authorization: "Bearer " + getToken()
  184. },
  185. parseTimeRemaining: function (timeRemaining, parsedTimeRemaining) {
  186. return parsedTimeRemaining
  187. .replace(/\syears?/, "年")
  188. .replace(/\days?/, "天")
  189. .replace(/\shours?/, "小时")
  190. .replace(/\sminutes?/, "分钟")
  191. .replace(/\sseconds?/, "秒");
  192. },
  193. // // 服务器分片校验函数
  194. checkChunkUploadedByResponse: (chunk, message) => {
  195. const result = JSON.parse(message);
  196. if (result.data.skipUpload) {
  197. this.skip = true;
  198. return true;
  199. }
  200. return (result.data.uploaded || []).indexOf(chunk.offset + 1) >= 0;
  201. },
  202. },
  203. //上传数据
  204. upForm:{
  205. id:'',
  206. versionName:null,
  207. version:null,
  208. apkInfo:null,
  209. onepcType:null,
  210. apkFileUpload:null,
  211. },
  212. // apk上传表单校验
  213. apkRules: {
  214. versionName: [
  215. { required: true, message: "请输入版本名称", trigger: "blur" }
  216. ],
  217. apkInfo: [
  218. { required: true, message: "请输入版本描述", trigger: "blur" }
  219. ],
  220. version: [
  221. { required: true, message: "请输入版本编号", trigger: "blur" },
  222. { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
  223. ],
  224. onepcType: [
  225. { required: true, message: "请选择版本类型", trigger: "blur" }
  226. ],
  227. apkFileUpload: [
  228. { required: true, message: "请上传安装包", trigger: "blur" }
  229. ],
  230. },
  231. attrs: {
  232. accept: [".apk"]
  233. },
  234. statusText: {
  235. success: "上传成功",
  236. error: "上传出错了",
  237. uploading: "上传中...",
  238. paused: "暂停中...",
  239. waiting: "等待中...",
  240. cmd5: "计算文件MD5中...",
  241. },
  242. fileData:{},
  243. };
  244. },
  245. created() {
  246. this.getList();
  247. },
  248. methods: {
  249. //版本管理页面开关
  250. upPage(){
  251. this.apkGetList();
  252. this.$set(this,'upForm',{});
  253. this.$set(this,'fileData',{});
  254. this.openUp = true;
  255. },
  256. //apk列表获取
  257. apkGetList() {
  258. this.loading = true;
  259. listLog(this.queryParams).then( response => {
  260. this.apkLogList = response.rows;
  261. this.apkTotal = response.total;
  262. this.loading = false;
  263. });
  264. },
  265. //开始上传
  266. progressUp(event, file, fileList){
  267. this.loading = true;
  268. },
  269. //上传成功
  270. handleAvatarSuccess(res, file,index) {
  271. this.upForm.apkFileUpload = res.data.url;
  272. this.loading = false;
  273. this.$forceUpdate()
  274. },
  275. //上传失败
  276. errorUp(err, file, fileList){
  277. this.loading = false;
  278. },
  279. //上传检查
  280. beforeAvatarUpload(file) {
  281. let type = false;
  282. if (file.type == 'application/vnd.android.package-archive') {
  283. type = true;
  284. }else{
  285. this.$message.error('只能上传APK格式文件');
  286. type = false;
  287. }
  288. console.log('file',file);
  289. return type;
  290. },
  291. // 新增/编辑节点单击事件
  292. handleNodeClick(data) {
  293. this.form.deptId = data;
  294. this.getSubjectDictList(data);
  295. },
  296. // 新增/编辑节点单击事件
  297. handleNodeClick2(data) {
  298. this.$set(this.form, 'apkId', '')
  299. let params = {};
  300. if(data){
  301. params.onepcType = data;
  302. }
  303. console.log("params",params)
  304. getApkUploadList(params).then(response => {
  305. this.$set(this, 'apkIdOptions', response.data)
  306. });
  307. },
  308. handleClick(index,row,doType){
  309. if(doType=='download'){
  310. window.open(window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + row.apkFileUpload)
  311. }else if(doType=='edit'){
  312. this.upForm.id=row.id
  313. this.upForm.versionName=row.versionName
  314. this.upForm.version=row.version
  315. this.upForm.apkInfo=row.apkInfo
  316. this.upForm.onepcType=row.onepcType.toString()
  317. this.upForm.apkFileUpload=row.apkFileUpload
  318. if(row.fileData){
  319. this.upForm.fileData=row.fileData
  320. this.fileData=row.fileData
  321. }
  322. this.openUp=true
  323. }else if(doType=='delete'){
  324. this.$confirm('确认要删除?', "警告", {
  325. confirmButtonText: "确定",
  326. cancelButtonText: "取消",
  327. type: "warning"
  328. }).then(() => {
  329. // 确定
  330. apkUploadDelete(row.id).then((response) => {
  331. this.msgSuccess(response.msg)
  332. this.getList();
  333. });
  334. }).catch(function() {
  335. // 取消
  336. });
  337. }
  338. },
  339. /** 查询apk需要对应升级的日志列表 */
  340. getList() {
  341. this.loading = true;
  342. apkUploadList(this.queryParams).then( response => {
  343. this.total = response.total;
  344. this.loading = false;
  345. this.logList = response.rows;
  346. this.logList.forEach(function(item) {
  347. if(item.fileData){
  348. item.fileData=JSON.parse(item.fileData)
  349. }
  350. })
  351. });
  352. },
  353. /** 搜索按钮操作 */
  354. handleQuery() {
  355. this.queryParams.pageNum = 1;
  356. this.getList();
  357. },
  358. /** 重置按钮操作 */
  359. resetQuery() {
  360. this.queryParams.versionName='';
  361. this.queryParams.onepcType='';
  362. this.handleQuery();
  363. },
  364. fileSuccess(rootFile, file, response, chunk) {
  365. const result = JSON.parse(response);
  366. if (result.code == 200 && !this.skip) {
  367. axios.post(httpHeader+this.judgmentNetworkReturnAddress()+"/base/file/upload/merge", {
  368. identifier: file.uniqueIdentifier,
  369. filename: file.name,
  370. totalChunks: chunk.offset,
  371. },{
  372. headers: {
  373. Authorization: "Bearer " + getToken()
  374. }
  375. }).then((res) => {
  376. if (res.data.code==200) {
  377. this.upForm.apkFileUpload=res.data.data;
  378. } else {
  379. console.log(res);
  380. }
  381. }).catch(function (error) {
  382. console.log(error);
  383. });
  384. } else {
  385. console.log("上传成功,不需要合并");
  386. }
  387. if (this.skip) {
  388. this.skip = false;
  389. }
  390. },
  391. fileComplete(rootFile) {
  392. // 一个根文件(文件夹)成功上传完成。
  393. this.fileName=rootFile.name;
  394. this.fileSize=rootFile.size;
  395. console.log("rootFile",rootFile)
  396. this.fileData = {
  397. name:rootFile.name,
  398. size:(parseInt(rootFile._prevUploadedSize/1024)/1024).toFixed(2)+'MB',
  399. text:"上传完成"
  400. }
  401. },
  402. complete(file) {
  403. console.log("complete file:",file)
  404. // 上传完毕。
  405. },
  406. filesAdded(file, fileList, event) {
  407. this.fileData = {
  408. name:file[0].name,
  409. size:"",
  410. text:"上传中..."
  411. }
  412. console.log("file",file)
  413. console.log("fileList",fileList)
  414. console.log("event",event)
  415. // this.$refs.uploader.fileList = [];
  416. // this.$refs.uploader.files = [];
  417. this.fileList=[];
  418. file.forEach((e) => {
  419. this.fileList.push(e);
  420. this.computeMD5(e);
  421. });
  422. },
  423. computeMD5(file) {
  424. let fileReader = new FileReader();
  425. let time = new Date().getTime();
  426. let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
  427. let currentChunk = 0;
  428. const chunkSize = 1024 * 1024;
  429. let chunks = Math.ceil(file.size / chunkSize);
  430. let spark = new SparkMD5.ArrayBuffer();
  431. // 文件状态设为"计算MD5"
  432. file.cmd5 = true; //文件状态为“计算md5...”
  433. file.pause();
  434. loadNext();
  435. fileReader.onload = (e) => {
  436. spark.append(e.target.result);
  437. if (currentChunk < chunks) {
  438. currentChunk++;
  439. loadNext();
  440. // 实时展示MD5的计算进度
  441. } else {
  442. let md5 = spark.end();
  443. spark.destroy(); //释放缓存
  444. file.uniqueIdentifier = md5; //将文件md5赋值给文件唯一标识
  445. file.cmd5 = false; //取消计算md5状态
  446. file.resume(); //开始上传
  447. }
  448. };
  449. fileReader.onerror = function () {
  450. this.error(`文件${file.name}读取出错,请检查该文件`);
  451. file.cancel();
  452. };
  453. function loadNext() {
  454. let start = currentChunk * chunkSize;
  455. let end = start + chunkSize >= file.size ? file.size : start + chunkSize;
  456. fileReader.readAsArrayBuffer(blobSlice.call(file.file, start, end));
  457. }
  458. },
  459. allStart() {
  460. this.fileList.map((e) => {
  461. if (e.paused) {
  462. e.resume();
  463. }
  464. });
  465. },
  466. allStop() {
  467. this.fileList.map((e) => {
  468. if (!e.paused) {
  469. e.pause();
  470. }
  471. });
  472. },
  473. allRemove() {
  474. this.fileList.map((e) => {
  475. e.cancel();
  476. });
  477. this.fileList = [];
  478. },
  479. // 取消按钮
  480. cancelUp() {
  481. if (this.loading){
  482. return
  483. }
  484. this.fileList=[];
  485. this.fileData = {};
  486. this.openUp = false;
  487. },
  488. //上传apk提交按钮
  489. submitFormUp(){
  490. if(this.loading){
  491. return
  492. }
  493. if(this.upForm.id){//编辑
  494. this.$refs["upForm"].validate(valid => {
  495. if (valid) {
  496. let obj = {
  497. id:this.upForm.id,
  498. versionName:this.upForm.versionName,
  499. version:this.upForm.version,
  500. apkInfo:this.upForm.apkInfo,
  501. onepcType:this.upForm.onepcType,
  502. apkFileUpload:this.upForm.apkFileUpload,
  503. fileData:JSON.stringify(this.fileData),
  504. };
  505. editApkList(obj).then( response => {
  506. this.msgSuccess("编辑成功");
  507. this.getList()
  508. this.openUp = false;
  509. this.upForm = {};
  510. this.fileList=[];
  511. this.fileData = {};
  512. });
  513. }
  514. });
  515. }else{//添加
  516. this.$refs["upForm"].validate(valid => {
  517. if (valid) {
  518. let obj = {
  519. versionName:this.upForm.versionName,
  520. version:this.upForm.version,
  521. apkInfo:this.upForm.apkInfo,
  522. onepcType:this.upForm.onepcType,
  523. apkFileUpload:this.upForm.apkFileUpload,
  524. fileData:JSON.stringify(this.fileData),
  525. };
  526. addApkUpload(obj).then( response => {
  527. this.msgSuccess("新增成功");
  528. this.getList()
  529. this.openUp = false;
  530. this.upForm = {};
  531. this.fileList=[];
  532. this.fileData = {};
  533. });
  534. }
  535. });
  536. }
  537. },
  538. }
  539. };
  540. </script>
  541. <style scoped lang="scss">
  542. .apkfile {
  543. display: flex!important;
  544. flex-direction: column;
  545. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  546. padding:20px 20px 20px!important;
  547. .button-box{
  548. width:90px;
  549. display: flex;
  550. margin:0 auto;
  551. }
  552. }
  553. </style>
  554. <style lang="scss">
  555. .dialog-up-data-box{
  556. .text-box{
  557. width:360px;
  558. display: flex;
  559. p:nth-child(1){
  560. width:200px;
  561. display:block;
  562. overflow:hidden;
  563. text-overflow:ellipsis;
  564. white-space:nowrap;
  565. }
  566. p:nth-child(2){
  567. width:100px;
  568. text-align: center;
  569. }
  570. p:nth-child(3){
  571. width:60px;
  572. text-align: right;
  573. }
  574. }
  575. .dialog-up-data-min-box{
  576. height:500px;
  577. }
  578. .uploader-drop{
  579. width:360px;
  580. .el-icon-upload{
  581. color:#0183FA;
  582. display: block;
  583. font-size:78px;
  584. width:78px;
  585. height:78px;
  586. margin:0 auto;
  587. }
  588. .el-upload__text{
  589. width:210px;
  590. margin:0 auto;
  591. }
  592. .uploader-btn{
  593. border:none;
  594. color:#0183FA;
  595. }
  596. }
  597. .uploader-files{
  598. width:360px;
  599. }
  600. }
  601. </style>