MixedTable.vue 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  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. {{isShowDecimal(cell)?showDecimalValue(cell):isShowFormat(cell.ShowStyle)?cell.ShowFormatValue:cell.DataTime?cell.ShowValue:[7,6,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. console.log(cell)
  1301. this.copyCellItem = cell;
  1302. // 阻止默认的复制操作
  1303. e.preventDefault();
  1304. },
  1305. /* 要支持复制粘贴把公式也带过去 公式单元格类型为6 其余就正常复制文本 */
  1306. pasteCellHandle(e,cell) {
  1307. if(this.copyCellItem.DataType === 6) {
  1308. cell.DataType = this.copyCellItem.DataType;
  1309. cell.ShowValue = this.copyCellItem.ShowValue;
  1310. cell.Value = this.copyCellItem.Value;
  1311. cell.DataTime = this.copyCellItem.DataTime;
  1312. cell.EdbInfoId = this.copyCellItem.EdbInfoId;
  1313. cell.ShowStyle = this.copyCellItem.ShowStyle;
  1314. cell.ShowFormatValue = this.copyCellItem.ShowFormatValue;
  1315. cell.Extra = this.copyCellItem.Extra;
  1316. }else {
  1317. cell.DataType = 3;
  1318. cell.ShowValue = this.copyCellItem.ShowValue;
  1319. cell.Value = this.copyCellItem.ShowValue;
  1320. cell.ShowStyle = this.copyCellItem.ShowStyle;
  1321. cell.ShowFormatValue = this.copyCellItem.ShowFormatValue;
  1322. cell.DataTime = '';
  1323. cell.EdbInfoId = 0;
  1324. }
  1325. // 阻止默认的粘贴操作
  1326. e.preventDefault();
  1327. },
  1328. /* 单元格enter失焦 */
  1329. keyEnterHandle(e,cell) {
  1330. if(e.keyCode===13) {
  1331. //非得搞个要回车失焦
  1332. e.target.nodeName && e.target.blur();
  1333. this.$refs[`inputRef${e.target.dataset.key}`]&&this.$refs[`inputRef${e.target.dataset.key}`][0].close()
  1334. // cell.DataType===6 && this.$set(cell,'CanEdit',false)
  1335. // this.$set(cell,'CanEdit',false)
  1336. }
  1337. },
  1338. /* 双击切换状态 插值单元格不允许切换 可切换类型1,2,3,6*/
  1339. dblClickCellHandle(e,cell) {
  1340. if(this.disabled || ![1,2,3,6].includes(cell.DataType) || [1,2].includes(cell.DataTimeType)) return
  1341. this.$set(cell,'CanEdit',true)
  1342. console.log(cell)
  1343. this.$nextTick(() => {
  1344. if(e.target.childNodes[0].childNodes[0].childNodes[1].nodeName==='INPUT') e.target.childNodes[0].childNodes[0].childNodes[1].focus();
  1345. })
  1346. },
  1347. /* 处理保存的参数 */
  1348. getSaveParams() {
  1349. const { data } = this.config;
  1350. let params = {
  1351. CellRelation: JSON.stringify(this.insertRelationArr),
  1352. Data: data
  1353. }
  1354. return params
  1355. },
  1356. /* tab禁掉 */
  1357. handlekeyDownKeys(e) {
  1358. if(e.keyCode === 9) {
  1359. e.preventDefault();
  1360. }
  1361. },
  1362. // /* 改变单元格显示文本 */
  1363. // updateCellStyle({ShowStyle,ShowFormatValue}) {
  1364. // this.$set(this.selectCell,'ShowStyle',ShowStyle)
  1365. // this.$set(this.selectCell,'ShowFormatValue',ShowFormatValue)
  1366. // },
  1367. // 更新数据来源
  1368. updateSourceFrom(source){
  1369. if(!source) return
  1370. let concatSourceArr = this.sourceFrom.text?`${this.sourceFrom.text},${source}`.split(','):[source];
  1371. let sourceStr = Array.from(new Set(concatSourceArr)).join(',');
  1372. this.$set(this.sourceFrom,'text',sourceStr)
  1373. this.$emit('updateSourceName')
  1374. },
  1375. // ==================================================合并单元格
  1376. // 选区开始
  1377. selectCellHandle(e) {
  1378. // 不是左键的mousedown事件
  1379. if(e.button!==0) return
  1380. if(this.disabled) return
  1381. this.isSelectionStart=true
  1382. let startTd;
  1383. if(e.target.nodeName==='TD'){
  1384. startTd = e.target
  1385. }else if(e.target.parentNode.nodeName==='TD'){
  1386. startTd = e.target.parentNode
  1387. }else if(e.target.parentNode.parentNode.nodeName==='TD'){
  1388. startTd = e.target.parentNode.parentNode
  1389. }else if(e.target.parentNode.parentNode.parentNode.nodeName==='TD'){
  1390. startTd = e.target.parentNode.parentNode.parentNode
  1391. }
  1392. if(!startTd) return
  1393. this.startCell={
  1394. row:+startTd.dataset.datarindex,
  1395. column:+startTd.dataset.datacindex
  1396. }
  1397. document.addEventListener('mousemove',this.selectZoneHandle)
  1398. document.addEventListener('mouseup',this.selectCellEndHandle)
  1399. },
  1400. // 选取
  1401. selectZoneHandle(e) {
  1402. if(!this.isSelectionStart) return
  1403. if(this.disabled) return
  1404. const selection = window.getSelection();
  1405. if (selection.rangeCount>0) {
  1406. // 清除选中的文本范围
  1407. selection.removeAllRanges();
  1408. }
  1409. let tableRect=this.$refs.tableRef.getBoundingClientRect()
  1410. const mouseX = e.pageX;
  1411. const mouseY = e.pageY;
  1412. let endTd;
  1413. if(mouseX >= tableRect.left && mouseX <= tableRect.right &&
  1414. mouseY >= tableRect.top && mouseY <= tableRect.bottom){
  1415. // 表格内
  1416. if(e.target.nodeName==='TD'){
  1417. endTd = e.target
  1418. }else if(e.target.parentNode.nodeName==='TD'){
  1419. endTd = e.target.parentNode
  1420. }else if(e.target.parentNode.parentNode.nodeName==='TD'){
  1421. endTd = e.target.parentNode.parentNode
  1422. }else if(e.target.parentNode.parentNode.parentNode.nodeName==='TD'){
  1423. endTd = e.target.parentNode.parentNode.parentNode
  1424. }
  1425. if(!endTd) return
  1426. this.endCell={
  1427. row:+endTd.dataset.datarindex,
  1428. column:+endTd.dataset.datacindex
  1429. }
  1430. }
  1431. },
  1432. // 选区结束
  1433. selectCellEndHandle(){
  1434. this.isSelectionStart=false
  1435. // click事件走在mouseup事件前面,延迟下
  1436. setTimeout(()=>{
  1437. if((this.selectionStart.row || this.selectionStart.row==0)
  1438. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1439. && (this.selectionStart.column || this.selectionStart.column==0)
  1440. && (this.selectionEnd.column || this.selectionEnd.column==0)){
  1441. this.selectedCells=[]
  1442. resetStyle()
  1443. this.selectCell=null
  1444. // 选区
  1445. for (let i = this.selectionStart.row; i < this.selectionEnd.row+1; i++) {
  1446. for (let j = this.selectionStart.column; j < this.selectionEnd.column+1; j++) {
  1447. this.selectedCells.push(this.config.data[i][j])
  1448. }
  1449. }
  1450. }else{
  1451. this.selectedCells=[]
  1452. }
  1453. },1)
  1454. document.removeEventListener('mousemove',this.selectZoneHandle)
  1455. document.removeEventListener('mouseup',this.selectCellEndHandle)
  1456. },
  1457. findCellDom(key){
  1458. if(!key) return null
  1459. if(key !== this.cacheKey){
  1460. // 重新找
  1461. this.cacheCellDom = this.$refs.tableRef.querySelector(`[data-key="${key}"]`)
  1462. this.cacheKey=key
  1463. }
  1464. return this.cacheCellDom
  1465. },
  1466. // 确定选区范围和设置选区样式
  1467. setSelectionStyle(){
  1468. if(!this.isSelectionStart) return
  1469. // 开始的单元格没有
  1470. if(!( (this.startCell.row || this.startCell.row==0) &&
  1471. (this.startCell.column || this.startCell.column==0))) return
  1472. // 结束的单元格没有
  1473. if(!( (this.endCell.row || this.endCell.row==0) &&
  1474. (this.endCell.column || this.endCell.column==0))) return
  1475. // 递归确定选区范围
  1476. const findZone = ({sR,eR,sC,eC})=>{
  1477. this.hasValueCellItem.cellNumber=0
  1478. for (let i = sR; i < eR+1; i++) {
  1479. for (let j = sC; j < eC+1; j++) {
  1480. const element = this.config.data[i][j]
  1481. if(element.Value){
  1482. this.hasValueCellItem.cellNumber++
  1483. this.hasValueCellItem.row=i
  1484. this.hasValueCellItem.column=j
  1485. }
  1486. if(element.merData && element.merData.type==='merge'){
  1487. if(i+element.merData.mer.rowspan-1 > eR){
  1488. // 该单元格的行有合并 重新规定选取范围
  1489. return findZone({sR,eR:i+element.merData.mer.rowspan-1,sC,eC})
  1490. }
  1491. if(j+element.merData.mer.colspan-1 > eC){
  1492. // 该单元格的列有合并 重新规定选取范围
  1493. return findZone({sR,eR,sC,eC:j+element.merData.mer.colspan-1})
  1494. }
  1495. this.hasMergedCell=true
  1496. }
  1497. if(element.merData && element.merData.type==='merged' ){
  1498. let item = this.findCellDom(element.merData.mer.sKey)
  1499. let row = +item.dataset.datarindex
  1500. let col = +item.dataset.datacindex
  1501. if(row < sR){
  1502. // 该单元格的行有被合并 重新规定选取范围
  1503. return findZone({sR:row,eR,sC,eC})
  1504. }
  1505. if(col < sC){
  1506. // 该单元格的行有被合并 重新规定选取范围
  1507. return findZone({sR,eR,sC:col,eC})
  1508. }
  1509. this.hasMergedCell=true
  1510. }
  1511. }
  1512. }
  1513. // 防止选中的区域不是整个的单元格(合并后的),后面确定selectionRef 区域大小有问题
  1514. if(this.config.data[eR][eC].merData && this.config.data[eR][eC].merData.type==='merged'){
  1515. let item = this.findCellDom(this.config.data[eR][eC].merData.mer.sKey)
  1516. let row = +item.dataset.datarindex
  1517. let col = +item.dataset.datacindex
  1518. eR=row
  1519. eC=col
  1520. this.hasMergedCell=true
  1521. }
  1522. return {startR:sR,
  1523. endR:eR,
  1524. startC:sC,
  1525. endC:eC}
  1526. }
  1527. // 看是否是从下往上、从右往左选的
  1528. let rowReverse = this.startCell.row > this.endCell.row
  1529. let colReverse = this.startCell.column > this.endCell.column
  1530. let postion={
  1531. sR:rowReverse?this.endCell.row:this.startCell.row,
  1532. eR:rowReverse?this.startCell.row:this.endCell.row,
  1533. sC:colReverse?this.endCell.column:this.startCell.column,
  1534. eC:colReverse?this.startCell.column:this.endCell.column
  1535. }
  1536. this.hasMergedCell=false
  1537. const zone = findZone(postion)
  1538. let start = this.config.data[zone.startR][zone.startC]
  1539. let end = this.config.data[zone.endR][zone.endC]
  1540. this.selectionStart.row = zone.startR
  1541. this.selectionStart.column = zone.startC
  1542. this.selectionStart.rowSpan = start.merData?start.merData.mer.rowspan:1
  1543. this.selectionStart.colSpan = start.merData?start.merData.mer.colspan:1
  1544. this.selectionEnd.row = zone.endR
  1545. this.selectionEnd.column = zone.endC
  1546. this.selectionEnd.rowSpan = end.merData?end.merData.mer.rowspan:1
  1547. this.selectionEnd.colSpan = end.merData?end.merData.mer.colspan:1
  1548. let tableRect = this.$refs.tableRef.getBoundingClientRect()
  1549. let startTd = this.$refs.tableRef.querySelector(`[data-key="${start.Uid}"]`)
  1550. let endTd = this.$refs.tableRef.querySelector(`[data-key="${end.Uid}"]`)
  1551. if(!(startTd && endTd)) return
  1552. let startRect = startTd.getBoundingClientRect()
  1553. let endRect = endTd.getBoundingClientRect()
  1554. this.$refs.selectionRef.style.left = startRect.left-tableRect.left+'px'
  1555. this.$refs.selectionRef.style.top = startRect.top-tableRect.top+'px'
  1556. let width = Math.abs(endRect.right - startRect.right) + startRect.width
  1557. let height = Math.abs(endRect.bottom - startRect.bottom) + startRect.height
  1558. this.$refs.selectionRef.style.width = width+'px'
  1559. this.$refs.selectionRef.style.height = height + 'px'
  1560. this.$refs.selectionRef.style.visibility='visible'
  1561. },
  1562. clearSelection(){
  1563. this.$refs.selectionRef.style.width = 0
  1564. this.$refs.selectionRef.style.height = 0
  1565. this.$refs.selectionRef.style.visibility='hidden'
  1566. this.selectionStart={
  1567. row:null,
  1568. rowSpan:0,
  1569. column:null,
  1570. colSpan:0
  1571. }
  1572. this.selectionEnd={
  1573. row:null,
  1574. rowSpan:0,
  1575. column:null,
  1576. colSpan:0,
  1577. }
  1578. this.selectedCells=[]
  1579. },
  1580. mergeCellFun(){
  1581. // 无选区
  1582. if(!((this.selectionStart.row || this.selectionStart.row==0)
  1583. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1584. && (this.selectionStart.column || this.selectionStart.column==0)
  1585. && (this.selectionEnd.column || this.selectionEnd.column==0))) return
  1586. if(this.hasValueCellItem.cellNumber>1 || this.hasValueCellItem.cellNumber<0){
  1587. return this.$message.warning(this.$t('ETable.Msg.merge_cell_fail_msg'))
  1588. }
  1589. const firstCell = this.config.data[this.selectionStart.row][this.selectionStart.column]
  1590. if(this.hasValueCellItem.cellNumber!=0 && (this.hasValueCellItem.row!=this.selectionStart.row || this.hasValueCellItem.column!=this.selectionStart.column)){
  1591. const reserveCell=this.config.data[this.hasValueCellItem.row][this.hasValueCellItem.column]
  1592. // 将原本有值的单元格 移给左上角第一个单元格
  1593. firstCell.ShowValue=reserveCell.ShowValue
  1594. firstCell.ShowStyle=reserveCell.ShowStyle
  1595. firstCell.ShowFormatValue=reserveCell.ShowFormatValue
  1596. firstCell.Value=reserveCell.Value
  1597. firstCell.DataType=reserveCell.DataType
  1598. firstCell.DataTimeType=reserveCell.DataTimeType
  1599. firstCell.DataTime=reserveCell.DataTime
  1600. firstCell.EdbInfoId=reserveCell.EdbInfoId
  1601. reserveCell.CanEdit && (firstCell.CanEdit=reserveCell.CanEdit)
  1602. reserveCell.Extra && (firstCell.Extra=reserveCell.Extra)
  1603. // 处理合并后的依赖关系 就是替换
  1604. this.replaceCellRelation(reserveCell.Uid,firstCell.Uid)
  1605. // 清空
  1606. this.clearCell(reserveCell)
  1607. }
  1608. this.$set(firstCell,'merData',{
  1609. type:'merge',
  1610. mer:{
  1611. sKey:firstCell.Uid,//保留的单元格的Uid
  1612. rowspan: this.selectionEnd.row - this.selectionStart.row+1,
  1613. colspan: this.selectionEnd.column - this.selectionStart.column+1,
  1614. }
  1615. })
  1616. for (let i = this.selectionStart.row; i < this.selectionEnd.row+1; i++) {
  1617. for (let j = this.selectionStart.column; j < this.selectionEnd.column+1; j++) {
  1618. const element = this.config.data[i][j]
  1619. if(i == this.selectionStart.row && j == this.selectionStart.column){
  1620. continue
  1621. }
  1622. element.merData={
  1623. type:'merged',
  1624. mer:{
  1625. sKey:firstCell.Uid,//左上角第一个单元格的Uid
  1626. }
  1627. }
  1628. }
  1629. }
  1630. let startCell = this.config.data[this.selectionStart.row][this.selectionStart.column]
  1631. let target = this.$refs.tableRef.querySelector(`[data-key="${startCell && startCell.Uid}"]`)
  1632. // 触发单元格的点击事件
  1633. target.click()
  1634. },
  1635. unmergeCellsFun(){
  1636. if((this.selectionStart.row || this.selectionStart.row==0)
  1637. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1638. && (this.selectionStart.column || this.selectionStart.column==0)
  1639. && (this.selectionEnd.column || this.selectionEnd.column==0)){
  1640. // 选区
  1641. for (let i = this.selectionStart.row; i < this.selectionEnd.row+1; i++) {
  1642. for (let j = this.selectionStart.column; j < this.selectionEnd.column+1; j++) {
  1643. this.unmergeCellFun(this.config.data[i][j])
  1644. }
  1645. }
  1646. }else{
  1647. // 单个单元格
  1648. this.selectCell && this.unmergeCellFun(this.selectCell)
  1649. }
  1650. this.hasMergedCell=false
  1651. // 取消合并后,调整选区(有的话)
  1652. if((this.selectionStart.row || this.selectionStart.row==0)
  1653. && (this.selectionEnd.row || this.selectionEnd.row==0)
  1654. && (this.selectionStart.column || this.selectionStart.column==0)
  1655. && (this.selectionEnd.column || this.selectionEnd.column==0)){
  1656. this.selectionStart.rowSpan=1
  1657. this.selectionStart.colSpan=1
  1658. this.selectionEnd.row += (this.selectionEnd.rowSpan-1)
  1659. this.selectionEnd.column += (this.selectionEnd.colSpan-1)
  1660. this.selectionEnd.rowSpan=1
  1661. this.selectionEnd.colSpan=1
  1662. }
  1663. },
  1664. unmergeCellFun(cell){
  1665. if(!(cell.merData && cell.merData.type=='merge')) return
  1666. let {row,col} = this.findDataByStartKey(cell.merData.mer.sKey)
  1667. const sRow = row,
  1668. sCol = col,
  1669. eRow = row+cell.merData.mer.rowspan-1,
  1670. eCol = col+cell.merData.mer.colspan-1
  1671. for (let i = sRow; i < eRow+1; i++) {
  1672. for (let j = sCol; j < eCol+1; j++) {
  1673. this.config.data[i][j].merData=null
  1674. }
  1675. }
  1676. },
  1677. toolCellMergeFun(){
  1678. if(this.hasMergedCell) this.unmergeCellsFun()
  1679. else this.mergeCellFun()
  1680. }
  1681. },
  1682. };
  1683. </script>
  1684. <style scoped lang="scss">
  1685. .nodata {
  1686. text-align: center;
  1687. font-size: 16px;
  1688. color: #666;
  1689. padding: 100px 0;
  1690. }
  1691. .table-wrapper {
  1692. width: 100%;
  1693. overflow: auto;
  1694. * { box-sizing: border-box; }
  1695. .formula-wrapper {
  1696. height: 42px;
  1697. display: flex;
  1698. align-items: center;
  1699. background: #fff;
  1700. border-radius: 4px;
  1701. box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
  1702. border: 1px solid #DCDFE6;
  1703. margin-bottom: 15px;
  1704. padding: 0 15px;
  1705. }
  1706. .table td,th {
  1707. width: 104px;
  1708. min-width: 104px;
  1709. height: 35px;
  1710. max-height: 35px;
  1711. background: #fff;
  1712. text-align: center;
  1713. word-break: break-all;
  1714. border: 1px solid #dcdfe6;
  1715. overflow: hidden;
  1716. text-overflow: ellipsis;
  1717. position: relative;
  1718. color: #606266;
  1719. &.td-chose::after {
  1720. position: absolute;
  1721. top: 0;
  1722. left: 0;
  1723. right: 0;
  1724. bottom: 0;
  1725. content: "";
  1726. display: block;
  1727. outline: 0;
  1728. border: 2px solid #0033ff;
  1729. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1730. }
  1731. &.td-relation::after {
  1732. position: absolute;
  1733. top: 0;
  1734. left: 0;
  1735. right: 0;
  1736. bottom: 0;
  1737. content: "";
  1738. display: block;
  1739. outline: 0;
  1740. border: 2px dashed #0033ff;
  1741. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1742. }
  1743. // &.td-col-select::after {
  1744. // position: absolute;
  1745. // top: 0;
  1746. // left: 0;
  1747. // right: 0;
  1748. // bottom: 0;
  1749. // content: "";
  1750. // display: block;
  1751. // outline: 0;
  1752. // border: 1px solid rgb(24, 173, 24);
  1753. // border-bottom: none;
  1754. // border-top: none;
  1755. // }
  1756. // &.td-row-select::after {
  1757. // position: absolute;
  1758. // top: 0;
  1759. // left: 0;
  1760. // right: 0;
  1761. // bottom: 0;
  1762. // content: "";
  1763. // display: block;
  1764. // outline: 0;
  1765. // border: 1px solid rgb(24, 173, 24);
  1766. // border-left: none;
  1767. // border-right: none;
  1768. // }
  1769. &.td-choose-insert-target::after {
  1770. position: absolute;
  1771. top: 0;
  1772. left: 0;
  1773. right: 0;
  1774. bottom: 0;
  1775. content: "";
  1776. display: block;
  1777. outline: 0;
  1778. border: 2px dashed orange;
  1779. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1780. }
  1781. }
  1782. .th-tg {
  1783. background: #ebeef5;
  1784. &:hover {
  1785. cursor: pointer;
  1786. background: #ddd;
  1787. /* border: 2px solid #409eff; */
  1788. }
  1789. &.sm {
  1790. width: 36px;
  1791. min-width: 36px;
  1792. max-width: 36px;
  1793. }
  1794. }
  1795. //整行选中
  1796. tr {
  1797. position: relative;
  1798. &.choose-all::after {
  1799. position: absolute;
  1800. top: 0;
  1801. left: 0;
  1802. right: 0;
  1803. bottom: 0;
  1804. content: "";
  1805. display: block;
  1806. outline: 0;
  1807. border: 2px solid #5897fb;
  1808. box-shadow: 0 0 5px rgba(73, 177, 249, 0.5);
  1809. }
  1810. }
  1811. .contextMenu-wrapper {
  1812. position: fixed;
  1813. z-index: 99;
  1814. top: -9999px;
  1815. left: -9999px;
  1816. background: #fff;
  1817. padding: 10px 0;
  1818. min-width: 180px;
  1819. max-height: 400px;
  1820. overflow-y: auto;
  1821. /* border: 1px solid #999; */
  1822. box-shadow: 0 1px 4px #999;
  1823. .item {
  1824. padding: 10px 25px;
  1825. cursor: pointer;
  1826. &:hover {
  1827. background-color: #f5f7fa;
  1828. }
  1829. &:hover .subMenu-wrapper {
  1830. display: block;
  1831. }
  1832. }
  1833. .subMenu-wrapper {
  1834. width: 180px;
  1835. /* display: none; */
  1836. padding: 10px 0;
  1837. /* box-shadow: 0 1px 4px #999; */
  1838. /* background: #fff; */
  1839. /* position: absolute;
  1840. right: -178px;
  1841. top:-205px;
  1842. max-height: 400px;
  1843. overflow-y: auto; */
  1844. .item {
  1845. &:hover {
  1846. background: #fff;
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. </style>
  1853. <style lang="scss">
  1854. .table-wrapper {
  1855. td {
  1856. .el-input__inner {
  1857. border: none;
  1858. outline: none;
  1859. text-align: center;
  1860. height: 34px;
  1861. line-height: 34px;
  1862. }
  1863. }
  1864. .el-input.is-disabled .el-input__inner {
  1865. background-color: #fff;
  1866. }
  1867. }
  1868. .formula-wrapper .el-input__inner { border: none; outline: none; }
  1869. .edb-select-popover {
  1870. width: 300px !important;
  1871. .edb-item {
  1872. display: flex;
  1873. justify-content: space-between;
  1874. align-items: center;
  1875. .edb-item-name {
  1876. max-width: 260px;
  1877. }
  1878. }
  1879. }
  1880. .mixed-edb-slide-collapse {
  1881. border: none !important;
  1882. .el-collapse-item__header {
  1883. padding: 0;
  1884. height: auto;
  1885. line-height: normal;
  1886. margin-bottom: 0 !important;
  1887. background: transparent !important;
  1888. }
  1889. .el-collapse-item__wrap {
  1890. background: transparent !important;
  1891. border: none !important;
  1892. }
  1893. .el-collapse-item__content {
  1894. padding: 0 !important;
  1895. }
  1896. }
  1897. </style>