﻿# nf-search-form {#search-form}

配置式搜索表单，支持数据联动、字段设置、查询、导出与校验。

字段设置（显隐和顺序）使用 IndexedDB 的 `common-ui-plus` 数据库、`nf-search-form` 对象仓库，以 `storageKey` 隔离。初始化时异步恢复；保存、清除和旧 `*Cookies*` 同步方法支持 `await`。IndexedDB 不可用时仅保留当前实例状态，不回退 localStorage，也不自动迁移旧缓存。表格内置搜索表单同样适用，通过 `searchFormStorageKey` 隔离。

```ts
import NfSearchForm from '@94ai-plus/nf-search-form'
import type { NfSearchFormItemOption, SearchFormInstance } from '@94ai-plus/nf-search-form'
import '@94ai-plus/nf-search-form/style.css'
```

## 用法大会萃 {#all-controls}

### 用法大会萃
```vue
<script setup lang="ts">
import { NfSearchForm } from '@94ai-plus/common-ui'
import { ElInput, ElButton, ElSelect, ElOption } from 'element-plus'
import { Search, Calendar } from '@element-plus/icons-vue'

import { ref } from 'vue'
const EXCHANGE_KEY_TYPE = {range:1,split:2}

const nfSearchFormRef = ref()

const columns = ref(6)
const inline = ref(true)
const labelPosition = ref('top')
const changeLabelPosition = (val) => {
  labelPosition.value = val
}

const isCollapseChange = (collapse) => {
   console.log(collapse)
}

const rules = ref({
   normalInputBox: [
    { required: true, message: '支持校验', trigger: 'change' },
    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'change' }
  ],
})

const btnItemList = ref([
  'search',
  'export',
  'reset',
  {
    name: '自定义配置按钮',
    onClick(formData) {
      console.log('点击了自定义按钮', formData);
    }
  },
  {
    name: '动态展示按钮show(formData)',
    show(formData) {
      return formData.showKey === '3'
    }
  }
]);

const submitForm = (formName) => {
  nfSearchFormRef.value?.onNfSearchFormValidate()
};
const resetForm = (formName) => {
  nfSearchFormRef.value?.resetNfSearchFormModel();
};

const testPage = async ({pageNo = 1, pageSize = 10, keyword = ''}) => {
  await new Promise(resolve => setTimeout(resolve, 150))
  const all = Array.from({length:100}, (_,value)=>({value:String(value), label:String(value)})).filter(row=>row.label.includes(keyword))
  return {records:all.slice((pageNo-1)*pageSize,pageNo*pageSize),total:all.length}
}
const searchOption = ref([
  {
    label: '普通输入框',
    prop: 'normalInputBox',
    element: 'el-input',
    width: '200px',
    category: '分类一',
    isShowColon: true
  },
  {
    label: '输入框带append',
    prop: 'normalInputBox2',
    element: 'el-input',
    width: '200px',
    category: '分类一',
    isShowColon: true,
    append: '元'
  },
  {
    label: '输入框带prepend',
    prop: 'normalInputBox3',
    element: 'el-input',
    width: '200px',
    category: '分类一',
    isShowColon: true,
    prepend: '前prepend'
  },
  {
    label: '数字输入框',
    prop: 'numberInputBox',
    element: 'el-input-number',
    width: '200px',
    category: '分类一'
  },
  {
    label: '普通下拉',
    prop: 'normalDropdown',
    element: 'el-select',
    'data-key': 'value',
    options: [
      { label: '给点意见', value: '1' },
      { label: '售后问题', value: '2' }
    ],
    category: '分类一'
  },
  {
    label: '动态展示show(formData)',
    prop: 'showKey',
    element: 'el-select',
    'data-key': 'value',
    options: [
      { label: '展示所属企业form-item', value: '1' },
      { label: '展示所属任务form-item', value: '2' },
      { label: '展示"动态展示按钮"', value: '3' },
    ],
    category: '分类一'
  },
  {
    label: '所属企业',
    prop: 'companyId',
    element: 'el-select',
    'data-key': 'value',
    options: [
      { label: '企业1', value: '1' },
      { label: '企业2', value: '2' }
    ],
    show(formData) {
      return formData.showKey === '1'
    },
    category: '分类一'
  },
  {
    label: '所属任务',
    prop: 'taskId',
    element: 'el-select',
    'data-key': 'value',
    options: [
      { label: '任务1', value: '1' },
      { label: '任务2', value: '2' }
    ],
    show(formData) {
      return formData.showKey === '2'
    },
    category: '分类一'
  },
  {
    label: 'changeProps下拉',
    prop: 'changePropsKey',
    element: 'el-select',
    'data-key': 'value',
    options: [
      { label: 'changeProps1', value: 1 },
      { label: 'changeProps2', value: 2 }
    ],
    changeProps: ['getOptionsKey'],
    category: '分类一'
  },
  {
    label: 'getOptions下拉',
    prop: 'getOptionsKey',
    element: 'el-select',
    'data-key': 'value',
    getOptions(callback, formData) {

      setTimeout(() => {
        callback([
          { label: 'getOptions1', value: '1' },
          { label: 'getOptions2', value: '2' }
        ])
      }, 150)
    },
    category: '分类一'
  },
  {
    label: '日期区间配置（exchangeKey）',
    prop: 'exchangeTime',
    type: 'daterange',
    element: 'el-date-picker',
    category: '分类二',
    exchangeKey: { type: EXCHANGE_KEY_TYPE.range, value: ['beginTime', 'endTime'] },
  },
  {
    label: '全选下拉',
    prop: 'multipleDropdown',
    element: 'nf-virtual-select',
    multiple: true,
    selectAll: true,
    selectAllText: '我全都要',
    'data-key': 'value',
    options: [{
      value: '选项1',
      label: '黄金糕'
    }, {
      value: '选项2',
      label: '双皮奶'
    }, {
      value: '选项3',
      label: '蚵仔煎'
    }, {
      value: '选项4',
      label: '龙须面'
    }, {
      value: '选项5',
      label: '北京烤鸭'
    }, {
      value: '选项6',
      label: '干炒牛河'
    }, {
      value: '选项7',
      label: '艇仔粥'
    }, {
      value: '选项8',
      label: '油条'
    }, {
      value: '选项9',
      label: '糯米鸡'
    }],
    category: '分类一'
  },
  {
    label: '虚拟下拉',
    prop: 'virtualDropdown',
    element: 'el-select',
    'data-key': 'value',
    virtualList: true,
    options: [
      { label: '给点意见', value: '1' },
      { label: '售后问题', value: '2' }
    ],
    category: '分类一'
  },
  {
    label: '分页虚拟下拉',
    prop: 'pageVirtualDropdown',
    element: 'nf-lazy-select',
    'data-key': 'value',
    virtualList: true,
    request: testPage,
    category: '分类一'
  },
  {
    label: '多选穿梭',
    prop: 'multipleChoiceShuttle',
    element: 'nf-transfer-select',
    initValue: [],
    options:[{
      value: '选项1',
      label: '黄金糕'
    }, {
      value: '选项2',
      label: '双皮奶'
    }, {
      value: '选项3',
      label: '蚵仔煎'
    }, {
      value: '选项4',
      label: '龙须面'
    }, {
      value: '选项5',
      label: '北京烤鸭'
    }],
    category: '分类一'
  },
  {
    label: '级联',
    prop: 'elCascader',
    element: 'el-cascader',
    'popper-class': 'nf-search-form-demo',
    options: [{
          value: 'zhinan',
          label: '指南',
          children: [{
            value: 'shejiyuanze',
            label: '设计原则',
            children: [{
              value: 'yizhi',
              label: '一致'
            }]
          }, {
            value: 'daohang',
            label: '导航',
            children: [{
              value: 'cexiangdaohang',
              label: '侧向导航'
            }]
          }]
        }, {
          value: 'zujian',
          label: '组件',
          children: [{
            value: 'basic',
            label: 'Basic',
            children: [{
              value: 'layout',
              label: 'Layout 布局'
            }]
          }]
        }, {
          value: 'ziyuan',
          label: '资源',
          children: [{
            value: 'axure',
            label: 'Axure Components'
          }]
        }],
    category: '分类一'
  },
   {
    label: '任意时间点',
    prop: 'anyPointInTime',
    element: 'el-time-picker',
    'picker-options': {
      start: '08:30',
      step: '00:10',
      end: '18:30'
    },
    category: '分类二'
  },
 {
    label: '任意时间区间',
    prop: 'anyTimeInterval',
    element: 'el-time-picker',
    'is-range': true,
    'picker-options': {
      start: '08:30',
      step: '00:10',
      end: '18:30'
    },
    category: '分类二'
  },
 {
    label: '年份选择',
    prop: 'year',
    type: 'year',
    element: 'el-date-picker',
    category: '分类二'
  },
   {
    label: '半年选择',
    prop: 'halfyear',
    element: 'nf-half-year-picker',
    category: '分类二'
  },
  {
    label: '季度选择',
    prop: 'quarter',
    element: 'el-date-picker',
    type: 'quarter',
    category: '分类二'
  },
 {
    label: '月份选择',
    prop: 'month',
    type: 'month',
    element: 'el-date-picker',
    category: '分类二'
  },
 {
    label: '周数选择',
    prop: 'week',
    type: 'week',
    element: 'el-date-picker',
    category: '分类二'
  },
 {
    label: '日期选择',
    prop: 'date',
    type: 'date',
    element: 'el-date-picker',
    category: '分类二'
  },
  {
    label: '日期区间',
    prop: 'daterange',
    type: 'daterange',
    element: 'el-date-picker',
    category: '分类二'
  },
   {
    label: '周区间',
    prop: 'weekrange',
    element: 'nf-week-range-picker',
    category: '分类二'
  },
 {
    label: '月份区间',
    prop: 'monthrange',
    type: 'monthrange',
    element: 'el-date-picker',
    category: '分类二'
},
  {
    label: '季度区间',
    prop: 'quarterrange',
    element: 'el-date-picker',
    type: 'quarterrange',
    category: '分类二'
  },
   {
    label: '半年区间',
    prop: 'halfyearrrange',
    element: 'nf-half-year-range-picker',
    category: '分类二'
  },
    {
    label: '年区间',
    prop: 'yearrrange',
    element: 'el-date-picker',
    type: 'yearrange',
    category: '分类二'
  },
  {
    label: '日期和时间点',
    prop: 'datetime',
    type: 'datetime',
    element: 'el-date-picker',
    category: '分类二'
  },
  {
    label: '日期和时间范围',
    prop: 'datetimerange',
    type: 'datetimerange',
    element: 'el-date-picker',
    category: '分类二'
  },
  {
    label: '固定时间',
    prop: 'fixedtime',
    element: 'el-time-select',
    'picker-options': {
      start: '08:30',
      step: '00:10',
      end: '18:30'
    },
    category: '分类三'
  },
 {
    label: '固定时间区间',
    prop: 'fixedTimeInterval',
    element: 'el-time-select',
    type: 'datetimerange',
    'picker-options': {
      start: '08:30',
      step: '00:10',
      end: '18:30'
    },
    category: '分类三'
  },
  {
    label: '数字区间',
    prop: 'numberRange',
    element: 'number-range',
    initValue: [],
    min: 0,
    category: '分类三',
    class: 'number-range-box',
    width: 334,
    inputSlot: {
      append: 'repeatCountAppend',
      doubleAppend: 'doubleRepeatCountAppend',
      doubleSegment: 'doubleRepeatCountAppendSegment',
    },
    tag: 'el-input',
    events: {
       input: (val) => {
          let flag = false
          const val0 = val[0]?.replace(/[^0-9]/g, '')
          const val1 = val[1]?.replace(/[^0-9]/g, '')
          if (val[0] && val0 != val[0]) {
            flag = true
          }
          if (val[1] && val1 != val[1]) {
            flag = true
          }
          if (flag) nfSearchFormRef.value?.setNfSearchFormModel({numberRange:[val0,val1]})
        }
    }
  },
  {
    label: '自定义slot',
    prop: 'custumSlot',
    slot: 'custumSlot',
    category: '分类四',
  },
])

const searchForm = ref({
  custumSlot: ''
})

const searchFn = (data) => {
  console.log(data)
  searchForm.value = {
    ...searchForm.value,
    ...data
  }
}
const resetFieldsFn = () => {
  searchForm.value.custumSlot = ''
}
const exportFn = (data) => {
  console.log(data)
}

</script>

<template>
<div class='nf-search-form-demo1 nf-search-form-demo-all'>

    <nf-search-form
        :form-options="searchOption"
        :rules='rules'

        :columns='columns'
        @isCollapseChange="isCollapseChange"

        :btn-items="btnItemList"
        @onSearch="searchFn"
        @onExport="exportFn"
        @onResetFields='resetFieldsFn'

        :closable='true'
        storage-key='nf-search-form-test1-zh'
        :column-edit='true'
        check-mode='dialog'

        :inline='inline'
        :label-position='labelPosition'
        btn-model='inline'
        btn-box-label='自定按钮slot定制的内容 + 默认按钮：'

        ref='nfSearchFormRef'
     >

        <template #repeatCountAppend><span >Not</span></template>
        <template #doubleRepeatCountAppend><span >In</span></template>
        <template #doubleRepeatCountAppendSegment><span>→</span></template>

       <template #custumSlot="{formData}"><el-input

         v-model="formData.custumSlot"
         placeholder='请输入'
         clearable
         :prefix-icon="Search"
         :suffix-icon="Calendar"
         style='display:inline-block;width: 100%'
       /></template>

       <template #btnBox><span  style='align-self: self-start;margin-right: 10px;'>
         <div>
             <el-button size="small" @click='inline=!inline'>切换块级</el-button>
             <el-button size="small" @click='columns++'>增加折叠个数</el-button>
             <el-button size="small" @click='columns=Math.max(1,columns-1)'>减少折叠个数</el-button>
         </div>
         <div>
             <el-button size="small" @click='changeLabelPosition("top")'>表单项前缀向上</el-button>
             <el-button size="small" @click='changeLabelPosition("right")'>表单项前缀向右</el-button>
         </div>
         <div>
             <el-button size="small" @click='changeLabelPosition("left")'>表单项前缀向左</el-button>
            <el-button size="small" type="primary" @click="submitForm()">表单校验</el-button>
            <el-button size="small" @click="resetForm()">重置校验</el-button>
         </div>
       </span></template>
    </nf-search-form>
  </div>

<pre class="search-result" aria-live="polite">{{ JSON.stringify(searchForm, null, 2) }}</pre>
</template>

<style scoped>
.search-result {max-height:240px;overflow:auto;white-space:pre-wrap}
:deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0 16px}
:deep(.nf-search-form-item) {max-width:100%;margin-right:0}
:deep(.el-form-item__content) {min-width:0;flex-wrap:wrap;gap:8px}
:deep(.el-divider--horizontal) {margin:40px 0} :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
@media(max-width:600px){:deep(.nf-search-form-control){max-width:100%!important} :deep(.el-form-item){flex-direction:column;align-items:stretch} :deep(.el-form-item__label){width:auto!important;justify-content:flex-start}}

</style>
```

