Commit 247d2892 by zhouhaibao

feat(filter): 优化月份选择器组件体验

- 为月份输入框添加包装器结构支持占位符显示
- 实现月份选择器占位符功能,过滤条件显示"全部",模态框显示"请选择月份"
- 添加JavaScript逻辑处理月份选择器的值变化和占位符切换
- 调整CSS样式统一输入框高度为38px并优化月份选择器视觉效果
- 修复月份选择器重置时占位符不更新的问题
- 完善月份选择器焦点状态和交互反馈样式
1 parent 73a7847c
...@@ -128,11 +128,60 @@ body { ...@@ -128,11 +128,60 @@ body {
} }
.filter-item { display: flex; flex-direction: column; gap: 6px; } .filter-item { display: flex; flex-direction: column; gap: 6px; }
.filter-item label { font-size: 13px; color: #666; } .filter-item label { font-size: 13px; color: #666; }
.filter-item select, .filter-item input, .filter-item input[type="month"] { .filter-item select, .filter-item input {
height: 32px; padding: 0 10px; border: 1px solid #d0d3da; height: 38px; padding: 0 10px; border: 1px solid #d0d3da;
border-radius: 4px; min-width: 140px; outline: none; border-radius: 4px; min-width: 140px; outline: none;
} }
.filter-item input:focus, .filter-item select:focus, .filter-item input[type="month"]:focus { border-color: #185fa5; } .filter-item input:focus, .filter-item select:focus { border-color: #185fa5; }
/* 月份选择器包装器 - 支持显示默认文本 */
.month-picker-wrapper {
position: relative;
display: inline-block;
min-width: 140px;
}
.month-picker-wrapper input[type="month"] {
width: 100%;
height: 38px;
padding: 0 10px;
border: 1px solid #d0d3da;
border-radius: 4px;
outline: none;
background: #fff;
position: relative;
z-index: 2;
color: transparent; /* 默认隐藏原生文字 */
}
.month-picker-wrapper input[type="month"]::-webkit-calendar-picker-indicator {
cursor: pointer;
}
.month-picker-wrapper .month-placeholder {
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
color: #999;
pointer-events: none;
z-index: 3; /* 提高 placeholder 层级,确保在 input 之上 */
white-space: nowrap;
}
/* 有值状态:隐藏 placeholder,显示真实值 */
.month-picker-wrapper.has-value input[type="month"] {
color: #333 !important;
}
.month-picker-wrapper.has-value .month-placeholder {
display: none;
}
/* 无值状态:显示 placeholder,隐藏 input 文字 */
.month-picker-wrapper:not(.has-value) input[type="month"] {
color: transparent;
}
.modal-control .month-picker-wrapper {
width: 100%;
}
.modal-control .month-picker-wrapper input[type="month"] {
width: 100%;
}
.filter-actions { display: flex; gap: 8px; } .filter-actions { display: flex; gap: 8px; }
/* 表格 */ /* 表格 */
...@@ -291,14 +340,12 @@ tbody tr:hover { background: #f8fafd; } ...@@ -291,14 +340,12 @@ tbody tr:hover { background: #f8fafd; }
} }
.modal-row > label.required::before { content: '*'; color: #e24b4a; margin-right: 4px; } .modal-row > label.required::before { content: '*'; color: #e24b4a; margin-right: 4px; }
.modal-control { flex: 1; } .modal-control { flex: 1; }
.modal-control select, .modal-control select {
.modal-control input[type="month"] { width: 100%; height: 38px; padding: 0 10px;
width: 100%; height: 32px; padding: 0 10px;
border: 1px solid #d0d3da; border-radius: 4px; outline: none; border: 1px solid #d0d3da; border-radius: 4px; outline: none;
background: #fff; background: #fff;
} }
.modal-control select:focus, .modal-control select:focus { border-color: #185fa5; }
.modal-control input[type="month"]:focus { border-color: #185fa5; }
.modal-file { .modal-file {
display: flex; align-items: center; gap: 12px; display: flex; align-items: center; gap: 12px;
......
...@@ -77,12 +77,34 @@ ...@@ -77,12 +77,34 @@
var tbody = document.getElementById('tbody'); var tbody = document.getElementById('tbody');
var emptyTip = document.getElementById('emptyTip'); var emptyTip = document.getElementById('emptyTip');
// 设置月份选择器的最大值为当前月份 // 初始化月份选择器 - 处理 placeholder 显示逻辑
function initMonthPicker() { function initMonthPicker() {
var now = new Date(); var fMonth = document.getElementById('fMonth');
var maxMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0'); var mMonth = document.getElementById('mMonth');
if (fMonth) fMonth.max = maxMonth;
if (mMonth) mMonth.max = maxMonth; function setupMonthPicker(input) {
if (!input) return;
var wrapper = input.closest('.month-picker-wrapper');
if (!wrapper) return;
var placeholder = wrapper.querySelector('.month-placeholder');
function updatePlaceholder() {
if (input.value) {
wrapper.classList.add('has-value');
if (placeholder) placeholder.style.display = 'none';
} else {
wrapper.classList.remove('has-value');
if (placeholder) placeholder.style.display = 'block';
}
}
input.addEventListener('input', updatePlaceholder);
input.addEventListener('change', updatePlaceholder);
updatePlaceholder();
}
setupMonthPicker(fMonth);
setupMonthPicker(mMonth);
} }
function loadTypes() { function loadTypes() {
...@@ -217,6 +239,7 @@ ...@@ -217,6 +239,7 @@
fillModalTypes(); fillModalTypes();
mType.value = task ? task.data_table_type : ''; mType.value = task ? task.data_table_type : '';
mMonth.value = task ? task.month : ''; mMonth.value = task ? task.month : '';
mMonth.dispatchEvent(new Event('change')); // 更新 placeholder 显示
var locked = mode === 'regenerate'; var locked = mode === 'regenerate';
mType.disabled = locked; mType.disabled = locked;
mMonth.disabled = locked; mMonth.disabled = locked;
...@@ -352,6 +375,7 @@ ...@@ -352,6 +375,7 @@
document.getElementById('btnSearch').onclick = function () { state.page = 1; loadList(); }; document.getElementById('btnSearch').onclick = function () { state.page = 1; loadList(); };
document.getElementById('btnReset').onclick = function () { document.getElementById('btnReset').onclick = function () {
fType.value = ''; fMonth.value = ''; fCreator.value = ''; fStatus.value = ''; fType.value = ''; fMonth.value = ''; fCreator.value = ''; fStatus.value = '';
fMonth.dispatchEvent(new Event('change')); // 更新 placeholder 显示
state.page = 1; loadList(); state.page = 1; loadList();
}; };
document.getElementById('btnPrev').onclick = function () { if (state.page > 1) { state.page--; loadList(); } }; document.getElementById('btnPrev').onclick = function () { if (state.page > 1) { state.page--; loadList(); } };
......
...@@ -47,7 +47,10 @@ ...@@ -47,7 +47,10 @@
</div> </div>
<div class="filter-item"> <div class="filter-item">
<label>所属月份</label> <label>所属月份</label>
<div class="month-picker-wrapper">
<input type="month" id="fMonth" min="2026-01"> <input type="month" id="fMonth" min="2026-01">
<span class="month-placeholder" id="fMonthPlaceholder">全部</span>
</div>
</div> </div>
<div class="filter-item"> <div class="filter-item">
<label>创建人</label> <label>创建人</label>
...@@ -137,7 +140,10 @@ ...@@ -137,7 +140,10 @@
<div class="modal-row"> <div class="modal-row">
<label class="required">所属月份</label> <label class="required">所属月份</label>
<div class="modal-control"> <div class="modal-control">
<div class="month-picker-wrapper">
<input type="month" id="mMonth" min="2026-01"> <input type="month" id="mMonth" min="2026-01">
<span class="month-placeholder" id="mMonthPlaceholder">请选择月份</span>
</div>
</div> </div>
</div> </div>
<div id="mFiles"></div> <div id="mFiles"></div>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!