更新地址 更新后端
This commit is contained in:
@@ -1306,6 +1306,46 @@ def search_product_categories():
|
||||
})
|
||||
|
||||
|
||||
@admin_api.route('/product-categories/export')
|
||||
@login_required
|
||||
def export_product_categories():
|
||||
_ensure_product_category_schema()
|
||||
_, _, denied = _ensure_product_category_access()
|
||||
if denied:
|
||||
return denied
|
||||
keyword = (request.args.get('keyword') or '').strip()
|
||||
params = {}
|
||||
if keyword:
|
||||
params['keyword'] = keyword
|
||||
|
||||
url = f"{backend_java_base_url}/api/admin/product-categories/export"
|
||||
try:
|
||||
resp = _get_backend_java_session().get(url, params=params, timeout=60)
|
||||
except requests.RequestException:
|
||||
return jsonify({'success': False, 'error': 'backend-java 服务不可用'}), 502
|
||||
if resp.status_code >= 400:
|
||||
try:
|
||||
data = resp.json()
|
||||
error = data.get('message') or data.get('error') or '导出失败'
|
||||
except ValueError:
|
||||
error = '导出失败'
|
||||
return jsonify({'success': False, 'error': error}), resp.status_code
|
||||
|
||||
headers = {}
|
||||
disposition = resp.headers.get('Content-Disposition')
|
||||
if disposition:
|
||||
headers['Content-Disposition'] = disposition
|
||||
return Response(
|
||||
resp.content,
|
||||
status=resp.status_code,
|
||||
headers=headers,
|
||||
content_type=resp.headers.get(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@admin_api.route('/product-category', methods=['POST'])
|
||||
@login_required
|
||||
def create_product_category():
|
||||
|
||||
@@ -60,7 +60,7 @@ backend_java_base_url, backend_java_base_url_source = _get_env(
|
||||
"java_api_base",
|
||||
"BACKEND_JAVA_BASE_URL",
|
||||
default="http://api.aishufu.top:18080/",
|
||||
# default="http://api.aishufu.top:18080/",
|
||||
# default="http://127.0.0.1:18080/",
|
||||
)
|
||||
backend_java_base_url = backend_java_base_url.rstrip("/")
|
||||
os.environ["OSS_ACCESS_KEY_ID"] = accessKeyId
|
||||
|
||||
@@ -3420,6 +3420,34 @@
|
||||
renderProductCategoryRows();
|
||||
}
|
||||
|
||||
function exportProductCategories() {
|
||||
var keyword = (document.getElementById('productCategoryKeyword').value || '').trim();
|
||||
var url = '/api/admin/product-categories/export' + (keyword ? ('?keyword=' + encodeURIComponent(keyword)) : '');
|
||||
fetch(url)
|
||||
.then(function (response) {
|
||||
var contentType = response.headers.get('content-type') || '';
|
||||
if (!response.ok || contentType.indexOf('application/json') >= 0) {
|
||||
return response.json().then(function (res) {
|
||||
throw new Error((res && (res.error || res.msg)) || '导出失败');
|
||||
}).catch(function (err) {
|
||||
throw err instanceof Error ? err : new Error('导出失败');
|
||||
});
|
||||
}
|
||||
return response.blob().then(function (blob) {
|
||||
return {
|
||||
blob: blob,
|
||||
filename: extractDownloadFilename(response.headers.get('content-disposition'), 'product-categories.xlsx')
|
||||
};
|
||||
});
|
||||
})
|
||||
.then(function (payload) {
|
||||
triggerBrowserDownload(payload.blob, payload.filename);
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err.message || '导出失败');
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('btnCancelProductCategoryEdit').onclick = function () {
|
||||
resetProductCategoryForm();
|
||||
};
|
||||
@@ -3435,6 +3463,10 @@
|
||||
loadProductCategories();
|
||||
};
|
||||
|
||||
document.getElementById('btnExportProductCategory').onclick = function () {
|
||||
exportProductCategories();
|
||||
};
|
||||
|
||||
document.getElementById('productCategoryKeyword').onkeydown = function (event) {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
@@ -3976,4 +4008,3 @@
|
||||
loadAdminMenus();
|
||||
});
|
||||
}) ();
|
||||
|
||||
|
||||
@@ -1426,6 +1426,7 @@
|
||||
</div>
|
||||
<button class="btn btn-sm" id="btnSearchProductCategory" type="button">搜索</button>
|
||||
<button class="btn btn-sm btn-secondary" id="btnClearProductCategorySearch" type="button">清空</button>
|
||||
<button class="btn btn-sm btn-secondary" id="btnExportProductCategory" type="button">导出</button>
|
||||
</div>
|
||||
</div>
|
||||
<table>
|
||||
|
||||
Reference in New Issue
Block a user