Commit 5cef5fc3 authored by 张烨's avatar 张烨

fix: 网站配置回显

parent a54591f2
...@@ -3,12 +3,12 @@ import { Drawer } from 'antd'; ...@@ -3,12 +3,12 @@ import { Drawer } from 'antd';
import WebConfigForm from './webConfigForm'; import WebConfigForm from './webConfigForm';
export default props => { export default props => {
const { visible, onClose, config, hasIntegerate } = props; const { visible, onClose, config, hasIntegerate, isEdit } = props;
return ( return (
<Drawer <Drawer
title={config ? '编辑网站' : '添加网站'} title={isEdit ? '查看/编辑网站配置' : '新增网站'}
width={520} width={620}
closable closable
onClose={onClose} onClose={onClose}
visible={visible} visible={visible}
...@@ -16,6 +16,7 @@ export default props => { ...@@ -16,6 +16,7 @@ export default props => {
> >
<WebConfigForm <WebConfigForm
hasIntegerate={hasIntegerate} hasIntegerate={hasIntegerate}
isEdit={isEdit}
config={config} config={config}
onCancel={onClose} onCancel={onClose}
onOk={values => { onOk={values => {
......
...@@ -9,11 +9,10 @@ import { Row, Col } from 'antd'; ...@@ -9,11 +9,10 @@ import { Row, Col } from 'antd';
import { getDefaultGetWebconfig, singleStyleData } from '../utils'; import { getDefaultGetWebconfig, singleStyleData } from '../utils';
const WebConfigForm = props => { const WebConfigForm = props => {
const { hasIntegerate, config, onCancel, onSubmit, onOk } = props; const { hasIntegerate, config, onCancel, onSubmit, onOk, isEdit } = props;
const [webThemes, setWebThemes] = useState([]); const [webThemes, setWebThemes] = useState([]);
const [mapConfigs, setMapConfigs] = useState([]); const [mapConfigs, setMapConfigs] = useState([]);
const [loginPages, setLoginPages] = useState([]); const [loginPages, setLoginPages] = useState([]);
const [webType, setWebType] = useState();
const [form, setForm] = useState(null); const [form, setForm] = useState(null);
const getForm = f => { const getForm = f => {
...@@ -48,12 +47,12 @@ const WebConfigForm = props => { ...@@ -48,12 +47,12 @@ const WebConfigForm = props => {
initialValues: config, initialValues: config,
hasIntegerate, hasIntegerate,
webThemes, webThemes,
webType,
onGetThemes, onGetThemes,
loginPages, loginPages,
mapConfigs, mapConfigs,
onGetLoginPages, onGetLoginPages,
onGetMapConfig, onGetMapConfig,
isEdit,
}); });
const formConfig = { const formConfig = {
...@@ -97,15 +96,12 @@ const WebConfigForm = props => { ...@@ -97,15 +96,12 @@ const WebConfigForm = props => {
labelCol={{ span: 6 }} labelCol={{ span: 6 }}
wrapperCol={{ span: 14 }} wrapperCol={{ span: 14 }}
onValuesChange={v => { onValuesChange={v => {
if (v.type) { if (form && v.mode === 'single') {
setWebType(v.type);
if (form) {
const sty = form.getFieldValue('style'); const sty = form.getFieldValue('style');
if (!singleStyleData[sty]) { if (!singleStyleData[sty]) {
form.setFieldsValue([{ name: 'style', value: 'platform' }]); form.setFieldsValue([{ name: 'style', value: 'platform' }]);
} }
} }
}
}} }}
onFinish={values => { onFinish={values => {
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
......
...@@ -19,47 +19,61 @@ const WebConfigPage = props => { ...@@ -19,47 +19,61 @@ const WebConfigPage = props => {
const [curWeb, setCurWeb] = useState(null); // 当前展示的web const [curWeb, setCurWeb] = useState(null); // 当前展示的web
const [configObj, setConfigObj] = useState({}); // 获取当前的web的配置 const [configObj, setConfigObj] = useState({}); // 获取当前的web的配置
const [toEdit, setToEdit] = useState(null); // 编辑展示用的配置 const [toEdit, setToEdit] = useState(null); // 编辑展示用的配置
const [isEdit, setIsEdit] = useState(true);
const hasIntegerate = () => webs.some(w => w.webType === 'integrate'); const hasIntegerate = () => webs.some(w => w.mode === 'integrate');
useEffect(() => { useEffect(() => {
let canceled = false;
getWebModuleTree(userMode || 'super').then(res => { getWebModuleTree(userMode || 'super').then(res => {
const websArr = [ const websArr = [
res.data res.data
.filter(d => d.id === 'Web4IntegrateStation') .filter(d => d.id === 'Web4IntegrateStation')
.map(r => r.children.map(i => ({ ...i, webType: 'integrate' }))), .map(r => r.children),
res.data res.data.filter(d => d.id === 'Web4SingleStation').map(r => r.children),
.filter(d => d.id === 'Web4SingleStation')
.map(r => r.children.map(i => ({ ...i, webType: 'single' }))),
].flat(2); ].flat(2);
if (!canceled) {
setWebs(websArr); setWebs(websArr);
setCurWeb(websArr[0]); setCurWeb(websArr[0]);
setLoading(false); setLoading(false);
}
}); });
return () => {
canceled = true;
};
}, []); }, []);
useEffect(() => { useEffect(() => {
let canceled = false;
if (!curWeb) return; if (!curWeb) return;
const title = curWeb.text; const title = curWeb.text;
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
getWebconfig(curWeb.text).then(res => { getWebconfig(curWeb.text).then(res => {
if (!canceled) {
setConfigObj(res); setConfigObj(res);
if (title === curWeb.text) { if (title === curWeb.text) {
setToEdit(res); setToEdit(res);
} }
}
}); });
// eslint-disable-next-line consistent-return
return () => {
canceled = true;
};
}, [curWeb]); }, [curWeb]);
const renderTabPane = tabPaneItem => ( const renderTabPane = tabPaneItem => (
<TabPane key={tabPaneItem.text} tab={tabPaneItem.text}> <TabPane key={tabPaneItem.text} tab={tabPaneItem.text}>
<> <>
<span <span
className={styles.link}
onClick={() => { onClick={() => {
setToEdit(configObj); setToEdit({ ...configObj });
setConfigVisible(true); setConfigVisible(true);
setIsEdit(true);
}} }}
> >
查看配置 查看/编辑网站配置
</span> </span>
</> </>
</TabPane> </TabPane>
...@@ -69,6 +83,8 @@ const WebConfigPage = props => { ...@@ -69,6 +83,8 @@ const WebConfigPage = props => {
// console.log(targetKey, action); // action: add|remove // console.log(targetKey, action); // action: add|remove
switch (action) { switch (action) {
case 'add': case 'add':
setIsEdit(false);
setToEdit({});
setConfigVisible(true); setConfigVisible(true);
break; break;
case 'remove': case 'remove':
...@@ -92,6 +108,7 @@ const WebConfigPage = props => { ...@@ -92,6 +108,7 @@ const WebConfigPage = props => {
{webs.map(renderTabPane)} {webs.map(renderTabPane)}
</Tabs> </Tabs>
<SiteConfig <SiteConfig
isEdit={isEdit}
visible={configVisible} visible={configVisible}
onClose={onDrawerClose} onClose={onDrawerClose}
config={toEdit} config={toEdit}
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 100%; height: 100%;
.link{
color: #2f54eb;
cursor: pointer;
user-select: none;
border-bottom: 1px solid #2f54eb;
}
.ant-tabs-content-holder>.ant-tabs-content.ant-tabs-content-top{ .ant-tabs-content-holder>.ant-tabs-content.ant-tabs-content-top{
position: absolute; position: absolute;
width: 100%; width: 100%;
......
...@@ -6,7 +6,7 @@ const typeContent = hasIntegerate => { ...@@ -6,7 +6,7 @@ const typeContent = hasIntegerate => {
} }
return [ return [
{ {
value: 'a', value: 'integrate',
children: '集成网站', children: '集成网站',
}, },
]; ];
...@@ -29,6 +29,7 @@ export const menuStyle = { ...@@ -29,6 +29,7 @@ export const menuStyle = {
'banner-big': '标题栏-大', 'banner-big': '标题栏-大',
table: '左侧', table: '左侧',
dock: '底部', dock: '底部',
'banner-left-noShrink': '标题栏-左-不收',
}; };
export const MDILabel = { export const MDILabel = {
MDI: '多标签模式', MDI: '多标签模式',
...@@ -39,23 +40,25 @@ export const notificationTypes = { ...@@ -39,23 +40,25 @@ export const notificationTypes = {
MQTT: 'MQTT消息', MQTT: 'MQTT消息',
}; };
const isIntegerate = (webType, hasIntegerate) => { const isIntegerate = (mode, hasIntegerate) => {
if (typeof webType !== 'undefined') { if (typeof mode !== 'undefined') {
return webType === 'a'; return mode === 'single';
} }
return hasIntegerate; return hasIntegerate;
}; };
export const defaultWebConfigObj = {};
export const getDefaultGetWebconfig = ({ export const getDefaultGetWebconfig = ({
initialValues = {}, initialValues = {},
hasIntegerate, hasIntegerate,
webThemes, webThemes,
onGetThemes, onGetThemes,
webType,
loginPages, loginPages,
onGetLoginPages, onGetLoginPages,
mapConfigs, mapConfigs,
onGetMapConfig, onGetMapConfig,
isEdit,
}) => { }) => {
const config = { const config = {
title: { title: {
...@@ -75,13 +78,14 @@ export const getDefaultGetWebconfig = ({ ...@@ -75,13 +78,14 @@ export const getDefaultGetWebconfig = ({
formType: ITEM_TYPE.INPUT, formType: ITEM_TYPE.INPUT,
allowClear: true, allowClear: true,
}, },
type: { mode: {
label: '网站类型', label: '网站类型',
formType: ITEM_TYPE.SINGLE_RADIO, formType: ITEM_TYPE.SINGLE_RADIO,
initialValue: 'b', initialValue: 'single',
disabled: isEdit,
options: [ options: [
{ {
value: 'b', value: 'single',
children: '一般网站', children: '一般网站',
}, },
].concat(typeContent(hasIntegerate)), ].concat(typeContent(hasIntegerate)),
...@@ -106,7 +110,7 @@ export const getDefaultGetWebconfig = ({ ...@@ -106,7 +110,7 @@ export const getDefaultGetWebconfig = ({
}, },
], ],
}, },
bannerlogo: { bannerLogo: {
label: '标题logo', label: '标题logo',
formType: ITEM_TYPE.IMGSHOP, formType: ITEM_TYPE.IMGSHOP,
rules: [ rules: [
...@@ -119,6 +123,7 @@ export const getDefaultGetWebconfig = ({ ...@@ -119,6 +123,7 @@ export const getDefaultGetWebconfig = ({
client: { client: {
label: '虚拟目录', label: '虚拟目录',
formType: ITEM_TYPE.INPUT, formType: ITEM_TYPE.INPUT,
disabled: isEdit,
allowClear: true, allowClear: true,
size: 'small', size: 'small',
rules: [ rules: [
...@@ -169,7 +174,7 @@ export const getDefaultGetWebconfig = ({ ...@@ -169,7 +174,7 @@ export const getDefaultGetWebconfig = ({
formType: ITEM_TYPE.SELECT, formType: ITEM_TYPE.SELECT,
initialValue: '', initialValue: '',
options: Object.keys( options: Object.keys(
isIntegerate(webType, hasIntegerate) isIntegerate(initialValues.mode, hasIntegerate)
? integrateStyleData ? integrateStyleData
: singleStyleData, : singleStyleData,
).map(k => ({ ).map(k => ({
...@@ -223,6 +228,7 @@ export const getDefaultGetWebconfig = ({ ...@@ -223,6 +228,7 @@ export const getDefaultGetWebconfig = ({
hideMap: { hideMap: {
label: '按需加载地图', label: '按需加载地图',
formType: ITEM_TYPE.SINGLE_RADIO, formType: ITEM_TYPE.SINGLE_RADIO,
optionType: 'button',
options: [ options: [
{ {
value: true, value: true,
...@@ -255,9 +261,8 @@ export const getDefaultGetWebconfig = ({ ...@@ -255,9 +261,8 @@ export const getDefaultGetWebconfig = ({
}; };
if (initialValues) { if (initialValues) {
Object.keys(config).forEach(k => { Object.keys(config).forEach(k => {
if (initialValues[k]) { config[k].initialValue =
config[k].initialValue = initialValues[k]; typeof initialValues[k] !== 'undefined' ? initialValues[k] : '';
}
}); });
} }
return config; return config;
......
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