x-php-Admin/src/views/system/table/index.vue

131 lines
3.6 KiB
Vue
Raw Normal View History

2023-06-07 10:48:30 +00:00
<template>
<el-container>
<el-header>
<div class="left-panel">
<el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
</div>
</el-header>
<el-main class="nopadding">
2023-06-20 11:03:48 +00:00
<scTable ref="table" :tableColumn="column" :api="api" row-key="id" @selection-change="selectionChange" :remoteSort="true" :remoteFilter="true" stripe>
2023-06-07 10:48:30 +00:00
<el-table-column type="selection" width="50"></el-table-column>
2023-06-20 11:03:48 +00:00
<el-table-column min-width="1" label="操作" :width="(Object.keys(operation).length*50)+22" fixed="right" align="left" v-if="Object.keys(operation).length>0">
<template #default="scope">
<el-button-group>
<el-button v-if="operation.edit" type="primary" size="small" @click="table_edit(scope.row, scope.$index)">{{ operation.edit.name || '编辑' }}</el-button>
<el-popconfirm v-if="operation.delete" :title="operation.delete.title || '确定删除吗?'" @confirm="table_del(scope.row, scope.$index)">
<template #reference>
<el-button type="info" size="small">{{ operation.delete.name || '删除' }}</el-button>
</template>
</el-popconfirm>
</el-button-group>
</template>
</el-table-column>
2023-06-07 10:48:30 +00:00
</scTable>
</el-main>
</el-container>
2023-06-20 11:03:48 +00:00
<save-dialog v-if="dialog.save" :column="column" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
2023-06-07 10:48:30 +00:00
</template>
<script>
import saveDialog from './save'
export default {
2023-06-20 11:03:48 +00:00
name: 'propertyAuth',
2023-06-07 10:48:30 +00:00
components: {
saveDialog
},
data() {
return {
dialog: {
save: false
},
2023-06-19 14:55:32 +00:00
selection: [],
2023-06-20 11:03:48 +00:00
column: [],
api: '',
operation:{
// delete:'1',
// edit:'1',
}
2023-06-07 10:48:30 +00:00
}
},
mounted() {
2023-06-20 11:03:48 +00:00
//判断是否开启自定义列
if(this.$route.meta.tablename) {
this.$http.get('system/table/get', { name: this.$route.meta.tablename }, { cache:0 }).then((res) => {
if (res.code == 200) {
Object.assign(this.$data, res.data);
}
});
}
2023-06-07 10:48:30 +00:00
},
methods: {
//增加
add(){
this.dialog.save = true
this.$nextTick(() => {
this.$refs.saveDialog.open()
})
},
//编辑
table_edit(row){
this.dialog.save = true
this.$nextTick(() => {
this.$refs.saveDialog.open('edit').setData(row)
})
},
//删除
async table_del(row, index){
var reqData = {id: row.id}
2023-06-11 14:57:10 +00:00
var res = await this.$api.demo.post.post(reqData);
2023-06-07 10:48:30 +00:00
if(res.code == 200){
//这里选择刷新整个表格 OR 插入/编辑现有表格数据
this.$refs.table.tableData.splice(index, 1);
this.$message.success("删除成功")
}else{
this.$alert(res.message, "提示", {type: 'error'})
}
},
//批量删除
async batch_del(){
this.$confirm(`确定删除选中的 ${this.selection.length} 项吗?`, '提示', {
type: 'warning'
}).then(() => {
const loading = this.$loading();
this.selection.forEach(item => {
this.$refs.table.tableData.forEach((itemI, indexI) => {
if (item.id === itemI.id) {
this.$refs.table.tableData.splice(indexI, 1)
}
})
})
loading.close();
this.$message.success("操作成功")
}).catch(() => {
})
},
//表格选择后回调事件
selectionChange(selection){
this.selection = selection;
},
//本地更新数据
handleSuccess(data, mode){
if(mode=='add'){
data.id = new Date().getTime()
this.$refs.table.tableData.unshift(data)
}else if(mode=='edit'){
this.$refs.table.tableData.filter(item => item.id===data.id ).forEach(item => {
Object.assign(item, data)
})
}
}
}
}
</script>
<style>
</style>