forked from maple3142/GDIndex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
111 lines (108 loc) · 2.57 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
<v-app>
<v-app-bar app color="primary" dark>
<v-toolbar-title class="headline pointer mr-3 hidden-sm-and-down">
<router-link
:to="{ path: '/', query: { rootId: $route.query.rootId } }"
tag="span"
>{{ title }}</router-link
>
</v-toolbar-title>
<v-toolbar-items>
<v-menu offset-y v-if="drives.length">
<template v-slot:activator="{ on }">
<v-btn text v-on="on" class="text-none">
<v-icon>mdi-cloud</v-icon> {{
currentDrive.text
}}<v-icon>mdi-menu-down</v-icon>
</v-btn>
</template>
<v-list>
<v-list-item
v-for="(item, index) in drives"
:key="index.id"
@click="changeDrive(item.value)"
>
<v-list-item-title>{{
item.text
}}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-toolbar-items>
<portal-target name="navbar" slim />
<v-spacer />
<v-toolbar-items>
<v-btn
text
class="text-none hidden-sm-and-down"
tag="a"
href="https://github.com/Misaka13514"
target="_blank"
>
<v-icon>mdi-github-circle</v-icon> GitHub</v-btn
>
</v-toolbar-items>
</v-app-bar>
<v-content> <router-view /> </v-content>
<LoginDialog :show="showAuthInput" />
</v-app>
</template>
<script>
import api from './api'
import LoginDialog from './components/LoginDialog.vue'
export default {
props: {
title: String,
},
data() {
return {
drives: [],
value: {},
showAuthInput: false,
}
},
computed: {
currentDrive() {
const id = this.$route.query.rootId || window.props.default_root_id
return this.drives.find((d) => d.value === id)
},
},
async created() {
const ok =
new URL(window.props.api).hostname === location.hostname ||
(await api
.get(window.props.api)
.then(() => true)
.catch((err) => {
if (err.response.status === 401) {
this.showAuthInput = true
return false
}
}))
if (!ok) return
const { drives } = await api.get('/~_~_gdindex/drives').json()
this.drives = [{ text: this.$t('mainDrive'), value: 'root' }].concat(
drives.map((d) => ({
value: d.id,
text: d.name,
}))
)
},
methods: {
changeDrive(drive) {
const rootId =
drive !== window.props.default_root_id ? drive : undefined
const dest = { path: '/', query: { rootId } }
if (
dest.path === this.$route.path &&
dest.query.rootId === this.$route.query.rootId
) {
return // vue-router forbid going to same location
}
this.$router.push({ path: '/', query: { rootId } })
},
},
components: { LoginDialog },
}
</script>