index.vue 10 KB

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