This commit is contained in:
+3
-2
@@ -6,6 +6,7 @@ import {
|
||||
buildFilters,
|
||||
createFieldState,
|
||||
groupRows,
|
||||
resolveQueryOption,
|
||||
} from './composables/useFilters.js';
|
||||
import UnknownPlaceholder from './components/UnknownPlaceholder.vue';
|
||||
const props = defineProps({
|
||||
@@ -114,7 +115,7 @@ defineExpose({ getFilters, setFilters, loadFilters, reset });
|
||||
:disabled="state[fieldDef.field]?.disabled"
|
||||
>
|
||||
<option
|
||||
v-for="opt in fieldDef['query-option'] || []"
|
||||
v-for="opt in resolveQueryOption(fieldDef)"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
@@ -131,7 +132,7 @@ defineExpose({ getFilters, setFilters, loadFilters, reset });
|
||||
:placeholder="fieldDef['field-name']"
|
||||
:field="fieldDef.field"
|
||||
:field-name="fieldDef['field-name']"
|
||||
:query-option="fieldDef['query-option'] || []"
|
||||
:query-option="resolveQueryOption(fieldDef)"
|
||||
:schema="fieldDef"
|
||||
:options="fieldDef.options || []"
|
||||
/>
|
||||
|
||||
@@ -15,6 +15,22 @@
|
||||
* @property {string} [query]
|
||||
*/
|
||||
|
||||
import { getDefaultQueryOption } from '../config.js';
|
||||
|
||||
/**
|
||||
* 解析字段的查询操作符列表:
|
||||
* - schema 显式配置了 query-option 时,优先使用字段自己的;
|
||||
* - 否则若配置了自定义 query-component(操作符由组件自己管理),返回空数组、不套默认;
|
||||
* - 否则返回默认操作符列表(getDefaultQueryOption 深拷贝,调用方可安全修改)。
|
||||
* @param {SchemaField} [fieldDef]
|
||||
* @returns {Array<{value: string, label?: string}>}
|
||||
*/
|
||||
export function resolveQueryOption(fieldDef) {
|
||||
if (fieldDef?.['query-option']) return fieldDef['query-option'];
|
||||
if (fieldDef?.['query-component']) return [];
|
||||
return getDefaultQueryOption();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {SchemaField[]} schema
|
||||
*/
|
||||
@@ -26,7 +42,7 @@ export function createFieldState(schema) {
|
||||
const defaultQuery =
|
||||
item['default-query'] ??
|
||||
item.query ??
|
||||
item['query-option']?.[0]?.value ??
|
||||
resolveQueryOption(item)[0]?.value ??
|
||||
'EQ';
|
||||
state[item.field] = {
|
||||
value: item.value ?? '',
|
||||
@@ -60,7 +76,7 @@ export function buildFilters(schema, state) {
|
||||
const row = {
|
||||
field: key,
|
||||
value: empty ? null : value,
|
||||
query: current.query ?? fieldDef['query-option']?.[0]?.value ?? 'EQ',
|
||||
query: current.query ?? resolveQueryOption(fieldDef)[0]?.value ?? 'EQ',
|
||||
hidden: current.hidden === true,
|
||||
disabled: current.disabled === true,
|
||||
readOnly: current.readOnly === true,
|
||||
|
||||
+36
-1
@@ -20,13 +20,35 @@ export const BUILTIN_COMPONENT_MAP = {
|
||||
between: HeadlessBetween,
|
||||
};
|
||||
|
||||
/** @typedef {{ componentMap?: Record<string, import('vue').Component>, colRatio?: { name?: number, query?: number, value?: number }, changeEmit?: 'immediate'|'debounce'|'manual' }} TransFormConfig */
|
||||
/**
|
||||
* 默认查询操作符全集(对应 DESIGN.md Q12/Q61 操作符码表)。
|
||||
* 注意:这是共享常量,请通过 getDefaultQueryOption() 获取深拷贝后再修改,
|
||||
* 不要直接改动本常量,以免污染全局配置。
|
||||
*/
|
||||
export const DEFAULT_QUERY_OPTION = [
|
||||
{ value: 'EQ', label: '=' },
|
||||
{ value: 'NE', label: '≠' },
|
||||
{ value: 'GT', label: '>' },
|
||||
{ value: 'GTE', label: '≥' },
|
||||
{ value: 'LT', label: '<' },
|
||||
{ value: 'LTE', label: '≤' },
|
||||
{ value: 'LIKE', label: 'LIKE' },
|
||||
{ value: 'IN', label: 'IN' },
|
||||
{ value: 'NOT_IN', label: 'NOT IN' },
|
||||
{ value: 'BETWEEN', label: 'BETWEEN' },
|
||||
{ value: 'IS_NULL', label: 'IS NULL' },
|
||||
{ value: 'IS_NOT_NULL', label: 'IS NOT NULL' },
|
||||
];
|
||||
|
||||
/** @typedef {{ componentMap?: Record<string, import('vue').Component>, colRatio?: { name?: number, query?: number, value?: number }, changeEmit?: 'immediate'|'debounce'|'manual', queryOption?: Array<{value: string, label?: string}> }} TransFormConfig */
|
||||
|
||||
/** @type {TransFormConfig & { componentMap: Record<string, import('vue').Component> }} */
|
||||
const globalConfig = {
|
||||
componentMap: { ...BUILTIN_COMPONENT_MAP },
|
||||
colRatio: { name: 3, query: 2, value: 7 },
|
||||
changeEmit: 'immediate',
|
||||
// 默认操作符列表(深拷贝一份,避免外部修改 DEFAULT_QUERY_OPTION 常量污染配置)
|
||||
queryOption: structuredClone(DEFAULT_QUERY_OPTION),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -43,6 +65,18 @@ export function setConfig(patch) {
|
||||
globalConfig.colRatio = { ...globalConfig.colRatio, ...patch.colRatio };
|
||||
}
|
||||
if (patch.changeEmit) globalConfig.changeEmit = patch.changeEmit;
|
||||
// queryOption:整体替换整个数组(深拷贝存储,防止外部后续修改污染配置)
|
||||
if (patch.queryOption) {
|
||||
globalConfig.queryOption = structuredClone(patch.queryOption);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认查询操作符列表(始终返回深拷贝,调用方可安全修改,不影响全局配置)。
|
||||
* @returns {Array<{value: string, label?: string}>}
|
||||
*/
|
||||
export function getDefaultQueryOption() {
|
||||
return structuredClone(globalConfig.queryOption);
|
||||
}
|
||||
|
||||
export function getConfig() {
|
||||
@@ -53,4 +87,5 @@ export function resetConfig() {
|
||||
globalConfig.componentMap = { ...BUILTIN_COMPONENT_MAP };
|
||||
globalConfig.colRatio = { name: 3, query: 2, value: 7 };
|
||||
globalConfig.changeEmit = 'immediate';
|
||||
globalConfig.queryOption = structuredClone(DEFAULT_QUERY_OPTION);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ import './styles/trans-form.css';
|
||||
|
||||
export { default as TransFormPlugin, TransForm, setConfig, getConfig } from './plugin.js';
|
||||
|
||||
export { DEFAULT_QUERY_OPTION, getDefaultQueryOption, resetConfig } from './config.js';
|
||||
export { resolveQueryOption } from './composables/useFilters.js';
|
||||
|
||||
export { default as HeadlessInput } from './components/HeadlessInput.vue';
|
||||
export { default as HeadlessTextarea } from './components/HeadlessTextarea.vue';
|
||||
export { default as HeadlessSelect } from './components/HeadlessSelect.vue';
|
||||
|
||||
Reference in New Issue
Block a user