| | |
| | | }); |
| | | |
| | | // 初始加载 |
| | | loadAreas(); // 加载库区颜色信息 |
| | | loadRowsOptions(); // 加载「排」选项(始终需要) |
| | | loadLayersOptions(); // 加载「层」选项(提前准备) |
| | | getLocTable('byRow', 1); // 默认按排 + 第1排 |
| | | function initMap() { |
| | | loadAreas(); // 加载库区颜色信息 |
| | | loadRowsOptions(); // 加载「排」选项(始终需要) |
| | | loadLayersOptions(); // 加载「层」选项(提前准备) |
| | | getLocTable('byRow', 1); // 默认按排 + 第1排 |
| | | } |
| | | |
| | | if (I18n.isReady()) { |
| | | initMap(); |
| | | } else { |
| | | $(document).on('i18n:ready', initMap); |
| | | } |
| | | |
| | | // Listen for dynamic language updates (no reload) |
| | | $(document).on('i18n:updated', function() { |
| | | // Update selection button text |
| | | if (isSelectionMode) { |
| | | $('#btnSelectMode').text(I18n.t('disable_selection')); |
| | | } else { |
| | | $('#btnSelectMode').text(I18n.t('enable_selection')); |
| | | } |
| | | |
| | | // Update assign button text if visible |
| | | if ($('.loc-selected').length > 0) { |
| | | $('#btnAssignZone').text(I18n.t('assign_zone') + ' (' + $('.loc-selected').length + ')'); |
| | | } else { |
| | | $('#btnAssignZone').text(I18n.t('assign_zone')); |
| | | } |
| | | |
| | | // Re-render legend to update text |
| | | loadAreas(); |
| | | |
| | | // Re-render select options if needed (but options usually don't have text needing translation unless hardcoded) |
| | | // Re-render form to apply changes |
| | | form.render(); |
| | | }); |
| | | |
| | | // 加载库区信息并显示图例 |
| | | function loadAreas() { |
| | |
| | | success: function(res) { |
| | | if (res.code === 200) { |
| | | areaMap = {}; |
| | | var legendHtml = '<div class="area-legend-item" style="cursor:default;font-weight:bold;">库区图例:</div>'; |
| | | var legendHtml = '<div class="area-legend-item" style="cursor:default;font-weight:bold;">' + I18n.t('zone_legend') + ':</div>'; |
| | | // 默认颜色列表,用于自动分配 |
| | | var defaultColors = ['#FF5733', '#33FF57', '#3357FF', '#FF33A1', '#A133FF', '#33FFF5', '#FFD700', '#FF8C00']; |
| | | var colorIndex = 0; |
| | |
| | | |
| | | var contentHtml = '<div style="padding: 20px;"><form class="layui-form">' + |
| | | '<div class="layui-form-item">' + |
| | | '<label class="layui-form-label" style="width: auto; padding-left: 0;">库区名称:</label>' + |
| | | '<label class="layui-form-label" style="width: auto; padding-left: 0;">' + I18n.t('zone_name') + ':</label>' + |
| | | '<div class="layui-input-inline" style="line-height: 45px;">' + areaData.name + '</div>' + |
| | | '</div>' + |
| | | '<div class="layui-form-item">' + |
| | | '<label class="layui-form-label" style="width: auto; padding-left: 0;">选择颜色</label>' + |
| | | '<label class="layui-form-label" style="width: auto; padding-left: 0;">' + I18n.t('select_color') + '</label>' + |
| | | '<div class="layui-input-inline"><input type="color" id="singleAreaColorPicker" value="' + (areaData.color || '#cccccc') + '" style="height: 38px; width: 100%;"></div>' + |
| | | '</div>' + |
| | | '</form></div>'; |
| | | |
| | | layer.open({ |
| | | type: 1, |
| | | title: '修改库区颜色', |
| | | title: I18n.t('modify_zone_color'), |
| | | area: ['350px', '250px'], |
| | | content: contentHtml, |
| | | btn: ['保存', '取消'], |
| | | btn: [I18n.t('save'), I18n.t('cancel')], |
| | | yes: function(index) { |
| | | var newColor = $('#singleAreaColorPicker').val(); |
| | | if (newColor !== areaData.color) { |
| | |
| | | data: { id: areaId, backup1: newColor }, |
| | | success: function(res) { |
| | | if (res.code === 200) { |
| | | layer.msg('颜色已更新'); |
| | | layer.msg(I18n.t('color_updated')); |
| | | layer.close(index); |
| | | loadAreas(); // 刷新图例和缓存 |
| | | // 刷新地图以应用新颜色 |
| | |
| | | if (mode === 'byRow') getLocTable('byRow', $('#rowSelect').val()); |
| | | else getLocTable('byLayer', $('#layerSelect').val()); |
| | | } else { |
| | | layer.msg(res.msg || '更新失败'); |
| | | layer.msg(res.msg || I18n.t('update_failed')); |
| | | } |
| | | } |
| | | }); |
| | |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl + "/"; |
| | | } else { |
| | | layer.msg(res.msg || '加载失败'); |
| | | layer.msg(res.msg || I18n.t('load_failed')); |
| | | } |
| | | } |
| | | }); |
| | |
| | | $('#btnSelectMode').click(function () { |
| | | isSelectionMode = !isSelectionMode; |
| | | if (isSelectionMode) { |
| | | $(this).text('关闭框选').addClass('layui-btn-danger').removeClass('layui-btn-normal'); |
| | | $(this).text(I18n.t('disable_selection')).addClass('layui-btn-danger').removeClass('layui-btn-normal'); |
| | | // 禁用原有点击事件,防止冲突 (通过 CSS pointer-events 或移除 onclick) |
| | | // 这里选择移除 onclick 属性 |
| | | $('.a-loc').each(function(){ |
| | | $(this).attr('data-onclick', $(this).attr('onclick')).removeAttr('onclick'); |
| | | }); |
| | | layer.msg('已开启框选模式,请在库位图上拖拽选择'); |
| | | layer.msg(I18n.t('selection_mode_tip')); |
| | | } else { |
| | | $(this).text('开启框选').addClass('layui-btn-normal').removeClass('layui-btn-danger'); |
| | | $(this).text(I18n.t('enable_selection')).addClass('layui-btn-normal').removeClass('layui-btn-danger'); |
| | | $('.loc-selected').removeClass('loc-selected'); |
| | | $('#btnAssignZone').hide(); |
| | | // 恢复点击事件 |
| | |
| | | }); |
| | | |
| | | if ($('.loc-selected').length > 0) { |
| | | $('#btnAssignZone').show().text('分配库区 (' + $('.loc-selected').length + ')'); |
| | | $('#btnAssignZone').show().text(I18n.t('assign_zone') + ' (' + $('.loc-selected').length + ')'); |
| | | } else { |
| | | $('#btnAssignZone').hide(); |
| | | } |
| | |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | success: function(listRes) { |
| | | if (listRes.code === 200) { |
| | | var optionsHtml = '<option value="">请选择库区</option>'; |
| | | var optionsHtml = '<option value="">' + I18n.t('please_select_zone') + '</option>'; |
| | | var areas = listRes.data.records; |
| | | areas.forEach(function(area) { |
| | | optionsHtml += '<option value="' + area.id + '">' + area.areaName + ' (' + area.areaId + ')</option>'; |
| | |
| | | var contentHtml = '<div style="padding: 20px;"><form class="layui-form">' + |
| | | '<div class="layui-form-item"><select id="selectArea" lay-filter="selectArea">' + optionsHtml + '</select></div>' + |
| | | '<div class="layui-form-item">' + |
| | | '<label class="layui-form-label" style="width: auto; padding-left: 0;">库区颜色</label>' + |
| | | '<label class="layui-form-label" style="width: auto; padding-left: 0;">' + I18n.t('zone_color') + '</label>' + |
| | | '<div class="layui-input-inline"><input type="color" id="areaColorPicker" value="#cccccc" style="height: 38px; width: 100%;"></div>' + |
| | | '</div>' + |
| | | '</form></div>'; |
| | | |
| | | layer.open({ |
| | | type: 1, |
| | | title: '分配库区及颜色', |
| | | title: I18n.t('assign_zone_and_color'), |
| | | area: ['400px', '350px'], |
| | | content: contentHtml, |
| | | btn: ['确定', '取消'], |
| | | btn: [I18n.t('confirm'), I18n.t('cancel')], |
| | | success: function(layero, index) { |
| | | form.render('select'); |
| | | form.on('select(selectArea)', function(data){ |
| | |
| | | var newColor = $('#areaColorPicker').val(); |
| | | |
| | | if (!areaId) { |
| | | layer.msg('请选择库区'); |
| | | layer.msg(I18n.t('please_select_zone')); |
| | | return; |
| | | } |
| | | |
| | |
| | | }), |
| | | success: function(updRes) { |
| | | if (updRes.code === 200) { |
| | | layer.msg('分配成功'); |
| | | layer.msg(I18n.t('assign_success')); |
| | | layer.close(index); |
| | | // 刷新 |
| | | var mode = $('#viewMode').val(); |
| | |
| | | }, 500); // 简单延时等待渲染 |
| | | } |
| | | } else { |
| | | layer.msg(updRes.msg || '操作失败'); |
| | | layer.msg(updRes.msg || I18n.t('operation_failed')); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } else { |
| | | layer.msg(listRes.msg || '无法获取库区列表'); |
| | | layer.msg(listRes.msg || I18n.t('fetch_zone_list_failed')); |
| | | } |
| | | } |
| | | }); |