Commit 966571bdcb11c2729ab9ce212bd3e195f7bf3a59

Authored by liuzhidong
Committed by GitHub
1 parent aee61303

fix(Tinymce): Read only status upload button can also be used (#718)

*修复富文本组件在只读状态下上传图片按钮也能点击的bug
src/components/Tinymce/src/Editor.vue
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 @done="handleDone" 6 @done="handleDone"
7 v-if="showImageUpload" 7 v-if="showImageUpload"
8 v-show="editorRef" 8 v-show="editorRef"
  9 + :disabled="disabled"
9 /> 10 />
10 <textarea :id="tinymceId" ref="elRef" :style="{ visibility: 'hidden' }"></textarea> 11 <textarea :id="tinymceId" ref="elRef" :style="{ visibility: 'hidden' }"></textarea>
11 </div> 12 </div>
@@ -170,6 +171,12 @@ @@ -170,6 +171,12 @@
170 }; 171 };
171 }); 172 });
172 173
  174 + const disabled = computed(() => {
  175 + const { options } = props;
  176 + const getdDisabled = options && Reflect.get(options, 'readonly');
  177 + return getdDisabled ?? false;
  178 + });
  179 +
173 watch( 180 watch(
174 () => attrs.disabled, 181 () => attrs.disabled,
175 () => { 182 () => {
@@ -301,6 +308,7 @@ @@ -301,6 +308,7 @@
301 handleDone, 308 handleDone,
302 editorRef, 309 editorRef,
303 fullscreen, 310 fullscreen,
  311 + disabled,
304 }; 312 };
305 }, 313 },
306 }); 314 });
src/components/Tinymce/src/ImgUpload.vue
@@ -8,14 +8,14 @@ @@ -8,14 +8,14 @@
8 :showUploadList="false" 8 :showUploadList="false"
9 accept=".jpg,.jpeg,.gif,.png,.webp" 9 accept=".jpg,.jpeg,.gif,.png,.webp"
10 > 10 >
11 - <a-button type="primary"> 11 + <a-button type="primary" v-bind="{ ...getButtonProps }">
12 {{ t('component.upload.imgUpload') }} 12 {{ t('component.upload.imgUpload') }}
13 </a-button> 13 </a-button>
14 </Upload> 14 </Upload>
15 </div> 15 </div>
16 </template> 16 </template>
17 <script lang="ts"> 17 <script lang="ts">
18 - import { defineComponent } from 'vue'; 18 + import { defineComponent, computed } from 'vue';
19 19
20 import { Upload } from 'ant-design-vue'; 20 import { Upload } from 'ant-design-vue';
21 import { useDesign } from '/@/hooks/web/useDesign'; 21 import { useDesign } from '/@/hooks/web/useDesign';
@@ -29,15 +29,26 @@ @@ -29,15 +29,26 @@
29 fullscreen: { 29 fullscreen: {
30 type: Boolean, 30 type: Boolean,
31 }, 31 },
  32 + disabled: {
  33 + type: Boolean,
  34 + default: false,
  35 + },
32 }, 36 },
33 emits: ['uploading', 'done', 'error'], 37 emits: ['uploading', 'done', 'error'],
34 - setup(_, { emit }) { 38 + setup(props, { emit }) {
35 let uploading = false; 39 let uploading = false;
36 40
37 const { uploadUrl } = useGlobSetting(); 41 const { uploadUrl } = useGlobSetting();
38 const { t } = useI18n(); 42 const { t } = useI18n();
39 const { prefixCls } = useDesign('tinymce-img-upload'); 43 const { prefixCls } = useDesign('tinymce-img-upload');
40 44
  45 + const getButtonProps = computed(() => {
  46 + const { disabled } = props;
  47 + return {
  48 + disabled,
  49 + };
  50 + });
  51 +
41 function handleChange(info: Recordable) { 52 function handleChange(info: Recordable) {
42 const file = info.file; 53 const file = info.file;
43 const status = file?.status; 54 const status = file?.status;
@@ -63,6 +74,7 @@ @@ -63,6 +74,7 @@
63 handleChange, 74 handleChange,
64 uploadUrl, 75 uploadUrl,
65 t, 76 t,
  77 + getButtonProps,
66 }; 78 };
67 }, 79 },
68 }); 80 });