dynamicExcel.vue 10 KB

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