Procházet zdrojové kódy

新增自动计算__CDN__和cdnurl的值
修复在二级目录下和非伪静态下的脚本加载错误
移除subdomain参数

Karson před 8 roky
rodič
revize
4abf8abe98

+ 3 - 2
application/admin/library/Auth.php

@@ -214,12 +214,13 @@ class Auth extends \fast\Auth
         $colorArr = ['red', 'green', 'yellow', 'blue', 'teal', 'orange', 'purple'];
         $colorNums = count($colorArr);
         $badgeList = [];
+        $module = request()->module();
         // 生成菜单的badge
         foreach ($params as $k => $v)
         {
             if (stripos($k, '/') === false)
             {
-                $url = '/admin/' . $k;
+                $url = '/' . $module . '/' . $k;
             }
             else
             {
@@ -249,7 +250,7 @@ class Auth extends \fast\Auth
         $userRule = $this->getRuleList();
 
         $select_id = 0;
-        $dashboard = rtrim(url('dashboard/'), '/');
+        $dashboard = '/' . $module . '/dashboard';
         // 必须将结果集转换为数组
         $ruleList = collection(model('AuthRule')->where('ismenu', 1)->order('weigh', 'desc')->cache("__menu__")->select())->toArray();
         foreach ($ruleList as $k => &$v)

+ 3 - 3
application/admin/view/common/header.html

@@ -61,13 +61,13 @@
             <!-- 账号信息下拉框 -->
             <li class="dropdown user user-menu">
                 <a href="#" class="dropdown-toggle" data-toggle="dropdown">
-                    <img src="{$admin.avatar}" class="user-image" alt="User Image">
+                    <img src="__CDN__{$admin.avatar}" class="user-image" alt="User Image">
                     <span class="hidden-xs">{$admin.nickname}</span>
                 </a>
                 <ul class="dropdown-menu">
                     <!-- User image -->
                     <li class="user-header">
-                        <img src="{$admin.avatar}" class="img-circle" alt="">
+                        <img src="__CDN__{$admin.avatar}" class="img-circle" alt="">
 
                         <p>
                             {$admin.nickname}
@@ -91,7 +91,7 @@
                     <!-- Menu Footer-->
                     <li class="user-footer">
                         <div class="pull-left">
-                            <a href="{:url('general.profile/index')}" class="btn btn-default btn-flat">{:__('Profile')}</a>
+                            <a href="{:rtrim(url('general.profile/'),'/')}" class="btn btn-default btn-flat">{:__('Profile')}</a>
                         </div>
                         <div class="pull-right">
                             <a href="{:url('index/logout')}" class="btn btn-default btn-flat">{:__('Logout')}</a>

+ 1 - 1
application/admin/view/common/menu.html

@@ -3,7 +3,7 @@
     <!-- Sidebar user panel -->
     <div class="user-panel hidden-xs">
         <div class="pull-left image">
-            <img src="{$admin.avatar}" class="img-circle" />
+            <img src="__CDN__{$admin.avatar}" class="img-circle" />
         </div>
         <div class="pull-left info">
             <p>{$admin.nickname}</p>

+ 1 - 1
application/admin/view/index/login.html

@@ -66,7 +66,7 @@
                 <div class="login-screen">
                     <div class="well">
                         <div class="login-form">
-                            <img id="profile-img" class="profile-img-card" src="/assets/img/avatar.png" />
+                            <img id="profile-img" class="profile-img-card" src="__CDN__/assets/img/avatar.png" />
                             <p id="profile-name" class="profile-name-card"></p>
                             <form action="" method="post" id="login-form">
                                 {:token()}

+ 25 - 0
application/common/behavior/Common.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace app\common\behavior;
+
+use think\Config;
+
+class Common
+{
+
+    public function run(&$params)
+    {
+        $cdnurl = str_replace('/index.php', '', $params->root());
+        // 如果未设置__CDN__则自动匹配得出
+        if (!Config::get('view_replace_str.__CDN__'))
+        {
+            Config::set('view_replace_str.__CDN__', $cdnurl);
+        }
+        // 如果未设置cdnurl则自动匹配得出
+        if (!Config::get('site.cdnurl'))
+        {
+            Config::set('site.cdnurl', $cdnurl);
+        }
+    }
+
+}

+ 6 - 3
application/common/controller/Backend.php

@@ -84,7 +84,11 @@ class Backend extends Controller
         // 非选项卡时重定向
         if (!IS_AJAX && !IS_ADDTABS && $controllername != 'index' && $actionname == 'index')
         {
-            header("location:" . url('index/index#!' . urlencode($this->request->baseUrl()), '', false));
+            $url = $this->request->baseUrl();
+            $start = stripos($url, 'index.php');
+            if ($start !== false)
+                $url = substr($url, 0, $start + 9) . str_replace('.', '/', substr($url, $start + 9));
+            header("location:" . url('index/index#!' . urlencode($url), '', false));
             exit;
         }
 
@@ -128,12 +132,11 @@ class Backend extends Controller
             'controllername' => $controllername,
             'actionname'     => $actionname,
             'jsname'         => 'backend/' . str_replace('.', '/', $controllername),
-            'subdomain'      => 0,
+            'moduleurl'      => url("/{$modulename}", '', false),
             'language'       => $lang
         ];
         Lang::load(APP_PATH . $modulename . '/lang/' . $lang . '/' . str_replace('.', '/', $controllername) . '.php');
 
-
         $this->assign('site', Config::get("site"));
         $this->assign('config', $config);
 

+ 1 - 2
application/common/controller/Frontend.php

@@ -59,11 +59,10 @@ class Frontend extends Controller
             'controllername' => $controllername,
             'actionname'     => $actionname,
             'jsname'         => 'frontend/' . str_replace('.', '/', $controllername),
-            'subdomain'      => 0,
+            'moduleurl'      => url("/{$modulename}", '', false),
             'language'       => $lang
         ];
         Lang::load(APP_PATH . $modulename . '/lang/' . $lang . '/' . str_replace('.', '/', $controllername) . '.php');
