静态数据编辑器改造完成

This commit is contained in:
aixianling
2024-01-24 10:03:09 +08:00
parent f77d943ba6
commit d18b879873

View File

@@ -1,8 +1,10 @@
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import AiDialogBtn from "dui/packages/layout/AiDialogBtn.vue";
export default { export default {
name: "tableEditor", name: "tableEditor",
components: {AiDialogBtn},
model: { model: {
event: "input", event: "input",
prop: "tableData" prop: "tableData"
@@ -14,7 +16,8 @@ export default {
}, },
data() { data() {
return { return {
records: [] records: [],
form: {}
} }
}, },
computed: { computed: {
@@ -49,12 +52,26 @@ export default {
this.$emit("data", this.getFormatData()) this.$emit("data", this.getFormatData())
done() done()
}, },
rowDel(form, index) {
this.$confirm("是否要删除该行?").then(() => {
this.records.splice(index, 1)
this.$emit("data", this.getFormatData())
}).catch(() => 0)
},
getFormatData() { getFormatData() {
return this.configs.map((c, i) => { return this.configs.map((c, i) => {
const item = {name: c.label} const item = {name: c.label}
this.records.map((row, j) => item[`v${j || ""}`] = row[`c${i || ""}`]) this.records.map((row, j) => item[`v${j || ""}`] = row[`c${i || ""}`])
return item return item
}) })
},
addColumn() {
return this.$refs.addColumn.validate().then(() => {
const cols = this.$copy(this.configs)
const prop = `c${cols.length}`
cols.push({label: this.form.label, prop})
return this.$emit("update:configs", cols)
})
} }
}, },
created() { created() {
@@ -70,12 +87,22 @@ export default {
<template> <template>
<section class="tableEditor"> <section class="tableEditor">
<avue-crud :option="option" :data="records" @row-save="rowSave" @row-cancel="rowSave"> <avue-crud :option="option" :data="records" @row-save="rowSave" @row-cancel="rowSave" @row-del="rowDel">
<template v-if="label" v-slot:menuLeft> <template v-if="label" v-slot:menuLeft>
<div class="label" v-text="label"/> <div class="label" v-text="label"/>
</template> </template>
<template v-slot:menuRight> <template v-slot:menuRight>
<div class="el-icon-plus pointer" @click="records.push({$cellEdit: true})">增加数据</div> <div class="flex">
<ai-dialog-btn dialogTitle="增加列" appendToBody :submit="addColumn" @closed="form={}" width="400px">
<div slot="btn" class="el-icon-plus pointer">增加列</div>
<el-form ref="addColumn" :model="form" size="small" labelWidth="60px">
<el-form-item label="列名" :rule="{required:true, message:'请输入列名'}">
<el-input v-model="form.label" clearable placeholder="请输入列名"/>
</el-form-item>
</el-form>
</ai-dialog-btn>
<div class="el-icon-plus pointer mar-l8" @click="records.push({$cellEdit: true})">增加数据</div>
</div>
</template> </template>
</avue-crud> </avue-crud>
</section> </section>
@@ -99,7 +126,7 @@ export default {
.el-table__cell { .el-table__cell {
color: white; color: white;
background-color: transparent; background-color: #1D2127;
input:disabled { input:disabled {
background-color: transparent; background-color: transparent;
@@ -107,6 +134,10 @@ export default {
color: white; color: white;
padding: 0; padding: 0;
} }
&:last-of-type {
border-left: 1px solid #fff;
}
} }
.label { .label {
@@ -119,6 +150,7 @@ export default {
.el-icon-plus { .el-icon-plus {
font-size: 12px; font-size: 12px;
color: $primaryColor; color: $primaryColor;
line-height: 18px;
&:before { &:before {
margin-right: 4px; margin-right: 4px;