GithubHelp home page GithubHelp logo

campaign-pattern's Introduction

Campaign Template Learn

封装与预制

原则:

  1. 唯业务可变

  2. 预制,封装业务无关

  3. 内核用插件拓展

灵感

要求

  1. 使用 JSX 书写

  2. 完全支持 antdProps

  3. 支持自定义,能够拿到上下文

const { Header, Table, Column, Action } = ListPageTemplate

export function CampaignListPage(): ReactNode {
  return (
    <ListPageTemplate>
      <Header />

      <Table>
        <Column {...antdProps} {...customProps} />
        <Column />
        <Column />

        <Action />
        <Action />
      </Table>
    </ListPageTemplate>
  )
}

Table 封装

import { ReactNode, useMemo } from 'react'

export function CampaignListPage(): ReactNode {
  const table = useMemo(() => createTable(), [])

  const handleBizLogic = () => {
    table.refresh()
  }

  const onRequest = async () => {
    // ...
    return [
      { label: 'free', value: 'FREE' },
      { label: 'paid', value: 'PAID' },
    ]
  }

  const onReaction = (column, table) => {
    const { record } = column

    column.setVisible(false)

    // table.refresh()
  }

  return (
    <TableContextProvider table={table}>
      <Header />

      <Table onRequest={() => {}} onInit={() => {}}>
        <Column dataIndex="campaign_id" />
        <Column dataIndex="charge_type" columnType="select" onRequest={onRequest} onReaction={[onReaction]} />
        <Column />

        <Action buttons={[]} />
      </Table>
    </TableContextProvider>
  )
}

Form 封装

import { ReactNode, useMemo } from 'react'

export function CampaignDetailPage(): ReactNode {
  const form = useMemo(() => createForm(), [])

  const handleBizLogic = () => {
    form.submit()
  }

  const onRequest = async () => {
    // ...
    return [
      { label: 'free', value: 'FREE' },
      { label: 'paid', value: 'PAID' },
    ]
  }

  const onReaction = (field: FormilyField, form: FormilyForm) => {
    field.setVisible(false)
  }

  return (
    <Form form={form} onInit={() => {}} onRequest={() => {}} requestId="123OrNull">
      <Header />

      <Field name="campaign_id" />
      <Field name="charge_type" fieldType="select" onRequest={onRequest} onReaction={[onReaction]} />
      <Field />

      <Footer buttons={[]} />
    </Form>
  )
}

Button 封装

<Button buttonType='drawer-filter' filters={[]} />
<Button buttonType='column-toggle' toggles={[]} />
<Button buttonType='form-modal' fields={[]} />
<Button buttonType='page-nav' pageType='' onBeforeNav={} />
<Button buttonType='download-csv' downloadUrl='' />
<Button buttonType='upload-csv' />
<Button buttonType='edit-csv' />

业务插件

const useTableColumnTogglePlugin = (table) => {
  const tableProps = table.getTableProps()

  // ...
}

function Table(props) {

  useTableColumnTogglePlugin(table)

  return <AntdTable {...props} />
}


const useFormTabGroupPlugin = (form) => {
  const formProps = form.getFormProps()

  // ...
}

function Form(props) {

  useFormTabGroupPlugin(table)

  return <FormilyForm {...props} />
}

编排

function CampaignScene() {

  return <></>
}

// with 确定的业务点
assign(CampaignScene, {
  CampaignListPage: (userProps) => <CampaignListPage {...props} {...userProps} />,
  CampaignDetailPage: (userProps) => <CampaignDetailPage {...props} {...userProps} />,
  // ...
})

实现步骤

  1. 底层工具 + tests => 底层稳定

  2. 封装、预制 => 定义规范

  3. 组装、编排 => 终极提效

campaign-pattern's People

Watchers

liam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.