## 表单block/inline模式 {#basic}

### 表单block/inline模式
```vue
<script setup lang="ts">
import { NfSearchForm } from '@94ai-plus/common-ui'
import { ElDivider } from 'element-plus'
import { Search, Calendar } from '@element-plus/icons-vue'

import { ref } from 'vue';

function deepClone(source) {
  if (!source && typeof source !== 'object') {
    throw new Error('error arguments shallowClone')
  }
  const targetObj: Record<string, any> | Record<string, any>[] = source.constructor === Array ? [] : {}
  Object.keys(source).forEach((keys) => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = source[keys].constructor === Array ? [] : {}
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}

const searchForm = ref({})

const searchFn = (data) => {
  searchForm.value = {
    ...searchForm.value,
    ...data
  }
}
const resetFieldsFn = () => {
  searchForm.value.custumSlot = ''
}
const exportFn = (data) => {
  console.log(data)
}

const searchOption2 = ref([
  {
    label: '普通输入框',
    prop: 'normalInputBox',
    element: 'el-input',
    width: '200px',
    category: '分类一'
  },
  {
    label: '数字输入框',
    prop: 'numberInputBox',
    element: 'el-input-number',
    width: '200px',
    category: '分类一'
  },
  {
    label: '普通下拉',
    prop: 'normalDropdown',
    element: 'el-select',
    'data-key': 'value',
    options: [
      { label: '给点意见', value: '1' },
      { label: '售后问题', value: '2' }
    ],
    category: '分类一'
  },
  {
    label: '虚拟下拉',
    prop: 'virtualDropdown',
    element: 'el-select',
    'data-key': 'value',
    virtualList: true,
    options: [
      { label: '给点意见', value: '1' },
      { label: '售后问题', value: '2' }
    ],
    category: '分类一'
  },
])

const searchOption5 = ref(deepClone(searchOption2.value));
const searchOption6 = ref(deepClone(searchOption2.value));
const searchOption7 = ref(deepClone(searchOption2.value));
const searchOption8 = ref(deepClone(searchOption2.value));
const searchOption9 = ref(deepClone(searchOption2.value));

</script>

<template>
<div class='nf-search-form-demo2'>
    <div class='nf-search-form-demo-inline-inline'>
      <nf-search-form
        storage-key='nf-search-form-test2-zh'
        :columns='2'
        :form-options="searchOption2"
        :btn-items="['search', 'export', 'reset']"
        @onSearch="searchFn"
        @onExport="exportFn"
        @onResetFields='resetFieldsFn'
        label-position='right'
        :column-edit='true'
      />
     </div>

     <el-divider>操作按钮block模式：上面label inline模式 </el-divider>

     <el-divider>操作按钮block模式：下面label block模式 </el-divider>

      <div class='nf-search-form-demo-inline-inline'>
         <nf-search-form
          storage-key='nf-search-form-test3-zh'
          :columns='2'
          :form-options="searchOption5"
          :btn-items="['search', 'export', 'reset']"
          @onSearch="searchFn"
          @onExport="exportFn"
          @onResetFields='resetFieldsFn'
          :column-edit='true'
        />
      </div>

     <el-divider>操作按钮block模式：上面form inline模式 </el-divider>

     <el-divider>操作按钮block模式：下面form block模式 </el-divider>

      <div class='nf-search-form-demo-inline-inline'>
         <nf-search-form
          storage-key='nf-search-form-test4-zh'
          :columns='2'
          :form-options="searchOption6"
          :btn-items="['search', 'export', 'reset']"
          @onSearch="searchFn"
          @onExport="exportFn"
          :inline='false'
          @onResetFields='resetFieldsFn'
          :column-edit='true'
        />
      </div>

     <el-divider style='font-weight: 700;'>以上操作按钮block模式(block模式默认按钮和自定义按钮slot 独立一行) </el-divider>

     <br />

     <el-divider style='font-weight: 700;'>以下操作按钮inline模式 (inline模式默认按钮和自定义按钮slot 额外作为最后form-item包裹)</el-divider>

    <div class='nf-search-form-demo-inline-inline'>
       <nf-search-form
         storage-key='nf-search-form-test5-zh'
        :columns='3'
        :form-options="searchOption7"
        :btn-items="['search', 'export', 'reset']"
        @onSearch="searchFn"
        @onExport="exportFn"
        @onResetFields='resetFieldsFn'
        btn-model='inline'
        label-position='right'
        :column-edit='true'
      />
    </div>

     <el-divider>操作按钮inline模式：上面label inline模式 </el-divider>

     <el-divider>操作按钮inline模式：下面label block模式 </el-divider>

    <div class='nf-search-form-demo-inline-block'>
      <nf-search-form
         storage-key='nf-search-form-test6-zh'
        :columns='3'
        :form-options="searchOption8"
        :btn-items="['search', 'export', 'reset']"
        @onSearch="searchFn"
        @onExport="exportFn"
        @onResetFields='resetFieldsFn'
        btn-model='inline'
        :column-edit='true'
      />
    </div>

     <el-divider>操作按钮inline模式：上面form inline模式 </el-divider>

     <el-divider>操作按钮inline模式：下面form block模式 </el-divider>

     <div class='nf-search-form-demo-inline-block'>
      <nf-search-form
         storage-key='nf-search-form-test7-zh'
        :columns='3'
        :form-options="searchOption9"
        :btn-items="['search', 'export', 'reset']"
        @onSearch="searchFn"
        @onExport="exportFn"
        @onResetFields='resetFieldsFn'
        btn-model='inline'
        :inline='false'
        :column-edit='true'
      />
    </div>
  </div>

<pre class="search-result" aria-live="polite">{{ JSON.stringify(searchForm, null, 2) }}</pre>
</template>

<style scoped>
.search-result {max-height:240px;overflow:auto;white-space:pre-wrap}
:deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0 16px}
:deep(.nf-search-form-item) {max-width:100%;margin-right:0}
:deep(.el-form-item__content) {min-width:0;flex-wrap:wrap;gap:8px}
:deep(.el-divider--horizontal) {margin:40px 0} :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
@media(max-width:600px){:deep(.nf-search-form-control){max-width:100%!important} :deep(.el-form-item){flex-direction:column;align-items:stretch} :deep(.el-form-item__label){width:auto!important;justify-content:flex-start}}

</style>
```

