回退组件库版本

main
chenbowen 4 days ago
parent f4dd21286c
commit 7436647b00

@ -26,7 +26,7 @@
"core-js": "^3.8.3", "core-js": "^3.8.3",
"crypto-browserify": "^3.12.0", "crypto-browserify": "^3.12.0",
"echarts": "5.4.3", "echarts": "5.4.3",
"element-plus": "^2.4.1", "element-plus": "2.10.4",
"generate-avatar": "1.4.10", "generate-avatar": "1.4.10",
"js-cookie": "3.0.5", "js-cookie": "3.0.5",
"lodash": "^4.17.21", "lodash": "^4.17.21",

@ -44,7 +44,7 @@
<Block v-for="{ title, dataSource } in rangeConfig" :title="title" :key="title"> <Block v-for="{ title, dataSource } in rangeConfig" :title="title" :key="title">
<template #extra> <template #extra>
<time-picker v-model="times" type="datetimerange" size="small" :key="`time-picker-${title}`" /> <time-picker v-model="times" type="datetimerange" size="small" />
</template> </template>
<echarts-plus :options="getRangeOptions(dataSource)" style="height: 250px" /> <echarts-plus :options="getRangeOptions(dataSource)" style="height: 250px" />
</Block> </Block>

@ -1,6 +1,5 @@
<template> <template>
<el-date-picker <el-date-picker
ref="pickerRef"
v-model="value" v-model="value"
:type="type" :type="type"
range-separator="至" range-separator="至"
@ -8,36 +7,24 @@
end-placeholder="结束时间" end-placeholder="结束时间"
unlink-panels unlink-panels
:shortcuts="type.includes('range') && shortcuts" :shortcuts="type.includes('range') && shortcuts"
:teleported="false"
:append-to-body="false"
class="date-picker" class="date-picker"
:disabled-date="disabledDate" :disabled-date="disabledDate"
@visible-change="onVisibleChange"
v-bind="$attrs" v-bind="$attrs"
/> ></el-date-picker>
</template> </template>
<script setup lang="jsx"> <script setup lang="jsx">
import { computed, defineProps, defineEmits, ref } from 'vue'; import { computed, defineProps, defineEmits } from 'vue';
import { ElDatePicker } from 'element-plus';
// props emits
const props = defineProps({ const props = defineProps({
modelValue: {}, modelValue: {},
type: { type: String, default: 'date' }, type: { type: String, default: 'date' },
parse: { type: Function, default: (times) => times }, parse: { type: Function, default: (times) => times },
}); });
const emits = defineEmits(['update:modelValue']);
// ref
const pickerRef = ref();
const visible = ref(false);
// const emits = defineEmits(['update:modelValue']);
const onVisibleChange = (val) => {
visible.value = val;
};
//
const value = computed({ const value = computed({
get() { get() {
return props.modelValue; return props.modelValue;
@ -47,44 +34,105 @@ const value = computed({
}, },
}); });
// const shortcuts = [
function genShortcut(text, hoursAgo) { {
return { text: '前 1 小时',
text,
value: () => { value: () => {
const end = new Date(); const end = new Date();
const start = new Date(end.getTime() - hoursAgo * 3600 * 1000); const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 1);
//
setTimeout(() => {
if (visible.value) {
pickerRef.value?.handleClose?.();
}
}, 0);
return [start, end]; return [start, end];
}, },
}; },
} {
text: '前 6 小时',
// value: () => {
const shortcuts = [ const end = new Date();
genShortcut('前 1 小时', 1), const start = new Date();
genShortcut('前 6 小时', 6), start.setTime(start.getTime() - 3600 * 1000 * 6);
genShortcut('前 12 小时', 12), return [start, end];
genShortcut('前 1 天', 24), },
genShortcut('前 2 天', 48), },
genShortcut('前 3 天', 72), {
genShortcut('前 1 周', 168), text: '前 12 小时',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 12);
return [start, end];
},
},
{
text: '前 1 天',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24);
return [start, end];
},
},
{
text: '前 2 天',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 2);
return [start, end];
},
},
{
text: '前 3 天',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
return [start, end];
},
},
{
text: '前 1 周',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
return [start, end];
},
},
// {
// text: '',
// value: () => {
// const end = new Date();
// const start = new Date();
// start.setTime(start.getTime() - 3600 * 1000 * 24 * 14);
// return [start, end];
// },
// },
// {
// text: '',
// value: () => {
// const end = new Date();
// const start = new Date();
// start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
// return [start, end];
// },
// },
// {
// text: '',
// value: () => {
// const end = new Date();
// const start = new Date();
// start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
// return [start, end];
// },
// },
]; ];
//
const disabledDate = (time) => { const disabledDate = (time) => {
return time.getTime() >= Date.now(); return time.getTime() >= Date.now();
}; };
</script> </script>
<style scoped> <style>
.date-picker { .date-picker {
max-width: 450px; max-width: 450px;
} }

Loading…
Cancel
Save