This commit is contained in:
zlwu committed 2026-07-30 15:02:13 +08:00
1 parent f7d1004e6b
commit 310b2efe8a
91 files changed
+14420 -10840

No files matched your search

@@ -65,6 +65,23 @@
:value="u.id"
/>
</el-select>
<el-select
v-else-if="isPostField(rule.field)"
:model-value="personValueIds(rule.value)"
multiple
filterable
placeholder="选择职位(任一命中)"
:disabled="disabled"
class="cond-rule-editor__post-select"
@update:model-value="(v) => onValueChange(idx, Array.isArray(v) ? v.map(String) : [])"
>
<el-option
v-for="p in postOptions"
:key="p.id"
:label="p.label"
:value="p.id"
/>
</el-select>
<el-select
v-else-if="optionsFor(rule.field)?.length"
:model-value="rule.value"
@@ -115,7 +132,7 @@
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { Delete, Plus } from '@element-plus/icons-vue'
import { fetchUserList } from '@/api/admin'
import { fetchPostList, fetchUserList } from '@/api/admin'
import { MAX_ADMIN_LIST_PAGE_SIZE } from '@/utils/fetch-paged-list'
import {
opsForFieldType,
@@ -147,6 +164,7 @@
const localRules = computed(() => props.modelValue || [])
const userOptions = ref<Array<{ id: string; label: string }>>([])
const postOptions = ref<Array<{ id: string; label: string }>>([])
function meta(field: string) {
return props.candidates.find((c) => c.field === field)
@@ -157,6 +175,10 @@
return t === 'person' || t === 'initiator'
}
function isPostField(field: string) {
return meta(field)?.type === 'post'
}
function personValueIds(v: unknown): string[] {
if (Array.isArray(v)) return v.map(String)
if (v == null || v === '') return []
@@ -164,7 +186,7 @@
}
function defaultValueForType(type: string, opts?: ConditionCandidate['options']) {
if (type === 'person' || type === 'initiator') return [] as string[]
if (type === 'person' || type === 'post' || type === 'initiator') return [] as string[]
return opts?.[0]?.value ?? ''
}
@@ -285,10 +307,40 @@
}
}
async function loadPosts() {
try {
const pageSize = MAX_ADMIN_LIST_PAGE_SIZE
const raw: any[] = []
let page = 1
for (;;) {
const res = await fetchPostList({ page, pageSize })
const list = res?.list || []
raw.push(...list)
if (list.length < pageSize) break
if (typeof res?.total === 'number' && raw.length >= res.total) break
page += 1
}
postOptions.value = raw
.filter((r) => String(r.status ?? '1') === '1')
.map((r) => {
const id = String(r.id || '')
const name = String(r.postName || '').trim()
const code = String(r.postCode || '').trim()
return { id, label: name || code || id }
})
.filter((p) => p.id)
} catch {
postOptions.value = []
}
}
onMounted(() => {
if (props.candidates.some((c) => c.type === 'person' || c.type === 'initiator')) {
loadUsers()
}
if (props.candidates.some((c) => c.type === 'post')) {
loadPosts()
}
})
watch(
@@ -297,6 +349,13 @@
if (need && !userOptions.value.length) loadUsers()
}
)
watch(
() => props.candidates.some((c) => c.type === 'post'),
(need) => {
if (need && !postOptions.value.length) loadPosts()
}
)
</script>
<style scoped lang="scss">
@@ -336,4 +395,8 @@
font-size: 11px;
text-align: center;
}
.cond-rule-editor__post-select :deep(.el-select__selection) {
flex-wrap: wrap;
}
</style>