feat(permission): replace OA roles with post-bound roles and assignee posts
Unify effective roles via post-role bindings, remove dedicated OA role UI, and update OA assignee resolution plus related SQL/docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a3c73d76bb
commit
06db3bc966
66 files changed
+55337
-38647
No files matched your search
@@ -1,4 +1,9 @@
|
||||
/** 加班套件运行时:时长仅手动填写,补齐数字框左对齐 */
|
||||
/** 加班套件运行时:时长仅手动填写,补齐数字框左对齐;加班人默认当前登录人 */
|
||||
|
||||
import {
|
||||
buildCurrentOwnerPerson,
|
||||
type OwnerUserSnapshot
|
||||
} from '@/utils/oa-owner-field-defaults'
|
||||
|
||||
function asRules(schema: unknown): Record<string, unknown>[] {
|
||||
if (Array.isArray(schema)) return schema.filter((r) => r && typeof r === 'object') as any
|
||||
@@ -11,12 +16,88 @@ function asRules(schema: unknown): Record<string, unknown>[] {
|
||||
return []
|
||||
}
|
||||
|
||||
function walk(rules: Record<string, unknown>[], out: Record<string, unknown>[]) {
|
||||
for (const r of rules) {
|
||||
out.push(r)
|
||||
if (Array.isArray(r.children)) {
|
||||
walk(r.children as any, out)
|
||||
}
|
||||
const props = r.props as any
|
||||
if (props && Array.isArray(props.rule)) walk(props.rule, out)
|
||||
}
|
||||
}
|
||||
|
||||
export type OvertimeKitBinding = {
|
||||
personField?: string
|
||||
durationField?: string
|
||||
}
|
||||
|
||||
function resolveBinding(kit: Record<string, unknown>): OvertimeKitBinding {
|
||||
const props = (kit.props && typeof kit.props === 'object' ? kit.props : {}) as Record<
|
||||
string,
|
||||
any
|
||||
>
|
||||
let personField = props.personField ? String(props.personField) : undefined
|
||||
let durationField = props.durationField ? String(props.durationField) : undefined
|
||||
const children = (
|
||||
Array.isArray(kit.children)
|
||||
? kit.children
|
||||
: Array.isArray(props.rule)
|
||||
? props.rule
|
||||
: []
|
||||
) as Record<string, any>[]
|
||||
for (const c of children) {
|
||||
if (!c?.field) continue
|
||||
const sem = String(c.props?._fc_kit_field || '')
|
||||
if (sem === 'overtimePerson' && !personField) personField = String(c.field)
|
||||
if (sem === 'overtimeDuration' && !durationField) durationField = String(c.field)
|
||||
}
|
||||
return { personField, durationField }
|
||||
}
|
||||
|
||||
export function listOvertimeKitBindings(schema: unknown): OvertimeKitBinding[] {
|
||||
const flat: Record<string, unknown>[] = []
|
||||
walk(asRules(schema), flat)
|
||||
return flat.filter((r) => String(r.type || '') === 'overtimeKit').map(resolveBinding)
|
||||
}
|
||||
|
||||
function isEmptyPersonValue(raw: unknown): boolean {
|
||||
if (raw == null || raw === '') return true
|
||||
if (Array.isArray(raw)) return raw.length === 0
|
||||
if (typeof raw === 'object') {
|
||||
const o = raw as Record<string, unknown>
|
||||
return !String(o.id || '').trim()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起页:加班人字段为空时写入当前登录人(人员组件为多选,值为数组)。
|
||||
*/
|
||||
export function applyOvertimeKitDefaults(
|
||||
schema: unknown,
|
||||
formData: Record<string, unknown>,
|
||||
user: OwnerUserSnapshot | null | undefined
|
||||
): Record<string, unknown> {
|
||||
const data = { ...formData }
|
||||
const person = buildCurrentOwnerPerson(user)
|
||||
if (!person) return data
|
||||
for (const kit of listOvertimeKitBindings(schema)) {
|
||||
const f = kit.personField
|
||||
if (f && isEmptyPersonValue(data[f])) {
|
||||
data[f] = [person]
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
function resolveDurationField(kit: Record<string, unknown>): string | undefined {
|
||||
const binding = resolveBinding(kit)
|
||||
if (binding.durationField) return binding.durationField
|
||||
const props = (kit.props && typeof kit.props === 'object' ? kit.props : {}) as Record<
|
||||
string,
|
||||
any
|
||||
>
|
||||
if (props.durationField) return String(props.durationField)
|
||||
const children = (
|
||||
Array.isArray(kit.children)
|
||||
? kit.children
|
||||
@@ -26,7 +107,6 @@ function resolveDurationField(kit: Record<string, unknown>): string | undefined
|
||||
) as Record<string, any>[]
|
||||
for (const c of children) {
|
||||
if (!c?.field) continue
|
||||
if (String(c.props?._fc_kit_field || '') === 'overtimeDuration') return String(c.field)
|
||||
const t = String(c.type || '')
|
||||
if ((t === 'inputNumber' || t === 'number') && String(c.title || '').includes('时长')) {
|
||||
return String(c.field)
|
||||
|
||||
Reference in new issue
Block a user