index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="page-wrapper">
  3. <editor v-show="showCom == 'EDITOR'" :linkInputDescImage="pageData.linkInputDescImage" @changeShowCom="changeShowCom" />
  4. <preview v-show="showCom == 'PREVIEW'"
  5. :previewData="previewData"
  6. :screenshotWebsiteData="screenshotWebsiteData"
  7. :showCom="showCom"
  8. :defaultLinkTitle="pageData.defaultLinkTitle"
  9. :certNftProjectId="certNftProjectId"
  10. :hasNft="hasNft"
  11. :resourceInfo="resourceInfo"
  12. :contentTypeConfig="contentTypeConfig"
  13. @publishFinish="publishFinish">
  14. <nft-setting ref="nftSettingDom" @change="changeSetting"></nft-setting>
  15. </preview>
  16. </div>
  17. </template>
  18. <script setup>
  19. import { ref, reactive, watch, defineProps, defineEmits, onMounted } from "vue";
  20. import axios from 'axios';
  21. import { screenshotWebsite, getContentTypeConfig } from "@/http/toolBoxApi";
  22. import editor from '@/view/iframe/publish/tool-box/child/editor.vue'
  23. import preview from '@/view/iframe/publish/tool-box/child/preview.vue'
  24. import Report from "@/log-center/log"
  25. import nftSetting from '@/view/iframe/publish/components/nft-setting.vue'
  26. const props = defineProps({
  27. pageData: {
  28. type: Object,
  29. default: {
  30. linkInputDescImage: '',
  31. defaultLinkTitle: ''
  32. }
  33. },
  34. activePage: {
  35. type: String,
  36. default: 'EDITOR', // EDITOR PREVIEW
  37. },
  38. });
  39. const emits = defineEmits(["onToolBoxPageChange"]);
  40. watch(
  41. () => props.activePage,
  42. (newVal) => {
  43. showCom.value = newVal;
  44. if(newVal == 'PREVIEW') {
  45. hasNft.value = nftSettingDom.value && nftSettingDom.value.nftList.length > 0;
  46. Report.reportLog({
  47. pageSource: Report.pageSource.previewPage,
  48. businessType: Report.businessType.pageView,
  49. }, {
  50. 'type': Report.bizType.ToolBox,
  51. 'post-editor-url': previewData.convertUrl,
  52. 'has-nft': hasNft.value
  53. })
  54. }
  55. },
  56. {
  57. deep: true
  58. }
  59. );
  60. let showCom = ref('EDITOR');
  61. let previewData = reactive({
  62. convertUrl: '',
  63. originUrl: '',
  64. appId: '',
  65. currentApp: {}
  66. })
  67. let certNftProjectId = ref('')
  68. let screenshotWebsiteData = reactive({
  69. url: '',
  70. viewBgImagePath: '',
  71. status: '',
  72. });
  73. let nftSettingDom = ref(null);
  74. let hasNft = ref(false);
  75. let contentTypeConfig = ref({
  76. allowContentTypes: [],
  77. unSupportToast: ''
  78. })
  79. let resourceInfo = ref({
  80. isSet: false,
  81. contentType: '',
  82. statusCode: '',
  83. title: '',
  84. hasTitle: false,
  85. });
  86. const changeShowCom = (params) => {
  87. showCom.value = 'PREVIEW';
  88. previewData.convertUrl = params.convertUrl;
  89. previewData.originUrl = params.originUrl;
  90. previewData.appId = params.appId
  91. previewData.linkImagePath = params.linkImagePath || '';
  92. previewData.currentApp = params.currentApp || {};
  93. screenshotWebsiteData.url = '';
  94. screenshotWebsiteData.viewBgImagePath = '';
  95. screenshotWebsiteData.status = '';
  96. resourceInfo.value = {
  97. isSet: false,
  98. contentType: '',
  99. statusCode: '',
  100. title: '',
  101. hasTitle: false,
  102. };
  103. if(!params.appId || params.appId && !params.linkImagePath) {
  104. screenshotWebsite({
  105. params: {
  106. url: params.convertUrl
  107. }
  108. }).then(res => {
  109. if(showCom.value != 'PREVIEW') {
  110. return;
  111. }
  112. if(res.code == 0 && res.data) {
  113. screenshotWebsiteData.url = res.data.linkImagePath;
  114. screenshotWebsiteData.viewBgImagePath = res.data.viewBgImagePath;
  115. screenshotWebsiteData.status = 1;
  116. } else {
  117. screenshotWebsiteData.status = 1;
  118. }
  119. }).catch(() => {
  120. if(showCom.value != 'PREVIEW') {
  121. return;
  122. }
  123. screenshotWebsiteData.status = 1;
  124. })
  125. }
  126. if(!params.appId) {
  127. getResourceInfo({url:params.convertUrl});
  128. }
  129. emits("onPageChange", {page: showCom.value});
  130. }
  131. const getResourceInfo = ({url}) => {
  132. console.log(url)
  133. axios.get(url).then(res => {
  134. if(res) {
  135. resourceInfo.value.isSet = true;
  136. resourceInfo.value.contentType = res.headers['content-type'];
  137. resourceInfo.value.statusCode = res.request.status;
  138. resourceInfo.value.hasTitle = resourceInfo.value.contentType.indexOf('text/html') > -1 ? true : false;
  139. console.log(res, resourceInfo.value, 'resourceInfo')
  140. let siteTitle = '';
  141. if(resourceInfo.value.hasTitle) {
  142. siteTitle = getTitleByHtmlStr(res.data);
  143. if (!siteTitle) {
  144. let urlObj = new URL(siteUrl.value);
  145. siteTitle = urlObj.hostname;
  146. }
  147. }
  148. resourceInfo.value.title = siteTitle;
  149. }
  150. }).catch(err => {
  151. resourceInfo.value.isSet = true;
  152. })
  153. }
  154. const getTitleByHtmlStr = (str = '') => {
  155. let tag_start = '<title>'
  156. let tag_end = '</title>'
  157. let index1 = str.indexOf(tag_start) + tag_start.length;
  158. let index2 = str.indexOf(tag_end);
  159. if (index1 < tag_start.length || index2 < 0 || index2 < index1) {
  160. return '';
  161. }
  162. return str.substring(index1, index2) || '';
  163. };
  164. const publishFinish = (params) => {
  165. emits("toolBoxPublishFinish", params);
  166. }
  167. const changeSetting = (id = '') => {
  168. certNftProjectId.value = id;
  169. }
  170. onMounted(() => {
  171. getContentTypeConfig({
  172. params: {}
  173. }).then(res => {
  174. if(res.code == 0) {
  175. contentTypeConfig.value = res.data;
  176. }
  177. })
  178. })
  179. </script>
  180. <style lang="scss" scoped>
  181. .page-wrapper {
  182. width: 100%;
  183. height: 100%;
  184. }
  185. </style>