fix: 报告页面支持删除报告

This commit is contained in:
azhengzz 2021-10-17 21:31:31 +08:00
parent 9efbd45ca6
commit 299e6b6db1
3 changed files with 77 additions and 1 deletions

View File

@ -3225,6 +3225,7 @@ class Report(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), nullable=False, default='', server_default='')
result = db.Column(db.String(64), nullable=False, default='', server_default='')
status = db.Column(db.String(64), nullable=False, default=STATUS.NORMAL, server_default=STATUS.NORMAL)
# relationship
dispatcher_id = db.Column(db.Integer, db.ForeignKey('dispatcher.id'))
@ -3238,6 +3239,16 @@ class Report(db.Model):
db.session.commit()
return report
@classmethod
def update(cls, id, **kwargs):
report = cls.query.filter_by(id=int(id)).first()
if report is not None:
report.status = STATUS.DELETED
status = kwargs.get('status')
if status:
report.status = status
db.session.commit()
def update_result(self, result):
self.result = result
db.session.commit()

View File

@ -2030,7 +2030,7 @@ def drag_element():
@bp.route('/report/get', methods=['POST'])
def get_report_list_data():
reports = Report.query.all()
reports = Report.query.filter(Report.status == STATUS.NORMAL).all() # 只返回正常状态报告数据
ret = []
reports.sort(key=lambda report: report.id, reverse=True) # 按照id从大到小排序
for report in reports:
@ -2054,6 +2054,26 @@ def get_latest_reports():
})
@bp.route('/report/delete', methods=['POST'])
def delete_report():
# 参数校验
exist, form_id = get_form_from_request(request, 'id')
if not exist: return form_id
try:
Report.update(id=form_id, status=STATUS.DELETED)
except Exception as e:
exception_handle(current_app, e)
return jsonify({
'error_no': -1,
'error_msg': '错误信息 [' + repr(e) + ']',
})
else:
return jsonify({
'error_no': 0,
'error_msg': '',
})
@bp.route('/report_detail/tree', methods=['POST'])
def get_report_detail_tree():
exist, form_dispatcher_id = get_form_from_request(request, 'dispatcher_id')

View File

@ -76,6 +76,11 @@ function getReportListTable() {
title: '结果',
class: 'cursor-pointer',
formatter: resultFormatter,
},{
filed: 'action',
title: '操作',
formatter: actionFormatter,
events: 'actionEvents',
}
],
// 事件
@ -83,7 +88,14 @@ function getReportListTable() {
});
};
function actionFormatter(value, row, index, field) {
return '<button class="btn btn-outline-secondary btn-delete-row">删除</button>'
}
function onClickRow(row, $element, field){
if (field === 6){ // 如果是点击了操作列则不跳转
return;
}
window.location.href="/report/detail/" + row.id;
}
@ -113,5 +125,38 @@ function getReportListTable() {
}
}
window.actionEvents = {
'click .btn-delete-row': function (event, value, row, index) {
Swal.fire({
title: '确定删除 编号:' + row.id + ' 名称:' + row.name + ' 报告吗?',
text: "删除后将无法恢复!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: '确定',
cancelButtonColor: '#d33',
cancelButtonText: '取消',
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: 'POST',
url: '/ajax/report/delete',
data: {
id: row.id,
},
success: function (data, status, xhr) {
if (data.error_no === 0){
message("报告删除成功", "success");
$table_report_list.bootstrapTable('refresh');
}else{
message("报告删除失败: " + data.error_msg, "error");
}
},
});
}
});
},
};
return table;
}