diff --git a/package-lock.json b/package-lock.json index 05c8dbe..2c20f22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,8 @@ "tailwindcss": "^3.2.4", "vue": "^3.2.45", "vue-axios": "^3.5.2", - "vue-router": "^4.1.6" + "vue-router": "^4.1.6", + "vue-toast-notification": "^3.0.4" }, "devDependencies": { "@rushstack/eslint-patch": "^1.1.4", @@ -5901,6 +5902,17 @@ "vue": "^3.2.0" } }, + "node_modules/vue-toast-notification": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/vue-toast-notification/-/vue-toast-notification-3.0.4.tgz", + "integrity": "sha512-rEhLtcKg8SVdBpdN7PrNst5nmY8dw0j3NkNImqurhlGurqR/QDKoou0t2PuCReEOCTKqHvfLCle2I3kwQWDWDQ==", + "engines": { + "node": ">=12.15.0" + }, + "peerDependencies": { + "vue": "^3.0" + } + }, "node_modules/w3c-xmlserializer": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz", @@ -10431,6 +10443,12 @@ "@vue/devtools-api": "^6.4.5" } }, + "vue-toast-notification": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/vue-toast-notification/-/vue-toast-notification-3.0.4.tgz", + "integrity": "sha512-rEhLtcKg8SVdBpdN7PrNst5nmY8dw0j3NkNImqurhlGurqR/QDKoou0t2PuCReEOCTKqHvfLCle2I3kwQWDWDQ==", + "requires": {} + }, "w3c-xmlserializer": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz", diff --git a/package.json b/package.json index 8d109f1..0d0fd86 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "tailwindcss": "^3.2.4", "vue": "^3.2.45", "vue-axios": "^3.5.2", - "vue-router": "^4.1.6" + "vue-router": "^4.1.6", + "vue-toast-notification": "^3.0.4" }, "devDependencies": { "@rushstack/eslint-patch": "^1.1.4", diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index c654912..fe030ee 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -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; } diff --git a/src/main.js b/src/main.js index 4262ad2..6eb6595 100644 --- a/src/main.js +++ b/src/main.js @@ -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"); diff --git a/src/stores/files.js b/src/stores/files.js index 8115504..31e8fef 100644 --- a/src/stores/files.js +++ b/src/stores/files.js @@ -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.'); + }) }; }, } diff --git a/src/stores/main.js b/src/stores/main.js index 63280c1..609dfdb 100644 --- a/src/stores/main.js +++ b/src/stores/main.js @@ -1,3 +1,5 @@ import { createPinia } from 'pinia'; + const pinia = createPinia(); + export default pinia; diff --git a/src/views/Files/index.vue b/src/views/Files/index.vue index 0503189..c062872 100644 --- a/src/views/Files/index.vue +++ b/src/views/Files/index.vue @@ -47,7 +47,7 @@ Name - + @@ -115,7 +115,6 @@