|
@@ -1,190 +1,81 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <page-wrapper>
|
|
|
|
|
- <el-card :bordered="false" class="mb-3 proCard">
|
|
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <el-card class="mb-3 proCard">
|
|
|
<el-space align="center">
|
|
<el-space align="center">
|
|
|
<el-input
|
|
<el-input
|
|
|
:style="{ width: '320px' }"
|
|
:style="{ width: '320px' }"
|
|
|
- v-model="params.roleName"
|
|
|
|
|
|
|
+ v-model="requestParams.queryParam!.roleName"
|
|
|
clearable
|
|
clearable
|
|
|
placeholder="请输入角色名称"
|
|
placeholder="请输入角色名称"
|
|
|
- @keyup.enter="reloadTable"
|
|
|
|
|
|
|
+ @keyup.enter="queryRolesPage"
|
|
|
/>
|
|
/>
|
|
|
- <el-button type="primary" @click="reloadTable">
|
|
|
|
|
- <template #icon>
|
|
|
|
|
- <el-icon>
|
|
|
|
|
- <SearchOutlined />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- </template>
|
|
|
|
|
- 查询
|
|
|
|
|
- </el-button>
|
|
|
|
|
|
|
+ <el-button type="primary" :icon="Search" @click="queryRolesPage">查询</el-button>
|
|
|
</el-space>
|
|
</el-space>
|
|
|
</el-card>
|
|
</el-card>
|
|
|
- <el-card :bordered="false" class="proCard">
|
|
|
|
|
- <BasicTable
|
|
|
|
|
- :columns="columns"
|
|
|
|
|
- :request="loadDataTable"
|
|
|
|
|
- :row-key="(row) => row.id"
|
|
|
|
|
- :pagination="{ hideOnSinglePage: false }"
|
|
|
|
|
- :tableSetting="{
|
|
|
|
|
- size: false,
|
|
|
|
|
- redo: false,
|
|
|
|
|
- fullscreen: false,
|
|
|
|
|
- striped: false,
|
|
|
|
|
- setting: false,
|
|
|
|
|
- }"
|
|
|
|
|
- ref="tableRef"
|
|
|
|
|
- :actionColumn="actionColumn"
|
|
|
|
|
- @update:checked-row-keys="onCheckedRow"
|
|
|
|
|
- >
|
|
|
|
|
- <template #tableTitle>
|
|
|
|
|
- <el-button type="primary" @click="openCreateUserDrawer">
|
|
|
|
|
- <template #icon>
|
|
|
|
|
- <el-icon>
|
|
|
|
|
- <FileAddOutlined />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- </template>
|
|
|
|
|
- 用户角色
|
|
|
|
|
- </el-button>
|
|
|
|
|
- <el-button type="primary" @click="openCreateDrawer">
|
|
|
|
|
- <template #icon>
|
|
|
|
|
- <el-icon>
|
|
|
|
|
- <FileAddOutlined />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- </template>
|
|
|
|
|
- 管理员角色
|
|
|
|
|
- </el-button>
|
|
|
|
|
- </template>
|
|
|
|
|
|
|
|
|
|
- <template #action>
|
|
|
|
|
- <TableAction />
|
|
|
|
|
- </template>
|
|
|
|
|
- </BasicTable>
|
|
|
|
|
- </el-card>
|
|
|
|
|
|
|
+ <el-card>
|
|
|
|
|
+ <template #header>
|
|
|
|
|
+ <el-button type="primary" @click="openDrawer()">添加角色</el-button>
|
|
|
|
|
+ </template>
|
|
|
|
|
+
|
|
|
|
|
+ <el-table height="calc(100vh - 340px)" :data="roleList">
|
|
|
|
|
+ <el-table-column label="角色ID" width="100" prop="id" />
|
|
|
|
|
+ <el-table-column label="角色名称" prop="roleName" />
|
|
|
|
|
+ <el-table-column label="备注" prop="remark" />
|
|
|
|
|
+ <el-table-column label="创建时间" width="200" prop="createdAt" />
|
|
|
|
|
+ <el-table-column label="操作" width="160">
|
|
|
|
|
+ <template #default="{ row }">
|
|
|
|
|
+ <el-space>
|
|
|
|
|
+ <el-button type="primary" :icon="Edit" text @click="openDrawer(row)" />
|
|
|
|
|
+ <el-button :icon="Delete" text />
|
|
|
|
|
+ </el-space>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ </el-table>
|
|
|
|
|
|
|
|
- <CreateDrawer
|
|
|
|
|
- ref="createDrawerRef"
|
|
|
|
|
- :title="drawerTitle"
|
|
|
|
|
- :permissionList="treeData"
|
|
|
|
|
- @change="reloadTable"
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <section class="mt-4 flex justify-end">
|
|
|
|
|
+ <el-pagination
|
|
|
|
|
+ background
|
|
|
|
|
+ layout="total, sizes, prev, pager, next"
|
|
|
|
|
+ :page-sizes="[10, 30, 50]"
|
|
|
|
|
+ :total="total"
|
|
|
|
|
+ v-model:page-size="requestParams.pageSize"
|
|
|
|
|
+ v-model:current-page="requestParams.pageNumber"
|
|
|
|
|
+ @change="queryRolesPage"
|
|
|
|
|
+ />
|
|
|
|
|
+ </section>
|
|
|
|
|
+ </el-card>
|
|
|
|
|
|
|
|
- <CreateUserDrawer ref="createUserDrawerRef" :title="drawerTitle" @change="reloadTable" />
|
|
|
|
|
- </page-wrapper>
|
|
|
|
|
|
|
+ <RoleDrawer :title="drawerTitle" ref="drawerInstance" @submitted="onSubmitRole" />
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
- import { reactive, ref, unref, h, onMounted } from 'vue';
|
|
|
|
|
- import { ElMessage } from 'element-plus';
|
|
|
|
|
- import { BasicTable, TableAction, BasicColumn } from '@/components/Table';
|
|
|
|
|
- import { roleList, permissionList, delAdminRole, delUserRole } from '@/api/system/role';
|
|
|
|
|
- import { columns } from './columns';
|
|
|
|
|
- import { FileAddOutlined, SearchOutlined } from '@vicons/antd';
|
|
|
|
|
- import CreateDrawer from './CreateDrawer.vue';
|
|
|
|
|
- import CreateUserDrawer from './CreateUserDrawer.vue';
|
|
|
|
|
- import { useUserStore } from '@/store/modules/user';
|
|
|
|
|
|
|
+ import { ref, onMounted } from 'vue';
|
|
|
|
|
+ import { Edit, Delete, Search } from '@element-plus/icons-vue';
|
|
|
|
|
+ import RoleDrawer from './components/RoleDrawer.vue';
|
|
|
|
|
+ import useRolesQuery from './hooks/useRolesQuery';
|
|
|
|
|
+ import { Role } from '@/types/role/type';
|
|
|
|
|
|
|
|
- const message = ElMessage;
|
|
|
|
|
- const tableRef = ref();
|
|
|
|
|
- const createDrawerRef = ref();
|
|
|
|
|
- const createUserDrawerRef = ref();
|
|
|
|
|
- const drawerTitle = ref('添加角色');
|
|
|
|
|
- const treeData = ref([]);
|
|
|
|
|
- const userStore = useUserStore();
|
|
|
|
|
|
|
+ const { roleList, total, queryRolesPage, requestParams } = useRolesQuery();
|
|
|
|
|
|
|
|
- const params = reactive({
|
|
|
|
|
- roleName: '',
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // drawer 相关变量
|
|
|
|
|
+ const drawerTitle = ref('');
|
|
|
|
|
+ const drawerInstance = ref<InstanceType<typeof RoleDrawer>>();
|
|
|
|
|
|
|
|
- const actionColumn: BasicColumn = reactive({
|
|
|
|
|
- width: 150,
|
|
|
|
|
- title: '操作',
|
|
|
|
|
- key: 'action',
|
|
|
|
|
- fixed: 'right',
|
|
|
|
|
- render(record) {
|
|
|
|
|
- return h(TableAction as any, {
|
|
|
|
|
- style: 'button',
|
|
|
|
|
- actions: [
|
|
|
|
|
- {
|
|
|
|
|
- label: '删除',
|
|
|
|
|
- isConfirm: true,
|
|
|
|
|
- popConfirm: {
|
|
|
|
|
- onConfirm: handleDelete.bind(null, record.row),
|
|
|
|
|
- title: '您确定要删除吗?',
|
|
|
|
|
- confirmButtonText: '确定',
|
|
|
|
|
- cancelButtonText: '取消',
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- label: '编辑',
|
|
|
|
|
- onClick: handleEdit.bind(null, record.row),
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- });
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- const loadDataTable = async (res: any) => {
|
|
|
|
|
- let _params = {
|
|
|
|
|
- ...unref(params),
|
|
|
|
|
- ...res,
|
|
|
|
|
- };
|
|
|
|
|
- return await roleList(_params);
|
|
|
|
|
|
|
+ const openDrawer = (row?: Role) => {
|
|
|
|
|
+ drawerTitle.value = row ? '编辑角色' : '添加角色';
|
|
|
|
|
+ drawerInstance.value?.open(row);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- function openCreateDrawer() {
|
|
|
|
|
- drawerTitle.value = '添加角色';
|
|
|
|
|
- const { openDrawer } = createDrawerRef.value;
|
|
|
|
|
- openDrawer();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function openCreateUserDrawer() {
|
|
|
|
|
- drawerTitle.value = '添加角色';
|
|
|
|
|
- const { openDrawer } = createUserDrawerRef.value;
|
|
|
|
|
- openDrawer();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function onCheckedRow(rowKeys: any[]) {
|
|
|
|
|
- console.log(rowKeys);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function reloadTable() {
|
|
|
|
|
- tableRef.value.reload();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function handleEdit(record: Recordable) {
|
|
|
|
|
- console.log('点击了编辑', record);
|
|
|
|
|
- console.log('record.roleType', record.roleType);
|
|
|
|
|
- drawerTitle.value = '编辑角色';
|
|
|
|
|
- if (record.roleType === 1 || record.roleType === 2) {
|
|
|
|
|
- const { openDrawer } = createDrawerRef.value;
|
|
|
|
|
- openDrawer(record.roleId);
|
|
|
|
|
- } else {
|
|
|
|
|
- const { openDrawer } = createUserDrawerRef.value;
|
|
|
|
|
- openDrawer(record.roleId);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function handleDelete(record: Recordable) {
|
|
|
|
|
- console.log('record.roleType', record.roleType);
|
|
|
|
|
- // if (userStore.getRoleTypes.includes(String(record.roleId))) {
|
|
|
|
|
- // message.error('不能删除自己的角色');
|
|
|
|
|
- // return;
|
|
|
|
|
- // }
|
|
|
|
|
- if (record.roleType === 1 || record.roleType === 2) {
|
|
|
|
|
- delAdminRole({ roleId: record.roleId }).then(() => {
|
|
|
|
|
- message.success('删除成功');
|
|
|
|
|
- reloadTable();
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- delUserRole({ roleId: record.roleId }).then(() => {
|
|
|
|
|
- message.success('删除成功');
|
|
|
|
|
- reloadTable();
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建或编辑角色后重新获取列表
|
|
|
|
|
+ */
|
|
|
|
|
+ const onSubmitRole = () => {
|
|
|
|
|
+ queryRolesPage();
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- onMounted(async () => {
|
|
|
|
|
- const list = await permissionList();
|
|
|
|
|
- treeData.value = list.filter((item) => item.label !== '功能权限');
|
|
|
|
|
|
|
+ onMounted(() => {
|
|
|
|
|
+ queryRolesPage();
|
|
|
});
|
|
});
|
|
|
</script>
|
|
</script>
|