2023-04-19 20:16:22 +08:00
|
|
|
<template>
|
2023-05-09 20:53:50 +08:00
|
|
|
<div class="w-[216px] h-full border rounded bg-sn-white flex flex-col right-0 absolute navigator-container">
|
2023-04-19 20:16:22 +08:00
|
|
|
<div class="p-3 flex items-center">
|
2023-05-08 05:52:05 +08:00
|
|
|
<i class="fas fa-bars cursor-pointer"></i>
|
|
|
|
<div class="font-bold text-base p-2">
|
2023-04-19 20:16:22 +08:00
|
|
|
{{ i18n.t('navigator.title') }}
|
|
|
|
</div>
|
|
|
|
<i @click="$emit('navigator:colapse')" class="fas fa-times ml-auto cursor-pointer"></i>
|
|
|
|
</div>
|
2023-05-08 05:52:05 +08:00
|
|
|
<perfect-scrollbar class="grow py-4 relative">
|
2023-04-25 18:30:45 +08:00
|
|
|
<NavigatorItem v-for="item in sortedMenuItems"
|
|
|
|
:key="item.id"
|
|
|
|
:currentItemId="currentItemId"
|
|
|
|
:item="item"
|
2023-04-26 16:24:50 +08:00
|
|
|
:reloadCurrentLevel="reloadCurrentLevel"
|
|
|
|
:reloadChildrenLevel="reloadChildrenLevel"
|
2023-04-25 18:30:45 +08:00
|
|
|
:archived="archived" />
|
2023-04-21 21:25:52 +08:00
|
|
|
</perfect-scrollbar>
|
2023-04-19 20:16:22 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import NavigatorItem from './navigator_item.vue'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name : 'NavigatorContainer',
|
|
|
|
components: {
|
|
|
|
NavigatorItem
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
menuItems: [],
|
2023-04-21 21:25:52 +08:00
|
|
|
navigatorCollapsed: false,
|
|
|
|
navigatorUrl: null,
|
2023-04-25 18:30:45 +08:00
|
|
|
currentItemId: null,
|
|
|
|
archived: null
|
2023-04-19 20:16:22 +08:00
|
|
|
}
|
|
|
|
},
|
2023-04-26 16:24:50 +08:00
|
|
|
props: {
|
|
|
|
reloadCurrentLevel: Boolean,
|
|
|
|
reloadChildrenLevel: Boolean
|
|
|
|
},
|
2023-04-19 20:16:22 +08:00
|
|
|
computed: {
|
|
|
|
sortedMenuItems() {
|
2023-04-26 16:24:50 +08:00
|
|
|
return this.menuItems.sort((a, b) => {
|
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
2023-04-19 20:16:22 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
2023-04-21 21:25:52 +08:00
|
|
|
this.changePage();
|
|
|
|
|
|
|
|
$(document).on('turbolinks:load', () => {
|
|
|
|
this.changePage();
|
|
|
|
if ($(`[navigator-item-id="${this.currentItemId}"]`).length === 0) {
|
|
|
|
this.loadTree();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2023-04-25 18:30:45 +08:00
|
|
|
watch: {
|
|
|
|
archived() {
|
|
|
|
this.loadTree();
|
2023-04-26 16:24:50 +08:00
|
|
|
},
|
|
|
|
reloadCurrentLevel: function() {
|
|
|
|
if (this.reloadCurrentLevel && (
|
|
|
|
this.currentItemId.length == 0 ||
|
|
|
|
this.menuItems.filter(item => item.id == this.currentItemId)
|
|
|
|
)) {
|
|
|
|
this.loadTree();
|
|
|
|
}
|
2023-04-25 18:30:45 +08:00
|
|
|
}
|
|
|
|
},
|
2023-04-21 21:25:52 +08:00
|
|
|
methods: {
|
|
|
|
changePage() {
|
|
|
|
this.navigatorUrl = $('#active_navigator_url').val();
|
|
|
|
this.currentItemId = $('#active_navigator_item').val();
|
2023-04-25 18:30:45 +08:00
|
|
|
this.archived = $('#active_navigator_archived').val() === 'true';
|
2023-04-21 21:25:52 +08:00
|
|
|
},
|
|
|
|
loadTree() {
|
|
|
|
if (!this.navigatorUrl) return;
|
|
|
|
|
2023-04-25 18:30:45 +08:00
|
|
|
$.get(this.navigatorUrl, {archived: this.archived}, (data) => {
|
|
|
|
this.menuItems = [];
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.menuItems = data.items;
|
|
|
|
});
|
2023-04-21 21:25:52 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2023-04-19 20:16:22 +08:00
|
|
|
}
|
|
|
|
</script>
|