feat: 功能18优化 (#342)

题目标题编辑自动focus
This commit is contained in:
Jiangchunfu 2024-07-15 17:50:00 +08:00 committed by sudoooooo
parent 5e85e5a3b9
commit a14d444960
3 changed files with 40 additions and 1 deletions

View File

@ -28,7 +28,7 @@ import './styles/reset-wangeditor.scss'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { ref, shallowRef, onBeforeMount, watch } from 'vue' import { ref, shallowRef, onBeforeMount, watch } from 'vue'
const emit = defineEmits(['input', 'onFocus', 'change', 'blur']) const emit = defineEmits(['input', 'onFocus', 'change', 'blur', 'created'])
const model = defineModel() const model = defineModel()
const props = defineProps(['staticToolBar']) const props = defineProps(['staticToolBar'])
@ -60,6 +60,7 @@ const onCreated = (editor) => {
if (model.value) { if (model.value) {
setHtml(model.value) setHtml(model.value)
} }
emit('created', editor)
} }
const onChange = (editor) => { const onChange = (editor) => {
const editorHtml = editor.getHtml() const editorHtml = editor.getHtml()

View File

@ -14,6 +14,7 @@
<RichEditor <RichEditor
:modelValue="element.text" :modelValue="element.text"
@change="(value) => handleChange(index, value)" @change="(value) => handleChange(index, value)"
@created="handleCreated"
/> />
</div> </div>
@ -41,6 +42,7 @@
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
import { cloneDeep as _cloneDeep } from 'lodash-es' import { cloneDeep as _cloneDeep } from 'lodash-es'
import RichEditor from '@/common/Editor/RichEditor.vue' import RichEditor from '@/common/Editor/RichEditor.vue'
import { mapGetters, mapState } from 'vuex'
export default { export default {
name: 'OptionEdit', name: 'OptionEdit',
@ -58,6 +60,14 @@ export default {
draggable, draggable,
RichEditor RichEditor
}, },
data() {
return {
//
createdEditorCount: 0,
//
editorList: []
}
},
mounted() { mounted() {
// hash // hash
const hashMap = {} const hashMap = {}
@ -101,6 +111,29 @@ export default {
optionSortChange() { optionSortChange() {
const optionList = _cloneDeep(this.optionList) const optionList = _cloneDeep(this.optionList)
this.$emit('optionChange', optionList) this.$emit('optionChange', optionList)
},
// editor
handleCreated(editor) {
this.createdEditorCount++
this.editorList.push(editor)
}
},
computed: {
...mapGetters({
moduleConfig: 'edit/moduleConfig'
}),
//
createdAllCurrentEditQuestionEditor() {
return this.createdEditorCount === this.moduleConfig?.options?.length
}
},
watch: {
//
//
createdAllCurrentEditQuestionEditor(bool) {
if (bool) {
this.editorList[0]?.focus()
}
} }
} }
} }

View File

@ -70,6 +70,11 @@ export default defineComponent({
class="rich-editor" class="rich-editor"
modelValue={filterXSS(this.title)} modelValue={filterXSS(this.title)}
onChange={this.handleChange} onChange={this.handleChange}
onCreated={
(editor) => {
editor?.focus()
}
}
/> />
) )
} }