index.vue 34 KB

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