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.

190 lines
5.3 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
2 years ago
ref="table"
2 years ago
stripe
style="margin-top: 10px;"
: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"
2 years ago
:data="tableData"
>
<vxe-column type="seq" width="58" align="center" />
<vxe-column field="title" width="160" title="名称" :edit-render="{ name: 'input', attrs: { type: 'text'} }" />
<vxe-column field="name" width="160" title="模块" :edit-render="{ name: 'input', attrs: { type: 'text'} }" />
<vxe-column field="sortnumber" width="80" title="排序" align="center" :edit-render="{ name: 'input', attrs: { type: 'number' } }" />
2 years ago
<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>
2 years ago
<el-button size="small" type="primary" @click="showModuleAuth(row)"></el-button>
2 years ago
<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>
2 years ago
<AddModule ref="AddModule" :is-show.sync="isShowAdd" @refresh="getList" />
<ModuleAuth ref="ModuleAuth" :is-show.sync="isShowDrawer" />
2 years ago
</div>
</template>
<script>
2 years ago
import ModuleAuth from './components/ModuleAuth.vue'
2 years ago
import AddModule from './components/AddModule.vue'
2 years ago
import { deepCopy } from '@/utils'
import { index, save, destroy } from '@/api/module'
2 years ago
export default {
components: {
2 years ago
AddModule,
ModuleAuth
2 years ago
},
data() {
return {
2 years ago
isShowDrawer: false,
2 years ago
isShowAdd: false,
loading: false,
total: 0,
allAlign: null,
tableData: [],
validRules: {
name: [
2 years ago
{ required: true, message: '请输入模块' }
2 years ago
],
title: [
2 years ago
{ required: true, message: '请输入名称' }
2 years ago
]
},
form: {
2 years ago
id: '',
title: '',
name: '',
2 years ago
sortnumber: 0
}
}
},
2 years ago
computed: {
isActiveStatus() {
return function(row) {
if (this.$refs['table']) {
return this.$refs['table'].isEditByRow(row)
}
}
}
},
created() {
this.getList()
},
2 years ago
methods: {
2 years ago
showModuleAuth(row) {
2 years ago
this.$refs['ModuleAuth'].setId(row.id)
2 years ago
this.isShowDrawer = true
},
2 years ago
editRowEvent(row) {
2 years ago
if (this.$refs['table']) {
this.$refs['table'].setEditRow(row)
}
},
2 years ago
cancelRowEvent(row) {
2 years ago
if (this.$refs['table']) {
this.$refs['table'].clearEdit().then(() => {
// 还原行数据
this.$refs['table'].revertData(row)
})
}
},
2 years ago
async getList() {
this.loading = true
2 years ago
try {
const res = await index()
2 years ago
this.tableData = res.rows
this.total = res.total
this.loading = false
2 years ago
} catch (err) {
console.error(err)
2 years ago
this.loading = false
2 years ago
}
},
2 years ago
async saveRowEvent(row) {
2 years ago
try {
2 years ago
const errMap = await this.$refs['table'].validate()
if (errMap) {
throw new Error(errMap)
}
2 years ago
await this.$confirm('确认保存?', '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消'
2 years ago
})
await this.$refs['table'].clearEdit()
2 years ago
const form = deepCopy(this.form)
for (const key in form) {
2 years ago
form[key] = row[key]
}
if (!form.password) {
delete form.password
}
2 years ago
this.loading = true
2 years ago
await save(form)
2 years ago
await this.getList()
this.loading = false
2 years ago
} catch (err) {
2 years ago
this.loading = false
2 years ago
}
},
2 years ago
async destroyRowEvent(row) {
2 years ago
try {
2 years ago
await this.$confirm('确认删除?', '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消'
2 years ago
})
2 years ago
this.loading = true
2 years ago
if (row.id) {
await destroy({
id: row.id
})
2 years ago
await this.getList()
2 years ago
} else {
console.log(row)
2 years ago
this.tableData.splice(this.tableData.findIndex(i => i._X_ROW_KEY === row._X_ROW_KEY), 1)
2 years ago
}
2 years ago
this.loading = false
2 years ago
} catch (err) {
2 years ago
this.loading = false
2 years ago
}
}
}
}
</script>
<style scoped lang="scss">
.total {
color: #666;
text-align: right;
line-height: 3;
}
::v-deep .el-tag + .el-tag {
margin-left: 4px;
}
</style>