提交 | 用户 | 时间
|
91cd98
|
1 |
<template> |
潘 |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle" width="50%"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="120px" |
|
9 |
> |
|
10 |
<el-row> |
|
11 |
<el-col :span="12"> |
|
12 |
<el-form-item label="Tag名称" prop="tagName"> |
|
13 |
<el-input v-model="formData.tagName" placeholder="请输Tag名称"/> |
|
14 |
</el-form-item> |
|
15 |
</el-col> |
|
16 |
<el-col :span="12"> |
|
17 |
<el-form-item label="数据类型" prop="dataType"> |
|
18 |
<el-select v-model="formData.dataType" placeholder="请选择"> |
|
19 |
<el-option |
|
20 |
v-for="dict in getStrDictOptions(DICT_TYPE.TAG_DATA_TYPE)" |
|
21 |
:key="dict.value" |
|
22 |
:label="dict.label" |
|
23 |
:value="dict.value" |
|
24 |
/> |
|
25 |
</el-select> |
|
26 |
</el-form-item> |
|
27 |
</el-col> |
|
28 |
</el-row> |
|
29 |
<el-row> |
|
30 |
<el-col :span="12"> |
|
31 |
<el-form-item label="是否启用" prop="enabled"> |
|
32 |
<el-select v-model="formData.enabled" placeholder="请选择"> |
|
33 |
<el-option |
6c2636
|
34 |
v-for="dict in getIntDictOptions(DICT_TYPE.COM_IS_INT)" |
91cd98
|
35 |
:key="dict.value" |
潘 |
36 |
:label="dict.label" |
|
37 |
:value="dict.value" |
|
38 |
/> |
|
39 |
</el-select> |
|
40 |
</el-form-item> |
|
41 |
</el-col> |
|
42 |
</el-row> |
|
43 |
<el-row> |
|
44 |
<el-col :span="24"> |
|
45 |
<el-form-item label="描述" prop="tagDesc"> |
|
46 |
<el-input v-model="formData.tagDesc" placeholder="描述"/> |
|
47 |
</el-form-item> |
|
48 |
</el-col> |
|
49 |
</el-row> |
|
50 |
</el-form> |
|
51 |
<template #footer> |
|
52 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
53 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
54 |
</template> |
|
55 |
</Dialog> |
|
56 |
</template> |
|
57 |
<script lang="ts" setup> |
|
58 |
import * as HttpTagApi from '@/api/data/channel/http/tag' |
6c2636
|
59 |
import {CommonEnabled} from '@/utils/constants' |
J |
60 |
import { DICT_TYPE, getStrDictOptions, getIntDictOptions } from '@/utils/dict' |
91cd98
|
61 |
|
潘 |
62 |
defineOptions({name: 'HttpTagForm'}) |
|
63 |
|
|
64 |
const {t} = useI18n() // 国际化 |
|
65 |
const message = useMessage() // 消息弹窗 |
|
66 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
67 |
const dialogTitle = ref('') // 弹窗的标题 |
|
68 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
69 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
70 |
const formData = ref({ |
|
71 |
id: undefined, |
|
72 |
apiId: undefined, |
|
73 |
tagName: undefined, |
|
74 |
dataType: undefined, |
|
75 |
tagDesc: '', |
6c2636
|
76 |
enabled: CommonEnabled.ENABLE, |
91cd98
|
77 |
}) |
潘 |
78 |
const formRules = reactive({ |
|
79 |
tagName: [{required: true, message: 'Tag名称不能为空', trigger: 'blur'}], |
|
80 |
dataType: [{required: true, message: '数据类型不能为空', trigger: 'blur'}] |
|
81 |
}) |
|
82 |
const formRef = ref() // 表单 Ref |
|
83 |
|
|
84 |
/** 打开弹窗 */ |
|
85 |
const open = async (type: string, id?: number, apiId?: string) => { |
|
86 |
dialogVisible.value = true |
|
87 |
dialogTitle.value = t('action.' + type) |
|
88 |
formType.value = type |
|
89 |
resetForm() |
|
90 |
if (apiId) { |
|
91 |
formData.value.apiId = apiId |
|
92 |
} |
|
93 |
// 修改时,设置数据 |
|
94 |
if (id) { |
|
95 |
formLoading.value = true |
|
96 |
try { |
|
97 |
formData.value = await HttpTagApi.getHttpTag(id) |
|
98 |
} finally { |
|
99 |
formLoading.value = false |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
defineExpose({open}) // 提供 open 方法,用于打开弹窗 |
|
104 |
|
|
105 |
/** 提交表单 */ |
|
106 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
107 |
const submitForm = async () => { |
|
108 |
// 校验表单 |
|
109 |
if (!formRef) return |
|
110 |
const valid = await formRef.value.validate() |
|
111 |
if (!valid) return |
|
112 |
// 提交请求 |
|
113 |
formLoading.value = true |
|
114 |
try { |
|
115 |
const data = formData.value as unknown as HttpTagApi.HttpTagVO |
|
116 |
if (formType.value === 'create') { |
|
117 |
await HttpTagApi.createHttpTag(data) |
|
118 |
message.success(t('common.createSuccess')) |
|
119 |
} else { |
|
120 |
await HttpTagApi.updateHttpTag(data) |
|
121 |
message.success(t('common.updateSuccess')) |
|
122 |
} |
|
123 |
dialogVisible.value = false |
|
124 |
// 发送操作成功的事件 |
|
125 |
emit('success') |
|
126 |
} finally { |
|
127 |
formLoading.value = false |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
/** 重置表单 */ |
|
132 |
const resetForm = () => { |
|
133 |
formData.value = { |
|
134 |
id: undefined, |
|
135 |
apiId: undefined, |
|
136 |
tagName: undefined, |
|
137 |
dataType: undefined, |
|
138 |
tagDesc: '', |
6c2636
|
139 |
enabled: CommonEnabled.ENABLE, |
91cd98
|
140 |
} |
潘 |
141 |
formRef.value?.resetFields() |
|
142 |
} |
|
143 |
</script> |
|
144 |
ss |