preview-file.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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: this.src
  30. // })
  31. location.href = this.src
  32. // uni.showLoading({
  33. // title: "下载中...",
  34. // mask: true,
  35. // });
  36. // uni.downloadFile({
  37. // url: this.src,
  38. // success: (res) => {
  39. // if (res.statusCode === 200) {
  40. // uni.openDocument({
  41. // filePath: res.tempFilePath,
  42. // // filePath: escape(res.tempFilePath),
  43. // // 如果文件名包含中文,建议使用escape(res.tempFilePath)转码,防止ios和安卓客户端导致的差异
  44. // success: function(res) {
  45. // console.log("打开文档成功");
  46. // },
  47. // });
  48. // }
  49. // },
  50. // complete: () => {
  51. // uni.hideLoading();
  52. // },
  53. // });
  54. },
  55. },
  56. };
  57. </script>
  58. <style lang="scss" scoped>
  59. .img {
  60. width: 100rpx;
  61. height: 100rpx;
  62. }
  63. .file-name {
  64. font-size: 30rpx;
  65. font-weight: bold;
  66. color: #2f42ca;
  67. text-decoration: underline;
  68. }
  69. </style>