index.vue 9.7 KB

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