Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:插件面板优化功能 #632

Merged
merged 15 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/canvas/src/components/container/CanvasFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default {
bottom: 0;
position: absolute;
background-color: var(--ti-lowcode-breadcrumb-bg);
z-index: 90;
z-index: 3;
border-top: 1px solid var(--ti-lowcode-canvas-footer-border-top-color);
.content {
.tip {
Expand Down
160 changes: 153 additions & 7 deletions packages/common/component/PluginPanel.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
<template>
<div class="plugin-panel">
<div class="plugin-panel" ref="panel" :style="{ width: panelWidth + 'px' }">
<div class="plugin-panel-header">
<div class="plugin-panel-title">
<span class="title">{{ title }}</span>
<close-icon v-if="isCloseLeft" :name="name" @close="closePanel"></close-icon>
</div>
<div class="plugin-panel-icon">
<slot name="header"></slot>
<svg-button
class="item icon-sidebar"
:class="[fixedPanels?.includes(fixedName) && 'active']"
name="fixed"
:tips="!fixedPanels?.includes(fixedName) ? '固定面板' : '解除固定面板'"
@click="fixPanel"
></svg-button>
<close-icon v-if="!isCloseLeft" :name="name" @close="closePanel"></close-icon>
</div>
</div>
<slot name="content"></slot>
<div class="scroll-content">
<slot name="content"></slot>
</div>

<div class="resizer-right" @mousedown="onMouseDownRight"></div>
<div class="resizer-left" @mousedown="onMouseDownLeft"></div>
</div>
</template>

<script>
import { inject, ref, watch } from 'vue'
import { useLayout } from '@opentiny/tiny-engine-controller'
import CloseIcon from './CloseIcon.vue'

import SvgButton from './SvgButton.vue'
export default {
components: {
CloseIcon
CloseIcon,
SvgButton
},
props: {
/**
Expand All @@ -40,31 +54,123 @@ export default {
name: {
type: String,
default: 'cross'
},
/**
* 固定面板插件数组
*/
fixedPanels: {
type: Array
},
/**
* 固定面板标识
*/
fixedName: {
type: String
}
},
emits: ['close'],
setup(props, { emit }) {
const { pluginWidth } = useLayout()
const panelState = inject('panelState')
const closePanel = () => {
useLayout().closePlugin()

emit('close')
}

//节流
function throttle(func, limit) {
let lastFunc
let lastRan
return function (...args) {
const context = this
if (!lastRan) {
func.apply(context, args)
lastRan = Date.now()
} else {
clearTimeout(lastFunc)
lastFunc = setTimeout(function () {
if (Date.now() - lastRan >= limit) {
func.apply(context, args)
lastRan = Date.now()
}
}, limit - (Date.now() - lastRan))
}
}
}

const fixPanel = () => {
panelState.emitEvent('fixPanel', props.fixedName)
}
const MIN_WIDTH = 300 // 固定的最小宽度值
const MAX_WIDTH = 1000 // 固定的最大宽度值
const panel = ref(null)
const panelWidth = ref(pluginWidth[props.fixedName]) // 使用默认宽度
watch(pluginWidth, (newWidth) => {
panelWidth.value = newWidth[props.fixedName]
})
let startX = 0
let startWidth = 0

const onMouseMoveRight = (event) => {
const newWidth = startWidth + (event.clientX - startX)
panelWidth.value = Math.max(MIN_WIDTH, Math.min(newWidth, MAX_WIDTH))
pluginWidth[props.fixedName] = panelWidth.value
}

const onMouseMoveLeft = (event) => {
const newWidth = startWidth - (event.clientX - startX)
panelWidth.value = Math.max(MIN_WIDTH, Math.min(newWidth, MAX_WIDTH))
pluginWidth[props.fixedName] = panelWidth.value
}

const throttledMouseMoveRight = throttle(onMouseMoveRight, 50)
const throttledMouseMoveLeft = throttle(onMouseMoveLeft, 50)

const onMouseUpRight = () => {
document.removeEventListener('mousemove', throttledMouseMoveRight)
document.removeEventListener('mouseup', onMouseUpRight)
}

const onMouseUpLeft = () => {
document.removeEventListener('mousemove', throttledMouseMoveLeft)
document.removeEventListener('mouseup', onMouseUpLeft)
}

const onMouseDownRight = (event) => {
startX = event.clientX
startWidth = panel.value.offsetWidth
document.addEventListener('mousemove', throttledMouseMoveRight)
document.addEventListener('mouseup', onMouseUpRight)
}

const onMouseDownLeft = (event) => {
startX = event.clientX
startWidth = panel.value.offsetWidth
document.addEventListener('mousemove', throttledMouseMoveLeft)
document.addEventListener('mouseup', onMouseUpLeft)
}

return {
closePanel
closePanel,
fixPanel,
panel,
panelWidth,
onMouseDownRight,
onMouseDownLeft,
pluginWidth
}
}
}
</script>

<style lang="less" scoped>
.plugin-panel {
width: 100%;
height: 100%;
background: var(--ti-lowcode-plugin-panel-bg, --ti-lowcode-toolbar-bg);
display: flex;
flex-direction: column;
position: relative;
overflow: hidden;

.plugin-panel-header {
display: flex;
Expand Down Expand Up @@ -99,4 +205,44 @@ export default {
}
}
}
// 右边拖拽线
.resizer-right {
position: absolute;
top: 0;
right: 0;
width: 1px;
height: 100%;
cursor: ew-resize;
background-color: rgba(0, 0, 0, 0.1);
transition: width 0.3s ease;
}
.resizer-right:hover {
width: 8px;
background-color: var(--ti-base-color-brand-7);
}
// 左边拖拽线
.resizer-left {
position: absolute;
top: 0;
left: 0;
width: 1px;
height: 100%;
cursor: ew-resize;
background-color: rgba(0, 0, 0, 0.1);
transition: width 0.3s ease;
}
.resizer-left:hover {
width: 8px;
background-color: var(--ti-base-color-brand-7);
}
.scroll-content {
height: 100%;
overflow: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}

.scroll-content::-webkit-scrollbar {
display: none;
}
</style>
2 changes: 1 addition & 1 deletion packages/common/component/PluginSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export default {
<style lang="less" scoped>
.plugin-setting {
position: absolute;
left: calc(var(--base-left-panel-width) - 6px);
top: 0;
z-index: 10;
width: var(--base-collection-panel-width);
height: 100%;
border-right: 1px solid var(--ti-lowcode-toolbar-border-color);
Expand Down
48 changes: 43 additions & 5 deletions packages/controller/src/useLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,36 @@ const PLUGIN_NAME = {
Lock: 'Lock',
Tutorial: 'Tutorial',
OutlineTree: 'OutlineTree',
save: 'save'
save: 'save',
Page: 'AppManage',
Block: 'BlockManage',
Datasource: 'Collections',
Bridge: 'Bridge',
I18n: 'I18n',
Script: 'PageController',
Data: 'DataSource',
Schema: 'Schema'
}

const SETTING_NAME = {
Event: 'event',
Style: 'style',
Props: 'props'
}
const pluginWidth = reactive({
Materials: '300',
OutlineTree: '300',
AppManage: '300',
BlockManage: '300',
Collections: '300',
Bridge: '300',
I18n: '620',
PageController: '1000',
DataSource: '300',
Schema: '1000',
props: '320',
style: '320',
event: '320'
})
const pluginState = reactive({
pluginEvent: 'all'
})
Expand All @@ -47,7 +74,8 @@ const layoutState = reactive({
api: {} // 插件需要注册交互API到这里
},
settings: {
render: 'props',
fixedPanels: [],
render: null,
api: null,
activating: false, // 右侧面版激活提示状态
showDesignSettings: true
Expand Down Expand Up @@ -77,6 +105,13 @@ const activeSetting = (name) => {
}, 1000)
})
}
// 关闭右侧setting插件面板
const closeSetting = (forceClose) => {
const { settings } = layoutState
if (forceClose) {
settings.render = null
}
}

// 获取当前插件注册的Api
const getPluginApi = (pluginName) => {
Expand All @@ -98,7 +133,7 @@ const activePlugin = (name, noActiveRender) => {
})
}

// 关闭插件面板
// 关闭左侧plugin插件面板
const closePlugin = (forceClose) => {
const { plugins } = layoutState
if (!plugins.fixedPanels.includes(plugins.render) || forceClose) {
Expand All @@ -119,9 +154,11 @@ const isEmptyPage = () => layoutState.pageStatus?.state === PAGE_STATUS.Empty
export default () => {
return {
PLUGIN_NAME,
SETTING_NAME,
activeSetting,
activePlugin,
closePlugin,
closeSetting,
layoutState,
getScale,
setDimension,
Expand All @@ -130,6 +167,7 @@ export default () => {
getPluginApi,
getPluginState,
pluginState,
isEmptyPage
isEmptyPage,
pluginWidth
}
}
Loading