## 最简单用法 {#linked}

### 最简单用法
```vue
<script setup lang="ts">
import { NfSearchForm } from '@94ai-plus/common-ui'
import { ElDivider } from 'element-plus'
import { Search, Calendar } from '@element-plus/icons-vue'

import { ref } from 'vue';

function deepClone(source) {
  if (!source && typeof source !== 'object') {
    throw new Error('error arguments shallowClone')
  }
  const targetObj: Record<string, any> | Record<string, any>[] = source.constructor === Array ? [] : {}
  Object.keys(source).forEach((keys) => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = source[keys].constructor === Array ? [] : {}
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}

const searchForm = ref({})

const searchFn = (data) => {

  searchForm.value = {
    ...searchForm.value,
    ...data
  }
}

const searchOption3 = ref([
  {
    label: '普通输入框',
    prop: 'normalInputBox',
    element: 'el-input',
    width: '200px',
    category: '分类一'
  },
  {
    label: '数字输入框',
    prop: 'numberInputBox',
    element: 'el-input-number',
    width: '200px',
    category: '分类一'
  },
])
const searchOption4 = [...searchOption3.value, {
    label: '数字输入框',
    prop: 'numberInputBox2',
    element: 'el-input-number',
    width: '200px',
    category: '分类一'
}]

const searchOption12 = ref(deepClone(searchOption3.value))
const searchOption13 = ref(deepClone(searchOption3.value))
const searchOption14 = ref(deepClone(searchOption3.value))
const searchOption15 = ref(deepClone(searchOption3.value))
const searchOption16 = ref(deepClone(searchOption3.value))

const searchOption17 = ref(deepClone(searchOption4))

</script>

<template>
<div class='nf-search-form-demo3'>
       <div class='nf-search-form-demo-inline-inline'>
        <nf-search-form
          storage-key='nf-search-form-test8-zh'
          :form-options="searchOption3"
          @onSearch="searchFn"
          :btn-items="['search']"
          btn-model='inline'
          label-position='left'
          :column-edit='true'
          check-mode='dialog'
        />
     </div>
     <el-divider>上面没有折叠 + (btn-model=inline) + (form=inline) + (labelPosition=left)</el-divider>
     <div class='nf-search-form-demo-inline-inline'>
        <nf-search-form
          storage-key='nf-search-form-test9-zh'
          :form-options="searchOption12"
           @onSearch="searchFn"
          :btn-items="['search']"
           btn-model='inline'
           :column-edit='true'
           check-mode='dialog'
        />
     </div>
     <el-divider>上面没有折叠 + (btn-model=inline) + (form=inline) + (labelPosition=top)</el-divider>
      <div class='nf-search-form-demo-inline-inline'>
        <nf-search-form
          storage-key='nf-search-form-test10-zh'
          :columns='2'
          :form-options="searchOption13"
          @onSearch="searchFn"
          :btn-items="['search']"
          btn-model='inline'
          label-position='left'
          :column-edit='true'
           check-mode='dialog'
        />
     </div>
     <el-divider>上面有折叠 + (btn-model=inline) + (form=inline) + (labelPosition=left)</el-divider>
     <div class='nf-search-form-demo-inline-inline'>
        <nf-search-form
          storage-key='nf-search-form-test11-zh'
          :columns='2'
          :form-options="searchOption14"
          @onSearch="searchFn"
          :btn-items="['search']"
           btn-model='inline'
           :column-edit='true'
           check-mode='dialog'
        />
     </div>
     <el-divider>上面有折叠 + (btn-model=inline) + (form=inline) + (labelPosition=top)</el-divider>
     <div style='display: flex'>
       <nf-search-form
         storage-key='nf-search-form-test12-zh'
        :form-options="searchOption15"
        @onSearch="searchFn"
        :btn-items="['search']"
        btn-model='inline'
        :inline='false'
        :column-edit='true'
         check-mode='dialog'
       />
       <nf-search-form
         storage-key='nf-search-form-test13-zh'
        :form-options="searchOption4"
        @onSearch="searchFn"
        :btn-items="['search']"
        label-position="right"
        btn-model='inline'
        :inline='false'
        :column-edit='true'
        check-mode='dialog'
       />
     </div>
     <el-divider>上面没有折叠 + (btn-model=inline) + (form=block) + (labelPosition=top/right)</el-divider>
     <br />
     <el-divider>下面有折叠 + (btn-model=inline) + (form=block) + (labelPosition=top/right)</el-divider>
      <div style='display: flex'>
       <nf-search-form
        storage-key='nf-search-form-test14-zh'
       :columns='2'
        :form-options="searchOption16"
        @onSearch="searchFn"
        :btn-items="['search']"
        btn-model='inline'
        :inline='false'
        :column-edit='true'
        check-mode='dialog'
       />
       <nf-search-form
         storage-key='nf-search-form-test15-zh'
        :columns='3'
        :form-options="searchOption17"
        @onSearch="searchFn"
        :btn-items="['search']"
        label-position="right"
        btn-model='inline'
        :inline='false'
        :column-edit='true'
        check-mode='dialog'
       />
     </div>
  </div>

<pre class="search-result" aria-live="polite">{{ JSON.stringify(searchForm, null, 2) }}</pre>
</template>

<style scoped>
.search-result {max-height:240px;overflow:auto;white-space:pre-wrap}
:deep(.el-form--inline) {display:flex;flex-wrap:wrap;gap:0 16px}
:deep(.nf-search-form-item) {max-width:100%;margin-right:0}
:deep(.el-form-item__content) {min-width:0;flex-wrap:wrap;gap:8px}
:deep(.el-divider--horizontal) {margin:40px 0} :deep(.el-divider__text) {max-width:90%;white-space:normal;font-size:12px}
@media(max-width:600px){:deep(.nf-search-form-control){max-width:100%!important} :deep(.el-form-item){flex-direction:column;align-items:stretch} :deep(.el-form-item__label){width:auto!important;justify-content:flex-start}}

</style>
```

