var colors = {}; var map; var type = "0"; var county = "all"; var breedChart = null; var foodNumPerColors = ["0, 255, 255", "50, 255, 50", "255, 215, 0", "255, 69, 0", "0, 191, 255", "30, 144, 255", "255, 20, 147", "255, 105, 180", "0, 255, 127", "255, 165, 0", "255, 218, 185", "255, 255, 0", "0, 250, 155", "255, 99, 71"]; //var switch2AreaNode2; let iframe = document.getElementById("gisFrame"); // ============ 接收iframe消息 ============ window.addEventListener("message", function (event) { // 生产环境建议校验 event.origin const data = event.data; if (data && data.type === "CLICK_BUILDING") { // alert(`点击了仓库 ${data.data.uid}`); renderDepotMess(data.data.uid); } }); $(function () { //初始化时间 initTime(); initDicSlogan(); //初始化左侧图表 pieChartLoad( [ {value: "0", name: '伊宁市'}, {value: "0", name: '奎屯市'}, {value: "0", name: '霍尔果斯市'}, {value: "0", name: '伊宁县'}, {value: "0", name: '察布查尔锡伯自治县'}, {value: "0", name: '霍城县'}, {value: "0", name: '巩留县'}, {value: "0", name: '新源县'}, {value: "0", name: '昭苏县'}, {value: "0", name: '特克斯县'}, {value: "0", name: '尼勒克县'} ], 'breedChart' ); window.onresize = function (e) { if (breedChart) { breedChart.resize(); } } //渲染部门 renderList(); renderNum(); //定位到新疆省 setTimeout(function () { positioning("650000"); }, 2000); $('.sup-menu-title').click(function () { var kai = $(this).parent(".sup-menu-group") if (kai.hasClass('menu-group')) { kai.removeClass('menu-group') } else { kai.addClass('menu-group') } }); $('.sup-menu-h').click(function () { var kai2 = $(this).parents(".sup-menu-ul") if (kai2.hasClass('menu-h')) { kai2.removeClass('menu-h') } else { kai2.addClass('menu-h') } }); // 初始化WebSocket // initWS(companyId, bizType, bizTag, userId); renderDeptMess(defaultDeptId); }); function renderDeptMess(deptId) { for (let i = 0; i < deptList.length; i++) { if( deptId == deptList[i].deptId){ let htmlMess=`
库点信息
${deptList[i].county}

${deptList[i].deptName}

当日入库单数(个)

${deptList[i].inNum}

当日出库单数(个)

${deptList[i].outNum}

`; $("#areaInformation").html(htmlMess); } } } function renderDepotMess(depotId) { for (let i = 0; i < depotList.length; i++) { if( depotId == depotList[i].depotId){ let htmlMess=`
库点信息
${depotList[i].county}

${depotList[i].deptName}

${depotList[i].depotName}

