12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004 |
- <?php
- namespace Manage\Src;
- use Dever;
- class Menu
- {
- /**
- * fast
- *
- * @var array
- */
- private $fast = array();
- private $group = array();
- /**
- * data
- *
- * @var array
- */
- private $data = array();
- private $default = array
- (
- 'value' => -1,
- 'name' => '不选择',
- );
- private $search_default = array
- (
- 'value' => -1,
- 'name' => '菜单',
- );
- /**
- * __construct
- *
- * @return mixed
- */
- public function __construct()
- {
- }
- public function getManageMenu()
- {
- # 联动总数,默认到县区
- $level_total = Dever::input('level_total', 3);
- # 当前联动级别
- $level_num = Dever::input('level_num');
- # 一般为id
- $level_id = Dever::input('level_id');
- # 是否是搜索列表页
- $level_search = Dever::input('level_search');
- if ($level_search) {
- $default = $this->search_default;
- if ($level_num == 1) {
- $default['name'] = '分组选择';
- } elseif ($level_num == 2) {
- $default['name'] = '主菜单选择';
- } elseif ($level_num == 3) {
- $default['name'] = '子菜单选择';
- }
- } else {
- $default = $this->default;
- }
- if ($level_num == 1) {
- $data = Dever::db('manage/menu_group')->getAll();
- } elseif ($level_num == 2) {
- $where = array('group_id' => $level_id, 'menu_id' => -1);
- $data = Dever::db('manage/menu')->getAll($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $child = Dever::db('manage/menu')->total(array('menu_id' => $v['id']));
- if (!$child) {
- unset($data[$k]);
- }
- }
- }
-
- } elseif ($level_num == 3) {
- if ($level_id == -1) {
- Dever::alert('error');
- }
- $where = array('menu_id' => $level_id);
- $data = Dever::db('manage/menu')->getAll($where);
- }
- if (!$data) {
- Dever::alert('error');
- }
- if ($level_search || $level_num > 1) {
- array_unshift($data, $default);
- }
-
- $result['level_total'] = $level_total;
- $result['list'] = $data;
- return $result;
- }
- public function updateKey($id, $name, $data)
- {
- $key = Dever::param('key', $data);
- $menu = Dever::param('menu_id', $data);
- if (!$key || $key == 'null' || strstr($key, 'menu_')) {
- Dever::config('base')->hook = true;
- $prefix = '';
- if ($menu > 0) {
- $info = Dever::db('manage/menu')->one($menu);
- if ($info) {
- if (!$info['key']) {
- $info['key'] = $info_update['key'] = 'menu_' . $info['id'];
- $info_update['where_id'] = $info['id'];
- Dever::db('manage/menu')->update($info_update);
- }
- $prefix .= $info['key'] . '.';
- }
- }
- $update['key'] = $prefix . 'menu_' . $id;
- $update['where_id'] = $id;
- Dever::db('manage/menu')->update($update);
- }
- }
- public function test_api()
- {
- $data = Dever::db('manage/menu-in', array('where_id' => '2,1'));
- print_r(Dever::sql());die;
- }
- public function checkKey($id = 0)
- {
- $id = Dever::input('where_id');
- $key = Dever::input('update_key');
- if ($key && !$id) {
- $info = Dever::db('manage/menu')->key(array('where_key' => $key));
- if ($info) {
- Dever::alert('该菜单唯一key已被使用,请换一个吧');
- }
- } elseif ($id > 0) {
- $info = Dever::db('manage/menu')->keyId(array('where_key' => $key, 'where_id' => $id));
- if ($info) {
- Dever::alert('该菜单唯一key已被使用,请换一个吧');
- }
- }
- }
- # 菜单无限分类
- public function getCate()
- {
- # 联动总数
- $level_total = 1;
- # 当前联动级别
- $level_num = Dever::input('level_num', 1);
- # 一般为id
- $level_id = Dever::input('level_id');
- # 传入的参数
- $level_param = Dever::input('level_param');
- if ($level_param) {
- parse_str($level_param, $param);
- $where['id'] = $param['id'];
- }
- # 是否是搜索列表页
- $level_search = Dever::input('level_search');
- if ($level_search) {
- $default = $this->search_default;
- $default['name'] = $level_num . '级' . $default['name'];
- } else {
- $default = $this->default;
- }
- $data = array();
- # 三级联动
- if ($level_num == 1) {
- $where['menu_id'] = -1;
- } elseif($level_id > 0) {
- $where['menu_id'] = $level_id;
- }
- if (isset($where['menu_id'])) {
- $data = Dever::db('manage/menu')->getAll($where);
- }
- if ($data || $level_num == 1) {
- array_unshift($data, $default);
- }
- if (!$data) {
- Dever::alert('error');
- }
- $result['level_total'] = $level_total;
- $result['list'] = $data;
- return $result;
- }
- /**
- * menu 从数据库中得到所有菜单,如果为空,则从项目中读取一次
- *
- * @return array
- */
- private function get($auth = '', $state = 2)
- {
- $ms = Dever::input('ms');
- $param = array();
- if ($ms) {
- $param['option_key'] = $ms;
- }
- $menu = Dever::db('manage/menu')->main($param);
- if ($menu) {
- $this->fast = array();
- $child = Dever::db('manage/menu')->child();
- if ($auth && is_array($auth)) {
- //$auth = implode(',', $auth);
- }
-
- $console = false;
- if (layadmin()) {
- $console = true;
- }
- foreach ($menu as $k => $v) {
- if (!$console && $k == 'console') {
- unset($menu[$k]);
- continue;
- }
- if ($auth && !in_array($v['id'], $auth)) {
- //unset($menu[$k]);
- //continue;
- }
- /*
- if ($auth && strpos($auth . '.', $k . '.') === false) {
- unset($menu[$k]);
- continue;
- }
- */
- $path = Dever::load('manage/project.path', $v['key']);
- if ($path && strpos($path, 'http://') === 0) {
- unset($menu[$k]);
- continue;
- }
- $menu[$k] = $this->getChild($menu[$k], $child, $v, $auth);
- if (!isset($menu[$k]['child'])) {
- unset($menu[$k]);
- } else {
- $this->group[$menu[$k]['group_id']] = $menu[$k]['group_id'];
- }
- }
- } elseif (!$ms && $state == 2) {
- # 数据为空,读取一次,后续就得手动读取了
- $this->load();
- $menu = $this->get($auth, 1);
- }
- return $menu;
- }
- public function getChild($menu, $child, $v, $auth, $state = false)
- {
- if (isset($child[$v['id']])) {
- foreach ($child[$v['id']] as $i => $j) {
- //if ($state == false && $auth && $i && strpos($auth . '.', $i) === false) {
- if ($state == false && $auth && !in_array($j['id'], $auth)) {
- //unset($child[$parent][$i]);
- //continue;
- } else {
- if ($j['link'] && $i != 'console.index') {
- $j['link'] = Dever::url($j['link'] . '&menu_id=' . $j['id']);
- }
- $menu['child'][$i] = $j;
- $menu['child'][$i] = $this->getChild($menu['child'][$i], $child, $j, $auth, true);
- $menu['child'][$i]['func'] = Dever::db('manage/menu_func')->select(array('menu_id' => $menu['child'][$i]['id']));
- if ($j['fast'] == 1) {
- $this->fast[$i] = $j;
- }
- }
- }
- }
- return $menu;
- }
- /**
- * 清空所有菜单
- *
- * @return array
- */
- public function delete()
- {
- $data = $menu = Dever::db('manage/menu')->all;
- foreach ($data as $k => $v) {
- }
- Dever::out('yes');
- }
- /**
- * 更新菜单
- *
- * @return array
- */
- public function update_api()
- {
- $this->load();
- Dever::out('yes');
- }
- private function getKey($k, $i, $j)
- {
- if (is_string($j['menu'])) {
- $m = $j['menu'];
- } else {
- $m = $k;
- }
- if ($m == $k) {
- $key = $k . '.' . $i;
- } else {
- $key = $m . '.' . $k . '.' . $i;
- }
- return array($m, $key);
- }
- /**
- * 载入从项目中定义好的菜单
- *
- * @return array
- */
- public function load()
- {
- $project = array();
- $project['console'] = array
- (
- 'name' => '主页',
- 'lang' => '主页',
- 'path' => 'console',
- 'icon' => 'layui-icon-home',
- 'order' => 10000,
- 'child' => array
- (
- 'index' => Array
- (
- 'key' => 'console.index',
- 'name' => '控制台',
- 'link' => Dever::url('console'),
- 'order' => 10,
- 'fast' => 2,
- )
- )
- );
- $project += Dever::load('manage/project.get');
- $database = Dever::load('manage/database');
- $top = Dever::load('manage/top');
- $auth = Dever::load('manage/auth');
- $child = array();
- foreach ($project as $k => $v) {
- $project[$k]['group_id'] = 1;
- if (!isset($v['url'])) {
- continue;
- }
- if (!isset($v['lang'])) {
- continue;
- }
- if (isset($v['group_name'])) {
- $group = Dever::db('manage/menu_group')->find(array('name' => $v['group_name']));
- if (!$group) {
- $project[$k]['group_id'] = Dever::db('manage/menu_group')->insert(array('name' => $v['group_name'], 'reorder' => $v['group_order']));
- } else {
- $project[$k]['group_id'] = $group['id'];
- }
- }
- if (isset($v['base']) && isset($v['rel'])) {
- $v['path'] = DEVER_INCLUDE_PATH . $v['rel'];
- }
- $project[$k]['name'] = $v['lang'];
- $config = $database->config($k, $v['path']);
- if ($config) {
- foreach ($config as $i => $j) {
- //$this->sync('top', 'update', $j, $k, $i, $v, $top);
- $this->sync('auth', 'update_action', $j, $k, $i, $v, $auth);
- if (!isset($j['menu'])) {
- $j['menu'] = true;
- }
- if (isset($j['manage']) && $j['menu'] != false) {
- list($m, $key) = $this->getKey($k, $i, $j);
- $project[$m]['child'][$i]['key'] = $key;
- $project[$m]['child'][$i]['name'] = $j['lang'];
- $project[$m]['child'][$i]['link'] = 'project/database/list?project=' . $k . '&table=' . $i . '&menu=' . $m . '&search_option_state=1';
- $project[$m]['child'][$i]['order'] = isset($j['order']) ? $j['order'] : 1;
- $project[$m]['child'][$i]['fast'] = isset($j['fast']) ? $j['fast'] : 2;
- if (isset($j['parent'])) {
- $parent = $j['parent'];
- $parent['menu'] = $parent['key'];
- list($parent_menu, $parent_key) = $this->getKey($k, $parent['name'], $parent);
- $project[$m]['child'][$i]['parent'] = array();
- $project[$m]['child'][$i]['parent']['key'] = $parent_key;
- $project[$m]['child'][$i]['parent']['name'] = $parent['name'];
- $project[$m]['child'][$i]['parent']['link'] = '';
- $project[$m]['child'][$i]['parent']['order'] = isset($parent['order']) ? $parent['order'] : 1;
- $project[$m]['child'][$i]['parent']['fast'] = isset($parent['fast']) ? $parent['fast'] : 2;
- }
- }
- }
- } else {
- unset($project[$k]);
- }
- }
- //print_r($project);die;
- # 将所有数据都记录到菜单中
- if ($project) {
- $menu = Dever::config('base', 'manage')->menu;
- if ($menu && layadmin()) {
- $old = $project;
- $project = array();
- if (!isset($menu['console']) && isset($old['console'])) {
- $project['console'] = $old['console'];
- }
- foreach ($menu as $k => $v) {
- $project[$k] = $v;
- $project[$k]['key'] = $v['project'];
- $project[$k]['lang'] = $v['name'];
- $project[$k]['path'] = $k;
- $project[$k]['icon'] = $old[$v['icon']]['icon'];
- $child = explode(',', $v['project']);
- foreach ($child as $k1 => $v1) {
- $project[$k]['child'][$v1] = $old[$v1];
- $project[$k]['child'][$v1]['key'] = $v1;
- $project[$k]['child'][$v1]['link'] = $old[$v1]['url'];
- $project[$k]['child'][$v1]['fast'] = 2;
- }
- }
- if (!isset($project['manage']) && isset($old['manage'])) {
- $project['manage'] = $old['manage'];
- }
- }
- foreach ($project as $k => $v) {
- if (!isset($v['child'])) {
- unset($project[$k]);
- continue;
- }
- if ($v && isset($v['lang']) && $v['child']) {
- $id = $this->updateMenu($k, $v['lang'], $v['path'] . ':' . $v['name'], -1, $v['order'], 2, (isset($v['icon']) ? $v['icon'] : ''), $v['group_id']);
- if ($id > 0) {
- foreach ($v['child'] as $i => $j) {
- if (isset($j['child']) && $j['child']) {
- $parent = $this->updateMenu($j['key'], $j['name'], $j['link'], $id, $j['order'], $j['fast'], '', $v['group_id']);
- foreach ($j['child'] as $i1 => $j1) {
- $this->updateMenu($j1['key'], $j1['name'], $j1['link'], $parent, $j1['order'], $j1['fast'], '', $v['group_id']);
- }
- } elseif (isset($j['parent']) && $j['parent']) {
- $p = $j['parent'];
- $parent = $this->updateMenu($p['key'], $p['name'], $p['link'], $id, $p['order'], $p['fast'], '', $v['group_id']);
- if ($parent) {
- $this->updateMenu($j['key'], $j['name'], $j['link'], $parent, $j['order'], $j['fast'], '', $v['group_id']);
- }
- } else {
- $this->updateMenu($j['key'], $j['name'], $j['link'], $id, $j['order'], $j['fast'], '', $v['group_id']);
- }
- }
- }
- }
- }
- }
- return $project;
- }
- private function sync($key, $update, $data, $k, $i, $project, $model)
- {
- if (isset($data[$key]) && is_array($data[$key])) {
- # 加入头部左侧控制权限的菜单
- if ($key == 'top') {
- $data[$key]['name'] = $project['lang'] . '-' . $data[$key]['name'];
- }
- if (isset($data[$key]['type']) && $data[$key]['type'] == 2) {
- $id = false;
- } else {
- $id = $model->{$update}($data[$key]);
- }
- if (strpos($data[$key]['data'], '/')) {
- $parent = Dever::load($data[$key]['data']);
- } else {
- $parent = Dever::load($k . '/' . $i . '-' . $data[$key]['data']);
- }
- //print_r($data[$key]);die;
- if ($parent) {
- if (!$id) {
- foreach ($parent as $k => $v) {
- if (isset($v['child']) && $v['child']) {
- $param = array();
- $param['project'] = $project['name'];
- $param['project_name'] = $project['lang'];
- $param['name'] = $v[$data[$key]['col']];
- if (isset($data[$key]['type']) && $data[$key]['type'] && isset($v[$data[$key]['type']])) {
- $type = $v[$data[$key]['type']];
- $param['key'] = $data[$key]['key'] . '-' . $type . '_' . $v['id'];
- } else {
- $param['key'] = $data[$key]['key'] . '_' . $v['id'];
- }
- $param[$key] = -1;
- $param['value'] = $v['id'];
- $pid = $model->{$update}($param);
- foreach ($v['child'] as $k1 => $v1) {
- $param = array();
- $param['project'] = $project['name'];
- $param['project_name'] = $project['lang'];
- if (isset($data[$key]['type']) && $data[$key]['type'] && isset($v1[$data[$key]['type']])) {
- $type = $v1[$data[$key]['type']];
- $param['key'] = $data[$key]['key'] . '-' . $type . '_' . $v1['id'];
- } else {
- $param['key'] = $data[$key]['key'] . '_' . $v1['id'];
- }
- $param['name'] = $v1[$data[$key]['col']];
- $param[$key] = $pid;
- $param['value'] = $v1['id'];
- $model->{$update}($param);
- }
- }
- }
- } elseif ($id) {
- foreach ($parent as $v) {
- $param = array();
- if ($key == 'auth') {
- $param['project'] = $project['name'];
- $param['project_name'] = $project['lang'];
- }
- if (isset($data[$key]['type']) && $data[$key]['type'] && isset($v[$data[$key]['type']])) {
- $type = $v[$data[$key]['type']];
- $param['key'] = $data[$key]['key'] . '-' . $type . '_' . $v['id'];
- } else {
- if (!isset($v['id'])) {
- print_r($parent);die;
- }
- $param['key'] = $data[$key]['key'] . '_' . $v['id'];
- }
- $param['name'] = $v[$data[$key]['col']];
- $param[$key] = $id;
- $param['value'] = $v['id'];
- $model->{$update}($param);
- }
- }
- }
- }
- }
- /**
- * 更新菜单到数据库
- *
- * @return array
- */
- public function updateMenu($key, $name, $link, $menu, $order, $fast, $icon = '', $group_id = 1)
- {
- if (!$key) {
- return;
- }
- //$where['name'] = $name;
- //$where['menu_id'] = $menu;
- $where['key'] = $key;
- $info = Dever::db('manage/menu')->one($where);
- if (!$info) {
- $update['add_key'] = $key;
- $update['add_name'] = $name;
- $update['add_link'] = $link;
- $update['add_menu_id'] = $menu;
- $update['add_menu'] = $menu;
- $update['add_reorder'] = $order;
- $update['add_fast'] = $fast;
- $update['add_state'] = 1;
- $update['add_type'] = 2;
- if ($icon) {
- $update['add_icon'] = $icon;
- }
- if ($group_id) {
- $update['group_id'] = $group_id;
- }
- $info['id'] = Dever::db('manage/menu')->insert($update);
- }
- /*
- elseif($link != $info['link'])
- {
- $update['set_link'] = $link;
- $id = $update['where_id'] = $info['id'];
- Dever::load('manage/menu-update', $update);
- }
- */
- return $info['id'];
- }
- private function getGroup()
- {
- $company_id = Dever::load('manage/company')->get();
- $where = array();
- if ($company_id) {
- $company = Dever::db('manage/company')->find($company_id);
- if ($company && $company['is_project'] == 2 && $company['project']) {
- $where['ids'] = $company['project'];
- }
- }
- if ($this->group) {
- $group = Dever::db('manage/menu_group')->getIds($where);
- foreach ($group as $k => $v) {
- if (!isset($this->group[$k])) {
- unset($group[$k]);
- }
- }
- return $group;
- } else {
- $this->group = Dever::db('manage/menu_group')->getIds($where);
- }
- return $this->group;
- }
- /**
- * menu 生成顶部菜单
- *
- * @return array
- */
- public function getTop()
- {
- Dever::load('manage/menu.getHtml');
- $data = $this->getGroup();
- $html = '<li class="layui-nav-item layadmin-flexible" lay-unselect>
- <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">
- <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
- </a>
- </li><li class="layui-nav-item" lay-unselect style="display:">
- <a href="javascript:;" layadmin-event="back" title="上一页">
- <i class="layui-icon layui-icon-return"></i>
- </a>
- </li><li class="layui-nav-item" lay-unselect>
- <a href="javascript:;" layadmin-event="refresh" title="刷新">
- <i class="layui-icon layui-icon-refresh-3"></i>
- </a>
- </li></ul><ul class="layui-nav nav layui-layout-left" style="margin-left: 161px;">';
- $cur_group = Dever::input('group');
- if (layadmin()) {
- $i = 0;
- foreach ($data as $k => $v) {
- $v['icon'] = $v['icon'] ? "layui-icon " . $v['icon'] : "";
- $cur = '';
- if ($cur_group) {
- if ($v['id'] == $cur_group) {
- $cur = 'layui-this';
- }
- } elseif ($i == 0) {
- $cur = 'layui-this';
- }
- $html .= '<li class="layui-nav-item '.$cur.'">';
- $link = 'href="javascript:;" onclick="menuGroup('.$v['id'].', $(this))"';
- $html .= '<a '.$link.' lay-tipss="'.$v['name'].'" id="menu_group_'.$v['id'].'">';
- $html .= '<i class="'.$v['icon'].'"></i><cite style="margin-left:5px;">'.$v['name'].'</cite></a>';
- if ($cur && !$cur_group) {
- $html .= '<script>$(document).ready(function(){$("#menu_group_'.$v['id'].'").click()});</script>';
- }
- $html .= '</li>';
- $i++;
- }
- $html .= '';
- }
- return $html;
- }
- /**
- * menu 生成左侧的菜单 此处应加上权限来显示是否管理员有该菜单的权限
- *
- * @return array
- */
- public function getHtml($state = false)
- {
- $data = $this->all();
- $html = '';
- $menu = Dever::input('parent_menu');
- if (layadmin()) {
- foreach ($data as $k => $v) {
- $v['icon'] = $v['icon'] ? "layui-icon " . $v['icon'] : "layui-icon layui-icon-home";
- $style = 'style="display:none;"';
- $nav = '';
- if ($menu && $menu == $v['key']) {
- $style = '';
- $nav = 'layui-nav-itemed';
- }
- $html .= '<li data-name="'.$v['key'].'" class="layui-nav-item menu_group menu_group_'.$v['group_id'].' '.$nav.'" '.$style.'>';
- if (isset($v['child']) && $v['child']) {
- $link = 'href="javascript:;"';
- } else {
- $link = 'lay-href="'.$v['link'].'"';
- }
- $html .= '<a '.$link.' lay-tips="'.$v['name'].'" lay-direction="2">';
- $html .= '<i class="'.$v['icon'].'"></i><cite>'.$v['name'].'</cite></a>';
- $html .= $this->getHtmlChild($v);
- $html .= '</li>';
- }
- $html .= '';
- }
- return $html;
- }
- public function getHtmlChild($v)
- {
- $html = '';
- $menu = Dever::input('menu');
- if (isset($v['child']) && $v['child']) {
- $html .= '<dl class="layui-nav-child">';
- foreach ($v['child'] as $k1 => $v1) {
- $active = '';
- if ($menu && $menu == $v1['key']) {
- $active = 'layui-this';
- } elseif ($v1['key'] == 'console.index') {
- $active = 'layui-this';
- }
- $html .= '<dd data-name="'.$v1['key'].'" class="'.$active.'">';
- if (isset($v1['child']) && $v1['child']) {
- $html .= '<a href="javascript:;">'.$v1['name'].'</a><dl class="layui-nav-child">';
- foreach ($v1['child'] as $k2 => $v2) {
- $html .= '<dd data-name="'.$v2['key'].'"><a lay-href="'.$v2['link'].'">'.$v2['name'].'</a></dd>';
- }
- $html .= '</dl>';
- } else {
- $html .= '<a lay-href="'.$v1['link'].'">'.$v1['name'].'</a>';
- }
- $html .= '</dd>';
- }
- $html .= '</dl>';
- }
- return $html;
- }
- /**
- * menu 生成左侧的菜单 此处应加上权限来显示是否管理员有该菜单的权限
- *
- * @return array
- */
- public function all($state = false)
- {
- $data = $this->left($state);
- if (!$data) {
- Dever::location(Dever::url('home', 'manage'));
- }
- return $data;
- }
- /**
- * menu 生成左侧的菜单 此处应加上权限来显示是否管理员有该菜单的权限
- *
- * @return array
- */
- public function left($state = false)
- {
- if ($this->data) {
- return $this->data;
- }
- $auth = '';
- if ($state == false) {
- # 需要验证权限
- $auth = Dever::load('manage/auth.admin');
- }
- //$auth = 'manage_admin';
- $menu = $this->get($auth);
- $this->data = $menu;
- return $menu;
- /*
- //$auth = 'manage_admin,image_thumb';
- foreach($project as $k => $v)
- {
- if($auth && strpos($auth, $k . '_') === false)
- {
- unset($project[$k]);
- continue;
- }
- if($auth && strpos($auth, $k . '_' . $i) === false)
- {
- //unset($project[$k]['child'][$i]);
- continue;
- }
- if(!isset($v['child']))
- {
- unset($project[$k]);
- continue;
- }
- if($k == 'manage')
- {
- $project[$k]['child']['manage_project'] = array
- (
- 'name' => '管理菜单设置',
- 'link' => Dever::load('manage/menu.link#project'),
- 'order' => 1,
- );
- $project[$k]['child']['manage_log'] = array
- (
- 'name' => '管理操作日志',
- 'link' => Dever::load('manage/menu.link#log'),
- 'order' => 1,
- );
- //print_r($project[$k]);die;
- }
- //array_multisort($v['child_order'], SORT_DESC, $v['child']);
- $order = array();
- foreach($project[$k]['child'] as $i => $j)
- {
- $order[] = $j['order'];
- }
- array_multisort($order, SORT_DESC, $project[$k]['child']);
- }
- //此处加缓存吧,不过要针对用户,加到session中也可以
- return $project;
- */
- }
- /**
- * menu 获取快捷管理菜单
- *
- * @return array
- */
- public function fast()
- {
- $this->left();
- return $this->fast;
- }
- /**
- * menu 对一些固定的菜单,生成其链接
- *
- * @return array
- */
- public function link()
- {
- $link = Dever::input('link');
- return array
- (
- 'project' => Dever::url('project/list?menu=manage&table=manage_project'),
- 'log' => Dever::url('log/list?menu=manage&table=manage_log'),
- 'logout' => Dever::url('auth.quit'),
- 'index' => Dever::url('home'),
- 'console' => $link ? urldecode($link) : Dever::url('console'),
- );
- }
- /**
- * getLink
- *
- * @return array
- */
- public function getLink($param)
- {
- $extend = '';
- if (is_array($param)) {
- $key = $param[0];
- $type = $param[1];
- $extend = isset($param[2]) ? $param[2] : '';
- } else {
- $key = $param;
- $type = 'list';
- }
- $info = Dever::load('manage/menu-one', array('option_key' => $key));
- $link = '';
- if ($info) {
- $link = $info['link'] . '&menu_id=' . $info['id'] . '&' . $extend;
- if ($type != 'list') {
- $link = str_replace('project/database/list', 'project/database/' . $type, $link);
- }
- }
- $link = Dever::url($link);
- return $link;
- }
- /**
- * database
- *
- * @return array
- */
- public function database()
- {
- $this->config();
- $result = array();
- $method = $this->project . '/' . $this->table . '-list';
- $data = Dever::load($method);
- //print_r($data);die;
- //print_r(Helper::page("current"));die;
- if ($data) {
- foreach ($data as $k => $v) {
- $result[$k] = '<tr>';
- foreach ($this->config['manage']['list'] as $ki => $vi) {
- if (isset($v[$vi['col']]) && $v[$vi['col']]) {
- if (isset($vi['value'])) {
- $eval = '$value = ' . str_replace('{col}', $v[$vi['col']], $vi['value']) . ';';
- eval($eval);
- if ($value) {
- $v[$vi['col']] = $value;
- }
- } elseif (isset($vi['modal'])) {
- $v[$vi['col']] = '<a href="#" data-toggle="modal" data-target="#DEVER_modal" onclick="$(\'#DEVER_modal_body\').html($(this).next().html())">' . $vi['modal'] . '</a><div style="display:none;">' . $v[$vi['col']] . '</div>';
- } elseif (isset($vi['option'])) {
- $v[$vi['col']] = $vi['option'][$v[$vi['col']]];
- }
- $result[$k] .= '<td>' . $v[$vi['col']] . '</td>';
- } elseif ($vi['col'] == 'manage' && isset($vi['value']) && is_array($vi['value'])) {
- $result[$k] .= '<td>';
- foreach ($vi['value'] as $kj => $vj) {
- $result[$k] .= '<a href="' . $this->url($kj, $v['id']) . '" class="oper_' . $kj . '">' . $vj . '</a>';
- }
- $result[$k] .= '</td>';
- }
- }
- $result[$k] .= '</tr>';
- }
- }
- return $result;
- }
- }
|