优化图片返回为url
This commit is contained in:
@@ -15,7 +15,7 @@ db_config = {
|
||||
"user": "postgres",
|
||||
"password": "postgres",
|
||||
"port": "5432",
|
||||
"host": "172.16.10.98"
|
||||
"host": "172.16.10.113"
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,8 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
'first_online_duration': first_online_duration,
|
||||
# 停机时间:关机时间 - 运行时间
|
||||
# 停机时长:关机时间 - 初次上线时间
|
||||
'img': f'data:image/png;base64,{machine_data.machine_tool_picture.decode("utf-8")}',
|
||||
# 'img': f'data:image/png;base64,{machine_data.machine_tool_picture.decode("utf-8")}',
|
||||
'img': f'https://xt.sf.jikimo.com/equipment/get_image/{machine_data.id}',
|
||||
'equipment_type': machine_data.category_id.name,
|
||||
})
|
||||
|
||||
@@ -843,3 +844,21 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
# 返回数据
|
||||
res['data'] = oee_data
|
||||
return json.dumps(res)
|
||||
|
||||
@http.route(['/equipment/get_image/<int:record_id>'], type='http', auth="public", website=True)
|
||||
def get_image(self, record_id, **kwargs):
|
||||
# 获取模型中的记录
|
||||
record = request.env['maintenance.equipment'].sudo().browse(record_id)
|
||||
|
||||
# 获取图片字段的数据
|
||||
image_data_base64 = record.machine_tool_picture
|
||||
|
||||
if image_data_base64:
|
||||
# 将Base64解码为二进制数据
|
||||
image_data_binary = base64.b64decode(image_data_base64)
|
||||
|
||||
# 返回图片数据,并设置正确的Content-Type
|
||||
return request.make_response(image_data_binary, headers=[('Content-Type', 'image/png')])
|
||||
else:
|
||||
# 如果没有图片数据,返回404
|
||||
return request.not_found()
|
||||
|
||||
Reference in New Issue
Block a user