You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.9 KiB

2 years ago
<template>
<div>
<card-container>
<vxe-toolbar>
<template #buttons>
<el-button icon="el-icon-plus" type="primary" size="small" @click="isShowAdd = true">新增</el-button>
<el-button icon="el-icon-search" type="primary" plain size="small" @click="getList"></el-button>
</template>
</vxe-toolbar>
<vxe-table
stripe
style="margin-top: 10px;"
ref="table"
:loading="loading"
keep-source
show-overflow
:column-config="{ resizable: true }"
:edit-rules="validRules"
:edit-config="{ trigger: 'manual', mode: 'row', showStatus: true, isHover: true, autoClear: false }"
:align="allAlign"
:data="tableData">
<vxe-column type="seq" width="58" align="center"></vxe-column>
<vxe-column field="title" width="160" title="名称" :edit-render="{ name: 'input', attrs: { type: 'text'} }"></vxe-column>
<vxe-column field="name" width="160" title="模块" :edit-render="{ name: 'input', attrs: { type: 'text'} }"></vxe-column>
<vxe-column field="sortnumber" width="80" title="排序" align="center" :edit-render="{ name: 'input', attrs: { type: 'number' } }"></vxe-column>
<vxe-column field="operate" title="操作" min-width="220">
<template #default="{ row }">
<template v-if="isActiveStatus(row)">
<el-button size="small" type="primary" @click="saveRowEvent(row)"></el-button>
<el-button size="small" type="primary" plain @click="cancelRowEvent(row)"></el-button>
</template>
<template v-else>
<el-button size="small" type="warning" @click="editRowEvent(row)"></el-button>
<el-button size="small" type="danger" @click="destroyRowEvent(row)"></el-button>
</template>
</template>
</vxe-column>
</vxe-table>
<p class="total" type="primary"> {{ total }} 条数据</p>
</card-container>
<AddModule ref="AddModule" :is-show.sync="isShowAdd" @refresh="getList"></AddModule>
</div>
</template>
<script>
import AddModule from './components/AddModule.vue'
import { deepCopy } from "@/utils"
import { index, save, destroy } from "@/api/module"
export default {
components: {
AddModule
},
data() {
return {
isShowAdd: false,
loading: false,
total: 0,
allAlign: null,
tableData: [],
validRules: {
name: [
{ required: true, message: "请输入模块" }
],
title: [
{ required: true, message: "请输入名称" }
]
},
form: {
id: "",
title: "",
name: "",
sortnumber: 0
}
}
},
methods: {
editRowEvent (row) {
if (this.$refs['table']) {
this.$refs['table'].setEditRow(row)
}
},
cancelRowEvent (row) {
if (this.$refs['table']) {
this.$refs['table'].clearEdit().then(() => {
// 还原行数据
this.$refs['table'].revertData(row)
})
}
},
async getList () {
this.loading = true;
try {
const res = await index()
this.tableData = res.rows;
this.total = res.total;
this.loading = false;
} catch (err) {
console.error(err)
this.loading = false;
}
},
async saveRowEvent (row) {
try {
await this.$confirm("确认保存?","提示",{
confirmButtonText: "确认",
cancelButtonText: "取消"
})
await this.$refs['table'].clearEdit()
let form = deepCopy(this.form)
for (let key in form) {
form[key] = row[key]
}
if (!form.password) {
delete form.password
}
this.loading = true;
await save(form)
await this.getList();
this.loading = false;
} catch (err) {
this.loading = false;
}
},
async destroyRowEvent (row) {
try {
await this.$confirm("确认删除?","提示",{
confirmButtonText: "确认",
cancelButtonText: "取消"
})
this.loading = true;
if (row.id) {
await destroy({
id: row.id
})
await this.getList();
} else {
console.log(row)
this.tableData.splice(this.tableData.findIndex(i => i._X_ROW_KEY === row._X_ROW_KEY),1)
}
this.loading = false;
} catch (err) {
this.loading = false;
}
},
},
computed: {
isActiveStatus () {
return function (row) {
if (this.$refs['table']) {
return this.$refs['table'].isEditByRow(row)
}
}
}
},
created() {
this.getList()
}
}
</script>
<style scoped lang="scss">
.total {
color: #666;
text-align: right;
line-height: 3;
}
::v-deep .el-tag + .el-tag {
margin-left: 4px;
}
</style>