perf: 问卷编辑页标题优化 (#240)

* refactor: 重构 src/management/pages/edit/modules 目录下组件, 使用 Vue3 组合式 API 写法

* perf: 问卷编辑页标题优化
This commit is contained in:
xixiIBN5100 2024-05-30 14:40:53 +08:00 committed by GitHub
parent ae6907a3f4
commit 8db8f9ab19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 96 additions and 71 deletions

View File

@ -14,6 +14,7 @@
"format": "prettier --write src/" "format": "prettier --write src/"
}, },
"dependencies": { "dependencies": {
"@types/lodash-es": "^4.17.12",
"@wangeditor/editor": "^5.1.23", "@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12", "@wangeditor/editor-for-vue": "^5.1.12",
"async-validator": "^4.2.5", "async-validator": "^4.2.5",

View File

@ -15,35 +15,19 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import BackPanel from '../modules/generalModule/BackPanel.vue' import BackPanel from '../modules/generalModule/BackPanel.vue'
import TitlePanel from '../modules/generalModule/TitlePanel.vue' import TitlePanel from '../modules/generalModule/TitlePanel.vue'
import NavPanel from '../modules/generalModule/NavPanel.vue' import NavPanel from '../modules/generalModule/NavPanel.vue'
import HistoryPanel from '../modules/contentModule/HistoryPanel.vue' import HistoryPanel from '../modules/contentModule/HistoryPanel.vue'
import SavePanel from '../modules/contentModule/SavePanel.vue' import SavePanel from '../modules/contentModule/SavePanel.vue'
import PublishPanel from '../modules/contentModule/PublishPanel.vue' import PublishPanel from '../modules/contentModule/PublishPanel.vue'
import { mapState } from 'vuex' import { useStore } from 'vuex'
import { get as _get } from 'lodash-es' import { get as _get } from 'lodash-es'
import { computed } from 'vue'
export default { const store = useStore()
name: 'ModuleNavbar', const title = computed(() => _get(store.state, 'edit.schema.metaData.title'))
components: {
BackPanel,
TitlePanel,
NavPanel,
HistoryPanel,
SavePanel,
PublishPanel
},
data() {
return {}
},
computed: {
...mapState({
title: (state) => _get(state, 'edit.schema.metaData.title')
})
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -5,14 +5,9 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
export default { const onBack = () => {
name: 'BackPanel', window.open('/survey', '_self')
methods: {
onBack() {
window.open('/survey', '_self')
}
}
} }
</script> </script>

View File

@ -25,38 +25,32 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
export default { import { reactive } from 'vue'
name: 'NavPanel',
props: {}, const btnList = reactive([
data() { {
return { icon: 'icon-wenjuanbianji',
btnList: [ text: '问卷编辑',
{ router: 'QuestionEditIndex',
icon: 'icon-wenjuanbianji', key: 'edit',
text: '问卷编辑', next: true
router: 'QuestionEditIndex', },
key: 'edit', {
next: true icon: 'icon-wenjuanshezhi',
}, text: '问卷设置',
{ router: 'QuestionEditSetting',
icon: 'icon-wenjuanshezhi', key: 'settings',
text: '问卷设置', next: true
router: 'QuestionEditSetting', },
key: 'settings', {
next: true icon: 'icon-yangshishezhi',
}, text: '皮肤设置',
{ router: 'QuestionSkinSetting',
icon: 'icon-yangshishezhi', key: 'skinsettings',
text: '皮肤设置', next: true
router: 'QuestionSkinSetting',
key: 'skinsettings',
next: true
}
]
}
} }
} ])
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -1,26 +1,77 @@
<template> <template>
<div class="title"> <div class="title-container">
{{ title }} <div
class="title"
@mouseover="showFullTitle"
@mousemove="updateTooltipPosition"
@mouseleave="hideFullTitle"
>
{{ title }}
</div>
<div
class="tooltip"
v-if="tooltipVisible"
:style="{ top: tooltipPosition.top + 'px', left: tooltipPosition.left + 'px' }"
>
{{ title }}
</div>
</div> </div>
</template> </template>
<script> <script setup lang="ts">
export default { import { ref } from 'vue'
name: 'TitlePanel', import { defineProps } from 'vue'
props: {
title: { defineProps({
type: String, title: {
default: '' type: String,
} default: ''
} }
})
const tooltipVisible = ref(false)
const tooltipPosition = ref({ top: 0, left: 0 })
const showFullTitle = () => {
tooltipVisible.value = true
}
const updateTooltipPosition = (event: MouseEvent) => {
tooltipPosition.value = {
top: event.clientY + 10,
left: event.clientX + 10
}
}
const hideFullTitle = () => {
tooltipVisible.value = false
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.title-container {
position: relative;
width: 280px;
}
.title { .title {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
width: 400px; white-space: nowrap;
width: 100%;
cursor: pointer;
}
.tooltip {
position: fixed;
z-index: 10;
background: white;
padding: 5px;
border: 1px solid #ddd;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 1200px;
white-space: nowrap; white-space: nowrap;
} }
</style> </style>