-
         $this->assign('site', Config::get("site"));
         $this->assign('config', $config);
     }

+ 4 - 4
application/index/view/index/index.html

@@ -13,7 +13,7 @@
     <div class="row">
         <div class="col-sm-6 col-md-4">
             <div class="thumbnail">
-                <a href="{:url('index/user/login')}"><img style="height: 200px; width: 100%; display: block;" src="/assets/img/third.jpg" data-holder-rendered="true"></a>
+                <a href="{:url('index/user/login')}"><img style="height: 200px; width: 100%; display: block;" src="__CDN__/assets/img/third.jpg" data-holder-rendered="true"></a>
                 <div class="caption">
                     <h3>第三方登录</h3>
                     <p>FastAdmin中自带第三方登录扩展组件,包括微博登录、QQ登录、微信登录,可极速进行第三方登录的融合,同时系统中已提供注册登录的代码</p>
@@ -23,7 +23,7 @@
         </div>
         <div class="col-sm-6 col-md-4">
             <div class="thumbnail">
-                <a href="{:url('index/user/login')}"><img style="height: 200px; width: 100%; display: block;" src="/assets/img/ucenter.jpg" data-holder-rendered="true"></a>
+                <a href="{:url('index/user/login')}"><img style="height: 200px; width: 100%; display: block;" src="__CDN__/assets/img/ucenter.jpg" data-holder-rendered="true"></a>
                 <div class="caption">
                     <h3>Ucenter整合登录</h3>
                     <p>FastAdmin中基于Ucenter融合一套账号同步登录注册退出的方案,同时提供修改版Ucenter和Discuz论坛代码下载,同时适应于PHP7,此版本改动较大,建议适用于新系统的开发</p>
@@ -33,7 +33,7 @@
         </div>
         <div class="col-sm-6 col-md-4">
             <div class="thumbnail">
-                <a href="{:url('index/demo/qrcode')}"><img style="height: 200px; width: 100%; display: block;" src="/assets/img/qrcode.jpg" data-holder-rendered="true"></a>
+                <a href="{:url('index/demo/qrcode')}"><img style="height: 200px; width: 100%; display: block;" src="__CDN__/assets/img/qrcode.jpg" data-holder-rendered="true"></a>
                 <div class="caption">
                     <h3>二维码生成</h3>
                     <p>基于第三方组件增加了一个二维码的生成示例,可快速的调整文字、标签、Logo的大小、颜色、字体等等。此外还可对标签位置、容错率等进行相关设置。</p>
@@ -43,7 +43,7 @@
         </div>
         <div class="col-sm-6 col-md-4">
             <div class="thumbnail">
-                <a href="{:url('index/demo/bootstrap')}"><img style="height: 200px; width: 100%; display: block;" src="/assets/img/bootstrap.jpg" data-holder-rendered="true"></a>
+                <a href="{:url('index/demo/bootstrap')}"><img style="height: 200px; width: 100%; display: block;" src="__CDN__/assets/img/bootstrap.jpg" data-holder-rendered="true"></a>
                 <div class="caption">
                     <h3>Bootstrap组件</h3>
                     <p>由于FastAdmin对Bootstrap进行了大量的二次开发,对Bootstrap的组件样式有许多更改,你可以直接在这里预览到Bootstrap的部分组件</p>

