Blame view

ant-design-vue-jeecg/src/views/jeecg/ImgTurnPage.vue 4.24 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<template>
  <a-card title="树形结构图片翻页查看" style="min-width: 800px;overflow-x:auto ">
    <a-row>
      <!-- 左侧文件树 -->
      <a-col :span="5">
        <a-tree
          showLine
          :treeData="treeData"
          :expandedKeys="[expandedKeys[0]]"
          :selectedKeys="selectedKeys"
          :style="{'height':'500px','border-right':'2px solid #c1c1c1','overflow-y':'auto'}"
          @expand="onExpand"
          @select="this.onSelect"
        >
        </a-tree>
      </a-col>

      <!--右侧缩略图-->
      <a-col :span="19">
        <a-row style="margin-top: 10px">
          <a-col :span="24" style="padding-left: 2%;margin-bottom: 10px">
肖超群 authored
22
23
24
25
26
27
28
            <a-button @click="prev" type="primary">
              <a-icon type="left"/>
              上一页
            </a-button>
            <a-button @click="next" type="primary" style="margin-left: 8px">下一页
              <a-icon type="right"/>
            </a-button>
肖超群 authored
29
30
31
32
33
34
35
36
37
38
39
40
            <span style="margin-left: 15%;font-weight: bolder">{{ navName }}</span>
          </a-col>
          <a-col :span="24" style="padding-left: 2%;">
            <img :src="imgUrl" preview>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
  </a-card>
</template>

<script>
肖超群 authored
41
import draggable from 'vuedraggable'
肖超群 authored
42
肖超群 authored
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
export default {
  name: 'ImgTurnPage',
  components: {
    draggable
  },
  data() {
    return {
      description: '图片翻页',
      //数据集
      treeData: [{
        title: '第一页',
        key: '0-0',
        children: [{
          title: '1页',
          key: '0-0-0',
          imgUrl: 'https://static.jeecg.com/upload/test/1_1588149743473.jpg'
        }, {
          title: '2页',
          key: '0-0-1',
          imgUrl: 'https://static.jeecg.com/upload/test/u27356337152749454924fm27gp0_1588149731821.jpg'
        }]
      }, {
        title: '第二页',
        key: '0-1',
        children: [{
          title: '1页',
          key: '0-1-0',
          imgUrl: 'https://static.jeecg.com/upload/test/u24454681402491956848fm27gp0_1588149712663.jpg'
        }, {
          title: '2页',
          key: '0-1-1',
          imgUrl: 'https://static.jeecg.com/upload/test/u8891206113801177793fm27gp0_1588149704459.jpg'
        }]
      }, {
        title: '第三页',
        key: '0-2',
        children: [{
          title: '1页',
          key: '0-2-0',
          imgUrl: 'https://static.jeecg.com/upload/test/1374962_1587621329085.jpg'
        }]
      }],
      selectedKeys: [],
      expandedKeys: [],
      sort: 0,
      imgUrl: '',
      navName: '',
      imgList: [],
    }
  },
  created() {
    this.getImgList();
  },
  methods: {
    getImgList() {
      var count = 0;
      for (var i = 0; i < this.treeData.length; i++) {
        for (var j = 0; j < this.treeData[i].children.length; j++) {
          this.imgList.push({
            key: this.treeData[i].children[j].key,
            pkey: this.treeData[i].key,
            sort: count++,
            imgUrl: this.treeData[i].children[j].imgUrl,
            navName: this.treeData[i].title + "/" + this.treeData[i].children[j].title
          })
        }
      }
      this.setValue(this.imgList[this.sort]);
肖超群 authored
111
    },
肖超群 authored
112
113
114
115
116
117
118
    onSelect(selectedKeys, info) {
      for (var i = 0; i < this.imgList.length; i++) {
        if (this.imgList[i].key === selectedKeys[0]) {
          this.sort = this.imgList[i].sort;
          this.setValue(this.imgList[i]);
          break;
        }
肖超群 authored
119
120
      }
    },
肖超群 authored
121
122
123
124
125
    onExpand(expandedKeys) {
      this.expandedKeys = [];
      if (expandedKeys !== null && expandedKeys !== '') {
        this.expandedKeys[0] = expandedKeys[1];
      }
肖超群 authored
126
    },
肖超群 authored
127
128
129
130
131
    prev() {
      if (this.sort === 0) {
        this.sort = this.imgList.length - 1;
      } else {
        this.sort = this.sort - 1;
肖超群 authored
132
      }
肖超群 authored
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
      this.setValue(this.imgList[this.sort]);
    },
    next() {
      if (this.sort === this.imgList.length - 1) {
        this.sort = 0;
      } else {
        this.sort = this.sort + 1;
      }
      this.setValue(this.imgList[this.sort]);
    },
    // 设置受控节点值
    setValue(value) {
      this.selectedKeys = [];
      this.imgUrl = value.imgUrl;
      this.selectedKeys[0] = value.key;
      this.expandedKeys[0] = value.pkey;
      this.navName = value.navName;
肖超群 authored
150
151
    }
  }
肖超群 authored
152
}
肖超群 authored
153
154
155
156
157
</script>

<style scoped>

</style>