🐛 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,12 +15,14 @@
</template> </template>
<script> <script>
import util from '@/libs/util' import { mapActions } from "vuex";
import util from "@/libs/util";
export default { export default {
data() { data() {
return {}; return {};
}, },
methods: { methods: {
...mapActions("acrou/db", ["databaseClear"]),
cleanCache() { cleanCache() {
new Promise((resolve) => { new Promise((resolve) => {
Object.keys(localStorage).forEach((item) => { Object.keys(localStorage).forEach((item) => {
@ -28,7 +30,8 @@ export default {
localStorage.removeItem(item); localStorage.removeItem(item);
} }
}); });
util.cookies.remove("lang") util.cookies.remove("lang");
this.databaseClear();
resolve(); resolve();
}).then(() => { }).then(() => {
this.$notify({ this.$notify({

View File

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

View File

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

View File

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