adtec-core-package 2.6.9 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adtec-core-package",
3
- "version": "2.6.9",
3
+ "version": "2.7.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -18,7 +18,12 @@
18
18
  import { AiEditor } from 'aieditor'
19
19
  import 'aieditor/dist/style.css'
20
20
  import { onMounted, onUnmounted, ref, watch, nextTick } from 'vue'
21
+ import type { WatchStopHandle } from 'vue'
21
22
  import { ElMessage } from 'element-plus'
23
+ enum WatchType {
24
+ initWatch = 'initWatch',
25
+ }
26
+ const watchHandlers = ref<Partial<Record<WatchType, WatchStopHandle>>>({});
22
27
 
23
28
  const divRef = ref()
24
29
  let aiEditor: AiEditor | null
@@ -322,29 +327,18 @@ function customStringReplacement(
322
327
  return result
323
328
  }
324
329
 
325
- watch(
326
- () => props.isEdit,
327
- (val) => {
328
- if (aiEditor) {
329
- aiEditor.setEditable(val)
330
- //头尾显隐
331
- const footer = divRef.value?.querySelector('aie-footer') as HTMLElement
332
- if (footer) {
333
- footer.style.display = val ? '' : 'none'
334
- }
335
- const header = divRef.value?.querySelector('aie-header') as HTMLElement
336
- if (header) {
337
- header.style.display = val ? '' : 'none'
338
- }
339
- }
340
- },
341
- { immediate: true },
342
- )
330
+
343
331
  function initHtml(html: string) {
344
332
  html = customStringReplacement(html, '<img', '>', 'height="[0-9]+"', 'height="auto"')
345
333
  return convertPtToPx(html)
346
334
  }
347
-
335
+ const stopWatchByType = (type: WatchType) => {
336
+ const stopHandle = watchHandlers.value[type]
337
+ if (stopHandle) {
338
+ stopHandle()
339
+ delete watchHandlers.value[type]
340
+ }
341
+ }
348
342
  onMounted(() => {
349
343
  const config = {
350
344
  element: divRef.value as Element,
@@ -363,7 +357,27 @@ onMounted(() => {
363
357
  { name: 'Times New Roman', value: 'Times New Roman' },
364
358
  ],
365
359
  },
366
- onCreated: (editor: AiEditor) => {},
360
+ onCreated: (editor: AiEditor) => {
361
+ stopWatchByType(WatchType.initWatch)
362
+ watchHandlers.value[WatchType.initWatch] =watch(
363
+ () => props.isEdit,
364
+ (val) => {
365
+ if (aiEditor) {
366
+ aiEditor.setEditable(val)
367
+ //头尾显隐
368
+ const footer = divRef.value?.querySelector('aie-footer') as HTMLElement
369
+ if (footer) {
370
+ footer.style.display = val ? '' : 'none'
371
+ }
372
+ const header = divRef.value?.querySelector('aie-header') as HTMLElement
373
+ if (header) {
374
+ header.style.display = val ? '' : 'none'
375
+ }
376
+ }
377
+ },
378
+ { immediate: true },
379
+ )
380
+ },
367
381
  }
368
382
  // 隐藏工具栏
369
383
  if (!props.showToolbar) {
@@ -196,13 +196,13 @@ const mouseout = () => {
196
196
  }
197
197
  const getAccept = computed(() => {
198
198
  if (props.accept === 'images') {
199
- return '.jpg,.jpeg,.png,.gif,.bmp,.JPG,.JPEG,.PBG,.GIF,.BMP'
199
+ return '.jpg,.jpeg,.png,.gif,.bmp'
200
200
  } else if (props.accept === 'document') {
201
201
  return '.txt,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx'
202
202
  } else if (props.accept === 'txt') {
203
203
  return '.txt'
204
204
  } else if (props.accept === 'pdf') {
205
- return '.pdf'
205
+ return '.pdf' // 正确配置,仅允许 pdf
206
206
  } else if (props.accept === 'word') {
207
207
  return '.doc,.docx'
208
208
  } else if (props.accept === 'excel') {
@@ -266,6 +266,17 @@ const beforeUpload = (file: File) => {
266
266
  ElMessage.warning('文件大小不能超过' + props.size + 'MB')
267
267
  return false
268
268
  }
269
+ const acceptSuffixes = getAccept.value
270
+ ?.split(',')
271
+ .map(suffix => suffix.slice(1).toLowerCase())
272
+ const fileSuffix = file.name.split('.').pop()?.toLowerCase()
273
+ if (acceptSuffixes && !acceptSuffixes.includes(fileSuffix)) {
274
+ ElMessage.error(`文件 ${file.name} 格式不支持,仅允许 ${getAccept.value}!`)
275
+ setTimeout(() => {
276
+ ref_upload.value?.clearFiles(["ready"])
277
+ }, 1)
278
+ return false
279
+ }
269
280
  loadingFiles.value.push(file.name)
270
281
  return true
271
282
  }