提交 | 用户 | 时间
|
cfaf8b
|
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="24"> |
|
12 |
<el-form-item label="认证地址" prop="loginUrl"> |
|
13 |
<el-input v-model="formData.loginUrl" placeholder="请输认证地址"/> |
|
14 |
</el-form-item> |
|
15 |
</el-col> |
|
16 |
</el-row> |
|
17 |
<el-row> |
|
18 |
<el-col :span="12"> |
|
19 |
<el-form-item label="ClientId" prop="clientId"> |
|
20 |
<el-input v-model="formData.clientId" placeholder="请输ClientId"/> |
|
21 |
</el-form-item> |
|
22 |
</el-col> |
|
23 |
<el-col :span="12"> |
|
24 |
<el-form-item label="ClientSecret" prop="clientSecret"> |
|
25 |
<el-input v-model="formData.clientSecret" placeholder="请输ClientSecret"/> |
|
26 |
</el-form-item> |
|
27 |
</el-col> |
|
28 |
</el-row> |
|
29 |
<el-row> |
|
30 |
<el-col :span="12"> |
|
31 |
<el-form-item label="用户名" prop="username"> |
|
32 |
<el-input v-model="formData.username" placeholder="请输用户名"/> |
|
33 |
</el-form-item> |
|
34 |
</el-col> |
|
35 |
<el-col :span="12"> |
|
36 |
<el-form-item label="密码" prop="password"> |
|
37 |
<el-input v-model="formData.password" placeholder="请输密码"/> |
|
38 |
</el-form-item> |
|
39 |
</el-col> |
|
40 |
</el-row> |
|
41 |
<el-row> |
|
42 |
<el-col :span="12"> |
|
43 |
<el-form-item label="刷新频率" prop="refreshFreq"> |
|
44 |
<el-input v-model="formData.refreshFreq" placeholder="请输刷新频率"/> |
|
45 |
</el-form-item> |
|
46 |
</el-col> |
|
47 |
</el-row> |
|
48 |
</el-form> |
|
49 |
<template #footer> |
|
50 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
51 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
52 |
</template> |
|
53 |
</Dialog> |
|
54 |
</template> |
|
55 |
<script lang="ts" setup> |
|
56 |
import * as HttpTokenApi from '@/api/data/channel/http/token' |
|
57 |
import { DICT_TYPE, getStrDictOptions, getBoolDictOptions } from '@/utils/dict' |
|
58 |
|
|
59 |
defineOptions({name: 'HttpTokenForm'}) |
|
60 |
|
|
61 |
const {t} = useI18n() // 国际化 |
|
62 |
const message = useMessage() // 消息弹窗 |
|
63 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
64 |
const dialogTitle = ref('') // 弹窗的标题 |
|
65 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
66 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
67 |
const formData = ref({ |
|
68 |
id: undefined, |
|
69 |
loginUrl: undefined, |
|
70 |
clientId: undefined, |
|
71 |
clientSecret: undefined, |
|
72 |
username: undefined, |
|
73 |
password: undefined, |
|
74 |
token: undefined, |
|
75 |
refreshFreq: undefined |
|
76 |
}) |
|
77 |
const formRules = reactive({ |
|
78 |
loginUrl: [{required: true, message: '登录地址不能为空', trigger: 'blur'}], |
|
79 |
username: [{required: true, message: '用户名不能为空', trigger: 'blur'}], |
|
80 |
password: [{required: true, message: '密码不能为空', trigger: 'blur'}], |
|
81 |
refreshFreq: [{required: true, message: '刷新频率不能为空', trigger: 'blur'}] |
|
82 |
}) |
|
83 |
const formRef = ref() // 表单 Ref |
|
84 |
|
|
85 |
/** 打开弹窗 */ |
|
86 |
const open = async (type: string, id?: number, apiId?: string) => { |
|
87 |
dialogVisible.value = true |
|
88 |
dialogTitle.value = t('action.' + type) |
|
89 |
formType.value = type |
|
90 |
resetForm() |
|
91 |
if (apiId) { |
|
92 |
formData.value.apiId = apiId |
|
93 |
} |
|
94 |
// 修改时,设置数据 |
|
95 |
if (id) { |
|
96 |
formLoading.value = true |
|
97 |
try { |
|
98 |
formData.value = await HttpTokenApi.getHttpToken(id) |
|
99 |
} finally { |
|
100 |
formLoading.value = false |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
defineExpose({open}) // 提供 open 方法,用于打开弹窗 |
|
105 |
|
|
106 |
/** 提交表单 */ |
|
107 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
108 |
const submitForm = async () => { |
|
109 |
// 校验表单 |
|
110 |
if (!formRef) return |
|
111 |
const valid = await formRef.value.validate() |
|
112 |
if (!valid) return |
|
113 |
// 提交请求 |
|
114 |
formLoading.value = true |
|
115 |
try { |
|
116 |
const data = formData.value as unknown as HttpTokenApi.HttpTokenVO |
|
117 |
if (formType.value === 'create') { |
|
118 |
await HttpTokenApi.createHttpToken(data) |
|
119 |
message.success(t('common.createSuccess')) |
|
120 |
} else { |
|
121 |
await HttpTokenApi.updateHttpToken(data) |
|
122 |
message.success(t('common.updateSuccess')) |
|
123 |
} |
|
124 |
dialogVisible.value = false |
|
125 |
// 发送操作成功的事件 |
|
126 |
emit('success') |
|
127 |
} finally { |
|
128 |
formLoading.value = false |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
/** 重置表单 */ |
|
133 |
const resetForm = () => { |
|
134 |
formData.value = { |
|
135 |
id: undefined, |
|
136 |
loginUrl: undefined, |
|
137 |
clientId: undefined, |
|
138 |
clientSecret: undefined, |
|
139 |
username: undefined, |
|
140 |
password: undefined, |
|
141 |
token: undefined, |
|
142 |
refreshFreq: undefined |
|
143 |
} |
|
144 |
formRef.value?.resetFields() |
|
145 |
} |
|
146 |
</script> |