index.vue 10 KB

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