vue2-client 1.16.22 → 1.16.23

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,481 +1,482 @@
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
8
- v-if="showCreateButton"
9
- plain
10
- type="primary"
11
- @click="showVitalSignsModal('create')"
12
- :loading="loading"
13
- :disabled="!editorReady">创建体温单</a-button>
14
- <a-button
15
- v-if="showUpdateButton"
16
- plain
17
- type="primary"
18
- @click="showVitalSignsModal('update')"
19
- :loading="loading"
20
- :disabled="!editorReady">更新体温单</a-button>
21
- </a-button-group>
22
- <a-button-group v-if="showClearButton" style="margin: 0 20px;">
23
- <a-button plain type="primary" @click="execCommand('print')" :loading="loading" :disabled="!editorReady">打印</a-button>
24
- </a-button-group>
25
- <!-- 修改清空体温单按钮样式,使其更加醒目 -->
26
- <a-button
27
- type="primary"
28
- danger
29
- v-if="showClearButton"
30
- @click="clearVitalSigns"
31
- :loading="loading"
32
- :disabled="!editorReady"
33
- style="margin-left: 10px;">
34
- <a-icon type="delete" /> 清空体温单
35
- </a-button>
36
- </a-row>
37
- <div v-if="!editorReady" style="margin: 10px 0; padding: 10px; background-color: #fffbe6; border: 1px solid #ffe58f;">
38
- <a-icon type="loading" /> 体温单编辑器加载中...
39
- </div>
40
-
41
- <!-- 添加体温单生成加载遮罩 -->
42
- <div v-if="generating" class="generating-mask">
43
- <div class="generating-content">
44
- <a-spin size="large" />
45
- <div class="generating-text">体温单生成中,请稍候...</div>
46
- </div>
47
- </div>
48
-
49
- <Editor @editor-ready="onEditorReady" style="margin: 10px 0;" ref="editorComponent"></Editor>
50
-
51
- <!-- 使用TextBox组件替代原有弹窗 -->
52
- <TextBox
53
- :visible="modalVisible"
54
- :modalType="modalType"
55
- :editorReady="editorReady"
56
- :id="Number(vitalSignsId) || 180"
57
- @submit="handleSubmit"
58
- @cancel="closeModal"
59
- />
60
- </div>
61
- </template>
62
-
63
- <script setup>
64
- import { ref, onMounted } from 'vue'
65
- import Editor from './editor.vue'
66
- import TextBox from './textBox.vue'
67
- import { message } from 'ant-design-vue'
68
-
69
- // 响应式状态
70
- const vitalSignsId = ref(null)
71
- const loading = ref(false)
72
- const editorReady = ref(false)
73
- const editorComponent = ref(null)
74
- const modalVisible = ref(false)
75
- const modalType = ref('create')
76
- const generating = ref(false) // 添加体温单生成中状态
77
- let editor = null
78
- // 定义组件事件
79
- const emit = defineEmits(['submit'])
80
- // 常量
81
- const modalTitles = {
82
- create: '创建体温单',
83
- update: '更新体温单'
84
- }
85
-
86
- // 接受父组件传递的属性
87
- defineProps({
88
- showCreateButton: {
89
- type: Boolean,
90
- default: false
91
- },
92
- showUpdateButton: {
93
- type: Boolean,
94
- default: false
95
- },
96
- // 添加打印按钮是否显示属性
97
- showPrintButton: {
98
- type: Boolean,
99
- default: false
100
- },
101
- showClearButton: {
102
- type: Boolean,
103
- default: false
104
- },
105
- // 时间模式 -2 ~ 2
106
- adjustHour: {
107
- type: Number,
108
- default: 0
109
- }
110
- })
111
-
112
- // 显示弹窗
113
- function showVitalSignsModal (type) {
114
- modalType.value = type
115
- modalVisible.value = true
116
- }
117
-
118
- // 关闭弹窗
119
- function closeModal () {
120
- modalVisible.value = false
121
- }
122
-
123
- // 编辑器初始化
124
- function onEditorReady (editorObj) {
125
- try {
126
- if (!editorObj) {
127
- throw new Error('传入的editor对象为null或undefined')
128
- }
129
-
130
- // 尝试获取编辑器对象
131
- if (typeof editorObj.createVitalSigns === 'function') {
132
- editor = editorObj
133
- } else if (editorObj.getEditor && typeof editorObj.getEditor === 'function') {
134
- const editorFromComponent = editorObj.getEditor()
135
- editor = editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function'
136
- ? editorFromComponent
137
- : (typeof editorObj.createVitalSigns === 'function' ? editorObj : null)
138
- }
139
- if (!editor) {
140
- throw new Error('无法获取有效的editor对象')
141
- }
142
- editorReady.value = true
143
- } catch (err) {
144
- console.error('设置editor对象失败:', err)
145
- message.error('体温单编辑器初始化失败,请刷新页面重试')
146
- }
147
- }
148
-
149
- // 执行命令
150
- function execCommand (cmd) {
151
- if (!editorReady.value || !editor) return
152
- loading.value = true
153
- try {
154
- editor.execCommand(cmd)
155
- } catch (err) {
156
- console.error('执行命令出错:', err)
157
- message.error(`执行${cmd}命令失败`)
158
- } finally {
159
- loading.value = false
160
- }
161
- }
162
-
163
- // 清空体温单
164
- async function clearVitalSigns () {
165
- if (!editorReady.value || !editor) {
166
- message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
167
- return
168
- }
169
- loading.value = true
170
- generating.value = true
171
- try {
172
- // 重新加载editor.html页面来完全重置编辑器
173
- try {
174
- const iframe = editorComponent.value.$refs.editorIframe
175
- if (iframe) {
176
- // 保存当前src
177
- const currentSrc = iframe.src
178
- // 确认提示
179
- message.loading('正在清空体温单...', 1)
180
- // 重新加载iframe
181
- iframe.onload = async () => {
182
- try {
183
- // 等待iframe重新加载完成
184
- await new Promise(resolve => setTimeout(resolve, 500))
185
- // 获取新的editor对象
186
- const newEditorObj = iframe.contentWindow.editor
187
- if (newEditorObj) {
188
- // 等待editor初始化
189
- if (typeof newEditorObj.init === 'function') {
190
- await new Promise((resolve) => {
191
- const checkInterval = setInterval(() => {
192
- if (newEditorObj.isReady) {
193
- clearInterval(checkInterval)
194
- resolve()
195
- }
196
- }, 100)
197
- // 最多等待5秒
198
- setTimeout(() => {
199
- clearInterval(checkInterval)
200
- resolve()
201
- }, 5000)
202
- })
203
- }
204
- // 更新全局editor引用
205
- editor = newEditorObj
206
- window.iframeEditor = newEditorObj
207
- } else {
208
- throw new Error('重新加载后无法获取editor对象')
209
- }
210
- } catch (err) {
211
- console.error('重新加载iframe后清空体温单出错:', err)
212
- message.error(`清空体温单失败: ${err.message || '未知错误'}`)
213
- } finally {
214
- loading.value = false
215
- generating.value = false
216
- // 移除临时onload处理器
217
- iframe.onload = null
218
- }
219
- }
220
- // 重新加载iframe
221
- iframe.src = currentSrc + '?t=' + new Date().getTime()
222
- return
223
- }
224
- } catch (reloadErr) {
225
- console.warn('重新加载iframe失败,将尝试其他方法清空体温单:', reloadErr)
226
- }
227
- // 备用清空方法
228
- try {
229
- const iframe = editorComponent.value.$refs.editorIframe
230
- if (iframe?.contentWindow) {
231
- iframe.contentWindow.eval(`
232
- try {
233
- // 尝试使用编辑器提供的各种可能的清空方法
234
- if (editor) {
235
- if (typeof editor.loadUrl === 'function') {
236
- editor.loadUrl('');
237
- } else if (typeof editor.resetDocument === 'function') {
238
- editor.resetDocument();
239
- } else if (typeof editor.clearContent === 'function') {
240
- editor.clearContent();
241
- } else if (typeof editor.clear === 'function') {
242
- editor.clear();
243
- } else if (typeof editor.setEditorContent === 'function') {
244
- editor.setEditorContent('');
245
- } else if (editor.document) {
246
- try {
247
- editor.document.body.innerHTML = '';
248
- } catch(clearErr) {
249
- console.warn('清空编辑器内容失败');
250
- }
251
- }
252
- }
253
- } catch(e) {
254
- console.error('清空体温单失败:', e);
255
- }
256
- `)
257
- } else if (window.iframeEditor) {
258
- const editorObj = window.iframeEditor
259
- if (typeof editorObj.loadUrl === 'function') {
260
- editorObj.loadUrl('')
261
- } else if (typeof editorObj.resetDocument === 'function') {
262
- editorObj.resetDocument()
263
- } else if (typeof editorObj.clearContent === 'function') {
264
- editorObj.clearContent()
265
- } else if (typeof editorObj.clear === 'function') {
266
- editorObj.clear()
267
- } else if (typeof editorObj.setEditorContent === 'function') {
268
- editorObj.setEditorContent('')
269
- }
270
- } else if (editor) {
271
- if (typeof editor.loadUrl === 'function') {
272
- editor.loadUrl('')
273
- } else if (typeof editor.resetDocument === 'function') {
274
- editor.resetDocument()
275
- } else if (typeof editor.clearContent === 'function') {
276
- editor.clearContent()
277
- } else if (typeof editor.clear === 'function') {
278
- editor.clear()
279
- } else if (typeof editor.setEditorContent === 'function') {
280
- editor.setEditorContent('')
281
- }
282
- } else {
283
- throw new Error('无法获取编辑器对象')
284
- }
285
- } catch (err) {
286
- console.error('清空体温单出错:', err)
287
- message.error(`清空体温单失败: ${err.message || '未知错误'}`)
288
- }
289
- } finally {
290
- loading.value = false
291
- generating.value = false
292
- }
293
- }
294
-
295
- // 处理表单提交
296
- async function handleSubmit (formData) {
297
- console.log('表单数据:', formData)
298
- if (!editorReady.value || !editor) {
299
- message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
300
- return
301
- }
302
- loading.value = true
303
- generating.value = true // 开始生成,显示加载遮罩
304
- try {
305
- let result
306
- try {
307
- const iframe = editorComponent.value.$refs.editorIframe
308
- if (iframe?.contentWindow) {
309
- // 直接传递数据对象,避免使用eval
310
- if (iframe.contentWindow.editor && typeof iframe.contentWindow.editor.createVitalSigns === 'function') {
311
- result = iframe.contentWindow.editor.createVitalSigns(formData)
312
- } else {
313
- throw new Error('编辑器对象无效')
314
- }
315
- } else if (window.iframeEditor) {
316
- result = window.iframeEditor.createVitalSigns(formData)
317
- } else {
318
- throw new Error('无法访问iframe')
319
- }
320
- } catch (err) {
321
- // 备用方案
322
- if (editor && typeof editor.createVitalSigns === 'function') {
323
- editor.createVitalSigns(formData)
324
- } else {
325
- throw new Error('无法调用createVitalSigns方法')
326
- }
327
- }
328
-
329
- vitalSignsId.value = result || formData.id
330
- modalVisible.value = false
331
- message.success(`${modalTitles[modalType.value]}成功`)
332
- emit('submit', formData)
333
- } catch (err) {
334
- console.error('创建体温单出错:', err)
335
- message.error(`创建体温单失败: ${err.message || '未知错误'}`)
336
- } finally {
337
- loading.value = false
338
- generating.value = false // 无论成功失败,都结束加载遮罩
339
- }
340
- }
341
-
342
- // 处理表单数据
343
- function mergeAndTransformData (records, patientInfo, id, date, operateDate) {
344
- // 提取records中的数据
345
- const temperatureList = records.map(record => record.temperature).join(',')
346
- const sphygmusList = records.map(record => record.sphygmus).join(',')
347
- const breathList = records.map(record => record.breath).join(',')
348
- const heartList = records.map(record => record.heart).join(',')
349
- const notesList = records.map(record => record.notes).join(',')
350
- const painList = records.map(record => record.pain).join(',')
351
- const data1List = records.map(record => {
352
- const [systolic, diastolic] = record.data1.split('|')
353
- return `${systolic}/${diastolic}`
354
- }).join(',')
355
- const data2List = records.map(record => record.data2).join(',')
356
- const data3List = records.map(record => record.data3).join(',')
357
- const data4List = records.map(record => record.data4).join(',')
358
- const data5List = records.map(record => record.data5).join(',')
359
- const data6List = records.map(record => record.data6).join(',')
360
- const data7List = records.map(record => record.data7).join(',')
361
- const tempTypeList = records.map(record => record.temptype).join(',')
362
-
363
- // 提取patientInfo中的数据
364
- const name = patientInfo.name || ''
365
- const dept = patientInfo.dept || ''
366
- const bed = patientInfo.bed || ''
367
- const inDate = patientInfo.indate || ''
368
- const diag = patientInfo.diag || ''
369
-
370
- // 生成合并后的对象
371
- const mergedData = {
372
- bed: bed.toString(),
373
- sphygmus: sphygmusList,
374
- notes: notesList,
375
- medicalNo: id, // 示例中的固定值
376
- diag: diag,
377
- type: 'normal', // 示例中的固定值
378
- breath: breathList,
379
- temperature: temperatureList,
380
- id: id, // 示例中的固定值
381
- tempType: tempTypeList,
382
- data7: data7List,
383
- pain: painList,
384
- data6: data6List,
385
- data5: data5List,
386
- data4: data4List,
387
- data3: data3List,
388
- data2: data2List,
389
- inDate: inDate.split(' ')[0], // 只取日期部分
390
- data1: data1List,
391
- dept: dept,
392
- heart: heartList,
393
- labels: '血压(mmHg)|入水量(ml)|出水量(ml)|大便(次)|小便(次)|身高(cm)|体重(kg)', // 示例中的固定值
394
- name: name,
395
- begin: date, // 只取日期部分
396
- operateDate: operateDate // 只取日期部分
397
- }
398
- return mergedData
399
- }
400
- // 设置病历号的方法
401
- function setMedicalRecordId (id) {
402
- vitalSignsId.value = id
403
- console.log('病历号已设置为:', vitalSignsId.value)
404
- }
405
- // 生命周期钩子
406
- onMounted(() => {
407
- window.addEventListener('message', (event) => {
408
- if (event.data?.type === 'editorReady' && !editorReady.value && editorComponent.value?.getEditor) {
409
- try {
410
- const editorFromComponent = editorComponent.value.getEditor()
411
- if (editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function') {
412
- editor = editorFromComponent
413
- editorReady.value = true
414
- }
415
- } catch (err) {
416
- console.error('从组件获取editor对象错误:', err)
417
- }
418
- }
419
- })
420
- })
421
-
422
- // 暴露方法和属性给父组件,使父组件可以通过ref访问
423
- defineExpose({
424
- // 属性
425
- vitalSignsId,
426
- // 清空体温单方法
427
- clearVitalSigns,
428
- // 展示更新和创建弹框 创建参数:(String) create, 更新参数:(String) update
429
- showVitalSignsModal,
430
- // 触发打印函数 参数:(String) print
431
- execCommand,
432
- // 获取当前体温单ID的方法
433
- getVitalSignsId: () => vitalSignsId.value,
434
- // 设置体温单ID的方法
435
- setVitalSignsId: (id) => {
436
- vitalSignsId.value = id
437
- },
438
- // 创建体温单 参数:(Object) data
439
- handleSubmit,
440
- // 设置病历号
441
- setMedicalRecordId,
442
- // 获取表单数据
443
- mergeAndTransformData
444
- })
445
- </script>
446
-
447
- <style scoped>
448
- .box {
449
- display: flex;
450
- align-items: center;
451
- padding: 1%;
452
- }
453
-
454
- /* 体温单生成加载遮罩样式 */
455
- .generating-mask {
456
- position: fixed;
457
- top: 0;
458
- left: 0;
459
- right: 0;
460
- bottom: 0;
461
- background-color: rgba(0, 0, 0, 0.5);
462
- display: flex;
463
- justify-content: center;
464
- align-items: center;
465
- z-index: 9999;
466
- }
467
-
468
- .generating-content {
469
- background-color: white;
470
- padding: 20px 40px;
471
- border-radius: 4px;
472
- text-align: center;
473
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
474
- }
475
-
476
- .generating-text {
477
- margin-top: 16px;
478
- color: rgba(0, 0, 0, 0.85);
479
- font-size: 16px;
480
- }
481
- </style>
1
+ <template>
2
+ <!-- <Source src="/code/VitalSigns.vue"></Source>-->
3
+ <div>
4
+ <a-row class="box">
5
+ <!-- 病历号输入框已隐藏,通过setMedicalRecordId方法设置vitalSignsId -->
6
+ <!-- 病历号&nbsp;&nbsp;<a-input v-model="vitalSignsId" style="width: 160px"></a-input> -->
7
+ <a-button-group style="margin-left: 20px;">
8
+ <a-button
9
+ v-if="showCreateButton"
10
+ plain
11
+ type="primary"
12
+ @click="showVitalSignsModal('create')"
13
+ :loading="loading"
14
+ :disabled="!editorReady">创建体温单</a-button>
15
+ <a-button
16
+ v-if="showUpdateButton"
17
+ plain
18
+ type="primary"
19
+ @click="showVitalSignsModal('update')"
20
+ :loading="loading"
21
+ :disabled="!editorReady">更新体温单</a-button>
22
+ </a-button-group>
23
+ <a-button-group v-if="showClearButton" style="margin: 0 20px;">
24
+ <a-button plain type="primary" @click="execCommand('print')" :loading="loading" :disabled="!editorReady">打印</a-button>
25
+ </a-button-group>
26
+ <!-- 修改清空体温单按钮样式,使其更加醒目 -->
27
+ <a-button
28
+ type="primary"
29
+ danger
30
+ v-if="showClearButton"
31
+ @click="clearVitalSigns"
32
+ :loading="loading"
33
+ :disabled="!editorReady"
34
+ style="margin-left: 10px;">
35
+ <a-icon type="delete" /> 清空体温单
36
+ </a-button>
37
+ </a-row>
38
+ <div v-if="!editorReady" style="margin: 10px 0; padding: 10px; background-color: #fffbe6; border: 1px solid #ffe58f;">
39
+ <a-icon type="loading" /> 体温单编辑器加载中...
40
+ </div>
41
+
42
+ <!-- 添加体温单生成加载遮罩 -->
43
+ <div v-if="generating" class="generating-mask">
44
+ <div class="generating-content">
45
+ <a-spin size="large" />
46
+ <div class="generating-text">体温单生成中,请稍候...</div>
47
+ </div>
48
+ </div>
49
+
50
+ <Editor @editor-ready="onEditorReady" style="margin: 10px 0;" ref="editorComponent"></Editor>
51
+
52
+ <!-- 使用TextBox组件替代原有弹窗 -->
53
+ <TextBox
54
+ :visible="modalVisible"
55
+ :modalType="modalType"
56
+ :editorReady="editorReady"
57
+ :id="Number(vitalSignsId) || 180"
58
+ @submit="handleSubmit"
59
+ @cancel="closeModal"
60
+ />
61
+ </div>
62
+ </template>
63
+
64
+ <script setup>
65
+ import { ref, onMounted } from 'vue'
66
+ import Editor from './editor.vue'
67
+ import TextBox from './textBox.vue'
68
+ import { message } from 'ant-design-vue'
69
+
70
+ // 响应式状态
71
+ const vitalSignsId = ref(null)
72
+ const loading = ref(false)
73
+ const editorReady = ref(false)
74
+ const editorComponent = ref(null)
75
+ const modalVisible = ref(false)
76
+ const modalType = ref('create')
77
+ const generating = ref(false) // 添加体温单生成中状态
78
+ let editor = null
79
+ // 定义组件事件
80
+ const emit = defineEmits(['submit'])
81
+ // 常量
82
+ const modalTitles = {
83
+ create: '创建体温单',
84
+ update: '更新体温单'
85
+ }
86
+
87
+ // 接受父组件传递的属性
88
+ defineProps({
89
+ showCreateButton: {
90
+ type: Boolean,
91
+ default: false
92
+ },
93
+ showUpdateButton: {
94
+ type: Boolean,
95
+ default: false
96
+ },
97
+ // 添加打印按钮是否显示属性
98
+ showPrintButton: {
99
+ type: Boolean,
100
+ default: false
101
+ },
102
+ showClearButton: {
103
+ type: Boolean,
104
+ default: false
105
+ },
106
+ // 时间模式 -2 ~ 2
107
+ adjustHour: {
108
+ type: Number,
109
+ default: 0
110
+ }
111
+ })
112
+
113
+ // 显示弹窗
114
+ function showVitalSignsModal (type) {
115
+ modalType.value = type
116
+ modalVisible.value = true
117
+ }
118
+
119
+ // 关闭弹窗
120
+ function closeModal () {
121
+ modalVisible.value = false
122
+ }
123
+
124
+ // 编辑器初始化
125
+ function onEditorReady (editorObj) {
126
+ try {
127
+ if (!editorObj) {
128
+ throw new Error('传入的editor对象为null或undefined')
129
+ }
130
+
131
+ // 尝试获取编辑器对象
132
+ if (typeof editorObj.createVitalSigns === 'function') {
133
+ editor = editorObj
134
+ } else if (editorObj.getEditor && typeof editorObj.getEditor === 'function') {
135
+ const editorFromComponent = editorObj.getEditor()
136
+ editor = editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function'
137
+ ? editorFromComponent
138
+ : (typeof editorObj.createVitalSigns === 'function' ? editorObj : null)
139
+ }
140
+ if (!editor) {
141
+ throw new Error('无法获取有效的editor对象')
142
+ }
143
+ editorReady.value = true
144
+ } catch (err) {
145
+ console.error('设置editor对象失败:', err)
146
+ message.error('体温单编辑器初始化失败,请刷新页面重试')
147
+ }
148
+ }
149
+
150
+ // 执行命令
151
+ function execCommand (cmd) {
152
+ if (!editorReady.value || !editor) return
153
+ loading.value = true
154
+ try {
155
+ editor.execCommand(cmd)
156
+ } catch (err) {
157
+ console.error('执行命令出错:', err)
158
+ message.error(`执行${cmd}命令失败`)
159
+ } finally {
160
+ loading.value = false
161
+ }
162
+ }
163
+
164
+ // 清空体温单
165
+ async function clearVitalSigns () {
166
+ if (!editorReady.value || !editor) {
167
+ message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
168
+ return
169
+ }
170
+ loading.value = true
171
+ generating.value = true
172
+ try {
173
+ // 重新加载editor.html页面来完全重置编辑器
174
+ try {
175
+ const iframe = editorComponent.value.$refs.editorIframe
176
+ if (iframe) {
177
+ // 保存当前src
178
+ const currentSrc = iframe.src
179
+ // 确认提示
180
+ message.loading('正在清空体温单...', 1)
181
+ // 重新加载iframe
182
+ iframe.onload = async () => {
183
+ try {
184
+ // 等待iframe重新加载完成
185
+ await new Promise(resolve => setTimeout(resolve, 500))
186
+ // 获取新的editor对象
187
+ const newEditorObj = iframe.contentWindow.editor
188
+ if (newEditorObj) {
189
+ // 等待editor初始化
190
+ if (typeof newEditorObj.init === 'function') {
191
+ await new Promise((resolve) => {
192
+ const checkInterval = setInterval(() => {
193
+ if (newEditorObj.isReady) {
194
+ clearInterval(checkInterval)
195
+ resolve()
196
+ }
197
+ }, 100)
198
+ // 最多等待5秒
199
+ setTimeout(() => {
200
+ clearInterval(checkInterval)
201
+ resolve()
202
+ }, 5000)
203
+ })
204
+ }
205
+ // 更新全局editor引用
206
+ editor = newEditorObj
207
+ window.iframeEditor = newEditorObj
208
+ } else {
209
+ throw new Error('重新加载后无法获取editor对象')
210
+ }
211
+ } catch (err) {
212
+ console.error('重新加载iframe后清空体温单出错:', err)
213
+ message.error(`清空体温单失败: ${err.message || '未知错误'}`)
214
+ } finally {
215
+ loading.value = false
216
+ generating.value = false
217
+ // 移除临时onload处理器
218
+ iframe.onload = null
219
+ }
220
+ }
221
+ // 重新加载iframe
222
+ iframe.src = currentSrc + '?t=' + new Date().getTime()
223
+ return
224
+ }
225
+ } catch (reloadErr) {
226
+ console.warn('重新加载iframe失败,将尝试其他方法清空体温单:', reloadErr)
227
+ }
228
+ // 备用清空方法
229
+ try {
230
+ const iframe = editorComponent.value.$refs.editorIframe
231
+ if (iframe?.contentWindow) {
232
+ iframe.contentWindow.eval(`
233
+ try {
234
+ // 尝试使用编辑器提供的各种可能的清空方法
235
+ if (editor) {
236
+ if (typeof editor.loadUrl === 'function') {
237
+ editor.loadUrl('');
238
+ } else if (typeof editor.resetDocument === 'function') {
239
+ editor.resetDocument();
240
+ } else if (typeof editor.clearContent === 'function') {
241
+ editor.clearContent();
242
+ } else if (typeof editor.clear === 'function') {
243
+ editor.clear();
244
+ } else if (typeof editor.setEditorContent === 'function') {
245
+ editor.setEditorContent('');
246
+ } else if (editor.document) {
247
+ try {
248
+ editor.document.body.innerHTML = '';
249
+ } catch(clearErr) {
250
+ console.warn('清空编辑器内容失败');
251
+ }
252
+ }
253
+ }
254
+ } catch(e) {
255
+ console.error('清空体温单失败:', e);
256
+ }
257
+ `)
258
+ } else if (window.iframeEditor) {
259
+ const editorObj = window.iframeEditor
260
+ if (typeof editorObj.loadUrl === 'function') {
261
+ editorObj.loadUrl('')
262
+ } else if (typeof editorObj.resetDocument === 'function') {
263
+ editorObj.resetDocument()
264
+ } else if (typeof editorObj.clearContent === 'function') {
265
+ editorObj.clearContent()
266
+ } else if (typeof editorObj.clear === 'function') {
267
+ editorObj.clear()
268
+ } else if (typeof editorObj.setEditorContent === 'function') {
269
+ editorObj.setEditorContent('')
270
+ }
271
+ } else if (editor) {
272
+ if (typeof editor.loadUrl === 'function') {
273
+ editor.loadUrl('')
274
+ } else if (typeof editor.resetDocument === 'function') {
275
+ editor.resetDocument()
276
+ } else if (typeof editor.clearContent === 'function') {
277
+ editor.clearContent()
278
+ } else if (typeof editor.clear === 'function') {
279
+ editor.clear()
280
+ } else if (typeof editor.setEditorContent === 'function') {
281
+ editor.setEditorContent('')
282
+ }
283
+ } else {
284
+ throw new Error('无法获取编辑器对象')
285
+ }
286
+ } catch (err) {
287
+ console.error('清空体温单出错:', err)
288
+ message.error(`清空体温单失败: ${err.message || '未知错误'}`)
289
+ }
290
+ } finally {
291
+ loading.value = false
292
+ generating.value = false
293
+ }
294
+ }
295
+
296
+ // 处理表单提交
297
+ async function handleSubmit (formData) {
298
+ console.log('表单数据:', formData)
299
+ if (!editorReady.value || !editor) {
300
+ message.error('体温单编辑器未加载完成,请等待或刷新页面重试')
301
+ return
302
+ }
303
+ loading.value = true
304
+ generating.value = true // 开始生成,显示加载遮罩
305
+ try {
306
+ let result
307
+ try {
308
+ const iframe = editorComponent.value.$refs.editorIframe
309
+ if (iframe?.contentWindow) {
310
+ // 直接传递数据对象,避免使用eval
311
+ if (iframe.contentWindow.editor && typeof iframe.contentWindow.editor.createVitalSigns === 'function') {
312
+ result = iframe.contentWindow.editor.createVitalSigns(formData)
313
+ } else {
314
+ throw new Error('编辑器对象无效')
315
+ }
316
+ } else if (window.iframeEditor) {
317
+ result = window.iframeEditor.createVitalSigns(formData)
318
+ } else {
319
+ throw new Error('无法访问iframe')
320
+ }
321
+ } catch (err) {
322
+ // 备用方案
323
+ if (editor && typeof editor.createVitalSigns === 'function') {
324
+ editor.createVitalSigns(formData)
325
+ } else {
326
+ throw new Error('无法调用createVitalSigns方法')
327
+ }
328
+ }
329
+
330
+ vitalSignsId.value = result || formData.id
331
+ modalVisible.value = false
332
+ message.success(`${modalTitles[modalType.value]}成功`)
333
+ emit('submit', formData)
334
+ } catch (err) {
335
+ console.error('创建体温单出错:', err)
336
+ message.error(`创建体温单失败: ${err.message || '未知错误'}`)
337
+ } finally {
338
+ loading.value = false
339
+ generating.value = false // 无论成功失败,都结束加载遮罩
340
+ }
341
+ }
342
+
343
+ // 处理表单数据
344
+ function mergeAndTransformData (records, patientInfo, id, date, operateDate) {
345
+ // 提取records中的数据
346
+ const temperatureList = records.map(record => record.temperature).join(',')
347
+ const sphygmusList = records.map(record => record.sphygmus).join(',')
348
+ const breathList = records.map(record => record.breath).join(',')
349
+ const heartList = records.map(record => record.heart).join(',')
350
+ const notesList = records.map(record => record.notes).join(',')
351
+ const painList = records.map(record => record.pain).join(',')
352
+ const data1List = records.map(record => {
353
+ const [systolic, diastolic] = record.data1.split('|')
354
+ return `${systolic}/${diastolic}`
355
+ }).join(',')
356
+ const data2List = records.map(record => record.data2).join(',')
357
+ const data3List = records.map(record => record.data3).join(',')
358
+ const data4List = records.map(record => record.data4).join(',')
359
+ const data5List = records.map(record => record.data5).join(',')
360
+ const data6List = records.map(record => record.data6).join(',')
361
+ const data7List = records.map(record => record.data7).join(',')
362
+ const tempTypeList = records.map(record => record.temptype).join(',')
363
+
364
+ // 提取patientInfo中的数据
365
+ const name = patientInfo.name || ''
366
+ const dept = patientInfo.dept || ''
367
+ const bed = patientInfo.bed || ''
368
+ const inDate = patientInfo.indate || ''
369
+ const diag = patientInfo.diag || ''
370
+
371
+ // 生成合并后的对象
372
+ const mergedData = {
373
+ bed: bed.toString(),
374
+ sphygmus: sphygmusList,
375
+ notes: notesList,
376
+ medicalNo: id, // 示例中的固定值
377
+ diag: diag,
378
+ type: 'normal', // 示例中的固定值
379
+ breath: breathList,
380
+ temperature: temperatureList,
381
+ id: id, // 示例中的固定值
382
+ tempType: tempTypeList,
383
+ data7: data7List,
384
+ pain: painList,
385
+ data6: data6List,
386
+ data5: data5List,
387
+ data4: data4List,
388
+ data3: data3List,
389
+ data2: data2List,
390
+ inDate: inDate.split(' ')[0], // 只取日期部分
391
+ data1: data1List,
392
+ dept: dept,
393
+ heart: heartList,
394
+ labels: '血压(mmHg)|入水量(ml)|出水量(ml)|大便(次)|小便(次)|身高(cm)|体重(kg)', // 示例中的固定值
395
+ name: name,
396
+ begin: date, // 只取日期部分
397
+ operateDate: operateDate // 只取日期部分
398
+ }
399
+ return mergedData
400
+ }
401
+ // 设置病历号的方法
402
+ function setMedicalRecordId (id) {
403
+ vitalSignsId.value = id
404
+ // console.log('病历号已设置为:', vitalSignsId.value)
405
+ }
406
+ // 生命周期钩子
407
+ onMounted(() => {
408
+ window.addEventListener('message', (event) => {
409
+ if (event.data?.type === 'editorReady' && !editorReady.value && editorComponent.value?.getEditor) {
410
+ try {
411
+ const editorFromComponent = editorComponent.value.getEditor()
412
+ if (editorFromComponent && typeof editorFromComponent.createVitalSigns === 'function') {
413
+ editor = editorFromComponent
414
+ editorReady.value = true
415
+ }
416
+ } catch (err) {
417
+ console.error('从组件获取editor对象错误:', err)
418
+ }
419
+ }
420
+ })
421
+ })
422
+
423
+ // 暴露方法和属性给父组件,使父组件可以通过ref访问
424
+ defineExpose({
425
+ // 属性
426
+ vitalSignsId,
427
+ // 清空体温单方法
428
+ clearVitalSigns,
429
+ // 展示更新和创建弹框 创建参数:(String) create, 更新参数:(String) update
430
+ showVitalSignsModal,
431
+ // 触发打印函数 参数:(String) print
432
+ execCommand,
433
+ // 获取当前体温单ID的方法
434
+ getVitalSignsId: () => vitalSignsId.value,
435
+ // 设置体温单ID的方法
436
+ setVitalSignsId: (id) => {
437
+ vitalSignsId.value = id
438
+ },
439
+ // 创建体温单 参数:(Object) data
440
+ handleSubmit,
441
+ // 设置病历号
442
+ setMedicalRecordId,
443
+ // 获取表单数据
444
+ mergeAndTransformData
445
+ })
446
+ </script>
447
+
448
+ <style scoped>
449
+ .box {
450
+ display: flex;
451
+ align-items: center;
452
+ padding: 1%;
453
+ }
454
+
455
+ /* 体温单生成加载遮罩样式 */
456
+ .generating-mask {
457
+ position: fixed;
458
+ top: 0;
459
+ left: 0;
460
+ right: 0;
461
+ bottom: 0;
462
+ background-color: rgba(0, 0, 0, 0.5);
463
+ display: flex;
464
+ justify-content: center;
465
+ align-items: center;
466
+ z-index: 9999;
467
+ }
468
+
469
+ .generating-content {
470
+ background-color: white;
471
+ padding: 20px 40px;
472
+ border-radius: 4px;
473
+ text-align: center;
474
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
475
+ }
476
+
477
+ .generating-text {
478
+ margin-top: 16px;
479
+ color: rgba(0, 0, 0, 0.85);
480
+ font-size: 16px;
481
+ }
482
+ </style>