|
@@ -7,9 +7,7 @@
|
|
:pagination="{ pageSize: 2, defaultPageSize: 2, showSizeChanger: false }"
|
|
:pagination="{ pageSize: 2, defaultPageSize: 2, showSizeChanger: false }"
|
|
>
|
|
>
|
|
<template #toolbar>
|
|
<template #toolbar>
|
|
- <a-button type="primary" @click="addRole" >
|
|
|
|
- 添加
|
|
|
|
- </a-button>
|
|
|
|
|
|
+ <a-button type="primary" @click="addRole"> 添加 </a-button>
|
|
</template>
|
|
</template>
|
|
<template #action="{ record }">
|
|
<template #action="{ record }">
|
|
<TableAction :actions="createActions(record)" />
|
|
<TableAction :actions="createActions(record)" />
|
|
@@ -20,21 +18,29 @@
|
|
</template>
|
|
</template>
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
import { defineComponent, reactive, ref, unref } from 'vue';
|
|
import { defineComponent, reactive, ref, unref } from 'vue';
|
|
- import Popup from './popup.vue'
|
|
|
|
|
|
+ import Popup from './popup.vue';
|
|
import { useModal } from '/@/components/Modal';
|
|
import { useModal } from '/@/components/Modal';
|
|
-// import { getAllMenuList } from '/@/api/sys/menu';
|
|
|
|
|
|
+ // import { getAllMenuList } from '/@/api/sys/menu';
|
|
import { h } from 'vue';
|
|
import { h } from 'vue';
|
|
import { Tag } from 'ant-design-vue';
|
|
import { Tag } from 'ant-design-vue';
|
|
- import { getUserList, addUser, editUser,deleteUser } from '/@/api/sys/user';
|
|
|
|
- import {BasicTable, useTable, TableAction, BasicColumn, ActionItem, EditRecordRow, TableActionType } from '/@/components/Table';
|
|
|
|
|
|
+ import { getUserList, addUser, editUser, deleteUser } from '/@/api/sys/user';
|
|
|
|
+ import {
|
|
|
|
+ BasicTable,
|
|
|
|
+ useTable,
|
|
|
|
+ TableAction,
|
|
|
|
+ BasicColumn,
|
|
|
|
+ ActionItem,
|
|
|
|
+ EditRecordRow,
|
|
|
|
+ TableActionType,
|
|
|
|
+ } from '/@/components/Table';
|
|
|
|
|
|
-// interface ModelData {
|
|
|
|
-// title: string,
|
|
|
|
-// treeData: object[],
|
|
|
|
-// checkedKeys: string[] | number[],
|
|
|
|
-// selectedKeys: string[] | number[],
|
|
|
|
-// expandedKeys: string[] | number[]
|
|
|
|
-// }
|
|
|
|
|
|
+ // interface ModelData {
|
|
|
|
+ // title: string,
|
|
|
|
+ // treeData: object[],
|
|
|
|
+ // checkedKeys: string[] | number[],
|
|
|
|
+ // selectedKeys: string[] | number[],
|
|
|
|
+ // expandedKeys: string[] | number[]
|
|
|
|
+ // }
|
|
|
|
|
|
const columns: BasicColumn[] = [
|
|
const columns: BasicColumn[] = [
|
|
{
|
|
{
|
|
@@ -76,26 +82,26 @@
|
|
title: '最后登录',
|
|
title: '最后登录',
|
|
dataIndex: 'time',
|
|
dataIndex: 'time',
|
|
width: 150,
|
|
width: 150,
|
|
- }
|
|
|
|
|
|
+ },
|
|
];
|
|
];
|
|
const formData = [
|
|
const formData = [
|
|
- {
|
|
|
|
- id: 1,
|
|
|
|
- username: 'test1',
|
|
|
|
- nickname: '用户1',
|
|
|
|
- email: 'test1@163.com',
|
|
|
|
- status: 0,
|
|
|
|
- time: '2020-10-20'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- id: 2,
|
|
|
|
- username: 'test2',
|
|
|
|
- nickname: '用户2',
|
|
|
|
- email: 'test2@163.com',
|
|
|
|
- status: 1,
|
|
|
|
- time: '2020-10-20'
|
|
|
|
- },
|
|
|
|
- ]
|
|
|
|
|
|
+ {
|
|
|
|
+ id: 1,
|
|
|
|
+ username: 'test1',
|
|
|
|
+ nickname: '用户1',
|
|
|
|
+ email: 'test1@163.com',
|
|
|
|
+ status: 0,
|
|
|
|
+ time: '2020-10-20',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ id: 2,
|
|
|
|
+ username: 'test2',
|
|
|
|
+ nickname: '用户2',
|
|
|
|
+ email: 'test2@163.com',
|
|
|
|
+ status: 1,
|
|
|
|
+ time: '2020-10-20',
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
components: { BasicTable, TableAction, Popup },
|
|
components: { BasicTable, TableAction, Popup },
|
|
@@ -105,11 +111,12 @@
|
|
const modelData = reactive({
|
|
const modelData = reactive({
|
|
title: '添加',
|
|
title: '添加',
|
|
treeData: [],
|
|
treeData: [],
|
|
- })
|
|
|
|
- getTreeData()
|
|
|
|
|
|
+ });
|
|
|
|
+ getTreeData();
|
|
const [registerTable] = useTable({
|
|
const [registerTable] = useTable({
|
|
- title: "角色组",
|
|
|
|
- titleHelpMessage: "角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别的下级角色组或管理员",
|
|
|
|
|
|
+ title: '角色组',
|
|
|
|
+ titleHelpMessage:
|
|
|
|
+ '角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别的下级角色组或管理员',
|
|
rowSelection: { type: 'checkbox' },
|
|
rowSelection: { type: 'checkbox' },
|
|
columns: columns,
|
|
columns: columns,
|
|
clickToRowSelect: false, // 点击行不勾选
|
|
clickToRowSelect: false, // 点击行不勾选
|
|
@@ -127,7 +134,8 @@
|
|
});
|
|
});
|
|
const [addRegister, { openModal: openAdd }] = useModal();
|
|
const [addRegister, { openModal: openAdd }] = useModal();
|
|
|
|
|
|
- function getTableAction() { // 获取组件
|
|
|
|
|
|
+ function getTableAction() {
|
|
|
|
+ // 获取组件
|
|
const tableAction = unref(tableRef);
|
|
const tableAction = unref(tableRef);
|
|
if (!tableAction) {
|
|
if (!tableAction) {
|
|
throw new Error('tableAction is null');
|
|
throw new Error('tableAction is null');
|
|
@@ -135,44 +143,46 @@
|
|
return tableAction;
|
|
return tableAction;
|
|
}
|
|
}
|
|
|
|
|
|
- function getSelectRowList() { // 获取选中行
|
|
|
|
|
|
+ function getSelectRowList() {
|
|
|
|
+ // 获取选中行
|
|
console.log(getTableAction().getSelectRows());
|
|
console.log(getTableAction().getSelectRows());
|
|
}
|
|
}
|
|
- function getSelectRowKeyList() { // 获取选中行的key --- id
|
|
|
|
|
|
+ function getSelectRowKeyList() {
|
|
|
|
+ // 获取选中行的key --- id
|
|
console.log(getTableAction().getSelectRowKeys());
|
|
console.log(getTableAction().getSelectRowKeys());
|
|
}
|
|
}
|
|
|
|
|
|
function addRole() {
|
|
function addRole() {
|
|
- modelData.title = '添加'
|
|
|
|
|
|
+ modelData.title = '添加';
|
|
openAdd(true, {
|
|
openAdd(true, {
|
|
id: null,
|
|
id: null,
|
|
username: '',
|
|
username: '',
|
|
nickname: '',
|
|
nickname: '',
|
|
email: '',
|
|
email: '',
|
|
- status: 1
|
|
|
|
|
|
+ status: 1,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
function handleEdit(record: EditRecordRow) {
|
|
function handleEdit(record: EditRecordRow) {
|
|
- currentEditKeyRef.value = record.id; // record.key
|
|
|
|
- modelData.title = '编辑'
|
|
|
|
|
|
+ currentEditKeyRef.value = record.id; // record.key
|
|
|
|
+ modelData.title = '编辑';
|
|
|
|
|
|
- const data = getTableAction().getDataSource()
|
|
|
|
- data.map(item => {
|
|
|
|
|
|
+ const data = getTableAction().getDataSource();
|
|
|
|
+ data.map((item) => {
|
|
if (item.id === record.id) {
|
|
if (item.id === record.id) {
|
|
- record = item
|
|
|
|
|
|
+ record = item;
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ });
|
|
openAdd(true, record);
|
|
openAdd(true, record);
|
|
}
|
|
}
|
|
|
|
|
|
async function handleDelete(record: Recordable) {
|
|
async function handleDelete(record: Recordable) {
|
|
console.log('点击了删除', record.id);
|
|
console.log('点击了删除', record.id);
|
|
- console.log(record)
|
|
|
|
- await deleteUser({id:record.id}).then(res => {
|
|
|
|
- console.log(res)
|
|
|
|
- getTableAction().reload()
|
|
|
|
- })
|
|
|
|
|
|
+ console.log(record);
|
|
|
|
+ await deleteUser({ id: record.id }).then((res) => {
|
|
|
|
+ console.log(res);
|
|
|
|
+ getTableAction().reload();
|
|
|
|
+ });
|
|
// const data = getTableAction().getDataSource()
|
|
// const data = getTableAction().getDataSource()
|
|
// console.log(data)
|
|
// console.log(data)
|
|
// getTableAction().setTableData(data.filter(item => item.id !== record.id))
|
|
// getTableAction().setTableData(data.filter(item => item.id !== record.id))
|
|
@@ -181,31 +191,30 @@
|
|
async function saveData(data: any) {
|
|
async function saveData(data: any) {
|
|
// const datas = getTableAction().getDataSource()
|
|
// const datas = getTableAction().getDataSource()
|
|
// const info = reactive({...data.info})
|
|
// const info = reactive({...data.info})
|
|
- console.log('------------save---------')
|
|
|
|
- console.log(data)
|
|
|
|
- if(!data.id) {
|
|
|
|
- await addUser(data).then(res => {
|
|
|
|
- console.log(res)
|
|
|
|
- getTableAction().reload()
|
|
|
|
- })
|
|
|
|
- console.log('----------add---')
|
|
|
|
- }else {
|
|
|
|
- await editUser(data).then(res => {
|
|
|
|
- console.log(res)
|
|
|
|
- getTableAction().reload()
|
|
|
|
- })
|
|
|
|
- console.log('----------edit---')
|
|
|
|
-
|
|
|
|
|
|
+ console.log('------------save---------');
|
|
|
|
+ console.log(data);
|
|
|
|
+ if (!data.id) {
|
|
|
|
+ await addUser(data).then((res) => {
|
|
|
|
+ console.log(res);
|
|
|
|
+ getTableAction().reload();
|
|
|
|
+ });
|
|
|
|
+ console.log('----------add---');
|
|
|
|
+ } else {
|
|
|
|
+ await editUser(data).then((res) => {
|
|
|
|
+ console.log(res);
|
|
|
|
+ getTableAction().reload();
|
|
|
|
+ });
|
|
|
|
+ console.log('----------edit---');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
async function getTreeData() {
|
|
async function getTreeData() {
|
|
// let treeData = await getAllMenuList()
|
|
// let treeData = await getAllMenuList()
|
|
// modelData.treeData = JSON.parse(JSON.stringify(treeData).replace(/menuName/g,"title").replace(/id/g,"key"))
|
|
// modelData.treeData = JSON.parse(JSON.stringify(treeData).replace(/menuName/g,"title").replace(/id/g,"key"))
|
|
|
|
|
|
- console.log(modelData.treeData)
|
|
|
|
|
|
+ console.log(modelData.treeData);
|
|
}
|
|
}
|
|
|
|
|
|
- function createActions(record: EditRecordRow,): ActionItem[] {
|
|
|
|
|
|
+ function createActions(record: EditRecordRow): ActionItem[] {
|
|
return [
|
|
return [
|
|
{
|
|
{
|
|
label: '编辑',
|
|
label: '编辑',
|
|
@@ -237,7 +246,7 @@
|
|
addRegister,
|
|
addRegister,
|
|
saveData,
|
|
saveData,
|
|
getUserList,
|
|
getUserList,
|
|
- getTreeData
|
|
|
|
|
|
+ getTreeData,
|
|
};
|
|
};
|
|
},
|
|
},
|
|
});
|
|
});
|