## NfSearchFormItemOption {#item-options}

| 参数 | 说明 | 类型 |
| --- | --- | --- |
| prop | 字段路径，关联表单数据。 | string |
| label | 字段标签，可按表单数据动态计算。 | string / Function |
| element / component | 内置名称或自定义 Vue 3 组件。 | string / Component |
| initValue | 字段初始值。 | unknown |
| options | 静态选项。 | object[] |
| getOptions | 异步选项回调，done 返回列表；支持 Promise。 | (done, model) =&gt; void / Promise |
| changeProps | 当前值变化后重新加载的依赖字段。 | string[] |
| exchangeKey | 提交数据转换；type=1 拆分区间，type=2 拆分字符串。 | { type: number; value: string / string[] } |
| show | 动态显示；false 时不渲染字段。 | boolean / Function |
| hidden | 始终显示但不参与折叠。 | boolean |
| destroy / destory | 动态销毁字段，兼容旧拼写。 | boolean / Function |
| initHidden | 初始不显示，可在字段设置中恢复。 | boolean |
| slot / labelSlot / tooltip.slot | 字段内容、标签和提示插槽名称。 | string |
| inputSlot | 输入框和区间两端插槽映射。 | object |
| events | 输入控件事件；change 接收当前值、保留参数和表单数据。 | object |
| rules / required | 字段校验规则与必填状态。 | object / boolean |
| width / labelWidth | 内容及标签宽度。 | string / number |
| category | 字段设置中的分组名称。 | string |

