Your Name 3 年 前
コミット
60f3a99041
共有3 個のファイルを変更した22 個の追加5 個の削除を含む
  1. 7
    0
      public/tinymce/langs/zh-Hans.js
  2. 12
    3
      src/components/Editor.vue
  3. 3
    2
      src/pages/index.vue

+ 7
- 0
public/tinymce/langs/zh-Hans.js
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 12
- 3
src/components/Editor.vue ファイルの表示

@@ -9,7 +9,8 @@ const props = defineProps({
9 9
   modelValue: {
10 10
     type: String,
11 11
     default: '',
12
-  }
12
+  },
13
+  disabled: Boolean,
13 14
 })
14 15
 
15 16
 const emit = defineEmits(['update:modelValue', 'save'])
@@ -22,16 +23,24 @@ watch(() => props.modelValue, (newVal) => {
22 23
   }
23 24
 }, { immediate: true })
24 25
 
26
+watch(() => props.disabled, (newVal) => {
27
+  if (!editorRef.value) return;
28
+  const mode = newVal ? 'readonly' : 'design'
29
+  editorRef.value.mode.set(mode);
30
+  console.log('-----editorRef.value.mode------?', editorRef.value.mode)
31
+})
32
+
25 33
 onMounted(() => {
26 34
   window.tinymce.init({
27 35
     selector: '#noteEditor',
28 36
     plugins: 'save',
29 37
     menubar: false,
30
-    language: 'zh_CN',
38
+    readonly: props.disabled,
39
+    language: 'zh-Hans',
31 40
     plugins: ['image', 'save'],
32 41
     image_description: false,   // 禁用图片描述
33 42
     image_dimensions: false,  // 禁用图片宽高设置
34
-    toolbar: 'blocks fontfamily fontsize bold italic backcolor alignleft aligncenter alignright alignjustify image outdent indent undo redo removeformat',
43
+    toolbar: 'save | blocks fontfamily fontsize | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | outdent indent | undo redo | removeformat',
35 44
     setup: (editor) => {
36 45
       if (props.modelValue) {
37 46
         editor.setContent(props.modelValue)

+ 3
- 2
src/pages/index.vue ファイルの表示

@@ -1,6 +1,7 @@
1 1
 <template>
2 2
   <div>
3 3
     <Editor
4
+      :disabled="disabled"
4 5
       v-model="valueHtml"
5 6
       @save="handleSave"
6 7
     />
@@ -8,7 +9,7 @@
8 9
 </template>
9 10
 
10 11
 <script setup>
11
-import { ref, shallowRef, watch, onMounted } from 'vue'
12
+import { ref, shallowRef, watch, onMounted, computed } from 'vue'
12 13
 import Editor from '@/components/Editor.vue';
13 14
 import { useModel } from '@zjxpcyc/vue-tiny-store'
14 15
 import eventBus from '@/utils/eventBus'
@@ -16,7 +17,7 @@ import eventBus from '@/utils/eventBus'
16 17
 const mode = 'simple'
17 18
 const { user } = useModel('user')
18 19
 const { note, updateNote } = useModel('note')
19
-
20
+const disabled = computed(() => !note.value || !note.value.path)
20 21
 const valueHtml = ref()
21 22
 
22 23
 const handleSave = () => {