Commit df3e146b authored by Bill's avatar Bill

fix: v1 资讯bug

parent 0d80ff03
......@@ -29,7 +29,7 @@ import SmilingFace from './components/SmilingFace';
import AntUpload from './components/AntUpload';
import './index.less'
import { currentStateType, getCurrentState } from './utils/keepAlive';
import { useRouteMatch } from 'umi';
export interface NiceFormProps extends IAntdSchemaFormProps {}
const SchemaFormButtonGroup = createVirtualBox('schemaButtonGroup', FormButtonGroup)
......@@ -102,13 +102,21 @@ export const componentExport = {
}
const NiceForm: React.FC<NiceFormProps> = props => {
const { children, components, ...reset } = props;
const match = useRouteMatch();
const defineComponents = Object.assign(componentExport, components);
useEffect(() => {
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(
state => (state.values = paginationInfo.queryParams),
);
......
......@@ -5,6 +5,7 @@ import { UploadFile, UploadChangeParam } from 'antd/lib/upload/interface';
import { UPLOAD_TYPE } from '@/constants/index';
import cx from 'classnames'
import styles from './index.less'
import { getAuth } from '@/utils/auth';
interface UploadImagePorpsType {
imgUrl?: string;
......@@ -18,7 +19,8 @@ interface UploadImagePorpsType {
}
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 [visible, setVisible] = useState(false);
const beforeUpload = (file: UploadFile) => {
......@@ -36,7 +38,9 @@ const UploadImage: React.FC<UploadImagePorpsType> = forwardRef((props, ref) => {
const uploadProps = {
name: 'file',
action: '/api/file/file/upload',
headers: {},
headers: {
token: auth?.token,
},
data: {
fileType: UPLOAD_TYPE
},
......
......@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { FilterTable, SchemaFlexRowLayout, SchemaFlexColumnLayout } from '../components/FilterTable';
import { Card, Input, Button, Table, Dropdown, Menu, Select, Space, Popconfirm, Modal } from '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 { timeRange } from '@/utils/index';
import { PublicApi } from '@/services/api';
......@@ -41,14 +41,14 @@ const Announcements = () => {
state.visible = false;
})
})
merge(
onFieldValueChange$('columnType'),
onFieldValueChange$('status'),
onFieldValueChange$('status'),
onFieldValueChange$('time'),
).subscribe(
fieldState => {
if(fieldState.active && fieldState.value != null) {
handleSearch({})
}
......@@ -58,7 +58,7 @@ const Announcements = () => {
onFieldValueChange$('pagination').subscribe((state) => {
handleSearch({...state.value})
})
}
const handleSearch = async (params) => {
......@@ -71,9 +71,9 @@ const Announcements = () => {
title: title || '',
columnType: columnType != 0 ? columnType : '',
status: status != 0 ? status : '',
startTime: st && st * 1000,
endTime: et && et * 1000,
current: 1,
startTime: st && st,
endTime: et && et,
current: 1,
pageSize: 10,
...params
}
......@@ -91,7 +91,7 @@ const Announcements = () => {
})
}
})
}
// 修改状态
......@@ -115,7 +115,7 @@ const Announcements = () => {
return (
<Card>
<FilterTable
<FilterTable
schema={advertisementSchema}
components={{
CustomSearch,
......@@ -155,7 +155,7 @@ const Announcements = () => {
</span>
)
},
toggleFilters: () => {
actions.setFieldState('FILTERS', state => {
const visible = !state.visible;
......@@ -182,7 +182,7 @@ const Announcements = () => {
<a>
删除
</a>
</Menu.Item>
</Menu.Item>
</Menu>
)
return (
......@@ -198,7 +198,7 @@ const Announcements = () => {
</Popconfirm>
{/* // 只有待上架, 已下架架才有 修改和删除 */}
{
canModify.includes(record.status)
canModify.includes(record.status)
? (
<Dropdown overlay={menu}>
<a>
......@@ -219,4 +219,4 @@ const Announcements = () => {
)
}
export default Announcements;
\ No newline at end of file
export default Announcements;
......@@ -2,7 +2,7 @@ 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 { history, Link } from 'umi';
import { DownOutlined, DeleteOutlined, UpOutlined } from '@ant-design/icons';
import { timeRange } from '@/utils/index';
import { PublicApi } from '@/services/api';
......@@ -11,6 +11,8 @@ import TablePagination from '../components/TablePagination';
import { getTableDataSource, setFormStatus } from '../utils/utils'
import { merge } from 'rxjs';
import CustomSearch from '../components/CustomSearch';
import { useRowSelectionTable } from '@/hooks/useRowSelectionTable';
const { onFormInit$, onFieldValueChange$ } = FormEffectHooks
const { Search } = Input;
......@@ -55,6 +57,8 @@ const getData = async (params: any) => {
const Infomation = () => {
const columns = useGetColumns();
const [selectedRow, setSelectedRow] = useState<any[]>([]);
// const [roleSelection, roleSelectCtl] = useRowSelectionTable()
// const refkeys = useRef([])
useEffect(() => {
const params = {
......@@ -73,14 +77,14 @@ const Infomation = () => {
merge(
onFieldValueChange$('columns'),
onFieldValueChange$('status'),
onFieldValueChange$('status'),
onFieldValueChange$('time')
).subscribe((state) => {
if(state.active && state.value != null) {
handleSearch({})
}
})
onFieldValueChange$('pagination').subscribe((state) => {
handleSearch({...state.value})
})
......@@ -93,12 +97,12 @@ const Infomation = () => {
const time = actions.getFieldValue('time');
const { st, et } = timeRange(time);
const postData = {
title: title,
title: title,
status: status != 0 ? status : '',
columnId: columnId,
startTime: st && st * 1000,
endTime: et && et * 1000,
current: 1,
startTime: st && st,
endTime: et && et,
current: 1,
pageSize: 10,
...params,
}
......@@ -114,12 +118,12 @@ const Infomation = () => {
handleSearch({...paginationValue})
});
}
// 批量删除
const batchDelete = () => {
const rows = selectedRow.map((item) => item.id);
const rows = selectedRow
handleBatch(rows, 1);
}
}
// type 1-批量删除 2-批量上架 3-批量下架
const handleBatch = (row, type) => {
......@@ -153,12 +157,12 @@ const Infomation = () => {
return (
<Card>
<FilterTable
<FilterTable
schema={infomationSchema}
components={{
CustomSearch,
// SchemaFlexRowLayout,
// SchemaDropDown,
CustomSearch,
// SchemaFlexRowLayout,
// SchemaDropDown,
SchemaFlexColumnLayout,
Select,
Table,
......@@ -196,7 +200,7 @@ const Infomation = () => {
<a>
删除
</a>
</Menu.Item>
</Menu.Item>
</Menu>
)
return (
......@@ -210,7 +214,7 @@ const Infomation = () => {
>
<a href="#">{status[record.status]}</a>
</Popconfirm>
{
CAN_MODIFY.includes(record.status)
? <Dropdown overlay={menu}>
......@@ -220,19 +224,19 @@ const Infomation = () => {
</Dropdown>
: null
}
</Space>
)
},
batchGrounding: () => {
console.log("批量上架");
const rows = selectedRow.map((item) => item.id);
const rows = selectedRow
handleBatch(rows, 2);
},
undercarriage: () => {
console.log("批量下架")
const rows = selectedRow.map((item) => item.id);
const rows = selectedRow
handleBatch(rows, 3);
},
menu: () => {
......@@ -256,18 +260,27 @@ const Infomation = () => {
</span>
)
},
// rowSelection: roleSelection,
rowSelection: {
onSelect: (record, selected, selectedRows) => {
console.log(record, selected, selectedRows);
setSelectedRow(selectedRows);
const selectedRowsKeys = selectedRows.filter((_item) => _item).map((item) => item.id);
let keys = Array.from(new Set([...selectedRowsKeys, ...selectedRow]))
if(!selected) {
keys = keys.filter((_item) => _item !== record.id);
}
setSelectedRow(keys)
},
onSelectAll: (record, selected, changeRows) => {
// const res = selectedRow.concat(selectedRows);
console.log(selectedRow);
const res = selected.filter((item) => item && item.id);
setSelectedRow(res);
}
onSelectAll: (selected, checkedRows, changeRows) => {
const changeRowKey = changeRows.filter((_item) => _item).map((item) => item.id);
let keys = Array.from(new Set([...changeRowKey, ...selectedRow]))
if(selected) {
setSelectedRow(keys)
} else {
const removeKeys = keys.filter((_item) => !changeRowKey.includes(_item));
setSelectedRow(removeKeys)
}
},
selectedRowKeys: selectedRow
},
toggleFilters: () => {
actions.setFieldState('FILTERS', state => {
......@@ -283,7 +296,7 @@ const Infomation = () => {
)
})
});
},
}}
effects={infomationEffects()}
......@@ -292,4 +305,4 @@ const Infomation = () => {
)
}
export default Infomation;
\ No newline at end of file
export default Infomation;
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