## Attribute {#props}

| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- |
| formOptions | 【json data】渲染表单框架数据 | NfSearchFormItemOption[] | — | [] |
| columns | 超过指定表单项个数折叠；未设置时根据容器宽度检测。 | number | — | 3 |
| upIcon | 【折叠功能】按钮展开图标 | string | — | 'icon-xiangshang2' |
| downIcon | 【折叠功能】按钮收起图标 | string | — | 'icon-xiangxia2' |
| showBtn | 【折叠功能】按钮显示隐藏，可以开启关闭折叠功能 | boolean | — | true |
| isCollapse | 【折叠功能】初始化是否展开 | boolean | — | false |
| expandBtnIcon | 展开按钮icon | string | — | — |
| expandBtnType | 展开按钮type | string | — | default |
| expandBtnPlain | 展开按钮plain | boolean | — | false |
| expandBtnSize | 展开按钮size | string | mini/small/medium | — |
| expandBtnRound | 展开按钮round | boolean | — | false |
| expandBtnCircle | 展开按钮circle | boolean | — | false |
| expandBtnLoading | 展开按钮loading | boolean | — | false |
| expandBtnDisabled | 展开按钮disabled | boolean | — | false |
| expandBtnTooltipDesc | 展开按钮tooltip描述 | string | — | 跟随语言包 |
| shrinkBtnTooltipDesc | 收起按钮tooltip描述 | string | — | 跟随语言包 |
| defaultFormData | 初始化表单数据对象；Vue 3 双向绑定使用 v-model。 | object | — | {} |
| rules | 【表单功能】校验规则 | object | — | undefined |
| labelWidth | 【表单功能】 表单域label的宽度，例如 '50px'。作为 Form 直接子元素的 form-item 会继承该值。支持 auto。 | number / string | — | 150 |
| itemWidth | 【表单功能】每个search form item content的宽度定制，实现表单项对齐，如果需要单独做一个定制宽度，form-options的每个item传入width即可 | number | — | 227 |
| labelSuffix | 【表单功能】域标签的后缀 | string | — | undefined |
| hideRequiredAsterisk | 【表单功能】是否隐藏必填字段的标签旁边的红色星号 | boolean | — | false |
| showMessage | 【表单功能】是否显示校验错误信息 | boolean | — | true |
| inlineMessage | 【表单功能】是否以行内形式展示校验信息 | boolean | — | false |
| statusIcon | 【表单功能】是否在输入框中显示校验结果反馈图标 | boolean | — | false |
| validateOnRuleChange | 【表单功能】是否在 rules 属性改变后立即触发一次验证 | boolean | — | true |
| size | 表单及按钮尺寸；兼容 mini→small、medium→default。 | string | mini/small/medium | 'mini' |
| disabled | 【表单功能】是否禁用该表单内的所有组件。若设置为 true，则表单内组件上的 disabled 属性不再生效 | boolean | — | false |
| btnModel | 【表单功能】操作按钮是否换行 | string | block/inline | 'block' |
| labelPosition | 【表单功能】标签位置 | string | — | 'top' |
| inline | 【表单功能】行内 | boolean | — | true |
| btnBoxLabel | 自定义按钮slot的label | string | — | '' |
| closable | 是否显示【控制表单列目项隐藏的icon】，用来控制隐藏表单列目项 | boolean | — | false |
| columnEdit | 是否显示【列编辑按钮】，用来开启显示隐藏表单列目项 | boolean | — | false |
| checkMode | 设置列编辑功能的交互模式 | string | dialog/drawer | 'drawer' |
| storageKey | 字段设置的 IndexedDB 缓存键；同页多实例应使用独立键。 | string | - | nf-search-form-columns-cached-key-${routeName} |
| priority | 缓存回显优先级，处理item.initHidden,form.showColumn和IndexedDB.cache的回显关系 | string | cached/value | 'cached' |
| showItems | 【json data】渲染的表单列目项prop属性集合，用来初始化控制哪些表单列目项显示隐藏，其中[]会全部显示,可以和columns的initHidden配合使用 | string[] | — | undefined |
| checkBtnIcon | 列编辑按钮icon | string | - | - |
| checkBtnType | 列编辑按钮type | string | - | - |
| checkBtnPlain | 列编辑按钮plain | boolean | - | true |
| checkBtnSize | 列编辑按钮size | mini/small/medium | - | — |
| checkBtnRound | 列编辑按钮round | boolean | - | false |
| checkBtnCircle | 列编辑按钮circle | boolean | - | false |
| checkBtnLoading | 列编辑按钮loading | boolean | - | false |
| checkBtnDisabled | 列编辑按钮disabled | boolean | - | false |
| checkBtnClass | 列编辑按钮class | string | - | - |
| columnDisplayBtnText | 列编辑按钮tooltip文本 | string | - | 跟随语言包 |
| moreDialogTitle | 列编辑dialog/drawer模式-&gt;弹框标题 | string | — | 跟随语言包 |
| columnCheckCancelButtonText | 列编辑dialog/drawer模式取消按钮文本 | string | - | '取消' |
| columnCheckConfirmButtonText | 列编辑dialog/drawer模式确定按钮文本 | string | - | '确定' |
| columnCheckBasicFieldDesc | 默认category分类标题 | string | - | 跟随语言包 |
| columnCheckTabs | 列编辑drawer模式-&gt;控制渲染tabs的数据 | ITabItem[] | - | - |
| columnCheckCurrentTab | 列编辑drawer模式-&gt;当前显示的tab名称 | string | - | - |
| selectEmptyWarningTips | 设置列编辑时清空所有列告警提示，默认不允许隐藏所有表单列目项 | string | - | 请选择至少一个选项 |
| columnCheckSearchPlaceholder | 列编辑drawer模式-&gt;搜索框placeholder | string | - | '搜索' |
| columnCheckFixedLeftDesc | 兼容字段；搜索表单的字段设置不提供固定列功能。 | string | - | 跟随语言包 |
| columnCheckClearDesc | 列编辑drawer模式-&gt;清除描述 | string | - | 跟随语言包 |
| columnCheckNoFixedDesc | 兼容字段；搜索表单的字段设置不提供固定列功能。 | string | - | 跟随语言包 |
| columnCheckGetCheckedLengthDesc | 列编辑drawer模式-&gt;已选描述 | (length) =&gt; string | - | (length) =&gt; '已选（' + length + '）' |
| columnCheckGetAllCheckDesc | 列编辑drawer模式-&gt;全选描述 | (length) =&gt; string | - | (length) =&gt; '全选（' + length + '） |
| moreDialogWidth | 列编辑dialog模式-&gt;弹框度度 | string | — | '600px' |
| modalAppendToBody | 列编辑dialog模式-&gt;弹框遮罩层是否插入至 body 元素上，若为 false，则遮罩层会插入至 Dialog 的父元素上 | boolean | — | true |
| modal | 列编辑dialog模式-&gt;弹框是否需要遮罩层 | boolean | — | true |
| fullscreen | 列编辑dialog模式-&gt;弹框是否为全屏 Dialog | boolean | — | false |
| top | 列编辑dialog模式-&gt;弹框Dialog CSS 中的 margin-top 值 | string | — | '15vh' |
| appendToBody | 列编辑dialog模式-&gt;弹框Dialog 自身是否插入至 body 元素上。嵌套的 Dialog 必须指定该属性并赋值为true | boolean | — | false |
| lockScroll | 列编辑dialog模式-&gt;弹框是否在Dialog 出现时将 body 滚动锁定 | boolean | — | true |
| customClass | 列编辑dialog模式-&gt;弹框Dialog 的自定义类名 | string | — | ' |
| closeOnlickModal | 列编辑dialog模式-&gt;弹框是否可以通过点击 modal 关闭 Dialog | boolean | — | true |
| closeOnPressEscape | 列编辑dialog模式-&gt;弹框是否可以通过按下 ESC 关闭 Dialog | boolean | — | true |
| showClose | 列编辑dialog模式-&gt;弹框是否显示关闭按钮 | boolean | — | true |
| beforeClose | 列编辑dialog模式-&gt;弹框关闭前的回调，会暂停 Dialog 的关闭 | Function | — | undefined |
| center | 列编辑dialog模式-&gt;弹框是否对头部和底部采用居中布局 | boolean | — | false |
| destroyOnClose | 列编辑dialog模式-&gt;弹框关闭时销毁 Dialog 中的元素 | boolean | — | false |
| btnItems | 【默认按钮】显示哪些默认内定的按钮 | string[]/IBtnItems[] / 'search'、'export'、'reset'、'' | — | '' |
| reverseBtnSlot | 【默认按钮】反转自定义按钮slot和默认按钮的顺序 | boolean | — | false |
| exportBtnIcon | 【导出按钮】图标 | string | — | '' |
| exportBtnType | 【导出按钮】类型 | string | — | 'primary' |
| exportBtnPlain | 【导出按钮】镂空 | boolean | — | true |
| exportBtnSize | 【导出按钮】尺寸 | mini/small/medium | — | — |
| exportBtnRound | 【导出按钮】圆角 | boolean | — | false |
| exportBtnCircle | 【导出按钮】圆形 | boolean | — | false |
| exportBtnLoading | 【导出按钮】Loading | boolean | — | false |
| exportBtnDisabled | 【导出按钮】禁用 | boolean | — | false |
| exportBtnText | 【导出按钮】文本 | string | — | 跟随语言包 |
| exportBtnClass | 【导出按钮】类名 | string | — | '' |
| queryBtnIcon | 【查询按钮】图标 | string | — | '' |
| queryBtnType | 【查询按钮】类型 | string | — | 'primary' |
| queryBtnPlain | 【查询按钮】镂空 | boolean | — | true |
| queryBtnSize | 【查询按钮】尺寸 | mini/small/medium | — | — |
| queryBtnRound | 【查询按钮】圆角 | boolean | — | false |
| queryBtnCircle | 【查询按钮】圆形 | boolean | — | false |
| queryBtnLoading | 【查询按钮】Loading | boolean | — | false |
| queryBtnDisabled | 【查询按钮】禁用 | boolean | — | false |
| queryBtnText | 【查询按钮】文本 | string | — | 跟随语言包 |
| queryBtnClass | 【查询按钮】类名 | string | — | '' |
| resetBtnIcon | 【重置按钮】图标 | string | — | '' |
| resetBtnType | 【重置按钮】类型 | string | — | 'default' |
| resetBtnPlain | 【重置按钮】镂空 | boolean | — | true |
| resetBtnSize | 【重置按钮】尺寸 | mini/small/medium | — | — |
| resetBtnRound | 【重置按钮】圆角 | boolean | — | false |
| resetBtnCircle | 【重置按钮】圆形 | boolean | — | false |
| resetBtnLoading | 【重置按钮】Loading | boolean | — | false |
| resetBtnDisabled | 【重置按钮】禁用 | boolean | — | false |
| resetBtnText | 【重置按钮】文本 | string | — | 跟随语言包 |
| resetBtnClass | 【重置按钮】类名 | string | — | '' |
| modelValue | 表单数据；使用 v-model 双向绑定。 | SearchFormModel | — | undefined |
| requiredValidate | 查询和导出前是否先校验。 | boolean | — | false |
| components | 扩展表单控件映射。 | Record&lt;string, Component&gt; | — | undefined |
| viewIdentity | 视图或用户配置标识。 | string | — | undefined |
| isMvc | 使用外部数据模式。 | boolean | — | false |

