应无所住,而生其心
排名
1
文章
860
粉丝
112
评论
163
net core webapi post传递参数
庸人 : 确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

element ui table 表格自定义边框样式,边框颜色。合并单元格,合并行。element ui table表格行转列

1208人阅读 2024/10/15 17:30 总访问:5182279 评论:0 收藏:0 手机
分类: 前端

设计图:

具体的代码和样式(表格没有加上合并行的)

关于自定义边框样式都加了星号的

  1. <template>
  2. <div class="app-container">
  3. <el-table :data="tableData" :header-cell-style="headerCellStyle" :row-style="rowStyle" :border="true" style="width: 100%">
  4. <el-table-column prop="date" label="日期" width="180"> </el-table-column>
  5. <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
  6. <el-table-column prop="address" label="地址"> </el-table-column>
  7. </el-table>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. // 组件名字
  13. name: "AnalyseTrendByMonth",
  14. // 组件参数
  15. props: {
  16. percentage: {
  17. type: Number,
  18. default: 0,
  19. },
  20. title: {
  21. type: String,
  22. default: "",
  23. },
  24. },
  25. data() {
  26. return {
  27. columnsConfg: [
  28. {
  29. label: "",
  30. prop: "describePlatform",
  31. width: "178px",
  32. paddingLeft: "35px",
  33. textAlign: "left",
  34. },
  35. ],
  36. rowdata: [],
  37. headerCellStyle: {
  38. background: "rgba(29, 123, 189, 1)",
  39. height: "39px",
  40. color: "#fff",
  41. // border: '1px solid tan',
  42. // 注意如果想要降低表头高度,需要设置一下padding,不然它默认的padding有点大,你高度设置得在小它也有一定的高度
  43. paddingTop: "0px",
  44. paddingBottom: "0px",
  45. },
  46. rowStyle: {
  47. color: "#fff",
  48. height: "39px",
  49. //background: 'rgba(8, 32, 68, 0.7)',
  50. // 新版本皮肤表格行颜色
  51. background: "rgba(8, 65, 120, 0.4)",
  52. // marginBottom: "10px",
  53. opacity: "0.8",
  54. paddingTop: "10px",
  55. paddingBottom: "10px",
  56. },
  57. tableData: [
  58. {
  59. date: "2016-05-02",
  60. name: "王小虎",
  61. address: "上海市普陀区金沙江路 1518 弄",
  62. },
  63. {
  64. date: "2016-05-04",
  65. name: "王小虎",
  66. address: "上海市普陀区金沙江路 1517 弄",
  67. },
  68. {
  69. date: "2016-05-01",
  70. name: "王小虎",
  71. address: "上海市普陀区金沙江路 1519 弄",
  72. },
  73. {
  74. date: "2016-05-03",
  75. name: "王小虎",
  76. address: "上海市普陀区金沙江路 1516 弄",
  77. },
  78. ],
  79. };
  80. },
  81. mounted() {
  82. },
  83. // 组件方法
  84. methods: {
  85. },
  86. };
  87. </script>
  88. <style scoped="scoped" lang="scss">
  89. .app-container {
  90. padding-top: 5px;
  91. padding-bottom: 10px;
  92. }
  93. </style>
  94. <!-- 表格样式 -->
  95. <style scoped="scoped" lang="scss">
  96. ::v-deep.el-table--border::after,
  97. ::v-deep .el-table--group::after,
  98. ::v-deep .el-table::before {
  99. content: "";
  100. position: absolute;
  101. background-color: #ebeef5;
  102. z-index: 1;
  103. display: none;
  104. }
  105. // ************这里设置边框样式 ************
  106. // 这里是整个表格外面一圈的边框样式
  107. ::v-deep .el-table--border{
  108. border: 1px solid rgba(255, 255, 255, 0.2);
  109. border-right: none;
  110. border-bottom: none;
  111. }
  112. ::v-deep .el-table--group{
  113. border: 1px solid rgba(255, 255, 255, 0.2);
  114. border-right: none;
  115. border-bottom: none;
  116. }
  117. // element ui table 鼠标移动高亮颜色
  118. ::v-deep .el-table tbody tr:hover > td {
  119. background: #23aaac !important;
  120. }
  121. /* 表格内背景颜色 */
  122. ::v-deep .el-table th,
  123. ::v-deep .el-table tr,
  124. ::v-deep .el-table td {
  125. background-color: transparent;
  126. }
  127. // 设置行间距
  128. ::v-deep .el-table__body {
  129. border-collapse: separate !important;
  130. // 设置这里居然会影响边框线的对齐
  131. // border-spacing: 0px 3px !important;
  132. }
  133. // ************这里设置边框样式 ************
  134. ::v-deep .el-table--border .el-table__cell {
  135. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  136. border-right: 1px solid rgba(255, 255, 255, 0.2);
  137. }
  138. // ************这里设置边框样式 ************
  139. ::v-deep .el-table th.el-table__cell.is-leaf {
  140. border-bottom: 1px solid rgba(255, 255, 255, 0.2)
  141. }
  142. // 这句代码加了鼠标指上去变色就显示不出来
  143. ::v-deep.el-table--enable-row-transition .el-table__body td.el-table__cell {
  144. background-color: transparent !important;
  145. }
  146. ::v-deep.el-table td.el-table__cell div.cell {
  147. background-color: transparent !important;
  148. }
  149. ::v-deep .el-table {
  150. background-color: transparent !important;
  151. }
  152. ::v-deep .el-table__row {
  153. background-color: transparent;
  154. }
  155. /* 去除底部白线 */
  156. .el-table::before {
  157. background-color: transparent;
  158. }
  159. .pageWrapper {
  160. margin: 10px auto;
  161. text-align: center;
  162. padding-bottom: 15px;
  163. }
  164. // --------------------隐藏table gutter列和内容区右侧的空白 start
  165. ::v-deep .el-table th.gutter {
  166. display: none;
  167. width: 0;
  168. }
  169. ::v-deep .el-table colgroup col[name="gutter"] {
  170. display: none;
  171. width: 0;
  172. }
  173. // 这个样式不加的话内容哪里会缺一点,估计是因为滚动条哪里缺的没有补上
  174. ::v-deep .el-table__body {
  175. width: 100% !important;
  176. }
  177. // --------------------隐藏table gutter列和内容区右侧的空白 end
  178. </style>

