MixedTable.vue 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  1. <template>
  2. <div class="table-wrapper" @keydown="handlekeyDownKeys">
  3. <template v-if="config.data.length">
  4. <!-- 工具栏 -->
  5. <toolBarSection v-if="!disabled" :cell="selectCell?selectCell:selectedCells" @openConDialog="openConDialog" @cellMerge="toolCellMergeFun"
  6. :echoParameter="{hasMergedCell}"/>
  7. <!-- 公式显示区 -->
  8. <div class="formula-wrapper" v-if="!disabled">
  9. <span style="flex-shrink: 0;color:#C0C4CC">{{$t('OnlineExcelPage.formula_lable')}}</span>
  10. <el-input
  11. v-if="selectCell&&selectCell.DataType===6"
  12. v-model="selectCell.Value"
  13. @change="updateValueByFormula"
  14. />
  15. </div>
  16. <table
  17. width="auto"
  18. border="0"
  19. class="table"
  20. id="myTable"
  21. :style="disabled ? 'width:100%' : ''"
  22. ref="tableRef"
  23. style="position: relative;"
  24. @mousedown="selectCellHandle"
  25. >
  26. <thead>
  27. <tr>
  28. <!-- 行头 -->
  29. <th class="th-tg sm"></th>
  30. <!-- 列头 -->
  31. <th
  32. v-for="(item, index) in columnHeader"
  33. :key="index"
  34. class="th-tg th-col"
  35. :data-cindex="item"
  36. :data-rindex="-1"
  37. @contextmenu.prevent="rightClickHandle"
  38. >
  39. {{ item }}
  40. </th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. <tr v-for="(row, index) in config.data" :key="index">
  45. <!-- 行头 -->
  46. <th
  47. class="th-tg th-row sm"
  48. @contextmenu.prevent="rightClickHandle"
  49. :data-rindex="rowHeader[index]"
  50. :data-cindex="-1"
  51. >
  52. {{ rowHeader[index] }}
  53. </th>
  54. <td
  55. v-for="(cell, cell_index) in row"
  56. :key="`${index}_${cell_index}`"
  57. :data-rindex="rowHeader[index]"
  58. :data-cindex="columnHeader[cell_index]"
  59. :data-datarindex="index"
  60. :data-datacindex="cell_index"
  61. :style="cell.ShowStyle?getShowCss(cell.ShowStyle):{}"
  62. :initIndex="initIndex(index,cell_index,rowHeader[index],columnHeader[cell_index])"
  63. :data-key="cell.Uid"
  64. v-show="!cell.merData || cell.merData.type!=='merged'"
  65. :colspan="(cell.merData && cell.merData.type=='merge' && cell.merData.mer)?cell.merData.mer.colspan || 1:1"
  66. :rowspan="(cell.merData && cell.merData.type=='merge' && cell.merData.mer)?cell.merData.mer.rowspan || 1:1"
  67. @click="clickCell($event, cell)"
  68. @dblclick="dblClickCellHandle($event,cell)"
  69. @contextmenu.prevent="rightClickHandle($event,cell)"
  70. @mouseenter="getRelationEdbInfo(cell)"
  71. @copy="copyCellHandle($event,cell)"
  72. @paste="pasteCellHandle($event,cell)"
  73. >
  74. <!-- 插入单元格禁止编辑 -->
  75. <!-- [4,5,6,7,8].includes(cell.DataType)&&!cell.CanEdit -->
  76. <template
  77. v-if="!cell.CanEdit
  78. ||disabled
  79. ||(cell.DataType===1&&[1,2].includes(cell.DataTimeType))"
  80. >
  81. <!-- 单元格类型5 7显示指标浮窗 -->
  82. <el-popover
  83. v-if="[5,7].includes(cell.DataType)&&!disabled"
  84. placement="top-start"
  85. width="350"
  86. trigger="hover"
  87. >
  88. <ul>
  89. <li style="display:flex;margin:10px;">
  90. <label style="min-width:80px;">{{$t('OnlineExcelPage.indicator_name_lbl')}}</label>
  91. {{cellrelationEdbInfo.EdbName}}
  92. </li>
  93. <li style="display:flex;margin:10px;">
  94. <label style="min-width:80px;">{{$t('OnlineExcelPage.lastest_date_lab')}}</label>
  95. {{cellrelationEdbInfo.LatestDate}}
  96. </li>
  97. <li style="display:flex;margin:10px;">
  98. <label style="min-width:80px;">{{$t('Table.edb_id')}}</label>
  99. {{cellrelationEdbInfo.EdbCode}}
  100. </li>
  101. </ul>
  102. <span
  103. slot="reference"
  104. :data-rindex="rowHeader[index]"
  105. :data-cindex="columnHeader[cell_index]"
  106. :data-datarindex="index"
  107. :data-datacindex="cell_index"
  108. :data-key="cell.Uid"
  109. >{{ cell.ShowStyle?cell.ShowFormatValue:cell.ShowValue }}</span>
  110. </el-popover>
  111. <!-- 数字格式化显示 -->
  112. <span
  113. v-else-if="cell.ShowStyle"
  114. :data-rindex="rowHeader[index]"
  115. :data-cindex="columnHeader[cell_index]"
  116. :data-datarindex="index"
  117. :data-datacindex="cell_index"
  118. :data-key="cell.Uid"
  119. >
  120. {{isShowFormat(cell.ShowStyle)?cell.ShowFormatValue:cell.DataTime?cell.ShowValue:[7,5].includes(cell.DataType)?cell.ShowValue:cell.Value}}
  121. </span>
  122. <span
  123. :data-rindex="rowHeader[index]"
  124. :data-cindex="columnHeader[cell_index]"
  125. :data-datarindex="index"
  126. :data-datacindex="cell_index"
  127. :data-key="cell.Uid"
  128. v-else
  129. >{{ cell.ShowValue }}</span>
  130. </template>
  131. <el-autocomplete
  132. v-else
  133. v-model="cell.Value"
  134. :ref="`inputRef${cell.Uid}`"
  135. popper-class="edb-select-popover"
  136. :data-key="cell.Uid"
  137. :data-rindex="rowHeader[index]"
  138. :data-cindex="columnHeader[cell_index]"
  139. :data-datarindex="index"
  140. :data-datacindex="cell_index"
  141. :fetch-suggestions="searchTarget"
  142. @change.native="changeVal($event, cell)"
  143. @keydown.native="keyEnterHandle($event,cell)"
  144. @blur="() => {$set(cell,'CanEdit',false)}"
  145. >
  146. <!-- @select="selectTarget($event,cell)"
  147. @click="clickCell($event, cell)"
  148. :highlight-first-item="cell.DataType===2"
  149. -->
  150. <template slot-scope="scope">
  151. <edbDetailPopover :info="scope.item">
  152. <div slot="reference" v-if="cell.DataType===2" class="edb-item">
  153. <span class="edb-item-name text_oneLine">{{ scope.item.EdbName }}</span>
  154. <i class="el-icon-check" style="color:#0052D9;font-size:18px;"/>
  155. </div>
  156. <div slot="reference" v-else>{{ scope.item.EdbName }}</div>
  157. </edbDetailPopover>
  158. </template>
  159. </el-autocomplete>
  160. </td>
  161. </tr>
  162. </tbody>
  163. <!-- 选区 -->
  164. <div ref="selectionRef" id="selection-id"
  165. style="position: absolute;border: 2px solid #0052D9;background-color: rgba(0, 82, 217, 0.1);visibility: hidden;z-index: 1;pointer-events: none;"></div>
  166. <!-- 行列选中样式 -->
  167. <div ref="rowColSelectRef" id="row-col-select"
  168. style="position: absolute;border-color: #18ad18;border-style: solid;background-color: transparent;visibility: hidden;z-index: 1;pointer-events: none;"></div>
  169. </table>
  170. <!-- 右键菜单 -->
  171. <div class="contextMenu-wrapper" id="contextMenu-wrapper" @mouseleave="()=>{activeNames=[];hideContextMenu()}">
  172. <div :class="['item',{'deletesty': menu.key==='reset'}]" v-for="menu in config.contextMenuOption" :key="menu.key" @click="handleContext(menu.key)">
  173. <span v-if="!menu.children">{{menu.label}}</span>
  174. <el-collapse v-model="activeNames" @change="handleChange" v-if="menu.children" class="mixed-edb-slide-collapse">
  175. <el-collapse-item name="1">
  176. <template slot="title">
  177. {{menu.label}}
  178. </template>
  179. <div class="subMenu-wrapper">
  180. <div slot="reference" class="item" v-for="submenu in menu.children" :key="submenu.key" @click="edbCalculateInsertOpen(submenu)">
  181. <el-popover
  182. width="300"
  183. trigger="hover"
  184. placement="right"
  185. >
  186. <div v-html="formulaTip.get(submenu.fromEdbKey)"></div>
  187. <div slot="reference" style="width:100%">{{submenu.label}}</div>
  188. </el-popover>
  189. </div>
  190. </div>
  191. </el-collapse-item>
  192. </el-collapse>
  193. </div>
  194. </div>
  195. </template>
  196. <div class="nodata" v-else>
  197. <tableNoData :text="$t('Table.prompt_slogan')"/>
  198. </div>
  199. <!-- 选择指标 -->
  200. <selectTargetValueDia
  201. :isShow.sync="isSelectTargetValueDialog"
  202. :info="insertTargetValueInfo"
  203. @insert="insertSelectData"
  204. ref="selectTargetValueRef"
  205. />
  206. <!-- 插入系统/指标日期弹窗 -->
  207. <insertDateDia
  208. :isShow.sync="isInsertDateDialog"
  209. :info="insertDateInfo"
  210. @insert="insertDatehandle"
  211. />
  212. <!-- 指标计算弹窗 -->
  213. <calculateEdbDia
  214. ref="calculateEdbDiaRef"
  215. :isShow.sync="isInsertCalculate"
  216. :info="insertCalculateInfo"
  217. @insert="insertCalculateData"
  218. />
  219. <!-- 日期计算弹窗 -->
  220. <calculateDateDia
  221. ref="calculateDateDiaRef"
  222. :isShow.sync="isInsertCalculateDate"
  223. :info="insertCalculateDateInfo"
  224. @insert="insertCalculateDateValue"
  225. />
  226. <condition-dia
  227. :chooseCell="selectCell?selectCell:selectedCells"
  228. ref="conditionDia"
  229. @changeRule="getExcelRule"
  230. @deleteRule="deleteExcelRule"
  231. @editRule="editExcelRule"
  232. />
  233. </div>
  234. </template>
  235. <script>
  236. import {
  237. getRowHeaderCode,
  238. getColumnHeaderCode,
  239. selectCellStyle,
  240. selectMoreCellStyle,
  241. setRelationStyle,
  242. getRightClickMenu,
  243. checkDateFormat,
  244. setFocus,
  245. findCellByKey,
  246. resetRelationStyle,
  247. resetDialogCellStyle,
  248. extractFactorsFromFormula,
  249. findCellByFactorMixed,
  250. splitString,
  251. toUpperCase,
  252. findCellKeyByFactor,
  253. isNumberVal,
  254. transDecimalPlace,
  255. resetStyle
  256. } from "../common/customTable";
  257. import * as sheetInterface from "@/api/modules/sheetApi.js";
  258. import { dataBaseInterface } from '@/api/api.js';
  259. import md5 from '@/utils/md5.js';
  260. import selectTargetValueDia from './selectTargetValueDia.vue';
  261. import insertDateDia from './insertDateDia.vue';
  262. import calculateEdbDia from './calculateEdbDia.vue';
  263. import calculateDateDia from './calculateDateDia.vue';
  264. import toolBarSection from './toolBarSection.vue';
  265. import conditionDia from './conditionDia.vue'
  266. import { formulaTip } from '@/views/dataEntry_manage/databaseComponents/util';
  267. import conditionTableMixin from "../mixins/conditionTableMixin.js"
  268. export default {
  269. mixins:[conditionTableMixin],
  270. props: {
  271. disabled: { //是否只预览
  272. type: Boolean,
  273. default: false,
  274. },
  275. sourceFrom:{
  276. type: Object,
  277. default: ()=>{
  278. return {}
  279. },
  280. }
  281. },
  282. components: {
  283. conditionDia,
  284. selectTargetValueDia,
  285. insertDateDia,
  286. calculateEdbDia,
  287. calculateDateDia,
  288. toolBarSection
  289. },
  290. computed: {
  291. //列头
  292. columnHeader() {
  293. return getColumnHeaderCode(
  294. this.config.data[0] ? this.config.data[0].length : 0
  295. );
  296. },
  297. //行头
  298. rowHeader() {
  299. let total_length = this.config.data.length;
  300. // console.log(this.config.data)
  301. return getRowHeaderCode(total_length);
  302. },
  303. },
  304. watch:{
  305. 'config.data':{
  306. handler(newVal){
  307. if(!this.disabled && this.hasInit){
  308. this.$emit("autoSave")
  309. }
  310. },
  311. deep:true
  312. },
  313. insertRelationArr:{
  314. handler(newVal){
  315. if(!this.disabled && this.hasInit){
  316. this.$emit("autoSave")
  317. }
  318. },
  319. deep:true
  320. },
  321. 'endCell.row':{
  322. handler(newVal){
  323. this.setSelectionStyle()
  324. }
  325. },
  326. 'endCell.column':{
  327. handler(newVal){
  328. this.setSelectionStyle()
  329. }
  330. }
  331. },
  332. data() {
  333. return {
  334. config: {
  335. /* 单元格类型
  336. 1手动日期格 DataTimeType 0 /系统日期导入格 DataTimeType 1 /指标日期导入格 DataTimeType 2
  337. 2指标格 //eta1.5.6又弃用了
  338. 3自定义输入
  339. 4插入值 表格里有关联的日期和指标格 // eta1.1.6弃用了
  340. 5弹窗里的插入值 有关联日期格
  341. 6公式计算单元格
  342. 7指标计算的插入值单元格
  343. 8日期计算值单元格
  344. */
  345. data: [],
  346. contextMenuOption: [],
  347. },
  348. selectCell: {},//选中单元格info
  349. rightClickCell: {},//右键单元格 key c r
  350. insertTargetCell: {},//选择右键插入时的单元格 可和右键单元格不一样 key c r
  351. insertRelationArr: [], //表格单元格依赖关系数组
  352. isSelectTargetValueDialog: false,//选择指标插入值弹窗
  353. insertTargetValueInfo: {},//编辑 关联info
  354. cellrelationEdbInfo: {}, //指标浮窗信息
  355. copyCellItem: {},//复制时的单元格信息 用于粘贴赋值
  356. calculateClickCell: null,//双击公式单元格时的单元格信息 用于之后选其他单元格拼接公式
  357. isInsertDateDialog: false,//导入日期弹窗
  358. insertDateInfo: {},
  359. isInsertCalculate: false,//插入指标计算值
  360. insertCalculateInfo: {},//指标计算单元格info
  361. formulaTip,
  362. hasInit:false,
  363. isInsertCalculateDate: false,//日期计算弹窗
  364. insertCalculateDateInfo: {},//日期计算info
  365. activeNames: [],
  366. // 合并单元格data
  367. isSelectionStart:false, //选区开始
  368. startCell:{// 选区时鼠标开始的单元格
  369. row:null,
  370. column:null
  371. },
  372. endCell:{// 选区时鼠标结束的单元格
  373. row:null,
  374. column:null
  375. },
  376. selectionStart:{// 选区范围的左上角单元格
  377. row:null,
  378. rowSpan:0,
  379. column:null,
  380. colSpan:0
  381. },
  382. selectionEnd:{// 选区范围的右下角角单元格
  383. row:null,
  384. rowSpan:0,
  385. column:null,
  386. colSpan:0
  387. },
  388. hasMergedCell:false,// 选区内是否有合并的单元格
  389. selectedCells:[],
  390. // 选区有'值'单元格 因为超一个单元格有值不让合并,所以记录一个就行
  391. hasValueCellItem:{
  392. cellNumber:0, //有几个
  393. row:null,
  394. column:null
  395. },
  396. // 做个缓存
  397. cacheKey:'',
  398. cacheCellDom:{},
  399. //规则列表
  400. excelRuleList:[]
  401. };
  402. },
  403. mounted() {
  404. if(this.$route.path === '/addMixedSheet' && !this.$route.query.id) this.initData();
  405. },
  406. methods: {
  407. // 获取规则
  408. async getExcelRule(ExcelInfoId='',){
  409. const res = await dataBaseInterface.getRuleList({ExcelInfoId:ExcelInfoId?ExcelInfoId:this.$route.query.id})
  410. // console.log(res)
  411. if(res.Ret !== 200) return
  412. this.excelRuleList = res.Data.List?res.Data.List:[];
  413. this.commonInitCell()
  414. },
  415. openConDialog({chooseItem,chooseCells}){
  416. this.$refs.conditionDia.openDialog(chooseItem,chooseCells,this.excelRuleList,this.$route.query.id)
  417. },
  418. /* 输入时实时搜索 满足日期格式不搜索 有=视为输入公式不搜索 eta1.5.6弃用了*/
  419. async searchTarget(query,cb) {
  420. return cb([])
  421. //又要过滤掉2020-05-这样的奇葩其他格式 不让检索
  422. let dateOtherRegex = /^(?:(?:19|20)\d\d)([-])(0[1-9]|1[0-2])(-?)$/
  423. if(!query
  424. ||checkDateFormat(query)
  425. ||dateOtherRegex.test(query)
  426. ||query.startsWith('=')
  427. ) return cb([])
  428. const { DataType,EdbInfoId } = this.selectCell;
  429. const res = DataType===2
  430. ? await dataBaseInterface.targetDetail({EdbInfoId})
  431. : await sheetInterface.searchTarget({
  432. KeyWord: query,
  433. CurrentIndex: 1,
  434. PageSize: 1000
  435. })
  436. if(res.Ret !== 200) return
  437. let arr = DataType===2 ? [res.Data] : (res.Data.List||[])
  438. cb(arr);
  439. },
  440. /* 单击 */
  441. clickCell(e, cell) {
  442. if(this.disabled) return
  443. selectCellStyle(e);
  444. this.clearSelection()
  445. this.hasMergedCell = !!(cell && cell.merData)
  446. this.selectCell = cell;
  447. setFocus(e);
  448. //是插值单元格时寻找关联依赖的单元格 设置选框
  449. if([4,5,7].includes(cell.DataType)) {
  450. const { key } = e.target.dataset;
  451. if(!this.insertRelationArr.find(_ => _.key===key)) return
  452. let { relation_date,relation_edb } = this.insertRelationArr.find(_ => _.key===key)
  453. relation_date.key && setRelationStyle(relation_date)
  454. relation_edb.key && setRelationStyle(relation_edb)
  455. }
  456. //选择指标弹窗打开时选择日期更新弹窗数据
  457. this.isSelectTargetValueDialog&&this.$refs.selectTargetValueRef.changeRleationDate(this.selectCell)
  458. //计算指标弹窗打开时选择日期更新弹窗数据
  459. this.isInsertCalculate&&this.$refs.calculateEdbDiaRef.changeRleationDate(this.selectCell)
  460. //日期计算弹窗打开选中日期框时且有选中item时更新选中值
  461. cell.DataType===1&&this.isInsertCalculateDate&&this.$refs.calculateDateDiaRef.selectIndex&&this.$refs.calculateDateDiaRef.setSelectItemValue(this.selectCell)
  462. },
  463. /* 插入值 往左往上寻找同行同列是否有符合条件的一指标一日期 */
  464. async insertValue() {
  465. let params = this.findNearestCell();
  466. console.log(params)
  467. if(!params) {
  468. this.selectCell.DataType = 3;
  469. this.selectCell.DataTimeType = 0;
  470. this.selectCell.ShowValue = '';
  471. this.selectCell.Value = '';
  472. this.selectCell.DataTime = '';
  473. this.selectCell.EdbInfoId = 0;
  474. this.$message.warning(this.$t('OnlineExcelPage.no_here_val_msg') );
  475. return
  476. }
  477. const { EdbInfoId,Date,DataTimeType } = params
  478. const res = await sheetInterface.insertData({EdbInfoId,Date})
  479. if(res.Ret !==200) return
  480. res.Data ? this.$message.success(this.$t('OnlineExcelPage.insert_success_msg') ) : this.$message.warning(this.$t('OnlineExcelPage.the_date_no_val_msg') )
  481. this.selectCell.DataType = 4;
  482. this.selectCell.ShowValue = res.Data;
  483. this.selectCell.Value = res.Data;
  484. this.selectCell.EdbInfoId = EdbInfoId;
  485. this.selectCell.DataTime = Date;
  486. this.setRelation(params)
  487. },
  488. // 建立插入单元格和依赖单元格关联关系
  489. setRelation(data,cellType=4) {
  490. const { insert_cell } = data;
  491. let relation_obj = {
  492. type: cellType,
  493. key: insert_cell.key,
  494. relation_date: {
  495. type: 1,
  496. key: insert_cell.relation_date
  497. },
  498. relation_edb: {
  499. type: 2,
  500. key: insert_cell.relation_edb
  501. }
  502. }
  503. let haveIndex = this.insertRelationArr.findIndex(_ => _.key===insert_cell.key);
  504. if(haveIndex===-1) {
  505. this.insertRelationArr.push(relation_obj)
  506. }else {
  507. this.insertRelationArr.splice(haveIndex,1,relation_obj)
  508. }
  509. console.log(this.insertRelationArr)
  510. },
  511. /* 向左向上找出所有格子 找出离插入单元格最近的两个符合条件的单元格 看是否满足一指标一日期的条件
  512. 不满足就无法插入值
  513. */
  514. findNearestCell() {
  515. let { rindex,cindex,key } = this.rightClickCell;
  516. let index_row = this.rowHeader.findIndex(_ => _===rindex);
  517. let index_col = this.columnHeader.findIndex(_ => _===cindex);
  518. //同行左侧所有格子
  519. let row_cell_arr = this.config.data[index_row].filter((_,cell_index) => cell_index<index_col);
  520. //同列上侧所有格子
  521. let col_cell_arr = this.config.data.filter((row,row_index) => row_index<index_row).map(row=> row[index_col]);
  522. if(!row_cell_arr.length || !col_cell_arr.length){
  523. return null
  524. }
  525. //寻找最近的符合1 2类型的两个格子
  526. let params = null;
  527. for (let i = row_cell_arr.length - 1; i >= 0; i--) {
  528. for (let j = col_cell_arr.length - 1; j >= 0; j--) {
  529. if(!params) {
  530. if((row_cell_arr[i].DataType===1&&col_cell_arr[j].DataType===2)
  531. ||(row_cell_arr[i].DataType===2&&col_cell_arr[j].DataType===1)) {
  532. params = {
  533. DataTimeType: row_cell_arr[i].DataType===1 ? row_cell_arr[i].DataTimeType : col_cell_arr[j].DataTimeType,
  534. Date: row_cell_arr[i].DataType===1 ? row_cell_arr[i].ShowValue : col_cell_arr[j].ShowValue,
  535. EdbInfoId: row_cell_arr[i].DataType===2 ? row_cell_arr[i].EdbInfoId : col_cell_arr[j].EdbInfoId,
  536. insert_cell: {
  537. key,
  538. relation_date: row_cell_arr[i].DataType===1 ? row_cell_arr[i].Uid: col_cell_arr[j].Uid,
  539. relation_edb: row_cell_arr[i].DataType===2 ? row_cell_arr[i].Uid: col_cell_arr[j].Uid,
  540. },
  541. }
  542. break
  543. }
  544. }
  545. }
  546. }
  547. return params;
  548. },
  549. /* 选择指标 单元格类型为2 已经是指标单元格了就重置单元格 否则就视为选择指标*/
  550. // selectTarget(e,cell) {
  551. // const { EdbName,EdbInfoId } = e;
  552. // //如果已经是指标单元格了再次点击就清空
  553. // if(cell.DataType===2&&cell.EdbInfoId) {
  554. // this.clearCell()
  555. // }else {
  556. // cell.DataType = 2;
  557. // cell.DataTime = '';
  558. // cell.ShowValue = EdbName;
  559. // cell.Value = EdbName;
  560. // cell.EdbInfoId = EdbInfoId;
  561. // }
  562. // this.checkCellRelation(cell)
  563. // },
  564. /* 输入框失焦 设置单元格类型 处理关联关系 */
  565. async changeVal(e, cell) {
  566. // 是日期格式 DataType为1
  567. // 自定义内容 DataType 3
  568. //有=号为输入公式 DataType 6
  569. const {value} = e.target;
  570. if(!value){ //无值重置单元格
  571. cell.DataType = 3;
  572. cell.ShowValue = value;
  573. cell.Value = value;
  574. cell.EdbInfoId = 0;
  575. cell.DataTime = '';
  576. cell.Extra=''
  577. }else {
  578. //指标类型不做格式处理
  579. if(cell.DataType===2) return
  580. console.log(checkDateFormat(value))
  581. let dateFormat = checkDateFormat(value);
  582. if(dateFormat) { //是日期格式
  583. cell.DataType = 1;
  584. cell.Extra='';
  585. cell.ShowValue = dateFormat;
  586. cell.DataTime = dateFormat;
  587. cell.Value = dateFormat;
  588. }else if(value.startsWith('=')) { //公式单元格
  589. cell.Value = value;
  590. cell.DataType = 6;
  591. let calculateVal = await this.getValueByFormula(value);
  592. if(!calculateVal) return
  593. cell.ShowValue = calculateVal;
  594. //处理公式关系
  595. this.$set(cell,'Extra',this.dealFormulaConstruction(value))
  596. }else {//自定义值
  597. cell.DataType = 3;
  598. cell.ShowValue = value;
  599. cell.Value = value;
  600. cell.EdbInfoId = 0;
  601. cell.DataTime = '';
  602. cell.Extra=''
  603. }
  604. }
  605. /* 不是数字类型,清除原来设置的格式 */
  606. if(!isNumberVal(value)){
  607. cell.ShowStyle = '';
  608. cell.ShowStyle = '';
  609. } ;
  610. //判断是否是有插入值的依赖单元格 更新值或重置关系
  611. this.checkCellRelation(cell)
  612. this.commonInitCell('edit')
  613. },
  614. /* 当前单元格是否和插入值有关联 无就不管 */
  615. async checkCellRelation(cell) {
  616. if(!this.insertRelationArr.length) return
  617. const key= cell.Uid;
  618. //有关联的N组数组
  619. let haveRelationArr = this.insertRelationArr.filter(_ => _.relation_date.key===key||_.relation_edb.key===key);
  620. if(!haveRelationArr.length) return
  621. //去处理每一组关联的情况
  622. haveRelationArr.forEach(relation => {
  623. const { relation_date,relation_edb,type } = relation;
  624. if((relation_date.key === key && cell.DataType === 1) || (relation_edb.key === key && cell.DataType === 2)) { //单元格类型不变只变值仍有关联关系 更新值
  625. // 根据关系关联数组去更新每种单元格类型的值
  626. this.updateRelationCell(relation,cell)
  627. }else {
  628. // 清除插入值单元格式和关联关系
  629. this.clearInsertCell(relation.key);
  630. }
  631. })
  632. },
  633. // 清除插入值单元格式和关联关系
  634. clearInsertCell(key) {
  635. this.config.data.forEach(row => {
  636. row.forEach(cell => {
  637. if(cell.Uid === key) {
  638. cell.DataType = 3;
  639. cell.EdbInfoId = 0;
  640. cell.DataTime = '';
  641. cell.ShowValue = '';
  642. cell.Value = '';
  643. cell.ShowStyle = ''
  644. }
  645. })
  646. })
  647. let relationIndex = this.insertRelationArr.findIndex(_ => _.key===key)
  648. this.insertRelationArr.splice(relationIndex,1)
  649. },
  650. // 替换关联关系
  651. replaceCellRelation(originKey,replaceKey){
  652. if(!this.insertRelationArr.length) return
  653. this.insertRelationArr = JSON.parse(JSON.stringify(this.insertRelationArr).replaceAll(originKey,replaceKey))
  654. },
  655. /* 单元格更新时去更新有依赖关系单元格的值 目前只更4 5 7*/
  656. updateRelationCell(relation,cell) {
  657. const cellTypeMap = {
  658. 4: this.refreshRelationInsertCell,
  659. 5: this.refreshRelationByEdbInsertCell,
  660. 7: this.refreshRelationByEdbCalculateCell,
  661. }
  662. cellTypeMap[relation.type]&& cellTypeMap[relation.type](relation,cell)
  663. },
  664. //关联类型4的单元格值刷新
  665. async refreshRelationInsertCell({relation_date,relation_edb},cell) {
  666. //刷新插入值结果
  667. let params = null;
  668. if(relation_date.key === key && cell.DataType === 1) { //修改的是依赖日期格
  669. let { EdbInfoId } = findCellByKey(this.config.data,relation.key)
  670. params = {
  671. EdbInfoId,
  672. Date: cell.ShowValue
  673. }
  674. } else if( relation_edb.key === key && cell.DataType === 2) { //修改的依赖指标格
  675. let {ShowValue} = findCellByKey(this.config.data,relation_date.key)
  676. params = {
  677. EdbInfoId: cell.EdbInfoId,
  678. Date: ShowValue
  679. }
  680. }
  681. const res = await sheetInterface.insertData(params)
  682. if(res.Ret !==200) return
  683. //现在日期无值也不清除关系了
  684. // !res.Data && this.clearInsertCell(relation.key);
  685. this.config.data.forEach(row => {
  686. row.forEach(cell => {
  687. if(cell.Uid === relation.key) {
  688. cell.DataType = relation.type;
  689. cell.ShowValue = res.Data;
  690. cell.Value = res.Data;
  691. cell.EdbInfoId = params.EdbInfoId;
  692. cell.DataTime = params.Date;
  693. }
  694. })
  695. })
  696. },
  697. //关联类型5的弹窗插值单元格值刷新
  698. async refreshRelationByEdbInsertCell(relation,cell) {
  699. let { EdbInfoId,Value } = findCellByKey(this.config.data,relation.key)
  700. let params = {
  701. EdbInfoId,
  702. MoveForward: JSON.parse(Value).MoveForward,
  703. DateChange: JSON.parse(Value).DateChange,
  704. Date: cell.ShowValue
  705. }
  706. const res = await sheetInterface.getDateLatelyData(params)
  707. if(res.Ret !== 200) return
  708. let value = (res.Data.List&&res.Data.List.length)
  709. ? res.Data.List.find(_ => _.DataTime===res.Data.Date)
  710. ? res.Data.List.find(_ => _.DataTime===res.Data.Date).Value.toString()
  711. : ''
  712. : ''
  713. this.config.data.forEach(row => {
  714. row.forEach(cell => {
  715. if(cell.Uid === relation.key) {
  716. cell.ShowValue = value;
  717. cell.ShowFormatValue = cell.ShowStyle ? transDecimalPlace(value,JSON.parse(cell.ShowStyle)) : '';
  718. }
  719. })
  720. })
  721. },
  722. //关联类型7的指标计算单元格值刷新
  723. async refreshRelationByEdbCalculateCell(relation,cell) {
  724. console.log(relation,cell)
  725. console.log(findCellByKey(this.config.data,relation.key))
  726. let { Value } = findCellByKey(this.config.data,relation.key)
  727. const {
  728. Source,
  729. Frequency,
  730. Formula,
  731. EdbInfoId,
  732. MoveFrequency,
  733. MoveType,
  734. Calendar,
  735. MoveForward,
  736. DateChange
  737. } = JSON.parse(Value);
  738. let params = {
  739. DataTime: cell.ShowValue,
  740. Source,
  741. Frequency,
  742. Formula,
  743. EdbInfoId,
  744. MoveFrequency,
  745. MoveType,
  746. Calendar,
  747. MoveForward,
  748. DateChange,
  749. }
  750. const res = await sheetInterface.getMixedCalculateData(params)
  751. if(res.Ret !== 200) return
  752. let value = res.Data.ShowValue||"";
  753. this.config.data.forEach(row => {
  754. row.forEach(cell => {
  755. if(cell.Uid === relation.key) {
  756. cell.ShowValue = value;
  757. cell.ShowFormatValue = cell.ShowStyle ? transDecimalPlace(value,JSON.parse(cell.ShowStyle)) : '';
  758. }
  759. })
  760. })
  761. },
  762. /* 输入公式的计算值 */
  763. async getValueByFormula(val) {
  764. // 提取因数数组
  765. let factors = extractFactorsFromFormula(val)
  766. //根据因数找单元格
  767. let isAllCell = factors.some(_ => findCellByFactorMixed(this.config.data,_)===null||isNaN(findCellByFactorMixed(this.config.data,_)))
  768. if(isAllCell) {
  769. this.$message.warning(this.$t('OnlineExcelPage.formula_val_error_msg') )
  770. return '';
  771. }
  772. let TagMap = {};
  773. factors.forEach(_ => {
  774. if(!TagMap[_]) {
  775. TagMap[_] = Number(findCellByFactorMixed(this.config.data,_))
  776. }
  777. });
  778. const res = await sheetInterface.calculateCustomCellData({
  779. CalculateFormula: val,
  780. TagMap
  781. })
  782. if(res.Ret !== 200) return
  783. return res.Data
  784. },
  785. /* 顶部公式改变 */
  786. async updateValueByFormula(value) {
  787. this.changeVal({target: {value}},this.selectCell)
  788. },
  789. /* 右键 */
  790. rightClickHandle(e,cell) {
  791. if(this.disabled) return
  792. const { rindex,cindex,key,datacindex,datarindex } = e.target.dataset;
  793. this.rightClickCell = {
  794. rindex,
  795. cindex,
  796. datarindex,
  797. datacindex,
  798. key
  799. }
  800. this.selectCell = cell;
  801. let pos;
  802. if(rindex==='-1') { //列头处
  803. pos = 'col'
  804. }else if(cindex==='-1') { //行头
  805. pos = 'row'
  806. }else if( datarindex>=this.selectionStart.row && datarindex<=this.selectionEnd.row &&
  807. datacindex>=this.selectionStart.column && datacindex<=this.selectionEnd.column &&
  808. (this.selectionEnd.row-this.selectionStart.row>0||this.selectionEnd.column-this.selectionStart.column>0)){
  809. // 选区
  810. pos = 'selection'
  811. }else {//单元格
  812. pos = 'cell'
  813. }
  814. pos==='cell' && this.clickCell(e,cell);
  815. this.config.contextMenuOption = pos === 'cell'
  816. ? getRightClickMenu(pos,(cell.DataType===1&&[1,2].includes(cell.DataTimeType))||[5,7,8].includes(cell.DataType),false,{cellMerged:this.hasMergedCell})
  817. : getRightClickMenu(pos,false,false,{cellMerged:this.hasMergedCell})
  818. this.$nextTick(() => {
  819. let dom = $('#contextMenu-wrapper')[0];
  820. if(e.clientY > window.innerHeight/2) {
  821. dom.style.left = e.clientX-3 + 'px';
  822. dom.style.top = e.clientY-dom.offsetHeight-3 + 'px';
  823. }else {
  824. dom.style.left = e.clientX-3 + 'px';
  825. dom.style.top = e.clientY-3 + 'px';
  826. }
  827. if(['col','row'].includes(pos)){
  828. this.clearSelection()
  829. selectMoreCellStyle(e);
  830. }
  831. })
  832. },
  833. /* */
  834. hideContextMenu() {
  835. const dom = $('#contextMenu-wrapper')[0];
  836. dom.style.left = '-9999px';
  837. dom.style.top = '-9999px';
  838. },
  839. /* 右键事件 */
  840. async handleContext(key) {
  841. //可右键编辑的单元格类型
  842. let editHandlesMap = {
  843. 1: this.insertDateOpen,
  844. 5: this.selectTargetOpen,
  845. 7: this.edbCalculateInsertOpen,
  846. 8: this.insertDateCalculateOpen
  847. }
  848. const keyMap = {
  849. 'del': this.delColOrRow,//删除
  850. 'insert-col-left': this.insertCol,//向左插入列
  851. 'insert-col-right': this.insertCol,//向右插入列
  852. 'insert-row-up': this.insertRow,//向上插入行
  853. 'insert-row-down': this.insertRow,//向下插入行
  854. 'insert-value': this.insertValue,//插入值
  855. 'choose-target': this.selectTargetOpen,//选择指标插入值
  856. 'insert-date': this.insertDateOpen,//导入系统日期
  857. // 'insert-edb-date': this.insertDateOpen,//导入指标日期
  858. 'insert-date-calculate': this.insertDateCalculateOpen,//日期计算弹窗
  859. 'reset': this.clearCell, //清空
  860. 'cell-edit': this.selectCell ? editHandlesMap[this.selectCell.DataType] : null,
  861. 'cell-merge':this.mergeCellFun,
  862. 'cell-unmerge':this.unmergeCellsFun
  863. }
  864. keyMap[key] && keyMap[key](key)
  865. key!=='insert-edb-calculate' && this.hideContextMenu()
  866. },
  867. /* 打开选择指标弹窗
  868. 打开弹窗后仍可以在页面上点击 多存一个选择指标时的当前单元格信息 */
  869. selectTargetOpen(type) {
  870. this.insertTargetCell = this.selectCell;
  871. resetDialogCellStyle();
  872. setRelationStyle({ key:this.insertTargetCell.Uid },'td-choose-insert-target')
  873. if(type === 'cell-edit') {
  874. this.insertTargetValueInfo = {
  875. ...this.insertTargetCell
  876. }
  877. }else {
  878. this.insertTargetValueInfo = {}
  879. }
  880. this.isSelectTargetValueDialog = true;
  881. this.resetDialogStatus('insertEdbVal')
  882. },
  883. /* 插入选择指标的值 */
  884. insertSelectData({ edbId,value,relationDate,relationUid,str,sourceName }) {
  885. this.insertTargetCell.DataType = 5;
  886. this.insertTargetCell.ShowValue = value;
  887. this.insertTargetCell.Value = str;
  888. this.insertTargetCell.EdbInfoId = edbId;
  889. this.insertTargetCell.DataTime = relationDate;
  890. this.insertTargetCell.ShowFormatValue = this.insertTargetCell.ShowStyle ? transDecimalPlace(value,JSON.parse(this.insertTargetCell.ShowStyle)) : '';
  891. value ? this.$message.success(this.$t('ETable.Msg.insertion_success_msg')) : this.$message.warning(this.$t('ETable.Msg.date_no_data'))
  892. this.updateSourceFrom(sourceName)
  893. //如果有关联表格日期就建立新的关联关系
  894. if(relationDate&&relationUid) {
  895. let relation = {
  896. insert_cell: {
  897. key: this.insertTargetCell.Uid,
  898. relation_date: relationUid,
  899. relation_edb: '',
  900. }
  901. }
  902. this.setRelation(relation,5);
  903. }else { //重新插值后之后原来有关联的清除关系
  904. let haveIndex = this.insertRelationArr.findIndex(_ => _.key===this.insertTargetCell.Uid);
  905. haveIndex!==-1 && this.insertRelationArr.splice(haveIndex,1)
  906. resetRelationStyle();
  907. }
  908. this.commonInitCell('edit')
  909. },
  910. /*
  911. 清除单元格内容 格式 关联关系
  912. config:{
  913. single:true 清除单个,不考虑合并单元格的联系
  914. }
  915. */
  916. clearCell(c) {
  917. const isCell = c && typeof(c)=='object' && c.Uid
  918. const cell = isCell ? c: this.selectCell
  919. if([4,5].includes(cell.DataType)) resetRelationStyle();
  920. cell.DataType = 3;
  921. cell.ShowValue = '';
  922. cell.Value = '';
  923. cell.DataTime = '';
  924. cell.DataTimeType = 0;
  925. cell.EdbInfoId = 0;
  926. cell.ShowStyle = '';
  927. cell.ShowFormatValue = '';
  928. cell.Extra && (cell.Extra = '');
  929. this.checkCellRelation(cell)
  930. },
  931. findDataByStartKey(key){
  932. if(!key) return {data:{},row:-1,col:-1}
  933. let mergeCellDom = this.$refs.tableRef.querySelector(`[data-key="${key}"]`)
  934. let row = +mergeCellDom.dataset.datarindex
  935. let col = +mergeCellDom.dataset.datacindex
  936. return {data:this.config.data[row][col],row,col}
  937. },
  938. /* 删除行列 */
  939. delColOrRow() {
  940. let { rindex,cindex } = this.rightClickCell;
  941. if(rindex==='-1') { //删除列
  942. console.log('删除列',cindex)
  943. if(this.columnHeader.length === 1) return this.$message.warning(this.$t('OnlineExcelPage.keep_one_column_msg') )
  944. let index = this.columnHeader.findIndex(_ => _ === cindex);
  945. // 处理删除列对合并单元格的影响
  946. let startMainKey=''
  947. this.config.data.map((row,rowInd) => {
  948. let rowEle=row[index]
  949. if(rowEle.merData){
  950. let {data,row,col} = this.findDataByStartKey(rowEle.merData.mer.sKey)
  951. let r = row
  952. let c = col
  953. let rs = data.merData.mer.rowspan
  954. let cs = data.merData.mer.colspan
  955. if(cs == 1) return //只有一列
  956. if(rowEle.merData.type == 'merged'){
  957. // 每个大单元格只处理一次
  958. if(startMainKey != rowEle.merData.mer.sKey){
  959. if(data.merData.mer.colspan==2 && data.merData.mer.rowspan==1){
  960. //删除这一列之后,只有一个单元格了
  961. data.merData=null
  962. return
  963. }
  964. data.merData.mer.colspan--
  965. startMainKey = rowEle.merData.mer.sKey
  966. }
  967. }else{
  968. // 右一列的单元格作为新的左上角单元格
  969. const newStartCell = this.config.data[r][c+1]
  970. if(rowEle.merData.mer.colspan==2 && rowEle.merData.mer.rowspan==1){
  971. //删除这一列之后,只有一个单元格了
  972. newStartCell.merData=null
  973. return
  974. }
  975. newStartCell.merData=rowEle.merData
  976. newStartCell.merData.mer.sKey = newStartCell.Uid
  977. newStartCell.merData.mer.colspan--
  978. for (let i = r; i < (r+rs); i++) {
  979. for (let j = c+1; j < (c+cs); j++) {
  980. const element = this.config.data[i][j];
  981. if(element.merData.type == 'merged'){
  982. element.merData.mer.sKey = newStartCell.Uid
  983. }
  984. }
  985. }
  986. }
  987. }
  988. })
  989. //删除时清除关系
  990. if(this.insertRelationArr.length) {
  991. let delCellIds = this.config.data.map(row => row[index].Uid);
  992. this.clearRelationInsertCell(delCellIds);
  993. }
  994. this.config.data.forEach(row => {
  995. row.splice(index,1)
  996. })
  997. // 删除的是最后一列
  998. if(!(index < this.config.data[0].length)){
  999. resetStyle()
  1000. }
  1001. }else if(cindex === '-1') { //删除行
  1002. console.log('删除行',rindex)
  1003. if(this.rowHeader.length === 1) return this.$message.warning(this.$t('OnlineExcelPage.keep_one_row_msg') )
  1004. let index = this.rowHeader.findIndex(_ => _ === rindex)
  1005. // 处理删除行对合并单元格的影响
  1006. let startMainKey=''
  1007. this.config.data[index].map((rowEle,rowInd) => {
  1008. if(rowEle.merData){
  1009. let {data,row,col} = this.findDataByStartKey(rowEle.merData.mer.sKey)
  1010. let r = row
  1011. let c = col
  1012. let rs = data.merData.mer.rowspan
  1013. let cs = data.merData.mer.colspan
  1014. if(rs == 1) return //只有一行
  1015. if(rowEle.merData.type == 'merged'){
  1016. // 每个大单元格只处理一次
  1017. if(startMainKey != rowEle.merData.mer.sKey){
  1018. if(data.merData.mer.colspan==1 && data.merData.mer.rowspan==2){
  1019. //删除这一行之后,只有一个单元格了
  1020. data.merData=null
  1021. return
  1022. }
  1023. data.merData.mer.rowspan--
  1024. startMainKey = rowEle.merData.mer.sKey
  1025. }
  1026. }else{
  1027. // 下一行的单元格作为新的左上角单元格
  1028. const newStartCell = this.config.data[r+1][c]
  1029. if(rowEle.merData.mer.colspan==1 && rowEle.merData.mer.rowspan==2){
  1030. //删除这一行之后,只有一个单元格了
  1031. newStartCell.merData=null
  1032. return
  1033. }
  1034. newStartCell.merData=rowEle.merData
  1035. newStartCell.merData.mer.sKey = newStartCell.Uid
  1036. newStartCell.merData.mer.rowspan--
  1037. for (let i = r+1; i < (r+rs); i++) {
  1038. for (let j = c; j < (c+cs); j++) {
  1039. const element = this.config.data[i][j];
  1040. if(element.merData.type == 'merged'){
  1041. element.merData.mer.sKey = newStartCell.Uid
  1042. }
  1043. }
  1044. }
  1045. }
  1046. }
  1047. })
  1048. if(this.insertRelationArr.length) {
  1049. //删除时清除关系
  1050. let delCellIds = this.config.data[index].map(cell => cell.Uid);
  1051. this.clearRelationInsertCell(delCellIds);
  1052. }
  1053. this.config.data.splice(index,1)
  1054. // 删除的是最后一行
  1055. if(!(index < this.config.data.length)){
  1056. resetStyle()
  1057. }
  1058. }
  1059. },
  1060. /* 删除时清除关联关系 和删除单元格有关联的插入值单元格和 */
  1061. clearRelationInsertCell(delCellIds) {
  1062. //清除关联插入值得单元格
  1063. let haveRelationArr = this.insertRelationArr.filter(_ => delCellIds.includes(_.relation_date.key)||delCellIds.includes(_.relation_edb.key));
  1064. // console.log(haveRelationArr)
  1065. haveRelationArr.forEach(relation => {
  1066. !delCellIds.includes(relation)&&this.clearInsertCell(relation.key);
  1067. })
  1068. this.insertRelationArr = this.insertRelationArr.filter(_ => !delCellIds.includes(_.key)&&!delCellIds.includes(_.relation_date.key)&&!delCellIds.includes(_.relation_edb.key))
  1069. },
  1070. /* 插入列 */
  1071. insertCol(key) {
  1072. let { cindex } = this.rightClickCell;
  1073. let index = this.columnHeader.findIndex(_ => _ === cindex);
  1074. let checkIndex = key==='insert-col-left'?index-1:index+1
  1075. let startMainKey=''
  1076. this.config.data.forEach((row,rindex) => {
  1077. let isEnlargeCell = !!(row[index].merData && row[checkIndex] && row[checkIndex].merData)
  1078. if(isEnlargeCell && startMainKey != row[index].merData.mer.sKey){
  1079. const data = row[index].merData.type == 'merge'?row[index]:this.findDataByStartKey(row[index].merData.mer.sKey).data
  1080. data.merData.mer.colspan++
  1081. startMainKey = row[index].merData.mer.sKey
  1082. }
  1083. row.splice(key==='insert-col-left'?index:index+1,0,{
  1084. ShowValue: "",
  1085. Value: "",
  1086. DataType: 3,
  1087. DataTime: "",
  1088. EdbInfoId: 0,
  1089. Uid: md5.hex_md5(`${new Date().getTime()}${rindex}`),
  1090. merData:isEnlargeCell?{
  1091. type:'merged',
  1092. mer:{
  1093. sKey:row[index].merData.mer.sKey,//左上角第一个单元格的Uid
  1094. }
  1095. }:null
  1096. })
  1097. })
  1098. },
  1099. /* 插入行 */
  1100. insertRow(key) {
  1101. let { rindex } = this.rightClickCell;
  1102. let index = this.rowHeader.findIndex(_ => _ === rindex)
  1103. let checkIndex = key==='insert-row-up'?index-1:index+1
  1104. let startMainKey=''
  1105. let row = new Array(this.columnHeader.length).fill("").map((_,cindex) => {
  1106. let isEnlargeCell = !!(this.config.data[index][cindex].merData &&(this.config.data[checkIndex]&&this.config.data[checkIndex][cindex]) && this.config.data[checkIndex][cindex].merData)
  1107. if(isEnlargeCell && startMainKey != this.config.data[index][cindex].merData.mer.sKey){
  1108. const data = this.config.data[index][cindex].merData.type == 'merge'?
  1109. this.config.data[index][cindex]:
  1110. this.findDataByStartKey(this.config.data[index][cindex].merData.mer.sKey).data
  1111. data.merData.mer.rowspan++
  1112. startMainKey = this.config.data[index][cindex].merData.mer.sKey
  1113. }
  1114. return {
  1115. ShowValue: "",
  1116. Value: "",
  1117. DataType: 3,
  1118. DataTime: "",
  1119. EdbInfoId: 0,
  1120. Uid: md5.hex_md5(`${new Date().getTime()}${cindex}`),
  1121. merData:isEnlargeCell?{
  1122. type:'merged',
  1123. mer:{
  1124. sKey:this.config.data[index][cindex].merData.mer.sKey,//左上角第一个单元格的Uid
  1125. }
  1126. }:null
  1127. }
  1128. });
  1129. this.config.data.splice( key==='insert-row-up'?index:index+1,0,row)
  1130. },
  1131. /* 单元格类型5 浮到上面展示指标信息浮窗 */
  1132. async getRelationEdbInfo({EdbInfoId,DataType}) {
  1133. if(![5,7].includes(DataType)||this.disabled) return
  1134. const res = await dataBaseInterface.targetDetail({EdbInfoId})
  1135. if(res.Ret !== 200) return
  1136. this.cellrelationEdbInfo = res.Data;
  1137. },
  1138. /* 导入系统/指标日期弹窗 */
  1139. insertDateOpen(type) {
  1140. this.insertTargetCell = this.selectCell;
  1141. resetDialogCellStyle();
  1142. if(type === 'cell-edit') { //编辑日期
  1143. this.insertDateInfo = {
  1144. ...this.insertTargetCell
  1145. }
  1146. }else {
  1147. this.insertDateInfo = {
  1148. // key:type
  1149. }
  1150. }
  1151. this.isInsertDateDialog = true;
  1152. this.resetDialogStatus();
  1153. },
  1154. /* 弹窗都是无遮罩的 弹一个就重置其他的 */
  1155. resetDialogStatus(type='init') {
  1156. if(type!=='insertEdbVal') {
  1157. this.$refs.selectTargetValueRef&&this.$refs.selectTargetValueRef.initData();
  1158. this.isSelectTargetValueDialog = false;
  1159. }
  1160. if(type!=='insertEdbCalculateVal') {
  1161. this.$refs.calculateEdbDiaRef&&this.$refs.calculateEdbDiaRef.initData();
  1162. this.isInsertCalculate = false;
  1163. }
  1164. if(type!=='insertDateCalculateVal') {
  1165. this.$refs.calculateDateDiaRef&&this.$refs.calculateDateDiaRef.initData();
  1166. this.isInsertCalculateDate = false;
  1167. }
  1168. },
  1169. /* 插入系统/指标日期 */
  1170. insertDatehandle({insertValue,dataTimeType,str,sourceName}) {
  1171. this.updateSourceFrom(sourceName)
  1172. this.insertTargetCell.DataType = 1;
  1173. this.insertTargetCell.DataTimeType = dataTimeType;
  1174. this.insertTargetCell.ShowValue = insertValue;
  1175. this.insertTargetCell.Value = str;
  1176. this.insertTargetCell.EdbInfoId = 0;
  1177. this.insertTargetCell.DataTime = insertValue;
  1178. this.commonInitCell('edit')
  1179. },
  1180. /* 指标计算弹窗 */
  1181. edbCalculateInsertOpen(item) {
  1182. this.insertTargetCell = this.selectCell;
  1183. resetDialogCellStyle();
  1184. setRelationStyle({ key:this.insertTargetCell.Uid },'td-choose-insert-target');
  1185. if(item === 'cell-edit') { //编辑
  1186. const { Value } = this.insertTargetCell;
  1187. let menuInfo = this.config.contextMenuOption
  1188. .find(_ => _.key==='insert-edb-calculate').children
  1189. .find(menu => menu.source === JSON.parse(Value).Source);
  1190. this.insertCalculateInfo = {
  1191. ...menuInfo,
  1192. ...this.insertTargetCell
  1193. }
  1194. }else {
  1195. this.insertCalculateInfo = {
  1196. ...item
  1197. }
  1198. }
  1199. this.isInsertCalculate = true;
  1200. this.resetDialogStatus('insertEdbCalculateVal')
  1201. },
  1202. /* 导入指标计算值 */
  1203. insertCalculateData(item) {
  1204. // console.log(item)
  1205. const { InsertValue,EdbInfoId,Str,relationDate,relationUid,sourceName } = item;
  1206. this.insertTargetCell.DataType = 7;
  1207. this.insertTargetCell.ShowValue = InsertValue;
  1208. this.insertTargetCell.Value = Str;
  1209. this.insertTargetCell.EdbInfoId = EdbInfoId;
  1210. this.insertTargetCell.DataTime = relationDate;
  1211. this.insertTargetCell.ShowFormatValue = this.insertTargetCell.ShowStyle ? transDecimalPlace(InsertValue,JSON.parse(this.insertTargetCell.ShowStyle)) : '';
  1212. InsertValue ? this.$message.success(this.$t('ETable.Msg.insertion_success_msg')) : this.$message.warning(this.$t('ETable.Msg.date_no_data'))
  1213. this.updateSourceFrom(sourceName)
  1214. //如果有关联表格日期就建立新的关联关系
  1215. if(relationDate&&relationUid) {
  1216. let relation = {
  1217. insert_cell: {
  1218. key: this.insertTargetCell.Uid,
  1219. relation_date: relationUid,
  1220. relation_edb: '',
  1221. }
  1222. }
  1223. this.setRelation(relation,7);
  1224. }else { //重新插值后之后原来有关联的清除关系
  1225. let haveIndex = this.insertRelationArr.findIndex(_ => _.key===this.insertTargetCell.Uid);
  1226. haveIndex!==-1 && this.insertRelationArr.splice(haveIndex,1)
  1227. resetRelationStyle();
  1228. }
  1229. this.commonInitCell('edit')
  1230. },
  1231. /* 日期计算弹窗 */
  1232. insertDateCalculateOpen(type) {
  1233. this.insertTargetCell = this.selectCell;
  1234. resetDialogCellStyle()
  1235. setRelationStyle({ key:this.insertTargetCell.Uid },'td-choose-insert-target')
  1236. if(type === 'cell-edit') { //编辑
  1237. this.insertCalculateDateInfo = {
  1238. ...this.insertTargetCell
  1239. }
  1240. }else {
  1241. this.insertCalculateDateInfo = {}
  1242. }
  1243. this.isInsertCalculateDate = true;
  1244. this.resetDialogStatus('insertDateCalculateVal');
  1245. },
  1246. /* 插入日期计算值 */
  1247. insertCalculateDateValue(data) {
  1248. const { insertValue,str } = data;
  1249. this.insertTargetCell.DataType = 8;
  1250. this.insertTargetCell.ShowValue = insertValue;
  1251. this.insertTargetCell.Value = str;
  1252. this.insertTargetCell.EdbInfoId = 0;
  1253. this.insertTargetCell.DataTime = '';
  1254. this.insertTargetCell.ShowFormatValue = this.insertTargetCell.ShowStyle ? transDecimalPlace(insertValue,JSON.parse(this.insertTargetCell.ShowStyle)) : '';
  1255. this.$message.success(this.$t('ETable.Msg.insertion_success_msg'))
  1256. this.commonInitCell('edit')
  1257. },
  1258. /* 初始化8行5列 */
  1259. initData(initData=null) {
  1260. this.hasInit=false
  1261. if(initData) {
  1262. const { CellRelation,Data } = initData;
  1263. this.config.data = Data;
  1264. this.insertRelationArr = JSON.parse(CellRelation);
  1265. }else {
  1266. this.config.data = new Array(8).fill("").map((_,_rindex) => {
  1267. return new Array(5).fill("").map((cell,_cindex) => ({
  1268. ShowValue: "",
  1269. ShowStyle: '',
  1270. ShowFormatValue: '',
  1271. Value: "",
  1272. DataType: 3,
  1273. DataTimeType: 0,
  1274. DataTime: "",
  1275. EdbInfoId:0,
  1276. Uid: md5.hex_md5(`${new Date().getTime()}${_rindex}${_cindex}`),
  1277. }));
  1278. });
  1279. }
  1280. this.$nextTick(()=>{
  1281. this.hasInit=true
  1282. if(this.$route.query.id){
  1283. this.getExcelRule()
  1284. }
  1285. })
  1286. },
  1287. /* 处理因数结构 =a1+b1 => [{ Tag: a,Row:1,Key:'' }] */
  1288. dealFormulaConstruction(val) {
  1289. // 提取因数数组
  1290. let factors = extractFactorsFromFormula(val)
  1291. let arr = factors.map(str => ({
  1292. Tag: splitString(toUpperCase(str))[0],
  1293. Row: splitString(toUpperCase(str))[1],
  1294. Key: findCellKeyByFactor(str)
  1295. }))
  1296. return JSON.stringify(arr)
  1297. },
  1298. /* 要支持复制粘贴把公式也带过去 公式单元格类型为6 其余就正常复制文本 */
  1299. copyCellHandle(e,cell) {
  1300. this.copyCellItem = cell;
  1301. // 阻止默认的复制操作
  1302. e.preventDefault();
  1303. },
  1304. /* 要支持复制粘贴把公式也带过去 公式单元格类型为6 其余就正常复制文本 */
  1305. pasteCellHandle(e,cell) {
  1306. if(this.copyCellItem.DataType === 6) {
  1307. cell.DataType = this.copyCellItem.DataType;
  1308. cell.ShowValue = this.copyCellItem.ShowValue;
  1309. cell.Value = this.copyCellItem.Value;
  1310. cell.DataTime = this.copyCellItem.DataTime;
  1311. cell.EdbInfoId = this.copyCellItem.EdbInfoId;
  1312. cell.ShowStyle = this.copyCellItem.ShowStyle;
  1313. cell.ShowFormatValue = this.copyCellItem.ShowFormatValue;
  1314. cell.Extra = this.copyCellItem.Extra;
  1315. }else {
  1316. cell.DataType = 3;
  1317. cell.ShowValue = this.copyCellItem.ShowValue;
  1318. cell.Value = this.copyCellItem.ShowValue;
  1319. cell.ShowStyle = this.copyCellItem.ShowStyle;
  1320. cell.ShowFormatValue = this.copyCellItem.ShowFormatValue;
  1321. cell.DataTime = '';
  1322. cell.EdbInfoId = 0;
  1323. }
  1324. // 阻止默认的粘贴操作
  1325. e.preventDefault();
  1326. },
  1327. /* 单元格enter失焦 */
  1328. keyEnterHandle(e,cell) {
  1329. if(e.keyCode===13) {
  1330. //非得搞个要回车失焦
  1331. e.target.nodeName && e.target.blur();
  1332. this.$refs[`inputRef${e.target.dataset.key}`]&&this.$refs[`inputRef${e.target.dataset.key}`][0].close()
  1333. // cell.DataType===6 && this.$set(cell,'CanEdit',false)
  1334. // this.$set(cell,'CanEdit',false)
  1335. }
  1336. },
  1337. /* 双击切换状态 插值单元格不允许切换 可切换类型1,2,3,6*/
  1338. dblClickCellHandle(e,cell) {
  1339. if(this.disabled || ![1,2,3,6].includes(cell.DataType) || [1,2].includes(cell.DataTimeType)) return
  1340. this.$set(cell,'CanEdit',true)
  1341. console.log(cell)
  1342. this.$nextTick(() => {
  1343. if(e.target.childNodes[0].childNodes[0].childNodes[1].nodeName==='INPUT') e.target.childNodes[0].childNodes[0].childNodes[1].focus();
  1344. })
  1345. },
  1346. /* 处理保存的参数 */
  1347. getSaveParams() {
  1348. const { data } = this.config;
  1349. let params = {
  1350. CellRelation: JSON.stringify(this.insertRelationArr),
  1351. Data: data
  1352. }
  1353. return params
  1354. },
  1355. /* tab禁掉 */
  1356. handlekeyDownKeys(e) {
  1357. if(e.keyCode === 9) {
  1358. e.preventDefault();
  1359. }
  1360. },
  1361. // /* 改变单元格显示文本 */
  1362. // updateCellStyle({ShowStyle,ShowFormatValue}) {
  1363. // this.$set(this.selectCell,'ShowStyle',ShowStyle)
  1364. // this.$set(this.selectCell,'ShowFormatValue',ShowFormatValue)
  1365. // },
  1366. // 更新数据来源
  1367. updateSourceFrom(source){
  1368. if(!source) return
  1369. let concatSourceArr = this.sourceFrom.text?`${this.sourceFrom.text},${source}`.split(','):[source];
  1370. let sourceStr = Array.from(new Set(concatSourceArr)).join(',');
  1371. this.$set(this.sourceFrom,'text',sourceStr)
  1372. this.$emit('updateSourceName')
  1373. },
  1374. // ==================================================合并单元格
  1375. // 选区开始
  1376. selectCellHandle(e) {
  1377. // 不是左键的mousedown事件
  1378. if(e.button!==0) return
  1379. if(this.disabled) return
  1380. this.isSelectionStart=true
  1381. let startTd;
  1382. if(e.target.nodeName==='TD'){
  1383. startTd = e.target
  1384. }else if(e.target.parentNode.nodeName==='TD'){
  1385. startTd = e.target.parentNode
  1386. }else if(e.target.parentNode.parentNode.nodeName==='TD'){
  1387. startTd = e.target.parentNode.parentNode
  1388. }else if(e.target.parentNode.parentNode.parentNode.nodeName==='TD'){
  1389. startTd = e.target.parentNode.parentNode.parentNode
  1390. }
  1391. if(!startTd) return
  1392. this.startCell={
  1393. row:+startTd.dataset.datarindex,
  1394. column:+startTd.dataset.datacindex
  1395. }
  1396. document.addEventListener('mousemove',this.selectZoneHandle)
  1397. document.addEventListener('mouseup',this.selectCellEndHandle)
  1398. },
  1399. // 选取
  1400. selectZoneHandle(e) {
  1401. if(!this.isSelectionStart) return
  1402. if(this.disabled) return
  1403. const selection = window.getSelection();
  1404. if (selection.rangeCount>0) {
  1405. // 清除选中的文本范围
  1406. selection.removeAllRanges();
  1407. }
  1408. let tableRect=this.$refs.tableRef.getBoundingClientRect()
  1409. const mouseX = e.pageX;
  1410. const mouseY = e.pageY;
  1411. let endTd;
  1412. if(mouseX >= tableRect.left && mouseX <= tableRect.right &&
  1413. mouseY >= tableRect.top && mouseY <= tableRect.bottom){
  1414. // 表格内
  1415. if(e.target.nodeName==='TD'){
  1416. endTd = e.target
  1417. }else if(e.target.parentNode.nodeName==='TD'){
  1418. endTd = e.target.parentNode
  1419. }else if(e.target.parentNode.parentNode.nodeName==='TD'){
  1420. endTd = e.target.parentNode.parentNode
  1421. }else if(e.target.parentNode.parentNode.parentNode.nodeName==='TD'){
  1422. endTd = e.target.parentNode.parentNode.parentNode
  1423. }
  1424. if(!endTd) return
  1425. this.endCell={
  1426. row:+endTd.dataset.datarindex,
  1427. column:+endTd.dataset.datacindex
  1428. }
  1429. }
  1430. },
  1431. // 选区结束
  1432. selectCellEndHandle(){
  1433. this.isSelectionStart=false
  1434. // click事件走在mouseup事件前面,延迟下
  1435. setTimeout(()=>{
  1436. if((this.selectionStart.row || this.selectionStart.row==0)
  1437. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1438. && (this.selectionStart.column || this.selectionStart.column==0)
  1439. && (this.selectionEnd.column || this.selectionEnd.column==0)){
  1440. this.selectedCells=[]
  1441. resetStyle()
  1442. this.selectCell=null
  1443. // 选区
  1444. for (let i = this.selectionStart.row; i < this.selectionEnd.row+1; i++) {
  1445. for (let j = this.selectionStart.column; j < this.selectionEnd.column+1; j++) {
  1446. this.selectedCells.push(this.config.data[i][j])
  1447. }
  1448. }
  1449. }else{
  1450. this.selectedCells=[]
  1451. }
  1452. },1)
  1453. document.removeEventListener('mousemove',this.selectZoneHandle)
  1454. document.removeEventListener('mouseup',this.selectCellEndHandle)
  1455. },
  1456. findCellDom(key){
  1457. if(!key) return null
  1458. if(key !== this.cacheKey){
  1459. // 重新找
  1460. this.cacheCellDom = this.$refs.tableRef.querySelector(`[data-key="${key}"]`)
  1461. this.cacheKey=key
  1462. }
  1463. return this.cacheCellDom
  1464. },
  1465. // 确定选区范围和设置选区样式
  1466. setSelectionStyle(){
  1467. if(!this.isSelectionStart) return
  1468. // 开始的单元格没有
  1469. if(!( (this.startCell.row || this.startCell.row==0) &&
  1470. (this.startCell.column || this.startCell.column==0))) return
  1471. // 结束的单元格没有
  1472. if(!( (this.endCell.row || this.endCell.row==0) &&
  1473. (this.endCell.column || this.endCell.column==0))) return
  1474. // 递归确定选区范围
  1475. const findZone = ({sR,eR,sC,eC})=>{
  1476. this.hasValueCellItem.cellNumber=0
  1477. for (let i = sR; i < eR+1; i++) {
  1478. for (let j = sC; j < eC+1; j++) {
  1479. const element = this.config.data[i][j]
  1480. if(element.Value){
  1481. this.hasValueCellItem.cellNumber++
  1482. this.hasValueCellItem.row=i
  1483. this.hasValueCellItem.column=j
  1484. }
  1485. if(element.merData && element.merData.type==='merge'){
  1486. if(i+element.merData.mer.rowspan-1 > eR){
  1487. // 该单元格的行有合并 重新规定选取范围
  1488. return findZone({sR,eR:i+element.merData.mer.rowspan-1,sC,eC})
  1489. }
  1490. if(j+element.merData.mer.colspan-1 > eC){
  1491. // 该单元格的列有合并 重新规定选取范围
  1492. return findZone({sR,eR,sC,eC:j+element.merData.mer.colspan-1})
  1493. }
  1494. this.hasMergedCell=true
  1495. }
  1496. if(element.merData && element.merData.type==='merged' ){
  1497. let item = this.findCellDom(element.merData.mer.sKey)
  1498. let row = +item.dataset.datarindex
  1499. let col = +item.dataset.datacindex
  1500. if(row < sR){
  1501. // 该单元格的行有被合并 重新规定选取范围
  1502. return findZone({sR:row,eR,sC,eC})
  1503. }
  1504. if(col < sC){
  1505. // 该单元格的行有被合并 重新规定选取范围
  1506. return findZone({sR,eR,sC:col,eC})
  1507. }
  1508. this.hasMergedCell=true
  1509. }
  1510. }
  1511. }
  1512. // 防止选中的区域不是整个的单元格(合并后的),后面确定selectionRef 区域大小有问题
  1513. if(this.config.data[eR][eC].merData && this.config.data[eR][eC].merData.type==='merged'){
  1514. let item = this.findCellDom(this.config.data[eR][eC].merData.mer.sKey)
  1515. let row = +item.dataset.datarindex
  1516. let col = +item.dataset.datacindex
  1517. eR=row
  1518. eC=col
  1519. this.hasMergedCell=true
  1520. }
  1521. return {startR:sR,
  1522. endR:eR,
  1523. startC:sC,
  1524. endC:eC}
  1525. }
  1526. // 看是否是从下往上、从右往左选的
  1527. let rowReverse = this.startCell.row > this.endCell.row
  1528. let colReverse = this.startCell.column > this.endCell.column
  1529. let postion={
  1530. sR:rowReverse?this.endCell.row:this.startCell.row,
  1531. eR:rowReverse?this.startCell.row:this.endCell.row,
  1532. sC:colReverse?this.endCell.column:this.startCell.column,
  1533. eC:colReverse?this.startCell.column:this.endCell.column
  1534. }
  1535. this.hasMergedCell=false
  1536. const zone = findZone(postion)
  1537. let start = this.config.data[zone.startR][zone.startC]
  1538. let end = this.config.data[zone.endR][zone.endC]
  1539. this.selectionStart.row = zone.startR
  1540. this.selectionStart.column = zone.startC
  1541. this.selectionStart.rowSpan = start.merData?start.merData.mer.rowspan:1
  1542. this.selectionStart.colSpan = start.merData?start.merData.mer.colspan:1
  1543. this.selectionEnd.row = zone.endR
  1544. this.selectionEnd.column = zone.endC
  1545. this.selectionEnd.rowSpan = end.merData?end.merData.mer.rowspan:1
  1546. this.selectionEnd.colSpan = end.merData?end.merData.mer.colspan:1
  1547. let tableRect = this.$refs.tableRef.getBoundingClientRect()
  1548. let startTd = this.$refs.tableRef.querySelector(`[data-key="${start.Uid}"]`)
  1549. let endTd = this.$refs.tableRef.querySelector(`[data-key="${end.Uid}"]`)
  1550. if(!(startTd && endTd)) return
  1551. let startRect = startTd.getBoundingClientRect()
  1552. let endRect = endTd.getBoundingClientRect()
  1553. this.$refs.selectionRef.style.left = startRect.left-tableRect.left+'px'
  1554. this.$refs.selectionRef.style.top = startRect.top-tableRect.top+'px'
  1555. let width = Math.abs(endRect.right - startRect.right) + startRect.width
  1556. let height = Math.abs(endRect.bottom - startRect.bottom) + startRect.height
  1557. this.$refs.selectionRef.style.width = width+'px'
  1558. this.$refs.selectionRef.style.height = height + 'px'
  1559. this.$refs.selectionRef.style.visibility='visible'
  1560. },
  1561. clearSelection(){
  1562. this.$refs.selectionRef.style.width = 0
  1563. this.$refs.selectionRef.style.height = 0
  1564. this.$refs.selectionRef.style.visibility='hidden'
  1565. this.selectionStart={
  1566. row:null,
  1567. rowSpan:0,
  1568. column:null,
  1569. colSpan:0
  1570. }
  1571. this.selectionEnd={
  1572. row:null,
  1573. rowSpan:0,
  1574. column:null,
  1575. colSpan:0,
  1576. }
  1577. this.selectedCells=[]
  1578. },
  1579. mergeCellFun(){
  1580. // 无选区
  1581. if(!((this.selectionStart.row || this.selectionStart.row==0)
  1582. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1583. && (this.selectionStart.column || this.selectionStart.column==0)
  1584. && (this.selectionEnd.column || this.selectionEnd.column==0))) return
  1585. if(this.hasValueCellItem.cellNumber>1 || this.hasValueCellItem.cellNumber<0){
  1586. return this.$message.warning(this.$t('ETable.Msg.merge_cell_fail_msg'))
  1587. }
  1588. const firstCell = this.config.data[this.selectionStart.row][this.selectionStart.column]
  1589. if(this.hasValueCellItem.cellNumber!=0 && (this.hasValueCellItem.row!=this.selectionStart.row || this.hasValueCellItem.column!=this.selectionStart.column)){
  1590. const reserveCell=this.config.data[this.hasValueCellItem.row][this.hasValueCellItem.column]
  1591. // 将原本有值的单元格 移给左上角第一个单元格
  1592. firstCell.ShowValue=reserveCell.ShowValue
  1593. firstCell.ShowStyle=reserveCell.ShowStyle
  1594. firstCell.ShowFormatValue=reserveCell.ShowFormatValue
  1595. firstCell.Value=reserveCell.Value
  1596. firstCell.DataType=reserveCell.DataType
  1597. firstCell.DataTimeType=reserveCell.DataTimeType
  1598. firstCell.DataTime=reserveCell.DataTime
  1599. firstCell.EdbInfoId=reserveCell.EdbInfoId
  1600. reserveCell.CanEdit && (firstCell.CanEdit=reserveCell.CanEdit)
  1601. reserveCell.Extra && (firstCell.Extra=reserveCell.Extra)
  1602. // 处理合并后的依赖关系 就是替换
  1603. this.replaceCellRelation(reserveCell.Uid,firstCell.Uid)
  1604. // 清空
  1605. this.clearCell(reserveCell)
  1606. }
  1607. this.$set(firstCell,'merData',{
  1608. type:'merge',
  1609. mer:{
  1610. sKey:firstCell.Uid,//保留的单元格的Uid
  1611. rowspan: this.selectionEnd.row - this.selectionStart.row+1,
  1612. colspan: this.selectionEnd.column - this.selectionStart.column+1,
  1613. }
  1614. })
  1615. for (let i = this.selectionStart.row; i < this.selectionEnd.row+1; i++) {
  1616. for (let j = this.selectionStart.column; j < this.selectionEnd.column+1; j++) {
  1617. const element = this.config.data[i][j]
  1618. if(i == this.selectionStart.row && j == this.selectionStart.column){
  1619. continue
  1620. }
  1621. element.merData={
  1622. type:'merged',
  1623. mer:{
  1624. sKey:firstCell.Uid,//左上角第一个单元格的Uid
  1625. }
  1626. }
  1627. }
  1628. }
  1629. let startCell = this.config.data[this.selectionStart.row][this.selectionStart.column]
  1630. let target = this.$refs.tableRef.querySelector(`[data-key="${startCell && startCell.Uid}"]`)
  1631. // 触发单元格的点击事件
  1632. target.click()
  1633. },
  1634. unmergeCellsFun(){
  1635. if((this.selectionStart.row || this.selectionStart.row==0)
  1636. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1637. && (this.selectionStart.column || this.selectionStart.column==0)
  1638. && (this.selectionEnd.column || this.selectionEnd.column==0)){
  1639. // 选区
  1640. for (let i = this.selectionStart.row; i < this.selectionEnd.row+1; i++) {
  1641. for (let j = this.selectionStart.column; j < this.selectionEnd.column+1; j++) {
  1642. this.unmergeCellFun(this.config.data[i][j])
  1643. }
  1644. }
  1645. }else{
  1646. // 单个单元格
  1647. this.selectCell && this.unmergeCellFun(this.selectCell)
  1648. }
  1649. this.hasMergedCell=false
  1650. // 取消合并后,调整选区(有的话)
  1651. if((this.selectionStart.row || this.selectionStart.row==0)
  1652. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1653. && (this.selectionStart.column || this.selectionStart.column==0)
  1654. && (this.selectionEnd.column || this.selectionEnd.column==0)){
  1655. this.selectionStart.rowSpan=1
  1656. this.selectionStart.colSpan=1
  1657. this.selectionEnd.row += (this.selectionEnd.rowSpan-1)
  1658. this.selectionEnd.column += (this.selectionEnd.colSpan-1)
  1659. this.selectionEnd.rowSpan=1
  1660. this.selectionEnd.colSpan=1
  1661. }
  1662. },
  1663. unmergeCellFun(cell){
  1664. if(!(cell.merData && cell.merData.type=='merge')) return
  1665. let {row,col} = this.findDataByStartKey(cell.merData.mer.sKey)
  1666. const sRow = row,
  1667. sCol = col,
  1668. eRow = row+cell.merData.mer.rowspan-1,
  1669. eCol = col+cell.merData.mer.colspan-1
  1670. for (let i = sRow; i < eRow+1; i++) {
  1671. for (let j = sCol; j < eCol+1; j++) {
  1672. this.config.data[i][j].merData=null
  1673. }
  1674. }
  1675. },
  1676. toolCellMergeFun(){
  1677. if(this.hasMergedCell) this.unmergeCellsFun()
  1678. else this.mergeCellFun()
  1679. }
  1680. },
  1681. };
  1682. </script>
  1683. <style scoped lang="scss">
  1684. .nodata {
  1685. text-align: center;
  1686. font-size: 16px;
  1687. color: #666;
  1688. padding: 100px 0;
  1689. }
  1690. .table-wrapper {
  1691. width: 100%;
  1692. overflow: auto;
  1693. * { box-sizing: border-box; }
  1694. .formula-wrapper {
  1695. height: 42px;
  1696. display: flex;
  1697. align-items: center;
  1698. background: #fff;
  1699. border-radius: 4px;
  1700. box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
  1701. border: 1px solid #DCDFE6;
  1702. margin-bottom: 15px;
  1703. padding: 0 15px;
  1704. }
  1705. .table td,th {
  1706. width: 104px;
  1707. min-width: 104px;
  1708. height: 35px;
  1709. max-height: 35px;
  1710. background: #fff;
  1711. text-align: center;
  1712. word-break: break-all;
  1713. border: 1px solid #dcdfe6;
  1714. overflow: hidden;
  1715. text-overflow: ellipsis;
  1716. position: relative;
  1717. color: #606266;
  1718. &.td-chose::after {
  1719. position: absolute;
  1720. top: 0;
  1721. left: 0;
  1722. right: 0;
  1723. bottom: 0;
  1724. content: "";
  1725. display: block;
  1726. outline: 0;
  1727. border: 2px solid #0033ff;
  1728. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1729. }
  1730. &.td-relation::after {
  1731. position: absolute;
  1732. top: 0;
  1733. left: 0;
  1734. right: 0;
  1735. bottom: 0;
  1736. content: "";
  1737. display: block;
  1738. outline: 0;
  1739. border: 2px dashed #0033ff;
  1740. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1741. }
  1742. // &.td-col-select::after {
  1743. // position: absolute;
  1744. // top: 0;
  1745. // left: 0;
  1746. // right: 0;
  1747. // bottom: 0;
  1748. // content: "";
  1749. // display: block;
  1750. // outline: 0;
  1751. // border: 1px solid rgb(24, 173, 24);
  1752. // border-bottom: none;
  1753. // border-top: none;
  1754. // }
  1755. // &.td-row-select::after {
  1756. // position: absolute;
  1757. // top: 0;
  1758. // left: 0;
  1759. // right: 0;
  1760. // bottom: 0;
  1761. // content: "";
  1762. // display: block;
  1763. // outline: 0;
  1764. // border: 1px solid rgb(24, 173, 24);
  1765. // border-left: none;
  1766. // border-right: none;
  1767. // }
  1768. &.td-choose-insert-target::after {
  1769. position: absolute;
  1770. top: 0;
  1771. left: 0;
  1772. right: 0;
  1773. bottom: 0;
  1774. content: "";
  1775. display: block;
  1776. outline: 0;
  1777. border: 2px dashed orange;
  1778. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1779. }
  1780. }
  1781. .th-tg {
  1782. background: #ebeef5;
  1783. &:hover {
  1784. cursor: pointer;
  1785. background: #ddd;
  1786. /* border: 2px solid #409eff; */
  1787. }
  1788. &.sm {
  1789. width: 36px;
  1790. min-width: 36px;
  1791. max-width: 36px;
  1792. }
  1793. }
  1794. //整行选中
  1795. tr {
  1796. position: relative;
  1797. &.choose-all::after {
  1798. position: absolute;
  1799. top: 0;
  1800. left: 0;
  1801. right: 0;
  1802. bottom: 0;
  1803. content: "";
  1804. display: block;
  1805. outline: 0;
  1806. border: 2px solid #5897fb;
  1807. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1808. }
  1809. }
  1810. .contextMenu-wrapper {
  1811. position: fixed;
  1812. z-index: 99;
  1813. top: -9999px;
  1814. left: -9999px;
  1815. background: #fff;
  1816. padding: 10px 0;
  1817. min-width: 180px;
  1818. max-height: 400px;
  1819. overflow-y: auto;
  1820. /* border: 1px solid #999; */
  1821. box-shadow: 0 1px 4px #999;
  1822. .item {
  1823. padding: 10px 25px;
  1824. cursor: pointer;
  1825. &:hover {
  1826. background-color: #f5f7fa;
  1827. }
  1828. &:hover .subMenu-wrapper {
  1829. display: block;
  1830. }
  1831. }
  1832. .subMenu-wrapper {
  1833. width: 180px;
  1834. /* display: none; */
  1835. padding: 10px 0;
  1836. /* box-shadow: 0 1px 4px #999; */
  1837. /* background: #fff; */
  1838. /* position: absolute;
  1839. right: -178px;
  1840. top:-205px;
  1841. max-height: 400px;
  1842. overflow-y: auto; */
  1843. .item {
  1844. &:hover {
  1845. background: #fff;
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. </style>
  1852. <style lang="scss">
  1853. .table-wrapper {
  1854. td {
  1855. .el-input__inner {
  1856. border: none;
  1857. outline: none;
  1858. text-align: center;
  1859. height: 34px;
  1860. line-height: 34px;
  1861. }
  1862. }
  1863. .el-input.is-disabled .el-input__inner {
  1864. background-color: #fff;
  1865. }
  1866. }
  1867. .formula-wrapper .el-input__inner { border: none; outline: none; }
  1868. .edb-select-popover {
  1869. width: 300px !important;
  1870. .edb-item {
  1871. display: flex;
  1872. justify-content: space-between;
  1873. align-items: center;
  1874. .edb-item-name {
  1875. max-width: 260px;
  1876. }
  1877. }
  1878. }
  1879. .mixed-edb-slide-collapse {
  1880. border: none !important;
  1881. .el-collapse-item__header {
  1882. padding: 0;
  1883. height: auto;
  1884. line-height: normal;
  1885. margin-bottom: 0 !important;
  1886. background: transparent !important;
  1887. }
  1888. .el-collapse-item__wrap {
  1889. background: transparent !important;
  1890. border: none !important;
  1891. }
  1892. .el-collapse-item__content {
  1893. padding: 0 !important;
  1894. }
  1895. }
  1896. </style>