index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. @publishFinish="publishFinish" />
  10. </div>
  11. </template>
  12. <script setup>
  13. import { ref, reactive, watch, defineProps, defineEmits } from "vue";
  14. import { screenshotWebsite } from "@/http/toolBoxApi";
  15. import editor from '@/view/iframe/publish/tool-box/child/editor.vue'
  16. import preview from '@/view/iframe/publish/tool-box/child/preview.vue'
  17. const props = defineProps({
  18. pageData: {
  19. type: Object,
  20. default: {
  21. linkInputDescImage: '',
  22. defaultLinkTitle: ''
  23. }
  24. },
  25. activePage: {
  26. type: String,
  27. default: 'EDITOR', // EDITOR PREVIEW
  28. },
  29. });
  30. const emits = defineEmits(["onToolBoxPageChange"]);
  31. watch(
  32. () => props.activePage,
  33. (newVal) => {
  34. showCom.value = newVal;
  35. },
  36. {
  37. deep: true
  38. }
  39. );
  40. let showCom = ref('EDITOR');
  41. let previewData = reactive({
  42. convertUrl: '',
  43. originUrl: '',
  44. appId: '',
  45. currentApp: {}
  46. })
  47. let screenshotWebsiteData = reactive({
  48. url: '',
  49. status: '',
  50. });
  51. const changeShowCom = (params) => {
  52. showCom.value = 'PREVIEW';
  53. previewData.convertUrl = params.convertUrl;
  54. previewData.originUrl = params.originUrl;
  55. previewData.appId = params.appId
  56. previewData.linkImagePath = params.linkImagePath || '';
  57. previewData.currentApp = params.currentApp || {};
  58. screenshotWebsiteData.url = '';
  59. screenshotWebsiteData.status = '';
  60. if(!params.appId || params.appId && !params.linkImagePath) {
  61. screenshotWebsite({
  62. params: {
  63. url: params.convertUrl
  64. }
  65. }).then(res => {
  66. if(showCom.value != 'PREVIEW') {
  67. return;
  68. }
  69. if(res.code == 0) {
  70. screenshotWebsiteData.url = res.data;
  71. screenshotWebsiteData.status = 1;
  72. } else {
  73. screenshotWebsiteData.status = 1;
  74. }
  75. }).catch(() => {
  76. if(showCom.value != 'PREVIEW') {
  77. return;
  78. }
  79. screenshotWebsiteData.status = 1;
  80. })
  81. }
  82. emits("onPageChange", {page: showCom.value});
  83. }
  84. const publishFinish = (params) => {
  85. emits("toolBoxPublishFinish", params);
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .page-wrapper {
  90. width: 100%;
  91. height: 100%;
  92. }
  93. </style>