feat: 管理员查看藏品列表时显示所属用户名
This commit is contained in:
parent
cd2e8e80cb
commit
a5cce17218
|
|
@ -107,8 +107,13 @@ def get_collections(
|
||||||
):
|
):
|
||||||
"""获取藏品列表"""
|
"""获取藏品列表"""
|
||||||
# admin 用户可以看到所有藏品,普通用户只能看到自己的
|
# admin 用户可以看到所有藏品,普通用户只能看到自己的
|
||||||
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
if current_user.role == "admin":
|
if current_user.role == "admin":
|
||||||
query = db.query(Collection)
|
# 联表查询获取用户名
|
||||||
|
query = db.query(Collection, User.f01_01_name.label('owner_name')).join(
|
||||||
|
User, Collection.f99_91_user_id == User.f99_90_id, isouter=True
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
query = db.query(Collection).filter(Collection.f99_91_user_id == current_user.f99_90_id)
|
query = db.query(Collection).filter(Collection.f99_91_user_id == current_user.f99_90_id)
|
||||||
|
|
||||||
|
|
@ -122,7 +127,10 @@ def get_collections(
|
||||||
(Collection.f01_05_remark.contains(search))
|
(Collection.f01_05_remark.contains(search))
|
||||||
)
|
)
|
||||||
|
|
||||||
# 总数
|
# 总数(分开查询避免join影响count)
|
||||||
|
if current_user.role == "admin":
|
||||||
|
total = db.query(Collection).count()
|
||||||
|
else:
|
||||||
total = query.count()
|
total = query.count()
|
||||||
|
|
||||||
# 分页
|
# 分页
|
||||||
|
|
@ -134,43 +142,51 @@ def get_collections(
|
||||||
# 转换为字典列表并转为 camelCase
|
# 转换为字典列表并转为 camelCase
|
||||||
data_list = []
|
data_list = []
|
||||||
for item in data:
|
for item in data:
|
||||||
|
# 处理联表查询结果
|
||||||
|
if current_user.role == "admin":
|
||||||
|
collection_item, owner_name = item
|
||||||
|
else:
|
||||||
|
collection_item = item
|
||||||
|
owner_name = None
|
||||||
|
|
||||||
item_dict = {
|
item_dict = {
|
||||||
'f99_90_id': item.f99_90_id,
|
'f99_90_id': collection_item.f99_90_id,
|
||||||
'f99_91_user_id': item.f99_91_user_id,
|
'f99_91_user_id': collection_item.f99_91_user_id,
|
||||||
'f01_01_name': item.f01_01_name,
|
'owner_name': owner_name, # 所属用户名(仅管理员可见)
|
||||||
'f01_02_code': item.f01_02_code,
|
'f01_01_name': collection_item.f01_01_name,
|
||||||
'f01_03_category': item.f01_03_category,
|
'f01_02_code': collection_item.f01_02_code,
|
||||||
'f01_04_status': item.f01_04_status,
|
'f01_03_category': collection_item.f01_03_category,
|
||||||
'f01_05_remark': item.f01_05_remark,
|
'f01_04_status': collection_item.f01_04_status,
|
||||||
'f02_10_prefix_serial': item.f02_10_prefix_serial,
|
'f01_05_remark': collection_item.f01_05_remark,
|
||||||
'f02_11_version': item.f02_11_version,
|
'f02_10_prefix_serial': collection_item.f02_10_prefix_serial,
|
||||||
'f02_12_packaging': item.f02_12_packaging,
|
'f02_11_version': collection_item.f02_11_version,
|
||||||
'f02_13_rarity': item.f02_13_rarity,
|
'f02_12_packaging': collection_item.f02_12_packaging,
|
||||||
'f03_20_is_graded': item.f03_20_is_graded,
|
'f02_13_rarity': collection_item.f02_13_rarity,
|
||||||
'f03_21_grading_company': item.f03_21_grading_company,
|
'f03_20_is_graded': collection_item.f03_20_is_graded,
|
||||||
'f03_22_grading_score': item.f03_22_grading_score,
|
'f03_21_grading_company': collection_item.f03_21_grading_company,
|
||||||
'f03_23_three_star': item.f03_23_three_star,
|
'f03_22_grading_score': collection_item.f03_22_grading_score,
|
||||||
'f04_30_special_mark': item.f04_30_special_mark,
|
'f03_23_three_star': collection_item.f03_23_three_star,
|
||||||
'f04_31_serial_feature': item.f04_31_serial_feature,
|
'f04_30_special_mark': collection_item.f04_30_special_mark,
|
||||||
'f04_32_issuer': item.f04_32_issuer,
|
'f04_31_serial_feature': collection_item.f04_31_serial_feature,
|
||||||
'f04_33_issue_year': item.f04_33_issue_year,
|
'f04_32_issuer': collection_item.f04_32_issuer,
|
||||||
'f04_34_material': item.f04_34_material,
|
'f04_33_issue_year': collection_item.f04_33_issue_year,
|
||||||
'f04_35_denomination': item.f04_35_denomination,
|
'f04_34_material': collection_item.f04_34_material,
|
||||||
'f04_36_issue_quantity': item.f04_36_issue_quantity,
|
'f04_35_denomination': collection_item.f04_35_denomination,
|
||||||
'f05_40_cost_price': float(item.f05_40_cost_price) if item.f05_40_cost_price else None,
|
'f04_36_issue_quantity': collection_item.f04_36_issue_quantity,
|
||||||
'f05_41_target_price': float(item.f05_41_target_price) if item.f05_41_target_price else None,
|
'f05_40_cost_price': float(collection_item.f05_40_cost_price) if collection_item.f05_40_cost_price else None,
|
||||||
'f05_42_goal_price': float(item.f05_42_goal_price) if item.f05_42_goal_price else None,
|
'f05_41_target_price': float(collection_item.f05_41_target_price) if collection_item.f05_41_target_price else None,
|
||||||
'f05_43_repair_fee': float(item.f05_43_repair_fee) if item.f05_43_repair_fee else None,
|
'f05_42_goal_price': float(collection_item.f05_42_goal_price) if collection_item.f05_42_goal_price else None,
|
||||||
'f05_44_grading_fee': float(item.f05_44_grading_fee) if item.f05_44_grading_fee else None,
|
'f05_43_repair_fee': float(collection_item.f05_43_repair_fee) if collection_item.f05_43_repair_fee else None,
|
||||||
'f06_50_purpose': item.f06_50_purpose,
|
'f05_44_grading_fee': float(collection_item.f05_44_grading_fee) if collection_item.f05_44_grading_fee else None,
|
||||||
'f99_92_created_at': item.f99_92_created_at.isoformat() if item.f99_92_created_at else None,
|
'f06_50_purpose': collection_item.f06_50_purpose,
|
||||||
|
'f99_92_created_at': collection_item.f99_92_created_at.isoformat() if collection_item.f99_92_created_at else None,
|
||||||
'images': []
|
'images': []
|
||||||
}
|
}
|
||||||
|
|
||||||
# 加载图片数据
|
# 加载图片数据
|
||||||
from app.models.models import CollectionImage
|
from app.models.models import CollectionImage
|
||||||
images = db.query(CollectionImage).filter(
|
images = db.query(CollectionImage).filter(
|
||||||
CollectionImage.collection_id == item.f99_90_id
|
CollectionImage.collection_id == collection_item.f99_90_id
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
for img in images:
|
for img in images:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# Version Configuration for Zodiac Collection Management System
|
# Version Configuration for Zodiac Collection Management System
|
||||||
|
|
||||||
# 当前版本号 (语义化版本:主版本。次版本.修订版)
|
# 当前版本号 (语义化版本:主版本。次版本.修订版)
|
||||||
VERSION=1.1.9
|
VERSION=1.2.0
|
||||||
|
|
||||||
# 版本代号 (可选)
|
# 版本代号 (可选)
|
||||||
VERSION_CODENAME="新生"
|
VERSION_CODENAME="新生"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<title>甲辰收藏 v1.1.8</title>
|
<title>甲辰收藏 v1.1.9</title>
|
||||||
|
|
||||||
<!-- Favicon -->
|
<!-- Favicon -->
|
||||||
<link rel="icon" type="image/x-icon" href="/static/icons/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/static/icons/favicon.ico" />
|
||||||
|
|
|
||||||
|
|
@ -343,7 +343,7 @@ export default function List() {
|
||||||
<div onClick={() => goDetail(item.id)} style={{ background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.05)', borderRadius: '12px', padding: '14px', marginBottom: '10px', cursor: 'pointer' }}>
|
<div onClick={() => goDetail(item.id)} style={{ background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.05)', borderRadius: '12px', padding: '14px', marginBottom: '10px', cursor: 'pointer' }}>
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||||
<div style={{ flex: 1 }}>
|
<div style={{ flex: 1 }}>
|
||||||
{isAdmin && item.user && <div style={{ color: '#60a5fa', fontSize: '12px', marginBottom: '2px' }}>👤 {item.username}</div>}
|
{isAdmin && item.owner_name && <div style={{ color: '#60a5fa', fontSize: '12px', marginBottom: '2px' }}>👤 {item.owner_name}</div>}
|
||||||
<div style={{ color: '#fff', fontSize: '15px', fontWeight: '500' }}>{item.code || '-'}</div>
|
<div style={{ color: '#fff', fontSize: '15px', fontWeight: '500' }}>{item.code || '-'}</div>
|
||||||
<div style={{ color: '#fbbf24', fontSize: '13px', fontFamily: 'monospace', marginTop: '4px' }}>{item.prefixSerial || '-'}</div>
|
<div style={{ color: '#fbbf24', fontSize: '13px', fontFamily: 'monospace', marginTop: '4px' }}>{item.prefixSerial || '-'}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue