VtTimePicker 时间选择
时间列。与 VtDatePicker 同构,编辑态是原生 input[type=time]。
示例
微应用尚未挂载。
源码
点击查看源码
ts
import { VirtTable, type VirtTableColumn } from '@virt-table/vanilla';
import { vtCellEditor } from '@virt-table/vanilla/plugins';
import { VtTimePicker } from '@virt-table/vanilla/components';
export function bootstrapTableVtTimePicker(root: HTMLElement): () => void {
const rowCount = 5000;
const columns: VirtTableColumn[] = [
{ key: 'id', title: 'ID', width: 80, align: 'center' },
{ key: 'name', title: '排班', width: 160 },
VtTimePicker({ key: 'start', title: '开始', width: 150 }),
VtTimePicker({ key: 'end', title: '结束', width: 150, clearable: true }),
// step: 1 让原生控件出现秒位;min/max 限制可选范围
VtTimePicker({ key: 'checkAt', title: '打卡(含秒)', width: 180, step: 1, min: '06:00', max: '23:00' }),
VtTimePicker({ key: 'fixed', title: '只读', width: 150, disabled: true }),
];
const pad = (n: number) => String(n).padStart(2, '0');
const list = Array.from({ length: rowCount }, (_, i) => ({
id: i,
name: `班次 ${i}`,
start: `${pad(8 + (i % 4))}:${pad((i * 15) % 60)}`,
end: `${pad(17 + (i % 3))}:${pad((i * 20) % 60)}`,
checkAt: `${pad(8 + (i % 4))}:${pad((i * 7) % 60)}:${pad((i * 13) % 60)}`,
fixed: '09:00',
}));
root.innerHTML = `
<div id="status" class="status-text"></div>
<div style="width:880px;height:600px;" class="demo-container" id="vtContainer"></div>
`;
const container = root.querySelector('#vtContainer') as HTMLElement;
const statusEl = root.querySelector('#status') as HTMLElement;
const table = new VirtTable(container, {
list,
columns,
itemKey: 'id',
estimatedSize: 40,
buffer: 4,
border: true,
plugins: [vtCellEditor()],
});
statusEl.textContent =
'VtTimePicker:与 VtDatePicker 同构,用原生 input[type=time]。值就是控件的原始字符串(HH:mm,配了 step 则含秒),不做二次解析。清除「×」默认就有(原生 time 控件「怎么删回空」各家不一),传 clearable: false 关掉';
return () => {
table.destroy();
root.innerHTML = '';
};
}说明
值就是原生控件的字符串格式('09:30',step 带秒时 '09:30:15'),不做二次解析 —— 表格拿到什么就存什么,格式化留给使用方的 render 或数据层。走 renderEditor,必须装 vtCellEditor 插件。
日期与区间那两个组件已经换成自绘面板(跟随暗色主题),时间列仍是原生控件:原生 input[type=time] 的下拉由操作系统渲染,吃不到 --vt-*。
清除「×」在控件右侧、默认就有(原生 time 控件「怎么删回空」各家不一,给个叉更确定), 清空写回 '';不需要的列传 clearable: false。
相关 API
| 字段 | 作用 |
|---|---|
min / max | 可选范围 |
step | 步进(秒);给 1 出现秒位 |
全量选项表见 单元格组件;公共选项 (
placeholder/disabled/clearable/onChange)、asCell()、三类交互模型见 同页上方;列的通用字段见 列配置。编辑态需装
vtCellEditor,见 插件机制。