diff --git a/src/views/markdown/index.vue b/src/views/markdown/index.vue index 7e3e120..81e1772 100644 --- a/src/views/markdown/index.vue +++ b/src/views/markdown/index.vue @@ -45,7 +45,7 @@ 本文链接:{{file.slug ? articleLink+file.slug : articleLink+file.id}}

分类:

0){ + this.findCategoryIds(null, this.categories, this.file.categoryIds) + } // 初始化编辑器 if(isReload){ this.contentEditor.setValue(res.data.contentText) @@ -221,24 +225,30 @@ categoryTree() { categoryApi.categoryTree({userId: this.$store.state.user.userId}).then(res => { this.categories = res.data - - let ss = ["5fbf6857aff038ad2c1d686d", "5fbf685eaff038ad2c1d686e", "5fbf6863aff038ad2c1d686f", "5fbf689baff038ad2c1d6874"] - this.findCategoryIds(this.categories, ss) - console.log(this.categoryIds) + if(this.file.categoryIds && this.file.categoryIds.length > 0){ + this.findCategoryIds(null, this.categories, this.file.categoryIds) + } }) }, - findCategoryIds(categories, ss) { + findCategoryIds(parentCategory, categories, categoryIds) { + if(!categoryIds){ + return + } categories.forEach(category => { let ids = [] - if(category.ids){ - ids = category.ids + if(parentCategory && parentCategory.ids){ + ids = parentCategory.ids } ids.push(category.id) category['ids'] = ids - if(ss.includes(category.id)){ - this.categoryIds.push(ids) + if(categoryIds.includes(category.id)){ + let newIds = [] + Object.assign(newIds , ids) + this.categoryIdsList.push(newIds) + } + if(category.children){ + this.findCategoryIds(category, category.children, categoryIds) } - this.findCategoryIds(categories.children) }) }, vditorInit(content){ @@ -342,17 +352,11 @@ this.update() }, selectCategory(val){ - console.log(val) - let categoryIds = [] - this.categoryIds.forEach(categoryIdList => { - categoryIds.push(categoryIdList[categoryIdList.length - 1]) - }) - console.log(categoryIds) }, // update update(message){ let categoryIds = [] - this.categoryIds.forEach(categoryIdList => { + this.categoryIdsList.forEach(categoryIdList => { categoryIds.push(categoryIdList[categoryIdList.length - 1]) }) if(!this.checkParam()){ diff --git a/src/views/setting/articles/articleManager.vue b/src/views/setting/articles/articleManager.vue index 7293896..4e49cc1 100644 --- a/src/views/setting/articles/articleManager.vue +++ b/src/views/setting/articles/articleManager.vue @@ -35,17 +35,20 @@
- + 取消筛选 + + :props="{ multiple: true, checkStrictly: true, value: 'id', label: 'name' }" + clearable + @change="selectCategory" + > 筛选
@@ -90,7 +93,7 @@ @@ -139,14 +142,27 @@ export default { total: 0, }, categories: [], + categoryIdsList: [], + isFilter: false, query: { radioStatus: '', radioUser: 'my', keyword: '', + categoryIds: '' }, } }, computed: {}, + created(){ + if(this.$route.query.keyword){ + this.query.keyword = this.$route.query.keyword + this.isFilter = true + } + if(this.$route.query.categoryIds){ + this.query.categoryIds = this.$route.query.categoryIds + this.isFilter = true + } + }, mounted() { this.getArticleList() this.categoryTree() @@ -171,8 +187,7 @@ export default { }, methods: { beforeunloadFn(){ - console.log('beforeunloadFn') - return '是的发生' + return '确定要退出吗?' }, goBack() { const operation = this.$route.query.operation @@ -188,14 +203,35 @@ export default { this.newArticleDialogVisible = false } }, + cancelFilter() { + this.$router.push({query: {}}) + this.query.keyword = '' + this.categoryIdsList = [] + this.getArticleList() + }, getArticleList() { + this.query.categoryIds = '' + if(this.$route.query.categoryIds){ + this.query.categoryIds = this.$route.query.categoryIds + } + if(this.categoryIdsList.length > 0){ + this.categoryIdsList.forEach(categoryIdList => { + this.query.categoryIds += categoryIdList[categoryIdList.length - 1] + ',' + }) + this.query.categoryIds = this.query.categoryIds.substring(0, this.query.categoryIds.length - 1) + } + this.isFilter = this.query.keyword.length > 0 || this.query.categoryIds.length > 0; + if(this.isFilter){ + this.$router.push({query: {keyword: this.query.keyword, categoryIds: this.query.categoryIds}}) + } markdownApi.getMarkdown({ pageIndex: this.pagination.pageIndex, pageSize: this.pagination.pageSize, userId: this.query.radioUser === 'my' ? this.$store.state.user.userId : null, isRelease: this.query.radioStatus === 'release', isDraft: this.query.radioStatus === 'draft', - keyword: this.query.keyword + keyword: this.query.keyword, + categoryIds: this.query.categoryIds }).then((res) => { this.articleList = res.data this.pagination.total = res.count @@ -204,6 +240,36 @@ export default { }) }) }, + findCategoryIds(parentCategory, categories, categoryIds) { + if(!categoryIds){ + return + } + categories.forEach(category => { + let ids = [] + if(parentCategory && parentCategory.ids){ + ids = parentCategory.ids + } + ids.push(category.id) + category['ids'] = ids + if(categoryIds.includes(category.id)){ + let newIds = [] + Object.assign(newIds , ids) + this.categoryIdsList.push(newIds) + } + if(category.children){ + this.findCategoryIds(category, category.children, categoryIds) + } + }) + }, + selectCategory(val) { + console.log('selectCategory', val) + let categoryIds = '' + this.categoryIdsList.forEach(categoryIdList => { + categoryIds += categoryIdList[categoryIdList.length - 1] + ',' + }) + categoryIds = categoryIds.substring(0, categoryIds.length - 2) + console.log(categoryIds) + }, currentChange() { this.$router.push({query: {page : this.pagination.pageIndex}}) this.getArticleList() @@ -222,6 +288,13 @@ export default { categoryTree() { categoryApi.categoryTree({userId: this.$store.state.user.userId}).then(res => { this.categories = res.data + if(this.$route.query.categoryIds){ + this.query.categoryIds = this.$route.query.categoryIds + let categoryIds = this.query.categoryIds.split(",") + if(categoryIds){ + this.findCategoryIds(null, this.categories, categoryIds) + } + } }) }, handleClose(done) { diff --git a/src/views/setting/articles/categoryManager.vue b/src/views/setting/articles/categoryManager.vue index 1c8f22e..ccb5c66 100644 --- a/src/views/setting/articles/categoryManager.vue +++ b/src/views/setting/articles/categoryManager.vue @@ -84,7 +84,9 @@ prop="quota" label="文章数">