import { useEditor } from "@/modules/editor"; import { CloseOutlined } from "@ant-design/icons-vue"; import { defineComponent, reactive } from "vue"; import { Button, Input, message } from "ant-design-vue"; import { css } from "@linaria/core"; import { queenApi } from "queenjs"; export default defineComponent({ emits: ["visible"], setup(props, { emit }) { const { store, actions } = useEditor(); const state = reactive({ loading: false, inputValue: "", aiValue: "", boxFocus: false, generated: false, }); const generateWord = () => { if (state.loading) { return; } state.loading = true; const reqData = { model: "gpt-3.5-turbo", messages: [ { role: "user", content: state.inputValue, }, ], }; const xhr = new XMLHttpRequest(); xhr.open( "post", "https://186b2d5554134321a0afd4b1be443273.apig.ap-southeast-1.huaweicloudapis.com/chatgpt" ); xhr.setRequestHeader("content-type", "application/json"); xhr.send(JSON.stringify(reqData)); xhr.onload = function (e: any) { let result = e.target?.responseText; try { result = JSON.parse(result); const { choices } = result; const message = choices[0].message.content; state.aiValue = message; state.generated = true; } catch (e) { queenApi.messageError("生成失败!"); console.log(e); } finally { state.loading = false; } }; xhr.onerror = (e: any) => { queenApi.messageError("生成失败!"); console.log(e); state.loading = false; }; }; const addText = async () => { const aitext = `
${state.aiValue}
`; await actions.clickCompToDesign("Text", (comp) => { actions.updateCompData(comp, "value", aitext); }); }; return () => (