improve marketplace search functionality and user experience
This commit is contained in:
parent
a2d3094495
commit
96e2e0bbbe
@ -388,8 +388,8 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听搜索和排序变化
|
// 只监听排序变化,搜索需要手动触发(按Enter或点击搜索按钮)
|
||||||
watch([searchQuery, sortBy], () => {
|
watch([sortBy], () => {
|
||||||
page.value = 1 // 重置到第一页
|
page.value = 1 // 重置到第一页
|
||||||
loadAgents()
|
loadAgents()
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|||||||
@ -417,8 +417,8 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听搜索和排序变化
|
// 只监听排序变化,搜索需要手动触发(按Enter或点击搜索按钮)
|
||||||
watch([searchQuery, sortBy], () => {
|
watch([sortBy], () => {
|
||||||
page.value = 1 // 重置到第一页
|
page.value = 1 // 重置到第一页
|
||||||
loadApps()
|
loadApps()
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|||||||
@ -400,8 +400,8 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听搜索和排序变化
|
// 只监听排序变化,搜索需要手动触发(按Enter或点击搜索按钮)
|
||||||
watch([searchQuery, sortBy], () => {
|
watch([sortBy], () => {
|
||||||
page.value = 1 // 重置到第一页
|
page.value = 1 // 重置到第一页
|
||||||
loadNodes()
|
loadNodes()
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|||||||
@ -419,8 +419,8 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听搜索和排序变化
|
// 只监听排序变化,搜索需要手动触发(按Enter或点击搜索按钮)
|
||||||
watch([searchQuery, sortBy], () => {
|
watch([sortBy], () => {
|
||||||
page.value = 1 // 重置到第一页
|
page.value = 1 // 重置到第一页
|
||||||
loadTools()
|
loadTools()
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|||||||
@ -918,55 +918,54 @@ async def get_app_marketplace(
|
|||||||
try:
|
try:
|
||||||
url = f"{get_jingrow_cloud_url()}/api/action/jcloud.api.jlocal.get_local_app_list"
|
url = f"{get_jingrow_cloud_url()}/api/action/jcloud.api.jlocal.get_local_app_list"
|
||||||
|
|
||||||
# 构建过滤条件
|
|
||||||
filters = {"public": 1}
|
filters = {"public": 1}
|
||||||
if search:
|
|
||||||
filters["title"] = ["like", f"%{search}%"]
|
|
||||||
|
|
||||||
# 1. 先获取总数(不分页)
|
# 1. 先获取所有数据(用于搜索过滤)
|
||||||
total_params = {
|
total_params = {
|
||||||
'filters': json.dumps(filters, ensure_ascii=False),
|
'filters': json.dumps(filters, ensure_ascii=False),
|
||||||
'limit_start': 0,
|
'limit_start': 0,
|
||||||
'limit_page_length': 0 # 不限制数量,获取所有数据来计算总数
|
'limit_page_length': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
headers = get_jingrow_cloud_api_headers()
|
headers = get_jingrow_cloud_api_headers()
|
||||||
total_response = requests.get(url, params=total_params, headers=headers, timeout=20)
|
total_response = requests.get(url, params=total_params, headers=headers, timeout=20)
|
||||||
|
|
||||||
total_count = 0
|
all_apps = []
|
||||||
if total_response.status_code == 200:
|
if total_response.status_code == 200:
|
||||||
total_data = total_response.json()
|
total_data = total_response.json()
|
||||||
total_count = len(total_data.get('message', []))
|
all_apps = total_data.get('message', [])
|
||||||
|
|
||||||
# 2. 获取分页数据
|
# 如果有搜索关键词,在Python中进行多字段过滤(OR逻辑)
|
||||||
params = {
|
if search:
|
||||||
'filters': json.dumps(filters, ensure_ascii=False)
|
search_lower = search.lower()
|
||||||
}
|
filtered_apps = []
|
||||||
|
for app in all_apps:
|
||||||
|
if (search_lower in str(app.get('app_name', '')).lower() or
|
||||||
|
search_lower in str(app.get('title', '')).lower()):
|
||||||
|
filtered_apps.append(app)
|
||||||
|
all_apps = filtered_apps
|
||||||
|
|
||||||
# 排序参数
|
total_count = len(all_apps)
|
||||||
|
|
||||||
|
# 2. 排序
|
||||||
if sort_by:
|
if sort_by:
|
||||||
params['order_by'] = sort_by
|
sort_field, sort_order = sort_by.rsplit(' ', 1)
|
||||||
|
reverse = sort_order.lower() == 'desc'
|
||||||
|
try:
|
||||||
|
all_apps.sort(key=lambda x: x.get(sort_field, ''), reverse=reverse)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# 分页参数
|
# 3. 分页
|
||||||
limit_start = (page - 1) * page_size
|
limit_start = (page - 1) * page_size
|
||||||
params['limit_start'] = limit_start
|
apps = all_apps[limit_start:limit_start + page_size]
|
||||||
params['limit_page_length'] = page_size
|
|
||||||
|
|
||||||
response = requests.get(url, params=params, headers=headers, timeout=20)
|
return {
|
||||||
|
"items": apps,
|
||||||
if response.status_code == 200:
|
"total": total_count,
|
||||||
data = response.json()
|
"page": page,
|
||||||
apps = data.get('message', [])
|
"page_size": page_size
|
||||||
|
}
|
||||||
# 返回分页格式的数据
|
|
||||||
return {
|
|
||||||
"items": apps,
|
|
||||||
"total": total_count,
|
|
||||||
"page": page,
|
|
||||||
"page_size": page_size
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
raise HTTPException(status_code=response.status_code, detail="获取应用市场数据失败")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"获取应用市场数据失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"获取应用市场数据失败: {str(e)}")
|
||||||
|
|||||||
@ -253,8 +253,9 @@ async def get_node_marketplace(
|
|||||||
# 构建过滤条件
|
# 构建过滤条件
|
||||||
filters = {"public": 1}
|
filters = {"public": 1}
|
||||||
if search:
|
if search:
|
||||||
|
# 注意:字典格式的filters是AND关系,所以先搜索title
|
||||||
|
# 如果需要在多个字段中搜索,需要在获取数据后进行过滤
|
||||||
filters["title"] = ["like", f"%{search}%"]
|
filters["title"] = ["like", f"%{search}%"]
|
||||||
filters["node_type"] = ["like", f"%{search}%"]
|
|
||||||
|
|
||||||
# 1. 先获取总数(不分页)
|
# 1. 先获取总数(不分页)
|
||||||
total_params = {
|
total_params = {
|
||||||
@ -797,7 +798,8 @@ async def get_agent_marketplace(
|
|||||||
# 构建过滤条件
|
# 构建过滤条件
|
||||||
filters = {"public": 1}
|
filters = {"public": 1}
|
||||||
if search:
|
if search:
|
||||||
filters["agent_name"] = ["like", f"%{search}%"]
|
# 注意:字典格式的filters是AND关系,所以先搜索title
|
||||||
|
# 如果需要在多个字段中搜索,需要在获取数据后进行过滤
|
||||||
filters["title"] = ["like", f"%{search}%"]
|
filters["title"] = ["like", f"%{search}%"]
|
||||||
|
|
||||||
# 1. 先获取总数(不分页)
|
# 1. 先获取总数(不分页)
|
||||||
|
|||||||
@ -54,12 +54,8 @@ async def get_tool_marketplace(
|
|||||||
|
|
||||||
# 构建过滤条件
|
# 构建过滤条件
|
||||||
filters = {"public": 1}
|
filters = {"public": 1}
|
||||||
if search:
|
|
||||||
filters["name"] = ["like", f"%{search}%"]
|
|
||||||
filters["title"] = ["like", f"%{search}%"]
|
|
||||||
filters["description"] = ["like", f"%{search}%"]
|
|
||||||
|
|
||||||
# 1. 先获取总数(不分页)
|
# 1. 先获取所有数据(用于搜索过滤)
|
||||||
total_params = {
|
total_params = {
|
||||||
'filters': json.dumps(filters, ensure_ascii=False),
|
'filters': json.dumps(filters, ensure_ascii=False),
|
||||||
'limit_start': 0,
|
'limit_start': 0,
|
||||||
@ -69,39 +65,44 @@ async def get_tool_marketplace(
|
|||||||
headers = get_jingrow_cloud_api_headers()
|
headers = get_jingrow_cloud_api_headers()
|
||||||
total_response = requests.get(url, params=total_params, headers=headers, timeout=20)
|
total_response = requests.get(url, params=total_params, headers=headers, timeout=20)
|
||||||
|
|
||||||
total_count = 0
|
all_tools = []
|
||||||
if total_response.status_code == 200:
|
if total_response.status_code == 200:
|
||||||
total_data = total_response.json()
|
total_data = total_response.json()
|
||||||
total_count = len(total_data.get('message', []))
|
all_tools = total_data.get('message', [])
|
||||||
|
|
||||||
# 2. 获取分页数据
|
# 如果有搜索关键词,在Python中进行多字段过滤(OR逻辑)
|
||||||
params = {
|
if search:
|
||||||
'filters': json.dumps(filters, ensure_ascii=False)
|
search_lower = search.lower()
|
||||||
}
|
filtered_tools = []
|
||||||
|
for tool in all_tools:
|
||||||
|
if (search_lower in str(tool.get('name', '')).lower() or
|
||||||
|
search_lower in str(tool.get('tool_name', '')).lower() or
|
||||||
|
search_lower in str(tool.get('title', '')).lower() or
|
||||||
|
search_lower in str(tool.get('description', '')).lower()):
|
||||||
|
filtered_tools.append(tool)
|
||||||
|
all_tools = filtered_tools
|
||||||
|
|
||||||
# 排序参数
|
total_count = len(all_tools)
|
||||||
|
|
||||||
|
# 2. 排序
|
||||||
if sort_by:
|
if sort_by:
|
||||||
params['order_by'] = sort_by
|
sort_field, sort_order = sort_by.rsplit(' ', 1)
|
||||||
|
reverse = sort_order.lower() == 'desc'
|
||||||
|
try:
|
||||||
|
all_tools.sort(key=lambda x: x.get(sort_field, ''), reverse=reverse)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# 分页参数
|
# 3. 分页
|
||||||
limit_start = (page - 1) * page_size
|
limit_start = (page - 1) * page_size
|
||||||
params['limit_start'] = limit_start
|
tools = all_tools[limit_start:limit_start + page_size]
|
||||||
params['limit_page_length'] = page_size
|
|
||||||
|
|
||||||
response = requests.get(url, params=params, headers=headers, timeout=20)
|
return {
|
||||||
|
"items": tools,
|
||||||
if response.status_code == 200:
|
"total": total_count,
|
||||||
data = response.json()
|
"page": page,
|
||||||
tools = data.get('message', [])
|
"page_size": page_size
|
||||||
|
}
|
||||||
return {
|
|
||||||
"items": tools,
|
|
||||||
"total": total_count,
|
|
||||||
"page": page,
|
|
||||||
"page_size": page_size
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
raise HTTPException(status_code=response.status_code, detail="获取工具市场数据失败")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取工具市场数据失败: {e}", exc_info=True)
|
logger.error(f"获取工具市场数据失败: {e}", exc_info=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user