Skip to content

Commit 72d4a7f

Browse files
committed
Reconstruct layer components
1 parent 14304dd commit 72d4a7f

File tree

20 files changed

+123
-138
lines changed

20 files changed

+123
-138
lines changed

src/app/components/common/content-container.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import { defineComponent, h, VNode } from "vue"
9-
10-
/**
11-
* @returns the render function of content container
12-
*/
13-
export function renderContentContainer(childNodes: () => VNode[] | VNode): () => VNode {
14-
return () => h('div', { class: 'content-container' }, childNodes())
15-
}
16-
17-
export const contentContainerCardStyle = { class: 'container-card' }
8+
import { ElCard } from "element-plus"
9+
import { defineComponent, h, useSlots, VNode } from "vue"
1810

1911
const _default = defineComponent({
2012
name: "ContentContainer",
21-
setup(_, ctx) {
13+
setup() {
14+
const slots = useSlots()
15+
const children = []
16+
const hasDefault = !!slots.default
17+
if (hasDefault) {
18+
// Only one content
19+
children.push(h(slots.default))
20+
} else {
21+
// Else filter and content
22+
const hasFilter = !!slots.filter
23+
if (hasFilter) {
24+
children.push(h(ElCard, { class: "filter-container" }, () => h(slots.filter)))
25+
}
26+
slots.content && children.push(h(ElCard, { class: 'container-card' }, () => h(slots.content)))
27+
}
28+
2229
return () => h("div",
2330
{ class: "content-container" },
24-
() => {
25-
const child = []
26-
ctx.slots.filter && child.push(h(ctx.slots.filter))
27-
child.push(h(ctx.slots.content))
28-
return child
29-
}
31+
children
3032
)
3133
}
3234
})

src/app/components/common/date-range-filter-item.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const _default = defineComponent({
1515
disabledDate: Function,
1616
startPlaceholder: String,
1717
endPlaceholder: String,
18-
shortcuts: Array as PropType<Array<ElementDatePickerShortcut>>
18+
shortcuts: Array as PropType<Array<ElementDatePickerShortcut>>,
19+
clearable: {
20+
type: Boolean,
21+
default: true
22+
}
1923
},
2024
emits: ["change"],
2125
setup(props, ctx) {
@@ -30,7 +34,8 @@ const _default = defineComponent({
3034
shortcuts: props.shortcuts,
3135
'onUpdate:modelValue': (newVal: Array<Date>) => ctx.emit("change", dateRange.value = newVal),
3236
startPlaceholder: props.startPlaceholder,
33-
endPlaceholder: props.endPlaceholder
37+
endPlaceholder: props.endPlaceholder,
38+
clearable: props.clearable
3439
}
3540
))
3641
}

src/app/components/common/filter.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/app/components/data-manage/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ElRow, ElCol } from "element-plus"
99
import { defineComponent, h, ref, Ref } from "vue"
1010
import { getUsedStorage } from "@db/memory-detector"
1111
import './style'
12-
import { renderContentContainer } from "../common/content-container"
12+
import ContentContainer from "../common/content-container"
1313
import migration from "./migration"
1414
import memoryInfo from "./memory-info"
1515
import clearPanel from "./clear"
@@ -34,4 +34,6 @@ const firstRow = () => h(ElRow, { gutter: 20 },
3434
]
3535
)
3636

37-
export default defineComponent(() => renderContentContainer(firstRow))
37+
export default defineComponent(() => {
38+
return () => h(ContentContainer, {}, { default: () => firstRow() })
39+
})

src/app/components/habit/chart/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import { ElCard } from "element-plus"
98
import { h, Ref } from "vue"
10-
import { contentContainerCardStyle } from "@app/components/common/content-container"
119

1210
export type ChartProps = {
1311
chartRef: Ref<HTMLDivElement>
1412
}
1513

16-
const _default = (props: ChartProps) => h(ElCard,
17-
contentContainerCardStyle,
18-
() => h('div', { class: 'chart-container', ref: props.chartRef })
19-
)
14+
const _default = (props: ChartProps) => h('div', { class: 'chart-container', ref: props.chartRef })
2015

2116
export default _default

src/app/components/habit/filter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { daysAgo } from "@util/time"
1111
import { t } from "@app/locale"
1212
import { HabitMessage } from "@app/locale/components/habit"
1313
import SwitchFilterItem from "@app/components/common/switch-filter-item"
14-
import { renderFilterContainer } from "../common/filter"
1514
import { ElementDatePickerShortcut } from "@app/element-ui/date"
1615
import DateRangeFilterItem from "@app/components/common/date-range-filter-item"
1716