加上合并行之后的

  1. <template>
  2. <div class="app-container">
  3. <el-table :data="tableData" :span-method="courseSpan" :header-cell-style="headerCellStyle" :row-style="rowStyle" :border="true" style="width: 100%">
  4. <el-table-column prop="date" label="日期" width="180"> </el-table-column>
  5. <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
  6. <el-table-column prop="address" label="地址"> </el-table-column>
  7. </el-table>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. // 组件名字
  13. name: "AnalyseTrendByMonth",
  14. // 组件参数
  15. props: {
  16. percentage: {
  17. type: Number,
  18. default: 0,
  19. },
  20. title: {
  21. type: String,
  22. default: "",
  23. },
  24. },
  25. data() {
  26. return {
  27. columnsConfg: [
  28. {
  29. label: "",
  30. prop: "describePlatform",
  31. width: "178px",
  32. paddingLeft: "35px",
  33. textAlign: "left",
  34. },
  35. ],
  36. rowdata: [],
  37. headerCellStyle: {
  38. background: "rgba(29, 123, 189, 1)",
  39. height: "39px",
  40. color: "#fff",
  41. // border: '1px solid tan',
  42. // 注意如果想要降低表头高度,需要设置一下padding,不然它默认的padding有点大,你高度设置得在小它也有一定的高度
  43. paddingTop: "0px",
  44. paddingBottom: "0px",
  45. },
  46. rowStyle: {
  47. color: "#fff",
  48. height: "39px",
  49. //background: 'rgba(8, 32, 68, 0.7)',
  50. // 新版本皮肤表格行颜色
  51. background: "rgba(8, 65, 120, 0.4)",
  52. // marginBottom: "10px",
  53. opacity: "0.8",
  54. paddingTop: "10px",
  55. paddingBottom: "10px",
  56. },
  57. tableData: [
  58. {
  59. date: "2016-05-02",
  60. name: "王小虎",
  61. address: "上海市普陀区金沙江路 1518 弄",
  62. },
  63. {
  64. date: "2016-05-02",
  65. name: "王大虎",
  66. address: "上海市普陀区金沙江路 3213 弄",
  67. },
  68. {
  69. date: "2016-05-04",
  70. name: "张晓白",
  71. address: "上海市普陀区金沙江路 1517 弄",
  72. },
  73. {
  74. date: "2016-05-04",
  75. name: "陈木惟",
  76. address: "上海市普陀区金沙江路 6666 弄",
  77. },
  78. {
  79. date: "2016-05-01",
  80. name: "柏树枝",
  81. address: "上海市普陀区金沙江路 1519 弄",
  82. },
  83. {
  84. date: "2016-05-03",
  85. name: "杨华锋",
  86. address: "上海市普陀区金沙江路 1516 弄",
  87. },
  88. ],
  89. };
  90. },
  91. mounted() {
  92. this.initCourseSpanArr(this.tableData)
  93. },
  94. // 组件方法
  95. methods: {
  96. // 处理合并数据
  97. initCourseSpanArr(data) {
  98. const spanArray = [];
  99. for (var i = 0; i < data.length; i++) {
  100. if (i === 0) {
  101. spanArray.push(1);
  102. this.pos = 0;
  103. } else {
  104. // 判断当前元素与上一个元素是否相同。这里是判断需要合并的字段
  105. if (data[i].date === data[i - 1].date) {
  106. spanArray[this.pos] += 1;
  107. spanArray.push(0);
  108. } else {
  109. spanArray.push(1);
  110. this.pos = i;
  111. }
  112. }
  113. }
  114. this.courseSpanArry = spanArray;
  115. },
  116. courseSpan({rowIndex, columnIndex }) {
  117. if (columnIndex === 0) {
  118. const _row = this.courseSpanArry[rowIndex];
  119. const _col = _row > 0 ? 1 : 0;
  120. return {
  121. rowspan: _row,
  122. colspan: _col,
  123. };
  124. }
  125. },
  126. },
  127. };
  128. </script>
  129. <style scoped="scoped" lang="scss">
  130. .app-container {
  131. padding-top: 5px;
  132. padding-bottom: 10px;
  133. }
  134. </style>
  135. <!-- 表格样式 -->
  136. <style scoped="scoped" lang="scss">
  137. ::v-deep.el-table--border::after,
  138. ::v-deep .el-table--group::after,
  139. ::v-deep .el-table::before {
  140. content: "";
  141. position: absolute;
  142. background-color: #ebeef5;
  143. z-index: 1;
  144. display: none;
  145. }
  146. // ************这里设置边框样式 ************
  147. // 这里是整个表格外面一圈的边框样式
  148. ::v-deep .el-table--border {
  149. border: 1px solid rgba(255, 255, 255, 0.2);
  150. border-right: none;
  151. border-bottom: none;
  152. }
  153. ::v-deep .el-table--group {
  154. border: 1px solid rgba(255, 255, 255, 0.2);
  155. border-right: none;
  156. border-bottom: none;
  157. }
  158. // element ui table 鼠标移动高亮颜色
  159. ::v-deep .el-table tbody tr:hover > td {
  160. background: #23aaac !important;
  161. }
  162. /* 表格内背景颜色 */
  163. ::v-deep .el-table th,
  164. ::v-deep .el-table tr,
  165. ::v-deep .el-table td {
  166. background-color: transparent;
  167. }
  168. // 设置行间距
  169. ::v-deep .el-table__body {
  170. border-collapse: separate !important;
  171. // 设置这里居然会影响边框线的对齐
  172. // border-spacing: 0px 3px !important;
  173. }
  174. // ************这里设置边框样式 ************
  175. ::v-deep .el-table--border .el-table__cell {
  176. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  177. border-right: 1px solid rgba(255, 255, 255, 0.2);
  178. }
  179. // ************这里设置边框样式 ************
  180. ::v-deep .el-table th.el-table__cell.is-leaf {
  181. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  182. }
  183. // 这句代码加了鼠标指上去变色就显示不出来
  184. ::v-deep.el-table--enable-row-transition .el-table__body td.el-table__cell {
  185. background-color: transparent !important;
  186. }
  187. ::v-deep.el-table td.el-table__cell div.cell {
  188. background-color: transparent !important;
  189. }
  190. ::v-deep .el-table {
  191. background-color: transparent !important;
  192. }
  193. ::v-deep .el-table__row {
  194. background-color: transparent;
  195. }
  196. /* 去除底部白线 */
  197. .el-table::before {
  198. background-color: transparent;
  199. }
  200. .pageWrapper {
  201. margin: 10px auto;
  202. text-align: center;
  203. padding-bottom: 15px;
  204. }
  205. // --------------------隐藏table gutter列和内容区右侧的空白 start
  206. ::v-deep .el-table th.gutter {
  207. display: none;
  208. width: 0;
  209. }
  210. ::v-deep .el-table colgroup col[name="gutter"] {
  211. display: none;
  212. width: 0;
  213. }
  214. // 这个样式不加的话内容哪里会缺一点,估计是因为滚动条哪里缺的没有补上
  215. ::v-deep .el-table__body {
  216. width: 100% !important;
  217. }
  218. // --------------------隐藏table gutter列和内容区右侧的空白 end
  219. </style>
