🐛 Fix text cache content not refreshing

This commit is contained in:
Aicirou 2020-08-28 23:53:07 +08:00
parent 398483e864
commit a014e81b77
4 changed files with 40 additions and 23 deletions

View File

@ -15,20 +15,23 @@
</template>
<script>
import util from '@/libs/util'
import { mapActions } from "vuex";
import util from "@/libs/util";
export default {
data () {
data() {
return {};
},
methods: {
cleanCache () {
...mapActions("acrou/db", ["databaseClear"]),
cleanCache() {
new Promise((resolve) => {
Object.keys(localStorage).forEach((item) => {
if (item.indexOf("file_path_") !== -1) {
localStorage.removeItem(item);
}
});
util.cookies.remove("lang")
util.cookies.remove("lang");
this.databaseClear();
resolve();
}).then(() => {
this.$notify({

View File

@ -88,11 +88,10 @@ export const decode64 = (str) => {
return Base64.decode(str);
};
export function get_file(option, callback) {
var path = option.path;
var modifiedTime = option.file.modifiedTime;
export function get_file({ path, file }, callback) {
var modifiedTime = file ? file.modifiedTime : null;
var key = "file_path_" + path + modifiedTime;
var data = localStorage.getItem(key);
var data = modifiedTime ? localStorage.getItem(key) : null;
if (data) {
return callback(data);
} else {

View File

@ -161,6 +161,7 @@ export default {
},
methods: {
...mapActions("acrou/aplayer", ["add"]),
...mapActions("acrou/db", ["set"]),
infiniteHandler($state) {
//
if (!this.page.page_token) {
@ -288,7 +289,7 @@ export default {
}
if (
file.mimeType.startsWith("audio/") &&
file.mimeType.indexOf("mpegurl")==-1 &&
file.mimeType.indexOf("mpegurl") == -1 &&
target === "view"
) {
if (window.aplayer) {
@ -321,8 +322,13 @@ export default {
return;
}
if (target === "view") {
let checkViewPath = checkView(path);
this.set({
path: `page.${checkViewPath}`,
value: file,
});
this.$router.push({
path: checkView(path),
path: checkViewPath,
});
return;
}

View File

@ -6,16 +6,8 @@
v-model="content"
:options="options"
/>
<markdown
v-if="ismd"
v-show="!isEdit"
:source="content"
/>
<a
v-if="ismd"
class="g2-content-edit is-hidden-mobile"
@click="edit"
>
<markdown v-if="ismd" v-show="!isEdit" :source="content" />
<a v-if="ismd" class="g2-content-edit is-hidden-mobile" @click="edit">
<i
:class="'fa' + (isEdit ? ' fa-eye' : ' fa-pencil-square-o')"
aria-hidden="true"
@ -25,6 +17,7 @@
</template>
<script>
import { mapActions } from "vuex";
import { get_file, decode64 } from "@utils/AcrouUtil";
import { codemirror } from "vue-codemirror";
@ -50,6 +43,12 @@ export default {
loaded: false,
};
},
beforeRouteEnter(to, from, next) {
if (from.path === "/") {
to.params.reload = true;
}
next();
},
activated() {
this.render();
},
@ -68,13 +67,23 @@ export default {
codemirror,
},
methods: {
render() {
...mapActions("acrou/db", ["get"]),
async render() {
let path = this.url;
this.content = `<center>
this.content = `<center>
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr-only">Loading...</span>
</center>`;
get_file({ path: path, file: {} }, (data) => {
let file;
let reload = this.$route.params.reload;
if (!reload) {
file = await this.get({
path: `page.${this.$route.fullPath}`,
});
}
get_file({ path: path, file }, (data) => {
this.content = data;
});
},