Skip to content

Commit

Permalink
文档排序可选
Browse files Browse the repository at this point in the history
  • Loading branch information
fesiong committed Jan 30, 2024
1 parent 11acc46 commit e5d86d3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 31 deletions.
63 changes: 36 additions & 27 deletions src/pages/content/archive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PlusOutlined } from '@ant-design/icons';
import { Alert, Button, Dropdown, Input, Menu, message, Modal, Select, Space, Tag } from 'antd';
import React, { useState, useRef, useEffect } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import type { ProColumns, ActionType } from '@ant-design/pro-table';
import type { ProColumns, ActionType, ProColumnType } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import {
ModalForm,
Expand Down Expand Up @@ -362,36 +362,37 @@ const ArchiveList: React.FC = (props) => {
setQuickVisible(true);
};

const sortColumn: ProColumnType = {
title: '排序',
dataIndex: 'sort',
hideInSearch: true,
sorter: true,
tooltip: '数值越大,越靠前',
width: 90,
render: (_, entity: any, index) => {
return (
<div>
<Input
onBlur={(e: any) => {
updateSort(index, entity, e.target.value);
}}
onPressEnter={(e: any) => {
updateSort(index, entity, e.target?.value);
}}
defaultValue={entity.sort}
></Input>
</div>
);
},
};

const columns: ProColumns<any>[] = [
{
title: '编号',
dataIndex: 'id',
hideInSearch: true,
sorter: true,
},
{
title: '排序',
dataIndex: 'sort',
hideInSearch: true,
sorter: true,
tooltip: '数值越大,越靠前',
width: 90,
render: (_, entity, index) => {
return (
<div>
<Input
onBlur={(e) => {
updateSort(index, entity, e.target.value);
}}
onPressEnter={(e) => {
updateSort(index, entity, e.target.value);
}}
defaultValue={entity.sort}
></Input>
</div>
);
},
},
{
title: '标题',
dataIndex: 'title',
Expand Down Expand Up @@ -465,6 +466,14 @@ const ArchiveList: React.FC = (props) => {
hideInSearch: true,
sorter: true,
},
{
title: 'Flag',
dataIndex: 'flag',
hideInTable: true,
renderFormItem: () => {
return <ProFormSelect name="flag" valueEnum={Object.assign({ '': '不限' }, flagEnum)} />;
},
},
{
title: '状态',
dataIndex: 'status',
Expand All @@ -479,16 +488,16 @@ const ArchiveList: React.FC = (props) => {
},
2: {
text: '待发布',
status: 'Default',
status: 'Warning',
},
},
renderFormItem: () => {
return (
<ProFormSelect
name="status"
initialValue={'ok'}
request={async () => {
return [
{ label: '全部', value: '' },
{ label: '正常', value: 'ok' },
{ label: '草稿', value: 'draft' },
{ label: '待发布', value: 'plan' },
Expand Down Expand Up @@ -713,7 +722,7 @@ const ArchiveList: React.FC = (props) => {
}
return getArchives(params);
}}
columns={columns}
columns={contentSetting.use_sort ? (columns.splice(1, 0, sortColumn), columns) : columns}
rowSelection={{
preserveSelectedRowKeys: true,
onChange: (selectedRowKeys) => {
Expand Down
28 changes: 24 additions & 4 deletions src/pages/content/archive/recycle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import React, { useState, useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import type { ProColumns, ActionType } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { deleteArchive, getArchives, recoverArchive } from '@/services';
import { deleteArchive, getArchiveInfo, getArchives, recoverArchive } from '@/services';

const ArchiveList: React.FC = (props) => {
const actionRef = useRef<ActionType>();
const [selectedRowKeys, setSelectedRowKeys] = useState<any[]>([]);
const [visible, setVisible] = useState<boolean>(false);
const [currentArchive, setCurrentArchive] = useState<any>(null);

const handleRemove = async (selectedRowKeys: any[]) => {
Modal.confirm({
Expand Down Expand Up @@ -61,6 +63,14 @@ const ArchiveList: React.FC = (props) => {
});
};

const previewArchive = (item: any) => {
setCurrentArchive(item);
setVisible(true);
getArchiveInfo({ id: item.id }).then((res) => {
setCurrentArchive(res.data || {});
});
};

const columns: ProColumns<any>[] = [
{
title: '编号',
Expand All @@ -74,9 +84,7 @@ const ArchiveList: React.FC = (props) => {
render: (dom, entity) => {
return (
<div style={{ maxWidth: 400 }}>
<a href={entity.link} target="_blank">
{dom}
</a>
<a onClick={() => previewArchive(entity)}>{dom}</a>
</div>
);
},
Expand Down Expand Up @@ -168,6 +176,18 @@ const ArchiveList: React.FC = (props) => {
showSizeChanger: true,
}}
/>
<Modal
title="文档预览"
open={visible}
width={1000}
onOk={() => setVisible(false)}
onCancel={() => setVisible(false)}
>
<h3>{currentArchive?.title}</h3>
<div className="article-content">
<div dangerouslySetInnerHTML={{ __html: currentArchive?.data?.content }}></div>
</div>
</Modal>
</PageContainer>
);
};
Expand Down
16 changes: 16 additions & 0 deletions src/pages/setting/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const SettingContactFrom: React.FC<any> = (props) => {
values.thumb_width = Number(values.thumb_width);
values.thumb_height = Number(values.thumb_height);
values.quality = Number(values.quality);
values.use_sort = Number(values.use_sort);

const hide = message.loading('正在提交中', 0);
saveSettingContent(values)
Expand Down Expand Up @@ -170,6 +171,21 @@ const SettingContactFrom: React.FC<any> = (props) => {
]}
extra="默认不启用多分类支持,启用多分类可能会导致网站加载变慢"
/>
<ProFormRadio.Group
name="use_sort"
label="启用文档排序"
options={[
{
value: 0,
label: '不启用',
},
{
value: 1,
label: '启用',
},
]}
extra="默认不启用文档排序支持,启用文档可能会导致网站加载变慢"
/>
<ProFormRadio.Group
name="use_webp"
label="启用Webp图片格式"
Expand Down

0 comments on commit e5d86d3

Please sign in to comment.