1 files added
7 files modified
| | |
| | | $this->route = $this->getRoute(); |
| | | //初始化redis |
| | | $this->redis = System_Service_Locator::getInstance()->get('redis'); |
| | | if(!$this->redis->exists('modules') ){ |
| | | //if(!$this->redis->exists('modules') ){ |
| | | $this->redis->set('modules', $this->getModules()); |
| | | } |
| | | //} |
| | | //是否渲染模板 |
| | | if(!empty($this->layout)){ |
| | | //根据角色权限访问 |
| | |
| | | $this->_TIMEOUT = 0; |
| | | $this->_DBNAME = null; |
| | | $this->_CTYPE = 1; |
| | | |
| | | $this->_AUTH = $config['auth']; |
| | | if (!isset($this->_REDIS)) { |
| | | $this->_REDIS = new Redis(); |
| | | $this->connect($this->_HOST, $this->_PORT, $this->_TIMEOUT, $this->_DBNAME, $this->_CTYPE); |
| | |
| | | default: |
| | | break; |
| | | } |
| | | $this->_REDIS->auth($this->_AUTH); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | return $this->_TRANSCATION->discard(); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | class Util{ |
| | | |
| | | public function selectItem($id){ |
| | | public function selectItem($id, $selected = 0){ |
| | | $module_service = new Service_Module(); |
| | | $modules = $module_service->getModuleList(); |
| | | return "<select class='form-control' id='".$id."' name='".$id."'>".self::getModules($modules)."</select>"; |
| | | return "<select class='form-control' id='".$id."' name='".$id."'>".self::getModules($modules, 0, 0, $selected)."</select>"; |
| | | } |
| | | |
| | | public function getModules($modules, $parent = 0, $deep = 0){ |
| | | public function getModules($modules, $parent = 0, $deep = 0, $selected){ |
| | | static $html = "<option value='0'>顶级栏目</option>"; |
| | | foreach ($modules as $key => $module) { |
| | | if($module['parent'] == $parent){ |
| | | if($deep == 0 || $parent == 0){ |
| | | $html .="<option value='".$module['_id']."'>".$module['name']."</option>"; |
| | | $html .="<option value='".$module['_id']."' ".($selected == $module['_id']? "seleced":'').">".$module['name']."</option>"; |
| | | } |
| | | else{ |
| | | $html .="<option value='".$module['_id']."'>".str_repeat('  ', $deep)."└".$module['name']."</option>"; |
| | | $html .="<option value='".$module['_id']."' ".($selected == $module['_id']? "seleced":'').">".str_repeat('  ', $deep)."└".$module['name']."</option>"; |
| | | } |
| | | $deep ++; |
| | | unset($modules[$key]); |
| | | self::getModules($modules, $module['_id'], $deep); |
| | | self::getModules($modules, $module['_id'], $deep, $selected); |
| | | } |
| | | |
| | | } |
| | |
| | | $redis->set('role_auth', $role_auth); |
| | | } |
| | | |
| | | /** |
| | | * 更新栏目 |
| | | * @return [type] [description] |
| | | */ |
| | | public function updateModules(){ |
| | | $this->module_service = new Service_Module(); |
| | | $modules= $this->module_service->getModuleList(array(), array(), array('level' => 1)); |
| | | //初始化redis |
| | | $redis = System_Service_Locator::getInstance()->get('redis'); |
| | | $redis->set('modules', $modules); |
| | | } |
| | | |
| | | } |
| | |
| | | <?php $s_html = '';?> |
| | | <?php if(isset($second_modules[$pid])):?> |
| | | <?php foreach ($second_modules[$pid] as $s_module):?> |
| | | <?php if(isset($is_active_class) && in_array($s_module['_id'], $current_role_auth)):?> |
| | | |
| | | <?php if($route['module'] == $s_module['module'] && $route['controller'] == $s_module['controller'] && $route['action'] == $s_module['action']):?> |
| | | <?php $is_active_class = 'active';?> |
| | | <?php $s_html .= " |
| | |
| | | <?php $s_html .= " |
| | | <li ><a href='/{$s_module['module']}/{$s_module['controller']}/{$s_module['action']}'><i class='fa fa-circle-o'></i> {$s_module['name']}</a></li>"; |
| | | ?> |
| | | <?php endif;?> |
| | | |
| | | <?php endif;?> |
| | | <?php endforeach;?> |
| | | <li class="<?php echo $is_active_class; ?> treeview"> |
| | |
| | | $data['action'] = $this->getRequest()->getPost('action'); |
| | | $data['parent'] = $this->getRequest()->getPost('parent'); |
| | | $data['name'] = $this->getRequest()->getPost('name'); |
| | | $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent'])); |
| | | if($parent_module){ |
| | | if($parent['level'] <= 2 ){ |
| | | $data['level'] = $parent['level'] + 1; |
| | | if($data['parent'] != 0){ |
| | | $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent'])); |
| | | if($parent_module){ |
| | | $data['is_module'] = false; |
| | | if($parent['level'] <= 2 ){ |
| | | $data['level'] = $parent['level'] + 1; |
| | | } |
| | | else{ |
| | | exit($this->showError('目前栏目只支持三级', 400, true)); |
| | | } |
| | | } |
| | | else{ |
| | | exit($this->showError('目前栏目只支持三级', 400, true)); |
| | | exit($this->showError('所属栏目不存在,请重新选择', 400, true)); |
| | | } |
| | | } |
| | | else{ |
| | | exit($this->showError('所属栏目不存在,请重新选择', 400, true)); |
| | | $data['level'] = 1; |
| | | $data['is_module'] = true; |
| | | } |
| | | if($this->module_service->add($data)){ |
| | | Util::updateModules(); |
| | | exit($this->showSuccess('栏目添加成功', true)); |
| | | } |
| | | else{ |
| | |
| | | public function EditAction($id){ |
| | | $module = $this->module_service->getModuleInfo(array('_id' => $id)); |
| | | if($module){ |
| | | $data['module'] = $this->getRequest()->getPost('module'); |
| | | $data['controller'] = $this->getRequest()->getPost('controller'); |
| | | $data['action'] = $this->getRequest()->getPost('action'); |
| | | $data['parent'] = $this->getRequest()->getPost('parent'); |
| | | $data['name'] = $this->getRequest()->getPost('name'); |
| | | $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent'])); |
| | | if($parent_module){ |
| | | if($parent['level'] <= 2 ){ |
| | | $data['level'] = $parent['level'] + 1; |
| | | if($this->getRequest()->isXmlHttpRequest()){ |
| | | $data['module'] = $this->getRequest()->getPost('module'); |
| | | $data['controller'] = $this->getRequest()->getPost('controller'); |
| | | $data['action'] = $this->getRequest()->getPost('action'); |
| | | $data['parent'] = $this->getRequest()->getPost('parent'); |
| | | $data['name'] = $this->getRequest()->getPost('name'); |
| | | if($data['parent']){ |
| | | $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent'])); |
| | | if($parent_module){ |
| | | if($parent['level'] <= 2 ){ |
| | | $data['level'] = $parent['level'] + 1; |
| | | } |
| | | else{ |
| | | exit($this->showError('目前栏目只支持三级', 400, true)); |
| | | } |
| | | } |
| | | else{ |
| | | exit($this->showError('所属栏目不存在,请重新选择', 400, true)); |
| | | } |
| | | } |
| | | else{ |
| | | exit($this->showError('目前栏目只支持三级', 400, true)); |
| | | $data['level'] = 1; |
| | | $data['is_module'] = true; |
| | | } |
| | | if($this->module_service->update($data, array('_id' => $module['_id']))){ |
| | | Util::updateModules(); |
| | | exit($this->showSuccess('栏目添加成功', true)); |
| | | } |
| | | else{ |
| | | exit($this->showError($this->module_service->error, 400, true)); |
| | | } |
| | | } |
| | | else{ |
| | | exit($this->showError('所属栏目不存在,请重新选择', 400, true)); |
| | | } |
| | | if($this->module_service->update($data)){ |
| | | exit($this->showSuccess('栏目添加成功', true)); |
| | | } |
| | | else{ |
| | | exit($this->showError($this->module_service->error, 400, true)); |
| | | } |
| | | $this->getView()->assign('module', $module); |
| | | } |
| | | else{ |
| | | $this->redirect('/error/show/type/no_data'); |
| | |
| | | <div class="box-body"> |
| | | <div class="form-group"> |
| | | <label >模块名</label> |
| | | <input type="text" class="form-control" id="module" name="module" placeholder="模块名"> |
| | | <input type="text" class="form-control" value="<?php echo $module['module']?>" id="module" name="module" placeholder="模块名"> |
| | | </div> |
| | | <div class="form-group"> |
| | | <label >控制器名</label> |
| | | <input type="text" class="form-control" id="controller" name="controller" placeholder="控制器名"> |
| | | <input type="text" class="form-control" value="<?php echo $module['controller']?>" id="controller" name="controller" placeholder="控制器名"> |
| | | </div> |
| | | <div class="form-group"> |
| | | <label >动作名</label> |
| | | <input type="text" class="form-control" id="action" name="action" placeholder="动作名"> |
| | | <input type="text" class="form-control" value="<?php echo $module['action']?>" id="action" name="action" placeholder="动作名"> |
| | | </div> |
| | | <div class="form-group"> |
| | | <label >栏目名称</label> |
| | | <input type="text" class="form-control" id="name" name="name" placeholder="栏目名称"> |
| | | <input type="text" class="form-control" value="<?php echo $module['name']?>" id="name" name="name" placeholder="栏目名称"> |
| | | </div> |
| | | <div class="form-group"> |
| | | <label >上级栏目</label> |
| | |
| | | </section> |
| | | <script src="/themes/AdminLTE/bootstrap/js/bootstrapValidator.min.js"></script> |
| | | <script type="text/javascript"> |
| | | var ID = '<?php echo $module['_id']?>'; |
| | | var SITE_URL = '<?php echo Yaf_Registry::get('var')['site_url']; ?>'; |
| | | </script> |
| | | <script src="/static/module/manager/js/add.js"></script> |
| | | <script src="/static/<?php echo $route['module']?>/<?php echo $route['controller']?>/js/<?php echo $route['action']?>.js"></script> |
| | |
| | | ;redis
|
| | | redis.host = 127.0.0.1
|
| | | redis.port = 6379
|
| | | redis.auth = yfs_moral_password2017
|
New file |
| | |
| | | var validator_config = { |
| | | message: '输入框内容不能为空', |
| | | feedbackIcons: { |
| | | valid: 'glyphicon glyphicon-ok', |
| | | invalid: 'glyphicon glyphicon-remove', |
| | | validating: 'glyphicon glyphicon-refresh' |
| | | }, |
| | | fields:{ |
| | | module:{ |
| | | validators:{ |
| | | callback: { |
| | | message: '模块名不能为空', |
| | | callback: function(value, validator){ |
| | | var parent = $('#parent').val(); |
| | | if(parent == 0){ |
| | | return true; |
| | | } |
| | | else{ |
| | | if(value != ""){ |
| | | return true; |
| | | } |
| | | else{ |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | } |
| | | }, |
| | | controller: { |
| | | validators: { |
| | | callback: { |
| | | message: '控制器名不能为空', |
| | | callback: function(value, validator){ |
| | | var parent = $('#parent').val(); |
| | | if(parent == 0){ |
| | | return true; |
| | | } |
| | | else{ |
| | | if(value != ""){ |
| | | return true; |
| | | } |
| | | else{ |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | action: { |
| | | validators: { |
| | | callback: { |
| | | message: '动作名称不能为空', |
| | | callback:function(value, validator){ |
| | | var parent = $('#parent').val(); |
| | | if(parent == 0){ |
| | | return true; |
| | | } |
| | | else{ |
| | | if(value != ""){ |
| | | return true; |
| | | } |
| | | else{ |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | name: { |
| | | validators: { |
| | | notEmpty:{ |
| | | message: '栏目名称不能为空', |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | $('#validateform').bootstrapValidator(validator_config).on('success.form.bv', function(e) { |
| | | e.preventDefault(); |
| | | |
| | | $("#dosubmit").attr("disabled","disabled"); |
| | | $.scojs_message('请稍候...', $.scojs_message.TYPE_WAIT); |
| | | $.ajax({ |
| | | type: "POST", |
| | | url: SITE_URL+"/module/manager/edit/id/"+ID, |
| | | data: $("#validateform").serialize(), |
| | | success:function(response){ |
| | | var dataObj=jQuery.parseJSON(response); |
| | | if(dataObj.code == 200) |
| | | { |
| | | $.scojs_message('操作成功,3秒后将返回列表页...', $.scojs_message.TYPE_OK); |
| | | setTimeout(function(){window.location.href = SITE_URL+'/module/manager/index';}, 1800); |
| | | }else |
| | | { |
| | | $.scojs_message(dataObj.content, $.scojs_message.TYPE_ERROR); |
| | | $("#dosubmit").removeAttr("disabled"); |
| | | } |
| | | }, |
| | | error: function (request, status, error) { |
| | | $.scojs_message(request.responseText, $.scojs_message.TYPE_ERROR); |
| | | $("#dosubmit").removeAttr("disabled"); |
| | | } |
| | | }); |
| | | |
| | | }).on('error.form.bv',function(e){ $.scojs_message('登录中遇到错误,请按照提示修改', $.scojs_message.TYPE_ERROR);$("#dosubmit").removeAttr("disabled");}); |