WXdraw.js 7.0 KB

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