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 @done="handleDone"
7 7 v-if="showImageUpload"
8 8 v-show="editorRef"
  9 + :disabled="disabled"
9 10 />
10 11 <textarea :id="tinymceId" ref="elRef" :style="{ visibility: 'hidden' }"></textarea>
11 12 </div>
... ... @@ -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 180 watch(
174 181 () => attrs.disabled,
175 182 () => {
... ... @@ -301,6 +308,7 @@
301 308 handleDone,
302 309 editorRef,
303 310 fullscreen,
  311 + disabled,
304 312 };
305 313 },
306 314 });
... ...
src/components/Tinymce/src/ImgUpload.vue
... ... @@ -8,14 +8,14 @@
8 8 :showUploadList="false"
9 9 accept=".jpg,.jpeg,.gif,.png,.webp"
10 10 >
11   - <a-button type="primary">
  11 + <a-button type="primary" v-bind="{ ...getButtonProps }">
12 12 {{ t('component.upload.imgUpload') }}
13 13 </a-button>
14 14 </Upload>
15 15 </div>
16 16 </template>
17 17 <script lang="ts">
18   - import { defineComponent } from 'vue';
  18 + import { defineComponent, computed } from 'vue';
19 19  
20 20 import { Upload } from 'ant-design-vue';
21 21 import { useDesign } from '/@/hooks/web/useDesign';
... ... @@ -29,15 +29,26 @@
29 29 fullscreen: {
30 30 type: Boolean,
31 31 },
  32 + disabled: {
  33 + type: Boolean,
  34 + default: false,
  35 + },
32 36 },
33 37 emits: ['uploading', 'done', 'error'],
34   - setup(_, { emit }) {
  38 + setup(props, { emit }) {
35 39 let uploading = false;
36 40  
37 41 const { uploadUrl } = useGlobSetting();
38 42 const { t } = useI18n();
39 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 52 function handleChange(info: Recordable) {
42 53 const file = info.file;
43 54 const status = file?.status;
... ... @@ -63,6 +74,7 @@
63 74 handleChange,
64 75 uploadUrl,
65 76 t,
  77 + getButtonProps,
66 78 };
67 79 },
68 80 });
... ...