@@ -76,6 +75,7 @@ const childNodes = ({
7675
h(DateRangeFilterItem, {
7776
startPlaceholder: dateRangeStartPlaceholder,
7877
endPlaceholder: dateRangeEndPlaceholder,
78+
clearable: false,
7979
disabledDate: (date: Date) => date.getTime() > new Date().getTime(),
8080
shortcuts,
8181
onChange: (newVal: Date[]) => dateRangeRef.value = newVal
@@ -88,4 +88,4 @@ const childNodes = ({
8888
})
8989
]
9090

91-
export default renderFilterContainer(childNodes)
91+
export default (props: _Props) => childNodes(props)

src/app/components/habit/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
*/
77

88
import { ECharts, init } from "echarts"
9-
import { computed, ComputedRef, defineComponent, onMounted, ref, Ref, watch } from "vue"
9+
import { computed, ComputedRef, defineComponent, h, onMounted, ref, Ref, watch } from "vue"
1010
import { MAX_PERIOD_ORDER, PeriodKey } from "@entity/dto/period-info"
1111
import periodService, { PeriodQueryParam } from "@service/period-service"
1212
import { daysAgo, isSameDay } from "@util/time"
13-
import { renderContentContainer } from "../common/content-container"
13+
import ContentContainer from "@app/components/common/content-container"
1414
import chart, { ChartProps } from "./chart"
1515
import generateOptions from "./chart/option"
1616
import filter from "./filter"
@@ -72,10 +72,17 @@ const handleMounted = () => {
7272
queryAndRenderChart()
7373
}
7474

75-
const _default = defineComponent(() => {
76-
// Must use closure, not function variable
77-
onMounted(() => handleMounted())
78-
return renderContentContainer(() => [filter(filterProps), chart(chartProps)])
75+
const _default = defineComponent({
76+
name: "Habit",
77+
setup() {
78+
onMounted(() => handleMounted())
79+
return () => h(ContentContainer, {},
80+
{
81+
filter: () => filter(filterProps),
82+
content: () => chart(chartProps)
83+
}
84+
)
85+
}
7986
})
8087

8188
export default _default

src/app/components/limit/filter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Ref, h } from "vue"
1010
import InputFilterItem from "@app/components/common/input-filter-item"
1111
import SwitchFilterItem from "@app/components/common/switch-filter-item"
1212
import ButtonFilterItem from "@app/components/common/button-filter-item"
13-
import { renderFilterContainer } from "../common/filter"
1413
import { t } from "@app/locale"
1514

1615
type _Props = {
@@ -46,4 +45,4 @@ const filterItems = (props: _Props) => [
4645
// buttonFilterItem({ type: 'primary', label: msg => msg.limit.button.test, onClick: props.handleTest, icon: 'search' })
4746
]
4847

49-
export default renderFilterContainer(filterItems)
48+
export default (props: _Props) => filterItems(props)

src/app/components/limit/index.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
*/
77

88
import { defineComponent, h, ref, Ref, watch } from "vue"
9-
import { renderContentContainer, contentContainerCardStyle } from "../common/content-container"
9+
import ContentContainer from "../common/content-container"
1010
import filter, { FilterProps } from "./filter"
1111
import table from "./table"
1212
import AddDialog from "./add-dialog"
1313
import TimeLimitItem from "@entity/dto/time-limit-item"
1414
import limitService from "@service/limit-service"
1515
import { useRoute, useRouter } from "vue-router"
16-
import { ElCard } from "element-plus"
1716

1817
const urlRef: Ref<string> = ref('')
1918
const onlyEnabledRef: Ref<boolean> = ref(false)
@@ -38,25 +37,22 @@ const filterProps: FilterProps = {
3837
handleTest: () => { }
3938
}
4039

41-
const card = (listRef: Ref<TimeLimitItem[]>, addDialogRef: Ref) => h(ElCard,
42-
contentContainerCardStyle,
43-
() => [
44-
table({ list: listRef, queryData }),
45-
h(AddDialog, { ref: addDialogRef, onSaved: queryData })
46-
]
47-
)
48-
49-
const childNodes = () => [
50-
filter(filterProps),
51-
card(listRef, addDialogRef)
40+
const content = (listRef: Ref<TimeLimitItem[]>, addDialogRef: Ref) => [
41+
table({ list: listRef, queryData }),
42+
h(AddDialog, { ref: addDialogRef, onSaved: queryData })
5243
]
5344

54-
const _default = defineComponent(() => {
55-
const url = useRoute().query['url'] as string
56-
// Remove all the query params
57-
useRouter().replace({ query: {} })
58-
url && (urlRef.value = decodeURIComponent(url))
59-
return renderContentContainer(childNodes)
45+
const _default = defineComponent({
46+
name: "Limit",
47+
setup() {
48+
const url = useRoute().query['url'] as string
49+
useRouter().replace({ query: {} })
50+
url && (urlRef.value = decodeURIComponent(url))
51+
return () => h(ContentContainer, {}, {
52+
filter: () => filter(filterProps),
53+
content: () => content(listRef, addDialogRef)
54+
})
55+
}
6056
})
6157

6258
export default _default

src/app/components/report/file-export.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)