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:The plugin width is persisted using vueuse. #732

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 6 additions & 10 deletions packages/common/component/PluginPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</template>

<script>
import { inject, ref, watch } from 'vue'
import { inject, ref } from 'vue'
import { useLayout } from '@opentiny/tiny-engine-controller'
import CloseIcon from './CloseIcon.vue'
import SvgButton from './SvgButton.vue'
Expand Down Expand Up @@ -70,7 +70,7 @@ export default {
},
emits: ['close'],
setup(props, { emit }) {
const { pluginWidth } = useLayout()
const { getPluginWidth, changePluginWidth } = useLayout()
const panelState = inject('panelState')
const closePanel = () => {
useLayout().closePlugin()
Expand Down Expand Up @@ -104,23 +104,20 @@ export default {
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]
})
const panelWidth = ref(getPluginWidth(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
changePluginWidth(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
changePluginWidth(props.fixedName, panelWidth.value)
}

const throttledMouseMoveRight = throttle(onMouseMoveRight, 50)
Expand Down Expand Up @@ -156,8 +153,7 @@ export default {
panel,
panelWidth,
onMouseDownRight,
onMouseDownLeft,
pluginWidth
onMouseDownLeft
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions packages/controller/src/useLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { reactive, nextTick } from 'vue'
import { constants } from '@opentiny/tiny-engine-utils'
import { useStorage } from '@vueuse/core'

const { PAGE_STATUS } = constants

Expand All @@ -36,7 +37,8 @@ const PLUGIN_NAME = {
Style: 'SettingStyles',
Props: 'SettingProps'
}
const pluginWidth = reactive({

const pluginWidth = {
Materials: '300',
OutlineTree: '300',
AppManage: '300',
Expand All @@ -50,7 +52,17 @@ const pluginWidth = reactive({
SettingProps: '320',
SettingStyles: '320',
SettingEvents: '320'
})
}
const pluginWidthStorage = useStorage('pluginWidth', pluginWidth)
const getPluginWidth = (name) => {
return pluginWidthStorage.value[name]
}
const changePluginWidth = (name, width) => {
if (Object.prototype.hasOwnProperty.call(pluginWidthStorage.value, name)) {
pluginWidthStorage.value[name] = width
}
}

const pluginState = reactive({
pluginEvent: 'all'
})
Expand Down Expand Up @@ -167,6 +179,7 @@ export default () => {
getPluginState,
pluginState,
isEmptyPage,
pluginWidth
getPluginWidth,
changePluginWidth
}
}
4 changes: 2 additions & 2 deletions packages/plugins/bridge/src/BridgeSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ import { useLayout, useApp, getGlobalConfig, useModal, useNotify } from '@openti
import { theme } from '@opentiny/tiny-engine-controller/adapter'

const isOpen = ref(false)
const { pluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME['Bridge']])
const { getPluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['Bridge']))

export const openPanel = () => {
isOpen.value = true
Expand Down
5 changes: 2 additions & 3 deletions packages/plugins/data/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,13 @@ export default {
const activeName = ref(STATE.CURRENT_STATE)
const isBlock = computed(() => useCanvas().isBlock())
const { setSaved } = useCanvas()
const { PLUGIN_NAME, getPluginApi, pluginWidth } = useLayout()
const { PLUGIN_NAME, getPluginApi, getPluginWidth } = useLayout()
const { openCommon } = getPluginApi(PLUGIN_NAME.save)
const docsUrl = useHelp().getDocsUrl('data')
const panelState = reactive({
emitEvent: emit
})
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME['Data']])

const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['Data']))
provide('panelState', panelState)

const state = reactive({
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/datasource/src/DataSourceForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import { useModal, useApp, useDataSource } from '@opentiny/tiny-engine-controlle
import { extend } from '@opentiny/vue-renderless/common/object'

let isOpen = ref(false)
const { pluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME['Datasource']])
const { getPluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['Datasource']))

export const open = () => {
isOpen.value = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import { constants } from '@opentiny/tiny-engine-utils'

const { DEFAULT_INTERCEPTOR } = constants
const isOpen = ref(false)
const { pluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME['Datasource']])
const { getPluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['Datasource']))
export const open = () => {
isOpen.value = true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/datasource/src/DataSourceRecordList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ import { downloadFn, handleImportedData, overrideOrMergeData, getDataAfterPage }
import DataSourceRecordUpload from './DataSourceRecordUpload.vue'

let isOpen = ref(false)
const { pluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME['Datasource']])
const { getPluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['Datasource']))

export const open = () => {
isOpen.value = true
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/datasource/src/DataSourceRemotePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ import { obj2String, string2Obj } from '@opentiny/tiny-engine-controller/adapter
import { getRequest } from './js/datasource'

export const isOpen = ref(false)
const { pluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME['Datasource']] - 280)
const { getPluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['Datasource']) - 280)
export const open = () => {
isOpen.value = true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/page/src/PageFolderSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import PageGeneral from './PageGeneral.vue'
import http from './http.js'

let isShow = ref(false)
const { pluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME['AppManage']])
const { getPluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['AppManage']))

export const openFolderSettingPanel = () => {
isShow.value = true
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/page/src/PageSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ import http from './http.js'

const { COMPONENT_NAME } = constants
const isShow = ref(false)
const { pluginWidth,PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => pluginWidth[PLUGIN_NAME["AppManage"]])
const { getPluginWidth, PLUGIN_NAME } = useLayout()
const leftMargin = computed(() => getPluginWidth(PLUGIN_NAME['AppManage']))

export const openPageSettingPanel = () => {
isShow.value = true
Expand Down
8 changes: 1 addition & 7 deletions packages/settings/events/src/Main.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<plugin-panel
title="高级"
:fixed-panels="fixedPanels"
:fixed-name="PLUGIN_NAME.Event"
:defaultWidth="320"
@close="$emit('close')"
>
<plugin-panel title="高级" :fixed-panels="fixedPanels" :fixed-name="SETTING_NAME.Event" @close="$emit('close')">
<template #content>
<tiny-collapse v-model="activeNames">
<tiny-collapse-item title="事件绑定" name="bindEvent">
Expand Down
Loading