|
@@ -8,9 +8,8 @@
|
|
|
<template #action="{ record, column }">
|
|
|
<TableAction :actions="createActions(record, column)" />
|
|
|
</template>
|
|
|
- <!-- <template #form-custom > custom-slot </template> -->
|
|
|
</BasicTable>
|
|
|
- <Popup @register="addRegister" :modelData="modelData" @saveData="saveData" />
|
|
|
+ <Popup @register="addRegister" :popupData="popupData" @saveData="saveData" />
|
|
|
</div>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
@@ -18,9 +17,8 @@
|
|
|
import Popup from './popup.vue';
|
|
|
import { useModal } from '/@/components/Modal';
|
|
|
// import { getAllMenuList } from '/@/api/sys/menu';
|
|
|
- import { h } from 'vue';
|
|
|
- import { Tag } from 'ant-design-vue';
|
|
|
- import { getUserList, addUser, editUser, deleteUser } from '/@/api/sys/user';
|
|
|
+ import { columns } from './data';
|
|
|
+ import { getGroupTree, addGroup, editGroup, deleteGroup } from '/@/api/sys/user';
|
|
|
import {
|
|
|
BasicTable,
|
|
|
useTable,
|
|
@@ -31,83 +29,20 @@
|
|
|
TableActionType,
|
|
|
} from '/@/components/Table';
|
|
|
|
|
|
- // interface ModelData {
|
|
|
- // title: string,
|
|
|
- // treeData: object[],
|
|
|
- // checkedKeys: string[] | number[],
|
|
|
- // selectedKeys: string[] | number[],
|
|
|
- // expandedKeys: string[] | number[]
|
|
|
- // }
|
|
|
-
|
|
|
- const columns: BasicColumn[] = [
|
|
|
- {
|
|
|
- title: 'ID',
|
|
|
- dataIndex: 'id',
|
|
|
- editComponentProps: {
|
|
|
- prefix: '$',
|
|
|
- },
|
|
|
- width: 80,
|
|
|
- },
|
|
|
- {
|
|
|
- title: '父级',
|
|
|
- dataIndex: 'parent',
|
|
|
- // editRow: true,
|
|
|
- width: 160,
|
|
|
- },
|
|
|
- {
|
|
|
- title: '名称',
|
|
|
- dataIndex: 'uname',
|
|
|
- // editRow: true,
|
|
|
- width: 160,
|
|
|
- },
|
|
|
- {
|
|
|
- title: '状态',
|
|
|
- dataIndex: 'status',
|
|
|
- width: 80,
|
|
|
- customRender: ({ record }) => {
|
|
|
- const status = record.status;
|
|
|
- // const enable = ~~status === 0;
|
|
|
- const color = status ? 'green' : 'red';
|
|
|
- const text = status ? '启用' : '停用';
|
|
|
- return h(Tag, { color: color }, () => text);
|
|
|
- },
|
|
|
- },
|
|
|
- ];
|
|
|
-
|
|
|
- const formData = [
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- parent: null,
|
|
|
- uname: '超级管理员',
|
|
|
- status: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- parent: 1,
|
|
|
- uname: '普通管理员',
|
|
|
- status: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- parent: 2,
|
|
|
- uname: '游客',
|
|
|
- status: 1,
|
|
|
- },
|
|
|
- ];
|
|
|
+ interface PopupData {
|
|
|
+ title: string;
|
|
|
+ treeData: object[];
|
|
|
+ }
|
|
|
|
|
|
export default defineComponent({
|
|
|
components: { BasicTable, TableAction, Popup },
|
|
|
setup() {
|
|
|
const tableRef = ref<Nullable<TableActionType>>(null);
|
|
|
const currentEditKeyRef = ref('');
|
|
|
- const modelData = reactive({
|
|
|
+ const popupData = reactive<PopupData>({
|
|
|
title: '添加',
|
|
|
- treeData: [],
|
|
|
- checkedKeys: [],
|
|
|
- selectedKeys: [],
|
|
|
- expandedKeys: [],
|
|
|
+ treeData: [{}],
|
|
|
});
|
|
|
- getTreeData();
|
|
|
const [registerTable] = useTable({
|
|
|
title: '角色列表',
|
|
|
titleHelpMessage:
|
|
@@ -115,8 +50,9 @@
|
|
|
rowSelection: { type: 'checkbox' },
|
|
|
columns: columns,
|
|
|
clickToRowSelect: false, // 点击行不勾选
|
|
|
- // api: getUserList,
|
|
|
- dataSource: formData,
|
|
|
+ api: getGroupTree,
|
|
|
+ afterFetch: afterFetch,
|
|
|
+ // dataSource: formData,
|
|
|
actionColumn: {
|
|
|
width: 160,
|
|
|
title: '操作',
|
|
@@ -129,6 +65,11 @@
|
|
|
});
|
|
|
const [addRegister, { openModal: openAdd }] = useModal();
|
|
|
|
|
|
+ function afterFetch(result) {
|
|
|
+ console.log(`result`, result);
|
|
|
+ popupData.treeData = result;
|
|
|
+ }
|
|
|
+
|
|
|
function getTableAction() {
|
|
|
// 获取组件
|
|
|
const tableAction = unref(tableRef);
|
|
@@ -149,60 +90,58 @@
|
|
|
|
|
|
function addRole() {
|
|
|
console.log('添加');
|
|
|
- modelData.title = '添加';
|
|
|
+ popupData.title = '添加';
|
|
|
openAdd(true, {});
|
|
|
}
|
|
|
|
|
|
function handleEdit(record: EditRecordRow) {
|
|
|
currentEditKeyRef.value = record.id; // record.key
|
|
|
console.log(record);
|
|
|
- modelData.title = '编辑';
|
|
|
+ popupData.title = '编辑';
|
|
|
|
|
|
const data = getTableAction().getDataSource();
|
|
|
data.map((item) => {
|
|
|
if (item.id === record.id) {
|
|
|
record = item;
|
|
|
}
|
|
|
+ if (record.pid === item.id) {
|
|
|
+ record.pname = item.name;
|
|
|
+ } else {
|
|
|
+ record.pname = null;
|
|
|
+ }
|
|
|
});
|
|
|
- modelData.checkedKeys = record.menus;
|
|
|
- modelData.selectedKeys = [];
|
|
|
- modelData.expandedKeys = [];
|
|
|
openAdd(true, record);
|
|
|
}
|
|
|
|
|
|
async function handleDelete(record: Recordable) {
|
|
|
console.log('点击了删除', record.id);
|
|
|
console.log(record);
|
|
|
- await deleteUser({ id: record.id }).then((res) => {
|
|
|
+ await deleteGroup({ id: record.id }).then((res) => {
|
|
|
console.log(res);
|
|
|
getTableAction().reload();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- async function saveData(data: any) {
|
|
|
- // const datas = getTableAction().getDataSource()
|
|
|
- // const info = reactive({...data.info})
|
|
|
+ async function saveData(params: any) {
|
|
|
console.log('------------save---------');
|
|
|
- console.log(data);
|
|
|
+ const data = params.data;
|
|
|
+ const closeModel = params.closeModal;
|
|
|
if (!data.id) {
|
|
|
- await addUser(data).then((res) => {
|
|
|
+ await addGroup(data).then((res) => {
|
|
|
console.log(res);
|
|
|
getTableAction().reload();
|
|
|
+ closeModel();
|
|
|
});
|
|
|
console.log('----------add---');
|
|
|
} else {
|
|
|
- await editUser(data).then((res) => {
|
|
|
+ await editGroup(data).then((res) => {
|
|
|
console.log(res);
|
|
|
getTableAction().reload();
|
|
|
+ closeModel();
|
|
|
});
|
|
|
console.log('----------edit---');
|
|
|
}
|
|
|
}
|
|
|
- async function getTreeData() {
|
|
|
- // let treeData = await getAllMenuList() as any
|
|
|
- // modelData.treeData = JSON.parse(JSON.stringify(treeData).replace(/menuName/g,"title").replace(/id/g,"key"))
|
|
|
- // console.log(modelData.treeData)
|
|
|
- }
|
|
|
|
|
|
function createActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
|
|
|
if (false) {
|
|
@@ -227,7 +166,7 @@
|
|
|
];
|
|
|
}
|
|
|
return {
|
|
|
- modelData,
|
|
|
+ popupData,
|
|
|
tableRef,
|
|
|
registerTable,
|
|
|
addRole,
|
|
@@ -238,8 +177,6 @@
|
|
|
getSelectRowKeyList,
|
|
|
addRegister,
|
|
|
saveData,
|
|
|
- getUserList,
|
|
|
- getTreeData,
|
|
|
};
|
|
|
},
|
|
|
});
|