## Attribute IBtnItems {#button-options}

| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- |
| btnType | 【按钮类型】（'search'、'export'、'reset'、''、undefined） | string | 可选 | undefined |
| name | 按钮名称 | string | 可选 | undefined |
| type | nf-button属性 | - | 可选 | Attribute.queryBtnType |
| icon | nf-button属性 | - | 可选 | Attribute.queryBtnIcon |
| plain | nf-button属性 | - | 可选 | Attribute.queryBtnPlain |
| size | nf-button属性 | - | 可选 | Attribute.size |
| round | nf-button属性 | - | 可选 | Attribute.queryBtnRound |
| circle | nf-button属性 | - | 可选 | Attribute.queryBtnCircle |
| loading | nf-button属性 | - | 可选 | Attribute.queryBtnLoading |
| disabled | nf-button属性 | - | 可选 | Attribute.queryBtnDisabled |
| class | className | string、object | 可选 | undefined |
| validate | 是否校验表单后触发onClick事件 | boolean | 可选 | false |
| onClick | 点击事件 | (formData: 当前表单数据) =&gt; void | 可选 | undefined |
| show | 是否显示 | (formData: 当前表单数据) =&gt; boolean | 可选 | undefined |

## Event {#events}

| 事件名称 | 说明 | 回调参数 |
| --- | --- | --- |
| open | 列编辑dialog模式-&gt;弹框打开的回调 | — |
| opened | 列编辑dialog模式-&gt;弹框打开动画结束时的回调 | — |
| close | 列编辑dialog模式-&gt;弹框关闭的回调 | — |
| closed | 列编辑dialog模式-&gt;弹框关闭动画结束时的回调 | — |
| changeTab | 列编辑drawer模式-&gt;切换多个drawer tab | name |
| cancel | 列编辑drawer模式-&gt;关闭drawer | Event |
| onSearch | 点击查询或调用查询方法时触发，数据已按 exchangeKey 转换。 | (data, refresh: boolean) |
| onExport | 导出回调，传入转换后的表单数据。 | data: SearchFormModel |
| onResetFields | 重置表单后触发。 | — |
| onChange | 表单数据变化。 | model: SearchFormModel |
| itemsChange | 字段显示列表变化。 | items: string[] |
| update:modelValue | 用于 v-model。 | model: SearchFormModel |
| update:showItems | 用于 v-model:showItems。 | items: string[] |
| isCollapseChange | 表单展开状态变化；true 表示展开。 | expanded: boolean |
| options-error | 异步选项加载失败。 | (error, prop: string) |

