tree_table.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <div class="tree-table">
  3. <div class="tree-head">
  4. <table>
  5. <tr>
  6. <td class="td1">序号</td>
  7. <td class="td2">组织名称</td>
  8. <td class="td3" @click="isDesc = !isDesc">
  9. 创建时间
  10. <div class="arrow">
  11. <span class="up-arrow" :class="{ sort: isDesc }"></span>
  12. <span class="down-arrow" :class="{ sort: !isDesc }"></span>
  13. </div>
  14. </td>
  15. <td class="td4">最后更新时间</td>
  16. <td class="td6">操作</td>
  17. </tr>
  18. </table>
  19. </div>
  20. <div id="scrollWrap" class="tree-wrap">
  21. <div class="tree-body">
  22. <table v-if="treeDataSource.length > 0">
  23. <tbody>
  24. <tr>
  25. <td>
  26. <tree-item
  27. v-for="(model, i) in treeDataSource"
  28. :key="'root_node_' + i"
  29. :root="0"
  30. :num="i"
  31. @actionFunc="actionFunc"
  32. @deleteFunc="deleteFunc"
  33. @addOrganization="addOrganization"
  34. @handlerExpand="handlerExpand"
  35. :nodes="treeDataSource.length"
  36. :trees.sync="treeDataSource"
  37. :model.sync="model"
  38. >
  39. </tree-item>
  40. </td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. export default {
  50. name: "treeTable",
  51. props: ["list"],
  52. data() {
  53. return {
  54. isDesc: false,
  55. treeDataSource: []
  56. };
  57. },
  58. watch: {
  59. list: {
  60. handler() {
  61. console.log("ddddd");
  62. this.initTreeData();
  63. },
  64. deep: true
  65. },
  66. isDesc(nelVal, oldVal) {
  67. this.$emit("orderByFunc", nelVal);
  68. }
  69. },
  70. computed: {},
  71. methods: {
  72. initTreeData() {
  73. console.log("处理前的:", JSON.parse(JSON.stringify(this.list)));
  74. // 这里一定要转化,要不然他们的值监听不到变化
  75. let tempData = JSON.parse(JSON.stringify(this.list));
  76. let reduceDataFunc = (data, level) => {
  77. data.map((m, i) => {
  78. m.isExpand = false;
  79. m.childrens = m.childrens || [];
  80. m.level = level;
  81. m.bLeft = level === 1 ? 34 : (level - 2) * 16 + 34;
  82. // m.Experience = m.Experience || "无";
  83. if (m.childrens.length > 0) {
  84. reduceDataFunc(m.childrens, level + 1);
  85. }
  86. });
  87. };
  88. reduceDataFunc(tempData, 1);
  89. console.log("处理后的:", tempData);
  90. this.treeDataSource = tempData;
  91. },
  92. getMore() {
  93. alert("滚动到底部加载更多");
  94. // 滚动到最后
  95. $("#scrollWrap").mCustomScrollbar("scrollTo", "top", {
  96. scrollInertia: 0
  97. });
  98. },
  99. // 编辑
  100. actionFunc(m) {
  101. this.$emit("actionFunc", m);
  102. },
  103. // 删除
  104. deleteFunc(m) {
  105. this.$emit("deleteFunc", m);
  106. },
  107. // 添加下级组织
  108. addOrganization(m) {
  109. this.$emit("addOrganization", m);
  110. },
  111. // 展开
  112. handlerExpand(m) {
  113. this.$emit("handlerExpand", m);
  114. }
  115. },
  116. components: {
  117. treeItem: () => import("./tree-item.vue")
  118. },
  119. mounted() {
  120. const vm = this;
  121. vm.$nextTick(() => {
  122. vm.initTreeData();
  123. });
  124. }
  125. };
  126. </script>
  127. <style lang="less">
  128. .tree-table {
  129. width: 100%;
  130. position: relative;
  131. .center {
  132. text-align: center;
  133. }
  134. table {
  135. width: 100%;
  136. text-align: center;
  137. border-collapse: collapse;
  138. border-spacing: 0;
  139. td {
  140. word-break: break-all;
  141. word-wrap: break-word;
  142. font-size: 12px;
  143. }
  144. }
  145. .td-border {
  146. border-bottom: 1px solid #e8e8e8;
  147. .leve {
  148. // 屏蔽双击不能选择文本样式
  149. -webkit-user-select: none;
  150. -moz-user-select: none;
  151. -o-user-select: none;
  152. user-select: none;
  153. &:hover {
  154. background-color: #f7f9ff;
  155. }
  156. }
  157. }
  158. th,
  159. td {
  160. font-weight: 400;
  161. text-align: left;
  162. }
  163. .td1 {
  164. width: 120px;
  165. padding-left: 30px;
  166. }
  167. .td2 {
  168. width: 260px;
  169. padding-left: 30px;
  170. }
  171. .td3 {
  172. width: 120px;
  173. }
  174. .td4 {
  175. width: 220px;
  176. }
  177. .td6 {
  178. width: 280px;
  179. }
  180. .p20 {
  181. padding-left: 20px;
  182. }
  183. .leve-1 .td1 {
  184. padding-left: 30px;
  185. }
  186. .leve-2 .td1 {
  187. padding-left: 46px;
  188. }
  189. .leve-3 .td1 {
  190. padding-left: 62px;
  191. }
  192. .leve-4 .td1 {
  193. padding-left: 78px;
  194. }
  195. .leve-5 .td1 {
  196. padding-left: 90px;
  197. }
  198. .leve-6 .td1 {
  199. padding-left: 106px;
  200. }
  201. .leve-7 .td1 {
  202. padding-left: 122px;
  203. }
  204. .leve-8 .td1 {
  205. padding-left: 138px;
  206. }
  207. .leve-9 .td1 {
  208. padding-left: 154px;
  209. }
  210. .td4 {
  211. .unvisibie {
  212. visibility: hidden;
  213. }
  214. .ellipsis {
  215. display: block;
  216. max-width: 200px;
  217. }
  218. .iconfont {
  219. color: #414959;
  220. position: relative;
  221. top: 0px;
  222. left: 5px;
  223. font-size: 14px;
  224. }
  225. }
  226. > div {
  227. position: absolute;
  228. width: 100%;
  229. }
  230. .line-height {
  231. height: 40px;
  232. line-height: 40px;
  233. }
  234. .tree-head {
  235. .line-height;
  236. td {
  237. color: rgba(0, 0, 0, 0.45);
  238. border-bottom: 2px solid #e8e8e8;
  239. }
  240. .arrow {
  241. position: relative;
  242. display: inline-block;
  243. width: 16px;
  244. height: 16px;
  245. background: #fff;
  246. span {
  247. position: absolute;
  248. display: block;
  249. width: 0;
  250. height: 0;
  251. left: 0;
  252. border-style: solid;
  253. border-width: 4px;
  254. }
  255. .up-arrow {
  256. top: 3px;
  257. border-color: transparent transparent #ddd transparent;
  258. &.sort {
  259. border-bottom-color: #3c4454;
  260. }
  261. }
  262. .down-arrow {
  263. top: 12px;
  264. border-color: #ddd transparent transparent transparent;
  265. &.sort {
  266. border-top-color: #3c4454;
  267. }
  268. }
  269. }
  270. }
  271. .ellipsis {
  272. // overflow: hidden;
  273. white-space: nowrap;
  274. text-overflow: ellipsis;
  275. }
  276. .tree-wrap {
  277. top: 40px;
  278. }
  279. .tree-body {
  280. table {
  281. table-layout: fixed;
  282. }
  283. td {
  284. a {
  285. text-decoration: none;
  286. }
  287. .line-height;
  288. color: rgba(0, 0, 0, 0.85);
  289. font-size: 14px;
  290. .reset {
  291. color: #1890ff;
  292. }
  293. .delete {
  294. color: #f56c6c;
  295. }
  296. .user {
  297. color: #e6a23c;
  298. }
  299. .addr {
  300. color: #67c23a;
  301. }
  302. .line {
  303. display: inline-block;
  304. width: 1px;
  305. background: rgba(0, 0, 0, 0.09);
  306. margin: 0 11px;
  307. height: 14px;
  308. }
  309. }
  310. .td-title {
  311. position: relative;
  312. a {
  313. display: block;
  314. }
  315. .tree-close,
  316. .tree-open {
  317. position: absolute;
  318. width: 0;
  319. height: 0;
  320. border-color: #999;
  321. border-style: solid;
  322. cursor: pointer;
  323. border-width: 5px;
  324. z-index: 2;
  325. }
  326. .tree-close {
  327. left: -12px;
  328. top: 14px;
  329. border-color: transparent transparent transparent #aaaaaa;
  330. }
  331. .tree-open {
  332. left: -17px;
  333. top: 17px;
  334. border-color: #aaaaaa transparent transparent;
  335. }
  336. }
  337. .leve-1 .td-title a {
  338. width: 230px;
  339. }
  340. .leve-2 .td-title a {
  341. width: 200px;
  342. }
  343. .leve-3 .td-title a {
  344. width: 170px;
  345. }
  346. .leve-4 .td-title a {
  347. width: 140px;
  348. }
  349. .leve-5 .td-title a {
  350. width: 110px;
  351. }
  352. .leve-6 .td-title a {
  353. width: 80px;
  354. }
  355. .leve-7 .td-title a {
  356. width: 50px;
  357. }
  358. .leve-8 .td-title a {
  359. width: 20px;
  360. }
  361. .other-node {
  362. position: relative;
  363. > .not-border:not(:last-child) {
  364. position: relative;
  365. .before-line {
  366. content: "";
  367. position: absolute;
  368. width: 1px;
  369. height: 100%;
  370. background-color: #e8e8e8;
  371. border: none;
  372. top: -20px;
  373. z-index: 1;
  374. left: 34px;
  375. }
  376. }
  377. }
  378. .not-border {
  379. .td-title {
  380. &::before {
  381. content: "";
  382. position: absolute;
  383. width: 1px;
  384. height: 40px;
  385. background-color: #e8e8e8;
  386. border: none;
  387. left: -12px;
  388. top: -20px;
  389. z-index: 1;
  390. }
  391. &::after {
  392. content: "";
  393. left: -11px;
  394. position: absolute;
  395. right: auto;
  396. background-color: #e8e8e8;
  397. height: 1px;
  398. top: 19px;
  399. width: 16px;
  400. z-index: 1;
  401. }
  402. }
  403. }
  404. }
  405. .t-icon {
  406. display: inline-block;
  407. width: 14px;
  408. height: 18px;
  409. background-size: 100% 100% !important;
  410. vertical-align: middle;
  411. margin: -3px 4px 0 0;
  412. &.m-dep {
  413. background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC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