预览代码界面增加复制代码按钮,方便使用。

This commit is contained in:
keyleaf 2021-05-26 12:08:25 +08:00
parent 1610407c91
commit 52d30edcf2

View File

@ -162,6 +162,9 @@
/> />
<!-- 预览界面 --> <!-- 预览界面 -->
<el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body> <el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body>
<el-button class="copy-btn-main" icon="el-icon-document-copy" type="text" @click="execCopy">
复制代码
</el-button>
<el-tabs v-model="preview.activeName"> <el-tabs v-model="preview.activeName">
<el-tab-pane <el-tab-pane
v-for="(value, key) in preview.data" v-for="(value, key) in preview.data"
@ -174,12 +177,14 @@
</el-tabs> </el-tabs>
</el-dialog> </el-dialog>
<import-table ref="import" @ok="handleQuery" /> <import-table ref="import" @ok="handleQuery" />
<input id="copyNode" type="hidden">
</div> </div>
</template> </template>
<script> <script>
import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen"; import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
import importTable from "./importTable"; import importTable from "./importTable";
import ClipboardJS from 'clipboard'
import { downLoadZip } from "@/utils/zipdownload"; import { downLoadZip } from "@/utils/zipdownload";
import hljs from "highlight.js/lib/highlight"; import hljs from "highlight.js/lib/highlight";
import "highlight.js/styles/github-gist.css"; import "highlight.js/styles/github-gist.css";
@ -231,6 +236,24 @@ export default {
} }
}; };
}, },
mounted() {
const clipboard = new ClipboardJS('#copyNode', {
text: trigger => {
const suffix = this.preview.activeName.substring(this.preview.activeName.indexOf(".") + 1)
const key = 'vm/' + suffix + '/' + this.preview.activeName + '.vm'
const codeStr = this.preview.data[key]
this.$notify({
title: '成功',
message: '代码已复制到剪切板,可粘贴。',
type: 'success'
})
return codeStr
}
})
clipboard.on('error', e => {
this.$message.error('代码复制失败')
})
},
created() { created() {
this.getList(); this.getList();
}, },
@ -334,6 +357,9 @@ export default {
this.getList(); this.getList();
this.msgSuccess("删除成功"); this.msgSuccess("删除成功");
}) })
},
execCopy(data) {
document.getElementById('copyNode').click()
} }
} }
}; };