checkEleHtml.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="excelHtnl">
  3. <div
  4. class="excelBox hc-excel-table-form"
  5. style="margin-top:40px;height: 100%;"
  6. @click="parentClick($event)"
  7. >
  8. <div style="width:100%;height: 100%;overflow: scroll;" class='parent' id='parent'></div>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. import Vue from 'vue'
  14. import {getExcelHtml} from '@/api/exctab/excelmodel'
  15. export default {
  16. props: ['pkeyId'],
  17. data() {
  18. return {
  19. selectedElements: [] ,// 存储已选中的元素
  20. exHtml:''
  21. }
  22. },
  23. watch: {
  24. pkeyId: {
  25. immediate: true,
  26. deep: true,
  27. handler(newVal) {
  28. if(newVal) {
  29. this.exHtml = ''
  30. this.getExcelHtml(newVal)// 重新初始化数据
  31. }else {
  32. this.exHtml = ''
  33. this.clearForm()
  34. }
  35. }
  36. }
  37. },
  38. mounted() {
  39. },
  40. methods: {
  41. async getExcelHtml(pkeyId) {
  42. const {data: res} = await getExcelHtml({pkeyId})
  43. if (res.code === 200) {
  44. this.exHtml = res.data
  45. this.cop();
  46. }
  47. },
  48. // 新增清空表单方法
  49. clearForm() {
  50. const parentElement = document.getElementById('parent')
  51. console.log(parentElement, 'parentElement');
  52. if(parentElement) {
  53. // 清空父元素内容
  54. parentElement.innerHTML = ''
  55. }
  56. // 清空已选中元素
  57. this.clearAllSelected()
  58. },
  59. async cop() {
  60. let _that = this
  61. var MyComponent = await Vue.extend({
  62. template: this.exHtml ,
  63. data() {
  64. return {
  65. formData: {},
  66. getTokenHeader: {},
  67. dap_site_data: {}
  68. }
  69. },
  70. methods: {
  71. contextmenuClick(tr, td, x1, x2, y1, y2, event) {
  72. },
  73. getInformation(name, tr, td) {//鼠标右键事件
  74. },
  75. formUploadSuccess() {
  76. },
  77. formUploadExceed() {
  78. },
  79. formUploadLoading() {
  80. },
  81. delTableFormFile() {
  82. },
  83. formUploadError() {
  84. },
  85. uploadprogress() {
  86. },
  87. formRemoteMethod() {
  88. },
  89. getRegularExpression() {
  90. },
  91. checkboxGroupChange() {
  92. },
  93. formRemoteChange() {
  94. },
  95. dateKeydown() {
  96. },
  97. keyupShiftUp() {
  98. },
  99. keyupShiftDown() {
  100. },
  101. keyupShiftLeft() {
  102. },
  103. keyupShiftRight() {
  104. },
  105. inputLeftClick() {
  106. },
  107. }
  108. })
  109. var component = new MyComponent().$mount()
  110. document.getElementById('parent').appendChild(component.$el);
  111. },
  112. //excel父节点点击检测
  113. async parentClick(e) {
  114. let target = e.target;
  115. const elementId = target.id;
  116. const keyName = target.placeholder;
  117. // 判断元素是否已选中
  118. const index = this.selectedElements.findIndex(item => item.elementId === elementId);
  119. if (index === -1) {
  120. // 添加选中效果
  121. target.style.backgroundColor = '#ffa500'; // 橙色背景
  122. this.selectedElements.push({elementId, keyName}); // 存储选中元素的id和keyName
  123. } else {
  124. // 取消选中效果
  125. target.style.backgroundColor = ''; // 恢复默认背景
  126. this.selectedElements.splice(index, 1);
  127. }
  128. // 触发选中元素变化事件
  129. this.$emit('element-selected', this.selectedElements);
  130. },
  131. // 清除所有选中状态的方法
  132. clearAllSelected() {
  133. this.selectedElements.forEach(item => {
  134. const element = document.getElementById(item.elementId);
  135. if (element) {
  136. element.style.backgroundColor = '';
  137. }
  138. });
  139. this.selectedElements = [];
  140. },
  141. getParentTD(ele) {
  142. let targetParent = ele.parentNode;
  143. while (targetParent.nodeName !== "TD") {
  144. if (targetParent.id == 'parent') {
  145. return null;
  146. }
  147. targetParent = targetParent.parentNode;
  148. }
  149. return targetParent;
  150. },
  151. },
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .excelHtnl {
  156. margin: 0 0 0 10px;
  157. background-color: #fff;
  158. box-sizing: border-box;
  159. padding: 0 20px 100px 20px;
  160. height: 100%;
  161. }
  162. // 设置图片样式
  163. .hc-upload-table-form {
  164. position: relative;
  165. height: 100%;
  166. display: flex;
  167. justify-content: center;
  168. align-items: center;
  169. }
  170. .hc-upload-table-form .el-upload {
  171. position: relative;
  172. flex: 1;
  173. height: 100%;
  174. color: #ccc;
  175. }
  176. .hc-upload-table-form .el-upload .hc-table-form-icon {
  177. font-size: 24px;
  178. font-weight: 100;
  179. }
  180. .hc-upload-table-form .el-upload .hc-table-form-img {
  181. width: 100%;
  182. height: 100%;
  183. }
  184. .excelBox {
  185. ::v-deep .oldlace-bg {
  186. background-color: oldlace;
  187. }
  188. ::v-deep .select-td {
  189. border-width: 4px;
  190. border-color: #E6A23C;
  191. border-style: solid;
  192. }
  193. }
  194. </style>