af-mobile-client-vue3 1.2.13 → 1.2.14

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.
@@ -2,8 +2,10 @@
2
2
  import type { FormInstance } from 'vant'
3
3
  import XFormItem from '@af-mobile-client-vue3/components/data/XFormItem/index.vue'
4
4
  import XOlMap from '@af-mobile-client-vue3/components/data/XOlMap/index.vue'
5
- import { addOrModifyEntity } from '@af-mobile-client-vue3/services/api/common'
5
+ import { formatDate } from '@af-mobile-client-vue3/hooks/useCommon'
6
+ import { addOrModifyEntity, runLogic } from '@af-mobile-client-vue3/services/api/common'
6
7
  import { post } from '@af-mobile-client-vue3/services/restTools'
8
+ import { useUserStore } from '@af-mobile-client-vue3/stores'
7
9
  import {
8
10
  showFailToast,
9
11
  showSuccessToast,
@@ -20,6 +22,11 @@ interface FormItem {
20
22
  model?: string
21
23
  }
22
24
 
25
+ interface SilenceAddFormItem extends FormItem {
26
+ silencePurpose: string
27
+ silenceSource?: string
28
+ }
29
+
23
30
  interface GroupFormItems {
24
31
  btnName?: string
25
32
  formJson: any[] // 根据实际类型调整
@@ -45,6 +52,7 @@ const props = withDefaults(defineProps<{
45
52
  submitButton: true,
46
53
  })
47
54
  const emits = defineEmits(['onSubmit'])
55
+ const userStore = useUserStore()
48
56
  const formRef = ref<FormInstance>()
49
57
  const myFormItems = ref<FormItem[]>([])
50
58
  const rules = reactive({})
@@ -68,6 +76,16 @@ const realJsonData = computed(() => {
68
76
  })
69
77
  })
70
78
 
79
+ // 是否处理表单Key值
80
+ const isHandleFormKey = ref(true)
81
+
82
+ // 过滤出用于静默新增场景的表单项
83
+ const silenceAddJsonData = computed(() => {
84
+ return myFormItems.value.filter((item) => {
85
+ return item.addOrEdit === 'silenceAdd'
86
+ }) as SilenceAddFormItem[]
87
+ })
88
+
71
89
  const resolvedSubmitButton = computed(() => {
72
90
  if (props.configName && internalSubmitButton.value !== undefined) {
73
91
  return internalSubmitButton.value
@@ -242,20 +260,128 @@ function setForm(obj) {
242
260
  }
243
261
 
244
262
  // 获取表单字段实际值
245
- function getRealKey(form) {
246
- const result = {}
247
- for (const key in form) {
248
- result[key.substring(key.indexOf('_') + 1)] = form[key]
263
+ function getRealKey(key, mustHandleKey = false) {
264
+ if (key === 'selected_id')
265
+ return key
266
+ if (isHandleFormKey.value || mustHandleKey) {
267
+ return key.substring(key.indexOf('_') + 1)
268
+ }
269
+ else {
270
+ return key
271
+ }
272
+ }
273
+
274
+ async function asyncSubmit() {
275
+ return new Promise((resolve, reject) => {
276
+ validate().then(async () => {
277
+ const requestForm = prepareForm()
278
+ await appendSilenceAddFields(requestForm)
279
+ const realForm = handleFormKeys(requestForm)
280
+ resolve({
281
+ realForm,
282
+ mode: props.mode,
283
+ serviceName: props.serviceName,
284
+ currUserName: userStore.getUserInfo().name,
285
+ currUserId: userStore.getUserInfo().id,
286
+ orgId: userStore.getUserInfo().orgid,
287
+ })
288
+ }).catch((error) => {
289
+ reject(error)
290
+ })
291
+ })
292
+ }
293
+
294
+ function handleFormKeys(form, mustHandleKey = false) {
295
+ const realForm = {}
296
+ for (const key of Object.keys(form)) {
297
+ const value = form[key]
298
+ const extraFormKeyTagIndex = key.indexOf('@')
299
+ if (extraFormKeyTagIndex !== -1) {
300
+ const extraFormKey = key.substring(0, extraFormKeyTagIndex)
301
+ const realKey = key.substring(extraFormKeyTagIndex + 1)
302
+ if (!realForm[extraFormKey]) {
303
+ realForm[extraFormKey] = {}
304
+ }
305
+ realForm[extraFormKey][realKey] = value
306
+ }
307
+ else {
308
+ const realKey = isHandleFormKey.value || mustHandleKey ? getRealKey(key, mustHandleKey) : key
309
+ // 如果发生重名,不覆盖,把key的别名带上
310
+ if (realForm[realKey]) {
311
+ realForm[key] = value
312
+ }
313
+ else {
314
+ realForm[realKey] = value
315
+ }
316
+ }
317
+ }
318
+ return realForm
319
+ }
320
+
321
+ async function appendSilenceAddFields(form) {
322
+ if (props.mode === '新增') {
323
+ for (const item of silenceAddJsonData.value) {
324
+ switch (item.silencePurpose) {
325
+ case 'createTime':
326
+ form[item.model] = formatDate(new Date())
327
+ break
328
+ case 'operator':
329
+ form[item.model] = userStore.getUserInfo().name
330
+ break
331
+ case 'operatorId':
332
+ form[item.model] = userStore.getUserInfo().id
333
+ break
334
+ case 'orgId':
335
+ form[item.model] = userStore.getUserInfo().orgid
336
+ break
337
+ case 'orgName':
338
+ form[item.model] = userStore.getUserInfo().orgs
339
+ break
340
+ case 'depId':
341
+ form[item.model] = userStore.getUserInfo().depids
342
+ break
343
+ case 'depName':
344
+ form[item.model] = userStore.getUserInfo().deps
345
+ break
346
+ }
347
+ }
348
+ for (const item of silenceAddJsonData.value.filter(item => item.silencePurpose === 'customize')) {
349
+ const result: any = await runLogic(item.silenceSource, form, props.serviceName)
350
+ if (result) {
351
+ const keys = Object.keys(result)
352
+ if (keys.length === 1 && keys[0] === 'value') {
353
+ form[item.model] = result.value
354
+ }
355
+ else {
356
+ form[item.model] = result
357
+ }
358
+ }
359
+ else {
360
+ form[item.model] = result
361
+ }
362
+ }
363
+ }
364
+ }
365
+
366
+ function prepareForm() {
367
+ const formObj = { ...form.value }
368
+ for (const key of Object.keys(formObj)) {
369
+ const value = formObj[key]
370
+ if (value === null || (typeof value === 'object' && Object.keys(value).length === 0)) {
371
+ formObj[key] = undefined
372
+ }
249
373
  }
250
- return result
374
+ return formObj
251
375
  }
252
376
 
253
- function onSubmit() {
377
+ async function onSubmit() {
254
378
  if (!props.configName && props.groupFormItems) {
255
379
  // 只有单表才可以成功,多表关联或者自定义sql不行
256
- const params = getRealKey(form.value)
380
+ const requestForm = prepareForm()
381
+ await appendSilenceAddFields(requestForm)
382
+ const realForm = handleFormKeys(requestForm)
257
383
  try {
258
- addOrModifyEntity(params, tableName.value, props.serviceName || import.meta.env.VITE_APP_SYSTEM_NAME).then(() => {
384
+ addOrModifyEntity(realForm, tableName.value, props.serviceName || import.meta.env.VITE_APP_SYSTEM_NAME).then(() => {
259
385
  showSuccessToast('提交成功!')
260
386
  })
261
387
  }
@@ -278,7 +404,7 @@ async function validate() {
278
404
  watch(() => props.formData, (_val) => {
279
405
  form.value = _val
280
406
  })
281
- defineExpose({ init, form, formGroupName, validate })
407
+ defineExpose({ init, form, formGroupName, validate, asyncSubmit })
282
408
  </script>
283
409
 
284
410
  <template>
@@ -1,33 +1,33 @@
1
- <script setup lang="ts">
2
- import { onMounted, ref } from 'vue'
3
- import XReport from './XReport.vue'
4
-
5
- const mainRef = ref()
6
-
7
- onMounted(() => {
8
- // 初始化逻辑
9
- })
10
- </script>
11
-
12
- <template>
13
- <div id="test">
14
- <van-card :bordered="false">
15
- <XReport
16
- ref="mainRef"
17
- :use-oss-for-img="false"
18
- config-name="nurseWorkstationCover"
19
- server-name="af-his"
20
- :show-img-in-cell="true"
21
- :display-only="true"
22
- :edit-mode="false"
23
- :show-save-button="false"
24
- :no-padding="true"
25
- :dont-format="true"
26
- />
27
- </van-card>
28
- </div>
29
- </template>
30
-
31
- <style scoped>
32
-
33
- </style>
1
+ <script setup lang="ts">
2
+ import { onMounted, ref } from 'vue'
3
+ import XReport from './XReport.vue'
4
+
5
+ const mainRef = ref()
6
+
7
+ onMounted(() => {
8
+ // 初始化逻辑
9
+ })
10
+ </script>
11
+
12
+ <template>
13
+ <div id="test">
14
+ <van-card :bordered="false">
15
+ <XReport
16
+ ref="mainRef"
17
+ :use-oss-for-img="false"
18
+ config-name="nurseWorkstationCover"
19
+ server-name="af-his"
20
+ :show-img-in-cell="true"
21
+ :display-only="true"
22
+ :edit-mode="false"
23
+ :show-save-button="false"
24
+ :no-padding="true"
25
+ :dont-format="true"
26
+ />
27
+ </van-card>
28
+ </div>
29
+ </template>
30
+
31
+ <style scoped>
32
+
33
+ </style>
@@ -1,184 +1,184 @@
1
- // print.js
2
-
3
- export function printElement(elementToPrint) {
4
- // 创建一个新的浏览器窗口
5
- const printWindow = window.open('', '_blank', 'height=1024,width=768')
6
- // 设置新窗口的文档内容
7
- printWindow.document.write(`
8
- <html>
9
- <head>
10
- <title>Print</title>
11
- <style>
12
- @page {
13
- size: auto;
14
- margin: 0mm;
15
- }
16
- html, body {
17
- margin: 0;
18
- padding: 0;
19
- width: 100%;
20
- height: 100%;
21
- }
22
- #print-container {
23
- display: none
24
- }
25
- .img{
26
- width: 95%;
27
- height: 180px;
28
- object-fit: cover;
29
- }
30
- .reportMain {
31
- text-align: center;
32
- margin: 0 auto;
33
- font-size: 16px;
34
- color: #000;
35
- background-color: #fff;
36
- border-radius: 8px;
37
-
38
- .reportTitle {
39
- font-weight: bold;
40
- }
41
-
42
- .subTitle {
43
- display: flex;
44
- justify-content: space-between;
45
- margin-bottom: 1%;
46
-
47
- .subTitleItems {
48
- max-width: 30%;
49
- }
50
- }
51
-
52
- .inputsDiv {
53
- display: flex;
54
- justify-content: space-between;
55
- .inputsDivItem {
56
- display: flex;
57
- align-items: center;
58
- padding: 0 4px;
59
- white-space: nowrap;
60
- .inputsDivItemLabel {
61
- padding: 0 4px;
62
- }
63
- }
64
- }
65
-
66
- .reportTable {
67
- width: 100%;
68
- border-collapse: collapse;
69
- table-layout:fixed;
70
- word-break:break-all;
71
- text-align: center;
72
- }
73
- }
74
- .reportMainForDisplay {
75
- text-align: center;
76
- margin: 10% auto;
77
- font-size: 16px;
78
- color: #000;
79
- background-color: #fff;
80
- border-radius: 8px;
81
-
82
- .reportTitle {
83
- font-weight: bold;
84
- }
85
-
86
- .subTitle {
87
- display: flex;
88
- justify-content: space-between;
89
-
90
- .subTitleItems {
91
- max-width: 30%;
92
- }
93
- }
94
-
95
- .inputsDiv {
96
- display: flex;
97
- justify-content: space-around;
98
- .inputsDivItem {
99
- display: flex;
100
- align-items: center;
101
- padding: 0 4px;
102
- white-space: nowrap;
103
- .inputsDivItemLabel {
104
- padding: 0 4px;
105
- }
106
- }
107
- }
108
-
109
- .reportTable {
110
- width: 100%;
111
- border-collapse: collapse;
112
- table-layout:fixed;
113
- word-break:break-all;
114
- }
115
- }
116
- .reportMainNoPadding {
117
- text-align: center;
118
- margin: 0 auto;
119
- font-size: 16px;
120
- color: #000;
121
- background-color: #fff;
122
- border-radius: 8px;
123
-
124
- .reportTitle {
125
- font-weight: bold;
126
- }
127
-
128
- .subTitle {
129
- display: flex;
130
- justify-content: space-between;
131
-
132
- .subTitleItems {
133
- max-width: 30%;
134
- }
135
- }
136
-
137
- .inputsDiv {
138
- display: flex;
139
- justify-content: space-between;
140
- .inputsDivItem {
141
- display: flex;
142
- align-items: center;
143
- padding: 0 4px;
144
- white-space: nowrap;
145
- .inputsDivItemLabel {
146
- padding: 0 4px;
147
- }
148
- }
149
- }
150
-
151
- .reportTable {
152
- width: 100%;
153
- border-collapse: collapse;
154
- table-layout:fixed;
155
- word-break:break-all;
156
- }
157
- }
158
- .tools{
159
- position: fixed;
160
- right: 2%;
161
- text-align: right;
162
- width: 60%;
163
- cursor: pointer;
164
- .toolsItem{
165
- width: 15%;
166
- margin-right: 3%;
167
- display: inline-block;
168
- }
169
- }
170
- </style>
171
- </head>
172
- <body>
173
- <!-- 将需要打印的元素内容复制到新窗口中 -->
174
- ${elementToPrint.innerHTML}
175
- </body>
176
- </html>
177
- `)
178
- // 延迟执行打印,以确保新窗口的内容已加载完成
179
- printWindow.document.close() // 关闭文档流,确保内容完全加载
180
- setTimeout(() => {
181
- printWindow.print() // 调用打印方法
182
- printWindow.close()
183
- }, 500) // 延迟500毫秒后执行打印
184
- }
1
+ // print.js
2
+
3
+ export function printElement(elementToPrint) {
4
+ // 创建一个新的浏览器窗口
5
+ const printWindow = window.open('', '_blank', 'height=1024,width=768')
6
+ // 设置新窗口的文档内容
7
+ printWindow.document.write(`
8
+ <html>
9
+ <head>
10
+ <title>Print</title>
11
+ <style>
12
+ @page {
13
+ size: auto;
14
+ margin: 0mm;
15
+ }
16
+ html, body {
17
+ margin: 0;
18
+ padding: 0;
19
+ width: 100%;
20
+ height: 100%;
21
+ }
22
+ #print-container {
23
+ display: none
24
+ }
25
+ .img{
26
+ width: 95%;
27
+ height: 180px;
28
+ object-fit: cover;
29
+ }
30
+ .reportMain {
31
+ text-align: center;
32
+ margin: 0 auto;
33
+ font-size: 16px;
34
+ color: #000;
35
+ background-color: #fff;
36
+ border-radius: 8px;
37
+
38
+ .reportTitle {
39
+ font-weight: bold;
40
+ }
41
+
42
+ .subTitle {
43
+ display: flex;
44
+ justify-content: space-between;
45
+ margin-bottom: 1%;
46
+
47
+ .subTitleItems {
48
+ max-width: 30%;
49
+ }
50
+ }
51
+
52
+ .inputsDiv {
53
+ display: flex;
54
+ justify-content: space-between;
55
+ .inputsDivItem {
56
+ display: flex;
57
+ align-items: center;
58
+ padding: 0 4px;
59
+ white-space: nowrap;
60
+ .inputsDivItemLabel {
61
+ padding: 0 4px;
62
+ }
63
+ }
64
+ }
65
+
66
+ .reportTable {
67
+ width: 100%;
68
+ border-collapse: collapse;
69
+ table-layout:fixed;
70
+ word-break:break-all;
71
+ text-align: center;
72
+ }
73
+ }
74
+ .reportMainForDisplay {
75
+ text-align: center;
76
+ margin: 10% auto;
77
+ font-size: 16px;
78
+ color: #000;
79
+ background-color: #fff;
80
+ border-radius: 8px;
81
+
82
+ .reportTitle {
83
+ font-weight: bold;
84
+ }
85
+
86
+ .subTitle {
87
+ display: flex;
88
+ justify-content: space-between;
89
+
90
+ .subTitleItems {
91
+ max-width: 30%;
92
+ }
93
+ }
94
+
95
+ .inputsDiv {
96
+ display: flex;
97
+ justify-content: space-around;
98
+ .inputsDivItem {
99
+ display: flex;
100
+ align-items: center;
101
+ padding: 0 4px;
102
+ white-space: nowrap;
103
+ .inputsDivItemLabel {
104
+ padding: 0 4px;
105
+ }
106
+ }
107
+ }
108
+
109
+ .reportTable {
110
+ width: 100%;
111
+ border-collapse: collapse;
112
+ table-layout:fixed;
113
+ word-break:break-all;
114
+ }
115
+ }
116
+ .reportMainNoPadding {
117
+ text-align: center;
118
+ margin: 0 auto;
119
+ font-size: 16px;
120
+ color: #000;
121
+ background-color: #fff;
122
+ border-radius: 8px;
123
+
124
+ .reportTitle {
125
+ font-weight: bold;
126
+ }
127
+
128
+ .subTitle {
129
+ display: flex;
130
+ justify-content: space-between;
131
+
132
+ .subTitleItems {
133
+ max-width: 30%;
134
+ }
135
+ }
136
+
137
+ .inputsDiv {
138
+ display: flex;
139
+ justify-content: space-between;
140
+ .inputsDivItem {
141
+ display: flex;
142
+ align-items: center;
143
+ padding: 0 4px;
144
+ white-space: nowrap;
145
+ .inputsDivItemLabel {
146
+ padding: 0 4px;
147
+ }
148
+ }
149
+ }
150
+
151
+ .reportTable {
152
+ width: 100%;
153
+ border-collapse: collapse;
154
+ table-layout:fixed;
155
+ word-break:break-all;
156
+ }
157
+ }
158
+ .tools{
159
+ position: fixed;
160
+ right: 2%;
161
+ text-align: right;
162
+ width: 60%;
163
+ cursor: pointer;
164
+ .toolsItem{
165
+ width: 15%;
166
+ margin-right: 3%;
167
+ display: inline-block;
168
+ }
169
+ }
170
+ </style>
171
+ </head>
172
+ <body>
173
+ <!-- 将需要打印的元素内容复制到新窗口中 -->
174
+ ${elementToPrint.innerHTML}
175
+ </body>
176
+ </html>
177
+ `)
178
+ // 延迟执行打印,以确保新窗口的内容已加载完成
179
+ printWindow.document.close() // 关闭文档流,确保内容完全加载
180
+ setTimeout(() => {
181
+ printWindow.print() // 调用打印方法
182
+ printWindow.close()
183
+ }, 500) // 延迟500毫秒后执行打印
184
+ }