尝试修改loading组件解决加载问题

This commit is contained in:
Aicirou 2020-05-29 02:17:34 +08:00
parent edf690d5bd
commit 98fd18ede2
3 changed files with 64 additions and 67 deletions

5
package-lock.json generated
View File

@ -12533,6 +12533,11 @@
} }
} }
}, },
"vue-infinite-loading": {
"version": "2.4.5",
"resolved": "https://registry.npm.taobao.org/vue-infinite-loading/download/vue-infinite-loading-2.4.5.tgz",
"integrity": "sha1-zCD9QK9/IBiABkQ8mbYEcM8d4bM="
},
"vue-infinite-scroll": { "vue-infinite-scroll": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npm.taobao.org/vue-infinite-scroll/download/vue-infinite-scroll-2.0.2.tgz", "resolved": "https://registry.npm.taobao.org/vue-infinite-scroll/download/vue-infinite-scroll-2.0.2.tgz",

View File

@ -29,6 +29,7 @@
"vue-clipboard2": "^0.3.1", "vue-clipboard2": "^0.3.1",
"vue-codemirror": "^4.0.6", "vue-codemirror": "^4.0.6",
"vue-i18n": "^8.17.3", "vue-i18n": "^8.17.3",
"vue-infinite-loading": "^2.4.5",
"vue-infinite-scroll": "^2.0.2", "vue-infinite-scroll": "^2.0.2",
"vue-lazyload": "^1.3.3", "vue-lazyload": "^1.3.3",
"vue-router": "^3.1.6", "vue-router": "^3.1.6",

View File

@ -1,15 +1,9 @@
<template> <template>
<div> <div>
<headmd :option="headmd" v-if="renderHeadMD && headmd.display"></headmd> <headmd :option="headmd" v-if="renderHeadMD && headmd.display"></headmd>
<div <div class="golist">
class="golist"
v-loading="loading"
v-infinite-scroll="pageLoad"
infinite-scroll-disabled="busy"
infinite-scroll-distance="10"
>
<list-view <list-view
:data="buildFiles" :data="files"
v-if="mode === 'list'" v-if="mode === 'list'"
:icons="getIcon" :icons="getIcon"
:action="action" :action="action"
@ -17,21 +11,21 @@
/> />
<grid-view <grid-view
class="g2-content" class="g2-content"
:data="buildFiles" :data="files"
v-if="mode !== 'list'" v-if="mode !== 'list'"
:getIcon="getIcon" :getIcon="getIcon"
:action="action" :action="action"
:thum="thum" :thum="thum"
/> />
<infinite-loading
:identifier="infiniteId"
@infinite="infiniteHandler"
></infinite-loading>
<div <div
v-show="files.length === 0" v-show="files.length === 0"
class="has-text-centered no-content" class="has-text-centered no-content"
></div> ></div>
<center> <center>
<div :class="!busy ? 'is-hidden' : ''">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
<!-- <span v-if="page.page_token === null && files.length !== 0" class="tag"> <!-- <span v-if="page.page_token === null && files.length !== 0" class="tag">
{{ $t("list.total") }} {{ files.length }} {{ $t("list.item") }} {{ $t("list.total") }} {{ files.length }} {{ $t("list.item") }}
</span>--> </span>-->
@ -78,12 +72,14 @@ import {
} from "@utils/AcrouUtil"; } from "@utils/AcrouUtil";
import axios from "@/utils/axios"; import axios from "@/utils/axios";
import { mapState } from "vuex"; import { mapState } from "vuex";
import InfiniteLoading from "vue-infinite-loading";
import ListView from "./components/list"; import ListView from "./components/list";
import GridView from "./components/grid"; import GridView from "./components/grid";
import Markdown from "../common/Markdown"; import Markdown from "../common/Markdown";
export default { export default {
name: "GoList", name: "GoList",
components: { components: {
InfiniteLoading,
ListView, ListView,
GridView, GridView,
Headmd: Markdown, Headmd: Markdown,
@ -91,13 +87,12 @@ export default {
}, },
data: function() { data: function() {
return { return {
busy: false, infiniteId: +new Date(),
page: { page: {
page_token: null, page_token: null,
page_index: 0, page_index: 0,
}, },
files: [], files: [],
loading: true,
viewer: false, viewer: false,
icon: { icon: {
"application/vnd.google-apps.folder": "icon-morenwenjianjia", "application/vnd.google-apps.folder": "icon-morenwenjianjia",
@ -130,28 +125,6 @@ export default {
}, },
computed: { computed: {
...mapState("acrou/view", ["mode"]), ...mapState("acrou/view", ["mode"]),
buildFiles() {
var path = this.$route.path;
return this.files
.map((item) => {
var p = path + checkoutPath(item.name, item);
let isFolder = item.mimeType === "application/vnd.google-apps.folder";
let size = isFolder ? "-" : formatFileSize(item.size);
return {
path: p,
...item,
modifiedTime: formatDate(item.modifiedTime),
size: size,
isFolder: isFolder,
};
})
.sort((a, b) => {
if (a.isFolder && b.isFolder) {
return 0;
}
return a.isFolder ? -1 : 1;
});
},
images() { images() {
return this.buildFiles.filter( return this.buildFiles.filter(
(file) => file.mimeType.indexOf("image") != -1 (file) => file.mimeType.indexOf("image") != -1
@ -164,21 +137,14 @@ export default {
return window.themeOptions.render.readme_md || false; return window.themeOptions.render.readme_md || false;
}, },
}, },
created() {
this.render();
},
methods: { methods: {
pageLoad() { infiniteHandler($state) {
if (!this.page.page_token) return; // TODO
this.page.page_index++; this.page.page_index++;
this.render("scroll"); console.log("滚动加载了", this.page.page_index, this.$route.path);
this.render($state);
}, },
render(scroll) { render($state) {
if (scroll) {
this.busy = true;
} else {
this.loading = true;
}
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;
@ -205,26 +171,51 @@ export default {
page_token: body.nextPageToken, page_token: body.nextPageToken,
page_index: body.curPageIndex, page_index: body.curPageIndex,
}; };
try { if (scroll) {
if (scroll) { this.files = this.buildFiles(this.files.concat(data.files));
this.files = this.files.concat(data.files); } else {
} else { this.files = this.buildFiles(data.files);
this.files = data.files; }
} if (data.files) {
this.renderMd(data.files, path); this.renderMd(data.files, path);
} catch (e) {
console.log(e);
} }
} }
this.loading = false; if (body.nextPageToken) {
this.busy = false; $state.loaded();
} else {
$state.complete();
}
}) })
.catch(() => { .catch((e) => {
this.loading = false; $state.loaded();
this.busy = false; console.log(e);
this.$router.go(-1);
}); });
}, },
buildFiles(files) {
var path = this.$route.path;
return !files
? []
: files
.map((item) => {
var p = path + checkoutPath(item.name, item);
let isFolder =
item.mimeType === "application/vnd.google-apps.folder";
let size = isFolder ? "-" : formatFileSize(item.size);
return {
path: p,
...item,
modifiedTime: formatDate(item.modifiedTime),
size: size,
isFolder: isFolder,
};
})
.sort((a, b) => {
if (a.isFolder && b.isFolder) {
return 0;
}
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);
@ -236,7 +227,7 @@ export default {
}, },
copy(path) { copy(path) {
let origin = window.location.origin; let origin = window.location.origin;
console.log(path) console.log(path);
path = origin + encodeURI(path); path = origin + encodeURI(path);
this.$copyText(path) this.$copyText(path)
.then(() => { .then(() => {
@ -282,11 +273,11 @@ export default {
return; return;
} }
if (target === "copy") { if (target === "copy") {
this.copy(path) this.copy(path);
return; return;
} }
if (target === "down" || (!checkExtends(path) && !file.isFolder)) { if (target === "down" || (!checkExtends(path) && !file.isFolder)) {
location.href = path.replace(/^\/(\d+:)\//,"/$1down/"); location.href = path.replace(/^\/(\d+:)\//, "/$1down/");
return; return;
} }
if (target === "view") { if (target === "view") {
@ -336,7 +327,7 @@ export default {
let data = res.data; let data = res.data;
if (data) { if (data) {
file.path = `/${id}:${data}`; file.path = `/${id}:${data}`;
this.target(file, target) this.target(file, target);
} }
}) })
.catch((e) => { .catch((e) => {