Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
dj-car-boutique-work-wechat
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7375f7ca
authored
Jul 15, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat 自测功能修复
1 parent
b5c20a66
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
267 additions
and
16 deletions
config.js
packageDynamicForm/components/form-field-multipleSelect/form-field-multipleSelect.js
packageDynamicForm/form-engine/app-subform-json.js
packageDynamicForm/form-engine/multiple-select-display.helpers.js
packageDynamicForm/form-engine/multiple-select-value.js
packageDynamicForm/tests/f21-staff-echo.test.mjs
config.js
View file @
7375f7c
...
...
@@ -22,7 +22,7 @@ export const RECRUIT_MENU_ENABLED = false
* 4预发布
* 5cdptest
*/
let
index
=
1
;
let
index
=
2
;
const
accountInfo
=
wx
.
getAccountInfoSync
();
const
systemInfo
=
getSystemInfoSync
();
const
envName
=
accountInfo
.
miniProgram
.
envVersion
;
...
...
packageDynamicForm/components/form-field-multipleSelect/form-field-multipleSelect.js
View file @
7375f7c
...
...
@@ -6,6 +6,7 @@
*/
const
{
fetchFieldOptions
}
=
require
(
'../../api/fieldOptionsService.js'
)
const
{
coerceMultipleSelectValue
}
=
require
(
'../../form-engine/multiple-select-value.js'
)
const
{
resolveMultipleSelectItemDisplayLabel
}
=
require
(
'../../form-engine/multiple-select-display.helpers.js'
)
const
{
normalizeOptionRecord
}
=
require
(
'../../form-engine/field-submit-value.js'
)
const
{
shouldRefreshOptionsOnPopup
,
...
...
@@ -113,15 +114,16 @@ Component({
?
normalizedValue
.
find
(
item
=>
this
.
resolveItemKey
(
item
)
===
selectedKey
)
:
null
labels
.
push
(
(
rawItem
&&
typeof
rawItem
===
'object'
&&
(
rawItem
.
name
||
rawItem
.
label
))
||
matched
?.
label
||
selectedKey
resolveMultipleSelectItemDisplayLabel
({
selectedKey
,
rawItem
,
matched
,
hasOptionsKey
:
!!
field
?.
optionsKey
})
)
})
this
.
setData
({
displayLabel
:
labels
.
length
?
labels
.
join
(
'/'
)
:
''
,
displayLabel
:
labels
.
filter
(
part
=>
part
!=
null
&&
part
!==
''
).
join
(
'/'
)
,
pickerValueIds
:
selectedValues
})
},
...
...
packageDynamicForm/form-engine/app-subform-json.js
View file @
7375f7c
...
...
@@ -508,7 +508,9 @@ function extractMultipleSelectIdsAndLabels(raw, field = {}) {
if
(
id
!==
''
)
{
ids
.
push
(
String
(
id
))
}
names
.
push
(
name
||
String
(
id
))
if
(
name
&&
!
isMultipleSelectIdLikeLabel
(
name
,
id
))
{
names
.
push
(
name
)
}
}
return
}
...
...
@@ -518,7 +520,10 @@ function extractMultipleSelectIdsAndLabels(raw, field = {}) {
}
ids
.
push
(
str
)
const
matched
=
findStaticOption
(
field
,
str
)
names
.
push
(
matched
?.
label
??
matched
?.
name
??
str
)
const
label
=
matched
?.
label
??
matched
?.
name
if
(
label
&&
!
isMultipleSelectIdLikeLabel
(
label
,
str
))
{
names
.
push
(
label
)
}
})
return
{
ids
,
displayLabel
:
names
.
filter
(
part
=>
part
!=
null
&&
part
!==
''
).
join
(
'/'
)
}
}
...
...
@@ -535,12 +540,59 @@ function splitMultipleSelectDisplayLabel(value) {
return
trimmed
.
split
(
'/'
).
map
(
part
=>
part
.
trim
()).
filter
(
part
=>
part
!==
''
)
}
/** 展示名是否实为 id(jsonContent 误把 uuid 当 value 时不作为 label) */
function
isMultipleSelectIdLikeLabel
(
label
,
id
=
''
)
{
if
(
label
==
null
||
label
===
''
)
{
return
true
}
return
String
(
label
)
===
String
(
id
)
}
/** `/` 展示串是否含至少一段真实姓名(非 id) */
function
hasRealMultipleSelectDisplayNames
(
ids
=
[],
displayLabel
=
''
)
{
const
names
=
splitMultipleSelectDisplayLabel
(
displayLabel
)
if
(
!
names
.
length
)
{
return
false
}
return
names
.
some
((
name
,
index
)
=>
!
isMultipleSelectIdLikeLabel
(
name
,
ids
[
index
]))
}
/** 保存前剔除与 id 相同的展示段 */
function
sanitizeMultipleSelectSlashLabel
(
ids
=
[],
displayLabel
=
''
)
{
if
(
typeof
displayLabel
!==
'string'
||
displayLabel
===
''
)
{
return
''
}
const
parts
=
displayLabel
.
trim
()
.
split
(
'/'
)
.
map
(
part
=>
part
.
trim
())
const
sanitized
=
ids
.
map
((
id
,
index
)
=>
{
const
part
=
parts
[
index
]
if
(
part
==
null
||
part
===
''
||
isMultipleSelectIdLikeLabel
(
part
,
id
))
{
return
''
}
return
part
})
.
filter
(
Boolean
)
return
sanitized
.
join
(
'/'
)
}
function
zipMultipleSelectIdsWithDisplayLabel
(
ids
=
[],
displayLabel
=
''
)
{
const
names
=
splitMultipleSelectDisplayLabel
(
displayLabel
)
return
ids
.
map
((
id
,
index
)
=>
({
id
:
String
(
id
),
name
:
names
[
index
]
!=
null
&&
names
[
index
]
!==
''
?
names
[
index
]
:
String
(
id
)
}))
return
ids
.
map
((
id
,
index
)
=>
{
const
idStr
=
String
(
id
)
const
namePart
=
names
[
index
]
const
entry
=
{
id
:
idStr
}
if
(
namePart
!=
null
&&
namePart
!==
''
&&
!
isMultipleSelectIdLikeLabel
(
namePart
,
idStr
)
)
{
entry
.
name
=
namePart
}
return
entry
})
}
function
resolveMultipleSelectEngineValueFromAppField
(
field
=
{})
{
...
...
@@ -555,7 +607,7 @@ function resolveMultipleSelectEngineValueFromAppField(field = {}) {
return
coerceMultipleSelectValue
(
meta
)
}
const
displayNames
=
splitMultipleSelectDisplayLabel
(
field
.
value
)
if
(
displayNames
.
length
)
{
if
(
displayNames
.
length
&&
hasRealMultipleSelectDisplayNames
(
meta
,
field
.
value
)
)
{
return
zipMultipleSelectIdsWithDisplayLabel
(
meta
,
field
.
value
)
}
return
meta
.
map
(
id
=>
String
(
id
))
...
...
@@ -1336,7 +1388,7 @@ export function formatFieldForAppJsonContent(field = {}, options = {}) {
return
next
}
next
[
key
]
=
ids
next
.
value
=
displayLabel
next
.
value
=
sanitizeMultipleSelectSlashLabel
(
ids
,
displayLabel
)
return
next
}
...
...
packageDynamicForm/form-engine/multiple-select-display.helpers.js
0 → 100644
View file @
7375f7c
/**
* multipleSelect 展示名解析 — 纯函数,供组件回显与 jsonContent 编解码共用
* @see packageDynamicForm/docs/field-options-api.md
*/
/**
* 展示名是否实为 id(jsonContent 误把 uuid 写入 value 时不应作为 label)
* @param {*} label 候选展示名
* @param {*} [id] 对应选项 id
* @returns {boolean}
*/
function
isMultipleSelectIdLikeLabel
(
label
,
id
=
''
)
{
if
(
label
==
null
||
label
===
''
)
{
return
true
}
return
String
(
label
)
===
String
(
id
)
}
/**
* 解析 multipleSelect 单选项展示文案;optionsKey 未匹配时不回退 id
* @param {Object} [params]
* @param {string} params.selectedKey 选中 id
* @param {*} [params.rawItem] 引擎值中的原始项
* @param {Object} [params.matched] 已加载 options 中的匹配项
* @param {boolean} [params.hasOptionsKey] 是否远程 optionsKey 字段
* @returns {string}
*/
function
resolveMultipleSelectItemDisplayLabel
({
selectedKey
,
rawItem
,
matched
,
hasOptionsKey
=
false
}
=
{})
{
if
(
rawItem
!=
null
&&
typeof
rawItem
===
'object'
)
{
const
name
=
rawItem
.
name
||
rawItem
.
label
if
(
name
&&
!
isMultipleSelectIdLikeLabel
(
name
,
selectedKey
))
{
return
String
(
name
)
}
}
if
(
matched
?.
label
)
{
return
String
(
matched
.
label
)
}
return
hasOptionsKey
?
''
:
String
(
selectedKey
||
''
)
}
/**
* `/` 拼接展示串中剔除与 id 相同的段(保存入库前防御)
* @param {Array<string>} [ids=[]]
* @param {string} [displayLabel='']
* @returns {string}
*/
function
sanitizeMultipleSelectSlashLabel
(
ids
=
[],
displayLabel
=
''
)
{
if
(
typeof
displayLabel
!==
'string'
||
displayLabel
===
''
)
{
return
''
}
const
parts
=
displayLabel
.
trim
()
.
split
(
'/'
)
.
map
(
part
=>
part
.
trim
())
const
sanitized
=
ids
.
map
((
id
,
index
)
=>
{
const
part
=
parts
[
index
]
if
(
part
==
null
||
part
===
''
||
isMultipleSelectIdLikeLabel
(
part
,
id
))
{
return
''
}
return
part
})
.
filter
(
Boolean
)
return
sanitized
.
join
(
'/'
)
}
/** App jsonContent 双 key:`value` 为 `/` 拼接展示串 */
function
splitMultipleSelectDisplayLabel
(
value
)
{
if
(
typeof
value
!==
'string'
||
value
===
''
)
{
return
[]
}
const
trimmed
=
value
.
trim
()
if
(
trimmed
.
startsWith
(
'['
))
{
return
[]
}
return
trimmed
.
split
(
'/'
).
map
(
part
=>
part
.
trim
()).
filter
(
part
=>
part
!==
''
)
}
/** `/` 展示串是否含至少一段真实姓名(非 id) */
function
hasRealMultipleSelectDisplayNames
(
ids
=
[],
displayLabel
=
''
)
{
const
names
=
splitMultipleSelectDisplayLabel
(
displayLabel
)
if
(
!
names
.
length
)
{
return
false
}
return
names
.
some
((
name
,
index
)
=>
!
isMultipleSelectIdLikeLabel
(
name
,
ids
[
index
]))
}
/** id 数组 + `/` 展示串 → `{ id, name? }[]`(不把 id 当 name) */
function
zipMultipleSelectIdsWithDisplayLabel
(
ids
=
[],
displayLabel
=
''
)
{
const
names
=
splitMultipleSelectDisplayLabel
(
displayLabel
)
return
ids
.
map
((
id
,
index
)
=>
{
const
idStr
=
String
(
id
)
const
namePart
=
names
[
index
]
const
entry
=
{
id
:
idStr
}
if
(
namePart
!=
null
&&
namePart
!==
''
&&
!
isMultipleSelectIdLikeLabel
(
namePart
,
idStr
)
)
{
entry
.
name
=
namePart
}
return
entry
})
}
module
.
exports
=
{
isMultipleSelectIdLikeLabel
,
resolveMultipleSelectItemDisplayLabel
,
sanitizeMultipleSelectSlashLabel
,
splitMultipleSelectDisplayLabel
,
hasRealMultipleSelectDisplayNames
,
zipMultipleSelectIdsWithDisplayLabel
}
packageDynamicForm/form-engine/multiple-select-value.js
View file @
7375f7c
...
...
@@ -55,8 +55,10 @@ export function normalizeMultipleSelectValuesInMap(list = [], values = {}) {
}
if
(
typeof
module
!==
'undefined'
&&
module
.
exports
)
{
const
displayHelpers
=
require
(
'./multiple-select-display.helpers.js'
)
module
.
exports
=
{
coerceMultipleSelectValue
,
normalizeMultipleSelectValuesInMap
normalizeMultipleSelectValuesInMap
,
...
displayHelpers
}
}
packageDynamicForm/tests/f21-staff-echo.test.mjs
0 → 100644
View file @
7375f7c
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
isMultipleSelectIdLikeLabel,
resolveMultipleSelectItemDisplayLabel,
sanitizeMultipleSelectSlashLabel,
hasRealMultipleSelectDisplayNames,
zipMultipleSelectIdsWithDisplayLabel
} = require('../form-engine/multiple-select-display.helpers.js')
describe('F2-1 staff echo (id-only jsonContent)', () => {
it('IT-F21-ECHO-001: dual key with uuid slash label resolves to id array not named objects', () => {
const meta = ['uuid-1', 'uuid-2']
const result = hasRealMultipleSelectDisplayNames(meta, 'uuid-1/uuid-2')
? zipMultipleSelectIdsWithDisplayLabel(meta, 'uuid-1/uuid-2')
: meta.map(id => String(id))
assert.deepEqual(result, ['uuid-1', 'uuid-2'])
})
it('IT-F21-ECHO-001b: dual key with real names still zips id and name', () => {
const meta = ['staff-001', 'staff-002']
assert.equal(hasRealMultipleSelectDisplayNames(meta, '张三/李四'), true)
assert.deepEqual(zipMultipleSelectIdsWithDisplayLabel(meta, '张三/李四'), [
{ id: 'staff-001', name: '张三' },
{ id: 'staff-002', name: '李四' }
])
})
it('IT-F21-ECHO-002: resolveMultipleSelectItemDisplayLabel uses options not uuid fallback', () => {
const options = [
{ label: '张三', value: 'uuid-1', id: 'uuid-1', name: '张三' },
{ label: '李四', value: 'uuid-2', id: 'uuid-2', name: '李四' }
]
const labels = ['uuid-1', 'uuid-2'].map(selectedKey => {
const matched = options.find(item => String(item.value) === selectedKey)
return resolveMultipleSelectItemDisplayLabel({
selectedKey,
rawItem: selectedKey,
matched,
hasOptionsKey: true
})
})
assert.deepEqual(labels, ['张三', '李四'])
assert.equal(
resolveMultipleSelectItemDisplayLabel({
selectedKey: 'uuid-1',
rawItem: 'uuid-1',
matched: null,
hasOptionsKey: true
}),
''
)
})
it('IT-F21-ECHO-002b: sanitizeMultipleSelectSlashLabel strips id-like segments', () => {
assert.equal(
sanitizeMultipleSelectSlashLabel(['uuid-1', 'uuid-2'], 'uuid-1/uuid-2'),
''
)
assert.equal(
sanitizeMultipleSelectSlashLabel(['staff-001', 'staff-002'], '张三/李四'),
'张三/李四'
)
assert.equal(isMultipleSelectIdLikeLabel('uuid-1', 'uuid-1'), true)
assert.equal(isMultipleSelectIdLikeLabel('张三', 'uuid-1'), false)
})
it('IT-F21-ECHO-003: sanitize id-only slash label for jsonContent save', () => {
const ids = ['uuid-1', 'uuid-2']
const displayLabel = sanitizeMultipleSelectSlashLabel(ids, 'uuid-1/uuid-2')
assert.equal(displayLabel, '')
assert.deepEqual(ids, ['uuid-1', 'uuid-2'])
})
})
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment