dynamicExcel.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <div class="excelHtnl">
  3. <div class="header" style=" position: absolute;left:10px;top:0">
  4. <div class="flexStar">
  5. <h2>编辑WBS库</h2>
  6. <div
  7. class="GoBack marleft20"
  8. @click="GoBack()"
  9. >
  10. 返回上一级
  11. </div>
  12. </div>
  13. <div style="width: 37%;">
  14. <avue-tabs :option="option" @change="handleChange"></avue-tabs>
  15. </div>
  16. </div>
  17. <div
  18. class="excelBox hc-excel-table-form"
  19. style="margin-top:40px;height: 100%;"
  20. @click="parentClick($event)"
  21. >
  22. <div style="width:60%;height: 100%;overflow: scroll;" class='parent' id='parent'></div>
  23. <div class="excelRight" style="width:30%;margin-left:4%;height: 100%;overflow: scroll;" >
  24. <span v-if="type.prop==='tab1'">
  25. <setInputTPT
  26. v-if="type.prop==='tab1'"
  27. :pkeyId='pkeyId'
  28. @cop='domss'
  29. :htmlData="htmlData"
  30. :checkList="checkList"
  31. :checkNameList="checkNameList"
  32. @change="change"
  33. />
  34. </span>
  35. <span v-else-if="type.prop==='tab2'"> <electronicSignature :pkeyId1='pkeyId' :htmlData1="htmlData" :excelId="excelId" /> </span>
  36. <span v-else-if="type.prop==='tab3'"> <setFormula :pkeyId1='pkeyId' :htmlData1="htmlData" /> </span>
  37. <span v-else-if="type.prop==='tab4'"> <editDefault :pkeyId1='pkeyId' :htmlData1="htmlData" /> </span>
  38. <span v-else-if="type.prop==='tab5'"> <promptSettings :pkeyId1='pkeyId' :htmlData1="htmlData" /> </span>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import setInputTPT from './template/setInputTPT.vue'
  45. import electronicSignature from './template/electronicSignature.vue'
  46. import setFormula from './template/setFormula.vue'
  47. import editDefault from './template/editDefault.vue'
  48. import promptSettings from './template/promptSettings.vue'
  49. import Vue from 'vue'
  50. import {getExcelHtml } from '@/api/exctab/excelmodel'
  51. export default {
  52. props: ['pkeyId','excelId'],
  53. data () {
  54. return {
  55. setUptype: 0,//右侧显示的类型1
  56. htmlData: {
  57. name: '',
  58. tr: '',
  59. td: ''
  60. },
  61. type:{},
  62. option:{
  63. column: [{
  64. label: '设置输入框',
  65. prop: 'tab1',
  66. width: 10,
  67. }, {
  68. label: '电签位置配置',
  69. prop: 'tab2',
  70. }, {
  71. label: '设置公式开放条件',
  72. prop: 'tab3',
  73. }, {
  74. label: '编辑默认信息',
  75. prop: 'tab4',
  76. }, {
  77. label: '提示设置',
  78. prop: 'tab5',
  79. }
  80. ]
  81. },
  82. checkList:[],
  83. checkNameList:[],
  84. }
  85. },
  86. mounted () {
  87. this.cop()
  88. this.type = this.option.column[0];
  89. console.log(111);
  90. },
  91. methods: {
  92. change(){
  93. this.checkList=[]
  94. this.checkNameList=[]
  95. },
  96. GoBack () {//返回上一级
  97. this.$emit('remove')
  98. },
  99. handleChange(column) {
  100. this.type = column;
  101. },
  102. async getExcelHtml (pkeyId) {
  103. const { data: res } = await getExcelHtml({ pkeyId })
  104. console.log(res);
  105. if (res.code === 200) {
  106. localStorage.setItem('excelHtml', res.data)
  107. this.copss();
  108. }
  109. },
  110. async cop () {
  111. let _that = this
  112. var MyComponent = await Vue.extend({
  113. template: localStorage.getItem('excelHtml'),
  114. data () {
  115. return {
  116. formData: {},
  117. getTokenHeader: {},
  118. dap_site_data:{}
  119. }
  120. },
  121. methods: {
  122. contextmenuClick(tr, td, x1, x2, y1, y2, event) {},
  123. getInformation (name, tr, td) {//鼠标右键事件
  124. _that.getInformation(name, tr, td)
  125. },
  126. formUploadSuccess(){},
  127. formUploadExceed(){},
  128. formUploadLoading(){},
  129. delTableFormFile(){},
  130. formUploadError(){},
  131. uploadprogress(){},
  132. formRemoteMethod(){},
  133. getRegularExpression(){},
  134. checkboxGroupChange(){},
  135. formRemoteChange(){},
  136. dateKeydown(){},
  137. keyupShiftUp() {},
  138. keyupShiftDown() {},
  139. keyupShiftLeft() {},
  140. keyupShiftRight() {},
  141. inputLeftClick() {},
  142. }
  143. })
  144. var component = new MyComponent().$mount()
  145. document.getElementById('parent').appendChild(component.$el);
  146. },
  147. async copss () {
  148. let _that = this
  149. var MyComponent = await Vue.extend({
  150. template: localStorage.getItem('excelHtml'),
  151. data () {
  152. return {
  153. formData: {},
  154. getTokenHeader: {},
  155. dap_site_data:{}
  156. }
  157. },
  158. methods: {
  159. contextmenuClick(tr, td, x1, x2, y1, y2, event) {},
  160. getInformation (name, tr, td) {//鼠标右键事件
  161. _that.getInformation(name, tr, td)
  162. },
  163. formUploadSuccess(){},
  164. formUploadExceed(){},
  165. formUploadLoading(){},
  166. delTableFormFile(){},
  167. formUploadError(){},
  168. uploadprogress(){},
  169. getRegularExpression(){},
  170. formRemoteMethod(){},
  171. checkboxGroupChange(){},
  172. formRemoteChange(){},
  173. dateKeydown(){},
  174. keyupShiftUp() {},
  175. keyupShiftDown() {},
  176. keyupShiftLeft() {},
  177. keyupShiftRight() {},
  178. inputLeftClick() {},
  179. }
  180. })
  181. var component = new MyComponent().$mount()
  182. let na = document.getElementById('parent')
  183. na.innerHTML = `<div
  184. class='parent'
  185. id='parent'
  186. ></div>`
  187. document.getElementById('parent').appendChild(component.$el);
  188. },
  189. domss () {
  190. this.copss()
  191. },
  192. getInformation (name, tr, td) {//鼠标点击事件
  193. console.log(name,'name')
  194. let tdEle = null;
  195. //获取TD元素
  196. if(event.target.nodeName == "TD"){
  197. tdEle = event.target
  198. }else{
  199. tdEle = this.getParentTD(event.target);
  200. }
  201. let moreObj = {};
  202. if(tdEle){
  203. moreObj = this.getWidget(tdEle);
  204. }
  205. this.htmlData = Object.assign({
  206. name,
  207. tr,
  208. td
  209. },moreObj)
  210. },
  211. //excel父节点点击检测
  212. parentClick(e){
  213. let target = e.target;
  214. const{metaKey,ctrlKey}=e
  215. console.log(target,'target')
  216. let bgs = document.querySelectorAll("#parent .oldlace-bg")
  217. //console.log(bgs)
  218. for (let i = 0; i < bgs.length; i++) {
  219. bgs[i].classList.remove("oldlace-bg");
  220. }
  221. //console.log(target.getAttribute('trindex'))
  222. let tdEle = this.getParentTD(target);
  223. console.log(tdEle,'tdEle');
  224. let target1
  225. if(tdEle){
  226. let mydiv=tdEle.getElementsByTagName('div')
  227. target1=mydiv[0]
  228. }else{
  229. tdEle=target
  230. let mydiv=tdEle.getElementsByTagName('div')
  231. target=mydiv[0]
  232. }
  233. this.htmlData.keyname=target.getAttribute('keyname')||target1.getAttribute('keyname')
  234. if(target.getAttribute('trindex') !== null && target.getAttribute('tdindex')||target1.getAttribute('trindex') !== null && target1.getAttribute('tdindex')){
  235. let tdEle = this.getParentTD(target);
  236. if(tdEle){
  237. //橙色背景
  238. target.classList.add("oldlace-bg");
  239. if(metaKey||ctrlKey){
  240. target.classList.add("select-td");
  241. this.checkNameList.push(this.htmlData)
  242. this.checkList.push({
  243. tr:target.getAttribute('trindex')||target1.getAttribute('trindex'),
  244. td:target.getAttribute('tdindex')||target1.getAttribute('tdindex'),
  245. })
  246. }else{
  247. target.classList.remove("select-td");
  248. this.checkList.forEach((ele,index)=>{
  249. if(ele.tr===target.getAttribute('trindex')||ele.tr===target1.getAttribute('trindex')){
  250. this.checkList.splice(index,1)
  251. }
  252. })
  253. this.checkNameList.forEach((ele,index)=>{
  254. if(this.htmlData.tr===ele.tr){
  255. this.checkNameList.splice(index,1)
  256. }
  257. })
  258. }
  259. }
  260. }
  261. },
  262. getParentTD(ele){
  263. let targetParent = ele.parentNode;
  264. while (targetParent.nodeName !== "TD") {
  265. if(targetParent.id == 'parent'){
  266. return null;
  267. }
  268. targetParent = targetParent.parentNode;
  269. }
  270. return targetParent;
  271. },
  272. //获取控件信息
  273. getWidget(tdEle){
  274. let checkLabels = tdEle.querySelectorAll('.el-checkbox-group span.el-checkbox__label');
  275. //console.log(checkLabels)
  276. if(checkLabels.length > 0){
  277. let checkLabelDatas = [];
  278. for (let i = 0; i < checkLabels.length; i++) {
  279. //console.dir(checkLabels[i])
  280. checkLabelDatas.push({
  281. dictValue:checkLabels[i].innerText
  282. });
  283. }
  284. return {
  285. type:'checkbox',
  286. checkLabelDatas
  287. }
  288. }
  289. let radioLabels = tdEle.querySelectorAll('.el-radio .el-radio__label');
  290. if(radioLabels.length > 0){
  291. let radioDatas = [];
  292. for (let i = 0; i < radioLabels.length; i++) {
  293. radioDatas.push({
  294. dictValue:radioLabels[i].innerText
  295. });
  296. }
  297. return {
  298. type:'radio',
  299. radioDatas
  300. }
  301. }
  302. let elSelect = tdEle.querySelectorAll('.el-select');
  303. //console.dir(elSelect[0])
  304. if(elSelect.length){
  305. let options = elSelect[0].__vue__.options;
  306. let selectDatas = [];
  307. for (let i = 0; i < options.length; i++) {
  308. selectDatas.push({
  309. dictValue:options[i].label
  310. });
  311. }
  312. return {
  313. type:'select',
  314. selectDatas
  315. }
  316. }
  317. return {};
  318. },
  319. },
  320. components: {
  321. setInputTPT,
  322. electronicSignature,
  323. setFormula,
  324. editDefault,
  325. promptSettings
  326. }
  327. }
  328. </script>
  329. <style lang="scss" scoped>
  330. .excelHtnl {
  331. margin: 0 0 0 10px;
  332. background-color: #fff;
  333. box-sizing: border-box;
  334. padding: 0 20px 100px 20px;
  335. height: 100%;
  336. .header {
  337. border-radius: 4px;
  338. box-sizing: border-box;
  339. width: calc(100% - 20px);
  340. background-color: #fff;
  341. display: flex;
  342. justify-content: space-between;
  343. z-index: 99;
  344. height: 50px;
  345. align-items: center;
  346. .GoBack {
  347. color: rgba(0, 82, 216, 1);
  348. text-decoration: underline;
  349. display: flex;
  350. align-items: center;
  351. font-family: SourceHanSansSC;
  352. cursor: pointer;
  353. }
  354. }
  355. .excelBox {
  356. margin-top: 10px;
  357. display: flex;
  358. justify-content: flex-start;
  359. .excelRight {
  360. flex-grow: 1;
  361. box-sizing: border-box;
  362. padding: 20px 0px 0px 30px;
  363. }
  364. }
  365. }
  366. // 设置图片样式
  367. .hc-upload-table-form {
  368. position: relative;
  369. height: 100%;
  370. display: flex;
  371. justify-content: center;
  372. align-items: center;
  373. }
  374. .hc-upload-table-form .el-upload {
  375. position: relative;
  376. flex: 1;
  377. height: 100%;
  378. color: #ccc;
  379. }
  380. .hc-upload-table-form .el-upload .hc-table-form-icon {
  381. font-size: 24px;
  382. font-weight: 100;
  383. }
  384. .hc-upload-table-form .el-upload .hc-table-form-img {
  385. width: 100%;
  386. height: 100%;
  387. }
  388. .excelBox{
  389. /deep/ .oldlace-bg{
  390. background-color: oldlace;
  391. }
  392. /deep/ .select-td{
  393. border-width: 4px;
  394. border-color: #E6A23C;
  395. border-style: solid;
  396. }
  397. }
  398. </style>