使用字典数据获取下拉选项

main
liuyiliang 4 months ago
parent 7ae5133851
commit 0a3218b399
  1. 2
      packages/examination/src/api/demo/index.tsx
  2. 8
      packages/examination/src/api/dict/index.tsx
  3. 72
      packages/examination/src/views/demo/demoList.tsx

@ -2,7 +2,7 @@ import axios from '../axios';
export function getList(obj: any) { export function getList(obj: any) {
return axios({ return axios({
url: '/ins/demo/list', url: '/ex/demo/list',
method: 'get' method: 'get'
}) })
} }

@ -0,0 +1,8 @@
import axios from '../axios';
export function dictionary(code: any) {
return axios({
url: '/ex/dict/dictionary?code=' + code,
method: 'get'
})
}

@ -1,12 +1,16 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { Button, Empty, Modal, notification, Popconfirm } from "antd"; import {Button, Empty, Form, Input, Modal, notification, Popconfirm, Select} from "antd";
import { getList } from "api/demo/index"; import { getList } from "api/demo/index";
import { dictionary } from "api/dict/index";
const { Option } = Select
interface States { interface States {
resData: any resData: any
visible: boolean visible: boolean
title: string title: string
current: any current: any,
sexDict: any
} }
class DemoList extends Component<any, States> { class DemoList extends Component<any, States> {
@ -16,12 +20,14 @@ class DemoList extends Component<any, States> {
resData: undefined, resData: undefined,
visible: false, visible: false,
title: '新增公告', title: '新增公告',
current: {} current: {},
sexDict: undefined
} }
} }
componentDidMount() { componentDidMount() {
this.getList() this.getList()
this.getDict()
} }
getList() { getList() {
@ -33,39 +39,20 @@ class DemoList extends Component<any, States> {
}).catch(() => { }) }).catch(() => { })
} }
getStatusText(status: number): string { getDict() {
if (status === 1) { dictionary('sex').then((res) => {
return "启用"; if(res.data){
} else if (status === 0) { this.setState({ sexDict: res.data })
return "禁用";
} else {
return '';
} }
})
} }
handelCreate() { handelCreate() {
this.setState({ visible: true }) this.setState({ visible: true })
} }
handelUpdate(item: any) {
this.setState({
visible: true,
title: '编辑公告',
current: item
})
}
handleEnable(item: any) {
}
handleDisable(item: any) {
}
handleDel(item: any) {
}
render() { render() {
const { resData, visible, title, current } = this.state; const { resData, visible, title, current, sexDict } = this.state;
const handleCancel = () => { const handleCancel = () => {
this.setState({ visible: false }) this.setState({ visible: false })
}; };
@ -73,6 +60,35 @@ class DemoList extends Component<any, States> {
return ( return (
<div className="container"> <div className="container">
<div className="ikd-page-header"><div className="title">TABLE</div></div> <div className="ikd-page-header"><div className="title">TABLE</div></div>
<div className="list-filter">
<Form
className="filter"
layout="inline"
name="basic"
>
<Form.Item
label="性别:"
name="sex">
<Select placeholder="全部" style={{ width: 120 }} allowClear>
{
sexDict && sexDict.length > 0 ?
(() => {
let rows = [];
for (let i = 0; i < sexDict.length; i++) {
const item = sexDict[i];
rows.push(
<Option value={item.dictKey}>{item.dictValue}</Option>
);
}
return rows;
})()
:
<Option disabled></Option>
}
</Select>
</Form.Item>
</Form>
</div>
{ {
resData ? null : resData ? null :
<Button type="primary" style={{ marginBottom: 15 }} onClick={this.handelCreate.bind(this)}>ADD</Button> <Button type="primary" style={{ marginBottom: 15 }} onClick={this.handelCreate.bind(this)}>ADD</Button>

Loading…
Cancel
Save