feat(Design): 新增图文题型组件

- 添加 Contenteditable组件用于富文本编辑
- 实现 CheckboxQuestionAction 组件用于多选题配置
- 开发 TextWithImages 组件用于图文题型展示
- 更新 QuestionAction 组件以支持多选题操作
- 调整 QuestionBefore 组件移除分组功能
This commit is contained in:
陈昱达
2025-03-06 17:37:36 +08:00
parent 91e5ba7985
commit 01b53ee4a0
7 changed files with 254 additions and 13 deletions

View File

@@ -0,0 +1,117 @@
<template>
<div
ref="editor"
contenteditable="true"
class="van-field"
@focus="showToolbar"
@blur="save"
v-html="modelValue"
></div>
<div ref="editorAction" class="editor-action">
<button v-for="item in actions" :key="item.name" @click="funEvent(item)">{{ item.label }}</button>
</div>
</template>
<script setup>
import { defineEmits, ref, onMounted, onBeforeUnmount } from 'vue';
defineProps({
modelValue: {
type: String,
default: ''
}
});
const editor = ref(null);
const editorAction = ref(null);
const emit = defineEmits(['update:modelValue']);
let lastHeight = window.innerHeight;
const save = (e) => {
emit('update:modelValue', e.target.innerHTML);
};
const functions = {
boldModern: () => {
document.execCommand('bold', false, null);
},
underLine: () => {
document.execCommand('underline', false, null);
},
italic: () => {
document.execCommand('italic', false, null);
}
};
const funEvent = (item) => {
functions[item.fun]();
};
const actions = [
{
label: '加粗',
fun: 'boldModern',
icon: ''
},
{
label: '下划线',
fun: 'underLine',
icon: ''
},
{
label: '图片上传',
fun: 'uploadImage',
icon: ''
},
{
label: '倾斜',
fun: 'italic'
}
];
const showToolbar = () => {
editorAction.value.style.display = '';
};
const handleResize = () => {
const currentHeight = window.innerHeight;
if (currentHeight < lastHeight) {
// 键盘弹出
editorAction.value.style.display = '';
} else {
setTimeout(() => {
// 键盘收起
editorAction.value.style.display = 'none';
}, 100);
}
lastHeight = currentHeight;
};
onMounted(() => {
window.addEventListener('resize', handleResize);
});
onBeforeUnmount(() => {
window.removeEventListener('resize', handleResize);
});
</script>
<style scoped lang="scss">
.editor-action {
position: fixed;
bottom: 0;
left: 0;
z-index: 3000;
width: 100%;
height: 40px;
padding: 0 10px;
background: #fff;
line-height: 40px;
& button {
border: none;
background: #fff;
outline: none;
}
}
</style>