index.vue 20 KB

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