Delay loading and toast 待æDone

This commit is contained in:
chiayin
2023-02-16 15:00:16 +08:00
parent 819199864d
commit a20c22dcae
7 changed files with 89 additions and 25 deletions

View File

@@ -47,7 +47,7 @@ export default {
// navViewName: {
// files: ['all', 'discover', 'compare', 'design'],
// },
navViewName: '',
// navViewName: '',
};
},
setup() {
@@ -65,9 +65,9 @@ export default {
this.showNavbarBreadcrumb = this.$route.matched[0].name !== ('AuthContainer')? true : false;
},
methods: {
switchNavView(name) {
this.navViewName = name;
},
// switchNavView(name) {
// this.navViewName = name;
// },
switchNavItem(event) {
this.store.filesTag = event.target.innerText;
}

View File

@@ -7,14 +7,18 @@ import axios from 'axios';
import VueAxios from 'vue-axios';
import moment from 'moment';
import mitt from 'mitt';
import ToastPlugin from 'vue-toast-notification';
import "./assets/main.css";
//import 'vue-toast-notification/dist/theme-default.css';
import 'vue-toast-notification/dist/theme-sugar.css';
const emitter = mitt();
const app = createApp(App);
pinia.use(({ store }) => {
store.$router = markRaw(router)
store.$toast = markRaw(ToastPlugin)
});
// can use `this.$moment` in Vue.js
@@ -23,5 +27,9 @@ app.config.globalProperties.emitter = emitter;
app.use(pinia);
app.use(router);
app.use(VueAxios, axios);
// use `this.$toast` in Vue.js
app.use(ToastPlugin, {
duration: 10000,
});
app.mount("#app");

View File

@@ -3,8 +3,13 @@ import loadingStore from './loading.js';
import pinia from '@/stores/main.js'
import axios from "axios";
import moment from 'moment';
import {useToast} from 'vue-toast-notification';
import 'vue-toast-notification/dist/theme-sugar.css';
const loading = loadingStore(pinia);
const $toast = useToast();
// Delay loading and toast 待模組化
let delay = s => new Promise((resolve, reject) => setTimeout(resolve, s));
export default defineStore('filesStore', {
state: () => ({
@@ -67,8 +72,16 @@ export default defineStore('filesStore', {
})
if(this.httpStatus < 300) loading.isLoading = false;
} catch(error) {
loading.isLoading = true;
this.httpStatus = error.request.status;
delay().then(() =>{
loading.isLoading = true;
return delay(1000);
}).then(()=>{
loading.isLoading = false;
return delay(500);
}).then(() => {
$toast.default('Import Filter files error.');
})
};
},
/**
@@ -88,8 +101,16 @@ export default defineStore('filesStore', {
});
if(this.httpStatus < 300) loading.isLoading = false;
} catch(error) {
loading.isLoading = true;
this.httpStatus = error.request.status;
delay().then(() =>{
loading.isLoading = true;
return delay(1000);
}).then(()=>{
loading.isLoading = false;
return delay(500);
}).then(() => {
$toast.default('Import Filter files error.');
})
};
},
}

View File

@@ -1,3 +1,5 @@
import { createPinia } from 'pinia';
const pinia = createPinia();
export default pinia;

View File

@@ -47,7 +47,7 @@
<tr>
<th>
Name
<span class="ml-2 cursor-pointer">
<span class="ml-2 cursor-pointer" @click="addSortEvent($event)">
<IconVector class="inline-block fill-neutral-500"></IconVector>
</span>
</th>
@@ -115,7 +115,6 @@
</template>
<script>
// import { storeToRefs } from 'pinia';
import filesStore from '@/stores/files.js';
import IconDataFormat from '@/components/icons/IconDataFormat.vue';
import IconRule from '@/components/icons/IconRule.vue';
@@ -130,6 +129,7 @@
return {
switchListOrGrid: false,
filesTag: 'all',
sortReverseOrder: false,
}
},
setup() {
@@ -152,7 +152,17 @@
/**
* Read allFiles
*/
allFiles: function() {
allFiles: function(value) {
// let sortFiles = this.store.allFiles;
// let nameSortOrder = sortFiles.sort((x, y)=> x.name.localeCompare(y.name, 'en'));
// let nameSortReverse = sortFiles.sort((x, y)=> y.name.localeCompare(x.name, 'en'));
// if(this.sortReverseOrder === false){
// return nameSortOrder;
// }
// else {
// return nameSortReverse;
// }
return this.store.allFiles;
},
// 時間排序,如果沒有 accessed_at 就不加入 data
@@ -171,35 +181,39 @@
// return sortFiles;
// }
},
watch: {
// allFiles: {
// handler: function(newVal, oldVal) {
// console.log(newVal);
// console.log(oldVal);
// },
// deep: true,
// },
},
methods: {
/**上下按鈕切換 */
// 順序預設為 true點擊變逆序 false每改一次都會重新渲染一次
addSortEvent(event) {
if(this.sortReverseOrder === false){
this.sortReverseOrder = true;
}else {
this.sortReverseOrder = false;
}
console.log(this.sortReverseOrder);
},
/**
* Sort Files item
*/
sortFiles(value) {
sortFiles(value) {
let sortFiles = this.store.allFiles;
let nameSort = sortFiles.sort((x, y)=> x.name.localeCompare(y.name, 'en'));
let updateSort = sortFiles.sort((x, y)=> x.updated_at - y.updated_at);
console.log(nameSort);
// if(sortFiles.length === undefined) return;
if(value === 'string') nameSort;
else if(value === 'date') updateSort;
console.log(sortFiles);
return sortFiles;
// if(value === 'string') nameSort;
// else if(value === 'date') updateSort;
// console.log(sortFiles);
// return sortFiles;
}
},
mounted() {
this.store.fetchEventLog();
this.store.fetchFilter();
// this.sortFiles();
// console.log(this.sortReverseOrder);
}
}