-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor sorting logic in TermTable.vue and use-app.ts
- Loading branch information
1 parent
29b39aa
commit 40df843
Showing
8 changed files
with
88 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<div class="flex cursor-pointer items-center gap-1" @click="toggleSort"> | ||
<slot> | ||
{{ label }} | ||
</slot> | ||
<Icon :name="sortIcon" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { SORT_MODE } from '~/constants'; | ||
import type { SortKey } from '~/types'; | ||
interface Props { | ||
label?: string; | ||
field: string; | ||
modelValue: SortKey; | ||
} | ||
const props = defineProps<Props>(); | ||
const emit = defineEmits(['update:modelValue']); | ||
function toggleSort() { | ||
const { mode } = props.modelValue; | ||
const newMode = mode === SORT_MODE.ASC ? SORT_MODE.DESC : SORT_MODE.ASC; | ||
emit('update:modelValue', { key: props.field, mode: newMode }); | ||
} | ||
const sortIcon = computed(() => { | ||
const { key, mode } = props.modelValue; | ||
if (key === props.field) { | ||
return mode === SORT_MODE.ASC | ||
? 'system-uicons:arrow-up' | ||
: 'system-uicons:arrow-down'; | ||
} | ||
return 'system-uicons:question-circle'; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import type { KeyValue } from '~/types'; | ||
import { SORT_MODE } from '~/constants'; | ||
import type { KeyValue, SortKey } from '~/types'; | ||
|
||
export const useApp = () => { | ||
const title = useState('app-title', () => 'Dashboard'); | ||
|
||
// setting app | ||
const setting = useState<KeyValue>('app-setting', () => ({})); | ||
const setting = useState<KeyValue>('app-setting', () => ({ | ||
formatDate: 'dd/MM/yyyy', | ||
formatDateTime: 'dd/MM/yyyy HH:mm:ss', | ||
formatTime: 'HH:mm:ss', | ||
})); | ||
|
||
const page = ref(1); | ||
const limit = 10; | ||
const search = ref(''); | ||
const orderBy = useState<SortKey>('app-order-by', () => ({ | ||
key: 'id', | ||
mode: SORT_MODE.ASC, | ||
})); | ||
|
||
function getOrderBy() { | ||
const { key, mode } = orderBy.value; | ||
return { | ||
[key]: mode, | ||
}; | ||
} | ||
|
||
return { | ||
title, | ||
setting, | ||
page, | ||
limit, | ||
search, | ||
orderBy, | ||
getOrderBy, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,6 @@ | |
"vue-router": "^4.2.5" | ||
}, | ||
"dependencies": { | ||
"echarts": "^5.4.3" | ||
"echarts": "^5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
import type { SORT_MODE } from '~/constants'; | ||
|
||
export interface KeyValue { | ||
[key: string]: string | number | boolean; | ||
} | ||
|
||
export interface SortKey { | ||
key: string; | ||
mode: SORT_MODE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters