1
1
<template >
2
- <BasicModal v-bind =" $attrs" :showFooter =" true" @register =" registerModal" @ok =" handleSubmit" width =" 40%"
3
- :show-ok-btn =" hasPermission(Authority.TENANT_ADMIN)" >
4
- <template #title >
5
- <Icon :icon =" getTitle.icon" class =" pr-1 m-1" />
6
- <span > {{ getTitle.value }} </span >
7
- </template >
8
- <BasicForm @register =" registerForm" >
9
-
10
- </BasicForm >
11
- </BasicModal >
12
- </template >
13
- <script lang="ts" setup name="ViewsScreenVisualForm">
2
+ <BasicModal
3
+ v-bind =" $attrs"
4
+ :showFooter =" true"
5
+ @register =" registerModal"
6
+ @ok =" handleSubmit"
7
+ width =" 40%"
8
+ :show-ok-btn =" hasPermission(Authority.TENANT_ADMIN)"
9
+ >
10
+ <template #title >
11
+ <Icon :icon =" getTitle.icon" class =" pr-1 m-1" />
12
+ <span > {{ getTitle.value }} </span >
13
+ </template >
14
+ <BasicForm @register =" registerForm" > </BasicForm >
15
+ </BasicModal >
16
+ </template >
17
+ <script lang="ts" setup name="ViewsScreenVisualForm">
14
18
import { ref , unref , computed } from ' vue' ;
15
19
import { useI18n } from ' /@/hooks/web/useI18n' ;
16
20
import { useMessage } from ' /@/hooks/web/useMessage' ;
17
21
import { router } from ' /@/router' ;
18
22
import { Icon } from ' /@/components/Icon' ;
19
-
23
+
20
24
import { BasicForm , FormSchema , useForm } from ' /@/components/Form' ;
21
25
import { BasicModal , useModalInner } from ' /@/components/Modal' ;
22
26
import { useUserStore } from ' /@/store/modules/user' ;
23
- import { getTbVisualInfoById , createTbVisual , saveTbVisual , TbVisualInfo } from ' /@/api/screen/visual' ;
27
+ import {
28
+ getTbVisualInfoById ,
29
+ createTbVisual ,
30
+ saveTbVisual ,
31
+ TbVisualInfo ,
32
+ } from ' /@/api/screen/visual' ;
24
33
import { EntityType } from ' /@/enums/entityTypeEnum' ;
25
34
import { usePermission } from ' /@/hooks/web/usePermission' ;
26
35
import { Authority } from ' /@/enums/authorityEnum' ;
27
-
36
+
28
37
const emit = defineEmits ([' success' , ' register' ]);
29
-
38
+
30
39
const { t } = useI18n (' tb' );
31
40
const { hasPermission } = usePermission ();
32
41
const userStore = useUserStore ();
37
46
icon: meta .icon || ' ant-design:book-outlined' ,
38
47
value: record .value .id ?.id ? t (' 编辑数据大屏' ) : t (' 新增数据大屏' ),
39
48
}));
40
-
41
-
42
-
43
-
49
+
44
50
const inputFormSchemas: FormSchema [] = [
45
- { field: ' tenantId' , component: ' Input' , defaultValue: userStore .getUserInfo .tenantId , show: false },
51
+ {
52
+ field: ' tenantId' ,
53
+ component: ' Input' ,
54
+ defaultValue: userStore .getUserInfo .tenantId ,
55
+ show: false ,
56
+ },
46
57
{
47
58
label: t (' 大屏名称' ),
48
59
field: ' title' ,
49
60
component: ' Input' ,
50
61
componentProps: {
51
62
maxlength: 100 ,
52
- placeholder: ' 请输大屏名称'
63
+ placeholder: ' 请输大屏名称' ,
53
64
},
54
65
required: true ,
55
66
},
56
-
67
+ {
68
+ label: t (' 访问密钥' ),
69
+ field: ' credentials' ,
70
+ component: ' Input' ,
71
+ ifShow : () => !! record .value .id ?.id ,
72
+ componentProps: {
73
+ maxlength: 100 ,
74
+ placeholder: ' 请输大屏访问密钥' ,
75
+ },
76
+ rules: [
77
+ { required: false },
78
+ { max: 10 , message: t (' 请输入长度在 10 个字符之内' ) },
79
+ { pattern: / ^ [a-zA-Z0-9 ] * $ / , message: t (' 请输入字母和数字' ) },
80
+ ],
81
+ },
82
+
57
83
{
58
84
label: t (' 描述信息' ),
59
85
field: ' additionalInfo.description' ,
62
88
maxlength: 500 ,
63
89
},
64
90
},
65
-
66
91
];
67
-
92
+
68
93
const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm ({
69
94
labelWidth: 120 ,
70
95
schemas: inputFormSchemas ,
71
96
baseColProps: { lg: 24 , md: 24 },
72
97
});
73
-
98
+
74
99
const [registerModal, { setModalProps, closeModal }] = useModalInner (async (data ) => {
75
100
setModalProps ({ loading: true });
76
101
await resetFields ();
82
107
setFieldsValue (record .value );
83
108
setModalProps ({ loading: false });
84
109
});
85
-
110
+
86
111
async function handleSubmit() {
87
112
try {
88
113
const data = await validate ();
89
114
setModalProps ({ confirmLoading: true });
90
115
// console.log('submit', params, data, record);
91
-
116
+
92
117
if (record .value ?.id ?.id ) {
93
118
const res = await saveTbVisual ({ ... record .value , ... data , id: record .value .id });
94
- }else {
119
+ } else {
95
120
const res = await createTbVisual ({ ... data });
96
121
}
97
122
showMessage (` ${record .value .id ?.id ? ' 编辑' : ' 新增' }设备大屏成功! ` );
106
131
setModalProps ({ confirmLoading: false });
107
132
}
108
133
}
109
-
110
-
111
-
112
-
113
- </script >
114
-
134
+ </script >
0 commit comments