合并单元格的代码就是js这点
  1. mounted() {
  2. this.initCourseSpanArr(this.tableData)
  3. },
  4. // 组件方法
  5. methods: {
  6. // 处理合并数据
  7. initCourseSpanArr(data) {
  8. const spanArray = [];
  9. for (var i = 0; i < data.length; i++) {
  10. if (i === 0) {
  11. spanArray.push(1);
  12. this.pos = 0;
  13. } else {
  14. // 判断当前元素与上一个元素是否相同。这里是判断需要合并的字段
  15. if (data[i].date === data[i - 1].date) {
  16. spanArray[this.pos] += 1;
  17. spanArray.push(0);
  18. } else {
  19. spanArray.push(1);
  20. this.pos = i;
  21. }
  22. }
  23. }
  24. this.courseSpanArry = spanArray;
  25. },
  26. courseSpan({rowIndex, columnIndex }) {
  27. if (columnIndex === 0) {
  28. const _row = this.courseSpanArry[rowIndex];
  29. const _col = _row > 0 ? 1 : 0;
  30. return {
  31. rowspan: _row,
  32. colspan: _col,
  33. };
  34. }
  35. },
  36. },

还有就是表格上方要加上这句:

  1. <el-table :span-method="courseSpan">

对接真实的接口,加上行转列的效果

