fix(前端): 后台摘掉公司这一维度——列表列/筛选/建号选择/顶栏旁白全部去掉

用户定案:隔离该由数据和后端自己做,不该把"公司"摆到操作员眼前多一个选错的机会。
于是原计划里给品牌库/去重库两页加公司列(Task 9)反向执行,顺带把一期已上线的展示也收掉。

建号归属改为请求体不带 company_id,由后端 resolveTargetCompanyId 落操作者自己的公司。
这条前端删下拉的安全依据完全靠后端那两条分支撑着,所以用跨仓读 Java 源码的方式钉成可执行断言:
谁把那边改成"必填公司"或删掉任一分支,这边立刻红。
副作用要说清——超管建的号一律归公司 1,给第 2 家建号得用那家公司自己的管理员登录。

「公司管理」页的引导语原写"建号时选哪家公司",下拉没了就成了错的承诺;
"停用后不能再用于新建账号"也不再成立(requireActive 两个调用点都要求显式传 company_id,
而页面现在一律不传)。文案改成真实口径,并断言这三句失效说法不得回流。

1683 例 / 0 红,vue-tsc 干净,变异 6/6 被杀。
This commit is contained in:
2026-10-04 16:15:13 +08:00
parent e6c4c9e7cf
commit ce69fa217c
14 changed files with 179 additions and 275 deletions
-12
View File
@@ -15,8 +15,6 @@ export interface UserListParams {
adminId?: number | null adminId?: number | null
/** 角色过滤(''=全部)。 */ /** 角色过滤(''=全部)。 */
role?: string role?: string
/** 按所属公司过滤(V143);仅超管用得到——公司内 admin 后端本来就只返回本公司账号。 */
companyId?: number | null
} }
/** 序列化到 GET /api/admin/users 的查询参数(Java snake_case)。 */ /** 序列化到 GET /api/admin/users 的查询参数(Java snake_case)。 */
@@ -28,7 +26,6 @@ export interface UserListQuery {
created_by_id?: number created_by_id?: number
admin_id?: number admin_id?: number
role?: string role?: string
company_id?: number
} }
/** 用户列表项即 AdminUser(与 Java AdminUserItemVo 字段对齐)。 */ /** 用户列表项即 AdminUser(与 Java AdminUserItemVo 字段对齐)。 */
@@ -49,12 +46,6 @@ function finiteInt(value: unknown): number | null {
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
} }
/** 公司 id 只认正整数:0/负数/NaN 一律当"没筛选",否则会下发一个必然查不到账号的过滤。 */
function positiveId(value: unknown): number | null {
const id = finiteInt(value)
return id !== null && id > 0 ? id : null
}
/** 归一化分页/筛选参数:页码下限 1、页大小 1..上限,空关键字视为无过滤。 */ /** 归一化分页/筛选参数:页码下限 1、页大小 1..上限,空关键字视为无过滤。 */
export function normalizeUserPageParams(raw: Partial<UserListParams>): UserListParams { export function normalizeUserPageParams(raw: Partial<UserListParams>): UserListParams {
const page = Math.max(finiteInt(raw.page) ?? USER_PAGE_MIN_PAGE, USER_PAGE_MIN_PAGE) const page = Math.max(finiteInt(raw.page) ?? USER_PAGE_MIN_PAGE, USER_PAGE_MIN_PAGE)
@@ -70,7 +61,6 @@ export function normalizeUserPageParams(raw: Partial<UserListParams>): UserListP
keyword, keyword,
createdById: typeof raw.createdById === 'number' ? raw.createdById : null, createdById: typeof raw.createdById === 'number' ? raw.createdById : null,
adminId: typeof raw.adminId === 'number' ? raw.adminId : null, adminId: typeof raw.adminId === 'number' ? raw.adminId : null,
companyId: positiveId(raw.companyId),
role: typeof raw.role === 'string' ? raw.role.trim() || undefined : undefined, role: typeof raw.role === 'string' ? raw.role.trim() || undefined : undefined,
} }
} }
@@ -82,8 +72,6 @@ export function toUserListQuery(params: UserListParams): UserListQuery {
if (params.createdById != null) query.created_by_id = params.createdById if (params.createdById != null) query.created_by_id = params.createdById
if (params.adminId != null) query.admin_id = params.adminId if (params.adminId != null) query.admin_id = params.adminId
if (params.role) query.role = params.role if (params.role) query.role = params.role
const companyId = positiveId(params.companyId)
if (companyId !== null) query.company_id = companyId
return query return query
} }
@@ -27,12 +27,6 @@ export function toAdminUserItem(raw: unknown): AdminUser | null {
if (updatedAt) item.updatedAt = updatedAt if (updatedAt) item.updatedAt = updatedAt
const creator = text(r.creator_username) const creator = text(r.creator_username)
if (creator) item.creatorUsername = creator if (creator) item.creatorUsername = creator
// 公司维度只在后端带上时才写键:留 undefined 而不是 null,好让"这版后端没带公司"
// 与"账号确实没归属公司"在页面上是两种可读的状态。
const companyId = numberOrNull(r.company_id)
if (companyId !== null) item.companyId = companyId
const companyName = text(r.company_name).trim()
if (companyName) item.companyName = companyName
const abbr = text(r.pinyin_abbr) const abbr = text(r.pinyin_abbr)
if (abbr) item.pinyinAbbr = abbr if (abbr) item.pinyinAbbr = abbr
return item return item
@@ -104,9 +104,6 @@ async function signOut() {
<NotificationBell /> <NotificationBell />
<div class="admin-user-meta"> <div class="admin-user-meta">
<strong>{{ userVm.username }}</strong> <strong>{{ userVm.username }}</strong>
<span v-if="userVm.company" class="admin-user-company" :title="`所属公司:${userVm.company}`">
{{ userVm.company }}
</span>
</div> </div>
<span v-if="userVm.role" class="admin-user-role">{{ userVm.role }}</span> <span v-if="userVm.role" class="admin-user-role">{{ userVm.role }}</span>
<el-button class="admin-user-logout" @click="signOut">退出登录</el-button> <el-button class="admin-user-logout" @click="signOut">退出登录</el-button>
@@ -30,7 +30,7 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
steps: ['筛选用户或状态', '立即检测连通性', '必要时清空'], steps: ['筛选用户或状态', '立即检测连通性', '必要时清空'],
}, },
admin_companies: { admin_companies: {
text: '公司决定账号归属:建号时选哪家公司,该账号名下的数据就归哪家公司。公司只做启用/停用,不提供删除——停用后不能再用于新建账号。', text: '公司决定账号归属:新建账号自动落在操作者自己所在的公司,页面上不出现公司选项——要给别的公司建号,请用那个公司自己的管理员登录。公司只做启用/停用,不提供删除。',
steps: ['查看公司列表', '新建公司', '改名或启停'], steps: ['查看公司列表', '新建公司', '改名或启停'],
}, },
admin_dedupe_total_data: { admin_dedupe_total_data: {
@@ -13,18 +13,15 @@ export function pageTitleOf(title: string | null | undefined): string {
export interface TopbarUserViewModel { export interface TopbarUserViewModel {
username: string username: string
role: string role: string
/** 所属公司名(V143);后端没带就是空串,模板据此整段不显示,不能渲染出 undefined。 */
company: string
hasUser: boolean hasUser: boolean
} }
/** 顶部栏用户模型:用户信息或未登录空态统一为可渲染视图模型。 */ /** 顶部栏用户模型:用户信息或未登录空态统一为可渲染视图模型。 */
export function topbarUserOf(user: AdminUser | null | undefined): TopbarUserViewModel { export function topbarUserOf(user: AdminUser | null | undefined): TopbarUserViewModel {
if (!user) return { username: '当前用户', role: '', company: '', hasUser: false } if (!user) return { username: '当前用户', role: '', hasUser: false }
return { return {
username: user.username || '当前用户', username: user.username || '当前用户',
role: roleLabel(user.role) || user.role || '', role: roleLabel(user.role) || user.role || '',
company: (user.companyName || '').trim(),
hasUser: true, hasUser: true,
} }
} }
@@ -1,16 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, reactive, ref, watch } from 'vue' import { reactive, ref, watch } from 'vue'
import { submitCreateUser } from './user-create-adapter' import { submitCreateUser } from './user-create-adapter'
import { import {
createEmptyCreateUserForm, createEmptyCreateUserForm,
initialCompanyId,
selectableCompanies,
type CreateOperatorScope,
type CreateUserForm, type CreateUserForm,
type CreateUserFormErrors, type CreateUserFormErrors,
validateCreateUserForm, validateCreateUserForm,
} from './user-create-model' } from './user-create-model'
import type { CompanyItem } from '@/api/companies-dto'
import { showAdminFeedback } from '@/components/admin-feedback-ui' import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { actionableErrorText } from '@/components/admin-feedback' import { actionableErrorText } from '@/components/admin-feedback'
import UserMenuAuthTree from './UserMenuAuthTree.vue' import UserMenuAuthTree from './UserMenuAuthTree.vue'
@@ -20,10 +16,6 @@ const props = defineProps<{
operatorSuper?: boolean operatorSuper?: boolean
/** 所属管理员候选(列表响应 admins;仅超管创建普通账号时展示)。 */ /** 所属管理员候选(列表响应 admins;仅超管创建普通账号时展示)。 */
adminOptions?: Array<{ id: number; username: string }> adminOptions?: Array<{ id: number; username: string }>
/** 整份公司目录(GET /api/admin/companies,后端已按操作者收窄)。 */
companies?: CompanyItem[]
/** 操作者角色与归属:决定公司下拉是否必选。 */
operator?: CreateOperatorScope
}>() }>()
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'created'): void }>() const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'created'): void }>()
@@ -31,9 +23,6 @@ const form = reactive<CreateUserForm>(createEmptyCreateUserForm())
const errors = reactive<CreateUserFormErrors>({}) const errors = reactive<CreateUserFormErrors>({})
const busy = ref(false) const busy = ref(false)
/** 可选项收窄规则与后端 resolveTargetCompanyId 同源,写在这里而不是父页模板里。 */
const companyOptions = computed(() => selectableCompanies(props.companies || [], props.operator || {}))
/** 角色下拉(对齐 admin.html:普通账号/管理员;超管才显示可改)。 */ /** 角色下拉(对齐 admin.html:普通账号/管理员;超管才显示可改)。 */
const ROLE_CHOICES: Array<{ value: 'admin' | 'normal'; label: string }> = [ const ROLE_CHOICES: Array<{ value: 'admin' | 'normal'; label: string }> = [
{ value: 'normal', label: '普通账号' }, { value: 'normal', label: '普通账号' },
@@ -49,10 +38,8 @@ watch(
form.role = 'normal' form.role = 'normal'
form.columnIds = [] form.columnIds = []
form.createdBy = null form.createdBy = null
form.companyId = initialCompanyId(props.operator || {}, props.companies || [])
errors.username = undefined errors.username = undefined
errors.password = undefined errors.password = undefined
errors.company = undefined
}, },
) )
@@ -61,7 +48,7 @@ function close(): void {
} }
async function create(): Promise<void> { async function create(): Promise<void> {
const { valid, errors: errs } = validateCreateUserForm(form, props.operator) const { valid, errors: errs } = validateCreateUserForm(form)
Object.assign(errors, errs) Object.assign(errors, errs)
if (!valid) return if (!valid) return
busy.value = true busy.value = true
@@ -120,22 +107,6 @@ async function create(): Promise<void> {
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item v-if="companyOptions.length" label="所属公司" :error="errors.company">
<el-select
v-model="form.companyId"
filterable
:placeholder="operatorSuper ? '请选择所属公司' : '所属公司'"
style="width: 200px"
@change="errors.company = undefined"
>
<el-option
v-for="company in companyOptions"
:key="company.id"
:label="company.companyName"
:value="company.id"
/>
</el-select>
</el-form-item>
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)"> <el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
<div class="auth-tree-box"> <div class="auth-tree-box">
<UserMenuAuthTree v-model:checked="form.columnIds" /> <UserMenuAuthTree v-model:checked="form.columnIds" />
@@ -8,9 +8,6 @@ import type { AdminUser } from '@/types/admin'
import { roleLabel } from '@/types/admin' import { roleLabel } from '@/types/admin'
import { useAdminSessionStore } from '@/stores/admin-session' import { useAdminSessionStore } from '@/stores/admin-session'
import { deleteUser, fetchUserList } from '@/api/users' import { deleteUser, fetchUserList } from '@/api/users'
import { fetchCompanies } from '@/api/companies'
import type { CompanyItem } from '@/api/companies-dto'
import type { CreateOperatorScope } from './user-create-model'
import { createUserFilterState, toUserListParams, type UserFilterState } from './users-filter' import { createUserFilterState, toUserListParams, type UserFilterState } from './users-filter'
import { totalPageCount } from './user-pagination' import { totalPageCount } from './user-pagination'
import { deleteBlockReason, deleteConfirmMessage } from './user-delete-model' import { deleteBlockReason, deleteConfirmMessage } from './user-delete-model'
@@ -27,12 +24,6 @@ const rows = ref<AdminUser[]>([])
const total = ref(0) const total = ref(0)
/** 所属管理员候选(来自列表响应的 admins),供超管筛选下拉使用。 */ /** 所属管理员候选(来自列表响应的 admins),供超管筛选下拉使用。 */
const admins = ref<Array<{ id: number; username: string }>>([]) const admins = ref<Array<{ id: number; username: string }>>([])
/** 公司目录(GET /api/admin/companies):后端已按操作者收窄,前端不再自己判权限。 */
const companies = ref<CompanyItem[]>([])
const operatorScope = computed<CreateOperatorScope>(() => ({
role: session.user?.role,
companyId: session.user?.companyId ?? null,
}))
const filters = reactive<UserFilterState>(createUserFilterState()) const filters = reactive<UserFilterState>(createUserFilterState())
const isSuperAdmin = computed(() => session.isSuperAdmin) const isSuperAdmin = computed(() => session.isSuperAdmin)
const currentUserId = computed(() => session.user?.id ?? null) const currentUserId = computed(() => session.user?.id ?? null)
@@ -87,18 +78,6 @@ function retry() {
void loadUsers() void loadUsers()
} }
/**
* 公司目录只服务下拉,不参与表格状态机:拉失败时列表照常显示,
* 但超管建号会卡在"请选择所属公司"——所以要把原因说出来,别让人对着空下拉猜。
*/
async function loadCompanies() {
try {
companies.value = await fetchCompanies()
} catch (error) {
ElMessage.warning(error instanceof Error ? error.message : '公司目录加载失败')
}
}
/** 提交新筛选条件:重置回第一页再查询。 */ /** 提交新筛选条件:重置回第一页再查询。 */
function search() { function search() {
filters.page = 1 filters.page = 1
@@ -143,7 +122,6 @@ function goJump() {
} }
onMounted(() => { onMounted(() => {
void loadCompanies()
void loadUsers() void loadUsers()
}) })
</script> </script>
@@ -162,12 +140,6 @@ onMounted(() => {
<label>用户名(模糊搜索)</label> <label>用户名(模糊搜索)</label>
<input v-model="filters.keyword" type="text" placeholder="输入用户名关键字" @keyup.enter="search" /> <input v-model="filters.keyword" type="text" placeholder="输入用户名关键字" @keyup.enter="search" />
</div> </div>
<div v-if="isSuperAdmin" class="form-group" style="min-width: 160px">
<label>所属公司</label>
<el-select v-model="filters.companyId" class="admin-filter" filterable clearable placeholder="全部公司" @change="search">
<el-option v-for="company in companies" :key="company.id" :label="company.companyName" :value="company.id" />
</el-select>
</div>
<div v-if="isSuperAdmin" class="form-group" style="min-width: 160px"> <div v-if="isSuperAdmin" class="form-group" style="min-width: 160px">
<label>所属管理员</label> <label>所属管理员</label>
<el-select v-model="filters.createdByAdminId" class="admin-filter" filterable clearable placeholder="全部" @change="search"> <el-select v-model="filters.createdByAdminId" class="admin-filter" filterable clearable placeholder="全部" @change="search">
@@ -197,7 +169,6 @@ onMounted(() => {
<th style="width: 70px">ID</th> <th style="width: 70px">ID</th>
<th style="width: 180px">用户名</th> <th style="width: 180px">用户名</th>
<th style="width: 140px">角色</th> <th style="width: 140px">角色</th>
<th style="width: 140px">所属公司</th>
<th style="width: 160px">所属管理员</th> <th style="width: 160px">所属管理员</th>
<th style="width: 180px">创建时间</th> <th style="width: 180px">创建时间</th>
<th style="width: 180px">更新时间</th> <th style="width: 180px">更新时间</th>
@@ -210,7 +181,6 @@ onMounted(() => {
<td>{{ row.id }}</td> <td>{{ row.id }}</td>
<td>{{ row.username }}</td> <td>{{ row.username }}</td>
<td>{{ roleLabel(row.role) }}</td> <td>{{ roleLabel(row.role) }}</td>
<td>{{ row.companyName || '-' }}</td>
<td>{{ row.creatorUsername || '-' }}</td> <td>{{ row.creatorUsername || '-' }}</td>
<td>{{ formatDateTime(row.createdAt) }}</td> <td>{{ formatDateTime(row.createdAt) }}</td>
<td>{{ formatDateTime(row.updatedAt) }}</td> <td>{{ formatDateTime(row.updatedAt) }}</td>
@@ -237,10 +207,10 @@ onMounted(() => {
</tr> </tr>
</template> </template>
<tr v-else-if="loading"> <tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td> <td colspan="7" class="empty-tip">加载中...</td>
</tr> </tr>
<tr v-else> <tr v-else>
<td colspan="8" class="empty-tip">{{ userListEmptyHint() }}</td> <td colspan="7" class="empty-tip">{{ userListEmptyHint() }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -253,8 +223,6 @@ onMounted(() => {
v-model="createVisible" v-model="createVisible"
:operator-super="isSuperAdmin" :operator-super="isSuperAdmin"
:admin-options="admins" :admin-options="admins"
:companies="companies"
:operator="operatorScope"
@created="loadUsers" @created="loadUsers"
/> />
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" @updated="loadUsers" /> <EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" @updated="loadUsers" />
@@ -1,20 +1,11 @@
/** 新建用户表单模型(任务 45):纯逻辑,镜像 Java AdminUserCreateRequest 字段与后端校验。 */ /** 新建用户表单模型(任务 45):纯逻辑,镜像 Java AdminUserCreateRequest 字段与后端校验。 */
// 相对路径而非 @/ 别名:本文件被 node --test 直接 import,别名只有 vite 认。
import { COMPANY_STATUS_ACTIVE, type CompanyItem } from '../../api/companies-dto.ts'
export const CREATE_USERNAME_MIN_LEN = 2 export const CREATE_USERNAME_MIN_LEN = 2
export const CREATE_PASSWORD_MIN_LEN = 6 export const CREATE_PASSWORD_MIN_LEN = 6
/** 新建用户可选角色:super_admin 不可由表单创建(后端只收 admin|normal)。 */ /** 新建用户可选角色:super_admin 不可由表单创建(后端只收 admin|normal)。 */
export type CreatableUserRole = 'normal' | 'admin' export type CreatableUserRole = 'normal' | 'admin'
/** 当前操作者的公司归属(来自 /api/admin/current-user)。 */
export interface CreateOperatorScope {
role?: string | null
companyId?: number | null
}
export interface CreateUserForm { export interface CreateUserForm {
username: string username: string
password: string password: string
@@ -23,14 +14,11 @@ export interface CreateUserForm {
columnIds: number[] columnIds: number[]
/** 所属管理员 id(超管创建普通账号时可指定,对齐 admin 的 created_by_id)。 */ /** 所属管理员 id(超管创建普通账号时可指定,对齐 admin 的 created_by_id)。 */
createdBy?: number | null createdBy?: number | null
/** 所属公司 id(V143)。超管必选;公司内 admin 由后端强制落自己公司。 */
companyId?: number | null
} }
export interface CreateUserFormErrors { export interface CreateUserFormErrors {
username?: string username?: string
password?: string password?: string
company?: string
} }
/** 发送 POST /api/admin/user 的请求体(与 Java AdminUserCreateRequest camelCase 对齐)。 */ /** 发送 POST /api/admin/user 的请求体(与 Java AdminUserCreateRequest camelCase 对齐)。 */
@@ -41,11 +29,10 @@ export interface CreateUserPayload {
columnIds: number[] columnIds: number[]
/** 仅 role=normal 且选了所属管理员时发送,与参考 admin.js 的 created_by_id 语义一致。 */ /** 仅 role=normal 且选了所属管理员时发送,与参考 admin.js 的 created_by_id 语义一致。 */
createdById?: number createdById?: number
companyId?: number
} }
export function createEmptyCreateUserForm(): CreateUserForm { export function createEmptyCreateUserForm(): CreateUserForm {
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null, companyId: null } return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null }
} }
/** 未知/空白/超管角色一律归一到 normal,与后端 "admin"/"normal" 白名单一致。 */ /** 未知/空白/超管角色一律归一到 normal,与后端 "admin"/"normal" 白名单一致。 */
@@ -53,40 +40,11 @@ export function normalizeCreateRole(role: string | null | undefined): CreatableU
return (role || '').trim().toLowerCase() === 'admin' ? 'admin' : 'normal' return (role || '').trim().toLowerCase() === 'admin' ? 'admin' : 'normal'
} }
function positiveInt(value: unknown): number | null { /** 表单校验(镜像后端:用户名≥2、密码≥6、均必填);返回逐字段错误。 */
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : null export function validateCreateUserForm(form: CreateUserForm): {
} valid: boolean
errors: CreateUserFormErrors
/** } {
* 建号能选哪家公司,口径与后端 AdminUserService#resolveTargetCompanyId 一致:
* 超管 = 全部启用中的公司(后端 requireActive 会拒停用公司);
* 其余角色 = 只有自己也那一家,且不看启停——后端对非超管直接落 operator.companyId、
* 不校验状态,前端若跟着过滤就会出现「下拉没得选、提交却能建号」的自相矛盾。
*/
export function selectableCompanies(companies: CompanyItem[], operator: CreateOperatorScope): CompanyItem[] {
const rows = Array.isArray(companies) ? companies : []
if (operator?.role === 'super_admin') {
return rows.filter((company) => company.status === COMPANY_STATUS_ACTIVE)
}
const own = positiveInt(operator?.companyId)
if (own === null) return []
return rows.filter((company) => company.id === own)
}
/**
* 弹窗打开时预选哪家公司:候选只有一个(公司内 admin 的本公司)就落它;
* 多个(超管)返回 null——给超管填默认值等于替他决定账号挂在哪家,这是会写进库的判断。
*/
export function initialCompanyId(operator: CreateOperatorScope, companies: CompanyItem[]): number | null {
const options = selectableCompanies(companies, operator)
return options.length === 1 ? options[0].id : null
}
/** 表单校验(镜像后端:用户名≥2、密码≥6、均必填;超管必须显式选公司);返回逐字段错误。 */
export function validateCreateUserForm(
form: CreateUserForm,
operator?: CreateOperatorScope,
): { valid: boolean; errors: CreateUserFormErrors } {
const errors: CreateUserFormErrors = {} const errors: CreateUserFormErrors = {}
const username = (form.username || '').trim() const username = (form.username || '').trim()
if (!username) { if (!username) {
@@ -100,15 +58,17 @@ export function validateCreateUserForm(
} else if (password.length < CREATE_PASSWORD_MIN_LEN) { } else if (password.length < CREATE_PASSWORD_MIN_LEN) {
errors.password = `密码至少${CREATE_PASSWORD_MIN_LEN}个字符` errors.password = `密码至少${CREATE_PASSWORD_MIN_LEN}个字符`
} }
if (operator?.role === 'super_admin' && positiveInt(form.companyId) === null) {
errors.company = '请选择所属公司'
}
return { valid: Object.keys(errors).length === 0, errors } return { valid: Object.keys(errors).length === 0, errors }
} }
/** 表单 → 创建请求体:用户名去空格、角色归一、菜单 id 拷贝不共享引用; /**
* createdById 仅在 role=normal 且选了所属管理员时携带(对齐 admin.js 的 created_by_id 语义); * 表单 → 创建请求体:用户名去空格、角色归一、菜单 id 拷贝不共享引用;
* companyId 选了才带,未选时由后端落操作者自己公司。 */ * createdById 仅在 role=normal 且选了所属管理员时携带(对齐 admin.js 的 created_by_id 语义)。
*
* <p>故意不带 company_id:归属由后端 `AdminUserService#resolveTargetCompanyId` 落操作者自己的公司。
* 页面上没有公司可选项(2026-10-04 定案),所以这条是"新账号归哪家公司"的唯一口径 ——
* 想给别的公司建号,得用那个公司自己的 admin 登录,不是在这里改请求体。</p>
*/
export function toCreateUserRequest(form: CreateUserForm): CreateUserPayload { export function toCreateUserRequest(form: CreateUserForm): CreateUserPayload {
const payload: CreateUserPayload = { const payload: CreateUserPayload = {
username: (form.username || '').trim(), username: (form.username || '').trim(),
@@ -119,7 +79,5 @@ export function toCreateUserRequest(form: CreateUserForm): CreateUserPayload {
if (payload.role === 'normal' && form.createdBy != null) { if (payload.role === 'normal' && form.createdBy != null) {
payload.createdById = form.createdBy payload.createdById = form.createdBy
} }
const companyId = positiveInt(form.companyId)
if (companyId !== null) payload.companyId = companyId
return payload return payload
} }
@@ -9,8 +9,6 @@ export interface UserFilterState {
createdByAdminId: number | null createdByAdminId: number | null
/** 角色过滤(''=全部;super_admin/admin/normal)。 */ /** 角色过滤(''=全部;super_admin/admin/normal)。 */
role: string role: string
/** 按所属公司过滤(null=全部);只有超管能用,公司内 admin 看到的本来就是本公司。 */
companyId: number | null
page: number page: number
pageSize: number pageSize: number
} }
@@ -20,7 +18,6 @@ export function createUserFilterState(): UserFilterState {
keyword: '', keyword: '',
createdByAdminId: null, createdByAdminId: null,
role: '', role: '',
companyId: null,
page: USER_PAGE_MIN_PAGE, page: USER_PAGE_MIN_PAGE,
pageSize: USER_PAGE_DEFAULT_SIZE, pageSize: USER_PAGE_DEFAULT_SIZE,
} }
@@ -29,7 +26,7 @@ export function createUserFilterState(): UserFilterState {
/** 修改筛选条件时重置回第一页(避免停在可能越界的旧页)。 */ /** 修改筛选条件时重置回第一页(避免停在可能越界的旧页)。 */
export function withFilterReset( export function withFilterReset(
state: UserFilterState, state: UserFilterState,
next: Partial<Pick<UserFilterState, 'keyword' | 'createdByAdminId' | 'role' | 'companyId'>>, next: Partial<Pick<UserFilterState, 'keyword' | 'createdByAdminId' | 'role'>>,
): UserFilterState { ): UserFilterState {
return { ...state, ...next, page: USER_PAGE_MIN_PAGE } return { ...state, ...next, page: USER_PAGE_MIN_PAGE }
} }
@@ -41,11 +38,7 @@ export function withPage(state: UserFilterState, page: number): UserFilterState
/** 是否存在生效筛选(仅空白关键字不算)。 */ /** 是否存在生效筛选(仅空白关键字不算)。 */
export function isFilterActive(state: UserFilterState): boolean { export function isFilterActive(state: UserFilterState): boolean {
return ( return Boolean(state.keyword && state.keyword.trim()) || state.createdByAdminId != null
Boolean(state.keyword && state.keyword.trim()) ||
state.createdByAdminId != null ||
state.companyId != null
)
} }
/** 页面状态 → 查询适配层参数(空关键字不下发)。 */ /** 页面状态 → 查询适配层参数(空关键字不下发)。 */
@@ -56,7 +49,6 @@ export function toUserListParams(state: UserFilterState): UserListParams {
pageSize: state.pageSize, pageSize: state.pageSize,
keyword: keyword || undefined, keyword: keyword || undefined,
createdById: state.createdByAdminId, createdById: state.createdByAdminId,
companyId: state.companyId,
} }
const role = (state.role || '').trim() const role = (state.role || '').trim()
if (role) params.role = role if (role) params.role = role
-5
View File
@@ -106,11 +106,6 @@ button, input, textarea, select { font: inherit; }
.admin-user { display: flex; align-items: center; gap: 14px; } .admin-user { display: flex; align-items: center; gap: 14px; }
.admin-user-meta { display: flex; align-items: flex-end; flex-direction: column; } .admin-user-meta { display: flex; align-items: flex-end; flex-direction: column; }
.admin-user-meta strong { font-size: 13px; font-weight: 600; color: var(--admin-text); } .admin-user-meta strong { font-size: 13px; font-weight: 600; color: var(--admin-text); }
.admin-user-company {
max-width: 200px; margin-top: 3px;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
color: #6b8096; font-size: 11.5px;
}
.admin-user-role { .admin-user-role {
display: inline-flex; align-items: center; display: inline-flex; align-items: center;
padding: 2px 10px; border-radius: 999px; font-size: 12px; line-height: 1.7; padding: 2px 10px; border-radius: 999px; font-size: 12px; line-height: 1.7;
-4
View File
@@ -11,10 +11,6 @@ export interface AdminUser {
isAdmin?: boolean isAdmin?: boolean
createdById?: number | null createdById?: number | null
creatorUsername?: string creatorUsername?: string
/** 所属公司(V143):列表来自 AdminUserItemVo 的 company_id/company_name,
* current-user 来自 AdminConsoleController 的 camelCase 摘要。 */
companyId?: number | null
companyName?: string
createdAt?: string createdAt?: string
updatedAt?: string updatedAt?: string
pinyinAbbr?: string pinyinAbbr?: string
@@ -1,72 +1,114 @@
import { test } from 'node:test' import test from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { import {
initialCompanyId, createEmptyCreateUserForm,
selectableCompanies,
toCreateUserRequest, toCreateUserRequest,
validateCreateUserForm, validateCreateUserForm,
createEmptyCreateUserForm,
} from '../src/pages/account/user-create-model.ts' } from '../src/pages/account/user-create-model.ts'
import { COMPANY_STATUS_ACTIVE, COMPANY_STATUS_DISABLED, type CompanyItem } from '../src/api/companies-dto.ts' import { OPERATION_GUIDES } from '../src/layout/operation-guides.ts'
/** 建号表单的公司归属(设计文档 §2.2):超管必须显式选一家;公司内 admin 只能落自己公司。 */ /**
* 建号不再让用户挑公司(2026-10-04 15:4x 定案)。
const xiamen: CompanyItem = { id: 1, companyName: '厦门米椿花', status: COMPANY_STATUS_ACTIVE, remark: null, createdAt: null, updatedAt: null } *
const fuzhou: CompanyItem = { id: 2, companyName: '福州数富', status: COMPANY_STATUS_ACTIVE, remark: null, createdAt: null, updatedAt: null } * <p>归属这件事改由后端单点决定:请求体不带 company_id 时,`resolveTargetCompanyId` 落操作者自己的公司。
const stopped: CompanyItem = { id: 3, companyName: '已停用公司', status: COMPANY_STATUS_DISABLED, remark: null, createdAt: null, updatedAt: null } * 所以"前端删掉下拉是安全的"这个结论完全靠那条后端分支撑着 —— 下面最后一用例把它钉成可执行断言,
const ALL = [xiamen, fuzhou, stopped] * 谁把那边改成"必填公司",这边立刻红。</p>
*/
const SUPER = { role: 'super_admin', companyId: 1 }
const ADMIN = { role: 'admin', companyId: 2 }
function form(overrides: Record<string, unknown> = {}) { function form(overrides: Record<string, unknown> = {}) {
return { ...createEmptyCreateUserForm(), username: 'zhangsan', password: 'secret123', ...overrides } return { ...createEmptyCreateUserForm(), username: 'zhangsan', password: 'secret123', ...overrides }
} }
test('超管可选公司 = 启用中的公司,停用的不出现', () => { test('空表单里没有公司这一项', () => {
assert.deepEqual(selectableCompanies(ALL, SUPER).map((c) => c.id), [1, 2]) const blank = createEmptyCreateUserForm()
assert.equal('companyId' in blank, false)
assert.deepEqual(blank, { username: '', password: '', role: 'normal', columnIds: [], createdBy: null })
}) })
test('公司内 admin 只列自己公司,不看状态', () => { test('校验只看用户名与密码,不再要求选公司', () => {
// 后端对非超管直接落 operator.companyId、不校验启用状态;前端跟着把本公司列出, assert.deepEqual(validateCreateUserForm(form()), { valid: true, errors: {} })
// 否则会出现「下拉里没得选、提交却能建号」的自相矛盾。
assert.deepEqual(selectableCompanies(ALL, ADMIN).map((c) => c.id), [2])
const ownStopped = [{ ...xiamen, status: COMPANY_STATUS_DISABLED }, fuzhou]
assert.deepEqual(selectableCompanies(ownStopped, { role: 'admin', companyId: 1 }).map((c) => c.id), [1])
})
test('操作者没有公司归属时不给出任何可选项', () => {
assert.deepEqual(selectableCompanies(ALL, { role: 'admin', companyId: null }), [])
assert.deepEqual(selectableCompanies(ALL, { role: 'admin' }), [])
})
test('超管不选公司就是校验不过,不能静默落自己公司', () => {
const missing = validateCreateUserForm(form({ companyId: null }), SUPER)
assert.equal(missing.valid, false)
assert.match(missing.errors.company || '', /公司/)
assert.equal(validateCreateUserForm(form({ companyId: 2 }), SUPER).valid, true)
})
test('非超管不要求选公司(后端强制落自己公司)', () => {
assert.equal(validateCreateUserForm(form({ companyId: null }), ADMIN).valid, true)
})
test('不带操作者时保持原有校验口径(老调用方不受影响)', () => {
assert.equal(validateCreateUserForm(form()).valid, true)
assert.equal(validateCreateUserForm(form({ username: 'a' })).errors.username !== undefined, true) assert.equal(validateCreateUserForm(form({ username: 'a' })).errors.username !== undefined, true)
assert.equal(validateCreateUserForm(form({ password: '123' })).errors.password !== undefined, true)
}) })
test('请求体带 camelCase companyId,未选时不带该键', () => { test('请求体不带 companyId,其余字段照旧', () => {
assert.equal(toCreateUserRequest(form({ companyId: 2 })).companyId, 2) assert.deepEqual(toCreateUserRequest(form({ columnIds: [3, 1] })), {
assert.equal('companyId' in toCreateUserRequest(form({ companyId: null })), false) username: 'zhangsan',
assert.equal('companyId' in toCreateUserRequest(form({ companyId: 0 })), false) password: 'secret123',
role: 'normal',
columnIds: [3, 1],
})
// 所属管理员仍按原语义携带(仅 normal 角色)
assert.equal(toCreateUserRequest(form({ role: 'normal', createdBy: 5 })).createdById, 5)
assert.equal('createdById' in toCreateUserRequest(form({ role: 'admin', createdBy: 5 })), false)
assert.equal('companyId' in toCreateUserRequest(form()), false,
'不传 company_id 才会走后端"落操作者公司"那条分支')
}) })
test('弹窗打开时的默认公司:候选只有一个就落它,多个则不替超管决定', () => { test('建号模型源码里公司口径已摘干净', () => {
// 公司内 admin 只有一家在选,预选上省一步,也不会出现"没选就提交"的空值。 const mod = readSource('src/pages/account/user-create-model.ts')
assert.equal(initialCompanyId(ADMIN, ALL), 2) assert.equal(/companyId|CompanyItem|selectableCompanies|initialCompanyId|CreateOperatorScope/.test(mod), false,
// 超管面对多家时必须自己选:默认值等于替他决定账号挂在哪家,这是会写进库的判断。 '公司相关的类型、可选项收窄函数、预选函数都应整体删除')
assert.equal(initialCompanyId(SUPER, ALL), null) const dialog = readSource('src/pages/account/CreateUserDialog.vue')
// 本公司压根不在列表里时不猜(返回 null 让后端按 operator 归属落库)。 assert.equal(/companyId|CompanyItem|所属公司|selectableCompanies/.test(dialog), false,
assert.equal(initialCompanyId(ADMIN, [xiamen]), null) '弹窗不再有公司选择;操作者角色门控(operatorSuper)保留,它管的是角色与所属管理员下拉')
assert.match(dialog, /operatorSuper/, '角色/所属管理员仍按操作者是否超管收窄')
})
/**
* 「公司管理」页那段引导文案原先写着"建号时选哪家公司"。下拉已经删了,这句话就成了错的承诺:
* 管理员会在新建账号弹窗里找一个根本不存在的选择器。
* 同理"停用后不能再用于新建账号"也不成立了——requireActive 只在显式传 company_id 时才走,
* 而页面现在一律不传(接口直连的老调用方仍受它保护,那条由上一用例盯着)。
*/
test('「公司管理」引导文案说的是自动继承,不再让操作员挑公司', () => {
const guide = OPERATION_GUIDES.admin_companies.text
assert.match(guide, /操作者自己所在的公司/, '要写清归属的真实口径:落在操作者本公司')
assert.match(guide, /请用那个公司自己的管理员登录|用该公司自己的管理员登录/,
'要给别家建号只能换账号登录——不写这句,超管会以为自己建的号能归到别家')
for (const stale of ['建号时选哪家公司', '选哪家公司', '停用后不能再用于新建账号']) {
assert.equal(guide.includes(stale), false, `文案仍含已失效的说法:${stale}`)
}
})
/** 从 Java 源码里按大括号配平切出一个方法体(只看 resolveTargetCompanyId,别把邻居方法的 throw 算进来)。 */
function javaMethod(source: string, signature: string): string {
const start = source.indexOf(signature)
assert.ok(start >= 0, `找不到方法签名:${signature}`)
let depth = 0
let seen = false
for (let i = source.indexOf('{', start); i < source.length; i++) {
if (source[i] === '{') {
depth++
seen = true
} else if (source[i] === '}') {
depth--
if (seen && depth === 0) return source.slice(start, i + 1)
}
}
assert.fail(`${signature} 大括号不配平,切片失败`)
return ''
}
test('后端仍然把"没传公司"落成操作者自己公司(前端删下拉的前提)', () => {
const java = readSource(
'../backend-java/src/main/java/com/nanri/aiimage/modules/admin/service/AdminUserService.java',
)
// 只切 resolveTargetCompanyId:resolveCompanyMove 里也有 "super_admin".equals(operatorRole) + throw,
// 拿整份文件做正则会把它算进来,那条本来就该抛。
const body = javaMethod(java, 'private Long resolveTargetCompanyId(').replace(/\s+/g, ' ')
// 两条分支都必须"落操作者公司":超管不传=自己公司,非超管不传=自己公司。
// 少任何一条,页面上就没有别的办法决定归属了——建号会直接失败,而不是退回"归到某一家"。
assert.equal(
(body.match(/return operator\.getCompanyId\(\);/g) || []).length,
2,
'resolveTargetCompanyId 应有两处"落操作者公司"(非超管分支 + 超管未传分支),实际 ' + body,
)
assert.match(body, /if \(!"super_admin"\.equals\(operatorRole\)\) \{.*return operator\.getCompanyId\(\);/)
assert.match(body, /if \(requestedCompanyId == null\) \{ return operator\.getCompanyId\(\); \}/,
'"没传公司"这条分支是"新账号归操作者本公司"的唯一依据,删掉它前端就没有任何地方能定归属')
assert.match(body, /companyService\.requireActive\(requestedCompanyId\)/,
'显式传公司时仍要校验启用状态(接口直连的老调用方不会被绕过)')
}) })
@@ -7,79 +7,86 @@ import {
createUserFilterState, createUserFilterState,
isFilterActive, isFilterActive,
toUserListParams, toUserListParams,
withFilterReset,
} from '../src/pages/account/users-filter.ts' } from '../src/pages/account/users-filter.ts'
import { topbarUserOf } from '../src/layout/topbar-model.ts' import { topbarUserOf } from '../src/layout/topbar-model.ts'
/** 公司维度进账号页(设计文档 §2.3/§5.1):列表列、按公司筛选(仅超管)、顶栏公司名。 */ /**
* 公司维度不出现在后台前端(2026-10-04 15:4x 定案,推翻一期 §2.3/§5.1 的"列表加公司列 + 筛选 + 顶栏公司名")。
*
* <p>不显示 ≠ 不存在:建号请求体不带 company_id,归属由后端
* `AdminUserService#resolveTargetCompanyId` 落操作者自己的公司;跨公司隔离发生在消费侧与读取侧
* (二期批次 2/3),不依赖页面把公司名渲染出来。所以这里的断言全部打在"不得回流"上:
* 任何一处重新渲染公司,本文件就红。</p>
*/
test('company_user_list_item_reads_snake_case_company_columns', () => { test('公司列不再写进列表项,但其余字段必须照常解析', () => {
const item = toAdminUserItem({ const item = toAdminUserItem({
id: 7, id: 7,
username: '张三', username: '张三',
role: 'normal', role: 'normal',
company_id: 2, company_id: 2,
company_name: '福州数富', company_name: '福州数富',
created_by_id: 5,
creator_username: 'admin',
}) })
assert.equal(item?.companyId, 2) assert.ok(item, '解析结果不该为 null')
assert.equal(item?.companyName, '福州数富') assert.equal('companyId' in item, false, '后端仍会带 company_id/company_name,前端不再往列表项里写')
assert.equal('companyName' in item, false)
// 反向自检:不许靠"整条解析都坏了"变绿
assert.equal(item.id, 7)
assert.equal(item.username, '张三')
assert.equal(item.createdById, 5)
assert.equal(item.creatorUsername, 'admin')
}) })
test('company_user_list_item_ignores_camel_case_company_keys', () => { test('筛选状态与查询参数里都没有公司这一维', () => {
// 反向排他:后端 AdminUserItemVo 走 @JsonProperty snake_case,解析器若跟着读 camelCase 就是双向猜。 const state = createUserFilterState()
const item = toAdminUserItem({ id: 7, username: '张三', role: 'normal', companyId: 9, companyName: '别家' }) assert.equal('companyId' in state, false)
assert.equal(item?.companyId, undefined) assert.deepEqual(state, { keyword: '', createdByAdminId: null, role: '', page: 1, pageSize: 10 })
assert.equal(item?.companyName, undefined)
const params = toUserListParams({ ...state, keyword: ' x ', createdByAdminId: 4 })
assert.equal('companyId' in params, false)
assert.equal(isFilterActive({ ...state, keyword: ' ' }), false)
const query = toUserListQuery(normalizeUserPageParams({ page: 2, pageSize: 20, keyword: 'x' }))
assert.equal('company_id' in query, false, '绝不下发 company_id:一旦下发就是"只看这家"的过滤')
}) })
test('company_user_list_filter_state_defaults_to_no_company', () => { test('顶栏不再渲染公司名', () => {
assert.equal(createUserFilterState().companyId, null) const vm = topbarUserOf({ id: 1, username: 'admin', role: 'admin', companyName: '厦门米椿花' } as never)
// 改了公司筛选要回第一页,与其他筛选条件同规则 assert.equal('company' in vm, false)
const next = withFilterReset({ ...createUserFilterState(), page: 5 }, { companyId: 3 }) assert.deepEqual(vm, { username: 'admin', role: '管理员', hasUser: true })
assert.equal(next.companyId, 3) assert.equal(topbarUserOf(null).hasUser, false)
assert.equal(next.page, 1)
assert.equal(isFilterActive({ ...createUserFilterState(), companyId: 3 }), true)
}) })
test('company_user_list_query_sends_company_id_only_when_selected', () => { test('账号页与顶栏的源码里公司维度已摘干净', () => {
const withCompany = toUserListQuery(normalizeUserPageParams({ page: 1, pageSize: 10, companyId: 3 }))
assert.equal(withCompany.company_id, 3)
assert.equal(
'company_id' in toUserListQuery(normalizeUserPageParams({ page: 1, pageSize: 10 })),
false,
'未选公司时不下发 company_id,否则后端会当成"只看这家公司"过滤',
)
})
test('company_user_list_params_adapter_carries_company_id', () => {
const params = toUserListParams({ ...createUserFilterState(), companyId: 2 })
assert.equal(params.companyId, 2)
})
test('company_topbar_shows_company_name', () => {
assert.equal(
topbarUserOf({ id: 1, username: 'admin', role: 'admin', companyName: ' 厦门米椿花 ' }).company,
'厦门米椿花',
)
// 未登录空态与"后端没带公司"都必须是不显示,而不是渲染出 undefined
assert.equal(topbarUserOf(null).company, '')
assert.equal(topbarUserOf({ id: 1, username: 'admin', role: 'admin' }).company, '')
})
test('company_user_list_page_ui_wiring', () => {
const page = readSource('src/pages/account/UsersPage.vue') const page = readSource('src/pages/account/UsersPage.vue')
assert.match(page, /所属公司/, '账号页要有公司这一列/筛选的中文标签') assert.equal(/所属公司/.test(page), false, '账号页不该再出现「所属公司」标签')
assert.match(page, /fetchCompanies/, '公司候选来自 /api/admin/companies') assert.equal(/companyId|companyName|companies/.test(page), false, '页面不再持有公司目录或公司筛选状态')
assert.match(page, /:companies="companies"/, '整份公司目录交给弹窗,由弹窗按操作者收窄') assert.equal(/fetchCompanies/.test(page), false, '公司目录接口不该再被账号页调用')
assert.match(page, /:operator="operatorScope"/, '弹窗要拿到操作者角色与归属才能判必选')
assert.match(page, /colspan="8"/, '加了公司列后空态横跨整表') // 「删了列忘了改占位行 colspan」是这类改动最常留下的残行:按表头列数交叉核对
// (`<th` 是 `<thead` 的前缀,必须带上后随字符才数得准)
const headers = (page.match(/<th[\s>]/g) || []).length
const spans = [...page.matchAll(/colspan="(\d+)"/g)].map((m) => Number(m[1]))
assert.ok(spans.length >= 1, '列表 tbody 没有 colspan 占位行')
for (const span of spans) assert.equal(span, headers, `占位行 colspan=${span} 与表头列数 ${headers} 不符`)
const dialog = readSource('src/pages/account/CreateUserDialog.vue') const dialog = readSource('src/pages/account/CreateUserDialog.vue')
assert.match(dialog, /selectableCompanies\(/, '下拉选项走同一条后端收窄规则') assert.equal(/所属公司|selectableCompanies|initialCompanyId|companyId/.test(dialog), false,
assert.match(dialog, /initialCompanyId\(/, '打开弹窗时的默认公司走纯函数,不在模板里现写') '建号弹窗不该再有公司选择')
assert.match(dialog, /请选择所属公司/, '下拉占位与校验文案同源')
assert.match(dialog, /validateCreateUserForm\(form, props\.operator\)/, '校验必须带上操作者,否则"超管必选公司"永远不触发')
const layout = readSource('src/layout/AdminLayout.vue') const layout = readSource('src/layout/AdminLayout.vue')
assert.match(layout, /userVm\.company/, '顶栏走同一条公司名视图模型') assert.equal(/userVm\.company|admin-user-company/.test(layout), false, '顶栏旁白只剩用户名与角色')
// 视图模型只删映射、留着 company 字段="接口说有、运行时永远空",是最难看出来的一种回流
const topbar = readSource('src/layout/topbar-model.ts')
assert.equal(/compan/i.test(topbar), false, '顶栏模型里不该再出现公司字段(连类型一起删)')
const filter = readSource('src/pages/account/users-filter.ts')
assert.equal(/companyId/.test(filter), false)
const dto = readSource('src/api/users-dto.ts')
assert.equal(/company_id|companyId/.test(dto), false)
const model = readSource('src/api/users-model.ts')
assert.equal(/company_id|company_name/.test(model), false)
}) })
+2 -3
View File
@@ -57,9 +57,8 @@ test('test_task_043_user_filter_state_invalid_input_rejected', () => {
// 异常输入:仅空白关键字不视为激活;筛选与分页参数映射正确。 // 异常输入:仅空白关键字不视为激活;筛选与分页参数映射正确。
assert.equal(isFilterActive({ ...createUserFilterState(), keyword: ' ' }), false) assert.equal(isFilterActive({ ...createUserFilterState(), keyword: ' ' }), false)
const params = toUserListParams({ ...createUserFilterState(), keyword: ' x ', page: 2, pageSize: 20 }) const params = toUserListParams({ ...createUserFilterState(), keyword: ' x ', page: 2, pageSize: 20 })
// companyId 自 V143(多公司一期)起是筛选状态的一等字段:未选时同样以 null 出现在参数里, // 公司维度已于 2026-10-04 从前端摘掉(见 company-user-list.test.ts),筛选状态只剩这三项。
// 是否下发由 toUserListQuery 决定(见 company-user-list.test.ts)。 assert.deepEqual(params, { page: 2, pageSize: 20, keyword: 'x', createdById: null })
assert.deepEqual(params, { page: 2, pageSize: 20, keyword: 'x', createdById: null, companyId: null })
}) })
test('test_task_043_user_filter_state_dependency_failure_returns_actionable_message', () => { test('test_task_043_user_filter_state_dependency_failure_returns_actionable_message', () => {