`; $("#areaInformation").html(htmlMess); } } } function socketOnMessage(pocket) { //console.log(pocket); if (pocket.bizId == "slogan") { var data = pocket.data; dicSlogan = data; initDicSlogan(); } } // 刷新时间 function positioning(code) { var kai = $("#prov"); if (kai.hasClass('menu-group')) { kai.removeClass('menu-group') } else { kai.addClass('menu-group') } // renderAreas(code); } // 刷新时间 function initTime() { setInterval(function () { $("#navBarDate").html(formatDate('mm月dd日', new Date())); $("#navBarTime").html(formatDate('HH:MM:SS', new Date())); $("#navBarWeek").html(getWeekDate()); }, 1000); } //库区点击事件 function clickDept(deptid) { // 方案一:通知iframe切换库区 if (iframe.contentWindow) { iframe.contentWindow.postMessage( { type: "CHANGE_AREA", data: {uid: deptid}, }, "*", // 生产环境建议替换为具体域名 ); } // 方案二:直接修改src(会重新加载页面) // iframe.src = `http://172.67.157.132:5000?uid=${uid}`; //切换库区的库点信息 renderDeptMess(deptid); } /** * 渲染库区列表 */ function renderList() { if (areaList) { var html = ""; var childs = []; var childsItem = []; var areas = []; for (var i = 0; i < areaList.length; i++) { html += "
" + "
" + ""; if (areaList[i].children && areaList[i].children.length > 0) { childs = areaList[i].children; for (var j = 0; j < childs.length; j++) { //默认关闭库区 // html += "
" + "
"; } $("#menuDiv").html(html); } } function renderNum() { $("#foodSum").html(gisData.deptNum); let deptNum = 0; var foodNumPerHtml = ''; for (var i = 0; i < gisData.deptList.length; i++) { if ('0.0' != gisData.deptList[i].percent) { foodNumPerHtml += '
  • '; foodNumPerHtml += '
    '; foodNumPerHtml += '
    ' + gisData.deptList[i].percent + '%
    '; foodNumPerHtml += '
    ' + gisData.deptList[i].name + '
    '; foodNumPerHtml += '
  • '; deptNum += 1; } } $("#foodSum").html(deptNum); $("#foodNumPer").html(foodNumPerHtml); if (gisData.deptList.length > 0) { var varietyChart = breedChart; varietyChart.option.series[0].data = gisData.deptList; varietyChart.option.color = getHexColorsFromRGB(foodNumPerColors, gisData.deptList.length); varietyChart.chart.setOption(varietyChart.option, true); breedChart = varietyChart; } modelingBarChartLoad("ss"); } /** * 将 RGB 格式颜色转换为十六进制格式 * @param rgbColors RGB 颜色数组 * @param count 需要的颜色数量 * @returns {Array} 十六进制颜色数组 */ function getHexColorsFromRGB(rgbColors, count) { var hexColors = []; for (var i = 0; i < count && i < rgbColors.length; i++) { var rgb = rgbColors[i].split(','); var r = parseInt(rgb[0]); var g = parseInt(rgb[1]); var b = parseInt(rgb[2]); var hex = '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); hexColors.push(hex); } return hexColors; } /** * 格式化日期 * @param fmt * @param date * @return {*} */ function formatDate(fmt, date) { var ret; const opt = { "Y+": date.getFullYear().toString(), // 年 "m+": (date.getMonth() + 1).toString(), // 月 "d+": date.getDate().toString(), // 日 "H+": date.getHours().toString(), // 时 "M+": date.getMinutes().toString(), // 分 "S+": date.getSeconds().toString() // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (var k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) } } return fmt; } /** * 格式化日期 * @param fmt * @param date * @return {*} */ function formatDate(fmt, date) { var ret; const opt = { "Y+": date.getFullYear().toString(), // 年 "m+": (date.getMonth() + 1).toString(), // 月 "d+": date.getDate().toString(), // 日 "H+": date.getHours().toString(), // 时 "M+": date.getMinutes().toString(), // 分 "S+": date.getSeconds().toString() // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (let k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) } } return fmt; } /** *获取当前星期几 */ function getWeekDate() { var now = new Date(); var day = now.getDay(); var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); var week = weeks[day]; return week; } var navBarDateDom = document.getElementById('navBarDate'); var navBarTimeDom = document.getElementById('navBarTime'); var navBarWeekDom = document.getElementById('navBarWeek'); /*刷新时间*/ setInterval(function () { navBarDateDom.innerHTML = formatDate('mm月dd日', new Date()); navBarTimeDom.innerHTML = formatDate('HH:MM:SS', new Date()); navBarWeekDom.innerHTML = getWeekDate(); }, 1000) $(function () { $('.m-nav .tit').click(function () { $(this).siblings('.sub').stop().slideToggle(); }); $('.c-left .close').on('click', function () { $('.c-left').addClass('hidden') }); $('.c-left .o-btn').on('click', function () { $('.c-left').removeClass('hidden') }); $('.c-right .close').on('click', function () { $('.c-right').addClass('hidden') }); $('.c-right .o-btn').on('click', function () { $('.c-right').removeClass('hidden') }); });