train_cocopi.js 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  1. function initLanguage(langKey) {
  2. let defaultLang = 'en';
  3. let lang = langKey || defaultLang;
  4. if (defaultLang !== lang) {
  5. injectLanguageJsSources(lang);
  6. //updateLanguageText();
  7. }
  8. }
  9. var datasetName = ''
  10. var screenIndex = 0
  11. // logout
  12. $("#modal_logout_btn").on("click", function () {
  13. // logout();
  14. });
  15. // if(document.location.host != "beta.v.cocorobo.cn" && document.location.host != "pi.cocorobo.cn"){
  16. // document.domain = "cocorobo.cn";
  17. // }
  18. function logout() {
  19. $.ajax(`${CCB.base_url}api/logout`, {
  20. type: "GET",
  21. xhrFields: {
  22. withCredentials: true
  23. },
  24. success: () => {
  25. // $('#login_iframe').attr('src', '//staging.cocorobo.hk/login/');
  26. appendIframe("TM_login");
  27. $('#TM_login').children().css("height", "820px");
  28. appendIframe("TM_login_Model_download_modal");
  29. $('#TM_login_Model_download_modal').children().css("height", "820px");
  30. $('#TM_login_Model_download_modal').children().css("margin-top", "-225px");
  31. appendIframe("TM_login_object");
  32. $('#TM_login_object').children().css("height", "820px");
  33. appendIframe("TM_login_posenet");
  34. $('#TM_login_posenet').children().css("height", "820px");
  35. appendIframe("TM_posenet_login");
  36. $('#TM_posenet_login').children().css("height", "820px");
  37. appendIframe("before_login");
  38. appendIframe("cloud_askLogin");
  39. appendIframe("TM_login_webcam_capture_modal");
  40. $('#TM_login_webcam_capture_modal').children().css("width", "820px");
  41. $('#TM_login_webcam_capture_modal').children().css("height", "820px");
  42. appendIframe("TM_login_gesture_recog_modal");
  43. $('#TM_login_gesture_recog_modal').children().css("width", "820px");
  44. $('#TM_login_gesture_recog_modal').children().css("height", "820px");
  45. appendIframe("TM_login_voice_input_modal");
  46. $('#TM_login_voice_input_modal').children().css("width", "820px");
  47. $('#TM_login_voice_input_modal').children().css("height", "820px");
  48. appendIframe("TM_center_game");
  49. $('#TM_center_game').children().css("margin-top", "-300px");
  50. $('#TM_center_game').children().css("height", "820px");
  51. Materialize.toast(CCB.str_group.success_userLogout, 4000);
  52. CCB.userState = false;
  53. $("#cloud_fileListArea").html("");
  54. loginModalStatus();
  55. $("#modal_logout_btn").addClass('blue')
  56. $(".svgImg").css('display', 'none');
  57. $(".translate-signout").css('opacity', '1')
  58. }
  59. });
  60. }
  61. // 点击语言下拉隐藏
  62. // document.onclick = function () {
  63. // $('#languages').removeClass('active');
  64. // $('#languages').css({ display: 'none' })
  65. // }
  66. // 点击切换语言
  67. // $('#nav_language').click(function (e) {
  68. // $('#languages').addClass('active');
  69. // $('#languages').css({ display: 'block', opacity: 1, position: 'absolute',top:'64px' })
  70. // var ev = e || window.event;
  71. // if (ev.stopPropagation) { //阻止冒泡,否则会触发点击空白区域的事件
  72. // ev.stopPropagation();
  73. // } else if (window.event) {
  74. // window.event.cancelBubble = true; //兼容IE
  75. // }
  76. // })
  77. function getUrlLanguage() {
  78. const val = location.search.match(new RegExp('[?&]lang=([^&]+)'));
  79. let language = val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : '';
  80. if (['en', 'zh-hant', 'zh-hans'].indexOf(language) < 0) return 'zh-hant';
  81. return language;
  82. };
  83. function injectLanguageJsSources(langKey) {
  84. const head = document.getElementsByTagName('head')[0];
  85. // Retrieve and inject Ardublockly translations synchronously
  86. const appLangJsLoad = document.createElement('script');
  87. const request = createAjaxRequest();
  88. const appLangJdPath = `msg/${langKey}.js`;
  89. try {
  90. request.open('GET', appLangJdPath, false);
  91. request.send('');
  92. appLangJsLoad.text = request.responseText;
  93. } catch (e) {
  94. // But still asynchronous lazy load so at least some text gets translated
  95. appLangJsLoad.src = appLangJdPath;
  96. }
  97. head.appendChild(appLangJsLoad);
  98. // Retrieve and inject Blockly translations asynchronously
  99. const blocklyLangJsLoad = document.createElement('script');
  100. blocklyLangJsLoad.src = `blockly/msg/js/${langKey}.js`;
  101. head.appendChild(blocklyLangJsLoad);
  102. };
  103. function createAjaxRequest() {
  104. let request = false;
  105. try {
  106. // Firefox, Chrome, IE7+, Opera, Safari
  107. request = new XMLHttpRequest();
  108. } catch (e) {
  109. // IE6 and earlier
  110. try {
  111. request = new ActiveXObject('Msxml2.XMLHTTP');
  112. } catch (e) {
  113. try {
  114. request = new ActiveXObject('Microsoft.XMLHTTP');
  115. } catch (e) {
  116. throw 'Your browser does not support AJAX. You will not be able to' +
  117. 'use all of Ardublockly features.';
  118. request = null;
  119. }
  120. }
  121. }
  122. return request;
  123. };
  124. function updateLanguageText() {
  125. for (let textId in LOCALISED_TEXT) {
  126. const textStrings = document.getElementsByClassName(`translate-${textId}`);
  127. for (let i = 0; i < textStrings.length; i++) {
  128. textStrings[i].innerHTML = LOCALISED_TEXT[textId];
  129. }
  130. }
  131. };
  132. function clearBlocks(cb = () => { }) {
  133. const length = Blockly.mainWorkspace.getAllBlocks(true).length;
  134. if (length < 2) {
  135. Blockly.mainWorkspace.clear();
  136. cb();
  137. } else {
  138. Blockly.confirm(
  139. Blockly.Msg.DELETE_ALL_BLOCKS.replace("%1", length),
  140. ok => {
  141. if (!ok) return;
  142. Blockly.mainWorkspace.clear();
  143. cb();
  144. }
  145. );
  146. }
  147. }
  148. function addLibButton(lang) {
  149. // const addLib = document.createElement("button");
  150. // addLib.className = "waves-effect waves-light btn blue";
  151. // let content = lang === 'zh-hans' ? "添加库" : lang === 'zh-hant' ? "添加庫" : "Add Library";
  152. // addLib.textContent = content;
  153. // addLib.style = `
  154. // position: absolute;
  155. // width: 88%;
  156. // bottom: 10px;
  157. // left: 50%;
  158. // transform: translateX(-50%);
  159. // `;
  160. // $(addLib).click(e =>
  161. // blockpy.components.dialog.show("Add Library", document.createElement("div")));
  162. // $(".blocklyToolboxDiv").append(addLib);
  163. }
  164. // /**
  165. // * Save blocks into local storage. Note that MSIE 11 does not support
  166. // * LocalStorage on file:// URLs.
  167. // */
  168. // function saveLocalStorageBlocks() {
  169. // if (window.sessionStorage) {
  170. // var xml = blockpy.components.editor.getBlocksFromXml();
  171. // var text = Blockly.Xml.domToText(xml);
  172. // localStorage.setItem("blocks", text);
  173. // }
  174. // // blockpy.components.editor.getBlocksFromXml()
  175. // };
  176. // /** Load blocks saved on loacl storage and deletes them from storage. */
  177. // function loadLocalStorageBlocks() {
  178. // // try {
  179. // // var loadOnce = window.localStorage.loadOnceBlocks;
  180. // // } catch (e) {
  181. // // // Firefox sometimes throws a SecurityError when accessing sessionStorage.
  182. // // // Restarting Firefox fixes this, so it looks like a bug.
  183. // // var loadOnce = null;
  184. // // }
  185. // var loadBlocks = localStorage.getItem("blocks");
  186. // if (loadBlocks) {
  187. // var xml = Blockly.Xml.textToDom(loadBlocks);
  188. // blockpy.components.editor.setBlocksFromXml(xml);
  189. // localStorage.removeItem('blocks')
  190. // }
  191. // };
  192. var copyCodeClipboard;
  193. window.onbeforeunload = window.onunload = function () {
  194. if ($("#mode")[0].selectedIndex == 0) {
  195. saveLocalStorage("type", 1);
  196. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  197. } else {
  198. saveLocalStorage("type", 1);
  199. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  200. }
  201. }
  202. function getJsonData(filepath) {
  203. return new Promise(resolve => {
  204. $.getJSON(filepath, data => resolve(data));
  205. });
  206. }
  207. var isRunCodeData = '';
  208. var RunInterval = '';
  209. window.onload = async function () {
  210. var url = window.location.hash.substring(1);
  211. // if (url) {
  212. // document.getElementById('ipAddress').value = 'ws://' + url;
  213. // }
  214. // document.domain = "cocorobo.cn";
  215. $('.dropdown-trigger').dropdown();
  216. setTimeout(() => $('.modal').modal(), 0);
  217. let xmlName = '图像传输显示电脑.xml'
  218. readTxt("src/python/" + xmlName, function (txt) {
  219. if (xmlName.split(".")[1] == "xml") {
  220. var xmlfile = Blockly.Xml.textToDom(txt);
  221. blockpy.components.editor.setBlocksFromXml(xmlfile);
  222. } else {
  223. blockpy.components.editor.codeMirror.setValue(txt);
  224. }
  225. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  226. // setTimeout(() => {
  227. // $('#loading').css({ 'display': 'none' });
  228. // $('#example_alert').modal('close');
  229. // }, 300)
  230. });
  231. blockpy = new BlockPy({
  232. blocklyPath: "blockly/",
  233. attachmentPoint: document.getElementById("blockpy-div"),
  234. instructor:
  235. !getQueryParams()["instructor"] ||
  236. getQueryParams()["instructor"] == "true",
  237. developer: true,
  238. editor: getQueryParams()["mode"] || "Split",
  239. urls: {
  240. }
  241. });
  242. // ready();
  243. var size = calculate_size($("#term")[0]);
  244. term = new Terminal({
  245. cols: size[0],
  246. rows: size[1],
  247. useStyle: true,
  248. screenKeys: true,
  249. cursorBlink: false
  250. });
  251. term.open(document.getElementById("term"));
  252. //show_https_warning();
  253. $(".filled-in")[0].onclick = function () {
  254. var _chi = $(".filled-in")[0];
  255. var _par = $(".filled-in")[0].parentNode;
  256. if (!_chi.checked) {
  257. _par.children[1].className = 'filled-in_nocheked translatable_Adapter_fill_connected';
  258. _par.children[1].innerHTML = CCB.str_group.Adapter_fill_connected;
  259. } else {
  260. _par.children[1].className = 'translatable_Adapter_connected';
  261. _par.children[1].innerHTML = CCB.str_group.Adapter_connected;
  262. };
  263. }
  264. setTimeout(() => {
  265. cocoblockly();
  266. }, 0);
  267. $('.blockpy-toolbar-download').on(
  268. "click", () => export_data(
  269. pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue(), '.py', 0
  270. )
  271. );
  272. // uploadpy
  273. document.getElementById('uploadpy').onclick = function () {
  274. window.file_manger_modal = false
  275. $("#runCode").addClass('disabled')
  276. $("#uploadpy").addClass('disabled')
  277. $("#resetDevice").addClass('disabled')
  278. $("#poweroff").addClass('disabled')
  279. $("#backHome").addClass('disabled')
  280. // 上传
  281. $('.progress > .determinate').css('width', 10);
  282. // 这么写是因为文件转换是异步任务
  283. transToFile = async (blob, fileName, fileType) => {
  284. return new window.File([blob], fileName, { type: fileType })
  285. }
  286. let text = pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue()
  287. // console.log(text)
  288. // 开始上传
  289. // function test(){
  290. let blob = new Blob([text], { type: "text/plain;charset=utf-8" })
  291. let textContain = transToFile(blob, "user_latest_code.py", "text/plain")
  292. if (isWifiContent) {
  293. sendWebsocket(text, 'upload')
  294. } else {
  295. // 转换完成后可以将file对象传给接口
  296. textContain.then((res) => {
  297. let file = res;
  298. // window.stateapi.upload(file,"/root/")
  299. $('.progress > .determinate').css('width', '50%');
  300. setTimeout(() => {
  301. if (file) {
  302. $('.progress > .determinate').css('width', '100%');
  303. document.getElementById('webadb_iframe').contentWindow.upload(file, "/root/")
  304. } else {
  305. $('.progress > .determinate').css('width', 0);
  306. }
  307. window.file_manger_modal = true
  308. $("#runCode").removeClass('disabled')
  309. $("#uploadpy").removeClass('disabled')
  310. $("#resetDevice").removeClass('disabled')
  311. $("#poweroff").removeClass('disabled')
  312. }, 500)
  313. })
  314. }
  315. // }
  316. }
  317. // runCode
  318. document.getElementById('runCode').onclick = async function () {
  319. window.file_manger_modal = false
  320. $("#runCode").addClass('disabled')
  321. $("#uploadpy").addClass('disabled')
  322. $("#resetDevice").addClass('disabled')
  323. $("#poweroff").addClass('disabled')
  324. $("#backHome").addClass('disabled')
  325. $('.progress > .determinate').css('width', 0);
  326. $("#error-btn").css("display", "none")
  327. transToFile = async (blob, fileName, fileType) => {
  328. return new window.File([blob], fileName, { type: fileType })
  329. }
  330. let text = pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue()
  331. let blob = new Blob([text], { type: "text/plain;charset=utf-8" })
  332. //let textContain =
  333. let file = await transToFile(blob, "user_latest_code.py", "text/plain")
  334. if (isWifiContent) {
  335. // 无线连接
  336. sendWebsocket(text, 'run')
  337. $('.progress > .determinate').css('width', '50%');
  338. } else {
  339. await document.getElementById('webadb_iframe').contentWindow.upload(file, "/root/");
  340. $('.progress > .determinate').css('width', '50%');
  341. clearInterval(RunInterval);
  342. if (isRunCodeData) {
  343. isRunCodeData.kill().then(() => {
  344. run_user_lastet_code()
  345. })
  346. }
  347. else {
  348. run_user_lastet_code()
  349. }
  350. setTimeout(function () {
  351. $('.progress > .determinate').css('width', '100%');
  352. window.file_manger_modal = true
  353. $("#runCode").removeClass('disabled')
  354. $("#uploadpy").removeClass('disabled')
  355. $("#resetDevice").removeClass('disabled')
  356. $("#poweroff").removeClass('disabled')
  357. }, 2000);
  358. }
  359. //})
  360. }
  361. const uploadXmlButton = $('#pyFileImport > input');
  362. uploadXmlButton.change(function () {
  363. var fr = new FileReader();
  364. var files = uploadXmlButton[0].files;
  365. const file = files[0];
  366. Ardublockly.alertExampleMessage(
  367. '', Ardublockly.getLocalStr('loadBlockBody'),
  368. true, {});
  369. fr.onload = function (e) {
  370. var pyInnerHTML = e.target.result;
  371. blockpy.components.editor.codeMirror.setValue(pyInnerHTML);
  372. };
  373. fr.readAsText(file);
  374. setTimeout(() => {
  375. $('#loading').css({ 'display': 'none' });
  376. $('#example_alert').modal('close');
  377. }, 300)
  378. uploadXmlButton.val("");
  379. });
  380. $('.blockpy-toolbar-upload').click(e => $('#pyFileImport > input').click());
  381. fanyi();
  382. selectOnload();
  383. styled()
  384. // let iframe = document.createElement("iframe")
  385. // iframe.src = window.location.host.indexOf("beta") > -1 ? "//beta.project-x.cocorobo.cn/" : '//project-x.cocorobo.cn/';
  386. // iframe.style.width = "100%";
  387. // iframe.style.height = "99%";
  388. // iframe.style.border = "none";
  389. // document.getElementById('iframe').appendChild(iframe)
  390. // $('#select_mode')[0].onchange = function(e){
  391. // var e = e.target;
  392. // selectmode(e.selectedIndex);
  393. // var _index = e.selectedIndex;
  394. //   localStorage.setItem("ModeIndex",_index);
  395. //   
  396. // }
  397. // var _index = localStorage.getItem("ModeIndex") != "undefined" ? localStorage.getItem("ModeIndex") : 0;
  398. // selectmode(parseInt(_index));
  399. // $('#select_mode')[0].selectedIndex = parseInt(_index);
  400. $('#toggle-button').click(() => {
  401. if ($('#toggle-button')[0].checked) {
  402. $('#edit')[0].style.display = 'none';
  403. // $('.translatable_editing')[0].style.display = "none";
  404. // $('.translatable_close_editing')[0].style.display = "inline-block"
  405. } else {
  406. $('#edit')[0].style.display = 'block';
  407. // $('.translatable_editing')[0].style.display = "inline-block";
  408. // $('.translatable_close_editing')[0].style.display = "none"
  409. }
  410. })
  411. const _lang = getUrlLanguage();
  412. if (window.location.search.indexOf('datasetName') > -1) {
  413. datasetName = window.location.search.split('datasetName=')[1]
  414. screenIndex = 0
  415. $.ajax(`//traininguser-api.cocorobo.cn/v831_update_code_connect_device`, {
  416. type: "POST",
  417. dataType: "json",
  418. contentType: 'application/json;charset=utf-8',
  419. data: JSON.stringify({ "DatasetName": datasetName }),
  420. success: (res) => {
  421. console.log(res)
  422. Materialize.toast(CCB.str_group.connection_success, 4000);
  423. }
  424. });
  425. }
  426. // 判断从python blcokly 跳转过来是ai或者iot
  427. if (window.location.search.indexOf('name=1') > -1 || window.location.search.indexOf('id=ai') > -1) {
  428. $("#mode")[0].selectedIndex = 1;
  429. $("#mode")[0].onchange();
  430. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  431. history.pushState(null, null, '//x.cocorobo.cn/?lang=' + _lang);
  432. selectmode($("#mode")[0], true);
  433. // document.getElementById("list").getElementsByTagName("li")[1].onclick();
  434. }
  435. else if (window.location.search.indexOf('name=0') > -1 || window.location.search.indexOf('id=iot') > -1) {
  436. $("#mode")[0].selectedIndex = 0;
  437. $("#mode")[0].onchange();
  438. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  439. history.pushState(null, null, '//x.cocorobo.cn/?lang=' + _lang);
  440. selectmode($("#mode")[0], true);
  441. // document.getElementById("list").getElementsByTagName("li")[0].onclick();
  442. }
  443. else {
  444. if (getLocalStorage("type") == 1) {
  445. $("#mode")[0].selectedIndex = 1;
  446. $("#mode")[0].onchange();
  447. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  448. selectmode($("#mode")[0], true);
  449. // document.getElementById("list").getElementsByTagName("li")[1].onclick();
  450. } else {
  451. $("#mode")[0].selectedIndex = 0;
  452. $("#mode")[0].onchange();
  453. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  454. selectmode($("#mode")[0], true);
  455. // document.getElementById("list").getElementsByTagName("li")[0].onclick();
  456. }
  457. }
  458. $('#white-box').css('display', 'none');
  459. const copyCodeClipboard = new ClipboardJS(".copy_code", {
  460. text: function () {
  461. return blockpy.components.editor.codeMirror.getValue();
  462. // const codes = $(".CodeMirror-code pre");
  463. // let target = "";
  464. // for (let i = 0; i < codes.length; i++) {
  465. // let line = codes[i].textContent;
  466. // !(line.length === 1 && line.charCodeAt(0) === 8203) ? target += line : "";
  467. // i !== codes.length - 1 ? target += "\n" : "";
  468. // }
  469. // return target;
  470. }
  471. });
  472. copyCodeClipboard.on("success", () => copyCodeToast(2000));
  473. mouseMove();
  474. const copyCodeToast = (function (lang) {
  475. let toast = null,
  476. timeout = null;
  477. const content = lang === 'zh-hans' ? "复制成功" :
  478. lang === 'zh-hant' ? "複製成功" : "Copy Successfully";
  479. return function (ms) {
  480. if (toast) {
  481. toast.dismiss();
  482. clearTimeout(timeout);
  483. }
  484. toast = Materialize.toast(content, ms);
  485. timeout = setTimeout(() => toast = timeout = null, ms);
  486. };
  487. })(_lang);
  488. $("#delete-all").click(() => clearBlocks());
  489. $("#screenshot").click(() => Blockly.captureDialog_());
  490. $("#clearOutput").click(() => $(".blockpy-printer").html(""));
  491. $("#resetAll").click(() => clearBlocks(() => $(".blockpy-printer").html("")));
  492. // $("#lang-tool").click(() => $("#side-lang-trigger > a").dropdown('open'));
  493. // $("#file-tool").click(() => $("#side-file-trigger > a").dropdown('open'));
  494. $("#blockpy-content > .blockpy-editor img.fullscreenIcon").click(e => {
  495. $(e.currentTarget.parentNode).toggleClass("fullscreen");
  496. $('#edit')[0].style.display = 'none';
  497. $("#blockpy-content > .blockpy-editor img.fullscreenIcon").toggleClass("hidden");
  498. $("html").toggleClass("fullscreenMode");
  499. setTimeout(function () {
  500. Blockly.svgResize(blockpy.components.editor.blockly);
  501. Blockly.svgResize(Blockly.mainWorkspace);
  502. }, 100)
  503. });
  504. $("#blockpy-content .card-header > img.fullscreenIcon").click(e => {
  505. $(e.currentTarget.parentNode.parentNode).toggleClass("fullscreen");
  506. $('#edit')[0].style.display = 'block';
  507. $("#blockpy-content .card-header > img.fullscreenIcon").toggleClass("hidden");
  508. $("html").toggleClass("fullscreenMode");
  509. setTimeout(() => $(".blockpy-toolbar > .blockpy-text")
  510. .css("height", "90%")
  511. .css("height", "100%"), 0);
  512. });
  513. let browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  514. if (browserWidth < 500) {
  515. $('.mobileSwitch')[0].style.display = "block"
  516. $('#py-editor')[0].style.display = "none"
  517. // $("#IP")[0].style.display = "block"
  518. // isWifiContent = true
  519. }
  520. // 提示全屏
  521. // setTimeout(() => {
  522. // // if (document.body.clientWidth < 1265) {
  523. // // alert(CCB.str_group.alert)
  524. // // }
  525. // myChart = echarts.init(document.getElementById('echartsMain'));
  526. // window.onresize = function () {
  527. // myChart.resize();
  528. // }
  529. // }, 1000)
  530. // 加载echarts
  531. // myChart = myChart = echarts.init(document.getElementById('echartsMain'));
  532. // window.onresize = function () {
  533. // myChart.resize();
  534. // }
  535. // 点击复制分享链接
  536. copyShare()
  537. let autoContent = 0
  538. window.file_manger_modal = true
  539. document.getElementById("webadb_iframe").onload = function () {
  540. setInterval(function () {
  541. if (document.getElementById("webadb_iframe").contentWindow.getdevice && window.file_manger_modal && !isWifiContent) {
  542. isDevice = document.getElementById("webadb_iframe").contentWindow.getdevice();
  543. isConnect = document.getElementById("webadb_iframe").contentWindow.isconnect()
  544. if (isDevice.device == undefined && isDevice.selectdevice == undefined) {
  545. $("#webadb_connect")[0].disabled = true;
  546. $("#webadb_add")[0].disabled = false;
  547. $("#runCode").addClass('disabled')
  548. $("#uploadpy").addClass('disabled')
  549. $("#resetDevice").addClass('disabled')
  550. $("#backHome").addClass('disabled')
  551. $("#poweroff").addClass('disabled')
  552. $('#message_file').css({ display: 'none' })
  553. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
  554. $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusNotConn
  555. $('.progress > .determinate').css('width', 0);
  556. $('#cnt_icon').css('display', 'none')
  557. $('#discnt_icon').css('display', 'inline-block')
  558. $('#select-connected').attr("disabled", false)
  559. }
  560. else if (isDevice.device == undefined && isDevice.selectdevice != undefined) {
  561. $("#webadb_connect")[0].disabled = false;
  562. $("#webadb_add")[0].disabled = false;
  563. $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusNotConn
  564. $("#runCode").addClass('disabled')
  565. $("#uploadpy").addClass('disabled')
  566. $("#resetDevice").addClass('disabled')
  567. $("#backHome").addClass('disabled')
  568. $("#poweroff").addClass('disabled')
  569. $('#message_file').css({ display: 'none' })
  570. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
  571. $('.progress > .determinate').css('width', 0);
  572. $('#cnt_icon').css('display', 'none')
  573. $('#discnt_icon').css('display', 'inline-block')
  574. $('#select-connected').attr("disabled", false)
  575. // if(autoContent<5){
  576. // setTimeout(()=>{
  577. // serialSwich('Serial_Interaction')
  578. // document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbconnect").click()
  579. // $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
  580. // autoContent++
  581. // },2000)
  582. // }else{
  583. // console.log('111111')
  584. // // alert('你的板子已在其他页面连接成功')
  585. // }
  586. }
  587. else if (isDevice.device != undefined && isDevice.selectdevice != undefined) {
  588. $("#webadb_add")[0].disabled = true;
  589. if (!!isConnect) {
  590. $('#select-connected').attr("disabled", true)
  591. $('#cnt_icon').css('display', 'inline-block')
  592. $('#discnt_icon').css('display', 'none')
  593. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
  594. $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusbar
  595. $("#webadb_connect")[0].disabled = false;
  596. $('#message_file').css({ display: 'inline-block' })
  597. $("#runCode").removeClass('disabled')
  598. $("#uploadpy").removeClass('disabled')
  599. $("#resetDevice").removeClass('disabled')
  600. $("#poweroff").removeClass('disabled')
  601. } else {
  602. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
  603. $("#webadb_connect")[0].disabled = true;
  604. $('#message_file').css({ display: 'none' })
  605. }
  606. }
  607. }
  608. }, 1000)
  609. }
  610. // 加载更新提示框
  611. let updateData = await getJsonData('./update.json');
  612. // 最新更新你内容
  613. let updateNew = _lang == "zh-hans" ? updateData.updateNew.zhHans : _lang == "zh-hant" ? updateData.updateNew.zhHant : updateData.updateNew.en;
  614. let isUpdate = localStorage.getItem('isUpdate') || 0
  615. let blocklLis = "";
  616. let exampleLis = "";
  617. let noteLis = ""
  618. for (let i = 0; i < updateNew.blocks.length; i++) {
  619. let blockLi = `<li>${updateNew.blocks[i]}</li>`
  620. blocklLis = blocklLis + blockLi
  621. }
  622. $('#blockLis').append(blocklLis)
  623. for (let i = 0; i < updateNew.example.length; i++) {
  624. let exampleLi = `<li>${updateNew.example[i]}</li>`
  625. exampleLis = exampleLis + exampleLi
  626. }
  627. $('#exampleLis').append(exampleLis)
  628. for (let i = 0; i < updateNew.note.length; i++) {
  629. let noteLi = `<li>${updateNew.note[i]}</li>`
  630. noteLis = noteLis + noteLi
  631. }
  632. $('#noteLis').append(noteLis)
  633. $('.updateTime')[0].innerHTML = updateData.updateNew.time
  634. // 历史更新
  635. let updateDataOld = updateData.updateOld
  636. let leftStr = ''
  637. let noteStr = ''
  638. for (let i = 0; i < updateDataOld.length; i++) {
  639. let data = updateDataOld[i]
  640. let time = `<h5>${data.time}</h5>`;
  641. let updateData = _lang == "zh-hans" ? data.zhHans : _lang == "zh-hant" ? data.zhHant : data.en;
  642. let blocklLisOld = ''
  643. let exampleLisOld = ''
  644. let noteLisOld = ''
  645. for (let i = 0; i < updateData.blocks.length; i++) {
  646. let blockLi = `<li>${updateData.blocks[i]}</li>`
  647. blocklLisOld = blocklLisOld + blockLi
  648. }
  649. for (let i = 0; i < updateData.example.length; i++) {
  650. let exampleLi = `<li>${updateData.example[i]}</li>`
  651. exampleLisOld = exampleLisOld + exampleLi
  652. }
  653. for (let i = 0; i < updateData.note.length; i++) {
  654. let noteLi = `<li>${updateData.note[i]}</li>`
  655. noteLisOld = noteLisOld + noteLi
  656. }
  657. leftStr = leftStr + `${time}<li>积木<ul class="updateContent">${blocklLisOld}</ul></li><li>样例<ul class="updateContent">${exampleLisOld}</ul></li>`
  658. noteStr = noteStr + `${time}${noteLisOld}`
  659. }
  660. $('#leftUpdateOld').append(leftStr)
  661. $('#noteLisOld').append(noteStr)
  662. // $("#root").modal("open");
  663. setTimeout(() => {
  664. // // if (isUpdate < 2) {
  665. // $("#select_Example_modal").modal("close");
  666. // $("#loadModal").modal("open");
  667. // localStorage.setItem('isUpdate', Number(isUpdate) + 1)
  668. // // }
  669. }, 3000);
  670. }
  671. function styled() {
  672. if (window.location.search.indexOf("en") > -1) {
  673. $(".downbox-style").css({ width: '280px', marginLeft: '-100px' }),
  674. $(".HarxA1").css({ left: "calc(100% - 610px)" });
  675. $('#aaa .HarxA1').addClass('HarxA1_style')
  676. // $(".container-bottom").css("height","390px")
  677. $(".modelDownloadItemTitle").css("marginTop", "15px");
  678. $(".vision_category").css("marginTop", "15px");
  679. $(".model_download_modal_column").css("height", "435px");
  680. $(".modelDownloadItemDesc").css("height", "110px");
  681. }
  682. }
  683. function fanyi() {
  684. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn
  685. $('.ModeSelect')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Example;
  686. $('.ModeBox')[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.artificial_intelligence_textbook_program;
  687. $('.Hardware9 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.third_grade;
  688. $('.ModeBox ul')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
  689. $('.ModeBox ul')[0].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.voice_recognition_lamp_stand;
  690. $('.Hardware4n div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.four_grade;
  691. $('.ModeBox ul')[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_aifr;
  692. $('.ModeBox ul')[1].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaor;
  693. $('.Hardware5 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.fifth_grade;
  694. $('.ModeBox ul')[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
  695. $('.ModeBox ul')[2].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_curtain;
  696. $('.ModeBox ul')[2].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.fruit_picking_robot;
  697. $('.ModeBox ul')[2].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.fntelligent_inspection_robot;
  698. $('.Hardware6 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.sixth_grade;
  699. $('.ModeBox ul')[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_traffic_lights;
  700. $('.ModeBox ul')[3].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.seeing_eye_necklace;
  701. $('.ModeBox ul')[3].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.code_package_sorting_robot;
  702. $('.ModeBox ul')[3].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.unmanned_circulation_car;
  703. $('.Hardware7 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.seventh_grade;
  704. $('.ModeBox ul')[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.face_recognition_electronic_police;
  705. $('.Hardware8 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.eighth_grade;
  706. $('.ModeBox ul')[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.payment_platform;
  707. $('.ModeBox')[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Basics;
  708. $('.ModeBox ul')[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcb;
  709. $('.ModeBox ul')[6].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcsl;
  710. $('.ModeBox ul')[6].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_tacl;
  711. $('.ModeBox ul')[6].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ba;
  712. $('.ModeBox ul')[6].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_desl;
  713. $('.ModeBox ul')[6].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_tdsl;
  714. $('.ModeBox ul')[6].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ha;
  715. $('.ModeBox ul')[6].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ssl;
  716. $('.ModeBox ul')[6].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ldliv;
  717. $('.ModeBox')[0].children[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_imefc;
  718. $('.ModeBox ul')[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_uls;
  719. $('.ModeBox ul')[7].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_umdm;
  720. $('.ModeBox ul')[7].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_uoglls;
  721. $('.ModeBox ul')[7].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
  722. $('.ModeBox ul')[7].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctsotem;
  723. $('.ModeBox ul')[7].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_thwos;
  724. $('.ModeBox ul')[7].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
  725. $('.ModeBox ul')[7].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_line;
  726. $('.ModeBox ul')[7].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
  727. $('.ModeBox ul')[7].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter;
  728. $('.ModeBox ul')[7].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter_1;
  729. $('.ModeBox ul')[7].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_send;
  730. $('.ModeBox ul')[7].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_receive;
  731. $('.ModeBox')[0].children[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ionc;
  732. $('.ModeBox ul')[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_btsldtc;
  733. $('.ModeBox ul')[8].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_ktsedti;
  734. $('.ModeBox ul')[8].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_btoldalua;
  735. $('.ModeBox ul')[8].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_tsedtc;
  736. $('.ModeBox ul')[8].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_toedaluatc;
  737. $('.ModeBox ul')[8].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_ewhadtnocd;
  738. $('.ModeBox ul')[8].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledss;
  739. $('.ModeBox ul')[8].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledac;
  740. $('.ModeBox ul')[8].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctwn;
  741. $('.ModeBox ul')[8].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_bssbms;
  742. $('.ModeBox ul')[8].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_bsrbmc;
  743. $('.ModeBox ul')[8].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbms;
  744. $('.ModeBox ul')[8].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbmr;
  745. $('.ModeBox ul')[8].children[13].innerHTML = Ardublockly.LOCALISED_TEXT.select_snt;
  746. $('.ModeBox ul')[8].children[14].innerHTML = Ardublockly.LOCALISED_TEXT.select_dwsdat;
  747. $('.ModeBox')[0].children[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_work_u;
  748. $('.ModeBox ul')[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_middle_led;
  749. $('.ModeBox ul')[9].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_all_led;
  750. $('.ModeBox ul')[9].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_liu_led;
  751. $('.ModeBox ul')[9].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_warning;
  752. $('.ModeBox ul')[9].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_music;
  753. $('.ModeBox ul')[9].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_open;
  754. $('.ModeBox ul')[9].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_touch_open;
  755. $('.ModeBox ul')[9].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_close;
  756. $('.ModeBox ul')[9].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_control_LED;
  757. $('.ModeBox ul')[9].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_sensor_LED;
  758. $('.ModeBox ul')[9].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_humidity_alarm;
  759. $('.ModeBox')[0].children[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_work_d;
  760. $('.ModeBox ul')[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_shaking_LED;
  761. // $('.ModeBox ul')[4].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_connect_wifi;
  762. $('.ModeBox ul')[10].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_show_statement;
  763. $('.ModeBox ul')[10].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_establish_WiFi;
  764. $('.ModeBox ul')[10].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_download_lighting;
  765. $('.ModeBox ul')[10].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_controlling_servo;
  766. $('.ModeBox ul')[10].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_move_servo;
  767. $('.ModeBox ul')[10].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_controlling_servo;
  768. $('.ModeBox ul')[10].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_face_recognition_door;
  769. $('.ModeBox ul')[10].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_speech_recognition_car;
  770. $('.ModeBox ul')[10].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_gyro_control_robot;
  771. $('.ModeBox ul')[10].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_gesture_recognition_robot;
  772. $('.ModeBox ul')[10].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_speech_recogniton_lamp;
  773. $('.ModeBox')[0].children[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_smmlc;
  774. $('.ModeBox ul')[11].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.basis_face_Intelligent;
  775. $('.ModeBox ul')[11].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_gcaerhk;
  776. $('.ModeBox ul')[11].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_frs;
  777. $('.ModeBox ul')[11].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ors;
  778. $('.ModeBox ul')[11].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fr;
  779. $('.ModeBox ul')[11].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_or;
  780. $('.ModeBox ul')[11].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_srd;
  781. $('.ModeBox ul')[11].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_srt;
  782. $('.ModeBox ul')[11].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_mhdr;
  783. $('.ModeBox')[0].children[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ambc;
  784. $('.ModeBox ul')[12].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bcsc;
  785. $('.ModeBox ul')[12].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpccs;
  786. $('.ModeBox ul')[12].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpficc;
  787. $('.ModeBox ul')[12].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
  788. $('.ModeBox ul')[12].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_mc;
  789. $('.ModeBox ul')[12].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_sor;
  790. $('.ModeBox ul')[12].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
  791. $('.ModeBox')[0].children[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amefc;
  792. $('.ModeBox ul')[13].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_auls;
  793. $('.ModeBox ul')[13].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aumdm;
  794. $('.ModeBox ul')[13].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
  795. $('.ModeBox ul')[13].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_actsotem;
  796. $('.ModeBox ul')[13].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_greedy_snake;
  797. $('.ModeBox')[0].children[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amvc;
  798. $('.ModeBox ul')[14].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bctbotci;
  799. $('.ModeBox ul')[14].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aca;
  800. $('.ModeBox ul')[14].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_rqc;
  801. $('.ModeBox ul')[14].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_lhbl;
  802. $('.ModeBox ul')[14].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgr;
  803. $('.ModeBox ul')[14].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgaat;
  804. $('.ModeBox')[0].children[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_av;
  805. $('.ModeBox ul')[15].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.paly_video;
  806. $('.ModeBox ul')[15].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.paly_music;
  807. $('.ModeBox ul')[15].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.recording_camera;
  808. $('.ModeBox ul')[15].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.microphone_sound_analysis;
  809. $('.ModeBox')[0].children[11].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher;
  810. $('.ModeBox ul')[16].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
  811. $('.ModeBox ul')[16].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
  812. $('.ModeBox ul')[16].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
  813. $('.ModeBox ul')[16].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
  814. $('.ModeBox ul')[16].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor;
  815. $('.ModeBox')[0].children[12].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher2;
  816. $('.ModeBox ul')[17].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaor;
  817. $('.ModeBox ul')[17].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aifr;
  818. $('.ModeBox ul')[17].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_aica;
  819. $('.ModeBox ul')[17].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_aisrc;
  820. $('.ModeBox ul')[17].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_aisrr;
  821. $('.ModeBox ul')[17].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaa;
  822. $('.ModeBox')[0].children[13].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_teachingcases;
  823. $('.ModeBox ul')[18].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ex1_servo;
  824. $('.ModeBox ul')[18].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ex2_Ultrasound;
  825. // $('.ModeBox ul')[12].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ex3_RangeFinder;
  826. // $('.ModeBox ul')[12].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ex4_LightStrip;
  827. // $('.ModeBox ul')[12].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ex5_Microbit;
  828. // $('.ModeBox ul')[12].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.ex6_MicrobitFace;
  829. // $('.ModeBox ul')[12].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.ex7_Door;
  830. $('.ModeBox ul')[18].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ex4_LightStrip
  831. $('.ModeBox ul')[18].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ex5_Microbit;
  832. $('.ModeBox ul')[18].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ex6_MicrobitFace;
  833. $('.ModeBox ul')[18].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.ex7_Door;
  834. $('.ModeBox')[0].children[14].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_wc;
  835. $('.ModeBox ul')[19].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_smaa;
  836. $('.ModeBox ul')[19].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_gc;
  837. $('.ModeBox ul')[19].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_wsb;
  838. $('.ModeBox')[0].children[15].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_ad;
  839. $('.ModeBox ul')[20].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_trsr;
  840. $('.ModeBox ul')[20].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpl2;
  841. $('.ModeBox ul')[20].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpll;
  842. $('.ModeBox ul')[20].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tph;
  843. $('.ModeBox')[0].children[16].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm;
  844. $('.ModeBox ul')[21].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_iot_send;
  845. $('.ModeBox ul')[21].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_ai_get;
  846. $('.ModeBox ul')[21].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_ai_send;
  847. $('.ModeBox ul')[21].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_iot_get;
  848. $('.ModeBox1')[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.artificial_intelligence_textbook_program;
  849. $('.Hardware9 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.third_grade;
  850. $('.ModeBox1 ul')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
  851. $('.ModeBox1 ul')[0].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.voice_recognition_lamp_stand;
  852. $('.Hardware4n div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.four_grade;
  853. $('.ModeBox1 ul')[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_aifr;
  854. $('.ModeBox1 ul')[1].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaor;
  855. $('.Hardware5 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.fifth_grade;
  856. $('.ModeBox1 ul')[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
  857. $('.ModeBox1 ul')[2].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_curtain;
  858. $('.ModeBox1 ul')[2].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.fruit_picking_robot;
  859. $('.ModeBox1 ul')[2].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.fntelligent_inspection_robot;
  860. $('.Hardware6 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.sixth_grade;
  861. $('.ModeBox1 ul')[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_traffic_lights;
  862. $('.ModeBox1 ul')[3].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.seeing_eye_necklace;
  863. $('.ModeBox1 ul')[3].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.code_package_sorting_robot;
  864. $('.ModeBox1 ul')[3].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.unmanned_circulation_car;
  865. $('.Hardware7 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.seventh_grade;
  866. $('.ModeBox1 ul')[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.face_recognition_electronic_police;
  867. $('.Hardware8 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.eighth_grade;
  868. $('.ModeBox1 ul')[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.payment_platform;
  869. $('.ModeBox1')[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Basics;
  870. $('.ModeBox1 ul')[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcb;
  871. $('.ModeBox1 ul')[6].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcsl;
  872. $('.ModeBox1 ul')[6].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_tacl;
  873. $('.ModeBox1 ul')[6].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ba;
  874. $('.ModeBox1 ul')[6].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_desl;
  875. $('.ModeBox1 ul')[6].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_tdsl;
  876. $('.ModeBox1 ul')[6].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ha;
  877. $('.ModeBox1 ul')[6].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ssl;
  878. $('.ModeBox1 ul')[6].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ldliv;
  879. $('.ModeBox1')[0].children[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_imefc;
  880. $('.ModeBox1 ul')[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_uls;
  881. $('.ModeBox1 ul')[7].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_umdm;
  882. $('.ModeBox1 ul')[7].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_uoglls;
  883. $('.ModeBox1 ul')[7].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
  884. $('.ModeBox1 ul')[7].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctsotem;
  885. $('.ModeBox1 ul')[7].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_thwos;
  886. $('.ModeBox1 ul')[7].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
  887. $('.ModeBox1 ul')[7].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_line;
  888. $('.ModeBox1 ul')[7].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
  889. $('.ModeBox1 ul')[7].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter;
  890. $('.ModeBox1 ul')[7].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter_1;
  891. $('.ModeBox1 ul')[7].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_send;
  892. $('.ModeBox1 ul')[7].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_receive;
  893. $('.ModeBox1')[0].children[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ionc;
  894. $('.ModeBox1 ul')[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_btsldtc;
  895. $('.ModeBox1 ul')[8].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_ktsedti;
  896. $('.ModeBox1 ul')[8].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_btoldalua;
  897. $('.ModeBox1 ul')[8].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_tsedtc;
  898. $('.ModeBox1 ul')[8].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_toedaluatc;
  899. $('.ModeBox1 ul')[8].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_ewhadtnocd;
  900. $('.ModeBox1 ul')[8].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledss;
  901. $('.ModeBox1 ul')[8].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledac;
  902. $('.ModeBox1 ul')[8].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctwn;
  903. $('.ModeBox1 ul')[8].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_bssbms;
  904. $('.ModeBox1 ul')[8].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_bsrbmc;
  905. $('.ModeBox1 ul')[8].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbms;
  906. $('.ModeBox1 ul')[8].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbmr;
  907. $('.ModeBox1 ul')[8].children[13].innerHTML = Ardublockly.LOCALISED_TEXT.select_snt;
  908. $('.ModeBox1 ul')[8].children[14].innerHTML = Ardublockly.LOCALISED_TEXT.select_dwsdat;
  909. $('.ModeBox1')[0].children[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_smmlc;
  910. $('.ModeBox1 ul')[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.basis_face_Intelligent;
  911. $('.ModeBox1 ul')[9].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_gcaerhk;
  912. $('.ModeBox1 ul')[9].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_frs;
  913. $('.ModeBox1 ul')[9].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ors;
  914. $('.ModeBox1 ul')[9].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fr;
  915. $('.ModeBox1 ul')[9].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_or;
  916. $('.ModeBox1 ul')[9].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_srd;
  917. $('.ModeBox1 ul')[9].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_srt;
  918. $('.ModeBox1 ul')[9].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_mhdr;
  919. $('.ModeBox1')[0].children[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_ad;
  920. $('.ModeBox1 ul')[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_trsr;
  921. $('.ModeBox1 ul')[10].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpl2;
  922. $('.ModeBox1 ul')[10].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpll;
  923. $('.ModeBox1 ul')[10].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tph;
  924. // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
  925. $("#sketch_name").val(Ardublockly.LOCALISED_TEXT.sketch_name);
  926. // $('#runCode')[0].innerHTML = Ardublockly.LOCALISED_TEXT.runCode;
  927. // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
  928. // $('#resetMainUI')[0].innerHTML = Ardublockly.LOCALISED_TEXT.resetMainUI;
  929. $('#select_dropdown')[0].value = Ardublockly.LOCALISED_TEXT.select_dropdown;
  930. // $('#iot_modules')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  931. $(".qiehuanbtn")[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_csm;
  932. $("#localsssssaveOrOpen")[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_butvmi;
  933. $("#localsssssaveOrOpen")[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_buartlp;
  934. // $('#ai_tt div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
  935. // $('#ai_tt div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
  936. // $('#ai_tt div')[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
  937. // $('#ai_tt div')[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
  938. // $('#ai_tt div')[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor;
  939. }
  940. function selectOnload() {
  941. $('.select-connected')[0].onchange = function () {
  942. var a = $('.select-connected')[0].selectedIndex;
  943. if (a == 0) {
  944. isWifiContent = false
  945. $('#Serial_Interaction').css("display", 'inline-block')
  946. $('#IP').css('display', 'none')
  947. } else {
  948. isWifiContent = true
  949. $('#Serial_Interaction').css("display", 'none')
  950. $('#IP').css('display', 'block')
  951. // 进行socket 连接
  952. }
  953. }
  954. $('.selectMode_input')[0].parentNode.onclick = function (e) {
  955. $('.MouduleBox')[0].style.cssText = 'display:block';
  956. }
  957. $('.ModeSelectBox')[0].onclick = function (e) {
  958. U.UF.EV.stopBubble();
  959. // $('.ModeSelect')[0].className = 'ModeSelect active';
  960. $("#select_Example_modal").modal("open")
  961. }
  962. $('#update_log')[0].onclick = function (e) {
  963. $("#loadModal").modal("open")
  964. }
  965. $('#model_download_modal')[0].onclick = function (e) {
  966. $("#select_Model_download_modal").modal("open")
  967. }
  968. var modelsItems = document.getElementsByClassName("modelDownloadItemTitle");
  969. var modelsItemDescs = document.getElementsByClassName("modelDownloadItemDesc");
  970. for (var i = 0, len = modelsItems.length; i < len; i++) {
  971. modelsItems[i].title = modelsItems[i].innerHTML;
  972. }
  973. for (var i = 0, len = modelsItemDescs.length; i < len; i++) {
  974. modelsItemDescs[i].title = modelsItemDescs[i].innerHTML;
  975. }
  976. // var items = document.getElementById("list").getElementsByTagName("li");
  977. //获取5个内容盒子;
  978. var divs = document.getElementById("item").getElementsByTagName("div");
  979. var examples = document.getElementById("item").getElementsByTagName("li");
  980. var divs_type = document.getElementById("item_1").getElementsByTagName("div");
  981. var examples_type = document.getElementById("item_1").getElementsByTagName("li");
  982. var exampleList = document.getElementById("example").getElementsByClassName("con");
  983. // if (items.length != divs.length) {
  984. // return;
  985. // }
  986. for (var i = 0, len = examples.length; i < len; i++) {
  987. examples[i].id = i;
  988. examples[i].onclick = function () {
  989. for (var j = 0, len = examples.length; j < len; j++) {
  990. examples[j].className = "container-middle-noactive arrow";
  991. divs_type[j].style.display = "none";
  992. }
  993. for (var k = 0, len = examples_type.length; k < len; k++) {
  994. examples_type[k].className = "container-middle-1-noactive arrow";
  995. exampleList[k].style.display = "none";
  996. }
  997. this.className = "container-middle-active arrow_active";
  998. divs_type[this.id].getElementsByTagName("li")[0].className = "container-middle-1-active arrow_active";
  999. divs_type[this.id].style.display = "block";
  1000. if (this.id == 0) {
  1001. for (var k = 0, len = exampleList.length; k < len; k++) {
  1002. exampleList[k].style.display = "none";
  1003. }
  1004. exampleList[0].style.display = "block";
  1005. }
  1006. else if (this.id == 1) {
  1007. for (var k = 0, len = exampleList.length; k < len; k++) {
  1008. exampleList[k].style.display = "none";
  1009. }
  1010. exampleList[6].style.display = "block";
  1011. }
  1012. else if (this.id == 2) {
  1013. for (var k = 0, len = exampleList.length; k < len; k++) {
  1014. exampleList[k].style.display = "none";
  1015. }
  1016. exampleList[9].style.display = "block";
  1017. }
  1018. else if (this.id == 3) {
  1019. for (var k = 0, len = exampleList.length; k < len; k++) {
  1020. exampleList[k].style.display = "none";
  1021. }
  1022. exampleList[11].style.display = "block";
  1023. }
  1024. else if (this.id == 4) {
  1025. for (var k = 0, len = exampleList.length; k < len; k++) {
  1026. exampleList[k].style.display = "none";
  1027. }
  1028. exampleList[13].style.display = "block";
  1029. }
  1030. else if (this.id == 5) {
  1031. for (var k = 0, len = exampleList.length; k < len; k++) {
  1032. exampleList[k].style.display = "none";
  1033. }
  1034. exampleList[20].style.display = "block";
  1035. }
  1036. else if (this.id == 6) {
  1037. for (var k = 0, len = exampleList.length; k < len; k++) {
  1038. exampleList[k].style.display = "none";
  1039. }
  1040. exampleList[25].style.display = "block";
  1041. }
  1042. else {
  1043. for (var k = 0, len = exampleList.length; k < len; k++) {
  1044. exampleList[k].style.display = "none";
  1045. }
  1046. exampleList[31].style.display = "block";
  1047. }
  1048. }
  1049. }
  1050. for (var i = 0, len = examples_type.length; i < len; i++) {
  1051. examples_type[i].id = i;
  1052. examples_type[i].onclick = function () {
  1053. for (var k = 0, len = examples_type.length; k < len; k++) {
  1054. examples_type[k].className = "container-middle-1-noactive arrow";
  1055. exampleList[k].style.display = "none";
  1056. }
  1057. this.className = "container-middle-1-active arrow_active";
  1058. exampleList[this.id].style.display = "block";
  1059. }
  1060. }
  1061. likeclose($('.selectMode_input')[0].parentNode, $('.MouduleBox')[0], '', '');
  1062. likeclose($('.ModeSelect')[0].children[0], $('.ModeSelect')[0], 1, 'ModeSelect');
  1063. likeclose($('#bar_ai img')[0], $('.MouduleBox')[1], '', '');
  1064. likeclose($('#bar_t img')[0], $('#ai_tt')[0], '', '');
  1065. var MChild = $('.MouduleBox')[0].children;
  1066. var tchild = $('.MouduleBox')[1].children;
  1067. for (var i = 0; i < MChild.length; i++) {
  1068. tchild[i].onclick = MChild[i].onclick = function (e) {
  1069. window.event ? window.event.cancelBubble = true : e.stopPropagation()
  1070. var e = e.target;
  1071. if (e.parentElement.children[2] && e.parentElement.children[2].children.length > 0) { } else {
  1072. if (e.innerHTML == Ardublockly.LOCALISED_TEXT.iot_module) {
  1073. $("#mode")[0].selectedIndex = 0;
  1074. $("#mode")[0].onchange();
  1075. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  1076. // document.getElementById("list").getElementsByTagName("li")[0].onclick();
  1077. }
  1078. else if (e.innerHTML == Ardublockly.LOCALISED_TEXT.ai_module) {
  1079. $("#mode")[0].selectedIndex = 1;
  1080. $("#mode")[0].onchange();
  1081. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  1082. // document.getElementById("list").getElementsByTagName("li")[1].onclick();
  1083. }
  1084. $('.MouduleBox')[0].style.display = 'none';
  1085. $('.MouduleBox')[1].style.display = 'none';
  1086. $('#ai_tt')[0].style.display = 'none';
  1087. }
  1088. }
  1089. }
  1090. for (var i = 0; i < $('.ModeBox')[0].children.length; i++) {
  1091. $('.ModeBox')[0].children[i].onclick = function (e) {
  1092. window.event ? window.event.cancelBubble = true : e.stopPropagation()
  1093. }
  1094. }
  1095. for (var i = 0; i < $('.ModeBox1')[0].children.length; i++) {
  1096. $('.ModeBox1')[0].children[i].onclick = function (e) {
  1097. window.event ? window.event.cancelBubble = true : e.stopPropagation()
  1098. }
  1099. }
  1100. $("#repl_delete")[0].onclick = function () {
  1101. $("#repl_box_content")[0].innerHTML = "";
  1102. }
  1103. }
  1104. function clickLoadingExample(name) {
  1105. console.log(name)
  1106. $('#select_Example_modal').modal('close');
  1107. Ardublockly.alertExampleMessage(
  1108. '',
  1109. Ardublockly.getLocalStr('loadBlockBody'),
  1110. true, {});
  1111. readTxt("src/python/" + name, function (txt) {
  1112. if (name.split(".")[1] == "xml") {
  1113. var xmlfile = Blockly.Xml.textToDom(txt);
  1114. blockpy.components.editor.setBlocksFromXml(xmlfile);
  1115. } else {
  1116. blockpy.components.editor.codeMirror.setValue(txt);
  1117. }
  1118. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  1119. setTimeout(() => {
  1120. $('#loading').css({ 'display': 'none' });
  1121. $('#example_alert').modal('close');
  1122. }, 300)
  1123. });
  1124. }
  1125. function readTxt(url, fun) {
  1126. var xhr = new XMLHttpRequest();
  1127. xhr.open('get', url, true);
  1128. xhr.send();
  1129. xhr.onreadystatechange = function () {
  1130. if (xhr.readyState == 4 && xhr.status == 200) {
  1131. fun(xhr.responseText)
  1132. }
  1133. };
  1134. }
  1135. function serialSwich(type) {
  1136. if (type == 'Serial_Interaction') {
  1137. $('#python_box').addClass('hidden')
  1138. $('#repl_box').removeClass('hidden')
  1139. $('#serial_plotter_content').addClass('hidden')
  1140. $('#repl_delete').addClass('hidden')
  1141. document.getElementById('repl_delete').style.display = 'none';
  1142. $('#python_SourceCode').removeClass('switch_select')
  1143. $('#python_SourceCode').addClass('switch_box1')
  1144. $('#Serial_Interaction').removeClass('switch_box1')
  1145. $('#Serial_Interaction').addClass('switch_select')
  1146. $('#serial_plotter').removeClass('switch_select')
  1147. $('#serial_plotter').addClass('switch_box1')
  1148. } else if (type == 'python_SourceCode') {
  1149. $('#repl_box').addClass('hidden')
  1150. $('#python_box').removeClass('hidden')
  1151. $('#serial_plotter_content').addClass('hidden')
  1152. $('#repl_delete').addClass('hidden')
  1153. document.getElementById('repl_delete').style.display = 'none';
  1154. $('#Serial_Interaction').removeClass('switch_select')
  1155. $('#Serial_Interaction').addClass('switch_box1')
  1156. $('#python_SourceCode').removeClass('switch_box1')
  1157. $('#python_SourceCode').addClass('switch_select')
  1158. $('#serial_plotter').removeClass('switch_select')
  1159. $('#serial_plotter').addClass('switch_box1')
  1160. saveLocalStorageBlocks('pythonai-mode-blocks-xml')
  1161. setTimeout(function () {
  1162. blockpy.components.editor.updateTextFromModel();
  1163. blockpy.components.editor.updateText()
  1164. blockpy.components.editor.unhighlightLines()
  1165. var text = localStorage.getItem('pythonai-mode-blocks-xml')
  1166. var xmlfile = Blockly.Xml.textToDom(text);
  1167. blockpy.components.editor.setBlocksFromXml(xmlfile);
  1168. }, 100)
  1169. } else if (type == 'serial_plotter') {
  1170. $('#repl_box').addClass('hidden')
  1171. $('#python_box').addClass('hidden')
  1172. $('#serial_plotter_content').removeClass('hidden')
  1173. document.getElementById('repl_delete').style.display = 'inline-block';
  1174. $('#Serial_Interaction').removeClass('switch_select')
  1175. $('#Serial_Interaction').addClass('switch_box1')
  1176. $('#python_SourceCode').removeClass('switch_select')
  1177. $('#python_SourceCode').addClass('switch_box1')
  1178. $('#serial_plotter').removeClass('switch_box1')
  1179. $('#serial_plotter').addClass('switch_select')
  1180. }
  1181. }
  1182. function qiehuanjjj(ele, _container) {
  1183. $("body")[0].addEventListener('click', function (e) {
  1184. if (ele != e.target) {
  1185. _container.className = 'dropdown-content';
  1186. }
  1187. })
  1188. }
  1189. function likeclose(ele, _container, type, _className) {
  1190. $("body")[0].addEventListener('click', function (e) {
  1191. if (ele != e.target && e.target.parentNode != ele) {
  1192. if (type == 1) {
  1193. _container.className = _className;
  1194. } else {
  1195. _container.style.display = 'none'
  1196. }
  1197. }
  1198. })
  1199. }
  1200. function export_data(data, postfix, is_firefox) {
  1201. let url = new Blob([data], { type: 'text/plain' });
  1202. let download_link = URL.createObjectURL(url);
  1203. let a = document.createElement('a');
  1204. a.style = "display:none";
  1205. a.href = download_link;
  1206. a.download = "user_latest_code" + postfix;
  1207. if (is_firefox) {
  1208. document.body.appendChild(a);
  1209. a.click();
  1210. setTimeout(() => document.body.removeChild(a), 100);
  1211. } else
  1212. a.click();
  1213. // URL.revokeObjectURL(download_link);
  1214. // IE edge need a short delay before revoke virtual download link
  1215. setTimeout(() => URL.revokeObjectURL(download_link), 100);
  1216. }
  1217. // 积木生成
  1218. function selectmode(sel, isload) {
  1219. // var _type = 1;
  1220. // if (sel.selectedIndex == 0 && (_type != 0 || isload === true)) {
  1221. saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
  1222. saveLocalStorage("type", 1);
  1223. // $("#changeRunCuploadFilesode").css("display", "inline-block");
  1224. // $("#resetMainUIBtn").css("display", "inline-block");
  1225. blockpy.setAssignment(
  1226. // settings
  1227. {},
  1228. // assignment
  1229. {
  1230. modules: {
  1231. added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Files", "Time", "Serial Comm.", "A.I.Board", "ExtendedFunctions", "AI", "IOT", "system", "ExtendedFunction", "Third_party_Sensor"],
  1232. removed: ['MainBoard']
  1233. }
  1234. },
  1235. // programs
  1236. {
  1237. __main__: ""
  1238. }
  1239. );
  1240. loadLocalStorageBlocks("pythonai-mode-blocks-xml")
  1241. // }
  1242. }
  1243. function getQueryParams() {
  1244. try {
  1245. url = window.location.href;
  1246. query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
  1247. r_params = query_str.split("&");
  1248. params = {};
  1249. for (i in r_params) {
  1250. param = r_params[i].split("=");
  1251. params[param[0]] = param[1];
  1252. }
  1253. return params;
  1254. } catch (e) {
  1255. return {};
  1256. }
  1257. }
  1258. // onresize 多次执行解决办法
  1259. var debounce = function (func, threshold, execAsap) {
  1260. var timeout;
  1261. return function debounced() {
  1262. var obj = this, args = arguments;
  1263. function delayed() {
  1264. if (!execAsap)
  1265. func.apply(obj, args);
  1266. timeout = null;
  1267. };
  1268. if (timeout)
  1269. clearTimeout(timeout);
  1270. else if (execAsap)
  1271. func.apply(obj, args);
  1272. timeout = setTimeout(delayed, threshold || 100);
  1273. };
  1274. }
  1275. // window.onresize = debounce(function () {
  1276. // if (document.body.clientWidth < 1265) {
  1277. // alert(CCB.str_group.alert)
  1278. // }
  1279. // }, 100, true);
  1280. // 切换数据显示方式
  1281. var myChart = "";
  1282. function switchSerial(type) {
  1283. if (type == 2) {
  1284. document.getElementById('image_transmission').style.display = 'none';
  1285. document.getElementById('repl_box_content').style.display = 'block';
  1286. // document.getElementById('repl_box_content').innerHTML = ""
  1287. document.getElementsByClassName('translatable_image_transmission')[0].classList.remove("serial-active")
  1288. document.getElementsByClassName('translatable_serial_plotter')[1].classList.add("serial-active")
  1289. } else {
  1290. document.getElementById('image_transmission').style.display = 'block';
  1291. document.getElementById('repl_box_content').style.display = 'none';
  1292. document.getElementsByClassName('translatable_image_transmission')[0].classList.add("serial-active")
  1293. document.getElementsByClassName('translatable_serial_plotter')[1].classList.remove("serial-active")
  1294. // document.getElementById('repl_box_content').innerHTML = ""
  1295. }
  1296. }
  1297. // 点击下载文件
  1298. function fileDownload(url, name) {
  1299. var nowA = document.createElement('a');
  1300. nowA.setAttribute('href', url);
  1301. nowA.setAttribute('download', name);
  1302. nowA.style.display = 'none';
  1303. document.body.appendChild(nowA);
  1304. nowA.click();
  1305. document.body.removeChild(nowA);
  1306. }
  1307. // 点击复制分享链接
  1308. function copyShare() {
  1309. $('#cloudBtn-shares').click(() => {
  1310. if (CCB.userState) {
  1311. let time = 10000
  1312. var $toastContent = $(`<span id="abc">${CCB.str_group.share_loading}</span>`)
  1313. Materialize.toast($toastContent, time, "shareUrl")
  1314. let fileNmae = new Date().getTime()
  1315. $.ajax(`${CCB.base_url}blockx/`, {
  1316. type: "POST",
  1317. xhrFields: {
  1318. withCredentials: true
  1319. },
  1320. data: {
  1321. filename: fileNmae,
  1322. xml: Ardublockly.generateXml()
  1323. },
  1324. success: (res) => {
  1325. let fileobject = {
  1326. filenameId: res.filename,
  1327. filename: fileNmae,
  1328. time: getCurrentDate(),
  1329. timestamp: (new Date()).valueOf()
  1330. };
  1331. CCB.cloudFileList.push(fileobject);
  1332. CCB.selectCloudFile = filename;
  1333. var id = U.UF.C.queryString("Qd");
  1334. var url = window.location.href + '&Qd=' + res.filename;
  1335. if (id) {
  1336. url = window.location.href.replace(/Qd=[0-9a-zA-Z_]+/g, "Qd=" + res.filename);
  1337. }
  1338. let flag = copyText(url);
  1339. // time = 3000;
  1340. // document.getElementById('abc').innerHTML = flag ? CCB.str_group.share_success : CCB.str_group.share_fail
  1341. // setTimeout(function () {
  1342. Materialize.toast(flag ? CCB.str_group.share_success : CCB.str_group.share_fail, 3000, "shareUrl")
  1343. //}, time)
  1344. },
  1345. error: () => {
  1346. $("#cloud_modal_preload").css("display", "none");
  1347. // time = 4000;
  1348. // Materialize.toast(CCB.str_group.error_uploadFile, 4000);
  1349. // document.getElementById('abc').style.display = CCB.str_group.error_uploadFile
  1350. setTimeout(function () {
  1351. Materialize.toast(CCB.str_group.error_uploadFile, 4000)
  1352. }, time)
  1353. }
  1354. });
  1355. } else {
  1356. Materialize.toast(CCB.str_group.requestLogin, 3000);
  1357. $("#login_modal").modal("open")
  1358. }
  1359. })
  1360. }
  1361. function enterNext(value) {
  1362. $("#select_folder").html('')
  1363. var path = getLocalStorage("path") + value;
  1364. // 获取 sd 卡的路径
  1365. saveLocalStorage("path", path + '/');
  1366. saveLocalStorage("fileAndFolder", '');
  1367. pythoncmdselect(getLocalStorage("path"), function (data) {
  1368. if (data.responseText != null) {
  1369. var arr = data.responseText.split("\n");
  1370. saveLocalStorage("fileAndFolder", arr);
  1371. var str = '<div style="display:flex;flex-wrap: wrap;align-content: space-around;justify-content:space-around;">';
  1372. for (var i = 0; i < arr.length - 1; i++) {
  1373. if (arr[i].indexOf(".") != -1) {
  1374. var aa = arr[i].replace("\r", "").replace("\r", "");
  1375. str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
  1376. str += '<img src="blockly/media/fileManage/file.png" style="position: relative;"/>';
  1377. str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 65px;margin-top: -5px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
  1378. str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
  1379. }
  1380. else {
  1381. var aa = arr[i].replace("\r", "").replace("\r", "");
  1382. str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
  1383. str += '<img src="blockly/media/fileManage/package.png" style="position: relative;" onclick="enterNext(\'' + aa + '\')">';
  1384. str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 80px;margin-top: -10px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
  1385. str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
  1386. }
  1387. }
  1388. if ((arr.length - 1) % 4 == 1) {
  1389. str += '<div class = "box-item"></div><div class = "box-item"></div><div class = "box-item"></div>';
  1390. }
  1391. else if ((arr.length - 1) % 4 == 2) {
  1392. str += '<div class = "box-item"></div><div class = "box-item"></div>';
  1393. }
  1394. else if ((arr.length - 1) % 4 == 3) {
  1395. str += '<div class = "box-item"></div>';
  1396. }
  1397. str += '</div>';
  1398. $("#select_folder").html(str)
  1399. }
  1400. })
  1401. $("#return_folder").css("display", "inline-block");
  1402. }
  1403. function deleteFile(value) {
  1404. $("#select_folder").html('')
  1405. $('#cancle_delete').css('display', 'none');
  1406. $("#delete_folder").css('display', 'inline-block');
  1407. var path = getLocalStorage("path") + value;
  1408. saveLocalStorage("fileAndFolder", '');
  1409. // 获取 sd 卡的路径
  1410. pythoncmddel(path, function (data) {
  1411. if (data.responseText != null) {
  1412. var arr = data.responseText.split("\n");
  1413. saveLocalStorage("fileAndFolder", arr);
  1414. var str = '<div style="display:flex;flex-wrap: wrap;align-content: space-around;justify-content:space-around;">';
  1415. for (var i = 0; i < arr.length - 1; i++) {
  1416. if (arr[i].indexOf(".") != -1) {
  1417. var aa = arr[i].replace("\r", "").replace("\r", "");
  1418. str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
  1419. str += '<img src="blockly/media/fileManage/file.png" style="position: relative;"/>';
  1420. str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 65px;margin-top: -5px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
  1421. str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
  1422. }
  1423. else {
  1424. var aa = arr[i].replace("\r", "").replace("\r", "");
  1425. str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
  1426. str += '<img src="blockly/media/fileManage/package.png" style="position: relative;" onclick="enterNext(\'' + aa + '\')">';
  1427. str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 80px;margin-top: -10px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
  1428. str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
  1429. }
  1430. }
  1431. if ((arr.length - 1) % 4 == 1) {
  1432. str += '<div class = "box-item"></div><div class = "box-item"></div><div class = "box-item"></div>';
  1433. }
  1434. else if ((arr.length - 1) % 4 == 2) {
  1435. str += '<div class = "box-item"></div><div class = "box-item"></div>';
  1436. }
  1437. else if ((arr.length - 1) % 4 == 3) {
  1438. str += '<div class = "box-item"></div>';
  1439. }
  1440. str += '</div>';
  1441. $("#select_folder").html(str)
  1442. }
  1443. })
  1444. }
  1445. String.prototype.isEmpty = function () {
  1446. var s1 = this.replace(/[\r\n]/g, '').replace(/[ ]/g, ''),
  1447. s2 = (s1 == '') ? true : false;
  1448. return s2;
  1449. };
  1450. function isInArray(str, value) {
  1451. var arr = str.split(",");
  1452. for (var i = 0; i < arr.length; i++) {
  1453. if (value === arr[i].replace("\r", "").replace("\r", "")) {
  1454. return true;
  1455. }
  1456. }
  1457. return false;
  1458. }
  1459. function deleteFileOrFolder() {
  1460. if (!$("#select_folder").html().isEmpty()) {
  1461. $('.deleteImg').css('display', 'block');
  1462. $('#cancle_delete').css('display', 'inline-block');
  1463. $("#delete_folder").css('display', 'none');
  1464. }
  1465. }
  1466. function cancelDeleteFileOrFolder() {
  1467. if (!$("#select_folder").html().isEmpty()) {
  1468. $('.deleteImg').css('display', 'none');
  1469. $('#cancle_delete').css('display', 'none');
  1470. $("#delete_folder").css('display', 'inline-block');
  1471. }
  1472. }
  1473. function return_pre_folder() {
  1474. $("#select_folder").html('');
  1475. var path = getLocalStorage("path").split("/").slice(0, -2).join("/") + '/';
  1476. // 获取 sd 卡的路径
  1477. saveLocalStorage("path", path);
  1478. pythoncmdselect(path, function (data) {
  1479. if (data.responseText != null) {
  1480. var arr = data.responseText.split("\n");
  1481. saveLocalStorage("fileAndFolder", arr);
  1482. var str = '<div style="display:flex;flex-wrap: wrap;align-content: space-around;justify-content:space-around;">';
  1483. for (var i = 0; i < arr.length - 1; i++) {
  1484. if (arr[i].indexOf(".") != -1) {
  1485. var aa = arr[i].replace("\r", "").replace("\r", "");
  1486. str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
  1487. str += '<img src="blockly/media/fileManage/file.png" style="position: relative;"/>';
  1488. str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 65px;margin-top: -5px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
  1489. str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
  1490. }
  1491. else {
  1492. var aa = arr[i].replace("\r", "").replace("\r", "");
  1493. str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
  1494. str += '<img src="blockly/media/fileManage/package.png" style="position: relative;" onclick="enterNext(\'' + aa + '\')">';
  1495. str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 80px;margin-top: -10px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
  1496. str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
  1497. }
  1498. }
  1499. if ((arr.length - 1) % 4 == 1) {
  1500. str += '<div class = "box-item"></div><div class = "box-item"></div><div class = "box-item"></div>';
  1501. }
  1502. else if ((arr.length - 1) % 4 == 2) {
  1503. str += '<div class = "box-item"></div><div class = "box-item"></div>';
  1504. }
  1505. else if ((arr.length - 1) % 4 == 3) {
  1506. str += '<div class = "box-item"></div>';
  1507. }
  1508. str += '</div>';
  1509. $("#select_folder").html(str)
  1510. }
  1511. })
  1512. if (path == "/") {
  1513. $("#return_folder").css("display", "none");
  1514. }
  1515. else {
  1516. $("#return_folder").css("display", "inline-block");
  1517. }
  1518. }
  1519. function uploadSuccess(data) {
  1520. console.log(data);
  1521. }
  1522. function toHref_own(href) {
  1523. window.open(href + "&lang=" + localStorage.getItem("handPyLanguage"), "_blank");
  1524. }
  1525. function toHref(href) {
  1526. window.open(href + "/?lang=" + localStorage.getItem("handPyLanguage"), "_blank");
  1527. }
  1528. function select_Module(module) {
  1529. if (module == 'AI_module') {
  1530. $('#AI_module').addClass("moduleActive");
  1531. $('#IoT_module').removeClass("moduleActive");
  1532. }
  1533. else {
  1534. $('#IoT_module').addClass("moduleActive");
  1535. $('#AI_module').removeClass("moduleActive");
  1536. }
  1537. }
  1538. function selectModule_confirm() {
  1539. if ($("#AI_module").attr('class') == "moduleActive") {
  1540. $("#mode")[0].selectedIndex = 1;
  1541. $("#mode")[0].onchange();
  1542. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  1543. // document.getElementById("list").getElementsByTagName("li")[1].onclick();
  1544. $("#selectModule").modal('close');
  1545. $('#IoT_module').removeClass("moduleActive");
  1546. $('#AI_module').removeClass("moduleActive");
  1547. }
  1548. else if ($("#IoT_module").attr('class') == "moduleActive") {
  1549. $("#mode")[0].selectedIndex = 0;
  1550. $("#mode")[0].onchange();
  1551. $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  1552. // document.getElementById("list").getElementsByTagName("li")[0].onclick();
  1553. $("#selectModule").modal('close');
  1554. $('#IoT_module').removeClass("moduleActive");
  1555. $('#AI_module').removeClass("moduleActive");
  1556. }
  1557. }
  1558. function mouseMove() {
  1559. // 拖拉改变右侧上下块的高度
  1560. let PC = document.getElementById('mouseMove')
  1561. let divA = document.getElementById('py-editor')
  1562. let divB = document.getElementById('mouseMove-bottom')
  1563. let midd = document.getElementById('left_move_right')
  1564. let left_midd = document.getElementById('blocks_content')
  1565. let right = document.getElementById('sss')
  1566. // $('#mouseMove').click()
  1567. // window.addEventListener('mousemove', function () {
  1568. PC.onmousedown = function (ev) {
  1569. $('#wabadb_iframe_model').removeClass('hidden')
  1570. // 鼠标按下坐标
  1571. let pX1 = ev.clientX
  1572. let pY1 = ev.clientY
  1573. // 得到两个 div 的高度
  1574. let heightA = divA.clientHeight
  1575. let heightB = divB.clientHeight
  1576. // divB.style.height = '300px'
  1577. document.onmousemove = function (ev) {
  1578. // document.onmousedown = new Function("return false");
  1579. // document.onmouseup = new Function("return true");
  1580. // 鼠标移动是坐标
  1581. let pX2 = ev.clientX
  1582. let pY2 = ev.clientY
  1583. // 计算出鼠标上下移动的距离
  1584. let Y = pY2 - pY1
  1585. if (heightB - Y > 5 && heightA + Y > 60) {
  1586. divB.style.height = heightB - Y + 'px'
  1587. divA.style.height = heightA + Y + 'px'
  1588. }
  1589. }
  1590. //清除
  1591. document.onmouseup = function (ev) {
  1592. $('#wabadb_iframe_model').addClass('hidden')
  1593. document.onmousemove = null;
  1594. document.onmouseup = null;
  1595. }
  1596. }
  1597. midd.onmousedown = function (ev) {
  1598. $('#wabadb_iframe_model').removeClass('hidden')
  1599. let pX1 = ev.clientX
  1600. let pY1 = ev.clientY
  1601. // 得到两个 div 的宽度
  1602. let widthA = left_midd.clientWidth
  1603. let widthB = right.clientWidth
  1604. // divB.style.height = '300px'
  1605. document.onmousemove = function (ev) {
  1606. // 鼠标移动是坐标
  1607. let pX2 = ev.clientX
  1608. let pY2 = ev.clientY
  1609. // 计算出鼠标左右移动的距离
  1610. let Y = pX2 - pX1
  1611. if (Number(widthB - Y) > 425 && widthA + Y > 135) {
  1612. left_midd.style.width = widthA + Y + 'px'
  1613. right.style.width = widthB - Y + 'px'
  1614. // Ardublockly.toogleToolbox()
  1615. setTimeout(function () {
  1616. Blockly.svgResize(blockpy.components.editor.blockly);
  1617. Blockly.svgResize(Blockly.mainWorkspace);
  1618. }, 100)
  1619. }
  1620. }
  1621. //清除
  1622. document.onmouseup = function (ev) {
  1623. $('#wabadb_iframe_model').addClass('hidden')
  1624. document.onmousemove = null;
  1625. document.onmouseup = null;
  1626. }
  1627. }
  1628. // })
  1629. }
  1630. let isWebadb = ''
  1631. let isDevice = ''
  1632. let isConnect = ''
  1633. function addWebadb() {
  1634. if (isWifiContent) {
  1635. // $("#webadb_connect")[0].disabled = false;
  1636. if ($('#IP').val().length > 0) {
  1637. $('#wifi_process').modal('open');
  1638. console.log(`${$('#IP').val()}:5678`)
  1639. if (window.location.href.split("://")[0] === "https") {
  1640. $("#getIpLink").html(`https://${$('#IP').val()}:5678`)
  1641. } else {
  1642. $("#getIpLink").html(`http://${$('#IP').val()}:5678`)
  1643. }
  1644. } else {
  1645. alert(CCB.str_group.ipAddress)
  1646. }
  1647. // console.log(window.location.origin.indexOf("https"))
  1648. } else {
  1649. document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbadd").click();
  1650. }
  1651. // $("#webadb_connect")[0].disabled = false;
  1652. // isDevice = document.getElementById("webadb_iframe").contentWindow.getdevice().device;
  1653. }
  1654. // webadb 连接
  1655. function webadbConnect() {
  1656. if (isWifiContent) {
  1657. if ($('#webadb_connect')[0].innerHTML == Ardublockly.LOCALISED_TEXT.connectBtn) {
  1658. connectWebsocket()
  1659. } else {
  1660. ws.close()
  1661. }
  1662. } else {
  1663. if (!!isConnect) {
  1664. document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbdisconnect").click()
  1665. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn
  1666. } else {
  1667. // serialSwich('Serial_Interaction')
  1668. document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbconnect").click()
  1669. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
  1670. }
  1671. }
  1672. }
  1673. function ac() {
  1674. }
  1675. function systemCommand(com) {
  1676. if (isWifiContent) {
  1677. sendWebsocket(`import os
  1678. os.system("${com}")`, 'run')
  1679. setTimeout(() => {
  1680. ws.close()
  1681. }, 200)
  1682. } else {
  1683. document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(com).then(function (e) {
  1684. e.stdout.reader.read().then(function (e) {
  1685. // 重启或关机
  1686. })
  1687. }).catch(err => {
  1688. })
  1689. }
  1690. }
  1691. function backHome() {
  1692. if (isWifiContent) {
  1693. // ws.send(`import os
  1694. // os.system("rm /tmp/disable")`,"run")
  1695. } else {
  1696. if (isRunCodeData) {
  1697. isRunCodeData.kill().then(() => {
  1698. document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(`rm /tmp/disable`).then(function (e) {
  1699. isRunCodeData = e;
  1700. })
  1701. })
  1702. } else {
  1703. document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(`rm /tmp/disable`).then(function (e) {
  1704. isRunCodeData = e;
  1705. })
  1706. }
  1707. }
  1708. $("#backHome").addClass('disabled')
  1709. }
  1710. // 点击切换更新记录
  1711. function switchUpdate(type) {
  1712. if (type == '1') {
  1713. $('.update-old').css({ display: 'none' })
  1714. $('.update-new').css({ display: 'block' })
  1715. } else {
  1716. $('.update-old').css({ display: 'block' })
  1717. $('.update-new').css({ display: 'none' })
  1718. }
  1719. }
  1720. function Uint8ArrayToString(fileData) {
  1721. const Utf8Decoder = new TextDecoder();
  1722. return Utf8Decoder.decode(fileData);
  1723. // var dataString = "";
  1724. // for (var i = 0; i < fileData.length; i++) {
  1725. // dataString += String.fromCharCode(fileData[i]);
  1726. // }
  1727. // return dataString
  1728. }
  1729. function run_user_lastet_code() {
  1730. canvasImg = $("#image_transmission_canvas")[0].getContext("2d")
  1731. canImage = new Image()
  1732. document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(`ln -sf /root/user_latest_code.py /tmp/event && touch /tmp/disable && python -u /tmp/event`).then(function (e) {
  1733. isRunCodeData = e;
  1734. _data = "";
  1735. _ti = "";
  1736. serverPrint(e)
  1737. RunInterval = setInterval(() => {
  1738. serverPrint(e)
  1739. }, 10);
  1740. })
  1741. }
  1742. var _data = "";
  1743. var _ti;
  1744. var canvasImg = "";
  1745. var canImage = "";
  1746. function serverPrint(e) {
  1747. if (e.stdout.readable._state != 'readable') {
  1748. $('#backHome').addClass('disabled')
  1749. clearInterval(RunInterval)
  1750. backHome()
  1751. }
  1752. else {
  1753. $('#backHome').removeClass('disabled')
  1754. }
  1755. e.stdout.reader.read().then(function (e) {
  1756. if (e.value) {
  1757. clearTimeout(_ti);
  1758. _data += Uint8ArrayToString(e.value);
  1759. //showServal(_data)
  1760. _ti = setTimeout(function () {
  1761. showServal(_data)
  1762. _data = "";
  1763. }, 50)
  1764. }
  1765. }).catch(err => {
  1766. $('.progress > .determinate').css('width', 0);
  1767. })
  1768. }
  1769. var newStr = ''
  1770. var isScreenshot = false
  1771. function showServal(_data) {
  1772. if (!isScreenshot) {
  1773. try {
  1774. newStr = _data;
  1775. canImage.src = _data;
  1776. canImage.onload = () => {
  1777. canvasImg.drawImage(canImage, 0, 0, 300, 150)
  1778. $("#training_screenshot").css({
  1779. "display": "block"
  1780. })
  1781. $("#training_upload").css({
  1782. "display": "none"
  1783. })
  1784. $("#training_cancel").css({
  1785. "display": "none"
  1786. })
  1787. }
  1788. }
  1789. catch (e) {
  1790. }
  1791. }
  1792. else {
  1793. try {
  1794. canImage.src = newStr;
  1795. canImage.onload = () => {
  1796. canvasImg.drawImage(canImage, 0, 0, 300, 150)
  1797. $("#training_screenshot").css({
  1798. "display": "none"
  1799. })
  1800. $("#training_upload").css({
  1801. "display": "block"
  1802. })
  1803. $("#training_cancel").css({
  1804. "display": "block"
  1805. })
  1806. }
  1807. }
  1808. catch (e) {
  1809. }
  1810. }
  1811. // }
  1812. if (_data.indexOf(`File "/tmp/event", line`) > -1) {
  1813. setTimeout(() => {
  1814. $("#error-btn").css("display", "block")
  1815. $('.card-reveal').css({ 'display': 'block', 'transform': 'translateY(-100%)', 'padding': '8px 13px' });
  1816. }, 500)
  1817. let errMsg = _data.slice(_data.indexOf(`File "/tmp/event", line`)).split('\r\n')
  1818. $("#err-msg").text(`${errMsg[0]}\n${errMsg[1]}\n${errMsg[2]}\n${CCB.str_group.errSol}\n${Ardublockly.LOCALISED_TEXT.error_pv}`)
  1819. } else if (_data.indexOf("IndentationError") > -1 || _data.indexOf("SyntaxError") > -1) {
  1820. setTimeout(() => {
  1821. $("#error-btn").css("display", "block")
  1822. $('.card-reveal').css({ 'display': 'block', 'transform': 'translateY(-100%)', 'padding': '8px 13px' });
  1823. }, 500)
  1824. $("#err-msg").text(`_data\n${CCB.str_group.errSol}\n${Ardublockly.LOCALISED_TEXT.error_unindent}`)
  1825. } else if (_data.indexOf("fopen") > -1) {
  1826. setTimeout(() => {
  1827. $("#error-btn").css("display", "block")
  1828. $('.card-reveal').css({ 'display': 'block', 'transform': 'translateY(-100%)', 'padding': '8px 13px' });
  1829. }, 500)
  1830. $("#err-msg").text(`${_data.slice(_data.indexOf("fopen"), _data.indexOf("failed"))}\n${Ardublockly.LOCALISED_TEXT.ENOEN}`)
  1831. } else {
  1832. let c = ''
  1833. let m = _data.indexOf("DEBUG") > -1 || _data.indexOf("debug") > -1 || _data.indexOf("modName") > -1 || _data.indexOf("tag") > -1 || _data.indexOf("branch") > -1 || _data.indexOf("commit") > -1 || _data.indexOf("author") > -1 || _data.indexOf("WARNING") > -1
  1834. if (!m) {
  1835. let b = _data.split('\r\n')
  1836. for (let i = 0; i <= b.length - 1; i++) {
  1837. c += `<div>${b[i]}</div>`
  1838. }
  1839. }
  1840. $('#repl_box_content').append(c);
  1841. }
  1842. }
  1843. function getQrCode() {
  1844. document.getElementById("codeImg").innerHTML = ""
  1845. let browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  1846. let qrCode = ""
  1847. if (browserWidth < 500) {
  1848. qrCode = new QRCode(document.getElementById("codeImg"), {
  1849. width: 150,
  1850. height: 150
  1851. })
  1852. } else {
  1853. qrCode = new QRCode(document.getElementById("codeImg"), {
  1854. width: 200,
  1855. height: 200
  1856. })
  1857. }
  1858. let SSID = $('#SSID').val()
  1859. let PASS = $('#PAS').val()
  1860. if (SSID == "" && PASS == "") {
  1861. alert(Ardublockly.LOCALISED_TEXT.SSIDPWD)
  1862. return
  1863. }
  1864. console.log(`SSID:${SSID};PASS:${PASS}`)
  1865. qrCode.makeCode(`SSID:${SSID};PASS:${PASS}`)
  1866. }
  1867. var isWifiContent = false
  1868. var ws = ''
  1869. var WifiContent = 'close';
  1870. let ifconfig = "wifi_get_connection_info_test 1 > /root/event.log &";
  1871. // let ifconfig = `import os
  1872. // cmd = "wifi_get_connection_info_test 1"
  1873. // res = os.popen(cmd).read()
  1874. // print("res",res)
  1875. // `
  1876. function connectWebsocket(type) {
  1877. ws = new WebSocket(`wss://${$('#IP').val()}:5678`);
  1878. WifiContent = type
  1879. ws.onopen = () => {
  1880. // console.log('连接服务端WebSocket成功');
  1881. $('#repl_box_content').append(`<div>${CCB.str_group.connection_success}</div>`);
  1882. serialSwich('serial_plotter')
  1883. $("#runCode").removeClass('disabled')
  1884. $("#uploadpy").removeClass('disabled')
  1885. $("#resetDevice").removeClass('disabled')
  1886. $("#poweroff").removeClass('disabled')
  1887. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
  1888. $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusbar
  1889. $('#cnt_icon').css('display', 'inline-block')
  1890. $('#discnt_icon').css('display', 'none')
  1891. $('#select-connected').attr("disabled", true)
  1892. setTimeout(() => {
  1893. //sendWebsocket(ifconfig,"run")
  1894. ws.send(ifconfig)
  1895. }, 1000)
  1896. };
  1897. // 监听服务端消息(接收消息)
  1898. ws.onmessage = (msg) => {
  1899. $('#repl_box_content').append(`<div>${msg.data}</div>`);
  1900. };
  1901. // 监听连接失败
  1902. ws.onerror = () => {
  1903. // console.log('连接失败,正在重连...');
  1904. $('.progress > .determinate').css('width', '0');
  1905. $('#repl_box_content').append(`<div>${CCB.str_group.connection}</div>`);
  1906. // connectWebsocket();
  1907. };
  1908. // 监听连接关闭
  1909. ws.onclose = () => {
  1910. $('#repl_box_content').append(`<div>${CCB.str_group.disconnect}</div>`);
  1911. // console.log('连接关闭');
  1912. $('#cnt_icon').css('display', 'none')
  1913. $('#discnt_icon').css('display', 'inline-block')
  1914. $('#select-connected').attr("disabled", false)
  1915. setTimeout(() => {
  1916. $("#webadb_connect")[0].disabled = false;
  1917. $("#webadb_add")[0].disabled = false;
  1918. $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusNotConn
  1919. $("#runCode").addClass('disabled')
  1920. $("#uploadpy").addClass('disabled')
  1921. $("#resetDevice").addClass('disabled')
  1922. $("#backHome").addClass('disabled')
  1923. $("#poweroff").addClass('disabled')
  1924. $('#message_file').css({ display: 'none' })
  1925. $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
  1926. $('.progress > .determinate').css('width', 0);
  1927. }, 500)
  1928. };
  1929. };
  1930. function sendWebsocket(file, type) {
  1931. canvasImg = $("#image_transmission_canvas")[0].getContext("2d")
  1932. canImage = new Image()
  1933. // console.log(file)
  1934. // ws.send('ls')
  1935. // ws.send(`echo '${file}' > user_latest_code.py && ln -sf /root/user_latest_code.py /tmp/event && touch /tmp/disable && python /tmp/event`)
  1936. if (type == "run") {
  1937. ws.send(`echo '${file}' > /root/user_latest_code.py && ln -sf /root/user_latest_code.py /tmp/event && touch /tmp/disable && python -u /tmp/event > /root/event.log`)
  1938. } else {
  1939. ws.send(`echo '${file}' > /root/user_latest_code.py`)
  1940. }
  1941. ws.onmessage = (msg) => {
  1942. if (msg.data.indexOf('data:image/jpg;base64') > -1) {
  1943. try {
  1944. canImage.src = msg.data;
  1945. canImage.onload = () => {
  1946. canvasImg.drawImage(canImage, 0, 0, 300, 150)
  1947. }
  1948. }
  1949. catch (e) {
  1950. }
  1951. } else {
  1952. // modName ,tag,branch,commit,author
  1953. let a = msg.data.indexOf("DEBUG") > -1 || msg.data.indexOf("debug") > -1 || msg.data.indexOf("modName") > -1 || msg.data.indexOf("tag") > -1 || msg.data.indexOf("branch") > -1 || msg.data.indexOf("commit") > -1 || msg.data.indexOf("author") > -1
  1954. if (!a) {
  1955. $('#repl_box_content').append(`<div>${msg.data}</div>`);
  1956. }
  1957. // $('.progress > .determinate').css('width', '100%');
  1958. }
  1959. // $("#backHome").removeClass('disabled')
  1960. $('.progress > .determinate').css('width', '100%');
  1961. };
  1962. // setTimeout(function () {
  1963. $('.progress > .determinate').css('width', '100%');
  1964. $("#runCode").removeClass('disabled')
  1965. $("#uploadpy").removeClass('disabled')
  1966. $("#resetDevice").removeClass('disabled')
  1967. $("#poweroff").removeClass('disabled')
  1968. // }, 2000);
  1969. }
  1970. function mobileSwitchMode(type) {
  1971. if (type == 'python') {
  1972. $('.mobileSwitch')[0].style.display = "block"
  1973. $('.mobileSwitch')[1].style.display = "none"
  1974. $('#blocks_content')[0].style.display = "block"
  1975. $('#py-editor')[0].style.display = "none"
  1976. $('#sss')[0].style.height = 'fit-content'
  1977. } else {
  1978. $('.mobileSwitch')[1].style.display = "block"
  1979. $('.mobileSwitch')[0].style.display = "none"
  1980. $('#blocks_content')[0].style.display = "none"
  1981. $('#py-editor')[0].style.display = "block"
  1982. $('#sss')[0].style.height = '100%'
  1983. }
  1984. setTimeout(function () {
  1985. blockpy.components.editor.updateTextFromModel();
  1986. blockpy.components.editor.updateText()
  1987. blockpy.components.editor.unhighlightLines()
  1988. var text = localStorage.getItem('pythonai-mode-blocks-xml')
  1989. var xmlfile = Blockly.Xml.textToDom(text);
  1990. blockpy.components.editor.setBlocksFromXml(xmlfile);
  1991. }, 100)
  1992. }
  1993. function linkOkay() {
  1994. $("#webadb_connect")[0].disabled = false;
  1995. console.log(`https://${$('#IP').val()}:5678`)
  1996. if (window.location.href.split("://")[0] === "https") {
  1997. window.open(`https://${$('#IP').val()}:5678`, '_blank');
  1998. } else {
  1999. window.open(`http://${$('#IP').val()}:5678`, '_blank');
  2000. }
  2001. $('#wifi_process').modal('close');
  2002. }
  2003. // 跨网页复制
  2004. document.addEventListener("paste", function (event) {
  2005. if ((event.clipboardData || event.originalEvent)) {
  2006. var clipboardData = (event.clipboardData || window.clipboardData);
  2007. var val = clipboardData.getData('text');
  2008. // console.log(Blockly.Xml.workspaceToDom(blockpy.components.editor.blockly))
  2009. // let a = val.substr(0,7)+val.substr(44,val.length)
  2010. let c = Blockly.Xml.textToDom(val)
  2011. Blockly.clipboardSource_ = blockpy.components.editor.blockly
  2012. Blockly.clipboardSource_.paste(c)
  2013. // event.preventDefault();
  2014. }
  2015. });
  2016. function loadingXml(result_xml) {
  2017. var success = Ardublockly.replaceBlocksfromXml(result_xml);
  2018. if (!success) {
  2019. Ardublockly.alertMessage(Ardublockly.getLocalStr('ErrorBlockTitle'), Ardublockly.getLocalStr('ErrorBlockBody'), false);
  2020. }
  2021. }
  2022. function getLoadXmlStr() {
  2023. var xml = Blockly.Xml.workspaceToDom(blockpy.components.editor.blockly);
  2024. var XmlStr = Blockly.Xml.domToText(xml);
  2025. return XmlStr
  2026. }
  2027. var trainImg = ""
  2028. function getTrainImg() {
  2029. isScreenshot = true
  2030. screenIndex = screenIndex + 1
  2031. }
  2032. function convertBase64UrlToBlob(urlData) {
  2033. var bytes = window.atob(urlData.split(',')[1]); //如果包含data:image/png;base64,串,需要去掉url的头,并转换为byte
  2034. // var bytes = window.atob(urlData); //去掉url的头,并转换为byte
  2035. //处理异常,将ascii码小于0的转换为大于0
  2036. var ab = new ArrayBuffer(bytes.length);
  2037. var ia = new Uint8Array(ab);
  2038. for (var i = 0; i < bytes.length; i++) {
  2039. ia[i] = bytes.charCodeAt(i);
  2040. }
  2041. var blob = new Blob([ab], { type: 'image/jpg' })
  2042. var newFile = new File([blob], "image" + screenIndex + ".jpg", { type: 'image/jpg', lastModified: Date.now() });
  2043. return newFile;
  2044. }
  2045. function uploadImg() {
  2046. var formData = new FormData();
  2047. // console.log(newStr)
  2048. formData.append("file", convertBase64UrlToBlob(newStr));
  2049. formData.append("name", datasetName);
  2050. $.ajax(`//traininguser-api.cocorobo.cn/v831_upload_image`, {
  2051. type: "POST",
  2052. data: formData,
  2053. dataType: "json",
  2054. processData: false, // 重要!!告诉jQuery不要去处理发送的数据
  2055. contentType: false, // 重要!!告诉jQuery不要去设置Content-Type请求头
  2056. cache: false, //关闭缓存
  2057. success: (res) => {
  2058. console.log(res)
  2059. }
  2060. });
  2061. isScreenshot = false
  2062. }
  2063. function cancelImg() {
  2064. isScreenshot = false
  2065. }