var burl = 'http://api.edu.cocorobo.cn/edu', ba = '18.136.193.160', db = 'cocorobocloud'; function selecteqWay(tbody) { tbody.innerHTML = ''; U.A.Request(burl + '/devices/select/a', [], function (r) { var res = r.value[0] for (var i = 0; i < res.length; i++) { var _li = $$('li', {}, tbody); $$('div', { 'innerHTML': res[i].deviceid }, _li); if (res[i].status == 1) { var _div = $$('div', { 'class': 'hs_dp_btnbox disconnect' }, _li); $$('span', {}, _div); $$('span', { 'innerHTML': deviceLangu.device_next }, _div); } else { var _div = $$('div', { 'class': 'hs_dp_btnbox connect' }, _li); $$('span', {}, _div); $$('span', { 'innerHTML': deviceLangu.device_on }, _div); } } }); } function getUrlLanguage() { const val = location.search.match(new RegExp('[?&]lang=([^&]+)')); let language = val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : ''; if (['en', 'zh-hant', 'zh-hans'].indexOf(language) < 0) return 'zh-hant'; return language; }; var languages = { cn: { device: "设备", existing_device: "已有设备", add_device: "添加设备", device_id: "设备 ID", device_status: "设备状态", device_confirm: "确认", device_cancel: "取消", add_edevice_success: "设备添加成功", device_next: "下线", device_on: "上线", }, english: { device: "Device", existing_device: "Existing Device", add_device: "Add Device", device_id: "Device ID", device_status: "Device Status", device_confirm: "Confirm", device_cancel: "Cancel", add_edevice_success: "Device added successfully", device_next: "Next", device_on: "On", }, hant: { device: "設備", existing_device: "已有設備", add_device: "添加設備", device_id: "設備 ID", device_status: "設備狀態", device_confirm: "確認", device_cancel: "取消", add_edevice_success: "設備添加成功", device_next: "下線", device_on: "上線", } } var deviceLangu ; let _lang = getUrlLanguage() if(_lang === "en"){ deviceLangu = languages.english }else if(_lang === "zh-hans"){ deviceLangu = languages.cn }else{ deviceLangu = languages.hant } function DevicesSelect() { var BOX = $$("div", {}); var form_main = $$('div', { "className": "form-main" }, BOX); var form_content = $$('div', { "className": "form_content" }, form_main); var form_eqmain = $$('div', { "className": "form_eqmain" }, form_content); var form_eqtitle = $$('div', { 'className': 'form_eqtitle' }, form_eqmain); $$('span', { 'innerHTML': deviceLangu.existing_device }, form_eqtitle); var _add = $$('div', {}, form_eqtitle); $$('span', {}, _add); $$('span', { 'innerHTML': deviceLangu.add_device }, _add); var formtable = $$('div', {}, form_eqmain); var table = $$('div', { 'className': 'hs_pub_tb table' }, formtable); var head = $$('ul', { 'className': 'hs_dp_head' }, table); var _li = $$('li', {}, head); $$('div', { 'innerHTML': deviceLangu.device_id }, _li); $$('div', { 'innerHTML': deviceLangu.device_status }, _li); var tbody = $$('ul', { 'className': 'hs_dp_tbody' }, table); // console.log(r) selecteqWay(tbody); var btnBox = $$('div', { "className": "form-btn" }, BOX); var confirm = $$('button', { "className": "form-confirm", "innerHTML": deviceLangu.device_confirm }, btnBox); new U.UF.UI.form(deviceLangu.device, BOX, { id: 'selecteq', style: { "background": "#fffefe", "width": "800px", // "height": "600px" } }, { isenlarge: false, isnarrow: false }, { style: { "height": "40px", "text-align": "center", "line-height": "40px", "background-repeat": "no-repeat", "font-size": "18px", "background-color": "#3d67bc" } }); _add.onclick = function () { DevicesInsert(); } confirm.onclick = function () { $('#selecteq')[0].remove(); } } function DevicesInsert() { var BOX = $$("div", {}); var form_main = $$('div', { "className": "form-main" }, BOX); var form_content = $$('div', { "className": "form_content" }, form_main); var form_eqmain = $$('div', { "className": "form_eqmain" }, form_content); var form_eqcontent = $$('div', { 'className': 'form_eqcontent' }, form_eqmain); $$('span', { 'innerHTML': deviceLangu.device_id + ":" }, form_eqcontent); $$('input', { 'text': 'input', 'className': 'device_input' }, form_eqcontent); var btnBox = $$('div', { "className": "form-btn" }, BOX); var cencal = $$('button', { "className": "form-cencal", "innerHTML": deviceLangu.device_cancel }, btnBox); var confirm = $$('button', { "className": "form-confirm", "innerHTML": deviceLangu.device_confirm }, btnBox); new U.UF.UI.form(deviceLangu.device, BOX, { id: 'inserteq', style: { "background": "#fffefe", "width": "450px", "height": "300px" } }, { isenlarge: false, isnarrow: false }, { style: { "height": "40px", "text-align": "center", "line-height": "40px", "background-repeat": "no-repeat", "font-size": "18px", "background-color": "#3d67bc" } }); cencal.onclick = function () { $('#inserteq')[0].remove(); } confirm.onclick = function () { // msocket.emit("userconn", { "userid": "a" }); //发送用户数据 msocket.emit("useraddmachine", { "userid": "a", "deviceid": $('.device_input')[0].value }); //发送用户数据 msocket.on('successadd', function (data) { U.Alert(deviceLangu.add_edevice_success); selecteqWay($('.hs_dp_tbody')[0]) }); $('#inserteq')[0].remove(); } }