Files
dvcp_v2_webapp/packages/publicity/AppContentManage/components/List.vue

178 lines
5.5 KiB
Vue
Raw Normal View History

2021-12-18 17:16:42 +08:00
<template>
<ai-list class="notice">
<template slot="title">
<ai-title title="内容管理" isShowBottomBorder></ai-title>
</template>
<template slot="content">
<ai-search-bar class="search-bar">
<template #left>
2022-07-06 11:12:15 +08:00
<el-button size="small" type="primary" icon="iconfont iconAdd" @click="toAdd()">添加模块</el-button>
2021-12-18 17:16:42 +08:00
</template>
</ai-search-bar>
<ai-table
2022-06-06 09:16:39 +08:00
:tableData="tableData"
:col-configs="colConfigs"
:total="total" :dict="dict"
style="margin-top: 6px;"
:current.sync="search.current"
:size.sync="search.size"
@getList="getList">
2022-03-18 14:30:56 +08:00
<el-table-column slot="options" width="160px" fixed="right" label="操作" align="center">
2021-12-18 17:16:42 +08:00
<template slot-scope="{ row }">
<div class="table-options">
<el-button type="text" @click="toAdd(row.id)">编辑</el-button>
2022-07-06 11:12:15 +08:00
<el-button type="text" @click="getCateList(row.id),isShowAdd = true">分类</el-button>
2021-12-18 17:16:42 +08:00
<el-button type="text" @click="remove(row.id)">删除</el-button>
</div>
</template>
</el-table-column>
</ai-table>
2022-07-06 11:12:15 +08:00
<ai-dialog :visible.sync="isShowAdd" width="880px" height="580px" title="文章分类" @close="onClose" @onConfirm="submitCategory">
<el-button icon="iconfont iconAdd" type="text" @click="cateList.push({error:false,categoryName:null})">添加分类</el-button>
<ai-table v-if="moduleId" :tableData="cateList" :col-configs="cateColConfigs" :isShowPagination="false" @getList="getCateList">
<el-table-column slot="category" label="分类名称" align="center">
<template slot-scope="{row}">
<ai-edit-input v-model="row.categoryName" :error.sync="row.error"/>
</template>
</el-table-column>
2021-12-18 17:16:42 +08:00
<el-table-column slot="options" width="220px" fixed="right" label="操作" align="center">
2022-07-06 11:12:15 +08:00
<template slot-scope="{ row,$index }">
<el-button type="text" @click="handleMove(row,$index,-1)" :disabled="$index==0">上移</el-button>
<el-button type="text" @click="handleMove(row,$index,1)" :disabled="$index==(cateList.length-1)">下移</el-button>
<el-button type="text" @click="removeCate($index)">删除</el-button>
2021-12-18 17:16:42 +08:00
</template>
</el-table-column>
</ai-table>
</ai-dialog>
</template>
</ai-list>
</template>
<script>
2022-07-06 11:12:15 +08:00
import AiEditInput from "./AiEditInput";
2022-06-06 09:16:39 +08:00
export default {
name: 'List',
2022-07-06 11:12:15 +08:00
components: {AiEditInput},
2022-06-06 09:16:39 +08:00
props: {
instance: Function,
dict: Object
},
data() {
return {
search: {
current: 1,
size: 10,
title: ''
},
moduleId: '',
total: 10,
cateList: [],
colConfigs: [
{prop: 'moduleName', label: '模块名称', align: 'left', width: '200px'},
{prop: 'menuName', label: '关联菜单', align: 'center'},
{prop: 'categoryStr', label: '文章分类', align: 'center'},
{prop: 'needExamine', label: '是否审核', align: 'center', dict: 'yesOrNo'},
{prop: 'isComment', label: '是否可以评论', align: 'center', dict: 'yesOrNo'}
],
cateColConfigs: [
2022-07-06 11:12:15 +08:00
{type: 'index', label: "排序", align: 'center'},
{slot: 'category'}
2022-06-06 09:16:39 +08:00
],
isShowAdd: false,
tableData: []
}
},
2021-12-18 17:16:42 +08:00
2022-06-06 09:16:39 +08:00
mounted() {
this.getList()
},
2021-12-18 17:16:42 +08:00
2022-06-06 09:16:39 +08:00
methods: {
getList() {
this.instance.post(`/app/appcontentmoduleinfo/list`, null, {
params: {
...this.search
}
}).then(res => {
if (res.code == 0) {
this.tableData = res.data.records
this.total = res.data.total
}
})
2021-12-18 17:16:42 +08:00
},
2022-07-06 11:12:15 +08:00
getCateList(moduleId) {
this.moduleId = moduleId
2022-06-06 09:16:39 +08:00
this.instance.post(`/app/appcontentmodulecategory/list`, null, {
2022-07-06 11:12:15 +08:00
params: {size: 99999, moduleId}
2022-06-06 09:16:39 +08:00
}).then(res => {
2022-07-06 11:12:15 +08:00
if (res?.data) {
this.cateList = res.data.records.map(e => ({...e, error: false}))
2022-06-06 09:16:39 +08:00
}
})
2021-12-18 17:16:42 +08:00
},
2022-07-06 11:12:15 +08:00
removeCate(i) {
2022-06-06 09:16:39 +08:00
this.$confirm('确定删除该数据?').then(() => {
2022-07-06 11:12:15 +08:00
this.cateList.splice(i, 1)
2022-06-06 09:16:39 +08:00
})
},
2022-07-06 11:12:15 +08:00
handleMove(row, i, forward) {
const tmp = this.$copy(row), target = i + forward
this.cateList.splice(i, 1, this.cateList[target])
this.cateList.splice(target, 1, tmp)
},
2022-06-06 09:16:39 +08:00
remove(id) {
this.$confirm('确定删除该数据?').then(() => {
this.instance.post(`/app/appcontentmoduleinfo/delete?ids=${id}`).then(res => {
2021-12-18 17:16:42 +08:00
if (res.code == 0) {
2022-06-06 09:16:39 +08:00
this.$message.success('删除成功!')
this.getList()
2021-12-18 17:16:42 +08:00
}
})
2022-06-06 09:16:39 +08:00
})
},
2022-07-06 11:12:15 +08:00
submitCategory() {
if (!this.cateList.some((e, i, arr) => {
arr[i].error = !e.categoryName
if (!e.categoryName) {
this.$message.error(`${i + 1}行未填写分类名称!`)
return true
2021-12-23 16:10:20 +08:00
}
2022-07-06 11:12:15 +08:00
})) {
const {cateList: categorys, moduleId} = this
this.instance.post(`/app/appcontentmodulecategory/addOrUpdate2`, {
categorys, moduleId
}).then(res => {
if (res?.code == 0) {
this.$message.success('提交成功')
this.isShowAdd = false
this.getList()
}
})
}
2022-06-06 09:16:39 +08:00
},
onClose() {
this.moduleId = ''
2022-07-06 11:12:15 +08:00
this.cateList = []
2022-06-06 09:16:39 +08:00
},
2021-12-18 17:16:42 +08:00
2022-06-06 09:16:39 +08:00
toAdd(id) {
this.$emit('change', {
type: 'Add',
2022-07-06 11:12:15 +08:00
params: {id}
2022-06-06 09:16:39 +08:00
})
2021-12-18 17:16:42 +08:00
}
}
2022-06-06 09:16:39 +08:00
}
2021-12-18 17:16:42 +08:00
</script>
<style lang="scss" scoped>
2022-06-06 09:16:39 +08:00
.notice {
.catewrapper {
display: flex;
align-items: center;
2021-12-18 17:16:42 +08:00
}
2022-06-06 09:16:39 +08:00
}
2021-12-18 17:16:42 +08:00
</style>