diff --git a/front/src/views/components/Materials.vue b/front/src/views/components/Materials.vue index 8b7b474..1b5be18 100644 --- a/front/src/views/components/Materials.vue +++ b/front/src/views/components/Materials.vue @@ -11,7 +11,13 @@ value-format="yyyy-MM-dd" size="small" style="width: 240px;"/> - + @@ -228,6 +234,7 @@ export default { fileName: '', currentFileName: '', query_triggered: false, + useDefaultMaterialsType: true, total: 0, currPage: 1, pageSize: 10, @@ -238,6 +245,7 @@ export default { newMaterials: { materials_intro: '', create_time: '', + materials_type: '', project_id: 0 }, editMaterials: { @@ -254,9 +262,7 @@ export default { }, mounted() { this.get_material_type_list() - if (!Array.isArray(this.materials_type)) { - this.filter.materials_type = this.materials_type - } + this.resetDefaultMaterialsType() }, created() { @@ -301,7 +307,7 @@ export default { }, handleReset() { this.filter.dateRange = null - this.filter.materials_type = '' + this.resetDefaultMaterialsType() this.currPage = 1 this.pageSize = 10 this.total = 0 @@ -317,6 +323,37 @@ export default { this.currPage = val this.get_materials_info_list() }, + handleMaterialsTypeChange() { + this.useDefaultMaterialsType = false + }, + resetDefaultMaterialsType() { + this.useDefaultMaterialsType = true + this.filter.materials_type = Array.isArray(this.materials_type) ? '' : this.materials_type + }, + hasSelectedMaterialType(value) { + return value !== '' && value !== undefined && value !== null + }, + buildMaterialsQueryParams() { + const param = { + materials_owner: this.materials_owner, + materials_class: this.materials_class, + currPage: this.currPage, + pageSize: this.pageSize + } + + if (this.hasSelectedMaterialType(this.filter.materials_type)) { + param.materials_type = this.filter.materials_type + } else if (this.useDefaultMaterialsType && this.hasSelectedMaterialType(this.materials_type)) { + param.materials_type = this.materials_type + } + + if (this.filter.dateRange && this.filter.dateRange.length === 2) { + param.start_time = this.filter.dateRange[0] + param.end_time = this.filter.dateRange[1] + } + + return param + }, confirmEdit() { const formData = { materials_id: this.editMaterials.materials_id, @@ -429,12 +466,15 @@ export default { }, confirmAddMaterials() { - if (this.newMaterials.materials_intro.trim() === '') { + const materialsIntro = (this.newMaterials.materials_intro || '').trim() + const materialsUrl = (this.materials_url || '').trim() + + if (materialsIntro === '') { this.$message.warning('请输入文件描述') return } console.log(this.materials_url) - if (this.materials_url.trim() === '') { + if (materialsUrl === '') { this.$message.warning('请选择文件') return } @@ -443,7 +483,7 @@ export default { materials_class: this.materials_class, materials_owner: this.materials_owner, materials_type: this.newMaterials.materials_type, - materials_intro: this.newMaterials.materials_intro, + materials_intro: materialsIntro, materials_url: this.materials_url, materials_file_name: this.fileName, create_time: this.newMaterials.create_time @@ -468,23 +508,7 @@ export default { }, get_materials_info_list() { - var param = { - materials_owner: this.materials_owner, - materials_class: this.materials_class, - currPage: this.currPage, - pageSize: this.pageSize - } - - if (this.filter.materials_type !== '') { - param.materials_type = this.filter.materials_type - } else if (!Array.isArray(this.materials_type)) { - param.materials_type = this.materials_type - } - - if (this.filter.dateRange && this.filter.dateRange.length === 2) { - param.start_time = this.filter.dateRange[0] - param.end_time = this.filter.dateRange[1] - } + var param = this.buildMaterialsQueryParams() material.GetMaterialsInfo(param).then(response => { const data = response.data.data