Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deot committed Jan 14, 2020
1 parent 4dbc639 commit 64d6446
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
19 changes: 14 additions & 5 deletions client/src/components/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</template>

<script>
import { Message } from '@wya/vc';
import { ajax } from '@wya/http';
import md from '../extends/md';
Expand Down Expand Up @@ -47,6 +48,7 @@ export default {
immediate: true,
handler(v, oldV) {
this.loadData();
document.documentElement.scrollTop = 0;
}
}
},
Expand All @@ -70,27 +72,34 @@ export default {
let data;
if (!__DEV__) {
if (__DEV__) {
try {
data = (await this.$global.db.read(url) || {}).data;
} catch (e) {
console.log(e);
}
}
let errorMsg = '请刷新后再试试';
ajax({
url,
debug: true,
localData: data,
onAfter: ({ response }) => {
return {
status: 1,
data: response.data || '请刷新后再试试'
data: response.data || errorMsg
};
},
onLoading: () => {
Message.loading('数据加载中...');
},
onLoaded: () => {
Message.destroy();
}
}).then((res) => {
this.content = res.data;
!__DEV__ && this.$global.db.update({
__DEV__ && res.data !== errorMsg && this.$global.db.update({
__id: url,
data: res,
});
Expand All @@ -112,7 +121,7 @@ export default {
</script>

<style lang="scss">
@include block(md-content) {
@include block(v-layout-content) {
min-height: 600px;
}
</style>
9 changes: 7 additions & 2 deletions client/src/components/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ export default {
},
handleClear() {
this.$global.db.deleteDatabase();
Message.success('缓存清理成功');
return this.$global.db.deleteDatabase().then((e) => {
Message.success('缓存清理成功');
}).catch(e => {
Message.success('缓存清理失败');
console.log(e);
});
}
}
};
Expand Down
29 changes: 17 additions & 12 deletions client/src/utils/cache/indexed-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@ export default class IndexedDB {

// 删库
deleteDatabase() {
const { name, version } = this.defaultOptions;
window.indexedDB.deleteDatabase(name, version);
return new Promise((resolve, reject) => {
const { name, version } = this.defaultOptions;
let request = window.indexedDB.deleteDatabase(name, version);

request.onsuccess = resolve;
request.onerror = reject;
});
}

// 删表
deleteObjecteStore(storeName = 'default-store') {
const { name, version } = this.defaultOptions;
return new Promise((resolve) => {
let request = window.indexedDB.open(name, version);
request.onsuccess = e => {
let db = e.target.result;
db.deleteObjecteStore(storeName);
resolve();
};
request.onerror = () => reject('数据库打开报错');
deleteObjectStore(storeName = 'default-store') {
return new Promise((resolve, reject) => {
this.open()
.then(db => {
db.deleteObjectStore(storeName);
resolve();
}).catch((e) => {
console.error(e);
reject(e);
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wya/doc",
"version": "1.0.0",
"version": "1.0.1",
"description": "wya-doc for js",
"main": "index.js",
"files": [
Expand Down

0 comments on commit 64d6446

Please sign in to comment.