@longhongguo/form-create-ant-design-vue 3.3.24 → 3.3.25

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": "@longhongguo/form-create-ant-design-vue",
3
- "version": "3.3.24",
3
+ "version": "3.3.25",
4
4
  "description": "AntDesignVue版本低代码表单|FormCreate 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单生成组件。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。",
5
5
  "main": "./dist/form-create.min.js",
6
6
  "module": "./dist/form-create.esm.js",
@@ -52,6 +52,10 @@ export default defineComponent({
52
52
  // 当只读状态变化时,更新编辑器状态
53
53
  if (this._editor) {
54
54
  this.setReadOnlyMode(newVal)
55
+ // 如果是只读模式,设置图片点击监听
56
+ if (newVal) {
57
+ this.setupImageClickHandler(this._editor)
58
+ }
55
59
  }
56
60
  }
57
61
  },
@@ -537,17 +541,21 @@ export default defineComponent({
537
541
  // 立即设置一次
538
542
  this.$nextTick(() => {
539
543
  this.setReadOnlyMode(true)
544
+ this.setupImageClickHandler(editor)
540
545
  })
541
546
 
542
547
  // 第一次延迟:等待编辑器 DOM 创建
543
548
  setTimeout(() => {
544
549
  this.setReadOnlyMode(true)
550
+ this.setupImageClickHandler(editor)
545
551
  // 第二次延迟:确保设置生效
546
552
  setTimeout(() => {
547
553
  this.setReadOnlyMode(true)
554
+ this.setupImageClickHandler(editor)
548
555
  // 第三次延迟:确保完全生效
549
556
  setTimeout(() => {
550
557
  this.setReadOnlyMode(true)
558
+ this.setupImageClickHandler(editor)
551
559
  }, 300)
552
560
  }, 200)
553
561
  }, 100)
@@ -1037,6 +1045,90 @@ export default defineComponent({
1037
1045
  }
1038
1046
  })
1039
1047
  },
1048
+ // 设置图片点击处理器(用于只读/预览模式下向父窗口发送预览消息)
1049
+ setupImageClickHandler(editor) {
1050
+ if (!editor) return
1051
+
1052
+ // 如果已经有处理器,先清理
1053
+ if (this._imageClickHandler && this._imageClickContainer) {
1054
+ this._imageClickContainer.removeEventListener(
1055
+ 'click',
1056
+ this._imageClickHandler,
1057
+ true
1058
+ )
1059
+ }
1060
+
1061
+ // 查找编辑器文本容器
1062
+ let textContainer = null
1063
+ if (editor.$textElem && editor.$textElem[0]) {
1064
+ textContainer = editor.$textElem[0]
1065
+ } else if (editor.id) {
1066
+ const editorEl = document.getElementById(editor.id)
1067
+ if (editorEl) {
1068
+ textContainer = editorEl.querySelector('.w-e-text')
1069
+ }
1070
+ }
1071
+
1072
+ if (!textContainer) {
1073
+ // 如果找不到容器,延迟重试
1074
+ setTimeout(() => {
1075
+ this.setupImageClickHandler(editor)
1076
+ }, 100)
1077
+ return
1078
+ }
1079
+
1080
+ // 创建图片点击处理器
1081
+ const handleImageClick = (event) => {
1082
+ // 检查是否点击的是图片
1083
+ const target = event.target
1084
+ if (target && target.tagName === 'IMG') {
1085
+ event.preventDefault()
1086
+ event.stopPropagation()
1087
+
1088
+ // 提取图片信息
1089
+ const imgSrc = target.getAttribute('src') || target.src
1090
+ const imgAlt = target.getAttribute('alt') || ''
1091
+ const imgTitle = target.getAttribute('title') || imgAlt
1092
+
1093
+ // 如果图片有链接,提取链接地址
1094
+ let imgUrl = imgSrc
1095
+ const parentLink = target.closest('a')
1096
+ if (parentLink) {
1097
+ imgUrl = parentLink.getAttribute('href') || imgSrc
1098
+ }
1099
+
1100
+ // 发送预览消息到父窗口(类似 Upload 组件)
1101
+ if (window.parent && window.parent !== window) {
1102
+ // 生成一个基于图片 URL 的 uid(用于标识图片)
1103
+ const uid = imgSrc.split('').reduce((acc, char) => {
1104
+ return ((acc << 5) - acc + char.charCodeAt(0)) | 0
1105
+ }, 0)
1106
+
1107
+ window.parent.postMessage(
1108
+ {
1109
+ type: 'upload-preview',
1110
+ file: {
1111
+ url: imgUrl, // 使用图片 URL 或链接地址
1112
+ name: imgTitle || imgAlt || '图片', // 使用 title、alt 或默认值
1113
+ uid: uid, // 基于 URL 生成的标识
1114
+ size: 0, // 图片大小未知
1115
+ type: 'image' // 文件类型
1116
+ },
1117
+ timestamp: Date.now()
1118
+ },
1119
+ '*'
1120
+ )
1121
+ }
1122
+ }
1123
+ }
1124
+
1125
+ // 在捕获阶段添加点击监听器(优先级高)
1126
+ textContainer.addEventListener('click', handleImageClick, true)
1127
+
1128
+ // 保存引用以便清理
1129
+ this._imageClickHandler = handleImageClick
1130
+ this._imageClickContainer = textContainer
1131
+ },
1040
1132
  // 验证是否为有效的URL
1041
1133
  isValidUrl(str) {
1042
1134
  if (!str || typeof str !== 'string') return false