browserDetail.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <link rel="icon" href="../static/img/favicon2.ico" type="img/x-ico">
  7. <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
  8. <title></title>
  9. <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
  10. <script src="../static/js/vender/vue/axios.min.js"></script>
  11. <script src="../static/js/vender/vue/vue.min.js"></script>
  12. <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
  13. <link rel="stylesheet" href="../static/css/browserDetail.css">
  14. <script src="../static/js/vender/jquery-3.4.1.min.js"></script>
  15. <script src="../static/js/vender/config.js"></script>
  16. <script src="../static/js/vender/toastr/toastr.min.js"></script>
  17. <script src="../static/js/vender/vue/config.js"></script>
  18. <script type="text/javascript">
  19. var deviveWidth = document.documentElement.clientWidth;
  20. document.documentElement.style.fontSize = deviveWidth / 7.5 + 'px';
  21. </script>
  22. <script>
  23. toastr.options.positionClass = 'toast-center-center';
  24. // toastr.options.timeOut = '1500';
  25. </script>
  26. </head>
  27. <body>
  28. <div class="container">
  29. <div class="header-wrap">
  30. <!-- <div class="search-wrap" id="search-wrap">
  31. <img class="search-icon" src="../static/img/browser/search-icon2.png" />
  32. <div class="ipt" id="ipt">双子星浏览器</div>
  33. </div> -->
  34. <div class="title-wrap">
  35. <img class="left-arrow" src="../static/img/browser/left-arrow.png" />
  36. <div class="title"></div>
  37. </div>
  38. <div class="tag-wrap"></div>
  39. </div>
  40. <div class="download-wrap">
  41. <div class="download-content"></div>
  42. <div class="loading"></div>
  43. </div>
  44. </div>
  45. <script type="text/javascript">
  46. document.addEventListener("visibilitychange",()=>{
  47. if(document.hidden){
  48. init('visibilitychange');
  49. }else{
  50. init('visibilitychange');
  51. }
  52. })
  53. let title = decodeURIComponent(GetRequest().plateName);
  54. let timer,flag = true;
  55. let labelId = '', pageNum = 1, pageSize = 10, index = 0, recordFlag = true, total = 0, nowlength = 0, isLoading = false, appList= [], downloadObj = {};
  56. $('.title').eq(0).text(title);
  57. (function(){
  58. init();
  59. })();
  60. function init(type){
  61. $.ajax({
  62. url: `${baseUrl}/api/public/v1/browserLabel/client/query/${GetRequest().plateId}`,
  63. type: 'get',
  64. contentType:"application/json",
  65. dataType: 'json',
  66. cache: false,
  67. success: function (res) {
  68. isLoading = false;
  69. let node = '';
  70. $('.tag-wrap').eq(0).text('');
  71. let list = res.data;
  72. if(list.length === 0) {
  73. node = `<div class="none-wrap">
  74. <img class="none-img" src="../static/img/browser/none.png" />
  75. <div class="none-text">没有更多内容哦~</div>
  76. </div>`
  77. $('.download-content').eq(0).append(node);
  78. return
  79. }
  80. labelId = list[0].id;
  81. if(type != 'visibilitychange'){
  82. rankingGet();
  83. }
  84. for(let i=0; i < list.length; i++){
  85. node += `<div class="tag-item ${i === index ? 'active' : ''}" data-id="${list[i].id}" data-index="${i}">${list[i].labelName}</div>`
  86. }
  87. $('.tag-wrap').eq(0).append(node);
  88. }
  89. })
  90. };
  91. function getType() {
  92. return new Promise((resolve, reject) => {
  93. resolve('SVIP');
  94. // $.ajax({
  95. // url: `http://localhost:9888/getType`,
  96. // type: 'get',
  97. // contentType:"application/json",
  98. // dataType: 'json',
  99. // cache: false,
  100. // success: function (res) {
  101. // if(res.code === 200){
  102. // let cardType = res.data.devType;
  103. // let phoneObj = {
  104. // 'VIRTUAL_RK3399': 'VIP',
  105. // 'RK_3399': 'SVIP',
  106. // 'MTK_G90': 'STAR',
  107. // 'QUALCOMM': 'STARPRO'
  108. // }
  109. // phoneType = phoneObj[cardType];
  110. // resolve(phoneType);
  111. // }
  112. // }
  113. // })
  114. })
  115. }
  116. function rankingGet(type){
  117. getType().then((phoneType) => {
  118. $.ajax({
  119. url: `${baseUrl}/api/public/v1/ranking/client/get`,
  120. type: 'post',
  121. data: JSON.stringify({
  122. labelId: +labelId,
  123. phoneType: phoneType,
  124. pageNum: pageNum,
  125. pageSize: pageSize
  126. }),
  127. contentType:"application/json",
  128. dataType: 'json',
  129. cache: false,
  130. success: function (res) {
  131. if(res.status === 0){
  132. appList = res.data.records;
  133. nowlength += appList.length;
  134. total = res.data.total;
  135. recordFlag = true;
  136. let node = '';
  137. if(type != 'down'){
  138. $('.download-content').eq(0).text('');
  139. }
  140. for(let i=0; i < appList.length; i++){
  141. node += `<div class="download-item">
  142. <div class="main-wrap">
  143. <img class="app-icon" src=${fileCenterApi}/document/newFile/download/0/13d0arghebcc4cm49cf04?fileKey=${appList[i].iconKey} />
  144. <div class="app-wrap">
  145. <div class="app-title">${appList[i].appName}</div>
  146. <div class="app-description">${appList[i].introduction}</div>
  147. </div>
  148. </div>
  149. <div class="btn-wrap" data-key="${appList[i].fileKey}" data-id="${appList[i].id}" data-index="${i}" data-md5="${appList[i].md5}">
  150. <div class="progress" data-key="${appList[i].fileKey}" data-id="${appList[i].id}" data-index="${i}" data-md5="${appList[i].md5}"></div>
  151. <text class="text" data-key="${appList[i].fileKey}" data-id="${appList[i].id}" data-index="${i}" data-md5="${appList[i].md5}">下载</text>
  152. </div>
  153. </div>`
  154. }
  155. if(nowlength < total && appList.length !== 0){
  156. $('.loading').eq(0).text('正在努力加载中...');
  157. } else if(nowlength != 0) {
  158. $('.loading').eq(0).text('已加载全部内容');
  159. }
  160. if(appList.length === 0){
  161. node = `<div class="none-wrap">
  162. <img class="none-img" src="../static/img/browser/none.png" />
  163. <div class="none-text">没有更多内容哦~</div>
  164. </div>`
  165. }
  166. $('.download-content').eq(0).append(node);
  167. }else{
  168. stopManyClick(() => {
  169. toastr.error(res.msg);
  170. })
  171. }
  172. }
  173. })
  174. })
  175. };
  176. //点击切换
  177. $('.tag-wrap')[0].addEventListener('click',(e)=>{
  178. if(index === e.target.dataset.index) {
  179. return
  180. }
  181. labelId = e.target.dataset.id;
  182. let className = e.target.className;
  183. if(className.includes('tag-item')){
  184. pageNum = 1;
  185. nowlength = 0;
  186. total = 0;
  187. $('.loading').eq(0).text('');
  188. $('.tag-item')[index].className = 'tag-item';
  189. index = e.target.dataset.index;
  190. $('.tag-item')[index].className = 'tag-item active';
  191. rankingGet();
  192. }
  193. },false);
  194. // // 验证是否下架
  195. // function isGetStatus(id) {
  196. // $.ajax({
  197. // url: `${baseUrl}/api/public/v1/browserLabel/getStatus/${id}`,
  198. // type: 'get',
  199. // contentType:"application/json",
  200. // dataType: 'json',
  201. // cache: false,
  202. // success: function (res) {
  203. // if(res.status === 0){
  204. // } else {
  205. // stopManyClick(() => {
  206. // toastr.error(res.msg);
  207. // })
  208. // }
  209. // }
  210. // })
  211. // }
  212. // 点击下载按钮
  213. $('.download-wrap')[0].addEventListener('click',(e)=>{
  214. let key = e.target.dataset.key;
  215. let md5 = e.target.dataset.md5;
  216. let index = e.target.dataset.index;
  217. let id = e.target.dataset.id;
  218. let className = e.target.className;
  219. if(className === 'btn-wrap btn-active' || e.target.innerText !== '下载'){
  220. return
  221. }
  222. let appName = $('.app-title').eq(index).text();
  223. if(['btn-wrap','progress', 'text'].includes(className)){
  224. $.ajax({
  225. url: `${baseUrl}/api/public/v1/ranking/getstatus/${id}`,
  226. type: 'get',
  227. contentType:"application/json",
  228. dataType: 'json',
  229. cache: false,
  230. success: function (res) {
  231. if(res.status === 0){
  232. const downloadUrl = `${fileCenterApi}/document/newFile/breakpointDownloadFile/13d0arghebcc4cm49cf04?fileKey=${key}`;
  233. window.location.href = downloadUrl;
  234. let xhr = new XMLHttpRequest();
  235. xhr.open('GET', downloadUrl, true);
  236. xhr.addEventListener('progress', function (event) {
  237. // 响应头要有Content-Length
  238. if (event.lengthComputable) {
  239. let percentComplete = event.loaded / event.total;
  240. downloadObj[appName] = {
  241. index: index,
  242. name: appName,
  243. percentComplete: percentComplete
  244. };
  245. }
  246. }, false);
  247. xhr.send();
  248. } else {
  249. stopManyClick(() => {
  250. toastr.error(res.msg);
  251. })
  252. }
  253. }
  254. })
  255. }
  256. },false);
  257. setInterval(() => {
  258. newData();
  259. },2000);
  260. //更新百分数
  261. function newData() {
  262. if(JSON.stringify(downloadObj) == "{}"){
  263. return
  264. }
  265. appList.map((item, index) => {
  266. Object.keys(downloadObj).map((key) => {
  267. if(item.appName === downloadObj[key].name){
  268. // 进度条的位置也是translate,一开始是用translateX(-100%)挪到外面去
  269. $('.btn-wrap')[index].className = 'btn-wrap btn-active';
  270. $('.progress')[index].style.transform = `translateX(${downloadObj[key].percentComplete * 100}%)`;
  271. $('.text').eq(index).text(`${(downloadObj[key].percentComplete * 100).toFixed(1)}%`);
  272. if((downloadObj[key].percentComplete * 100).toFixed(1) == 100){
  273. delete downloadObj[key]
  274. console.log(downloadObj)
  275. $('.text').eq(index).text('下载完成');
  276. }
  277. }
  278. })
  279. })
  280. }
  281. //点击返回按钮
  282. $('.left-arrow')[0].addEventListener('click',()=>{
  283. location.href = './browser.html'
  284. },false);
  285. //数据下拉加载
  286. $('.download-wrap')[0].addEventListener('scroll',function () {
  287. let scrollTop = $('.download-wrap')[0].scrollTop;
  288. let clientHeight = $('.download-wrap')[0].clientHeight;
  289. let scrollHeight = $('.download-wrap')[0].scrollHeight;
  290. if(scrollTop + clientHeight + 10 > scrollHeight){
  291. if(recordFlag && nowlength < total && total > 0){
  292. recordFlag = false;
  293. pageNum++;
  294. rankingGet('down');
  295. }
  296. }
  297. });
  298. //防止提示一秒内重复显示
  299. function stopManyClick(fn) {
  300. if (flag) {
  301. fn();
  302. }
  303. flag = false;
  304. if(timer){clearTimeout(timer);}
  305. timer = setTimeout(() => {flag = true}, 1500);
  306. }
  307. //点击按钮搜索
  308. // const searchDom = document.getElementById("search-wrap");
  309. // searchDom.addEventListener('click',()=>{
  310. // var wd = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu";
  311. // window.open(wd);
  312. // },false);
  313. </script>
  314. </body>
  315. </html>