Skip to content

Commit 8825fd7

Browse files
committed
输入数字调换顺序
1 parent c416360 commit 8825fd7

File tree

4 files changed

+125
-63
lines changed

4 files changed

+125
-63
lines changed

src/api/modules/column.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import http from "@/api";
22
import { PORT1 } from "@/api/config/servicePort";
33
import { Login } from "@/api/interface/index";
44
import { IFormType } from "@/views/column/setting";
5+
import { IArticleSortFormType } from "@/views/column/setting/articlesort";
56

67
/**
78
* @name 教程模块
@@ -56,3 +57,8 @@ export const delColumnArticleApi = (id: number) => {
5657
export const sortColumnArticleApi = (activeId: number, overId: number) => {
5758
return http.post<Login.ResAuthButtons>(`${PORT1}/column/sortColumnArticleApi`, { activeId, overId });
5859
};
60+
61+
// 调整教程的顺序
62+
export const sortColumnArticleByIDApi = (form: IArticleSortFormType) => {
63+
return http.post<Login.ResAuthButtons>(`${PORT1}/column/sortColumnArticleByIDApi`, form);
64+
};

src/views/author/zsxqlist/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ const Zsxqlist: FC<IProps> = props => {
332332
dataIndex: "strategy",
333333
key: "strategy",
334334
render(value) {
335-
const desc = UserAiStrategy[value] || "绑定";
335+
const desc = UserAiStrategy[value] || "绑定" + value;
336336
// 如果 desc 的长度大于 5,那么就截取前 5 个字符
337337
let len = desc.length;
338338
if (len > 8) {
@@ -479,6 +479,5 @@ const Zsxqlist: FC<IProps> = props => {
479479
};
480480

481481
const mapStateToProps = (state: any) => state.disc.disc;
482-
console.log("mapStateToProps", mapStateToProps);
483482
const mapDispatchToProps = {};
484483
export default connect(mapStateToProps, mapDispatchToProps)(Zsxqlist);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.rotated-icon {
2+
transform: rotate(90deg); /* 或任何您需要的角度 */
3+
}

src/views/column/setting/articlesort/index.tsx

