Skip to content

Commit

Permalink
feat: update subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
nella17 committed Jun 8, 2023
1 parent 9b12f02 commit 5867f70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
19 changes: 13 additions & 6 deletions src/components/PopUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DepPath, CourseWrap, SnackBar } from '@/types'
import Fuse from 'fuse.js'
import {
coursewrap2title,
coursewrap2subtitle,
limitStr,
path2str,
} from '@/composables/utils'
Expand Down Expand Up @@ -164,11 +164,18 @@ watch(pathSelect, async (value) => {
:item-title="coursewrap2title"
no-filter
>
<template v-slot:item="{ props, item }">
<v-list-item
v-bind="props"
:subtitle="coursewrap2subtitle(item.raw)"
/>
<template v-slot:item="{ props, item: { raw: { course } } }">
<v-list-item v-bind="props" lines="two">
<v-list-item-subtitle>
{{ course.master_dep_cname }}
{{ limitStr(course.lecturers, 5, 5) }}
{{ course.registered_num }} / {{ course.num_limit }}
({{ course.cos_credit }} / {{ course.cos_hours }})
{{ course.cos_time }}
<br>
{{ limitStr(course.memo, 30, 20) }}
</v-list-item-subtitle>
</v-list-item>
</template>
</v-autocomplete>

Expand Down
18 changes: 6 additions & 12 deletions src/composables/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ export async function digestMessage(message: any) {
return hashHex
}

export function coursewrap2title({ course }: CourseWrap) {
const { cos_id, cos_cname, cos_ename } = course
export function coursewrap2title({
course: { cos_id, cos_cname, cos_ename },
}: CourseWrap) {
return `${cos_id} ${cos_cname} ${cos_ename}`
}

export function coursewrap2subtitle({ course }: CourseWrap) {
const {
master_dep_cname,
lecturers,
cos_hours,
cos_credit,
num_limit,
registered_num,
} = course
return `${master_dep_cname} ${lecturers} (${cos_credit} / ${cos_hours}) ${registered_num} / ${num_limit}`
export function limitStr(str: string, limit_front: number, limit_back: number = 0) {
if (str.length <= limit_front + limit_back) return str
return str.slice(0, limit_front) + ' ... ' + str.slice(-limit_back)
}

export function path2str({ path }: { path: DepPath }) {
Expand Down

0 comments on commit 5867f70

Please sign in to comment.