+ 4 - 2
application/tags.php

@@ -1,4 +1,5 @@
 <?php
+
 // +----------------------------------------------------------------------
 // | ThinkPHP [ WE CAN DO IT JUST THINK ]
 // +----------------------------------------------------------------------
@@ -8,7 +9,6 @@
 // +----------------------------------------------------------------------
 // | Author: liu21st <liu21st@gmail.com>
 // +----------------------------------------------------------------------
-
 // 应用行为扩展定义文件
 return [
     // 应用初始化
@@ -16,7 +16,9 @@ return [
     // 应用开始
     'app_begin'    => [],
     // 模块初始化
-    'module_init'  => [],
+    'module_init'  => [
+        'app\\common\\behavior\\Common',
+    ],
     // 操作开始执行
     'action_begin' => [],
     // 视图内容过滤

+ 2 - 0
public/assets/css/backend-func.css

@@ -33,6 +33,8 @@ body {
 .tab-addtabs .tab-pane {
   height: 100%;
   width: 100%;
+}
+.tab-addtabs.ios-iframe-fix .tab-pane {
   -webkit-overflow-scrolling: touch;
   overflow: auto;
 }

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
public/assets/css/backend.min.css


+ 1 - 1
public/assets/js/backend.js

@@ -56,7 +56,7 @@ define(['jquery', 'bootstrap', 'toastr', 'layer', 'lang', 'config'], function ($
                 if (url.substr(0, 1) !== "/") {
                     var r = new RegExp('^(?:[a-z]+:)?//', 'i');
                     if (!r.test(url)) {
-                        url = (Config.subdomain == "1" ? "" : "/" + Config.modulename) + "/" + url;
+                        url = Config.moduleurl + "/" + url;
                     }
                 }
                 return url;

+ 5 - 1
public/assets/js/backend/index.js

@@ -62,6 +62,11 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'validator'], f
             //绑定tabs事件
             $('#nav').addtabs({iframeHeight: "100%"});
 
+            //修复iOS下iframe无法滚动的BUG
+            if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
+                $(".tab-addtabs").addClass("ios-iframe-fix");
+            }
+
             if (location.hash.indexOf("#!") === 0) {
                 var url = decodeURIComponent(location.hash.substring(2));
                 //刷新页面后将左侧对应的LI展开
@@ -181,7 +186,6 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'validator'], f
 
                 // 切换子菜单显示和菜单小图标的显示
                 $("[data-menu]").on('click', function () {
-                    console.log($(this).data("menu"));
                     if ($(this).data("menu") == 'show-submenu') {
                         $("ul.sidebar-menu").toggleClass("show-submenu");
                     } else {

+ 0 - 1
public/assets/js/backend/wechat/menu.js

@@ -121,7 +121,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'sortable'], function
                     } else if (false) {
 
                     }
-                    console.log(currentItem.children());
                     currentItem.children("a").find("span").text(title.subByte(0, 16));
                     $("input[name='item-title']").val(title);
                     currentItem.attr('data-name', title);

+ 1 - 1
public/assets/js/frontend.js

@@ -56,7 +56,7 @@ define(['jquery', 'bootstrap', 'toastr', 'layer', 'config'], function ($, undefi
                 if (url.substr(0, 1) !== "/") {
                     var r = new RegExp('^(?:[a-z]+:)?//', 'i');
                     if (!r.test(url)) {
-                        url = (Config.subdomain == "1" ? "" : "/" + Config.modulename) + "/" + url;
+                        url = (Config.moduleurl) + "/" + url;
                     }
                 }
                 return url;

+ 1 - 1
public/assets/js/frontend/demo.js

@@ -3,7 +3,7 @@ define(['jquery', 'bootstrap', 'frontend', 'config'], function ($, undefined, Fr
     var Controller = {
         qrcode: function () {
             $("form").submit(function () {
-                $("#qrcodeimg").prop("src", (Config.subdomain == "1" ? '' : '/index') + "/demo/qrcode?" + $(this).serialize());
+                $("#qrcodeimg").prop("src", Config.moduleurl + "/demo/qrcode?" + $(this).serialize());
                 return false;
             });
             $("form").trigger('submit');

+ 3 - 2
public/assets/js/require-backend.js

@@ -138,8 +138,7 @@ require.config({
 require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
     // 配置语言包的路径
     var paths = {};
-    paths['lang'] = (Config.subdomain == "1" ? '' : '/admin') + '/ajax/lang?callback=define&controllername=' + Config.controllername;
-
+    paths['lang'] = Config.moduleurl + '/ajax/lang?callback=define&controllername=' + Config.controllername;
     // 避免目录冲突
     paths['backend/'] = 'backend/';
     require.config({paths: paths});
@@ -170,6 +169,8 @@ require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
             //加载相应模块
             require([Config.jsname], function (Controller) {
                 Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+            }, function (e) {
+                // 这里可捕获模块加载的错误
             });
         });
     });

+ 5 - 4
public/assets/js/require-backend.min.js

@@ -155,8 +155,7 @@ require.config({
 require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
     // 配置语言包的路径
     var paths = {};
-    paths['lang'] = (Config.subdomain == "1" ? '' : '/admin') + '/ajax/lang?callback=define&controllername=' + Config.controllername;
-
+    paths['lang'] = Config.moduleurl + '/ajax/lang?callback=define&controllername=' + Config.controllername;
     // 避免目录冲突
     paths['backend/'] = 'backend/';
     require.config({paths: paths});
@@ -187,6 +186,8 @@ require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
             //加载相应模块
             require([Config.jsname], function (Controller) {
                 Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+            }, function (e) {
+                // 这里可捕获模块加载的错误
             });
         });
     });
@@ -1968,7 +1969,7 @@ define('backend',['jquery', 'bootstrap', 'toastr', 'layer', 'lang', 'config'], f
                 if (url.substr(0, 1) !== "/") {
                     var r = new RegExp('^(?:[a-z]+:)?//', 'i');
                     if (!r.test(url)) {
-                        url = (Config.subdomain == "1" ? "" : "/" + Config.modulename) + "/" + url;
+                        url = Config.moduleurl + "/" + url;
                     }
                 }
                 return url;
@@ -8943,7 +8944,7 @@ $.fn.addtabs = function (options) {
                 content.append(opts.content);
             } else if (options.iframeUse && !opts.ajax) {//没有内容,使用IFRAME打开链接
                 var height = options.iframeHeight;
-                content.append('<iframe src="' + url + '" width="100%" height="' + height + '%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling-x="no" scrolling-y="auto" allowtransparency="yes"></iframe></div>');
+                content.append('<iframe src="' + url + '" width="100%" height="' + height + '" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling-x="no" scrolling-y="auto" allowtransparency="yes"></iframe></div>');
             } else {
                 $.get(url, function (data) {
                     content.append(data);

+ 3 - 1
public/assets/js/require-frontend.js

@@ -138,7 +138,7 @@ require.config({
 require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
     // 配置语言包的路径
     var paths = {};
-    paths['lang'] = (Config.subdomain == "1" ? '' : '/index') + '/ajax/lang?callback=define&controllername=' + Config.controllername;
+    paths['lang'] = Config.moduleurl + '/ajax/lang?callback=define&controllername=' + Config.controllername;
 
     // 避免目录冲突
     paths['frontend/'] = 'frontend/';
@@ -170,6 +170,8 @@ require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
             //加载相应模块
             require([Config.jsname], function (Controller) {
                 Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+            }, function (e) {
+                // 这里可捕获模块加载的错误
             });
         });
     });

+ 4 - 2
public/assets/js/require-frontend.min.js

@@ -155,7 +155,7 @@ require.config({
 require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
     // 配置语言包的路径
     var paths = {};
-    paths['lang'] = (Config.subdomain == "1" ? '' : '/index') + '/ajax/lang?callback=define&controllername=' + Config.controllername;
+    paths['lang'] = Config.moduleurl + '/ajax/lang?callback=define&controllername=' + Config.controllername;
 
     // 避免目录冲突
     paths['frontend/'] = 'frontend/';
@@ -187,6 +187,8 @@ require(['jquery', 'bootstrap', 'config'], function ($, undefined, Config) {
             //加载相应模块
             require([Config.jsname], function (Controller) {
                 Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+            }, function (e) {
+                // 这里可捕获模块加载的错误
             });
         });
     });
@@ -1968,7 +1970,7 @@ define('frontend',['jquery', 'bootstrap', 'toastr', 'layer', 'config'], function
                 if (url.substr(0, 1) !== "/") {
                     var r = new RegExp('^(?:[a-z]+:)?//', 'i');
                     if (!r.test(url)) {
-                        url = (Config.subdomain == "1" ? "" : "/" + Config.modulename) + "/" + url;
+                        url = (Config.moduleurl) + "/" + url;
                     }
                 }
                 return url;

+ 6 - 2
public/assets/less/backend-func.less

@@ -51,8 +51,12 @@ body {
     .tab-pane {
         height: 100%;
         width: 100%;
-        -webkit-overflow-scrolling:touch;
-        overflow:auto;
+    }
+    &.ios-iframe-fix{
+        .tab-pane {
+            -webkit-overflow-scrolling:touch;
+            overflow: auto;
+        }
     }
 }