Update: (步骤备份)部门管理更新完成
This commit is contained in:
@@ -11,8 +11,6 @@ from applications.schemas import DeptSchema
|
|||||||
|
|
||||||
bp = Blueprint('dept', __name__, url_prefix='/dept')
|
bp = Blueprint('dept', __name__, url_prefix='/dept')
|
||||||
|
|
||||||
# Todo: 部门管理后端
|
|
||||||
|
|
||||||
@bp.get('/')
|
@bp.get('/')
|
||||||
@authorize("system:dept:main", log=True)
|
@authorize("system:dept:main", log=True)
|
||||||
def main():
|
def main():
|
||||||
@@ -79,7 +77,7 @@ def save():
|
|||||||
)
|
)
|
||||||
r = db.session.add(dept)
|
r = db.session.add(dept)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return success_api(msg="成功")
|
return success_api(msg="添加部门成功")
|
||||||
|
|
||||||
|
|
||||||
@bp.get('/edit')
|
@bp.get('/edit')
|
||||||
@@ -100,7 +98,7 @@ def enable():
|
|||||||
d = Dept.query.filter_by(id=id).update({"status": enable})
|
d = Dept.query.filter_by(id=id).update({"status": enable})
|
||||||
if d:
|
if d:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return success_api(msg="启用成功")
|
return success_api(msg="启用部门成功")
|
||||||
return fail_api(msg="出错啦")
|
return fail_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})
|
d = Dept.query.filter_by(id=id).update({"status": enable})
|
||||||
if d:
|
if d:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return success_api(msg="禁用成功")
|
return success_api(msg="禁用部门成功")
|
||||||
return fail_api(msg="出错啦")
|
return fail_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)
|
d = Dept.query.filter_by(id=id).update(data)
|
||||||
if not d:
|
if not d:
|
||||||
return fail_api(msg="更新失败")
|
return fail_api(msg="更新部门失败")
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return success_api(msg="更新成功")
|
return success_api(msg="更新部门成功")
|
||||||
|
|
||||||
|
|
||||||
@bp.delete('/remove/<int:_id>')
|
@bp.delete('/remove/<int:_id>')
|
||||||
@authorize("system:dept:remove", log=True)
|
@authorize("system:dept:remove", log=True)
|
||||||
def remove(_id):
|
def remove(_id):
|
||||||
d = Dept.query.filter_by(id=_id).delete()
|
d = Dept.query.filter_by(id=_id).delete()
|
||||||
|
|
||||||
if not d:
|
if not d:
|
||||||
return fail_api(msg="删除失败")
|
return fail_api(msg="删除部门失败")
|
||||||
res = User.query.filter_by(dept_id=_id).update({"dept_id": None})
|
|
||||||
|
User.query.filter_by(dept_id=_id).update({"dept_id": None})
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if res:
|
|
||||||
return success_api(msg="删除成功")
|
return success_api(msg="删除部门成功")
|
||||||
else:
|
|
||||||
return fail_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()
|
r = Power.query.filter_by(id=id).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
if r:
|
if r:
|
||||||
return success_api(msg="删除成功")
|
return success_api(msg="删除成功")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -102,36 +102,66 @@
|
|||||||
{field: 'sort', title: '排序', width: 50},
|
{field: 'sort', title: '排序', width: 50},
|
||||||
{title: '操作', templet: '#dept-bar', width: 150, align: 'center'}
|
{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) {
|
form.on('submit(dept-query)', function (data) {
|
||||||
var keyword = data.field.deptName
|
var keyword = data.field.deptName;
|
||||||
var $tds = $('#dept-table').next('.treeTable').find('.layui-table-body tbody tr td')
|
|
||||||
if (!keyword) {
|
if (!keyword) {
|
||||||
$tds.css('background-color', 'transparent')
|
layer.msg('搜索内容为空', {
|
||||||
layer.msg('请输入关键字', {icon: 5})
|
icon: 3,
|
||||||
return
|
time: 1000
|
||||||
|
})
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
var searchCount = 0
|
|
||||||
$tds.each(function () {
|
treeTable.checkAllNodes('dept-table', false);
|
||||||
$(this).css('background-color', 'transparent')
|
|
||||||
if ($(this).text().indexOf(keyword) >= 0) {
|
var expandNotes = [];
|
||||||
$(this).css('background-color', 'rgba(250,230,160,0.5)')
|
|
||||||
if (searchCount === 0) {
|
treeTable.getNodesByFilter('dept-table', function (item) {
|
||||||
$('body,html').stop(true)
|
if (item.dept_name.indexOf(keyword) !== -1) {
|
||||||
$('body,html').animate({scrollTop: $(this).offset().top - 150}, 500)
|
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;
|
||||||
}
|
}
|
||||||
searchCount++
|
|
||||||
|
|
||||||
|
if (!expandNotes.includes(parent_id)) {
|
||||||
|
expandNotes.push(item.LAY_DATA_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
if (searchCount === 0) {
|
|
||||||
layer.msg('没有匹配结果', {icon: 5})
|
treeTable.expandAll('dept-table', false);
|
||||||
} else {
|
|
||||||
treeTable.expandAll('#dept-table')
|
expandNotes.forEach(function (note_id) {
|
||||||
}
|
treeTable.expandNode('dept-table', {
|
||||||
return false
|
index: note_id,
|
||||||
|
expandFlag: true
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
return false;
|
||||||
})
|
})
|
||||||
|
|
||||||
render()
|
render()
|
||||||
@@ -150,8 +180,7 @@
|
|||||||
} else if (obj.event === 'refresh') {
|
} else if (obj.event === 'refresh') {
|
||||||
window.refresh()
|
window.refresh()
|
||||||
} else if (obj.event === 'batchRemove') {
|
} else if (obj.event === 'batchRemove') {
|
||||||
{#window.batchRemove(obj)#}
|
window.batchRemove(obj)
|
||||||
console.log(table.checkStatus(obj.config.id).data)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -212,7 +241,7 @@
|
|||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.msg, function () {
|
||||||
obj.del()
|
treeTable.removeNode('dept-table', obj.data.LAY_DATA_INDEX)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
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>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
@@ -248,8 +248,7 @@
|
|||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.msg, function () {
|
||||||
console.log(obj)
|
treeTable.removeNode('power-table', obj.data.LAY_DATA_INDEX)
|
||||||
obj.del()
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user