f1c0abad058654a16942c4e946f26d832521ba08.svn-base 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <a-card title="树形结构图片翻页查看" style="min-width: 800px;overflow-x:auto ">
  3. <a-row>
  4. <!-- 左侧文件树 -->
  5. <a-col :span="5">
  6. <a-tree
  7. showLine
  8. :treeData="treeData"
  9. :expandedKeys="[expandedKeys[0]]"
  10. :selectedKeys="selectedKeys"
  11. :style="{'height':'500px','border-right':'2px solid #c1c1c1','overflow-y':'auto'}"
  12. @expand="onExpand"
  13. @select="this.onSelect"
  14. >
  15. </a-tree>
  16. </a-col>
  17. <!--右侧缩略图-->
  18. <a-col :span="19">
  19. <a-row style="margin-top: 10px">
  20. <a-col :span="24" style="padding-left: 2%;margin-bottom: 10px">
  21. <a-button @click="prev" type="primary"><a-icon type="left" />上一页</a-button>
  22. <a-button @click="next" type="primary" style="margin-left: 8px">下一页<a-icon type="right" /></a-button>
  23. <span style="margin-left: 15%;font-weight: bolder">{{ navName }}</span>
  24. </a-col>
  25. <a-col :span="24" style="padding-left: 2%;">
  26. <img :src="imgUrl" preview>
  27. </a-col>
  28. </a-row>
  29. </a-col>
  30. </a-row>
  31. </a-card>
  32. </template>
  33. <script>
  34. import draggable from 'vuedraggable'
  35. export default {
  36. name: 'ImgTurnPage',
  37. components:{
  38. draggable
  39. },
  40. data() {
  41. return {
  42. description: '图片翻页',
  43. //数据集
  44. treeData: [{
  45. title: '第一页',
  46. key: '0-0',
  47. children: [{
  48. title: '1页',
  49. key: '0-0-0',
  50. imgUrl:'https://static.jeecg.com/upload/test/1_1588149743473.jpg'
  51. }, {
  52. title: '2页',
  53. key: '0-0-1',
  54. imgUrl:'https://static.jeecg.com/upload/test/u27356337152749454924fm27gp0_1588149731821.jpg'
  55. }]
  56. },{
  57. title: '第二页',
  58. key: '0-1',
  59. children: [{
  60. title: '1页',
  61. key: '0-1-0',
  62. imgUrl:'https://static.jeecg.com/upload/test/u24454681402491956848fm27gp0_1588149712663.jpg'
  63. }, {
  64. title: '2页',
  65. key: '0-1-1',
  66. imgUrl:'https://static.jeecg.com/upload/test/u8891206113801177793fm27gp0_1588149704459.jpg'
  67. }]
  68. },{
  69. title: '第三页',
  70. key: '0-2',
  71. children: [{
  72. title: '1页',
  73. key: '0-2-0',
  74. imgUrl:'https://static.jeecg.com/upload/test/1374962_1587621329085.jpg'
  75. }]
  76. }],
  77. selectedKeys:[],
  78. expandedKeys:[],
  79. sort:0,
  80. imgUrl:'',
  81. navName:'',
  82. imgList:[],
  83. }
  84. },
  85. created(){
  86. this.getImgList();
  87. },
  88. methods: {
  89. getImgList(){
  90. var count = 0;
  91. for(var i=0;i<this.treeData.length;i++){
  92. for(var j=0;j<this.treeData[i].children.length;j++){
  93. this.imgList.push({key:this.treeData[i].children[j].key,pkey:this.treeData[i].key,sort:count++,
  94. imgUrl:this.treeData[i].children[j].imgUrl,navName:this.treeData[i].title+"/"+this.treeData[i].children[j].title})
  95. }
  96. }
  97. this.setValue(this.imgList[this.sort]);
  98. },
  99. onSelect (selectedKeys, info) {
  100. for(var i=0;i<this.imgList.length;i++){
  101. if(this.imgList[i].key === selectedKeys[0]){
  102. this.sort = this.imgList[i].sort;
  103. this.setValue(this.imgList[i]);
  104. break;
  105. }
  106. }
  107. },
  108. onExpand (expandedKeys) {
  109. this.expandedKeys = [];
  110. if(expandedKeys !== null && expandedKeys !== ''){
  111. this.expandedKeys[0] = expandedKeys[1];
  112. }
  113. },
  114. prev(){
  115. if(this.sort === 0){
  116. this.sort = this.imgList.length-1;
  117. }else{
  118. this.sort = this.sort - 1;
  119. }
  120. this.setValue(this.imgList[this.sort]);
  121. },
  122. next(){
  123. if(this.sort === this.imgList.length-1){
  124. this.sort = 0;
  125. }else{
  126. this.sort = this.sort + 1;
  127. }
  128. this.setValue(this.imgList[this.sort]);
  129. },
  130. // 设置受控节点值
  131. setValue(value){
  132. this.selectedKeys = [];
  133. this.imgUrl = value.imgUrl;
  134. this.selectedKeys[0] = value.key;
  135. this.expandedKeys[0] = value.pkey;
  136. this.navName = value.navName;
  137. }
  138. }
  139. }
  140. </script>
  141. <style scoped>
  142. </style>