11<template >
22 <div >
3- <div class =" site-demo" >
3+ <div class =" site-demo-container " >
44 <ve-table
55 fixed-header
66 border-y
7- :max-height =" 500 "
8- :scroll-width =" 1600 "
7+ :max-height =" 600 "
8+ :scroll-width =" 2000 "
99 :virtual-scroll-option =" virtualScrollOption"
1010 :columns =" columns"
1111 :table-data =" tableData"
1212 row-key-field-name =" rowKey"
13+ :cell-style-option =" cellStyleOption"
1314 />
1415 </div >
1516 <!-- <Footer /> -->
1819
1920<script >
2021/* import Footer from "@/comp/layout/footer.vue"; */
22+ import Mock from " mockjs" ;
2123export default {
2224 components: {
2325 /* Footer */
2426 },
2527 data () {
2628 return {
29+ cellStyleOption: {
30+ bodyCellClass : ({ row, column, rowIndex }) => {
31+ if (column .field === " proficiency" ) {
32+ return " table-body-cell-proficiency" ;
33+ }
34+ }
35+ },
2736 virtualScrollOption: {
2837 // 是否开启
2938 enable: true
3039 },
3140 columns: [
3241 {
33- field: " col1 " ,
42+ field: " rowIndex " ,
3443 key: " a" ,
35- title: " col1 " ,
44+ title: " # " ,
3645 width: 50 ,
3746 fixed: " left"
3847 },
3948 {
40- title: " col2-col3 " ,
49+ title: " Basic Info " ,
4150 fixed: " left" ,
4251 children: [
4352 {
44- field: " col2 " ,
53+ field: " name " ,
4554 key: " b" ,
46- title: " col2" ,
47- width: 50
55+ title: " Name" ,
56+ width: 100 ,
57+ align: " left"
4858 },
4959 {
50- field: " col3 " ,
60+ field: " sex " ,
5161 key: " c" ,
52- title: " col3" ,
53- width: 50
62+ title: " Sex" ,
63+ width: 50 ,
64+ align: " center" ,
65+ renderBodyCell : ({ row, column, rowIndex }, h ) => {
66+ const cellData = row[column .field ];
67+
68+ let iconName =
69+ cellData === 1
70+ ? " icon-male"
71+ : " icon-female" ;
72+
73+ return (
74+ < i
75+ style= " font-size:20px;color:#666;"
76+ class = {" iconfont " + iconName}
77+ / >
78+ );
79+ }
5480 }
5581 ]
5682 },
5783 {
58- title: " col4-col5-col6" ,
84+ title: " Personal Experience" ,
85+ align: " center" ,
5986 children: [
6087 {
61- title: " col4-col5" ,
88+ title: " Profession" ,
89+ field: " profession" ,
90+ key: " d" ,
91+ width: 100 ,
92+ align: " left"
93+ },
94+ {
95+ title: " IT Skills" ,
6296 children: [
6397 {
64- field: " col4" ,
65- key: " d" ,
66- title: " col4" ,
67- width: 130
98+ field: " proficiency" ,
99+ key: " e" ,
100+ title: " Proficiency" ,
101+ width: 150 ,
102+ renderBodyCell: (
103+ { row, column, rowIndex },
104+ h
105+ ) => {
106+ const cellData = row[column .field ];
107+
108+ const colorClass =
109+ cellData > 60
110+ ? " demo-blue"
111+ : cellData > 30
112+ ? " demo-orange"
113+ : " demo-red" ;
114+
115+ return (
116+ < div class = " proficiency-span-container" >
117+ < span
118+ class = {
119+ " proficiency-span " +
120+ colorClass
121+ }
122+ style= {
123+ " width:" +
124+ cellData +
125+ " %;"
126+ }
127+ >
128+ {cellData}%
129+ < / span>
130+ < / div>
131+ );
132+ }
68133 },
69134 {
70- field: " col5" ,
71- key: " e" ,
72- title: " col5" ,
73- width: 140
135+ field: " skills" ,
136+ key: " f" ,
137+ title: " Skills" ,
138+ width: 150 ,
139+ align: " left" ,
140+ renderBodyCell: (
141+ { row, column, rowIndex },
142+ h
143+ ) => {
144+ const cellData = row[column .field ];
145+
146+ const LANGS = [
147+ {
148+ name: " Javascript" ,
149+ color: " #48a4ef"
150+ },
151+ {
152+ name: " Python" ,
153+ color: " #d8899c"
154+ },
155+ { name: " java" , color: " #a88cd9" },
156+ { name: " C++" , color: " #88d317" }
157+ ];
158+
159+ const skills = LANGS .slice (0 , cellData);
160+
161+ return skills .map (skill => {
162+ return (
163+ < span
164+ class = " skill-span"
165+ style= {
166+ " background-color:" +
167+ skill .color
168+ }
169+ >
170+ {skill .name }
171+ < / span>
172+ );
173+ });
174+ }
74175 }
75176 ]
76- },
77- {
78- title: " col6" ,
79- field: " col6" ,
80- key: " f" ,
81- width: 140
82177 }
83178 ]
84179 },
85180 {
86- field: " col7 " ,
181+ field: " address " ,
87182 key: " g" ,
88- title: " col7 " ,
89- width: 50 ,
90- fixed : " right "
183+ title: " Address " ,
184+ width: 250 ,
185+ align : " left "
91186 },
92187 {
93- field: " col8 " ,
188+ field: " zip " ,
94189 key: " h" ,
95- title: " col8 " ,
190+ title: " Zip " ,
96191 width: 50 ,
97192 fixed: " right"
98193 }
@@ -105,20 +200,27 @@ export default {
105200 return Math .floor (Math .random () * (max - min) + min);
106201 },
107202 initData () {
203+ const PROFESSIONS = [
204+ " Project Manager" ,
205+ " User Interface Designer" ,
206+ " Front-End Developer" ,
207+ " Testor" ,
208+ " Product Designer" ,
209+ " System Designer"
210+ ];
211+
108212 let data = [];
109213 for (let i = 0 ; i < 10000 ; i++ ) {
110214 data .push ({
111215 rowKey: i,
112- col1: i,
113- col2: i,
114- col3: i,
115- col4: i,
116- col5: i,
117- col6: i,
118- col7: i,
119- col8: i,
120- col9: i,
121- col10: i
216+ rowIndex: i + 1 ,
217+ name: Mock .Random .name (),
218+ sex: Mock .Random .boolean () ? 1 : 2 ,
219+ profession: PROFESSIONS [Mock .Random .natural (0 , 5 )],
220+ proficiency: Mock .Random .natural (5 , 85 ),
221+ skills: Mock .Random .natural (0 , 4 ),
222+ address: Mock .Random .county (true ),
223+ zip: Mock .Random .zip ()
122224 });
123225 }
124226
@@ -130,10 +232,46 @@ export default {
130232 }
131233};
132234 </script >
133- <style lang="less" scoped >
134- .site-demo {
235+ <style lang="less">
236+ .site-demo-container {
135237 background : #fff ;
136238 margin-top : 62px ;
137239 padding : 10px ;
240+
241+ // proficiency filed custom cell style
242+ .table-body-cell-proficiency {
243+ padding : 0 !important ;
244+ }
245+ // proficiency filed
246+ .proficiency-span-container {
247+ height : 100% ;
248+ text-align : left ;
249+ .proficiency-span {
250+ height : 100% ;
251+ display : inline-flex ;
252+ align-items : center ;
253+ padding-left : 10px ;
254+ font-weight : bold ;
255+ color : #555 ;
256+
257+ & .demo-blue {
258+ background-color : RGBA (24 , 144 , 255 , 0.7 );
259+ }
260+ & .demo-orange {
261+ background-color : RGBA (255 , 179 , 0 , 0.7 );
262+ }
263+ & .demo-red {
264+ background-color : RGBA (244 , 93 , 81 , 0.7 );
265+ }
266+ }
267+ }
268+
269+ // skills
270+ .skill-span {
271+ display : inline-block ;
272+ margin-right : 5px ;
273+ padding : 3px 8px ;
274+ color : #333 ;
275+ }
138276}
139277 </style >
0 commit comments