AIChat.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <script setup>
  2. import {
  3. onMounted,
  4. onUnmounted,
  5. ref
  6. } from 'vue'
  7. import AIFlowChat from '@/components/AIFlowChat.vue';
  8. import {
  9. useUserStore
  10. } from '@/store'
  11. import {
  12. useRouter
  13. } from 'vue-router';
  14. import {
  15. Notification,
  16. Position
  17. } from '@element-plus/icons-vue'
  18. const router = ref(useRouter())
  19. const user = ref(useUserStore().userData);
  20. const websiteUrl = ref('');
  21. const loading = ref(false);
  22. const iframeDom = ref(null);
  23. const isEdit = ref(false);
  24. const aiFlowChatRef = ref(null);
  25. const updateURL = (url) => {
  26. if (websiteUrl.value === url) return;
  27. websiteUrl.value = url;
  28. loading.value = true;
  29. }
  30. const linTo = () => {
  31. window.open(websiteUrl.value)
  32. }
  33. const edit = () => {
  34. const iframe = iframeDom.value;
  35. if (iframe.contentWindow) {
  36. if (isEdit.value) {
  37. removeEdit();
  38. } else {
  39. iframe.contentWindow.postMessage({
  40. designMode: false,
  41. enabled: true,
  42. type: "devtools_enable",
  43. __v0_remote__: 1
  44. }, '*')
  45. }
  46. isEdit.value = !isEdit.value;
  47. }
  48. }
  49. const removeEdit = () => {
  50. const iframe = iframeDom.value;
  51. if (iframe.contentWindow) {
  52. iframe.contentWindow.postMessage({
  53. designMode: false,
  54. enabled: false,
  55. type: "devtools_enable",
  56. __v0_remote__: 1
  57. }, '*')
  58. isEdit.value = false;
  59. }
  60. }
  61. const handleFunc = e => {
  62. if (e.data && e.data.type === 'app_navigation_state') return;
  63. if (e.data.type) {
  64. let type = e.data.type;
  65. if (type === 'frame_onload') {
  66. loading.value = false;
  67. removeEdit();
  68. }
  69. if (type === 'devtools_selected_state' && e.data.key) {
  70. aiFlowChatRef.value.selectItem(e.data);
  71. }
  72. }
  73. }
  74. onMounted(() => {
  75. window.addEventListener('message', handleFunc);
  76. })
  77. onUnmounted(() => {
  78. window.removeEventListener('message', handleFunc);
  79. })
  80. </script>
  81. <template>
  82. <div class="ai-website">
  83. <header class="ai-website-header">
  84. <div class="home-nav-left" @click="router.push('/')">
  85. <img class="img"
  86. src="https://file-node.oss-cn-shanghai.aliyuncs.com/youji/f9617c7f80da485cb3cc72b6accc62ed"
  87. alt="logo.png" />
  88. <span class="title">WorkArk.AI</span>
  89. </div>
  90. <div class="home-nav-right">
  91. <div class="item no-token">
  92. <el-avatar :size="26" :src="user.portrait"></el-avatar>
  93. </div>
  94. </div>
  95. </header>
  96. <div class="ai-website-content">
  97. <div class="website-form ai-website-box">
  98. <div class="website-form-title">AI聊天</div>
  99. <div class="hui-flex-box">
  100. <AIFlowChat ref="aiFlowChatRef" @updateURL="updateURL" @removeEdit="removeEdit"></AIFlowChat>
  101. </div>
  102. </div>
  103. <div class="website-show ai-website-box">
  104. <div class="website-form-title">
  105. <div>网页展示</div>
  106. <div class="title-icon-box" v-if="websiteUrl">
  107. <el-icon :class="isEdit?'active':''" @click="edit">
  108. <Position />
  109. </el-icon>
  110. <el-icon @click="linTo">
  111. <Notification />
  112. </el-icon>
  113. </div>
  114. </div>
  115. <div class="hui-flex-box">
  116. <div class="no-empty" v-if="!websiteUrl">
  117. <el-empty description="请先预览网站"></el-empty>
  118. </div>
  119. <div class="html-box" v-else v-loading="loading">
  120. <iframe ref="iframeDom" :src="websiteUrl" width="100%" height="100%" frameborder="0"
  121. @load="onloadIframe" :key="websiteUrl">
  122. </iframe>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. </div>
  128. </template>
  129. <style lang="scss">
  130. .ai-website {
  131. width: 100%;
  132. height: 100%;
  133. display: flex;
  134. background: #fcfbf8;
  135. flex-direction: column;
  136. .ai-website-header {
  137. height: 44px;
  138. display: flex;
  139. justify-content: space-between;
  140. align-items: center;
  141. padding: 0 15px;
  142. .home-nav-left {
  143. display: flex;
  144. align-items: center;
  145. cursor: pointer;
  146. }
  147. .title {
  148. font-weight: 600;
  149. color: #000;
  150. font-size: 18px;
  151. margin-left: 10px;
  152. }
  153. .img {
  154. width: 32px;
  155. height: 32px;
  156. }
  157. .home-nav-right {
  158. .item {
  159. display: flex;
  160. align-items: center;
  161. }
  162. .no-token {
  163. cursor: pointer;
  164. }
  165. .name {
  166. margin-left: 10px;
  167. }
  168. .el-avatar {
  169. background: var(--el-color-primary);
  170. img {
  171. background: #fff;
  172. }
  173. }
  174. }
  175. }
  176. .ai-website-content {
  177. display: flex;
  178. width: 100%;
  179. height: 0;
  180. flex: 1;
  181. padding: 0 10px 10px 10px;
  182. }
  183. .ai-website-box {
  184. background: #fff;
  185. border: 1px solid var(--el-border-color);
  186. border-radius: 10px;
  187. display: flex;
  188. flex-direction: column;
  189. }
  190. .html-box {
  191. width: 100%;
  192. overflow: hidden;
  193. height: 100%;
  194. }
  195. .iframe-class {
  196. width: 100%;
  197. height: 100%;
  198. border: none;
  199. overflow: hidden;
  200. }
  201. .website-form-title {
  202. height: 44px;
  203. line-height: 44px;
  204. border-bottom: 1px solid var(--el-border-color);
  205. padding: 0 10px;
  206. font-weight: bold;
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. .title-icon-box {
  211. font-size: 18px;
  212. color: #6c6d70;
  213. display: flex;
  214. align-items: center;
  215. cursor: pointer;
  216. .el-icon {
  217. margin-left: 10px;
  218. &.active {
  219. color: var(--el-color-primary);
  220. }
  221. &:hover {
  222. color: var(--el-color-primary);
  223. }
  224. }
  225. }
  226. }
  227. .website-form {
  228. width: 600px;
  229. border-right: 1px solid var(--el-border-color);
  230. margin-right: 10px;
  231. }
  232. .no-empty {
  233. width: 100%;
  234. height: 100%;
  235. display: flex;
  236. flex-direction: column;
  237. justify-content: center;
  238. }
  239. .website-show {
  240. flex: 1;
  241. width: 0;
  242. }
  243. .hui-flex-box {
  244. height: 0;
  245. flex: 1;
  246. }
  247. .website-form-content {
  248. padding: 10px;
  249. .el-form {
  250. display: block;
  251. .el-form-item {
  252. width: 100%;
  253. padding: 0 !important;
  254. margin-bottom: 15px;
  255. }
  256. }
  257. }
  258. }
  259. </style>