From cfaf8bf67f276d29f67d32f61b09cb38f14de081 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期五, 20 九月 2024 14:49:59 +0800 Subject: [PATCH] http 认证 --- src/api/data/channel/http/index.ts | 2 src/views/data/channel/http/token/TokenForm.vue | 146 ++++++++++++++++++++ src/views/data/channel/http/api/HttpApiForm.vue | 46 +++++ src/views/data/channel/http/token/index.vue | 153 +++++++++++++++++++++ src/utils/constants.ts | 5 src/api/data/channel/http/token.ts | 9 + src/views/data/channel/http/api/tag/TagForm.vue | 0 src/views/data/channel/http/api/index.vue | 0 src/views/data/channel/http/api/tag/index.vue | 0 9 files changed, 353 insertions(+), 8 deletions(-) diff --git a/src/api/data/channel/http/index.ts b/src/api/data/channel/http/index.ts index ef106df..93b1683 100644 --- a/src/api/data/channel/http/index.ts +++ b/src/api/data/channel/http/index.ts @@ -9,6 +9,8 @@ collectType: string, param: string, descp: string, + isAuth: number, + authUrl: string, status: number } diff --git a/src/api/data/channel/http/token.ts b/src/api/data/channel/http/token.ts index 5f87245..a5120c8 100644 --- a/src/api/data/channel/http/token.ts +++ b/src/api/data/channel/http/token.ts @@ -2,17 +2,17 @@ export interface HttpTokenVO { id: string - apiId: string, loginUrl: string, clientId: string, clientSecret: string, username: string, password: string, + refreshFreq: string, token: string, } export interface HttpTokenPageReqVO extends PageParam { - apiId?: string + loginUrl?: string } // 查询HttpToken列表 @@ -20,6 +20,11 @@ return request.get({ url: '/data/channel/http/token/page', params }) } +// 查询HttpToken列表 +export const getHttpTokenList = () => { + return request.get({ url: '/data/channel/http/token/list'}) +} + // 查询HttpToken详情 export const getHttpToken = (id: number) => { return request.get({ url: `/data/channel/http/token/info/${id}`}) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d0b4888..870bbfb 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -456,3 +456,8 @@ ENABLE: true, // 启用 DISABLE: false // 禁用 } + +export const CommonInfraBool = { + TRUE: true, // 启用 + FALSE: false // 禁用 +} diff --git a/src/views/data/channel/http/HttpApiForm.vue b/src/views/data/channel/http/api/HttpApiForm.vue similarity index 76% rename from src/views/data/channel/http/HttpApiForm.vue rename to src/views/data/channel/http/api/HttpApiForm.vue index e9ef92b..1df7856 100644 --- a/src/views/data/channel/http/HttpApiForm.vue +++ b/src/views/data/channel/http/api/HttpApiForm.vue @@ -46,6 +46,33 @@ </el-col> </el-row> <el-row> + <el-col :span="12"> + <el-form-item label="是否认证" prop="isAuth"> + <el-select v-model="formData.isAuth" placeholder="请选择"> + <el-option + v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)" + :key="dict.value" + :label="dict.label" + :value="dict.value" + /> + </el-select> + </el-form-item> + </el-col> + <el-col :span="12"> + <el-form-item label="认证地址" prop="authUrl"> + <el-select v-model="formData.authUrl" clearable placeholder="请选择数据源"> + <el-option + v-for="item in httpTokenList" + :key="item.id" + :label="item.loginUrl" + :value="item.id" + /> + </el-select> + </el-form-item> + </el-col> + </el-row> + + <el-row> <el-col :span="24"> <el-form-item label="描述" prop="descp"> <el-input v-model="formData.descp" placeholder="请输入描述" type="textarea" maxlength="100" @@ -62,7 +89,11 @@ </template> <script lang="ts" setup> import * as HttpApi from '@/api/data/channel/http' +import * as HttpToken from '@/api/data/channel/http/token' import { DICT_TYPE, getStrDictOptions, getBoolDictOptions } from '@/utils/dict' +import {CommonStatusEnum, CommonInfraBool} from '@/utils/constants' +import * as DataSourceConfigApi from "@/api/infra/dataSourceConfig"; +import {HttpTokenVO} from "@/api/data/channel/http/token"; defineOptions({name: 'DataHttpApiForm'}) @@ -74,14 +105,14 @@ const formType = ref('') // 表单的类型:create - 新增;update - 修改 const formData = ref({ id: undefined, - name: undefined, code: undefined, + name: undefined, url: undefined, method: undefined, - collectType: undefined, param: undefined, descp: undefined, - status: undefined + isAuth: CommonInfraBool.FALSE, + authUrl: undefined }) const formRules = reactive({ name: [{required: true, message: '名称不能为空', trigger: 'blur'}], @@ -89,6 +120,7 @@ url: [{required: true, message: 'url不能为空', trigger: 'blur'}], }) const formRef = ref() // 表单 Ref +const httpTokenList = ref([] as HttpToken.HttpTokenVO[]) /** 打开弹窗 */ const open = async (type: string, id?: number) => { @@ -105,6 +137,8 @@ formLoading.value = false } } + // 加载认证列表 + httpTokenList.value = await HttpToken.getHttpTokenList() } defineExpose({open}) // 提供 open 方法,用于打开弹窗 @@ -138,14 +172,14 @@ const resetForm = () => { formData.value = { id: undefined, - name: undefined, code: undefined, + name: undefined, url: undefined, method: undefined, - collectType: undefined, param: undefined, descp: undefined, - status: undefined + isAuth: CommonInfraBool.FALSE, + authUrl: undefined } formRef.value?.resetFields() } diff --git a/src/views/data/channel/http/index.vue b/src/views/data/channel/http/api/index.vue similarity index 100% rename from src/views/data/channel/http/index.vue rename to src/views/data/channel/http/api/index.vue diff --git a/src/views/data/channel/http/tag/TagForm.vue b/src/views/data/channel/http/api/tag/TagForm.vue similarity index 100% rename from src/views/data/channel/http/tag/TagForm.vue rename to src/views/data/channel/http/api/tag/TagForm.vue diff --git a/src/views/data/channel/http/tag/index.vue b/src/views/data/channel/http/api/tag/index.vue similarity index 100% rename from src/views/data/channel/http/tag/index.vue rename to src/views/data/channel/http/api/tag/index.vue diff --git a/src/views/data/channel/http/token/TokenForm.vue b/src/views/data/channel/http/token/TokenForm.vue new file mode 100644 index 0000000..6beef72 --- /dev/null +++ b/src/views/data/channel/http/token/TokenForm.vue @@ -0,0 +1,146 @@ +<template> + <Dialog v-model="dialogVisible" :title="dialogTitle" width="50%"> + <el-form + ref="formRef" + v-loading="formLoading" + :model="formData" + :rules="formRules" + label-width="120px" + > + <el-row> + <el-col :span="24"> + <el-form-item label="认证地址" prop="loginUrl"> + <el-input v-model="formData.loginUrl" placeholder="请输认证地址"/> + </el-form-item> + </el-col> + </el-row> + <el-row> + <el-col :span="12"> + <el-form-item label="ClientId" prop="clientId"> + <el-input v-model="formData.clientId" placeholder="请输ClientId"/> + </el-form-item> + </el-col> + <el-col :span="12"> + <el-form-item label="ClientSecret" prop="clientSecret"> + <el-input v-model="formData.clientSecret" placeholder="请输ClientSecret"/> + </el-form-item> + </el-col> + </el-row> + <el-row> + <el-col :span="12"> + <el-form-item label="用户名" prop="username"> + <el-input v-model="formData.username" placeholder="请输用户名"/> + </el-form-item> + </el-col> + <el-col :span="12"> + <el-form-item label="密码" prop="password"> + <el-input v-model="formData.password" placeholder="请输密码"/> + </el-form-item> + </el-col> + </el-row> + <el-row> + <el-col :span="12"> + <el-form-item label="刷新频率" prop="refreshFreq"> + <el-input v-model="formData.refreshFreq" placeholder="请输刷新频率"/> + </el-form-item> + </el-col> + </el-row> + </el-form> + <template #footer> + <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> + <el-button @click="dialogVisible = false">取 消</el-button> + </template> + </Dialog> +</template> +<script lang="ts" setup> +import * as HttpTokenApi from '@/api/data/channel/http/token' +import { DICT_TYPE, getStrDictOptions, getBoolDictOptions } from '@/utils/dict' + +defineOptions({name: 'HttpTokenForm'}) + +const {t} = useI18n() // 国际化 +const message = useMessage() // 消息弹窗 +const dialogVisible = ref(false) // 弹窗的是否展示 +const dialogTitle = ref('') // 弹窗的标题 +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 +const formType = ref('') // 表单的类型:create - 新增;update - 修改 +const formData = ref({ + id: undefined, + loginUrl: undefined, + clientId: undefined, + clientSecret: undefined, + username: undefined, + password: undefined, + token: undefined, + refreshFreq: undefined +}) +const formRules = reactive({ + loginUrl: [{required: true, message: '登录地址不能为空', trigger: 'blur'}], + username: [{required: true, message: '用户名不能为空', trigger: 'blur'}], + password: [{required: true, message: '密码不能为空', trigger: 'blur'}], + refreshFreq: [{required: true, message: '刷新频率不能为空', trigger: 'blur'}] +}) +const formRef = ref() // 表单 Ref + +/** 打开弹窗 */ +const open = async (type: string, id?: number, apiId?: string) => { + dialogVisible.value = true + dialogTitle.value = t('action.' + type) + formType.value = type + resetForm() + if (apiId) { + formData.value.apiId = apiId + } + // 修改时,设置数据 + if (id) { + formLoading.value = true + try { + formData.value = await HttpTokenApi.getHttpToken(id) + } finally { + formLoading.value = false + } + } +} +defineExpose({open}) // 提供 open 方法,用于打开弹窗 + +/** 提交表单 */ +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 +const submitForm = async () => { + // 校验表单 + if (!formRef) return + const valid = await formRef.value.validate() + if (!valid) return + // 提交请求 + formLoading.value = true + try { + const data = formData.value as unknown as HttpTokenApi.HttpTokenVO + if (formType.value === 'create') { + await HttpTokenApi.createHttpToken(data) + message.success(t('common.createSuccess')) + } else { + await HttpTokenApi.updateHttpToken(data) + message.success(t('common.updateSuccess')) + } + dialogVisible.value = false + // 发送操作成功的事件 + emit('success') + } finally { + formLoading.value = false + } +} + +/** 重置表单 */ +const resetForm = () => { + formData.value = { + id: undefined, + loginUrl: undefined, + clientId: undefined, + clientSecret: undefined, + username: undefined, + password: undefined, + token: undefined, + refreshFreq: undefined + } + formRef.value?.resetFields() +} +</script> diff --git a/src/views/data/channel/http/token/index.vue b/src/views/data/channel/http/token/index.vue new file mode 100644 index 0000000..c552c9f --- /dev/null +++ b/src/views/data/channel/http/token/index.vue @@ -0,0 +1,153 @@ +<template> + <!-- 搜索 --> + <ContentWrap> + <el-form + class="-mb-15px" + :model="queryParams" + ref="queryFormRef" + :inline="true" + label-width="68px" + > + <el-form-item label="名称" prop="name"> + <el-input + v-model="queryParams.name" + placeholder="请输入名称" + clearable + @keyup.enter="handleQuery" + class="!w-240px" + /> + </el-form-item> + <el-form-item> + <el-button @click="handleQuery"> + <Icon icon="ep:search" class="mr-5px"/> + 搜索 + </el-button> + <el-button @click="resetQuery"> + <Icon icon="ep:refresh" class="mr-5px"/> + 重置 + </el-button> + <el-button + type="primary" + plain + @click="openForm('create')" + v-hasPermi="['data:channel-http:create']" + > + <Icon icon="ep:plus" class="mr-5px"/> + 新增 + </el-button> + </el-form-item> + </el-form> + </ContentWrap> + + <!-- 列表 --> + <ContentWrap> + <el-table v-loading="loading" :data="list"> + <el-table-column label="认证地址" header-align="center" align="left" min-width="300" prop="loginUrl"/> + <el-table-column label="ClientId" align="center" prop="clientId"/> + <el-table-column label="ClientSecret" align="center" prop="clientSecret"/> + <el-table-column label="用户名" align="center" prop="username"/> + <el-table-column label="密码" align="center" prop="password"/> + <el-table-column label="刷新频率" align="center" prop="refreshFreq"/> + <el-table-column label="操作" align="center" min-width="110" fixed="right"> + <template #default="scope"> + <el-button + link + type="primary" + @click="openForm('update', scope.row.id)" + v-hasPermi="['data:channel-http:update']" + > + 编辑 + </el-button> + <el-button + link + type="danger" + @click="handleDelete(scope.row.id)" + v-hasPermi="['data:channel-http:delete']" + > + 删除 + </el-button> + </template> + </el-table-column> + </el-table> + <!-- 分页 --> + <Pagination + :total="total" + v-model:page="queryParams.pageNo" + v-model:limit="queryParams.pageSize" + @pagination="getList" + /> + </ContentWrap> + + <!-- 表单弹窗:添加/修改 --> + <TokenForm ref="formRef" @success="getList"/> + +</template> +<script lang="ts" setup> +import * as HttpToken from '@/api/data/channel/http/token' +import TokenForm from './TokenForm.vue' + +defineOptions({name: 'HttpToken'}) + +const message = useMessage() // 消息弹窗 +const {t} = useI18n() // 国际化 + +const loading = ref(true) // 列表的加载中 +const total = ref(0) // 列表的总页数 +const list = ref([]) // 列表的数据 +const queryParams = reactive({ + pageNo: 1, + pageSize: 10, + loginUrl: undefined +}) +const queryFormRef = ref() // 搜索的表单 +const exportLoading = ref(false) // 导出的加载中 + +/** 查询列表 */ +const getList = async () => { + loading.value = true + try { + const page = await HttpToken.getHttpTokenPage(queryParams) + list.value = page.list + total.value = page.total + } finally { + loading.value = false + } +} + +/** 搜索按钮操作 */ +const handleQuery = () => { + queryParams.pageNo = 1 + getList() +} + +/** 重置按钮操作 */ +const resetQuery = () => { + queryFormRef.value.resetFields() + handleQuery() +} + +/** 添加/修改操作 */ +const formRef = ref() +const openForm = (type: string, id?: number) => { + formRef.value.open(type, id) +} + +/** 删除按钮操作 */ +const handleDelete = async (id: number) => { + try { + // 删除的二次确认 + await message.delConfirm() + // 发起删除 + await HttpToken.deleteHttpToken(id) + message.success(t('common.delSuccess')) + // 刷新列表 + await getList() + } catch { + } +} + +/** 初始化 **/ +onMounted(async () => { + await getList() +}) +</script> -- Gitblit v1.9.3