index.vue 10 KB

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