单独的示例可以参考一下这篇文章,这里边的数据没有对接真是接口逻辑要简单一些:https://www.tnblog.net/xiuxin3/article/details/8482

接口返回的数据源是这个样子:
有评估,实验,产教的数据接口回来,这里只展示了评估的数据接口作为示例:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "systemName": null,
  6. "year": 2024,
  7. "month": 9,
  8. "quantity": 0,
  9. "completPr": 0.2164,
  10. "planCompletePr": 0.8455172413793103448275862069
  11. },
  12. {
  13. "systemName": null,
  14. "year": 2024,
  15. "month": 10,
  16. "quantity": 0,
  17. "completPr": 0.3224,
  18. "planCompletePr": 0.4787902592301649646504320503
  19. },
  20. {
  21. "systemName": null,
  22. "year": 2024,
  23. "month": 11,
  24. "quantity": 0,
  25. "completPr": 0.0,
  26. "planCompletePr": 0.0
  27. },
  28. {
  29. "systemName": null,
  30. "year": 2024,
  31. "month": 12,
  32. "quantity": 0,
  33. "completPr": 0.0,
  34. "planCompletePr": 0.0
  35. },
  36. {
  37. "systemName": null,
  38. "year": 2025,
  39. "month": 1,
  40. "quantity": 0,
  41. "completPr": 0.0,
  42. "planCompletePr": 0.0
  43. }
  44. ],
  45. "success": true,
  46. }

接口出来的数据源要先处理成这个样子的,这样行专列好处理一点:

  1. const rawData = [
  2. { "type": "评估", "month": 9, "CompleteType": "目标达成率", "CompleteValue": 0.2164 },
  3. { "type": "评估", "month": 10, "CompleteType": "整体完成率", "CompleteValue": 0.7164 },
  4. { "type": "审计", "month": 9, "CompleteType": "目标达成率", "CompleteValue": 0.6164 },
  5. { "type": "审计", "month": 10, "CompleteType": "整体完成率", "CompleteValue": 0.5164 },
  6. ];

