Skip to content

Commit 8867b25

Browse files
author
zhongchubing
committed
feat: 控制分类是否显示到前台菜单
1 parent 34ccc22 commit 8867b25

File tree

18 files changed

+156
-82
lines changed

18 files changed

+156
-82
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
ModalForm, ProFormSelect, ProFormText,
2+
ModalForm, ProFormDependency, ProFormSelect, ProFormSwitch, ProFormText,
33
ProFormUploadButton,
44
} from "@ant-design/pro-form";
55
import useProFormItem from "@/hooks/useProFormItem";
@@ -31,6 +31,11 @@ export default function CategoryForm(props: any) {
3131
label: '分类图标',
3232
width: 'sm',
3333
})
34+
const showMenuProps = useProFormItem({
35+
name: 'showInMenu',
36+
label: '显示到菜单',
37+
width: 'sm',
38+
})
3439

3540
const icons = [
3641
'iconfont icon-qianduan',
@@ -47,7 +52,6 @@ export default function CategoryForm(props: any) {
4752
id: props.isEdit ? props.selectedData?._id : undefined,
4853
...values,
4954
}
50-
console.log(data, 'data')
5155
await request({
5256
url: API_CATEGORY,
5357
method: props.isEdit ? 'PUT' : 'POST',
@@ -59,13 +63,13 @@ export default function CategoryForm(props: any) {
5963
}
6064

6165
return (
62-
<ModalForm {...props} {...formProps} onFinish={onFinish} width={300}>
66+
<ModalForm {...props} {...formProps} onFinish={onFinish} width={350}>
6367
<ProFormText {...nameProps} />
6468
<ProFormSelect {...categoryProps} options={props.categoryList.reduce((t, v) => [...t, {label: v.name, value: v._id}], [])}/>
65-
<ProFormSelect
66-
{...categoryIconProps}
67-
options={icons.reduce((t, v) => [...t, {label: <i className={v}></i>, value: v}], [])}
68-
/>
69+
<ProFormDependency name={['icon']}>
70+
{({ icon })=> <ProFormText {...categoryIconProps} formItemProps={{extra: <i className={icon}></i>}} />}
71+
</ProFormDependency>
72+
<ProFormSwitch {...showMenuProps} />
6973
</ModalForm>
7074
)
7175
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ function transformCategoryList(list: any) {
2525

2626
export default function NavAuditListPage() {
2727
const formProps = useGeekProTablePopup()
28-
const tableRef = useRef<ActionType>(null);
28+
const tableRef = useRef<ActionType>();
2929
const [categoryList, setCategoryList] = useState([]);
3030

3131
async function onRequestData() {
3232
const res = await request({
3333
url: API_CATEGORY_LIST,
34-
method: 'GET'
34+
method: 'GET',
35+
data: {
36+
showInMenu: false
37+
}
3538
})
3639
const data = transformCategoryList(res.data)
3740
setCategoryList(data)
@@ -56,7 +59,16 @@ export default function NavAuditListPage() {
5659
{
5760
title: '分类名',
5861
dataIndex: 'name'
59-
}
62+
},
63+
{
64+
title: '显示在菜单',
65+
dataIndex: 'showInMenu',
66+
valueType: 'select',
67+
valueEnum: {
68+
true: { text: '显示', status: 'Success' },
69+
false: { text: '不显示', status: 'Error' },
70+
}
71+
},
6072
]
6173
return (
6274
<div>

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
DrawerForm,
2+
DrawerForm, ProFormDependency,
33
ProFormText,
44
ProFormTextArea,
55
ProFormUploadButton,
@@ -14,14 +14,7 @@ import request from "@/utils/request";
1414
export default function NavListForm(props: any) {
1515
const formProps = useGeekProForm({
1616
...props,
17-
onInitialValues(values: any): object {
18-
if (typeof values.logo === 'string') {
19-
values.logo = [{url: values.logo}]
20-
}
21-
return values
22-
},
2317
onFinish: async (values) => {
24-
values.logo = values.logo[0]?.url
2518
const data = {
2619
id: props.isEdit ? props.selectedData?._id : undefined,
2720
...values
@@ -36,7 +29,7 @@ export default function NavListForm(props: any) {
3629
props.tableRef?.reload()
3730
}
3831
})
39-
const logoProps = useProFormItem<UploadProps>({
32+
const logoProps = useProFormItem({
4033
name: 'logo',
4134
label: '网站LOGO',
4235
required: true,
@@ -66,7 +59,10 @@ export default function NavListForm(props: any) {
6659
})
6760
return (
6861
<DrawerForm {...props} {...formProps}>
69-
<ProFormUploadButton {...logoProps} />
62+
<ProFormDependency name={['logo']}>
63+
{({ logo })=> <ProFormText {...logoProps} formItemProps={{extra: <img width={50} src={logo} />}} />}
64+
</ProFormDependency>
65+
7066
<ProFormText {...nameProps} />
7167
<ProFormTextArea {...descProps} />
7268
<ProFormText {...urlProps} />

geekape-nav-main/components/AppHeader.vue

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<template>
22
<el-header>
33
<AppSearch />
4-
<div>
5-
<el-tooltip content="意见反馈"><i class="el-icon-question" @click="onJumpFeedback"></i></el-tooltip>
6-
<el-tooltip content="推荐网站"><i class="el-icon-circle-plus" @click="$emit('showPopup')"></i></el-tooltip>
7-
</div>
4+
5+
<el-row type="flex">
6+
<el-col>
7+
<el-tooltip content="意见反馈"><i class="el-icon-question" @click="onJumpFeedback"></i></el-tooltip>
8+
</el-col>
9+
<el-col>
10+
<el-tooltip content="推荐网站"><i class="el-icon-circle-plus" @click="$emit('showPopup')"></i></el-tooltip>
11+
</el-col>
12+
</el-row>
813
</el-header>
914
</template>
1015

@@ -53,9 +58,24 @@ export default {
5358
5459
i {
5560
font-size: 25px;
56-
margin-left: 30px;
61+
margin-left: 2rem;
5762
color: #999;
5863
cursor: pointer;
5964
}
6065
}
66+
67+
@media screen and (max-width: 568px) {
68+
.app-search {
69+
/deep/ .el-select {
70+
display: none;
71+
}
72+
}
73+
}
74+
@media screen and (min-width: 569px) {
75+
.app-search {
76+
/deep/ .el-select {
77+
display: block;
78+
}
79+
}
80+
}
6181
</style>

geekape-nav-main/components/AppNavItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<el-col :xs="24" :sm="8" :md="4" lg="4" class="website-item">
2+
<el-col :xs="24" :sm="8" :md="6" :lg="4" class="website-item">
33
<div class="wrap">
44
<a class="link" target="_blank" :href="data.href">
55
<el-tooltip content="链接直达" property="top">

geekape-nav-main/components/AppNavMenus.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,16 @@ $sidebar-w: auto;
210210
}
211211
212212
213+
@media screen and (max-width: 568px) {
214+
.app-search,
215+
.sidebar-fix {
216+
display: none;
217+
}
218+
}
219+
@media screen and (min-width: 569px) {
220+
.app-search,
221+
.sidebar-fix {
222+
display: block;
223+
}
224+
}
213225
</style>

geekape-nav-main/layouts/default.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<nuxt />
3+
<nuxt keep-alive />
44
</div>
55
</template>
66

geekape-nav-main/nuxt.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const nuxtPageCache = require('nuxt-page-cache')
2+
13
module.exports = {
24
mode: "universal",
35
telemetry: false,
@@ -86,5 +88,14 @@ module.exports = {
8688
*/
8789
extend(config, ctx) {},
8890
vendor: ["axios"]
89-
}
91+
},
92+
93+
// serverMiddleware: [
94+
// nuxtPageCache.cacheSeconds(1, req => {
95+
// if (req.query && req.query.pageType) {
96+
// return req.query.pageType
97+
// }
98+
// return false
99+
// })
100+
// ]
90101
}

geekape-nav-main/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"https": "^1.0.0",
3030
"mongoose": "^5.9.24",
3131
"nuxt": "^2.0.0",
32+
"nuxt-page-cache": "^0.0.5",
3233
"request": "^2.88.2",
3334
"vuex": "^3.6.2"
3435
},

geekape-nav-main/pages/index.vue

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ export default {
6666
},
6767
methods: {
6868
async getCategoryList() {
69-
const { data } = await this.$api.getCategoryList();
70-
this.categorys = data.data;
69+
const { data: categorys } = await this.$api.getCategoryList();
70+
this.categorys = categorys;
7171
72-
if (this.categorys.length) {
73-
const { children } = this.categorys.slice(0, 1)[0];
74-
const categoryId = children[0]._id;
72+
if (Array.isArray(categorys)) {
73+
const categoryId = categorys[0]._id;
7574
this.findNav(categoryId);
7675
}
7776
},
@@ -107,22 +106,10 @@ export default {
107106
data
108107
};
109108
},
110-
mounted() {
111-
window.onresize = () => {
112-
return (() => {
113-
window.screenWidth = document.body.clientWidth;
114-
if (window.screenWidth < 481) {
115-
this.isLeftbar = false;
116-
} else {
117-
this.isLeftbar = true;
118-
}
119-
})();
120-
};
121-
window.onresize();
122-
},
123-
created() {
124-
console.log(process.env.navUrl, "process.env");
125-
}
109+
// created() {
110+
// this.getCategoryList()
111+
// console.log(process.env.navUrl, "process.env");
112+
// }
126113
};
127114
</script>
128115

@@ -151,20 +138,6 @@ export default {
151138
}
152139
}
153140

154-
@media screen and (max-width: 568px) {
155-
.user-layout {
156-
/deep/ .el-header .arrow {
157-
display: none;
158-
}
159-
}
160-
}
161-
@media screen and (min-width: 569px) {
162-
.user-layout {
163-
/deep/ .el-header .arrow {
164-
display: block;
165-
}
166-
}
167-
}
168141

169142
/deep/ .el-menu--popup-right-start {
170143
height: 500px !important;

geekape-nav-main/pages/nav/_id.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<div class="container">
1818
<el-row :gutter="25" class="site-info">
19-
<el-col span="6" xs="24">
19+
<el-col :md="6" :xs="24">
2020
<div class="left">
2121
<div class="img-wrap">
2222
<el-image :src="detail.logo" />
@@ -40,7 +40,7 @@
4040
</div>
4141
</div>
4242
</el-col>
43-
<el-col span="10" xs="24">
43+
<el-col :md="10" :xs="24">
4444
<div class="content">
4545
<!-- <div class="category-bar">-->
4646
<!-- <span class="category">素材资源</span>-->
@@ -55,7 +55,7 @@
5555
</div>
5656
</div>
5757
</el-col>
58-
<el-col span="8" xs="24">
58+
<el-col :md="8" :xs="24">
5959
<div class="right">
6060
<div class="app-card">
6161
<div class="app-card-header">
@@ -126,7 +126,7 @@ export default {
126126
.container {
127127
max-width: 1200px;
128128
margin: auto;
129-
padding: 3rem 0;
129+
padding: 3rem 15px;
130130
}
131131
132132
.placeholder {
@@ -458,4 +458,14 @@ export default {
458458
margin-right: 8px;
459459
}
460460
}
461+
462+
463+
@media screen and (max-width: 568px) {
464+
.site-info {
465+
margin-top: 0;
466+
.el-col {
467+
margin-bottom: 40px;
468+
}
469+
}
470+
}
461471
</style>

geekape-nav-main/yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5652,7 +5652,7 @@ lowercase-keys@^1.0.0:
56525652
resolved "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f"
56535653
integrity sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==
56545654

5655-
lru-cache@^4.0.1, lru-cache@^4.1.2:
5655+
lru-cache@^4.0.1, lru-cache@^4.1.2, lru-cache@^4.1.3:
56565656
version "4.1.5"
56575657
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
56585658
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
@@ -6323,6 +6323,13 @@ number-is-nan@^1.0.0:
63236323
resolved "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
63246324
integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=
63256325

6326+
nuxt-page-cache@^0.0.5:
6327+
version "0.0.5"
6328+
resolved "https://registry.nlark.com/nuxt-page-cache/download/nuxt-page-cache-0.0.5.tgz#9d32ad3f037105e6fc7788734f1bda4a162e8ec3"
6329+
integrity sha1-nTKtPwNxBeb8d4hzTxvaShYujsM=
6330+
dependencies:
6331+
lru-cache "^4.1.3"
6332+
63266333
nuxt@^2.0.0:
63276334
version "2.13.3"
63286335
resolved "https://registry.npmjs.org/nuxt/-/nuxt-2.13.3.tgz#494f0df34851dfcdbdf4fd092112fa1d4bed1b02"

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import Controller from './common';
33
export default class CategoryController extends Controller {
44
async list() {
55
const { ctx } = this
6+
const { showInMenu = true } = ctx.query
67
try {
7-
let data = await ctx.model.Category.find({}).limit(100000)
8-
const stairCategory = data.filter(item=> !item.categoryId)
9-
const secondCategory = data.filter(item=> item.categoryId)
8+
const params: any = {}
9+
if (showInMenu && showInMenu !== "false") {
10+
params.showInMenu = { $in: [null, true] }
11+
}
12+
let data = await ctx.model.Category.find(params).limit(100000)
1013

11-
let newData = stairCategory.map(item=> {
12-
item.children = [...secondCategory.filter(cate=> item._id == cate.categoryId)]
13-
return item
14-
})
14+
const newData = ctx.service.category.formatCategoryList(data)
1515
this.success(newData)
1616
} catch (error) {
1717
this.error(error.message)

0 commit comments

Comments
 (0)