2024-11-12 15:44:05 +08:00
|
|
|
<template>
|
2025-02-17 22:42:51 +08:00
|
|
|
<div class="container">
|
|
|
|
<Breadcrumb :items="['系统管理', '权限管理']" />
|
|
|
|
<a-card class="general-card" title=" ">
|
|
|
|
<a-row>
|
|
|
|
<a-col :flex="1">
|
|
|
|
<a-form
|
|
|
|
:label-col-props="{ span: 6 }"
|
|
|
|
:wrapper-col-props="{ span: 12 }"
|
|
|
|
label-align="right"
|
|
|
|
:model="formModel"
|
|
|
|
>
|
|
|
|
<a-row :gutter="16">
|
|
|
|
<a-col :span="12">
|
|
|
|
<a-form-item field="title" label="权限名称">
|
|
|
|
<a-input
|
|
|
|
placeholder="请输入权限名称"
|
|
|
|
v-model="formModel.name"
|
|
|
|
></a-input>
|
|
|
|
</a-form-item>
|
|
|
|
</a-col>
|
2024-11-12 15:44:05 +08:00
|
|
|
</a-row>
|
2025-02-17 22:42:51 +08:00
|
|
|
</a-form>
|
|
|
|
</a-col>
|
|
|
|
<a-divider style="height: 42px" direction="vertical" />
|
|
|
|
<a-col :flex="'46px'" style="text-align: right">
|
|
|
|
<a-space :size="18">
|
|
|
|
<a-button type="primary" @click="search">
|
|
|
|
<template #icon>
|
|
|
|
<icon-search />
|
|
|
|
</template>
|
|
|
|
查询
|
|
|
|
</a-button>
|
|
|
|
<a-button @click="reset">
|
|
|
|
<template #icon>
|
|
|
|
<icon-refresh />
|
|
|
|
</template>
|
|
|
|
重置
|
|
|
|
</a-button>
|
|
|
|
</a-space>
|
|
|
|
</a-col>
|
|
|
|
</a-row>
|
|
|
|
<a-divider style="margin-top: 10px" />
|
|
|
|
<a-row style="margin-bottom: 16px">
|
|
|
|
<a-col :span="12">
|
|
|
|
<a-space>
|
|
|
|
<AuthEdit ref="createRef" :is-create="true" @refresh="fetchData" />
|
|
|
|
</a-space>
|
|
|
|
</a-col>
|
|
|
|
<a-col
|
|
|
|
:span="12"
|
|
|
|
style="display: flex; align-items: center; justify-content: end"
|
|
|
|
>
|
|
|
|
<a-tooltip content="刷新">
|
|
|
|
<div class="action-icon" @click="fetchData">
|
|
|
|
<icon-refresh size="18" />
|
|
|
|
</div>
|
|
|
|
</a-tooltip>
|
|
|
|
<a-dropdown @select="handleSelectDensity">
|
|
|
|
<a-tooltip content="密度">
|
|
|
|
<div class="action-icon"><icon-line-height size="18" /></div>
|
|
|
|
</a-tooltip>
|
|
|
|
<template #content>
|
|
|
|
<a-doption
|
|
|
|
v-for="item in densityList"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value"
|
|
|
|
:class="{ active: item.value === sizeof }"
|
|
|
|
>
|
|
|
|
<span>{{ item.name }}</span>
|
|
|
|
</a-doption>
|
2024-12-26 10:43:27 +08:00
|
|
|
</template>
|
2025-02-17 22:42:51 +08:00
|
|
|
</a-dropdown>
|
|
|
|
<a-tooltip content="列设置">
|
|
|
|
<a-popover
|
|
|
|
trigger="click"
|
|
|
|
position="bl"
|
|
|
|
@popup-visible-change="popupVisibleChange"
|
|
|
|
>
|
|
|
|
<div class="action-icon"><icon-settings size="18" /></div>
|
|
|
|
<template #content>
|
|
|
|
<div id="tableSetting">
|
|
|
|
<div
|
|
|
|
v-for="(item, index) in showColumns"
|
|
|
|
:key="item.dataIndex"
|
|
|
|
class="setting"
|
|
|
|
>
|
|
|
|
<div style="margin-right: 4px; cursor: move">
|
|
|
|
<icon-drag-arrow />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<a-checkbox
|
|
|
|
v-model="item.checked"
|
|
|
|
@change="
|
|
|
|
handleChange($event, item as TableColumnData, index)
|
|
|
|
"
|
|
|
|
>
|
|
|
|
</a-checkbox>
|
|
|
|
</div>
|
|
|
|
<div class="title">
|
|
|
|
{{ item.title === '#' ? '序列号' : item.title }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</a-popover>
|
|
|
|
</a-tooltip>
|
|
|
|
</a-col>
|
|
|
|
</a-row>
|
|
|
|
<a-table
|
|
|
|
row-key="id"
|
|
|
|
:loading="loading"
|
|
|
|
:pagination="false"
|
|
|
|
:columns="(cloneColumns as TableColumnData[])"
|
|
|
|
:data="renderData"
|
|
|
|
:bordered="false"
|
|
|
|
:size="sizeof"
|
|
|
|
style="margin-bottom: 40px"
|
|
|
|
@pageChange="onPageChange"
|
|
|
|
>
|
|
|
|
<template #index="{ rowIndex }">
|
|
|
|
{{ rowIndex + 1 }}
|
|
|
|
</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="确认删除此权限?"
|
|
|
|
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>
|
|
|
|
<a-pagination
|
|
|
|
style="float: right; position: relative; right: 1px; bottom: 25px"
|
|
|
|
:total="pagination.total"
|
|
|
|
show-total
|
|
|
|
show-jumper
|
|
|
|
show-page-size
|
|
|
|
@page-size-change="onSizeChange"
|
|
|
|
@change="onPageChange"
|
|
|
|
/>
|
|
|
|
</a-card>
|
|
|
|
</div>
|
2024-11-12 15:44:05 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-12-26 10:43:27 +08:00
|
|
|
import { ref, watch, computed, onMounted } from 'vue';
|
2025-02-17 22:42:51 +08:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
import { Message } from '@arco-design/web-vue';
|
|
|
|
import useLoading from '@/hooks/loading';
|
|
|
|
import { useAuthStore } from '@/store';
|
|
|
|
import { AuthRecord } from '@/api/authority';
|
|
|
|
import { Pagination } from '@/types/global';
|
|
|
|
import useTableOption from '@/hooks/table-option';
|
|
|
|
import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
|
|
|
|
import AuthEdit from './components/auth-edit.vue';
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
const { loading, setLoading } = useLoading();
|
|
|
|
const authStore = useAuthStore();
|
|
|
|
const renderData = ref<AuthRecord[]>([]);
|
|
|
|
const {
|
|
|
|
cloneColumns,
|
|
|
|
showColumns,
|
|
|
|
densityList,
|
|
|
|
handleSelectDensity,
|
|
|
|
handleChange,
|
|
|
|
popupVisibleChange,
|
|
|
|
deepClone,
|
|
|
|
} = useTableOption();
|
|
|
|
const sizeof = useTableOption().size;
|
|
|
|
const pagination: Pagination = {
|
|
|
|
page: 1,
|
|
|
|
size: 10,
|
|
|
|
current: 1,
|
|
|
|
total: 10,
|
|
|
|
};
|
|
|
|
const generateFormModel = () => {
|
|
|
|
return {
|
|
|
|
name: undefined,
|
|
|
|
};
|
2024-11-12 15:44:05 +08:00
|
|
|
};
|
2025-02-17 22:42:51 +08:00
|
|
|
const formModel = ref(generateFormModel());
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
const columns = computed<TableColumnData[]>(() => [
|
|
|
|
{
|
|
|
|
title: '序号',
|
|
|
|
dataIndex: 'index',
|
|
|
|
slotName: 'index',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '权限名称',
|
|
|
|
dataIndex: 'name',
|
|
|
|
// sortable: {
|
|
|
|
// sortDirections: ['ascend', 'descend'],
|
|
|
|
// },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '备注',
|
|
|
|
dataIndex: 'remark',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '状态',
|
|
|
|
dataIndex: 'enabled',
|
|
|
|
slotName: 'enabled',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '操作',
|
|
|
|
dataIndex: 'operations',
|
|
|
|
slotName: 'operations',
|
|
|
|
},
|
|
|
|
]);
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
const fetchData = async (params: any) => {
|
2024-11-12 15:44:05 +08:00
|
|
|
setLoading(true);
|
|
|
|
try {
|
2025-02-17 22:42:51 +08:00
|
|
|
const res = await authStore.getAuthList(params);
|
|
|
|
renderData.value = res.data.records;
|
|
|
|
pagination.page = res.data.page;
|
|
|
|
pagination.current = res.data.current;
|
|
|
|
pagination.total = res.data.total;
|
2024-11-12 15:44:05 +08:00
|
|
|
} catch (err) {
|
2025-02-17 22:42:51 +08:00
|
|
|
// you can report use errorHandler or other
|
2024-11-12 15:44:05 +08:00
|
|
|
} finally {
|
2025-02-17 22:42:51 +08:00
|
|
|
setLoading(false);
|
2024-11-12 15:44:05 +08:00
|
|
|
}
|
2025-02-17 22:42:51 +08:00
|
|
|
};
|
|
|
|
// 模糊查询
|
|
|
|
const search = () => {
|
2024-11-12 15:44:05 +08:00
|
|
|
fetchData({
|
2025-02-17 22:42:51 +08:00
|
|
|
...pagination,
|
|
|
|
...formModel.value,
|
2024-11-12 15:44:05 +08:00
|
|
|
} as unknown as any);
|
2025-02-17 22:42:51 +08:00
|
|
|
};
|
2024-12-26 10:43:27 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
onMounted(() => {
|
|
|
|
search();
|
|
|
|
});
|
|
|
|
// 分页发生改变
|
|
|
|
const onPageChange = (current: number) => {
|
|
|
|
pagination.page = current;
|
|
|
|
pagination.current = current;
|
|
|
|
search();
|
|
|
|
};
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
// 数据条数改变
|
|
|
|
const onSizeChange = (size: number) => {
|
|
|
|
pagination.size = size;
|
|
|
|
search();
|
|
|
|
};
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
// 重置
|
|
|
|
const reset = () => {
|
|
|
|
formModel.value = generateFormModel();
|
|
|
|
};
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
// 是否启用
|
|
|
|
const enabledStatus = async (record: any) => {
|
|
|
|
record.enabled = !record.enabled;
|
|
|
|
const res = await authStore.enabledAuth(record.id);
|
|
|
|
if (res.status === 200) {
|
|
|
|
Message.success({
|
|
|
|
content: '修改成功',
|
|
|
|
duration: 3 * 1000,
|
|
|
|
});
|
|
|
|
search();
|
|
|
|
} else {
|
|
|
|
Message.error({
|
|
|
|
content: '修改失败',
|
|
|
|
duration: 3 * 1000,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2024-12-26 10:43:27 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
// 删除
|
|
|
|
const handleDelete = async (record: AuthRecord) => {
|
|
|
|
const res = await authStore.removeAuth(record.id);
|
|
|
|
if (res.status === 200) {
|
|
|
|
Message.success({
|
|
|
|
content: '删除成功',
|
|
|
|
duration: 5 * 1000,
|
|
|
|
});
|
|
|
|
search();
|
|
|
|
} else {
|
|
|
|
Message.error({
|
|
|
|
content: '删除失败',
|
|
|
|
duration: 3 * 1000,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2024-12-26 10:43:27 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
watch(() => columns.value, deepClone, { deep: true, immediate: true });
|
2024-11-12 15:44:05 +08:00
|
|
|
</script>
|
|
|
|
|
2025-01-10 10:40:37 +08:00
|
|
|
<script lang="ts">
|
|
|
|
export default {
|
|
|
|
name: 'Authority',
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2024-11-12 15:44:05 +08:00
|
|
|
<style scoped lang="less">
|
2025-02-17 22:42:51 +08:00
|
|
|
.container {
|
2024-11-12 15:44:05 +08:00
|
|
|
padding: 0 20px 20px 20px;
|
2025-02-17 22:42:51 +08:00
|
|
|
}
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
:deep(.arco-table-th) {
|
2024-11-12 15:44:05 +08:00
|
|
|
&:last-child {
|
2025-02-17 22:42:51 +08:00
|
|
|
.arco-table-th-item-title {
|
|
|
|
margin-left: 16px;
|
|
|
|
}
|
2024-11-12 15:44:05 +08:00
|
|
|
}
|
2025-02-17 22:42:51 +08:00
|
|
|
}
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
.action-icon {
|
2024-11-12 15:44:05 +08:00
|
|
|
margin-left: 12px;
|
|
|
|
cursor: pointer;
|
2025-02-17 22:42:51 +08:00
|
|
|
}
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
.active {
|
2024-11-12 15:44:05 +08:00
|
|
|
color: #0960bd;
|
|
|
|
background-color: #e3f4fc;
|
2025-02-17 22:42:51 +08:00
|
|
|
}
|
2024-11-12 15:44:05 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
.setting {
|
2024-11-12 15:44:05 +08:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
width: 200px;
|
|
|
|
|
|
|
|
.title {
|
2025-02-17 22:42:51 +08:00
|
|
|
margin-left: 12px;
|
|
|
|
cursor: pointer;
|
2024-11-12 15:44:05 +08:00
|
|
|
}
|
2025-02-17 22:42:51 +08:00
|
|
|
}
|
|
|
|
</style>
|