整体代码如下:
this.$sysconfig.evaluate_name_short = “评估”
this.$sysconfig.labroom_name_short = “实验”
this.$sysconfig.prod_name_short = “产教”

  1. <template>
  2. <div class="app-container">
  3. <el-table :data="tableData" :span-method="courseSpan" :header-cell-style="headerCellStyle" :row-style="rowStyle" :border="true" style="width: 100%">
  4. <el-table-column prop="type" label="系统" width="180" align="center"> </el-table-column>
  5. <el-table-column prop="indicator" label="类型" width="180" align="center"> </el-table-column>
  6. <el-table-column v-for="(month, key) in monthMapValues" align="center" :key="key" :label="month" :prop="month" :formatter="formatPercentage" />
  7. </el-table>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. // 组件名字
  13. name: "AnalyseTrendByMonth",
  14. // 组件参数
  15. props: {
  16. percentage: {
  17. type: Number,
  18. default: 0,
  19. },
  20. title: {
  21. type: String,
  22. default: "",
  23. },
  24. },
  25. data() {
  26. return {
  27. columnsConfg: [
  28. {
  29. label: "",
  30. prop: "describePlatform",
  31. width: "178px",
  32. paddingLeft: "35px",
  33. textAlign: "left",
  34. },
  35. ],
  36. rowdata: [],
  37. headerCellStyle: {
  38. background: "rgba(29, 123, 189, 1)",
  39. height: "39px",
  40. color: "#fff",
  41. // border: '1px solid tan',
  42. // 注意如果想要降低表头高度,需要设置一下padding,不然它默认的padding有点大,你高度设置得在小它也有一定的高度
  43. paddingTop: "0px",
  44. paddingBottom: "0px",
  45. },
  46. rowStyle: {
  47. color: "#fff",
  48. height: "39px",
  49. //background: 'rgba(8, 32, 68, 0.7)',
  50. // 新版本皮肤表格行颜色
  51. background: "rgba(8, 65, 120, 0.4)",
  52. // marginBottom: "10px",
  53. opacity: "0.8",
  54. paddingTop: "10px",
  55. paddingBottom: "10px",
  56. },
  57. monthTableData: [],
  58. tableData: [],
  59. monthMapValues: ["9月", "10月"],
  60. monthMap: {},
  61. monthResultCount: 0,
  62. };
  63. },
  64. mounted() {
  65. this.monthResultCount = 0;
  66. this.getSysUseMonthReport();
  67. },
  68. watch: {
  69. monthResultCount(newVal) {
  70. // 三个平台的数据都回来了在去处理行专列合并单元格等
  71. if (newVal === 3) {
  72. // console.log("三个平台的数据都回来了...")
  73. // 这里可以进行一个排序,方便自己控制数据列的展示
  74. this.monthTableData = this.monthTableData.slice().sort((a, b) => a.sort - b.sort);
  75. let transformTableData = this.transformData(this.monthTableData, this.monthMap);
  76. this.tableData = transformTableData;
  77. this.initCourseSpanArr(transformTableData);
  78. }
  79. },
  80. },
  81. // 组件方法
  82. methods: {
  83. formatPercentage(row, column, cellValue) {
  84. // console.log("看看返回值", cellValue);
  85. // 这个方法可以用于格式化百分比,但我们已经在transformData中完成了格式化
  86. // 所以这里可以直接返回cellValue,或者根据需要进行进一步处理
  87. return cellValue;
  88. },
  89. // 行专列方法,把行中的月份转化为方法
  90. transformData: function (data, monthMap) {
  91. const result = [];
  92. const types = [...new Set(data.map((item) => item.type))];
  93. const completeTypes = [...new Set(data.map((item) => item.completType))];
  94. types.forEach((type) => {
  95. completeTypes.forEach((completeType) => {
  96. const row = {
  97. type: type,
  98. indicator: completeType,
  99. ...Object.keys(monthMap).reduce((acc, month) => {
  100. const value = data.find((item) => item.type === type && item.completType === completeType && item.month === parseInt(month, 10))?.completValue;
  101. let returnValue = "0%";
  102. if (value >= 0) {
  103. returnValue = (value * 100).toFixed(2);
  104. } else {
  105. returnValue = "-";
  106. }
  107. return { ...acc, [monthMap[month]]: returnValue };
  108. // return { ...acc, [monthMap[month]]: value ? (value * 100).toFixed(2) + "%" : "-" };
  109. }, {}),
  110. };
  111. result.push(row);
  112. });
  113. });
  114. return result;
  115. },
  116. // 系统月使用情况
  117. getSysUseMonthReport: async function () {
  118. let stId = await this.$getStId();
  119. let my = this;
  120. let mCount = 7;
  121. const currentDate = new Date();
  122. const currentYear = currentDate.getFullYear();
  123. let currentMonth = currentDate.getMonth();
  124. this.monthMapValues = [];
  125. this.monthTableData = [];
  126. this.monthResultCount = 0;
  127. let monthMap = {};
  128. for (let index = currentMonth; index < currentMonth + 7; index++) {
  129. let calYear = currentYear;
  130. let calMonth = index;
  131. // 说明应该是下一年开始了
  132. if (index > 12) {
  133. calYear = calYear + 1;
  134. calMonth = index - 12;
  135. }
  136. monthMap[calMonth] = calMonth + "月";
  137. // 给动态列名提供数据
  138. this.monthMapValues.push(calMonth + "月");
  139. // console.log("看看年月", calYear, calMonth);
  140. }
  141. this.monthMap = monthMap;
  142. // console.log("看看月转化对象", monthMap);
  143. // 评估完成情况
  144. this.$http.get("/evaluation/api/TeacherReportCurriculum/XX", { SchoolTermID: stId, monthCount: mCount, IncludeAll: this.includeAll }).then((res) => {
  145. // console.log("评估月使用情况", res.data);
  146. // 每月都要显示一条数据,其实用行转列做逻辑应该简单点
  147. for (let index = currentMonth; index < currentMonth + 7; index++) {
  148. let calYear = currentYear;
  149. let calMonth = index;
  150. // 说明应该是下一年开始了
  151. if (index > 12) {
  152. calYear = calYear + 1;
  153. calMonth = index - 12;
  154. }
  155. // console.log("看看年月", calYear, calMonth);
  156. let findData = res.data.find((a) => a.month == calMonth && a.year == calYear);
  157. my.monthTableData.push({
  158. sort: 1,
  159. type: my.$sysconfig.evaluate_name_short,
  160. year: calYear,
  161. month: calMonth,
  162. completType: "目标达成率",
  163. completValue: findData.planCompletePr,
  164. });
  165. my.monthTableData.push({
  166. completType: "整体完成率",
  167. sort: 2,
  168. year: calYear,
  169. type: my.$sysconfig.evaluate_name_short,
  170. month: findData.month,
  171. completValue: findData.completPr,
  172. });
  173. }
  174. my.monthResultCount = my.monthResultCount + 1;
  175. // let transformTableData = this.transformData(my.monthTableData, monthMap);
  176. // this.tableData = transformTableData
  177. // this.initCourseSpanArr(transformTableData)
  178. // console.log("看看表格组装出来的数据呢",my.monthTableData)
  179. // console.log("看看转化出来后的表格", this.tableData);
  180. });
  181. // 实验完成情况
  182. this.$http.get("/labroom/api/Report/XX", { stdetailID: stId, monthCount: mCount, IncludeAll: this.includeAll }).then((res) => {
  183. // console.log("实验月使用情况", res.data);
  184. // 每月都要显示一条数据,其实用行转列做逻辑应该简单点
  185. for (let index = currentMonth; index < currentMonth + 7; index++) {
  186. let calYear = currentYear;
  187. let calMonth = index;
  188. // 说明应该是下一年开始了
  189. if (index > 12) {
  190. calYear = calYear + 1;
  191. calMonth = index - 12;
  192. }
  193. let findData = res.data.find((a) => a.month == calMonth && a.year == calYear);
  194. my.monthTableData.push({
  195. sort: 3,
  196. completType: "目标达成率",
  197. type: my.$sysconfig.labroom_name_short,
  198. year: calYear,
  199. month: calMonth,
  200. completValue: findData.goalAchievementPr,
  201. });
  202. my.monthTableData.push({
  203. sort: 4,
  204. completType: "整体完成率",
  205. type: my.$sysconfig.labroom_name_short,
  206. month: findData.month,
  207. year: calYear,
  208. completValue: findData.mustDoCompletPr,
  209. });
  210. }
  211. my.monthResultCount = my.monthResultCount + 1;
  212. });
  213. // 产教使用情况
  214. this.$http.get("/prodedu/api/v2/Report/XX", { stdetailID: stId, monthCount: mCount, includeAll: this.includeAll }).then((res) => {
  215. // console.log("产教月使用情况", res.data);
  216. // 每月都要显示一条数据,其实用行转列做逻辑应该简单点
  217. for (let index = currentMonth; index < currentMonth + 7; index++) {
  218. let calYear = currentYear;
  219. let calMonth = index;
  220. if (index > 12) {
  221. calYear = calYear + 1;
  222. calMonth = index - 12;
  223. }
  224. let findData = res.data.find((a) => a.month == calMonth && a.year == calYear);
  225. my.monthTableData.push({
  226. sort: 5,
  227. completType: "目标达成率",
  228. type: my.$sysconfig.prod_name_short,
  229. year: calYear,
  230. month: calMonth,
  231. completValue: findData.monthCper,
  232. });
  233. my.monthTableData.push({
  234. sort: 6,
  235. completType: "整体完成率",
  236. type: my.$sysconfig.prod_name_short,
  237. month: findData.month,
  238. year: calYear,
  239. completValue: findData.completPr,
  240. });
  241. }
  242. my.monthResultCount = my.monthResultCount + 1;
  243. });
  244. },
  245. // 处理合并数据
  246. initCourseSpanArr(data) {
  247. const spanArray = [];
  248. for (var i = 0; i < data.length; i++) {
  249. if (i === 0) {
  250. spanArray.push(1);
  251. this.pos = 0;
  252. } else {
  253. // 判断当前元素与上一个元素是否相同。这里是判断需要合并的字段
  254. if (data[i].type === data[i - 1].type) {
  255. spanArray[this.pos] += 1;
  256. spanArray.push(0);
  257. } else {
  258. spanArray.push(1);
  259. this.pos = i;
  260. }
  261. }
  262. }
  263. this.courseSpanArry = spanArray;
  264. },
  265. courseSpan({ rowIndex, columnIndex }) {
  266. if (columnIndex === 0) {
  267. const _row = this.courseSpanArry[rowIndex];
  268. const _col = _row > 0 ? 1 : 0;
  269. return {
  270. rowspan: _row,
  271. colspan: _col,
  272. };
  273. }
  274. },
  275. },
  276. };
  277. </script>
  278. <style scoped="scoped" lang="scss">
  279. .app-container {
  280. padding-top: 5px;
  281. padding-bottom: 10px;
  282. }
  283. </style>
  284. <!-- 表格样式 -->
  285. <style scoped="scoped" lang="scss">
  286. ::v-deep.el-table--border::after,
  287. ::v-deep .el-table--group::after,
  288. ::v-deep .el-table::before {
  289. content: "";
  290. position: absolute;
  291. background-color: #ebeef5;
  292. z-index: 1;
  293. display: none;
  294. }
  295. // ************这里设置边框样式 ************
  296. // 这里是整个表格外面一圈的边框样式
  297. ::v-deep .el-table--border {
  298. border: 1px solid rgba(255, 255, 255, 0.2);
  299. border-right: none;
  300. border-bottom: none;
  301. }
  302. ::v-deep .el-table--group {
  303. border: 1px solid rgba(255, 255, 255, 0.2);
  304. border-right: none;
  305. border-bottom: none;
  306. }
  307. // element ui table 鼠标移动高亮颜色
  308. ::v-deep .el-table tbody tr:hover > td {
  309. background: #23aaac !important;
  310. }
  311. /* 表格内背景颜色 */
  312. ::v-deep .el-table th,
  313. ::v-deep .el-table tr,
  314. ::v-deep .el-table td {
  315. background-color: transparent;
  316. }
  317. // 设置行间距
  318. ::v-deep .el-table__body {
  319. border-collapse: separate !important;
  320. // 设置这里居然会影响边框线的对齐
  321. // border-spacing: 0px 3px !important;
  322. }
  323. // ************这里设置边框样式 ************
  324. ::v-deep .el-table--border .el-table__cell {
  325. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  326. border-right: 1px solid rgba(255, 255, 255, 0.2);
  327. }
  328. // ************这里设置边框样式 ************
  329. ::v-deep .el-table th.el-table__cell.is-leaf {
  330. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  331. }
  332. // 这句代码加了鼠标指上去变色就显示不出来
  333. ::v-deep.el-table--enable-row-transition .el-table__body td.el-table__cell {
  334. background-color: transparent !important;
  335. }
  336. ::v-deep.el-table td.el-table__cell div.cell {
  337. background-color: transparent !important;
  338. }
  339. ::v-deep .el-table {
  340. background-color: transparent !important;
  341. }
  342. ::v-deep .el-table__row {
  343. background-color: transparent;
  344. }
  345. /* 去除底部白线 */
  346. .el-table::before {
  347. background-color: transparent;
  348. }
  349. .pageWrapper {
  350. margin: 10px auto;
  351. text-align: center;
  352. padding-bottom: 15px;
  353. }
  354. // --------------------隐藏table gutter列和内容区右侧的空白 start
  355. ::v-deep .el-table th.gutter {
  356. display: none;
  357. width: 0;
  358. }
  359. ::v-deep .el-table colgroup col[name="gutter"] {
  360. display: none;
  361. width: 0;
  362. }
  363. // 这个样式不加的话内容哪里会缺一点,估计是因为滚动条哪里缺的没有补上
  364. ::v-deep .el-table__body {
  365. width: 100% !important;
  366. }
  367. // --------------------隐藏table gutter列和内容区右侧的空白 end
  368. </style>

