优化代码 弹框表单详情 当流程表单过长时候增加对应往上往下跳转按钮并内容在弹框内滚动

pull/709/head
Lemon 2025-02-22 11:53:27 +08:00
parent b2ddefe4a0
commit 212d798788
1 changed files with 150 additions and 2 deletions

View File

@ -254,8 +254,32 @@
</Dialog>
<!-- 弹窗表单详情 -->
<Dialog title="表单详情" :fullscreen="true" v-model="formDetailVisible">
<form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" />
<Dialog title="表单详情" :fullscreen="false" v-model="formDetailVisible" width="800" class="form-detail-dialog">
<div class="form-detail-container relative" @scroll="handleScroll">
<form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" />
</div>
<!-- 将滚动按钮组移到 Dialog 组件内但在 form-detail-container -->
<div class="scroll-buttons-overlay">
<div
v-show="showTopBtn"
class="scroll-btn"
@click="scrollToTop"
>
<el-icon :size="20">
<ArrowUpBold />
</el-icon>
</div>
<div
v-show="showBottomBtn"
class="scroll-btn"
@click="scrollToBottom"
>
<el-icon :size="20">
<ArrowDownBold />
</el-icon>
</div>
</div>
</Dialog>
</template>
@ -274,6 +298,8 @@ import { cloneDeep, isEqual } from 'lodash-es'
import { useTagsView } from '@/hooks/web/useTagsView'
import { useDebounceFn } from '@vueuse/core'
import { subString } from '@/utils/index'
import { ArrowUpBold, ArrowDownBold } from '@element-plus/icons-vue'
import { ElBacktop } from 'element-plus'
defineOptions({ name: 'BpmModel' })
@ -609,9 +635,109 @@ watchEffect(() => {
isExpand.value = false
}
})
//
const showTopBtn = ref(false)
//
const showBottomBtn = ref(false)
//
const handleScroll = () => {
const container = document.querySelector('.form-detail-container')
if (container) {
const { scrollTop, scrollHeight, clientHeight } = container
//
showTopBtn.value = scrollTop > 100
//
showBottomBtn.value = scrollTop + clientHeight < scrollHeight - 10
}
}
//
const scrollToTop = () => {
const container = document.querySelector('.form-detail-container')
if (container) {
container.scrollTo({
top: 0,
behavior: 'smooth'
})
}
}
//
const scrollToBottom = () => {
const container = document.querySelector('.form-detail-container')
if (container) {
container.scrollTo({
top: container.scrollHeight,
behavior: 'smooth'
})
}
}
//
onMounted(() => {
const container = document.querySelector('.form-detail-container')
if (container) {
container.addEventListener('scroll', handleScroll)
}
})
//
onUnmounted(() => {
const container = document.querySelector('.form-detail-container')
if (container) {
container.removeEventListener('scroll', handleScroll)
}
})
</script>
<style lang="scss">
.form-detail-dialog.el-dialog {
margin: 5vh auto !important;
.el-dialog__body {
position: relative;
padding: 0;
height: 70vh; //
max-height: 800px;
}
//
.scroll-buttons-overlay {
position: fixed;
right: calc(50% - 400px - 60px); // (400px)(60px)
top: 50%;
transform: translateY(-50%);
display: flex;
flex-direction: column;
gap: 10px;
z-index: 2001;
.scroll-btn {
background-color: var(--el-color-primary);
color: white;
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: 50%;
box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
cursor: pointer;
transition: all 0.3s;
opacity: 0.8;
&:hover {
background-color: var(--el-color-primary);
opacity: 1;
transform: scale(1.1);
}
}
}
}
.rename-dialog.el-dialog {
padding: 0 !important;
@ -648,4 +774,26 @@ watchEffect(() => {
transform: translateZ(0);
}
}
.form-detail-container {
height: 100%;
width: 100%;
overflow-y: auto;
padding: 20px;
position: relative;
//
&::-webkit-scrollbar {
width: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--el-color-primary-light-5);
border-radius: 3px;
}
&::-webkit-scrollbar-track {
background-color: #f5f7fa;
}
}
</style>