perf(权限模块): 优化权限代码

1.修改权限命名
2.优化事务代码
This commit is contained in:
Kven 2024-12-23 13:07:25 +08:00
parent 2bff98212b
commit ffe50d431c
3 changed files with 14 additions and 171 deletions

View File

@ -11,7 +11,7 @@ export interface AuthCreateRecord {
// 基础信息
export interface AuthRecord extends AuthCreateRecord {
id: string;
id?: string;
}
// export interface RoleListRecord extends AuthRecord {
@ -21,7 +21,7 @@ export interface AuthRecord extends AuthCreateRecord {
// 查询所有的权限列表
export function queryAuthList(data: any) {
return axios({
url: '/api/rest/auth', // 路径
url: '/api/rest/authority', // 路径
method: 'get',
params: data, // 参数
})
@ -29,29 +29,26 @@ export function queryAuthList(data: any) {
// 切换启用状态
export function enabled(id: string) {
return axios.patch(`/api/rest/auth/toggle/${id}`);
return axios.patch(`/api/rest/authority/toggle/${id}`);
}
// 删除
export function remove(id: string) {
return axios.delete(`/api/rest/auth/${id}`);
return axios.delete(`/api/rest/authority/${id}`);
}
// 添加
export function create(data: AuthCreateRecord) {
return axios.post(`/api/rest/auth`, data);
return axios.post(`/api/rest/authority`, data);
}
// 更新
export function update(data: AuthRecord) {
return axios.patch(`/api/rest/auth/${data.id}`, data);
return axios.patch(`/api/rest/authority/${data.id}`, data);
}
// 获取详情
export function getDetail(id: string) {
return axios.get<AuthRecord>(`/api/rest/auth/${id}`);
return axios.get<AuthRecord>(`/api/rest/authority/${id}`);
}
// export function queryRoles(params?: ListParams<Partial<RoleRecord>>) {
// return queryList<RoleRecord>(`/api/rest/role/query`, params);
// }

View File

@ -25,7 +25,7 @@
field="name"
label="权限名称"
:validate-trigger="['change', 'input']"
:rules="[{ required: true, message: t('auth.info.name.required') }]"
:rules="[{ required: true }]"
>
<a-input
v-model="formData.name"
@ -46,7 +46,6 @@
</template>
<script lang="ts" setup>
import { useI18n } from 'vue-i18n';
import useVisible from '@/hooks/visible';
import { computed, PropType, ref } from 'vue';
import { FormInstance } from '@arco-design/web-vue/es/form';
@ -60,41 +59,21 @@
},
isCreate: Boolean,
});
const { t } = useI18n();
const modalTitle = computed(() => {
return props.isCreate ? t('Create Auth Info') : t('Edit Auth Info');
return props.isCreate ? '创建权限' : '修改权限';
});
const { visible, setVisible } = useVisible(false);
const createEditRef = ref<FormInstance>();
const authStore = useAuthStore();
const formData = ref<AuthRecord>({
id: '',
name: '',
// dataScope: '',
// permissionIds: [],
enabled: true,
remark: '',
// authorities: [],
const formData = ref<any>({
...props.prem,
});
const emit = defineEmits(['refresh']);
//
const handleClick = () => {
const authId = props.prem?.id;
//
if (!props.isCreate && authId) {
authStore
.getAuthDetail(authId)
.then((res:any) => {
formData.value = res.data;
})
.then(() => {
setVisible(true);
});
} else {
setVisible(true);
}
setVisible(true);
};
//
@ -106,7 +85,7 @@
const res = await authStore.createAuth(formData.value);
if (res.status === 200) {
Message.success({
content: t('create.sucess'),
content: '创建成功',
duration: 5 * 1000,
});
}
@ -116,7 +95,7 @@
const res = await authStore.updateAuth(formData.value);
if (res.status === 200) {
Message.success({
content: t('modify.sucess'),
content: '修改成功',
duration: 5 * 1000,
});
}

View File

@ -1,133 +0,0 @@
<template>
<a-table row-key="id" :loading="loading" :pagination="false" :columns="columns" :data="data" :bordered="false"
:size="size" style="margin-bottom: 40px" @pageChange="onPageChange">
<template #index="{ rowIndex }">
{{ rowIndex + 1 }}
</template>
<template #createTime="{ record }">
{{ dayjs(record.createTime).format('YYYY-MM-DD') }}
</template>
<template #enabled="{ record }">
<a-switch :model-value="record.enabled" :checked-value="true" :unchecked-value="false"
@change="enabledStatus(record)" />
</template>
<template #operations="{ record }">
<!-- 编辑 -->
<AuthEdit ref="editRef" :prem="record" :is-create="false" @refresh="fetchData" />
<a-popconfirm :content="t('Confirm the deletion of this role')" type="error" @ok="handleDelete(record)">
<a-button type="outline" size="small" status="danger" style="padding: 7px">
<template #icon><icon-delete /></template>
删除
</a-button>
</a-popconfirm>
</template>
</a-table>
</template>
<script lang="ts" setup>
import { defineProps, defineEmits} from 'vue';
import dayjs from 'dayjs';
import { useI18n } from 'vue-i18n';
import { Message } from '@arco-design/web-vue';
import { useAuthStore } from '@/store';
import { AuthRecord } from '@/api/authority';
// import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
import AuthEdit from './auth-edit.vue';
const authStore = useAuthStore();
const props = defineProps({
loading: Boolean,
data: Array,
size: String,
});
const { t } = useI18n();
const emit = defineEmits(['pageChange', 'refresh','search']);
//
// const columns = computed<TableColumnData[]>(() => [
// {
// title: t('roleTable.columns.index'),
// dataIndex: 'index',
// slotName: 'index',
// },
// {
// title: t('roleTable.columns.name'),
// dataIndex: 'name',
// sortable: {
// sortDirections: ['ascend', 'descend'],
// },
// },
// {
// title: t('roleTable.columns.remark'),
// dataIndex: 'remark',
// },
// {
// title: t('roleTable.columns.createTime'),
// dataIndex: 'createTime',
// slotName: 'createTime',
// sortable: {
// sortDirections: ['ascend', 'descend'],
// },
// },
// {
// title: t('roleTable.columns.enabled'),
// dataIndex: 'enabled',
// slotName: 'enabled',
// },
// {
// title: t('searchTable.columns.operations'),
// dataIndex: 'operations',
// slotName: 'operations',
// },
// ]);
const fetchData = () => {
emit('refresh');
};
//
const onPageChange = (page: number) => {
emit('pageChange', page);
};
//
const enabledStatus = async (record: string) => {
record.enabled = !record.enabled;
const res = await authStore.enabledAuth(record.id);
if (res.status === 200) {
Message.success({
content: t('modify.status.sucess'),
duration: 3 * 1000,
});
} else {
Message.error({
content: t('modify.status.fail'),
duration: 3 * 1000,
});
}
};
//
const handleDelete = async (record: AuthRecord) => {
const res = await authStore.removeAuth(record.id);
if (res.status === 200) {
Message.success({
content: t('delete.auth.sucess'),
duration: 5 * 1000,
});
emit('search');
} else {
Message.error({
content: t('delete.auth.fail'),
duration: 3 * 1000,
});
}
};
// watch(() => columns.value, deepClone, { deep: true, immediate: true });
</script>
<style scoped>
/* 添加一些样式 */
</style>