element ui table 自定义样式其他参考

https://www.tnblog.net/aojiancc2/article/details/8061
https://www.tnblog.net/notebook/article/details/8469
https://www.tnblog.net/aojiancc2/article/details/8111


欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

element ui table 表格行颜色自定义单元格颜色 根据条件改变行或者单元格的颜色

行列样式主要是这几个 属性名 描述 回调函数 row-class-name 行的 className 的回调方法,也可以使用字符...

element ui table 表格获取 行号列数

方法一:页面 &lt;el-table-column prop=&quot;courseName&quot; label=&quot;测试获取行号&quot; align=&quot;center&quo...

element ui table 表格行颜色自定义单元格颜色自定义背景颜色自定义风格自定义

[TOC]实现效果一效果图 代码如下template:&lt;template&gt; &lt;div class=&quot;emergencyEvents-container&quot;&gt;...

element ui table表格行转列月份数据行转列

我们需要展示一个这样的表格数据 [TOC]接口返回的数据源是这个样子有评估,实验,产教的数据接口回来,这里只展示了评估...

css弹性盒子flex布局

css弹性盒子由于版本不同浏览器问题造成了一些不同的写法display:flexbox;在google浏览器中如果使用下面的写法就不行displa...

可输入下拉文本框据输入动态加载数据 jquery-editable-select

