WXdraw.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. //蒙版
  2. var canvas_bak = document.getElementById("box");
  3. var winHeight = window.screen.height - window.innerHeight;
  4. var vowidth = window.screen.width;
  5. var topwinHeightDraw = window.screen.height - window.innerHeight + 30; // 计算title top 头部
  6. var numse = window.screen.height;
  7. // 计算title top 头部
  8. if (numse <= 70) {
  9. var voheight = window.screen.height - winHeight - 34 - 20
  10. } else {
  11. var voheight = window.screen.height - topwinHeightDraw - 20
  12. }
  13. // 画笔大小
  14. var resolving;
  15. var url = window.location.href;
  16. url = url.split('/');
  17. var parameters = GetRequest();
  18. var form = {};
  19. form.clientType = parameters["clientType"];
  20. form.cardIp = parameters["cardIp"];
  21. form.port = parameters["port"];
  22. form.sn = parameters["sn"];
  23. form.username = parameters["username"];
  24. form.userCardId = parameters["userCardId"];
  25. form.ip = parameters["ip"];
  26. form.domainName = parameters["domainName"];
  27. var isWSS = false;
  28. var cUrl = isWSS ? "wss" : "ws" + "://" + form.domainName + "/card?cardIp=" + form.ip;
  29. var wsss;
  30. doConnect();
  31. function doConnect() {
  32. wsss = new WebSocket(cUrl);
  33. wsss.binaryType = 'arraybuffer';
  34. wsss.onopen = function () {
  35. var pings = {
  36. "event": "getScreenStatus"
  37. }
  38. wsss.send(JSON.stringify(pings));
  39. var bitRate = {
  40. "data": {
  41. "bitRate": 2243000
  42. },
  43. "event": "bitRate"
  44. }
  45. wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
  46. };
  47. wsss.onclose = function (evt) {
  48. console.log(evt.data);
  49. $.confirm({
  50. title: '提示',
  51. text: '连接断开,是否准备重连?',
  52. onOK: function () {
  53. doConnect();
  54. },
  55. onCancel: function () {
  56. wx.miniProgram.switchTab({
  57. url: '/pages/home/home'
  58. })
  59. }
  60. });
  61. };
  62. wsss.onerror = function (evt) {
  63. console.log(evt.data);
  64. $.confirm({
  65. title: '提示',
  66. text: '连接断开,是否准备重连?',
  67. onOK: function () {
  68. doConnect();
  69. },
  70. onCancel: function () {
  71. wx.miniProgram.switchTab({
  72. url: '/pages/home/home'
  73. })
  74. }
  75. });
  76. };
  77. }
  78. $('#box').on("click", function () {
  79. draw_graph('pencil', this)
  80. })
  81. //剪切板
  82. $(".upload").on("click", function () {
  83. var texts = $(this).attr("data-text")
  84. if (texts == "uploads") {
  85. $(".mainbox").css({
  86. "display": "block"
  87. })
  88. $(".sbox").css({
  89. "display": "none"
  90. })
  91. }
  92. })
  93. //home 控制home
  94. $(".botmat1img").on("click", function () {
  95. var codes = $(this).attr("data-text")
  96. if (codes == "home") {
  97. wsss.send(ExexuteKeyBoard(3), form.sn);
  98. } else if (codes == "return") {
  99. wsss.send(ExexuteKeyBoard(4), form.sn);
  100. } else if (codes == "gengduo") {
  101. wsss.send(ExexuteKeyBoard(187), form.sn);
  102. }
  103. })
  104. //高清控制
  105. $(".PictureQuality").on("click", function () {
  106. $(this).addClass("avit").siblings().removeClass('avit')
  107. var id = $(this).attr("data-id")
  108. var bitRate = {
  109. "data": {
  110. "bitRate": id
  111. },
  112. "event": "bitRate"
  113. }
  114. wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
  115. })
  116. //画图形
  117. var draw_graph = function (graphType, obj) {
  118. //把蒙版放于画板上面
  119. $("#container").css("z-index", 30);
  120. $("#dedit").css("z-index", 20);
  121. var canDraw = false;
  122. //鼠标按下获取 开始xy开始画图
  123. var touchstart = function (e) {
  124. $('.control-right-img').attr({
  125. "data-id": "2"
  126. })
  127. $(".leftmains").css({
  128. "right": "-4rem"
  129. })
  130. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  131. //是否横屏
  132. if (resolving == 0) {
  133. var ping;
  134. for (var i = 0; i < touchfor.length; i++) {
  135. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  136. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  137. ping = {
  138. "data": {
  139. "action": 0,
  140. "count": touchfor.length,
  141. "pointerId": i,
  142. "x": cawidthXs.toFixed(2),
  143. "y": caheightYs.toFixed(2)
  144. },
  145. "event": "0"
  146. }
  147. }
  148. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  149. } else {
  150. var ping;
  151. for (var i = 0; i < touchfor.length; i++) {
  152. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  153. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  154. ping = {
  155. "data": {
  156. "action": 0,
  157. "count": touchfor.length,
  158. "pointerId": i,
  159. "x": cawidthXs.toFixed(2),
  160. "y": caheightYs.toFixed(2)
  161. },
  162. "event": "0"
  163. }
  164. }
  165. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn));
  166. }
  167. canDraw = true;
  168. };
  169. //鼠标离开 把蒙版canvas的图片生成到canvas中
  170. var touchend = function (e) {
  171. var touchfor = e.originalEvent.changedTouches; //for 的手指数组
  172. //是否横屏 morePortionUp
  173. if (resolving == 0) {
  174. var ping;
  175. for (var i = 0; i < touchfor.length; i++) {
  176. var cawidthXs = touchfor[i].pageY * (1280 / voheight);
  177. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth);
  178. ping = {
  179. "data": {
  180. "action": 1,
  181. "count": touchfor.length,
  182. "pointerId": i,
  183. "x": cawidthXs.toFixed(2),
  184. "y": caheightYs.toFixed(2)
  185. },
  186. "event": "1"
  187. }
  188. }
  189. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn));
  190. } else {
  191. var ping;
  192. for (var i = 0; i < touchfor.length; i++) {
  193. var cawidthXs = touchfor[i].pageX * (720 / vowidth);
  194. var caheightYs = touchfor[i].pageY * (1280 / voheight);
  195. ping = {
  196. "data": {
  197. "action": 1,
  198. "count": touchfor.length,
  199. "pointerId": i,
  200. "x": cawidthXs.toFixed(2),
  201. "y": caheightYs.toFixed(2)
  202. },
  203. "event": "1"
  204. }
  205. }
  206. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  207. }
  208. canDraw = false;
  209. };
  210. //清空层 云手机超出屏幕的开关
  211. var clearContext = function () {
  212. canDraw = false;
  213. }
  214. // 鼠标移动
  215. var touchmove = function (e) {
  216. e = e || window.event;
  217. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  218. var ping;
  219. //是否横屏 morePortionMove
  220. if (resolving == 0) {
  221. for (var i = 0; i < touchfor.length; i++) {
  222. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  223. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  224. ping = {
  225. "data": {
  226. "action": 2,
  227. "count": touchfor.length,
  228. "pointerId": i,
  229. "x": cawidthXs.toFixed(2),
  230. "y": caheightYs.toFixed(2)
  231. },
  232. "event": "2"
  233. }
  234. }
  235. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  236. } else {
  237. var ping;
  238. for (var i = 0; i < touchfor.length; i++) {
  239. var cawidthXs = touchfor[i].pageX * (720 / vowidth);
  240. var caheightYs = touchfor[i].pageY * (1280 / voheight);
  241. ping = {
  242. "data": {
  243. "action": 2,
  244. "count": touchfor.length,
  245. "pointerId": i,
  246. "x": cawidthXs.toFixed(2),
  247. "y": caheightYs.toFixed(2)
  248. },
  249. "event": "2"
  250. }
  251. }
  252. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn));
  253. };
  254. };
  255. //鼠标离开区域以外 除了涂鸦 都清空
  256. var mouseout = function () {
  257. if (graphType != 'handwriting') {
  258. clearContext();
  259. }
  260. }
  261. $(canvas_bak).unbind();
  262. $(canvas_bak).bind('touchstart', touchstart);
  263. $(canvas_bak).bind('touchmove', touchmove);
  264. $(canvas_bak).bind('touchend', touchend);
  265. $(canvas_bak).bind('mouseout', mouseout);
  266. }
  267. // 获取url中"?"符后的字串
  268. function GetRequest() {
  269. var url = location.search;
  270. var obj = new Object();
  271. if (url.indexOf("?") != -1) {
  272. var str = url.substr(1);
  273. strs = str.split("&");
  274. for (var i = 0; i < strs.length; i++) {
  275. obj[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  276. }
  277. }
  278. return obj;
  279. }