vue2-client 1.14.19 → 1.14.21

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.
@@ -1,373 +1,386 @@
1
- <template>
2
- <!-- <Source src="/code/VitalSigns.vue"></Source>-->
3
- <div>
4
- <a-row class="box">
5
- 病历号&nbsp;&nbsp;<a-input v-model="vitalSignsId" style="width: 160px"></a-input>
6
- <a-button-group style="margin-left: 20px;">
7
- <a-button plain type="primary" @click="showVitalSignsModal('create')" :loading="loading" :disabled="!editorReady">创建体温单</a-button>
8
- <a-button plain type="primary" @click="showVitalSignsModal('update')" :loading="loading" :disabled="!editorReady">更新体温单</a-button>
9
- </a-button-group>
10
- <a-button-group style="margin: 0 20px;">
11
- <a-button plain type="primary" @click="showVitalSignsModal('baby')" :loading="loading" :disabled="!editorReady">新生儿体温单</a-button>
12
- </a-button-group>
13
- <a-button-group style="margin: 0 20px;">
14
- <a-button plain type="primary" @click="execCommand('preview')" :loading="loading" :disabled="!editorReady">打印预览</a-button>
15
- <a-button plain type="primary" @click="execCommand('print')" :loading="loading" :disabled="!editorReady">打印</a-button>
16
- </a-button-group>
17
- <!-- 修改清空体温单按钮样式,使其更加醒目 -->
18
- <a-button type="primary"
19
- danger
20
- @click="clearVitalSigns"
21
- :loading="loading"
22
- :disabled="!editorReady"
23
- style="margin-left: 10px;">
24
- <a-icon type="delete" /> 清空体温单
25
- </a-button>
26
- </a-row>
27
- <div v-if="!editorReady" style="margin: 10px 0; padding: 10px; background-color: #fffbe6; border: 1px solid #ffe58f;">
28
- <a-icon type="loading" /> 体温单编辑器加载中...
29
- </div>
30
-
31
- <!-- 添加体温单生成加载遮罩 -->
32
- <div v-if="generating" class="generating-mask">
33
- <div class="generating-content">
34
- <a-spin size="large" />
35
- <div class="generating-text">体温单生成中,请稍候...</div>
36
- </div>
37
- </div>
38
-
39
- <Editor @editor-ready="onEditorReady" style="margin: 10px 0;" ref="editorComponent"></Editor>
40
-
41
- <!-- 使用TextBox组件替代原有弹窗 -->
42
- <TextBox
43
- :visible="modalVisible"
44
- :modalType="modalType"
45
- :initialId="vitalSignsId"
46
- :editorReady="editorReady"
47
- :id="Number(vitalSignsId) || 180"
48
- @submit="handleSubmit"
49
- @cancel="closeModal"
50
- />
51
- </div>
52
- </template>
53
-
54
- <script setup>
55
- import { ref, onMounted } from 'vue'
56
- import Editor from './editor.vue'
57
- import TextBox from './textBox.vue'
58
- import { message } from 'ant-design-vue'
59
-
60
- // 响应式状态
61
- const vitalSignsId = ref('')
62
- const loading = ref(false)
63
- const editorReady = ref(false)
64
- const editorComponent = ref(null)
65
- const modalVisible = ref(false)
66
- const modalType = ref('create')
67
- const generating = ref(false) // 添加体温单生成中状态
68
- let editor = null
69
- // 定义组件事件
70
- const emit = defineEmits(['submit'])
71
- // 常量
72
- const modalTitles = {
73
- create: '创建体温单',
74
- update: '更新体温单',
75
- baby: '新生儿体温单'
76
- }
77
-
78
- // 显示弹窗
79
- const showVitalSignsModal = (type) => {
80
- modalType.value = type
81
- modalVisible.value = true
82
- }
83
-
84
- // 关闭弹窗
85
- const closeModal = () => {
86
- modalVisible.value = false
87
- }
88
-
89
- // 编辑器初始化
90
- const onEditorReady = (editorObj) => {
91
- try {
92
- if (!editorObj) {
93
- throw new Error('传入的editor对象为null或undefined')
94
- }
95
-
96
- // 尝试获取编辑器对象
97
- if (typeof editorObj.createVitalSigns === 'function') {
98
- editor = editorObj
99
- } else if (editorObj.getEditor && typeof editorObj.getEditor === 'function') {
100
- const editorFromComponent = editorObj.getEditor()
101
- editor = editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function'
102
- ? editorFromComponent
103
- : (typeof editorObj.createVitalSigns === 'function' ? editorObj : null)
104
- }
105
- if (!editor) {
106
- throw new Error('无法获取有效的editor对象')
107
- }
108
- editorReady.value = true
109
- } catch (err) {
110
- console.error('设置editor对象失败:', err)
111
- message.error('体温单编辑器初始化失败,请刷新页面重试')
112
- }
113
- }
114
-
115
- // 执行命令
116
- const execCommand = (cmd) => {
117
- if (!editorReady.value || !editor) return
118
- loading.value = true
119
- try {
120
- editor.execCommand(cmd)
121
- } catch (err) {
122
- console.error('执行命令出错:', err)
123
- message.error(`执行${cmd}命令失败`)
124
- } finally {
125
- loading.value = false
126
- }
127
- }
128
-
129
- // 清空体温单
130
- const clearVitalSigns = async () => {
131
- if (!editorReady.value || !editor) {
132
- message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
133
- return
134
- }
135
-
136
- loading.value = true
137
- generating.value = true
138
-
139
- try {
140
- // 重新加载editor.html页面来完全重置编辑器
141
- try {
142
- const iframe = editorComponent.value.$refs.editorIframe
143
- if (iframe) {
144
- // 保存当前src
145
- const currentSrc = iframe.src
146
- // 确认提示
147
- message.loading('正在清空体温单...', 1)
148
- // 重新加载iframe
149
- iframe.onload = async () => {
150
- try {
151
- // 等待iframe重新加载完成
152
- await new Promise(resolve => setTimeout(resolve, 500))
153
-
154
- // 获取新的editor对象
155
- const newEditorObj = iframe.contentWindow.editor
156
- if (newEditorObj) {
157
- // 等待editor初始化
158
- if (typeof newEditorObj.init === 'function') {
159
- await new Promise((resolve) => {
160
- const checkInterval = setInterval(() => {
161
- if (newEditorObj.isReady) {
162
- clearInterval(checkInterval)
163
- resolve()
164
- }
165
- }, 100)
166
-
167
- // 最多等待5秒
168
- setTimeout(() => {
169
- clearInterval(checkInterval)
170
- resolve()
171
- }, 5000)
172
- })
173
- }
174
-
175
- // 更新全局editor引用
176
- editor = newEditorObj
177
- window.iframeEditor = newEditorObj
178
- } else {
179
- throw new Error('重新加载后无法获取editor对象')
180
- }
181
- } catch (err) {
182
- console.error('重新加载iframe后清空体温单出错:', err)
183
- message.error(`清空体温单失败: ${err.message || '未知错误'}`)
184
- } finally {
185
- loading.value = false
186
- generating.value = false
187
- // 移除临时onload处理器
188
- iframe.onload = null
189
- }
190
- }
191
-
192
- // 重新加载iframe
193
- iframe.src = currentSrc + '?t=' + new Date().getTime()
194
- return
195
- }
196
- } catch (reloadErr) {
197
- console.warn('重新加载iframe失败,将尝试其他方法清空体温单:', reloadErr)
198
- }
199
-
200
- // 备用清空方法
201
- try {
202
- const iframe = editorComponent.value.$refs.editorIframe
203
- if (iframe?.contentWindow) {
204
- iframe.contentWindow.eval(`
205
- try {
206
- // 尝试使用编辑器提供的各种可能的清空方法
207
- if (editor) {
208
- if (typeof editor.loadUrl === 'function') {
209
- editor.loadUrl('');
210
- } else if (typeof editor.resetDocument === 'function') {
211
- editor.resetDocument();
212
- } else if (typeof editor.clearContent === 'function') {
213
- editor.clearContent();
214
- } else if (typeof editor.clear === 'function') {
215
- editor.clear();
216
- } else if (typeof editor.setEditorContent === 'function') {
217
- editor.setEditorContent('');
218
- } else if (editor.document) {
219
- try {
220
- editor.document.body.innerHTML = '';
221
- } catch(clearErr) {
222
- console.warn('清空编辑器内容失败');
223
- }
224
- }
225
- }
226
- } catch(e) {
227
- console.error('清空体温单失败:', e);
228
- }
229
- `)
230
- } else if (window.iframeEditor) {
231
- const editorObj = window.iframeEditor
232
- if (typeof editorObj.loadUrl === 'function') {
233
- editorObj.loadUrl('')
234
- } else if (typeof editorObj.resetDocument === 'function') {
235
- editorObj.resetDocument()
236
- } else if (typeof editorObj.clearContent === 'function') {
237
- editorObj.clearContent()
238
- } else if (typeof editorObj.clear === 'function') {
239
- editorObj.clear()
240
- } else if (typeof editorObj.setEditorContent === 'function') {
241
- editorObj.setEditorContent('')
242
- }
243
- } else if (editor) {
244
- if (typeof editor.loadUrl === 'function') {
245
- editor.loadUrl('')
246
- } else if (typeof editor.resetDocument === 'function') {
247
- editor.resetDocument()
248
- } else if (typeof editor.clearContent === 'function') {
249
- editor.clearContent()
250
- } else if (typeof editor.clear === 'function') {
251
- editor.clear()
252
- } else if (typeof editor.setEditorContent === 'function') {
253
- editor.setEditorContent('')
254
- }
255
- } else {
256
- throw new Error('无法获取编辑器对象')
257
- }
258
- } catch (err) {
259
- console.error('清空体温单出错:', err)
260
- message.error(`清空体温单失败: ${err.message || '未知错误'}`)
261
- }
262
- } finally {
263
- loading.value = false
264
- generating.value = false
265
- }
266
- }
267
-
268
- // 处理表单提交(修改为直接叠加创建,无需清空)
269
- const handleSubmit = async (formData) => {
270
- if (!editorReady.value || !editor) {
271
- message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
272
- return
273
- }
274
- loading.value = true
275
- generating.value = true // 开始生成,显示加载遮罩
276
-
277
- try {
278
- // 简化代码,直接在现有体温单上创建新的体温单(不再清空)
279
- let result
280
- try {
281
- const iframe = editorComponent.value.$refs.editorIframe
282
- if (iframe?.contentWindow) {
283
- const dataStr = JSON.stringify(formData)
284
- const script = `
285
- try {
286
- const data = JSON.parse('${dataStr.replace(/'/g, "\\'")}');
287
- return editor.createVitalSigns(data);
288
- } catch(e) {
289
- console.error('iframe执行错误:', e);
290
- return null;
291
- }
292
- `
293
- result = iframe.contentWindow.eval(script)
294
- } else if (window.iframeEditor) {
295
- result = window.iframeEditor.createVitalSigns(formData)
296
- } else {
297
- throw new Error('无法访问iframe')
298
- }
299
- } catch (err) {
300
- // 备用方案
301
- if (editor && typeof editor.createVitalSigns === 'function') {
302
- result = editor.createVitalSigns(formData)
303
- } else {
304
- throw new Error('无法调用createVitalSigns方法')
305
- }
306
- }
307
-
308
- vitalSignsId.value = result || formData.id
309
- modalVisible.value = false
310
- message.success(`${modalTitles[modalType.value]}成功`)
311
- emit('submit', formData)
312
- } catch (err) {
313
- console.error('创建体温单出错:', err)
314
- message.error(`创建体温单失败: ${err.message || '未知错误'}`)
315
- } finally {
316
- loading.value = false
317
- generating.value = false // 无论成功失败,都结束加载遮罩
318
- }
319
- }
320
-
321
- // 生命周期钩子
322
- onMounted(() => {
323
- window.addEventListener('message', (event) => {
324
- if (event.data?.type === 'editorReady' && !editorReady.value && editorComponent.value?.getEditor) {
325
- try {
326
- const editorFromComponent = editorComponent.value.getEditor()
327
- if (editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function') {
328
- editor = editorFromComponent
329
- editorReady.value = true
330
- }
331
- } catch (err) {
332
- console.error('从组件获取editor对象错误:', err)
333
- }
334
- }
335
- })
336
- })
337
- </script>
338
-
339
- <style scoped>
340
- .box {
341
- display: flex;
342
- align-items: center;
343
- padding: 1%;
344
- }
345
-
346
- /* 体温单生成加载遮罩样式 */
347
- .generating-mask {
348
- position: fixed;
349
- top: 0;
350
- left: 0;
351
- right: 0;
352
- bottom: 0;
353
- background-color: rgba(0, 0, 0, 0.5);
354
- display: flex;
355
- justify-content: center;
356
- align-items: center;
357
- z-index: 9999;
358
- }
359
-
360
- .generating-content {
361
- background-color: white;
362
- padding: 20px 40px;
363
- border-radius: 4px;
364
- text-align: center;
365
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
366
- }
367
-
368
- .generating-text {
369
- margin-top: 16px;
370
- color: rgba(0, 0, 0, 0.85);
371
- font-size: 16px;
372
- }
373
- </style>
1
+ <template>
2
+ <!-- <Source src="/code/VitalSigns.vue"></Source>-->
3
+ <div>
4
+ <a-row class="box">
5
+ 病历号&nbsp;&nbsp;<a-input v-model="vitalSignsId" style="width: 160px"></a-input>
6
+ <a-button-group style="margin-left: 20px;">
7
+ <a-button plain type="primary" @click="showVitalSignsModal('create')" :loading="loading" :disabled="!editorReady">创建体温单</a-button>
8
+ <a-button plain type="primary" @click="showVitalSignsModal('update')" :loading="loading" :disabled="!editorReady">更新体温单</a-button>
9
+ </a-button-group>
10
+ <a-button-group style="margin: 0 20px;">
11
+ <a-button plain type="primary" @click="showVitalSignsModal('baby')" :loading="loading" :disabled="!editorReady">新生儿体温单</a-button>
12
+ </a-button-group>
13
+ <a-button-group style="margin: 0 20px;">
14
+ <a-button plain type="primary" @click="execCommand('preview')" :loading="loading" :disabled="!editorReady">打印预览</a-button>
15
+ <a-button plain type="primary" @click="execCommand('print')" :loading="loading" :disabled="!editorReady">打印</a-button>
16
+ </a-button-group>
17
+ <!-- 修改清空体温单按钮样式,使其更加醒目 -->
18
+ <a-button type="primary"
19
+ danger
20
+ @click="clearVitalSigns"
21
+ :loading="loading"
22
+ :disabled="!editorReady"
23
+ style="margin-left: 10px;">
24
+ <a-icon type="delete" /> 清空体温单
25
+ </a-button>
26
+ </a-row>
27
+ <div v-if="!editorReady" style="margin: 10px 0; padding: 10px; background-color: #fffbe6; border: 1px solid #ffe58f;">
28
+ <a-icon type="loading" /> 体温单编辑器加载中...
29
+ </div>
30
+
31
+ <!-- 添加体温单生成加载遮罩 -->
32
+ <div v-if="generating" class="generating-mask">
33
+ <div class="generating-content">
34
+ <a-spin size="large" />
35
+ <div class="generating-text">体温单生成中,请稍候...</div>
36
+ </div>
37
+ </div>
38
+
39
+ <Editor @editor-ready="onEditorReady" style="margin: 10px 0;" ref="editorComponent"></Editor>
40
+
41
+ <!-- 使用TextBox组件替代原有弹窗 -->
42
+ <TextBox
43
+ :visible="modalVisible"
44
+ :modalType="modalType"
45
+ :editorReady="editorReady"
46
+ :id="Number(vitalSignsId) || 180"
47
+ @submit="handleSubmit"
48
+ @cancel="closeModal"
49
+ />
50
+ </div>
51
+ </template>
52
+
53
+ <script setup>
54
+ import { ref, onMounted } from 'vue'
55
+ import Editor from './editor.vue'
56
+ import TextBox from './textBox.vue'
57
+ import { message } from 'ant-design-vue'
58
+
59
+ // 响应式状态
60
+ const vitalSignsId = ref(null)
61
+ const loading = ref(false)
62
+ const editorReady = ref(false)
63
+ const editorComponent = ref(null)
64
+ const modalVisible = ref(false)
65
+ const modalType = ref('create')
66
+ const generating = ref(false) // 添加体温单生成中状态
67
+ let editor = null
68
+ // 定义组件事件
69
+ const emit = defineEmits(['submit'])
70
+ // 常量
71
+ const modalTitles = {
72
+ create: '创建体温单',
73
+ update: '更新体温单',
74
+ baby: '新生儿体温单'
75
+ }
76
+
77
+ // 显示弹窗
78
+ const showVitalSignsModal = (type) => {
79
+ modalType.value = type
80
+ modalVisible.value = true
81
+ }
82
+
83
+ // 关闭弹窗
84
+ const closeModal = () => {
85
+ modalVisible.value = false
86
+ }
87
+
88
+ // 编辑器初始化
89
+ const onEditorReady = (editorObj) => {
90
+ try {
91
+ if (!editorObj) {
92
+ throw new Error('传入的editor对象为null或undefined')
93
+ }
94
+
95
+ // 尝试获取编辑器对象
96
+ if (typeof editorObj.createVitalSigns === 'function') {
97
+ editor = editorObj
98
+ } else if (editorObj.getEditor && typeof editorObj.getEditor === 'function') {
99
+ const editorFromComponent = editorObj.getEditor()
100
+ editor = editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function'
101
+ ? editorFromComponent
102
+ : (typeof editorObj.createVitalSigns === 'function' ? editorObj : null)
103
+ }
104
+ if (!editor) {
105
+ throw new Error('无法获取有效的editor对象')
106
+ }
107
+ editorReady.value = true
108
+ } catch (err) {
109
+ console.error('设置editor对象失败:', err)
110
+ message.error('体温单编辑器初始化失败,请刷新页面重试')
111
+ }
112
+ }
113
+
114
+ // 执行命令
115
+ const execCommand = (cmd) => {
116
+ if (!editorReady.value || !editor) return
117
+ loading.value = true
118
+ try {
119
+ editor.execCommand(cmd)
120
+ } catch (err) {
121
+ console.error('执行命令出错:', err)
122
+ message.error(`执行${cmd}命令失败`)
123
+ } finally {
124
+ loading.value = false
125
+ }
126
+ }
127
+
128
+ // 清空体温单
129
+ const clearVitalSigns = async () => {
130
+ if (!editorReady.value || !editor) {
131
+ message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
132
+ return
133
+ }
134
+
135
+ loading.value = true
136
+ generating.value = true
137
+
138
+ try {
139
+ // 重新加载editor.html页面来完全重置编辑器
140
+ try {
141
+ const iframe = editorComponent.value.$refs.editorIframe
142
+ if (iframe) {
143
+ // 保存当前src
144
+ const currentSrc = iframe.src
145
+ // 确认提示
146
+ message.loading('正在清空体温单...', 1)
147
+ // 重新加载iframe
148
+ iframe.onload = async () => {
149
+ try {
150
+ // 等待iframe重新加载完成
151
+ await new Promise(resolve => setTimeout(resolve, 500))
152
+
153
+ // 获取新的editor对象
154
+ const newEditorObj = iframe.contentWindow.editor
155
+ if (newEditorObj) {
156
+ // 等待editor初始化
157
+ if (typeof newEditorObj.init === 'function') {
158
+ await new Promise((resolve) => {
159
+ const checkInterval = setInterval(() => {
160
+ if (newEditorObj.isReady) {
161
+ clearInterval(checkInterval)
162
+ resolve()
163
+ }
164
+ }, 100)
165
+
166
+ // 最多等待5秒
167
+ setTimeout(() => {
168
+ clearInterval(checkInterval)
169
+ resolve()
170
+ }, 5000)
171
+ })
172
+ }
173
+
174
+ // 更新全局editor引用
175
+ editor = newEditorObj
176
+ window.iframeEditor = newEditorObj
177
+ } else {
178
+ throw new Error('重新加载后无法获取editor对象')
179
+ }
180
+ } catch (err) {
181
+ console.error('重新加载iframe后清空体温单出错:', err)
182
+ message.error(`清空体温单失败: ${err.message || '未知错误'}`)
183
+ } finally {
184
+ loading.value = false
185
+ generating.value = false
186
+ // 移除临时onload处理器
187
+ iframe.onload = null
188
+ }
189
+ }
190
+
191
+ // 重新加载iframe
192
+ iframe.src = currentSrc + '?t=' + new Date().getTime()
193
+ return
194
+ }
195
+ } catch (reloadErr) {
196
+ console.warn('重新加载iframe失败,将尝试其他方法清空体温单:', reloadErr)
197
+ }
198
+
199
+ // 备用清空方法
200
+ try {
201
+ const iframe = editorComponent.value.$refs.editorIframe
202
+ if (iframe?.contentWindow) {
203
+ iframe.contentWindow.eval(`
204
+ try {
205
+ // 尝试使用编辑器提供的各种可能的清空方法
206
+ if (editor) {
207
+ if (typeof editor.loadUrl === 'function') {
208
+ editor.loadUrl('');
209
+ } else if (typeof editor.resetDocument === 'function') {
210
+ editor.resetDocument();
211
+ } else if (typeof editor.clearContent === 'function') {
212
+ editor.clearContent();
213
+ } else if (typeof editor.clear === 'function') {
214
+ editor.clear();
215
+ } else if (typeof editor.setEditorContent === 'function') {
216
+ editor.setEditorContent('');
217
+ } else if (editor.document) {
218
+ try {
219
+ editor.document.body.innerHTML = '';
220
+ } catch(clearErr) {
221
+ console.warn('清空编辑器内容失败');
222
+ }
223
+ }
224
+ }
225
+ } catch(e) {
226
+ console.error('清空体温单失败:', e);
227
+ }
228
+ `)
229
+ } else if (window.iframeEditor) {
230
+ const editorObj = window.iframeEditor
231
+ if (typeof editorObj.loadUrl === 'function') {
232
+ editorObj.loadUrl('')
233
+ } else if (typeof editorObj.resetDocument === 'function') {
234
+ editorObj.resetDocument()
235
+ } else if (typeof editorObj.clearContent === 'function') {
236
+ editorObj.clearContent()
237
+ } else if (typeof editorObj.clear === 'function') {
238
+ editorObj.clear()
239
+ } else if (typeof editorObj.setEditorContent === 'function') {
240
+ editorObj.setEditorContent('')
241
+ }
242
+ } else if (editor) {
243
+ if (typeof editor.loadUrl === 'function') {
244
+ editor.loadUrl('')
245
+ } else if (typeof editor.resetDocument === 'function') {
246
+ editor.resetDocument()
247
+ } else if (typeof editor.clearContent === 'function') {
248
+ editor.clearContent()
249
+ } else if (typeof editor.clear === 'function') {
250
+ editor.clear()
251
+ } else if (typeof editor.setEditorContent === 'function') {
252
+ editor.setEditorContent('')
253
+ }
254
+ } else {
255
+ throw new Error('无法获取编辑器对象')
256
+ }
257
+ } catch (err) {
258
+ console.error('清空体温单出错:', err)
259
+ message.error(`清空体温单失败: ${err.message || '未知错误'}`)
260
+ }
261
+ } finally {
262
+ loading.value = false
263
+ generating.value = false
264
+ }
265
+ }
266
+ // 处理表单提交
267
+ const handleSubmit = async (formData) => {
268
+ if (!editorReady.value || !editor) {
269
+ message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
270
+ return
271
+ }
272
+ loading.value = true
273
+ generating.value = true // 开始生成,显示加载遮罩
274
+ try {
275
+ // 简化代码,直接在现有体温单上创建新的体温单(不再清空)
276
+ let result
277
+ try {
278
+ const iframe = editorComponent.value.$refs.editorIframe
279
+ if (iframe?.contentWindow) {
280
+ const dataStr = JSON.stringify(formData)
281
+ const script = `
282
+ try {
283
+ const data = JSON.parse('${dataStr.replace(/'/g, "\\'")}');
284
+ return editor.createVitalSigns(data);
285
+ } catch(e) {
286
+ console.error('iframe执行错误:', e);
287
+ return null;
288
+ }
289
+ `
290
+ result = iframe.contentWindow.eval(script)
291
+ } else if (window.iframeEditor) {
292
+ result = window.iframeEditor.createVitalSigns(formData)
293
+ } else {
294
+ throw new Error('无法访问iframe')
295
+ }
296
+ } catch (err) {
297
+ // 备用方案
298
+ if (editor && typeof editor.createVitalSigns === 'function') {
299
+ result = editor.createVitalSigns(formData)
300
+ } else {
301
+ throw new Error('无法调用createVitalSigns方法')
302
+ }
303
+ }
304
+
305
+ vitalSignsId.value = result || formData.id
306
+ modalVisible.value = false
307
+ message.success(`${modalTitles[modalType.value]}成功`)
308
+ emit('submit', formData)
309
+ } catch (err) {
310
+ console.error('创建体温单出错:', err)
311
+ message.error(`创建体温单失败: ${err.message || '未知错误'}`)
312
+ } finally {
313
+ loading.value = false
314
+ generating.value = false // 无论成功失败,都结束加载遮罩
315
+ }
316
+ }
317
+
318
+ // 生命周期钩子
319
+ onMounted(() => {
320
+ window.addEventListener('message', (event) => {
321
+ if (event.data?.type === 'editorReady' && !editorReady.value && editorComponent.value?.getEditor) {
322
+ try {
323
+ const editorFromComponent = editorComponent.value.getEditor()
324
+ if (editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function') {
325
+ editor = editorFromComponent
326
+ editorReady.value = true
327
+ }
328
+ } catch (err) {
329
+ console.error('从组件获取editor对象错误:', err)
330
+ }
331
+ }
332
+ })
333
+ })
334
+
335
+ // 暴露方法和属性给父组件,使父组件可以通过ref访问
336
+ defineExpose({
337
+ // 属性
338
+ vitalSignsId,
339
+ // 方法
340
+ clearVitalSigns,
341
+ showVitalSignsModal,
342
+ execCommand,
343
+ // 获取当前体温单ID的方法
344
+ getVitalSignsId: () => vitalSignsId.value,
345
+ // 设置体温单ID的方法
346
+ setVitalSignsId: (id) => {
347
+ vitalSignsId.value = id
348
+ }
349
+ })
350
+ </script>
351
+
352
+ <style scoped>
353
+ .box {
354
+ display: flex;
355
+ align-items: center;
356
+ padding: 1%;
357
+ }
358
+
359
+ /* 体温单生成加载遮罩样式 */
360
+ .generating-mask {
361
+ position: fixed;
362
+ top: 0;
363
+ left: 0;
364
+ right: 0;
365
+ bottom: 0;
366
+ background-color: rgba(0, 0, 0, 0.5);
367
+ display: flex;
368
+ justify-content: center;
369
+ align-items: center;
370
+ z-index: 9999;
371
+ }
372
+
373
+ .generating-content {
374
+ background-color: white;
375
+ padding: 20px 40px;
376
+ border-radius: 4px;
377
+ text-align: center;
378
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
379
+ }
380
+
381
+ .generating-text {
382
+ margin-top: 16px;
383
+ color: rgba(0, 0, 0, 0.85);
384
+ font-size: 16px;
385
+ }
386
+ </style>