index.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. <template>
  2. <div
  3. v-loading="config.loading"
  4. element-loading-text="数据加载中"
  5. :element-loading-background="loadingBackground"
  6. style="width: 100%;height: 100%"
  7. class="bs-design-wrap "
  8. >
  9. <!-- <span style="color: aliceblue;font-size: 40px;">
  10. {{ columnData }}
  11. </span> -->
  12. <!-- :border="this.config.customize.border" -->
  13. <el-table
  14. :id="config.code"
  15. ref="table"
  16. :key="updateKey"
  17. class="custom-table"
  18. height="100%"
  19. :stripe="config.customize.stripe"
  20. :data="config.option.tableData"
  21. :header-cell-style="headerCellStyle"
  22. :cell-style="cellStyle"
  23. :row-style="rowStyle"
  24. @row-click="rowClick"
  25. >
  26. <!-- :label="getLabel(col)" -->
  27. <el-table-column
  28. v-for="(col, index) in columnData"
  29. :key="index"
  30. show-overflow-tooltip
  31. :prop="col.alias"
  32. align="center"
  33. :render-header="renderHeader"
  34. >
  35. <!-- 自定义头部 -->
  36. <!-- <template
  37. slot="header"
  38. >
  39. <div class="default-class header-cell">
  40. <Header :render="col.render" />
  41. </div>
  42. </template> -->
  43. <template slot-scope="scope">
  44. <div
  45. :style="conditionalStyle(cellStyleList[scope.$index][Object.keys(columnData).findIndex(item => item === scope.column.property)])"
  46. class="default-class cell"
  47. >
  48. <span
  49. v-if="!conditionalComponent(cellStyleList[scope.$index][Object.keys(columnData).findIndex(item => item === scope.column.property)])"
  50. >
  51. {{ conditionalData(scope.row[col.alias], cellStyleList[scope.$index][Object.keys(columnData).findIndex(item => item === scope.column.property)]) }}
  52. </span>
  53. <div
  54. v-if="conditionalComponent(cellStyleList[scope.$index][Object.keys(columnData).findIndex(item => item === scope.column.property)])"
  55. style="width: 100%;display: flex;justify-content: center;align-items: center;"
  56. >
  57. <CellComponent
  58. :setting-data="cellStyleList[scope.$index][Object.keys(columnData).findIndex(item => item === scope.column.property)]"
  59. :value="conditionalData(scope.row[col.alias], cellStyleList[scope.$index][Object.keys(columnData).findIndex(item => item === scope.column.property)])"
  60. />
  61. </div>
  62. <!-- <component :is="" /> -->
  63. <!-- <div v-if="cellStyleList[scope.$index][Object.keys(columnData).findIndex(item => item === scope.column.property)].style.action.component.type">
  64. 123
  65. </div> -->
  66. </div>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. </div>
  71. </template>
  72. <script>
  73. import CellComponent from './renderCellComponent.js'
  74. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  75. import commonMixins from 'data-room-ui/js/mixins/commonMixins'
  76. import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
  77. import linkageMixins from 'data-room-ui/js/mixins/linkageMixins'
  78. import cloneDeep from 'lodash/cloneDeep'
  79. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  80. export default {
  81. name: 'TableChart',
  82. mixins: [paramsMixins, commonMixins, linkageMixins],
  83. props: {
  84. id: {
  85. type: String,
  86. default: ''
  87. },
  88. config: {
  89. type: Object,
  90. default: () => ({})
  91. }
  92. },
  93. components: {
  94. CellComponent
  95. },
  96. template: '',
  97. data () {
  98. return {
  99. conditionList: [],
  100. updateKey: 0,
  101. headerCellStyleObj: {
  102. backgroundColor: 'transparent'
  103. },
  104. cellStyleObj: {
  105. backgroundColor: 'transparent'
  106. },
  107. columnData: {},
  108. // 第一次获取
  109. isInit: true,
  110. cellStyleList: []
  111. // 条件脚本
  112. // conditionList: [
  113. // {
  114. // exp: 'row === 1',
  115. // column: '0',
  116. // propertyList: [
  117. // {
  118. // type: 'style',
  119. // style: 'background-color',
  120. // value: 'red',
  121. // scope: 'row'
  122. // },
  123. // {
  124. // type: 'style',
  125. // style: 'font-size',
  126. // value: '30',
  127. // unit: 'px',
  128. // scope: 'column'
  129. // },
  130. // {
  131. // type: 'component',
  132. // // component: {
  133. // // type: 'el-button',
  134. // // props: {
  135. // // type: 'primary',
  136. // // size: 'mini'
  137. // // },
  138. // // style: {
  139. // // width: '100%'
  140. // // }
  141. // // },
  142. // scope: 'row'
  143. // },
  144. // {
  145. // type: 'style',
  146. // style: 'font-size',
  147. // value: '60',
  148. // unit: 'px',
  149. // // component: {
  150. // // type: 'el-button',
  151. // // props: {
  152. // // type: 'primary',
  153. // // size: 'mini'
  154. // // },
  155. // // style: {
  156. // // width: '100%'
  157. // // }
  158. // // },
  159. // scope: 'cell'
  160. // },
  161. // {
  162. // type: 'newValue',
  163. // exp: '"新值" + cellValue',
  164. // scope: 'row'
  165. // }
  166. // ]
  167. // }
  168. // // {
  169. // // exp: "row === 2 && column === 'keyWord'",
  170. // // scope: 'row',
  171. // // action:
  172. // // {updateTableProperty
  173. // // exp: '',
  174. // // component: {
  175. // // type: ''
  176. // // },
  177. // // style: {
  178. // // 'background-color': 'yellow',
  179. // // 'font-size': '20px'
  180. // // }
  181. // // }
  182. // // },
  183. // // {
  184. // // exp: " column === 'userNum'",
  185. // // scope: 'column',
  186. // // action:
  187. // // {
  188. // // exp: 'Number(cellValue)',
  189. // // component: {
  190. // // type: 'el-progress',
  191. // // props: {
  192. // // status: 'exception',
  193. // // 'stroke-width': 50,
  194. // // 'text-inside': true
  195. // // },
  196. // // style: {
  197. // // width: '100%'
  198. // // }
  199. // // },
  200. // // style: {
  201. // // 'background-color': '',
  202. // // 'font-size': '25px'
  203. // // }
  204. // // }
  205. // // },
  206. // // {
  207. // // exp: " column === 'searchNum'",
  208. // // scope: 'column',
  209. // // action:
  210. // // {
  211. // // exp: '',
  212. // // component: {
  213. // // type: 'el-input',
  214. // // props: {
  215. // // placeholder: '请输入',
  216. // // disabled: true
  217. // // },
  218. // // style: {
  219. // // width: '300px'
  220. // // }
  221. // // },
  222. // // style: {
  223. // // 'background-color': 'pink'
  224. // // }
  225. // // }
  226. // // },
  227. // // {
  228. // // exp: 'column === "ranking" && cellValue === 1',
  229. // // scope: 'cell',
  230. // // action: {
  231. // // exp: '',
  232. // // component: {
  233. // // type: '',
  234. // // props: {},
  235. // // style: {}
  236. // // },
  237. // // style: {
  238. // // // 使用红色圆圈
  239. // // 'background-color': 'red',
  240. // // 'border-radius': '50%',
  241. // // 'font-size': '30px',
  242. // // width: '80px',
  243. // // height: '80px',
  244. // // display: 'flex',
  245. // // 'justify-content': 'center',
  246. // // 'align-items': 'center'
  247. // // }
  248. // // }
  249. // // },
  250. // // {
  251. // // exp: 'column === "ranking" && cellValue === 2',
  252. // // scope: 'cell',
  253. // // action: {
  254. // // exp: '',
  255. // // component: {
  256. // // type: '',
  257. // // props: {},
  258. // // style: {}
  259. // // },
  260. // // style: {
  261. // // // 使用伪元素红色圆环
  262. // // 'background-color': 'blue',
  263. // // 'border-radius': '50%',
  264. // // 'font-size': '30px',
  265. // // width: '80px',
  266. // // height: '80px',
  267. // // display: 'flex',
  268. // // 'justify-content': 'center',
  269. // // 'align-items': 'center'
  270. // // }
  271. // // }
  272. // // },
  273. // // {
  274. // // exp: 'column === "ranking" && cellValue === 3',
  275. // // scope: 'cell',
  276. // // action: {
  277. // // exp: '',
  278. // // component: {
  279. // // type: '',
  280. // // props: {},
  281. // // style: {}
  282. // // },
  283. // // style: {
  284. // // // 使用红色圆圈
  285. // // 'background-color': 'white !important',
  286. // // 'border-radius': '50%',
  287. // // 'font-size': '30px',
  288. // // width: '80px',
  289. // // height: '80px',
  290. // // display: 'flex',
  291. // // 'justify-content': 'center',
  292. // // 'align-items': 'center'
  293. // // }
  294. // // }
  295. // // },
  296. // // {
  297. // // exp: 'column === "ranking" && cellValue === 4',
  298. // // scope: 'cell',
  299. // // action: {
  300. // // exp: 'cellValue = ""',
  301. // // component: {
  302. // // type: '',
  303. // // props: {},
  304. // // style: {}
  305. // // },
  306. // // style: {
  307. // // 'background-image': 'url(https://images.dog.ceo/breeds/samoyed/n02111889_10206.jpg)',
  308. // // // 宽度50px
  309. // // width: '80px',
  310. // // height: '80px',
  311. // // // 图片不裁切
  312. // // 'background-size': 'cover'
  313. // // }
  314. // // }
  315. // // }
  316. // ]
  317. }
  318. },
  319. computed: {
  320. headerCellStyle () {
  321. const headerBackgroundColor = {
  322. light: '#ffffff',
  323. dark: 'transparent'
  324. }
  325. if (document.getElementById(this.config.code)?.querySelector('tr')) {
  326. document
  327. .getElementById(this.config.code)
  328. .querySelector('tr').style.backgroundColor =
  329. this.customTheme !== 'custom'
  330. ? this.config.customize.headerBackgroundColor || headerBackgroundColor[this.customTheme]
  331. : this.headerCellStyleObj.backgroundColor
  332. }
  333. const style = {
  334. height: '48px',
  335. borderBottom: 'solid 2px #007aff',
  336. backgroundColor:
  337. this.customTheme !== 'custom'
  338. ? this.config.customize.headerBackgroundColor || headerBackgroundColor[this.customTheme]
  339. : this.headerCellStyleObj.backgroundColor,
  340. color:
  341. this.customTheme === 'light'
  342. ? '#000000'
  343. : this.config.customize.headerFontColor || '#000000',
  344. fontSize: this.config.customize.headerFontSize + 'px' || '14px'
  345. }
  346. return style
  347. }
  348. },
  349. watch: {
  350. activeItemConfig (val) {
  351. }
  352. },
  353. created () { },
  354. mounted () {
  355. this.chartInit()
  356. // this.config.option?.columnData 对象的key 根据 list 对应的key 来排序
  357. EventBus.$on('dragSelectChange', (val) => {
  358. if (val.length > 0) {
  359. const sortedColumnData = {}
  360. const columnData = cloneDeep(this.config.option?.columnData)
  361. val.forEach((item, index) => {
  362. sortedColumnData[item] = columnData[item]
  363. })
  364. this.columnData = sortedColumnData
  365. this.updateKey = new Date().getTime()
  366. }
  367. })
  368. EventBus.$on('updateTableProperty', list => {
  369. this.getTablePropertyData(list).then(data => {
  370. this.conditionList = data
  371. this.updateTableProperty(this.config.option.tableData)
  372. })
  373. })
  374. this.getTablePropertyData().then(data => {
  375. this.conditionList = data
  376. if (data) {
  377. if (this.config.option.tableData && this.config.option.tableData.length > 0) {
  378. this.updateTableProperty(this.config.option.tableData)
  379. }
  380. }
  381. })
  382. },
  383. beforeDestroy () {
  384. EventBus.$off('dragSelectChange')
  385. EventBus.$off('updateTableProperty')
  386. },
  387. methods: {
  388. getTablePropertyData (conditionListParam) {
  389. return new Promise(resolve => {
  390. const list = []
  391. const conditionList = conditionListParam || cloneDeep(this.config.customize.condition.columnConditionList)
  392. conditionList.forEach((condition) => {
  393. // condition.exp = ''
  394. // condition.expList.forEach(exp => {
  395. // condition.exp += ` ${exp.relation ? exp.relation : ''} ${exp.value}`
  396. // })
  397. condition.propertyList.forEach((item) => {
  398. if (item.property === 'background-image' && item.enable) {
  399. if (item.value.findIndex(item => item === 'url') === -1) {
  400. item.value = `url(${item.value})`
  401. }
  402. }
  403. // if (item.type === 'component') {
  404. // console.log(item.cellComponent.type)
  405. // }
  406. })
  407. // console.log(condition)
  408. list.push(condition)
  409. resolve(list)
  410. })
  411. })
  412. },
  413. updateTableProperty (tableData) {
  414. const cellSettingList = []
  415. for (let i = 0; i < tableData.length; i++) {
  416. cellSettingList.push([])
  417. for (let j = 0; j < Object.keys(this.columnData).length; j++) {
  418. cellSettingList[i].push({ style: {}, cellIndex: { rowNum: i, columnNum: j }, cellComponent: { type: '' }, exp: '' })
  419. }
  420. }
  421. const rowNum = null
  422. const columnNum = null
  423. const cellRow = null
  424. const cellColumn = null
  425. const rowList = []
  426. // 单元格脚本列表
  427. const cellExpList = []
  428. // 单元格样式列表
  429. const cellStyleList = []
  430. // 单元格组件列表
  431. const cellComponentList = []
  432. tableData.forEach((tableItem, index) => {
  433. Object.values(tableItem).forEach((data, dataIndex) => {
  434. this.conditionList.forEach((condition) => {
  435. const cellValue = data
  436. const column = Object.keys(this.columnData)[dataIndex]
  437. const row = index
  438. if (condition.exp.trim() !== '') {
  439. // 如果condition.exp空字符串 则不执行
  440. eval(`if(${condition.exp}){
  441. if (condition.propertyList.length > 0) {
  442. condition.propertyList.forEach((property) => {
  443. if (property.scope === 'row' && property.enable) {
  444. rowNum = index.toString()
  445. if (property.type === 'style') {
  446. cellStyleList.push({
  447. rowNum: index.toString(),
  448. style: {
  449. [property.property]: property.value + property.unit
  450. }
  451. })
  452. } else if (property.type === 'exp') {
  453. cellExpList.push({
  454. rowNum: index.toString(),
  455. exp: property.exp
  456. })
  457. } else if (property.type === 'component') {
  458. cellComponentList.push({
  459. rowNum: index.toString(),
  460. component: property.cellComponent
  461. })
  462. }
  463. } else if (property.scope === 'column' && property.enable && condition.column.toString() === dataIndex.toString()) {
  464. columnNum = dataIndex.toString()
  465. if (property.type === 'style') {
  466. cellStyleList.push({
  467. columnNum: dataIndex.toString(),
  468. style: {
  469. [property.property]: property.value + property.unit
  470. }
  471. })
  472. } else if (property.type === 'exp') {
  473. cellExpList.push({
  474. columnNum: dataIndex.toString(),
  475. exp: property.exp
  476. })
  477. } else if (property.type === 'component') {
  478. cellComponentList.push({
  479. columnNum: dataIndex.toString(),
  480. component: property.cellComponent
  481. })
  482. }
  483. } else if (property.scope === 'cell' && property.enable) {
  484. cellRow = index.toString()
  485. cellColumn = dataIndex.toString()
  486. }
  487. })
  488. }
  489. }`)
  490. // 生成行数据
  491. // rowList.push(cellSettingList[row][dataIndex])
  492. cellStyleList.forEach((cellStyle) => {
  493. if (cellStyle.rowNum === rowNum) {
  494. cellSettingList[Number(cellStyle.rowNum)][dataIndex].style = {
  495. ...cellSettingList[Number(cellStyle.rowNum)][dataIndex].style,
  496. ...cellStyle.style
  497. }
  498. } else if (cellStyle.columnNum && cellStyle.columnNum === condition.column.toString()) {
  499. if (cellSettingList[row][Number(cellStyle.columnNum)]) {
  500. cellSettingList[row][Number(cellStyle.columnNum)].style = {
  501. ...(cellSettingList[row][Number(cellStyle.columnNum)].style || {}),
  502. ...cellStyle.style
  503. }
  504. }
  505. }
  506. })
  507. cellExpList.forEach((cellExp) => {
  508. if (cellExp.rowNum === rowNum) {
  509. cellSettingList[Number(cellExp.rowNum)][dataIndex].exp = cellExp.exp
  510. } else if (cellExp.columnNum && cellExp.columnNum === condition.column.toString()) {
  511. cellSettingList[row][Number(cellExp.columnNum)].exp = cellExp.exp
  512. }
  513. })
  514. cellComponentList.forEach((cellComponent) => {
  515. if (cellComponent.rowNum === rowNum) {
  516. cellSettingList[Number(cellComponent.rowNum)][dataIndex].cellComponent = {
  517. ...cellSettingList[Number(cellComponent.rowNum)][dataIndex].cellComponent,
  518. ...cellComponent.component
  519. }
  520. } else if (cellComponent.columnNum && cellComponent.columnNum === condition.column.toString()) {
  521. cellSettingList[row][Number(cellComponent.columnNum)].cellComponent = {
  522. ...cellSettingList[row][Number(cellComponent.columnNum)].cellComponent,
  523. ...cellComponent.component
  524. }
  525. }
  526. })
  527. // cellExpList.forEach((cellExp) => {
  528. // })
  529. // cellComponentList.forEach((cellComponent) => {
  530. // console.log(111, cellComponent)
  531. // if (cellComponent.rowNum === row.toString() && cellComponent.columnNum === dataIndex.toString()) {
  532. // cellSettingList[row][dataIndex].cellComponent = cellComponent.component
  533. // }
  534. // })
  535. // condition.propertyList.forEach((property) => {
  536. // if (property.scope === 'row') {
  537. // // console.log(property.property)
  538. // // if (rowNum && property.enable) {
  539. // // cellSettingList[Number(rowNum)].forEach((rowItem) => {
  540. // // if (property.type === 'style') {
  541. // // rowItem.style[property.property] = property.value + property.unit
  542. // // } else if (property.type === 'component') {
  543. // // rowItem.cellComponent = property.cellComponent
  544. // // } else if (property.type === 'exp') {
  545. // // rowItem.cellData.exp = property.exp
  546. // // }
  547. // // })
  548. // // }
  549. // // rowNum = null
  550. // } else if (property.scope === 'column') {
  551. // if (columnNum && property.enable) {
  552. // if (property.type === 'style') {
  553. // cellSettingList[row][Number(condition.column)].style[property.property] = property.value + property.unit
  554. // } else if (property.type === 'component') {
  555. // cellSettingList[row][Number(condition.column)].cellComponent = property.cellComponent
  556. // } else if (property.type === 'exp') {
  557. // cellSettingList[row][Number(condition.column)].exp = property.exp
  558. // }
  559. // if (cellSettingList[row][Number(condition.column)].cellIndex.columnNum !== Number(columnNum)) {
  560. // columnNum = null
  561. // }
  562. // }
  563. // } else if (property.scope === 'cell') {
  564. // if (cellRow && cellColumn && property.enable) {
  565. // if (property.type === 'style') {
  566. // cellSettingList[Number(cellRow)][Number(cellColumn)].style[property.property] = property.value + property.unit
  567. // } else if (property.type === 'component') {
  568. // cellSettingList[Number(cellRow)][Number(cellColumn)].cellComponent = property.cellComponent
  569. // } else if (property.type === 'exp') {
  570. // cellSettingList[Number(cellRow)][Number(cellColumn)].exp = property.exp
  571. // }
  572. // }
  573. // if (cellSettingList[Number(cellRow)][Number(cellColumn)].cellIndex.rowNum !== Number(cellRow) || cellSettingList[Number(cellRow)][Number(cellColumn)].cellIndex.columnNum !== Number(cellColumn)) {
  574. // cellRow = null
  575. // cellColumn = null
  576. // }
  577. // }
  578. // })
  579. // if (script.scope === 'row') {
  580. // // 如果作用范围是行
  581. // if (rowNum) {
  582. // cellSettingList[rowNum].forEach((rowItem) => {
  583. // rowItem.style = script.action.style
  584. // })
  585. // }
  586. // } else if (script.scope === 'column') {
  587. // // 如果作用范围是列
  588. // if (columnNum) {
  589. // if (script.action.style && !cellStyleList.find(item => item.columnNum === columnNum)) {
  590. // cellStyleList.push({
  591. // columnNum: columnNum,
  592. // style: script.action.style
  593. // })
  594. // script.action.style = {}
  595. // }
  596. // if (cellStyleList.length > 0) {
  597. // if (cellStyleList.find(item => item.columnNum === cellSettingList[row][dataIndex].cellIndex.columnNum)) {
  598. // cellSettingList[row][dataIndex].style = cellStyleList.find(item => item.columnNum === cellSettingList[row][dataIndex].cellIndex.columnNum).style
  599. // }
  600. // }
  601. // if (script.action.exp && !cellExpList.find(item => item.columnNum === columnNum)) {
  602. // cellExpList.push({
  603. // columnNum: columnNum,
  604. // exp: script.action.exp
  605. // })
  606. // script.action.exp = ''
  607. // }
  608. // if (cellExpList.length > 0) {
  609. // if (cellExpList.find(item => item.columnNum === cellSettingList[row][dataIndex].cellIndex.columnNum)) {
  610. // cellSettingList[row][dataIndex].cellData.exp = cellExpList.find(item => item.columnNum === cellSettingList[row][dataIndex].cellIndex.columnNum).exp
  611. // }
  612. // }
  613. // if (script.action.component && !cellComponentList.find(item => item.columnNum === columnNum)) {
  614. // cellComponentList.push({
  615. // columnNum: columnNum,
  616. // component: script.action.component
  617. // })
  618. // script.action.component = {}
  619. // }
  620. // if (cellComponentList.length > 0) {
  621. // if (cellComponentList.find(item => item.columnNum === cellSettingList[row][dataIndex].cellIndex.columnNum)) {
  622. // cellSettingList[row][dataIndex].component = cellComponentList.find(item => item.columnNum === cellSettingList[row][dataIndex].cellIndex.columnNum).component
  623. // }
  624. // }
  625. // }
  626. // } else if (script.scope === 'cell') {
  627. // if (cellRow && cellColumn) {
  628. // cellSettingList[Number(cellRow)][Number(cellColumn)].style = script.action.style
  629. // cellSettingList[Number(cellRow)][Number(cellColumn)].cellData.exp = script.action.exp
  630. // cellSettingList[Number(cellRow)][Number(cellColumn)].component = script.action.component
  631. // }
  632. // }
  633. }
  634. })
  635. rowList.length = 0
  636. })
  637. })
  638. // console.log('cellSettingList', cellSettingList)
  639. this.cellStyleList = cellSettingList
  640. },
  641. // 条件样式
  642. conditionalStyle (data) {
  643. const styleString = Object.keys(data?.style).map((key) => `${this.camelToDash(key)}: ${data.style[key]}`).join('; ')
  644. return styleString
  645. },
  646. camelToDash (str) {
  647. if (typeof str === 'undefined') {
  648. return ''
  649. }
  650. return str.replace(/([A-Z])/g, '-$1').toLowerCase()
  651. },
  652. // 条件脚本
  653. conditionalData (a, b) {
  654. const cellValue = a
  655. let newValue = null
  656. if (b.exp) {
  657. newValue = eval(b.exp)
  658. }
  659. return newValue || cellValue
  660. },
  661. // 判断是否是组件
  662. conditionalComponent (b) {
  663. let isComponent
  664. if (b.cellComponent.type) {
  665. isComponent = true
  666. } else {
  667. isComponent = false
  668. }
  669. return isComponent
  670. },
  671. renderHeader (h, { column, $index }) {
  672. const headerBackgroundColor = {
  673. light: '#ffffff',
  674. dark: 'transparent'
  675. }
  676. const initColor = this.customTheme === 'light' ? '#000000' : '#ffffff'
  677. const style = {
  678. backgroundColor: this.config.customize.headerBackgroundColor || headerBackgroundColor[this.customTheme],
  679. color: this.config.customize.headerFontColor || initColor,
  680. fontSize: this.config.customize.headerFontSize + 'px' || '14px'
  681. }
  682. console.log(11, style)
  683. return h('div', {
  684. style: style
  685. },
  686. [
  687. h('span', column.label)
  688. ])
  689. },
  690. // customizeCellStyles (initialIndex, cellData, column, label, scope) {
  691. // // eslint-disable-next-line no-unused-vars
  692. // const cellValue = cellData[label]
  693. // const styleData = ''
  694. // // eslint-disable-next-line no-unused-vars
  695. // const row = initialIndex + 1
  696. // const scopeRow = null
  697. // this.conditionScript.forEach((data) => {
  698. // eval(`if(${data.exp}){if(data.scope === 'row'){ scopeRow = initialIndex }}`)
  699. // })
  700. // return styleData
  701. // },
  702. cellStyle ({ row, column, rowIndex, columnIndex }) {
  703. const bodyBackgroundColor = {
  704. light: '#ffffff',
  705. dark: 'transparent'
  706. }
  707. const initColor = this.customTheme === 'light' ? '#000000' : '#ffffff'
  708. const style = {
  709. backgroundColor: '',
  710. color: this.config.customize.bodyFontColor || initColor,
  711. fontSize: this.config.customize.bodyFontSize + 'px' || '14px'
  712. }
  713. // 如果设置了奇偶行的背景颜色,则以奇偶行的背景颜色为主
  714. if (rowIndex % 2 && this.config.customize.evenRowBackgroundColor) {
  715. style.backgroundColor = this.config.customize.evenRowBackgroundColor
  716. } else if (!(rowIndex % 2) && this.config.customize.oddRowBackgroundColor) {
  717. style.backgroundColor = this.config.customize.oddRowBackgroundColor
  718. } else {
  719. style.backgroundColor = this.config.customize.bodyBackgroundColor || bodyBackgroundColor[this.customTheme]
  720. }
  721. return style
  722. },
  723. rowStyle ({ row, rowIndex }) {
  724. if (rowIndex % 2) {
  725. return {
  726. backgroundColor: this.config.customize.evenRowBackgroundColor
  727. }
  728. } else {
  729. return {
  730. backgroundColor: this.config.customize.oddRowBackgroundColor
  731. }
  732. }
  733. },
  734. // 表格点击事件
  735. rowClick (row) {
  736. this.linkage(row)
  737. },
  738. changeStyle (config) {
  739. config = { ...this.config, ...config }
  740. // 样式改变时更新主题配置
  741. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  742. this.changeChartConfig(config)
  743. if (config.code === this.activeCode) {
  744. this.changeActiveItemConfig(config)
  745. }
  746. return config
  747. },
  748. dataFormatting (config, data) {
  749. config.option.tableData = data?.data && data.data.length > 0 ? data.data : []
  750. const filteredData = {}
  751. const columnData = data?.columnData || {}
  752. const dimensionFieldList = config.dataSource.dimensionFieldList || []
  753. if (config.dataSource.dimensionFieldList && config.dataSource.dimensionFieldList.length > 0) {
  754. // 根据config.dataSource.dimensionFieldList 数据的顺序将表格列顺序调整,使其初始化的时候,顺序和组件配置面板中的一致
  755. const sortedColumnData = {}
  756. dimensionFieldList.forEach((item, index) => {
  757. sortedColumnData[item] = columnData[item]
  758. })
  759. Object?.keys(sortedColumnData).forEach(key => {
  760. if (
  761. config.dataSource.dimensionFieldList.includes(sortedColumnData[key]?.alias)
  762. ) {
  763. filteredData[key] = sortedColumnData[key]
  764. }
  765. })
  766. config.option.columnData = filteredData
  767. } else {
  768. config.option.columnData = columnData
  769. }
  770. this.columnData = cloneDeep(config.option.columnData)
  771. this.updateTableProperty(config.option.tableData)
  772. this.updateKey = new Date().getTime()
  773. return config
  774. },
  775. // 将样式字符串转成对象, 用于自定义主题,表格头部样式
  776. headerCellStyleToObj () {
  777. const str = this.themeJson.themeCss
  778. // 匹配包含header-cell-style的样式字符串
  779. // 匹配包含header-cell-style的样式字符串
  780. const regex = /\.header-cell-style\{([^{}]+)\}/
  781. const match = str.match(regex)
  782. if (match) {
  783. // 将样式字符串转成对象
  784. const styleStr = match[1].trim().replace(/\s*;\s*$/, '') // 去掉末尾的空格和分号
  785. // const styleObj = {};
  786. styleStr.split(';').forEach(s => {
  787. const [key, value] = s.split(':')
  788. if (key && value) {
  789. // 判断是否为空字符串
  790. this.headerCellStyleObj[key.trim()] = value.trim()
  791. }
  792. })
  793. } else {
  794. this.headerCellStyleObj = {}
  795. }
  796. },
  797. // 将样式字符串转成对象, 用于自定义主题,表格主体样式
  798. cellStyleToObj () {
  799. const str = this.themeJson.themeCss
  800. // 匹配包含header-cell-style的样式字符串
  801. // 匹配包含header-cell-style的样式字符串
  802. const regex = /\.cell-style\{([^{}]+)\}/
  803. const match = str.match(regex)
  804. if (match) {
  805. // 将样式字符串转成对象
  806. const styleStr = match[1].trim().replace(/\s*;\s*$/, '') // 去掉末尾的空格和分号
  807. styleStr.split(';').forEach(s => {
  808. const [key, value] = s.split(':')
  809. if (key && value) {
  810. // 判断是否为空字符串
  811. this.cellStyleObj[key.trim()] = value.trim()
  812. }
  813. })
  814. } else {
  815. this.cellStyleObj = {}
  816. }
  817. },
  818. getLabel (data) {
  819. return data.remark || data.originalColumn
  820. }
  821. }
  822. }
  823. </script>
  824. <style lang="scss" scoped>
  825. .bs-design-wrap {
  826. position: relative;
  827. width: 100%;
  828. height: 100%;
  829. background-color: transparent;
  830. border-radius: 4px;
  831. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
  832. box-sizing: border-box;
  833. }
  834. ::v-deep .el-table {
  835. // height: 100%;
  836. background-color: transparent;
  837. }
  838. ::v-deep .el-table tr {
  839. background-color: transparent;
  840. }
  841. ::v-deep .el-table__body {
  842. height: 100%;
  843. }
  844. ::v-deep .el-table .el-table__header tr {
  845. background-color: transparent;
  846. }
  847. ::v-deep tr.el-table__row--striped {
  848. z-index: 1;
  849. /*将容器的 z-index 设为 1,以便其在蒙版之上*/
  850. position: relative;
  851. /*设置容器为相对定位*/
  852. opacity: 0.9;
  853. }
  854. ::v-deep tr.el-table__row--striped::before {
  855. position: absolute;
  856. /*设置蒙版为绝对定位*/
  857. top: 0;
  858. left: 0;
  859. width: 100%;
  860. height: 100%;
  861. background-color: rgba(0, 0, 0, 0.2);
  862. /*设置半透明的灰色背景色*/
  863. z-index: 2;
  864. /*将蒙版的 z-index 设为 2,以便其覆盖在容器之上*/
  865. }
  866. ::v-deep .overlay {
  867. position: absolute;
  868. /*设置蒙版为绝对定位*/
  869. top: 0;
  870. left: 0;
  871. width: 100%;
  872. height: 100%;
  873. background-color: rgba(0, 0, 0, 0.2) !important;
  874. /*设置半透明的灰色背景色*/
  875. z-index: 2;
  876. /*将蒙版的 z-index 设为 2,以便其覆盖在容器之上*/
  877. }
  878. ::v-deep .cell.el-tooltip {
  879. z-index: 3;
  880. min-width: 50px;
  881. white-space: nowrap;
  882. position: inherit;
  883. }
  884. ::v-deep .el-table {
  885. .el-table__cell {
  886. border-bottom: none !important;
  887. }
  888. &:before {
  889. display: none !important;
  890. }
  891. th.gutter,
  892. colgroup.gutter {
  893. width: 0px !important; //此处的宽度值,对应你自定义滚动条的宽度即可
  894. }
  895. }
  896. // 关键css代码
  897. ::v-deep .el-table__header colgroup col[name="gutter"] {
  898. display: table-cell !important;
  899. }
  900. ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  901. width: 10px; // 横向滚动条
  902. height: 10px; // 纵向滚动条 必写
  903. background-color: transparent;
  904. }
  905. // 滚动条的滑块
  906. ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  907. background-color: #9093994D;
  908. border-radius: 5px;
  909. &:hover {
  910. background-color: #90939980;
  911. }
  912. }
  913. .default-class {
  914. height: 100%;
  915. display: flex;
  916. overflow: hidden;
  917. justify-content: center;
  918. align-items: center;
  919. }
  920. ::v-deep .el-table__body {
  921. width: 100% !important;
  922. }
  923. ::v-deep .cell {
  924. padding: 0;
  925. width: 100%;
  926. height: 100%;
  927. }
  928. ::v-deep .el-table th.el-table__cell>.cell {
  929. padding: 0 !important;
  930. }
  931. ::v-deep .el-table__cell {
  932. padding: 0px !important;
  933. }
  934. </style>