tiny-rdm/frontend/src/AppContent.vue

256 lines
8.5 KiB
Vue
Raw Normal View History

<script setup>
import ContentPane from './components/content/ContentPane.vue'
import BrowserPane from './components/sidebar/BrowserPane.vue'
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { debounce, get } from 'lodash'
import { useThemeVars } from 'naive-ui'
import NavMenu from './components/sidebar/NavMenu.vue'
import ConnectionPane from './components/sidebar/ConnectionPane.vue'
import ContentServerPane from './components/content/ContentServerPane.vue'
import useTabStore from './stores/tab.js'
import usePreferencesStore from './stores/preferences.js'
import useConnectionStore from './stores/connections.js'
2023-07-16 01:50:01 +08:00
import ContentLogPane from './components/content/ContentLogPane.vue'
2023-09-02 18:23:40 +08:00
import ContentValueTab from '@/components/content/ContentValueTab.vue'
import ToolbarControlWidget from '@/components/common/ToolbarControlWidget.vue'
import { EventsOn, WindowIsFullscreen, WindowIsMaximised, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js'
2023-09-02 18:23:40 +08:00
import { isMacOS } from '@/utils/platform.js'
import iconUrl from '@/assets/images/icon.png'
import ResizeableWrapper from '@/components/common/ResizeableWrapper.vue'
import { extraTheme } from '@/utils/extra_theme.js'
const themeVars = useThemeVars()
const props = defineProps({
loading: Boolean,
})
const data = reactive({
navMenuWidth: 60,
2023-09-02 18:23:40 +08:00
toolbarHeight: 45,
})
const tabStore = useTabStore()
const prefStore = usePreferencesStore()
const connectionStore = useConnectionStore()
const logPaneRef = ref(null)
const exThemeVars = computed(() => {
return extraTheme(prefStore.isDark)
})
// const preferences = ref({})
// provide('preferences', preferences)
const saveSidebarWidth = debounce(prefStore.savePreferences, 1000, { trailing: true })
const handleResize = () => {
saveSidebarWidth()
}
watch(
() => tabStore.nav,
(nav) => {
if (nav === 'log') {
logPaneRef.value?.refresh()
}
},
)
const border = computed(() => {
return isMacOS() ? 'none' : `1px solid ${themeVars.value.borderColor}`
})
const logoWrapperWidth = computed(() => {
return `${data.navMenuWidth + prefStore.behavior.asideWidth - 4}px`
})
const borderRadius = ref(10)
const logoPaddingLeft = ref(10)
const maximised = ref(false)
const toggleWindowRadius = (on) => {
borderRadius.value = on ? 10 : 0
}
const onToggleFullscreen = (fullscreen) => {
if (fullscreen) {
logoPaddingLeft.value = 10
toggleWindowRadius(false)
} else {
logoPaddingLeft.value = isMacOS() ? 70 : 10
toggleWindowRadius(true)
}
}
const onToggleMaximize = (isMaximised) => {
if (isMaximised) {
maximised.value = true
if (!isMacOS()) {
toggleWindowRadius(false)
}
} else {
maximised.value = false
if (!isMacOS()) {
toggleWindowRadius(true)
}
}
}
EventsOn('window_changed', (info) => {
const { fullscreen, maximised } = info
onToggleFullscreen(fullscreen === true)
onToggleMaximize(maximised)
})
onMounted(async () => {
const fullscreen = await WindowIsFullscreen()
onToggleFullscreen(fullscreen === true)
const maximised = await WindowIsMaximised()
onToggleMaximize(maximised)
})
</script>
<template>
<!-- app content-->
<n-spin
:show="props.loading"
:style="{ borderRadius: `${borderRadius}px`, border }"
:theme-overrides="{ opacitySpinning: 0 }">
<div id="app-content-wrapper" :style="{ color: themeVars.textColorBase }" class="flex-box-v">
<!-- title bar -->
2023-09-02 18:23:40 +08:00
<div
id="app-toolbar"
:style="{ height: data.toolbarHeight + 'px' }"
class="flex-box-h"
style="--wails-draggable: drag"
@dblclick="WindowToggleMaximise">
<!-- title -->
<div
id="app-toolbar-title"
:style="{
width: logoWrapperWidth,
minWidth: logoWrapperWidth,
paddingLeft: `${logoPaddingLeft}px`,
}">
<n-space :size="3" :wrap="false" :wrap-item="false" align="center">
<n-avatar :size="35" :src="iconUrl" color="#0000" style="min-width: 35px" />
<div style="min-width: 68px; font-weight: 800">Tiny RDM</div>
<transition name="fade">
<n-text v-if="tabStore.nav === 'browser'" class="ellipsis" strong style="font-size: 13px">
- {{ get(tabStore.currentTab, 'name') }}
</n-text>
</transition>
</n-space>
</div>
<!-- browser tabs -->
<div v-show="tabStore.nav === 'browser'" class="app-toolbar-tab flex-item-expand">
<content-value-tab />
</div>
<div class="flex-item-expand"></div>
<!-- simulate window control buttons -->
<toolbar-control-widget
v-if="!isMacOS()"
:maximised="maximised"
:size="data.toolbarHeight"
style="align-self: flex-start" />
2023-09-02 18:23:40 +08:00
</div>
<!-- content -->
<div
id="app-content"
:style="prefStore.generalFont"
class="flex-box-h flex-item-expand"
style="--wails-draggable: none">
<nav-menu v-model:value="tabStore.nav" :width="data.navMenuWidth" />
2023-09-22 18:31:50 +08:00
<!-- browser page -->
<div v-show="tabStore.nav === 'browser'" class="flex-box-h flex-item-expand">
<resizeable-wrapper
v-model:size="prefStore.behavior.asideWidth"
:min-size="300"
:offset="data.navMenuWidth"
class="flex-item"
@update:size="handleResize">
<browser-pane
v-for="t in tabStore.tabs"
v-show="get(tabStore.currentTab, 'name') === t.name"
:key="t.name"
class="app-side flex-item-expand" />
</resizeable-wrapper>
<content-pane
v-for="t in tabStore.tabs"
v-show="get(tabStore.currentTab, 'name') === t.name"
:key="t.name"
:server="t.name"
class="flex-item-expand" />
2023-09-02 18:23:40 +08:00
</div>
<!-- server list page -->
<div v-show="tabStore.nav === 'server'" class="flex-box-h flex-item-expand">
<resizeable-wrapper
v-model:size="prefStore.behavior.asideWidth"
:min-size="300"
:offset="data.navMenuWidth"
class="flex-item"
@update:size="handleResize">
<connection-pane class="app-side flex-item-expand" />
</resizeable-wrapper>
<content-server-pane class="flex-item-expand" />
2023-09-02 18:23:40 +08:00
</div>
<!-- log page -->
<div v-show="tabStore.nav === 'log'" class="flex-box-h flex-item-expand">
<content-log-pane ref="logPaneRef" class="flex-item-expand" />
</div>
2023-09-02 18:23:40 +08:00
</div>
2023-07-16 01:50:01 +08:00
</div>
</n-spin>
</template>
<style lang="scss" scoped>
2023-07-15 01:54:40 +08:00
#app-content-wrapper {
width: 100vw;
height: 100vh;
overflow: hidden;
box-sizing: border-box;
border-radius: 8px;
background-color: v-bind('themeVars.bodyColor');
#app-toolbar {
background-color: v-bind('exThemeVars.titleColor');
border-bottom: 1px solid v-bind('exThemeVars.splitColor');
2023-09-02 18:23:40 +08:00
&-title {
padding-left: 10px;
padding-right: 10px;
box-sizing: border-box;
align-self: center;
align-items: baseline;
}
}
.app-toolbar-tab {
align-self: flex-end;
margin-bottom: -1px;
2023-09-03 00:15:31 +08:00
margin-left: 3px;
2023-09-02 18:23:40 +08:00
}
#app-content {
height: calc(100% - 60px);
}
.app-side {
//overflow: hidden;
height: 100%;
background-color: v-bind('exThemeVars.sidebarColor');
border-right: 1px solid v-bind('exThemeVars.splitColor');
2023-09-03 00:15:31 +08:00
}
}
2023-09-02 18:23:40 +08:00
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s ease;
}
</style>