Your Name 3 år sedan
förälder
incheckning
60f3a99041
3 ändrade filer med 22 tillägg och 5 borttagningar
  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
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 12
- 3
src/components/Editor.vue Visa fil

9
   modelValue: {
9
   modelValue: {
10
     type: String,
10
     type: String,
11
     default: '',
11
     default: '',
12
-  }
12
+  },
13
+  disabled: Boolean,
13
 })
14
 })
14
 
15
 
15
 const emit = defineEmits(['update:modelValue', 'save'])
16
 const emit = defineEmits(['update:modelValue', 'save'])
22
   }
23
   }
23
 }, { immediate: true })
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
 onMounted(() => {
33
 onMounted(() => {
26
   window.tinymce.init({
34
   window.tinymce.init({
27
     selector: '#noteEditor',
35
     selector: '#noteEditor',
28
     plugins: 'save',
36
     plugins: 'save',
29
     menubar: false,
37
     menubar: false,
30
-    language: 'zh_CN',
38
+    readonly: props.disabled,
39
+    language: 'zh-Hans',
31
     plugins: ['image', 'save'],
40
     plugins: ['image', 'save'],
32
     image_description: false,   // 禁用图片描述
41
     image_description: false,   // 禁用图片描述
33
     image_dimensions: false,  // 禁用图片宽高设置
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
     setup: (editor) => {
44
     setup: (editor) => {
36
       if (props.modelValue) {
45
       if (props.modelValue) {
37
         editor.setContent(props.modelValue)
46
         editor.setContent(props.modelValue)

+ 3
- 2
src/pages/index.vue Visa fil

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