index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. viewBgImageFullPath: '',
  72. status: '',
  73. });
  74. let nftSettingDom = ref(null);
  75. let hasNft = ref(false);
  76. let contentTypeConfig = ref({
  77. allowContentTypes: [],
  78. unSupportToast: '',
  79. contentTypeTitleMap: {}
  80. })
  81. let resourceInfo = ref({
  82. isSet: false,
  83. contentType: '',
  84. statusCode: '',
  85. title: '',
  86. hasTitle: false,
  87. loadSuccess: false
  88. });
  89. const changeShowCom = (params) => {
  90. showCom.value = 'PREVIEW';
  91. previewData.convertUrl = params.convertUrl;
  92. previewData.originUrl = params.originUrl;
  93. previewData.appId = params.appId
  94. previewData.linkImagePath = params.linkImagePath || '';
  95. previewData.currentApp = params.currentApp || {};
  96. screenshotWebsiteData.url = '';
  97. screenshotWebsiteData.viewBgImagePath = '';
  98. screenshotWebsiteData.viewBgImageFullPath = '';
  99. screenshotWebsiteData.status = '';
  100. resourceInfo.value = {
  101. isSet: false,
  102. contentType: '',
  103. statusCode: '',
  104. title: '',
  105. hasTitle: false,
  106. loadSuccess: false
  107. };
  108. if(!params.appId || params.appId && !params.linkImagePath) {
  109. screenshotWebsite({
  110. params: {
  111. url: params.convertUrl
  112. }
  113. }).then(res => {
  114. if(showCom.value != 'PREVIEW') {
  115. return;
  116. }
  117. if(res.code == 0 && res.data) {
  118. screenshotWebsiteData.url = res.data.linkImagePath;
  119. screenshotWebsiteData.viewBgImagePath = res.data.viewBgImagePath;
  120. screenshotWebsiteData.viewBgImageFullPath = res.data.viewBgImageFullPath;
  121. screenshotWebsiteData.status = 1;
  122. } else {
  123. screenshotWebsiteData.status = 1;
  124. }
  125. }).catch(() => {
  126. if(showCom.value != 'PREVIEW') {
  127. return;
  128. }
  129. screenshotWebsiteData.status = 1;
  130. })
  131. }
  132. if(!params.appId) {
  133. getResourceInfo({url:params.convertUrl});
  134. }
  135. emits("onPageChange", {page: showCom.value});
  136. }
  137. const getResourceInfo = ({url}) => {
  138. axios.get(url).then(res => {
  139. if(res) {
  140. resourceInfo.value.isSet = true;
  141. resourceInfo.value.contentType = res.headers['content-type'];
  142. resourceInfo.value.statusCode = res.request.status;
  143. resourceInfo.value.hasTitle = resourceInfo.value.contentType.indexOf('text/html') > -1 ? true : false;
  144. resourceInfo.value.loadSuccess = true;
  145. let siteTitle = '';
  146. if(resourceInfo.value.hasTitle) {
  147. siteTitle = getTitleByHtmlStr(res.data);
  148. if (!siteTitle) {
  149. let urlObj = new URL(url);
  150. siteTitle = urlObj.hostname;
  151. }
  152. }
  153. resourceInfo.value.title = siteTitle;
  154. }
  155. }).catch(err => {
  156. resourceInfo.value.isSet = true;
  157. })
  158. }
  159. const getTitleByHtmlStr = (str = '') => {
  160. let tag_start = '<title>'
  161. let tag_end = '</title>'
  162. let index1 = str.indexOf(tag_start) + tag_start.length;
  163. let index2 = str.indexOf(tag_end);
  164. if (index1 < tag_start.length || index2 < 0 || index2 < index1) {
  165. return '';
  166. }
  167. return str.substring(index1, index2) || '';
  168. };
  169. const publishFinish = (params) => {
  170. emits("toolBoxPublishFinish", params);
  171. }
  172. const changeSetting = (id = '') => {
  173. certNftProjectId.value = id;
  174. }
  175. onMounted(() => {
  176. getContentTypeConfig({
  177. params: {}
  178. }).then(res => {
  179. if(res.code == 0) {
  180. contentTypeConfig.value = res.data;
  181. }
  182. })
  183. })
  184. </script>
  185. <style lang="scss" scoped>
  186. .page-wrapper {
  187. width: 100%;
  188. height: 100%;
  189. }
  190. </style>