🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 批量移动文章(用我的方式来完成之前框架未做好功能) View: 搜索 '批量移动' 发现代码是加了注释的,先把注释去掉: > \themes\admin_simpleboot3\portal\admin_article\index.html <button class="btn btn-primary btn-sm js-articles-move" type="button">批量移动</button> 同时需要修改底部的脚本。作者之前可能是想先获取旧的栏目ID然后通过方法替换成新的ID。以下是用我的方法来实现,直接请求批量更新成为新的栏目ID就好。 //首先是实现弹窗的功能: ids = ids.join(','); url = '{:url("AdminArticle/move")}?ids='+ ids ; art.dialog.open(url, { // art.dialog.open("__ROOT__/index.php?g=portal&m=AdminArticle&a=move&old_term_id={$term.term_id|default=0}&ids=" + ids, { title: "批量移动", width: "400px", close: function(){ reloadPage(window); } > \themes\admin_simpleboot3\portal\admin_article\move.html 新建move.html:页面选择分类以及IDS,然后将数据提交到moveSave()处理 <include file="public@header"/> </head> <body> <div class="wrap"> <form method="post" class="js-ajax-form" action="{:url('AdminArticle/moveSave')}"> <div style="width: 350px"> <label style="width: 350px">分类:</label> <select name="term_id" class="form-control" style="width: 280px;float: left;"> {$terms_tree} </select> <input type="hidden" name="ids" value="{$ids}"> <button class="btn btn-primary js-ajax-submit" type="submit" style="float: left;">移动</button> </div> </form> </div> <script src="__STATIC__/js/admin.js"></script> </body> </html> > \app\portal\controller\AdminArticleController.php 控制器实现方法: /** * 批量移动弹出的窗口 * @return [view] */ public function move() { $param = $this->request->param(); $categoryId = $this->request->param('category', 0, 'intval'); //获取栏目 $portalCategoryModel = new PortalCategoryModel(); $categoryTree = $portalCategoryModel->adminCategoryTree($categoryId); $this->assign('terms_tree', $categoryTree); //获取IDS $ids = $this->request->param('ids'); $this->assign('ids', $ids); return $this->fetch(); } /** * 更新关系表的栏目ID * @return [json] */ public function moveSave(){ $term_id = $this->request->param('term_id'); $ids = $this->request->param('ids'); Db::name('portal_category_post')->where('post_id', 'in', $ids)->update(['category_id' => $term_id]); $this->success("移动成功!", ''); } 简单粗暴的实现功能,希望有大神指点,提升一下水平。谢谢观看!