zy_detail.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="zyDetailContent">
  3. <div class="top flex justify-between items-center w-full p-1">
  4. <van-icon name="arrow-left" color="#fff" size="16" @click="onClickLeft" />
  5. </div>
  6. <div class="look px-2" v-if="suffix!='doc' && suffix!='docx'">当前观看人数:{{detailInfo.kf_view_num}}</div>
  7. <div class="look px-2" v-else @click="download">
  8. <van-icon name="down" /> 点击下载
  9. </div>
  10. <div v-if="suffix=='mp4'" class="videoDiv">
  11. <div class="aliPlayerShow" id="J_prismPlayer"></div>
  12. </div>
  13. <audio v-else-if="suffix=='mp3'" ref="urlResouce" controls :src="commonUrl">
  14. <source :src="commonUrl" type="audio/mp3">
  15. </audio>
  16. <div v-else-if="suffix=='pdf'" style="height: calc(100% - 60px);">
  17. <iframe :src="commonUrl" frameborder="0" width="100%" height="100%"></iframe>
  18. </div>
  19. <div v-else-if="suffix=='doc' || suffix=='docx'" style="height: 100px;line-height: 140px;text-align: center;font-size: 12px;color: #ccc;">
  20. 当前文件暂不支持预览
  21. </div>
  22. <div v-else style="height: calc(100% - 60px);">
  23. <iframe :src="(detailInfo.file_preview || commonUrl)" frameborder="0" width="100%" height="100%"></iframe>
  24. </div>
  25. <div class="flex justify-between items-center px-3 mt-2">
  26. <div style="font-size: 15px;">{{detailInfo.kf_name}}</div>
  27. <div class="flex space-x-4 tip">
  28. <div @click="handleFinger">
  29. <van-icon :name="detailInfo.is_like==0 ? 'good-job-o' : 'good-job'" />
  30. <span>{{detailInfo.kf_like_num}}</span>
  31. </div>
  32. <div @click="handleLoveIcon">
  33. <van-icon :name="detailInfo.is_fav==0 ? 'like-o' : 'like'" />
  34. <span>{{detailInfo.kf_fav_num}}</span>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script setup>
  41. import { getFullUrl } from '@/utils/helper';
  42. import { files_detail, likeApi_add, likeApi_del, collectApi_add, collectApi_del } from "./api.js";
  43. import { useRouter } from 'vue-router';
  44. const router = useRouter();
  45. const parentId = ref(router.currentRoute.value.params.id);
  46. const parentKkId = ref("");
  47. const detailInfo = ref({});
  48. const suffix = ref("mp4");
  49. const detailLoad = ref(false);
  50. const commonUrl = ref("");
  51. const sourceUrl = ref("");
  52. const player = ref("");
  53. const onClickLeft = () => history.back();
  54. initDetailData();
  55. function initDetailData() {
  56. detailLoad.value = true;
  57. files_detail({ kf_id: parentId.value }).then((res) => {
  58. if (res.code == 1) {
  59. detailInfo.value = res.data.one_info;
  60. parentKkId.value = detailInfo.value.kk_id;
  61. commonUrl.value = getFullUrl(res.data.one_info.kf_path);
  62. suffix.value = res.data.one_info.kf_path.substr(res.data.one_info.kf_path.lastIndexOf(".") + 1);
  63. // detailLoad.value = false;
  64. // console.log(detailInfo.value)
  65. // let tempD = res.data.one_info.kf_path;
  66. // this.typeKind = tempD.substr(tempD.lastIndexOf(".") + 1);
  67. // this.$refs.urlResouce.src = res.data.one_info.kf_path;
  68. //示例设置清晰度为超清和高清的地址("OD": "<原画URL>","FD": "<流畅URL>","LD":"<标清URL>","SD": "<高清URL>","HD": "<超清URL>","2K": "<2K URL>","4K": "<4K URL>")
  69. // source:'{"HD":"http://******/player/hdexample.mp4","SD":"http://******/player/sdexample.mp4"}'
  70. sourceUrl.value = { "OD": detailInfo.value.kf_path_od, "FD": detailInfo.value.kf_path_fd, "LD": detailInfo.value.kf_path_ld };
  71. let stringSourceUrl = JSON.stringify(sourceUrl.value)
  72. // 初始换aliplayer
  73. player.value = new Aliplayer({
  74. id: 'J_prismPlayer',
  75. source: stringSourceUrl,
  76. language: "zh-cn",
  77. width: '100%', //容器的大小
  78. height: '100%', //容器的大小
  79. isLive: false,//是不是直播
  80. preload: true,//播放器自动加载
  81. autoplay: true,//是否自动播放
  82. qualitySort: 'asc',//从小到大排序
  83. }, function (player) {
  84. console.log('播发器创建完成~')
  85. });
  86. if (localStorage.getItem('cur_time_' + parentKkId.value)) {
  87. player.value.seek(localStorage.getItem('cur_time_' + parentKkId.value));
  88. }
  89. var timer = setInterval(() => {
  90. var curTime = parseInt(player.value.getCurrentTime());
  91. if (player.value && player.value.getStatus() == "playing") {
  92. localStorage.setItem('cur_time_' + parentKkId.value, curTime);
  93. }
  94. }, 30000);
  95. // this.fingerNum = res.data.one_info.kf_like_num; //点赞数
  96. // this.fingerSwitch = res.data.one_info.is_like; //0:关 1:开
  97. // this.loveNum = res.data.one_info.kf_fav_num; //关注
  98. // this.loveSwitch = res.data.one_info.is_fav; //0:关 1:开
  99. }
  100. });
  101. }
  102. const download = () => {
  103. window.open(commonUrl.value);
  104. }
  105. const handleFinger = () => {
  106. if (detailInfo.value.is_like == 1) {//0:关 1:开
  107. //去掉赞
  108. let transObj = {
  109. kf_id: parentId.value,
  110. };
  111. likeApi_del(transObj)
  112. .then((res) => {
  113. if (res.code == "1") {
  114. detailInfo.value.kf_like_num--;
  115. detailInfo.value.is_like = 0;
  116. showSuccessToast(res.msg);
  117. } else {
  118. showFailToast(res.msg);
  119. }
  120. })
  121. .catch((error) => {
  122. console.log(error);
  123. });
  124. } else {
  125. let transObj = {
  126. kczy_files_like: {
  127. kf_id: parentId.value,
  128. kt_id: parentKkId.value,
  129. },
  130. };
  131. likeApi_add(transObj)
  132. .then((res) => {
  133. if (res.code == "1") {
  134. detailInfo.value.kf_like_num++;
  135. detailInfo.value.is_like = 1;
  136. showSuccessToast(res.msg);
  137. } else {
  138. showFailToast(res.msg);
  139. }
  140. })
  141. .catch((error) => {
  142. console.log(error);
  143. });
  144. }
  145. }
  146. const handleLoveIcon = () => {
  147. if (detailInfo.value.is_fav == 1) {
  148. //去掉收藏
  149. let transObj = {
  150. kf_id: parentId.value,
  151. };
  152. collectApi_del(transObj)
  153. .then((res) => {
  154. if (res.code == "1") {
  155. detailInfo.value.kf_fav_num--;
  156. detailInfo.value.is_fav = 0;
  157. showSuccessToast(res.msg);
  158. } else {
  159. showFailToast(res.msg);
  160. }
  161. })
  162. .catch((error) => {
  163. console.log(error);
  164. });
  165. } else {
  166. let transObj = {
  167. kczy_files_fav: {
  168. kf_id: parentId.value,
  169. kt_id: parentKkId.value,
  170. },
  171. };
  172. collectApi_add(transObj)
  173. .then((res) => {
  174. if (res.code == "1") {
  175. detailInfo.value.kf_fav_num++;
  176. detailInfo.value.is_fav = 1;
  177. showSuccessToast(res.msg);
  178. } else {
  179. showFailToast(res.msg);
  180. }
  181. })
  182. .catch((error) => {
  183. console.log(error);
  184. });
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .zyDetailContent {
  190. height: 100vh;
  191. background: #fcfeff;
  192. .top {
  193. position: absolute;
  194. z-index: 10;
  195. background: linear-gradient(180deg, rgba(0, 0, 0, 0.69), rgba(0, 0, 0, 0));
  196. color: #fff;
  197. font-size: 12px;
  198. }
  199. .look {
  200. background: rgba($color: #050026, $alpha: 0.5);
  201. border-radius: 5px;
  202. line-height: 22px;
  203. position: absolute;
  204. z-index: 10;
  205. top: 24px;
  206. right: 10px;
  207. color: #fff;
  208. font-size: 12px;
  209. }
  210. .videoDiv {
  211. height: 220px;
  212. }
  213. video {
  214. width: 100%;
  215. }
  216. .tip {
  217. color: #00a3ff;
  218. font-size: 12px;
  219. white-space: nowrap;
  220. }
  221. }
  222. </style>