-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathApp.vue
258 lines (252 loc) · 7.2 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<template>
<v-app style="background: rgba(0,0,0,0);">
<div id="web_bg" :style="'background-image: url(' + imgUrl + ');'"></div>
<v-app-bar app color="rgba(0,0,0,.2)" dark flat fixed>
<v-toolbar-title>Life In NJU</v-toolbar-title>
<v-spacer></v-spacer>
<v-icon
@click="open('https://github.com/idealclover/Life-in-NJU')"
class="mx-3"
>
mdi-github
</v-icon>
<v-icon
class="shareLink"
data-clipboard-text="https://nju.today"
@click="share"
>
mdi-open-in-new
</v-icon>
</v-app-bar>
<v-content class="mt-12">
<v-container>
<v-col align="center" justify="center" class="pa-0">
<v-img
class="logo-item"
:src="engineList[engineIndex]['src']"
@click="nextEngine"
></v-img>
<v-text-field
flat
solo
class="mt-10"
label="Search"
v-model="value"
append-icon="search"
@click:append="search"
@keyup.enter="search"
></v-text-field>
<v-row
class="mb-10"
align="center"
justify="center"
id="searchOptBox"
>
<div class="text-center mx-4">
<v-btn
depressed
rounded
color="rgba(0,0,0,.2)"
dark
class="searchOpt"
@click="changeEngine(0)"
>
<i class="iconfont" id="iconBaidu"></i>
</v-btn>
</div>
<div class="text-center mx-4">
<v-btn
depressed
rounded
color="rgba(0,0,0,.2)"
dark
class="searchOpt"
@click="changeEngine(1)"
>
<i class="iconfont" id="iconBing"></i>
</v-btn>
</div>
<div class="text-center mx-4">
<v-btn
depressed
rounded
color="rgba(0,0,0,.2)"
dark
class="searchOpt"
@click="changeEngine(2)"
>
<i class="iconfont" id="iconGoogle"></i>
</v-btn>
</div>
</v-row>
</v-col>
</v-container>
<v-container style="flex: 1 1 auto">
<v-expansion-panels multiple>
<!-- <v-expansion-panels multiple :value="[0, 1, 2, 3]"> -->
<v-expansion-panel
v-for="(category, i) in data"
:key="i"
class="panels"
>
<v-expansion-panel-header>{{
category.title
}}</v-expansion-panel-header>
<v-expansion-panel-content>
<v-row>
<v-col
class="pa-1 d-flex flex-column"
cols="12"
lg="3"
v-for="(item, i) in category.items"
:key="i"
>
<v-card
outlined
tile
@click="item.link === '' ? null : open(item.link)"
class="panel flex d-flex flex-column"
:title="item.description"
>
<v-card-text>
<p class="ma-0 font-weight-black">
{{ item.name }}
</p>
<p class="ma-0 flex">
{{ item.description }}
</p>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
</v-container>
<v-col
class="text-center white--text"
style="background-color: rgba(0,0,0,.2); flex: 0 1 auto"
cols="12"
>祝南哪 120 周年生日快乐!<br />
©{{ new Date().getFullYear() }}
<a
href="https://idealclover.top"
class="white--text"
target="_blank"
rel="noopener noreferrer nofollow"
>idealclover</a
>
</v-col>
<v-snackbar v-model="snackbar">
{{ snackText }}
<v-btn color="pink" text @click="snackbar = false">
Close
</v-btn>
</v-snackbar>
</v-content>
</v-app>
</template>
<script>
import axios from "axios";
import Vue from "vue";
import Vuex from "vuex";
import createPersiste from "vue-savedata";
import NativeShare from "nativeshare";
import Clipboard from "clipboard";
const dataUrl = "https://image.idealclover.cn/projects/Life-in-NJU/";
const imgUrl =
dataUrl + "background/bg" + Math.floor(Math.random() * 24) + ".jpg";
new Clipboard(".shareLink");
Vue.use(Vuex);
let nativeShare = new NativeShare();
const store = new Vuex.Store({
state: {
engineIndex: 0
},
mutations: {
changeEngineIndex(state, num) {
state.engineIndex = num;
}
},
plugins: [createPersiste()]
});
export default {
name: "App",
mounted() {
axios.get("./data.json").then(response => (this.data = response.data));
},
data: () => ({
data: null,
value: "",
dataUrl: dataUrl,
imgUrl: imgUrl,
snackbar: false,
snackText: "",
engineIndex: store.state.engineIndex,
engineList: [
{
name: "baidu",
url: "https://www.baidu.com/s?wd=",
src: dataUrl + "search/baidu-white.png"
},
{
name: "bing",
url: "https://cn.bing.com/search?q=",
src: dataUrl + "search/bing-white.png"
},
{
name: "google",
url: "https://www.google.com/search?q=",
src: dataUrl + "search/google-white.png"
}
]
}),
methods: {
open: function(link) {
// window.location.href = link;
let tab = window.open(link);
tab.opener = null;
tab.location = link;
},
share: function() {
nativeShare.setShareData({
icon: "https://nju.today/img/icons/android-chrome-192x192.png",
link: "https://nju.today",
title: "南哪指南",
desc: "南哪人的专属导航页!",
from: "@idealclover"
});
// 唤起浏览器原生分享组件(如果在微信中不会唤起,此时call方法只会设置文案。类似setShareData)
try {
nativeShare.call();
} catch (err) {
this.showToast("链接已复制,快分享给小伙伴吧!");
}
},
search: function() {
let value = this.value;
this.value = "";
this.open(this.engineList[this.engineIndex]["url"] + value);
},
changeEngine: function(num) {
this.engineIndex = num;
store.commit("changeEngineIndex", num);
},
nextEngine: function() {
this.engineIndex = (this.engineIndex + 1) % this.engineList.length;
store.commit("changeEngineIndex", this.engineIndex);
},
showToast: function(text) {
this.snackText = text;
this.snackbar = true;
}
}
};
</script>
<style>
/*因为v-content无法操作slot的临时hack,可能需要修改布局*/
div[class="v-content__wrap"] {
display: flex;
flex-direction: column;
}
</style>