WXdraw.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 // -winHeight
  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. var cUrl = "ws://192.168.198.82:9100/card?cardIp=" + form.ip;
  27. var wsss;
  28. doConnect();
  29. function doConnect() {
  30. wsss = new WebSocket(cUrl);
  31. wsss.binaryType = 'arraybuffer';
  32. wsss.onopen = function () {
  33. var pings = {
  34. "event": "getScreenStatus"
  35. }
  36. wsss.send(JSON.stringify(pings));
  37. var bitRate = {
  38. "data": {
  39. "bitRate": 2243000
  40. },
  41. "event": "bitRate"
  42. }
  43. wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
  44. };
  45. wsss.onclose = function () {
  46. $.confirm({
  47. title: '提示',
  48. text: '连接断开,是否准备重连?',
  49. onOK: function () {
  50. doConnect();
  51. },
  52. onCancel: function () {
  53. wx.miniProgram.switchTab({
  54. url: '/pages/home/home'
  55. })
  56. }
  57. });
  58. };
  59. }
  60. $('#box').on("click", function () {
  61. draw_graph('pencil', this)
  62. })
  63. //剪切板
  64. $(".upload").on("click", function () {
  65. var texts = $(this).attr("data-text")
  66. if (texts == "uploads") {
  67. $(".mainbox").css({
  68. "display": "block"
  69. })
  70. $(".sbox").css({
  71. "display": "none"
  72. })
  73. }
  74. })
  75. //home 控制home
  76. $(".botmat1img").on("click", function () {
  77. var codes = $(this).attr("data-text")
  78. if (codes == "home") {
  79. wsss.send(ExexuteKeyBoard(3, form.sn));
  80. } else if (codes == "return") {
  81. wsss.send(ExexuteKeyBoard(4, form.sn));
  82. } else if (codes == "gengduo") {
  83. wsss.send(ExexuteKeyBoard(187, form.sn));
  84. }
  85. })
  86. //高清控制
  87. $(".PictureQuality").on("click", function () {
  88. $(this).addClass("avit").siblings().removeClass('avit')
  89. var id = $(this).attr("data-id")
  90. var bitRate = {
  91. "data": {
  92. "bitRate": id
  93. },
  94. "event": "bitRate"
  95. }
  96. wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
  97. })
  98. var canDraw = false;
  99. //画图形
  100. var draw_graph = function (graphType) {
  101. //把蒙版放于画板上面
  102. $("#container").css("z-index", 30);
  103. $("#dedit").css("z-index", 20);
  104. // 先画在蒙版上 再复制到画布上
  105. //鼠标按下获取 开始xy开始画图
  106. var touchstart = function (e) {
  107. $('.control-right-img').attr({
  108. "data-id": "2"
  109. })
  110. $(".leftmains").css({
  111. "right": "-4rem"
  112. })
  113. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  114. //是否横屏
  115. if (resolving == 0) {
  116. var ping
  117. for (var i = 0; i < touchfor.length; i++) {
  118. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  119. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  120. ping = {
  121. "data": {
  122. "action": 0,
  123. "count": touchfor.length,
  124. "pointerId": i,
  125. "x": cawidthXs.toFixed(2),
  126. "y": caheightYs.toFixed(2)
  127. },
  128. "event": "0"
  129. }
  130. }
  131. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  132. } else {
  133. var ping
  134. for (var i = 0; i < touchfor.length; i++) {
  135. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  136. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  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. }
  150. canDraw = true;
  151. };
  152. //鼠标离开 把蒙版canvas的图片生成到canvas中
  153. var touchend = function (e) {
  154. var touchfor = e.originalEvent.changedTouches; //for 的手指数组
  155. //是否横屏 morePortionUp
  156. if (resolving == 0) {
  157. var ping
  158. for (var i = 0; i < touchfor.length; i++) {
  159. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  160. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  161. ping = {
  162. "data": {
  163. "action": 1,
  164. "count": touchfor.length,
  165. "pointerId": i,
  166. "x": cawidthXs.toFixed(2),
  167. "y": caheightYs.toFixed(2)
  168. },
  169. "event": "1"
  170. }
  171. }
  172. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  173. } else {
  174. var ping
  175. for (var i = 0; i < touchfor.length; i++) {
  176. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  177. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  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. }
  191. canDraw = false;
  192. };
  193. //清空层 云手机超出屏幕的开关
  194. var clearContext = function () {
  195. canDraw = false;
  196. }
  197. // 鼠标移动
  198. var touchmove = function (e) {
  199. e = e || window.event;
  200. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  201. var ping
  202. //是否横屏 morePortionMove
  203. if (resolving == 0) {
  204. for (var i = 0; i < touchfor.length; i++) {
  205. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  206. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  207. ping = {
  208. "data": {
  209. "action": 2,
  210. "count": touchfor.length,
  211. "pointerId": i,
  212. "x": cawidthXs.toFixed(2),
  213. "y": caheightYs.toFixed(2)
  214. },
  215. "event": "2"
  216. }
  217. }
  218. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  219. } else {
  220. var ping
  221. for (var i = 0; i < touchfor.length; i++) {
  222. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  223. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  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. }
  237. };
  238. //鼠标离开区域以外 除了涂鸦 都清空
  239. var mouseout = function () {
  240. if (graphType != 'handwriting') {
  241. clearContext();
  242. }
  243. }
  244. $(canvas_bak).unbind();
  245. $(canvas_bak).bind('touchstart', touchstart);
  246. $(canvas_bak).bind('touchmove', touchmove);
  247. $(canvas_bak).bind('touchend', touchend);
  248. $(canvas_bak).bind('mouseout', mouseout);
  249. }
  250. function GetRequest() {
  251. var url = location.search; // 获取url中"?"符后的字串
  252. var obj = new Object();
  253. if (url.indexOf("?") != -1) {
  254. var str = url.substr(1);
  255. strs = str.split("&");
  256. for (var i = 0; i < strs.length; i++) {
  257. obj[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  258. }
  259. }
  260. return obj;
  261. }