Commit 0f897324 authored by 张烨's avatar 张烨

feat: add and delete website

parent 0e528f06
...@@ -36,8 +36,8 @@ const BaseFormItem = itemOption => { ...@@ -36,8 +36,8 @@ const BaseFormItem = itemOption => {
case ITEM_TYPE.SELECT: case ITEM_TYPE.SELECT:
return ( return (
<Select {...rest}> <Select {...rest}>
{options.map(o => ( {options.map((o, i) => (
<Select.Option {...o} /> <Select.Option key={`item_${i}`} {...o} />
))} ))}
</Select> </Select>
); );
...@@ -47,16 +47,16 @@ const BaseFormItem = itemOption => { ...@@ -47,16 +47,16 @@ const BaseFormItem = itemOption => {
// eslint-disable-next-line no-case-declarations // eslint-disable-next-line no-case-declarations
return ( return (
<Radio.Group {...rest}> <Radio.Group {...rest}>
{options.map(o => ( {options.map((o, i) => (
<Radio {...o} /> <Radio {...o} key={`item_${i}`} />
))} ))}
</Radio.Group> </Radio.Group>
); );
case ITEM_TYPE.CHECK_BOX: case ITEM_TYPE.CHECK_BOX:
return ( return (
<Checkbox.Group {...rest}> <Checkbox.Group {...rest}>
{options.map(o => ( {options.map((o, i) => (
<Checkbox {...o} /> <Checkbox key={`item_${i}`} {...o} />
))} ))}
</Checkbox.Group> </Checkbox.Group>
); );
......
...@@ -37,7 +37,7 @@ export default props => { ...@@ -37,7 +37,7 @@ export default props => {
}); });
return; return;
} }
values.alarmWays = values.alarmWays.join(','); values.alarmWays = values.alarmWays?.join(',') || '';
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
onOk && onOk(values); onOk && onOk(values);
}} }}
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
getWebThemes, getWebThemes,
} from '@/services/webConfig/api'; } from '@/services/webConfig/api';
import { Row, Col } from 'antd'; import { Row, Col } from 'antd';
import { getDefaultGetWebconfig, singleStyleData } from '../utils'; import { getDefaultGetWebconfig, singleStyleData, webMode } from '../utils';
const WebConfigForm = props => { const WebConfigForm = props => {
const { const {
...@@ -106,7 +106,7 @@ const WebConfigForm = props => { ...@@ -106,7 +106,7 @@ const WebConfigForm = props => {
labelCol={{ span: 6 }} labelCol={{ span: 6 }}
wrapperCol={{ span: 14 }} wrapperCol={{ span: 14 }}
onValuesChange={v => { onValuesChange={v => {
if (form && v.mode === 'single') { if (form && v.mode === webMode.single) {
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' }]);
......
...@@ -6,10 +6,14 @@ import { ...@@ -6,10 +6,14 @@ import {
getWebconfig, getWebconfig,
postEditWebConfig, postEditWebConfig,
postAddWebSite, postAddWebSite,
deleteWebsite,
} from '@/services/webConfig/api'; } from '@/services/webConfig/api';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import Modal from 'antd/lib/modal/Modal';
import styles from './index.less'; import styles from './index.less';
import SiteConfig from './components/siteConfigDrawer'; import SiteConfig from './components/siteConfigDrawer';
import { appConnector } from '@/containers/App/store'; import { appConnector } from '@/containers/App/store';
import { defaultWebConfigObj, webMode } from './utils';
const { TabPane } = Tabs; const { TabPane } = Tabs;
const WebConfigPage = props => { const WebConfigPage = props => {
...@@ -23,7 +27,8 @@ const WebConfigPage = props => { ...@@ -23,7 +27,8 @@ const WebConfigPage = props => {
const [isEdit, setIsEdit] = useState(true); const [isEdit, setIsEdit] = useState(true);
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
const hasIntegerate = () => webs.some(w => w.mode === 'integrate'); const hasIntegerate = () =>
webs.some(w => w.id.startsWith(webMode.integration));
useEffect(() => { useEffect(() => {
let canceled = { cancel: false }; let canceled = { cancel: false };
...@@ -81,32 +86,67 @@ const WebConfigPage = props => { ...@@ -81,32 +86,67 @@ const WebConfigPage = props => {
}); });
}; };
const renderTabPane = tabPaneItem => ( const handleDeleteWeb = (webToOperate, closeModal) => {
<TabPane key={tabPaneItem.text} tab={tabPaneItem.text}> // eslint-disable-next-line prefer-destructuring
<> const client = webToOperate?.id?.split(
<span webToOperate.id.startsWith(webMode.single)
className={styles.link} ? webMode.single
onClick={() => { : webMode.integration,
setToEdit({ ...configObj }); )[1];
setConfigVisible(true); if (client) {
setIsEdit(true); deleteWebsite(client)
}} .then(res => {
> if (res.success) {
查看/编辑网站配置 notification.success({
</span> message: `删除网站${webToOperate.text}成功!`,
</> duration: 3,
</TabPane> });
); updateModuleTree(userMode || 'super');
} else {
notification.error({
message: res.message || `删除网站 ${webToOperate.text} 失败`,
});
}
// eslint-disable-next-line no-unused-expressions
closeModal && closeModal();
})
.catch(err => {
// eslint-disable-next-line no-console
console.error(err);
notification.error({ message: '删除网站失败!', duration: 5 });
// eslint-disable-next-line no-unused-expressions
closeModal && closeModal();
});
}
};
const onEdit = (targetKey, action) => { const onEdit = (targetKey, action) => {
// console.log(targetKey, action); // action: add|remove const webToOperate = webs.find(w => w.id === targetKey);
switch (action) { switch (action) {
case 'add': case 'add':
setIsEdit(false); setIsEdit(false);
setToEdit({}); setToEdit(defaultWebConfigObj);
setConfigVisible(true); setConfigVisible(true);
break; break;
case 'remove': case 'remove':
Modal.confirm({
title: '删除网站',
icon: <ExclamationCircleOutlined />,
content: (
<span>
删除网站{' '}
<span style={{ fontWeight: 800, color: '#1890ff' }}>
{webToOperate.text}
</span>{' '}
后将无法恢复, 确认删除?
</span>
),
okText: '确认',
cancelText: '取消',
onOk: closeModal => {
handleDeleteWeb(webToOperate, closeModal);
},
});
break; break;
default: default:
} }
...@@ -117,7 +157,7 @@ const WebConfigPage = props => { ...@@ -117,7 +157,7 @@ const WebConfigPage = props => {
}; };
const handleTabChange = v => { const handleTabChange = v => {
setCurWeb(webs.find(w => w.text === v)); setCurWeb(webs.find(w => w.id === v));
}; };
const handleSubmit = values => { const handleSubmit = values => {
...@@ -156,6 +196,23 @@ const WebConfigPage = props => { ...@@ -156,6 +196,23 @@ const WebConfigPage = props => {
}); });
}; };
const renderTabPane = tabPaneItem => (
<TabPane key={tabPaneItem.id} tab={tabPaneItem.text}>
<>
<span
className={styles.link}
onClick={() => {
setToEdit({ ...configObj });
setConfigVisible(true);
setIsEdit(true);
}}
>
查看/编辑网站配置
</span>
</>
</TabPane>
);
return ( return (
<PageContainer> <PageContainer>
<div className={styles.webConfigContainer}> <div className={styles.webConfigContainer}>
......
import { ITEM_TYPE } from '@/components/BaseForm'; import { ITEM_TYPE } from '@/components/BaseForm';
export const webMode = {
single: 'single',
integration: 'integration',
};
const typeContent = hasIntegerate => { const typeContent = hasIntegerate => {
if (hasIntegerate) { if (hasIntegerate) {
return []; return [];
} }
return [ return [
{ {
value: 'integrate', value: webMode.integration,
children: '集成网站', children: '集成网站',
}, },
]; ];
...@@ -47,7 +51,12 @@ const isIntegerate = (mode, hasIntegerate) => { ...@@ -47,7 +51,12 @@ const isIntegerate = (mode, hasIntegerate) => {
return hasIntegerate; return hasIntegerate;
}; };
export const defaultWebConfigObj = {}; export const defaultWebConfigObj = {
mode: webMode.single,
menu: 'banner-left',
mdi: 'MDI',
hideMap: true,
};
export const getDefaultGetWebconfig = ({ export const getDefaultGetWebconfig = ({
initialValues = {}, initialValues = {},
...@@ -81,11 +90,11 @@ export const getDefaultGetWebconfig = ({ ...@@ -81,11 +90,11 @@ export const getDefaultGetWebconfig = ({
mode: { mode: {
label: '网站类型', label: '网站类型',
formType: ITEM_TYPE.SINGLE_RADIO, formType: ITEM_TYPE.SINGLE_RADIO,
initialValue: 'single', initialValue: webMode.single,
disabled: isEdit, disabled: isEdit,
options: [ options: [
{ {
value: 'single', value: webMode.single,
children: '一般网站', children: '一般网站',
}, },
].concat(typeContent(hasIntegerate)), ].concat(typeContent(hasIntegerate)),
......
...@@ -59,3 +59,6 @@ export const postEditWebConfig = (config, isAdd = false) => ...@@ -59,3 +59,6 @@ export const postEditWebConfig = (config, isAdd = false) =>
); );
export const postAddWebSite = config => postEditWebConfig(config, true); export const postAddWebSite = config => postEditWebConfig(config, true);
export const deleteWebsite = client =>
get(`${CITY_SERVICE}/OMS.svc/W4_DeleteWebsite?_version=9999`, { client });
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