BlockNoteEditorDialog.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <el-dialog
  3. v-model="dialogVisible"
  4. :title="title + $t('common.xuxibiji')"
  5. width="80%"
  6. >
  7. <el-form :model="form" :rules="rules" ref="formRef" label-position="top" class="edit_note">
  8. <el-form-item label="" prop="noteTitle">
  9. <el-input v-model="form.noteTitle" placeholder="请输入标题" size="large" show-word-limit maxlength="20"/>
  10. </el-form-item>
  11. <el-form-item label="" prop="noteContent">
  12. <BlockNoteEditor v-model="editorContent" />
  13. </el-form-item>
  14. </el-form>
  15. <template #footer>
  16. <div class="flex-center">
  17. <div>
  18. <el-button @click="dialogVisible = false" type="primary" plain>{{ $t('common.cancel') }}</el-button>
  19. <el-button type="primary" @click="submitForm" class="gradient">{{ $t('common.confirm') }}</el-button>
  20. </div>
  21. </div>
  22. </template>
  23. </el-dialog>
  24. </template>
  25. <script setup>
  26. import BlockNoteEditor from '@/components/BlockNoteEditor.vue'
  27. import { ref, reactive, watchEffect } from 'vue'
  28. import { useI18n } from 'vue-i18n'
  29. const { t } = useI18n()
  30. const emit = defineEmits(['submit']);
  31. const dialogVisible = ref(false)
  32. const title = ref('');
  33. // 编辑器内容
  34. // 表单引用
  35. const formRef = ref(null);
  36. const editorContent = ref(null);
  37. const form = reactive({
  38. noteId: '',
  39. noteTitle: '',
  40. noteContent: ''
  41. })
  42. watchEffect(() => {
  43. // 将编辑器内容赋值给表单的workflowContent
  44. form.noteContent = JSON.stringify(editorContent.value);
  45. })
  46. const rules = {
  47. noteTitle: [{ required: true, message: t('common.pleaseInputTitle'), trigger: 'blur' }],
  48. noteContent: [{ required: true, message: t('common.pleaseInputContent'), trigger: 'change' }]
  49. }
  50. const submitForm = async () => {
  51. await formRef.value.validate((valid, fields,name) => {
  52. console.log(valid, fields,name)
  53. if (!valid) {
  54. //报错第一个key
  55. let firstKey = Object.keys(fields)[0]
  56. DGTMessage.warning(fields[firstKey][0].message)
  57. return
  58. }
  59. emit('submit', form);
  60. dialogVisible.value = false
  61. })
  62. };
  63. const openDialog = (item) => {
  64. dialogVisible.value = true;
  65. editorContent.value = [
  66. {
  67. "id": "77efedfb-1c9e-4377-bea4-4d4dfdc20c59",
  68. "type": "paragraph",
  69. "props": {
  70. "backgroundColor": "default",
  71. "textColor": "default",
  72. "textAlignment": "left"
  73. },
  74. "content": [],
  75. "children": []
  76. }
  77. ];
  78. if(item){
  79. form.noteId = item.noteId;
  80. form.noteTitle = item.noteTitle;
  81. form.noteContent = "";
  82. // 解析JSON字符串为对象
  83. if(item.noteContent){
  84. editorContent.value = JSON.parse(item.noteContent);
  85. }
  86. }
  87. if(item.noteId){
  88. title.value = t('common.edit')
  89. }else{
  90. title.value = t('common.add')
  91. }
  92. };
  93. defineExpose({
  94. openDialog
  95. });
  96. </script>
  97. <style lang="scss">
  98. .edit_note{
  99. height: calc(100vh - 300px);
  100. min-height: 400px;
  101. overflow-y: auto;
  102. .el-input--large .el-input__wrapper {
  103. border: none !important;
  104. box-shadow: none !important;
  105. border-top:1px solid #e5e7eb !important;
  106. border-bottom:1px solid #e5e7eb !important;
  107. }
  108. .el-input__inner{
  109. font-size: 18px !important;
  110. }
  111. }
  112. </style>