index.vue 17 KB

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