Update: (步骤备份)部门管理更新完成
This commit is contained in:
@@ -11,8 +11,6 @@ from applications.schemas import DeptSchema
|
||||
|
||||
bp = Blueprint('dept', __name__, url_prefix='/dept')
|
||||
|
||||
# Todo: 部门管理后端
|
||||
|
||||
@bp.get('/')
|
||||
@authorize("system:dept:main", log=True)
|
||||
def main():
|
||||
@@ -79,7 +77,7 @@ def save():
|
||||
)
|
||||
r = db.session.add(dept)
|
||||
db.session.commit()
|
||||
return success_api(msg="成功")
|
||||
return success_api(msg="添加部门成功")
|
||||
|
||||
|
||||
@bp.get('/edit')
|
||||
@@ -100,7 +98,7 @@ def enable():
|
||||
d = Dept.query.filter_by(id=id).update({"status": enable})
|
||||
if d:
|
||||
db.session.commit()
|
||||
return success_api(msg="启用成功")
|
||||
return success_api(msg="启用部门成功")
|
||||
return fail_api(msg="出错啦")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
@@ -115,7 +113,7 @@ def dis_enable():
|
||||
d = Dept.query.filter_by(id=id).update({"status": enable})
|
||||
if d:
|
||||
db.session.commit()
|
||||
return success_api(msg="禁用成功")
|
||||
return success_api(msg="禁用部门成功")
|
||||
return fail_api(msg="出错啦")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
@@ -137,20 +135,45 @@ def update():
|
||||
}
|
||||
d = Dept.query.filter_by(id=id).update(data)
|
||||
if not d:
|
||||
return fail_api(msg="更新失败")
|
||||
return fail_api(msg="更新部门失败")
|
||||
db.session.commit()
|
||||
return success_api(msg="更新成功")
|
||||
return success_api(msg="更新部门成功")
|
||||
|
||||
|
||||
@bp.delete('/remove/<int:_id>')
|
||||
@authorize("system:dept:remove", log=True)
|
||||
def remove(_id):
|
||||
d = Dept.query.filter_by(id=_id).delete()
|
||||
|
||||
if not d:
|
||||
return fail_api(msg="删除失败")
|
||||
res = User.query.filter_by(dept_id=_id).update({"dept_id": None})
|
||||
return fail_api(msg="删除部门失败")
|
||||
|
||||
User.query.filter_by(dept_id=_id).update({"dept_id": None})
|
||||
db.session.commit()
|
||||
if res:
|
||||
return success_api(msg="删除成功")
|
||||
else:
|
||||
return fail_api(msg="删除失败")
|
||||
|
||||
return success_api(msg="删除部门成功")
|
||||
|
||||
# 批量删除
|
||||
@bp.delete('/batchRemove')
|
||||
@authorize("system:dept:remove", log=True)
|
||||
def batch_remove():
|
||||
ids = request.form.getlist('ids[]')
|
||||
|
||||
if not ids:
|
||||
return fail_api(msg="未提供删除 ID")
|
||||
|
||||
for id in ids:
|
||||
|
||||
if not id.isdigit():
|
||||
db.session.rollback()
|
||||
return fail_api(msg="参数提供错误")
|
||||
|
||||
d = Dept.query.filter_by(id=id).delete()
|
||||
|
||||
if not d:
|
||||
return fail_api(msg="删除部门失败")
|
||||
|
||||
User.query.filter_by(dept_id=id).update({"dept_id": None})
|
||||
|
||||
db.session.commit()
|
||||
return success_api(msg="删除部门成功")
|
||||
@@ -167,6 +167,7 @@ def remove(id):
|
||||
|
||||
r = Power.query.filter_by(id=id).delete()
|
||||
db.session.commit()
|
||||
|
||||
if r:
|
||||
return success_api(msg="删除成功")
|
||||
else:
|
||||
|
||||
@@ -102,36 +102,66 @@
|
||||
{field: 'sort', title: '排序', width: 50},
|
||||
{title: '操作', templet: '#dept-bar', width: 150, align: 'center'}
|
||||
]
|
||||
]
|
||||
],
|
||||
done: function (res, curr, count, origin) {
|
||||
treeTable.expandAll('dept-table', true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
form.on('submit(dept-query)', function (data) {
|
||||
var keyword = data.field.deptName
|
||||
var $tds = $('#dept-table').next('.treeTable').find('.layui-table-body tbody tr td')
|
||||
var keyword = data.field.deptName;
|
||||
|
||||
if (!keyword) {
|
||||
$tds.css('background-color', 'transparent')
|
||||
layer.msg('请输入关键字', {icon: 5})
|
||||
return
|
||||
}
|
||||
var searchCount = 0
|
||||
$tds.each(function () {
|
||||
$(this).css('background-color', 'transparent')
|
||||
if ($(this).text().indexOf(keyword) >= 0) {
|
||||
$(this).css('background-color', 'rgba(250,230,160,0.5)')
|
||||
if (searchCount === 0) {
|
||||
$('body,html').stop(true)
|
||||
$('body,html').animate({scrollTop: $(this).offset().top - 150}, 500)
|
||||
}
|
||||
searchCount++
|
||||
}
|
||||
layer.msg('搜索内容为空', {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
})
|
||||
if (searchCount === 0) {
|
||||
layer.msg('没有匹配结果', {icon: 5})
|
||||
} else {
|
||||
treeTable.expandAll('#dept-table')
|
||||
return false;
|
||||
}
|
||||
return false
|
||||
|
||||
treeTable.checkAllNodes('dept-table', false);
|
||||
|
||||
var expandNotes = [];
|
||||
|
||||
treeTable.getNodesByFilter('dept-table', function (item) {
|
||||
if (item.dept_name.indexOf(keyword) !== -1) {
|
||||
treeTable.setRowChecked('dept-table', {index: item, checked: true});
|
||||
|
||||
// 遍历其全部父元素
|
||||
var parent_id = item.parent_id;
|
||||
|
||||
while (parent_id !== 0) {
|
||||
|
||||
if (!expandNotes.includes(parent_id)) {
|
||||
expandNotes.push(item.LAY_DATA_INDEX);
|
||||
}
|
||||
|
||||
item = treeTable.getNodeById('dept-table', item.parent_id).data;
|
||||
parent_id = item.parent_id;
|
||||
}
|
||||
|
||||
|
||||
if (!expandNotes.includes(parent_id)) {
|
||||
expandNotes.push(item.LAY_DATA_INDEX);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
|
||||
treeTable.expandAll('dept-table', false);
|
||||
|
||||
expandNotes.forEach(function (note_id) {
|
||||
treeTable.expandNode('dept-table', {
|
||||
index: note_id,
|
||||
expandFlag: true
|
||||
});
|
||||
})
|
||||
|
||||
return false;
|
||||
})
|
||||
|
||||
render()
|
||||
@@ -150,8 +180,7 @@
|
||||
} else if (obj.event === 'refresh') {
|
||||
window.refresh()
|
||||
} else if (obj.event === 'batchRemove') {
|
||||
{#window.batchRemove(obj)#}
|
||||
console.log(table.checkStatus(obj.config.id).data)
|
||||
window.batchRemove(obj)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -212,7 +241,7 @@
|
||||
layer.close(loading)
|
||||
if (result.success) {
|
||||
popup.success(result.msg, function () {
|
||||
obj.del()
|
||||
treeTable.removeNode('dept-table', obj.data.LAY_DATA_INDEX)
|
||||
})
|
||||
} else {
|
||||
popup.failure(result.msg)
|
||||
@@ -221,6 +250,49 @@
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
window.batchRemove = function (obj) {
|
||||
let data = treeTable.checkStatus(obj.config.id).data
|
||||
if (data.length === 0) {
|
||||
layer.msg('未选中数据', {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
})
|
||||
return false
|
||||
}
|
||||
var ids = []
|
||||
var hasCheck = treeTable.checkStatus('dept-table')
|
||||
var hasCheckData = hasCheck.data
|
||||
if (hasCheckData.length > 0) {
|
||||
$.each(hasCheckData, function (index, element) {
|
||||
ids.push(element.id)
|
||||
})
|
||||
}
|
||||
layer.confirm('确定要删除选中部门', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
layer.close(index)
|
||||
let loading = layer.load()
|
||||
$.ajax({
|
||||
url: MODULE_PATH + 'batchRemove',
|
||||
data: {ids: ids},
|
||||
dataType: 'json',
|
||||
type: 'delete',
|
||||
success: function (result) {
|
||||
layer.close(loading)
|
||||
if (result.success) {
|
||||
popup.success(result.msg, function () {
|
||||
treeTable.reload('dept-table');
|
||||
})
|
||||
} else {
|
||||
popup.failure(result.msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
@@ -248,8 +248,7 @@
|
||||
layer.close(loading)
|
||||
if (result.success) {
|
||||
popup.success(result.msg, function () {
|
||||
console.log(obj)
|
||||
obj.del()
|
||||
treeTable.removeNode('power-table', obj.data.LAY_DATA_INDEX)
|
||||
})
|
||||
} else {
|
||||
popup.failure(result.msg)
|
||||
|
||||
Reference in New Issue
Block a user