Skip to content

Commit 9dbd78e

Browse files
committed
Optmize for codebeat
1 parent c9f3569 commit 9dbd78e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2152
-1640
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 网费很贵
22

33
[![codecov](https://codecov.io/gh/sheepzh/timer/branch/main/graph/badge.svg?token=S98QSBSKCR&style=flat-square)](https://codecov.io/gh/sheepzh/timer)
4+
[![codebeat badge](https://codebeat.co/badges/69a88b51-2a07-4944-98dc-603a99d8a9f9)](https://codebeat.co/projects/github-com-sheepzh-timer-main)
45
[![](https://www.travis-ci.com/sheepzh/timer.svg?branch=main)](https://www.travis-ci.com/sheepzh/timer.svg?branch=main)
56
[![](https://img.shields.io/badge/license-Anti%20996-blue)](https://github.com/996icu/996.ICU)
67
[![](https://img.shields.io/github/v/release/sheepzh/timer)](https://github.com/sheepzh/timer/releases)

src/app/components/clear/filter.ts

Lines changed: 0 additions & 188 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const stepNoClz = 'step-no'
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { ElDatePicker } from "element-plus"
2+
import { Ref, h } from "vue"
3+
import { formatTime, MILL_PER_DAY } from "../../../../util/time"
4+
import { t, tN } from "../../../locale"
5+
import { stepNoClz } from "./consts"
6+
7+
export type DateFilterProps = {
8+
dateRangeRef: Ref<Date[]>
9+
}
10+
11+
const yesterday = new Date().getTime() - MILL_PER_DAY
12+
const yesterdayMsg = formatTime(yesterday, '{y}/{m}/{d}')
13+
const daysBefore = (days: number) => new Date().getTime() - days * MILL_PER_DAY
14+
15+
const birthdayOfBrowser = new Date()
16+
birthdayOfBrowser.setFullYear(1994)
17+
birthdayOfBrowser.setMonth(12 - 1)
18+
birthdayOfBrowser.setDate(15)
19+
20+
const datePickerShortcut = (msg: string, days: number) => {
21+
const text = t(messages => messages.clear.dateShortcut[msg])
22+
const value = [birthdayOfBrowser, daysBefore(days)]
23+
return { text, value }
24+
}
25+
26+
const pickerShortcuts = [
27+
datePickerShortcut('tillYesturday', 1),
28+
datePickerShortcut('till7DaysAgo', 7),
29+
datePickerShortcut('till30DaysAgo', 30)
30+
]
31+
32+
const basePickerProps = {
33+
size: 'mini',
34+
style: 'width:250px;',
35+
startPlaceholder: '1994/12/15',
36+
endPlaceholder: yesterdayMsg,
37+
type: 'daterange',
38+
disabledDate(date: Date) { return date.getTime() > yesterday },
39+
shortcuts: pickerShortcuts,
40+
rangeSeparator: '-'
41+
}
42+
43+
const picker = ({ dateRangeRef }: DateFilterProps) => h(ElDatePicker, {
44+
modelValue: dateRangeRef.value,
45+
"onUpdate:modelValue": (date: Array<Date>) => dateRangeRef.value = date,
46+
...basePickerProps
47+
})
48+
49+
const dateFilter = (props: DateFilterProps) => h('p', [
50+
h('a', { class: stepNoClz }, '1.'),
51+
tN(msg => msg.clear.filterDate, { picker: picker(props) })
52+
])
53+
54+
export default dateFilter
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { defineComponent, h, ref, Ref, SetupContext } from "vue"
2+
import TimerDatabase from "../../../../database/timer-database"
3+
import timerService from "../../../../service/timer-service"
4+
import { t } from "../../../locale"
5+
import '../style/filter'
6+
import dateFilter from "./date-filter"
7+
import numberFilter from "./number-filter"
8+
import operationButton, { BaseFilterProps } from "./operation-button"
9+
10+
const timerDatabase = new TimerDatabase(chrome.storage.local)
11+
12+
const dateRangeRef: Ref<Array<Date>> = ref([])
13+
const focusStartRef: Ref<string> = ref('0')
14+
const focusEndRef: Ref<string> = ref('2')
15+
const totalStartRef: Ref<string> = ref('0')
16+
const totalEndRef: Ref<string> = ref('')
17+
const timeStartRef: Ref<string> = ref('0')
18+
const timeEndRef: Ref<string> = ref('')
19+
20+
const title = h('h3', t(msg => msg.clear.filterItems))
21+
22+
const filterRefs: BaseFilterProps = {
23+
dateRangeRef,
24+
focusStartRef, focusEndRef,
25+
totalStartRef, totalEndRef,
26+
timeStartRef, timeEndRef,
27+
}
28+
29+
const archiveButton = (onDateChanged: () => void) => operationButton({
30+
...filterRefs,
31+
onDateChanged,
32+
33+
confirm: {
34+
message: 'archiveConfirm',
35+
operation: result => timerService.archive(result),
36+
resultMessage: 'archiveSuccess'
37+
},
38+
39+
button: {
40+
message: 'archive',
41+
icon: 'document-add',
42+
type: 'primary'
43+
},
44+
45+
tooltipMessage: 'archiveAlert'
46+
})
47+
48+
const deleteButton = (onDateChanged: () => void) => operationButton({
49+
...filterRefs,
50+
onDateChanged,
51+
52+
confirm: {
53+
message: 'deleteConfirm',
54+
operation: result => timerDatabase.delete(result),
55+
resultMessage: 'deleteSuccess'
56+
},
57+
58+
button: {
59+
message: 'delete',
60+
icon: 'delete',
61+
type: 'danger'
62+
}
63+
})
64+
65+
const _default = defineComponent((_props, ctx: SetupContext) => {
66+
const onDateChanged = ctx.attrs.onDateChanged as () => void
67+
68+
const buttons = () => [archiveButton(onDateChanged), deleteButton(onDateChanged)]
69+
70+
const footer = () => h('div', { class: 'filter-container', style: 'padding-top: 40px;' }, buttons())
71+
72+
return () => h('div', { style: 'text-align:left; padding-left:30px; padding-top:20px;' },
73+
[
74+
title,
75+
dateFilter({ dateRangeRef }),
76+
numberFilter('filterFocus', focusStartRef, focusEndRef, 2),
77+
numberFilter('filterTotal', totalStartRef, totalEndRef, 3),
78+
numberFilter('filterTime', timeStartRef, timeEndRef, 4),
79+
footer()
80+
]
81+
)
82+
})
83+
84+
export default _default
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ElInput } from "element-plus"
2+
import { Ref, h } from "vue"
3+
import { I18nKey, t, tN } from "../../../locale"
4+
import { ClearMessage } from "../../../locale/components/clear"
5+
import { stepNoClz } from "./consts"
6+
7+
const elInput = (valRef: Ref<string>, placeholder: string, min?: Ref<string>) =>
8+
h(ElInput, {
9+
class: 'filter-input',
10+
placeholder: placeholder,
11+
min: min !== undefined ? min.value || '0' : undefined,
12+
clearable: true,
13+
size: 'mini',
14+
modelValue: valRef.value,
15+
onInput: (val: string) => valRef.value = val.trim(),
16+
onClear: () => valRef.value = ''
17+
})
18+
19+
const numberFilter = (translateKey: keyof ClearMessage, startRef: Ref<string>, endRef: Ref<string>, lineNo: number) => h('p', [
20+
h('a', { class: stepNoClz }, `${lineNo}.`),
21+
tN(msg => msg.clear[translateKey], {
22+
start: elInput(startRef, '0'),
23+
end: elInput(endRef, t(msg => msg.clear.unlimited), startRef)
24+
})
25+
])
26+
27+
export default numberFilter

0 commit comments

Comments
 (0)