|
@@ -1,12 +1,8 @@
|
|
|
<template>
|
|
|
<div class="p-4">
|
|
|
- <BasicTable
|
|
|
- ref="tableRef"
|
|
|
- @register="registerTable"
|
|
|
- rowKey="id"
|
|
|
- >
|
|
|
+ <BasicTable ref="tableRef" @register="registerTable" rowKey="id">
|
|
|
<template #toolbar>
|
|
|
- <a-button type="primary" @click="addRole" >
|
|
|
+ <a-button type="primary" @click="addRole">
|
|
|
{{ '新增角色' }}
|
|
|
</a-button>
|
|
|
</template>
|
|
@@ -15,26 +11,34 @@
|
|
|
</template>
|
|
|
<!-- <template #form-custom > custom-slot </template> -->
|
|
|
</BasicTable>
|
|
|
- <Add @register="addRegister" :modelData = "modelData" @saveData="saveData" />
|
|
|
+ <Add @register="addRegister" :modelData="modelData" @saveData="saveData" />
|
|
|
</div>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
import { defineComponent, reactive, ref, unref } from 'vue';
|
|
|
- import Add from './add.vue'
|
|
|
+ import Add from './add.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 {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[] = [
|
|
|
{
|
|
@@ -80,7 +84,7 @@
|
|
|
dataIndex: 'detail',
|
|
|
// editRow: true,
|
|
|
width: 150,
|
|
|
- }
|
|
|
+ },
|
|
|
];
|
|
|
|
|
|
export default defineComponent({
|
|
@@ -93,12 +97,12 @@
|
|
|
treeData: [],
|
|
|
checkedKeys: [],
|
|
|
selectedKeys: [],
|
|
|
- expandedKeys: []
|
|
|
- })
|
|
|
- getTreeData()
|
|
|
+ expandedKeys: [],
|
|
|
+ });
|
|
|
+ getTreeData();
|
|
|
const [registerTable] = useTable({
|
|
|
- title: "角色列表",
|
|
|
- titleHelpMessage: "温馨提醒",
|
|
|
+ title: '角色列表',
|
|
|
+ titleHelpMessage: '温馨提醒',
|
|
|
rowSelection: { type: 'checkbox' },
|
|
|
columns: columns,
|
|
|
clickToRowSelect: false, // 点击行不勾选
|
|
@@ -115,7 +119,8 @@
|
|
|
});
|
|
|
const [addRegister, { openModal: openAdd }] = useModal();
|
|
|
|
|
|
- function getTableAction() { // 获取组件
|
|
|
+ function getTableAction() {
|
|
|
+ // 获取组件
|
|
|
const tableAction = unref(tableRef);
|
|
|
if (!tableAction) {
|
|
|
throw new Error('tableAction is null');
|
|
@@ -123,19 +128,21 @@
|
|
|
return tableAction;
|
|
|
}
|
|
|
|
|
|
- function getSelectRowList() { // 获取选中行
|
|
|
+ function getSelectRowList() {
|
|
|
+ // 获取选中行
|
|
|
console.log(getTableAction().getSelectRows());
|
|
|
}
|
|
|
- function getSelectRowKeyList() { // 获取选中行的key --- id
|
|
|
+ function getSelectRowKeyList() {
|
|
|
+ // 获取选中行的key --- id
|
|
|
console.log(getTableAction().getSelectRowKeys());
|
|
|
}
|
|
|
|
|
|
function addRole() {
|
|
|
- console.log('添加')
|
|
|
- modelData.title = '添加'
|
|
|
- modelData.checkedKeys = []
|
|
|
- modelData.selectedKeys = []
|
|
|
- modelData.expandedKeys = []
|
|
|
+ console.log('添加');
|
|
|
+ modelData.title = '添加';
|
|
|
+ modelData.checkedKeys = [];
|
|
|
+ modelData.selectedKeys = [];
|
|
|
+ modelData.expandedKeys = [];
|
|
|
openAdd(true, {
|
|
|
username: '',
|
|
|
password: '',
|
|
@@ -143,34 +150,34 @@
|
|
|
menus: [],
|
|
|
roleName: '',
|
|
|
nickname: '',
|
|
|
- status: true
|
|
|
+ status: true,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function handleEdit(record: EditRecordRow) {
|
|
|
- currentEditKeyRef.value = record.id; // record.key
|
|
|
- console.log(record)
|
|
|
- modelData.title = '编辑'
|
|
|
+ currentEditKeyRef.value = record.id; // record.key
|
|
|
+ console.log(record);
|
|
|
+ modelData.title = '编辑';
|
|
|
|
|
|
- const data = getTableAction().getDataSource()
|
|
|
- data.map(item => {
|
|
|
+ const data = getTableAction().getDataSource();
|
|
|
+ data.map((item) => {
|
|
|
if (item.id === record.id) {
|
|
|
- record = item
|
|
|
+ record = item;
|
|
|
}
|
|
|
- })
|
|
|
- modelData.checkedKeys = record.menus
|
|
|
- modelData.selectedKeys = []
|
|
|
- modelData.expandedKeys = []
|
|
|
+ });
|
|
|
+ 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 => {
|
|
|
- console.log(res)
|
|
|
- getTableAction().reload()
|
|
|
- })
|
|
|
+ console.log(record);
|
|
|
+ await deleteUser({ id: record.id }).then((res) => {
|
|
|
+ console.log(res);
|
|
|
+ getTableAction().reload();
|
|
|
+ });
|
|
|
// const data = getTableAction().getDataSource()
|
|
|
// console.log(data)
|
|
|
// getTableAction().setTableData(data.filter(item => item.id !== record.id))
|
|
@@ -179,21 +186,20 @@
|
|
|
async function saveData(data: any) {
|
|
|
// const datas = getTableAction().getDataSource()
|
|
|
// 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---');
|
|
|
}
|
|
|
// if (modelData.title === "添加") {
|
|
|
// datas.map(item => {
|
|
@@ -217,15 +223,19 @@
|
|
|
// }
|
|
|
}
|
|
|
async function getTreeData() {
|
|
|
- let treeData = await getAllMenuList() as any
|
|
|
- modelData.treeData = JSON.parse(JSON.stringify(treeData).replace(/menuName/g,"title").replace(/id/g,"key"))
|
|
|
+ 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)
|
|
|
+ console.log(modelData.treeData);
|
|
|
}
|
|
|
|
|
|
function createActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
|
|
|
if (false) {
|
|
|
- console.log(column)
|
|
|
+ console.log(column);
|
|
|
}
|
|
|
return [
|
|
|
{
|
|
@@ -258,7 +268,7 @@
|
|
|
addRegister,
|
|
|
saveData,
|
|
|
getUserList,
|
|
|
- getTreeData
|
|
|
+ getTreeData,
|
|
|
};
|
|
|
},
|
|
|
});
|