Commit bd776721 authored by littleforest's avatar littleforest

feat: add role

parent b59a755e
import { Form, Modal, Select } from "antd"; import { Form, Modal, Select } from 'antd';
import TextArea from "antd/lib/input/TextArea"; import TextArea from 'antd/lib/input/TextArea';
import { useEffect, useState } from "react"; import { useEffect, useState } from 'react';
import styles from './index.less'; import styles from './index.less';
import { IFormValue } from "@/pages/PromptWord"; import type { IFormValue } from '@/pages/PromptWord';
interface IEditPromptModalProps { interface IEditPromptModalProps {
open: boolean; open: boolean;
...@@ -16,34 +16,35 @@ interface IEditPromptModalProps { ...@@ -16,34 +16,35 @@ interface IEditPromptModalProps {
} }
const EditPromptModal = (props: IEditPromptModalProps) => { const EditPromptModal = (props: IEditPromptModalProps) => {
const { open, setOpen, types, modalType, handleEditPrompt, loading, oldRow, handleCreatePrompt } = props; const { open, setOpen, types, modalType, handleEditPrompt, loading, oldRow, handleCreatePrompt } =
props;
const [currentSelectValue, setCurrentSelectValue] = useState<string | null>("请选择"); const [currentSelectValue, setCurrentSelectValue] = useState<string | null>('请选择');
const [textAreaValue, setTextAreaValue] = useState(''); const [textAreaValue, setTextAreaValue] = useState('');
useEffect(() => { useEffect(() => {
if(modalType === 'create') { if (modalType === 'create') {
setTextAreaValue(''); setTextAreaValue('');
setCurrentSelectValue(''); setCurrentSelectValue('');
} else { } else {
setTextAreaValue(oldRow.content); setTextAreaValue(oldRow.content);
setCurrentSelectValue(oldRow.type || '请选择'); setCurrentSelectValue(oldRow.type || '请选择');
} }
}, [open]) }, [open]);
const handleSavePrompt = async () => { const handleSavePrompt = async () => {
if(modalType === 'create') { if (modalType === 'create') {
await handleCreatePrompt({ await handleCreatePrompt({
type: currentSelectValue, type: currentSelectValue,
content: textAreaValue, content: textAreaValue,
}); });
} }
if(modalType === 'edit') { if (modalType === 'edit') {
await handleEditPrompt({ await handleEditPrompt({
type: currentSelectValue, type: currentSelectValue,
content: textAreaValue, content: textAreaValue,
}) });
} }
setOpen(false); setOpen(false);
...@@ -60,39 +61,36 @@ const EditPromptModal = (props: IEditPromptModalProps) => { ...@@ -60,39 +61,36 @@ const EditPromptModal = (props: IEditPromptModalProps) => {
confirmLoading={loading} confirmLoading={loading}
wrapClassName={styles.modal} wrapClassName={styles.modal}
title={modalType === 'create' ? '新增提示用语' : '编辑提示用语'} title={modalType === 'create' ? '新增提示用语' : '编辑提示用语'}
okText='保存' okText="保存"
onOk={handleSavePrompt} onOk={handleSavePrompt}
onCancel={() => { onCancel={() => {
setCurrentSelectValue('请选择'); setCurrentSelectValue('请选择');
setOpen(false); setOpen(false);
}} }}
width={574} width={574}
bodyStyle={{ bodyStyle={{
padding: '20px' padding: '20px',
}} }}
> >
<Form <Form labelAlign="right" {...layout}>
labelAlign="right" <Form.Item label="类型:">
{...layout}
>
<Form.Item
label="类型:"
>
<Select <Select
onChange={(value: string) => { onChange={(value: string) => {
setCurrentSelectValue(value); setCurrentSelectValue(value);
}} }}
value={currentSelectValue} value={currentSelectValue}
> >
{types.map(item => <Select.Option value={item} key={item}>{item}</Select.Option>)} {types.map((item) => (
<Select.Option value={item} key={item}>
{item}
</Select.Option>
))}
</Select> </Select>
</Form.Item> </Form.Item>
<Form.Item <Form.Item label="提示词语">
label="提示词语" <TextArea
>
<TextArea
style={{ style={{
height: '200px' height: '200px',
}} }}
value={textAreaValue} value={textAreaValue}
onChange={(e) => { onChange={(e) => {
...@@ -102,7 +100,7 @@ const EditPromptModal = (props: IEditPromptModalProps) => { ...@@ -102,7 +100,7 @@ const EditPromptModal = (props: IEditPromptModalProps) => {
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
) );
} };
export default EditPromptModal; export default EditPromptModal;
\ No newline at end of file
import { Modal } from "antd"; import { Modal } from 'antd';
import styles from './index.less'; import styles from './index.less';
import { Exclamtion } from "../Icons/Icons"; import { Exclamtion } from '../Icons/Icons';
interface IDeletePromptModalProps { interface IDeletePromptModalProps {
title: string; title: string;
open: boolean; open: boolean;
...@@ -12,25 +12,17 @@ interface IDeletePromptModalProps { ...@@ -12,25 +12,17 @@ interface IDeletePromptModalProps {
} }
const DeletePromptModal = (props: IDeletePromptModalProps) => { const DeletePromptModal = (props: IDeletePromptModalProps) => {
const { const { title, open, setOpen, tip, content, loading, handleDeletePrompt } = props;
title,
open,
setOpen,
tip,
content,
loading,
handleDeletePrompt,
} = props;
const handleSavePrompt = async () => { const handleSavePrompt = async () => {
await handleDeletePrompt(); await handleDeletePrompt();
setOpen(false); setOpen(false);
} };
return ( return (
<Modal <Modal
title={title} title={title}
okText='确认' okText="确认"
open={open} open={open}
onOk={handleSavePrompt} onOk={handleSavePrompt}
onCancel={() => { onCancel={() => {
...@@ -41,11 +33,9 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => { ...@@ -41,11 +33,9 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => {
<div className={styles.deleteTitle}> <div className={styles.deleteTitle}>
<Exclamtion /> {tip} <Exclamtion /> {tip}
</div> </div>
<div className={styles.deleteContent}> <div className={styles.deleteContent}>{content}</div>
{content}
</div>
</Modal> </Modal>
) );
} };
export default DeletePromptModal; export default DeletePromptModal;
\ No newline at end of file
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
color: #ffffff; color: #ffffff;
font-size: 18px; font-size: 18px;
line-height: 25px; line-height: 25px;
cursor: pointer;
} }
.footer { .footer {
......
...@@ -162,13 +162,11 @@ const Chat: React.FC = () => { ...@@ -162,13 +162,11 @@ const Chat: React.FC = () => {
span={24} span={24}
className={styles.chatFooterItem} className={styles.chatFooterItem}
hidden={!access.roles?.find((x) => ['管理员', 'admin'].includes(x))} hidden={!access.roles?.find((x) => ['管理员', 'admin'].includes(x))}
onClick={() => {
history.push('/');
}}
> >
<Space <Space wrap>
wrap
onClick={() => {
history.push('/');
}}
>
<SettingOutlined /> <SettingOutlined />
后台管理 后台管理
</Space> </Space>
......
...@@ -13,7 +13,7 @@ import { ProTable } from '@ant-design/pro-components'; ...@@ -13,7 +13,7 @@ import { ProTable } from '@ant-design/pro-components';
import { Button, Col, Divider, Form, Input, Modal, Radio, Row, Switch, message } from 'antd'; import { Button, Col, Divider, Form, Input, Modal, Radio, Row, Switch, message } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { useRef, useState } from 'react'; import { useRef, useState, useEffect } from 'react';
import styles from './index.less'; import styles from './index.less';
import { Exclamtion } from '@/components/Icons/Icons'; import { Exclamtion } from '@/components/Icons/Icons';
...@@ -51,13 +51,18 @@ const UserManage = () => { ...@@ -51,13 +51,18 @@ const UserManage = () => {
const [accountForm] = Form.useForm(); const [accountForm] = Form.useForm();
const [resetPasswordForm] = Form.useForm(); const [resetPasswordForm] = Form.useForm();
const showModal = () => { useEffect(() => {
getRole().then((res) => { getRole().then((res) => {
if (!isEmpty(res)) { if (!isEmpty(res)) {
setRoles(res); setRoles(res);
setIsModalAccountOpen(true);
} }
}); });
}, []);
const showModal = () => {
if (!isEmpty(roles)) {
setIsModalAccountOpen(true);
}
}; };
const columns: any[] = [ const columns: any[] = [
...@@ -438,7 +443,6 @@ const UserManage = () => { ...@@ -438,7 +443,6 @@ const UserManage = () => {
rowKey="id" rowKey="id"
pagination={{ pagination={{
pageSize: 9, pageSize: 9,
onChange: (page) => {},
}} }}
options={false} options={false}
dateFormatter="string" dateFormatter="string"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment