当前位置:   article > 正文

vue 自定义侧边栏组件_dis-hover

dis-hover
  1. <template>
  2. <div :class="[cusClass]">
  3. <Affix :offset-top="0" :use-capture="true">
  4. <Card class="category mr_10" :bordered="false" dis-hover :padding="0">
  5. <!-- <RadioGroup v-model="vertical" v-for="(item, index) in list" :key="index" vertical @on-change="onChange(item)">
  6. <Radio :label="item.dataName">
  7. </Radio>
  8. </RadioGroup> -->
  9. <div class="Box" v-for="(option, index) in list" :key="index" @click="onChange(option, index)" :class="activeClass == index ? 'active':''">
  10. <div style="height: 37px; line-height: 37px; font-size: 14px; cursor: pointer;">{{option.dataName}}</div>
  11. </div>
  12. <div>
  13. <Spin class="cus-auto-body-more" v-if="loading"></Spin>
  14. <div class="cus-auto-body-more" @click="onMore" v-if="!loading && !finished">查看更多</div>
  15. <div class="cus-auto-body-more" v-if="finished">没有更多啦~</div>
  16. </div>
  17. </Card>
  18. </Affix>
  19. </div>
  20. </template>
  21. <script>
  22. /**
  23. * 语法糖value
  24. * @fnc 接口列表方法
  25. * @onChange 回调方法 -> 返回当前选中对象, 索引(option, index)
  26. */
  27. export default {
  28. name: "cusSidebar",
  29. props:{
  30. value: {
  31. type: Object,
  32. default: () =>{
  33. return {
  34. label: '',
  35. value: ''
  36. }
  37. }
  38. },
  39. fnc: {
  40. type: Function,
  41. default: () =>{
  42. return () =>{
  43. }
  44. }
  45. }
  46. },
  47. computed: {
  48. cusClass() {
  49. if (this.menu_collapsed) {
  50. return "close";
  51. } else {
  52. return "open";
  53. }
  54. },
  55. },
  56. data() {
  57. return {
  58. collapsed: false,
  59. vertical: "",
  60. list: [],
  61. activeClass: "",
  62. loading: true,
  63. finished: false,
  64. contextData: {
  65. level: 0,
  66. },
  67. pages :{
  68. page: 1,
  69. pageSize: 1000,
  70. }
  71. };
  72. },
  73. mounted() {
  74. this.getOptionsList();
  75. },
  76. methods: {
  77. handleContextMenu(data) {
  78. this.contextData = data;
  79. },
  80. onChange(option, index) {
  81. this.$emit("onChange", option);
  82. this.activeClass = index;
  83. },
  84. onMore () {
  85. this.loading = true
  86. this.getOptionsList()
  87. },
  88. getOptionsList() {
  89. return new Promise((resolve, reject) => {
  90. let params = {
  91. pageNum: this.pages.page,
  92. pageSize: this.pages.pageSize,
  93. }
  94. this.fnc( params ).then( res => {
  95. this.loading = false;
  96. if (res.retCode === 2000) {
  97. this.pages.page += 1;
  98. this.list = res.data.records;
  99. this.finished = true;
  100. if (this.list.length) {
  101. this.$emit("onChange", this.list[0]);
  102. }
  103. resolve()
  104. }
  105. })
  106. })
  107. }
  108. },
  109. };
  110. </script>
  111. <style lang="scss" scoped>
  112. .close .ivu-affix {
  113. transition: all 0.5s;
  114. left: 84px !important;
  115. }
  116. .open .ivu-affix {
  117. transition: all 0.5s;
  118. left: 270px !important;
  119. }
  120. </style>
  121. <style scoped lang="scss">
  122. .category {
  123. min-width: 150px;
  124. overflow-y: scroll;
  125. padding: 20px 20px 10px;
  126. max-height: calc(100vh - 150px);
  127. }
  128. .category::-webkit-scrollbar {
  129. display: none;
  130. width: 0 !important;
  131. }
  132. .ivu-tree-arrow {
  133. display: none;
  134. }
  135. .active {
  136. background: #f3f3f3;
  137. color: #1e6fff;
  138. }
  139. .Box:hover {
  140. background: #f3f3f3;
  141. }
  142. .cus-auto-body-more {
  143. justify-content: start!important;;
  144. }
  145. </style>

代码已经封装可实现侧边选择(可用作管理系统侧边选择组件使用)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/971775
推荐阅读
相关标签