preview-file.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view>
  3. <template v-if="isPic">
  4. <view class="file-name" v-if="showName">{{ name }}</view>
  5. <image class="img" @click="previewImg" :src="src" mode="aspectFill"></image>
  6. </template>
  7. <view class="file-name" v-if="!isPic" @click="previewFile">{{ name }}</view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: ["name", "src", "showName"],
  13. computed: {
  14. isPic() {
  15. var reg = /\.(png|jpg|gif|jpeg|webp)$/;
  16. return reg.test(this.name);
  17. },
  18. },
  19. methods: {
  20. previewImg() {
  21. uni.previewImage({
  22. current: 0,
  23. urls: [this.src],
  24. });
  25. },
  26. previewFile() {
  27. console.log(this.src);
  28. uni.navigateTo({
  29. url: '/pages/preview/preview?fileSrc=' + this.src
  30. })
  31. // uni.showLoading({
  32. // title: "下载中...",
  33. // mask: true,
  34. // });
  35. // uni.downloadFile({
  36. // url: this.src,
  37. // success: (res) => {
  38. // if (res.statusCode === 200) {
  39. // uni.openDocument({
  40. // filePath: res.tempFilePath,
  41. // // filePath: escape(res.tempFilePath),
  42. // // 如果文件名包含中文,建议使用escape(res.tempFilePath)转码,防止ios和安卓客户端导致的差异
  43. // success: function(res) {
  44. // console.log("打开文档成功");
  45. // },
  46. // });
  47. // }
  48. // },
  49. // complete: () => {
  50. // uni.hideLoading();
  51. // },
  52. // });
  53. },
  54. },
  55. };
  56. </script>
  57. <style lang="scss" scoped>
  58. .img {
  59. width: 100rpx;
  60. height: 100rpx;
  61. }
  62. .file-name {
  63. font-size: 30rpx;
  64. font-weight: bold;
  65. color: #2f42ca;
  66. text-decoration: underline;
  67. }
  68. </style>