From 4356de36b30e47794253bbbb633588854ff52479 Mon Sep 17 00:00:00 2001 From: augushong Date: Wed, 27 Sep 2023 16:32:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=8B=E6=9C=BA=E7=AB=AF?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/base/admin/controller/IndexBase.php | 37 ++++++ extend/base/admin/model/SystemMenuBase.php | 6 + extend/base/admin/view/common/_require.html | 1 + extend/base/admin/view/index/mobile.html | 31 +++++ extend/base/admin/view/index/mobile.js | 0 extend/base/admin/view/layout/default.html | 32 +++++ .../common/controller/AdminControllerBase.php | 9 ++ public/static/admin/css/public.css | 27 +++- public/static/common/js/app.js | 28 +++- public/static/plugs/ulthon-admin/table.js | 123 ++++++++++++++++++ .../static/plugs/ulthon-admin/ulthon-admin.js | 44 +++---- 11 files changed, 310 insertions(+), 28 deletions(-) create mode 100644 extend/base/admin/view/index/mobile.html create mode 100644 extend/base/admin/view/index/mobile.js create mode 100644 public/static/plugs/ulthon-admin/table.js diff --git a/extend/base/admin/controller/IndexBase.php b/extend/base/admin/controller/IndexBase.php index 29a7245..eb9352a 100644 --- a/extend/base/admin/controller/IndexBase.php +++ b/extend/base/admin/controller/IndexBase.php @@ -3,8 +3,10 @@ namespace base\admin\controller; use app\admin\model\SystemAdmin; +use app\admin\model\SystemMenu; use app\admin\model\SystemQuick; use app\common\controller\AdminController; +use app\common\service\MenuService; class IndexBase extends AdminController { @@ -116,4 +118,39 @@ class IndexBase extends AdminController return $this->fetch(); } + + public function mobile() + { + $pid = $this->request->param('pid', 0); + + $menuService = new MenuService(session('admin.id')); + + $home_info = $menuService->getHomeInfo(); + + $list_menu = SystemMenu::with(['children' => function ($query) { + $query->order('sort', 'desc')->order('id', 'asc'); + }])->where('pid', $pid)->order([ + 'sort' => 'desc', + 'id' => 'asc', + ]) + ->where('status', 1) + ->select(); + + $list_menu_pid = SystemMenu::group('pid')->column('pid'); + + foreach ($list_menu as $model_menu) { + foreach ($model_menu->children as $model_child) { + if (in_array($model_child->id, $list_menu_pid)) { + $model_child->href = __url('mobile', ['pid' => $model_child->pid]); + } else { + $model_child->href = __url($model_child->href); + } + } + } + + $this->assign('home_info', $home_info); + $this->assign('list_menu', $list_menu); + + return $this->fetch(); + } } diff --git a/extend/base/admin/model/SystemMenuBase.php b/extend/base/admin/model/SystemMenuBase.php index eda9cfa..08eee35 100644 --- a/extend/base/admin/model/SystemMenuBase.php +++ b/extend/base/admin/model/SystemMenuBase.php @@ -2,6 +2,7 @@ namespace base\admin\model; +use app\admin\model\SystemMenu; use app\common\constants\MenuConstant; use app\common\model\TimeModel; @@ -9,6 +10,11 @@ class SystemMenuBase extends TimeModel { protected $deleteTime = 'delete_time'; + public function children() + { + return $this->hasMany(SystemMenu::class, 'pid', 'id'); + } + public function getPidMenuList() { $list = $this->field('id,pid,title') diff --git a/extend/base/admin/view/common/_require.html b/extend/base/admin/view/common/_require.html index 9a82dd4..d487f0d 100644 --- a/extend/base/admin/view/common/_require.html +++ b/extend/base/admin/view/common/_require.html @@ -30,4 +30,5 @@ + \ No newline at end of file diff --git a/extend/base/admin/view/index/mobile.html b/extend/base/admin/view/index/mobile.html new file mode 100644 index 0000000..05a891b --- /dev/null +++ b/extend/base/admin/view/index/mobile.html @@ -0,0 +1,31 @@ + + +
+
基本
+ +
+ +{volist name='list_menu' id='vo'} +{notempty name='vo.children'} +
+
{$vo.title}
+
+ {volist name='vo.children' id='vovo'} + +
+
+
+
{$vovo.title}
+
+ {/volist} +
+
+{/notempty} +{/volist} \ No newline at end of file diff --git a/extend/base/admin/view/index/mobile.js b/extend/base/admin/view/index/mobile.js new file mode 100644 index 0000000..e69de29 diff --git a/extend/base/admin/view/layout/default.html b/extend/base/admin/view/layout/default.html index dc5858a..4ac7e6e 100644 --- a/extend/base/admin/view/layout/default.html +++ b/extend/base/admin/view/layout/default.html @@ -30,6 +30,38 @@ + {if $Request.isMobile } + +
+
+
+
+ + + +
+ {notempty name='session_admin'} +
+
+
+
+ +
+
+ {/notempty} +
+
+
+ {/if} + {__CONTENT__} diff --git a/extend/base/common/controller/AdminControllerBase.php b/extend/base/common/controller/AdminControllerBase.php index 9ce378e..1ae1757 100644 --- a/extend/base/common/controller/AdminControllerBase.php +++ b/extend/base/common/controller/AdminControllerBase.php @@ -366,6 +366,15 @@ class AdminControllerBase extends BaseController ]; View::assign($data); + + if ($this->request->isMobile()) { + $logo_info = [ + 'title' => sysconfig('site', 'logo_title'), + 'image' => sysconfig('site', 'logo_image'), + 'href' => __url('index/index'), + ]; + $this->assign('logo_info', $logo_info); + } } /** diff --git a/public/static/admin/css/public.css b/public/static/admin/css/public.css index 2a96c7e..fcc93a8 100644 --- a/public/static/admin/css/public.css +++ b/public/static/admin/css/public.css @@ -337,6 +337,11 @@ table样式 padding: 10px 0px; } +/* 手机端的表格头部操作 */ +.layuimini-container .main-tool { + padding: 15px; +} + /** 开关 */ @@ -560,4 +565,24 @@ table样式 } -@media (max-width: 768px) {} \ No newline at end of file +@media (max-width: 768px) { + .layuimini-form .layui-form-item { + padding-right: 0; + } + + .layuimini-form .layui-form-item .layui-form-label { + float: unset; + display: inline-block; + width: auto; + padding-left: 0; + padding-bottom: 0px; + } + + .layuimini-form .layui-form-item .layui-input-block { + margin-left: 0; + } + + .layuimini-form.multiple-columns .layui-form-item.full-line { + width: calc(100% - 0px); + } +} \ No newline at end of file diff --git a/public/static/common/js/app.js b/public/static/common/js/app.js index c6f29a8..95a0393 100644 --- a/public/static/common/js/app.js +++ b/public/static/common/js/app.js @@ -9,11 +9,11 @@ loading.show = function (count) { } if (loading.showCount == 0) { - loading.index = layer.load() + loading.index = layer.load(); } loading.showCount += count; -} +}; loading.hide = function (count) { @@ -37,4 +37,26 @@ loading.hide = function (count) { layer.close(loading.index); } -} \ No newline at end of file +}; + +const tools = {}; + +tools.checkMobile = function () { + var userAgentInfo = navigator.userAgent; + var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; + var mobile_flag = false; + //根据userAgent判断是否是手机 + for (var v = 0; v < mobileAgents.length; v++) { + if (userAgentInfo.indexOf(mobileAgents[v]) > 0) { + mobile_flag = true; + break; + } + } + var screen_width = window.screen.width; + var screen_height = window.screen.height; + //根据屏幕分辨率判断是否是手机 + if (screen_width < 600 && screen_height < 800) { + mobile_flag = true; + } + return mobile_flag; +}; \ No newline at end of file diff --git a/public/static/plugs/ulthon-admin/table.js b/public/static/plugs/ulthon-admin/table.js new file mode 100644 index 0000000..8b01f8c --- /dev/null +++ b/public/static/plugs/ulthon-admin/table.js @@ -0,0 +1,123 @@ +(function () { + var table = {}; + + table.render = function (options) { + console.log(options); + + var divId = options.elem + 'MB'; + $(options.elem).hide(); + + var dataContainer = $( + `
+
+
+
` + ).insertAfter(options.elem); + + // 暂时隐藏按钮 + // var containerToobar = dataContainer.find('.main-tool'); + // containerToobar.prepend(options.toolbar); + + var containerBox = dataContainer.find('.main-data'); + + loadPage(); + + var page = 1; + function loadPage() { + $.get(options.url, { page: page }, function (res) { + + res.data.forEach(row => { + + var rowItem = $.extend(true, {}, row); + + var baseElem = $(baseItem).appendTo(containerBox); + + if (options.cols[0][0].type == 'checkbox' || options.cols[0[0]].type == 'radio') { + $('') + .appendTo(baseElem.find('.header').find('.plus')); + + } + + rowItem.LAY_COL = $.extend(true, {}, options.cols[0][1]); + baseElem.find('.header').find('.main').find('span').html( + options.cols[0][1].templet(rowItem) + ); + + options.cols[0].forEach(LAY_COL => { + var dataItem = $.extend(true, {}, row); + dataItem.LAY_COL = $.extend(true, {}, LAY_COL); + if (LAY_COL.type == 'checkbox' || LAY_COL.type == 'radio') { + return; + } + + if (LAY_COL.templet == ua.table.tool) { + // 暂时隐藏按钮 + // baseElem.find('.footer .plus').html(dataItem.LAY_COL.templet(dataItem)); + return; + } + + if (LAY_COL.field == 'create_time') { + baseElem.find('.footer .main').html(dataItem.LAY_COL.templet(dataItem)); + return; + } + + var baseDataItemElem = $(baseDataItem).appendTo(baseElem.find('.body .main')); + baseDataItemElem.find('.item-title').html( + dataItem.LAY_COL.title + ':' + ); + baseDataItemElem.find('.item-value').html( + dataItem.LAY_COL.templet(dataItem) + ); + }); + + }); + + + }); + } + + var baseItem = ` +
+
+
+ # + +
+
+ +
+
+
+
+ + +
+
+ +
`; + var baseDataItem = ` +
+
+ +
+
+ +
+
`; + + }; + + table.on = function (event, callback) { + // console.log(event, callback); + }; + + window.uaTable = table; +})(); \ No newline at end of file diff --git a/public/static/plugs/ulthon-admin/ulthon-admin.js b/public/static/plugs/ulthon-admin/ulthon-admin.js index 501072e..dd521eb 100644 --- a/public/static/plugs/ulthon-admin/ulthon-admin.js +++ b/public/static/plugs/ulthon-admin/ulthon-admin.js @@ -19,7 +19,6 @@ var form = layui.form, layer = layui.layer, - table = layui.table, laydate = layui.laydate, upload = layui.upload, element = layui.element, @@ -37,6 +36,13 @@ upload_exts: '', }; + var table; + + if (tools.checkMobile()) { + table = window.uaTable; + } else { + table = layui.table; + } var extGroup = { // 图片扩展名数组 @@ -1445,23 +1451,7 @@ } }, checkMobile: function () { - var userAgentInfo = navigator.userAgent; - var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; - var mobile_flag = false; - //根据userAgent判断是否是手机 - for (var v = 0; v < mobileAgents.length; v++) { - if (userAgentInfo.indexOf(mobileAgents[v]) > 0) { - mobile_flag = true; - break; - } - } - var screen_width = window.screen.width; - var screen_height = window.screen.height; - //根据屏幕分辨率判断是否是手机 - if (screen_width < 600 && screen_height < 800) { - mobile_flag = true; - } - return mobile_flag; + return tools.checkMobile(); }, open: function (title, url, width, height, isResize, shadeClose = false) { isResize = isResize === undefined ? true : isResize; @@ -1591,12 +1581,18 @@ clientHeight = '100%'; } - admin.open( - $(this).attr('data-title'), - external ? url : admin.url(url), - clienWidth, - clientHeight, - ); + // 如果是手机版,则直接跳转 + if (admin.checkMobile()) { + location.href = external ? url : admin.url(url); + } else { + admin.open( + $(this).attr('data-title'), + external ? url : admin.url(url), + clienWidth, + clientHeight, + ); + } + }); // 放大图片