index.vue 10 KB

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