123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <template>
- <view>
- <view class="cu-form-group solid-bottom ">
- <input placeholder="输入关键字进行过滤" v-model="filterText" ></input>
- </view>
- <ly-tree :tree-data="treeData"
- ref="tree"
- node-key="id"
- :ready="true"
- :accordion="true"
- :filter-node-method="filterNode"
- :highlightCurrent="true"
- :checkOnlyLeaf="true"
- @node-click="handleNodeClick">
- </ly-tree>
- <view class="cu-bar bg-white margin-top">
- <view class="action">
- <text class="cuIcon-title text-orange "></text> 侧边抽屉
- </view>
- <view class="action">
- <button class="cu-btn bg-green shadow" @tap="showModal" data-target="DrawerModalL">Left</button>
- <button class="cu-btn bg-blue shadow margin-left" @tap="showModal" data-target="DrawerModalR">Right</button>
- </view>
- </view>
- <view class="cu-modal drawer-modal justify-start" :class="modalName=='DrawerModalL'?'show':''" @tap="hideModal">
- <view class="bg-white cu-dialog basis-lg" @tap.stop="" :style="[{top:CustomBar+'px',height:'calc(100vh - ' + CustomBar + 'px)'}]">
- <scroll-view scroll-y="true" style="height: 100%;">
- <view class="cu-list menu text-left">
- <view class="cu-form-group solid-bottom ">
- <input placeholder="输入关键字进行过滤" v-model="filterTextLeft" ></input>
- </view>
- <ly-tree :tree-data="treeData"
- ref="treeLeft"
- node-key="id"
- :ready="true"
- :accordion="true"
- :filter-node-method="filterNodeLeft"
- :highlightCurrent="true"
- :checkOnlyLeaf="true"
- @node-click="handleNodeClick">
- </ly-tree>
- </view>
- </scroll-view>
- </view>
- </view>
-
- <view class="cu-modal drawer-modal justify-end" :class="modalName=='DrawerModalR'?'show':''" @tap="hideModal">
- <view class="cu-dialog basis-lg" @tap.stop="" :style="[{top:CustomBar+'px',height:'calc(100vh - ' + CustomBar + 'px)'}]">
- <scroll-view scroll-y="true" style="height: 100%;">
- <view class="bg-white cu-list tabbar menu text-left" style="margin-bottom: 100px;">
- <view class="cu-form-group solid-bottom ">
- <input placeholder="输入关键字进行过滤" v-model="filterTextRight" ></input>
- </view>
- <ly-tree :tree-data="treeData"
- ref="treeRight"
- node-key="id"
- :defaultExpandAll="true"
- :ready="true"
- :accordion="true"
- :filter-node-method="filterNodeRight"
- :highlightCurrent="true"
- :checkOnlyLeaf="true"
- @node-click="handleNodeClick">
- </ly-tree>
- </view>
- </scroll-view>
- </view>
- </view>
- </view>
-
- </template>
- <script>
- export default {
- data() {
- return {
- CustomBar: this.CustomBar,
- modalName: null,
- filterText:"",
- filterTextLeft:"",
- filterTextRight:"",
- ready: false, // 这里用于自主控制loading加载状态,避免异步正在加载数据的空档显示“暂无数据”
- treeData: [{
- id: 1,
- label: '一级 1',
- children: [{
- id: 11,
- label: '二级 1-1',
- children: [{
- id: 111,
- label: '三级 1-1-1'
- },{
- id: 112,
- label: '三级 1-1-2'
- }]
- }]
- }, {
- id: 2,
- label: '一级 2',
- children: [{
- id: 21,
- label: '二级 2-1',
- children: [{
- id: 211,
- label: '三级 2-1-1'
- }]
- }, {
- id: 22,
- label: '二级 2-2',
- children: [{
- id: 221,
- label: '三级 2-2-1'
- }]
- }]
- }, {
- id: 3,
- label: '一级 3',
- children: [{
- id: 31,
- label: '二级 3-1',
- children: [{
- id: 311,
- label: '三级 3-1-1'
- }]
- }, {
- id: 32,
- label: '二级 3-2',
- children: [{
- id: 321,
- label: '三级 3-2-1'
- }]
- }]
- }],
- };
- },
- methods: {
- handleNodeClick(obj) {
- console.log("子节点信息:",obj);
- console.log("子节点路径:",this.$refs.tree.getNodePath(obj))
- },
- filterNode(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- filterNodeLeft(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- filterNodeRight(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- showModal(e) {
- this.modalName = e.currentTarget.dataset.target
- },
- hideModal(e) {
- this.modalName = null
- },
- },
- watch:{
- filterText(val) {
- this.$refs.tree.filter(val);
- },
- filterTextLeft(val) {
- this.$refs.treeLeft.filter(val);
- },
- filterTextRight(val) {
- this.$refs.treeRight.filter(val);
- },
- }
- };
- </script>
- <style></style>
|