index.nvue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="page">
  3. <swiper class="swiper" :current="current" @change="onChange" :indicator-dots="false">
  4. <swiper-item v-for="(url, index) in urls" :key="index">
  5. <view class="image-wrapper" @click="close">
  6. <image class="image" :src="url" mode="aspectFit" @click="close" @longpress="onLongPress(index)"></image>
  7. </view>
  8. </swiper-item>
  9. </swiper>
  10. </view>
  11. </template>
  12. <script>
  13. import {
  14. forwardImg,
  15. downloadToAlbum
  16. } from "@/pages_im/util/preview";
  17. export default {
  18. data() {
  19. return {
  20. current: 0,
  21. urls: []
  22. }
  23. },
  24. onLoad(options) {
  25. this.current = parseInt(options.current || 0);
  26. // Get urls from globalData
  27. const app = getApp();
  28. if (app.globalData && app.globalData.previewUrls) {
  29. this.urls = app.globalData.previewUrls;
  30. }
  31. },
  32. methods: {
  33. close() {
  34. uni.navigateBack();
  35. },
  36. onChange(e) {
  37. this.current = e.detail.current;
  38. },
  39. onLongPress(index) {
  40. uni.showActionSheet({
  41. itemList: ["转发图片", "保存图片"],
  42. success: ({
  43. tapIndex
  44. }) => {
  45. const url = this.urls[index];
  46. if (tapIndex === 0) {
  47. // Forward
  48. // Logic copied from preview.js
  49. const isWebResource = /^(http|https):\/\//i.test(url);
  50. if (isWebResource) {
  51. uni.getImageInfo({
  52. src: url,
  53. success: (res) => {
  54. forwardImg(res.path);
  55. },
  56. });
  57. } else {
  58. forwardImg(url);
  59. }
  60. } else {
  61. // Save
  62. downloadToAlbum(url);
  63. }
  64. }
  65. });
  66. }
  67. }
  68. }
  69. </script>
  70. <style scoped>
  71. .page {
  72. position: absolute;
  73. top: 0;
  74. left: 0;
  75. right: 0;
  76. bottom: 0;
  77. background-color: #000000;
  78. }
  79. .swiper {
  80. flex: 1;
  81. }
  82. .image-wrapper {
  83. flex: 1;
  84. justify-content: center;
  85. align-items: center;
  86. }
  87. .image {
  88. width: 750rpx;
  89. flex: 1;
  90. }
  91. </style>