app.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="hui-flex border-box ai-website">
  3. <div class="website-form hui-flex">
  4. <div class="website-form-title">
  5. 网站信息
  6. </div>
  7. <div class="hui-flex-box">
  8. <ai-flow-chat @previewWebSite="previewWebSite"></ai-flow-chat>
  9. </div>
  10. </div>
  11. <div class="website-show hui-flex">
  12. <div class="website-form-title">
  13. <span>网站展示</span>
  14. <website-upload ref="upload" v-show="false" @reload="successFunc">
  15. </website-upload>
  16. {{websiteUrl}}
  17. </div>
  18. <div class="hui-flex-box">
  19. <div class="no-empty" v-if="!websiteUrl">
  20. <el-empty description="请先预览网站"></el-empty>
  21. </div>
  22. <div class="html-box" v-else v-loading="loading">
  23. <iframe ref="iframeDom" :src="websiteUrl" width="100%" height="100%" frameborder="0"
  24. @load="onloadIframe">
  25. </iframe>
  26. </div>
  27. </div>
  28. <div class="hui-drawer-submit">
  29. <el-button size="mini" :disabled="!websiteUrl" @click="cancelIframe" v-if="iframeEdit">取消</el-button>
  30. <el-button type="primary" size="mini" :disabled="!websiteUrl" @click="saveIframe" v-if="iframeEdit">
  31. 保存
  32. </el-button>
  33. <el-button type="primary" size="mini" :disabled="!websiteUrl" @click="editIframe" v-if="!iframeEdit">
  34. 编辑
  35. </el-button>
  36. <el-button type="primary" size="mini" :disabled="!websiteUrl" @click="submit" v-if="!iframeEdit">
  37. 发布
  38. </el-button>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import {
  45. getAIData,
  46. saveHtmlData,
  47. getHtmlData,
  48. updateHtmlData
  49. } from '@/api/ai'
  50. import aiFlowChat from '@/components/work/common/aiFlowChat.vue'
  51. import websiteUpload from '@/components/work/common/websiteUpload.vue'
  52. import config from '@/config'
  53. export default {
  54. components: {
  55. aiFlowChat,
  56. websiteUpload
  57. },
  58. data() {
  59. return {
  60. websiteUrl: '',
  61. loading: false,
  62. simpleUUID: '',
  63. iframeEdit: false,
  64. imageELement: null,
  65. htmlData: {}
  66. }
  67. },
  68. mounted() {},
  69. methods: {
  70. async previewWebSite(html, simpleUUID) {
  71. if (this.simpleUUID === simpleUUID) return;
  72. this.iframeEdit = false;
  73. this.loading = true;
  74. this.simpleUUID = simpleUUID;
  75. let htmlData = await getHtmlData({
  76. simpleUUID: simpleUUID
  77. })
  78. if (!htmlData.state) return this.websiteUrl = '';
  79. if (htmlData.data.length > 0) {
  80. this.htmlData = htmlData.data[0];
  81. return this.websiteUrl = `${config.baseURL}/api/enterprise/${simpleUUID}`
  82. }
  83. let saveData = await saveHtmlData({
  84. data: html,
  85. simpleUUID: simpleUUID
  86. })
  87. if (!saveData.state) return this.websiteUrl = '';
  88. this.htmlData = saveData.data;
  89. return this.websiteUrl = `${config.baseURL}/api/enterprise/${simpleUUID}`
  90. },
  91. submit() {
  92. this.$confirm('是否发布该官网?', () => {
  93. this.$prompt('发布连接', 'WorkArk提示', {
  94. confirmButtonText: '打开链接',
  95. cancelButtonText: '取消',
  96. inputValue: `https://workark.com/api/enterprise/${this.simpleUUID}`
  97. }).then(() => {
  98. window.open(`https://workark.com/api/enterprise/${this.simpleUUID}`, "_blank");
  99. }).catch(() => {});
  100. })
  101. },
  102. onloadIframe() {
  103. this.loading = false;
  104. },
  105. cancelIframe() {
  106. const iframe = this.$refs.iframeDom;
  107. iframe.contentWindow.location.reload();
  108. this.iframeEdit = false;
  109. },
  110. saveIframe() {
  111. const iframe = this.$refs.iframeDom;
  112. const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  113. const a = iframeDoc.querySelectorAll('a');
  114. a.forEach(element => {
  115. element.href = element.oldHref;
  116. element.removeAttribute('oldHref');
  117. });
  118. const allElements = iframeDoc.querySelectorAll('*');
  119. allElements.forEach(element => {
  120. element.removeAttribute('contentEditable');
  121. });
  122. const img = iframeDoc.querySelectorAll('img');
  123. img.forEach(element => {
  124. element.style.cursor = 'pointer';
  125. element.onclick = null;
  126. });
  127. const iframeDocs = iframe.contentDocument || iframe.contentWindow.document;
  128. const htmlContent = iframeDocs.documentElement.outerHTML;
  129. updateHtmlData({
  130. data: htmlContent,
  131. id: this.htmlData.id
  132. }).then(res => {
  133. if (res.state) {
  134. this.$message.success('操作成功');
  135. this.iframeEdit = false;
  136. }
  137. })
  138. },
  139. editIframe() {
  140. let _self = this;
  141. const iframe = _self.$refs.iframeDom;
  142. if (iframe.contentDocument) {
  143. const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  144. //编辑时a标签不要跳转
  145. const a = iframeDoc.querySelectorAll('a');
  146. a.forEach(element => {
  147. element.oldHref = element.href;
  148. element.href = 'javascript:void(0);'
  149. });
  150. // 获取页面所有元素
  151. const allElements = iframeDoc.querySelectorAll('*');
  152. // 为每个元素设置contenteditable=true
  153. allElements.forEach(element => {
  154. if (element.nodeName !== 'IMG') element.contentEditable = 'true';
  155. });
  156. // 获取页面所有元素
  157. const img = iframeDoc.querySelectorAll('img');
  158. // 为每个元素设置contenteditable=true
  159. img.forEach(element => {
  160. element.style.cursor = 'pointer';
  161. element.onclick = function() {
  162. _self.imageELement = this;
  163. _self.$refs.upload.reloadUpload();
  164. }
  165. });
  166. _self.iframeEdit = true;
  167. }
  168. },
  169. successFunc(url) {
  170. if (this.imageELement) this.imageELement.src = url;
  171. },
  172. handleSend() {
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss">
  178. .ai-website {
  179. flex-direction: row;
  180. .html-box {
  181. width: 100%;
  182. overflow: hidden;
  183. height: 100%;
  184. }
  185. .iframe-class {
  186. width: 100%;
  187. height: 100%;
  188. border: none;
  189. overflow: hidden;
  190. }
  191. .website-form-title {
  192. height: 44px;
  193. line-height: 44px;
  194. border-bottom: 1px solid $--border-color-light;
  195. padding: 0 10px;
  196. font-weight: bold;
  197. }
  198. .website-form {
  199. width: 300px;
  200. border-right: 1px solid $--border-color-light;
  201. }
  202. .no-empty {
  203. width: 100%;
  204. height: 100%;
  205. display: flex;
  206. flex-direction: column;
  207. justify-content: center;
  208. }
  209. .website-show {
  210. flex: 1;
  211. width: 0;
  212. }
  213. .website-form-content {
  214. padding: 10px;
  215. .el-form {
  216. display: block;
  217. .el-form-item {
  218. width: 100%;
  219. padding: 0 !important;
  220. margin-bottom: 15px;
  221. }
  222. }
  223. }
  224. }
  225. </style>