diff --git a/src/api/calibration/personnelManagement/index.ts b/src/api/calibration/personnelManagement/index.ts
index 7dc95be..3f888d6 100644
--- a/src/api/calibration/personnelManagement/index.ts
+++ b/src/api/calibration/personnelManagement/index.ts
@@ -63,7 +63,22 @@ export const UserEditorialStaff = (data: any) => {
formData.append('password', data.password)
formData.append('nation', data.nation)
formData.append('IdCard', data.IdCard)
- formData.append('department', data.department)
+ // 处理部门数据:如果是数组,转换为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'
+ }
+ })
+}
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 3b9ec30..1a9963b 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -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)
diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index 78fc01d..96814a4 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -106,21 +106,32 @@
-
+
+
+
+ {{ scope.row.department.map((d: any) => d.username).join(', ') }}
+
+ -
+
+
+
+
+
+ {{ role.RoleName }}
+
+ -
+
+
-
+
-
-
-
-
-
-
-
-
-
-
编辑
+
+ 分配权限
+
-
-
-
-
-
+
+
+
+
+
+
+
@@ -360,6 +405,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -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({
password: '',
nation: '',
IdCard: '',
- department: '',
+ department: [],
+ role: [],
mobilePhone: '',
position: '',
team: '',
@@ -467,6 +551,20 @@ const roleOptions = ref()
// 导入弹窗
const importDialogVisible = ref(false)
+// 分配权限对话框
+const assignRoleDialog = reactive({
+ visible: false,
+ userId: null as number | null
+})
+
+const assignRoleForm = reactive({
+ username: '',
+ role: [] as number[]
+})
+
+const assignRoleOptions = ref([])
+const assignRoleFormRef = ref()
+
// ==================== 计算属性 ====================
/**
@@ -657,10 +755,18 @@ async function handleOpenDialog(data?: any): Promise {
// 并行加载下拉选项数据
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 {
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 {
} 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 {
+ 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 {
+ 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()
+ }
}
/**
diff --git a/vite.config.ts b/vite.config.ts
index ebe53a7..39abd89 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -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 的请求