Commit bd776721 authored by littleforest's avatar littleforest

feat: add role

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