Lines changed: 115 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ import { FC, useCallback, useEffect, useState } from "react";
44
import React from "react";
55
import { connect } from "react-redux";
66
import { useLocation, useNavigate } from "react-router-dom";
7-
import { DeleteOutlined, EyeOutlined, MenuOutlined } from "@ant-design/icons";
7+
import { DeleteOutlined, EyeOutlined, SwapOutlined } from "@ant-design/icons";
88
import type { DragEndEvent } from '@dnd-kit/core';
99
import { DndContext, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
1010
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
1111
import {
12-
arrayMove,
1312
SortableContext,
1413
useSortable,
1514
verticalListSortingStrategy,
1615
} from '@dnd-kit/sortable';
1716
import { CSS } from '@dnd-kit/utilities';
18-
import { Button, Descriptions, Drawer, Form, Image,Input, message, Modal, Space, Table } from "antd";
17+
import { Button, Descriptions, Drawer, Form, Input, InputNumber, message, Modal, Space, Table, Tooltip } from "antd";
1918
import type { ColumnsType } from "antd/es/table";
2019

21-
import { delColumnArticleApi, getColumnArticleListApi, getColumnByNameListApi, sortColumnArticleApi, updateColumnArticleApi } from "@/api/modules/column";
20+
import { delColumnArticleApi, getColumnArticleListApi, sortColumnArticleApi, sortColumnArticleByIDApi,updateColumnArticleApi } from "@/api/modules/column";
2221
import { ContentInterWrap, ContentWrap } from "@/components/common-wrap";
2322
import { initPagination, IPagination, UpdateEnum } from "@/enums/common";
2423
import { MapItem } from "@/typings/common";
2524
import { baseDomain } from "@/utils/util";
26-
import { getCompleteUrl } from "@/utils/util";
2725
import TableSelect from "@/views/column/article/components/tableselect/TableSelect";
2826
import Search from "./search";
2927

@@ -59,6 +57,18 @@ export interface IFormType {
5957
sort: number; // 排序
6058
}
6159

60+
export interface IArticleSortFormType {
61+
id: number; // 主键id
62+
articleId: number; // 文章ID
63+
sort: number; // 排序
64+
}
65+
66+
const defaulArticleSorttInitForm: IArticleSortFormType = {
67+
id: -1,
68+
articleId: -1,
69+
sort: -1
70+
};
71+
6272
const defaultInitForm: IFormType = {
6373
id: -1,
6474
articleId: -1,
@@ -85,16 +95,22 @@ interface ColumnValue {
8595
const ColumnArticle: FC<IProps> = props => {
8696

8797
const [formRef] = Form.useForm();
98+
// 调整文章书序的表单
99+
const [articleSortFormRef] = Form.useForm();
88100
// form值(详情和新增的时候会用到)
89101
const [form, setForm] = useState<IFormType>(defaultInitForm);
90-
102+
// form值(调整文章顺序的表单值变化时保存)
103+
const [articleSortForm, setArticleSortForm] = useState<IArticleSortFormType>(defaulArticleSorttInitForm);
91104
// 查询表单
92105
const [searchForm, setSearchForm] = useState<ISearchForm>(defaultSearchForm);
93106

94107
// 修改添加抽屉
95108
const [isOpenDrawerShow, setIsOpenDrawerShow] = useState<boolean>(false);
96109
// 详情抽屉
97110
const [isDetailDrawerShow, setIsDetailDrawerShow] = useState<boolean>(false);
111+
// 调整顺序抽屉
112+
const [isSortDrawerShow, setIsSortDrawerShow] = useState<boolean>(false);
113+
98114
// 文章选择下拉框是否打开
99115
const [isArticleSelectOpen, setIsArticleSelectOpen] = useState<boolean>(false);
100116

@@ -114,10 +130,12 @@ const ColumnArticle: FC<IProps> = props => {
114130
const navigate = useNavigate();
115131
const { columnId: columnIdParam } = location.state || {};
116132

133+
// 拖拽相关 1
117134
interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
118135
'data-row-key': string;
119136
}
120137

138+
// 拖拽相关 2
121139
const Row = (props: RowProps) => {
122140
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
123141
id: props['data-row-key'],
@@ -156,6 +174,7 @@ const ColumnArticle: FC<IProps> = props => {
156174
}
157175
};
158176

177+
// 拖拽相关 3
159178
const sensors = useSensors(
160179
useSensor(PointerSensor, {
161180
activationConstraint: {
@@ -169,12 +188,17 @@ const ColumnArticle: FC<IProps> = props => {
169188
setQuery(prev => prev + 1);
170189
}, []);
171190

172-
// 值改变(新增教程文章时)
191+
// 值改变(新增教程文章时,老的做法,将 formRef 放到了这里,不太好
173192
const handleChange = (item: MapItem) => {
174193
setForm({ ...form, ...item });
175194
formRef.setFieldsValue({ ...item });
176195
};
177196

197+
// 值改变(调整顺序输入框发生变化时)
198+
const handleArticleSortChange = (item: MapItem) => {
199+
setArticleSortForm({ ...articleSortForm, ...item });
200+
};
201+
178202
// 查询表单值改变
179203
const handleSearchChange = (item: MapItem) => {
180204
// 当 status 的值为 -1 时,重新显示
@@ -208,11 +232,8 @@ const ColumnArticle: FC<IProps> = props => {
208232
setIsArticleSelectOpen(false);
209233
// 关闭抽屉
210234
setIsOpenDrawerShow(false);
211-
};
212-
213-
// 关闭详情抽屉时触发
214-
const handleCloseDetailDrawer = () => {
215-
setIsDetailDrawerShow(false);
235+
// 关闭调整顺序的抽屉
236+
setIsSortDrawerShow(false);
216237
};
217238

218239
// 删除
@@ -256,6 +277,25 @@ const ColumnArticle: FC<IProps> = props => {
256277
}
257278
};
258279

280+
// 调整顺序的 submit
281+
const handleSortByIDSubmit = async () => {
282+
const values = await articleSortFormRef.validateFields();
283+
const newValues = {
284+
...values,
285+
id: articleSortForm.id,
286+
};
287+
console.log("提交的值:", newValues);
288+
289+
const { status: successStatus } = (await sortColumnArticleByIDApi(newValues)) || {};
290+
const { code, msg } = successStatus || {};
291+
if (code === 0) {
292+
setIsSortDrawerShow(false);
293+
onSure();
294+
} else {
295+
message.error(msg);
296+
}
297+
};
298+
259299
const onDragEnd = async ({ active, over }: DragEndEvent) => {
260300
console.log("active over", active, over);
261301
if (over != null && active.id !== over.id) {
@@ -296,33 +336,6 @@ const ColumnArticle: FC<IProps> = props => {
296336
getSortList();
297337
}, [query, current, pageSize]);
298338

299-
// 教程下拉框,可根据教程查询
300-
async function fetchColumnList(key: string): Promise<ColumnValue[]> {
301-
console.log('根据教程名查询', key);
302-
const { status, result } = await getColumnByNameListApi(key);
303-
const { code } = status || {};
304-
//@ts-ignore
305-
const { items } = result || {};
306-
if (code === 0) {
307-
const newList = items.map((item: MapItem) => ({
308-
key: item?.columnId,
309-
// label 这里我想把教程封面也加上
310-
label: <div>
311-
<Image
312-
className="cover-select"
313-
src={getCompleteUrl(item?.cover)}
314-
/>
315-
<span>{item?.column}</span>
316-
</div>,
317-
value: item?.column
318-
}));
319-
console.log("教程列表", newList);
320-
return newList;
321-
}
322-
// 没查到数据时,返回空数组
323-
return [];
324-
};
325-
326339
// 表头设置
327340
const columns: ColumnsType<DataType> = [
328341
{
@@ -357,37 +370,68 @@ const ColumnArticle: FC<IProps> = props => {
357370
},
358371
{
359372
title: "操作",
360-
width: 210,
373+
width: 150,
361374
render: (_, item) => {
362375
// 删除的时候用
363-
const { id } = item;
376+
const { id, sort } = item;
364377
return (
365378
<div className="operation-btn">
366-
<Button
367-
type="primary"
368-
icon={<EyeOutlined />}
369-
style={{ marginRight: "10px" }}
370-
onClick={() => {
371-
setIsDetailDrawerShow(true);
372-
// 把所有的值传给 form 表单
373-
handleChange({ ...item });
374-
}}
375-
>
376-
详情
377-
</Button>
378-
<Button
379-
type="primary"
380-
danger
381-
icon={<DeleteOutlined />}
382-
onClick={() => handleDel(id)}>
383-
删除
384-
</Button>
379+
<Tooltip title="详情">
380+
<Button
381+
type="primary"
382+
icon={<EyeOutlined />}
383+
style={{ marginRight: "10px" }}
384+
onClick={() => {
385+
setIsDetailDrawerShow(true);
386+
// 把所有的值传给 form 表单
387+
handleChange({ ...item });
388+
}}
389+
></Button>
390+
</Tooltip>
391+
<Tooltip title="调整顺序">
392+
<Button
393+
type="primary"
394+
icon={<SwapOutlined className="rotated-icon"/>}
395+
style={{ marginRight: "10px" }}
396+
onClick={() => {
397+
setIsSortDrawerShow(true);
398+
// 把 id 和 sort 传给调整顺序的表单
399+
handleArticleSortChange({ id, sort });
400+
articleSortFormRef.setFieldsValue({ sort });
401+
}}
402+
></Button>
403+
</Tooltip>
404+
<Tooltip title="删除">
405+
<Button
406+
type="primary"
407+
danger
408+
icon={<DeleteOutlined />}
409+
onClick={() => handleDel(id)}>
410+
</Button>
411+
</Tooltip>
385412
</div>
386413
);
387414
}
388415
}
389416
];
390417

418+
// 调整顺序的表单
419+
const articleSortContent = (
420+
<Form
421+
autoComplete="off"
422+
form={articleSortFormRef}>
423+
<Form.Item
424+
label="设置文章顺序为"
425+
name="sort"
426+
rules={[{ required: true, message: '请输入文章顺序' }]}
427+
>
428+
<InputNumber min={1} size="small"
429+
onChange={value => handleArticleSortChange({ sort: value })}
430+
/>
431+
</Form.Item>
432+
</Form>
433+
);
434+
391435
// 编辑表单
392436
const reviseDrawerContent = (
393437
<Form
@@ -458,7 +502,7 @@ const ColumnArticle: FC<IProps> = props => {
458502
<Drawer
459503
title="详情"
460504
placement="right"
461-
onClose={handleCloseDetailDrawer}
505+
onClose={handleCloseDrawer}
462506
open={isDetailDrawerShow}>
463507
<Descriptions column={1} labelStyle={{ width: "100px" }}>
464508
{detailInfo.map(({ label, title }) => (
@@ -468,6 +512,16 @@ const ColumnArticle: FC<IProps> = props => {
468512
))}
469513
</Descriptions>
470514
</Drawer>
515+
{/* 调整顺序的抽屉 */}
516+
<Modal
517+
title="调整教程顺序"
518+
width={280}
519+
style={{ left: 200 }}
520+
onOk={handleSortByIDSubmit}
521+
onCancel={handleCloseDrawer}
522+
open={isSortDrawerShow}>
523+
{articleSortContent}
524+
</Modal>
471525
{/* 把弹窗修改为抽屉 */}
472526
<Drawer
473527
title="添加"

0 commit comments

Comments
 (0)