2023-04-19 20:16:22 +08:00
|
|
|
<template>
|
2023-11-09 02:32:43 +08:00
|
|
|
<Vue3DraggableResizable
|
|
|
|
:initW="getNavigatorWidth()"
|
2023-10-12 20:40:13 +08:00
|
|
|
ref="vueResizable"
|
2023-11-09 02:32:43 +08:00
|
|
|
:minW="208"
|
2023-11-20 23:28:43 +08:00
|
|
|
v-model:w="width"
|
2023-11-09 02:32:43 +08:00
|
|
|
:disabledH="true"
|
|
|
|
:handles="['mr']"
|
|
|
|
:resizable="true"
|
|
|
|
:draggable="false"
|
|
|
|
class="max-w-[400px] !h-full"
|
|
|
|
@resize-start="onResizeStart"
|
|
|
|
@resizing="onResizeMove"
|
|
|
|
@resize-end="onResizeEnd"
|
2023-10-12 20:40:13 +08:00
|
|
|
>
|
2023-11-20 23:28:43 +08:00
|
|
|
<div class="ml-4 h-full w-[calc(100%_-_1rem)] border rounded bg-sn-white flex flex-col right-0 absolute navigator-container">
|
2023-10-12 20:40:13 +08:00
|
|
|
<div class="px-3 py-2.5 flex items-center relative leading-4">
|
|
|
|
<i class="sn-icon sn-icon-navigator"></i>
|
|
|
|
<div class="font-bold text-base pl-3">
|
|
|
|
{{ i18n.t('navigator.title') }}
|
|
|
|
</div>
|
|
|
|
<i @click="$emit('navigator:colapse')" class="sn-icon sn-icon-close ml-auto cursor-pointer absolute right-2.5 top-2.5"></i>
|
2023-04-19 20:16:22 +08:00
|
|
|
</div>
|
2023-11-20 23:28:43 +08:00
|
|
|
<perfect-scrollbar @ps-scroll-y="onScrollY" @ps-scroll-x="onScrollX" ref="scrollContainer" class="grow py-2 relative px-2 scroll-container w-[calc(100%_-_.25rem)]">
|
2023-10-12 20:40:13 +08:00
|
|
|
<NavigatorItem v-for="item in sortedMenuItems"
|
|
|
|
:key="item.id"
|
|
|
|
:currentItemId="currentItemId"
|
|
|
|
:item="item"
|
|
|
|
:firstLevel="true"
|
|
|
|
:reloadCurrentLevel="reloadCurrentLevel"
|
|
|
|
:paddingLeft="0"
|
|
|
|
:reloadChildrenLevel="reloadChildrenLevel"
|
|
|
|
:archived="archived" />
|
|
|
|
</perfect-scrollbar>
|
2023-04-19 20:16:22 +08:00
|
|
|
</div>
|
2023-11-09 02:32:43 +08:00
|
|
|
</Vue3DraggableResizable>
|
2023-04-19 20:16:22 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import NavigatorItem from './navigator_item.vue'
|
2023-10-12 20:40:13 +08:00
|
|
|
import axios from '../../packs/custom_axios.js';
|
2023-11-09 02:32:43 +08:00
|
|
|
import Vue3DraggableResizable from 'vue3-draggable-resizable'
|
2023-04-19 20:16:22 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name : 'NavigatorContainer',
|
|
|
|
components: {
|
2023-10-12 20:40:13 +08:00
|
|
|
NavigatorItem,
|
2023-11-09 02:32:43 +08:00
|
|
|
Vue3DraggableResizable
|
2023-04-19 20:16:22 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
menuItems: [],
|
2023-04-21 21:25:52 +08:00
|
|
|
navigatorCollapsed: false,
|
|
|
|
navigatorUrl: null,
|
2023-05-19 17:46:36 +08:00
|
|
|
navigatorYScroll: 0,
|
2023-05-31 18:39:20 +08:00
|
|
|
navigatorXScroll: 0,
|
2023-04-25 18:30:45 +08:00
|
|
|
currentItemId: null,
|
2023-11-09 02:32:43 +08:00
|
|
|
archived: null,
|
2023-11-20 23:28:43 +08:00
|
|
|
width: 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) => {
|
2023-05-11 18:38:54 +08:00
|
|
|
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
2023-04-26 16:24:50 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-11 18:38:54 +08:00
|
|
|
if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
2023-04-26 16:24:50 +08:00
|
|
|
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', () => {
|
2023-05-19 17:46:36 +08:00
|
|
|
this.$refs.scrollContainer.$el.scrollTop = this.navigatorYScroll;
|
2023-05-31 18:39:20 +08:00
|
|
|
this.$refs.scrollContainer.$el.scrollLeft = this.navigatorXScroll;
|
|
|
|
|
2023-04-21 21:25:52 +08:00
|
|
|
this.changePage();
|
|
|
|
if ($(`[navigator-item-id="${this.currentItemId}"]`).length === 0) {
|
|
|
|
this.loadTree();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2023-10-12 20:40:13 +08:00
|
|
|
mounted() {
|
|
|
|
this.$refs.vueResizable.style.width = this.getNavigatorWidth()
|
|
|
|
},
|
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 && (
|
2023-12-15 17:42:30 +08:00
|
|
|
this.currentItemId?.length === 0
|
|
|
|
|| this.menuItems.filter((item) => item.id === this.currentItemId)
|
|
|
|
)) {
|
2023-04-26 16:24:50 +08:00
|
|
|
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
|
|
|
},
|
2023-10-12 20:40:13 +08:00
|
|
|
async loadTree() {
|
2023-04-21 21:25:52 +08:00
|
|
|
if (!this.navigatorUrl) return;
|
|
|
|
|
2023-10-12 20:40:13 +08:00
|
|
|
try {
|
|
|
|
const { data } = await axios.get(this.navigatorUrl, {
|
|
|
|
params: { archived: this.archived }
|
2023-04-25 18:30:45 +08:00
|
|
|
});
|
2023-10-12 20:40:13 +08:00
|
|
|
this.menuItems = data.items;
|
|
|
|
} catch (error) {
|
|
|
|
console.error('An error occurred while fetching the data', error);
|
|
|
|
}
|
2023-05-19 17:46:36 +08:00
|
|
|
},
|
2023-05-31 18:39:20 +08:00
|
|
|
onScrollY({target}) {
|
2023-05-19 17:46:36 +08:00
|
|
|
this.navigatorYScroll = target.scrollTop;
|
|
|
|
},
|
2023-05-31 18:39:20 +08:00
|
|
|
onScrollX({target}) {
|
|
|
|
this.navigatorXScroll = target.scrollLeft;
|
2023-10-12 20:40:13 +08:00
|
|
|
},
|
|
|
|
getNavigatorWidth() {
|
|
|
|
const computedStyle = getComputedStyle(document.documentElement);
|
2023-11-09 02:32:43 +08:00
|
|
|
return parseInt(computedStyle.getPropertyValue('--navigator-navigation-width').trim());
|
2023-10-12 20:40:13 +08:00
|
|
|
},
|
|
|
|
onResizeMove(event) {
|
2023-11-09 02:32:43 +08:00
|
|
|
if (event.w > 400) event.w = 400;
|
|
|
|
document.documentElement.style.setProperty('--navigator-navigation-width', event.w + 'px');
|
2023-10-12 20:40:13 +08:00
|
|
|
},
|
|
|
|
onResizeStart() {
|
|
|
|
document.body.style.cursor = 'url(/images/icon_small/Resize.svg) 0 0, auto';
|
2023-10-19 21:39:56 +08:00
|
|
|
$('.sci--layout-navigation-navigator').addClass('!transition-none');
|
|
|
|
$('.sci--layout').addClass('!transition-none');
|
2023-10-12 20:40:13 +08:00
|
|
|
},
|
|
|
|
onResizeEnd(event) {
|
2023-11-20 23:28:43 +08:00
|
|
|
if (event.w > 400) {
|
|
|
|
event.w = 400;
|
|
|
|
this.width = 400;
|
|
|
|
}
|
2023-10-12 20:40:13 +08:00
|
|
|
document.body.style.cursor = 'default';
|
2023-10-19 21:39:56 +08:00
|
|
|
$('.sci--layout-navigation-navigator').removeClass('!transition-none');
|
|
|
|
$('.sci--layout').removeClass('!transition-none');
|
2023-11-09 02:32:43 +08:00
|
|
|
this.changeNavigatorState(event.w)
|
2023-10-12 20:40:13 +08:00
|
|
|
},
|
|
|
|
async changeNavigatorState(newWidth) {
|
|
|
|
try {
|
|
|
|
const navigatorContainer = document.getElementById('sciNavigationNavigatorContainer');
|
|
|
|
const stateUrl = navigatorContainer.getAttribute('data-navigator-state-url');
|
|
|
|
await axios.post(stateUrl, { width: newWidth });
|
|
|
|
} catch (error) {
|
|
|
|
console.error('An error occurred while sending the request', error);
|
|
|
|
}
|
2023-05-31 18:39:20 +08:00
|
|
|
}
|
2023-04-21 21:25:52 +08:00
|
|
|
},
|
2023-04-19 20:16:22 +08:00
|
|
|
}
|
|
|
|
</script>
|