You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 lines
5.2 KiB

{"ast":null,"code":"import { ref } from 'vue';\nimport { ElMessage, ElMessageBox } from 'element-plus';\nimport { updateUserRole } from '@/api/auth';\nexport default {\n __name: 'UserManagement',\n setup(__props, {\n expose: __expose\n }) {\n __expose();\n const loading = ref(false);\n const userList = ref([]);\n const handleRoleChange = async user => {\n try {\n await ElMessageBox.confirm(`确定要将用户 ${user.username} 的角色更改为 ${user.role} 吗?`, '提示', {\n type: 'warning',\n confirmButtonText: '确定',\n cancelButtonText: '取消'\n });\n const res = await updateUserRole(user.id, user.role);\n if (res.code === 200) {\n ElMessage.success('角色更新成功');\n }\n } catch (error) {\n if (error !== 'cancel') {\n console.error('更新角色失败:', error);\n ElMessage.error(error.message || '更新角色失败');\n // 恢复原来的角色\n user.role = user.originalRole;\n }\n }\n };\n const __returned__ = {\n loading,\n userList,\n handleRoleChange,\n ref,\n get ElMessage() {\n return ElMessage;\n },\n get ElMessageBox() {\n return ElMessageBox;\n },\n get updateUserRole() {\n return updateUserRole;\n }\n };\n Object.defineProperty(__returned__, '__isScriptSetup', {\n enumerable: false,\n value: true\n });\n return __returned__;\n }\n};","map":{"version":3,"names":["ref","ElMessage","ElMessageBox","updateUserRole","loading","userList","handleRoleChange","user","confirm","username","role","type","confirmButtonText","cancelButtonText","res","id","code","success","error","console","message","originalRole"],"sources":["D:/language/VScode/Front-end logistics/src/views/admin/UserManagement.vue"],"sourcesContent":["<template>\r\n <div class=\"user-management\">\r\n <el-card>\r\n <template #header>\r\n <div class=\"card-header\">\r\n <span>用户管理</span>\r\n </div>\r\n </template>\r\n \r\n <el-table\r\n v-loading=\"loading\"\r\n :data=\"userList\"\r\n style=\"width: 100%\"\r\n >\r\n <el-table-column prop=\"id\" label=\"用户ID\" width=\"100\" />\r\n <el-table-column prop=\"username\" label=\"用户名\" />\r\n <el-table-column prop=\"email\" label=\"邮箱\" />\r\n <el-table-column prop=\"role\" label=\"角色\">\r\n <template #default=\"{ row }\">\r\n <el-select \r\n v-model=\"row.role\" \r\n @change=\"handleRoleChange(row)\"\r\n >\r\n <el-option label=\"普通用户\" value=\"ROLE_USER\" />\r\n <el-option label=\"仓库管理员\" value=\"ROLE_WAREHOUSE_ADMIN\" />\r\n <el-option label=\"物流管理员\" value=\"ROLE_LOGISTICS_ADMIN\" />\r\n <el-option label=\"系统管理员\" value=\"ROLE_ADMIN\" />\r\n </el-select>\r\n </template>\r\n </el-table-column>\r\n <el-table-column prop=\"createTime\" label=\"创建时间\" />\r\n </el-table>\r\n </el-card>\r\n </div>\r\n</template>\r\n\r\n<script setup>\r\nimport { ref } from 'vue'\r\nimport { ElMessage, ElMessageBox } from 'element-plus'\r\nimport { updateUserRole } from '@/api/auth'\r\n\r\nconst loading = ref(false)\r\nconst userList = ref([])\r\n\r\nconst handleRoleChange = async (user) => {\r\n try {\r\n await ElMessageBox.confirm(\r\n `确定要将用户 ${user.username} 的角色更改为 ${user.role} 吗?`,\r\n '提示',\r\n {\r\n type: 'warning',\r\n confirmButtonText: '确定',\r\n cancelButtonText: '取消'\r\n }\r\n )\r\n \r\n const res = await updateUserRole(user.id, user.role)\r\n if (res.code === 200) {\r\n ElMessage.success('角色更新成功')\r\n }\r\n } catch (error) {\r\n if (error !== 'cancel') {\r\n console.error('更新角色失败:', error)\r\n ElMessage.error(error.message || '更新角色失败')\r\n // 恢复原来的角色\r\n user.role = user.originalRole\r\n }\r\n }\r\n}\r\n</script>\r\n\r\n<style scoped>\r\n.user-management {\r\n padding: 20px;\r\n}\r\n\r\n.card-header {\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n}\r\n</style> "],"mappings":"AAqCA,SAASA,GAAG,QAAQ,KAAK;AACzB,SAASC,SAAS,EAAEC,YAAY,QAAQ,cAAc;AACtD,SAASC,cAAc,QAAQ,YAAY;;;;;;;IAE3C,MAAMC,OAAO,GAAGJ,GAAG,CAAC,KAAK,CAAC;IAC1B,MAAMK,QAAQ,GAAGL,GAAG,CAAC,EAAE,CAAC;IAExB,MAAMM,gBAAgB,GAAG,MAAOC,IAAI,IAAK;MACvC,IAAI;QACF,MAAML,YAAY,CAACM,OAAO,CACxB,UAAUD,IAAI,CAACE,QAAQ,WAAWF,IAAI,CAACG,IAAI,KAAK,EAChD,IAAI,EACJ;UACEC,IAAI,EAAE,SAAS;UACfC,iBAAiB,EAAE,IAAI;UACvBC,gBAAgB,EAAE;QACpB,CACF,CAAC;QAED,MAAMC,GAAG,GAAG,MAAMX,cAAc,CAACI,IAAI,CAACQ,EAAE,EAAER,IAAI,CAACG,IAAI,CAAC;QACpD,IAAII,GAAG,CAACE,IAAI,KAAK,GAAG,EAAE;UACpBf,SAAS,CAACgB,OAAO,CAAC,QAAQ,CAAC;QAC7B;MACF,CAAC,CAAC,OAAOC,KAAK,EAAE;QACd,IAAIA,KAAK,KAAK,QAAQ,EAAE;UACtBC,OAAO,CAACD,KAAK,CAAC,SAAS,EAAEA,KAAK,CAAC;UAC/BjB,SAAS,CAACiB,KAAK,CAACA,KAAK,CAACE,OAAO,IAAI,QAAQ,CAAC;UAC1C;UACAb,IAAI,CAACG,IAAI,GAAGH,IAAI,CAACc,YAAY;QAC/B;MACF;IACF,CAAC","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}