|
@@ -3,11 +3,14 @@ import {useState, useEffect} from "react";
|
|
|
import ModalHooks from "./components/dictType.jsx";
|
|
import ModalHooks from "./components/dictType.jsx";
|
|
|
import "./dict.scss";
|
|
import "./dict.scss";
|
|
|
import axios from "@/utils/axios.js";
|
|
import axios from "@/utils/axios.js";
|
|
|
-
|
|
|
|
|
|
|
+import { useDispatch } from 'react-redux';
|
|
|
|
|
+import { setDictData } from '@/store/reducer.js';
|
|
|
const {Column} = Table;
|
|
const {Column} = Table;
|
|
|
|
|
|
|
|
export default function Dict() {
|
|
export default function Dict() {
|
|
|
|
|
+ // 顶部两个搜索
|
|
|
const [inputVal, setInputVal] = useState("");
|
|
const [inputVal, setInputVal] = useState("");
|
|
|
|
|
+ const [keyVal, setKeyVal] = useState("");
|
|
|
// 页面数据
|
|
// 页面数据
|
|
|
const [data, setData] = useState([]);
|
|
const [data, setData] = useState([]);
|
|
|
// 是否展示弹框
|
|
// 是否展示弹框
|
|
@@ -23,7 +26,11 @@ export default function Dict() {
|
|
|
// 关闭页面
|
|
// 关闭页面
|
|
|
function closeModal() {
|
|
function closeModal() {
|
|
|
setIsModalOpen(false);
|
|
setIsModalOpen(false);
|
|
|
|
|
+ // 置空input,然后存reduce
|
|
|
|
|
+ setInputVal('')
|
|
|
|
|
+ setKeyVal('')
|
|
|
getData()
|
|
getData()
|
|
|
|
|
+ dispatch(setDictData(data))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 点击修改的回调
|
|
// 点击修改的回调
|
|
@@ -32,11 +39,13 @@ export default function Dict() {
|
|
|
setIsModalOpen(true);
|
|
setIsModalOpen(true);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ // reduce状态
|
|
|
|
|
+ const dispatch = useDispatch();
|
|
|
// 获取数据
|
|
// 获取数据
|
|
|
async function getData() {
|
|
async function getData() {
|
|
|
- let {data} = await axios.get("/sys/select");
|
|
|
|
|
|
|
+ let {data} = await axios.get("/dict/selectKey",{params:{type:inputVal,name:keyVal}});
|
|
|
setData(data);
|
|
setData(data);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -45,12 +54,32 @@ export default function Dict() {
|
|
|
* @returns {Promise<void>}
|
|
* @returns {Promise<void>}
|
|
|
*/
|
|
*/
|
|
|
async function deleteRow(data) {
|
|
async function deleteRow(data) {
|
|
|
- let {code} = await axios.get('/sys/delete', {params: {id: data.id}})
|
|
|
|
|
|
|
+ let {code} = await axios.get('/dict/deleteKey', {params: {id: data.id}})
|
|
|
if (code === 200) {
|
|
if (code === 200) {
|
|
|
await getData()
|
|
await getData()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 父表格的子表格
|
|
|
|
|
+ const expandedRowRender = (record) => {
|
|
|
|
|
+ const columns = [
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '名称',
|
|
|
|
|
+ dataIndex: 'name',
|
|
|
|
|
+ key: 'id',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '值',
|
|
|
|
|
+ dataIndex: 'val',
|
|
|
|
|
+ key: 'id',
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
|
|
+ ];
|
|
|
|
|
+ const data = [];
|
|
|
|
|
+ for (const item of record.valueList) {
|
|
|
|
|
+ data.push(item)
|
|
|
|
|
+ }
|
|
|
|
|
+ return <Table columns={columns} pagination={false} dataSource={data} bordered={true}/>;
|
|
|
|
|
+ };
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
getData();
|
|
getData();
|
|
|
}, []);
|
|
}, []);
|
|
@@ -58,14 +87,22 @@ export default function Dict() {
|
|
|
<div className="user">
|
|
<div className="user">
|
|
|
<div className="top">
|
|
<div className="top">
|
|
|
<div className="input">
|
|
<div className="input">
|
|
|
|
|
+ <Input
|
|
|
|
|
+ value={keyVal}
|
|
|
|
|
+ onChange={(e) => setKeyVal(e.target.value)}
|
|
|
|
|
+ placeholder="字典名称"
|
|
|
|
|
+
|
|
|
|
|
+ />
|
|
|
<Input
|
|
<Input
|
|
|
value={inputVal}
|
|
value={inputVal}
|
|
|
onChange={(e) => setInputVal(e.target.value)}
|
|
onChange={(e) => setInputVal(e.target.value)}
|
|
|
- />{" "}
|
|
|
|
|
- <Button type="primary">搜索</Button>
|
|
|
|
|
|
|
+ placeholder="字典类型"
|
|
|
|
|
+ style={{marginLeft:'10px'}}
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
|
|
+ <Button type="primary" onClick={getData}>搜索</Button>
|
|
|
</div>
|
|
</div>
|
|
|
<div className="button">
|
|
<div className="button">
|
|
|
-
|
|
|
|
|
<Button type="primary" onClick={addUser}>
|
|
<Button type="primary" onClick={addUser}>
|
|
|
添加字典数值
|
|
添加字典数值
|
|
|
</Button>
|
|
</Button>
|
|
@@ -76,21 +113,13 @@ export default function Dict() {
|
|
|
pagination={{position: ["bottomRight"]}}
|
|
pagination={{position: ["bottomRight"]}}
|
|
|
bordered={true}
|
|
bordered={true}
|
|
|
rowKey="id"
|
|
rowKey="id"
|
|
|
|
|
+ expandable={{
|
|
|
|
|
+ expandedRowRender,
|
|
|
|
|
+
|
|
|
|
|
+ }}
|
|
|
>
|
|
>
|
|
|
- <Column title="用户名" dataIndex="account" key="id" width="200px"/>
|
|
|
|
|
- <Column title="姓名" dataIndex="name" key="id"/>
|
|
|
|
|
- <Column title="手机号" dataIndex="phone" key="id"/>
|
|
|
|
|
- <Column
|
|
|
|
|
- title="类型"
|
|
|
|
|
- dataIndex="type"
|
|
|
|
|
- key="id"
|
|
|
|
|
- render={(type) => (
|
|
|
|
|
- <>
|
|
|
|
|
- <span>{type === 0 ? "管理员" : "游客"}</span>
|
|
|
|
|
- </>
|
|
|
|
|
- )}
|
|
|
|
|
- ></Column>
|
|
|
|
|
- <Column title="备注" dataIndex="remark" key="id"/>
|
|
|
|
|
|
|
+ <Column title="字典名称" dataIndex="name" key="id" width="200px"/>
|
|
|
|
|
+ <Column title="字典类型" dataIndex="type" key="id"/>
|
|
|
<Column
|
|
<Column
|
|
|
title="操作"
|
|
title="操作"
|
|
|
width="170px"
|
|
width="170px"
|