$(function () { // var communicationCenter = document.querySelector('.communication_center'); var stff = decodeURIComponent(window.atob($.cookie('s2b2b_staff'))) var staffData = JSON.parse(stff); const icon = 'icon-xiangmu' var $sidemenu = $('#sidemenu'); // 监听来自其他窗口的消息 window.addEventListener('message', function (event) { //console.log(event) if (event.origin !== window.location.origin) return; // 验证消息来源 // document.getElementById('message').innerText = event.data; $('#message').css('color', event.data) }); /** * 将十六进制字符串转换为UTF-8字符串 * * @param hex 十六进制字符串 * @returns 转换后的UTF-8字符串 */ function hexToString(hex) { const bytes = new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); const decoder = new TextDecoder('utf-8'); return decoder.decode(bytes); } // /** // * 加载侧边栏菜单 // */ // function loadSideMenu() { // try { // let { result } = getNewPermMenu(staffData.IKEY); // 获取到侧边栏菜单数据树 // $sidemenu.sidemenu({ // data: JSON.parse(hexToString(result)), // onSelect: function (item) { // console.log(window.location.origin); // // console.log(item); // 移除不必要的console.log // console.log(item); // $sidemenu.sidemenu('options').curMenu = item; // const url = '/' + item.URL.split('/').join('/'); // 假设item.URL已经是正确格式的URL,移除不必要的split和join操作 // console.log(window.location.origin + url); // document.getElementById('myFrame').src = url; // } // }); // } catch (error) { // console.error('Error loading side menu:', error); // } // } // loadSideMenu(); $('#toggle').click(function () { var opts = $sidemenu.sidemenu('options'); $sidemenu.sidemenu(opts.collapsed ? 'expand' : 'collapse'); opts = $sidemenu.sidemenu('options'); $sidemenu.sidemenu('resize', { width: opts.collapsed ? 60 : 200 }) $('#cc').layout('panel', 'west').panel('resize', { width: opts.collapsed ? '5%' : '13%' }) $.parser.parse(); // 解析指定节点 }) $('#user_esc').click(function () { //console.log('点击了') // $.removeCookie('s2b2b_staff', '', -1); $.removeCookie('s2b2b_staff', { path: '/' }); if (!($.cookie("s2b2b_staff"))) { //console.log("222222") window.location.href = "login.html"; } }) // $('#certification').click(function () { // // document.getElementById('myFrame').src = '../../../html/account/CorporateCertification.html' // }) apiClick = function () { // document.getElementById('myFrame').src = './api/index.html' } $('#center_main').click(function () { var link = document.getElementById("center_main"); link.href = window.location.protocol+"//"+window.location.host+"/main.html" }) //修改打开事件 $.fn.openmodal_viewig = function () { this.animate({ borderWidth: 0.5, top: '0' }, 500, function () { }) } $.fn.closeModal = function () { this.animate({ borderWidth: 0.5, top: '-999', }, 500, function () { }); }; // 修改密码 $('#change_password').click(function () { $('#window_changePassword').openmodal_viewig() // $('#window_changePassword').window('open') }) $('#submit').click(function () { let staff = { FS_auth_staffData: { IKEY: staffData.IKEY, STAFF_ID: staffData.STAFF_ID } } let oldPass = $('#user_oldPassword').textbox('getValue');//旧密码 let NewPass = $('#user_newPassword').textbox('getValue');// 新密码 let rest = UpStaffPassword(staff, oldPass, NewPass) //console.log(rest) if (rest.result == '1') { showAlert('succeed', '修改成功,请重新登录账户') $('#window_changePassword').closeModal() // setTimeout(() => { // $.removeCookie('s2b2b_staff', { path: '/' }); // window.location.href = "login.html"; // }, 1000); } else { showAlert('error', rest.error) } }) $('#close-moda').click(function () { $('#window_changePassword').closeModal() }) $('#UserInformation').click(function () { document.getElementById('myFrame').src = '/html/account/AccountInformation.html' }) $('#TM').click(function () { // 聊天窗口打开事件 $('#w').window('open') }) // 信息输入回车事件 $('#communication_text').textbox({ inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, { keydown: function (e) { if (e.shiftKey && e.keyCode === 13) { //console.log('用户按下了Shift和Enter键///换行'); // 在这里执行相应的操作 } else if (e.keyCode === 13) { // 只按下了Enter键 e.preventDefault(); // 阻止默认行为 // //console.log('用户按下了Enter键'); // //console.log($('#communication_text').textbox('getText')); //console.log($('#communication_text').textbox('getText')); const messageRegex = /^(?!\s+$)/; // 空值、回车占位 //console.log($('#communication_text').textbox('getText').trim() !== ''); if ($('#communication_text').textbox('getText').trim() !== '') { enter_save() } else { //console.log('内容为空'); } } } }) }); // 消息发送*(调用接口并保存到数据库) function enter_save() { let relesObj = {}; let ulData = $('.user_ul').datalist('getSelections')[0] //console.log(ulData); relesObj.index = ulData.RECEIVER_STAFF_IKEY.split(',')[0] relesObj.name = ulData.RECEIVER_STAFF_IKEY.split(',')[1] if ($('#communication_text').textbox('getText').trim() !== '') { //console.log($('#communication_text').textbox('getText') != ''); let html; html = $('#communication_text').textbox('getText'); //发送内容 let date = timescopePlus() // 发送时间 let type = 'MSG' //信息类型 let staff_ikey = staff.IKEY //发送者id let staff_company_name = staff.COMPANY_NAME //发送者公司 let staff_id = staff.STAFF_ID //发送者账户名 let msg = { ID: '', MSG: html, SendDate: date, msgType: type, SendUserid: staff_id, SendUser_staff_ikey: staff_ikey, SendCompany: staff_company_name, SendUserName: '', receiver_id: relesObj.index }; let mqtt = { FMqtt_msgData: { SENDER: staff.STAFF_ID, SEND_STAFF_IKEY: staff.IKEY, RECEIVER: relesObj.name, RECEIVER_STAFF_IKEY: relesObj.index, RTYPE: '0', MSG: html, FILE_NAME: "" } } let ba = '' let rest = SaveMqttMsg(mqtt, ba) //console.log(rest); if (rest.FMqtt_msgData != undefined) { sendMqttMsg(JSON.stringify(msg), relesObj.name); $(template('communication_rightNew', { right_Date: timescopePlus(), htmlTitle_right: `${html}` })).appendTo($('.communication_center')); $('#communication_text').textbox('clear') } else { showAlert('error', rest.error) } // 滚动到容器底部 communicationCenter.scrollTop = communicationCenter.scrollHeight; } else { //console.log('内容为空'); } } $('#sending').click(function () { enter_save() // let rest = VerificationCode('zhangaw112312@efficient.hk1') // //console.log(rest); }) $('#w').window({ onClose: function () { $('.user_ul').empty(); }, onBeforeOpen: function () { isUserlsit($('.user_ul'), $(".communication_center"), staff.IKEY, communicationCenter) } }) // // 等待iframe加载完成后执行操作 window.onload = function () { MQTT_webClient.on("message", (topic, message) => { const mes_str = message.toString() let mes_json = JSON.parse(mes_str) //console.log("来自主题:", topic) //console.log("获取到消息:", mes_json); let ulData = $('.user_ul').datalist('getSelections')[0] //console.log(ulData); // //console.log("获取到消息:", mes_json.mqType, mes_json.MSG); //mqType 过滤接收信息 JWYSTATION(打印程序发回) if (ulData != undefined) { if (mes_json.SendUser_staff_ikey == ulData.RECEIVER_STAFF_IKEY.split(',')[0]) { $(template('communication_leftNew', { left_Date: mes_json.SendDate, htmlTitle_left: mes_json.MSG })).appendTo($('.communication_center')); //console.log(mes_str); // 滚动到容器底部 communicationCenter.scrollTop = communicationCenter.scrollHeight; } } }); console.log('触发了'); }; })