浏览代码

release: 6.29.1

lanjianrong 3 年之前
父节点
当前提交
fa53ef8e98

+ 7 - 13
src/pages/Schema/Budget/components/Designable/antd/components/Field/shared.ts

@@ -67,10 +67,7 @@ export const createComponentSchema = (component: ISchema, decorator: ISchema) =>
   }
 }
 
-export const createFieldSchema = (
-  component?: ISchema,
-  decorator: ISchema = AllSchemas.FormItem
-): ISchema => {
+export const createFieldSchema = (component?: ISchema, decorator: ISchema = AllSchemas.FormItem): ISchema => {
   return {
     type: 'object',
     properties: {
@@ -78,11 +75,11 @@ export const createFieldSchema = (
         type: 'void',
         'x-component': 'CollapseItem',
         properties: {
-          name: {
-            type: 'string',
-            'x-decorator': 'FormItem',
-            'x-component': 'Input'
-          },
+          // name: {
+          //   type: 'string',
+          //   'x-decorator': 'FormItem',
+          //   'x-component': 'Input'
+          // },
           title: {
             type: 'string',
             'x-decorator': 'FormItem',
@@ -139,10 +136,7 @@ export const createFieldSchema = (
   }
 }
 
-export const createVoidFieldSchema = (
-  component?: ISchema,
-  decorator: ISchema = AllSchemas.FormItem
-) => {
+export const createVoidFieldSchema = (component?: ISchema, decorator: ISchema = AllSchemas.FormItem) => {
   return {
     type: 'object',
     properties: {

+ 0 - 46
src/pages/Schema/Budget/components/Designable/antd/components/GsCodeInput/preview.ts

@@ -1,46 +0,0 @@
-import React from 'react'
-import { Input as FormilyInput } from '@formily/antd'
-import { createBehavior, createResource } from '@designable/core'
-import { DnFC } from '@designable/react'
-import { createFieldSchema } from '../Field'
-import { AllSchemas } from '../../schemas'
-import { AllLocales } from '../../locales'
-
-export const Input: DnFC<React.ComponentProps<typeof FormilyInput>> = FormilyInput
-
-Input.Behavior = createBehavior(
-  {
-    name: 'Input',
-    extends: ['Field'],
-    selector: node => node.props['x-custom'] === 'Input',
-    designerProps: {
-      propsSchema: createFieldSchema(AllSchemas.Input)
-    },
-    designerLocales: AllLocales.Input
-  },
-  {
-    name: 'Input.TextArea',
-    extends: ['Field'],
-    selector: node => node.props['x-component'] === 'Input.TextArea',
-    designerProps: {
-      propsSchema: createFieldSchema(AllSchemas.Input.TextArea)
-    },
-    designerLocales: AllLocales.TextArea
-  }
-)
-
-Input.Resource = createResource({
-  icon: 'InputSource',
-  elements: [
-    {
-      componentName: 'Field',
-      props: {
-        type: 'string',
-        title: 'Input',
-        'x-decorator': 'FormItem',
-        'x-component': 'Input',
-        'x-custom': 'GsCodeInput'
-      }
-    }
-  ]
-})

src/pages/Schema/Budget/components/Designable/antd/components/GsCodeInput/index.ts → src/pages/Schema/Budget/components/Designable/antd/components/Input/index.ts


+ 63 - 0
src/pages/Schema/Budget/components/Designable/antd/components/Input/preview.tsx

@@ -0,0 +1,63 @@
+import React from 'react'
+import { Input as FormilyInput } from '@formily/antd'
+import { createBehavior, createResource } from '@designable/core'
+import { DnFC } from '@designable/react'
+import { createFieldSchema } from '../Field'
+import { AllSchemas } from '../../schemas'
+import { AllLocales } from '../../locales'
+
+export const Input: DnFC<React.ComponentProps<typeof FormilyInput>> = FormilyInput
+
+Input.Behavior = createBehavior(
+  {
+    name: 'Input',
+    extends: ['Field'],
+    selector: node => node.props['name'] === 'gsCode',
+    designerProps: {
+      propsSchema: createFieldSchema(AllSchemas.Input)
+    },
+    designerLocales: { 'zh-CN': { ...AllLocales.Input['zh-CN'], title: '项目编号' } }
+  },
+  {
+    name: 'Input',
+    extends: ['Field'],
+    selector: node => node.props['name'] === 'gsName',
+    designerProps: {
+      propsSchema: createFieldSchema(AllSchemas.Input)
+    },
+    designerLocales: { 'zh-CN': { ...AllLocales.Input['zh-CN'], title: '项目名称' } }
+  }
+)
+
+Input.Resource = createResource(
+  {
+    icon: 'InputSource',
+    elements: [
+      {
+        componentName: 'Field',
+        props: {
+          type: 'string',
+          title: '项目编号',
+          name: 'gsCode',
+          'x-decorator': 'FormItem',
+          'x-component': 'Input'
+        }
+      }
+    ]
+  },
+  {
+    icon: 'InputSource',
+    elements: [
+      {
+        componentName: 'Field',
+        props: {
+          type: 'string',
+          title: '项目名称',
+          name: 'gsName',
+          'x-decorator': 'FormItem',
+          'x-component': 'Input'
+        }
+      }
+    ]
+  }
+)

+ 1 - 0
src/pages/Schema/Budget/components/Designable/antd/components/Select/index.ts

@@ -0,0 +1 @@
+export * from './preview'

+ 84 - 0
src/pages/Schema/Budget/components/Designable/antd/components/Select/preview.tsx

@@ -0,0 +1,84 @@
+import React from 'react'
+import { Select as FormilySelect } from '@formily/antd'
+import { createBehavior, createResource } from '@designable/core'
+import { DnFC } from '@designable/react'
+import { createFieldSchema } from '../Field'
+import { AllSchemas } from '../../schemas'
+import { AllLocales } from '../../locales'
+
+export const Select: DnFC<React.ComponentProps<typeof FormilySelect>> = FormilySelect
+
+Select.Behavior = createBehavior(
+  {
+    name: 'Select',
+    extends: ['Field'],
+    selector: node => node.props['name'] === 'linkPID',
+    designerProps: {
+      propsSchema: createFieldSchema(AllSchemas.Select)
+    },
+    designerLocales: { 'zh-CN': { ...AllLocales.Select['zh-CN'], title: '关联项目' } }
+  },
+  {
+    name: 'Select',
+    extends: ['Field'],
+    selector: node => node.props['name'] === 'gcType',
+    designerProps: {
+      propsSchema: createFieldSchema(AllSchemas.Select)
+    },
+    designerLocales: { 'zh-CN': { ...AllLocales.Select['zh-CN'], title: '工程类型' } }
+  },
+  {
+    name: 'Select',
+    extends: ['Field'],
+    selector: node => node.props['name'] === 'pType',
+    designerProps: {
+      propsSchema: createFieldSchema(AllSchemas.Select)
+    },
+    designerLocales: { 'zh-CN': { ...AllLocales.Select['zh-CN'], title: '项目类型' } }
+  }
+)
+
+Select.Resource = createResource(
+  {
+    icon: 'SelectSource',
+    elements: [
+      {
+        componentName: 'Field',
+        props: {
+          title: '关联项目',
+          name: 'linkPID',
+          'x-decorator': 'FormItem',
+          'x-component': 'Select'
+        }
+      }
+    ]
+  },
+  {
+    icon: 'SelectSource',
+    elements: [
+      {
+        componentName: 'Field',
+        props: {
+          title: '工程类型',
+          name: 'gcType',
+          'x-decorator': 'FormItem',
+          'x-component': 'Select'
+        }
+      }
+    ]
+  },
+  {
+    icon: 'SelectSource',
+    elements: [
+      {
+        componentName: 'Field',
+        props: {
+          title: '项目类型',
+          name: 'pType',
+          'x-decorator': 'FormItem',
+          'x-component': 'Select'
+        }
+      }
+    ]
+  }
+)

+ 1 - 0
src/pages/Schema/Budget/components/Designable/antd/components/index.ts

@@ -2,3 +2,4 @@ export * from './Field'
 export * from './Form'
 export * from './FormGrid'
 export * from './FormLayout'
+export * from './Input'

+ 0 - 30
src/pages/Schema/Budget/components/Designable/antd/locales/Input.ts

@@ -16,35 +16,5 @@ export const Input = {
         checkStrength: '检测强度'
       }
     }
-  },
-  'en-US': {
-    title: 'Input',
-    settings: {
-      'x-component-props': {
-        addonAfter: 'Addon After',
-        addonBefore: 'Addon Before',
-        maxLength: 'Max Length',
-        prefix: 'Prefix',
-        suffix: 'Suffix',
-        autoSize: 'Auto Size',
-        showCount: 'Show Count',
-        checkStrength: 'Check Strength'
-      }
-    }
-  },
-  'ko-KR': {
-    title: '입력',
-    settings: {
-      'x-component-props': {
-        addonAfter: '애드온 후',
-        addonBefore: '애드온 전',
-        maxLength: '최대 길이',
-        prefix: '접두사',
-        suffix: '접미사',
-        autoSize: '자동 크기 맞춤',
-        showCount: '개수 보여주기',
-        checkStrength: '강도 체크'
-      }
-    }
   }
 }

+ 4 - 3
src/pages/Schema/Budget/components/Designable/index.tsx

@@ -19,7 +19,7 @@ import { SettingsForm } from '@designable/react-settings-form'
 import { createDesigner, GlobalRegistry, Shortcut, KeyCode } from '@designable/core'
 import { ActionsWidget, PreviewWidget, SchemaEditorWidget } from './widgets'
 import { saveSchema } from './service'
-import { Form, Field, FormGrid, FormLayout } from './antd'
+import { Form, Field, FormGrid, FormLayout, Input } from './antd'
 import { connect, useParams } from '@umijs/max'
 
 GlobalRegistry.registerDesignerLocales({
@@ -75,8 +75,8 @@ const Designable: FC<DesignableProps> = ({ templateSchema, title }) => {
         }>
         <CompositePanel>
           <CompositePanel.Item title="panels.Component" icon="Component">
-            <ResourceWidget title="sources.Inputs" sources={[]} />
             <ResourceWidget title="sources.Layouts" sources={[FormGrid, FormLayout]} />
+            <ResourceWidget title="sources.Inputs" sources={[Input]} />
           </CompositePanel.Item>
         </CompositePanel>
 
@@ -93,7 +93,8 @@ const Designable: FC<DesignableProps> = ({ templateSchema, title }) => {
                       Form,
                       Field,
                       FormGrid,
-                      FormLayout
+                      FormLayout,
+                      Input
                     }}
                   />
                 )}

+ 0 - 1
src/pages/Schema/Budget/detail.tsx

@@ -10,7 +10,6 @@ type DetailProps = RouteComponentProps & ConnectProps
 
 const Detail: React.FC<DetailProps> = ({ dispatch, templateSchema }) => {
   const { id: columnType } = useParams()
-
   useEffect(() => {
     if (templateSchema && !templateSchema[columnType]) {
       dispatch({

+ 17 - 7
src/pages/Schema/Budget/index.tsx

@@ -1,7 +1,7 @@
 import { queryTemplateList } from '@/services/api/schema'
 import { PageContainer } from '@ant-design/pro-layout'
-import React, { useState } from 'react'
-import { history, useRequest } from '@umijs/max'
+import React, { useEffect, useState } from 'react'
+import { history, useRequest, connect, useDispatch } from '@umijs/max'
 import { createForm } from '@formily/core'
 import { createSchemaField } from '@formily/react'
 import {
@@ -24,14 +24,24 @@ import { Button } from 'antd'
 import LeftMenu from '../Base/components/LeftMenu'
 
 type iState = {
-  menuData: API.TemplateListItem[]
-  activeKey: Nullable<string>
+  menuData?: API.TemplateListItem[]
+  activeKey?: string
 }
-const Budget = () => {
+
+const Budget: React.FC = () => {
+  const dispatch = useDispatch()
   const [state, setState] = useState<iState>({
     menuData: [],
     activeKey: null
   })
+  useEffect(() => {
+    if (state.menuData?.length) {
+      dispatch({
+        type: 'templateSchema/changeSchemaByColumnType',
+        payload: state.menuData
+      })
+    }
+  }, [state.menuData])
   useRequest(queryTemplateList, {
     onSuccess: (result: API.TemplateListItem[]) => {
       setState({
@@ -81,8 +91,8 @@ const Budget = () => {
 
         <div className="w-6/7 ml-8 bg-white p-4  rounded-20px shadow-hex-3e2c5a relative">
           <div className="flex justify-end">
-            {state.activeID && (
-              <Button type="primary" onClick={() => history.push(`/schema/budget/${state.activeID}`)}>
+            {state.activeKey && (
+              <Button type="primary" onClick={() => history.push(`/schema/budget/${state.activeKey}`)}>
                 编辑
               </Button>
             )}

+ 10 - 9
src/pages/Schema/Budget/model.ts

@@ -1,5 +1,6 @@
 import { getSchemaByColmunType, queryBudgetTemplateDetail } from '@/services/api/schema'
 import consts from '@/utils/consts'
+import { isArray } from '@/utils/is'
 import type { Effect, Reducer } from '@umijs/max'
 
 export type TemplateSchemaModelState = Record<
@@ -48,20 +49,20 @@ const TemplateSchemaModel: TemplateSchemaType = {
   },
   reducers: {
     save(state, action) {
-      if (action.payload?.schema) {
-        const targetSchema = JSON.parse(action.payload?.schema)
+      if (isArray(action.payload)) {
+        const schemaArrToMap = action.payload.reduce((prev, curr) => {
+          const schema = curr?.schema && JSON.parse(curr?.schema)
+          return { ...prev, [curr.action]: { ...curr, schema } }
+        }, {})
+        return { ...state, ...schemaArrToMap }
+      } else {
+        const schema = action.payload?.schema && JSON.parse(action.payload?.schema)
         return {
           ...state,
-          [action.payload.columnType]: targetSchema
+          [action.payload.action]: { ...action.payload, schema }
         }
       }
-      return state
     }
-
-    // 启用 immer 之后
-    // save(state, action) {
-    //   state.name = action.payload;
-    // },
   }
 }