classMenu.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="treeBox">
  3. <treeComp :treeData="options" @handleClick="handleClick"></treeComp>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. options: {
  10. default: {}
  11. },
  12. categoryValue: {
  13. type: Array,
  14. default: []
  15. },
  16. },
  17. name: 'classMenu',
  18. data () {
  19. return {
  20. checkArr:[],
  21. checkId:null
  22. }
  23. },
  24. created(){
  25. this.init()
  26. },
  27. mounted(){
  28. this.checkArr=this.categoryValue
  29. if(this.categoryValue.length!=0){
  30. this.checkId=this.categoryValue[(this.categoryValue.length-1)]
  31. }
  32. this.checkArr.push('000')
  33. //this.init()
  34. },
  35. methods:{
  36. init(){
  37. let that=this
  38. Vue.component('treeComp', {
  39. functional: true,
  40. props: {treeData: Object},
  41. render(h, {props: {treeData = {}}}) {
  42. const creatNode = (node,num,pId)=>{
  43. node.pId=pId
  44. if(num==1){
  45. node.parent='000'
  46. }
  47. if(node.children && node.children.length > 0){
  48. let hArr = node.children.map(item=>{
  49. let nowPid = pId+','+item.pkId
  50. return creatNode(item,num+1,nowPid)
  51. })
  52. if(num==0){
  53. return h('div', {class:{'demoShow':true}},
  54. [h('div',{class:{'demoText':true,'demoTextSelect':that.checkId==node.pkId},style:'padding-Left:'+(2+num*0.5)+'vw',
  55. on:{click:function (event){
  56. event.stopPropagation();
  57. event.preventDefault();
  58. that.handleClick(node,this);
  59. } }},[
  60. h('div',{class:{'classifyRightAction':that.checkArr.indexOf(node.pkId)>-1,'classifyRight':true},
  61. on:{click:function (event){
  62. event.stopPropagation();
  63. event.preventDefault();
  64. that.handleOpenClick(node);
  65. } }},['']),
  66. node.name]), hArr])
  67. }else{
  68. return h('div', {class:{'demo':!(that.checkArr.indexOf(node.parent)>-1),'demoShow':(that.checkArr.indexOf(node.parent)>-1)}}, [h('div',{class:{'demoText':true,'demoTextSelect':that.checkId==node.pkId},style:'padding-Left:'+(2+num*0.5)+'vw',
  69. on:{click:function (event){
  70. event.stopPropagation();
  71. event.preventDefault();
  72. that.handleClick(node,this);
  73. } }},[
  74. h('div',{class:{'classifyRightAction':that.checkArr.indexOf(node.pkId)>-1,'classifyRight':true},
  75. on:{click:function (event){
  76. event.stopPropagation();
  77. event.preventDefault();
  78. that.handleOpenClick(node);
  79. } }},['']),
  80. node.name]), hArr])
  81. }
  82. }else{
  83. return h('div', {class:{'demo':!(that.checkArr.indexOf(node.parent)>-1),'demoShow':(that.checkArr.indexOf(node.parent)>-1)}}, [h('div',{class:{'demoText':true,'demoTextSelect':that.checkId==node.pkId},style:'padding-Left:'+(3.2+num*0.5)+'vw',
  84. on:{click: function(event){
  85. event.stopPropagation();
  86. event.preventDefault();
  87. that.handleClick(node,this);
  88. }}},[
  89. node.name])])
  90. }
  91. }
  92. return creatNode(treeData,0,'')
  93. }
  94. })
  95. },
  96. handleOpenClick(node){
  97. //console.log(node)
  98. //node.openData=!node.openData
  99. let indexNum=this.checkArr.indexOf(node.pkId)
  100. if(indexNum>-1){
  101. this.checkArr.splice(indexNum, 1)
  102. }else{
  103. this.checkArr.push(node.pkId)
  104. }
  105. console.log(this.checkArr)
  106. },
  107. handleClick(node,ele){
  108. console.log(node)
  109. this.checkId = node.pkId;
  110. let dataArr=node.pId.split(",")
  111. dataArr.shift()
  112. let data={
  113. categoryId:node.pkId,
  114. categoryName:node.name,
  115. categoryValue:dataArr
  116. }
  117. this.$emit('changeClass',data);
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="less" scoped>
  123. .demoShow{
  124. min-width: 11.71875vw;
  125. width: max-content;
  126. text-align: left;
  127. font-size:0.9375vw;
  128. display: flex;
  129. flex-direction: column;
  130. color: #202124;
  131. &:before{
  132. content:' ';
  133. display: inline-block;
  134. }
  135. }
  136. .demo{
  137. min-width: 11.71875vw;
  138. width: max-content;
  139. display: none;
  140. text-align: left;
  141. font-size:0.9375vw;
  142. flex-direction: column;
  143. color: #202124;
  144. &:before{
  145. content:' ';
  146. display: inline-block;
  147. }
  148. }
  149. .demoText{
  150. padding-right:2vw;
  151. font-weight: 500;
  152. min-width: 11.71875vw;
  153. height: 2.91vw;
  154. display: inline-block;
  155. line-height: 2.91vw;
  156. cursor: pointer;
  157. color: #202124;
  158. }
  159. .demoTextSelect{
  160. background: #ECF3FF;
  161. }
  162. .classifyRight{
  163. background: url('../../../../image/rightIcon.png');
  164. background-size: 100% 100%;
  165. width:0.6vw;
  166. height: 0.6vw;
  167. color: #CBCCCC;
  168. display: inline-block;
  169. margin-left: auto;
  170. transform-origin: 150% 60%;
  171. margin-right: 0.6vw;
  172. -moz-user-select:none;/*火狐*/
  173. -webkit-user-select:none;/*webkit浏览器*/
  174. -ms-user-select:none;/*IE10*/
  175. -khtml-user-select:none;/*早期浏览器*/
  176. user-select:none;
  177. }
  178. .classifyRightAction{
  179. transform: rotate(90deg);
  180. transform-origin: 75% 50%;
  181. }
  182. .treeBox{
  183. overflow-x: scroll;
  184. height: calc(100% - 3.5vw);
  185. }
  186. .treeBox::-webkit-scrollbar{
  187. width:16px;
  188. height:16px;
  189. background-color:#fff;
  190. display:block;
  191. }
  192. </style>