Skip to content

Commit e944b74

Browse files
committed
feat: 适配手机
1 parent ba718f4 commit e944b74

15 files changed

Lines changed: 88 additions & 53 deletions

File tree

app.vue

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<template>
22
<v-app>
33
<v-layout>
4-
<v-app-bar flat border class="position-fixed">
5-
<v-toolbar border color="white">
4+
<v-app-bar flat border class="position-fixed" :density="mobile ? 'compact' : 'comfortable'">
5+
<v-toolbar border color="white" :density="mobile ? 'compact' : 'comfortable'">
66
<template #prepend>
7-
<v-btn icon="mdi-menu" variant="text" class="d-md-none" @click="toggleSidebar" />
8-
<v-icon class="ma-3 d-none d-md-block" icon="mdi-school" />
7+
<v-btn v-if="$vuetify.display.mobile && sidebarLabel" icon="mdi-menu" variant="text" @click="toggleSidebar" />
8+
<v-icon v-else class="ma-3" icon="mdi-school" />
99
</template>
10-
<v-toolbar-title class="site-title" @click="navigateTo('/')">{{ config.public.siteTitle
10+
<v-toolbar-title :class="$vuetify.display.mobile ? 'text-body-1' : ''" @click="navigateTo('/')">{{ config.public.siteTitle
1111
}}</v-toolbar-title>
12-
<v-spacer />
12+
<v-spacer class="d-none d-md-block" />
1313
<template #append>
1414
<TopTabs />
1515
</template>
1616
</v-toolbar>
1717
</v-app-bar>
18-
<NuxtPage />
18+
<NuxtPage :sidebar="sidebarDrawer" />
1919
</v-layout>
2020
</v-app>
2121
</template>
@@ -25,11 +25,24 @@ import TopTabs from '~/components/TopTabs.vue';
2525
const config = useRuntimeConfig();
2626
2727
const router = useRouter();
28+
const route = useRoute();
29+
const mobile = useNuxtApp().$vuetify.display.smAndDown;
2830
29-
const sidebarDrawer = ref(true);
31+
const sidebarLabel = computed(() => {
32+
const path = route.path.includes("edit");
33+
return path || route.params.major;
34+
})
35+
36+
const sidebarDrawer = ref(false);
3037
function toggleSidebar() {
3138
sidebarDrawer.value = !sidebarDrawer.value;
3239
}
40+
41+
watch(() => route.path, () => {
42+
if (mobile)
43+
sidebarDrawer.value = false;
44+
})
45+
3346
function navigateTo(path: string) {
3447
router.push(path);
3548
}

components/TopTabs.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<template>
22
<div class="d-flex">
3-
<v-menu v-if="schoolMajors" open-on-hover offset-y :close-on-content-click="false" attach="body">
3+
<v-menu v-if="schoolMajors" open-on-hover :open-on-click="$vuetify.display.mobile" offset-y :close-on-content-click="false" attach="body">
44
<template #activator="{ props }">
5-
<v-btn v-bind="props" variant="text" append-icon="mdi-chevron-down">选择专业</v-btn>
5+
<v-btn v-if="!$vuetify.display.mobile" v-bind="props" variant="text" append-icon="mdi-chevron-down">选择专业</v-btn>
6+
<v-btn v-else v-bind="props" variant="text" icon="mdi-library-shelves" />
67
</template>
78
<v-card>
89
<v-card-text class="overflow-auto-x" style="width: 60em">
10+
<div class="top-tabs-searchbar d-md-none mb-1">
11+
<SearchBar />
12+
</div>
913
<v-row>
10-
<v-col v-for="j in 3" :key="j">
14+
<v-col v-for="j in 3" :key="j" cols="12" md="4">
1115
<v-expansion-panels variant="accordion" flat width="20em">
1216
<v-expansion-panel
1317
v-for="i in Math.min(Math.floor((schoolMajors.length + 2) / 3), schoolMajors.length - Math.floor((schoolMajors.length + 2) / 3) * (j - 1))"
@@ -30,20 +34,23 @@
3034
</v-card>
3135
</v-menu>
3236

33-
<v-btn variant="text" class="ml-6" to="/docs/0/0" :active="false">简介</v-btn>
34-
<div class="top-tabs-searchbar ml-6">
37+
<v-btn v-if="!$vuetify.display.mobile" variant="text" class="ml-6" to="/docs/0/0" :active="false">简介</v-btn>
38+
<v-btn v-else variant="text" to="/docs/0/0" icon="mdi-book-play-outline" :active="false"/>
39+
40+
<div class="top-tabs-searchbar ml-6 d-none d-md-block">
3541
<SearchBar />
3642
</div>
3743
</div>
3844

39-
<v-divider vertical />
45+
<v-divider class="d-none d-md-block" vertical />
4046

4147
<div>
4248
<v-btn v-if="!loggedIn" class="ml-2 mr-2" append-icon="mdi-login"
4349
@click="navigateTo(`/login?redirect=${$route.path}`)">登录</v-btn>
44-
<v-menu v-else open-on-hover>
50+
<v-menu v-else open-on-hover :open-on-click="$vuetify.display.mobile">
4551
<template #activator="{ props }">
46-
<v-btn v-bind="props" variant="text" class="ml-2 mr-2" append-icon="mdi-chevron-down">操作</v-btn>
52+
<v-btn v-if="!$vuetify.display.mobile" v-bind="props" variant="text" class="ml-2 mr-2" append-icon="mdi-chevron-down">操作</v-btn>
53+
<v-btn v-else v-bind="props" variant="text" icon="mdi-chevron-down" />
4754
</template>
4855
<v-list density="compact">
4956
<v-list-item prepend-icon="mdi-account" title="个人中心" to="/user" />

components/mdc/Error.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="mt-4 mb-4">
33
<v-alert type="error" border="start" variant="tonal">
4-
<MDCSlot />
4+
<MDCSlot unwrap="p" />
55
</v-alert>
66
</div>
77
</template>

components/mdc/Info.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="mt-4 mb-4">
33
<v-alert type="info" border="start" variant="tonal">
4-
<MDCSlot />
4+
<MDCSlot unwrap="p" />
55
</v-alert>
66
</div>
77
</template>

components/mdc/Warning.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="mt-4 mb-4">
33
<v-alert type="warning" border="start" variant="tonal">
4-
<MDCSlot />
4+
<MDCSlot unwrap="p" />
55
</v-alert>
66
</div>
77
</template>

pages/docs/[major].vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<v-main>
3-
<v-navigation-drawer v-if="listItems" permanent class="position-fixed">
3+
<v-navigation-drawer v-if="listItems" :model-value="!$vuetify.display.mobile || props.sidebar" mobile-breakpoint="sm">
44
<v-list v-if="Number(majorId) != 0" v-model:opened="listOpen">
55
<v-list-group v-for="(gradeCourses, index) in listItems" v-show="gradeCourses.length" :key="index"
66
:value="index">
@@ -37,6 +37,8 @@ if (!route.params.doc)
3737
3838
const requestFetch = useRequestFetch();
3939
40+
const props = defineProps<{ sidebar: boolean }>();
41+
4042
/**
4143
* 分年级和类别的课程列表
4244
*/

pages/docs/[major]/[doc].vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
<script setup lang="ts">
7575
import { useRoute } from 'vue-router';
7676
77-
7877
const route = useRoute();
7978
const majorId = route.params.major as string;
8079
const docId = route.params.doc as string;

pages/edit.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<template>
22
<v-main>
3-
<v-navigation-drawer permanent>
3+
<v-btn v-if="$route.params.major && props.sidebar" icon="mdi-swap-horizontal" class="d-md-none position-fixed right-0" style="z-index: 1000;" @click="swap = !swap" />
4+
<v-navigation-drawer mobile-breakpoint="sm" :model-value="!$vuetify.display.mobile || (props.sidebar && !swap)" persistent>
45
<v-list>
56
<v-list-group v-for="[school, majors] in listItems" :key="school" :value="school">
7+
<!-- eslint-disable-next-line vue/no-template-shadow -->
68
<template #activator="{ props }">
79
<v-list-item v-bind="props" :title="school" />
810
</template>
@@ -12,9 +14,8 @@
1214
</v-list-group>
1315
</v-list>
1416
</v-navigation-drawer>
15-
<NuxtPage :majors="majorList" />
16-
17-
<div v-if="$route.params.major == undefined">
17+
<NuxtPage :majors="majorList" :sidebar="props.sidebar" :sidebar-swap="swap" />
18+
<div v-if="$route.params.major == undefined" class="ma-4">
1819
<v-breadcrumbs :items="['编辑专业']" />
1920
<v-row justify="center">
2021
<v-col cols="12" md="6" lg="4" xl="4">
@@ -98,6 +99,10 @@ definePageMeta({
9899
middleware: ['auth']
99100
});
100101
102+
const props = defineProps<{ sidebar: boolean }>();
103+
104+
const swap = ref(false);
105+
101106
const requestFetch = useRequestFetch();
102107
103108
const validAdd = ref(false);

pages/edit/[major].vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="fill-height">
3-
<v-navigation-drawer v-if="listItems" permanent class="position-fixed">
3+
<v-navigation-drawer v-if="listItems" mobile-breakpoint="sm" class="position-fixed" :model-value="!$vuetify.display.mobile || (props.sidebar && props.sidebarSwap)" persistent>
44
<v-list v-if="Number(majorId) != 0">
55
<v-list-group v-for="(gradeCourses, index) in listItems" v-show="gradeCourses.length" :key="index"
66
:value="index">
@@ -24,7 +24,7 @@
2424
</v-list>
2525
</v-navigation-drawer>
2626
<NuxtPage :majors="props.majors" class="fill-height" />
27-
<div v-if="$route.params.doc == undefined">
27+
<div v-if="$route.params.doc == undefined" class="ma-4">
2828

2929
<v-breadcrumbs>
3030
<v-breadcrumbs-item to="/edit">编辑专业</v-breadcrumbs-item>
@@ -81,7 +81,7 @@ import type { CourseInfo } from '~/utils/types';
8181
const route = useRoute();
8282
const majorId = route.params.major;
8383
84-
const props = defineProps<{ majors: Major[] }>();
84+
const props = defineProps<{ majors: Major[], sidebar: boolean, sidebarSwap: boolean }>();
8585
8686
const delCourse = ref({ name: "", reason: "" });
8787

pages/edit/[major]/[doc].vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<v-breadcrumbs-item :disabled="true">编辑文档</v-breadcrumbs-item>
99
</v-breadcrumbs>
1010
<v-row ref="row1Space" class="ml-1 mr-1">
11-
<v-col>
11+
<v-col cols="12" md="6">
1212
<v-text-field v-model="newCourse.course_name" variant="outlined" hide-details label="课程名称"
1313
density="compact" />
1414
</v-col>
15-
<v-col>
15+
<v-col cols="12" md="6">
1616
<v-btn-toggle v-model="toggle" divided>
1717
<v-btn value="unique">
1818
<span class="hidden-sm-and-down">独立页面</span>
@@ -34,22 +34,23 @@
3434
</v-row>
3535
<v-form v-model="infoValid">
3636
<v-row ref="row2Space" class="ml-1 mr-1 ">
37-
<v-col>
37+
<v-col cols="6" md="3">
3838
<v-number-input v-model="newCourse.credit" :precision="1" :step="0.5" control-variant="split"
39-
label="学分" :hide-input="false" :inset="false" variant="outlined" density="compact" />
39+
label="学分" :hide-input="false" :inset="false" variant="outlined" density="compact"
40+
hide-details />
4041
</v-col>
4142

42-
<v-col>
43+
<v-col cols="6" md="3">
4344
<v-combobox v-model="newCourse.class" :items="classNames" variant="outlined" density="compact"
44-
label="类型" />
45+
label="类型" hide-details />
4546
</v-col>
4647

47-
<v-col>
48+
<v-col cols="6" md="3">
4849
<v-combobox v-model="grade" :items="gradeName" variant="outlined" density="compact" label="年级"
4950
:rules="[checkGrade]" />
5051
</v-col>
5152

52-
<v-col>
53+
<v-col cols="6" md="3">
5354
<v-text-field v-model="newCourse.direction" variant="outlined" label="专业方向" hint="不区分方向则留空"
5455
density="compact" />
5556
</v-col>
@@ -102,11 +103,11 @@
102103
</v-row>
103104
<v-row ref="row4Space" class="ml-4 mr-4" justify="end">
104105
<!-- <v-col> -->
105-
<v-btn class="mt-2" :disabled="!infoValid || (toggle == 'other' && !linkValid)" color="primary"
106+
<v-btn class="mt-2 mb-4" :disabled="!infoValid || (toggle == 'other' && !linkValid)" color="primary"
106107
variant="tonal" @click="submit">提交</v-btn>
107108
<!-- </v-col> -->
108109
</v-row>
109-
<v-navigation-drawer location="right">
110+
<v-navigation-drawer :location="$vuetify.display.mobile ? 'bottom' : 'end'" permanent>
110111
<v-progress-linear v-show="uploadProgress != 0" v-model="uploadProgress" color="primary" />
111112

112113
<v-file-input v-show="toggle == 'unique'" v-model="selectedFiles" label="上传附件" multiple show-size counter
@@ -136,8 +137,8 @@
136137
</v-snackbar>
137138
</div>
138139
<div v-else>
139-
<v-row justify="center" class="mt-8">
140-
<v-sheet class="pa-4 ma-4 text-center mx-auto" elevation="12" max-width="600" rounded="lg" width="100%">
140+
<v-row justify="center" :class="!$vuetify.display.mobile ? 'mt-8' : 'ma-4'">
141+
<v-sheet class="pa-4 ma-4 text-center mx-auto" max-width="600" rounded="lg" width="100%">
141142
<v-icon class="mb-5" color="success" icon="mdi-check-circle" size="112" />
142143

143144
<h2 class="text-h5 mb-6">提交成功</h2>
@@ -383,7 +384,7 @@ const uploadFiles = () => {
383384
onUploadProgress: (progressEvent) => {
384385
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total!);
385386
uploadProgress.value = percentCompleted;
386-
}
387+
},
387388
}).then((res: AxiosResponse<{ resList: AttachmentInfo[] }>) => {
388389
newAttachments.value = newAttachments.value.concat(res.data.resList);
389390
uploadProgress.value = 0;

0 commit comments

Comments
 (0)