用到一个jquery-editable-select的控件github地址:https://github.com/indrimuska/jquery-editable-select这个插件的原理是...

.net mvc分部页.net core分部页

.net分部页的三种方式第一种:@Html.Partial(&quot;_分部页&quot;)第二种:@{ Html.RenderPartial(&quot;分部页&quot;);}...

css中单位pxemrem和vh/vw的理解

&gt;px像素(Pixel)。相对长度单位。像素px是相对于显示器屏幕分辨率而言的。em是相对长度单位。相对于当前对象内文本的字...

让IIS支持webp格式图片让IIS支持vtt格式iis设置mime类型iis配置支持的类型

webp格式图片可以让图片体积变小。也让下载图片变得更加困难一点 在线制作webp工具 https://www.upyun.com/webp?utm_mediu...

网页上传文件断点续传的实现无视文件大小上传以及datatables基本用法

首先明白js是客户带执行代码,c#是服务器上执行代码。本地文件需要用到js处理,服务器端接受c#代码处理1.HTML页面,文件信...

如何使用图标像使用文字一样使用文本图标的方法

1.首先在Iconfont-阿里巴巴矢量图标库上面找到你需要的图标然后加入你的购物车然后选择图标;注意:每个类型的图标会大小不...

使用七牛云的cdn服务提高图片的加载速度

CDN介绍CDN的全称是Content Delivery Network,即内容分发网络。CDN加速主要是加速静态资源,如网站上面上传的图片、媒体,...

通俗易懂什么是.NET?什么是.NET Framework?什么是.NET Core?

朋友圈@蓝羽 看到一篇文章写的太详细太通俗了,搬过来细细看完,保证你对.NET有个新的认识理解原文地址:https://www.cnblo...

JS监听input、keydown有输入法时打字完成后触发事件

在给输入框绑定input或keydown事件时预期效果是有输入法时,输入中文后触发事件,不希望输一个字母就触发一次事件可以用到c...