dev01 1 rok temu
rodzic
commit
994c606bde

+ 17 - 2
src/actions/report.js

@@ -1,5 +1,8 @@
-import { REPORT_QUERY, REPORT_AEADD, REPORT_DETAIL, REPORT_AL, REPORT_SUB } from '@constants/user'
-import { API_USER_QUERY, API_USER_AEADDREPORTS, API_USER_REPORTDETAIL, API_USER_AL, API_USER_SUBREPORT } from '@constants/api'
+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
+} from '@constants/api'
 import { createAction } from '@utils/redux'
 
 /**
@@ -57,4 +60,16 @@ export const report = payload => createAction({
   method: 'POST',
   type: REPORT_SUB,
   payload
+})
+
+
+/**
+ * 存为模板
+ * @param {*} payload 
+ */
+export const onReportTemplate = payload => createAction({
+  url: API_USER_TEMPLATE,
+  method: 'PUT',
+  type: REPORT_TEMPLATE,
+  payload
 })

+ 2 - 1
src/constants/api.js

@@ -19,4 +19,5 @@ 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_SUBREPORT = `${host}/gw/user/report` // 报告保存
+export const API_USER_SUBREPORT = `${host}/gw/user/report` // 报告保存
+export const API_USER_TEMPLATE = `${host}/gw/user/reportTemplate` // 存为模板

+ 1 - 0
src/constants/user.js

@@ -12,5 +12,6 @@ export const REPORT_AEADD = 'REPORT_AEADD'
 export const REPORT_DETAIL = 'REPORT_DETAIL'
 export const REPORT_AL = 'REPORT_AL'
 export const REPORT_SUB = 'REPORT_SUB'
+export const REPORT_TEMPLATE = 'REPORT_TEMPLATE'
 
 

+ 84 - 4
src/pages/reportdetail/reportdetail.js

@@ -40,7 +40,9 @@ class ReportDetail extends Component {
     name: "",
     newvb: false,
     popup: false,
-
+    template: false,
+    name: '',
+    tags: [],
   }
 
   componentDidMount() {
@@ -306,7 +308,7 @@ class ReportDetail extends Component {
     data.forEach(function (item, index) {
       if (index == i) {
         let val = e.detail.value.replace(/[\uff0c]/g, ",")
-        item.keywords = val.split(",")
+        item.keywords = !val ? [] : val.split(",")
       }
     })
     this.setState({
@@ -344,7 +346,7 @@ class ReportDetail extends Component {
     this.toggleVisible()
   }
   // 保存
-  onSubsmit = () => {
+  onSubmit = () => {
     const { data, metadata, chapters } = this.state
     if (!data.companyId) {
       Taro.showToast({
@@ -393,7 +395,44 @@ class ReportDetail extends Component {
 
     })
   }
+  // 另存为模板
+  onReportTemplate = () => {
+    const { data, metadata, chapters, name, tags } = this.state
+    if (!this.state.name) {
+      Taro.showToast({
+        title: "请填写模板名称!",
+        icon: 'none'
+      })
+      return
+    }
+    let payload = {
+      chapters,
+      companyId: data.companyId || 0,
+      id: 0,
+      logoPath: data.logoPath || '',
+      metadata,
+      name,
+      reportName: data.reportName || '',
+      tags,
+    }
+    this.props.onReportTemplate(payload).then((data) => {
+      this.onTemCancel()
+      Taro.showToast({
+        title: "模板保存成功",
+        icon: 'none'
+      })
+    }).catch(() => {
 
+    })
+  }
+  // 取消
+  onTemCancel = () => {
+    this.setState({
+      name: '',
+      tags: [],
+      template: false,
+    })
+  }
 
   render() {
     // if (!this.state.loaded) {
@@ -604,7 +643,14 @@ class ReportDetail extends Component {
           </Picker>
         </View>
         <View className='home-item' style={{ marginTop: 30, paddingBottom: 30 }}>
-          <Button type='primary' onClick={this.onSubsmit}>保存</Button>
+          <Button type='primary' onClick={this.onSubmit}>保存</Button>
+          <Button style={{ background: "#0079c2", color: "#fff" }}
+            onClick={() => {
+              this.setState({
+                template: true
+              })
+            }}
+          >另存为模板</Button>
         </View>
         {/* 新增项 */}
         {visible != "" &&
@@ -704,6 +750,40 @@ class ReportDetail extends Component {
               </View>
             </View>
           </View>}
+        {/* 另存为模板 */}
+        {this.state.template &&
+          <View className='mask'>
+            <View className='count'>
+              <View className='title'>另存为模板</View>
+              <View className='count_top' style={{ margin: "20px 0" }}>
+                <Input
+                  value={this.state.name}
+                  className='count_top_input'
+                  placeholder='模板名称'
+                  onChange={e => { this.setState({ name: e.detail.value }) }}
+                />
+                <Input
+                  value={this.state.tags.toString().replace(/,/g, ",")}
+                  style={{ marginTop: 15 }}
+                  className='count_top_input'
+                  placeholder='模板标签,输入逗号分割'
+                  onChange={e => {
+                    let val = e.detail.value.replace(/[\uff0c]/g, ",")
+                    this.setState({
+                      tags: !val ? [] : val.split(",")
+                    })
+                  }}
+                />
+              </View>
+              <View className='count_foot'>
+                <Button onClick={this.onTemCancel}>取消</Button>
+                <Button style={{ marginTop: 0 }}
+                  onClick={this.onReportTemplate}
+                >确认</Button>
+              </View>
+            </View>
+          </View>
+        }
       </View >
     )
   }

+ 7 - 5
src/pages/templatedetail/templatedetail.js

@@ -57,11 +57,13 @@ class TemplateDetail extends Component {
       id: this.$router.params.id,
     }
     this.props.reportTemplate(payload).then((data) => {
+      let datas = data
+      datas.tags = !data.tags ? [] : data.tags
       this.setState({
         loading: false,
-        data: data,
-        metadata: data.metadata,
-        chapters: data.chapters,
+        data: datas,
+        metadata: data.metadata || [],
+        chapters: data.chapters || [],
       }, () => {
         !!data.companyId && this.getCompany(data.companyId)
       })
@@ -297,7 +299,7 @@ class TemplateDetail extends Component {
     data.forEach(function (item, index) {
       if (index == i) {
         let val = e.detail.value.replace(/[\uff0c]/g, ",")
-        item.keywords = val.split(",")
+        item.keywords = !val ? [] : val.split(",")
       }
     })
     this.setState({
@@ -380,7 +382,7 @@ class TemplateDetail extends Component {
             onChange={e => {
               let obj = data
               let val = e.detail.value.replace(/[\uff0c]/g, ",")
-              obj.tags = val.split(",")
+              obj.tags = !val ? [] : val.split(",")
               this.setState({
                 data: obj,
               })