Example.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template lang="html">
  2. <div id="example">
  3. <ul class="switch-list">
  4. <li class="switch-item" v-for="item in propList">
  5. <span>{{ item.name }}: </span>
  6. <zk-switch v-model="props[item.name]"></zk-switch>
  7. </li>
  8. </ul>
  9. <tree-table
  10. ref="table"
  11. sum-text="sum"
  12. index-text="#"
  13. :data="data"
  14. :columns="columns"
  15. :stripe="props.stripe"
  16. :border="props.border"
  17. :show-header="props.showHeader"
  18. :show-summary="props.showSummary"
  19. :show-row-hover="props.showRowHover"
  20. :show-index="props.showIndex"
  21. :tree-type="props.treeType"
  22. select-type="radio"
  23. :is-fold="props.isFold"
  24. :expand-type="props.expandType"
  25. expand-key="sex"
  26. @radio-click="handleRadioClick"
  27. :selection-type="props.selectable">
  28. <!-- <tree-table
  29. :columns="columns"
  30. :expand-type="false"
  31. :selection-type="false"
  32. :data="data"> -->
  33. <template slot="$expand" slot-scope="scope">
  34. {{ `My name is ${scope.row.name},
  35. this rowIndex is ${scope.rowIndex}.`
  36. }}
  37. </template>
  38. <template slot="likes" slot-scope="scope">
  39. <button>123</button>
  40. </template>
  41. </tree-table>
  42. </div>
  43. </template>
  44. <script>
  45. import ZkSwitch from './Switch/Switch';
  46. export default {
  47. name: 'example',
  48. components: {
  49. ZkSwitch,
  50. },
  51. data() {
  52. return {
  53. props: {
  54. stripe: false,
  55. border: false,
  56. showHeader: true,
  57. showSummary: false,
  58. showRowHover: true,
  59. showIndex: false,
  60. treeType: true,
  61. isFold: true,
  62. expandType: false,
  63. selectable: false,
  64. },
  65. data: [
  66. {
  67. name: 'Jack',
  68. sex: 'male',
  69. likes: ['football', 'basketball'],
  70. score: 10,
  71. children: [
  72. {
  73. name: 'Ashley',
  74. sex: 'female',
  75. likes: ['football', 'basketball'],
  76. score: 20,
  77. children: [
  78. {
  79. name: 'Ashley',
  80. sex: 'female',
  81. likes: ['football', 'basketball'],
  82. score: 20,
  83. },
  84. {
  85. name: 'Taki',
  86. sex: 'male',
  87. likes: ['football', 'basketball'],
  88. score: 10,
  89. children: [
  90. {
  91. name: 'Ashley',
  92. sex: 'female',
  93. likes: ['football', 'basketball'],
  94. score: 20,
  95. },
  96. {
  97. name: 'Taki',
  98. sex: 'male',
  99. likes: ['football', 'basketball'],
  100. score: 10,
  101. children: [
  102. {
  103. name: 'Ashley',
  104. sex: 'female',
  105. likes: ['football', 'basketball'],
  106. score: 20,
  107. },
  108. {
  109. name: 'Taki',
  110. sex: 'male',
  111. likes: ['football', 'basketball'],
  112. score: 10,
  113. },
  114. ],
  115. },
  116. ],
  117. },
  118. ],
  119. },
  120. {
  121. name: 'Taki',
  122. sex: 'male',
  123. likes: ['football', 'basketball'],
  124. score: 10,
  125. },
  126. ],
  127. },
  128. {
  129. name: 'Tom',
  130. sex: 'male',
  131. likes: ['football', 'basketball'],
  132. score: 20,
  133. children: [
  134. {
  135. name: 'Ashley',
  136. sex: 'female',
  137. likes: ['football', 'basketball'],
  138. score: 20,
  139. children: [
  140. {
  141. name: 'Ashley',
  142. sex: 'female',
  143. likes: ['football', 'basketball'],
  144. score: 20,
  145. },
  146. {
  147. name: 'Taki',
  148. sex: 'male',
  149. likes: ['football', 'basketball'],
  150. score: 10,
  151. },
  152. ],
  153. },
  154. {
  155. name: 'Taki',
  156. sex: 'male',
  157. likes: ['football', 'basketball'],
  158. score: 10,
  159. children: [
  160. {
  161. name: 'Ashley',
  162. sex: 'female',
  163. likes: ['football', 'basketball'],
  164. score: 20,
  165. },
  166. {
  167. name: 'Taki',
  168. sex: 'male',
  169. likes: ['football', 'basketball'],
  170. score: 10,
  171. },
  172. ],
  173. },
  174. ],
  175. },
  176. {
  177. name: 'Tom',
  178. sex: 'male',
  179. likes: ['football', 'basketball'],
  180. score: 20,
  181. },
  182. {
  183. name: 'Tom',
  184. sex: 'male',
  185. likes: ['football', 'basketball'],
  186. score: 20,
  187. children: [
  188. {
  189. name: 'Ashley',
  190. sex: 'female',
  191. likes: ['football', 'basketball'],
  192. score: 20,
  193. },
  194. {
  195. name: 'Taki',
  196. sex: 'male',
  197. likes: ['football', 'basketball'],
  198. score: 10,
  199. },
  200. ],
  201. },
  202. ],
  203. columns: [
  204. {
  205. title: 'name',
  206. key: 'name',
  207. width: '400px',
  208. },
  209. {
  210. title: 'sex',
  211. key: 'sex',
  212. minWidth: '50px',
  213. },
  214. {
  215. title: 'score',
  216. key: 'score',
  217. },
  218. {
  219. title: 'likes',
  220. key: 'likes',
  221. minWidth: '200px',
  222. type: 'template',
  223. template: 'likes',
  224. },
  225. ],
  226. };
  227. },
  228. computed: {
  229. propList() {
  230. return Object.keys(this.props).map(item => ({
  231. name: item,
  232. }));
  233. },
  234. },
  235. methods: {
  236. handleRadioClick(option) {
  237. console.log(option); // eslint-disable-line
  238. },
  239. },
  240. };
  241. </script>
  242. <style scoped lang="less">
  243. * {
  244. margin: 0;
  245. padding: 0;
  246. }
  247. .switch-list {
  248. margin: 20px 0;
  249. list-style: none;
  250. overflow: hidden;
  251. }
  252. .switch-item {
  253. margin: 20px;
  254. float: left;
  255. }
  256. </style>