Skip to content

Commit e4f62bb

Browse files
author
zhongchubing
committed
fix: 导航分类和标签的修改
1 parent adf9861 commit e4f62bb

File tree

10 files changed

+117
-33
lines changed

10 files changed

+117
-33
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
export interface Category {
1+
export interface CategoryModel {
22
_id: string
33
name: string
44
parentId: string
5-
children: Category[]
5+
children: CategoryModel[]
66
}
77

8+
export interface TagModel {
9+
_id: string
10+
name: string
11+
}
12+
13+
814
export interface ApiResponse {
915
code: number
1016
msg: string
1117
data: any
1218
}
19+
20+
21+
export enum NavStatus {
22+
pass,
23+
wait,
24+
reject,
25+
}

geekape-nav-admin/src/pages/nav/Audit/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {API_NAV_AUDIT, API_NAV_LIST} from "@/services/api";
33
import {ProColumns} from "@ant-design/pro-table";
44
import {Popconfirm, Tag, Space} from "antd";
55
import request from "@/utils/request";
6+
import {NavStatus} from "@/constants/api";
67

78
function RandomColorTag({ children }) {
89
const colors = [
@@ -69,15 +70,15 @@ export default function NavAuditListPage() {
6970
},
7071
]
7172

72-
async function onActionClick(id: string, action: any, status = 0) {
73+
async function onActionClick(id: string, action: any, status = NavStatus.pass) {
7374
await request({
7475
url: API_NAV_AUDIT,
7576
method: 'PUT',
7677
data: {
7778
id,
78-
status: 0,
79+
status,
7980
},
80-
msg: status == 0 ? '通过成功' : '拒绝成功'
81+
msg: status == NavStatus.pass ? '通过成功' : '拒绝成功'
8182
})
8283
action?.reload()
8384
}
@@ -86,8 +87,8 @@ export default function NavAuditListPage() {
8687
<GeekProTable
8788
columns={columns}
8889
requestParams={{url: API_NAV_LIST, method: 'GET'}}
89-
renderOptions={(text, record, _, action) => record.status != 2 ? [
90-
<Popconfirm title={'确定通过吗?'} onConfirm={() => onActionClick(record._id, action, 1)}>
90+
renderOptions={(text, record, _, action) => record.status != NavStatus.reject ? [
91+
<Popconfirm title={'确定通过吗?'} onConfirm={() => onActionClick(record._id, action, 0)}>
9192
<a>通过</a>
9293
</Popconfirm>,
9394
<Popconfirm title={'确定拒绝吗?'} onConfirm={() => onActionClick(record._id, action, 2)}>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {Select} from "antd";
2+
import request from "@/utils/request";
3+
import {API_CATEGORY_LIST} from "@/services/api";
4+
import {useEffect, useState} from "react";
5+
import {CategoryModel} from "@/constants/api";
6+
7+
export default function CategorySelect(props: any) {
8+
const [categoryList, setCategoryList] = useState<CategoryModel[]>([]);
9+
const [value, setValue] = useState('')
10+
11+
useEffect(()=> {
12+
async function getCategoryList() {
13+
const res = await request({
14+
url: API_CATEGORY_LIST,
15+
method: 'GET'
16+
})
17+
setCategoryList(res.data)
18+
}
19+
20+
getCategoryList()
21+
}, [])
22+
23+
function onSelectChange(value: string) {
24+
setValue(value)
25+
}
26+
27+
return (
28+
<Select onChange={onSelectChange} value={value} showSearch {...props}>
29+
{categoryList.map(item => <Select.OptGroup label={item.name}>
30+
{item.children.map(subItem => <Select.Option value={subItem._id}>{subItem.name}</Select.Option>)}
31+
</Select.OptGroup>)}
32+
</Select>
33+
)
34+
}

geekape-nav-admin/src/pages/nav/Category/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {PlusOutlined} from "@ant-design/icons";
77
import useGeekProTablePopup from "@/components/GeekProTable/useGeekProTablePopup";
88
import CategoryForm from "@/pages/nav/Category/CategoryForm";
99
import {useRef, useState} from "react";
10+
import {CategoryModel} from "@/constants/api";
1011

1112

1213
function transformCategoryList(list: any) {
@@ -80,7 +81,7 @@ export default function NavAuditListPage() {
8081
}}
8182
search={false}
8283
request={onRequestData}
83-
renderOptions={(text, record, _, action)=> ([
84+
renderOptions={(text, record: CategoryModel, _, action)=> ([
8485
<a onClick={()=> formProps.show({type: 'edit', data: record, action})}>编辑</a>,
8586
<Popconfirm title={'确定删除吗?'} onConfirm={() => onDelete(record._id, action)}>
8687
<a>删除</a>

geekape-nav-admin/src/pages/nav/List/NavListForm.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import {
2-
DrawerForm, ProFormDependency,
2+
DrawerForm, ProFormDependency, ProFormSelect,
33
ProFormText,
44
ProFormTextArea,
55
ProFormUploadButton,
66
ProFormUploadDragger
77
} from "@ant-design/pro-form";
88
import useProFormItem from "@/hooks/useProFormItem";
9-
import {UploadProps} from "antd";
9+
import {Form, UploadProps} from "antd";
1010
import useGeekProForm from "@/components/GeekProForm/useGeekProForm";
1111
import {API_NAV} from "@/services/api";
1212
import request from "@/utils/request";
13+
import CategorySelect from "@/pages/nav/Category/CategorySelect";
14+
import TagSelect from "@/pages/nav/Tag/TagSelect";
1315

1416
export default function NavListForm(props: any) {
1517
const formProps = useGeekProForm({
@@ -39,6 +41,7 @@ export default function NavListForm(props: any) {
3941
label: '网站名称',
4042
required: true
4143
})
44+
4245
const descProps = useProFormItem({
4346
name: 'desc',
4447
label: '网站描述',
@@ -64,6 +67,12 @@ export default function NavListForm(props: any) {
6467
</ProFormDependency>
6568

6669
<ProFormText {...nameProps} />
70+
<Form.Item name='categoryId' label='网站分类'>
71+
<CategorySelect />
72+
</Form.Item>
73+
<Form.Item name='tags' label='网站标签'>
74+
<TagSelect valueKey={'name'} />
75+
</Form.Item>
6776
<ProFormTextArea {...descProps} />
6877
<ProFormText {...urlProps} />
6978
<ProFormText {...authorProps} />

geekape-nav-admin/src/pages/nav/List/index.tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,14 @@ import GeekProTable from "@/components/GeekProTable/GeekProTable";
33
import {ProColumns} from "@ant-design/pro-table";
44
import useGeekProTablePopup from "@/components/GeekProTable/useGeekProTablePopup";
55
import NavListForm from "@/pages/nav/List/NavListForm";
6-
import {Popconfirm, Select} from "antd";
6+
import {Form, Popconfirm, Select} from "antd";
77
import request from "@/utils/request";
88
import {useRef, useState} from "react";
9-
import {Category} from "@/constants/api";
9+
import CategorySelect from "@/pages/nav/Category/CategorySelect";
1010

1111
export default function NavListPage() {
1212
const tableRef = useRef();
1313
const formProps = useGeekProTablePopup()
14-
const [categoryList, setCategoryList] = useState<Category[]>([]);
15-
16-
async function onChange() {
17-
if (categoryList.length) return
18-
const res = await request({
19-
url: API_CATEGORY_LIST,
20-
method: 'GET'
21-
})
22-
setCategoryList(res.data)
23-
}
2414

2515
const columns: ProColumns[] = [
2616
{
@@ -33,13 +23,7 @@ export default function NavListPage() {
3323
dataIndex: 'categoryId',
3424
width: 500,
3525
hideInTable: true,
36-
renderFormItem: () => (
37-
<Select onClick={onChange} showSearch>
38-
{categoryList.map(item => <Select.OptGroup label={item.name}>
39-
{item.children.map(subItem => <Select.Option value={subItem._id}>{subItem.name}</Select.Option>)}
40-
</Select.OptGroup>)}
41-
</Select>
42-
)
26+
renderFormItem: (props) => <CategorySelect {...props} />
4327
},
4428
{
4529
title: '网站描述',
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {Select, SelectProps} from "antd";
2+
import request from "@/utils/request";
3+
import {API_TAG_list} from "@/services/api";
4+
import {useEffect, useState} from "react";
5+
import {TagModel} from "@/constants/api";
6+
7+
interface TagSelectProps extends SelectProps<any> {
8+
valueKey?: string
9+
}
10+
11+
export default function TagSelect(props: TagSelectProps) {
12+
const [tagList, setTagList] = useState<TagModel[]>([]);
13+
const [value, setValue] = useState([])
14+
15+
useEffect(()=> {
16+
async function getTagList() {
17+
const { data } = await request({
18+
url: API_TAG_list,
19+
method: 'GET'
20+
})
21+
if (Array.isArray(data.data)) {
22+
setTagList(data?.data)
23+
}
24+
}
25+
26+
getTagList()
27+
}, [])
28+
29+
function onSelectChange(value: any) {
30+
setValue(value)
31+
}
32+
33+
return (
34+
<Select onChange={onSelectChange} value={value} showSearch mode={'tags'} {...props}>
35+
{tagList.map(subItem => <Select.Option value={subItem[props.valueKey || '_id']}>{subItem.name}</Select.Option>)}
36+
</Select>
37+
)
38+
}

geekape-nav-admin/src/pages/nav/Tag/form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
ModalForm, ProFormSelect, ProFormText,
2+
ModalForm, ProFormText,
33
} from "@ant-design/pro-form";
44
import useProFormItem from "@/hooks/useProFormItem";
55
import useGeekProForm from "@/components/GeekProForm/useGeekProForm";

geekape-nav-admin/src/pages/nav/Tag/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Button, Popconfirm} from "antd";
22
import request from "@/utils/request";
3-
import {API_CATEGORY, API_CATEGORY_LIST, API_TAG_list} from "@/services/api";
3+
import {API_TAG, API_TAG_list} from "@/services/api";
44
import GeekProTable from "@/components/GeekProTable/GeekProTable";
5-
import {ActionType, ProColumns} from "@ant-design/pro-table";
5+
import type {ActionType, ProColumns} from "@ant-design/pro-table";
66
import {PlusOutlined} from "@ant-design/icons";
77
import useGeekProTablePopup from "@/components/GeekProTable/useGeekProTablePopup";
88
import {useRef, useState} from "react";
@@ -29,7 +29,7 @@ export default function NavTagListPage() {
2929

3030
async function onDelete(id: string, action: any) {
3131
await request({
32-
url: API_CATEGORY,
32+
url: API_TAG,
3333
method: 'DELETE',
3434
data: {
3535
id,

geekape-nav-server/app/controller/nav.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export default class NavController extends Controller {
8181

8282
async edit() {
8383
this.ctx.request.body.updateTime = new Date()
84+
const { tags } = this.ctx.request.body
85+
if (Array.isArray(tags)) {
86+
await this.ctx.service.tag.addMultiTag(tags)
87+
}
8488
await super.update();
8589
}
8690

0 commit comments

Comments
 (0)