Commit df3e146b authored by Bill's avatar Bill

fix: v1 资讯bug

parent 0d80ff03
...@@ -29,7 +29,7 @@ import SmilingFace from './components/SmilingFace'; ...@@ -29,7 +29,7 @@ import SmilingFace from './components/SmilingFace';
import AntUpload from './components/AntUpload'; import AntUpload from './components/AntUpload';
import './index.less' import './index.less'
import { currentStateType, getCurrentState } from './utils/keepAlive'; import { currentStateType, getCurrentState } from './utils/keepAlive';
import { useRouteMatch } from 'umi';
export interface NiceFormProps extends IAntdSchemaFormProps {} export interface NiceFormProps extends IAntdSchemaFormProps {}
const SchemaFormButtonGroup = createVirtualBox('schemaButtonGroup', FormButtonGroup) const SchemaFormButtonGroup = createVirtualBox('schemaButtonGroup', FormButtonGroup)
...@@ -102,13 +102,21 @@ export const componentExport = { ...@@ -102,13 +102,21 @@ export const componentExport = {
} }
const NiceForm: React.FC<NiceFormProps> = props => { const NiceForm: React.FC<NiceFormProps> = props => {
const { children, components, ...reset } = props; const { children, components, ...reset } = props;
const match = useRouteMatch();
const defineComponents = Object.assign(componentExport, components); const defineComponents = Object.assign(componentExport, components);
useEffect(() => { useEffect(() => {
let paginationInfo: currentStateType = getCurrentState(); let paginationInfo: currentStateType = getCurrentState();
if(paginationInfo?.queryParams) {
// @ts-ignore // 一般 列表检索传入的 controlRender 的 NiceForm 是没有 value 或者 initialValues 的
// value 或者 initialValues 的,表单页有
if (
paginationInfo
&& match.path === paginationInfo.pathname
&& !('value' in reset)
&& !('initialValues' in reset)
) {
//@ts-ignore
reset.actions.setFormState( reset.actions.setFormState(
state => (state.values = paginationInfo.queryParams), state => (state.values = paginationInfo.queryParams),
); );
......
...@@ -5,6 +5,7 @@ import { UploadFile, UploadChangeParam } from 'antd/lib/upload/interface'; ...@@ -5,6 +5,7 @@ import { UploadFile, UploadChangeParam } from 'antd/lib/upload/interface';
import { UPLOAD_TYPE } from '@/constants/index'; import { UPLOAD_TYPE } from '@/constants/index';
import cx from 'classnames' import cx from 'classnames'
import styles from './index.less' import styles from './index.less'
import { getAuth } from '@/utils/auth';
interface UploadImagePorpsType { interface UploadImagePorpsType {
imgUrl?: string; imgUrl?: string;
...@@ -18,7 +19,8 @@ interface UploadImagePorpsType { ...@@ -18,7 +19,8 @@ interface UploadImagePorpsType {
} }
const UploadImage: React.FC<UploadImagePorpsType> = forwardRef((props, ref) => { const UploadImage: React.FC<UploadImagePorpsType> = forwardRef((props, ref) => {
const { children, imgUrl, onChange, showDesc = true, size = "386x256", disabled = false, large = false, fileMaxSize = 200, listType = "picture-card" } = props const { children, imgUrl, onChange, showDesc = true, size = "386x256", disabled = false, large = false, fileMaxSize = 200, listType = "picture-card" } = props;
const auth = getAuth();
const [loading, setLoading] = useState<boolean>(false) const [loading, setLoading] = useState<boolean>(false)
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const beforeUpload = (file: UploadFile) => { const beforeUpload = (file: UploadFile) => {
...@@ -36,7 +38,9 @@ const UploadImage: React.FC<UploadImagePorpsType> = forwardRef((props, ref) => { ...@@ -36,7 +38,9 @@ const UploadImage: React.FC<UploadImagePorpsType> = forwardRef((props, ref) => {
const uploadProps = { const uploadProps = {
name: 'file', name: 'file',
action: '/api/file/file/upload', action: '/api/file/file/upload',
headers: {}, headers: {
token: auth?.token,
},
data: { data: {
fileType: UPLOAD_TYPE fileType: UPLOAD_TYPE
}, },
......
...@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; ...@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { FilterTable, SchemaFlexRowLayout, SchemaFlexColumnLayout } from '../components/FilterTable'; import { FilterTable, SchemaFlexRowLayout, SchemaFlexColumnLayout } from '../components/FilterTable';
import { Card, Input, Button, Table, Dropdown, Menu, Select, Space, Popconfirm, Modal } from 'antd'; import { Card, Input, Button, Table, Dropdown, Menu, Select, Space, Popconfirm, Modal } from 'antd';
import { createVirtualBox, createFormActions, FormEffectHooks, createEffectHook } from '@formily/antd'; import { createVirtualBox, createFormActions, FormEffectHooks, createEffectHook } from '@formily/antd';
import { history, Link } from 'umi'; import { history, Link } from 'umi';
import { DownOutlined, DeleteOutlined, UpOutlined } from '@ant-design/icons'; import { DownOutlined, DeleteOutlined, UpOutlined } from '@ant-design/icons';
import { timeRange } from '@/utils/index'; import { timeRange } from '@/utils/index';
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
...@@ -41,14 +41,14 @@ const Announcements = () => { ...@@ -41,14 +41,14 @@ const Announcements = () => {
state.visible = false; state.visible = false;
}) })
}) })
merge( merge(
onFieldValueChange$('columnType'), onFieldValueChange$('columnType'),
onFieldValueChange$('status'), onFieldValueChange$('status'),
onFieldValueChange$('time'), onFieldValueChange$('time'),
).subscribe( ).subscribe(
fieldState => { fieldState => {
if(fieldState.active && fieldState.value != null) { if(fieldState.active && fieldState.value != null) {
handleSearch({}) handleSearch({})
} }
...@@ -58,7 +58,7 @@ const Announcements = () => { ...@@ -58,7 +58,7 @@ const Announcements = () => {
onFieldValueChange$('pagination').subscribe((state) => { onFieldValueChange$('pagination').subscribe((state) => {
handleSearch({...state.value}) handleSearch({...state.value})
}) })
} }
const handleSearch = async (params) => { const handleSearch = async (params) => {
...@@ -71,9 +71,9 @@ const Announcements = () => { ...@@ -71,9 +71,9 @@ const Announcements = () => {
title: title || '', title: title || '',
columnType: columnType != 0 ? columnType : '', columnType: columnType != 0 ? columnType : '',
status: status != 0 ? status : '', status: status != 0 ? status : '',
startTime: st && st * 1000, startTime: st && st,
endTime: et && et * 1000, endTime: et && et,
current: 1, current: 1,
pageSize: 10, pageSize: 10,
...params ...params
} }
...@@ -91,7 +91,7 @@ const Announcements = () => { ...@@ -91,7 +91,7 @@ const Announcements = () => {
}) })
} }
}) })
} }
// 修改状态 // 修改状态
...@@ -115,7 +115,7 @@ const Announcements = () => { ...@@ -115,7 +115,7 @@ const Announcements = () => {
return ( return (
<Card> <Card>
<FilterTable <FilterTable
schema={advertisementSchema} schema={advertisementSchema}
components={{ components={{
CustomSearch, CustomSearch,
...@@ -155,7 +155,7 @@ const Announcements = () => { ...@@ -155,7 +155,7 @@ const Announcements = () => {
</span> </span>
) )
}, },
toggleFilters: () => { toggleFilters: () => {
actions.setFieldState('FILTERS', state => { actions.setFieldState('FILTERS', state => {
const visible = !state.visible; const visible = !state.visible;
...@@ -182,7 +182,7 @@ const Announcements = () => { ...@@ -182,7 +182,7 @@ const Announcements = () => {
<a> <a>
删除 删除
</a> </a>
</Menu.Item> </Menu.Item>
</Menu> </Menu>
) )
return ( return (
...@@ -198,7 +198,7 @@ const Announcements = () => { ...@@ -198,7 +198,7 @@ const Announcements = () => {
</Popconfirm> </Popconfirm>
{/* // 只有待上架, 已下架架才有 修改和删除 */} {/* // 只有待上架, 已下架架才有 修改和删除 */}
{ {
canModify.includes(record.status) canModify.includes(record.status)
? ( ? (
<Dropdown overlay={menu}> <Dropdown overlay={menu}>
<a> <a>
...@@ -219,4 +219,4 @@ const Announcements = () => { ...@@ -219,4 +219,4 @@ const Announcements = () => {
) )
} }
export default Announcements; export default Announcements;
\ No newline at end of file
...@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; ...@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { FilterTable, SchemaFlexRowLayout, SchemaFlexColumnLayout } from '../components/FilterTable'; import { FilterTable, SchemaFlexRowLayout, SchemaFlexColumnLayout } from '../components/FilterTable';
import { Card, Input, Button, Table, Dropdown, Menu, Select, Space, Modal, Popconfirm } from 'antd'; import { Card, Input, Button, Table, Dropdown, Menu, Select, Space, Modal, Popconfirm } from 'antd';
import { createVirtualBox, createFormActions, FormEffectHooks, createEffectHook } from '@formily/antd'; import { createVirtualBox, createFormActions, FormEffectHooks, createEffectHook } from '@formily/antd';
import { history, Link } from 'umi'; import { history, Link } from 'umi';
import { DownOutlined, DeleteOutlined, UpOutlined } from '@ant-design/icons'; import { DownOutlined, DeleteOutlined, UpOutlined } from '@ant-design/icons';
import { timeRange } from '@/utils/index'; import { timeRange } from '@/utils/index';
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
...@@ -11,6 +11,8 @@ import TablePagination from '../components/TablePagination'; ...@@ -11,6 +11,8 @@ import TablePagination from '../components/TablePagination';
import { getTableDataSource, setFormStatus } from '../utils/utils' import { getTableDataSource, setFormStatus } from '../utils/utils'
import { merge } from 'rxjs'; import { merge } from 'rxjs';
import CustomSearch from '../components/CustomSearch'; import CustomSearch from '../components/CustomSearch';
import { useRowSelectionTable } from '@/hooks/useRowSelectionTable';
const { onFormInit$, onFieldValueChange$ } = FormEffectHooks const { onFormInit$, onFieldValueChange$ } = FormEffectHooks
const { Search } = Input; const { Search } = Input;
...@@ -55,6 +57,8 @@ const getData = async (params: any) => { ...@@ -55,6 +57,8 @@ const getData = async (params: any) => {
const Infomation = () => { const Infomation = () => {
const columns = useGetColumns(); const columns = useGetColumns();
const [selectedRow, setSelectedRow] = useState<any[]>([]); const [selectedRow, setSelectedRow] = useState<any[]>([]);
// const [roleSelection, roleSelectCtl] = useRowSelectionTable()
// const refkeys = useRef([])
useEffect(() => { useEffect(() => {
const params = { const params = {
...@@ -73,14 +77,14 @@ const Infomation = () => { ...@@ -73,14 +77,14 @@ const Infomation = () => {
merge( merge(
onFieldValueChange$('columns'), onFieldValueChange$('columns'),
onFieldValueChange$('status'), onFieldValueChange$('status'),
onFieldValueChange$('time') onFieldValueChange$('time')
).subscribe((state) => { ).subscribe((state) => {
if(state.active && state.value != null) { if(state.active && state.value != null) {
handleSearch({}) handleSearch({})
} }
}) })
onFieldValueChange$('pagination').subscribe((state) => { onFieldValueChange$('pagination').subscribe((state) => {
handleSearch({...state.value}) handleSearch({...state.value})
}) })
...@@ -93,12 +97,12 @@ const Infomation = () => { ...@@ -93,12 +97,12 @@ const Infomation = () => {
const time = actions.getFieldValue('time'); const time = actions.getFieldValue('time');
const { st, et } = timeRange(time); const { st, et } = timeRange(time);
const postData = { const postData = {
title: title, title: title,
status: status != 0 ? status : '', status: status != 0 ? status : '',
columnId: columnId, columnId: columnId,
startTime: st && st * 1000, startTime: st && st,
endTime: et && et * 1000, endTime: et && et,
current: 1, current: 1,
pageSize: 10, pageSize: 10,
...params, ...params,
} }
...@@ -114,12 +118,12 @@ const Infomation = () => { ...@@ -114,12 +118,12 @@ const Infomation = () => {
handleSearch({...paginationValue}) handleSearch({...paginationValue})
}); });
} }
// 批量删除 // 批量删除
const batchDelete = () => { const batchDelete = () => {
const rows = selectedRow.map((item) => item.id); const rows = selectedRow
handleBatch(rows, 1); handleBatch(rows, 1);
} }
// type 1-批量删除 2-批量上架 3-批量下架 // type 1-批量删除 2-批量上架 3-批量下架
const handleBatch = (row, type) => { const handleBatch = (row, type) => {
...@@ -153,12 +157,12 @@ const Infomation = () => { ...@@ -153,12 +157,12 @@ const Infomation = () => {
return ( return (
<Card> <Card>
<FilterTable <FilterTable
schema={infomationSchema} schema={infomationSchema}
components={{ components={{
CustomSearch, CustomSearch,
// SchemaFlexRowLayout, // SchemaFlexRowLayout,
// SchemaDropDown, // SchemaDropDown,
SchemaFlexColumnLayout, SchemaFlexColumnLayout,
Select, Select,
Table, Table,
...@@ -196,7 +200,7 @@ const Infomation = () => { ...@@ -196,7 +200,7 @@ const Infomation = () => {
<a> <a>
删除 删除
</a> </a>
</Menu.Item> </Menu.Item>
</Menu> </Menu>
) )
return ( return (
...@@ -210,7 +214,7 @@ const Infomation = () => { ...@@ -210,7 +214,7 @@ const Infomation = () => {
> >
<a href="#">{status[record.status]}</a> <a href="#">{status[record.status]}</a>
</Popconfirm> </Popconfirm>
{ {
CAN_MODIFY.includes(record.status) CAN_MODIFY.includes(record.status)
? <Dropdown overlay={menu}> ? <Dropdown overlay={menu}>
...@@ -220,19 +224,19 @@ const Infomation = () => { ...@@ -220,19 +224,19 @@ const Infomation = () => {
</Dropdown> </Dropdown>
: null : null
} }
</Space> </Space>
) )
}, },
batchGrounding: () => { batchGrounding: () => {
console.log("批量上架"); console.log("批量上架");
const rows = selectedRow.map((item) => item.id); const rows = selectedRow
handleBatch(rows, 2); handleBatch(rows, 2);
}, },
undercarriage: () => { undercarriage: () => {
console.log("批量下架") console.log("批量下架")
const rows = selectedRow.map((item) => item.id); const rows = selectedRow
handleBatch(rows, 3); handleBatch(rows, 3);
}, },
menu: () => { menu: () => {
...@@ -256,18 +260,27 @@ const Infomation = () => { ...@@ -256,18 +260,27 @@ const Infomation = () => {
</span> </span>
) )
}, },
// rowSelection: roleSelection,
rowSelection: { rowSelection: {
onSelect: (record, selected, selectedRows) => { onSelect: (record, selected, selectedRows) => {
console.log(record, selected, selectedRows); const selectedRowsKeys = selectedRows.filter((_item) => _item).map((item) => item.id);
setSelectedRow(selectedRows); let keys = Array.from(new Set([...selectedRowsKeys, ...selectedRow]))
if(!selected) {
keys = keys.filter((_item) => _item !== record.id);
}
setSelectedRow(keys)
}, },
onSelectAll: (record, selected, changeRows) => { onSelectAll: (selected, checkedRows, changeRows) => {
// const res = selectedRow.concat(selectedRows); const changeRowKey = changeRows.filter((_item) => _item).map((item) => item.id);
console.log(selectedRow); let keys = Array.from(new Set([...changeRowKey, ...selectedRow]))
const res = selected.filter((item) => item && item.id); if(selected) {
setSelectedRow(res); setSelectedRow(keys)
} else {
} const removeKeys = keys.filter((_item) => !changeRowKey.includes(_item));
setSelectedRow(removeKeys)
}
},
selectedRowKeys: selectedRow
}, },
toggleFilters: () => { toggleFilters: () => {
actions.setFieldState('FILTERS', state => { actions.setFieldState('FILTERS', state => {
...@@ -283,7 +296,7 @@ const Infomation = () => { ...@@ -283,7 +296,7 @@ const Infomation = () => {
) )
}) })
}); });
}, },
}} }}
effects={infomationEffects()} effects={infomationEffects()}
...@@ -292,4 +305,4 @@ const Infomation = () => { ...@@ -292,4 +305,4 @@ const Infomation = () => {
) )
} }
export default Infomation; export default Infomation;
\ No newline at end of file
import React, { useEffect, useState } from 'react';
import { FilterTable, SchemaFlexRowLayout, SchemaFlexColumnLayout } from '../components/FilterTable';
import { Card, Input, Button, Table, Dropdown, Menu, Select, Space, Modal, Popconfirm } from 'antd';
import { createVirtualBox, createFormActions, FormEffectHooks, createEffectHook } from '@formily/antd';
import { history, Link } from 'umi';
import { DownOutlined, DeleteOutlined, UpOutlined } from '@ant-design/icons';
import { timeRange } from '@/utils/index';
import { PublicApi } from '@/services/api';
import { infomationSchema } from './schema';
import TablePagination from '../components/TablePagination';
import { getTableDataSource, setFormStatus } from '../utils/utils'
import { merge } from 'rxjs';
import CustomSearch from '../components/CustomSearch';
const { onFormInit$, onFieldValueChange$ } = FormEffectHooks
const { Search } = Input;
const SchemaButton = createVirtualBox('button', Button);
const SchemaTable = createVirtualBox('SchemaTable', Table);
const SchemaDropDown = createVirtualBox('SchemaDropDown', Dropdown.Button);
const actions = createFormActions();
const tagColorStyle = {
"1": {color: '#606266', background: '#F4F5F7'},
"2": {color: '#00B37A', background: '#EBF7F2'},
"3": {color: '#E63F3B', background: '#FFEBE6'},
}
interface optionsType {
label: string,
value: string | number
}
const useGetColumns = () => {
const [state, setState] = useState<optionsType[]>([]);
useEffect(() => {
async function getAllColumns() {
const res = await PublicApi.getManageContentColumnAll();
console.log(res);
const options = res.data.map((item) => ({label: item.name, value: item.id}));
// setTableStatus("column", "options", options);
setState(options)
}
getAllColumns();
}, [])
return state;
}
const getData = async (params: any) => {
const res = await PublicApi.getManageContentInformationPage(params);
return res.data
}
const Infomation = () => {
const columns = useGetColumns();
const [selectedRow, setSelectedRow] = useState<any[]>([]);
useEffect(() => {
const params = {
current: 1,
pageSize: 10
}
getTableDataSource(actions, params, getData);
}, [])
const infomationEffects = () => () => {
onFormInit$().subscribe(() => {
actions.setFieldState('FILTERS', state => {
state.visible = false;
})
})
merge(
onFieldValueChange$('columns'),
onFieldValueChange$('status'),
onFieldValueChange$('time')
).subscribe((state) => {
if(state.active && state.value != null) {
handleSearch({})
}
})
onFieldValueChange$('pagination').subscribe((state) => {
handleSearch({...state.value})
})
}
const handleSearch = async (params) => {
const title = actions.getFieldValue('search');
const columnId = actions.getFieldValue("columns") ; // 栏目
const status = actions.getFieldValue('status'); // 状态
const time = actions.getFieldValue('time');
const { st, et } = timeRange(time);
const postData = {
title: title,
status: status != 0 ? status : '',
columnId: columnId,
startTime: st && st * 1000,
endTime: et && et * 1000,
current: 1,
pageSize: 10,
...params,
}
getTableDataSource(actions, postData, getData);
}
// 修改状态
const handleUpdateState = (id, status) => {
// 该方法是上下架 所以 enableStatus 无用,随意传
PublicApi.postManageContentInformationUpdateStatus({id: id, shelfStatus: status, enableStatus: 0})
.then((data) => {
const paginationValue = actions.getFieldValue('pagination');
handleSearch({...paginationValue})
});
}
// 批量删除
const batchDelete = () => {
const rows = selectedRow.map((item) => item.id);
handleBatch(rows, 1);
}
// type 1-批量删除 2-批量上架 3-批量下架
const handleBatch = (row, type) => {
PublicApi.postManageContentInformationBatch({ids: row, type: type})
.then((data) => {
const paginationValue = actions.getFieldValue('pagination');
handleSearch({...paginationValue})
})
}
const handleDelete = (id) => {
Modal.confirm({
title: '确定要执行这个操作?',
onOk: () => {
PublicApi.postManageContentInformationDelete({id: id})
.then((data) => {
const paginationValue = actions.getFieldValue('pagination');
handleSearch({...paginationValue})
})
}
})
}
// 重设页码
const resetPagination = (params) => {
const paginationValue = actions.getFieldValue('pagination');
actions.setFieldValue('pagination', {
...paginationValue,
...params
})
}
return (
<Card>
<FilterTable
schema={infomationSchema}
components={{
CustomSearch,
// SchemaFlexRowLayout,
// SchemaDropDown,
SchemaFlexColumnLayout,
Select,
Table,
TablePagination
}}
actions={actions}
expressionScope={{
goToCreate: () => {
history.push(`/content/infomations/add`)
},
reset: () => {
actions.setFieldValue('search');
actions.setFieldValue("columns") ; // 栏目
actions.setFieldValue('status'); // 状态
actions.setFieldValue('time');
resetPagination({current: 1})
handleSearch({name: null, current: 1})
},
search: (value) => {
resetPagination({current: 1})
handleSearch({name: value, current: 1 });
},
renderOperation: (val, record) => {
const status = ["", "上架", "下架", "上架"];
const CAN_MODIFY = [1, 3];
// 只有待上架, 下架才有删除
const menu = (
<Menu>
<Menu.Item>
<Link to={`/content/infomations/detail?id=${record.id}`}>
编辑
</Link>
</Menu.Item>
<Menu.Item onClick={() => handleDelete(record.id)}>
<a>
删除
</a>
</Menu.Item>
</Menu>
)
return (
<Space>
{/* 这里反向操作, 上架的对应的是下架, 待上架,下架对应的是上架 */}
<Popconfirm
title="确定要执行这个操作吗"
onConfirm={() => handleUpdateState(record.id, status[record.status] == '上架' ? 2 : 3)}
okText="是"
cancelText="否"
>
<a href="#">{status[record.status]}</a>
</Popconfirm>
{
CAN_MODIFY.includes(record.status)
? <Dropdown overlay={menu}>
<a>
更多 <DownOutlined />
</a>
</Dropdown>
: null
}
</Space>
)
},
batchGrounding: () => {
console.log("批量上架");
const rows = selectedRow.map((item) => item.id);
handleBatch(rows, 2);
},
undercarriage: () => {
console.log("批量下架")
const rows = selectedRow.map((item) => item.id);
handleBatch(rows, 3);
},
menu: () => {
return (
<Menu onClick={batchDelete}>
<Menu.Item key="1" icon={<DeleteOutlined />}>
批量删除
</Menu.Item>
</Menu>
);
},
renderStatus: (text, record) => {
const STATUSMAP = {
"1": "待上架",
"2": "已上架",
"3": "已下架"
}
return (
<span style={{...tagColorStyle[record.status], padding: '3px 5px'}}>
{STATUSMAP[record.status]}
</span>
)
},
rowSelection: {
onSelect: (record, selected, selectedRows) => {
console.log(record, selected, selectedRows);
setSelectedRow(selectedRows);
},
onSelectAll: (record, selected, changeRows) => {
// const res = selectedRow.concat(selectedRows);
console.log(selectedRow);
const res = selected.filter((item) => item && item.id);
setSelectedRow(res);
}
},
toggleFilters: () => {
actions.setFieldState('FILTERS', state => {
const visible = !state.visible;
state.visible = visible;
if(visible) {
setFormStatus(actions, 'columns', "options", columns);
}
actions.setFieldState('HIGHT_FILTER_BTN', (state) => {
//@ts-ignore
state.props['x-component-props'].children = (
<div>高级搜索 {visible ? <UpOutlined /> : <DownOutlined /> }</div>
)
})
});
},
}}
effects={infomationEffects()}
/>
</Card>
)
}
export default Infomation;
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