## Slot {#slots}

| 名称 | 说明 |
| --- | --- |
| btnBox | 兼容ai-search-form扩展操作按钮 |
| dialogTitle | 列编辑dialog模式-&gt;弹框title |
| dialogFooter | 列编辑dialog模式-&gt;弹框footer |
| columCheckTitle | 列编辑drawer模式-&gt;弹框title |
| columCheckFooter | 列编辑drawer模式-&gt;弹框footer |
| NfSearchFormItemOption.tooltip.slot | 定制化每个SearhFormItem的图标tooltip |
| NfSearchFormItemOption.slot | 定制化每个SearhFormItem |
| NfSearchFormItemOption.inputSlot | 定制 prepend／append／prefix／suffix 及数字区间两端插槽。 |
| NfSearchFormItemOption.labelSlot | 定制字段标签。 |

## Expose {#methods}

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| localShowItems | string[] | 列编辑显示的列prop |
| getFormData | Function | 获取表单实时数据（已深拷贝） |
| syncLocalShowColumnToCookies | Function | 列编辑同步组件到IndexedDB |
| syncCookiesToLocalShowColumn | Function | 列编辑同步IndexedDB到组件localShowItems |
| syncShowItemToInitHidden | Function | showItems同步props.formOptions[i].initHidden |
| hiddenNfSearchFormItemOptionField | Function | 列编辑隐藏某个表单列目 |
| refreshNfSearchFormModel | Function | 列编辑操作后刷新表单数据模式 |
| renderSearchFormItemOptions | NfSearchFormItemOption[] | 渲染表单项 |
| resetNfSearchFormModel | Function | 重置 |
| onNfSearchFormValidate | Function | 校验 |
| onNfSearchFormSearch | Function | 搜索 |
| onNfSearchFormExport | Function | 导出 |
| nfSearchFormModel | Record | 表单数据 |
| nfSearchFormRef | Ref | 表单 ref |
| columnCheckNfDrawer | Ref | 列编辑nf-drawer ref |
| configNfSearchItemVisibleDialog | Boolean | 列编辑控制dialog/drawer显示/隐藏 |
| syncCookiesToTableColumn | Function | syncCookiesToLocalShowColumn |
| setNfSearchFormModel(model) | Function | 通过字段路径合并表单值。 |
| clearColumnEditCached() | Function | 清除字段设置缓存。 |
| clearDragCached() | Function | 清除拖拽缓存。 |

## 使用说明 {#configuration-notes}

示例标题、布局组合及功能对齐 common-ui。季度、半年和周区间通过示例内 components 扩展演示，不属于当前内置控件；值使用年与周期标识。内置控件使用 Vue 3 v-model，旧虚拟下拉使用 virtualList 配置。
