20260904173136
This commit is contained in:
1 parent
0928437c67
commit
4e167df0f0
40 files changed
+3471
-2314
No files matched your search
@@ -0,0 +1,50 @@
|
||||
// 模块数据驱动列表/编辑的「字段展示」工具:解析下拉选项、格式化日期等。
|
||||
// 供 fms-module-list / fms-module-edit 等按模块元数据渲染的组件共用;
|
||||
// 查询条件构建(buildQueryCondition 等)见 queryUtils.js。
|
||||
import { isEmptyValue } from './queryUtils'
|
||||
|
||||
const padDatePart = (number) => String(number).padStart(2, '0')
|
||||
|
||||
export function parseOptions(field) {
|
||||
if (!field?.b_options) return { optionConfig: {}, options: [] }
|
||||
try {
|
||||
const parsed = JSON.parse(field.b_options)
|
||||
let optionConfig = {}
|
||||
let source = []
|
||||
if (Array.isArray(parsed)) {
|
||||
source = parsed
|
||||
} else if (parsed && typeof parsed === 'object') {
|
||||
optionConfig = parsed
|
||||
if (Array.isArray(parsed.options)) {
|
||||
source = parsed.options
|
||||
} else if (Array.isArray(parsed.items)) {
|
||||
source = parsed.items
|
||||
}
|
||||
}
|
||||
const options = source.map((option) => {
|
||||
if (option && typeof option === 'object') {
|
||||
const value = option.value ?? option.key ?? option.id
|
||||
return { ...option, value, label: String(option.label ?? option.name ?? value ?? '') }
|
||||
}
|
||||
return { value: option, label: String(option ?? '') }
|
||||
})
|
||||
return { optionConfig, options }
|
||||
} catch {
|
||||
return { optionConfig: {}, options: [] }
|
||||
}
|
||||
}
|
||||
|
||||
export function formatDateValue(value, withTime = false) {
|
||||
if (isEmptyValue(value)) return ''
|
||||
if (value && typeof value.format === 'function') {
|
||||
return value.format(withTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD')
|
||||
}
|
||||
const text = String(value).replace('T', ' ')
|
||||
if (/^\d{4}-\d{2}-\d{2}/.test(text)) return withTime ? text.slice(0, 19) : text.slice(0, 10)
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return text
|
||||
const datePart = `${date.getFullYear()}-${padDatePart(date.getMonth() + 1)}-${padDatePart(date.getDate())}`
|
||||
return withTime
|
||||
? `${datePart} ${padDatePart(date.getHours())}:${padDatePart(date.getMinutes())}:${padDatePart(date.getSeconds())}`
|
||||
: datePart
|
||||
}
|
||||
+3
-47
@@ -1,9 +1,9 @@
|
||||
// 数据驱动列表的共享工具函数,避免在各组件间重复实现查询/格式化逻辑。
|
||||
// 模块数据驱动列表的「查询条件」工具:构建查询 SQL 片段、解析查询输入/默认值。
|
||||
// 供 fms-module-list / fms-module-edit 等按模块元数据渲染的组件共用;
|
||||
// 展示格式化(parseOptions / formatDateValue)见 fieldUtils.js。
|
||||
|
||||
export const identifierRe = /^[A-Za-z_][A-Za-z0-9_]*$/
|
||||
|
||||
const padDatePart = (number) => String(number).padStart(2, '0')
|
||||
|
||||
export function escapeSqlText(value) {
|
||||
return String(value).replaceAll("'", "''")
|
||||
}
|
||||
@@ -18,35 +18,6 @@ export function isEmptyValue(value) {
|
||||
return value === undefined || value === null || value === ''
|
||||
}
|
||||
|
||||
export function parseOptions(field) {
|
||||
if (!field?.b_options) return { optionConfig: {}, options: [] }
|
||||
try {
|
||||
const parsed = JSON.parse(field.b_options)
|
||||
let optionConfig = {}
|
||||
let source = []
|
||||
if (Array.isArray(parsed)) {
|
||||
source = parsed
|
||||
} else if (parsed && typeof parsed === 'object') {
|
||||
optionConfig = parsed
|
||||
if (Array.isArray(parsed.options)) {
|
||||
source = parsed.options
|
||||
} else if (Array.isArray(parsed.items)) {
|
||||
source = parsed.items
|
||||
}
|
||||
}
|
||||
const options = source.map((option) => {
|
||||
if (option && typeof option === 'object') {
|
||||
const value = option.value ?? option.key ?? option.id
|
||||
return { ...option, value, label: String(option.label ?? option.name ?? value ?? '') }
|
||||
}
|
||||
return { value: option, label: String(option ?? '') }
|
||||
})
|
||||
return { optionConfig, options }
|
||||
} catch {
|
||||
return { optionConfig: {}, options: [] }
|
||||
}
|
||||
}
|
||||
|
||||
export function isRangeQuery(item) {
|
||||
return (
|
||||
item.config.b_operator === 'between' ||
|
||||
@@ -160,18 +131,3 @@ export function buildQueryCondition(item, value) {
|
||||
}
|
||||
return `${field} = ${literal}`
|
||||
}
|
||||
|
||||
export function formatDateValue(value, withTime = false) {
|
||||
if (isEmptyValue(value)) return ''
|
||||
if (value && typeof value.format === 'function') {
|
||||
return value.format(withTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD')
|
||||
}
|
||||
const text = String(value).replace('T', ' ')
|
||||
if (/^\d{4}-\d{2}-\d{2}/.test(text)) return withTime ? text.slice(0, 19) : text.slice(0, 10)
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return text
|
||||
const datePart = `${date.getFullYear()}-${padDatePart(date.getMonth() + 1)}-${padDatePart(date.getDate())}`
|
||||
return withTime
|
||||
? `${datePart} ${padDatePart(date.getHours())}:${padDatePart(date.getMinutes())}:${padDatePart(date.getSeconds())}`
|
||||
: datePart
|
||||
}
|
||||
@@ -35,11 +35,8 @@ import {
|
||||
} from '@/components/ui'
|
||||
import { loadDataApi, loadDataBySqlApi, nextIdApi, saveObjectApi } from '@/services/api'
|
||||
import { diffRow } from '@/utils/dataChanges'
|
||||
import {
|
||||
identifierRe,
|
||||
isEmptyValue,
|
||||
parseOptions,
|
||||
} from '@/components/fms-module-list/moduleListUtils'
|
||||
import { identifierRe, isEmptyValue } from '@/components/fms-module-common/queryUtils'
|
||||
import { parseOptions } from '@/components/fms-module-common/fieldUtils'
|
||||
|
||||
const props = defineProps({
|
||||
/** 受控打开 */
|
||||
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
buildQueryCondition,
|
||||
defaultQueryValue,
|
||||
escapeSqlText,
|
||||
parseOptions,
|
||||
requireModuleId,
|
||||
} from './moduleListUtils'
|
||||
} from '@/components/fms-module-common/queryUtils'
|
||||
import { parseOptions } from '@/components/fms-module-common/fieldUtils'
|
||||
import FmsModuleTable from './FmsModuleTable.vue'
|
||||
import FmsQueryToolbar from './FmsQueryToolbar.vue'
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { computed, h, ref, shallowRef, useSlots, watch } from 'vue'
|
||||
import { Checkbox } from '@/components/ui'
|
||||
import FmsTable from '@/components/fms-table/FmsTable.vue'
|
||||
import { useI18nStore } from '@/stores/i18n'
|
||||
import { formatDateValue, parseOptions } from './moduleListUtils'
|
||||
import { formatDateValue, parseOptions } from '@/components/fms-module-common/fieldUtils'
|
||||
|
||||
const props = defineProps({
|
||||
fields: { type: Array, default: () => [] },
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { DatePicker, Input, RangePicker, Select } from '@/components/ui'
|
||||
import { isDateQuery, isEmptyValue, isNumericField, isRangeQuery } from './moduleListUtils'
|
||||
import {
|
||||
isDateQuery,
|
||||
isEmptyValue,
|
||||
isNumericField,
|
||||
isRangeQuery,
|
||||
} from '@/components/fms-module-common/queryUtils'
|
||||
|
||||
const props = defineProps({
|
||||
item: { type: Object, required: true },
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ChevronDown, ChevronUp, Ellipsis, Search } from '@lucide/vue'
|
||||
import { Button, Dropdown, FormItem, Select } from '@/components/ui'
|
||||
import { useI18nStore } from '@/stores/i18n'
|
||||
import FmsQueryControl from './FmsQueryControl.vue'
|
||||
import { defaultQueryValue, emptyQueryValue } from './moduleListUtils'
|
||||
import { defaultQueryValue, emptyQueryValue } from '@/components/fms-module-common/queryUtils'
|
||||
|
||||
const props = defineProps({
|
||||
queryItems: { type: Array, default: () => [] },
|
||||
|
||||
@@ -4,4 +4,3 @@ import FmsQueryControl from './FmsQueryControl.vue'
|
||||
import FmsQueryToolbar from './FmsQueryToolbar.vue'
|
||||
|
||||
export { FmsModuleListPage, FmsModuleTable, FmsQueryControl, FmsQueryToolbar }
|
||||
export * from './moduleListUtils.js'
|
||||
Reference in new issue
Block a user