123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <template>
- <div class="excelHtnl">
- <div
- class="excelBox hc-excel-table-form"
- style="margin-top:40px;height: 100%;"
- @click="parentClick($event)"
- >
- <div style="width:100%;height: 100%;overflow: scroll;" class='parent' id='parent'></div>
-
- </div>
- </div>
- </template>
- <script>
- import Vue from 'vue'
- import {getExcelHtml} from '@/api/exctab/excelmodel'
- export default {
- props: ['pkeyId'],
- data() {
- return {
- selectedElements: [] ,// 存储已选中的元素
- exHtml:''
- }
- },
- watch: {
- pkeyId: {
- immediate: true,
- deep: true,
- handler(newVal) {
- if(newVal) {
- this.exHtml = ''
- this.getExcelHtml(newVal)// 重新初始化数据
-
- }else {
- this.exHtml = ''
- this.clearForm()
- }
- }
- }
- },
- mounted() {
-
- },
- methods: {
- async getExcelHtml(pkeyId) {
- const {data: res} = await getExcelHtml({pkeyId})
- if (res.code === 200) {
- this.exHtml = res.data
- this.cop();
- }
- },
- // 新增清空表单方法
- clearForm() {
- const parentElement = document.getElementById('parent')
- console.log(parentElement, 'parentElement');
-
- if(parentElement) {
- // 清空父元素内容
- parentElement.innerHTML = ''
- }
- // 清空已选中元素
- this.clearAllSelected()
- },
- async cop() {
- let _that = this
- var MyComponent = await Vue.extend({
- template: this.exHtml ,
- data() {
- return {
- formData: {},
- getTokenHeader: {},
- dap_site_data: {}
- }
- },
- methods: {
- contextmenuClick(tr, td, x1, x2, y1, y2, event) {
- },
- getInformation(name, tr, td) {//鼠标右键事件
-
- },
- formUploadSuccess() {
- },
- formUploadExceed() {
- },
- formUploadLoading() {
- },
- delTableFormFile() {
- },
- formUploadError() {
- },
- uploadprogress() {
- },
- formRemoteMethod() {
- },
- getRegularExpression() {
- },
- checkboxGroupChange() {
- },
- formRemoteChange() {
- },
- dateKeydown() {
- },
- keyupShiftUp() {
- },
- keyupShiftDown() {
- },
- keyupShiftLeft() {
- },
- keyupShiftRight() {
- },
- inputLeftClick() {
- },
- }
- })
- var component = new MyComponent().$mount()
- document.getElementById('parent').appendChild(component.$el);
- },
-
- //excel父节点点击检测
- async parentClick(e) {
- let target = e.target;
- const elementId = target.id;
- const keyName = target.placeholder;
- // 判断元素是否已选中
- const index = this.selectedElements.findIndex(item => item.elementId === elementId);
- if (index === -1) {
- // 添加选中效果
- target.style.backgroundColor = '#ffa500'; // 橙色背景
- this.selectedElements.push({elementId, keyName}); // 存储选中元素的id和keyName
- } else {
- // 取消选中效果
- target.style.backgroundColor = ''; // 恢复默认背景
- this.selectedElements.splice(index, 1);
- }
-
- // 触发选中元素变化事件
- this.$emit('element-selected', this.selectedElements);
-
- },
- // 清除所有选中状态的方法
- clearAllSelected() {
- this.selectedElements.forEach(item => {
- const element = document.getElementById(item.elementId);
- if (element) {
- element.style.backgroundColor = '';
- }
- });
- this.selectedElements = [];
- },
- getParentTD(ele) {
- let targetParent = ele.parentNode;
- while (targetParent.nodeName !== "TD") {
- if (targetParent.id == 'parent') {
- return null;
- }
- targetParent = targetParent.parentNode;
- }
- return targetParent;
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- .excelHtnl {
- margin: 0 0 0 10px;
- background-color: #fff;
- box-sizing: border-box;
- padding: 0 20px 100px 20px;
- height: 100%;
- }
- // 设置图片样式
- .hc-upload-table-form {
- position: relative;
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .hc-upload-table-form .el-upload {
- position: relative;
- flex: 1;
- height: 100%;
- color: #ccc;
- }
- .hc-upload-table-form .el-upload .hc-table-form-icon {
- font-size: 24px;
- font-weight: 100;
- }
- .hc-upload-table-form .el-upload .hc-table-form-img {
- width: 100%;
- height: 100%;
- }
- .excelBox {
- ::v-deep .oldlace-bg {
- background-color: oldlace;
- }
- ::v-deep .select-td {
- border-width: 4px;
- border-color: #E6A23C;
- border-style: solid;
- }
- }
- </style>
|