ztree.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <div class="ztree" :id="ztreeId"></div>
  3. </template>
  4. <script>
  5. import * as $ from "jquery";
  6. if(!window.jQuery){
  7. window.jQuery = $;
  8. }
  9. require("@ztree/ztree_v3/js/jquery.ztree.all");
  10. export default {
  11. props: {
  12. setting: {
  13. type: Object,
  14. require: false,
  15. default: function(){
  16. return {}
  17. }
  18. },
  19. nodes: {
  20. type: Array,
  21. require: true,
  22. default: function(){
  23. return []
  24. }
  25. }
  26. },
  27. data(){
  28. return {
  29. ztreeId: 'ztree_'+ parseInt(Math.random() * 1e10),
  30. ztreeObj: null,
  31. list: [],
  32. ztreeSetting: {
  33. view: {
  34. showIcon: false // default to hide icon
  35. },
  36. callback: {
  37. onAsyncError: (...arg) => {
  38. this.$emit('onAsyncError', ...arg)
  39. },
  40. onAsyncSuccess: (...arg) => {
  41. this.$emit('onAsyncSuccess', ...arg)
  42. },
  43. onCheck: (...arg) => {
  44. this.$emit('onCheck', ...arg)
  45. },
  46. onClick: (...arg) => {
  47. this.$emit('onClick', ...arg)
  48. },
  49. onCollapse: (...arg) => {
  50. this.$emit('onCollapse', ...arg)
  51. },
  52. onDblClick: (...arg) => {
  53. this.$emit('onDblClick', ...arg)
  54. },
  55. onDrag: (...arg) => {
  56. this.$emit('onDrag', ...arg)
  57. },
  58. onDragMove: (...arg) => {
  59. this.$emit('onDragMove', ...arg)
  60. },
  61. onDrop: (...arg) => {
  62. this.$emit('onDrop', ...arg)
  63. },
  64. onExpand: (...arg) => {
  65. this.$emit('onExpand', ...arg)
  66. },
  67. onMouseDown: (...arg) => {
  68. this.$emit('onMouseDown', ...arg)
  69. },
  70. onMouseUp: (...arg) => {
  71. this.$emit('onMouseUp', ...arg)
  72. },
  73. onRemove: (...arg) => {
  74. this.$emit('onRemove', ...arg)
  75. },
  76. onRename: (...arg) => {
  77. this.$emit('onRename', ...arg)
  78. },
  79. onRightClick: (...arg) => {
  80. this.$emit('onRightClick', ...arg)
  81. }
  82. }
  83. }
  84. }
  85. },
  86. watch: {
  87. nodes: {
  88. handler: function(nodes){
  89. this.list = nodes;
  90. // update tree
  91. if(this.ztreeObj){
  92. this.ztreeObj.destroy();
  93. }
  94. this.$nextTick(() => {
  95. this.ztreeObj = $.fn.zTree.init($("#"+this.ztreeId), Object.assign({}, this.ztreeSetting, this.setting), this.list);
  96. this.$emit('onCreated', this.ztreeObj)
  97. })
  98. },
  99. deep: true,
  100. immediate: true
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. /* beauty ztree! */
  107. .ztree {
  108. text-align:left;
  109. font-size: 14px;
  110. }
  111. .ztree >>> li {
  112. list-style-type: none;
  113. white-space: nowrap;
  114. outline: none;
  115. }
  116. .ztree >>> li ul {
  117. position: relative;
  118. padding: 0 0 0 20px;
  119. margin: 0;
  120. }
  121. .ztree >>> .line:before {
  122. position: absolute;
  123. top: 0;
  124. left: 10px;
  125. height: 100%;
  126. content: '';
  127. border-right: 1px dotted #dbdbdb;
  128. }
  129. .ztree >>> .roots_docu:before,
  130. .ztree >>> .roots_docu:after,
  131. .ztree >>> .center_docu:before,
  132. .ztree >>> .bottom_docu:before,
  133. .ztree >>> .center_docu:after,
  134. .ztree >>> .bottom_docu:after {
  135. position: absolute;
  136. content: '';
  137. border: 0 dotted #dbdbdb;
  138. }
  139. .ztree >>> .roots_docu:before {
  140. left: 10px;
  141. height: 50%;
  142. top:50%;
  143. border-left-width: 1px;
  144. }
  145. .ztree >>> .roots_docu:after {
  146. top: 50%;
  147. left: 11px;
  148. width: 50%;
  149. border-top-width: 1px;
  150. }
  151. .ztree >>> .center_docu:before {
  152. left: 10px;
  153. height: 100%;
  154. border-left-width: 1px;
  155. }
  156. .ztree >>> .center_docu:after {
  157. top: 50%;
  158. left: 11px;
  159. width: 50%;
  160. border-top-width: 1px;
  161. }
  162. .ztree >>> .bottom_docu:before {
  163. left: 10px;
  164. height: 50%;
  165. border-left-width: 1px;
  166. }
  167. .ztree >>> .bottom_docu:after {
  168. top: 50%;
  169. left: 11px;
  170. width: 50%;
  171. border-top-width: 1px;
  172. }
  173. .ztree >>> li a {
  174. display: inline-block;
  175. line-height: 22px;
  176. height: 22px;
  177. margin: 0;
  178. cursor: pointer;
  179. transition: none;
  180. vertical-align: middle;
  181. color: #555555;
  182. }
  183. .ztree >>> .node_name{
  184. display: inline-block;
  185. padding: 0 3px;
  186. border-radius: 4px;
  187. }
  188. .ztree >>> .curSelectedNode .node_name{
  189. color: #000;
  190. background-color: #c9e9f7;
  191. }
  192. .ztree >>> .curSelectedNode_Edit {
  193. height: 20px;
  194. opacity: 0.8;
  195. color: #000;
  196. border: 1px #6cc2e8 solid;
  197. background-color: #9dd6f0;
  198. }
  199. .ztree >>> .tmpTargetNode_inner {
  200. opacity: 0.8;
  201. color: #fff;
  202. background-color: #4fcbf0;
  203. filter: alpha(opacity=80);
  204. }
  205. .ztree >>> .rename {
  206. font-size: 12px;
  207. line-height: 22px;
  208. width: 80px;
  209. height: 22px;
  210. margin: 0;
  211. padding: 0;
  212. vertical-align: top;
  213. border: 0;
  214. background: none;
  215. }
  216. .ztree >>> .button {
  217. position: relative;
  218. display: inline-block;
  219. line-height: 22px;
  220. height: 22px;
  221. width: 22px;
  222. cursor: pointer;
  223. text-align: center;
  224. vertical-align: middle;
  225. }
  226. .ztree >>> .button.edit {
  227. color: #25ae88;
  228. }
  229. .ztree >>> .button.remove {
  230. color: #CB4042;
  231. }
  232. .ztree >>> .button.chk {
  233. position: relative;
  234. width: 14px;
  235. height: 14px;
  236. margin: 0 4px 0 0;
  237. border: 1px solid #d7dde4;
  238. border-radius: 2px;
  239. background: #fff;
  240. }
  241. .ztree >>> .chk.radio_true_full,
  242. .ztree >>> .chk.radio_false_full,
  243. .ztree >>> .chk.radio_true_full_focus,
  244. .ztree >>> .chk.radio_false_full_focus,
  245. .ztree >>> .chk.radio_false_disable,
  246. .ztree >>> .chk.radio_true_disable,
  247. .ztree >>> .chk.radio_true_part,
  248. .ztree >>> .chk.radio_false_part,
  249. .ztree >>> .chk.radio_true_part_focus,
  250. .ztree >>> .chk.radio_false_part_focus {
  251. border-radius: 8px;
  252. }
  253. .ztree >>> .button.chk:after {
  254. position: absolute;
  255. top: 1px;
  256. left: 4px;
  257. width: 4px;
  258. height: 8px;
  259. content: '';
  260. transition: -webkit-transform 0.2s ease-in-out;
  261. transition: transform 0.2s ease-in-out;
  262. transition: transform 0.2s ease-in-out, -webkit-transform 0.2s ease-in-out;
  263. -webkit-transform: rotate(0deg) scale(0);
  264. transform: rotate(0deg) scale(0);
  265. border-right: 2px solid #fff;
  266. border-bottom: 2px solid #fff;
  267. }
  268. .ztree >>> .button.checkbox_false_full_focus {
  269. border-color: #ccc;
  270. }
  271. .ztree >>> .button.checkbox_true_full,
  272. .ztree >>> .button.checkbox_true_full_focus,
  273. .ztree >>> .button.checkbox_true_part,
  274. .ztree >>> .button.checkbox_true_part_focus,
  275. .ztree >>> .button.checkbox_true_disable {
  276. border-color: #39f;
  277. background-color: #39f;
  278. }
  279. .ztree >>> .button.checkbox_true_full:after,
  280. .ztree >>> .button.checkbox_true_full_focus:after,
  281. .ztree >>> .button.checkbox_true_disable:after {
  282. -webkit-transform: rotate(45deg) scale(1);
  283. transform: rotate(45deg) scale(1);
  284. }
  285. .ztree >>> .button.checkbox_true_part:after,
  286. .ztree >>> .button.checkbox_true_part_focus:after {
  287. top: 5px;
  288. left: 2px;
  289. width: 10px;
  290. height: 1px;
  291. -webkit-transform: rotate(0deg) scale(1);
  292. transform: rotate(0deg) scale(1);
  293. border-right: 0;
  294. }
  295. .ztree >>> .button.radio_true_full,
  296. .ztree >>> .chk.radio_true_full_focus,
  297. .ztree >>> .chk.radio_true_part,
  298. .ztree >>> .chk.radio_true_part_focus {
  299. border-color: #39f;
  300. }
  301. .ztree >>> .button.radio_true_full:after,
  302. .ztree >>> .chk.radio_true_full_focus:after,
  303. .ztree >>> .chk.radio_true_part:after,
  304. .ztree >>> .chk.radio_true_part_focus:after {
  305. top: 3px;
  306. left: 3px;
  307. width: 8px;
  308. -webkit-transform: rotate(0deg) scale(1);
  309. transform: rotate(0deg) scale(1);
  310. border: 0;
  311. border-radius: 4px;
  312. background: #39f;
  313. }
  314. .ztree >>> .button.checkbox_true_disable,
  315. .ztree >>> .button.checkbox_false_disable,
  316. .ztree >>> .chk.radio_false_disable,
  317. .ztree >>> .chk.radio_true_disable {
  318. cursor: not-allowed;
  319. }
  320. .ztree >>> .button.checkbox_false_disable {
  321. background-color: #f3f3f3;
  322. }
  323. .ztree >>> .button.noline_close:before,
  324. .ztree >>> .button.noline_open:before,
  325. .ztree >>> .button.root_open:before,
  326. .ztree >>> .button.root_close:before,
  327. .ztree >>> .button.roots_open:before,
  328. .ztree >>> .button.roots_close:before,
  329. .ztree >>> .button.bottom_open:before,
  330. .ztree >>> .button.bottom_close:before,
  331. .ztree >>> .button.center_open:before,
  332. .ztree >>> .button.center_close:before {
  333. position: absolute;
  334. top: 5px;
  335. left: 5px;
  336. content: '';
  337. transition: -webkit-transform ease 0.3s;
  338. transition: transform ease 0.3s;
  339. transition: transform ease 0.3s, -webkit-transform ease 0.3s;
  340. -webkit-transform: rotateZ(0deg);
  341. transform: rotateZ(0deg);
  342. -webkit-transform-origin: 25% 50%;
  343. transform-origin: 25% 50%;
  344. border: 6px solid;
  345. border-color: transparent transparent transparent #666;
  346. }
  347. .ztree >>> .button.noline_open:before,
  348. .ztree >>> .button.root_open:before,
  349. .ztree >>> .button.roots_open:before,
  350. .ztree >>> .button.bottom_open:before,
  351. .ztree >>> .button.center_open:before {
  352. -webkit-transform: rotateZ(90deg);
  353. transform: rotateZ(90deg);
  354. }
  355. .ztree >>> .button.ico_loading {
  356. margin-right: 2px;
  357. background: url('data:image/gif;base64,R0lGODlhEAAQAKIGAMLY8YSx5HOm4Mjc88/g9Ofw+v///wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgAGACwAAAAAEAAQAAADMGi6RbUwGjKIXCAA016PgRBElAVlG/RdLOO0X9nK61W39qvqiwz5Ls/rRqrggsdkAgAh+QQFCgAGACwCAAAABwAFAAADD2hqELAmiFBIYY4MAutdCQAh+QQFCgAGACwGAAAABwAFAAADD1hU1kaDOKMYCGAGEeYFCQAh+QQFCgAGACwKAAIABQAHAAADEFhUZjSkKdZqBQG0IELDQAIAIfkEBQoABgAsCgAGAAUABwAAAxBoVlRKgyjmlAIBqCDCzUoCACH5BAUKAAYALAYACgAHAAUAAAMPaGpFtYYMAgJgLogA610JACH5BAUKAAYALAIACgAHAAUAAAMPCAHWFiI4o1ghZZJB5i0JACH5BAUKAAYALAAABgAFAAcAAAMQCAFmIaEp1motpDQySMNFAgA7') 0 center no-repeat;
  358. }
  359. .ztree >>> .tmpTargetzTree {
  360. opacity: 0.8;
  361. background-color: #2EA9DF;
  362. filter: alpha(opacity=80);
  363. }
  364. .ztree >>> .tmpzTreeMove_arrow {
  365. position: absolute;
  366. width: 18px;
  367. height: 18px;
  368. color: #4fcbf0;
  369. }
  370. .ztree >>> .ztree.zTreeDragUL {
  371. overflow: hidden;
  372. position: absolute;
  373. width: auto;
  374. height: auto;
  375. margin: 0;
  376. padding: 0;
  377. opacity: 0.8;
  378. border: 1px #176b53 dotted;
  379. background-color: #dbdbdb;
  380. filter: alpha(opacity=80);
  381. }
  382. .zTreeMask {
  383. position: absolute;
  384. z-index: 10000;
  385. opacity: 0.0;
  386. background-color: #cfcfcf;
  387. filter: alpha(opacity=0);
  388. }
  389. </style>