index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="preview_video_container">
  3. <video :poster="snapshotUrl" autoplay class="video_player" :src="previewVideoUrl"></video>
  4. <view class="play_action_bar">
  5. <u-icon @click="back" size="24" color="#fff" name="close-circle"></u-icon>
  6. <u-icon v-if="!downloaded" @click="download" size="24" color="#fff" name="download"></u-icon>
  7. </view>
  8. <u-toast ref="uToast"></u-toast>
  9. </view>
  10. </template>
  11. <script>
  12. import { mapGetters } from "vuex";
  13. export default {
  14. name: "",
  15. components: {},
  16. data() {
  17. return {
  18. clientMsgID: "",
  19. previewVideoUrl: "",
  20. snapshotUrl: "",
  21. };
  22. },
  23. computed: {
  24. ...mapGetters([
  25. "storeCacheMap"
  26. ]),
  27. downloaded(){
  28. return !this.previewVideoUrl.startsWith("http")
  29. },
  30. currentFileIsDownloading() {
  31. return this.storeCacheMap[this.clientMsgID]?.state === "pending";
  32. },
  33. },
  34. watch: {
  35. storeCacheMap: {
  36. async handler(newVal) {
  37. const path = newVal[this.clientMsgID]?.path;
  38. if (path){
  39. this.previewVideoUrl = path
  40. }
  41. },
  42. },
  43. },
  44. onLoad(options) {
  45. this.previewVideoUrl = options.previewVideoUrl;
  46. this.snapshotUrl = options.snapshotUrl || ''
  47. this.clientMsgID = options.clientMsgID || ''
  48. },
  49. methods: {
  50. back() {
  51. uni.navigateBack();
  52. },
  53. download() {
  54. if (this.currentFileIsDownloading) return;
  55. uni.showToast({
  56. title: '下载中',
  57. icon: 'none'
  58. })
  59. this.$store.dispatch("user/addCacheTask", {
  60. key: this.clientMsgID,
  61. url: this.previewVideoUrl,
  62. });
  63. },
  64. },
  65. };
  66. </script>
  67. <style lang="scss">
  68. .preview_video_container {
  69. @include colBox(false);
  70. height: 100vh;
  71. background-color: #000;
  72. .video_player {
  73. flex: 1;
  74. // height: 80%;
  75. width: 100%;
  76. // margin-top: 50%;
  77. }
  78. .play_action_bar {
  79. padding: 24rpx 48rpx 48rpx;
  80. // margin-top: 24rpx;
  81. display: flex;
  82. justify-content: space-between;
  83. }
  84. }
  85. </style>