import React, { useEffect, useRef, useReducer } from "react";
import { Modal, Button, Drawer, Dropdown, Menu } from "antd";
import AutoTable from "@/components/AutoTable";
import getPrem from "@/utils/getPrem"; //权限判断fn
import InitForm from "@/components/InitForm";
import { useRequest } from "umi";
import defaultFields from "./fields";
import { doFetch } from "@/utils/doFetch";
import Permissiontree from "./Permissiontree";
import DrawInitForm from "@/components/DrawInitForm";
const initState = {
vs: false,
fields: {},
iftype: {},
curitem: {},
visible: false,
};
function reducer(state, action) {
let { type } = action,
newState = {};
switch (type) {
case "add":
newState = {
...state,
vs: true,
iftype: {
title: "新增角色",
val: type,
},
fields: { ...action.fields },
};
break;
case "edit":
newState = {
...state,
vs: true,
iftype: {
title: "编辑角色",
val: type,
},
fields: { ...action.fields },
curitem: action.curitem,
};
break;
case "auth":
newState = {
...state,
visible: true,
iftype: {
title: action.title,
val: type,
},
curitem: action.curitem,
};
break;
case "dataauth":
newState = {
...state,
vs: true,
iftype: {
title: action.title,
val: type,
},
fields: { ...action.fields },
curitem: action.curitem,
};
break;
case "staff":
newState = {
...state,
visible: true,
iftype: {
title: action.title,
val: type,
},
curitem: action.curitem,
};
break;
case "close":
newState = {
vs: false,
fields: {},
iftype: {},
curitem: {},
details: {
dataSource: {},
totalCard: [],
visible: false,
},
};
break;
}
return newState;
}
const Charactor = (props) => {
let actionRef = useRef(),
ChildRef = null;
function reload() {
actionRef?.current?.reload();
ChildRef?.onRefresh();
}
const { run, loading } = useRequest(doFetch, {
manual: true,
formatResult: (res) => res,
onSuccess: (result, params) => {
if (result.code == "0000") {
closeTree();
}
},
}),
[state, dispatch] = useReducer(reducer, initState),
{ vs, fields, iftype, curitem, visible } = state,
columns = [
{
title: "角色名称",
dataIndex: "roleName",
key: "roleName",
},
{
title: "角色描述",
dataIndex: "remark",
key: "remark",
search: false,
},
{
title: "操作",
valueType: "option",
dataIndex: "option_dataindex",
key: "option_dataindex",
width: 215,
render: (text, row, _, action) => extraAction(text, row, _, action),
},
],
columnsc = [
{
title: "用户名",
dataIndex: "accountName",
key: "accountName",
},
{
title: "姓名",
dataIndex: "userName",
key: "userName",
},
{
title: "工厂",
dataIndex: "factoryName",
key: "factoryName",
},
{
title: "部门",
dataIndex: "departmentName",
key: "departmentName",
},
{
title: "负责车间",
dataIndex: "shopNames",
key: "shopNames",
},
{
title: "负责产线",
dataIndex: "productionLines",
key: "productionLines",
},
{
title: "负责工段",
dataIndex: "sectionNames",
key: "sectionNames",
},
];
function extraAction(text, record, _, action) {
return [
getPrem("sysRole_save", action, "修改", () => {
for (let i in defaultFields) {
defaultFields[i].value = record[i];
}
dispatch({ type: "edit", fields: defaultFields, curitem: record });
}),
getPrem("sysRole_deleteById", action, "删除", null, {
title: "确认删除该用户?",
onConfirm: () => {
run({
url: "/ngic-auth/sysRole/deleteById",
params: { id: record.id },
});
},
}),