optimize: ♻️ 删除不需要的主键id
This commit is contained in:
parent
5f393fd291
commit
61e753c520
|
@ -0,0 +1,82 @@
|
|||
(async function requestPath() {
|
||||
// 获取基础paths对象
|
||||
const response = await fetch('http://localhost:7070/v3/api-docs/admin%E7%AE%A1%E7%90%86%E5%91%98%E6%8E%A5%E5%8F%A3%E8%AF%B7%E6%B1%82', { method: 'GET' });
|
||||
const json = await response.json();
|
||||
const paths = json.paths;
|
||||
|
||||
// 设置父级id顺序
|
||||
let id = 1;
|
||||
|
||||
// 最后整理的数据内容
|
||||
const data = {};
|
||||
|
||||
// 获取所有键
|
||||
Object.keys(paths)
|
||||
.filter(item => !item.includes('noAuth'))
|
||||
.forEach(key => {
|
||||
const pathKey = paths[key];
|
||||
const { tags, description } = pathKey[Object.keys(pathKey)[0]];
|
||||
const tag = tags[0];
|
||||
|
||||
// 父级内容为info信息
|
||||
const path = key.match(/\w+\/\w+/, key)[0];
|
||||
const info = {
|
||||
id: 1,
|
||||
parentId: 0,
|
||||
powerCode: path.replaceAll('/', '::'),
|
||||
powerName: tag,
|
||||
requestUrl: undefined,
|
||||
};
|
||||
|
||||
// 整理子级内容信息
|
||||
const powerCode = key.replace('/admin', '').replace('/{page}/{limit}', '').replace('/{id}', '').replace('/', '');
|
||||
const item = {
|
||||
parentId: info.id,
|
||||
powerCode: powerCode.replaceAll('/', '::'),
|
||||
powerName: description,
|
||||
requestUrl: key.replace('{page}', '\\d+').replace('{limit}', '\\d+').replace('/{id}', '\\d+'),
|
||||
};
|
||||
|
||||
// 向父级内容添加子级Children内容
|
||||
if (!data[tag]) {
|
||||
data[tag] = {
|
||||
info,
|
||||
children: [item],
|
||||
};
|
||||
}
|
||||
data[tag].children.push(item);
|
||||
});
|
||||
|
||||
// 便利整理好的参数data
|
||||
for (const item in data) {
|
||||
// 先添加父级内容
|
||||
const info = data[item].info;
|
||||
info.id = id;
|
||||
await add(info);
|
||||
|
||||
// 遍历子级内容向服务器添加
|
||||
const children = data[item].children;
|
||||
for (const item1 of children) {
|
||||
item1.parentId = id;
|
||||
await add(item1);
|
||||
}
|
||||
|
||||
// 父级添加后id增加
|
||||
id++;
|
||||
}
|
||||
})();
|
||||
|
||||
// 向服务器添加的内容
|
||||
async function add(data) {
|
||||
const response = await fetch('http://localhost:7070/admin/power/addPower', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
token:
|
||||
'eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_yWLQQqDMBBF7zJrUzJ24iSuirtuvINxJtCCtlYDLdK7G3D3ee_9HdYcoYUuz_MPKtDvG1rkOjiPTU0V5FU_dynsnP0wacnxiiFYi45uy3IZX1O5PrdHMWNiFK9kUiQxpMwmKDrjZUiaohA3Fv4HKp13G3cAAAA.qDzOIts0Wckglwm3L-BcprzRiW06ARC6Q8jN9qbVjQ0',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
const json = await response.json();
|
||||
console.log(json);
|
||||
}
|
|
@ -7,8 +7,6 @@ export const columns: TableColumnList = [
|
|||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
// 邮箱
|
||||
{ label: $t('emailUsers_email'), prop: 'email' },
|
||||
// // 邮件模板
|
||||
// { label: $t('emailUsers_emailTemplate'), prop: 'emailTemplate' },
|
||||
// 密码
|
||||
{ label: $t('emailUsers_password'), prop: 'password' },
|
||||
// Host地址
|
||||
|
|
|
@ -5,7 +5,6 @@ import { $t } from '@/plugins/i18n';
|
|||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
// icon 类名
|
||||
{ label: $t('menuIcon_iconCode'), prop: 'iconCode', slot: 'iconCode' },
|
||||
// icon 名称
|
||||
|
|
|
@ -6,7 +6,6 @@ import { $t } from '@/plugins/i18n';
|
|||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
{ label: $t('i18n.keyName'), prop: 'keyName' },
|
||||
{ label: $t('i18n.translation'), prop: 'translation' },
|
||||
{ label: $t('i18n.typeName'), prop: 'typeName' },
|
||||
|
|
|
@ -5,7 +5,6 @@ export const editMap = ref({});
|
|||
|
||||
export const columns: TableColumnList = [
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
{ label: $t('i18n_typeName'), prop: 'typeName' },
|
||||
{ label: $t('i18n_summary'), prop: 'summary' },
|
||||
{ label: $t('isDefault'), prop: 'isDefault', slot: 'isDefault' },
|
||||
|
|
|
@ -4,7 +4,7 @@ import { $t } from '@/plugins/i18n';
|
|||
// 表格列
|
||||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1 },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
// 文件的名称
|
||||
{ label: $t('files_filename'), prop: 'filename', width: 400 },
|
||||
// 文件在服务器上的存储路径
|
||||
|
|
|
@ -4,7 +4,7 @@ import { columns } from '@/views/monitor/schedulers/utils/columns';
|
|||
import PureTableBar from '@/components/TableBar/src/bar';
|
||||
import AddFill from '@iconify-icons/ri/add-circle-line';
|
||||
import PureTable from '@pureadmin/table';
|
||||
import { deleteIds, onAdd, onDelete, onDeleteBatch, onSearch, onUpdate } from '@/views/monitor/schedulers/utils/hooks';
|
||||
import { onAdd, onDelete, onSearch, onUpdate } from '@/views/monitor/schedulers/utils/hooks';
|
||||
import Delete from '@iconify-icons/ep/delete';
|
||||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
import Refresh from '@iconify-icons/ep/refresh';
|
||||
|
@ -35,14 +35,6 @@ const onPageSizeChange = async (value: number) => {
|
|||
await onSearch();
|
||||
};
|
||||
|
||||
/**
|
||||
* * 选择多行
|
||||
* @param rows
|
||||
*/
|
||||
const onSelectionChange = (rows: Array<any>) => {
|
||||
deleteIds.value = rows.map((row: any) => row.id);
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置表单
|
||||
* @param formEl
|
||||
|
@ -88,11 +80,6 @@ onMounted(() => {
|
|||
<PureTableBar :columns="columns" title="Schedulers视图" @fullscreen="tableRef.setAdaptive()" @refresh="onSearch">
|
||||
<template #buttons>
|
||||
<el-button :icon="useRenderIcon(AddFill)" type="primary" @click="onAdd"> {{ $t('add_new') }}</el-button>
|
||||
|
||||
<!-- 批量删除按钮 -->
|
||||
<el-button v-show="deleteIds.length > 0" :icon="useRenderIcon(Delete)" type="danger" @click="onDeleteBatch">
|
||||
{{ $t('delete_batches') }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<template v-slot="{ size, dynamicColumns }">
|
||||
|
@ -113,7 +100,6 @@ onMounted(() => {
|
|||
showOverflowTooltip
|
||||
table-layout="auto"
|
||||
@page-size-change="onPageSizeChange"
|
||||
@selection-change="onSelectionChange"
|
||||
@page-current-change="onCurrentPageChange"
|
||||
>
|
||||
<template #createUser="{ row }">
|
||||
|
|
|
@ -3,7 +3,6 @@ import { $t } from '@/plugins/i18n';
|
|||
|
||||
// 表格列
|
||||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
// 任务名称
|
||||
{ label: $t('schedulers_jobName'), prop: 'jobName' },
|
||||
|
|
|
@ -7,8 +7,6 @@ import type { FormItemProps } from '@/views/monitor/schedulers/utils/types';
|
|||
import { $t } from '@/plugins/i18n';
|
||||
|
||||
export const formRef = ref();
|
||||
// 删除ids
|
||||
export const deleteIds = ref([]);
|
||||
const schedulersStore = useSchedulersStore();
|
||||
|
||||
/**
|
||||
|
@ -108,23 +106,3 @@ export const onDelete = async (row: any) => {
|
|||
await schedulersStore.deleteSchedulers(data);
|
||||
await onSearch();
|
||||
};
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
export const onDeleteBatch = async () => {
|
||||
const ids = deleteIds.value;
|
||||
|
||||
// 是否确认删除
|
||||
const result = await messageBox({
|
||||
title: $t('confirm_delete'),
|
||||
showMessage: false,
|
||||
confirmMessage: undefined,
|
||||
cancelMessage: $t('cancel_delete'),
|
||||
});
|
||||
if (!result) return;
|
||||
|
||||
// 删除数据
|
||||
await schedulersStore.deleteSchedulers(ids);
|
||||
await onSearch();
|
||||
};
|
||||
|
|
|
@ -5,7 +5,6 @@ import { $t } from '@/plugins/i18n';
|
|||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
// 分组名称
|
||||
{ label: $t('schedulersGroup_groupName'), prop: 'groupName' },
|
||||
// 分组详情
|
||||
|
|
|
@ -8,8 +8,6 @@ export const isAddUserinfo = ref(false);
|
|||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
// 主键
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
// 用户名
|
||||
{ label: $t('adminUser_username'), prop: 'username', width: 260 },
|
||||
// 状态
|
||||
|
|
|
@ -5,9 +5,6 @@ import { $t } from '@/plugins/i18n';
|
|||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
// 父级id
|
||||
{ label: $t('power_parentId'), prop: 'parentId' },
|
||||
// 权限编码
|
||||
{ label: $t('power_powerCode'), prop: 'powerCode' },
|
||||
// 权限名称
|
||||
|
|
|
@ -5,7 +5,6 @@ import { $t } from '@/plugins/i18n';
|
|||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
// 角色代码
|
||||
{ label: $t('role_roleCode'), prop: 'roleCode' },
|
||||
// 描述
|
||||
|
|
Loading…
Reference in New Issue