雷佳斌 месяцев назад: 2
Родитель
Сommit
40a9f13bcf
3 измененных файлов с 62 добавлено и 14 удалено
  1. 12 1
      src/actions/report.js
  2. 1 0
      src/constants/api.js
  3. 49 13
      src/pages/reportdetail/reportdetail.js

+ 12 - 1
src/actions/report.js

@@ -1,7 +1,7 @@
 import { REPORT_QUERY, REPORT_AEADD, REPORT_DETAIL, REPORT_AL, REPORT_SUB, REPORT_TEMPLATE } from '@constants/user'
 import {
   API_USER_QUERY, API_USER_AEADDREPORTS, API_USER_REPORTDETAIL,
-  API_USER_AL, API_USER_SUBREPORT, API_USER_TEMPLATE
+  API_USER_AL, API_USER_SUBREPORT, API_USER_TEMPLATE, API_USER_AI_PLUS
 } from '@constants/api'
 import { createAction } from '@utils/redux'
 
@@ -52,6 +52,17 @@ export const generate = payload => createAction({
 })
 
 /**
+ * AI一键生成
+ * @param {*} payload 
+ */
+export const generatePlus = payload => createAction({
+  url: API_USER_AI_PLUS,
+  method: 'POST',
+  type: REPORT_AL,
+  payload
+})
+
+/**
  * 报告保存
  * @param {*} payload 
  */

+ 1 - 0
src/constants/api.js

@@ -19,5 +19,6 @@ export const API_USER_QUERY = `${host}/gw/user/company/query` // 获取企业列
 export const API_USER_AEADDREPORTS = `${host}/gw/user/company` // 新增企业名称  查看关联企业
 export const API_USER_REPORTDETAIL = `${host}/gw/user/report` // 报告详情
 export const API_USER_AL = `${host}/gw/user/ai/generate` // Al生成
+export const API_USER_AI_PLUS = `${host}/gw/user/ai/generatePlus` // AI一键生成
 export const API_USER_SUBREPORT = `${host}/gw/user/report` // 报告保存
 export const API_USER_TEMPLATE = `${host}/gw/user/reportTemplate` // 存为模板

+ 49 - 13
src/pages/reportdetail/reportdetail.js

@@ -86,6 +86,31 @@ class ReportDetail extends Component {
 
     })
   }
+  // AI一键生成
+  getGeneratePlus = () => {
+    const { chapters, reportName } = this.state.data;
+    const allTitle = chapters.map(item => item.title);
+    const payload = {
+      chapterTitle: allTitle.join(","),
+      projectName: reportName
+    };
+    Taro.showLoading({
+      title: 'AI正在撰写章节内容,请稍等…',
+      mask: true,
+    })
+
+    this.props.generatePlus(payload).then((res) => {
+      Taro.hideLoading()
+      chapters.forEach(item => {
+        console.log(item)
+        item.content = res[item.title];
+      });
+
+      this.setState({ chapters });
+    }).catch(() => {
+      Taro.hideLoading()
+    })
+  }
   // Al生成
   getGenerate(title, i) {
     const { data } = this.state
@@ -477,19 +502,30 @@ class ReportDetail extends Component {
           />
         </View>
         <View className='home-item'>
-          <View className='home-item-tit'>项目名称</View>
-          <Input
-            value={data.reportName}
-            className='home-item-val'
-            placeholder='请输入项目名称'
-            onChange={e => {
-              let obj = data
-              obj.reportName = e.detail.value
-              this.setState({
-                data: obj,
-              })
-            }}
-          />
+          <View className='home-item-tit'>
+            项目名称
+          </View>
+
+          <View className='home-item-vals'>
+            <View>
+              <Input
+                value={data.reportName}
+                className='home-item-val'
+                placeholder='请输入项目名称'
+                onChange={e => {
+                  let obj = data
+                  obj.reportName = e.detail.value
+                  this.setState({
+                    data: obj,
+                  })
+                }}
+                style={{ borderBottom: "none" }}
+              />
+            </View>
+            <View className='home-item-vals-bt'>
+              <Button size='mini' type='primary' onClick={this.getGeneratePlus}>Al一键生成</Button>
+            </View>
+          </View>
         </View>
         <View className='home-item'>
           <View className='home-item-tit'>项目负责人</View>