Files
dvcp_v2_webapp/packages/bigscreen/designer/components/tableEditor.vue

173 lines
4.3 KiB
Vue
Raw Normal View History

2024-01-22 17:12:32 +08:00
<script>
2024-01-24 10:03:09 +08:00
import AiDialogBtn from "dui/packages/layout/AiDialogBtn.vue";
2024-02-27 17:20:10 +08:00
import Template from "../../../../project/sass/apps/AppAskForm/components/Template.vue";
2024-01-22 17:12:32 +08:00
export default {
name: "tableEditor",
2024-02-27 17:20:10 +08:00
components: {Template, AiDialogBtn},
2024-01-22 18:19:56 +08:00
model: {
event: "input",
prop: "tableData"
},
2024-01-22 17:12:32 +08:00
props: {
2024-01-23 18:17:48 +08:00
label: String,
2024-01-22 17:12:32 +08:00
tableData: {default: () => []},
configs: {default: () => []}
},
2024-01-23 18:17:48 +08:00
data() {
return {
2024-01-24 10:03:09 +08:00
records: [],
form: {}
2024-01-23 18:17:48 +08:00
}
},
2024-01-22 17:12:32 +08:00
computed: {
2024-01-23 18:17:48 +08:00
option() {
return {
size: 'mini',
filterDic: true,
cellBtn: true,
menuWidth: 120,
addBtn: false,
columnBtn: false,
refreshBtn: false,
border: true,
delBtnText: " ",
editBtnText: " ",
saveBtnText: " ",
saveBtnIcon: "el-icon-check",
cancelBtnText: " ",
cancelBtnIcon: "el-icon-close",
column: this.configs.map(e => {
const item = this.$copy(e)
delete item.$index
delete item.$cellEdit
return {...item, cell: true}
})
}
},
2024-02-27 17:20:10 +08:00
columns:v=>v.configs
2024-01-23 18:17:48 +08:00
},
methods: {
rowSave(form, done) {
this.$emit("input", this.records)
this.$emit("data", this.getFormatData())
done()
},
2024-01-24 10:03:09 +08:00
rowDel(form, index) {
this.$confirm("是否要删除该行?").then(() => {
this.records.splice(index, 1)
this.$emit("data", this.getFormatData())
}).catch(() => 0)
},
2024-01-23 18:17:48 +08:00
getFormatData() {
return this.configs.map((c, i) => {
const item = {name: c.label}
this.records.map((row, j) => item[`v${j || ""}`] = row[`c${i || ""}`])
return item
})
2024-01-24 10:03:09 +08:00
},
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)
})
2024-01-23 18:17:48 +08:00
}
2024-01-22 17:12:32 +08:00
},
2024-01-22 18:19:56 +08:00
created() {
2024-01-23 18:17:48 +08:00
this.records = this.tableData.map(e => ({$cellEdit: true, ...e}))
2024-01-22 18:19:56 +08:00
}
2024-01-22 17:12:32 +08:00
}
</script>
<template>
<section class="tableEditor">
2024-01-24 10:03:09 +08:00
<avue-crud :option="option" :data="records" @row-save="rowSave" @row-cancel="rowSave" @row-del="rowDel">
2024-02-27 17:20:10 +08:00
<template v-for="c in columns" :slot="`${c.prop}Header`" slot-scope="{column = {}}">
<el-input class="headerInput" v-model="column.label" clearable placeholder="请输入列名" @change="$emit('update:configs', columns)"/>
</template>
2024-01-23 18:17:48 +08:00
<template v-if="label" v-slot:menuLeft>
<div class="label" v-text="label"/>
</template>
<template v-slot:menuRight>
2024-01-24 10:03:09 +08:00
<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>
2024-01-23 18:17:48 +08:00
</template>
</avue-crud>
2024-01-22 17:12:32 +08:00
</section>
</template>
2024-01-22 18:19:56 +08:00
<style scoped lang="scss">
.tableEditor {
width: 100%;
height: auto;
2024-01-23 18:17:48 +08:00
margin-bottom: 10px;
:deep(.avue-crud__body) {
background-color: transparent;
.avue-crud__header, .el-table, tr {
background-color: transparent;
}
.avue-crud__header {
min-height: unset;
}
.el-table__cell {
color: white;
2024-01-24 10:03:09 +08:00
background-color: #1D2127;
2024-01-23 18:17:48 +08:00
input:disabled {
background-color: transparent;
border-color: transparent;
color: white;
padding: 0;
}
2024-01-24 10:03:09 +08:00
&:last-of-type {
border-left: 1px solid #fff;
}
2024-01-23 18:17:48 +08:00
}
.label {
width: 60px;
color: #FFFFFF;
font-size: 12px;
text-align: right;
}
.el-icon-plus {
font-size: 12px;
color: $primaryColor;
2024-01-24 10:03:09 +08:00
line-height: 18px;
2024-01-23 18:17:48 +08:00
&:before {
margin-right: 4px;
}
}
}
2024-01-22 18:19:56 +08:00
2024-01-23 18:17:48 +08:00
&:last-of-type {
margin-bottom: 0;
2024-01-22 18:19:56 +08:00
}
2024-02-27 17:20:10 +08:00
:deep(.headerInput) {
.el-input__inner {
padding: 0;
border: none;
background: transparent;
}
}
2024-01-22 18:19:56 +08:00
}
</style>