listimage.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="container">
  3. <view style="width: 100%;height: 200rpx;padding: 20rpx;">
  4. <view style="font-size: 24px;">家族合影</view>
  5. <view style="font-size: 16px;color: #8f8f94;">134张/照片</view>
  6. </view>
  7. <view v-for="(item, index) in images" :key="index" style="margin-bottom: 20rpx;">
  8. <text style="margin: 1.6%;font-size: 32rpx;">{{ item.time }}</text>
  9. <view :data-index="index">
  10. <view style="width: 30%;height: 250rpx;margin: 1.6%;float: left;" :key="indexs" v-for="(items, indexs) in item.list">
  11. <image style="width: 100%;height: 100%;" :src="items.imgurl" :data-src="items.imgurl" @tap="previewOpen"></image>
  12. </view>
  13. </view>
  14. </view>
  15. <previewImage ref="previewImage" :opacity="0.8" :imgs="imgs" :descs="descs" @longPress="longPress"></previewImage>
  16. </view>
  17. </template>
  18. <script>
  19. import previewImage from '@/components/kxj-previewImage/kxj-previewImage.vue'; //引用插件
  20. export default {
  21. components: { previewImage }, //注册插件
  22. data() {
  23. return {
  24. images: [
  25. {
  26. time: '2020/8/1',
  27. list: [
  28. {
  29. imgurl: '../../../static/img/family/listimage/1.jpg',
  30. descs: '合照1'
  31. },{
  32. imgurl: '../../../static/img/family/listimage/2.jpg',
  33. descs: '合照2'
  34. },{
  35. imgurl: '../../../static/img/family/listimage/3.jpg',
  36. descs: '合照3'
  37. }
  38. ]
  39. },{
  40. time: '2020/8/2',
  41. list: [
  42. {
  43. imgurl: '../../../static/img/family/listimage/1.jpg',
  44. descs: '合照1'
  45. },{
  46. imgurl: '../../../static/img/family/listimage/2.jpg',
  47. descs: '合照2'
  48. },{
  49. imgurl: '../../../static/img/family/listimage/3.jpg',
  50. descs: '合照3'
  51. }
  52. ]
  53. }
  54. ],
  55. imgs:[],
  56. descs: []
  57. };
  58. },
  59. onLoad() {
  60. this.staticList();
  61. },
  62. onNavigationBarButtonTap(e) {
  63. uni.navigateTo({
  64. url: '/pages/family/listimage/uploadimg/uploadimg'
  65. });
  66. },
  67. methods: {
  68. staticList(){
  69. const data=this.images[0].list;
  70. const data_img=[];
  71. const data_desc=[];
  72. for(var item of data){
  73. data_img.push(item.imgurl);
  74. data_desc.push(item.descs);
  75. }
  76. this.imgs=data_img;
  77. this.descs=data_desc;
  78. },
  79. //打开预览e
  80. previewOpen(e) {
  81. var param = e.currentTarget.dataset.src;
  82. console.log(e);
  83. this.$refs.previewImage.open(param); // 传入当前选中的图片地址或序号
  84. return; //如需测试和uni原生预览差别可注释这两行
  85. //以下是效果对比相关
  86. var _this = this;
  87. uni.showModal({
  88. title: '请选择',
  89. content: '请选择使用uni原生图片预览或非原生自定义的图片预览。',
  90. cancelText: 'uni',
  91. confirmText: '自定义',
  92. success: function(res) {
  93. if (res.confirm) {
  94. _this.$refs.previewImage.open(param); // 传入当前选中的图片地址或序号
  95. } else if (res.cancel) {
  96. uni.previewImage({
  97. current: param,
  98. urls: _this.imgs
  99. });
  100. }
  101. }
  102. });
  103. },
  104. //长按事件
  105. longPress(data) {
  106. console.log(data);
  107. uni.showModal({
  108. showCancel: false,
  109. title: '长按事件',
  110. content: '已触发长按事件,你可以在这里做更多',
  111. success: showResult => {
  112. }
  113. });
  114. }
  115. }
  116. };
  117. </script>
  118. <style>
  119. page {
  120. background-color: #f7f7f7;
  121. }
  122. .container {
  123. padding-bottom: 110rpx;
  124. width: 100%;
  125. }
  126. .text-area {
  127. display: flex;
  128. justify-content: center;
  129. }
  130. .title {
  131. font-size: 26rpx;
  132. color: #999999;
  133. }
  134. </style>