|
@@ -1,10 +1,14 @@
|
|
|
-import {useCallback, useMemo, useState} from "react";
|
|
|
-import {Alert} from "antd";
|
|
|
+import {forwardRef, useCallback, useImperativeHandle, useMemo, useState} from "react";
|
|
|
+import {Alert, Modal} from "antd";
|
|
|
import './index.less'
|
|
|
import {CurdColumn, CurdPage} from "../../../components/curd";
|
|
|
import {ICurdConfig} from "../../../components/curd/types.ts";
|
|
|
import {Settings, SettingsApis} from "../../../api/settings.ts";
|
|
|
import {PageData} from "../../../models/api.ts";
|
|
|
+import {CurdForm} from "../../../components/curd/Form.tsx";
|
|
|
+import {useAppDispatch} from "../../../store";
|
|
|
+import {UserActions} from "../../../store/slice/user.ts";
|
|
|
+import {LoginApis} from "../../../api/user.ts";
|
|
|
|
|
|
const columns: CurdColumn[] = [
|
|
|
{
|
|
@@ -13,7 +17,9 @@ const columns: CurdColumn[] = [
|
|
|
type: 'string',
|
|
|
required: true,
|
|
|
width: 220,
|
|
|
- addable: true,
|
|
|
+ addable: false,
|
|
|
+ editable: false,
|
|
|
+ placeholder: '网站的唯一ID,不可重复'
|
|
|
},
|
|
|
{
|
|
|
key: 'title',
|
|
@@ -34,17 +40,21 @@ const columns: CurdColumn[] = [
|
|
|
key: 'type',
|
|
|
type: 'select',
|
|
|
title: '菜单类型',
|
|
|
- value: 'MENU',
|
|
|
+ value: 'LINK',
|
|
|
width: 100,
|
|
|
option: [
|
|
|
{
|
|
|
- label: '导航栏',
|
|
|
- value: 'NAV'
|
|
|
+ label: '文件夹',
|
|
|
+ value: 'FOLDER'
|
|
|
},
|
|
|
{
|
|
|
label: '快捷方式',
|
|
|
value: 'LINK'
|
|
|
- }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '导航栏',
|
|
|
+ value: 'NAV'
|
|
|
+ },
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -63,7 +73,7 @@ const columns: CurdColumn[] = [
|
|
|
value: 'APP',
|
|
|
},
|
|
|
{
|
|
|
- label: '新标签',
|
|
|
+ label: '路由',
|
|
|
value: 'TAB',
|
|
|
},
|
|
|
]
|
|
@@ -73,7 +83,8 @@ const columns: CurdColumn[] = [
|
|
|
type: 'number',
|
|
|
title: '排序',
|
|
|
placeholder: '越大越靠前',
|
|
|
- width: 100
|
|
|
+ width: 100,
|
|
|
+ required: false,
|
|
|
},
|
|
|
{
|
|
|
key: 'brief',
|
|
@@ -93,6 +104,18 @@ const serverConfig: ICurdConfig<Settings.Route> = {
|
|
|
operationWidth: 120,
|
|
|
}
|
|
|
|
|
|
+const onSave = (data: Partial<Settings.Route>) => {
|
|
|
+ return SettingsApis.saveRoute({
|
|
|
+ pid: "",
|
|
|
+ uid: -1,
|
|
|
+ deleted: true,
|
|
|
+ ...data,
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ return res.data.data as Settings.Route;
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 用户列表的操作
|
|
|
* @constructor
|
|
@@ -137,17 +160,7 @@ export const UserLinks = () => {
|
|
|
return Promise.resolve({...data} as Settings.Route)
|
|
|
}
|
|
|
|
|
|
- const onSave = (data: Partial<Settings.Route>) => {
|
|
|
- return SettingsApis.saveRoute({
|
|
|
- pid: "",
|
|
|
- uid: -1,
|
|
|
- deleted: true,
|
|
|
- ...data,
|
|
|
- })
|
|
|
- .then(res => {
|
|
|
- return res.data.data as Settings.Route;
|
|
|
- })
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
const handleDelete = (record: Settings.Route) => {
|
|
|
return SettingsApis.removeRoute(record.id)
|
|
@@ -176,3 +189,44 @@ export const UserLinks = () => {
|
|
|
config={config}/>
|
|
|
</>)
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+type IAddProps = {
|
|
|
+ onSuccess?: () => void
|
|
|
+}
|
|
|
+
|
|
|
+export const AddLinkModal = forwardRef<any,IAddProps>((_props, ref) => {
|
|
|
+ const [visible,setVisible] = useState<boolean>(false)
|
|
|
+ const dispatch = useAppDispatch()
|
|
|
+
|
|
|
+ const onShow = () => {
|
|
|
+ setVisible(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ const onClose = () => {
|
|
|
+ setVisible(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ const onSuccess = () => {
|
|
|
+ LoginApis.userinfo().then(({data}) => {
|
|
|
+ dispatch(UserActions.setUser(data as any))
|
|
|
+ _props.onSuccess?.()
|
|
|
+ }).catch(e => {
|
|
|
+ console.warn('userinfo fail', e);
|
|
|
+ }).finally(()=>{
|
|
|
+ setVisible(false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ useImperativeHandle(ref,()=>{
|
|
|
+ return {
|
|
|
+ onShow
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ return (<Modal open={visible} onCancel={onClose}
|
|
|
+ title="添加快捷方式"
|
|
|
+ footer={null} destroyOnClose={true}>
|
|
|
+ <CurdForm columns={columns} onSave={onSave as any} onClose={onClose} onSuccess={onSuccess}/>
|
|
|
+ </Modal>)
|
|
|
+})
|