24.1.编辑板块
cms/js/banners.js
$(function () { $(‘.edit-board-btn‘).click(function () { var self = $(this); var tr = self.parent().parent(); var name = tr.attr(‘data-name‘); var board_id = tr.attr(‘data-id‘); zlalert.alertOneInput({ ‘title‘: ‘编辑板块‘, ‘text‘: ‘请输入版块名称‘, ‘placeholder‘: name, ‘confirmCallback‘: function (inputValue) { zlajax.post({ ‘url‘: ‘/cms/uboards/‘, ‘data‘: { ‘board_id‘: board_id, ‘name‘: inputValue }, ‘success‘: function (data) { if (data[‘code‘] == 200) { window.location.reload(); } else { zlalert.alertInfo(data[‘message‘]) } } }); } }); }); });
24.2.删除板块
cms/js/banners.js
$(function () { $(‘.delete-board-btn‘).click(function (event) { event.preventDefault(); var self = $(this); var board_id = self.parent().parent().attr(‘data-id‘); zlalert.alertConfirm({ ‘title‘: ‘删除版块‘, ‘msg‘: ‘确认删除该版块吗?‘, ‘confirmCallback‘: function () { zlajax.post({ ‘url‘: ‘/cms/dboards/‘, ‘data‘: { ‘board_id‘: board_id }, ‘success‘: function (data) { if (data[‘code‘] == 200) { window.location.reload(); } else { zlalert.alertInfo(data[‘message‘]); } } }); } }) }) });
24.3.首页动态显示板块
(1)front/views.py
@bp.route(‘/‘) def index(): banners = BannerModel.query.order_by(BannerModel.priority.desc()).limit(4) boards = BoardModel.query.all() context = { ‘banners‘:banners, ‘boards‘:boards } return render_template(‘front/front_index.html‘,**context)
(2)front/index.py
<div class="sm-container"> <div style="margin-bottom: 10px;"> <button class="btn btn-warning btn-block">发布帖子</button> </div> <div class="list-group"> <a href="#" class="list-group-item active">所有板块</a> {% for board in boards %} <a href="#" class="list-group-item">{{ board.name }}</a> {% endfor %} </div> </div>