feat(P4): precompute移植+app.js sources双向回填+回归1003/1003+验收体积/文件/data.json
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Aurora Admin · RangeQuickPicker</title>
|
||||
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
|
||||
<link rel="stylesheet" href="./RangeQuickPicker.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="aa-page">
|
||||
<h2 class="aa-h2">RangeQuickPicker 日期范围快捷选择</h2>
|
||||
<p class="aa-desc">内置快捷选项(今天、近7天、本月等),也支持自定义起止日期。</p>
|
||||
|
||||
<div class="aa-demo">
|
||||
<div class="aa-demo__title">报表时间筛选</div>
|
||||
<div class="aa-range" id="range">
|
||||
<div class="aa-range-trigger" role="button" tabindex="0" aria-haspopup="listbox" aria-expanded="false" id="trigger">
|
||||
<span id="label" class="aa-range-placeholder" role="button" tabindex="0">请选择时间范围</span>
|
||||
</div>
|
||||
<div class="aa-range-pop" id="pop" style="display:none">
|
||||
<div class="aa-range-presets" id="presets"></div>
|
||||
<div class="aa-range-custom">
|
||||
<input type="date" id="start" />
|
||||
<span class="aa-range-tilde">~</span>
|
||||
<input type="date" id="end" />
|
||||
</div>
|
||||
<div class="aa-range-actions">
|
||||
<button class="aa-range-cancel" id="cancel">取消</button>
|
||||
<button class="aa-range-ok" id="ok">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="aa-code-tip" id="out"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var PRESETS = [
|
||||
{ label: '今天', days: 0 },
|
||||
{ label: '昨天', days: -1, len: 1 },
|
||||
{ label: '近7天', days: -6 },
|
||||
{ label: '近30天', days: -29 },
|
||||
{ label: '本月', month: 'this' },
|
||||
{ label: '上月', month: 'last' },
|
||||
{ label: '本年', year: 'this' }
|
||||
];
|
||||
function fmt(d) {
|
||||
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
|
||||
}
|
||||
function presetRange(p) {
|
||||
var end = new Date(); end.setHours(0, 0, 0, 0);
|
||||
var start = new Date(end);
|
||||
if (p.year === 'this') { start = new Date(end.getFullYear(), 0, 1); }
|
||||
else if (p.month === 'this') { start = new Date(end.getFullYear(), end.getMonth(), 1); }
|
||||
else if (p.month === 'last') { start = new Date(end.getFullYear(), end.getMonth() - 1, 1); var e = new Date(end.getFullYear(), end.getMonth(), 1); end = new Date(e - 1); }
|
||||
else { start.setDate(end.getDate() + (p.days || 0)); }
|
||||
if (p.days === -1 && !p.len) { start = new Date(end); }
|
||||
if (p.days === -1 && p.len) { start = new Date(end); start.setDate(end.getDate() - (p.len - 1)); }
|
||||
return { start: fmt(start), end: fmt(end) };
|
||||
}
|
||||
|
||||
var range = document.getElementById('range');
|
||||
var trigger = document.getElementById('trigger');
|
||||
var pop = document.getElementById('pop');
|
||||
var label = document.getElementById('label');
|
||||
var out = document.getElementById('out');
|
||||
var cur = { start: '', end: '' };
|
||||
|
||||
var presetsEl = document.getElementById('presets');
|
||||
PRESETS.forEach(function (p, i) {
|
||||
var b = document.createElement('button');
|
||||
b.className = 'aa-range-preset'; b.textContent = p.label;
|
||||
b.onclick = function () {
|
||||
var r = presetRange(p);
|
||||
cur = r; document.getElementById('start').value = r.start; document.getElementById('end').value = r.end;
|
||||
Array.prototype.forEach.call(presetsEl.children, function (c) { c.classList.remove('is-active'); });
|
||||
b.classList.add('is-active');
|
||||
};
|
||||
presetsEl.appendChild(b);
|
||||
});
|
||||
|
||||
function refresh() {
|
||||
if (cur.start && cur.end) {
|
||||
label.textContent = cur.start + ' ~ ' + cur.end;
|
||||
label.classList.remove('aa-range-placeholder');
|
||||
out.textContent = '已选范围:' + cur.start + ' 至 ' + cur.end;
|
||||
}
|
||||
}
|
||||
trigger.onclick = function (e) {
|
||||
e.stopPropagation();
|
||||
pop.style.display = pop.style.display === 'none' ? 'block' : 'none';
|
||||
trigger.classList.toggle('is-focus', pop.style.display === 'block');
|
||||
};
|
||||
document.getElementById('ok').onclick = function () {
|
||||
cur.start = document.getElementById('start').value;
|
||||
cur.end = document.getElementById('end').value;
|
||||
pop.style.display = 'none'; trigger.classList.remove('is-focus');
|
||||
Array.prototype.forEach.call(presetsEl.children, function (c) { c.classList.remove('is-active'); });
|
||||
refresh();
|
||||
};
|
||||
document.getElementById('cancel').onclick = function () { pop.style.display = 'none'; trigger.classList.remove('is-focus'); };
|
||||
document.addEventListener('click', function (e) { if (!range.contains(e.target)) { pop.style.display = 'none'; trigger.classList.remove('is-focus'); } });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,104 @@
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import './RangeQuickPicker.css';
|
||||
|
||||
function fmt(d) {
|
||||
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
|
||||
}
|
||||
function presetRange(p) {
|
||||
const end = new Date();
|
||||
end.setHours(0, 0, 0, 0);
|
||||
const start = new Date(end);
|
||||
if (p.year === 'this') start.setMonth(0, 1);
|
||||
else if (p.month === 'this') start.setDate(1);
|
||||
else if (p.month === 'last') {
|
||||
start = new Date(end.getFullYear(), end.getMonth() - 1, 1);
|
||||
end.setDate(0);
|
||||
} else {
|
||||
start.setDate(end.getDate() + (p.days || 0));
|
||||
if (p.len) start.setDate(end.getDate() - (p.len - 1));
|
||||
}
|
||||
return { start: fmt(start), end: fmt(end) };
|
||||
}
|
||||
|
||||
const DEFAULT_PRESETS = [
|
||||
{ label: '今天', days: 0 },
|
||||
{ label: '昨天', days: -1, len: 1 },
|
||||
{ label: '近7天', days: -6 },
|
||||
{ label: '近30天', days: -29 },
|
||||
{ label: '本月', month: 'this' },
|
||||
{ label: '上月', month: 'last' },
|
||||
{ label: '本年', year: 'this' }
|
||||
];
|
||||
|
||||
export default function RangeQuickPicker({ modelValue = { start: '', end: '' }, presets = DEFAULT_PRESETS, onChange }) {
|
||||
const root = useRef(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [start, setStart] = useState(modelValue.start);
|
||||
const [end, setEnd] = useState(modelValue.end);
|
||||
const [activeIndex, setActiveIndex] = useState(-1);
|
||||
|
||||
useEffect(() => {
|
||||
function onDoc(e) {
|
||||
if (root.current && !root.current.contains(e.target)) {
|
||||
setOpen(false);
|
||||
setActiveIndex(-1);
|
||||
}
|
||||
}
|
||||
document.addEventListener('click', onDoc);
|
||||
return () => document.removeEventListener('click', onDoc);
|
||||
}, []);
|
||||
|
||||
const applyPreset = (i) => {
|
||||
const r = presetRange(presets[i]);
|
||||
setStart(r.start);
|
||||
setEnd(r.end);
|
||||
setActiveIndex(i);
|
||||
};
|
||||
const confirm = () => {
|
||||
if (onChange) onChange({ start, end });
|
||||
setOpen(false);
|
||||
setActiveIndex(-1);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="aa-range" ref={root}>
|
||||
<div className={'aa-range-trigger' + (open ? ' is-focus' : '')} onClick={() => setOpen((o) => !o)}>
|
||||
{modelValue.start && modelValue.end ? (
|
||||
<span>
|
||||
{modelValue.start} <span className="aa-range-sep">~</span> {modelValue.end}
|
||||
</span>
|
||||
) : (
|
||||
<span className="aa-range-placeholder">请选择时间范围</span>
|
||||
)}
|
||||
</div>
|
||||
{open && (
|
||||
<div className="aa-range-pop">
|
||||
<div className="aa-range-presets">
|
||||
{presets.map((p, i) => (
|
||||
<button
|
||||
key={i}
|
||||
className={'aa-range-preset' + (activeIndex === i ? ' is-active' : '')}
|
||||
onClick={applyPreset.bind(null, i)}
|
||||
>
|
||||
{p.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="aa-range-custom">
|
||||
<input type="date" value={start} onChange={(e) => setStart(e.target.value)} />
|
||||
<span className="aa-range-tilde">~</span>
|
||||
<input type="date" value={end} onChange={(e) => setEnd(e.target.value)} />
|
||||
</div>
|
||||
<div className="aa-range-actions">
|
||||
<button className="aa-range-cancel" onClick={() => setOpen(false)}>
|
||||
取消
|
||||
</button>
|
||||
<button className="aa-range-ok" onClick={confirm}>
|
||||
确定
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<template>
|
||||
<div class="aa-range" v-click-outside="close">
|
||||
<div class="aa-range-trigger" :class="{ 'is-focus': open }" @click="open = !open">
|
||||
<span v-if="modelValue.start && modelValue.end">{{ modelValue.start }} <span class="aa-range-sep">~</span> {{ modelValue.end }}</span>
|
||||
<span v-else class="aa-range-placeholder">请选择时间范围</span>
|
||||
</div>
|
||||
<div v-show="open" class="aa-range-pop">
|
||||
<div class="aa-range-presets">
|
||||
<button
|
||||
v-for="(p, i) in presets"
|
||||
:key="i"
|
||||
class="aa-range-preset"
|
||||
:class="{ 'is-active': activeIndex === i }"
|
||||
@click="applyPreset(i)"
|
||||
>{{ p.label }}</button>
|
||||
</div>
|
||||
<div class="aa-range-custom">
|
||||
<input type="date" v-model="start" />
|
||||
<span class="aa-range-tilde">~</span>
|
||||
<input type="date" v-model="end" />
|
||||
</div>
|
||||
<div class="aa-range-actions">
|
||||
<button class="aa-range-cancel" @click="close">取消</button>
|
||||
<button class="aa-range-ok" @click="confirm">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
function fmt(d) {
|
||||
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
|
||||
}
|
||||
function presetRange(p) {
|
||||
var end = new Date(); end.setHours(0, 0, 0, 0);
|
||||
var start = new Date(end);
|
||||
if (p.year === 'this') start = new Date(end.getFullYear(), 0, 1);
|
||||
else if (p.month === 'this') start = new Date(end.getFullYear(), end.getMonth(), 1);
|
||||
else if (p.month === 'last') { start = new Date(end.getFullYear(), end.getMonth() - 1, 1); end = new Date(end.getFullYear(), end.getMonth(), 0); }
|
||||
else { start.setDate(end.getDate() + (p.days || 0)); if (p.len) start.setDate(end.getDate() - (p.len - 1)); }
|
||||
return { start: fmt(start), end: fmt(end) };
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'AaRangeQuickPicker',
|
||||
directives: {
|
||||
clickOutside: {
|
||||
bind(el, binding) {
|
||||
el.__doc = function (e) { if (!el.contains(e.target)) binding.value(); };
|
||||
document.addEventListener('click', el.__doc);
|
||||
},
|
||||
unbind(el) { document.removeEventListener('click', el.__doc); }
|
||||
}
|
||||
},
|
||||
props: {
|
||||
modelValue: { type: Object, default: () => ({ start: '', end: '' }) },
|
||||
presets: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ label: '今天', days: 0 },
|
||||
{ label: '昨天', days: -1, len: 1 },
|
||||
{ label: '近7天', days: -6 },
|
||||
{ label: '近30天', days: -29 },
|
||||
{ label: '本月', month: 'this' },
|
||||
{ label: '上月', month: 'last' },
|
||||
{ label: '本年', year: 'this' }
|
||||
]
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return { open: false, start: this.modelValue.start, end: this.modelValue.end, activeIndex: -1 };
|
||||
},
|
||||
methods: {
|
||||
applyPreset(i) {
|
||||
const r = presetRange(this.presets[i]);
|
||||
this.start = r.start; this.end = r.end; this.activeIndex = i;
|
||||
},
|
||||
confirm() {
|
||||
this.$emit('update:modelValue', { start: this.start, end: this.end });
|
||||
this.close();
|
||||
},
|
||||
close() { this.open = false; this.activeIndex = -1; }
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="./RangeQuickPicker.css"></style>
|
||||
@@ -0,0 +1,84 @@
|
||||
<template>
|
||||
<div class="aa-range" ref="root">
|
||||
<div class="aa-range-trigger" :class="{ 'is-focus': open }" @click="open = !open">
|
||||
<span v-if="modelValue.start && modelValue.end">{{ modelValue.start }} <span class="aa-range-sep">~</span> {{ modelValue.end }}</span>
|
||||
<span v-else class="aa-range-placeholder">请选择时间范围</span>
|
||||
</div>
|
||||
<div v-show="open" class="aa-range-pop">
|
||||
<div class="aa-range-presets">
|
||||
<button
|
||||
v-for="(p, i) in presets"
|
||||
:key="i"
|
||||
class="aa-range-preset"
|
||||
:class="{ 'is-active': activeIndex === i }"
|
||||
@click="applyPreset(i)"
|
||||
>{{ p.label }}</button>
|
||||
</div>
|
||||
<div class="aa-range-custom">
|
||||
<input type="date" v-model="start" />
|
||||
<span class="aa-range-tilde">~</span>
|
||||
<input type="date" v-model="end" />
|
||||
</div>
|
||||
<div class="aa-range-actions">
|
||||
<button class="aa-range-cancel" @click="close">取消</button>
|
||||
<button class="aa-range-ok" @click="confirm">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
||||
|
||||
function fmt(d) {
|
||||
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
|
||||
}
|
||||
function presetRange(p) {
|
||||
const end = new Date(); end.setHours(0, 0, 0, 0);
|
||||
const start = new Date(end);
|
||||
if (p.year === 'this') start.setMonth(0, 1);
|
||||
else if (p.month === 'this') start.setDate(1);
|
||||
else if (p.month === 'last') { start = new Date(end.getFullYear(), end.getMonth() - 1, 1); end.setDate(0); }
|
||||
else { start.setDate(end.getDate() + (p.days || 0)); if (p.len) start.setDate(end.getDate() - (p.len - 1)); }
|
||||
return { start: fmt(start), end: fmt(end) };
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: { type: Object, default: () => ({ start: '', end: '' }) },
|
||||
presets: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ label: '今天', days: 0 },
|
||||
{ label: '昨天', days: -1, len: 1 },
|
||||
{ label: '近7天', days: -6 },
|
||||
{ label: '近30天', days: -29 },
|
||||
{ label: '本月', month: 'this' },
|
||||
{ label: '上月', month: 'last' },
|
||||
{ label: '本年', year: 'this' }
|
||||
]
|
||||
}
|
||||
});
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
|
||||
const root = ref(null);
|
||||
const open = ref(false);
|
||||
const start = ref(props.modelValue.start);
|
||||
const end = ref(props.modelValue.end);
|
||||
const activeIndex = ref(-1);
|
||||
|
||||
function applyPreset(i) {
|
||||
const r = presetRange(props.presets[i]);
|
||||
start.value = r.start; end.value = r.end; activeIndex.value = i;
|
||||
}
|
||||
function confirm() {
|
||||
emit('update:modelValue', { start: start.value, end: end.value });
|
||||
close();
|
||||
}
|
||||
function close() { open.value = false; activeIndex.value = -1; }
|
||||
|
||||
function onDoc(e) { if (root.value && !root.value.contains(e.target)) close(); }
|
||||
onMounted(() => document.addEventListener('click', onDoc));
|
||||
onBeforeUnmount(() => document.removeEventListener('click', onDoc));
|
||||
</script>
|
||||
|
||||
<style src="./RangeQuickPicker.css"></style>
|
||||
Reference in New Issue
Block a user