提交 a972921a 作者: 龚洪江

修复:路由缓存,加盟入驻地址可选

上级 e79e1c55
...@@ -130,6 +130,8 @@ export type listCompanyPage = InterListFunction< ...@@ -130,6 +130,8 @@ export type listCompanyPage = InterListFunction<
phoneNum: string; phoneNum: string;
province: string; province: string;
remark: string; remark: string;
lat: number;
lon: number;
} }
>; >;
// 单位-新增 // 单位-新增
...@@ -147,6 +149,8 @@ export type listCompanyAdd = InterFunction< ...@@ -147,6 +149,8 @@ export type listCompanyAdd = InterFunction<
province?: string; province?: string;
remark?: string; remark?: string;
area?: string[]; area?: string[];
lat: number;
lon: number;
}, },
NonNullable<unknown> NonNullable<unknown>
>; >;
...@@ -165,6 +169,8 @@ export type listCompanyUpdate = InterFunction< ...@@ -165,6 +169,8 @@ export type listCompanyUpdate = InterFunction<
province?: string; province?: string;
remark?: string; remark?: string;
area?: string[]; area?: string[];
lat: number;
lon: number;
}, },
NonNullable<unknown> NonNullable<unknown>
>; >;
......
...@@ -5,7 +5,6 @@ import { Button, Dropdown, MenuProps, Modal } from 'antd'; ...@@ -5,7 +5,6 @@ import { Button, Dropdown, MenuProps, Modal } from 'antd';
import Logo from '../../../assets/icon/logo_big.png'; import Logo from '../../../assets/icon/logo_big.png';
import './index.scss'; import './index.scss';
import { REMOVE_MENU, REMOVE_MENU_ID, SET_COLLAPSE } from '~/store/module/menu'; import { REMOVE_MENU, REMOVE_MENU_ID, SET_COLLAPSE } from '~/store/module/menu';
import { REMOVE_ROLE_ID } from '~/store/module/userInfo';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
...@@ -42,7 +41,6 @@ export function TitleView() { ...@@ -42,7 +41,6 @@ export function TitleView() {
Cookies.remove('SHAREFLY-TOKEN'); Cookies.remove('SHAREFLY-TOKEN');
dispatch(REMOVE_MENU()); dispatch(REMOVE_MENU());
dispatch(REMOVE_MENU_ID()); dispatch(REMOVE_MENU_ID());
dispatch(REMOVE_ROLE_ID());
}, },
}); });
}} }}
...@@ -62,8 +60,8 @@ export function TitleView() { ...@@ -62,8 +60,8 @@ export function TitleView() {
}} }}
> >
<div className='layout-logo'> <div className='layout-logo'>
<img className='logo-img' src={Logo} alt='云享飞' /> <img src={userInfo.companyInfoVO.brandLogo || Logo} className='logo-img' alt='云享飞' />
<div className='logo-text'>云享飞后台管理</div> <div className='logo-text'>{userInfo.companyInfoVO.brandName || '云享飞管理后台'}</div>
<div onClick={setMenuCollapsed}> <div onClick={setMenuCollapsed}>
<svg <svg
className={`hamburger ${isActive ? 'is-active' : ''}`} className={`hamburger ${isActive ? 'is-active' : ''}`}
......
import React, { useEffect } from 'react'; import React, { useEffect, useState } from 'react';
import { InterListType, InterReqType } from '~/api/interface'; import { InterListType, InterReqType } from '~/api/interface';
import { listCompanyAdd, listCompanyPage } from '~/api/interface/systemManageType'; import { listCompanyAdd, listCompanyPage } from '~/api/interface/systemManageType';
import { Form, Input, message, Modal } from 'antd'; import { Button, Col, Form, Input, message, Modal, Row } from 'antd';
import { SystemManageAPI } from '~/api'; import { SystemManageAPI } from '~/api';
import { EnvironmentOutlined } from '@ant-design/icons';
import SelectMap from '~/components/select-map';
// 列表的类型 // 列表的类型
type TableType = InterListType<listCompanyPage>; type TableType = InterListType<listCompanyPage>;
// 请求的表单类型 // 请求的表单类型
type ReqType = InterReqType<listCompanyAdd>; type ReqType = Exclude<InterReqType<listCompanyAdd>, undefined>;
// 传参类型 // 传参类型
interface propType { interface propType {
title: string; title: string;
...@@ -20,6 +22,15 @@ const AddEditModal: React.FC<propType> = (props) => { ...@@ -20,6 +22,15 @@ const AddEditModal: React.FC<propType> = (props) => {
const { title, open, closed, data } = props; const { title, open, closed, data } = props;
/// 表单钩子 /// 表单钩子
const [form] = Form.useForm<ReqType>(); const [form] = Form.useForm<ReqType>();
//选点信息
const [position, setPosition] = useState<{
lat: number;
lon: number;
address: string;
}>();
//地图选点弹窗
const [selectMapShow, setSelectMapShow] = useState<boolean>(false);
// 关闭弹窗 // 关闭弹窗
const handleCancel = () => { const handleCancel = () => {
form.resetFields(); form.resetFields();
...@@ -30,13 +41,14 @@ const AddEditModal: React.FC<propType> = (props) => { ...@@ -30,13 +41,14 @@ const AddEditModal: React.FC<propType> = (props) => {
form form
.validateFields() .validateFields()
.then(async (values) => { .then(async (values) => {
await handleSubmit({ if (position) {
...values, await handleSubmit({
province: values?.area?.at(0), ...values,
city: values?.area?.at(1), lat: position.lat,
district: values?.area?.at(2), lon: position.lon,
companyType: data?.id === 1 ? 0 : 1, companyType: data?.id === 1 ? 0 : 1,
}); });
}
}) })
.catch((err) => { .catch((err) => {
message message
...@@ -57,6 +69,26 @@ const AddEditModal: React.FC<propType> = (props) => { ...@@ -57,6 +69,26 @@ const AddEditModal: React.FC<propType> = (props) => {
handleCancel(); handleCancel();
} }
}; };
const selectMapShowClick = () => {
setSelectMapShow(true);
};
const selectMapClose = () => {
setSelectMapShow(false);
};
const selectMapSubmit = (value: { lat: number; lon: number; address: string }) => {
form.setFieldValue('address', value.address);
setPosition(value);
setSelectMapShow(false);
};
const addressInputEvent = (e: any) => {
if (position) {
position.address = e.target.value;
form.setFieldValue('address', e.target.value || undefined);
setPosition({ ...position });
}
};
// componentDidMount // componentDidMount
useEffect(() => { useEffect(() => {
if (!open) return; if (!open) return;
...@@ -65,9 +97,12 @@ const AddEditModal: React.FC<propType> = (props) => { ...@@ -65,9 +97,12 @@ const AddEditModal: React.FC<propType> = (props) => {
// @ts-ignore // @ts-ignore
form.setFieldsValue({ form.setFieldsValue({
...data, ...data,
area: [data?.province, data?.city, data?.district],
}); });
// console.log('data --->', data); setPosition({
address: data.address,
lat: data.lat,
lon: data.lon,
});
}, [open]); }, [open]);
return ( return (
<Modal <Modal
...@@ -114,7 +149,27 @@ const AddEditModal: React.FC<propType> = (props) => { ...@@ -114,7 +149,27 @@ const AddEditModal: React.FC<propType> = (props) => {
name='address' name='address'
rules={[{ required: true, message: '请输入详细地址' }]} rules={[{ required: true, message: '请输入详细地址' }]}
> >
<Input.TextArea placeholder='请输入详细地址' maxLength={50} showCount /> {/*<Input.TextArea placeholder='请输入详细地址' maxLength={50} showCount />*/}
<Row justify='space-between'>
{position ? (
<Col span={21}>
<Input
placeholder='请输入详细地址'
value={position.address}
onChange={addressInputEvent}
/>
</Col>
) : (
''
)}
<Col span={2}>
<Button
icon={<EnvironmentOutlined />}
type='primary'
onClick={selectMapShowClick}
></Button>
</Col>
</Row>
</Form.Item> </Form.Item>
<Form.Item label='联系人' name='companyUserName'> <Form.Item label='联系人' name='companyUserName'>
<Input placeholder='请输入联系人' maxLength={15} /> <Input placeholder='请输入联系人' maxLength={15} />
...@@ -138,6 +193,7 @@ const AddEditModal: React.FC<propType> = (props) => { ...@@ -138,6 +193,7 @@ const AddEditModal: React.FC<propType> = (props) => {
<Form.Item label='备注' name='remark'> <Form.Item label='备注' name='remark'>
<Input.TextArea placeholder='请输入备注' maxLength={50} showCount /> <Input.TextArea placeholder='请输入备注' maxLength={50} showCount />
</Form.Item> </Form.Item>
<SelectMap open={selectMapShow} closed={selectMapClose} submit={selectMapSubmit} />
</Form> </Form>
</Modal> </Modal>
); );
......
...@@ -3,15 +3,15 @@ import { RouteObjectType, routerList } from '~/router/router'; ...@@ -3,15 +3,15 @@ import { RouteObjectType, routerList } from '~/router/router';
import { InterDataType } from '~/api/interface'; import { InterDataType } from '~/api/interface';
import { listMenuInfoType } from '~/api/interface/systemManageType'; import { listMenuInfoType } from '~/api/interface/systemManageType';
import { SystemManageAPI } from '~/api'; import { SystemManageAPI } from '~/api';
import { store } from '~/store';
import { SET_MENU } from '~/store/module/menu';
//菜单类型 //菜单类型
type menuType = InterDataType<listMenuInfoType>; type menuType = InterDataType<listMenuInfoType>;
// 缓存路由列表
let routerListStore: any[] = [];
// 获取用户权限路由列表 // 获取用户权限路由列表
export const authRouterList = async () => { export const authRouterList = async () => {
// 如果缓存中没有数据 // 如果缓存中没有数据
if (routerListStore.length === 0) { if (store.getState().Menu.menuList.length === 0) {
// 加载路由数据 // 加载路由数据
const { result } = await SystemManageAPI.getListRoleMenuInfo({ const { result } = await SystemManageAPI.getListRoleMenuInfo({
roleId: Number(localStorage.getItem('roleId')), roleId: Number(localStorage.getItem('roleId')),
...@@ -31,11 +31,11 @@ export const authRouterList = async () => { ...@@ -31,11 +31,11 @@ export const authRouterList = async () => {
}; };
const arr = [...getRouteList(routerList)]; const arr = [...getRouteList(routerList)];
// 将路由数据存到store中 // 将路由数据存到store中
routerListStore = arr; store.dispatch(SET_MENU(arr));
// 完成后返回路由数据 // 完成后返回路由数据
return Promise.resolve(arr); return Promise.resolve(arr);
} else { } else {
return Promise.resolve(routerListStore); return Promise.resolve(store.getState().Menu.menuList);
} }
}; };
//获取全部节点 //获取全部节点
......
...@@ -26,7 +26,7 @@ function PrivateRouter() { ...@@ -26,7 +26,7 @@ function PrivateRouter() {
const routes = [...value, ...whiteRouterList]; const routes = [...value, ...whiteRouterList];
setRouter(routes); setRouter(routes);
if (path === '/') { if (path === '/') {
navigate({ pathname: value[0].children.find((v: any) => !v.meta.hidden)?.path }); navigate({ pathname: value[0].children?.find((v: any) => !v.meta.hidden)?.path });
} }
} else { } else {
message.warning('该账号暂无权限'); message.warning('该账号暂无权限');
......
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
const initialState = { const initialState = {
menuList: JSON.parse(localStorage.getItem('SXTB-ADMIN-MENU-LIST') as string) || [], menuList: [],
collapsedActive: false, collapsedActive: false,
menuId: JSON.parse(localStorage.getItem('SXTB-ADMIN-MENU-ID') as string) || null, roleId: localStorage.getItem('roleId') || -1,
}; };
export const menuSlice = createSlice({ export const menuSlice = createSlice({
...@@ -12,22 +12,19 @@ export const menuSlice = createSlice({ ...@@ -12,22 +12,19 @@ export const menuSlice = createSlice({
reducers: { reducers: {
SET_MENU(state, action) { SET_MENU(state, action) {
state.menuList = action.payload; state.menuList = action.payload;
localStorage.setItem('SXTB-ADMIN-MENU-LIST', JSON.stringify(action.payload));
}, },
SET_COLLAPSE(state, action) { SET_COLLAPSE(state, action) {
state.collapsedActive = action.payload; state.collapsedActive = action.payload;
}, },
REMOVE_MENU(state) { REMOVE_MENU(state) {
localStorage.setItem('SXTB-ADMIN-MENU-LIST', JSON.stringify([]));
state.menuList = []; state.menuList = [];
}, },
SET_MENU_ID(state, action) { SET_MENU_ID(state, action) {
localStorage.setItem('SXTB-ADMIN-MENU-ID', JSON.stringify(action.payload)); state.roleId = action.payload;
state.menuId = action.payload; localStorage.setItem('roleId', action.payload);
}, },
REMOVE_MENU_ID(state) { REMOVE_MENU_ID() {
localStorage.setItem('SXTB-ADMIN-MENU-ID', JSON.stringify(null)); localStorage.removeItem('roleId');
state.menuId = null;
}, },
}, },
}); });
......
...@@ -2,8 +2,6 @@ import { createSlice } from '@reduxjs/toolkit'; ...@@ -2,8 +2,6 @@ import { createSlice } from '@reduxjs/toolkit';
const initialState = { const initialState = {
userInfo: JSON.parse(localStorage.getItem('SXTB-ADMIN-USER-INFO') as string) || [], userInfo: JSON.parse(localStorage.getItem('SXTB-ADMIN-USER-INFO') as string) || [],
roleId: -1,
roleList: [],
}; };
export const userInfoSlice = createSlice({ export const userInfoSlice = createSlice({
...@@ -14,24 +12,9 @@ export const userInfoSlice = createSlice({ ...@@ -14,24 +12,9 @@ export const userInfoSlice = createSlice({
state.userInfo = action.payload; state.userInfo = action.payload;
localStorage.setItem('SXTB-ADMIN-USER-INFO', JSON.stringify(action.payload)); localStorage.setItem('SXTB-ADMIN-USER-INFO', JSON.stringify(action.payload));
}, },
SET_ROLE_ID(state, action) {
state.roleId = action.payload;
localStorage.setItem('roleId', action.payload);
},
REMOVE_ROLE_ID() {
localStorage.removeItem('roleId');
},
SET_ROLE_LIST(state, action) {
state.roleList = action.payload;
localStorage.setItem('roleObj', JSON.stringify(action.payload));
},
REMOVE_ROLE_LIST() {
localStorage.removeItem('roleObj');
},
}, },
}); });
export const { SET_USERINFO, SET_ROLE_ID, SET_ROLE_LIST, REMOVE_ROLE_LIST, REMOVE_ROLE_ID } = export const { SET_USERINFO } = userInfoSlice.actions;
userInfoSlice.actions;
export const UserInfo = userInfoSlice.reducer; export const UserInfo = userInfoSlice.reducer;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论