| | |
| | | <script setup> |
| | | import { Search, Lock } from "@element-plus/icons-vue"; // 新增Lock图标导入 |
| | | import { reactive, ref, onMounted } from "vue"; // 合并导入 |
| | | import { reactive, ref, onMounted } from "vue"; |
| | | import { useRouter } from "vue-router"; |
| | | const router = useRouter(); |
| | | import request from "@/utils/request"; |
| | | import { ElMessage, ElMessageBox } from "element-plus"; |
| | | import { useI18n } from "vue-i18n"; |
| | | const { t } = useI18n(); |
| | | |
| | | let language = ref(localStorage.getItem("lang") || "zh"); |
| | | const selectedProjectNoa = ref(null); |
| | | const userName = ref(""); |
| | | const password = ref(""); |
| | | const confirmPassword = ref(""); // 新增:确认密码 |
| | | const editPassword = ref(""); // 新增:编辑时的密码 |
| | | const editConfirmPassword = ref(""); // 新增:编辑时的确认密码 |
| | | const confirmPassword = ref(""); |
| | | const editPassword = ref(""); |
| | | const editConfirmPassword = ref(""); |
| | | const tableData = ref([]); |
| | | const slot = ref(""); |
| | | const add = ref(false); // 添加弹窗 |
| | | const adda = ref(false); // 编辑弹窗 |
| | | |
| | | const add = ref(false); |
| | | const adda = ref(false); |
| | | let language = ref(localStorage.getItem("lang") || "zh"); |
| | | // 获取用户列表 |
| | | const listByUserName = async () => { |
| | | try { |
| | |
| | | } |
| | | } catch (error) { |
| | | ElMessage.error( ); |
| | | console.error("获取用户列表失败:", error); |
| | | } |
| | | }; |
| | | |
| | | // 重置密码 |
| | | const open = async (row) => { |
| | | try { |
| | |
| | | } |
| | | } |
| | | }; |
| | | |
| | | const titleSelectJsona = ref({ |
| | | processTypea: [], // 修正字段名拼写 |
| | | processTypea: [], |
| | | }); |
| | | |
| | | // 获取角色列表 |
| | | const fetchOptionsa = async () => { |
| | | try { |
| | |
| | | } |
| | | } catch (error) { |
| | | ElMessage.error( ); |
| | | console.error("获取角色列表失败:", error); |
| | | } |
| | | }; |
| | | |
| | | // 处理编辑按钮点击 |
| | | function handleEdit(row) { |
| | | userName.value = row.userName; |
| | | editPassword.value = ""; // 清空编辑密码 |
| | | editConfirmPassword.value = ""; // 清空编辑确认密码 |
| | | editPassword.value = ""; |
| | | editConfirmPassword.value = ""; |
| | | if (row.roleList && row.roleList.length > 0) { |
| | | const firstRole = row.roleList[0]; |
| | | selectedProjectNoa.value = firstRole.id; |
| | |
| | | adda.value = true; |
| | | window.localStorage.setItem("id", row.id); |
| | | } |
| | | |
| | | // 关闭添加弹窗 |
| | | function closeDialog() { |
| | | add.value = false; |
| | | userName.value = ""; |
| | | password.value = ""; |
| | | confirmPassword.value = ""; // 清空确认密码 |
| | | confirmPassword.value = ""; |
| | | selectedProjectNoa.value = ""; |
| | | } |
| | | |
| | | // 关闭编辑弹窗 |
| | | function closeDialoga() { |
| | | adda.value = false; |
| | | userName.value = ""; |
| | | editPassword.value = ""; // 清空编辑密码 |
| | | editConfirmPassword.value = ""; // 清空编辑确认密码 |
| | | editPassword.value = ""; |
| | | editConfirmPassword.value = ""; |
| | | selectedProjectNoa.value = ""; |
| | | } |
| | | |
| | | // 添加用户 |
| | | const getTableRow = async () => { |
| | | // 验证用户名 |
| | |
| | | } |
| | | // 验证确认密码 |
| | | if (!confirmPassword.value) { |
| | | ElMessage.error(t("productStock.inconfirmpassword")); // 需在i18n中添加该字段 |
| | | ElMessage.error(t("productStock.inconfirmpassword")); |
| | | return; |
| | | } |
| | | // 验证密码一致性 |
| | | if (password.value !== confirmPassword.value) { |
| | | ElMessage.error(t("productStock.passwordNotMatch")); // 需在i18n中添加该字段 |
| | | ElMessage.error(t("productStock.passwordNotMatch")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | const response = await request.post("/loadGlass/sys/user/saveUser", { |
| | | userName: userName.value, |
| | |
| | | } |
| | | } catch (error) { |
| | | ElMessage.error( ); |
| | | console.error("添加用户失败:", error); |
| | | } |
| | | }; |
| | | |
| | | // 编辑用户 |
| | | const getTableRowa = async () => { |
| | | // 验证用户名 |
| | |
| | | ElMessage.error(t("productStock.inrole")); |
| | | return; |
| | | } |
| | | // 如果填写了密码,验证密码和确认密码 |
| | | if (editPassword.value || editConfirmPassword.value) { |
| | | if (!editPassword.value) { |
| | | ElMessage.error(t("productStock.inpassword")); |
| | |
| | | return; |
| | | } |
| | | } |
| | | |
| | | let id = window.localStorage.getItem("id"); |
| | | if (!id) { |
| | | ElMessage.error(t("productStock.userIdError")); |
| | | return; |
| | | } |
| | | try { |
| | | // 构建请求参数 |
| | | const requestData = { |
| | | id: id, |
| | | userName: userName.value, |
| | |
| | | }, |
| | | ], |
| | | }; |
| | | // 如果填写了密码,添加到请求参数中 |
| | | if (editPassword.value) { |
| | | requestData.password = editPassword.value; |
| | | } |
| | | |
| | | const response = await request.post("/loadGlass/sys/user/updateUser", requestData); |
| | | if (response.code === 200) { |
| | | ElMessage.success(response.message); |
| | | closeDialoga(); // 关闭弹窗并清空表单 |
| | | listByUserName(); // 刷新列表 |
| | | closeDialoga(); |
| | | listByUserName(); |
| | | } else { |
| | | ElMessage.error(response.message); |
| | | } |
| | | } catch (error) { |
| | | ElMessage.error( ); |
| | | console.error("编辑用户失败:", error); |
| | | } |
| | | }; |
| | | |
| | | // 删除用户 |
| | | const opena = async (row) => { |
| | | try { |
| | |
| | | } catch (error) { |
| | | if (error !== "cancel") { |
| | | ElMessage.error( ); |
| | | console.error("删除用户失败:", error); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | fetchOptionsa(); |
| | | listByUserName(); |
| | | }); |
| | | </script> |
| | | |
| | | <template> |
| | | <div> |
| | | <el-button |
| | |
| | | </div> |
| | | </el-card> |
| | | </div> |
| | | |
| | | <!-- 添加用户弹窗 --> |
| | | <el-dialog |
| | | v-model="add" |
| | |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | |
| | | <!-- 编辑用户弹窗 --> |
| | | <el-dialog |
| | | v-model="adda" |
| | |
| | | </template> |
| | | </el-dialog> |
| | | </template> |
| | | |
| | | <style scoped> |
| | | #dt { |
| | | display: block; |