Commit d97fb832 authored by lwy's avatar lwy

用户管理-修改表格样式,配置制造工厂名称显示

parent 4905a21a
...@@ -118,15 +118,14 @@ ...@@ -118,15 +118,14 @@
v-loading="loading" v-loading="loading"
:data="userList" :data="userList"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
border
> >
<!-- <el-table-column type="selection" width="50" align="center" />--> <!-- <el-table-column type="selection" width="50" align="center" />-->
<el-table-column <el-table-column label="序号" align="center">
v-if="columns[0].visible" <template #default="scope">
key="userId" {{scope.$index + 1}}
label="序号" </template>
align="center" </el-table-column>
prop="userId"
/>
<el-table-column label="用户类型" align="center" prop="userType" sortable> <el-table-column label="用户类型" align="center" prop="userType" sortable>
<template #default="scope"> <template #default="scope">
<dict-tag :options="sys_user_type" :value="scope.row.userType" /> <dict-tag :options="sys_user_type" :value="scope.row.userType" />
...@@ -140,7 +139,12 @@ ...@@ -140,7 +139,12 @@
sortable sortable
prop="dept.deptName" prop="dept.deptName"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
/> >
<template #default="scope">
<!-- 判断 dept.deptName 是否为空 -->
{{ scope.row.dept?.deptName || '--' }}
</template>
</el-table-column>
<el-table-column <el-table-column
v-if="columns[1].visible" v-if="columns[1].visible"
key="userName" key="userName"
...@@ -170,7 +174,11 @@ ...@@ -170,7 +174,11 @@
align="center" align="center"
prop="divsion" prop="divsion"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
/> >
<template #default="scope">
{{ scope.row.divsion || '--' }}
</template>
</el-table-column>
<el-table-column <el-table-column
v-if="columns[2].visible" v-if="columns[2].visible"
key="factoryName" key="factoryName"
...@@ -178,7 +186,11 @@ ...@@ -178,7 +186,11 @@
align="center" align="center"
prop="factoryName" prop="factoryName"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
/> >
<template #default="scope">
{{ scope.row.factoryName || '--' }}
</template>
</el-table-column>
<el-table-column <el-table-column
v-if="columns[4].visible" v-if="columns[4].visible"
key="phonenumber" key="phonenumber"
...@@ -186,7 +198,11 @@ ...@@ -186,7 +198,11 @@
align="center" align="center"
prop="phonenumber" prop="phonenumber"
width="120" width="120"
/> >
<template #default="scope">
{{ scope.row.phonenumber || '--' }}
</template>
</el-table-column>
<el-table-column label="用户状态" align="center" prop="status" sortable> <el-table-column label="用户状态" align="center" prop="status" sortable>
<template #default="scope"> <template #default="scope">
<dict-tag :options="sys_user_status" :value="scope.row.status" /> <dict-tag :options="sys_user_status" :value="scope.row.status" />
...@@ -199,7 +215,11 @@ ...@@ -199,7 +215,11 @@
align="center" align="center"
prop="roleNames" prop="roleNames"
width="120" width="120"
/> >
<template #default="scope">
{{ scope.row.roleNames || '--' }}
</template>
</el-table-column>
<el-table-column <el-table-column
v-if="columns[7].visible" v-if="columns[7].visible"
label="同步时间" label="同步时间"
...@@ -209,7 +229,7 @@ ...@@ -209,7 +229,7 @@
width="160" width="160"
> >
<template #default="scope"> <template #default="scope">
<span>{{ parseTime(scope.row.updateTime) }}</span> <span>{{ parseTime(scope.row.updateTime) || "--" }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
...@@ -222,29 +242,29 @@ ...@@ -222,29 +242,29 @@
<el-button <el-button
v-hasPermi="['system:user:edit']" v-hasPermi="['system:user:edit']"
link link
v-if="scope.row.userId === 1" v-if="scope.row.userType === '00'"
type="primary" type="primary"
@click="handleUpdate(scope.row)" @click="handleUpdate(scope.row)"
>修改</el-button> >修改</el-button>
<el-button <el-button
v-hasPermi="['system:user:edit']" v-hasPermi="['system:user:edit']"
link link
v-if="scope.row.userId !== 1" v-if="scope.row.userType !== '00'"
type="primary" type="primary"
@click="handleAuthRole(scope.row)" @click="handleAuthRole(scope.row)"
>分配角色</el-button> >分配角色</el-button>
<el-button <el-button
link link
v-if="scope.row.userId !== 1" v-if="scope.row.userType !== '00'"
type="primary" type="primary"
@click="divsionDialog = true" @click="divsionDialog = true"
>配置事业部</el-button> <!--v-hasPermi="['system:user:edit']"--> >配置事业部</el-button> <!--v-hasPermi="['system:user:edit']"-->
<el-button <el-button
v-hasPermi="['system:user:edit']" v-hasPermi="['system:user:edit']"
link link
v-if="scope.row.userId !== 1" v-if="scope.row.userType !== '00'"
type="primary" type="primary"
@click="dialogFactory = true" @click="openFactoryDialog(scope.row)"
>配置制造工厂</el-button> >配置制造工厂</el-button>
</template> </template>
</el-table-column> </el-table-column>
...@@ -285,6 +305,7 @@ ...@@ -285,6 +305,7 @@
<el-checkbox-group v-model="selectedFactories"> <el-checkbox-group v-model="selectedFactories">
<div style="display: flex; flex-wrap: wrap;"> <div style="display: flex; flex-wrap: wrap;">
<div v-for="(factory, index) in allFactories" :key="index" style="width: 33%; margin-bottom: 10px;"> <div v-for="(factory, index) in allFactories" :key="index" style="width: 33%; margin-bottom: 10px;">
<!-- 在 el-checkbox 标签中 -->
<el-checkbox :label="factory">{{ factory }}</el-checkbox> <el-checkbox :label="factory">{{ factory }}</el-checkbox>
</div> </div>
</div> </div>
...@@ -299,6 +320,27 @@ ...@@ -299,6 +320,27 @@
</template> </template>
</el-dialog> </el-dialog>
<!-- 分配角色 -->
<el-dialog v-model="dialogRole" title="分配角色" width="600px" append-to-body>
<el-form ref="userRef" :model="form" label-width="80px">
<el-form-item prop="roleNames">
<el-checkbox-group v-model="selectedFactories">
<div style="display: flex; flex-wrap: wrap;">
<div v-for="(role, index) in allRoles" :key="index" style="width: 33%; margin-bottom: 10px;">
<el-checkbox :label="role">{{ role }}</el-checkbox>
</div>
</div>
</el-checkbox-group>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="cancel">取 消</el-button>
<el-button type="primary" @click="submitForm">保 存</el-button>
</span>
</template>
</el-dialog>
<!-- 添加或修改用户配置对话框 --> <!-- 添加或修改用户配置对话框 -->
<el-dialog v-model="open" :title="title" width="600px" append-to-body> <el-dialog v-model="open" :title="title" width="600px" append-to-body>
<el-form ref="userRef" :model="form" :rules="rules" label-width="80px"> <el-form ref="userRef" :model="form" :rules="rules" label-width="80px">
...@@ -461,6 +503,9 @@ import { ...@@ -461,6 +503,9 @@ import {
} from '@/api/system/user' } from '@/api/system/user'
import { Splitpanes, Pane } from 'splitpanes' import { Splitpanes, Pane } from 'splitpanes'
import 'splitpanes/dist/splitpanes.css' import 'splitpanes/dist/splitpanes.css'
import { getAllFactoryName } from "@/api/system/factory";
import { getRoleAll,listRole } from "@/api/system/role";
import {watch} from "vue";
const router = useRouter() const router = useRouter()
const appStore = useAppStore() const appStore = useAppStore()
...@@ -472,11 +517,13 @@ const { sys_normal_disable, sys_user_sex, sys_user_status, sys_user_type } = pro ...@@ -472,11 +517,13 @@ const { sys_normal_disable, sys_user_sex, sys_user_status, sys_user_type } = pro
'sys_user_type' 'sys_user_type'
) )
const dialogFactory = ref(false) const dialogFactory = ref(false)
const dialogRole = ref(false)
const divsionDialog = ref(false) const divsionDialog = ref(false)
// 选中的工厂列表 // 选中的工厂列表
const selectedFactories = ref([]); const selectedFactories = ref([]);
// 选中的事业部 // 选中的事业部
const selecteDivsions = ref([]); const selecteDivsions = ref([]);
const selectedRoles = ref([]);
const userList = ref([]) const userList = ref([])
const open = ref(false) const open = ref(false)
const loading = ref(true) const loading = ref(true)
...@@ -526,10 +573,10 @@ const data = reactive({ ...@@ -526,10 +573,10 @@ const data = reactive({
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
userName: undefined, userName: null,
phonenumber: undefined, phonenumber: null,
status: undefined, status: null,
deptId: undefined, deptId: null,
}, },
rules: { rules: {
userName: [ userName: [
...@@ -576,7 +623,10 @@ const data = reactive({ ...@@ -576,7 +623,10 @@ const data = reactive({
}) })
const { queryParams, form, rules } = toRefs(data) const { queryParams, form, rules } = toRefs(data)
// 所有可选的工厂列表
const allFactories = ref([])
// 所有可选的角色
const allRoles = ref([])
const isEditMode = computed(() => { const isEditMode = computed(() => {
return title.value === "编辑"; return title.value === "编辑";
}); });
...@@ -605,41 +655,43 @@ watch(() => form.value.divsion, (newVal) => { ...@@ -605,41 +655,43 @@ watch(() => form.value.divsion, (newVal) => {
} }
}, { immediate: true }); }, { immediate: true });
// 监听选中的工厂变化,更新表单数据 // 打开配置制造工厂对话框
watch(selecteDivsions, (newVal) => { function openFactoryDialog(row) {
const divsionObj = {}; dialogFactory.value = true;
newVal.forEach((item, index) => { // 直接使用当前行的 factoryName(假设是数组)
divsionObj[index] = item; selectedFactories.value = row.factoryName ? row.factoryName.split(',') : [];
}); }
form.value.divsion = JSON.stringify(divsionObj); // 解析 factoryName(假设存储为 JSON 字符串数组)
}, { deep: true }); function parseFactoryName(factoryName) {
// 所有可选的工厂列表
const allFactories = ref([
'整车二工厂', '整车三工厂', '整车四工厂',
'智造一工厂', '智造二工厂', '大连工厂',
'青岛工厂', '鄂尔多斯工厂', '开封工厂',
'城南工厂', '城北工厂', '齐河工厂',
'石家庄工厂'
]);
watch(() => form.value.factoryName, (newVal) => {
try { try {
const factoryObj = JSON.parse(newVal || '{}'); return JSON.parse(factoryName || '[]'); // 默认空数组
selectedFactories.value = Object.values(factoryObj);
} catch (e) { } catch (e) {
selectedFactories.value = []; return [];
} }
}, { immediate: true }); }
// 监听选中的工厂变化,更新表单数据 // 监听选中的工厂变化,更新表单数据
watch(selectedFactories, (newVal) => { watch(selectedFactories, (newVal) => {
const factoryObj = {}; form.value.factoryName = JSON.stringify(newVal); // 存储为 JSON 字符串
newVal.forEach((item, index) => {
factoryObj[index] = item;
});
form.value.factoryName = JSON.stringify(factoryObj);
}, { deep: true }); }, { deep: true });
// 获取工厂数据的方法
const fetchFactories = async () => {
try {
const response = await getAllFactoryName();
// 提取factoryName字段
allFactories.value = response.data.map(item => item.factoryName);
} catch (error) {
console.error('获取工厂列表失败:', error);
}
};
// 获取角色的方法
/*const fetchRoles = async () => {
const response = await listRole();
allRoles.value = response.data.map(item => item.roleName);
};*/
/** 查询用户列表 */ /** 查询用户列表 */
function getList() { function getList() {
loading.value = true loading.value = true
...@@ -755,6 +807,7 @@ function handleCommand(command, row) { ...@@ -755,6 +807,7 @@ function handleCommand(command, row) {
/** 跳转角色分配 */ /** 跳转角色分配 */
function handleAuthRole(row) { function handleAuthRole(row) {
dialogRole.value = true
const userId = row.userId const userId = row.userId
router.push('/system/user-auth/role/' + userId) router.push('/system/user-auth/role/' + userId)
} }
...@@ -832,18 +885,18 @@ function submitFileForm() { ...@@ -832,18 +885,18 @@ function submitFileForm() {
/** 重置操作表单 */ /** 重置操作表单 */
function reset() { function reset() {
form.value = { form.value = {
userId: undefined, userId: null,
deptId: undefined, deptId: null,
userName: undefined, userName: null,
nickName: undefined, nickName: null,
password: undefined, password: null,
phonenumber: undefined, phonenumber: null,
email: undefined, email: null,
sex: undefined, sex: null,
roleNames: '超级管理员', roleNames: '超级管理员',
status: '0', status: '0',
userType: '00', userType: '00',
remark: undefined, remark: null,
postIds: [], postIds: [],
roleIds: [], roleIds: [],
} }
...@@ -912,7 +965,10 @@ function submitForm() { ...@@ -912,7 +965,10 @@ function submitForm() {
} }
}) })
} }
onMounted(() => {
fetchFactories();
//fetchRoles();
});
getDeptTree() getDeptTree()
getList() getList()
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment