Преглед на файлове

feat: 预算业务表单处理请求接口参数

lanjianrong преди 3 години
родител
ревизия
047434f332

+ 1 - 1
.gitignore

@@ -14,7 +14,7 @@ _roadhog-api-doc
 .DS_Store
 npm-debug.log*
 yarn-error.log
-/pnpm-locak.yaml
+pnpm-locak.yaml
 /coverage
 .idea
 yarn.lock

+ 16 - 16
config/routes.ts

@@ -144,23 +144,23 @@
         name: 'baseDetail',
         component: './Schema/Base/detail.tsx',
         hideInMenu: true
+      },
+      {
+        path: 'option',
+        name: 'option',
+        component: './Schema/Option'
+      },
+      {
+        path: 'budget',
+        name: 'budget',
+        component: './Schema/Budget'
+      },
+      {
+        path: 'budget/:id',
+        name: 'budgetDetail',
+        component: './Schema/Budget/detail',
+        hideInMenu: true
       }
-      // {
-      //   path: 'option',
-      //   name: 'option',
-      //   component: './Schema/Option'
-      // },
-      // {
-      //   path: 'budget',
-      //   name: 'budget',
-      //   component: './Schema/Budget'
-      // },
-      // {
-      //   path: 'budget/:id',
-      //   name: 'budgetDetail',
-      //   component: './Schema/Budget/detail',
-      //   hideInMenu: true
-      // }
     ]
   },
   {

+ 2 - 2
package.json

@@ -43,8 +43,8 @@
     "@formily/reactive": "^2.1.4",
     "@formily/reactive-react": "^2.1.4",
     "@formily/shared": "^2.1.4",
-    "@umijs/max": "4.0.0-canary.20220628.1",
-    "@umijs/plugins": "4.0.0-canary.20220628.1",
+    "@umijs/max": "4.0.3",
+    "@umijs/plugins": "4.0.3",
     "ahooks": "^3.0.0",
     "antd": "4.20.7",
     "array-move": "^4.0.0",

+ 6 - 15
src/pages/Schema/Base/index.tsx

@@ -2,8 +2,8 @@
 import { PageContainer } from '@ant-design/pro-layout'
 import LeftMenu from './components/LeftMenu'
 import { useState, useEffect } from 'react'
-import { history, connect, Link } from '@umijs/max'
-import type { ProjectModelState, SchemaBaseModelState } from '@umijs/max'
+import { history, connect } from '@umijs/max'
+import type { SchemaBaseModelState } from '@umijs/max'
 import { createForm } from '@formily/core'
 import { createSchemaField } from '@formily/react'
 import {
@@ -45,10 +45,9 @@ export const menuOptions = [
 ]
 type BaseProps = ConnectProps & {
   base: SchemaBaseModelState
-  pTypeList: { label: string; value: string }[]
 }
 
-const Index: React.FC<BaseProps> = ({ base, pTypeList, dispatch }) => {
+const Index: React.FC<BaseProps> = ({ base, dispatch }) => {
   const [state, setState] = useState({
     activeKey: BaseMenuEnum.PROJECT
   })
@@ -64,11 +63,6 @@ const Index: React.FC<BaseProps> = ({ base, pTypeList, dispatch }) => {
         }
       })
     }
-    if (!pTypeList.length) {
-      dispatch({
-        type: 'project/queryProjectTypeList'
-      })
-    }
   }, [state.activeKey])
 
   const gotoDetail = columnType => {
@@ -127,9 +121,6 @@ const Index: React.FC<BaseProps> = ({ base, pTypeList, dispatch }) => {
   )
 }
 
-export default connect(
-  ({ project, schemaBase }: { project: ProjectModelState; schemaBase: SchemaBaseModelState }) => ({
-    pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID })),
-    base: schemaBase.base
-  })
-)(Index)
+export default connect(({ schemaBase }: { schemaBase: SchemaBaseModelState }) => ({
+  base: schemaBase.base
+}))(Index)

+ 5 - 5
src/pages/Schema/Budget/components/Designable/widgets/ActionsWidget.tsx

@@ -6,7 +6,7 @@ import { observer } from '@formily/react'
 import { loadInitialSchema } from '../service'
 import { useDispatch, history, useParams, useRequest } from '@umijs/max'
 import { transformToSchema } from '@designable/formily-transformer'
-import { updateSchema } from '@/services/api/schema'
+import { saveBudgetTemplate } from '@/services/api/schema'
 
 export const ActionsWidget = observer(({ schema }) => {
   const designer = useDesigner()
@@ -16,12 +16,12 @@ export const ActionsWidget = observer(({ schema }) => {
     GlobalRegistry.setDesignerLanguage('zh-cn')
   }, [schema])
   const dispatch = useDispatch()
-  const { run: tryUpdateSchema } = useRequest(updateSchema, {
+  const { run: tryUpdateSchema } = useRequest(saveBudgetTemplate, {
     manual: true,
-    onSuccess: result => {
+    onSuccess: (result: { schema: string }) => {
       message.success('更新成功')
       dispatch({
-        type: 'schemaBase/changeSchemaByColumnType',
+        type: 'templateSchema/changeSchemaByColumnType',
         payload: {
           columnType,
           schema: result.schema
@@ -32,7 +32,7 @@ export const ActionsWidget = observer(({ schema }) => {
 
   const saveSchema = () => {
     tryUpdateSchema({
-      columnType,
+      action: columnType,
       schema: JSON.stringify(transformToSchema(designer.getCurrentTree()).schema)
     })
   }

+ 38 - 29
src/pages/Schema/Budget/index.tsx

@@ -1,6 +1,6 @@
 import { queryTemplateList } from '@/services/api/schema'
 import { PageContainer } from '@ant-design/pro-layout'
-import React, { useEffect, useState } from 'react'
+import React, { useEffect, useMemo, useState } from 'react'
 import { history, useRequest, connect, useDispatch } from '@umijs/max'
 import { createForm } from '@formily/core'
 import { createSchemaField } from '@formily/react'
@@ -22,6 +22,7 @@ import {
 } from '@formily/antd'
 import { Button } from 'antd'
 import LeftMenu from '../Base/components/LeftMenu'
+import { isString } from '@/utils/is'
 
 type iState = {
   menuData?: API.TemplateListItem[]
@@ -51,31 +52,43 @@ const Budget: React.FC = () => {
       })
     }
   })
-  const onSelect = (key: string) => {
-    setState({ ...state, activeID: key })
-  }
 
-  const form = createForm({
-    initialValues: {},
-    effects() {}
-  })
-  const SchemaField = createSchemaField({
-    components: {
-      FormLayout,
-      FormItem,
-      FormGrid,
-      Input,
-      Switch,
-      Select,
-      Radio,
-      Checkbox,
-      NumberPicker,
-      Password,
-      DatePicker,
-      TimePicker,
-      TreeSelect
+  const currentSchema = useMemo(() => {
+    const schema = state.menuData?.find(item => item.action === state.activeKey)?.schema
+    if (schema && isString(schema)) {
+      return JSON.parse(schema)
     }
-  })
+    return {}
+  }, [state.activeKey])
+  const renderForm = () => {
+    const normalForm = createForm({
+      validateFirst: true,
+      pattern: 'readOnly'
+    })
+
+    const SchemaField = createSchemaField({
+      components: {
+        FormLayout,
+        FormItem,
+        FormGrid,
+        Input,
+        Switch,
+        Select,
+        Radio,
+        Checkbox,
+        NumberPicker,
+        Password,
+        DatePicker,
+        TimePicker,
+        TreeSelect
+      }
+    })
+    return (
+      <Form form={normalForm} labelCol={4} wrapperCol={8}>
+        <SchemaField schema={currentSchema} />
+      </Form>
+    )
+  }
 
   return (
     <PageContainer title={false}>
@@ -97,11 +110,7 @@ const Budget: React.FC = () => {
               </Button>
             )}
           </div>
-          <div className="w-600px">
-            <Form form={form} labelCol={8}>
-              <SchemaField />
-            </Form>
-          </div>
+          <div className="w-600px">{renderForm()}</div>
         </div>
       </div>
     </PageContainer>

+ 1 - 1
src/pages/Schema/Budget/model.ts

@@ -59,7 +59,7 @@ const TemplateSchemaModel: TemplateSchemaType = {
         const schema = action.payload?.schema && JSON.parse(action.payload?.schema)
         return {
           ...state,
-          [action.payload.action]: { ...action.payload, schema }
+          [action.payload.action]: { ...state[action.payload.action], ...action.payload, schema }
         }
       }
     }

+ 8 - 0
src/services/api/schema.ts

@@ -70,3 +70,11 @@ export async function queryBudgetTemplateDetail(params: Omit<API.TemplateListIte
     params
   })
 }
+
+/** 预算业务表单-保存模板 */
+export async function saveBudgetTemplate(params: Omit<API.TemplateListItem, 'name'>) {
+  return request('/form/v1/template/save', {
+    method: 'POST',
+    data: params
+  })
+}

+ 1 - 0
src/services/api/typings.d.ts

@@ -363,6 +363,7 @@ declare namespace API {
   type TemplateListItem = {
     action?: string
     name?: string
+    schema?: string
   }
 
   type SaveApprovalParams = {