源碼
<template>
<!--
前往https://blog.csdn.net/qq_37860634/article/details/136141769
查看使用說明
-->
<div :class="$options.name">
<div class="sg-head">表格數(shù)據(jù)生成工具</div>
<div class="sg-container">
<div class="sg-start">
<div style="margin-bottom: 10px">字段中文名</div>
<el-input
style="margin-bottom: 10px"
type="textarea"
:placeholder="`請粘貼字段中文名`"
v-model="textareaValue1"
:rows="30"
show-word-limit
/>
<el-button type="primary" @click="createResult">生成表格數(shù)據(jù)</el-button>
</div>
<div class="sg-center">→</div>
<div class="sg-end">
<div style="margin-bottom: 10px">生成結(jié)果</div>
<el-input
style="margin-bottom: 10px"
type="textarea"
:placeholder="`請復(fù)制結(jié)果`"
v-model="textareaValue2"
:rows="30"
show-word-limit
/>
<el-button type="primary" @click="copyResult">復(fù)制</el-button>
</div>
</div>
</div>
</template>
<script>
import pinyin from "@/js/pinyin";
export default {
name: "sgCreateTableData",
data() {
return {
textareaValue1: "",
textareaValue2: "",
};
},
watch: {
textareaValue1(newValue, oldValue) {
newValue && this.createResult(newValue);
},
},
methods: {
createResult(d) {
let texts = this.textareaValue1
.split("\n")
.map((v) => v.split("\t").join("").trim());
texts = texts.filter((v, i, ar) => v !== ``);
let rowData = {};
texts.map((v) => {
let cn_col = v;
let py_col = pinyin.getCamelChars(v);
rowData[py_col] = cn_col;
});
let data = [...Array(5)].map((v) => {
return Object.assign({}, { ID: this.$g.UUID() }, rowData);
});
this.textareaValue2 = JSON.stringify(data, null, 2);
this.copyResult(); //自動復(fù)制生成結(jié)果
},
copyResult(d) {
this.$g.copy(this.textareaValue2, true);
},
},
};
</script>
<style lang="scss" scoped>
.sgCreateTableData {
width: 100%;
height: 100%;
position: absolute;
box-sizing: border-box;
padding: 20px;
.sg-head {
display: flex;
// justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
color: #409eff;
margin-bottom: 10px;
}
.sg-container {
display: flex;
flex-wrap: nowrap;
& > .sg-start {
width: calc(50% - 20px);
flex-shrink: 0;
}
& > .sg-center {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
margin: 0 10px;
font-size: 24px;
color: #409eff;
font-weight: bold;
}
& > .sg-end {
width: calc(50% - 20px);
flex-shrink: 0;
}
>>> textarea {
max-height: revert;
height: calc(100vh - 200px);
word-wrap: break-word;
word-break: break-all;
white-space: break-spaces;
}
}
}
</style>
?文章來源地址http://www.zghlxwxcb.cn/news/detail-834497.html文章來源:http://www.zghlxwxcb.cn/news/detail-834497.html
?
到了這里,關(guān)于【sgCreateTableData】自定義小工具:敏捷開發(fā)→自動化生成表格數(shù)據(jù)數(shù)組[基于el-table]的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!