index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <video-preview
  3. v-if="params.type === '2' && fileUrl"
  4. :url="fileUrl"
  5. :is-permi="isPermi"
  6. />
  7. <pdf-preview v-if="params.type === '3' && fileUrl" :url="fileUrl" :is-permi="isPermi" />
  8. <image-preview
  9. v-if="params.type === '1' && form?.waters"
  10. :urls="form?.waters"
  11. :is-permi="isPermi"
  12. />
  13. <permi-mode v-if="!query.isSp" />
  14. <!--<iframe frameborder="0" src="http://localhost:8009/login.html" />-->
  15. <!--<div class="hidden">
  16. <div>pageHide: {{ pageHide }}</div>
  17. <div>visibility: {{ visibility }}</div>
  18. <div>onbeforeLoad: {{ onbeforeLoad }}</div>
  19. </div>-->
  20. </template>
  21. <script lang="ts" setup>
  22. import { usePermission } from "@/Hooks/usePermission/usePermission";
  23. import { previewData } from "@/api/context/context";
  24. import useStatisticalTime from "@/Hooks/useStatisticalTime";
  25. import { onMounted, computed, onUnmounted, ref, watch } from 'vue';
  26. import { useRoute } from "vue-router";
  27. import { ChangeTabEmit } from "@/types/views/database.type";
  28. import useWeChatShare, { shareOptions, shareParams } from "@/Hooks/useWeChatShare";
  29. import { IPreviewForm } from "@/types/api/context.type";
  30. import { myDecrypt } from "@/util/authStorage";
  31. import useStopWindowContext from "@/Hooks/useStopWindowContext";
  32. import createWebShareCard from "@/Hooks/useCreateWebShareCard";
  33. const { query } = useRoute();
  34. const form = ref<IPreviewForm>({
  35. waters: [],
  36. permission: 0,
  37. productId: "0",
  38. fileArchiveList: [],
  39. image: "",
  40. });
  41. //if (!window.localStorage.getItem("pageHide")) {
  42. // window.localStorage.setItem("pageHide", "2");
  43. //}
  44. //if (!window.localStorage.getItem("visibility")) {
  45. // window.localStorage.setItem("visibility", "2");
  46. //}
  47. //if (!window.localStorage.getItem("onbeforeLoad")) {
  48. // window.localStorage.setItem("onbeforeLoad", "2");
  49. //}
  50. //const pageHide = window.localStorage.getItem("pageHide");
  51. //const visibility = window.localStorage.getItem("visibility");
  52. //const onbeforeLoad = window.localStorage.getItem("onbeforeLoad");
  53. const fileUrl = ref<string>();
  54. const { isPermi, PermiMode } = usePermission(form.value?.permission! as number); // 权限hook
  55. const params = computed<shareParams & { url: string }>(
  56. () =>
  57. (({
  58. type: query?.t as ChangeTabEmit,
  59. userId: query?.uid as string,
  60. id: query?.id as string,
  61. spId: query?.spId as string,
  62. imageUrl: form.value?.image,
  63. url: query?.url as string,
  64. } as unknown) as shareParams & { url: string })
  65. );
  66. watch(() => params.value.url, () => {
  67. fileUrl.value = params.value.url
  68. })
  69. const getPreviewData = async () => {
  70. const { data } = await previewData({
  71. userId: (query.uid as string) || "0",
  72. id: query.id as string,
  73. type: query.t as ChangeTabEmit,
  74. });
  75. const DcreptoList = {
  76. ...data,
  77. ...{ waters: myDecrypt(data?.waters as string[]) },
  78. } as IPreviewForm;
  79. form.value = DcreptoList;
  80. fileUrl.value = form.value.waters[0]?.split("?")[0];
  81. console.log(form.value.waters);
  82. };
  83. const statistical = useStatisticalTime((time) => {
  84. const t = Math.floor(time / 1000);
  85. console.log("时长为:", t, Math.floor(time / 1000));
  86. localStorage.setItem("spentTime", t.toString());
  87. const f = {
  88. productArchiveId: params.value.id,
  89. headUserId: params.value.spId,
  90. accessClient: "0",
  91. pagePath: location.href,
  92. accessDuration: t * 1000,
  93. pageType: params.value.type === "1" ? "70" : params.value.type === "2" ? "71" : "69",
  94. pageLabel: "内容库预览",
  95. userId: params.value.userId || "0",
  96. productId: form.value?.productId || "0",
  97. shopId: "" || "0",
  98. behaviorType: "1",
  99. };
  100. fetch(
  101. `
  102. ${import.meta.env.VITE_BASE_URL}/user/record/Statistics?accessClient=${
  103. f.accessClient
  104. }&userId=${f.userId}&pagePath=${f.pagePath}&productId=${f.productId}&accessDuration=${
  105. f.accessDuration
  106. }&pageLabel=${f.pageLabel}&behaviorType=${f.behaviorType}&shopId=${
  107. f.shopId
  108. }&pageType=${f.pageType}
  109. `,
  110. {
  111. method: "GET",
  112. headers: {
  113. "Content-Type": "application/x-www-form-urlencoded",
  114. },
  115. keepalive: true,
  116. }
  117. )
  118. .then((res) => res.json())
  119. .then(() => {
  120. console.log("时间推送记录成功");
  121. });
  122. });
  123. useStopWindowContext(params.value.userId!);
  124. onUnmounted(() => {
  125. statistical();
  126. });
  127. onMounted(() => {
  128. const obj = shareOptions.filter(e => e.type === params.value.type)[0]
  129. if (!params.value.url) {
  130. getPreviewData();
  131. }
  132. useWeChatShare(params.value);
  133. createWebShareCard({
  134. title: obj.text,
  135. description: obj.text,
  136. image: params.value.imageUrl!,
  137. });
  138. });
  139. </script>
  140. <style scoped lang="scss">
  141. body {
  142. user-select: none !important;
  143. }
  144. .hidden {
  145. width: 100vw;
  146. height: 100vh;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. flex-direction: column;
  151. }
  152. @media print {
  153. .no-print {
  154. display: none !important;
  155. }
  156. }
  157. </style>