feat(多公司): 两端接上公司身份 —— 后台公司目录页、建号必选公司、顶栏显示所属公司

- 新后台新增「公司管理」页(列/新建/改名/启停,不提供删除),路由 menuKey 与
  columns 表的 admin_companies 逐字一致,由用例钉住;操作指引补该菜单一条。
- 建号弹窗对超管必须显式选一家(后端对"不传"仍落操作者自己公司,是给旧后台兜底);
  admin 只能落自己公司,越权直接 403。账号列表显示 company_name,可按公司筛。
- 客户端登录后把 companyId/companyName 落到 localStorage 并在顶栏显示;
  两个登出出口(handleKicked 与切号/登出)连公司名一起清 —— 残留会把上一个账号
  的归属显示给下一个账号。
- 契约分层:列表端点用 snake_case(company_id/company_name),current-user 与登录
  回包用 camelCase;解析器读到另一套写法必须忽略,防止前后端各猜一套。

admin-frontend-vue 1678/1678、frontend-vue 672/672,两边 build(含 vue-tsc --noEmit)干净。
This commit is contained in:
2026-10-04 07:11:47 +08:00
parent 4dbac40ef3
commit 15b8e46af8
29 changed files with 1109 additions and 16 deletions
@@ -1,12 +1,16 @@
<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,
initialCompanyId,
selectableCompanies,
type CreateOperatorScope,
type CreateUserForm,
type CreateUserFormErrors,
validateCreateUserForm,
} from './user-create-model'
import type { CompanyItem } from '@/api/companies-dto'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { actionableErrorText } from '@/components/admin-feedback'
import UserMenuAuthTree from './UserMenuAuthTree.vue'
@@ -16,6 +20,10 @@ const props = defineProps<{
operatorSuper?: boolean
/** 所属管理员候选(列表响应 admins;仅超管创建普通账号时展示)。 */
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 }>()
@@ -23,6 +31,9 @@ const form = reactive<CreateUserForm>(createEmptyCreateUserForm())
const errors = reactive<CreateUserFormErrors>({})
const busy = ref(false)
/** 可选项收窄规则与后端 resolveTargetCompanyId 同源,写在这里而不是父页模板里。 */
const companyOptions = computed(() => selectableCompanies(props.companies || [], props.operator || {}))
/** 角色下拉(对齐 admin.html:普通账号/管理员;超管才显示可改)。 */
const ROLE_CHOICES: Array<{ value: 'admin' | 'normal'; label: string }> = [
{ value: 'normal', label: '普通账号' },
@@ -38,8 +49,10 @@ watch(
form.role = 'normal'
form.columnIds = []
form.createdBy = null
form.companyId = initialCompanyId(props.operator || {}, props.companies || [])
errors.username = undefined
errors.password = undefined
errors.company = undefined
},
)
@@ -48,7 +61,7 @@ function close(): void {
}
async function create(): Promise<void> {
const { valid, errors: errs } = validateCreateUserForm(form)
const { valid, errors: errs } = validateCreateUserForm(form, props.operator)
Object.assign(errors, errs)
if (!valid) return
busy.value = true
@@ -107,6 +120,22 @@ async function create(): Promise<void> {
/>
</el-select>
</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="菜单权限(勾选上级菜单会继承全部子菜单)">
<div class="auth-tree-box">
<UserMenuAuthTree v-model:checked="form.columnIds" />