css
This commit is contained in:
parent
7e102fc193
commit
0d13556380
1
addons/betterform/.addonrc
Normal file
1
addons/betterform/.addonrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"files":["public\/assets\/addons\/betterform\/css\/common.css"],"license":"regular","licenseto":"15976","licensekey":"jonIxu8gCamyBzi5 N6Q6iqNNuNQoEV\/fV4rCvlZqQvDJEBrF+sYTD7HeULs=","domains":["fast.cc"],"licensecodes":[],"validations":["043c5318e9fc4870124f0d65db900fc1"]}
|
||||||
113
addons/betterform/Betterform.php
Normal file
113
addons/betterform/Betterform.php
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace addons\betterform;
|
||||||
|
|
||||||
|
use app\common\library\Menu;
|
||||||
|
use think\Addons;
|
||||||
|
use think\Loader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件
|
||||||
|
*/
|
||||||
|
class Betterform extends Addons
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件安装方法
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function install()
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件卸载方法
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function uninstall()
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件启用方法
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function enable()
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件禁用方法
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function disable()
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function viewFilter(&$content)
|
||||||
|
{
|
||||||
|
$request = \think\Request::instance();
|
||||||
|
$dispatch = $request->dispatch();
|
||||||
|
if (!$dispatch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$request->module() || $request->module() !== 'admin') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = get_addon_config('betterform');
|
||||||
|
|
||||||
|
//在head前引入CSS
|
||||||
|
$content = preg_replace("/<\/head>/i", "<link href='/assets/addons/betterform/css/common.css' rel='stylesheet' />" . "\n\$0", $content);
|
||||||
|
|
||||||
|
//如果不存在表单
|
||||||
|
if (!preg_match('/<form (.*?)data-toggle="validator"/i', $content)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 避免栈空间不足
|
||||||
|
ini_set('pcre.jit', false);
|
||||||
|
|
||||||
|
// 匹配<div class="form-group">标签
|
||||||
|
$regex = '/<div[^>]*class\s*=\s*"[^"]*\bform-group\b[^"]*"[^>]*>(?:(?!<div[^>]*class\s*=\s*"[^"]*\bform-group\b[^"]*").)*?data-rule="[^"]*?(required|checked)[^"]*?"[^>]*>/si';
|
||||||
|
$result = preg_replace_callback($regex, function ($matches) use ($config) {
|
||||||
|
return str_replace("form-group", "form-group required-{$config['asteriskposition']}", $matches[0]);
|
||||||
|
}, $content);
|
||||||
|
|
||||||
|
$content = is_null($result) ? $content : $result;
|
||||||
|
|
||||||
|
// 匹配<tr>
|
||||||
|
$pattern = '/(<tr[^>]*>)\s*<td[^>]*>(.*?)<\/td>\s*<td[^>]*>.*?<input[^>]*data-rule="[^"]*required[^"]*"[^>]*>.*?<\/td>\s*<\/tr>/si';
|
||||||
|
$result = preg_replace_callback($pattern, function ($matches) use ($config) {
|
||||||
|
if (preg_match('/(<tr[^>]*)class\s*=\s*"[^"]*"/i', $matches[1])) {
|
||||||
|
return preg_replace('/(<tr[^>]*)class\s*=\s*"([^"]*)"/i', '$1class="$2 required-' . $config['asteriskposition'] . '"', $matches[0]);
|
||||||
|
} else {
|
||||||
|
return str_replace("<tr", "<tr class=\"required-{$config['asteriskposition']}\"", $matches[0]);
|
||||||
|
}
|
||||||
|
}, $content);
|
||||||
|
|
||||||
|
$content = is_null($result) ? $content : $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $params
|
||||||
|
*/
|
||||||
|
public function configInit(&$params)
|
||||||
|
{
|
||||||
|
$config = $this->getConfig();
|
||||||
|
|
||||||
|
$config['area'] = preg_match("/\[(.*?)\]/i", $config['area']) ? array_slice(array_values((array)json_decode($config['area'], true)), 0, 2) : $config['area'];
|
||||||
|
$config['shade'] = floatval($config['shade']);
|
||||||
|
$config['shadeClose'] = boolval($config['shadeClose']);
|
||||||
|
$params['betterform'] = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
addons/betterform/bootstrap.js
vendored
Normal file
27
addons/betterform/bootstrap.js
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
require(['fast', 'layer'], function (Fast, Layer) {
|
||||||
|
var _fastOpen = Fast.api.open;
|
||||||
|
Fast.api.open = function (url, title, options) {
|
||||||
|
options = options || {};
|
||||||
|
options.area = Config.betterform.area;
|
||||||
|
options.offset = Config.betterform.offset;
|
||||||
|
options.anim = Config.betterform.anim;
|
||||||
|
options.shadeClose = Config.betterform.shadeClose;
|
||||||
|
options.shade = Config.betterform.shade;
|
||||||
|
return _fastOpen(url, title, options);
|
||||||
|
};
|
||||||
|
if (isNaN(Config.betterform.anim)) {
|
||||||
|
var _layerOpen = Layer.open;
|
||||||
|
Layer.open = function (options) {
|
||||||
|
var classNameArr = {slideDown: "layer-anim-slide-down", slideLeft: "layer-anim-slide-left", slideUp: "layer-anim-slide-up", slideRight: "layer-anim-slide-right"};
|
||||||
|
var animClass = "layer-anim " + classNameArr[options.anim] || "layer-anim-fadein";
|
||||||
|
var index = _layerOpen(options);
|
||||||
|
var layero = $('#layui-layer' + index);
|
||||||
|
|
||||||
|
layero.addClass(classNameArr[options.anim] + "-custom");
|
||||||
|
layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
|
||||||
|
$(this).removeClass(animClass);
|
||||||
|
});
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
102
addons/betterform/config.php
Normal file
102
addons/betterform/config.php
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'name' => 'asteriskposition',
|
||||||
|
'title' => '*号位置',
|
||||||
|
'type' => 'radio',
|
||||||
|
'group' => '',
|
||||||
|
'visible' => '',
|
||||||
|
'content' => [
|
||||||
|
'before' => '位于文本前',
|
||||||
|
'after' => '位于文本后',
|
||||||
|
],
|
||||||
|
'value' => 'before',
|
||||||
|
'rule' => 'required',
|
||||||
|
'msg' => '',
|
||||||
|
'tip' => '',
|
||||||
|
'ok' => '',
|
||||||
|
'extend' => '',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'offset',
|
||||||
|
'title' => '弹窗位置',
|
||||||
|
'type' => 'radio',
|
||||||
|
'content' => [
|
||||||
|
'auto' => '居中',
|
||||||
|
't' => '顶部',
|
||||||
|
'b' => '底部',
|
||||||
|
'l' => '左部',
|
||||||
|
'r' => '右部',
|
||||||
|
],
|
||||||
|
'value' => 'r',
|
||||||
|
'rule' => 'required',
|
||||||
|
'msg' => '',
|
||||||
|
'tip' => '',
|
||||||
|
'ok' => '',
|
||||||
|
'extend' => '',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'anim',
|
||||||
|
'title' => '打开动画',
|
||||||
|
'type' => 'select',
|
||||||
|
'content' => [
|
||||||
|
'平滑放大',
|
||||||
|
'从上掉落',
|
||||||
|
'从最底部往上滑入',
|
||||||
|
'从左滑入',
|
||||||
|
'从左翻滚',
|
||||||
|
'渐显',
|
||||||
|
'抖动',
|
||||||
|
'slideDown' => '从上边缘往下',
|
||||||
|
'slideLeft' => '从右边缘往左',
|
||||||
|
'slideUp' => '从下边缘往上',
|
||||||
|
'slideRight' => '从左边缘往右',
|
||||||
|
],
|
||||||
|
'value' => 'slideLeft',
|
||||||
|
'rule' => 'required',
|
||||||
|
'msg' => '',
|
||||||
|
'tip' => '',
|
||||||
|
'ok' => '',
|
||||||
|
'extend' => '',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'area',
|
||||||
|
'title' => '弹窗宽高',
|
||||||
|
'type' => 'string',
|
||||||
|
'content' => [],
|
||||||
|
'value' => '["80%", "100%"]',
|
||||||
|
'rule' => 'required',
|
||||||
|
'msg' => '',
|
||||||
|
'tip' => '',
|
||||||
|
'ok' => '',
|
||||||
|
'extend' => '',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'shade',
|
||||||
|
'title' => '阴影透明度',
|
||||||
|
'type' => 'number',
|
||||||
|
'content' => [],
|
||||||
|
'value' => '0.3',
|
||||||
|
'rule' => 'required',
|
||||||
|
'msg' => '',
|
||||||
|
'tip' => '',
|
||||||
|
'ok' => '',
|
||||||
|
'extend' => '',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'shadeClose',
|
||||||
|
'title' => '点击阴影关闭弹窗',
|
||||||
|
'type' => 'bool',
|
||||||
|
'content' => [
|
||||||
|
1 => '开启',
|
||||||
|
0 => '关闭',
|
||||||
|
],
|
||||||
|
'value' => '1',
|
||||||
|
'rule' => 'required',
|
||||||
|
'msg' => '',
|
||||||
|
'tip' => '',
|
||||||
|
'ok' => '',
|
||||||
|
'extend' => '',
|
||||||
|
],
|
||||||
|
];
|
||||||
15
addons/betterform/controller/Index.php
Normal file
15
addons/betterform/controller/Index.php
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace addons\betterform\controller;
|
||||||
|
|
||||||
|
use think\addons\Controller;
|
||||||
|
|
||||||
|
class Index extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->error("当前插件暂无前台页面");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
addons/betterform/info.ini
Normal file
10
addons/betterform/info.ini
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
name = betterform
|
||||||
|
title = FastAdmin表单弹窗优化插件
|
||||||
|
intro = 优化FastAdmin表单弹窗
|
||||||
|
author = FastAdmin
|
||||||
|
website = https://www.fastadmin.net
|
||||||
|
version = 1.0.3
|
||||||
|
state = 1
|
||||||
|
url = http://fast.cc:8088/addons/betterform
|
||||||
|
license = regular
|
||||||
|
licenseto = 15976
|
||||||
Loading…
Reference in New Issue
Block a user