md/src/components/CodemirrorEditor/insertForm.vue

115 lines
2.9 KiB
Vue
Raw Normal View History

2020-05-02 11:50:26 +08:00
<template>
2020-10-13 00:07:14 +08:00
<el-dialog
title="插入表格"
class="insert__dialog"
:visible="value"
@close="$emit('input', false)"
border
>
2020-07-12 20:51:06 +08:00
<el-row class="tb-options" type="flex" align="middle" :gutter="10">
2020-10-13 00:07:14 +08:00
<el-col>
行数
<el-input-number
v-model="rowNum"
controls-position="right"
:min="1"
:max="100"
size="small"
></el-input-number>
</el-col>
<el-col>
列数
<el-input-number
v-model="colNum"
controls-position="right"
:min="1"
:max="100"
size="small"
></el-input-number>
</el-col>
2020-07-12 20:51:06 +08:00
</el-row>
2020-09-02 19:54:39 +08:00
<table style="border-collapse: collapse" class="input-table">
2020-10-13 00:07:14 +08:00
<tr :class="{ 'head-style': row === 1 }" v-for="row in rowNum+1" :key="row">
<td v-for="col in colNum" :key="col">
<el-input
align="center"
v-model="tableData[`k_${row-1}_${col-1}`]"
:placeholder="row===1?'表头':''"
/>
</td>
</tr>
2020-07-12 20:51:06 +08:00
</table>
<div slot="footer" class="dialog-footer">
2020-10-13 00:07:14 +08:00
<el-button :type="btnType" plain @click="$emit('input', false)"> </el-button>
<el-button :type="btnType" @click="insertTable" plain> </el-button>
2020-07-12 20:51:06 +08:00
</div>
2020-10-13 00:07:14 +08:00
</el-dialog>
2020-05-02 11:50:26 +08:00
</template>
<script>
2020-10-13 00:07:14 +08:00
import config from "../../assets/scripts/config";
import {createTable} from '../../assets/scripts/util';
import {
mapState,
mapMutations
} from "vuex";
export default {
props: {
value: {
type: Boolean,
default: false
}
},
data() {
return {
config: config,
rowNum: 3,
colNum: 3,
tableData: {}
};
},
computed: {
btnType() {
return this.nightMode ? "default" : "primary";
2020-07-12 22:55:41 +08:00
},
2020-10-13 00:07:14 +08:00
...mapState({
nightMode: state => state.nightMode,
editor: state => state.editor
})
},
methods: {
// 插入表格
insertTable() {
const cursor = this.editor.getCursor();
const table = createTable({
data: this.tableData,
rows: this.rowNum,
cols: this.colNum
});
this.tableData = {};
this.rowNum = 3;
this.colNum = 3;
this.editor.replaceSelection(`\n${table}\n`, "end");
this.$emit('input', false);
this.editorRefresh();
2020-07-12 22:55:41 +08:00
},
2020-10-13 00:07:14 +08:00
...mapMutations(["editorRefresh"])
}
};
2020-07-12 20:51:06 +08:00
</script>
2020-05-02 11:50:26 +08:00
2020-09-03 09:26:26 +08:00
<style lang="less" scoped>
2020-07-12 20:51:06 +08:00
.tb-options {
2020-07-12 22:55:41 +08:00
margin-bottom: 20px;
2020-05-02 11:50:26 +08:00
}
2020-09-03 09:26:26 +08:00
.input-table ::v-deep .el-input__inner {
border-radius: 0;
2020-09-02 19:54:39 +08:00
}
2020-10-13 00:07:14 +08:00
.head-style /deep/ .el-input__inner {
2020-07-12 22:55:41 +08:00
background-color: #f2f2f2;
2020-07-12 20:51:06 +08:00
}
</style>