0.1.12 • Published 4 years ago

@sula/plugin-form-dependency v0.1.12

Weekly downloads
16
License
-
Repository
-
Last release
4 years ago
{
  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: {

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

@峻文的二元思路

{
  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: {

    }
  }
}

@峻文的二元思路的改版

{
  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']]
    },
  }
}
0.1.11

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.8-0

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0-alpha.1

5 years ago

0.1.0

5 years ago