0.1.13 • Published 8 months ago

van-filter-search v0.1.13

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

van-filter-search

van-filter-search for vant-ui.

this component is for vant4.x and vue3.x.

文档

https://starlet0822.github.io/van-filter-search

快速开始

1. ES module

安装

npm install --save van-filter-search
// or
yarn add van-filter-search
// or
pnpm add van-filter-search

注册

全局注册
import VanFilterSearch from "van-filter-search";

const app = createApp(App);
app.use(VanFilterSearch);
组件引入
<template>
  <van-filter-search></van-filter-search>
</template>

<script>
import { VanFilterSearch } from "van-filter-search";

export default defineComponent({
  components: {
    VanFilterSearch
})
</script>

使用

<script setup>
import { VanFilterSearch } from "van-filter-search";

const filterSearchRef = ref(null)
const fieldItems = ref([
  {
    type: 'InputField',
    title: '关键词查询',
    value: '',
    name: 'keyword',
    attrs: {
      placeholder: '输入搜索关键词'
    },
  },
  {
    type: 'RadioField',
    title: '任务状态',
    value: '0',
    name: 'status',
    attrs: {
      options: [
        { text: '未审核', value: '-1' },
        { text: '已审核', value: '0' },
        { text: '未通过', value: '1' },
        { text: '审核中', value: '2' },
        { text: '已退回', value: '3' }
      ],
    },
  },
  {
    type: 'CheckboxField',
    title: '紧急程度',
    value: [],
    name: 'level',
    attrs: {
      fieldNames: { text: 'label', value: 'id' },
      options: [
        { label: '重要', id: '0' },
        { label: '重要', id: '1' },
        { label: '紧急', id: '2', disabled: true },
        { label: '特急', id: '3' }
      ],
    },
  },
  {
    type: 'DateField',
    title: '创建时间',
    value: '',
    name: 'createTime',
    attrs: {
      placeholder: '选择时间'
    },
  },
])

const handleConfirm = (queryParams) => {
  // do something...
  // fetch data
}

onMounted(() => {
  console.log(filterSearchRef.value.getSelectedValues())
})
</script>

<template>
  <van-filter-search
    ref="filterSearchRef"
    :field-items="fieldItems"
    :show-header="true"
    @confirm="handleConfirm"
  ></van-filter-search>
</template>

<style lang="scss" scoped></style>

2. CDN

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@3.3.4/dist/vue.global.prod.js"></script>
  <script src="https://unpkg.com/van-filter-search"></script>
</head>

<body>
  <div id="app">
    <van-filter-search title="筛选条件" :field-items="fieldItems" show-header />
  </div>

</body>
<script>
  const App = {
    components: {
      VanFilterSearch: window['van-filter-search'].VanFilterSearch
    },
    data() {
      return {
        fieldItems: [
          {
            type: 'InputField',
            title: '关键词查询',
            value: '',
            name: 'keyword',
            attrs: {
              placeholder: '输入搜索关键词',
            },
          },
          {
            type: 'RadioField',
            title: '任务状态',
            value: '0',
            name: 'status',
            attrs: {
              options: [
                { text: '未审核', value: '-1' },
                { text: '已审核', value: '0' },
                { text: '未通过', value: '1' },
                { text: '审核中', value: '2' },
                { text: '已退回', value: '3' },
              ],
            },
          },
          {
            type: 'CheckboxField',
            title: '紧急程度',
            value: [],
            name: 'level',
            attrs: {
              options: [
                { text: '普通', value: '0' },
                { text: '重要', value: '1' },
                { text: '紧急', value: '2' },
                { text: '特急', value: '3' },
              ],
            },
          },
          {
            type: 'DateField',
            title: '创建时间',
            value: '',
            name: 'createTime',
            attrs: {
              placeholder: '选择时间',
            },
          },
        ]
      }
    },
  };
  Vue.createApp(App).mount('#app');
</script>

</html>

API

属性

参数说明类型默认值
field-items对象数组,配置选项类型显示的数据FormItemOption[][]
title顶部栏标题string数据筛选
show-header是否显示顶部栏booleanfalse
show-close是否显示关闭图标booleantrue
confirm-button-text按钮确认文字string确 认
cancel-button-text取消按钮文字string取 消
theme-color选项选中状态颜色 (暂不支持)string#2e6cf3

事件

事件名说明回调参数
confirm点击确认按钮时触发selectedValues
cancel点击取消按钮时触发selectedValues
close关闭弹窗时触发selectedValues

插槽

名称说明参数

方法

方法说明参数返回值
confirm触发 confirm 事件--
cancel触发 cancel事件-
getSelectedValues获取已选中的选项-selectedValues

FormItemOption 数据结构

键名说明类型
type选项类型,可选值为 InputField RadioField CheckboxField DateField CellFieldstring
title选项标题string
value选项当前输入或选中的值any
name选项字段名称,作为提交时的标识符string
attrs当前对应选项组件属性-

选项组件属性

InputField(输入框)

propdescriptiontype
VanField 的 props支持 VanField 所有属性-

RadioField(单选项)

参数说明类型默认值
v-model当前选中的值any-
name选项字段名称,作为提交时的标识符string-
options对象数组,可选项数据源Option[][]
field-names自定义 options 结构中的字段object{ text: 'text', value: 'value'}
column-num每行显示几个选项numberstring
gutter选项之间的间距numberstring

CheckboxField(多选项)

参数说明类型默认值
v-model当前选中的值string[][]
name选项字段名称,作为提交时的标识符string-
options对象数组,可选项数据源Option[][]
field-names自定义 options 结构中的字段object{ text: 'text', value: 'value'}
column-num每行显示几个选项numberstring
gutter选项之间的间距numberstring

CellField(排序项)

参数说明类型默认值
v-model当前选中的值string-
name选项字段名称,作为提交时的标识符string-
options对象数组,可选项数据源Option[][]
field-names自定义 options 结构中的字段object{ text: 'text', value: 'value'}
column-num每行显示几个选项numberstring
gutter选项之间的间距numberstring
justify选项文本对齐方式,可选值为 center startstringcenter

DateField(日期选择)

参数说明类型默认值
v-model当前选中的日期string-
separator日期显示分隔符string'-'
VanFieldVanDatePickerVanPopup 的 propsVanField VanDatePicker VanPopup 属性参考文档[VanField](https://vant-contrib.gitee.io/vant/#/zh-CN/field)VanDatePickerVanPopup | -

Option 数据结构

参数说明类型
text选项文字内容string
value选项对应的值any
disabled是否禁用选项boolean
className选项额外类名(暂未支持)string
0.1.13

8 months ago

0.1.12

8 months ago

0.1.11

8 months ago

0.1.10

8 months ago

0.1.9

8 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago

0.0.0

8 months ago