Files page Pinia Done
This commit is contained in:
11
package-lock.json
generated
11
package-lock.json
generated
@@ -10,6 +10,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"autoprefixer": "^10.4.13",
|
"autoprefixer": "^10.4.13",
|
||||||
"axios": "^1.2.2",
|
"axios": "^1.2.2",
|
||||||
|
"mitt": "^3.0.0",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"pinia": "^2.0.28",
|
"pinia": "^2.0.28",
|
||||||
"postcss": "^8.4.20",
|
"postcss": "^8.4.20",
|
||||||
@@ -4138,6 +4139,11 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/mitt": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ=="
|
||||||
|
},
|
||||||
"node_modules/moment": {
|
"node_modules/moment": {
|
||||||
"version": "2.29.4",
|
"version": "2.29.4",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||||
@@ -9243,6 +9249,11 @@
|
|||||||
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"mitt": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ=="
|
||||||
|
},
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.29.4",
|
"version": "2.29.4",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"autoprefixer": "^10.4.13",
|
"autoprefixer": "^10.4.13",
|
||||||
"axios": "^1.2.2",
|
"axios": "^1.2.2",
|
||||||
|
"mitt": "^3.0.0",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"pinia": "^2.0.28",
|
"pinia": "^2.0.28",
|
||||||
"postcss": "^8.4.20",
|
"postcss": "^8.4.20",
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
<div class="flex flex-1 items-center">
|
<div class="flex flex-1 items-center">
|
||||||
<h2 class="mr-28 text-2xl font-black text-neutral-10">FILES</h2>
|
<h2 class="mr-28 text-2xl font-black text-neutral-10">FILES</h2>
|
||||||
<ul class="flex justify-center items-center space-x-4 text-xl font-semibold text-neutral-300 cursor-pointer">
|
<ul class="flex justify-center items-center space-x-4 text-xl font-semibold text-neutral-300 cursor-pointer">
|
||||||
<li @click="changeViewType('all')">ALL</li>
|
<li @click="switchNavItem($event)">ALL</li>
|
||||||
<li @click="changeViewType('discover')">DISCOVER</li>
|
<li @click="switchNavItem($event)">DISCOVER</li>
|
||||||
<li @click="changeViewType('compare')">COMPARE</li>
|
<li @click="switchNavItem($event)">COMPARE</li>
|
||||||
<li @click="changeViewType('disign')">DESIGN</li>
|
<li @click="switchNavItem($event)">DESIGN</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end items-center">
|
<div class="flex justify-end items-center">
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import filesStore from '@/stores/files.js';
|
||||||
import IconSearch from '@/components/icons/IconSearch.vue';
|
import IconSearch from '@/components/icons/IconSearch.vue';
|
||||||
import IconSetting from '@/components/icons/IconSetting.vue';
|
import IconSetting from '@/components/icons/IconSetting.vue';
|
||||||
|
|
||||||
@@ -43,27 +44,34 @@ export default {
|
|||||||
return {
|
return {
|
||||||
showNavbarBreadcrumb: false,
|
showNavbarBreadcrumb: false,
|
||||||
// 之後優化要模組化
|
// 之後優化要模組化
|
||||||
// viewType:[
|
// navViewName: {
|
||||||
// {
|
// files: ['all', 'discover', 'compare', 'design'],
|
||||||
// typeName: '',
|
// },
|
||||||
// typeCategory: [],
|
navViewName: '',
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
viewType: ''
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
setup() {
|
||||||
|
const store = filesStore();
|
||||||
|
|
||||||
|
return {
|
||||||
|
store,
|
||||||
|
}
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
IconSearch,
|
IconSearch,
|
||||||
IconSetting
|
IconSetting,
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.showNavbarBreadcrumb = this.$route.matched[0].name !== ('AuthContainer')? true : false;
|
this.showNavbarBreadcrumb = this.$route.matched[0].name !== ('AuthContainer')? true : false;
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
changeViewType(type) {
|
switchNavView(name) {
|
||||||
this.viewType = type;
|
this.navViewName = name;
|
||||||
|
},
|
||||||
|
switchNavItem(event) {
|
||||||
|
this.store.filesTag = event.target.innerText;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import router from "./router";
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import VueAxios from 'vue-axios';
|
import VueAxios from 'vue-axios';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import mitt from 'mitt';
|
||||||
|
|
||||||
import "./assets/main.css";
|
import "./assets/main.css";
|
||||||
|
|
||||||
|
const emitter = mitt();
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
@@ -18,6 +20,7 @@ pinia.use(({ store }) => {
|
|||||||
|
|
||||||
// can use `this.$moment` in Vue.js
|
// can use `this.$moment` in Vue.js
|
||||||
app.config.globalProperties.$moment = moment;
|
app.config.globalProperties.$moment = moment;
|
||||||
|
app.config.globalProperties.emitter = emitter;
|
||||||
app.use(pinia);
|
app.use(pinia);
|
||||||
app.use(router);
|
app.use(router);
|
||||||
app.use(VueAxios, axios);
|
app.use(VueAxios, axios);
|
||||||
|
|||||||
85
src/stores/files.js
Normal file
85
src/stores/files.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
import axios from "axios";
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
export default defineStore('filesStore', {
|
||||||
|
state: () => ({
|
||||||
|
allFilter: [
|
||||||
|
{
|
||||||
|
log: {},
|
||||||
|
fileType: '',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
allEventLog: [
|
||||||
|
{
|
||||||
|
parentLog: '',
|
||||||
|
fileType: '',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
switchFilesTagData: {
|
||||||
|
ALL: ['Log', 'Filter', 'Rule', 'Design'],
|
||||||
|
DISCOVER: ['Log', 'Filter', 'Rule'],
|
||||||
|
COMPARE: ['Filter'],
|
||||||
|
DESIGN: ['Log', 'Design'],
|
||||||
|
},
|
||||||
|
filesTag: 'ALL',
|
||||||
|
}),
|
||||||
|
getters: {
|
||||||
|
/**
|
||||||
|
* Get allFiles and switch files tag
|
||||||
|
*/
|
||||||
|
allFiles: state => {
|
||||||
|
let result = [
|
||||||
|
...state.allEventLog,
|
||||||
|
...state.allFilter.map(itemFilter => {
|
||||||
|
return { ...itemFilter, parentLog: itemFilter.log.name }
|
||||||
|
})
|
||||||
|
];
|
||||||
|
let data = state.switchFilesTagData;
|
||||||
|
let filesTag = state.filesTag;
|
||||||
|
|
||||||
|
result = result.filter(file => data[filesTag].includes(file.fileType));
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
/**
|
||||||
|
* Fetch event logs api
|
||||||
|
*/
|
||||||
|
async fetchEventLog() {
|
||||||
|
const api = 'api/logs';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(api);
|
||||||
|
|
||||||
|
this.allEventLog = response.data;
|
||||||
|
this.allEventLog.map(o => {
|
||||||
|
o.parentLog = "-";
|
||||||
|
o.fileType = "Log";
|
||||||
|
o.updated_at = moment(o.updated_at).format('YYYY-MM-DD HH:MM');
|
||||||
|
o.accessed_at = moment(o.accessed_at).format('YYYY-MM-DD HH:MM');
|
||||||
|
return this.allEventLog
|
||||||
|
})
|
||||||
|
} catch(error) {
|
||||||
|
} finally {};
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Fetch filters api
|
||||||
|
*/
|
||||||
|
async fetchFilter() {
|
||||||
|
const api = 'api/filters';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(api);
|
||||||
|
|
||||||
|
this.allFilter = response.data;
|
||||||
|
this.allFilter.map(o => {
|
||||||
|
o.fileType = "Filter";
|
||||||
|
o.updated_at = moment(o.updated_at).format('YYYY-MM-DD HH:MM');
|
||||||
|
o.accessed_at = moment(o.accessed_at).format('YYYY-MM-DD HH:MM');
|
||||||
|
});
|
||||||
|
} catch(error) {
|
||||||
|
} finally {};
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<div class="py-4 mb-4 border-b flex justify-between items-center border-neutral-500">
|
<div class="py-4 mb-4 border-b flex justify-between items-center border-neutral-500">
|
||||||
<h2 class="font-bold" @click="filesTag = 'design'">All Files</h2>
|
<h2 class="font-bold">All Files</h2>
|
||||||
<ul class="flex items-center">
|
<ul class="flex items-center">
|
||||||
<li class="mr-4 cursor-pointer" @click="switchListOrGrid = false">
|
<li class="mr-4 cursor-pointer" @click="switchListOrGrid = false">
|
||||||
<IconList class="hover:fill-primary hover:bg-neutral-50 duration-300"></IconList>
|
<IconList class="hover:fill-primary hover:bg-neutral-50 duration-300"></IconList>
|
||||||
@@ -114,6 +114,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import filesStore from '@/stores/files.js';
|
||||||
import IconDataFormat from '@/components/icons/IconDataFormat.vue';
|
import IconDataFormat from '@/components/icons/IconDataFormat.vue';
|
||||||
import IconRule from '@/components/icons/IconRule.vue';
|
import IconRule from '@/components/icons/IconRule.vue';
|
||||||
import IconsFilter from '@/components/icons/IconsFilter.vue';
|
import IconsFilter from '@/components/icons/IconsFilter.vue';
|
||||||
@@ -125,29 +127,17 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
allFilter: [
|
|
||||||
{
|
|
||||||
log: {},
|
|
||||||
fileType: '',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
allEventLog: [
|
|
||||||
{
|
|
||||||
parentLog: '',
|
|
||||||
fileType: '',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
switchListOrGrid: false,
|
switchListOrGrid: false,
|
||||||
switchFilesTagData: {
|
|
||||||
all: ['Log', 'Filter', 'Rule', 'Design'],
|
|
||||||
discover: ['Log', 'Filter', 'Rule'],
|
|
||||||
compare: ['Filter'],
|
|
||||||
design: ['Log', 'Design'],
|
|
||||||
},
|
|
||||||
filesTag: 'all',
|
filesTag: 'all',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup() {},
|
setup() {
|
||||||
|
const store = filesStore();
|
||||||
|
|
||||||
|
return {
|
||||||
|
store,
|
||||||
|
}
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
IconDataFormat,
|
IconDataFormat,
|
||||||
IconRule,
|
IconRule,
|
||||||
@@ -155,25 +145,15 @@
|
|||||||
IconFlowChart,
|
IconFlowChart,
|
||||||
IconVector,
|
IconVector,
|
||||||
IconList,
|
IconList,
|
||||||
IconGrid
|
IconGrid,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
/**
|
/**
|
||||||
* Get allFiles and switch files tag
|
* Read allFiles
|
||||||
*/
|
*/
|
||||||
allFiles: function() {
|
allFiles: function() {
|
||||||
let result = [
|
return this.store.allFiles;
|
||||||
...this.allEventLog,
|
},
|
||||||
...this.allFilter.map(itemFilter => {
|
|
||||||
return { ...itemFilter, parentLog: itemFilter.log.name }
|
|
||||||
})
|
|
||||||
];
|
|
||||||
let data = this.switchFilesTagData;
|
|
||||||
let filesTag = this.filesTag;
|
|
||||||
|
|
||||||
result = result.filter(file => data[filesTag].includes(file.fileType));
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
// 時間排序,如果沒有 accessed_at 就不加入 data
|
// 時間排序,如果沒有 accessed_at 就不加入 data
|
||||||
recentlyUsedFiles: function() {
|
recentlyUsedFiles: function() {
|
||||||
let recentlyUsedFiles = this.allFiles.filter(item => item.accessed_at !== null);
|
let recentlyUsedFiles = this.allFiles.filter(item => item.accessed_at !== null);
|
||||||
@@ -181,51 +161,16 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
|
||||||
* Get all files
|
|
||||||
*/
|
|
||||||
async fetchFilter() {
|
|
||||||
const api = 'api/filters';
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.$http.get(api);
|
|
||||||
|
|
||||||
this.allFilter = response.data;
|
|
||||||
this.allFilter.map(o => {
|
|
||||||
o.fileType = "Filter";
|
|
||||||
o.updated_at = this.$moment(o.updated_at).format('YYYY-MM-DD HH:MM');
|
|
||||||
o.accessed_at = this.$moment(o.accessed_at).format('YYYY-MM-DD HH:MM');
|
|
||||||
});
|
|
||||||
} catch(error) {
|
|
||||||
} finally {};
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Get all event log
|
|
||||||
*/
|
|
||||||
async fetchEventLog() {
|
|
||||||
const api = 'api/logs';
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.$http.get(api);
|
|
||||||
|
|
||||||
this.allEventLog = response.data;
|
|
||||||
this.allEventLog.map(o => {
|
|
||||||
o.parentLog = "-";
|
|
||||||
o.fileType = "Log";
|
|
||||||
o.updated_at = this.$moment(o.updated_at).format('YYYY-MM-DD HH:MM');
|
|
||||||
o.accessed_at = this.$moment(o.accessed_at).format('YYYY-MM-DD HH:MM');
|
|
||||||
return this.allEventLog
|
|
||||||
})
|
|
||||||
} catch(error) {
|
|
||||||
};
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Sort Files item
|
* Sort Files item
|
||||||
*/
|
*/
|
||||||
|
switchFiles(item) {
|
||||||
|
this.filesTag = item
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.fetchFilter();
|
this.store.fetchEventLog();
|
||||||
this.fetchEventLog();
|
this.store.fetchFilter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ export default {
|
|||||||
return {
|
return {
|
||||||
isDisabled: true,
|
isDisabled: true,
|
||||||
showPassword: false,
|
showPassword: false,
|
||||||
name: 'hellow world'
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ export default {
|
|||||||
* check login for 'my-account' api
|
* check login for 'my-account' api
|
||||||
*/
|
*/
|
||||||
this.checkLogin();
|
this.checkLogin();
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user