WXtrialInterface.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="x5-orientation" content="portrait" />
  8. <meta name="screen-orientation" content="portrait" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <!-- 删除苹果默认的工具栏和菜单栏 -->
  12. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  13. <!-- 设置苹果工具栏颜? -->
  14. <meta name="format-detection" content="telphone=no, email=no">
  15. <!-- 忽略页面中的数字识别为电话,忽略email识别 -->
  16. <!-- 启用360浏览器的极速模?(webkit) -->
  17. <meta name="renderer" content="webkit">
  18. <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑? -->
  19. <meta name="HandheldFriendly" content="true">
  20. <!-- 微软的老式浏览? -->
  21. <meta name="MobileOptimized" content="320">
  22. <!-- 不能旋转,问题出在这 -->
  23. <!-- UC强制全屏 -->
  24. <meta name="full-screen" content="yes">
  25. <!-- QQ强制全屏 -->
  26. <meta name="x5-fullscreen" content="true">
  27. <!-- UC应用模式 -->
  28. <meta name="browsermode" content="application">
  29. <!-- QQ应用模式 -->
  30. <meta name="x5-page-mode" content="app">
  31. <!-- windows phone 点击无高? -->
  32. <meta name="msapplication-tap-highlight" content="no">
  33. <link rel="stylesheet" type="text/css" href="css/WXtrialInterface.css" />
  34. <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css" />
  35. <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css" />
  36. </head>
  37. <body class="scroll h-player" style="overscroll-behavior: contain;">
  38. <div class="container" id="player">
  39. <div class="muted" id="btnMuted">
  40. <div class="control-right-img" data-id="1">
  41. <img src="../static/img/xuanfu_icon.png">
  42. </div>
  43. </div>
  44. <div id="wine">
  45. <video id="playerVideo" muted="muted" x5-video-orientation="landscape" playsinline="true" autoplay="true"
  46. webkit-playsinline="true" x5-playsinline="true" x5-video-player-type="h5" x5-video-player-fullscreen="false"
  47. style="pointer-events: none;object-fit: fill;width: 100%;height:100%"></video>
  48. <div id="box"></div>
  49. <audio preload="auto" autoplay controls poster="images/loader-thumb.jpg" id="audioPlayer"
  50. style="position: absolute;top: 0;width: 0;height: 0;"></audio>
  51. </div>
  52. <div class="leftmains">
  53. <div class="PictureQualityMain">
  54. <div class="PictureQuality " data-id="1803000">高清</div>
  55. <div class="PictureQuality avit" data-id="1243000">标清</div>
  56. <div class="PictureQuality" data-id="400000">极速</div>
  57. <div class="PictureQuality" data-id="200">自动</div>
  58. </div>
  59. <div class="operation">
  60. <div class="upload" id="showsuss" data-text="uploads">
  61. <img src="../static/img/wx/shangchuan_icon.png">
  62. <div>上传</div>
  63. </div>
  64. <div class="upload" onclick="showShearPlate()" data-text="Shearplate">
  65. <img src="../static/img/wx/jianqieban_icon.png">
  66. <div>剪贴板</div>
  67. </div>
  68. <div class="upload" id="upload" data-text="Signout">
  69. <img src="../static/img/wx/tuichu_icon.png">
  70. <div>退出</div>
  71. </div>
  72. </div>
  73. </div>
  74. <div class="bottommains">
  75. <div class="botmat1">
  76. <div class="botmat1img" data-text="gengduo">
  77. <img src="../static/img/wx/gengduo_icon.png">
  78. </div>
  79. </div>
  80. <div class="botmat1">
  81. <div class="botmat1img" data-text="home">
  82. <img src="../static/img/wx/home_icon.png">
  83. </div>
  84. </div>
  85. <div class="botmat1">
  86. <div class="botmat1img" data-text="return">
  87. <img src="../static/img/wx/fanhui_icon.png">
  88. </div>
  89. </div>
  90. </div>
  91. <div class="loading"></div>
  92. </div>
  93. <div class="mask">
  94. <div class="box-shear-plate"></div>
  95. <img class="close" onclick="handleClose()" src="img/guanbi_icon@2x.png" alt="">
  96. </div>
  97. <div class="weui-mask_transparent"></div>
  98. <div class="weui-toast weui_loading_toast weui-toast--visible">
  99. <div class="weui_loading"><i class="weui-loading weui-icon_toast"></i></div>
  100. <p class="weui-toast_content">数据加载中</p>
  101. </div>
  102. <body oncontextmenu="Back()">
  103. </body>
  104. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
  105. <script src="https://lf1-cdn-tos.bytegoofy.com/goofy/developer/jssdk/jssdk-1.0.3.js"></script>
  106. <script type="text/javascript" src="../static/js/jquery-1.11.0.min.js"></script>
  107. <script type="text/javascript" src="helper.js"></script>
  108. <script type="text/javascript" src="pcm-player.js"></script>
  109. <script type="text/javascript" src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script>
  110. <script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
  111. <script type="text/javascript" src="WXdraw.js?v=110"></script>
  112. <script type="text/javascript" src="jmuxer.js"></script>
  113. <script>
  114. var isAudioPlay = false;
  115. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  116. var video = document.getElementById("playerVideo");
  117. video.play();
  118. setTimeout(() => { // 抖音环境需要设置延时,不然会有video默认图显示
  119. $.alert({
  120. title: '提示',
  121. text: '开始使用云手机',
  122. onOK: function () {
  123. setTimeout(() => {
  124. isAudioPlay = true;
  125. }, 1000);
  126. }
  127. });
  128. }, 1000)
  129. }else{
  130. $.alert({
  131. title: '提示',
  132. text: '开始使用云手机',
  133. onOK: function () {
  134. var video = document.getElementById("playerVideo");
  135. video.play();
  136. isAudioPlay = true;
  137. }
  138. });
  139. }
  140. var topwinHeight = window.screen.height - window.innerHeight + 30; //计算title top 头部
  141. $('#wine').css({
  142. "width": window.screen.width,
  143. "height": window.screen.height - topwinHeight - 20,
  144. "position": "absolute"
  145. });
  146. $('.loading').css({
  147. "width": window.screen.width,
  148. "height": window.screen.height - topwinHeight - 20
  149. });
  150. var winese = document.createElement("wine");
  151. wine.style.top = "-" + winese + 'px';
  152. var requestCount = 0;
  153. var isVisuable = true;
  154. var isFeed = true;
  155. var isDrag = false;
  156. var isEnough = true;
  157. var isFinish = false;
  158. var delayTime = new Date().getTime();
  159. var curTime = new Date().getTime();
  160. var myVideo = document.getElementById("playerVideo");
  161. Module = {};
  162. Module.onRuntimeInitialized = function () {
  163. isFinish = true;
  164. }
  165. var isWSS = true;
  166. var parameters = GetRequest();
  167. var ip = parameters["ip"];
  168. var appletPushAddress = parameters["appletPushAddress"];
  169. var socketURL = isWSS ? "wss://" + appletPushAddress + "?cardIp=" + ip : "ws://" + appletPushAddress + "?cardIp=" + ip;
  170. // var socketURL = "ws://14.215.128.96:2004";
  171. var jmuxer = new JMuxer({
  172. node: 'playerVideo',
  173. flushingTime: 15,
  174. fps: 30,
  175. mode: 'video',
  176. debug: false
  177. });
  178. window.onload = function () {
  179. curTime = new Date().getTime();
  180. var myPlay = document.getElementById("wine");
  181. myPlay.onkeydown = function (event) {
  182. ExexuteKeyDown(e.keyCode);
  183. }
  184. }
  185. var ws, errorTime = 0;
  186. doConnect();
  187. // 节流
  188. // 设置一个标志
  189. function throttle(fn, delay) {
  190. let flag = true;
  191. errorTime += delay;
  192. return () => {
  193. if (!flag) return;
  194. flag = false;
  195. timer = setTimeout(() => {
  196. fn();
  197. flag = true;
  198. }, delay);
  199. };
  200. }
  201. function doConnect() {
  202. ws = new WebSocket(socketURL);
  203. ws.binaryType = 'arraybuffer';
  204. ws.onclose = function (e) {
  205. ws.close();
  206. throttle(doConnect, 100);
  207. if (errorTime > 1000) {
  208. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  209. tt.miniProgram.switchTab({
  210. url: '/pages/home/home'
  211. })
  212. }else{
  213. wx.miniProgram.switchTab({
  214. url: '/pages/home/home'
  215. })
  216. }
  217. }
  218. }
  219. ws.addEventListener('open', function (event) {
  220. ws.send(ConfigChannel("RK3923C1201900139"));
  221. var checkBuffer = GetScreenState();
  222. ws.send(checkBuffer);
  223. });
  224. ws.addEventListener('error', function (event) {
  225. ws.close();
  226. throttle(doConnect, 100);
  227. if (errorTime > 1000) {
  228. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  229. tt.miniProgram.switchTab({
  230. url: '/pages/home/home'
  231. })
  232. }else{
  233. wx.miniProgram.switchTab({
  234. url: '/pages/home/home'
  235. })
  236. }
  237. }
  238. });
  239. ws.addEventListener('message', function (event) {
  240. var data = ParseProto(event.data); //JAVA服务器转发
  241. ws.send('ping');
  242. if (isAudioPlay) {
  243. $('.weui-mask_transparent').hide();
  244. $('.weui-toast').hide();
  245. $('.loading').hide();
  246. }
  247. var input = new Uint8Array(event.data);
  248. if (data.audio != null && isAudioPlay) { //喂音频
  249. if (input[0] == 0xff) {
  250. if (isFinish) {
  251. decodeAAC(input);
  252. }
  253. }
  254. }
  255. if (data.video != null) { //喂视频
  256. if (isFeed) {
  257. jmuxer.feed(data);
  258. }
  259. }
  260. });
  261. }
  262. document.addEventListener("visibilitychange", function () {
  263. if (document.visibilityState == "visible") {
  264. var buffer = RequestIFrame();
  265. ws.send(buffer);
  266. isVisuable = true;
  267. } else {
  268. isVisuable = false;
  269. isFeed = false;
  270. myVideo.pause();
  271. }
  272. });
  273. myVideo.addEventListener('pause', function () {
  274. isFeed = false;
  275. });
  276. var decodeCount = 1;
  277. var player = new PCMPlayer({
  278. encoding: '16bitInt',
  279. channels: 2,
  280. sampleRate: 44100,
  281. flushingTime: 22,
  282. debug: false
  283. });
  284. function handleClose() {
  285. document.body.addEventListener('touchmove', function (e) {
  286. e.preventDefault()
  287. }, {
  288. passive: false
  289. })
  290. $('.mask').hide();
  291. }
  292. function decodeAAC(data) {
  293. var retPtr = Module._malloc(4 * 5 * 1024); // 接收的数据
  294. var inputPtr = Module._malloc(4 * data.length); // 输入数据
  295. for (var i = 0; i < data.length; i++) {
  296. Module.HEAPU8[(inputPtr) + i] = data[i]; //转换为堆数据
  297. }
  298. var pcmLen = Module._feedData(retPtr, inputPtr, data.length);
  299. if (pcmLen >= 0) {
  300. var pcmData = new Uint8Array(pcmLen);
  301. for (var i = 0; i < pcmLen; i++) {
  302. pcmData[i] = Module.HEAPU8[(retPtr) + i]
  303. }
  304. player.feed(pcmData);
  305. }
  306. decodeCount++;
  307. Module._free(inputPtr);
  308. Module._free(retPtr);
  309. }
  310. //解协议
  311. function ParseProto(data) {
  312. var input = new Uint8Array(data),
  313. duration,
  314. video,
  315. audio;
  316. if (input[0] == 0 && input[1] == 0 && input[2] == 0 && input[3] == 1) {
  317. video = input;
  318. duration = 24;
  319. var nalType = input[4] & 0x1f;
  320. if (!isFeed) {
  321. if (nalType == 0x05 && isVisuable) {
  322. isFeed = true;
  323. }
  324. }
  325. } else if (input[0] == 0xff) {
  326. if (!isEnough) {
  327. requestCount++;
  328. }
  329. audio = input;
  330. if (new Date().getTime() - curTime > 100) {
  331. delayTime = new Date().getTime();
  332. }
  333. curTime = new Date().getTime();
  334. duration = 24;
  335. } else if (input[0] == 0x68) {
  336. if (input[23] == 0x05) { //横竖屏标识
  337. var state = CheckScreenDirection(input.slice(24, 24 + 8));
  338. if (state == 1) {
  339. console.log("安卓卡此时竖屏");
  340. //竖屏处理
  341. resolving = 1;
  342. } else {
  343. console.log("安卓卡此时横屏");
  344. //横屏处理
  345. resolving = 0;
  346. }
  347. }
  348. if (input[23] == 0x0b) {
  349. console.log("多端登陆");
  350. }
  351. }
  352. return {
  353. audio: audio,
  354. video: video,
  355. duration: duration
  356. };
  357. }
  358. function GetRequest() {
  359. var url = location.search; // 获取url中"?"符后的字串
  360. var obj = new Object();
  361. if (url.indexOf("?") != -1) {
  362. var str = url.substr(1);
  363. strs = str.split("&");
  364. for (var i = 0; i < strs.length; i++) {
  365. obj[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  366. }
  367. }
  368. return obj;
  369. }
  370. function Back() {
  371. ExexuteKeyDown(4);
  372. window.event.returnValue = false;
  373. return false;
  374. }
  375. var url = window.location.href;
  376. url = url.split('/');
  377. var baseUrl = url[0] + '//' + url[2];
  378. // var baseUrl = 'http://per.cs.se.androidscloud.com';
  379. var form = {};
  380. $.ajax({
  381. url: baseUrl + "/api/user/v1/config/download/isShow",
  382. data: {},
  383. type: 'get',
  384. dataType: 'json',
  385. success: function (data) {
  386. if (data.data) {
  387. $("#showsuss").show()
  388. } else {
  389. $("#showsuss").hide()
  390. }
  391. }
  392. })
  393. form.clientType = parameters['clientType'];
  394. form.id = parameters['id'];
  395. form.userCardId = parameters['userCardId'];
  396. if (form.clientType == 1) {
  397. form.cardIp = parameters['cardIp'];
  398. form.port = parameters['port'];
  399. form.sn = parameters['sn'];
  400. form.demoTime = parameters['demoTime'];
  401. form.id = parameters['id'];
  402. } else if (form.clientType == 2) { //分享屏幕
  403. $(".leftmains").css({
  404. "right": "-4rem"
  405. })
  406. $('.leftmains').hide()
  407. $('.bottommains').hide()
  408. $('#btnMuted').hide()
  409. form.id = parameters['id'];
  410. form.ip = parameters['ip'];
  411. form.userCardId = parameters['userCardId'];
  412. }
  413. function array_unique(arr) {
  414. return arr.filter(function (e, i) {
  415. return arr.indexOf(e) === i;
  416. })
  417. }
  418. var cutList = [];
  419. function showShearPlate() {
  420. $('.box-shear-plate').empty();
  421. $.ajax({
  422. url: baseUrl + "/api/user/v1/shear/content",
  423. data: {},
  424. headers: {
  425. 'Authorization': form.id //id
  426. },
  427. type: 'get',
  428. dataType: 'json',
  429. success: function (res) {
  430. if (res.status === 0) {
  431. if (res.data.length) {
  432. cutList = array_unique(res.data)
  433. var str = '<div class="title">剪贴板<div onclick="handleClear()" class="btn-clear">清空</div></div><div class="slide-wrapper-content">'
  434. cutList.forEach(function (item) {
  435. str += "<div class='slide-wrapper'><div class='slide-scroll animate-slide-start'><div class='slide-content'><div onclick='handleCopy(\"" + item.content + "\")'>" + item.content + "</div></div><div class='slide-content-button'><button onclick='handleDelete(" + item.id + ")'>删除</button></div></div></div>"
  436. })
  437. str += '</div>'
  438. $('.box-shear-plate').append(str);
  439. } else {
  440. $('.box-shear-plate').append('<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>')
  441. }
  442. $('.mask').show();
  443. initSlider();
  444. } else {
  445. $('.box-shear-plate').append('<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>')
  446. $('.mask').show();
  447. }
  448. }
  449. })
  450. }
  451. // 清空剪贴板
  452. function handleClear() {
  453. var ids = '';
  454. cutList.forEach(function (item) {
  455. ids += 'ids=' + item.id + '&'
  456. });
  457. ids = ids.substring(0, ids.lastIndexOf('&'));
  458. $.confirm("确定清空剪贴板?", function () {
  459. $.ajax({
  460. url: baseUrl + "/api/user/v1/shear/content?" + ids,
  461. headers: {
  462. 'Authorization': form.id //id
  463. },
  464. type: 'DELETE',
  465. dataType: 'json',
  466. success: function (res) {
  467. if (res.status === 0) {
  468. showShearPlate();
  469. } else {
  470. $.toast(res.msg, "text");
  471. }
  472. }
  473. })
  474. });
  475. }
  476. function handleCopy(content) {
  477. $.ajax({
  478. url: baseUrl + "/api/wsi/v1/config/cut",
  479. data: JSON.stringify({
  480. str: content,
  481. userCardId: form.userCardId
  482. }),
  483. headers: {
  484. 'Authorization': form.id //id
  485. },
  486. contentType: "application/json;charset=UTF-8",
  487. type: 'post',
  488. dataType: 'json',
  489. success: function (res) {
  490. if (res.status === 0) {
  491. $.toast('复制成功', "text");
  492. } else {
  493. $.toast(res.msg, "text");
  494. }
  495. }
  496. })
  497. }
  498. // 删除剪贴板
  499. function handleDelete(id) {
  500. $.ajax({
  501. url: baseUrl + "/api/user/v1/shear/content?ids=" + id,
  502. headers: {
  503. 'Authorization': form.id //id
  504. },
  505. type: 'DELETE',
  506. dataType: 'json',
  507. success: function (res) {
  508. if (res.status === 0) {
  509. showShearPlate();
  510. } else {
  511. $.toast(res.msg, "text");
  512. }
  513. }
  514. })
  515. }
  516. function initSlider() {
  517. //手指滑动多少距离就认为是滑成功
  518. //这个值不能太大,否则影响斜着滑动时,垂直滑动的流畅性,也不能太小,太灵敏也不好
  519. var diffXDistance = 50;
  520. //当前滑动的对象
  521. var currentObject;
  522. //上一次滑动的对象
  523. var lastObject;
  524. //是否可以左右滑动,在上下滑的时候禁止左右滑
  525. var canSlide = true;
  526. //用于记录按下的点
  527. var startPoint;
  528. $(".slide-content").css({
  529. width: $(".slide-wrapper").width()
  530. });
  531. document.body.removeEventListener('touchmove', function (e) {
  532. e.preventDefault()
  533. }, {
  534. passive: false
  535. })
  536. $(".slide-scroll").css({
  537. width: $(".slide-wrapper").width() + $(".slide-content-button").width()
  538. })
  539. .on('touchstart', function (e) {
  540. currentObject = this;
  541. startPoint = {
  542. x: e.originalEvent.changedTouches[0].pageX,
  543. y: e.originalEvent.changedTouches[0].pageY
  544. };
  545. })
  546. .on('touchmove', function (e) {
  547. //如果是左右滑动,就禁止上下的滑动
  548. //如果是上下的滑动,就禁止左右滑动
  549. if (Math.abs(e.originalEvent.changedTouches[0].pageX - startPoint.x) > Math.abs(e.originalEvent.changedTouches[0].pageY - startPoint.y)) {
  550. event.preventDefault();
  551. } else {
  552. canSlide = false;
  553. }
  554. })
  555. .on('touchend', function (e) {
  556. //如果是上下滑动,这里就直接返回了
  557. if (!canSlide) {
  558. canSlide = true;
  559. return true;
  560. }
  561. //点击除当前左滑对象之外的任意其他位置
  562. if (lastObject && currentObject != lastObject) {
  563. //右滑→
  564. $(lastObject).removeClass("animate-slide");
  565. //清空上一个左滑的对象
  566. lastObject = undefined;
  567. }
  568. var diffX = e.originalEvent.changedTouches[0].pageX - startPoint.x;
  569. if (diffX < -diffXDistance) {
  570. //左滑←
  571. $(currentObject).addClass("animate-slide");
  572. if (lastObject && lastObject != currentObject) {
  573. //右滑→
  574. $(lastObject).removeClass("animate-slide");
  575. }
  576. //记录上一个左滑的对象
  577. lastObject = currentObject;
  578. } else if (diffX >= diffXDistance) {
  579. if (currentObject == lastObject) {
  580. //右滑→
  581. $(currentObject).removeClass("animate-slide");
  582. //清空上一个左滑的对象
  583. lastObject = undefined;
  584. }
  585. }
  586. });
  587. }
  588. var orientation = 0; //0 竖屏,1横屏
  589. // document.body.addEventListener('touchmove', function (e) {
  590. // e.preventDefault()
  591. // }, {
  592. // passive: false
  593. // })
  594. // //初始化一下就可以了
  595. // var vConsole = new VConsole();
  596. var btnMuted = document.querySelector("#btnMuted");
  597. btnMuted && (function () {
  598. var setHistory = function (left, top) {
  599. try {
  600. localStorage.setItem("muted-btn-loc", JSON.stringify({
  601. left: left,
  602. top: top
  603. }));
  604. } catch (ex) { }
  605. };
  606. var getHistory = function () {
  607. try {
  608. var value = localStorage.getItem("muted-btn-loc");
  609. if (!value) return null;
  610. value = JSON.parse(value);
  611. if (!value) return null;
  612. return value;
  613. } catch (ex) {
  614. return null
  615. }
  616. };
  617. var fixLoc = function (loc) {
  618. var rect = btnMuted.getBoundingClientRect();
  619. rect = {
  620. top: rect.top,
  621. left: rect.left,
  622. width: rect.width,
  623. height: rect.height
  624. }; //部分低版本浏览器,该属性为只读
  625. if (loc) {
  626. rect.left = loc.left;
  627. rect.top = loc.top;
  628. }
  629. var minX = 0;
  630. var minY = 0;
  631. var docRect = document.documentElement.getBoundingClientRect();
  632. var maxY = docRect.height - rect.height;
  633. var maxX = docRect.width - rect.width;
  634. var left = rect.left;
  635. var top = rect.top;
  636. left = Math.min(left, maxX);
  637. left = Math.max(left, minX);
  638. top = Math.min(top, maxY);
  639. top = Math.max(top, minY);
  640. if (loc || top !== rect.top || left !== rect.left) {
  641. btnMuted.style.cssText += "left:" + left + "px;top:" + top + "px;";
  642. }
  643. }
  644. window.addEventListener("resize", function () {
  645. fixLoc();
  646. });
  647. var touchPoint = {
  648. pageY: 0,
  649. pageX: 0
  650. };
  651. var currentLoc = {
  652. top: 0,
  653. left: 0,
  654. curTop: 0,
  655. curLeft: 0
  656. };
  657. var toMove = false;
  658. var touchmove = function (e) {
  659. e.preventDefault();
  660. var point = e.changedTouches[0];
  661. var top = -touchPoint.pageY + point.pageY;
  662. var left = -touchPoint.pageX + point.pageX;
  663. if (toMove) {
  664. top += currentLoc.top;
  665. left += currentLoc.left;
  666. currentLoc.curLeft = left;
  667. currentLoc.curTop = top;
  668. btnMuted.style.cssText += "left:" + left + "px;top:" + top + "px;";
  669. } else {
  670. if (Math.abs(top) >= 5 || Math.abs(left) >= 5) {
  671. toMove = true;
  672. }
  673. }
  674. };
  675. var touchend = function () {
  676. window.removeEventListener("touchmove", touchmove, {
  677. passive: false
  678. });
  679. window.removeEventListener("touchend", touchend, {
  680. passive: false
  681. });
  682. if (toMove) {
  683. setHistory(currentLoc.curLeft, currentLoc.curTop);
  684. fixLoc();
  685. } else {
  686. //按点击处理
  687. var set = $('.control-right-img').attr("data-id")
  688. if (set == '1') {
  689. $('.control-right-img').attr({
  690. "data-id": "2"
  691. })
  692. $(".leftmains").css({
  693. "right": "0rem"
  694. })
  695. } else {
  696. $('.control-right-img').attr({
  697. "data-id": "1"
  698. })
  699. $(".leftmains").css({
  700. "right": "-4rem"
  701. })
  702. }
  703. }
  704. }
  705. btnMuted.addEventListener("touchstart", function (e) {
  706. e.preventDefault();
  707. toMove = false;
  708. var point = e.changedTouches[0];
  709. touchPoint.pageX = point.pageX;
  710. touchPoint.pageY = point.pageY;
  711. var rect = e.target.getBoundingClientRect();
  712. currentLoc.top = rect.top;
  713. currentLoc.left = rect.left;
  714. window.addEventListener("touchmove", touchmove, {
  715. passive: false
  716. });
  717. window.addEventListener("touchend", touchend, {
  718. passive: false
  719. });
  720. }, {
  721. passive: false
  722. });
  723. var history = getHistory();
  724. if (history) {
  725. fixLoc(history);
  726. }
  727. btnMuted.classList.remove("hide");
  728. })();
  729. $(".boximg").on("click", function () {
  730. $(".mainbox").css({
  731. "display": "none"
  732. })
  733. })
  734. // 剪贴板
  735. $(".sboxbu").on("click", function () {
  736. $(".sbox").css({
  737. "display": "none"
  738. })
  739. })
  740. // 剪贴板
  741. $(".uploadss").on("click", function () {
  742. $(".sbox").css({
  743. "display": "none"
  744. })
  745. })
  746. $("#upload").on("click", function () {
  747. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  748. tt.miniProgram.switchTab({
  749. url: '/pages/home/home'
  750. })
  751. }else{
  752. wx.miniProgram.switchTab({
  753. url: '/pages/home/home'
  754. })
  755. }
  756. })
  757. function selectText(x) {
  758. if (document.selection) {
  759. var range = document.body.createTextRange();
  760. range.moveToElementText(x);
  761. range.select();
  762. } else if (window.getSelection) {
  763. var selection = window.getSelection();
  764. var range = document.createRange();
  765. selection.removeAllRanges();
  766. range.selectNodeContents(x);
  767. selection.addRange(range);
  768. }
  769. }
  770. function cp(x) {
  771. $(".mainbox").css({
  772. "display": "none"
  773. })
  774. $(".sbox").css({
  775. "display": "block"
  776. })
  777. selectText(x);
  778. document.execCommand("copy");
  779. }
  780. </script>
  781. <script type="text/javascript" src="aac.js"></script>
  782. </body>
  783. </html>