|
@@ -11,10 +11,7 @@
|
|
|
<div class="message-header-label">AI网站生成助手</div>
|
|
|
</div>
|
|
|
<div class="message-content">
|
|
|
- <p>您好!我是AI网站生成助手,请点击按钮生成网站。</p>
|
|
|
- <el-button size="mini" @click="visible = true" style="margin-top: 10px;">
|
|
|
- 点击生成网站
|
|
|
- </el-button>
|
|
|
+ <p>您好!我是AI网站生成助手,请输入任务让我修改展示的网站。</p>
|
|
|
</div>
|
|
|
<div class="message-time">
|
|
|
{{ formatTime(messageList.length === 0? new Date():messageList[0].date) }}
|
|
@@ -54,10 +51,9 @@
|
|
|
<div class="ai-website-boxs" v-else>
|
|
|
<div class="ai-website-box" v-html="message.AIInput"></div>
|
|
|
<div class="ai-website-mask">
|
|
|
- <el-button size="mini" type="primary"
|
|
|
- @click="$emit('previewWebSite', message.AIInput,message.simpleUUID)">
|
|
|
- 预览
|
|
|
- </el-button>
|
|
|
+ <el-button size="mini"
|
|
|
+ @click="previewHtml(message.AIInput,message.simpleUUID)">预览</el-button>
|
|
|
+ <el-button size="mini" type="primary" @click="update(message.AIInput)">替换</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -74,83 +70,38 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="input-container">
|
|
|
- <el-input type="textarea" v-model="newMessage" placeholder="给AI发送消息" resize="none" rows="2"
|
|
|
- :autosize="{ minRows: 2, maxRows: 6 }" :disabled="!htmlCode">
|
|
|
+ <el-input type="textarea" v-model="messageValue" placeholder="给AI发送消息" resize="none" rows="2"
|
|
|
+ :autosize="{ minRows: 2, maxRows: 6 }">
|
|
|
</el-input>
|
|
|
<div class="input-button">
|
|
|
- <el-button size="mini" @click="visible = true">
|
|
|
- 生成网站
|
|
|
- </el-button>
|
|
|
- <el-button size="mini" @click="selectProduct" :disabled="loading || !htmlCode">
|
|
|
- 添加商品
|
|
|
- </el-button>
|
|
|
- <el-button type="primary" size="mini" @click="sendMessage"
|
|
|
- :disabled="!newMessage.trim() || loading || !htmlCode">
|
|
|
+ <el-button type="primary" size="mini" @click="sendMessage" :disabled="!messageValue.trim() || loading">
|
|
|
发送
|
|
|
</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <el-dialog :close-on-click-modal="false" title="生成网站" :visible.sync="visible" width="900px"
|
|
|
- :append-to-body="true">
|
|
|
- <website-form v-if="visible" @callback="callback"></website-form>
|
|
|
- </el-dialog>
|
|
|
- <el-dialog :close-on-click-modal="false" title="选择商品" :visible.sync="visibles" width="900px"
|
|
|
- :append-to-body="true">
|
|
|
- <div class="hui-flex hui-content hui-dialog">
|
|
|
- <select-product ref="selectProduct" v-if="visibles"></select-product>
|
|
|
- <div class="hui-dialog-submit">
|
|
|
- <el-button size="small" @click="visibles = false">取 消</el-button>
|
|
|
- <el-button size="small" type="primary" @click="sureProduct" :loading="productLoading">
|
|
|
- 确定
|
|
|
- </el-button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import websiteForm from '@/components/work/common/websiteForm.vue'
|
|
|
- const selectProduct = () => import('@/components/work/common/selectProduct');
|
|
|
import {
|
|
|
getAIFlowDataStatus,
|
|
|
getAIFlowDataList,
|
|
|
- createAIFlowData
|
|
|
+ createAIFlowData,
|
|
|
+ getHtmlData,
|
|
|
+ saveHtmlData,
|
|
|
+ updateHtml
|
|
|
} from '@/api/ai'
|
|
|
- import Crypto from '@/uitls/crypto'
|
|
|
+ import config from '@/config'
|
|
|
export default {
|
|
|
- components: {
|
|
|
- websiteForm,
|
|
|
- selectProduct
|
|
|
- },
|
|
|
+ props: ['htmlData', 'htmlCode'],
|
|
|
data() {
|
|
|
return {
|
|
|
+ user: {},
|
|
|
messageList: [],
|
|
|
- newMessage: '',
|
|
|
+ messageValue: '',
|
|
|
loading: false,
|
|
|
- darkMode: false,
|
|
|
- visible: false,
|
|
|
timer: null,
|
|
|
- formData: {
|
|
|
- company_name: '企业名称',
|
|
|
- logo_url: '企业logo',
|
|
|
- company_sub_name: '企业简称',
|
|
|
- business_scope: '核心业务',
|
|
|
- key_features: '核心优势',
|
|
|
- contact_info: '联系方式',
|
|
|
- industry_sector: '行业领域',
|
|
|
- create_time: '成立时间',
|
|
|
- create_place: '成立地点',
|
|
|
- all_style: '整体风格',
|
|
|
- model: '主要模块',
|
|
|
- color_scheme: '主色调',
|
|
|
- websites_url: '参考网站'
|
|
|
- },
|
|
|
- user: {},
|
|
|
- htmlCode: '',
|
|
|
- simpleUUID: '',
|
|
|
- visibles: false,
|
|
|
- productLoading: false
|
|
|
+ formData: {}
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
@@ -174,22 +125,21 @@
|
|
|
methods: {
|
|
|
init(data) {
|
|
|
getAIFlowDataList({
|
|
|
- userId: this.$store.getters.user.userId
|
|
|
+ userId: this.$store.getters.user.userId,
|
|
|
+ organizationId: this.$store.getters.organization.id,
|
|
|
+ type: 1,
|
|
|
+ insertType: 2,
|
|
|
+ fileId: this.htmlData.id
|
|
|
}).then(res => {
|
|
|
if (res.state) {
|
|
|
this.messageList = res.data.map(node => {
|
|
|
node['userInput'] = this.returnUserInputs(node.inputs);
|
|
|
- let AIInput = ''
|
|
|
- if (node.outputs) AIInput = this.extractContentBetween(JSON.parse(node.outputs)
|
|
|
- .text, node.simpleUUID)
|
|
|
- node['AIInput'] = AIInput;
|
|
|
+ node['AIInput'] = this.extractContentBetween(node.outputs);
|
|
|
return node;
|
|
|
});
|
|
|
if (this.messageList.length > 0) {
|
|
|
let data = this.messageList[this.messageList.length - 1];
|
|
|
if (data.status === 'running') this.initStaus(data.simpleUUID);
|
|
|
- if (data.status === 'succeeded') this.$emit('previewWebSite', this.htmlCode, this
|
|
|
- .simpleUUID);
|
|
|
}
|
|
|
}
|
|
|
})
|
|
@@ -207,13 +157,11 @@
|
|
|
this.$forceUpdate();
|
|
|
}
|
|
|
if (data.status === 'succeeded' || data.status === 'failed') {
|
|
|
+ if (data.status === 'succeeded') data['AIInput'] = this
|
|
|
+ .extractContentBetween(data.outputs);
|
|
|
this.clearTimer();
|
|
|
this.loading = false;
|
|
|
- if (data.outputs) data['AIInput'] = this.extractContentBetween(JSON.parse(
|
|
|
- data.outputs).text, data.simpleUUID);
|
|
|
this.messageList[this.messageList.length - 1] = data;
|
|
|
- if (data.status === 'succeeded') this.$emit('previewWebSite', this
|
|
|
- .htmlCode, this.simpleUUID);
|
|
|
}
|
|
|
} else {
|
|
|
this.clearTimer();
|
|
@@ -221,26 +169,14 @@
|
|
|
})
|
|
|
}, 20000)
|
|
|
},
|
|
|
+ extractContentBetween(html) {
|
|
|
+ if (!html) return '';
|
|
|
+ let htmlCode = JSON.parse(html).text;
|
|
|
+ return htmlCode.split('```html')[1];
|
|
|
+ },
|
|
|
returnUserInputs(data) {
|
|
|
if (!data) return '';
|
|
|
- let html = '';
|
|
|
- let objs = JSON.parse(data);
|
|
|
- if (objs.insertType === 1) {
|
|
|
- let query = JSON.parse(objs.query)
|
|
|
- for (let key in query) {
|
|
|
- if (query[key].indexOf('https://file-node.oss-cn-shanghai.aliyuncs.com/youji/') > -1) {
|
|
|
- html += this.formData[key] + ':<img class="message-image" src="' + query[key] +
|
|
|
- '" alt="aa"/><br />';
|
|
|
- } else if (this.formData[key]) {
|
|
|
- html += this.formData[key] + ':' + query[key] + "<br />";
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (objs.insertType === 2 || objs.insertType === 4) {
|
|
|
- html = objs.query;
|
|
|
- } else if (objs.insertType === 3) {
|
|
|
- html = objs.query;
|
|
|
- }
|
|
|
- return html;
|
|
|
+ return JSON.parse(data).query;
|
|
|
},
|
|
|
clearTimer() {
|
|
|
if (!this.timer) return;
|
|
@@ -259,16 +195,14 @@
|
|
|
container.scrollTop = container.scrollHeight;
|
|
|
}
|
|
|
},
|
|
|
- callback(type) {
|
|
|
- this.visible = false;
|
|
|
- if (type === 'init') this.init();
|
|
|
- },
|
|
|
sendMessage() {
|
|
|
createAIFlowData(5, {
|
|
|
type: 1,
|
|
|
insertType: 2,
|
|
|
- query: this.newMessage,
|
|
|
- html_code: this.htmlCode
|
|
|
+ query: this.messageValue,
|
|
|
+ html_code: this.htmlCode,
|
|
|
+ organizationId: this.$store.getters.organization.id,
|
|
|
+ fileId: this.htmlData.id
|
|
|
}).then(this.successFunc);
|
|
|
},
|
|
|
reload(message) {
|
|
@@ -278,52 +212,49 @@
|
|
|
query: data.query,
|
|
|
html_code: data.html_code,
|
|
|
insertType: data.insertType,
|
|
|
+ organizationId: this.$store.getters.organization.id
|
|
|
}).then(this.successFunc);
|
|
|
},
|
|
|
successFunc(res) {
|
|
|
if (res.state) {
|
|
|
this.visibles = false;
|
|
|
- this.newMessage = '';
|
|
|
+ this.messageValue = '';
|
|
|
this.$message.success('操作成功');
|
|
|
this.init();
|
|
|
}
|
|
|
},
|
|
|
- extractContentBetween(html, simpleUUID) {
|
|
|
- if (!html) return '';
|
|
|
- // 使用正则表达式匹配 ```html 和 ``` 之间的内容
|
|
|
- let regex = /```html([\s\S]*?)```/;
|
|
|
- let match = html.match(regex);
|
|
|
- let htmls = match && match[1] ? match[1].trim() : '';
|
|
|
- this.htmlCode = htmls;
|
|
|
- this.simpleUUID = simpleUUID;
|
|
|
- return htmls;
|
|
|
- },
|
|
|
- selectProduct() {
|
|
|
- this.visibles = true;
|
|
|
- },
|
|
|
- sureProduct() {
|
|
|
- let form = this.$refs.selectProduct.form;
|
|
|
- let currentRow = this.$refs.selectProduct.currentRow.map(node => {
|
|
|
- let id = Crypto.AES.encrypt(String(node.id), 'bosshand');
|
|
|
- return {
|
|
|
- id: encodeURIComponent(id),
|
|
|
- name: node.name,
|
|
|
- subtitme: node.subtitle,
|
|
|
- img: this.imageUrl(node.listDisplayImage),
|
|
|
- unit: '次'
|
|
|
- }
|
|
|
- });
|
|
|
- if (currentRow.length === 0) return this.$message.warning('请至少选择一个商品');
|
|
|
- createAIData(4, {
|
|
|
- detailed_html: this.htmlCode,
|
|
|
- model_name: form.modelName,
|
|
|
- json_data: JSON.stringify(currentRow)
|
|
|
- }).then(this.successFunc);
|
|
|
+ async previewHtml(html, simpleUUID) {
|
|
|
+ let url = await this.previewWebSite(html, simpleUUID);
|
|
|
+ window.open(url, '_blank');
|
|
|
},
|
|
|
- imageUrl(data) {
|
|
|
- if (data && JSON.parse(data)[0]) return JSON.parse(data)[0].url;
|
|
|
- return 'https://assets.api.uizard.io/api/cdn/stream/c05650d2-192b-4a56-ae97-05638f53804c.png';
|
|
|
+ async previewWebSite(html, simpleUUID) {
|
|
|
+ let htmlData = await getHtmlData({
|
|
|
+ simpleUUID: simpleUUID
|
|
|
+ })
|
|
|
+ if (!htmlData.state) return '';
|
|
|
+ if (htmlData.data.length > 0) return `${config.baseURL}/api/enterprise/${simpleUUID}`
|
|
|
+ let saveData = await saveHtmlData({
|
|
|
+ data: html,
|
|
|
+ simpleUUID: simpleUUID
|
|
|
+ })
|
|
|
+ if (!saveData.state) return '';
|
|
|
+ return `${config.baseURL}/api/enterprise/${simpleUUID}`
|
|
|
},
|
|
|
+ update(html) {
|
|
|
+ this.$confirm(`是否替换${this.htmlData.name}代码?替换后将不能再恢复。`, () => {
|
|
|
+ this.$loading();
|
|
|
+ updateHtml({
|
|
|
+ html: html,
|
|
|
+ id: this.htmlData.id
|
|
|
+ }).then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ this.$message.success('操作成功');
|
|
|
+ this.$emit('reloadIframe');
|
|
|
+ }
|
|
|
+ this.$loading.close();
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|