解决搜索结果无法预览的文件不能直接下载的问题 #30

This commit is contained in:
Aicirou 2020-05-29 00:11:00 +08:00
parent 4c9e33ce36
commit edf690d5bd
3 changed files with 30 additions and 31 deletions

View File

@ -12,7 +12,7 @@
:data="buildFiles" :data="buildFiles"
v-if="mode === 'list'" v-if="mode === 'list'"
:icons="getIcon" :icons="getIcon"
:go="go" :action="action"
:copy="copy" :copy="copy"
/> />
<grid-view <grid-view
@ -20,7 +20,7 @@
:data="buildFiles" :data="buildFiles"
v-if="mode !== 'list'" v-if="mode !== 'list'"
:getIcon="getIcon" :getIcon="getIcon"
:go="go" :action="action"
:thum="thum" :thum="thum"
/> />
<div <div
@ -43,7 +43,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"
@ -72,7 +75,6 @@ import {
checkoutPath, checkoutPath,
checkView, checkView,
checkExtends, checkExtends,
encodePath
} from "@utils/AcrouUtil"; } from "@utils/AcrouUtil";
import axios from "@/utils/axios"; import axios from "@/utils/axios";
import { mapState } from "vuex"; import { mapState } from "vuex";
@ -234,6 +236,7 @@ export default {
}, },
copy(path) { copy(path) {
let origin = window.location.origin; let origin = window.location.origin;
console.log(path)
path = origin + encodeURI(path); path = origin + encodeURI(path);
this.$copyText(path) this.$copyText(path)
.then(() => { .then(() => {
@ -256,7 +259,7 @@ export default {
inited(viewer) { inited(viewer) {
this.$viewer = viewer; this.$viewer = viewer;
}, },
go(file, target) { action(file, target) {
if (file.mimeType.indexOf("image") != -1) { if (file.mimeType.indexOf("image") != -1) {
this.viewer = true; this.viewer = true;
this.$nextTick(() => { this.$nextTick(() => {
@ -265,19 +268,25 @@ export default {
}); });
return; return;
} }
let path = file.path;
let cmd = this.$route.params.cmd; let cmd = this.$route.params.cmd;
if (cmd && cmd === "search") { if (cmd && cmd === "search") {
this.goSearchResult(file, target); this.goSearchResult(file, target);
return; return;
} }
this.target(file, target);
},
target(file, target) {
let path = file.path;
if (target === "_blank") { if (target === "_blank") {
window.open(path); window.open(path);
return; return;
} }
if (target === "copy") {
this.copy(path)
return;
}
if (target === "down" || (!checkExtends(path) && !file.isFolder)) { if (target === "down" || (!checkExtends(path) && !file.isFolder)) {
let temp_path = this.$route.params.path ? this.$route.params.path : ""; location.href = path.replace(/^\/(\d+:)\//,"/$1down/");
location.href = `/${this.$route.params.id}:down/${temp_path}/${encodePath(file.name)}`;
return; return;
} }
if (target === "view") { if (target === "view") {
@ -319,22 +328,15 @@ export default {
}, },
goSearchResult(file, target) { goSearchResult(file, target) {
this.loading = true; this.loading = true;
let cur = window.current_drive_order; let id = this.$route.params.id;
axios axios
.post(`/${cur}:id2path`, { id: file.id }) .post(`/${id}:id2path`, { id: file.id })
.then((res) => { .then((res) => {
this.loading = false; this.loading = false;
let data = res.data; let data = res.data;
if (data) { if (data) {
var href = checkoutPath(data, file); file.path = `/${id}:${data}`;
href = `/${cur}:${data}`; this.target(file, target)
if (target === "_blank") {
window.open(href);
} else {
this.$router.push({
path: checkView(href),
});
}
} }
}) })
.catch((e) => { .catch((e) => {

View File

@ -5,7 +5,7 @@
class="column is-one-quarter" class="column is-one-quarter"
v-for="(file, index) in folders" v-for="(file, index) in folders"
:key="'folder_' + index" :key="'folder_' + index"
@click="go(file)" @click="action(file)"
> >
<div class="card g2-grid-view-card g2-grid-view-folder"> <div class="card g2-grid-view-card g2-grid-view-folder">
<div class="media"> <div class="media">
@ -24,7 +24,7 @@
class="column is-one-quarter" class="column is-one-quarter"
v-for="(file, index) in files" v-for="(file, index) in files"
:key="'file_' + index" :key="'file_' + index"
@click="go(file, 'view')" @click="action(file, 'view')"
> >
<div class="card g2-grid-view-card"> <div class="card g2-grid-view-card">
<div <div
@ -65,7 +65,7 @@ export default {
getIcon: { getIcon: {
type: Function, type: Function,
}, },
go: { action: {
type: Function, type: Function,
}, },
thum: { thum: {

View File

@ -20,7 +20,7 @@
<tr v-for="(file, index) in data" v-bind:key="index"> <tr v-for="(file, index) in data" v-bind:key="index">
<td <td
@click.self=" @click.self="
go( action(
file, file,
file.mimeType !== 'application/vnd.google-apps.folder' file.mimeType !== 'application/vnd.google-apps.folder'
? 'view' ? 'view'
@ -43,14 +43,14 @@
</td> </td>
<td class="is-hidden-mobile is-hidden-touch">{{ file.size }}</td> <td class="is-hidden-mobile is-hidden-touch">{{ file.size }}</td>
<td class="is-hidden-mobile is-hidden-touch"> <td class="is-hidden-mobile is-hidden-touch">
<span class="icon" @click.stop="copy(file.path)"> <span class="icon" @click.stop="action(file,'copy')">
<i <i
class="fa fa-copy faa-shake animated-hover" class="fa fa-copy faa-shake animated-hover"
:title="$t('list.opt.copy')" :title="$t('list.opt.copy')"
aria-hidden="true" aria-hidden="true"
></i> ></i>
</span> </span>
<span class="icon" @click.stop="go(file, '_blank')"> <span class="icon" @click.stop="action(file, '_blank')">
<i <i
class="fa fa-external-link faa-shake animated-hover" class="fa fa-external-link faa-shake animated-hover"
:title="$t('list.opt.newTab')" :title="$t('list.opt.newTab')"
@ -59,7 +59,7 @@
</span> </span>
<span <span
class="icon" class="icon"
@click.stop="go(file, 'down')" @click.stop="action(file, 'down')"
v-if="file.mimeType !== 'application/vnd.google-apps.folder'" v-if="file.mimeType !== 'application/vnd.google-apps.folder'"
> >
<i <i
@ -83,12 +83,9 @@ export default {
icons: { icons: {
type: Function, type: Function,
}, },
go: { action: {
type: Function, type: Function,
}, }
copy: {
type: Function,
},
}, },
computed: { computed: {
columns() { columns() {