完善:分类管理

This commit is contained in:
jmal 2020-11-04 17:59:03 +08:00
parent 7bf8935171
commit 6207f1ef21
2 changed files with 45 additions and 9 deletions

View File

@ -37,6 +37,13 @@ export default {
data data
}) })
}, },
setDefault(params) {
return request({
url: 'category/setDefault',
method: 'put',
params
})
},
delete(params) { delete(params) {
return request({ return request({
url: 'category/delete', url: 'category/delete',

View File

@ -1,16 +1,17 @@
<template> <template>
<div class="container" v-wechat-title="title"> <div class="container" v-wechat-title="title">
<el-dialog class="dialog-cm" :title="dialogTitle" :visible.sync="dialogVisible"> <el-dialog class="dialog-cm" :title="dialogTitle" :visible.sync="dialogVisible">
<el-form ref="managerForm" :model="form" :rules="rules" label-width="120px"> <el-form ref="managerForm" :model="form" label-position="left" :rules="rules" label-width="85px">
<el-form-item label="分类名称" prop="name"> <el-form-item label="分类名称" prop="name">
<el-input v-model="form.name"/> <el-input v-model="form.name" style="width: 100%;"/>
</el-form-item> </el-form-item>
<el-form-item label="分类缩略名" prop="thumbnailName"> <el-form-item label="分类缩略名" prop="thumbnailName">
<el-input v-model="form.thumbnailName"/> <el-input v-model="form.thumbnailName" style="width: 100%;" placeholder="分类缩略名用于创建友好的链接形式."/>
</el-form-item> </el-form-item>
<el-form-item label="父级分类" prop="parentCategoryId"> <el-form-item label="父级分类" prop="parentCategoryId">
<el-cascader <el-cascader
v-model="form.parentCategoryId" v-model="form.parentCategoryId"
placeholder="不选择"
:options="categories" :options="categories"
:show-all-levels="false" :show-all-levels="false"
:props="{ checkStrictly: true }" :props="{ checkStrictly: true }"
@ -48,6 +49,8 @@
:data="categoryList" :data="categoryList"
stripe stripe
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
@cell-mouse-enter="cellMouseEnter"
@cell-mouse-leave="cellMouseLeave"
> >
<el-table-column <el-table-column
type="selection" type="selection"
@ -73,6 +76,10 @@
<el-table-column <el-table-column
prop="quota" prop="quota"
label="默认"> label="默认">
<template slot-scope="scope">
<span v-if="scope.row.isDefault">默认</span>
<a v-if="!scope.row.isDefault && scope.row.id === cellMouseIndexId" @click="setDefault(scope.row)">默认</a>
</template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="quota" prop="quota"
@ -116,7 +123,8 @@ export default {
] ]
}, },
editMove: 1,// 1添加,2修改 editMove: 1,// 1添加,2修改
multipleSelection: [] multipleSelection: [],
cellMouseIndexId: ''
} }
}, },
computed: {}, computed: {},
@ -190,6 +198,19 @@ export default {
} }
return data return data
}, },
// 设为默认
setDefault(row) {
categoryApi.setDefault({categoryId: row.id}).then(() => {
this.getCategories()
this.$message({
message: `${row.name} 已经被设为默认分类`,
type: 'success',
duration: 1500
})
}).catch(() => {
})
},
// 保存 // 保存
onSave() { onSave() {
this.$refs.managerForm.validate((valid) => { this.$refs.managerForm.validate((valid) => {
@ -200,19 +221,19 @@ export default {
this.addCategory(this.setFormData()) this.addCategory(this.setFormData())
} }
if (this.editMove === 2) { if (this.editMove === 2) {
this.userCategory(this.setFormData()) this.updateCategory(this.setFormData())
} }
} else { } else {
return false; return false;
} }
}); });
}, },
handleEdit(id) { handleEdit() {
this.editMove = 2 this.editMove = 2
this.dialogVisible = true this.dialogVisible = true
this.dialogTitle = '修改分类' this.dialogTitle = '修改分类'
categoryApi.categoryInfo({ categoryApi.categoryInfo({
categoryId: id categoryId: this.multipleSelection[0].id
}).then(res => { }).then(res => {
this.form = res.data this.form = res.data
}) })
@ -238,7 +259,7 @@ export default {
}) })
}, },
// 修改分类 // 修改分类
userCategory(data) { updateCategory(data) {
categoryApi.update(data).then(() => { categoryApi.update(data).then(() => {
this.onSuccess() this.onSuccess()
}).catch(() => { }).catch(() => {
@ -280,7 +301,15 @@ export default {
}, },
onError() { onError() {
this.categoryUpdateLoading = false this.categoryUpdateLoading = false
} },
// 单元格hover进入时事件
cellMouseEnter(row) {
this.cellMouseIndexId = row.id
},
// 单元格hover退出时事件
cellMouseLeave() {
this.cellMouseIndexId = ''
},
} }
} }
</script> </script>