Skip to content

Commit 51ae16c

Browse files
committed
Support to clear date range by shortcut
1 parent d100d22 commit 51ae16c

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
"@babel/plugin-transform-modules-commonjs": "^7.25.9",
2828
"@babel/preset-env": "^7.26.0",
2929
"@crowdin/crowdin-api-client": "^1.39.1",
30-
"@types/chrome": "0.0.284",
30+
"@types/chrome": "0.0.287",
3131
"@types/copy-webpack-plugin": "^10.1.3",
3232
"@types/decompress": "^4.2.7",
3333
"@types/echarts": "^4.9.22",
3434
"@types/generate-json-webpack-plugin": "^0.3.7",
3535
"@types/jest": "^29.5.14",
36-
"@types/node": "^22.9.3",
36+
"@types/node": "^22.10.1",
3737
"@types/psl": "^1.1.3",
3838
"@types/punycode": "^2.1.4",
3939
"@types/webpack": "^5.28.5",
@@ -43,7 +43,7 @@
4343
"copy-webpack-plugin": "^12.0.2",
4444
"css-loader": "^7.1.2",
4545
"decompress": "^4.2.1",
46-
"eslint": "^9.15.0",
46+
"eslint": "^9.16.0",
4747
"filemanager-webpack-plugin": "^8.0.0",
4848
"generate-json-webpack-plugin": "^2.0.0",
4949
"html-webpack-plugin": "^5.6.3",
@@ -69,10 +69,10 @@
6969
},
7070
"dependencies": {
7171
"@element-plus/icons-vue": "^2.3.1",
72-
"@vueuse/core": "^11.3.0",
72+
"@vueuse/core": "^12.0.0",
7373
"countup.js": "^2.8.0",
7474
"echarts": "^5.5.1",
75-
"element-plus": "2.8.8",
75+
"element-plus": "2.9.0",
7676
"js-base64": "^3.7.7",
7777
"punycode": "^2.3.1",
7878
"stream-browserify": "^3.0.0",

src/app/components/Report/ReportFilter/RemoteClient.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { UploadFilled } from "@element-plus/icons-vue"
1010
import { useRequest } from "@hooks"
1111
import statService from "@service/stat-service"
1212
import { ElButton, ElIcon, ElTooltip } from "element-plus"
13-
import { defineComponent, ref, watch, computed } from "vue"
13+
import { computed, defineComponent, ref, watch } from "vue"
1414

1515
const _default = defineComponent({
1616
emits: {

src/app/components/common/DateRangeFilterItem.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8+
import { t } from "@app/locale"
89
import { EL_DATE_FORMAT } from "@i18n/element"
910
import { ElementDatePickerShortcut } from "@src/element-ui/date"
1011
import { getDatePickerIconSlots } from "@src/element-ui/rtl"
1112
import { ElDatePicker } from "element-plus"
1213
import { defineComponent, PropType, ref, Ref } from "vue"
1314

15+
const clearShortcut = (): ElementDatePickerShortcut => ({
16+
text: t(msg => msg.button.clear),
17+
value: [new Date(0), new Date(0)],
18+
})
19+
1420
const _default = defineComponent({
1521
props: {
1622
defaultRange: Object as PropType<[Date, Date]>,
@@ -27,6 +33,18 @@ const _default = defineComponent({
2733
change: (_value: [Date, Date]) => true
2834
},
2935
setup(props, ctx) {
36+
const handleChange = (newVal: [Date, Date]) => {
37+
const [start, end] = newVal || []
38+
const isClearChosen = start?.getTime?.() === 0 && end?.getTime?.() === 0
39+
if (isClearChosen) newVal = null
40+
ctx.emit("change", dateRange.value = newVal)
41+
}
42+
const shortcuts = () => {
43+
const { shortcuts: value, clearable } = props
44+
if (!value?.length || !clearable) return value
45+
return [...value, clearShortcut()]
46+
}
47+
3048
const dateRange: Ref<[Date, Date]> = ref(props.defaultRange || [undefined, undefined])
3149
return () => <span class="filter-item">
3250
<ElDatePicker
@@ -35,8 +53,8 @@ const _default = defineComponent({
3553
type="daterange"
3654
rangeSeparator="-"
3755
disabledDate={props.disabledDate}
38-
shortcuts={props.shortcuts}
39-
onUpdate:modelValue={(newVal: [Date, Date]) => ctx.emit("change", dateRange.value = newVal)}
56+
shortcuts={shortcuts()}
57+
onUpdate:modelValue={(newVal: [Date, Date]) => handleChange(newVal)}
4058
startPlaceholder={props.startPlaceholder}
4159
endPlaceholder={props.endPlaceholder}
4260
clearable={props.clearable}

src/i18n/message/common/button-resource.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"next": "Next",
1313
"okey": "OK",
1414
"dont": "NO!",
15-
"operation": "Operations"
15+
"operation": "Operations",
16+
"clear": "Clear"
1617
},
1718
"zh_CN": {
1819
"create": "新增",
@@ -27,7 +28,8 @@
2728
"next": "下一步",
2829
"okey": "好的",
2930
"dont": "不用了",
30-
"operation": "操作"
31+
"operation": "操作",
32+
"clear": "清除"
3133
},
3234
"zh_TW": {
3335
"create": "新增",

src/i18n/message/common/button.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type ButtonMessage = {
2020
okey: string
2121
dont: string
2222
operation: string
23+
clear: string
2324
}
2425

2526
const _default: Messages<ButtonMessage> = resource

0 commit comments

Comments
 (0)