index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div
  3. style="width: 100%;height: 100%"
  4. class="bs-design-wrap "
  5. >
  6. <!-- :border="this.config.customize.border" -->
  7. <el-table
  8. :id="config.code"
  9. ref="table"
  10. :key="updateKey"
  11. class="custom-table"
  12. height="100%"
  13. :stripe="config.customize.stripe"
  14. :data="config.option.tableData"
  15. :header-cell-style="headerCellStyle"
  16. :cell-style="cellStyle"
  17. :row-style="rowStyle"
  18. @row-click="rowClick"
  19. >
  20. <el-table-column
  21. v-for="(col, index) in config.option.columnData"
  22. :key="index"
  23. show-overflow-tooltip
  24. :label="col.remark"
  25. :prop="col.alias"
  26. align="center"
  27. />
  28. </el-table>
  29. </div>
  30. </template>
  31. <script>
  32. import commonMixins from 'data-room-ui/js/mixins/commonMixins'
  33. import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
  34. import linkageMixins from 'data-room-ui/js/mixins/linkageMixins'
  35. import cloneDeep from 'lodash/cloneDeep'
  36. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  37. export default {
  38. name: 'TableChart',
  39. mixins: [paramsMixins, commonMixins, linkageMixins],
  40. props: {
  41. id: {
  42. type: String,
  43. default: ''
  44. },
  45. config: {
  46. type: Object,
  47. default: () => ({})
  48. }
  49. },
  50. data () {
  51. return {
  52. updateKey: '',
  53. headerCellStyleObj: {
  54. backgroundColor: 'transparent'
  55. },
  56. cellStyleObj: {
  57. backgroundColor: 'transparent'
  58. }
  59. }
  60. },
  61. computed: {
  62. headerCellStyle () {
  63. const headerBackgroundColor = {
  64. dark: '#141414',
  65. light: '#ffffff',
  66. auto: 'transparent'
  67. }
  68. if (document.getElementById(this.config.code)?.querySelector('tr')) {
  69. document
  70. .getElementById(this.config.code)
  71. .querySelector('tr').style.backgroundColor =
  72. this.customTheme !== 'custom'
  73. ? this.config.customize.headerBackgroundColor || headerBackgroundColor[this.customTheme]
  74. : this.headerCellStyleObj.backgroundColor
  75. }
  76. const style = {
  77. height: '48px',
  78. borderBottom: 'solid 2px #007aff',
  79. backgroundColor:
  80. this.customTheme !== 'custom'
  81. ? this.config.customize.headerBackgroundColor || headerBackgroundColor[this.customTheme]
  82. : this.headerCellStyleObj.backgroundColor,
  83. color:
  84. this.customTheme === 'light'
  85. ? '#000000'
  86. : this.config.customize.headerFontColor || '#000000',
  87. fontSize: this.config.customize.headerFontSize + 'px' || '14px'
  88. }
  89. return style
  90. }
  91. },
  92. created () { },
  93. mounted () {
  94. this.chartInit()
  95. },
  96. methods: {
  97. // 设置表格背景颜色
  98. cellStyle ({ row, column, rowIndex, columnIndex }) {
  99. const bodyBackgroundColor = {
  100. dark: '#141414',
  101. light: '#ffffff',
  102. auto: 'transparent'
  103. }
  104. const initColor = this.customTheme === 'light' ? '#000000' : '#ffffff'
  105. const style = {
  106. backgroundColor: '',
  107. color: this.config.customize.bodyFontColor || initColor,
  108. fontSize: this.config.customize.bodyFontSize + 'px' || '14px'
  109. }
  110. // 如果设置了奇偶行的背景颜色,则以奇偶行的背景颜色为主
  111. if (rowIndex % 2 && this.config.customize.evenRowBackgroundColor) {
  112. style.backgroundColor = this.config.customize.evenRowBackgroundColor
  113. } else if (!(rowIndex % 2) && this.config.customize.oddRowBackgroundColor) {
  114. style.backgroundColor = this.config.customize.oddRowBackgroundColor
  115. } else {
  116. style.backgroundColor = this.config.customize.bodyBackgroundColor || bodyBackgroundColor[this.customTheme]
  117. }
  118. return style
  119. },
  120. // 设置表格行颜色
  121. rowStyle ({ row, rowIndex }) {
  122. if (rowIndex % 2) {
  123. return {
  124. backgroundColor: this.config.customize.evenRowBackgroundColor
  125. }
  126. } else {
  127. return {
  128. backgroundColor: this.config.customize.oddRowBackgroundColor
  129. }
  130. }
  131. },
  132. // 表格点击事件
  133. rowClick (row) {
  134. this.linkage(row)
  135. },
  136. changeStyle (config) {
  137. config = { ...this.config, ...config }
  138. // 样式改变时更新主题配置
  139. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  140. this.changeChartConfig(config)
  141. if (config.code === this.activeCode) {
  142. this.changeActiveItemConfig(config)
  143. }
  144. // const config = cloneDeep(oldConfig)
  145. // if (this.customTheme === 'custom') {
  146. // this.headerCellStyleToObj()
  147. // this.cellStyleToObj()
  148. // }
  149. // if (this.customTheme === 'custom') {
  150. // this.headerCellStyleToObj()
  151. // this.cellStyleToObj()
  152. // }
  153. // if (config.customize.stripe) {
  154. // const trs = document
  155. // .getElementById(this.config.code)
  156. // ?.querySelectorAll('tr.el-table__row--striped')
  157. // if (trs) {
  158. // trs.forEach(tr => {
  159. // tr.style.opacity = '0.9'
  160. // // 透明度
  161. // // const overlay = document.createElement("div");
  162. // // overlay.classList.add("overlay");
  163. // // // 将蒙版添加到容器中
  164. // // tr.appendChild(overlay);
  165. // })
  166. // }
  167. // } else {
  168. // const trs = document
  169. // .getElementById(config.code)
  170. // ?.querySelectorAll('tr.el-table__row--striped')
  171. // if (trs) {
  172. // trs.forEach(tr => {
  173. // tr.style.opacity = '1'
  174. // // 透明度
  175. // // const overlay = document.createElement("div");
  176. // // overlay.classList.add("overlay");
  177. // // // 将蒙版添加到容器中
  178. // // tr.appendChild(overlay);
  179. // })
  180. // }
  181. // // document.querySelectorAll(".overlay").forEach(overlay => {
  182. // // overlay.remove();
  183. // // });
  184. // }
  185. // this.chartInit();
  186. // if (config.customize.evenRowBackgroundColor && !config.customize.oddRowBackgroundColor) {
  187. // config.customize.oddRowBackgroundColor = config.customize.bodyBackgroundColor
  188. // } else if (!config.customize.evenRowBackgroundColor && config.customize.oddRowBackgroundColor) {
  189. // config.customize.evenRowBackgroundColor = config.customize.bodyBackgroundColor
  190. // } else if (!(!config.customize.evenRowBackgroundColor && !config.customize.oddRowBackgroundColor)) {
  191. // config.customize.bodyBackgroundColor = ''
  192. // }
  193. // this.updateKey = new Date().getTime()
  194. return config
  195. },
  196. dataFormatting (config, data) {
  197. config.option.tableData = data?.data
  198. const filteredData = {}
  199. const columnData = data?.columnData || {}
  200. if (config.dataSource.dimensionFieldList && config.dataSource.dimensionFieldList.length > 0) {
  201. Object?.keys(columnData).forEach(key => {
  202. if (
  203. config.dataSource.dimensionFieldList.includes(columnData[key].alias)
  204. ) {
  205. filteredData[key] = columnData[key]
  206. }
  207. })
  208. config.option.columnData = filteredData
  209. } else {
  210. config.option.columnData = columnData
  211. }
  212. this.updateKey = new Date().getTime()
  213. return config
  214. },
  215. // 将样式字符串转成对象, 用于自定义主题,表格头部样式
  216. headerCellStyleToObj () {
  217. const str = this.themeJson.themeCss
  218. // 匹配包含header-cell-style的样式字符串
  219. // 匹配包含header-cell-style的样式字符串
  220. const regex = /\.header-cell-style\{([^{}]+)\}/
  221. const match = str.match(regex)
  222. if (match) {
  223. // 将样式字符串转成对象
  224. const styleStr = match[1].trim().replace(/\s*;\s*$/, '') // 去掉末尾的空格和分号
  225. // const styleObj = {};
  226. styleStr.split(';').forEach(s => {
  227. const [key, value] = s.split(':')
  228. if (key && value) {
  229. // 判断是否为空字符串
  230. this.headerCellStyleObj[key.trim()] = value.trim()
  231. }
  232. })
  233. } else {
  234. this.headerCellStyleObj = {}
  235. }
  236. },
  237. // 将样式字符串转成对象, 用于自定义主题,表格主体样式
  238. cellStyleToObj () {
  239. const str = this.themeJson.themeCss
  240. // 匹配包含header-cell-style的样式字符串
  241. // 匹配包含header-cell-style的样式字符串
  242. const regex = /\.cell-style\{([^{}]+)\}/
  243. const match = str.match(regex)
  244. if (match) {
  245. // 将样式字符串转成对象
  246. const styleStr = match[1].trim().replace(/\s*;\s*$/, '') // 去掉末尾的空格和分号
  247. styleStr.split(';').forEach(s => {
  248. const [key, value] = s.split(':')
  249. if (key && value) {
  250. // 判断是否为空字符串
  251. this.cellStyleObj[key.trim()] = value.trim()
  252. }
  253. })
  254. } else {
  255. this.cellStyleObj = {}
  256. }
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="scss" scoped>
  262. .bs-design-wrap {
  263. position: relative;
  264. width: 100%;
  265. height: 100%;
  266. background-color: transparent;
  267. border-radius: 4px;
  268. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
  269. box-sizing: border-box;
  270. }
  271. ::v-deep .el-table {
  272. // height: 100%;
  273. background-color: transparent;
  274. }
  275. ::v-deep .el-table tr {
  276. background-color: transparent;
  277. }
  278. // ::v-deep .el-table th.gutter {
  279. // border-bottom: 2px solid var(--bs-el-color-primary) !important;
  280. // }
  281. ::v-deep .el-table__body {
  282. height: 100%;
  283. }
  284. ::v-deep .el-table .el-table__header tr {
  285. background-color: transparent;
  286. }
  287. ::v-deep tr.el-table__row--striped {
  288. z-index: 1;
  289. /*将容器的 z-index 设为 1,以便其在蒙版之上*/
  290. position: relative;
  291. /*设置容器为相对定位*/
  292. opacity: 0.9;
  293. }
  294. ::v-deep tr.el-table__row--striped::before {
  295. position: absolute;
  296. /*设置蒙版为绝对定位*/
  297. top: 0;
  298. left: 0;
  299. width: 100%;
  300. height: 100%;
  301. background-color: rgba(0, 0, 0, 0.2);
  302. /*设置半透明的灰色背景色*/
  303. z-index: 2;
  304. /*将蒙版的 z-index 设为 2,以便其覆盖在容器之上*/
  305. }
  306. ::v-deep .overlay {
  307. position: absolute;
  308. /*设置蒙版为绝对定位*/
  309. top: 0;
  310. left: 0;
  311. width: 100%;
  312. height: 100%;
  313. background-color: rgba(0, 0, 0, 0.2) !important;
  314. /*设置半透明的灰色背景色*/
  315. z-index: 2;
  316. /*将蒙版的 z-index 设为 2,以便其覆盖在容器之上*/
  317. }
  318. ::v-deep .cell.el-tooltip {
  319. z-index: 3;
  320. min-width: 50px;
  321. white-space: nowrap;
  322. position: inherit;
  323. }
  324. ::v-deep .el-table {
  325. .el-table__cell {
  326. border-bottom: none !important;
  327. }
  328. &:before {
  329. display: none !important;
  330. }
  331. th.gutter,
  332. colgroup.gutter {
  333. width: 0px !important; //此处的宽度值,对应你自定义滚动条的宽度即可
  334. }
  335. }
  336. // 关键css代码
  337. ::v-deep .el-table__header colgroup col[name="gutter"] {
  338. display: table-cell !important;
  339. }
  340. ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  341. width: 10px; // 横向滚动条
  342. height: 10px; // 纵向滚动条 必写
  343. background-color: transparent;
  344. }
  345. // 滚动条的滑块
  346. ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  347. background-color: #9093994D;
  348. border-radius: 5px;
  349. &:hover {
  350. background-color: #90939980;
  351. }
  352. }
  353. </style>