hthhth
This commit is contained in:
@@ -63,7 +63,22 @@ export const UserEditorialStaff = (data: any) => {
|
||||
formData.append('password', data.password)
|
||||
formData.append('nation', data.nation)
|
||||
formData.append('IdCard', data.IdCard)
|
||||
// 处理部门数据:如果是数组,转换为JSON字符串
|
||||
if (data.department) {
|
||||
if (Array.isArray(data.department)) {
|
||||
formData.append('department', JSON.stringify(data.department))
|
||||
} else {
|
||||
formData.append('department', data.department)
|
||||
}
|
||||
}
|
||||
// 处理角色数据:如果是数组,转换为JSON字符串
|
||||
if (data.role) {
|
||||
if (Array.isArray(data.role)) {
|
||||
formData.append('role', JSON.stringify(data.role))
|
||||
} else {
|
||||
formData.append('role', data.role)
|
||||
}
|
||||
}
|
||||
formData.append('mobilePhone', data.mobilePhone)
|
||||
formData.append('position', data.position)
|
||||
formData.append('team', data.team)
|
||||
@@ -91,3 +106,17 @@ export const UserPersonneldisplay = () => {
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 获取角色列表(用于下拉选择)
|
||||
export const getUserRoleOptions = () => {
|
||||
const formData = new FormData()
|
||||
formData.append('RoleName', '')
|
||||
return request({
|
||||
url: `${AUTH_BASE_URL}/business/displayRole`,
|
||||
method: 'post',
|
||||
data: formData,
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -21,8 +21,18 @@ const generateRandomToken = () => {
|
||||
/**
|
||||
* 创建 HTTP 请求实例
|
||||
*/
|
||||
// 生产环境直接使用后端地址,开发环境使用代理
|
||||
const getBaseURL = () => {
|
||||
// 如果是生产环境且没有配置 VITE_APP_BASE_API,则使用后端地址
|
||||
if (import.meta.env.PROD && !import.meta.env.VITE_APP_BASE_API) {
|
||||
return 'http://199.168.137.123:8000'
|
||||
}
|
||||
// 开发环境或已配置环境变量,使用环境变量
|
||||
return import.meta.env.VITE_APP_BASE_API || ''
|
||||
}
|
||||
|
||||
const httpRequest = axios.create({
|
||||
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||
baseURL: getBaseURL(),
|
||||
timeout: 500000,
|
||||
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||
paramsSerializer: (params) => qs.stringify(params)
|
||||
|
||||
@@ -106,21 +106,32 @@
|
||||
<!-- <DictLabel v-model="scope.row.gender" code="gender" />-->
|
||||
<!-- </template>-->
|
||||
<!-- </el-table-column>-->
|
||||
<el-table-column label="部门" align="center" prop="department" />
|
||||
<el-table-column label="部门" align="center" prop="department">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.department && scope.row.department.length > 0">
|
||||
{{ scope.row.department.map((d: any) => d.username).join(', ') }}
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="角色" align="center" prop="role">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
v-for="(role, index) in scope.row.role"
|
||||
:key="index"
|
||||
type="primary"
|
||||
size="small"
|
||||
style="margin-right: 5px"
|
||||
>
|
||||
{{ role.RoleName }}
|
||||
</el-tag>
|
||||
<span v-if="!scope.row.role || scope.row.role.length === 0">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="手机号码" align="center" prop="mobilePhone" />
|
||||
<el-table-column label="入职时间" align="center" prop="Dateofjoining" />
|
||||
<el-table-column label="操作" fixed="right" align="center" width="220">
|
||||
<el-table-column label="操作" fixed="right" align="center" width="280">
|
||||
<template #default="scope">
|
||||
<!-- <el-button-->
|
||||
<!-- v-hasPerm="'sys:user:reset-password'"-->
|
||||
<!-- type="primary"-->
|
||||
<!-- icon="RefreshLeft"-->
|
||||
<!-- size="small"-->
|
||||
<!-- link-->
|
||||
<!-- @click="handleResetPassword(scope.row)"-->
|
||||
<!-- >-->
|
||||
<!-- 重置密码-->
|
||||
<!-- </el-button>-->
|
||||
<el-button
|
||||
v-hasPerm="'sys:user:edit'"
|
||||
type="primary"
|
||||
@@ -131,6 +142,16 @@
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPerm="'sys:user:assign-role'"
|
||||
type="warning"
|
||||
icon="User"
|
||||
link
|
||||
size="small"
|
||||
@click="handleAssignRole(scope.row)"
|
||||
>
|
||||
分配权限
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPerm="'sys:user:delete'"
|
||||
type="danger"
|
||||
@@ -184,11 +205,35 @@
|
||||
<el-input v-model="formData.mobilePhone" placeholder="请输入手机号" maxlength="11" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属部门" prop="department">
|
||||
<el-select v-model="formData.department" placeholder="请选择所属部门">
|
||||
<el-option key="行政部" label="行政部" value="行政部" />
|
||||
<el-option key="财务部" label="财务部" value="财务部" />
|
||||
<el-option key="执业律师" label="执业律师" value="执业律师" />
|
||||
<el-option key="实习律师" label="实习律师" value="实习律师" />
|
||||
<el-select
|
||||
v-model="formData.department"
|
||||
placeholder="请选择所属部门"
|
||||
multiple
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="dept in deptOptions"
|
||||
:key="dept.value"
|
||||
:label="dept.label"
|
||||
:value="dept.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色" prop="role">
|
||||
<el-select
|
||||
v-model="formData.role"
|
||||
placeholder="请选择角色"
|
||||
multiple
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="role in roleOptions"
|
||||
:key="role.value"
|
||||
:label="role.label"
|
||||
:value="role.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="岗位" prop="position">
|
||||
@@ -360,6 +405,42 @@
|
||||
|
||||
<!-- 用户导入 -->
|
||||
<UserImport v-model="importDialogVisible" @import-success="handleQuery()" />
|
||||
|
||||
<!-- 分配权限对话框 -->
|
||||
<el-dialog
|
||||
v-model="assignRoleDialog.visible"
|
||||
title="分配权限"
|
||||
width="500px"
|
||||
@close="handleCloseAssignRoleDialog"
|
||||
>
|
||||
<el-form ref="assignRoleFormRef" :model="assignRoleForm" label-width="100px">
|
||||
<el-form-item label="用户姓名">
|
||||
<el-input v-model="assignRoleForm.username" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="角色" required>
|
||||
<el-select
|
||||
v-model="assignRoleForm.role"
|
||||
placeholder="请选择角色"
|
||||
multiple
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="role in assignRoleOptions"
|
||||
:key="role.value"
|
||||
:label="role.label"
|
||||
:value="role.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="handleSubmitAssignRole">确 定</el-button>
|
||||
<el-button @click="handleCloseAssignRoleDialog">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -394,8 +475,10 @@ import UserImport from './components/UserImport.vue'
|
||||
import {
|
||||
UserCreateUser,
|
||||
UserEditorialStaff,
|
||||
UserPersonnelList
|
||||
UserPersonnelList,
|
||||
getUserRoleOptions
|
||||
} from '@/api/calibration/personnelManagement'
|
||||
import { BusinessDisplayRole } from '@/api/calibration/roleManagement'
|
||||
import { convertFilePathsToObject } from '@/utils/auxiliaryFunction'
|
||||
|
||||
// ==================== 组件配置 ====================
|
||||
@@ -440,7 +523,8 @@ const formData = reactive<any>({
|
||||
password: '',
|
||||
nation: '',
|
||||
IdCard: '',
|
||||
department: '',
|
||||
department: [],
|
||||
role: [],
|
||||
mobilePhone: '',
|
||||
position: '',
|
||||
team: '',
|
||||
@@ -467,6 +551,20 @@ const roleOptions = ref<OptionType[]>()
|
||||
// 导入弹窗
|
||||
const importDialogVisible = ref(false)
|
||||
|
||||
// 分配权限对话框
|
||||
const assignRoleDialog = reactive({
|
||||
visible: false,
|
||||
userId: null as number | null
|
||||
})
|
||||
|
||||
const assignRoleForm = reactive({
|
||||
username: '',
|
||||
role: [] as number[]
|
||||
})
|
||||
|
||||
const assignRoleOptions = ref<OptionType[]>([])
|
||||
const assignRoleFormRef = ref()
|
||||
|
||||
// ==================== 计算属性 ====================
|
||||
|
||||
/**
|
||||
@@ -657,10 +755,18 @@ async function handleOpenDialog(data?: any): Promise<void> {
|
||||
|
||||
// 并行加载下拉选项数据
|
||||
try {
|
||||
;[roleOptions.value, deptOptions.value] = await Promise.all([
|
||||
RoleAPI.getOptions(),
|
||||
const [roleRes, deptRes] = await Promise.all([
|
||||
BusinessDisplayRole({ RoleName: '' }),
|
||||
DeptAPI.getOptions()
|
||||
])
|
||||
|
||||
// 转换角色数据格式
|
||||
roleOptions.value = (roleRes.data || []).map((role: any) => ({
|
||||
label: role.RoleName,
|
||||
value: parseInt(role.id)
|
||||
}))
|
||||
|
||||
deptOptions.value = deptRes || []
|
||||
} catch (error) {
|
||||
ElMessage.error('加载选项数据失败')
|
||||
console.error('加载选项数据失败:', error)
|
||||
@@ -673,6 +779,20 @@ async function handleOpenDialog(data?: any): Promise<void> {
|
||||
const data1 = deepCloneByJSON(data)
|
||||
data1.academic = parseJsonToArray(data1.academic)
|
||||
|
||||
// 处理部门数据
|
||||
if (data1.department && Array.isArray(data1.department)) {
|
||||
data1.department = data1.department.map((d: any) => d.id)
|
||||
} else {
|
||||
data1.department = []
|
||||
}
|
||||
|
||||
// 处理角色数据
|
||||
if (data1.role && Array.isArray(data1.role)) {
|
||||
data1.role = data1.role.map((r: any) => parseInt(r.id))
|
||||
} else {
|
||||
data1.role = []
|
||||
}
|
||||
|
||||
data1.AcademicResume = convertFilePathsToObject(JSON.parse(data1.AcademicResume))[0]
|
||||
data1.contract = convertFilePathsToObject(JSON.parse(data1.contract))[0]
|
||||
data1.ApplicationForm = convertFilePathsToObject(JSON.parse(data1.ApplicationForm))[0]
|
||||
@@ -684,6 +804,9 @@ async function handleOpenDialog(data?: any): Promise<void> {
|
||||
} else {
|
||||
// 新增:设置默认值
|
||||
dialog.title = '新增用户'
|
||||
// 重置表单数据
|
||||
formData.department = []
|
||||
formData.role = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -726,6 +849,82 @@ function handleCloseDialog(): void {
|
||||
|
||||
// 重置表单数据
|
||||
formData.id = undefined
|
||||
formData.department = []
|
||||
formData.role = []
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配用户角色/权限
|
||||
*/
|
||||
async function handleAssignRole(row: any): Promise<void> {
|
||||
try {
|
||||
// 加载角色列表
|
||||
const roleRes = await BusinessDisplayRole({ RoleName: '' })
|
||||
assignRoleOptions.value = (roleRes.data || []).map((role: any) => ({
|
||||
label: role.RoleName,
|
||||
value: parseInt(role.id)
|
||||
}))
|
||||
|
||||
// 设置表单数据
|
||||
assignRoleForm.username = row.username
|
||||
assignRoleForm.role = row.role && Array.isArray(row.role)
|
||||
? row.role.map((r: any) => parseInt(r.id))
|
||||
: []
|
||||
assignRoleDialog.userId = row.id
|
||||
assignRoleDialog.visible = true
|
||||
} catch (error) {
|
||||
ElMessage.error('加载角色列表失败')
|
||||
console.error('加载角色列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交权限分配
|
||||
*/
|
||||
async function handleSubmitAssignRole(): Promise<void> {
|
||||
if (!assignRoleDialog.userId) {
|
||||
ElMessage.error('用户ID不存在')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
// 获取用户完整数据
|
||||
const userData = pageData.value.find((u: any) => u.id === assignRoleDialog.userId)
|
||||
if (!userData) {
|
||||
ElMessage.error('用户不存在')
|
||||
return
|
||||
}
|
||||
|
||||
// 构建更新数据
|
||||
const updateData = {
|
||||
...userData,
|
||||
role: assignRoleForm.role
|
||||
}
|
||||
|
||||
await UserEditorialStaff(updateData)
|
||||
ElMessage.success('权限分配成功')
|
||||
handleCloseAssignRoleDialog()
|
||||
handleQuery() // 刷新列表
|
||||
} catch (error) {
|
||||
ElMessage.error('权限分配失败')
|
||||
console.error('权限分配失败:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭分配权限对话框
|
||||
*/
|
||||
function handleCloseAssignRoleDialog(): void {
|
||||
assignRoleDialog.visible = false
|
||||
assignRoleDialog.userId = null
|
||||
assignRoleForm.username = ''
|
||||
assignRoleForm.role = []
|
||||
if (assignRoleFormRef.value) {
|
||||
assignRoleFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,14 +44,20 @@ export default defineConfig(({ mode }: ConfigEnv) => {
|
||||
port: +(env.VITE_APP_PORT as string),
|
||||
open: true,
|
||||
proxy: {
|
||||
'/dev-api/api2': {
|
||||
// 代理 /api2 的请求到后端服务器
|
||||
'/api2': {
|
||||
changeOrigin: true,
|
||||
// target: 'http://47.108.113.7:8000',
|
||||
// target: 'http://47.108.113.7:8000',
|
||||
// target: 'http://192.168.31.69:8006',
|
||||
target: 'http://199.168.137.123:8000',
|
||||
rewrite: (path: string) => {
|
||||
return path.replace(/^\/dev-api\/api2/, '')
|
||||
return path.replace(/^\/api2/, '/api2')
|
||||
}
|
||||
},
|
||||
// 代理 /dev-api/api2 的请求(兼容旧配置)
|
||||
'/dev-api/api2': {
|
||||
changeOrigin: true,
|
||||
target: 'http://199.168.137.123:8000',
|
||||
rewrite: (path: string) => {
|
||||
return path.replace(/^\/dev-api\/api2/, '/api2')
|
||||
}
|
||||
},
|
||||
// 代理 /dev-api 的请求
|
||||
|
||||
Reference in New Issue
Block a user