🎨Optimize tips

This commit is contained in:
Aicirou 2020-07-04 23:29:55 +08:00
parent 1bdbf46020
commit adedafde03
5 changed files with 75 additions and 59 deletions

View File

@ -54,6 +54,7 @@
"tips": "New version detected, <a href='${url}'>Go to GitHub</a>" "tips": "New version detected, <a href='${url}'>Go to GitHub</a>"
}, },
"error": { "error": {
"shortcut_not_down": "Shortcut can't open/download" "shortcut_not_down": "Shortcut can't open/download",
"401": "Unauthorized, please login"
} }
} }

View File

@ -54,6 +54,7 @@
"tips": "检测到有新版本,<a href='${url}'>前往GitHub</a>" "tips": "检测到有新版本,<a href='${url}'>前往GitHub</a>"
}, },
"error": { "error": {
"shortcut_not_down": "快捷方式无法打开/下载" "shortcut_not_down": "快捷方式无法打开/下载",
"401": "未授权,请登录"
} }
} }

View File

@ -54,6 +54,7 @@
"tips": "檢測到有新版本,<a href='${url}'>前往GitHub</a>" "tips": "檢測到有新版本,<a href='${url}'>前往GitHub</a>"
}, },
"error": { "error": {
"shortcut_not_down": "快捷方式無法打開/下載" "shortcut_not_down": "快捷方式無法打開/下載",
"401": "未授權,請登錄"
} }
} }

View File

