# @sula/plugin-form-dependency

Latest version **0.1.12** (published 2020-02-06) · 0 weekly downloads

## Install

```sh
npm install @sula/plugin-form-dependency
pnpm add @sula/plugin-form-dependency
yarn add @sula/plugin-form-dependency
bun add @sula/plugin-form-dependency
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.12 |
| Published | 2020-02-06 |
| First published | 2019-10-14 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 34.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | kakuyo |

## Links

- npm: https://www.npmjs.com/package/@sula/plugin-form-dependency
- npm.io page: https://npm.io/package/@sula/plugin-form-dependency

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [@sula/utils](https://npm.io/package/@sula/utils.md) ^0.1.0

## Recent versions

- 0.1.12 (latest) — 2020-02-06
- 0.1.8-0 (beta) — 2019-12-25
- 0.1.11 — 2020-02-06
- 0.1.10 — 2020-01-20
- 0.1.9 — 2020-01-03
- 0.1.8 — 2019-12-25
- 0.1.7 — 2019-12-22
- 0.1.6 — 2019-12-12
- 0.1.5 — 2019-11-28
- 0.1.4 — 2019-11-28
- 0.1.3 — 2019-11-28
- 0.1.2 — 2019-11-11
- 0.1.1 — 2019-10-14
- 0.1.0-alpha.1 — 2019-10-14
- 0.1.0 — 2019-10-14

## README

```js
{
  name: 'things',
  remoteSource: {
    url: '/fetch/source',
    params: {},
    convertParams: () => {},
    converter: () => {},
  },
  dependency: {
    source: {
      relates: ['food', 'fruit'], // 全局设置
      cases: [{
        inputs: ['potato', 'apple'],
        output: [{text: '桌子', value: 'desk'}]
      }, {
        relates: ['food'], // 优先级高于全局
        inputs: ['tomato'],
        output: [{text: '窗户', value: 'window'}]
      }, {
        relates: ['fruit'], // 如果不配置inputs和outputs，就会自动与remoteSource结合，并把fruit的值作为请求参数
      }, {
        relates: ['food'],
        type: 'custom-source-dep', // 通过插件扩展点 depend 透出，让用户自己实现更定制化的关联操作
      }],
      default: [],
      ignores: [undefined, undefined], // [undefined, [undefined, 'unknown']]
    },
    value: {
      
    },
    visible: {
      relates: ['fruit'],
      cases: [{
        inputs: ['apple', 'peach'], // 如果fruit取apple或peach，则该组件不显示
        output: false,
      }],
      default: true,
    },
    disabled: {

    }
  }
}

```

```js
class CustomDep {
  apply(api) {
    api.syncHooks.depend((ctx) => {
      const {
        dependency,  // source, value, visable, disabled
        type, // custom-source-dep,
        relatesValue, // 根据relates获取的value
        form
      } = ctx;
      // 实现定制化关联场景
    })
  }
}
```

@峻文的二元思路

```js
{
  name: 'things',
  remoteSource: {
    url: '/fetch/source',
    params: {},
    convertParams: () => {},
    converter: () => {},
  },
  dependency: {
    source: {
      cases: [{
        relates: ['food', 'fruit'],
        condition: 'AND',
        operateor: 'EQUAL',
        inputs: ['potato', 'apple'],
        output: [{text: '桌子', value: 'desk'}]
      }, {
        relates: ['food'],
        condition: 'OR',
        inputs: ['tomato', {
          relates: ['fruit', 'drink'],
          condition: 'AND',
          operateor: 'NOT_EQUAL',
          inputs: ['apple', 'coca-cola'],
        }],
        output: [{text: '窗户', value: 'window'}]
      }, {
        relates: ['fruit'], // 如果不配置inputs和outputs，就会自动与remoteSource结合，并把fruit的值作为请求参数
      }, {
        relates: ['food'],
        type: 'custom-source-dep', // 通过插件扩展点 depend 透出，让用户自己实现更定制化的关联操作
      }],
      default: [],
      ignores: [undefined, undefined], // [undefined, [undefined, 'unknown']]
    },
    value: {
      
    },
    visible: {
      relates: ['fruit'],
      cases: [{
        inputs: ['apple', 'peach'], // 如果fruit取apple或peach，则该组件不显示
        output: false,
      }],
      default: true,
    },
    disabled: {

    }
  }
}

```

@峻文的二元思路的改版

```js
{
  name: 'things',
  remoteSource: {
    url: '/fetch/source',
    params: {},
    convertParams: () => {},
    converter: () => {},
  },
  dependency: {
    source: {
      cases: [{
        relates: ['food', 'fruit'],
        condition: 'AND',
        operateor: 'EQUAL',
        inputs: ['potato', 'apple'],
        output: [{text: '桌子', value: 'desk'}]
      }, {
        relates: ['food'],
        condition: 'OR',
        inputs: ['tomato', {
          relates: ['fruit', 'drink'],
          condition: 'AND',
          operateor: 'NOT_EQUAL',
          inputs: ['apple', 'coca-cola'],
        }],
        output: [{text: '窗户', value: 'window'}]
      }, {
        relates: ['fruit'], // 如果不配置inputs和outputs，就会自动与remoteSource结合，并把fruit的值作为请求参数
      }, {
        relates: ['food'],
        type: 'custom-source-dep', // 通过插件扩展点 depend 透出，让用户自己实现更定制化的关联操作
      }],
      default: [],
      ignores: [undefined, undefined], // [undefined, [undefined, 'unknown']]
    },
  }
}

```

---
_Source: https://npm.io/package/@sula/plugin-form-dependency · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
