aliyun-video.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <view :class="loadingClass" v-if="!url">{{ loadingText }}</view>
  3. <block v-else>
  4. <video :src="url"></video>
  5. </block>
  6. </template>
  7. <script>
  8. import { handle, request } from "@kasite/uni-app-base";
  9. import { REQUEST_CONFIG } from "@kasite/uni-app-base/config"
  10. export default {
  11. props: {
  12. // 视频ID
  13. videoId: {
  14. type: [String, null],
  15. default: null,
  16. },
  17. },
  18. data() {
  19. return {
  20. url: "",
  21. loadingText: "视频解码中",
  22. loadingClass: "aliyun-video-loading-text",
  23. };
  24. },
  25. methods: {
  26. async doPost(url, data, options) {
  27. let resp = handle.promistHandleNew(await request.doPost(url, data, options));
  28. return handle.catchPromiseNew(resp, () => resp, options);
  29. },
  30. async getVideoUrlByIdasync(id) {
  31. if (!id) return;
  32. const { resp } = await this.doPost(`${REQUEST_CONFIG.BASE_URL}wsgw/article/video/GetVideoUrl/callApiJSON.do`, { ID: id });
  33. const url = resp && resp.length ? resp[0].Url : "";
  34. if (!url) {
  35. this.loadingClass = "aliyun-video-loading-fail-text";
  36. this.loadingText = "视频未完成解码,请刷新页面或稍后再试";
  37. } else {
  38. this.url = url;
  39. }
  40. },
  41. },
  42. mounted() {
  43. this.getVideoUrlByIdasync(this.videoId);
  44. },
  45. };
  46. </script>
  47. <style>
  48. .aliyun-video-loading-fail-text {
  49. color: red;
  50. }
  51. .aliyun-video-loading-text::after {
  52. animation: aliyun-video-loading-dots 2s linear infinite;
  53. content: "";
  54. }
  55. @keyframes aliyun-video-loading-dots {
  56. 0% {
  57. content: ".";
  58. }
  59. 30% {
  60. content: "..";
  61. }
  62. 60% {
  63. content: "...";
  64. }
  65. 90% {
  66. content: "";
  67. }
  68. }
  69. </style>