index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. cellStyle ({ row, column, rowIndex, columnIndex }) {
  98. const bodyBackgroundColor = {
  99. dark: '#141414',
  100. light: '#ffffff',
  101. auto: 'transparent'
  102. }
  103. const initColor = this.customTheme === 'light' ? '#000000' : '#ffffff'
  104. const style = {
  105. backgroundColor: '',
  106. color: this.config.customize.bodyFontColor || initColor,
  107. fontSize: this.config.customize.bodyFontSize + 'px' || '14px'
  108. }
  109. if (rowIndex % 2 && this.config.customize.evenRowBackgroundColor) {
  110. style.backgroundColor = this.config.customize.evenRowBackgroundColor
  111. } else if (!(rowIndex % 2) && this.config.customize.oddRowBackgroundColor) {
  112. style.backgroundColor = this.config.customize.oddRowBackgroundColor
  113. } else {
  114. style.backgroundColor = this.config.customize.bodyBackgroundColor || bodyBackgroundColor[this.customTheme]
  115. }
  116. return style
  117. },
  118. rowStyle ({ row, rowIndex }) {
  119. if (rowIndex % 2) {
  120. return {
  121. backgroundColor: this.config.customize.evenRowBackgroundColor
  122. }
  123. } else {
  124. return {
  125. backgroundColor: this.config.customize.oddRowBackgroundColor
  126. }
  127. }
  128. },
  129. // 表格点击事件
  130. rowClick (row) {
  131. this.linkage(row)
  132. },
  133. changeStyle (config) {
  134. config = { ...this.config, ...config }
  135. // 样式改变时更新主题配置
  136. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  137. this.changeChartConfig(config)
  138. if (config.code === this.activeCode) {
  139. this.changeActiveItemConfig(config)
  140. }
  141. // const config = cloneDeep(oldConfig)
  142. // if (this.customTheme === 'custom') {
  143. // this.headerCellStyleToObj()
  144. // this.cellStyleToObj()
  145. // }
  146. // if (this.customTheme === 'custom') {
  147. // this.headerCellStyleToObj()
  148. // this.cellStyleToObj()
  149. // }
  150. // if (config.customize.stripe) {
  151. // const trs = document
  152. // .getElementById(this.config.code)
  153. // ?.querySelectorAll('tr.el-table__row--striped')
  154. // if (trs) {
  155. // trs.forEach(tr => {
  156. // tr.style.opacity = '0.9'
  157. // // 透明度
  158. // // const overlay = document.createElement("div");
  159. // // overlay.classList.add("overlay");
  160. // // // 将蒙版添加到容器中
  161. // // tr.appendChild(overlay);
  162. // })
  163. // }
  164. // } else {
  165. // const trs = document
  166. // .getElementById(config.code)
  167. // ?.querySelectorAll('tr.el-table__row--striped')
  168. // if (trs) {
  169. // trs.forEach(tr => {
  170. // tr.style.opacity = '1'
  171. // // 透明度
  172. // // const overlay = document.createElement("div");
  173. // // overlay.classList.add("overlay");
  174. // // // 将蒙版添加到容器中
  175. // // tr.appendChild(overlay);
  176. // })
  177. // }
  178. // // document.querySelectorAll(".overlay").forEach(overlay => {
  179. // // overlay.remove();
  180. // // });
  181. // }
  182. // this.chartInit();
  183. // if (config.customize.evenRowBackgroundColor && !config.customize.oddRowBackgroundColor) {
  184. // config.customize.oddRowBackgroundColor = config.customize.bodyBackgroundColor
  185. // } else if (!config.customize.evenRowBackgroundColor && config.customize.oddRowBackgroundColor) {
  186. // config.customize.evenRowBackgroundColor = config.customize.bodyBackgroundColor
  187. // } else if (!(!config.customize.evenRowBackgroundColor && !config.customize.oddRowBackgroundColor)) {
  188. // config.customize.bodyBackgroundColor = ''
  189. // }
  190. // this.updateKey = new Date().getTime()
  191. return config
  192. },
  193. dataFormatting (config, data) {
  194. config.option.tableData = data?.data
  195. const filteredData = {}
  196. const columnData = data?.columnData || {}
  197. if (config.dataSource.dimensionFieldList && config.dataSource.dimensionFieldList.length > 0) {
  198. Object?.keys(columnData).forEach(key => {
  199. if (
  200. config.dataSource.dimensionFieldList.includes(columnData[key].alias)
  201. ) {
  202. filteredData[key] = columnData[key]
  203. }
  204. })
  205. config.option.columnData = filteredData
  206. } else {
  207. config.option.columnData = columnData
  208. }
  209. this.updateKey = new Date().getTime()
  210. return config
  211. },
  212. // 将样式字符串转成对象, 用于自定义主题,表格头部样式
  213. headerCellStyleToObj () {
  214. const str = this.themeJson.themeCss
  215. // 匹配包含header-cell-style的样式字符串
  216. // 匹配包含header-cell-style的样式字符串
  217. const regex = /\.header-cell-style\{([^{}]+)\}/
  218. const match = str.match(regex)
  219. if (match) {
  220. // 将样式字符串转成对象
  221. const styleStr = match[1].trim().replace(/\s*;\s*$/, '') // 去掉末尾的空格和分号
  222. // const styleObj = {};
  223. styleStr.split(';').forEach(s => {
  224. const [key, value] = s.split(':')
  225. if (key && value) {
  226. // 判断是否为空字符串
  227. this.headerCellStyleObj[key.trim()] = value.trim()
  228. }
  229. })
  230. } else {
  231. this.headerCellStyleObj = {}
  232. }
  233. },
  234. // 将样式字符串转成对象, 用于自定义主题,表格主体样式
  235. cellStyleToObj () {
  236. const str = this.themeJson.themeCss
  237. // 匹配包含header-cell-style的样式字符串
  238. // 匹配包含header-cell-style的样式字符串
  239. const regex = /\.cell-style\{([^{}]+)\}/
  240. const match = str.match(regex)
  241. if (match) {
  242. // 将样式字符串转成对象
  243. const styleStr = match[1].trim().replace(/\s*;\s*$/, '') // 去掉末尾的空格和分号
  244. styleStr.split(';').forEach(s => {
  245. const [key, value] = s.split(':')
  246. if (key && value) {
  247. // 判断是否为空字符串
  248. this.cellStyleObj[key.trim()] = value.trim()
  249. }
  250. })
  251. } else {
  252. this.cellStyleObj = {}
  253. }
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. .bs-design-wrap {
  260. position: relative;
  261. width: 100%;
  262. height: 100%;
  263. background-color: transparent;
  264. border-radius: 4px;
  265. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
  266. box-sizing: border-box;
  267. }
  268. ::v-deep .el-table {
  269. // height: 100%;
  270. background-color: transparent;
  271. }
  272. ::v-deep .el-table tr {
  273. background-color: transparent;
  274. }
  275. // ::v-deep .el-table th.gutter {
  276. // border-bottom: 2px solid var(--bs-el-color-primary) !important;
  277. // }
  278. ::v-deep .el-table__body {
  279. height: 100%;
  280. }
  281. ::v-deep .el-table .el-table__header tr {
  282. background-color: transparent;
  283. }
  284. ::v-deep tr.el-table__row--striped {
  285. z-index: 1;
  286. /*将容器的 z-index 设为 1,以便其在蒙版之上*/
  287. position: relative;
  288. /*设置容器为相对定位*/
  289. opacity: 0.9;
  290. }
  291. ::v-deep tr.el-table__row--striped::before {
  292. position: absolute;
  293. /*设置蒙版为绝对定位*/
  294. top: 0;
  295. left: 0;
  296. width: 100%;
  297. height: 100%;
  298. background-color: rgba(0, 0, 0, 0.2);
  299. /*设置半透明的灰色背景色*/
  300. z-index: 2;
  301. /*将蒙版的 z-index 设为 2,以便其覆盖在容器之上*/
  302. }
  303. ::v-deep .overlay {
  304. position: absolute;
  305. /*设置蒙版为绝对定位*/
  306. top: 0;
  307. left: 0;
  308. width: 100%;
  309. height: 100%;
  310. background-color: rgba(0, 0, 0, 0.2) !important;
  311. /*设置半透明的灰色背景色*/
  312. z-index: 2;
  313. /*将蒙版的 z-index 设为 2,以便其覆盖在容器之上*/
  314. }
  315. ::v-deep .cell.el-tooltip {
  316. z-index: 3;
  317. min-width: 50px;
  318. white-space: nowrap;
  319. position: inherit;
  320. }
  321. ::v-deep .el-table {
  322. .el-table__cell {
  323. border-bottom: none !important;
  324. }
  325. &:before {
  326. display: none !important;
  327. }
  328. th.gutter,
  329. colgroup.gutter {
  330. width: 0px !important; //此处的宽度值,对应你自定义滚动条的宽度即可
  331. }
  332. }
  333. // 关键css代码
  334. ::v-deep .el-table__header colgroup col[name="gutter"] {
  335. display: table-cell !important;
  336. }
  337. ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  338. width: 10px; // 横向滚动条
  339. height: 10px; // 纵向滚动条 必写
  340. background-color: transparent;
  341. }
  342. // 滚动条的滑块
  343. ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  344. background-color: #9093994D;
  345. border-radius: 5px;
  346. &:hover {
  347. background-color: #90939980;
  348. }
  349. }
  350. </style>