Commit 0b2f302d by 李宁

1

1 parent f539d7a0
...@@ -130,7 +130,7 @@ interface Props { ...@@ -130,7 +130,7 @@ interface Props {
roleId?: string roleId?: string
roles?: Role[] roles?: Role[]
expandedIds?: Set<string> expandedIds?: Set<string>
accountType?: '地市级' | '区县级' | '一线人员' accountType?: '1' | '2' | '3'
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
selectedId: '', selectedId: '',
...@@ -155,22 +155,22 @@ const hasChildren = (org: Organization): boolean => { ...@@ -155,22 +155,22 @@ const hasChildren = (org: Organization): boolean => {
return !!(org.children && org.children.length > 0) return !!(org.children && org.children.length > 0)
} }
const isSelectable = (org: Organization): boolean => { const isSelectable = (org: Organization): boolean => {
console.log('检查组织可选性:', org.name, org.type, '账号类型:', props.accountType) //console.log('检查组织可选性:', org.name, org.type, '账号类型:', props.accountType)
// 只根据账号类型判断,不根据角色层级判断 // 只根据账号类型判断,不根据角色层级判断
if (props.accountType) { if (props.accountType) {
switch (props.accountType) { switch (props.accountType) {
case '地市级': case '1':
// 地市级只能选择地市级组织 // 地市级只能选择地市级组织
console.log('地市级账号,检查组织类型是否为地市:', org.type === '地市') //console.log('地市级账号,检查组织类型是否为地市:', org.type === '地市')
return org.type === '地市' return org.type === '地市'
case '区县级': case '2':
// 区县级只能选择区县级组织 // 区县级只能选择区县级组织
console.log('区县级账号,检查组织类型是否为区县:', org.type === '区县') //console.log('区县级账号,检查组织类型是否为区县:', org.type === '区县')
return org.type === '区县' return org.type === '区县'
case '一线人员': case '3':
// 区县级只能选择区县级组织 // 区县级只能选择区县级组织
console.log('区县级账号,检查组织类型是否为区县:', org.type === '区县') //console.log('区县级账号,检查组织类型是否为区县:', org.type === '区县')
return org.type === '区县' return org.type === '区县'
default: default:
return true return true
......
...@@ -63,9 +63,9 @@ ...@@ -63,9 +63,9 @@
class="h-10 w-full" class="h-10 w-full"
clearable clearable
> >
<el-option label="全部状态" value="all" /> <el-option label="全部状态" value="" />
<el-option label="正常" value="1" /> <el-option label="开启" value="1" />
<el-option label="禁用" value="0" /> <el-option label="关闭" value="0" />
</el-select> </el-select>
<el-select <el-select
v-model="organizationFilter" v-model="organizationFilter"
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
class="h-10 w-full" class="h-10 w-full"
clearable clearable
> >
<el-option label="全部区域" value="all" /> <el-option label="全部区域" value="" />
<el-option <el-option
v-for="org in organizationOptions" v-for="org in organizationOptions"
:key="org.id" :key="org.id"
...@@ -81,6 +81,13 @@ ...@@ -81,6 +81,13 @@
:value="org.id" :value="org.id"
/> />
</el-select> </el-select>
<el-button
class="h-13 px-2"
@click="getAccountList"
style="width: 100px;"
>
查询
</el-button>
</div> </div>
</el-card> </el-card>
<!-- 用户列表 --> <!-- 用户列表 -->
...@@ -93,18 +100,10 @@ ...@@ -93,18 +100,10 @@
:header-cell-style="{ backgroundColor: '#f3f4f6', color: '#374151', fontWeight: '500', borderBottom: '1px solid #e5e7eb' }" :header-cell-style="{ backgroundColor: '#f3f4f6', color: '#374151', fontWeight: '500', borderBottom: '1px solid #e5e7eb' }"
:row-style="getRowStyle" :row-style="getRowStyle"
> >
<el-table-column prop="realName" label="用户姓名" min-width="100"> <el-table-column prop="username" label="用户姓名" min-width="100">
<template #default="{ row }"> <template #default="{ row }">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span :class="{ 'font-semibold': isCurrentUser(row) }">{{ row.realName }}</span> <span>{{ row.username || '--' }}</span>
<el-tag
v-if="isCurrentUser(row)"
type="primary"
size="small"
class="text-xs"
>
当前登录
</el-tag>
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
...@@ -115,54 +114,50 @@ ...@@ -115,54 +114,50 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="username" label="工号" min-width="120"> <el-table-column prop="userCode" label="工号" min-width="120">
<template #default="{ row }"> <template #default="{ row }">
<span :class="{ 'font-semibold': isCurrentUser(row) }">{{ row.username }}</span> <span>{{ row.userCode }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="accountType" label="账号类型" min-width="100"> <el-table-column prop="userType" label="账号类型" min-width="100">
<template #default="{ row }"> <template #default="{ row }">
<el-tag <el-tag
:type="getAccountTypeTagType(row.accountType)" :type="getAccountTypeTagType(row.userType)"
effect="plain" effect="plain"
size="small" size="small"
> >
{{ row.accountType || '-' }} {{ getAccountTypeName(row.userType) || '-' }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="roleId" label="角色" min-width="120"> <el-table-column prop="roleName" label="角色" min-width="120">
<template #default="{ row }"> <template #default="{ row }">
{{ getRoleById(row.roleId)?.name || '-' }} <span>{{ row.roleName || '--' }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="status" label="状态" min-width="80"> <el-table-column prop="status" label="状态" min-width="80">
<template #default="{ row }"> <template #default="{ row }">
<el-tag <el-tag
:type="row.status === '正常' ? 'success' : 'info'" :type="row.status === 1 ? 'success' : 'info'"
size="small" size="small"
> >
{{ row.status }} {{ row.status==1?'开启':'关闭' }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="organizationId" label="所属组织" min-width="150"> <el-table-column prop="areaName" label="所属区域" min-width="150">
<template #default="{ row }"> <template #default="{ row }">
<div v-if="getOrganizationById(row.organizationId)" class="flex items-center gap-2"> <span>{{ row.areaName || '--' }}</span>
<el-tag size="small" type="info">{{ getOrganizationById(row.organizationId)?.type }}</el-tag>
<span>{{ getOrganizationById(row.organizationId)?.name }}</span>
</div>
<span v-else>-</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="createTime" label="创建时间" min-width="120"> <el-table-column prop="createTime" label="创建时间" min-width="120">
<template #default="{ row }"> <template #default="{ row }">
{{ row.createTime || '-' }} {{ $utils.detailTime(row.createTime) }}
</template> </template>
</el-table-column> </el-table-column>
...@@ -222,9 +217,9 @@ ...@@ -222,9 +217,9 @@
class="w-full" class="w-full"
@change="handleAccountTypeChange" @change="handleAccountTypeChange"
> >
<el-option label="地市级" value="地市级" /> <el-option label="地市级" value="1" />
<el-option label="区县级" value="区县级" /> <el-option label="区县级" value="2" />
<el-option label="一线人员" value="一线人员" /> <el-option label="一线人员" value="3" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="角色" required class="col-span-2"> <el-form-item label="角色" required class="col-span-2">
...@@ -321,7 +316,7 @@ import { ref, computed, watch ,onMounted,getCurrentInstance} from 'vue' ...@@ -321,7 +316,7 @@ import { ref, computed, watch ,onMounted,getCurrentInstance} from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Building2, Search } from 'lucide-vue-next' import { Plus, Building2, Search } from 'lucide-vue-next'
import OrganizationTree from './OrganizationTree.vue' import OrganizationTree from './OrganizationTree.vue'
const { $api } = getCurrentInstance()!.appContext.config.globalProperties const { $api,$utils } = getCurrentInstance()!.appContext.config.globalProperties
// 类型定义 // 类型定义
export interface User { export interface User {
id: string id: string
...@@ -329,7 +324,7 @@ export interface User { ...@@ -329,7 +324,7 @@ export interface User {
realName: string realName: string
organizationId: string organizationId: string
roleId: string roleId: string
accountType?: '地市级' | '区县级' | '一线人员' accountType?: '1' | '2' | '3'
phone?: string phone?: string
email?: string email?: string
status: '正常' | '禁用' status: '正常' | '禁用'
...@@ -347,6 +342,7 @@ interface Role { ...@@ -347,6 +342,7 @@ interface Role {
interface Organization { interface Organization {
id: string id: string
name: string name: string
areaCode: string
type: '地市' | '区县' | '客户经理团队' type: '地市' | '区县' | '客户经理团队'
parentId?: string parentId?: string
children?: Organization[] children?: Organization[]
...@@ -372,7 +368,7 @@ const codeSearch = ref('') ...@@ -372,7 +368,7 @@ const codeSearch = ref('')
const roleFilter = ref<string>('all') const roleFilter = ref<string>('all')
const accountTypeFilter = ref<'' | '1' | '2' | '3'>('') const accountTypeFilter = ref<'' | '1' | '2' | '3'>('')
const statusFilter = ref<'' | '1' | '0'>('') const statusFilter = ref<'' | '1' | '0'>('')
const organizationFilter = ref<string>('all') const organizationFilter = ref<string>('')
const organizationExpandedIds = ref(new Set<string>()) const organizationExpandedIds = ref(new Set<string>())
// 表单数据 // 表单数据
const formData = ref({ const formData = ref({
...@@ -407,27 +403,25 @@ const getRoleList = async ()=>{ ...@@ -407,27 +403,25 @@ const getRoleList = async ()=>{
const getAccountList = async ()=>{ const getAccountList = async ()=>{
try { try {
const response = await $api.queryAccountList({ const response = await $api.queryAccountList({
phone: '', username: userNameSearch.value,
status: '', phone: phoneSearch.value,
userCode: codeSearch.value,
userType: accountTypeFilter.value,
status: statusFilter.value,
areaCode: organizationFilter.value,
page: 1,
pageSize: 1000
}) })
if (response && response.c === 0) { if (response && response.c === 0) {
filteredUsers.value = response.d filteredUsers.value = response.d.content
} }
} catch (error) { } catch (error) {
console.log('报错了')
} }
} }
const totalUsers = computed(() => props.users.length - 1) // 排除当前登录用户 const totalUsers = computed(() => props.users.length - 1) // 排除当前登录用户
const hasFilters = computed(() =>
generalSearch.value !== '' ||
roleFilter.value !== 'all' ||
accountTypeFilter.value !== 'all' ||
statusFilter.value !== 'all' ||
organizationFilter.value !== 'all'
)
const roleHint = computed(() => { const roleHint = computed(() => {
if (!formData.value.roleId) return '' if (!formData.value.roleId) return ''
...@@ -454,14 +448,22 @@ const getOrganizationById = (id: string): Organization | undefined => { ...@@ -454,14 +448,22 @@ const getOrganizationById = (id: string): Organization | undefined => {
const getRoleById = (id: string): Role | undefined => { const getRoleById = (id: string): Role | undefined => {
return props.roles.find(r => r.id === id) return props.roles.find(r => r.id === id)
} }
const getAccountTypeTagType = (accountType: string) => { const getAccountTypeTagType = (accountType: Number) => {
switch (accountType) { switch (accountType) {
case '地市级': return 'warning' case 1: return 'warning'
case '区县级': return 'primary' case 2: return 'primary'
case '一线人员': return 'success' case 3: return 'success'
default: return 'info' default: return 'info'
} }
} }
const getAccountTypeName = (accountType: Number) => {
switch (accountType) {
case 1: return '地市级'
case 2: return '区县级'
case 3: return '一线管理员'
default: return '--'
}
}
const isCurrentUser = (user: User): boolean => { const isCurrentUser = (user: User): boolean => {
return user.id === props.currentUserId return user.id === props.currentUserId
} }
...@@ -478,23 +480,23 @@ const handleOpenAddDialog = () => { ...@@ -478,23 +480,23 @@ const handleOpenAddDialog = () => {
username: '', username: '',
realName: '', realName: '',
phone: '', phone: '',
accountType: '一线人员' as '地市级' | '区县级' | '一线人员', accountType: '',
organizationId: '', organizationId: '',
roleId: '', roleId: '',
isActive: true isActive: true
} }
isDialogOpen.value = true isDialogOpen.value = true
} }
const handleOpenEditDialog = (user: User) => { const handleOpenEditDialog = (row) => {
editingUser.value = user editingUser.value = row
formData.value = { formData.value = {
username: user.username, username: row.userCode,
realName: user.realName, realName: row.username,
phone: user.phone || '', phone: row.phone || '',
accountType: user.accountType || '一线人员', accountType: row.userType+'',
organizationId: user.organizationId, organizationId: row.areaId,
roleId: user.roleId, roleId: row.roleId,
isActive: user.status === '正常' isActive: row.status === 1
} }
isDialogOpen.value = true isDialogOpen.value = true
} }
...@@ -579,36 +581,19 @@ const handleSave = async () => { ...@@ -579,36 +581,19 @@ const handleSave = async () => {
return return
} }
} }
// 检查用户名是否重复
const existingUser = props.users.find(u =>
u.username === formData.value.username.trim() && u.id !== editingUser.value?.id
)
if (existingUser) {
ElMessage.error('该工号已存在')
return
}
const userData: any = {
username: formData.value.username.trim(),
realName: formData.value.realName.trim(),
roleId: formData.value.roleId,
accountType: formData.value.accountType,
status: formData.value.isActive ? '正常' : '禁用',
phone: formData.value.phone.trim() || undefined,
creatorId: props.currentUserId
}
// 当前登录用户不可修改自己的所属组织
// if (!editingUser.value || !isCurrentUser(editingUser.value)) {
// userData.organizationId = formData.value.organizationId
// }
const response = await $api.addAndUpdateRole({ const response = await $api.addAndUpdateRole({
id: editingUser.value?editingUser.value.id:'',
userCode: formData.value.username.trim(),
userName: formData.value.realName.trim(),
phone: formData.value.phone.trim(),
userType: formData.value.accountType,
roleId: formData.value.roleId,
status: formData.value.isActive ? '1' : '0',
areaId: formData.value.organizationId
}) })
if (response.c === 0) { if (response.c === 0) {
//handleFilter() getAccountList()
ElMessage.success(editingUser.value?'编辑成功':'创建成功'); ElMessage.success(editingUser.value?'编辑成功':'创建成功');
} else { } else {
ElMessage.error(response.m); ElMessage.error(response.m);
...@@ -622,7 +607,7 @@ const organizationOptions = computed(() => { ...@@ -622,7 +607,7 @@ const organizationOptions = computed(() => {
const traverse = (orgs: Organization[], depth = 0) => { const traverse = (orgs: Organization[], depth = 0) => {
const prefix = depth > 0 ? '— '.repeat(depth) : '' const prefix = depth > 0 ? '— '.repeat(depth) : ''
orgs.forEach(org => { orgs.forEach(org => {
result.push({ id: org.id, label: `${prefix}${org.name}` }) result.push({ id: org.areaCode, label: `${prefix}${org.name}` })
if (org.children && org.children.length) traverse(org.children, depth + 1) if (org.children && org.children.length) traverse(org.children, depth + 1)
}) })
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!