WXdraw.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. $('.weui-mask_transparent').hide()
  45. $('.weui-toast').hide()
  46. $('.loading').hide()
  47. };
  48. wsss.onclose = function () {
  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. }
  63. $('#box').on("click", function () {
  64. draw_graph('pencil', this)
  65. })
  66. //剪切板
  67. $(".upload").on("click", function () {
  68. var texts = $(this).attr("data-text")
  69. if (texts == "uploads") {
  70. $(".mainbox").css({
  71. "display": "block"
  72. })
  73. $(".sbox").css({
  74. "display": "none"
  75. })
  76. }
  77. })
  78. //home 控制home
  79. $(".botmat1img").on("click", function () {
  80. var codes = $(this).attr("data-text")
  81. if (codes == "home") {
  82. wsss.send(ExexuteKeyBoard(3, form.sn));
  83. } else if (codes == "return") {
  84. wsss.send(ExexuteKeyBoard(4, form.sn));
  85. } else if (codes == "gengduo") {
  86. wsss.send(ExexuteKeyBoard(187, form.sn));
  87. }
  88. })
  89. //高清控制
  90. $(".PictureQuality").on("click", function () {
  91. $(this).addClass("avit").siblings().removeClass('avit')
  92. var id = $(this).attr("data-id")
  93. var bitRate = {
  94. "data": {
  95. "bitRate": id
  96. },
  97. "event": "bitRate"
  98. }
  99. wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
  100. })
  101. var canDraw = false;
  102. //画图形
  103. var draw_graph = function (graphType) {
  104. //把蒙版放于画板上面
  105. $("#container").css("z-index", 30);
  106. $("#dedit").css("z-index", 20);
  107. // 先画在蒙版上 再复制到画布上
  108. //鼠标按下获取 开始xy开始画图
  109. var touchstart = function (e) {
  110. $('.control-right-img').attr({
  111. "data-id": "2"
  112. })
  113. $(".leftmains").css({
  114. "right": "-4rem"
  115. })
  116. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  117. //是否横屏
  118. if (resolving == 0) {
  119. var ping
  120. for (var i = 0; i < touchfor.length; i++) {
  121. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  122. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  123. ping = {
  124. "data": {
  125. "action": 0,
  126. "count": touchfor.length,
  127. "pointerId": i,
  128. "x": cawidthXs.toFixed(2),
  129. "y": caheightYs.toFixed(2)
  130. },
  131. "event": "0"
  132. }
  133. }
  134. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  135. } else {
  136. var ping
  137. for (var i = 0; i < touchfor.length; i++) {
  138. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  139. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  140. ping = {
  141. "data": {
  142. "action": 0,
  143. "count": touchfor.length,
  144. "pointerId": i,
  145. "x": cawidthXs.toFixed(2),
  146. "y": caheightYs.toFixed(2)
  147. },
  148. "event": "0"
  149. }
  150. }
  151. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  152. }
  153. canDraw = true;
  154. };
  155. //鼠标离开 把蒙版canvas的图片生成到canvas中
  156. var touchend = function (e) {
  157. var touchfor = e.originalEvent.changedTouches; //for 的手指数组
  158. //是否横屏 morePortionUp
  159. if (resolving == 0) {
  160. var ping
  161. for (var i = 0; i < touchfor.length; i++) {
  162. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  163. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  164. ping = {
  165. "data": {
  166. "action": 1,
  167. "count": touchfor.length,
  168. "pointerId": i,
  169. "x": cawidthXs.toFixed(2),
  170. "y": caheightYs.toFixed(2)
  171. },
  172. "event": "1"
  173. }
  174. }
  175. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  176. } else {
  177. var ping
  178. for (var i = 0; i < touchfor.length; i++) {
  179. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  180. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  181. ping = {
  182. "data": {
  183. "action": 1,
  184. "count": touchfor.length,
  185. "pointerId": i,
  186. "x": cawidthXs.toFixed(2),
  187. "y": caheightYs.toFixed(2)
  188. },
  189. "event": "1"
  190. }
  191. }
  192. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  193. }
  194. canDraw = false;
  195. };
  196. //清空层 云手机超出屏幕的开关
  197. var clearContext = function () {
  198. canDraw = false;
  199. }
  200. // 鼠标移动
  201. var touchmove = function (e) {
  202. e = e || window.event;
  203. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  204. var ping
  205. //是否横屏 morePortionMove
  206. if (resolving == 0) {
  207. for (var i = 0; i < touchfor.length; i++) {
  208. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  209. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  210. ping = {
  211. "data": {
  212. "action": 2,
  213. "count": touchfor.length,
  214. "pointerId": i,
  215. "x": cawidthXs.toFixed(2),
  216. "y": caheightYs.toFixed(2)
  217. },
  218. "event": "2"
  219. }
  220. }
  221. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  222. } else {
  223. var ping
  224. for (var i = 0; i < touchfor.length; i++) {
  225. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  226. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  227. ping = {
  228. "data": {
  229. "action": 2,
  230. "count": touchfor.length,
  231. "pointerId": i,
  232. "x": cawidthXs.toFixed(2),
  233. "y": caheightYs.toFixed(2)
  234. },
  235. "event": "2"
  236. }
  237. }
  238. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  239. }
  240. };
  241. //鼠标离开区域以外 除了涂鸦 都清空
  242. var mouseout = function () {
  243. if (graphType != 'handwriting') {
  244. clearContext();
  245. }
  246. }
  247. $(canvas_bak).unbind();
  248. $(canvas_bak).bind('touchstart', touchstart);
  249. $(canvas_bak).bind('touchmove', touchmove);
  250. $(canvas_bak).bind('touchend', touchend);
  251. $(canvas_bak).bind('mouseout', mouseout);
  252. }
  253. function GetRequest() {
  254. var url = location.search; // 获取url中"?"符后的字串
  255. var obj = new Object();
  256. if (url.indexOf("?") != -1) {
  257. var str = url.substr(1);
  258. strs = str.split("&");
  259. for (var i = 0; i < strs.length; i++) {
  260. obj[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  261. }
  262. }
  263. return obj;
  264. }