feat(账号到期+公司超管): 级联过期判定、过期停任务巡检与两端续费提醒弹窗
需求两条:站点超管可开设其他公司的超级管理员(站点超管看全站、公司超管只看本公司、 组内管理员仍只看本组);账号要有过期时间,管理员过期后名下普通账户一并停用、 正在跑的任务也要停掉。落库只有 users.expires_at(V146,NULL=永不过期),级联一律现算, 不写"上级过期就把下级置成过期"那种续费也救不回来的数据。 - AccountExpiryService:生效到期 = min(自身, 本公司公司超管, 成员表组长, 创建人)。 登录拦 403(文案给续费提示)、每次请求鉴权拦 401(前端按下线踢回登录页),super_admin 永不适用。级联口径与数据可见范围同源(成员表基本未用、实际按 created_by_id 派生)。 - ExpiredAccountTaskStopService:每分钟把过期账号(含级联成员)名下 biz_file_task PENDING/SCHEDULED/RUNNING → FAILED,含未领取的 PENDING(防内部通道继续派发)。原因文案 刻意不以「客户端异常中断」开头,否则会被 TaskResumeService 自动复活。品牌采集与跟价循环 不在那张表上,经 ExpiredAccountTaskStopSpi 由各自模块停:品牌 pending/running→cancelled 且 UPDATE 的 WHERE 二次核对状态(抢到行后被客户端推进成完成的行不得误杀),跟价循环只置 stop_requested=1、沿用用户点「停止循环」那条收尾路径,绝不动 status。任务心跳接口保持匿名 不走 requireUser,所以过期账号的客户端仍能拿到 alive=false 协作停止。 - 角色 company_super_admin:由站点超管开设(唯一要显式选公司的建号场景),建号/授菜单/改用户/ 看数据四条链路都按"本公司"收口;公司超管之间、以及公司超管与站点超管互相碰不得。 - 续费提醒:剩余 <5 天在数富后台与用户端弹窗,只能收起不能关闭(无关闭按钮,收起态是右下角 浮标),续费到 ≥5 天自动消失。后台读 /api/admin/current-user 的 expiresAt/daysToExpire; 用户端无 Pinia,走 localStorage 的 account_expires_at(登录/check_login 落键、被顶下线清键, 换账号不残留)。只反映账号自身到期,弹窗不做任何级联推断。 - V146 撞掉了 V145 那批的一条护栏:它按"db/ 里不许出现 V146__ 前缀"编死号位,被一条正常的 前向迁移占用就红。改成钉动作——剥注释后的可执行 SQL 不得写 flyway_schema_history(回滚 一律是扫描路径外的人工补丁),并把盘点文档改 V146 时丢掉的 V145 文件名补回去。 验证(本会话亲跑,不是转述):后端定向 14 类 123/0(同一轮 mvn 里连批次③的 4 类 53 例、以及既有 ShopDataCrawl/SimilarAsin 两条回归对照 21 例一起跑,合计 197 例 0 红);admin-frontend-vue 本批定向 44/0(弹窗 7 + 公司建号/列表/入口/日期默认 21 + 角色 task-48/task-251 16),全量 1726 例里那 1 支红是另一条 会话刻意留的「公司 tab 接线缺口」尺子(点名 admin_task_center 等 6 页,与本批无关); frontend-vue 弹窗 9/0、全量 710/0。变异自证两批共 34 点:弹窗语义 16 点全杀(阈值 5、只能收起 不能关闭、挂载点含"注释掉挂载"、落键/清键链路),本批 SPI+迁移护栏 17 点全杀(含 G2 反向: 前向迁移只在注释里提 flyway_schema_history 必须照样绿),注入文件还原 dirty=0、探针残留 0。
This commit is contained in:
@@ -27,6 +27,8 @@ export function toAdminUserItem(raw: unknown): AdminUser | null {
|
||||
if (updatedAt) item.updatedAt = updatedAt
|
||||
const creator = text(r.creator_username)
|
||||
if (creator) item.creatorUsername = creator
|
||||
const expiresAt = text(r.expires_at)
|
||||
if (expiresAt) item.expiresAt = expiresAt
|
||||
const abbr = text(r.pinyin_abbr)
|
||||
if (abbr) item.pinyinAbbr = abbr
|
||||
return item
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 到期续费提醒(V146,2026-10-05 需求):
|
||||
* 「管理员快过期的时候(仅剩 5 天不到开始)要在数富后台界面上有个弹窗去提醒,
|
||||
* 只能缩小但是不能关闭,直到续费超过 5 天才消失。」
|
||||
*
|
||||
* - 数据源:/api/admin/current-user 的 expiresAt/daysToExpire(session store 的 user 上);
|
||||
* 只反映账号自身 expires_at,不级联——续费是账号自己的事。
|
||||
* - 触发:0 ≤ daysToExpire < 5(剩余不足 5 天)。刷新/重新登录后按最新值判定,
|
||||
* 续费到 ≥5 天自动消失,无需手动关。
|
||||
* - 只能缩小不能关闭:无关闭按钮;缩小态是右下角常驻浮标,点开即恢复。
|
||||
* - 缩小状态按「用户 + 到期值」记 localStorage:续费(到期值变化)后重置为展开。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
const props = defineProps<{
|
||||
/** 展示阈值(天):daysToExpire < EXPIRY_NOTICE_DAYS 时展示。需求口径 = 5(不足 5 天)。 */
|
||||
threshold?: number
|
||||
}>()
|
||||
|
||||
const THRESHOLD = props.threshold ?? 5
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const user = computed(() => session.user)
|
||||
const daysToExpire = computed<number | null>(() => {
|
||||
const value = user.value?.daysToExpire
|
||||
return typeof value === 'number' && Number.isFinite(value) ? value : null
|
||||
})
|
||||
const visible = computed(() => daysToExpire.value !== null && daysToExpire.value < THRESHOLD)
|
||||
const expiresAt = computed(() => (user.value?.expiresAt || '').trim())
|
||||
|
||||
const minimized = ref(false)
|
||||
const minimizedKey = computed(() =>
|
||||
user.value ? `admin-expiry-notice-min:${user.value.id}:${expiresAt.value}` : '',
|
||||
)
|
||||
watch(
|
||||
minimizedKey,
|
||||
(key) => {
|
||||
minimized.value = key ? localStorage.getItem(key) === '1' : false
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function minimize(): void {
|
||||
minimized.value = true
|
||||
if (minimizedKey.value) {
|
||||
try {
|
||||
localStorage.setItem(minimizedKey.value, '1')
|
||||
} catch {
|
||||
/* localStorage 不可用时仅本次会话生效 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function restore(): void {
|
||||
minimized.value = false
|
||||
if (minimizedKey.value) {
|
||||
try {
|
||||
localStorage.removeItem(minimizedKey.value)
|
||||
} catch {
|
||||
/* 同上 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const daysText = computed(() => {
|
||||
const days = daysToExpire.value
|
||||
if (days === null) return ''
|
||||
return days <= 0 ? '不足 1 天' : `还剩 ${days} 天`
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="visible">
|
||||
<div
|
||||
v-if="!minimized"
|
||||
class="expiry-notice"
|
||||
role="alert"
|
||||
aria-live="assertive"
|
||||
>
|
||||
<div class="expiry-notice-body">
|
||||
<strong>服务即将到期</strong>
|
||||
<span>
|
||||
您的账号{{ expiresAt ? `(${expiresAt})` : '' }}即将到期,{{ daysText }}。
|
||||
到期后账号将无法登录,名下账号与正在执行的任务也会一并停止,请联系管理员续费。
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
class="expiry-notice-min"
|
||||
type="button"
|
||||
title="收起(不可关闭,续费前会一直提醒)"
|
||||
@click="minimize"
|
||||
>
|
||||
收起
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
v-else
|
||||
class="expiry-notice-chip"
|
||||
type="button"
|
||||
:title="`服务即将到期:${daysText},点击展开`"
|
||||
@click="restore"
|
||||
>
|
||||
⏰ {{ daysText }}
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.expiry-notice {
|
||||
position: fixed;
|
||||
right: 24px;
|
||||
bottom: 24px;
|
||||
z-index: 3000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
max-width: 420px;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid #e4b363;
|
||||
border-radius: 12px;
|
||||
background: #fffaf0;
|
||||
color: #7a4d0b;
|
||||
box-shadow: 0 12px 32px -18px rgba(122, 77, 11, 0.55);
|
||||
}
|
||||
.expiry-notice-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
.expiry-notice-body strong {
|
||||
font-size: 14px;
|
||||
}
|
||||
.expiry-notice-min {
|
||||
flex-shrink: 0;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #e4b363;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #7a4d0b;
|
||||
font-size: 12.5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.expiry-notice-min:hover {
|
||||
background: #fdf3dd;
|
||||
}
|
||||
.expiry-notice-chip {
|
||||
position: fixed;
|
||||
right: 24px;
|
||||
bottom: 24px;
|
||||
z-index: 3000;
|
||||
padding: 8px 14px;
|
||||
border: 1px solid #e4b363;
|
||||
border-radius: 999px;
|
||||
background: #fffaf0;
|
||||
color: #7a4d0b;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 20px -12px rgba(122, 77, 11, 0.5);
|
||||
}
|
||||
</style>
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from '@/layout/empty-state'
|
||||
import GlobalErrorContainer from '@/layout/GlobalErrorContainer.vue'
|
||||
import NotificationBell from '@/components/NotificationBell.vue'
|
||||
import ExpiryNotice from '@/components/ExpiryNotice.vue'
|
||||
import OperationGuide from '@/layout/OperationGuide.vue'
|
||||
import CompanyTabs from '@/layout/CompanyTabs.vue'
|
||||
import { crumbsForActiveRoute, resolveDocumentTitle, updateDocumentTitle } from '@/layout/title-breadcrumb'
|
||||
@@ -127,6 +128,7 @@ async function signOut() {
|
||||
<RouterView v-else />
|
||||
</main>
|
||||
</section>
|
||||
<ExpiryNotice />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
|
||||
steps: ['筛选用户或状态', '立即检测连通性', '必要时清空'],
|
||||
},
|
||||
admin_companies: {
|
||||
text: '公司决定账号归属:新建账号自动落在操作者自己所在的公司,页面上不出现公司选项——要给别的公司建号,请用那个公司自己的管理员登录。公司只做启用/停用,不提供删除。',
|
||||
text: '公司决定账号归属:新建普通账号/管理员自动落在操作者自己所在的公司,页面上不出现公司选项——要给别的公司建号,请用那个公司自己的管理员登录。唯一例外是「公司超级管理员」:由站点超管开设、需在建号弹窗中显式选择所属公司。公司只做启用/停用,不提供删除。',
|
||||
steps: ['查看公司列表', '新建公司', '改名或启停'],
|
||||
},
|
||||
admin_dedupe_total_data: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { submitCreateUser } from './user-create-adapter'
|
||||
import {
|
||||
createEmptyCreateUserForm,
|
||||
@@ -14,8 +14,12 @@ import UserMenuAuthTree from './UserMenuAuthTree.vue'
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
operatorSuper?: boolean
|
||||
/** 操作者角色(company_super_admin 也能建管理员/普通账号)。 */
|
||||
operatorRole?: string | null
|
||||
/** 所属管理员候选(列表响应 admins;仅超管创建普通账号时展示)。 */
|
||||
adminOptions?: Array<{ id: number; username: string }>
|
||||
/** 公司候选(站点超管创建公司超级管理员时必选)。 */
|
||||
companyOptions?: Array<{ id: number; companyName: string }>
|
||||
}>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'created'): void }>()
|
||||
|
||||
@@ -23,11 +27,17 @@ const form = reactive<CreateUserForm>(createEmptyCreateUserForm())
|
||||
const errors = reactive<CreateUserFormErrors>({})
|
||||
const busy = ref(false)
|
||||
|
||||
/** 角色下拉(对齐 admin.html:普通账号/管理员;超管才显示可改)。 */
|
||||
const ROLE_CHOICES: Array<{ value: 'admin' | 'normal'; label: string }> = [
|
||||
{ value: 'normal', label: '普通账号' },
|
||||
/** 角色下拉:站点超管可选公司超管/管理员/普通账号;公司超管只可选管理员/普通账号;
|
||||
* 普通管理员不显示角色选择(后端强制 normal)。 */
|
||||
const ROLE_CHOICES: Array<{ value: 'company_super_admin' | 'admin' | 'normal'; label: string }> = [
|
||||
{ value: 'company_super_admin', label: '公司超级管理员' },
|
||||
{ value: 'admin', label: '管理员' },
|
||||
{ value: 'normal', label: '普通账号' },
|
||||
]
|
||||
const canChooseRole = computed(() => props.operatorSuper || props.operatorRole === 'company_super_admin')
|
||||
const roleChoices = computed(() =>
|
||||
props.operatorSuper ? ROLE_CHOICES : ROLE_CHOICES.filter((opt) => opt.value !== 'company_super_admin'),
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
@@ -38,8 +48,11 @@ watch(
|
||||
form.role = 'normal'
|
||||
form.columnIds = []
|
||||
form.createdBy = null
|
||||
form.expiresAt = ''
|
||||
form.companyId = null
|
||||
errors.username = undefined
|
||||
errors.password = undefined
|
||||
errors.companyId = undefined
|
||||
},
|
||||
)
|
||||
|
||||
@@ -92,9 +105,29 @@ async function create(): Promise<void> {
|
||||
@input="errors.password = undefined"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="operatorSuper" label="角色">
|
||||
<el-form-item v-if="canChooseRole" label="角色">
|
||||
<el-select filterable v-model="form.role" style="width: 200px">
|
||||
<el-option v-for="opt in ROLE_CHOICES" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
<el-option v-for="opt in roleChoices" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="operatorSuper && form.role === 'company_super_admin'"
|
||||
label="所属公司"
|
||||
:error="errors.companyId"
|
||||
>
|
||||
<el-select
|
||||
v-model="form.companyId"
|
||||
filterable
|
||||
placeholder="请选择公司(必选)"
|
||||
style="width: 240px"
|
||||
@change="errors.companyId = undefined"
|
||||
>
|
||||
<el-option
|
||||
v-for="company in props.companyOptions || []"
|
||||
:key="company.id"
|
||||
:label="company.companyName"
|
||||
:value="company.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="operatorSuper && form.role === 'normal'" label="所属管理员">
|
||||
@@ -107,6 +140,16 @@ async function create(): Promise<void> {
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="到期时间(留空 = 永不过期;到期后该账号及其名下账号将停用)">
|
||||
<el-date-picker
|
||||
v-model="form.expiresAt"
|
||||
type="datetime"
|
||||
placeholder="选择到期时间"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
style="width: 240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
|
||||
<div class="auth-tree-box">
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import type { AdminUser } from '@/types/admin'
|
||||
import { fillEditUserForm, validateEditUserForm, type EditUserForm, type EditUserFormErrors } from './user-edit-model'
|
||||
import { submitEditUser } from './user-edit-adapter'
|
||||
@@ -11,12 +11,14 @@ import UserMenuAuthTree from './UserMenuAuthTree.vue'
|
||||
const props = defineProps<{ modelValue: boolean; user: AdminUser | null; operatorSuper?: boolean }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'updated'): void }>()
|
||||
|
||||
const form = reactive<EditUserForm>({ uid: 0, username: '', password: '', role: 'normal', columnIds: [], originalRole: '' })
|
||||
const form = reactive<EditUserForm>({ uid: 0, username: '', password: '', role: 'normal', columnIds: [], originalRole: '', expiresAt: '' })
|
||||
const errors = reactive<EditUserFormErrors>({})
|
||||
const busy = ref(false)
|
||||
const loadingAuth = ref(false)
|
||||
/** 授权是否已成功加载:未就绪时保存会把空 columnIds 提交为“清空授权”,必须拦住。 */
|
||||
const authReady = ref(false)
|
||||
/** 公司超管目标:角色单选隐藏(请求体也不带 role),只允许改密码/到期时间/菜单。 */
|
||||
const targetIsCompanySuperAdmin = computed(() => (props.user?.role || '').trim().toLowerCase() === 'company_super_admin')
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
@@ -29,6 +31,7 @@ watch(
|
||||
form.role = base.role
|
||||
form.columnIds = []
|
||||
form.originalRole = base.originalRole
|
||||
form.expiresAt = base.expiresAt
|
||||
errors.password = undefined
|
||||
authReady.value = false
|
||||
void refreshAuth()
|
||||
@@ -100,12 +103,25 @@ async function save(): Promise<void> {
|
||||
@input="errors.password = undefined"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="operatorSuper" label="角色">
|
||||
<el-form-item v-if="operatorSuper && !targetIsCompanySuperAdmin" label="角色">
|
||||
<el-radio-group v-model="form.role">
|
||||
<el-radio-button value="normal">普通账号</el-radio-button>
|
||||
<el-radio-button value="admin">管理员</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="targetIsCompanySuperAdmin" label="角色">
|
||||
<el-input model-value="公司超级管理员" readonly />
|
||||
</el-form-item>
|
||||
<el-form-item label="到期时间(清空 = 永不过期;到期后该账号及其名下账号将停用)">
|
||||
<el-date-picker
|
||||
v-model="form.expiresAt"
|
||||
type="datetime"
|
||||
placeholder="选择到期时间"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
style="width: 240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="props.user && props.user.creatorUsername" label="所属管理员">
|
||||
<el-input :model-value="props.user.creatorUsername" readonly />
|
||||
</el-form-item>
|
||||
|
||||
@@ -8,11 +8,13 @@ import type { AdminUser } from '@/types/admin'
|
||||
import { roleLabel } from '@/types/admin'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { deleteUser, fetchUserList } from '@/api/users'
|
||||
import { fetchCompanies } from '@/api/companies'
|
||||
import { createUserFilterState, toUserListParams, type UserFilterState } from './users-filter'
|
||||
import { totalPageCount } from './user-pagination'
|
||||
import { deleteBlockReason, deleteConfirmMessage } from './user-delete-model'
|
||||
import { listPhaseOf, userListEmptyHint } from './user-list-state'
|
||||
import { isEditableUser } from './user-edit-model'
|
||||
import { editableBy } from './user-edit-model'
|
||||
import { formatExpiryCell } from './user-expiry'
|
||||
import CreateUserDialog from './CreateUserDialog.vue'
|
||||
import EditUserDialog from './EditUserDialog.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
@@ -24,8 +26,11 @@ const rows = ref<AdminUser[]>([])
|
||||
const total = ref(0)
|
||||
/** 所属管理员候选(来自列表响应的 admins),供超管筛选下拉使用。 */
|
||||
const admins = ref<Array<{ id: number; username: string }>>([])
|
||||
/** 公司候选(仅供建号弹窗的「公司超级管理员」下拉使用,2026-10-05 唯一豁免)。 */
|
||||
const companyOptions = ref<Array<{ id: number; companyName: string }>>([])
|
||||
const filters = reactive<UserFilterState>(createUserFilterState())
|
||||
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
||||
const operatorRole = computed(() => session.user?.role ?? null)
|
||||
const currentUserId = computed(() => session.user?.id ?? null)
|
||||
const statePhase = computed(() => listPhaseOf({ loading: loading.value, error: loadError.value, items: rows.value, total: total.value }))
|
||||
const jumpPage = ref('')
|
||||
@@ -40,13 +45,13 @@ function openCreate(): void {
|
||||
}
|
||||
|
||||
function openEdit(row: AdminUser): void {
|
||||
if (!isEditableUser(row.role)) return
|
||||
if (!editableBy(row.role, operatorRole.value)) return
|
||||
editUser.value = row
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
function editableOf(row: AdminUser): boolean {
|
||||
return isEditableUser(row.role)
|
||||
return editableBy(row.role, operatorRole.value)
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
@@ -123,6 +128,16 @@ function goJump() {
|
||||
|
||||
onMounted(() => {
|
||||
void loadUsers()
|
||||
// 公司目录仅站点超管拉取(建「公司超级管理员」时选公司用);非超管不发这个请求,后端 403 兜底
|
||||
if (isSuperAdmin.value) {
|
||||
void fetchCompanies()
|
||||
.then((items) => {
|
||||
companyOptions.value = items.map((c) => ({ id: c.id, companyName: c.companyName }))
|
||||
})
|
||||
.catch(() => {
|
||||
companyOptions.value = []
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -150,6 +165,7 @@ onMounted(() => {
|
||||
<label>角色</label>
|
||||
<el-select v-model="filters.role" class="admin-filter" filterable clearable placeholder="全部角色" @change="search">
|
||||
<el-option label="超级管理员" value="super_admin" />
|
||||
<el-option label="公司超级管理员" value="company_super_admin" />
|
||||
<el-option label="管理员" value="admin" />
|
||||
<el-option label="普通账号" value="normal" />
|
||||
</el-select>
|
||||
@@ -170,6 +186,7 @@ onMounted(() => {
|
||||
<th style="width: 180px">用户名</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: 160px">操作</th>
|
||||
@@ -182,6 +199,9 @@ onMounted(() => {
|
||||
<td>{{ row.username }}</td>
|
||||
<td>{{ roleLabel(row.role) }}</td>
|
||||
<td>{{ row.creatorUsername || '-' }}</td>
|
||||
<td :class="{ 'expiry-cell-expired': formatExpiryCell(row).expired }">
|
||||
{{ formatExpiryCell(row).text }}
|
||||
</td>
|
||||
<td>{{ formatDateTime(row.createdAt) }}</td>
|
||||
<td>{{ formatDateTime(row.updatedAt) }}</td>
|
||||
<td class="ops-cell">
|
||||
@@ -207,10 +227,10 @@ onMounted(() => {
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="7" class="empty-tip">加载中...</td>
|
||||
<td colspan="8" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="7" class="empty-tip">{{ userListEmptyHint() }}</td>
|
||||
<td colspan="8" class="empty-tip">{{ userListEmptyHint() }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -222,7 +242,9 @@ onMounted(() => {
|
||||
<CreateUserDialog
|
||||
v-model="createVisible"
|
||||
:operator-super="isSuperAdmin"
|
||||
:operator-role="operatorRole"
|
||||
:admin-options="admins"
|
||||
:company-options="companyOptions"
|
||||
@created="loadUsers"
|
||||
/>
|
||||
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" @updated="loadUsers" />
|
||||
@@ -415,6 +437,10 @@ h3 {
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.expiry-cell-expired {
|
||||
color: #c0392b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
export const CREATE_USERNAME_MIN_LEN = 2
|
||||
export const CREATE_PASSWORD_MIN_LEN = 6
|
||||
|
||||
/** 新建用户可选角色:super_admin 不可由表单创建(后端只收 admin|normal)。 */
|
||||
export type CreatableUserRole = 'normal' | 'admin'
|
||||
/**
|
||||
* 新建用户可选角色:super_admin 不可由表单创建;company_super_admin 仅站点超管可选
|
||||
* (后端 403「只有超级管理员可以创建公司超级管理员」兜底)。
|
||||
*/
|
||||
export type CreatableUserRole = 'normal' | 'admin' | 'company_super_admin'
|
||||
|
||||
export interface CreateUserForm {
|
||||
username: string
|
||||
@@ -14,11 +17,16 @@ export interface CreateUserForm {
|
||||
columnIds: number[]
|
||||
/** 所属管理员 id(超管创建普通账号时可指定,对齐 admin 的 created_by_id)。 */
|
||||
createdBy?: number | null
|
||||
/** 到期时间(yyyy-MM-dd HH:mm:ss);空串 = 永不过期(V146)。 */
|
||||
expiresAt: string
|
||||
/** 所属公司 id:仅 role=company_super_admin 时由站点超管必选(2026-10-05 需求)。 */
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
export interface CreateUserFormErrors {
|
||||
username?: string
|
||||
password?: string
|
||||
companyId?: string
|
||||
}
|
||||
|
||||
/** 发送 POST /api/admin/user 的请求体(与 Java AdminUserCreateRequest camelCase 对齐)。 */
|
||||
@@ -29,18 +37,27 @@ export interface CreateUserPayload {
|
||||
columnIds: number[]
|
||||
/** 仅 role=normal 且选了所属管理员时发送,与参考 admin.js 的 created_by_id 语义一致。 */
|
||||
createdById?: number
|
||||
/** 到期时间;空串=永不过期,不下发。 */
|
||||
expiresAt?: string
|
||||
/** 仅 role=company_super_admin 且显式选了公司时下发——这是「建号不带 company_id」
|
||||
* 反向钉(company-user-create.test.ts)唯一豁免的例外:公司超管必须落指定公司,
|
||||
* 否则会静默落操作者自己的公司(公司 1),用户需求就是给别家公司开超管。 */
|
||||
companyId?: number
|
||||
}
|
||||
|
||||
export function createEmptyCreateUserForm(): CreateUserForm {
|
||||
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null }
|
||||
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null, expiresAt: '', companyId: null }
|
||||
}
|
||||
|
||||
/** 未知/空白/超管角色一律归一到 normal,与后端 "admin"/"normal" 白名单一致。 */
|
||||
/** 未知/空白/超管角色归一:admin/company_super_admin/normal 白名单,其余归 normal。 */
|
||||
export function normalizeCreateRole(role: string | null | undefined): CreatableUserRole {
|
||||
return (role || '').trim().toLowerCase() === 'admin' ? 'admin' : 'normal'
|
||||
const value = (role || '').trim().toLowerCase()
|
||||
if (value === 'admin') return 'admin'
|
||||
if (value === 'company_super_admin') return 'company_super_admin'
|
||||
return 'normal'
|
||||
}
|
||||
|
||||
/** 表单校验(镜像后端:用户名≥2、密码≥6、均必填);返回逐字段错误。 */
|
||||
/** 表单校验(镜像后端:用户名≥2、密码≥6、均必填;公司超管必须选公司);返回逐字段错误。 */
|
||||
export function validateCreateUserForm(form: CreateUserForm): {
|
||||
valid: boolean
|
||||
errors: CreateUserFormErrors
|
||||
@@ -58,6 +75,9 @@ export function validateCreateUserForm(form: CreateUserForm): {
|
||||
} else if (password.length < CREATE_PASSWORD_MIN_LEN) {
|
||||
errors.password = `密码至少${CREATE_PASSWORD_MIN_LEN}个字符`
|
||||
}
|
||||
if (normalizeCreateRole(form.role) === 'company_super_admin' && form.companyId == null) {
|
||||
errors.companyId = '公司超级管理员必须指定所属公司'
|
||||
}
|
||||
return { valid: Object.keys(errors).length === 0, errors }
|
||||
}
|
||||
|
||||
@@ -65,19 +85,26 @@ export function validateCreateUserForm(form: CreateUserForm): {
|
||||
* 表单 → 创建请求体:用户名去空格、角色归一、菜单 id 拷贝不共享引用;
|
||||
* createdById 仅在 role=normal 且选了所属管理员时携带(对齐 admin.js 的 created_by_id 语义)。
|
||||
*
|
||||
* <p>故意不带 company_id:归属由后端 `AdminUserService#resolveTargetCompanyId` 落操作者自己的公司。
|
||||
* 页面上没有公司可选项(2026-10-04 定案),所以这条是"新账号归哪家公司"的唯一口径 ——
|
||||
* 想给别的公司建号,得用那个公司自己的 admin 登录,不是在这里改请求体。</p>
|
||||
* <p>company_id 仅在 role=company_super_admin 且显式选择时下发(见 CreateUserPayload 注释);
|
||||
* 其余角色不带——归属由后端 `AdminUserService#resolveTargetCompanyId` 落操作者自己的公司,
|
||||
* 想给别的公司建普通账号,得用那个公司自己的管理员登录,不是在这里改请求体。</p>
|
||||
*/
|
||||
export function toCreateUserRequest(form: CreateUserForm): CreateUserPayload {
|
||||
const role = normalizeCreateRole(form.role)
|
||||
const payload: CreateUserPayload = {
|
||||
username: (form.username || '').trim(),
|
||||
password: form.password || '',
|
||||
role: normalizeCreateRole(form.role),
|
||||
role,
|
||||
columnIds: Array.isArray(form.columnIds) ? form.columnIds.slice() : [],
|
||||
}
|
||||
if (payload.role === 'normal' && form.createdBy != null) {
|
||||
payload.createdById = form.createdBy
|
||||
}
|
||||
if (form.expiresAt && String(form.expiresAt).trim()) {
|
||||
payload.expiresAt = String(form.expiresAt).trim()
|
||||
}
|
||||
if (role === 'company_super_admin' && form.companyId != null) {
|
||||
payload.companyId = form.companyId
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { AdminUser } from '../../types/admin'
|
||||
import { CREATE_PASSWORD_MIN_LEN } from './user-create-model.ts'
|
||||
|
||||
/** 编辑可选角色:超管不可改,未知归 normal;后端只收 admin|normal。 */
|
||||
/** 编辑可选角色:站点/公司超管不可改,未知归 normal;后端只收 admin|normal。 */
|
||||
export type EditUserRole = 'normal' | 'admin'
|
||||
|
||||
export interface EditUserForm {
|
||||
@@ -16,6 +16,8 @@ export interface EditUserForm {
|
||||
columnIds: number[]
|
||||
/** 后端原角色字符串,用于超管禁止编辑判定。 */
|
||||
originalRole: string
|
||||
/** 到期时间(yyyy-MM-dd HH:mm:ss);空串 = 永不过期。null = 后端本来就无到期。 */
|
||||
expiresAt: string
|
||||
}
|
||||
|
||||
export interface EditUserFormErrors {
|
||||
@@ -24,9 +26,12 @@ export interface EditUserFormErrors {
|
||||
|
||||
/** 序列化到 PUT /api/admin/user/{uid} 的请求体(Java AdminUserUpdateRequest,空密码不下发)。 */
|
||||
export interface EditUserUpdateRequest {
|
||||
role: EditUserRole
|
||||
/** 目标是公司超管时不携带(防止表单把公司超管误降级);站点超管改其密码/到期时间即可。 */
|
||||
role?: EditUserRole
|
||||
columnIds: number[]
|
||||
password?: string
|
||||
/** 到期时间:空串=清除(恢复永不过期),有值=改期;总是下发(与后端"传了就更新"对齐)。 */
|
||||
expiresAt: string
|
||||
}
|
||||
|
||||
/** 行角色 → 可编辑角色:仅 admin 映射 admin,其余(含 unknown)归 normal。 */
|
||||
@@ -34,9 +39,31 @@ export function editRoleOf(role: string | null | undefined): EditUserRole {
|
||||
return (role || '').trim().toLowerCase() === 'admin' ? 'admin' : 'normal'
|
||||
}
|
||||
|
||||
/** 该角色是否允许被编辑:超级管理员不可编辑(镜像后端“不能修改超级管理员”)。 */
|
||||
/** 该角色是否允许被编辑:站点/公司超级管理员不可经普通编辑入口修改(镜像后端闸门)。 */
|
||||
export function isEditableUser(role: string | null | undefined): boolean {
|
||||
return (role || '').trim().toLowerCase() !== 'super_admin'
|
||||
const value = (role || '').trim().toLowerCase()
|
||||
return value !== 'super_admin' && value !== 'company_super_admin'
|
||||
}
|
||||
|
||||
/**
|
||||
* 结合操作者角色判断可编辑性(UsersPage 用):公司超管的目标只有站点超管能编辑
|
||||
* (改密码/到期时间做续费),站点超管目标谁都不能编辑。
|
||||
*/
|
||||
export function editableBy(
|
||||
targetRole: string | null | undefined,
|
||||
operatorRole: string | null | undefined,
|
||||
): boolean {
|
||||
const target = (targetRole || '').trim().toLowerCase()
|
||||
if (target === 'super_admin') return false
|
||||
if (target === 'company_super_admin') return (operatorRole || '').trim().toLowerCase() === 'super_admin'
|
||||
return true
|
||||
}
|
||||
|
||||
/** 列表的 expires_at 是 yyyy-MM-dd HH:mm;日期选择器按 yyyy-MM-dd HH:mm:ss 回填,秒位补 :00。 */
|
||||
export function normalizeExpiryForPicker(raw: string | null | undefined): string {
|
||||
const value = (raw || '').trim()
|
||||
if (!value) return ''
|
||||
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(value) ? `${value}:00` : value
|
||||
}
|
||||
|
||||
/** 从用户行回填编辑表单:用户名只读、密码留空、columnIds 待授权加载填充。 */
|
||||
@@ -49,6 +76,7 @@ export function fillEditUserForm(user: AdminUser): EditUserForm {
|
||||
role: editRoleOf(role),
|
||||
columnIds: [],
|
||||
originalRole: role,
|
||||
expiresAt: normalizeExpiryForPicker(user.expiresAt),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,16 +90,20 @@ export function validateEditUserForm(form: EditUserForm): { valid: boolean; erro
|
||||
return { valid: Object.keys(errors).length === 0, errors }
|
||||
}
|
||||
|
||||
/** 编辑表单 → 更新请求体:超管拒绝、空密码不下发、columnIds 拷贝不共享引用。 */
|
||||
/** 编辑表单 → 更新请求体:站点超管拒绝、空密码不下发、columnIds 拷贝不共享引用。 */
|
||||
export function toEditUserUpdateRequest(form: EditUserForm): EditUserUpdateRequest {
|
||||
const originalRole = (form.originalRole || '').trim().toLowerCase()
|
||||
if (originalRole === 'super_admin') {
|
||||
throw new Error('不能修改超级管理员')
|
||||
}
|
||||
const role: EditUserRole = form.role === 'admin' ? 'admin' : 'normal'
|
||||
const request: EditUserUpdateRequest = {
|
||||
role,
|
||||
columnIds: Array.isArray(form.columnIds) ? form.columnIds.slice() : [],
|
||||
expiresAt: (form.expiresAt || '').trim(),
|
||||
}
|
||||
// 公司超管目标不带 role:弹窗里的单选是给管理员/普通用户用的,带着它会整树提交把
|
||||
// 公司超管静默降级。站点超管要调角色,请删号重建或走接口。
|
||||
if (originalRole !== 'company_super_admin') {
|
||||
request.role = form.role === 'admin' ? 'admin' : 'normal'
|
||||
}
|
||||
const password = form.password || ''
|
||||
if (password) request.password = password
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/** 用户列表「到期时间」单元格渲染(V146):永不过期 / 具体时间 / 已过期。 */
|
||||
|
||||
export interface ExpiryCell {
|
||||
text: string
|
||||
expired: boolean
|
||||
}
|
||||
|
||||
/** 行 expiresAt 是 yyyy-MM-dd HH:mm 或空(后端空串=永不过期);解析失败按永不过期兜底。 */
|
||||
export function formatExpiryCell(row: { expiresAt?: string | null }): ExpiryCell {
|
||||
const raw = (row?.expiresAt || '').trim()
|
||||
if (!raw) {
|
||||
return { text: '永不过期', expired: false }
|
||||
}
|
||||
const parsed = new Date(raw.replace(' ', 'T'))
|
||||
if (Number.isNaN(parsed.getTime())) {
|
||||
return { text: raw, expired: false }
|
||||
}
|
||||
return { text: raw, expired: parsed.getTime() < Date.now() }
|
||||
}
|
||||
@@ -2,24 +2,26 @@
|
||||
import { roleKind } from '../../types/admin.ts'
|
||||
|
||||
/** 后台角色域(与 AdminUserItemVo.role / is_admin 对齐)。 */
|
||||
export type RoleDomain = 'super_admin' | 'admin' | 'normal'
|
||||
export type RoleDomain = 'super_admin' | 'company_super_admin' | 'admin' | 'normal'
|
||||
|
||||
/** 用户角色下拉可选值;super_admin 只能由系统持有,不入下拉。 */
|
||||
export type EditableRole = 'admin' | 'normal'
|
||||
export type EditableRole = 'company_super_admin' | 'admin' | 'normal'
|
||||
|
||||
export interface UserRoleOption {
|
||||
value: EditableRole
|
||||
label: string
|
||||
}
|
||||
|
||||
/** 编辑/创建表单角色下拉候选(镜像后端 admin|normal 白名单)。 */
|
||||
/** 建/编辑表单角色下拉候选(镜像后端白名单;company_super_admin 仅站点超管可选)。 */
|
||||
export const USER_ROLE_OPTIONS: readonly UserRoleOption[] = [
|
||||
{ value: 'company_super_admin', label: '公司超级管理员' },
|
||||
{ value: 'admin', label: '管理员' },
|
||||
{ value: 'normal', label: '普通用户' },
|
||||
]
|
||||
|
||||
const ROLE_DOMAIN_LABELS: Record<RoleDomain, string> = {
|
||||
super_admin: '超级管理员',
|
||||
company_super_admin: '公司超级管理员',
|
||||
admin: '管理员',
|
||||
normal: '普通用户',
|
||||
}
|
||||
@@ -27,14 +29,15 @@ const ROLE_DOMAIN_LABELS: Record<RoleDomain, string> = {
|
||||
/** 行字段 → 角色域:优先 role;为空时按 is_admin 布尔推断(1=管理员);未知归 normal。 */
|
||||
export function roleDomainOf(row: { role?: string | null; isAdmin?: boolean }): RoleDomain {
|
||||
const kind = roleKind(row?.role)
|
||||
if (kind === 'super_admin' || kind === 'admin' || kind === 'normal') return kind
|
||||
if (kind === 'super_admin' || kind === 'company_super_admin' || kind === 'admin' || kind === 'normal') return kind
|
||||
return row?.isAdmin ? 'admin' : 'normal'
|
||||
}
|
||||
|
||||
/** 行 → 可编辑角色值:超级管理员返回 null(不可编辑),其余返回 admin/normal。 */
|
||||
/** 行 → 可编辑角色值:站点/公司超管不可在此编辑角色(返回 null),其余返回对应值。 */
|
||||
export function selectRoleOf(row: { role?: string | null; isAdmin?: boolean }): EditableRole | null {
|
||||
const domain = roleDomainOf(row)
|
||||
return domain === 'super_admin' ? null : domain
|
||||
if (domain === 'super_admin' || domain === 'company_super_admin') return null
|
||||
return domain
|
||||
}
|
||||
|
||||
/** 角色域展示文案。 */
|
||||
@@ -43,14 +46,16 @@ export function roleDomainLabel(domain: RoleDomain): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色下拉锁定原因:目标为超管、或操作者非超管(镜像后端:admin 编辑时强制不调角色、
|
||||
* super_admin 不可改)。无锁定时返回 undefined。
|
||||
* 角色下拉锁定原因:目标为站点/公司超管、或操作者非站点超管(镜像后端:admin/公司超管
|
||||
* 编辑时角色不可调、super_admin 与同公司公司超管不可改)。无锁定时返回 undefined。
|
||||
*/
|
||||
export function userRoleLockMessage(
|
||||
operatorRole: string | null | undefined,
|
||||
target: { role?: string | null; isAdmin?: boolean },
|
||||
): string | undefined {
|
||||
if (roleDomainOf(target) === 'super_admin') return '不能修改超级管理员'
|
||||
const targetDomain = roleDomainOf(target)
|
||||
if (targetDomain === 'super_admin') return '不能修改超级管理员'
|
||||
if (targetDomain === 'company_super_admin') return '只有超级管理员可以修改公司超级管理员'
|
||||
if (roleKind(operatorRole) !== 'super_admin') return '仅超级管理员可调整角色'
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** 后台前端类型契约(任务 21):与 Java Admin 接口返回字段对齐。 */
|
||||
|
||||
/** 管理角色域(与后端 current-user / users 返回一致)。 */
|
||||
export type AdminRole = 'super_admin' | 'admin' | 'normal'
|
||||
export type AdminRole = 'super_admin' | 'company_super_admin' | 'admin' | 'normal'
|
||||
|
||||
export interface AdminUser {
|
||||
id: number
|
||||
@@ -13,6 +13,10 @@ export interface AdminUser {
|
||||
creatorUsername?: string
|
||||
createdAt?: string
|
||||
updatedAt?: string
|
||||
/** 到期时间(yyyy-MM-dd HH:mm);空串/缺省 = 永不过期(V146)。 */
|
||||
expiresAt?: string
|
||||
/** 自身到期剩余整天数(floor,来自 current-user);null/缺省 = 永不过期。续费提醒按它 <5 判定。 */
|
||||
daysToExpire?: number | null
|
||||
pinyinAbbr?: string
|
||||
}
|
||||
|
||||
@@ -28,12 +32,13 @@ export interface AdminMenuNode {
|
||||
icon?: string
|
||||
}
|
||||
|
||||
export type AdminRoleKind = 'super_admin' | 'admin' | 'normal' | null
|
||||
export type AdminRoleKind = 'super_admin' | 'company_super_admin' | 'admin' | 'normal' | null
|
||||
|
||||
/** 把任意角色字符串归一为角色域;未知/空返回 null。 */
|
||||
export function roleKind(role: string | null | undefined): AdminRoleKind {
|
||||
const value = (role || '').trim().toLowerCase()
|
||||
if (value === 'super_admin') return 'super_admin'
|
||||
if (value === 'company_super_admin') return 'company_super_admin'
|
||||
if (value === 'admin') return 'admin'
|
||||
if (value === 'normal') return 'normal'
|
||||
return null
|
||||
@@ -44,10 +49,15 @@ export function isSuperAdminRole(role: string | null | undefined): boolean {
|
||||
return roleKind(role) === 'super_admin'
|
||||
}
|
||||
|
||||
/** 是否管理员级(super_admin 或 admin,可进后台菜单管理类)。 */
|
||||
/** 是否公司超级管理员(单家公司内的最高账号,数据只看本公司)。 */
|
||||
export function isCompanySuperAdminRole(role: string | null | undefined): boolean {
|
||||
return roleKind(role) === 'company_super_admin'
|
||||
}
|
||||
|
||||
/** 是否管理员级(super_admin / company_super_admin / admin,可进后台菜单管理类)。 */
|
||||
export function isAdminRole(role: string | null | undefined): boolean {
|
||||
const kind = roleKind(role)
|
||||
return kind === 'super_admin' || kind === 'admin'
|
||||
return kind === 'super_admin' || kind === 'company_super_admin' || kind === 'admin'
|
||||
}
|
||||
|
||||
/** 顶部栏角色展示文案。 */
|
||||
@@ -55,6 +65,8 @@ export function roleLabel(role: string | null | undefined): string {
|
||||
switch (roleKind(role)) {
|
||||
case 'super_admin':
|
||||
return '超级管理员'
|
||||
case 'company_super_admin':
|
||||
return '公司超级管理员'
|
||||
case 'admin':
|
||||
return '管理员'
|
||||
case 'normal':
|
||||
|
||||
@@ -31,13 +31,16 @@ test('名单里的每个 menuKey 都在页面注册表上打了 superAdminOnly',
|
||||
}
|
||||
})
|
||||
|
||||
test('公司 API 模块的消费者集合恰好是公司管理两文件 + 公司 tab store(账号页已摘干净)', () => {
|
||||
test('公司 API 模块的消费者集合是公司管理两文件 + 用户页(建公司超管选公司,2026-10-05 唯一豁免)', () => {
|
||||
const found = filesWithSuffix(['.vue', '.ts'])
|
||||
.filter((rel) => readSource(rel).includes("from '@/api/companies'"))
|
||||
.sort()
|
||||
assert.deepEqual(found, [
|
||||
'src/pages/account/CompaniesPage.vue',
|
||||
'src/pages/account/CompanyEditorDialog.vue',
|
||||
// 2026-10-05 例外:站点超管建「公司超级管理员」必须选公司,UsersPage 因此拉公司目录。
|
||||
// 该用例的姊妹钉在 company-user-create.test.ts:公司下拉被「站点超管 + 公司超管角色」双重门控。
|
||||
'src/pages/account/UsersPage.vue',
|
||||
// 2026-10-05 公司 tab(spec §4):store 是目录的第二个消费者,仅超管侧 visibleForOperator 会发 GET。
|
||||
'src/stores/company-tab.ts',
|
||||
].sort())
|
||||
|
||||
@@ -9,31 +9,40 @@ import {
|
||||
import { OPERATION_GUIDES } from '../src/layout/operation-guides.ts'
|
||||
|
||||
/**
|
||||
* 建号不再让用户挑公司(2026-10-04 15:4x 定案)。
|
||||
* 建号公司口径(2026-10-05 修订):admin/normal 建号仍不让用户挑公司——请求体不带
|
||||
* company_id 时,`resolveTargetCompanyId` 落操作者自己的公司(下面的 Java 钉子仍然有效)。
|
||||
*
|
||||
* <p>归属这件事改由后端单点决定:请求体不带 company_id 时,`resolveTargetCompanyId` 落操作者自己的公司。
|
||||
* 所以"前端删掉下拉是安全的"这个结论完全靠那条后端分支撑着 —— 下面最后一用例把它钉成可执行断言,
|
||||
* 谁把那边改成"必填公司",这边立刻红。</p>
|
||||
* <p>唯一例外是<b>公司超级管理员</b>(2026-10-05 用户需求「admin 超管可以新建其他公司的
|
||||
* 超级管理员」):不显式选公司就会静默落进操作者自己的公司(公司 1),所以这一例必须
|
||||
* 让站点超管选公司、必选、并随请求体下发。除这一例外,公司维度仍然不回流界面。</p>
|
||||
*/
|
||||
|
||||
function form(overrides: Record<string, unknown> = {}) {
|
||||
return { ...createEmptyCreateUserForm(), username: 'zhangsan', password: 'secret123', ...overrides }
|
||||
}
|
||||
|
||||
test('空表单里没有公司这一项', () => {
|
||||
test('空表单默认没有公司、没有到期时间', () => {
|
||||
const blank = createEmptyCreateUserForm()
|
||||
assert.equal('companyId' in blank, false)
|
||||
assert.deepEqual(blank, { username: '', password: '', role: 'normal', columnIds: [], createdBy: null })
|
||||
assert.equal(blank.companyId ?? null, null, 'companyId 默认 null(仅公司超管角色使用)')
|
||||
assert.equal(blank.expiresAt, '', '到期时间默认空 = 永不过期')
|
||||
assert.deepEqual(
|
||||
{ ...blank, companyId: null, expiresAt: '' },
|
||||
{ username: '', password: '', role: 'normal', columnIds: [], createdBy: null, companyId: null, expiresAt: '' },
|
||||
)
|
||||
})
|
||||
|
||||
test('校验只看用户名与密码,不再要求选公司', () => {
|
||||
test('普通账号校验只看用户名与密码;公司超管必须选公司', () => {
|
||||
assert.deepEqual(validateCreateUserForm(form()), { valid: true, errors: {} })
|
||||
assert.equal(validateCreateUserForm(form({ username: 'a' })).errors.username !== undefined, true)
|
||||
assert.equal(validateCreateUserForm(form({ password: '123' })).errors.password !== undefined, true)
|
||||
const missingCompany = validateCreateUserForm(form({ role: 'company_super_admin' }))
|
||||
assert.equal(missingCompany.valid, false, '公司超级管理员必须指定所属公司')
|
||||
assert.equal(missingCompany.errors.companyId !== undefined, true)
|
||||
const withCompany = validateCreateUserForm(form({ role: 'company_super_admin', companyId: 2 }))
|
||||
assert.equal(withCompany.valid, true)
|
||||
})
|
||||
|
||||
// 反向钉:公司维度不得回流到界面(2026-10-04 定口径)
|
||||
test('请求体不带 companyId,其余字段照旧', () => {
|
||||
test('请求体:admin/normal 一律不带 companyId;公司超管必须带且选了公司才带', () => {
|
||||
assert.deepEqual(toCreateUserRequest(form({ columnIds: [3, 1] })), {
|
||||
username: 'zhangsan',
|
||||
password: 'secret123',
|
||||
@@ -44,17 +53,31 @@ test('请求体不带 companyId,其余字段照旧', () => {
|
||||
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 才会走后端"落操作者公司"那条分支')
|
||||
'不传 company_id 才会走后端"落操作者公司"那条分支(admin/normal 永远如此)')
|
||||
|
||||
// 2026-10-05 例外:公司超级管理员
|
||||
const companyAdmin = toCreateUserRequest(form({ role: 'company_super_admin', companyId: 2 }))
|
||||
assert.equal(companyAdmin.companyId, 2, '公司超管必须把选中的公司带给后端,否则会静默落操作者本公司')
|
||||
assert.equal(companyAdmin.role, 'company_super_admin')
|
||||
assert.equal('companyId' in toCreateUserRequest(form({ role: 'company_super_admin' })), false,
|
||||
'没选公司就不许带(校验层会先拦住,这里兜底不静默)')
|
||||
})
|
||||
|
||||
// 反向钉:公司维度不得回流到界面(2026-10-04 定口径)
|
||||
test('建号模型源码里公司口径已摘干净', () => {
|
||||
test('到期时间:空串不下发,有值随请求体走', () => {
|
||||
assert.equal('expiresAt' in toCreateUserRequest(form()), false, '留空 = 永不过期,不下发')
|
||||
assert.equal(toCreateUserRequest(form({ expiresAt: '2026-12-31 23:59:59' })).expiresAt,
|
||||
'2026-12-31 23:59:59')
|
||||
})
|
||||
|
||||
test('建号模型源码:公司口径只对「公司超管」这一例放行', () => {
|
||||
const mod = readSource('src/pages/account/user-create-model.ts')
|
||||
assert.equal(/companyId|CompanyItem|selectableCompanies|initialCompanyId|CreateOperatorScope/.test(mod), false,
|
||||
'公司相关的类型、可选项收窄函数、预选函数都应整体删除')
|
||||
assert.match(mod, /company_super_admin/, '角色白名单要包含公司超管')
|
||||
assert.match(mod, /role === 'company_super_admin' && form\.companyId != null/,
|
||||
'companyId 只在「角色=公司超管且已选公司」时下发——这是唯一豁免,别放宽成所有角色')
|
||||
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
|
||||
assert.equal(/companyId|CompanyItem|所属公司|selectableCompanies/.test(dialog), false,
|
||||
'弹窗不再有公司选择;操作者角色门控(operatorSuper)保留,它管的是角色与所属管理员下拉')
|
||||
assert.match(dialog, /operatorSuper && form\.role === 'company_super_admin'/,
|
||||
'公司下拉必须同时被「站点超管 + 公司超管角色」双重门控,普通建号不能看到公司维度')
|
||||
assert.match(dialog, /公司超级管理员必须指定所属公司|请选择公司/, '公司下拉要有必选提示')
|
||||
assert.match(dialog, /operatorSuper/, '角色/所属管理员仍按操作者是否超管收窄')
|
||||
})
|
||||
|
||||
@@ -64,12 +87,14 @@ test('建号模型源码里公司口径已摘干净', () => {
|
||||
* 同理"停用后不能再用于新建账号"也不成立了——requireActive 只在显式传 company_id 时才走,
|
||||
* 而页面现在一律不传(接口直连的老调用方仍受它保护,那条由上一用例盯着)。
|
||||
*/
|
||||
test('「公司管理」引导文案说的是自动继承,不再让操作员挑公司', () => {
|
||||
test('「公司管理」引导文案说的是自动继承,并写清公司超管这一例外', () => {
|
||||
const guide = OPERATION_GUIDES.admin_companies.text
|
||||
assert.match(guide, /操作者自己所在的公司/, '要写清归属的真实口径:落在操作者本公司')
|
||||
assert.match(guide, /请用那个公司自己的管理员登录|用该公司自己的管理员登录/,
|
||||
'要给别家建号只能换账号登录——不写这句,超管会以为自己建的号能归到别家')
|
||||
for (const stale of ['建号时选哪家公司', '选哪家公司', '停用后不能再用于新建账号']) {
|
||||
assert.match(guide, /公司超级管理员/,
|
||||
'2026-10-05 起开设公司超管是唯一要在建号时选公司的例外,文案要说清,别让人以为下拉没了是坏了')
|
||||
for (const stale of ['建号时选哪家公司', '停用后不能再用于新建账号']) {
|
||||
assert.equal(guide.includes(stale), false, `文案仍含已失效的说法:${stale}`)
|
||||
}
|
||||
})
|
||||
@@ -93,7 +118,7 @@ function javaMethod(source: string, signature: string): string {
|
||||
return ''
|
||||
}
|
||||
|
||||
test('后端仍然把"没传公司"落成操作者自己公司(前端删下拉的前提)', () => {
|
||||
test('后端仍然把"没传公司"落成操作者自己公司(admin/normal 不带下拉的前提)', () => {
|
||||
const java = readSource(
|
||||
'../backend-java/src/main/java/com/nanri/aiimage/modules/admin/service/AdminUserService.java',
|
||||
)
|
||||
|
||||
@@ -59,12 +59,18 @@ test('顶栏不再渲染公司名', () => {
|
||||
assert.equal(topbarUserOf(null).hasUser, false)
|
||||
})
|
||||
|
||||
// 反向钉:公司维度不得回流到界面(2026-10-04 定口径)
|
||||
// 反向钉:公司维度不得回流到「列表/筛选/顶栏」(2026-10-04 定口径;2026-10-05 修订——
|
||||
// 唯一例外是建号弹窗里的「公司超级管理员」所属公司下拉,由 company-user-create.test.ts 单独钉住)
|
||||
test('账号页与顶栏的源码里公司维度已摘干净', () => {
|
||||
const page = readSource('src/pages/account/UsersPage.vue')
|
||||
assert.equal(/所属公司/.test(page), false, '账号页不该再出现「所属公司」标签')
|
||||
assert.equal(/companyId|companyName|companies/.test(page), false, '页面不再持有公司目录或公司筛选状态')
|
||||
assert.equal(/fetchCompanies/.test(page), false, '公司目录接口不该再被账号页调用')
|
||||
// 列表契约层面不许出现公司维度:查询参数 company_id、筛选状态、行级公司列。
|
||||
// (companyOptions/c.companyName 是 2026-10-05 建公司超管选公司的唯一豁免,不在此列。)
|
||||
assert.equal(/company_id|filters\.company|row\.company|companyId/.test(page), false,
|
||||
'列表查询/筛选/行渲染不允许出现公司维度')
|
||||
assert.match(page, /fetchCompanies/, '公司目录仅供建号弹窗的「公司超管」下拉使用(唯一豁免)')
|
||||
assert.match(page, /isSuperAdmin[\s\S]{0,200}fetchCompanies/,
|
||||
'拉公司目录必须按站点超管门控,非超管不发这个请求(后端 403 兜底)')
|
||||
|
||||
// 「删了列忘了改占位行 colspan」是这类改动最常留下的残行:按表头列数交叉核对
|
||||
// (`<th` 是 `<thead` 的前缀,必须带上后随字符才数得准)
|
||||
@@ -74,8 +80,10 @@ test('账号页与顶栏的源码里公司维度已摘干净', () => {
|
||||
for (const span of spans) assert.equal(span, headers, `占位行 colspan=${span} 与表头列数 ${headers} 不符`)
|
||||
|
||||
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
|
||||
assert.equal(/所属公司|selectableCompanies|initialCompanyId|companyId/.test(dialog), false,
|
||||
'建号弹窗不该再有公司选择')
|
||||
assert.match(dialog, /operatorSuper && form\.role === 'company_super_admin'/,
|
||||
'建号弹窗的公司下拉只许在「站点超管 + 公司超管角色」时出现(例外口径见 company-user-create.test.ts)')
|
||||
assert.equal(/selectableCompanies|initialCompanyId/.test(dialog), false,
|
||||
'一次性预选/收窄的旧公司逻辑不许回流')
|
||||
|
||||
const layout = readSource('src/layout/AdminLayout.vue')
|
||||
assert.equal(/userVm\.company|admin-user-company/.test(layout), false, '顶栏旁白只剩用户名与角色')
|
||||
|
||||
@@ -34,6 +34,10 @@ const EXEMPT = new Set([
|
||||
'src/pages/tasks/ShopDataTasksPage.vue',
|
||||
'src/pages/tasks/ImageVideoTasksPage.vue',
|
||||
'src/pages/records/RecordsHistoryPage.vue',
|
||||
// 2026-10-05(V146):两处是「到期时间」表单字段而非列表筛选——留空 = 永不过期,
|
||||
// 是有业务语义的默认值,绝不能默认当天(默认当天等于建号即过期)。
|
||||
'src/pages/account/CreateUserDialog.vue',
|
||||
'src/pages/account/EditUserDialog.vue',
|
||||
])
|
||||
|
||||
/** 把日期筛选清回空值的写法(默认当天的页里初值或重置都不许出现)。
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { occurrences, readSource } from './helpers.ts'
|
||||
|
||||
/**
|
||||
* 数富后台「服务即将到期」续费提醒弹窗(V146,2026-10-05 需求)的口径护栏。
|
||||
*
|
||||
* 需求原话:仅剩不到 5 天开始提醒、只能缩小不能关闭、续费到超过 5 天才消失。
|
||||
* 这三条全靠 ExpiryNotice.vue 一个组件兑现,而组件是 SFC、node --test 编译不了,
|
||||
* 所以断言打在实际源码上:阈值、渲染条件、可点的按钮、收起态记的是什么键、挂在哪。
|
||||
*
|
||||
* 每个正则都必须在真源码上匹配得到(先确认真命中再断言),否则就是恒绿的摆设。
|
||||
*/
|
||||
const COMPONENT = 'src/components/ExpiryNotice.vue'
|
||||
const LAYOUT = 'src/layout/AdminLayout.vue'
|
||||
const TYPES = 'src/types/admin.ts'
|
||||
|
||||
/** SFC 的 <template> 段:从第一个 <template> 到最后一个 </template>(内层还有 v-if 包裹)。 */
|
||||
function templateOf(source: string): string {
|
||||
const start = source.indexOf('<template>')
|
||||
const end = source.lastIndexOf('</template>')
|
||||
assert.ok(start !== -1 && end > start, `${COMPONENT} 没有 <template> 段`)
|
||||
return source.slice(start, end)
|
||||
}
|
||||
|
||||
/** <script setup> 段。 */
|
||||
function scriptOf(source: string): string {
|
||||
const start = source.indexOf('<script setup')
|
||||
const end = source.indexOf('</script>')
|
||||
assert.ok(start !== -1 && end > start, `${COMPONENT} 没有 <script setup> 段`)
|
||||
return source.slice(start, end)
|
||||
}
|
||||
|
||||
/** 剥掉 HTML 注释:注释掉的 `<ExpiryNotice />` 在源码里照样匹配得上,挂载点断言必须是活代码。 */
|
||||
function withoutComments(source: string): string {
|
||||
return source.replace(/<!--[\s\S]*?-->/g, '')
|
||||
}
|
||||
|
||||
const source = readSource(COMPONENT)
|
||||
const template = templateOf(source)
|
||||
const script = scriptOf(source)
|
||||
|
||||
test('提醒阈值就是 5 天:THRESHOLD 取 props 兜底 5,且全文件没有第二个数字阈值', () => {
|
||||
assert.match(script, /const THRESHOLD = props\.threshold \?\? 5\b/, '阈值没写成 5 的兜底')
|
||||
// 排他:别处再写一个数字兜底,就等于偷偷加了第二套口径
|
||||
const numericFallbacks = script.match(/\?\?\s*\d+/g) ?? []
|
||||
assert.deepEqual(numericFallbacks, ['?? 5'], '数字兜底只能有阈值 5 这一个')
|
||||
})
|
||||
|
||||
test('渲染条件是「剩余 < 5」而不是「<= 5」:整 5 天不弹,第 4 天起才弹', () => {
|
||||
assert.match(
|
||||
script,
|
||||
/daysToExpire\.value !== null && daysToExpire\.value < THRESHOLD/,
|
||||
'visible 没按「有到期值且 < 阈值」判定',
|
||||
)
|
||||
assert.doesNotMatch(script, /daysToExpire\.value <= THRESHOLD/, '写成了 <=,整 5 天也会弹')
|
||||
})
|
||||
|
||||
test('没有关闭这条路:模板里只有「收起」和浮标两个可点项,没有任何对话框自带的关闭件', () => {
|
||||
assert.equal(occurrences(template, '@click="'), 2, '可点项必须恰好是收起 + 浮标恢复两个')
|
||||
assert.match(template, /@click="minimize"/, '收起按钮没接 minimize')
|
||||
assert.match(template, /@click="restore"/, '缩小态浮标没接 restore')
|
||||
assert.match(template, /收起\s*<\/button>/, '唯一的收起动作文案是「收起」')
|
||||
// 关闭语义的三种实际载体:对话框组件、显式 close 处理器、Element 的关闭开关
|
||||
assert.equal(occurrences(source, 'el-dialog'), 0, '用对话框会带来关闭件')
|
||||
assert.doesNotMatch(source, /@click="[^"]*close/i, '存在 close 点击处理器')
|
||||
assert.doesNotMatch(source, /show-close|close-on-click-modal|close-on-press-escape|:closable/, '存在任何关闭开关')
|
||||
})
|
||||
|
||||
test('收起态按「用户 id + 到期值」记键:续费换了到期值,键变了就自动回到展开', () => {
|
||||
assert.equal(occurrences(script, 'admin-expiry-notice-min:'), 1, '收起态键名只应有一处定义')
|
||||
assert.match(
|
||||
script,
|
||||
/`admin-expiry-notice-min:\$\{user\.value\.id\}:\$\{expiresAt\.value\}`/,
|
||||
'键里必须同时带用户 id 与到期值,缺到期值则续费后仍停在收起态',
|
||||
)
|
||||
// 全组件只写这一个键:任何形式的「已读/忽略」持久化都会让提醒在续费前被永久关掉
|
||||
assert.equal(occurrences(script, 'localStorage.setItem('), 1, '持久化写入只能有收起态这一处')
|
||||
assert.equal(occurrences(script, 'localStorage.removeItem('), 1, '只有恢复展开时清键')
|
||||
})
|
||||
|
||||
test('到期值变化会重新判定收起态:watch 键值且 immediate', () => {
|
||||
assert.match(script, /watch\(\s*minimizedKey,/, '没有监听 minimizedKey')
|
||||
assert.match(script, /minimized\.value = key \? localStorage\.getItem\(key\) === '1' : false/, '展开态直接由键值决定')
|
||||
assert.match(script, /\{ immediate: true \}/, '缺 immediate 则首屏不判定,刷新后不提醒')
|
||||
})
|
||||
|
||||
test('挂在后台布局上:AdminLayout 引了组件并且渲染,不挂就整站看不见', () => {
|
||||
const layout = withoutComments(readSource(LAYOUT))
|
||||
assert.match(layout, /import ExpiryNotice from '@\/components\/ExpiryNotice\.vue'/, '布局没引组件')
|
||||
assert.match(layout, /<ExpiryNotice\s*\/>/, '布局没渲染组件(注释掉等于没挂)')
|
||||
})
|
||||
|
||||
test('数据源键名与前端类型对齐:daysToExpire/expiresAt 来自 current-user,没有映射层', () => {
|
||||
const types = readSource(TYPES)
|
||||
assert.match(types, /daysToExpire\?: number \| null/, 'AdminUser 类型缺 daysToExpire')
|
||||
assert.match(types, /expiresAt\?: string/, 'AdminUser 类型缺 expiresAt')
|
||||
assert.match(readSource('src/api/session.ts'), /\/api\/admin\/current-user/, '会话数据源不是 current-user')
|
||||
// 组件读的是 store 上的这两个键,不是自己算时间
|
||||
assert.match(script, /session\.user/, '弹窗数据源是后台会话 store')
|
||||
assert.match(script, /user\.value\?\.daysToExpire/, '读 daysToExpire 而不是本地算')
|
||||
})
|
||||
@@ -36,10 +36,10 @@ test('test_task_251_user_dialog_boundary_empty_input', () => {
|
||||
})
|
||||
|
||||
test('test_task_251_user_dialog_boundary_single_item', () => {
|
||||
// 超管用户不可编辑(行按钮禁用)。
|
||||
// 超管用户不可编辑(行按钮禁用);2026-10-05 起判定结合操作者角色(公司超管目标仅站点超管可编辑)。
|
||||
const page = readSource('src/pages/account/UsersPage.vue')
|
||||
assert.match(page, /editableOf/, '需有可编辑判定')
|
||||
assert.match(page, /isEditableUser/, '可编辑判定应复用 user-edit-model')
|
||||
assert.match(page, /editableBy/, '可编辑判定应复用 user-edit-model')
|
||||
})
|
||||
|
||||
test('test_task_251_user_dialog_boundary_limit_or_missing_field', () => {
|
||||
|
||||
@@ -14,6 +14,8 @@ test('test_task_048_user_role_map_normal_primary_path', () => {
|
||||
assert.equal(roleDomainOf({ role: 'admin' }), 'admin')
|
||||
assert.equal(roleDomainOf({ role: 'normal' }), 'normal')
|
||||
assert.equal(roleDomainOf({ role: 'super_admin' }), 'super_admin')
|
||||
// 2026-10-05 新增角色:公司超级管理员(数据只看本公司,由站点超管开设)
|
||||
assert.equal(roleDomainOf({ role: 'company_super_admin' }), 'company_super_admin')
|
||||
})
|
||||
|
||||
test('test_task_048_user_role_map_normal_variant_input', () => {
|
||||
@@ -43,10 +45,11 @@ test('test_task_048_user_role_map_boundary_single_item', () => {
|
||||
})
|
||||
|
||||
test('test_task_048_user_role_map_boundary_limit_or_missing_field', () => {
|
||||
// 边界上限:超级管理员不可作为可编辑角色(null);候选不含 super_admin。
|
||||
// 边界上限:站点/公司超管不可作为可编辑角色(null);候选含公司超管但绝不含站点超管。
|
||||
assert.equal(selectRoleOf({ role: 'super_admin' }), null)
|
||||
assert.equal(selectRoleOf({ role: 'company_super_admin' }), null)
|
||||
const values = USER_ROLE_OPTIONS.map((o) => o.value)
|
||||
assert.deepEqual([...values].sort(), ['admin', 'normal'])
|
||||
assert.deepEqual([...values].sort(), ['admin', 'company_super_admin', 'normal'])
|
||||
assert.equal(values.includes('super_admin'), false)
|
||||
})
|
||||
|
||||
@@ -55,6 +58,8 @@ test('test_task_048_user_role_map_invalid_input_rejected', () => {
|
||||
assert.match(userRoleLockMessage('super_admin', { role: 'super_admin' }) || '', /超级管理员/)
|
||||
assert.match(userRoleLockMessage('admin', { role: 'normal' }) || '', /超管|管理员/)
|
||||
assert.equal(userRoleLockMessage('super_admin', { role: 'normal' }), undefined)
|
||||
// 2026-10-05:公司超管目标只有站点超管能编辑(改密码/到期时间做续费),角色锁定要单独说清
|
||||
assert.match(userRoleLockMessage('super_admin', { role: 'company_super_admin' }) || '', /公司超级管理员/)
|
||||
})
|
||||
|
||||
test('test_task_048_user_role_map_dependency_failure_returns_actionable_message', () => {
|
||||
@@ -64,4 +69,5 @@ test('test_task_048_user_role_map_dependency_failure_returns_actionable_message'
|
||||
assert.equal(roleDomainLabel('admin'), '管理员')
|
||||
assert.equal(roleDomainLabel('normal'), '普通用户')
|
||||
assert.equal(roleDomainLabel('super_admin'), '超级管理员')
|
||||
assert.equal(roleDomainLabel('company_super_admin'), '公司超级管理员')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user