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

260 lines
7.4 KiB
Vue

7 months ago
<template>
<div style="padding: 8px">
<el-card shadow="never" style="border-radius: 6px">
<el-form :inline="true" :model="queryForm" class="demo-form-inline">
<el-form-item label="模版名称">
<el-input v-model="queryForm.templateName" placeholder="模版名称"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="queryModels"></el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" style="border-radius: 6px;margin-top: 12px">
<el-button type="primary" @click="addModels"></el-button>
<el-table
v-loading="load"
:data="tableData"
style="width: 100%"
>
<el-table-column
v-if="false"
prop="templateId">
</el-table-column>
<el-table-column
prop="templateName"
label="名称">
</el-table-column>
<el-table-column
label="缩略图">
<template slot-scope="scope">
<div class="miniLayout">
<component :is="JSON.parse(scope.row.templateContent).center"
:tree="JSON.parse(scope.row.templateContent).centerChildren"></component>
</div>
</template>
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="120">
<template slot-scope="scope">
<el-button @click="queryModelInfo(scope.row)" type="text" size="small" style="padding: 0 4px">修改</el-button>
<el-popconfirm
title="确定删除吗?"
@confirm="delModelOk(scope.row.templateId)">
<el-button slot="reference" type="text" size="small" style="padding: 0 4px">删除</el-button>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<div style="margin-top: 12px">
<el-pagination
style="display: flex;justify-content: flex-end;"
@size-change="getList"
@current-change="getList"
:current-page.sync="queryForm.pageNum"
:page-sizes="[10,20,50,100]"
:page-size="queryForm.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
</el-card>
<el-dialog
:title="dialogTitle1"
:visible.sync="addModelDialog"
:append-to-body="true"
width="30%">
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="模型名称">
<el-input v-model="form.templateName"></el-input>
</el-form-item>
<el-form-item label="模型内容">
<div class="layout" ref="layout">
<component :is="form.templateContent.center" :tree="form.templateContent.centerChildren"></component>
</div>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="addModelOk" v-if="dialogTitle1 === '新增模型'"> </el-button>
<el-button type="primary" @click="changeModel" v-if="dialogTitle1 === '修改模型'"> </el-button>
<el-button @click="addModelDialog = false"> </el-button>
</span>
</el-dialog>
<el-dialog
title="提示"
:visible.sync="dialogVisible"
:append-to-body="true"
width="30%">
<el-button type="primary" @click="leftRight"></el-button>
<el-button type="primary" @click="upDown"></el-button>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import LeftRight from '../../components/setLayout/leftRightStr'
import UpDown from '../../components/setLayout/upDownStr'
import {addModel, delModel, queryModel, updateModel} from "@/api/configuration/layoutModel";
export default {
name: 'Layout',
components: {
LeftRight: () => import('../../components/setLayout/leftRightStr'),
UpDown: () => import('../../components/setLayout/upDownStr')
},
data() {
return {
load: false,
dialogTitle1: '',
addModelDialog: false,
tree: {},
dialogVisible: false,
queryForm: {
pageNum: 1,
pageSize: 10,
},
total: 0,
form: {
templateName: '',
templateContent: {
center: null,
centerChildren: {}
}
},
tableData: []
}
},
mounted() {
this.queryModels()
},
methods: {
getList() {
console.log(this.queryForm)
this.load = true
queryModel(this.queryForm).then(e => {
console.log(e)
this.tableData = e.rows
this.load = false
this.total = e.total
})
},
queryModels() {
this.queryForm = {
pageNum: 1,
pageSize: 10,
}
this.getList()
},
addModels() {
this.dialogTitle1 = '新增模型'
this.form = {
templateName: '',
templateContent: {
center: null,
centerChildren: {}
}
}
this.addModelDialog = true
this.$nextTick(() => {
this.$refs.layout.addEventListener('contextmenu', (event) => {
event.preventDefault()
if (!this.form.templateContent.center) {
this.dialogVisible = true
}
})
})
},
leftRight() {
this.$set(this.form.templateContent, 'center', 'LeftRight')
this.$set(this.form.templateContent.centerChildren, 'separate', 50)
this.dialogVisible = false
},
upDown() {
this.$set(this.form.templateContent, 'center', 'UpDown')
this.$set(this.form.templateContent.centerChildren, 'separate', 50)
this.dialogVisible = false
},
addModelOk() {
addModel({
templateName: this.form.templateName,
templateContent: JSON.stringify(this.form.templateContent)
}).then(e => {
this.$message({
message: '添加成功',
type: 'success'
});
this.getList()
this.addModelDialog = false
})
},
queryModelInfo(e) {
this.dialogTitle1 = '修改模型'
this.form = {
templateId: e.templateId,
templateName: e.templateName,
templateContent: JSON.parse(e.templateContent)
}
this.addModelDialog = true
this.$nextTick(() => {
this.$refs.layout.addEventListener('contextmenu', (event) => {
event.preventDefault()
if (!this.form.templateContent.center) {
this.dialogVisible = true
}
})
})
},
changeModel() {
updateModel({
templateId: this.form.templateId,
templateName: this.form.templateName,
templateContent: JSON.stringify(this.form.templateContent)
}).then(e => {
this.$message({
message: '修改成功',
type: 'success'
});
this.getList()
this.addModelDialog = false
})
},
delModelOk(e) {
delModel({
templateId: e
}).then(e => {
this.$message({
message: '删除成功',
type: 'success'
});
this.getList()
})
},
}
}
</script>
<style lang="less" scoped>
.layout {
height: 500px;
border: 1px solid #0003;
}
.miniLayout {
width: 30px;
height: 30px;
border: 1px solid #0003;
pointer-events: none
}
</style>