150 lines
4.5 KiB
Vue
150 lines
4.5 KiB
Vue
<template>
|
|
<el-dialog :title="form.id ? '编辑' : '新增'" v-model="visible" :close-on-click-modal="false" draggable>
|
|
<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="140px" v-loading="loading">
|
|
<el-row :gutter="24">
|
|
<el-col :span="24" class="mb20">
|
|
<el-form-item label="应用名" prop="name">
|
|
<el-input v-model="form.name" placeholder="请输入应用名" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24" class="mb20">
|
|
<el-form-item label="appKey" prop="appKey">
|
|
<el-input v-model="form.appKey" placeholder="请输入appKey" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24" class="mb20">
|
|
<el-form-item label="第三方token" prop="appToken">
|
|
<el-input v-model="form.appToken" placeholder="请输入第三方token" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24" class="mb20">
|
|
<el-form-item label="第三方刷新token" prop="appRefreshToken">
|
|
<el-input v-model="form.appRefreshToken" placeholder="请输入第三方刷新token" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24" class="mb20">
|
|
<el-form-item label="基础请求路径" prop="baseUrl">
|
|
<el-input v-model="form.baseUrl" placeholder="请输入基础请求路径" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24" class="mb20">
|
|
<el-form-item label="环境" prop="env">
|
|
<dict-select v-model="form.env" :options="third_env" placeholder="请选择" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24" class="mb20">
|
|
<el-form-item label="备注" prop="remark">
|
|
<el-input v-model="form.remark" placeholder="请输入备注" type="textarea" :autosize="{ minRows: 6 }" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
</el-row>
|
|
</el-form>
|
|
<template #footer>
|
|
<span class="dialog-footer">
|
|
<el-button @click="visible = false">取消</el-button>
|
|
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
|
|
</span>
|
|
</template>
|
|
</el-dialog>
|
|
</template>
|
|
|
|
<script setup lang="ts" name="ThirdKeyManageDialog">
|
|
import { useDict } from '/@/hooks/dict';
|
|
import { useMessage } from "/@/hooks/message";
|
|
import { rule } from '/@/utils/validate';
|
|
|
|
import * as ThirdKeyManageApi from "/@/api/thirdSelf/thirdKeyManage";
|
|
|
|
const emit = defineEmits(['refresh']);
|
|
|
|
// 定义变量内容
|
|
const dataFormRef = ref();
|
|
const visible = ref(false)
|
|
const loading = ref(false)
|
|
|
|
// 定义字典
|
|
// 定义查询字典
|
|
const { yes_no_type, third_env } = useDict("yes_no_type", "third_env")
|
|
|
|
// 提交表单数据
|
|
const form = reactive({
|
|
id: '',
|
|
name: '',
|
|
remark: '',
|
|
enabled: '',
|
|
appKey: '',
|
|
appToken: '',
|
|
appRefreshToken: '',
|
|
env: '',
|
|
baseUrl: '',
|
|
});
|
|
|
|
// 定义校验规则
|
|
const dataRules = ref({
|
|
name: [{ required: true, message: '应用名不能为空', trigger: 'blur' }],
|
|
appKey: [{ required: true, message: 'appKey不能为空', trigger: 'blur' }],
|
|
appToken: [{ required: true, message: '第三方token不能为空', trigger: 'blur' }],
|
|
appRefreshToken: [{ required: true, message: '第三方刷新token不能为空', trigger: 'blur' }],
|
|
env: [{ required: true, message: '环境不能为空', trigger: 'blur' }],
|
|
baseUrl: [{ required: true, message: '基础请求路径不能为空', trigger: 'blur' }],
|
|
})
|
|
|
|
// 打开弹窗
|
|
const openDialog = (id: string) => {
|
|
visible.value = true
|
|
form.id = ''
|
|
|
|
// 重置表单数据
|
|
nextTick(() => {
|
|
dataFormRef.value?.resetFields();
|
|
});
|
|
|
|
// 获取thirdKeyManage信息
|
|
if (id) {
|
|
form.id = id
|
|
getthirdKeyManageData(id)
|
|
}
|
|
};
|
|
|
|
// 提交
|
|
const onSubmit = async () => {
|
|
const valid = await dataFormRef.value.validate().catch(() => { });
|
|
if (!valid) return false;
|
|
|
|
try {
|
|
loading.value = true;
|
|
form.id ? await ThirdKeyManageApi.putObj(form) : await ThirdKeyManageApi.addObj(form);
|
|
useMessage().success(form.id ? '修改成功' : '添加成功');
|
|
visible.value = false;
|
|
emit('refresh');
|
|
} catch (err: any) {
|
|
useMessage().error(err.msg);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
|
|
// 初始化表单数据
|
|
const getthirdKeyManageData = (id: string) => {
|
|
// 获取数据
|
|
loading.value = true
|
|
ThirdKeyManageApi.getObj(id).then((res: any) => {
|
|
Object.assign(form, res.data)
|
|
}).finally(() => {
|
|
loading.value = false
|
|
})
|
|
};
|
|
|
|
// 暴露变量
|
|
defineExpose({
|
|
openDialog
|
|
});
|
|
</script> |