@ -1,6 +1,6 @@
import axios from "axios"; import axios from "axios";
import store from "@/store"; import store from "@/store";
import router from "@/router"; import notify from "@/components/notification";
// 创建一个 axios 实例 // 创建一个 axios 实例
const service = axios.create({ const service = axios.create({
@ -33,14 +33,19 @@ service.interceptors.response.use(
if (error && error.response) { if (error && error.response) {
switch (error.response.status) { switch (error.response.status) {
case 401: case 401:
error.message = "未授权,请登录"; error.message = "error.401";
notify({
title: "notify.title",
message: error.message,
type: "error",
duration: 5 * 1000,
});
break; break;
default: default:
console.log(error);
break; break;
} }
} }
console.log(error);
router.app.$router.go(-1);
return Promise.reject(error); return Promise.reject(error);
} }
); );

View File

@ -1,6 +1,10 @@
<template> <template>
<div> <div>
<headmd :option="headmd" v-if="renderHeadMD && headmd.display" style="margin:1rem 0;"></headmd> <headmd
:option="headmd"
v-if="renderHeadMD && headmd.display"
style="margin:1rem 0;"
></headmd>
<bread-crumb ref="breadcrumb"></bread-crumb> <bread-crumb ref="breadcrumb"></bread-crumb>
<div class="golist" v-loading="loading"> <div class="golist" v-loading="loading">
<list-view <list-view
@ -27,7 +31,10 @@
<div slot="no-more"></div> <div slot="no-more"></div>
<div slot="no-results"></div> <div slot="no-results"></div>
</infinite-loading> </infinite-loading>
<div v-show="files.length === 0" class="has-text-centered no-content"></div> <div
v-show="files.length === 0"
class="has-text-centered no-content"
></div>
</div> </div>
<div <div
class="is-divider" class="is-divider"
@ -35,7 +42,10 @@
$t('list.total') + ' ' + files.length + ' ' + $t('list.item') $t('list.total') + ' ' + files.length + ' ' + $t('list.item')
" "
></div> ></div>
<readmemd :option="readmemd" v-if="renderReadMeMD && readmemd.display"></readmemd> <readmemd
:option="readmemd"
v-if="renderReadMeMD && readmemd.display"
></readmemd>
<viewer <viewer
v-if="viewer && images && images.length > 0" v-if="viewer && images && images.length > 0"
@ -81,7 +91,7 @@ export default {
Readmemd: Markdown, Readmemd: Markdown,
InfiniteLoading, InfiniteLoading,
}, },
data: function () { data: function() {
return { return {
infiniteId: +new Date(), infiniteId: +new Date(),
loading: true, loading: true,
@ -123,7 +133,7 @@ export default {
"image/bmp": "icon-img", "image/bmp": "icon-img",
"image/jpeg": "icon-img", "image/jpeg": "icon-img",
"image/png": "icon-img", "image/png": "icon-img",
"image/gif": "icon-img" "image/gif": "icon-img",
}, },
headmd: { display: false, file: {}, path: "" }, headmd: { display: false, file: {}, path: "" },
readmemd: { display: false, file: {}, path: "" }, readmemd: { display: false, file: {}, path: "" },
@ -131,23 +141,21 @@ export default {
}, },
computed: { computed: {
...mapState("acrou/view", ["mode"]), ...mapState("acrou/view", ["mode"]),
images () { images() {
return this.files.filter( return this.files.filter((file) => file.mimeType.startsWith("image/"));
(file) => file.mimeType.startsWith("image/")
);
}, },
renderHeadMD () { renderHeadMD() {
return window.themeOptions.render.head_md || false; return window.themeOptions.render.head_md || false;
}, },
renderReadMeMD () { renderReadMeMD() {
return window.themeOptions.render.readme_md || false; return window.themeOptions.render.readme_md || false;
}, },
}, },
created () { created() {
this.render(); this.render();
}, },
methods: { methods: {
infiniteHandler ($state) { infiniteHandler($state) {
// //
if (!this.page.page_token) { if (!this.page.page_token) {
return; return;
@ -155,7 +163,7 @@ export default {
this.page.page_index++; this.page.page_index++;
this.render($state); this.render($state);
}, },
render ($state) { render($state) {
this.headmd = { display: false, file: {}, path: "" }; this.headmd = { display: false, file: {}, path: "" };
this.readmemd = { display: false, file: {}, path: "" }; this.readmemd = { display: false, file: {}, path: "" };
var path = this.$route.path; var path = this.$route.path;
@ -198,37 +206,36 @@ export default {
} }
this.loading = false; this.loading = false;
}) })
.catch((e) => { .catch(() => {
this.loading = false; this.loading = false;
console.log(e);
}); });
}, },
buildFiles (files) { buildFiles(files) {
var path = this.$route.path; var path = this.$route.path;
return !files return !files
? [] ? []
: files : files
.map((item) => { .map((item) => {
var p = path + checkoutPath(item.name, item); var p = path + checkoutPath(item.name, item);
let isFolder = let isFolder =
item.mimeType === "application/vnd.google-apps.folder"; item.mimeType === "application/vnd.google-apps.folder";
let size = isFolder ? "-" : formatFileSize(item.size); let size = isFolder ? "-" : formatFileSize(item.size);
return { return {
path: p, path: p,
...item, ...item,
modifiedTime: formatDate(item.modifiedTime), modifiedTime: formatDate(item.modifiedTime),
size: size, size: size,
isFolder: isFolder, isFolder: isFolder,
}; };
}) })
.sort((a, b) => { .sort((a, b) => {
if (a.isFolder && b.isFolder) { if (a.isFolder && b.isFolder) {
return 0; return 0;
} }
return a.isFolder ? -1 : 1; return a.isFolder ? -1 : 1;
}); });
}, },
checkPassword (path) { checkPassword(path) {
var pass = prompt(this.$t("list.auth"), ""); var pass = prompt(this.$t("list.auth"), "");
localStorage.setItem("password" + path, pass); localStorage.setItem("password" + path, pass);
if (pass != null && pass != "") { if (pass != null && pass != "") {
@ -237,36 +244,37 @@ export default {
this.$router.go(-1); this.$router.go(-1);
} }
}, },
copy (path) { copy(path) {
let origin = window.location.origin; let origin = window.location.origin;
path = origin + encodeURI(path); path = origin + encodeURI(path);
this.$copyText(path) this.$copyText(path)
.then(() => { .then(() => {
this.$notify({ this.$notify({
title: this.$t("notify.title"), title: "notify.title",
message: this.$t("copy.success"), message: "copy.success",
type: "success", type: "success",
}); });
}) })
.catch(() => { .catch(() => {
this.$notify.error({ this.$notify({
title: this.$t("notify.title"), title: "notify.title",
message: this.$t("copy.error"), message: "copy.error",
type: "error"
}); });
}); });
}, },
thum (url) { thum(url) {
return url ? `/${this.$route.params.id}:view?url=${url}` : ""; return url ? `/${this.$route.params.id}:view?url=${url}` : "";
}, },
inited (viewer) { inited(viewer) {
this.$viewer = viewer; this.$viewer = viewer;
}, },
action (file, target) { action(file, target) {
// If it is a shortcut, the prompt cannot be downloaded // If it is a shortcut, the prompt cannot be downloaded
if (file.mimeType === "application/vnd.google-apps.shortcut") { if (file.mimeType === "application/vnd.google-apps.shortcut") {
this.$notify({ this.$notify({
title: this.$t("notify.title"), title: "notify.title",
message: this.$t("error.shortcut_not_down"), message: "error.shortcut_not_down",
type: "warning", type: "warning",
}); });
return; return;
@ -286,7 +294,7 @@ export default {
} }
this.target(file, target); this.target(file, target);
}, },
target (file, target) { target(file, target) {
let path = file.path; let path = file.path;
if (target === "_blank") { if (target === "_blank") {
window.open(path); window.open(path);
@ -313,7 +321,7 @@ export default {
return; return;
} }
}, },
renderMd (files, path) { renderMd(files, path) {
var cmd = this.$route.params.cmd; var cmd = this.$route.params.cmd;
if (cmd) { if (cmd) {
return; return;
@ -337,7 +345,7 @@ export default {
} }
}); });
}, },
goSearchResult (file, target) { goSearchResult(file, target) {
this.loading = true; this.loading = true;
let id = this.$route.params.id; let id = this.$route.params.id;
this.axios this.axios
@ -355,7 +363,7 @@ export default {
console.log(e); console.log(e);
}); });
}, },
getIcon (type) { getIcon(type) {
return "#" + (this.icon[type] ? this.icon[type] : "icon-file"); return "#" + (this.icon[type] ? this.icon[type] : "icon-file");
}, },
}, },