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. :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. },
  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>