IRIS部门过滤: 后端users接口按department=IRIS过滤 + 前端双重兜底
This commit is contained in:
@ -11,6 +11,7 @@ class UserOption(BaseModel):
|
|||||||
id: str
|
id: str
|
||||||
username: str
|
username: str
|
||||||
full_name: str
|
full_name: str
|
||||||
|
department: str = ""
|
||||||
|
|
||||||
model_config = {"from_attributes": True}
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
@ -19,39 +20,32 @@ class UserOption(BaseModel):
|
|||||||
def list_users(
|
def list_users(
|
||||||
keyword: str = Query("", description="按用户名/姓名模糊搜索"),
|
keyword: str = Query("", description="按用户名/姓名模糊搜索"),
|
||||||
limit: int = Query(100, ge=1, le=500),
|
limit: int = Query(100, ge=1, le=500),
|
||||||
|
dept: str = Query("IRIS", description="部门过滤"),
|
||||||
):
|
):
|
||||||
"""获取 MOM 系统用户列表,供前端选人使用"""
|
"""获取 MOM 系统用户列表,默认只返回 IRIS 部门"""
|
||||||
db = MomSessionLocal()
|
db = MomSessionLocal()
|
||||||
try:
|
try:
|
||||||
|
base_sql = """
|
||||||
|
SELECT id, username,
|
||||||
|
SPLIT_PART(username, '/', 1) AS full_name,
|
||||||
|
COALESCE(department, '') AS department
|
||||||
|
FROM sys_user
|
||||||
|
WHERE department = :dept
|
||||||
|
"""
|
||||||
|
params = {"dept": dept, "lim": limit}
|
||||||
if keyword.strip():
|
if keyword.strip():
|
||||||
sql = text(
|
sql = text(base_sql + " AND username ILIKE :kw ORDER BY username LIMIT :lim")
|
||||||
"""
|
params["kw"] = f"%{keyword.strip()}%"
|
||||||
SELECT id, username,
|
|
||||||
SPLIT_PART(username, '/', 1) AS full_name
|
|
||||||
FROM sys_user
|
|
||||||
WHERE username ILIKE :kw
|
|
||||||
ORDER BY username
|
|
||||||
LIMIT :lim
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
rows = db.execute(sql, {"kw": f"%{keyword.strip()}%", "lim": limit}).fetchall()
|
|
||||||
else:
|
else:
|
||||||
sql = text(
|
sql = text(base_sql + " ORDER BY username LIMIT :lim")
|
||||||
"""
|
rows = db.execute(sql, params).fetchall()
|
||||||
SELECT id, username,
|
|
||||||
SPLIT_PART(username, '/', 1) AS full_name
|
|
||||||
FROM sys_user
|
|
||||||
ORDER BY username
|
|
||||||
LIMIT :lim
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
rows = db.execute(sql, {"lim": limit}).fetchall()
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
UserOption(
|
UserOption(
|
||||||
id=str(row.id),
|
id=str(row.id),
|
||||||
username=row.username.split("/")[-1] if "/" in row.username else row.username,
|
username=row.username.split("/")[-1] if "/" in row.username else row.username,
|
||||||
full_name=row.full_name,
|
full_name=row.full_name,
|
||||||
|
department=row.department or "",
|
||||||
)
|
)
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
|
|||||||
@ -198,7 +198,7 @@ export default {
|
|||||||
openEditProduct() { this.editForm = { order_no: this.product.order_no || "", external_serial: this.product.external_serial || "" }; this.editProductVisible = true; },
|
openEditProduct() { this.editForm = { order_no: this.product.order_no || "", external_serial: this.product.external_serial || "" }; this.editProductVisible = true; },
|
||||||
async doEditProduct() { this.editSaving = true; try { this.product = await patch(`/products/${this.product.id}`, { order_no: this.editForm.order_no.trim(), external_serial: this.editForm.external_serial.trim() }); uni.showToast({ title: "已保存", icon: "success" }); this.editProductVisible = false; } catch {} finally { this.editSaving = false; } },
|
async doEditProduct() { this.editSaving = true; try { this.product = await patch(`/products/${this.product.id}`, { order_no: this.editForm.order_no.trim(), external_serial: this.editForm.external_serial.trim() }); uni.showToast({ title: "已保存", icon: "success" }); this.editProductVisible = false; } catch {} finally { this.editSaving = false; } },
|
||||||
|
|
||||||
async loadUsers() { try { this.users = await get("/users/", { limit: 200 }); this.userOptions = (this.users || []).map(u => ({ id: u.username || u.id, name: u.full_name || u.username })); } catch {} },
|
async loadUsers() { try { const res = await get("/users/", { limit: 200, dept: "IRIS" }); this.users = (res || []).filter(u => u.department === "IRIS" || !u.department); this.userOptions = this.users.map(u => ({ id: u.username || u.id, name: u.full_name || u.username })); } catch {} },
|
||||||
loadCurrentUser() { try { let user = uni.getStorageSync("user"); if (typeof user === "string" && user) { try { user = JSON.parse(user); } catch (e) { user = null; } } if (user && typeof user === "object") { this.currentUser = user; this.currentUserId = String(user.id || ""); this.currentUsername = user.username || ""; } } catch {} },
|
loadCurrentUser() { try { let user = uni.getStorageSync("user"); if (typeof user === "string" && user) { try { user = JSON.parse(user); } catch (e) { user = null; } } if (user && typeof user === "object") { this.currentUser = user; this.currentUserId = String(user.id || ""); this.currentUsername = user.username || ""; } } catch {} },
|
||||||
|
|
||||||
onTaskNameChange(e) { const idx = e.detail.value; this.firstForm.taskNameIdx = idx; this.firstForm.task_name = TASK_NAME_OPTIONS[idx]; },
|
onTaskNameChange(e) { const idx = e.detail.value; this.firstForm.taskNameIdx = idx; this.firstForm.task_name = TASK_NAME_OPTIONS[idx]; },
|
||||||
|
|||||||
Reference in New Issue
Block a user