Files
mp-10579/src/views/system/access-key/index.vue
赵忠林 4af50e6449 style(api): 统一代码格式化规范
- 调整 import 语句格式,统一空格和引号风格
- 修复函数参数跨行时的格式对齐问题
- 清理多余空行和注释中的空白字符
- 统一对象属性结尾逗号的使用规范
- 规范化字符串拼接和模板语法的格式
- 优化长参数列表的换行和缩进格式
2026-01-17 17:04:46 +08:00

150 lines
4.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="page">
<a-page-header :ghost="false" title="秘钥管理">
<div class="ele-text-secondary">
API key 是您访WebSoft-API 的密钥具有该账户完全的权限请您妥善保管
</div>
</a-page-header>
<div class="ele-body">
<a-card :bordered="false">
<!-- 表格 -->
<ele-pro-table
ref="tableRef"
row-key="id"
:columns="columns"
:datasource="datasource"
:where="defaultWhere"
cache-key="userBalanceLogTable"
>
<template #toolbar>
<a-space>
<a-button type="primary" class="ele-btn-icon" @click="openEdit()">
<span>创建 API key</span>
</a-button>
</a-space>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'accessSecret'">
<span> sk-****************** </span>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a-popconfirm
placement="topRight"
title="确定要删除此用户吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
</div>
<!-- 编辑弹窗 -->
<AccessKeyEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</template>
<script lang="ts" setup>
import { ref, reactive } from 'vue';
import { message } from 'ant-design-vue/es';
import type { EleProTable } from 'ele-admin-pro/es';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import AccessKeyEdit from './components/accesskey-edit.vue';
import { toDateString } from 'ele-admin-pro/es';
import { pageAccessKey, removeAccessKey } from '@/api/system/access-key';
import { AccessKey, AccessKeyParam } from '@/api/system/access-key/model';
import { messageLoading } from 'ele-admin-pro/es';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: '名称',
key: 'accessKey',
dataIndex: 'accessKey',
showSorterTooltip: false
},
{
title: 'Key',
key: 'accessSecret',
dataIndex: 'accessSecret',
showSorterTooltip: false
},
{
title: '创建时间',
dataIndex: 'createTime',
align: 'center',
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd HH:mm:ss'),
width: 180
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center'
}
]);
// 表格选中数据
const selection = ref<AccessKey[]>([]);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 当前编辑数据
const current = ref<any>(null);
// 默认搜索条件
const defaultWhere = reactive({
code: '',
phone: '',
username: '',
nickname: '',
userId: undefined
});
// 表格数据源
const datasource: DatasourceFunction = ({ where }) => {
return pageAccessKey({ ...where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: any) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 删除单个 */
const remove = (row: AccessKey) => {
const hide = messageLoading('请求中..', 0);
removeAccessKey(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 搜索 */
const reload = (where?: AccessKeyParam) => {
selection.value = [];
tableRef?.value?.reload({ page: 1, where });
};
</script>
<script lang="ts">
export default {
name: 'AccessKeyIndex'
};
</script>