1.1.4 • Published 9 months ago

yl-dc-component v1.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

yl-dc-component

描述

一个动态查询json生成组件,用于构建复杂的条件查询,一般用于配合后端数据库查询

演示

演示图片

组件说明

属性
  • DynamicConditionProps
属性名说明类型默认值必传备注
size尺寸"small" 、 "large" 、 "default"'small'false
fromSchemas字段配置FormSchema[][]true
value (v-model)查询条件节点GroupNode[]true
storeOption条件josn存储配置选项ConditionStorageOption{mode: 'localstorage',conf: { storageKey: 'CONDITION_AST_STORAGE_KEY'}}false
layoutOption布局选项{cols: number}{cols: 2}false
  • FormSchema
属性名说明类型默认值必传备注
label标签string''true
field字段名string''true
conditionTypes条件类型ConditionType[]'eq'false
component组件类型ComponentType'Input'false
componentProps组件属性object{}false
defaultValue默认值any''false
  • ComponentType
type ComponentType =
    | 'Input'
    | 'InputGroup'
    | 'InputPassword'
    | 'InputSearch'
    | 'InputTextArea'
    | 'InputNumber'
    | 'InputCountDown'
    | 'Select'
    | 'ApiSelect'
    | 'TreeSelect'
    | 'ApiTreeSelect'
    | 'RadioButtonGroup'
    | 'RadioGroup'
    | 'Checkbox'
    | 'CheckboxGroup'
    | 'AutoComplete'
    | 'Cascader'
    | 'DatePicker'
    | 'MonthPicker'
    | 'RangePicker'
    | 'WeekPicker'
    | 'TimePicker'
    | 'Switch'
    | 'StrengthMeter'
    | 'Upload'
    | 'IconPicker'
    | 'Render'
    | 'Slider'
    | 'Rate'
    | 'Avatar'
    | 'Divider' | Component | (() => JSX.Element)
  • ConditionStorageOption
属性名说明类型必传备注
mode存储模式'localstorage' | ‘api'false
conf配置项LocalStorageConf | ApiConffalse
  • LocalStorageConf
属性名说明类型必传备注
storageKey存储keystringtrue
  • ApiConf
属性名说明类型必传备注
getAllApi获取所有条件AST接口() => Promise<DynamicConditionAST[]>true
getApi根据key获取条件AST(key: string) => Promisetrue
updateApi更新条件AST(condition: DynamicConditionAST) => Promisetrue
saveApi保存条件AST(condition: DynamicConditionAST) => Promisetrue
delApi删除条件AST(key: string) => Promisetrue
resultFieldapi请求结果字段stringtrueapi请求结果字段 支持 xx.xx.xx
  • DynamicConditionAST (该类型为json ast)
属性名说明类型备注
keyast唯一keystring
name名称string
groups条件组GroupNode[]
  • GroupNode
属性名说明类型备注
logicType逻辑类型LogicType
conditions条件节点ConditionNode[]
  • ConditionNode
属性名说明类型备注
logicType逻辑类型LogicType
type条件类型ConditionType
field条件字段string
value条件值any
  • LogicType
类型说明备注
and
or
  • ConditionType
类型说明备注
eq等于
not_eq不等于
greater_than大于
less_than小于
like模糊匹配
in包含
not_in不包含
null空值
not_null非空值
事件
事件名说明参数
search搜索事件
searchConditionSelect搜索条件选择事件
searchConditionSelectDel搜索条件删除事件
reset重置事件
save条件保存事件

使用

安装
yarn add yl-dc-component
npm install yl-dc-component
引入
import 'yl-dc-component/dist/style.css'
import ylDcComponent from 'yl-dc-component'

示例

<script setup lang="ts">
import {DynamicCondition} from 'yl-dc-component'
import {FormSchema} from "yl-dc-component/dist/components/DynamicCondition/src/types/schemas";
import {GroupNode} from "yl-dc-component/dist/components/DynamicCondition/src/types/node";
import {ref} from "vue";

const schemas: FormSchema[] = [{
  label: "配置名称",
  defaultValue: "测试",
  conditionTypes: ['eq', 'like'],
  field: "name"
}, {
  label: "接入类型",
  defaultValue: "MicroId_IOT111111",
  conditionTypes: ["not_in", "in", 'eq'],
  component: 'Select',
  componentProps: {
    placeholder: '请输入',
    options: [{
      label: '微标Iot平台',
      value: 'MicroId_IOT'
    }, {
      label: '阿里云Iot平台',
      value: 'Aliyun_Iot'
    }]
  },
  field: "type"
}];

function reset() {
  console.log('reset')
}

async function search(ast: GroupNode[]) {
  console.log('search', ast)
  const res = await getDataSource({
    pageSize: 10,
    page: 1,
    ast
  })

  console.log("搜索结果:", res)
}

function save() {
  console.log('save')
}


type SearchModel = {
  pageSize: number;
  page: number;
  ast: GroupNode[]
}

async function getDataSource(searchModel: SearchModel) {
  return fetch("http://localhost:8080/api/page", {
    method: "POST",
    body: JSON.stringify(searchModel) as any,
    headers: {
      "Content-Type": 'application/json'
    }
  })
}

const value = ref<GroupNode[]>();

</script>

<template>
  <div style="background: #eeeeee;height: 100vh">
    <dynamic-condition
        @reset="reset"
        @search="search"
        @save="save"
        v-model:value="value"
        size="small"
        :fromSchemas="schemas">
    </dynamic-condition>
  </div>
</template>

<style scoped>

</style>