Compare commits
50 Commits
v2.0.18-20
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b35403dbe1 | ||
|
|
f87af906d9 | ||
|
|
72f4cee174 | ||
|
|
b9eaa4099d | ||
|
|
d104bf66ce | ||
|
|
7c1b69b089 | ||
|
|
2d152489af | ||
|
|
f77a33581b | ||
|
|
aca9b6680b | ||
|
|
1aa4bb0634 | ||
|
|
fe1244b099 | ||
|
|
131d0d664b | ||
|
|
004273c0c4 | ||
|
|
851ff8285c | ||
|
|
b856c288b9 | ||
|
|
f2ce9c4eef | ||
|
|
01fdca800b | ||
|
|
77f357061a | ||
|
|
3ece39150c | ||
|
|
68464e34f9 | ||
|
|
9e31b94527 | ||
|
|
979295c684 | ||
|
|
91950de997 | ||
|
|
34f3c78fe9 | ||
|
|
06eb605e9a | ||
|
|
cdeea3ff36 | ||
|
|
98cf84b16c | ||
|
|
0d7353e692 | ||
|
|
1fe39f83f4 | ||
|
|
5c7136ff0f | ||
|
|
86be0ca786 | ||
|
|
1ece1135ea | ||
|
|
cec87b24f2 | ||
|
|
1d379543f5 | ||
|
|
0038e27493 | ||
|
|
3646cfba93 | ||
|
|
6a418f6c7f | ||
|
|
33386c75dc | ||
|
|
0bc6f7bea5 | ||
|
|
82e8321432 | ||
|
|
4bc10f7c25 | ||
|
|
65edb94998 | ||
|
|
1733e995d6 | ||
|
|
332cd313fb | ||
|
|
b6b0d7efe5 | ||
|
|
3073302069 | ||
|
|
c24b348f30 | ||
|
|
b5b2707c3c | ||
|
|
840162fd37 | ||
|
|
207140145a |
@@ -1,8 +1,5 @@
|
||||
# Apache配置文件
|
||||
RewriteEngine On
|
||||
RewriteRule ^(data|system|templates)/.*.(db|db3|sql|tar|gz|zip|info|log)$ - [F]
|
||||
RewriteRule '^login$' ./index.php?c=login [L]
|
||||
RewriteRule '^admin$' ./index.php?c=admin [L]
|
||||
RewriteRule '^([A-Za-z0-9]+)$' ./index.php?u=$1 [L]
|
||||
RewriteRule '^(.+)/click/([A-Za-z0-9]+)$' ./index.php?c=$2&id=$3&u=$1 [L]
|
||||
RewriteRule '^(.+)/click/(.+)' ./$3 [L]
|
||||
# 安全规则(必选)
|
||||
RewriteRule ^templates/.*\.(php|tar|gz|zip|info|log|json)$ - [F]
|
||||
RewriteRule ^data/.*\.(db|db3|php|sql|tar|gz|zip|info|log|json)$ - [F]
|
||||
80
README.md
@@ -1,40 +1,100 @@
|
||||
TwoNav 是一款开源免费的书签(导航)管理程序,界面简洁,安装简单,使用方便。TwoNav可帮助你将浏览器书签集中式管理,解决跨设备、跨平台、跨浏览器之间同步和访问困难问题,做到一处部署,随处访问。
|
||||
TwoNav 是一款开源的书签(导航)管理程序,界面简洁,安装简单,使用方便,基础功能免费。TwoNav可帮助你将浏览器书签集中式管理,解决跨设备、跨平台、跨浏览器之间同步和访问困难问题,做到一处部署,随处访问。
|
||||
|
||||
- **演示站**: [http://two.lm21.top](http://two.lm21.top)
|
||||
- **仅供体验,定期清理数据** 账号密码`admin`
|
||||
|
||||
|
||||
### 相关文档
|
||||
* [安装教程](https://gitee.com/tznb/TwoNav/wikis/pages?sort_id=7968668&doc_id=3767990) | [使用说明](https://gitee.com/tznb/TwoNav/wikis) | [下载TwoNav](https://gitee.com/tznb/TwoNav/releases)
|
||||
* [OneNav Extend 升级到 TwoNav](https://gitee.com/tznb/OneNav/wikis/pages?sort_id=7955135&doc_id=2439895)
|
||||
* [安装教程](https://gitee.com/tznb/TwoNav/wikis/pages?sort_id=7968668&doc_id=3767990) | [使用说明](https://gitee.com/tznb/TwoNav/wikis) | [下载TwoNav](https://gitee.com/tznb/TwoNav/releases) | [获取授权](https://gitee.com/tznb/TwoNav/wikis/pages?sort_id=7968669&doc_id=3767990)
|
||||
|
||||
|
||||
### 作者声明
|
||||
* 本程序没有二开版、除了下面的项目地址均为盗版。
|
||||
* 使用盗版软件存在法律风险且没有任何保障。
|
||||
* 未经许可禁止用于商业用途、转载请保留作品出处。
|
||||
|
||||
### 项目由来
|
||||
```
|
||||
起初只是搭建一个自己的书签站、网上找了一圈看中了小z的OneNav。
|
||||
因功能无法满足我,开始基于ONeNav各种魔改、然后就有了OneNav Extend、这个名字还是小z给取的。
|
||||
后来和小z都开始收费后、由于用户容易搞混等各种原因、于是我重写代码并改名为TwoNav。
|
||||
其中一些OneNav的特色依旧是保留下来、并兼容OneNav的一些插件。
|
||||
```
|
||||
|
||||
### 项目地址
|
||||
- [https://gitee.com/tznb/TwoNav](https://gitee.com/tznb/TwoNav)
|
||||
- [https://github.com/tznb1/TwoNav](https://github.com/tznb1/TwoNav)
|
||||
|
||||
### 技术支持
|
||||
- QQ: 271152681
|
||||
- QQ群: 695720839
|
||||
- 技术支持QQ: 271152681
|
||||
- 授权版QQ群: 695720839
|
||||
- 免费版QQ群: 621815595
|
||||
|
||||
### 运行环境
|
||||
* PHP: 7.3 - 8.2
|
||||
* PHP: 7.3 - 8.2
|
||||
* 数据库: SQLite3 或 MySQL > 5.6.0
|
||||
|
||||
### 版本差别
|
||||
|
||||
* 免费版无需授权即可使用 / 标准版|高级版需[获取授权](https://pay.twonav.cn/)
|
||||
* 以下是简要的差别对比, 还有很多细节无法全部列举出来
|
||||
|
||||
| 功能 | 免费版 | 标准版 | 高级版 |
|
||||
| ---------------------------- | ---------------- | ---------------- | ---------------------------|
|
||||
| 多用户支持 | 不支持 | 支持 | 支持 |
|
||||
| 系统更新 | 不支持 | 一键更新 | 一键更新 |
|
||||
| 下载主题 | 不支持 | 一键下载 | 一键下载 |
|
||||
| 链接识别 | 支持单个 | 支持批量 | 支持批量 |
|
||||
| 链接检测 | 不支持 | 支持 | 支持 |
|
||||
| 本地备份 | 不支持 | 备份+回滚 | 备份+回滚 |
|
||||
| 收录管理 | 不支持 | 支持 | 支持 |
|
||||
| 留言管理 | 不支持 | 支持 | 支持 |
|
||||
| 文章管理 | 不支持 | 支持 | 支持 |
|
||||
| 热点新闻 | 不支持 | 支持 | 支持 |
|
||||
| 账号保留 | 不支持 | 支持 | 支持 |
|
||||
| 站点地图 | 不支持 | 支持 | 支持 |
|
||||
| 用户组管理 | 不支持 | 支持 | 支持 |
|
||||
| 自定义版权 | 不支持 | 支持 | 支持 |
|
||||
| 自定义代码 | 不支持 | 支持 | 支持 |
|
||||
| 注册码功能 | 不支持 | 支持 | 支持 |
|
||||
| 图标获取 | 支持第三方 | 本地获取、第三方获取 | 本地获取、第三方获取 |
|
||||
| 找回密码 | 不支持 | 不支持 | **支持** |
|
||||
| 注册验证 | 不支持 | 邮箱 | **邮箱、短信** |
|
||||
| 第三方登录 | 不支持 | 不支持 | **支持** |
|
||||
| 短信登录 | 不支持 | 不支持 | **支持** |
|
||||
| 域名防红 | 不支持 | 不支持 | **支持** |
|
||||
| 个性域名 | 不支持 | 不支持 | **支持** |
|
||||
| 登录保护 | 不支持 | 不支持 | **支持** |
|
||||
| 广告功能 | 不支持 | 不支持 | **支持** |
|
||||
| 多域名授权 | 不支持 | 不支持 | **付费支持** |
|
||||
* 个性域名: 允许用户自定义域名前缀、访问前缀.主域名等于访问对应用户的主页、标准版支持用户名.主域名访问对应用户的主页
|
||||
* 登录保护: 用于防止暴力破解、可根据IP或账号自动限制登录行为
|
||||
* 广告功能: 支持在后台添加文字广告、大横幅、小横幅等、可设置到期后自动停用
|
||||
* 多域名授权: 支持授权多个主域名、支持给不同域名设置不同主页、从而节省成本(具体可联系客服咨询)
|
||||
|
||||
|
||||
### 功能特色
|
||||
* 支持
|
||||
* 支持后台管理
|
||||
* 支持私有链接
|
||||
* 支持加密链接
|
||||
* 支持分享链接
|
||||
* 支持二级分类
|
||||
* 支持用户分组
|
||||
* 支持用户分组/权限管理
|
||||
* 支持Chrome/Firefox/Edge书签批量导入
|
||||
* 支持多种主题风格
|
||||
* 支持批量更新链接图标/标题/描述等信息
|
||||
* 支持链接信息自动识别
|
||||
* 支持API
|
||||
* 支持Docker部署
|
||||
* 支持uTools插件
|
||||
* 支持Chromium内核的[浏览器扩展]
|
||||
* 支持简易文章管理
|
||||
* 支持更换各种模板/支持混搭,26个主题模板
|
||||
* 安全性支持:更换登录入口/二级密码/OTP双重验证
|
||||
|
||||
### 赞助商
|
||||
* [此项目的 CDN 加速和安全防护由腾讯 EdgeOne 赞助。](https://edgeone.ai/?from=github "此项目的 CDN 加速和安全防护由腾讯 EdgeOne 赞助。")
|
||||
[](https://edgeone.ai/?from=github)
|
||||
[Best Asian CDN, Edge, and Secure Solutions - Tencent EdgeOne](https://edgeone.ai/?from=github "Best Asian CDN, Edge, and Secure Solutions - Tencent EdgeOne")
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
1
data/README.md
Normal file
@@ -0,0 +1 @@
|
||||
用户数据目录,请勿随意删除!
|
||||
1
data/temp/README.md
Normal file
@@ -0,0 +1 @@
|
||||
临时目录,可删除
|
||||
1
data/user/README.md
Normal file
@@ -0,0 +1 @@
|
||||
用户数据目录,请勿随意删除!
|
||||
32
index.php
@@ -15,9 +15,10 @@ if($db_config['type'] == 'sqlite'){
|
||||
}catch (Exception $e) {
|
||||
Amsg(-1,'载入数据库失败'.$db_config['path']);
|
||||
}
|
||||
}elseif($db_config['type'] == 'mysql'){
|
||||
}elseif($db_config['type'] == 'mysql' || $db_config['type'] == 'mariadb' ){
|
||||
try {
|
||||
$db = new Medoo\Medoo(['type' => 'mysql',
|
||||
$db = new Medoo\Medoo([
|
||||
'type' => $db_config['type'],
|
||||
'host' => $db_config['host'],
|
||||
'port' => $db_config['port'],
|
||||
'database' => $db_config['name'],
|
||||
@@ -34,21 +35,19 @@ if($db_config['type'] == 'sqlite'){
|
||||
$global_config = unserialize( get_db("global_config", "v", ["k" => "o_config"]) ); //全局配置
|
||||
$c = Get('c');
|
||||
$libs = $global_config['Libs'];
|
||||
$layui['js'] = $libs.'/Layui/v2.9.18/layui.js';
|
||||
$layui['css'] = $libs.'/Layui/v2.9.18/css/layui.css';
|
||||
$global_config['static_link'] = isset($global_config['static_link']) ? $global_config['static_link'] : 0;
|
||||
define('libs',$global_config['Libs']);
|
||||
define('SysVer',Get_Version());
|
||||
define('Debug',$global_config['Debug'] == 1);
|
||||
define('static_link',$global_config['static_link'] > 0);
|
||||
|
||||
if($c != $global_config["Register"]){
|
||||
$u = Get('u');
|
||||
if(empty($u) && $global_config['Sub_domain'] == 1 && is_subscribe('bool')){
|
||||
$cut = explode('.',$_SERVER["HTTP_HOST"]);
|
||||
if(count($cut) == 3){
|
||||
$USER_DB = get_db("global_user", "*", ["User"=>reset($cut)]);
|
||||
if(!empty($USER_DB) && check_purview('Sub_domain',1)){
|
||||
$_COOKIE['Default_User'] = $USER_DB['User'];unset($cut);
|
||||
}
|
||||
}
|
||||
if(!in_array($c,[$global_config["Register"],'ico','icon','auth'])){
|
||||
if($global_config['static_link'] > 0 && !empty($UUID)){
|
||||
$_GET['u'] = $global_config['static_link'] == 2 ? get_db("global_user", "User", ["ID"=>$UUID]) : $UUID;
|
||||
}
|
||||
$u = Get('u');
|
||||
$u = !empty($u)?$u:(!empty($_COOKIE['Default_User'])?$_COOKIE['Default_User']:(!empty($global_config['Default_User'])?$global_config['Default_User']:'admin'));//优先级:Get>Host>Cookie>默认用户>admin
|
||||
$USER_DB = get_db("global_user", "*", ["User"=>$u]);
|
||||
//没找到账号显示404
|
||||
@@ -64,15 +63,20 @@ if($c != $global_config["Register"]){
|
||||
}
|
||||
|
||||
session_name('TwoNavSID');
|
||||
if(defined('UID')){
|
||||
define('is_login',is_login()); $is_login = is_login;
|
||||
}
|
||||
|
||||
if(empty($c) || $c == 'index'){
|
||||
$c = 'index';
|
||||
require "./system/index.php";//主页
|
||||
}elseif($c == $global_config["Register"]){
|
||||
require "./system/Register.php";//注册
|
||||
}elseif($c == $global_config['Login'] || $c == $USER_DB['Login']){
|
||||
require "./system/login.php";//登陆
|
||||
}elseif(in_array($c,['admin','click','api','ico','verify'])){
|
||||
}elseif(in_array($c,['admin','click','api','ico','icon','verify','auth'])){
|
||||
require "./system/{$c}.php";
|
||||
}elseif(in_array($c,['apply','guestbook'])){
|
||||
}elseif(in_array($c,['apply','guestbook','article','sitemap'])){
|
||||
if($global_config['Maintenance'] != 0){Amsg(-1,'网站正在进行维护,请稍后再试!');}
|
||||
require "./system/expand/{$c}.php";
|
||||
}else{
|
||||
|
||||
47
rewrite.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php //负责接管和处理Nginx伪静态规则
|
||||
|
||||
define('URI',$_SERVER['REQUEST_URI']);
|
||||
|
||||
//登录/管理/注册页面(不带html)
|
||||
if (URI === '/login' || URI === '/admin' || URI == '/register') {
|
||||
$_GET['c'] = substr(URI, 1);
|
||||
//管理页面
|
||||
}elseif (preg_match('/^\/admin-([A-Za-z0-9]+)\.html?$/', URI, $matches)) {
|
||||
$_GET['c'] = 'admin';
|
||||
$UUID = $matches[1];
|
||||
//专属登录页面
|
||||
}elseif (preg_match('/^\/login-([A-Za-z0-9]+)-([A-Za-z0-9]+)\.html?$/', URI, $matches)) {
|
||||
$UUID = $matches[1];
|
||||
$_GET['c'] = $matches[2];
|
||||
//收录和留言
|
||||
}elseif (preg_match('/^\/(apply|guestbook)-([A-Za-z0-9]+)\.html?$/', URI, $matches)) {
|
||||
$_GET['c'] = $matches[1];
|
||||
$UUID = $matches[2];
|
||||
//本地图标
|
||||
}elseif(preg_match('/^\/ico\/(.+)$/', URI, $matches)){
|
||||
$_GET['c'] = 'icon';
|
||||
$_GET['url'] = $matches[1];
|
||||
//用户主页
|
||||
}elseif (preg_match('/^\/([A-Za-z0-9]+)\.html?$/', URI, $matches)) {
|
||||
$UUID = $matches[1];
|
||||
//过渡/文章
|
||||
}elseif(preg_match('/^\/(click|article)-([A-Za-z0-9]+)-(\d+)\.html?$/', URI, $matches)) {
|
||||
$_GET['c'] = $matches[1];
|
||||
$UUID = $matches[2];
|
||||
$_GET['id'] = $matches[3];
|
||||
//分类页面
|
||||
}elseif(preg_match('/^\/category-([A-Za-z0-9]+)-(\d+)\.html?$/', URI, $matches)) {
|
||||
$_GET['c'] = 'index';
|
||||
$UUID = $matches[1];
|
||||
$_GET['oc'] = $matches[2];
|
||||
//站点地图
|
||||
}elseif(URI === '/sitemap.xml'){
|
||||
$_GET['c'] = 'sitemap';
|
||||
//匹配失败
|
||||
}else{
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
exit("404 Not Found.<br>".URI);
|
||||
}
|
||||
|
||||
include 'index.php';
|
||||
exit;
|
||||
@@ -1,190 +0,0 @@
|
||||
/** layui-v2.6.8 MIT License By https://www.layui.com 纯字体图标精简 */
|
||||
@font-face {
|
||||
font-family: layui-icon;
|
||||
src: url(../font/iconfont.woff2?v=256) format('woff2')
|
||||
}
|
||||
|
||||
.layui-icon {
|
||||
font-family: layui-icon!important;
|
||||
font-size: 16px;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale
|
||||
}
|
||||
|
||||
.layui-icon-reply-fill:before{content:"\e611"}
|
||||
.layui-icon-set-fill:before{content:"\e614"}
|
||||
.layui-icon-menu-fill:before{content:"\e60f"}
|
||||
.layui-icon-search:before{content:"\e615"}
|
||||
.layui-icon-share:before{content:"\e641"}
|
||||
.layui-icon-set-sm:before{content:"\e620"}
|
||||
.layui-icon-engine:before{content:"\e628"}
|
||||
.layui-icon-close:before{content:"\1006"}
|
||||
.layui-icon-close-fill:before{content:"\1007"}
|
||||
.layui-icon-chart-screen:before{content:"\e629"}
|
||||
.layui-icon-star:before{content:"\e600"}
|
||||
.layui-icon-circle-dot:before{content:"\e617"}
|
||||
.layui-icon-chat:before{content:"\e606"}
|
||||
.layui-icon-release:before{content:"\e609"}
|
||||
.layui-icon-list:before{content:"\e60a"}
|
||||
.layui-icon-chart:before{content:"\e62c"}
|
||||
.layui-icon-ok-circle:before{content:"\1005"}
|
||||
.layui-icon-layim-theme:before{content:"\e61b"}
|
||||
.layui-icon-table:before{content:"\e62d"}
|
||||
.layui-icon-right:before{content:"\e602"}
|
||||
.layui-icon-left:before{content:"\e603"}
|
||||
.layui-icon-cart-simple:before{content:"\e698"}
|
||||
.layui-icon-face-cry:before{content:"\e69c"}
|
||||
.layui-icon-face-smile:before{content:"\e6af"}
|
||||
.layui-icon-survey:before{content:"\e6b2"}
|
||||
.layui-icon-tree:before{content:"\e62e"}
|
||||
.layui-icon-ie:before{content:"\e7bb"}
|
||||
.layui-icon-upload-circle:before{content:"\e62f"}
|
||||
.layui-icon-add-circle:before{content:"\e61f"}
|
||||
.layui-icon-download-circle:before{content:"\e601"}
|
||||
.layui-icon-templeate-1:before{content:"\e630"}
|
||||
.layui-icon-util:before{content:"\e631"}
|
||||
.layui-icon-face-surprised:before{content:"\e664"}
|
||||
.layui-icon-edit:before{content:"\e642"}
|
||||
.layui-icon-speaker:before{content:"\e645"}
|
||||
.layui-icon-down:before{content:"\e61a"}
|
||||
.layui-icon-file:before{content:"\e621"}
|
||||
.layui-icon-layouts:before{content:"\e632"}
|
||||
.layui-icon-rate-half:before{content:"\e6c9"}
|
||||
.layui-icon-add-circle-fine:before{content:"\e608"}
|
||||
.layui-icon-prev-circle:before{content:"\e633"}
|
||||
.layui-icon-read:before{content:"\e705"}
|
||||
.layui-icon-404:before{content:"\e61c"}
|
||||
.layui-icon-carousel:before{content:"\e634"}
|
||||
.layui-icon-help:before{content:"\e607"}
|
||||
.layui-icon-code-circle:before{content:"\e635"}
|
||||
.layui-icon-windows:before{content:"\e67f"}
|
||||
.layui-icon-water:before{content:"\e636"}
|
||||
.layui-icon-username:before{content:"\e66f"}
|
||||
.layui-icon-find-fill:before{content:"\e670"}
|
||||
.layui-icon-about:before{content:"\e60b"}
|
||||
.layui-icon-location:before{content:"\e715"}
|
||||
.layui-icon-up:before{content:"\e619"}
|
||||
.layui-icon-pause:before{content:"\e651"}
|
||||
.layui-icon-date:before{content:"\e637"}
|
||||
.layui-icon-layim-uploadfile:before{content:"\e61d"}
|
||||
.layui-icon-delete:before{content:"\e640"}
|
||||
.layui-icon-play:before{content:"\e652"}
|
||||
.layui-icon-top:before{content:"\e604"}
|
||||
.layui-icon-firefox:before{content:"\e686"}
|
||||
.layui-icon-friends:before{content:"\e612"}
|
||||
.layui-icon-refresh-3:before{content:"\e9aa"}
|
||||
.layui-icon-ok:before{content:"\e605"}
|
||||
.layui-icon-layer:before{content:"\e638"}
|
||||
.layui-icon-face-smile-fine:before{content:"\e60c"}
|
||||
.layui-icon-dollar:before{content:"\e659"}
|
||||
.layui-icon-group:before{content:"\e613"}
|
||||
.layui-icon-layim-download:before{content:"\e61e"}
|
||||
.layui-icon-picture-fine:before{content:"\e60d"}
|
||||
.layui-icon-link:before{content:"\e64c"}
|
||||
.layui-icon-diamond:before{content:"\e735"}
|
||||
.layui-icon-log:before{content:"\e60e"}
|
||||
.layui-icon-key:before{content:"\e683"}
|
||||
.layui-icon-rate-solid:before{content:"\e67a"}
|
||||
.layui-icon-fonts-del:before{content:"\e64f"}
|
||||
.layui-icon-unlink:before{content:"\e64d"}
|
||||
.layui-icon-fonts-clear:before{content:"\e639"}
|
||||
.layui-icon-triangle-r:before{content:"\e623"}
|
||||
.layui-icon-circle:before{content:"\e63f"}
|
||||
.layui-icon-radio:before{content:"\e643"}
|
||||
.layui-icon-align-center:before{content:"\e647"}
|
||||
.layui-icon-align-right:before{content:"\e648"}
|
||||
.layui-icon-align-left:before{content:"\e649"}
|
||||
.layui-icon-loading-1:before{content:"\e63e"}
|
||||
.layui-icon-return:before{content:"\e65c"}
|
||||
.layui-icon-fonts-strong:before{content:"\e62b"}
|
||||
.layui-icon-upload:before{content:"\e67c"}
|
||||
.layui-icon-dialogue:before{content:"\e63a"}
|
||||
.layui-icon-video:before{content:"\e6ed"}
|
||||
.layui-icon-headset:before{content:"\e6fc"}
|
||||
.layui-icon-cellphone-fine:before{content:"\e63b"}
|
||||
.layui-icon-add-1:before{content:"\e654"}
|
||||
.layui-icon-face-smile-b:before{content:"\e650"}
|
||||
.layui-icon-fonts-html:before{content:"\e64b"}
|
||||
.layui-icon-screen-full:before{content:"\e622"}
|
||||
.layui-icon-form:before{content:"\e63c"}
|
||||
.layui-icon-cart:before{content:"\e657"}
|
||||
.layui-icon-camera-fill:before{content:"\e65d"}
|
||||
.layui-icon-tabs:before{content:"\e62a"}
|
||||
.layui-icon-heart-fill:before{content:"\e68f"}
|
||||
.layui-icon-fonts-code:before{content:"\e64e"}
|
||||
.layui-icon-ios:before{content:"\e680"}
|
||||
.layui-icon-at:before{content:"\e687"}
|
||||
.layui-icon-fire:before{content:"\e756"}
|
||||
.layui-icon-set:before{content:"\e716"}
|
||||
.layui-icon-fonts-u:before{content:"\e646"}
|
||||
.layui-icon-triangle-d:before{content:"\e625"}
|
||||
.layui-icon-tips:before{content:"\e702"}
|
||||
.layui-icon-picture:before{content:"\e64a"}
|
||||
.layui-icon-more-vertical:before{content:"\e671"}
|
||||
.layui-icon-bluetooth:before{content:"\e689"}
|
||||
.layui-icon-flag:before{content:"\e66c"}
|
||||
.layui-icon-loading:before{content:"\e63d"}
|
||||
.layui-icon-fonts-i:before{content:"\e644"}
|
||||
.layui-icon-refresh-1:before{content:"\e666"}
|
||||
.layui-icon-rmb:before{content:"\e65e"}
|
||||
.layui-icon-addition:before{content:"\e624"}
|
||||
.layui-icon-home:before{content:"\e68e"}
|
||||
.layui-icon-time:before{content:"\e68d"}
|
||||
.layui-icon-user:before{content:"\e770"}
|
||||
.layui-icon-notice:before{content:"\e667"}
|
||||
.layui-icon-chrome:before{content:"\e68a"}
|
||||
.layui-icon-edge:before{content:"\e68b"}
|
||||
.layui-icon-login-weibo:before{content:"\e675"}
|
||||
.layui-icon-voice:before{content:"\e688"}
|
||||
.layui-icon-upload-drag:before{content:"\e681"}
|
||||
.layui-icon-login-qq:before{content:"\e676"}
|
||||
.layui-icon-snowflake:before{content:"\e6b1"}
|
||||
.layui-icon-heart:before{content:"\e68c"}
|
||||
.layui-icon-logout:before{content:"\e682"}
|
||||
.layui-icon-file-b:before{content:"\e655"}
|
||||
.layui-icon-template:before{content:"\e663"}
|
||||
.layui-icon-transfer:before{content:"\e691"}
|
||||
.layui-icon-auz:before{content:"\e672"}
|
||||
.layui-icon-console:before{content:"\e665"}
|
||||
.layui-icon-app:before{content:"\e653"}
|
||||
.layui-icon-prev:before{content:"\e65a"}
|
||||
.layui-icon-website:before{content:"\e7ae"}
|
||||
.layui-icon-next:before{content:"\e65b"}
|
||||
.layui-icon-component:before{content:"\e857"}
|
||||
.layui-icon-android:before{content:"\e684"}
|
||||
.layui-icon-more:before{content:"\e65f"}
|
||||
.layui-icon-login-wechat:before{content:"\e677"}
|
||||
.layui-icon-shrink-right:before{content:"\e668"}
|
||||
.layui-icon-spread-left:before{content:"\e66b"}
|
||||
.layui-icon-camera:before{content:"\e660"}
|
||||
.layui-icon-note:before{content:"\e66e"}
|
||||
.layui-icon-refresh:before{content:"\e669"}
|
||||
.layui-icon-female:before{content:"\e661"}
|
||||
.layui-icon-male:before{content:"\e662"}
|
||||
.layui-icon-screen-restore:before{content:"\e758"}
|
||||
.layui-icon-password:before{content:"\e673"}
|
||||
.layui-icon-senior:before{content:"\e674"}
|
||||
.layui-icon-theme:before{content:"\e66a"}
|
||||
.layui-icon-tread:before{content:"\e6c5"}
|
||||
.layui-icon-praise:before{content:"\e6c6"}
|
||||
.layui-icon-star-fill:before{content:"\e658"}
|
||||
.layui-icon-rate:before{content:"\e67b"}
|
||||
.layui-icon-template-1:before{content:"\e656"}
|
||||
.layui-icon-vercode:before{content:"\e679"}
|
||||
.layui-icon-service:before{content:"\e626"}
|
||||
.layui-icon-cellphone:before{content:"\e678"}
|
||||
.layui-icon-print:before{content:"\e66d"}
|
||||
.layui-icon-cols:before{content:"\e610"}
|
||||
.layui-icon-wifi:before{content:"\e7e0"}
|
||||
.layui-icon-export:before{content:"\e67d"}
|
||||
.layui-icon-rss:before{content:"\e808"}
|
||||
.layui-icon-slider:before{content:"\e714"}
|
||||
.layui-icon-email:before{content:"\e618"}
|
||||
.layui-icon-subtraction:before{content:"\e67e"}
|
||||
.layui-icon-mike:before{content:"\e6dc"}
|
||||
.layui-icon-light:before{content:"\e748"}
|
||||
.layui-icon-gift:before{content:"\e627"}
|
||||
.layui-icon-mute:before{content:"\e685"}
|
||||
.layui-icon-reduce-circle:before{content:"\e616"}
|
||||
.layui-icon-music:before{content:"\e690"}
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name: layui.code
|
||||
@Description:Classic modular front-end UI framework
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
/* 加载就绪标志 */
|
||||
html #layuicss-skincodecss{display:none; position: absolute; width:1989px;}
|
||||
|
||||
/* 默认风格 */
|
||||
.layui-code-view{display: block; position: relative; margin: 10px 0; padding: 0; border: 1px solid #eee; border-left-width: 6px; background-color: #FAFAFA; color: #333; font-family: Courier New; font-size: 12px;}
|
||||
.layui-code-h3{position: relative; padding: 0 10px; height: 40px; line-height: 40px; border-bottom: 1px solid #eee; font-size: 12px;}
|
||||
.layui-code-h3 a{position: absolute; right: 10px; top: 0; color: #999;}
|
||||
.layui-code-view .layui-code-ol{position: relative; overflow: auto;}
|
||||
.layui-code-view .layui-code-ol li{position: relative; margin-left: 45px; line-height: 20px; padding: 0 10px; border-left: 1px solid #e2e2e2; list-style-type: decimal-leading-zero; *list-style-type: decimal; background-color: #fff;}
|
||||
.layui-code-view .layui-code-ol li:first-child{padding-top: 10px;}
|
||||
.layui-code-view .layui-code-ol li:last-child{padding-bottom: 10px;}
|
||||
.layui-code-view pre{margin: 0;}
|
||||
|
||||
/* notepadd++风格 */
|
||||
.layui-code-notepad{border: 1px solid #0C0C0C; border-left-color: #3F3F3F; background-color: #0C0C0C; color: #C2BE9E}
|
||||
.layui-code-notepad .layui-code-h3{border-bottom: none;}
|
||||
.layui-code-notepad .layui-code-ol li{background-color: #3F3F3F; border-left: none;}
|
||||
|
||||
/* 代码预览 */
|
||||
.layui-code-demo .layui-code{visibility: visible !important; margin: -15px; border-top: none; border-right: none; border-bottom: none;}
|
||||
.layui-code-demo .layui-tab-content{padding: 15px; border-top: none}
|
||||
@@ -1,16 +0,0 @@
|
||||
/** 图标字体 **/
|
||||
@font-face {font-family: 'laydate-icon';
|
||||
src: url('./font/iconfont.eot');
|
||||
src: url('./font/iconfont.eot#iefix') format('embedded-opentype'),
|
||||
url('./font/iconfont.svg#iconfont') format('svg'),
|
||||
url('./font/iconfont.woff') format('woff'),
|
||||
url('./font/iconfont.ttf') format('truetype');
|
||||
}
|
||||
|
||||
.laydate-icon{
|
||||
font-family:"laydate-icon" !important;
|
||||
font-size: 16px;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name: laydata
|
||||
|
||||
**/
|
||||
|
||||
|
||||
html #layuicss-laydate{display: none; position: absolute; width: 1989px;}
|
||||
|
||||
/* 初始化 */
|
||||
.layui-laydate *{margin: 0; padding: 0;}
|
||||
|
||||
/* 主体结构 */
|
||||
.layui-laydate, .layui-laydate *{box-sizing: border-box;}
|
||||
.layui-laydate{position: absolute; z-index: 66666666; margin: 5px 0; border-radius: 2px; font-size: 14px; -webkit-animation-duration: 0.2s; animation-duration: 0.2s; -webkit-animation-fill-mode: both; animation-fill-mode: both;}
|
||||
.layui-laydate-main{width: 272px;}
|
||||
.layui-laydate-header *,
|
||||
.layui-laydate-content td,
|
||||
.layui-laydate-list li{transition-duration: .3s; -webkit-transition-duration: .3s;}
|
||||
|
||||
/* 微微往下滑入 */
|
||||
@keyframes laydate-downbit {
|
||||
0% {opacity: 0.3; transform: translate3d(0, -5px, 0);}
|
||||
100% {opacity: 1; transform: translate3d(0, 0, 0);}
|
||||
}
|
||||
|
||||
.layui-laydate{animation-name: laydate-downbit;}
|
||||
.layui-laydate-static{ position: relative; z-index: 0; display: inline-block; margin: 0; -webkit-animation: none; animation: none;}
|
||||
|
||||
/* 展开年月列表时 */
|
||||
.laydate-ym-show .laydate-prev-m,
|
||||
.laydate-ym-show .laydate-next-m{display: none !important;}
|
||||
.laydate-ym-show .laydate-prev-y,
|
||||
.laydate-ym-show .laydate-next-y{display: inline-block !important;}
|
||||
.laydate-ym-show .laydate-set-ym span[lay-type="month"]{display: none !important;}
|
||||
|
||||
/* 展开时间列表时 */
|
||||
.laydate-time-show .layui-laydate-header .layui-icon,
|
||||
.laydate-time-show .laydate-set-ym span[lay-type="year"],
|
||||
.laydate-time-show .laydate-set-ym span[lay-type="month"]{display: none !important;}
|
||||
|
||||
/* 头部结构 */
|
||||
.layui-laydate-header{position: relative; line-height:30px; padding: 10px 70px 5px;}
|
||||
.layui-laydate-header *{display: inline-block; vertical-align: bottom;}
|
||||
.layui-laydate-header i{position: absolute; top: 10px; padding: 0 5px; color: #999; font-size: 18px; cursor: pointer;}
|
||||
.layui-laydate-header i.laydate-prev-y{left: 15px;}
|
||||
.layui-laydate-header i.laydate-prev-m{left: 45px;}
|
||||
.layui-laydate-header i.laydate-next-y{right: 15px;}
|
||||
.layui-laydate-header i.laydate-next-m{right: 45px;}
|
||||
.laydate-set-ym{width: 100%; text-align: center; box-sizing: border-box; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}
|
||||
.laydate-set-ym span{padding: 0 10px; cursor: pointer;}
|
||||
.laydate-time-text{cursor: default !important;}
|
||||
|
||||
/* 主体结构 */
|
||||
.layui-laydate-content{position: relative; padding: 10px; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none;}
|
||||
.layui-laydate-content table{border-collapse: collapse; border-spacing: 0;}
|
||||
.layui-laydate-content th,
|
||||
.layui-laydate-content td{width: 36px; height: 30px; padding: 5px; text-align: center;}
|
||||
.layui-laydate-content th{font-weight: 400;}
|
||||
.layui-laydate-content td{position: relative; cursor: pointer;}
|
||||
.laydate-day-mark{position: absolute; left: 0; top: 0; width: 100%; line-height: 30px; font-size: 12px; overflow: hidden;}
|
||||
.laydate-day-mark::after{position: absolute; content:''; right: 2px; top: 2px; width: 5px; height: 5px; border-radius: 50%;}
|
||||
|
||||
/* 底部结构 */
|
||||
.layui-laydate-footer{position: relative; height: 46px; line-height: 26px; padding: 10px;}
|
||||
.layui-laydate-footer span{display: inline-block; vertical-align: top; height: 26px; line-height: 24px; padding: 0 10px; border: 1px solid #C9C9C9; border-radius: 2px; background-color: #fff; font-size: 12px; cursor: pointer; white-space: nowrap; transition: all .3s;}
|
||||
.layui-laydate-footer span:hover{color: #5FB878;}
|
||||
.layui-laydate-footer span.layui-laydate-preview{cursor: default; border-color: transparent !important;}
|
||||
.layui-laydate-footer span.layui-laydate-preview:hover{color: #666;}
|
||||
.layui-laydate-footer span:first-child.layui-laydate-preview{padding-left: 0;}
|
||||
.laydate-footer-btns{position: absolute; right: 10px; top: 10px;}
|
||||
.laydate-footer-btns span{margin: 0 0 0 -1px;}
|
||||
|
||||
/* 年月列表 */
|
||||
.layui-laydate-list{position: absolute; left: 0; top: 0; width: 100%; height: 100%; padding: 10px; box-sizing: border-box; background-color: #fff;}
|
||||
.layui-laydate-list>li{position: relative; display: inline-block; width: 33.3%; height: 36px; line-height: 36px; margin: 3px 0; vertical-align: middle; text-align: center; cursor: pointer;}
|
||||
.laydate-month-list>li{width: 25%; margin: 17px 0;}
|
||||
.laydate-time-list{}
|
||||
.laydate-time-list>li{height: 100%; margin: 0; line-height: normal; cursor: default;}
|
||||
.laydate-time-list p{position: relative; top: -4px; line-height: 29px;}
|
||||
.laydate-time-list ol{height: 181px; overflow: hidden;}
|
||||
.laydate-time-list>li:hover ol{overflow-y: auto;}
|
||||
.laydate-time-list ol li{width: 130%; padding-left: 33px; height: 30px; line-height: 30px; text-align: left; cursor: pointer;}
|
||||
|
||||
/* 提示 */
|
||||
.layui-laydate-hint{position: absolute; top: 115px; left: 50%; width: 250px; margin-left: -125px; line-height: 20px; padding: 15px; text-align: center; font-size: 12px; color: #FF5722;}
|
||||
|
||||
|
||||
/* 双日历 */
|
||||
.layui-laydate-range{width: 546px;}
|
||||
.layui-laydate-range .layui-laydate-main{display: inline-block; vertical-align: middle;}
|
||||
.layui-laydate-range .laydate-main-list-1 .layui-laydate-header,
|
||||
.layui-laydate-range .laydate-main-list-1 .layui-laydate-content{border-left: 1px solid #e2e2e2;}
|
||||
|
||||
|
||||
/* 默认简约主题 */
|
||||
.layui-laydate, .layui-laydate-hint{border: 1px solid #d2d2d2; box-shadow: 0 2px 4px rgba(0,0,0,.12); background-color: #fff; color: #666;}
|
||||
.layui-laydate-header{border-bottom: 1px solid #e2e2e2;}
|
||||
.layui-laydate-header i:hover,
|
||||
.layui-laydate-header span:hover{color: #5FB878;}
|
||||
.layui-laydate-content{border-top: none 0; border-bottom: none 0;}
|
||||
.layui-laydate-content th{color: #333;}
|
||||
.layui-laydate-content td{color: #666;}
|
||||
.layui-laydate-content td.laydate-selected{background-color: #B5FFF8;}
|
||||
.laydate-selected:hover{background-color: #00F7DE !important;}
|
||||
.layui-laydate-content td:hover,
|
||||
.layui-laydate-list li:hover{background-color: #eee; color: #333;}
|
||||
.laydate-time-list li ol{margin: 0; padding: 0; border: 1px solid #e2e2e2; border-left-width: 0;}
|
||||
.laydate-time-list li:first-child ol{border-left-width: 1px;}
|
||||
.laydate-time-list>li:hover{background: none;}
|
||||
.layui-laydate-content .laydate-day-prev,
|
||||
.layui-laydate-content .laydate-day-next{color: #d2d2d2;}
|
||||
.laydate-selected.laydate-day-prev,
|
||||
.laydate-selected.laydate-day-next{background-color: #f8f8f8 !important;}
|
||||
.layui-laydate-footer{border-top: 1px solid #e2e2e2;}
|
||||
.layui-laydate-hint{color: #FF5722;}
|
||||
.laydate-day-mark::after{background-color: #5FB878;}
|
||||
.layui-laydate-content td.layui-this .laydate-day-mark::after{display: none;}
|
||||
.layui-laydate-footer span[lay-type="date"]{color: #5FB878;}
|
||||
.layui-laydate .layui-this{background-color: #009688 !important; color: #fff !important;}
|
||||
.layui-laydate .laydate-disabled,
|
||||
.layui-laydate .laydate-disabled:hover{background:none !important; color: #d2d2d2 !important; cursor: not-allowed !important; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none;}
|
||||
|
||||
/* 墨绿/自定义背景色主题 */
|
||||
.laydate-theme-molv{border: none;}
|
||||
.laydate-theme-molv.layui-laydate-range{width: 548px}
|
||||
.laydate-theme-molv .layui-laydate-main{width: 274px;}
|
||||
.laydate-theme-molv .layui-laydate-header{border: none; background-color: #009688;}
|
||||
.laydate-theme-molv .layui-laydate-header i,
|
||||
.laydate-theme-molv .layui-laydate-header span{color: #f6f6f6;}
|
||||
.laydate-theme-molv .layui-laydate-header i:hover,
|
||||
.laydate-theme-molv .layui-laydate-header span:hover{color: #fff;}
|
||||
.laydate-theme-molv .layui-laydate-content{border: 1px solid #e2e2e2; border-top: none; border-bottom: none;}
|
||||
.laydate-theme-molv .laydate-main-list-1 .layui-laydate-content{border-left: none;}
|
||||
.laydate-theme-molv .layui-laydate-footer{border: 1px solid #e2e2e2;}
|
||||
|
||||
/* 格子主题 */
|
||||
.laydate-theme-grid .layui-laydate-content td,
|
||||
.laydate-theme-grid .layui-laydate-content thead,
|
||||
.laydate-theme-grid .laydate-year-list>li,
|
||||
.laydate-theme-grid .laydate-month-list>li{border: 1px solid #e2e2e2;}
|
||||
.laydate-theme-grid .laydate-selected,
|
||||
.laydate-theme-grid .laydate-selected:hover{background-color: #f2f2f2 !important; color: #009688 !important;}
|
||||
.laydate-theme-grid .laydate-selected.laydate-day-prev,
|
||||
.laydate-theme-grid .laydate-selected.laydate-day-next{color: #d2d2d2 !important;}
|
||||
.laydate-theme-grid .laydate-year-list,
|
||||
.laydate-theme-grid .laydate-month-list{margin: 1px 0 0 1px;}
|
||||
.laydate-theme-grid .laydate-year-list>li,
|
||||
.laydate-theme-grid .laydate-month-list>li{margin: 0 -1px -1px 0;}
|
||||
.laydate-theme-grid .laydate-year-list>li{height: 43px; line-height: 43px;}
|
||||
.laydate-theme-grid .laydate-month-list>li{height: 71px; line-height: 71px;}
|
||||
|
||||
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 11 KiB |
@@ -1,179 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name: layer
|
||||
|
||||
**/
|
||||
|
||||
/* *html{background-image: url(about:blank); background-attachment: fixed;} */
|
||||
html #layuicss-layer{display: none; position: absolute; width: 1989px;}
|
||||
|
||||
/* common */
|
||||
.layui-layer-shade, .layui-layer{position:fixed; _position:absolute; pointer-events: auto;}
|
||||
.layui-layer-shade{top:0; left:0; width:100%; height:100%; _height:expression(document.body.offsetHeight+"px");}
|
||||
.layui-layer{-webkit-overflow-scrolling: touch;}
|
||||
.layui-layer{top:150px; left: 0; margin:0; padding:0; background-color:#fff; -webkit-background-clip: content; border-radius: 2px; box-shadow: 1px 1px 50px rgba(0,0,0,.3);}
|
||||
.layui-layer-close{position:absolute;}
|
||||
.layui-layer-content{position:relative;}
|
||||
.layui-layer-border{border: 1px solid #B2B2B2; border: 1px solid rgba(0,0,0,.1); box-shadow: 1px 1px 5px rgba(0,0,0,.2);}
|
||||
.layui-layer-load{background:url(loading-1.gif) #eee center center no-repeat;}
|
||||
.layui-layer-ico{ background:url(icon.png) no-repeat;}
|
||||
.layui-layer-dialog .layui-layer-ico,
|
||||
.layui-layer-setwin a,
|
||||
.layui-layer-btn a{display:inline-block; *display:inline; *zoom:1; vertical-align:top;}
|
||||
|
||||
.layui-layer-move{display: none; position: fixed; *position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; cursor: move; opacity: 0; filter:alpha(opacity=0); background-color: #fff; z-index: 2147483647;}
|
||||
.layui-layer-resize{position: absolute; width: 15px; height: 15px; right: 0; bottom: 0; cursor: se-resize;}
|
||||
|
||||
/* 动画 */
|
||||
.layer-anim{-webkit-animation-fill-mode: both; animation-fill-mode: both; -webkit-animation-duration:.3s; animation-duration:.3s;}
|
||||
|
||||
@-webkit-keyframes layer-bounceIn { /* 默认 */
|
||||
0% {opacity: 0; -webkit-transform: scale(.5); transform: scale(.5)}
|
||||
100% {opacity: 1; -webkit-transform: scale(1); transform: scale(1)}
|
||||
}
|
||||
@keyframes layer-bounceIn {
|
||||
0% {opacity: 0; -webkit-transform: scale(.5); -ms-transform: scale(.5); transform: scale(.5)}
|
||||
100% {opacity: 1; -webkit-transform: scale(1); -ms-transform: scale(1); transform: scale(1)}
|
||||
}
|
||||
.layer-anim-00{-webkit-animation-name: layer-bounceIn;animation-name: layer-bounceIn}
|
||||
|
||||
@-webkit-keyframes layer-zoomInDown{0%{opacity:0;-webkit-transform:scale(.1) translateY(-2000px);transform:scale(.1) translateY(-2000px);-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}60%{opacity:1;-webkit-transform:scale(.475) translateY(60px);transform:scale(.475) translateY(60px);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}}@keyframes layer-zoomInDown{0%{opacity:0;-webkit-transform:scale(.1) translateY(-2000px);-ms-transform:scale(.1) translateY(-2000px);transform:scale(.1) translateY(-2000px);-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}60%{opacity:1;-webkit-transform:scale(.475) translateY(60px);-ms-transform:scale(.475) translateY(60px);transform:scale(.475) translateY(60px);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}}.layer-anim-01{-webkit-animation-name:layer-zoomInDown;animation-name:layer-zoomInDown}
|
||||
|
||||
@-webkit-keyframes layer-fadeInUpBig{0%{opacity:0;-webkit-transform:translateY(2000px);transform:translateY(2000px)}100%{opacity:1;-webkit-transform:translateY(0);transform:translateY(0)}}@keyframes layer-fadeInUpBig{0%{opacity:0;-webkit-transform:translateY(2000px);-ms-transform:translateY(2000px);transform:translateY(2000px)}100%{opacity:1;-webkit-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0)}}.layer-anim-02{-webkit-animation-name:layer-fadeInUpBig;animation-name:layer-fadeInUpBig}
|
||||
|
||||
@-webkit-keyframes layer-zoomInLeft{0%{opacity:0;-webkit-transform:scale(.1) translateX(-2000px);transform:scale(.1) translateX(-2000px);-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}60%{opacity:1;-webkit-transform:scale(.475) translateX(48px);transform:scale(.475) translateX(48px);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}}@keyframes layer-zoomInLeft{0%{opacity:0;-webkit-transform:scale(.1) translateX(-2000px);-ms-transform:scale(.1) translateX(-2000px);transform:scale(.1) translateX(-2000px);-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}60%{opacity:1;-webkit-transform:scale(.475) translateX(48px);-ms-transform:scale(.475) translateX(48px);transform:scale(.475) translateX(48px);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}}.layer-anim-03{-webkit-animation-name:layer-zoomInLeft;animation-name:layer-zoomInLeft}
|
||||
|
||||
@-webkit-keyframes layer-rollIn{0%{opacity:0;-webkit-transform:translateX(-100%) rotate(-120deg);transform:translateX(-100%) rotate(-120deg)}100%{opacity:1;-webkit-transform:translateX(0px) rotate(0deg);transform:translateX(0px) rotate(0deg)}}@keyframes layer-rollIn{0%{opacity:0;-webkit-transform:translateX(-100%) rotate(-120deg);-ms-transform:translateX(-100%) rotate(-120deg);transform:translateX(-100%) rotate(-120deg)}100%{opacity:1;-webkit-transform:translateX(0px) rotate(0deg);-ms-transform:translateX(0px) rotate(0deg);transform:translateX(0px) rotate(0deg)}}.layer-anim-04{-webkit-animation-name:layer-rollIn;animation-name:layer-rollIn}
|
||||
|
||||
@keyframes layer-fadeIn{0%{opacity:0}100%{opacity:1}}.layer-anim-05{-webkit-animation-name:layer-fadeIn;animation-name:layer-fadeIn}
|
||||
|
||||
@-webkit-keyframes layer-shake{0%,100%{-webkit-transform:translateX(0);transform:translateX(0)}10%,30%,50%,70%,90%{-webkit-transform:translateX(-10px);transform:translateX(-10px)}20%,40%,60%,80%{-webkit-transform:translateX(10px);transform:translateX(10px)}}@keyframes layer-shake{0%,100%{-webkit-transform:translateX(0);-ms-transform:translateX(0);transform:translateX(0)}10%,30%,50%,70%,90%{-webkit-transform:translateX(-10px);-ms-transform:translateX(-10px);transform:translateX(-10px)}20%,40%,60%,80%{-webkit-transform:translateX(10px);-ms-transform:translateX(10px);transform:translateX(10px)}}.layer-anim-06{-webkit-animation-name:layer-shake;animation-name:layer-shake}@-webkit-keyframes fadeIn{0%{opacity:0}100%{opacity:1}}
|
||||
|
||||
/* 标题栏 */
|
||||
.layui-layer-title{padding:0 80px 0 20px; height: 50px; line-height: 50px; border-bottom:1px solid #F0F0F0; font-size: 14px; color:#333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 2px 2px 0 0;}
|
||||
.layui-layer-setwin{position:absolute; right: 15px; *right:0; top: 17px; font-size:0; line-height: initial;}
|
||||
.layui-layer-setwin a{position:relative; width: 16px; height:16px; margin-left:10px; font-size:12px; _overflow:hidden;}
|
||||
.layui-layer-setwin .layui-layer-min cite{position:absolute; width:14px; height:2px; left:0; top:50%; margin-top:-1px; background-color:#2E2D3C; cursor:pointer; _overflow:hidden;}
|
||||
.layui-layer-setwin .layui-layer-min:hover cite{background-color:#2D93CA; }
|
||||
.layui-layer-setwin .layui-layer-max{background-position:-32px -40px;}
|
||||
.layui-layer-setwin .layui-layer-max:hover{background-position:-16px -40px;}
|
||||
.layui-layer-setwin .layui-layer-maxmin{background-position:-65px -40px;}
|
||||
.layui-layer-setwin .layui-layer-maxmin:hover{background-position:-49px -40px;}
|
||||
.layui-layer-setwin .layui-layer-close1{background-position: 1px -40px; cursor: pointer;}
|
||||
.layui-layer-setwin .layui-layer-close1:hover{opacity:0.7;}
|
||||
.layui-layer-setwin .layui-layer-close2{position:absolute; right:-28px; top:-28px; width:30px; height:30px; margin-left:0; background-position:-149px -31px; *right:-18px; _display:none;}
|
||||
.layui-layer-setwin .layui-layer-close2:hover{ background-position:-180px -31px;}
|
||||
|
||||
/* 按钮栏 */
|
||||
.layui-layer-btn{text-align: right; padding: 0 15px 12px; pointer-events: auto; user-select: none; -webkit-user-select: none;}
|
||||
.layui-layer-btn a{height: 28px; line-height: 28px; margin: 5px 5px 0; padding: 0 15px; border: 1px solid #dedede; background-color:#fff; color: #333; border-radius: 2px; font-weight:400; cursor:pointer; text-decoration: none;}
|
||||
.layui-layer-btn a:hover{opacity: 0.9; text-decoration: none;}
|
||||
.layui-layer-btn a:active{opacity: 0.8;}
|
||||
.layui-layer-btn .layui-layer-btn0{border-color: #1E9FFF; background-color: #1E9FFF; color:#fff;}
|
||||
.layui-layer-btn-l{text-align: left;}
|
||||
.layui-layer-btn-c{text-align: center;}
|
||||
|
||||
/* 定制化 */
|
||||
.layui-layer-dialog{min-width: 300px;}
|
||||
.layui-layer-dialog .layui-layer-content{position: relative; padding:20px; line-height:24px; word-break: break-all; overflow:hidden; font-size:14px; overflow-x: hidden; overflow-y:auto;}
|
||||
.layui-layer-dialog .layui-layer-content .layui-layer-ico{position:absolute; top:16px; left:15px; _left:-40px; width:30px; height:30px;}
|
||||
.layui-layer-ico1{background-position:-30px 0 }
|
||||
.layui-layer-ico2{background-position:-60px 0;}
|
||||
.layui-layer-ico3{background-position:-90px 0;}
|
||||
.layui-layer-ico4{background-position:-120px 0;}
|
||||
.layui-layer-ico5{background-position:-150px 0;}
|
||||
.layui-layer-ico6{background-position:-180px 0;}
|
||||
.layui-layer-rim{border:6px solid #8D8D8D; border:6px solid rgba(0,0,0,.3); border-radius:5px; box-shadow: none;}
|
||||
.layui-layer-msg{min-width:180px; border:1px solid #D3D4D3; box-shadow: none;}
|
||||
.layui-layer-hui{min-width:100px; background-color: #000; filter:alpha(opacity=60); background-color: rgba(0,0,0,0.6); color: #fff; border:none;}
|
||||
.layui-layer-hui .layui-layer-content{padding:12px 25px; text-align:center;}
|
||||
.layui-layer-dialog .layui-layer-padding{padding: 20px 20px 20px 55px; text-align: left;}
|
||||
.layui-layer-page .layui-layer-content{position:relative; overflow:auto;}
|
||||
.layui-layer-page .layui-layer-btn,.layui-layer-iframe .layui-layer-btn{padding-top:10px;}
|
||||
.layui-layer-nobg{background:none;}
|
||||
.layui-layer-iframe iframe{display: block; width: 100%;}
|
||||
|
||||
.layui-layer-loading{border-radius:100%; background:none; box-shadow:none; border:none;}
|
||||
.layui-layer-loading .layui-layer-content{width:60px; height:24px; background:url(loading-0.gif) no-repeat;}
|
||||
.layui-layer-loading .layui-layer-loading1{width:37px; height:37px; background:url(loading-1.gif) no-repeat;}
|
||||
.layui-layer-loading .layui-layer-loading2, .layui-layer-ico16{width:32px; height:32px; background:url(loading-2.gif) no-repeat;}
|
||||
.layui-layer-tips{background: none; box-shadow:none; border:none;}
|
||||
.layui-layer-tips .layui-layer-content{position: relative; line-height: 22px; min-width: 12px; padding: 8px 15px; font-size: 12px; _float:left; border-radius: 2px; box-shadow: 1px 1px 3px rgba(0,0,0,.2); background-color: #000; color: #fff;}
|
||||
.layui-layer-tips .layui-layer-close{right:-2px; top:-1px;}
|
||||
.layui-layer-tips i.layui-layer-TipsG{ position:absolute; width:0; height:0; border-width:8px; border-color:transparent; border-style:dashed; *overflow:hidden;}
|
||||
.layui-layer-tips i.layui-layer-TipsT, .layui-layer-tips i.layui-layer-TipsB{left:5px; border-right-style:solid; border-right-color: #000;}
|
||||
.layui-layer-tips i.layui-layer-TipsT{bottom:-8px;}
|
||||
.layui-layer-tips i.layui-layer-TipsB{top:-8px;}
|
||||
.layui-layer-tips i.layui-layer-TipsR, .layui-layer-tips i.layui-layer-TipsL{top: 5px; border-bottom-style:solid; border-bottom-color: #000;}
|
||||
.layui-layer-tips i.layui-layer-TipsR{left:-8px;}
|
||||
.layui-layer-tips i.layui-layer-TipsL{right:-8px;}
|
||||
|
||||
/* skin */
|
||||
.layui-layer-lan[type="dialog"]{min-width:280px;}
|
||||
.layui-layer-lan .layui-layer-title{background:#4476A7; color:#fff; border: none;}
|
||||
.layui-layer-lan .layui-layer-btn{padding: 5px 10px 10px; text-align: right; border-top:1px solid #E9E7E7}
|
||||
.layui-layer-lan .layui-layer-btn a{background: #fff; border-color: #E9E7E7; color: #333;}
|
||||
.layui-layer-lan .layui-layer-btn .layui-layer-btn1{background:#C9C5C5;}
|
||||
.layui-layer-molv .layui-layer-title{background: #009f95; color:#fff; border: none;}
|
||||
.layui-layer-molv .layui-layer-btn a{background: #009f95; border-color: #009f95;}
|
||||
.layui-layer-molv .layui-layer-btn .layui-layer-btn1{background:#92B8B1;}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@Name: layer拓展样式
|
||||
|
||||
*/
|
||||
|
||||
.layui-layer-iconext{background:url(icon-ext.png) no-repeat;}
|
||||
|
||||
/* prompt模式 */
|
||||
.layui-layer-prompt .layui-layer-input{display: block; width: 260px; height: 36px; margin: 0 auto; line-height: 30px; padding-left: 10px; border: 1px solid #e6e6e6; color: #333;}
|
||||
.layui-layer-prompt textarea.layui-layer-input{width: 300px; height: 100px; line-height: 20px; padding: 6px 10px;}
|
||||
.layui-layer-prompt .layui-layer-content{padding: 20px;}
|
||||
.layui-layer-prompt .layui-layer-btn{padding-top: 0;}
|
||||
|
||||
/* tab模式 */
|
||||
.layui-layer-tab{box-shadow:1px 1px 50px rgba(0,0,0,.4);}
|
||||
.layui-layer-tab .layui-layer-title{padding-left:0; overflow: visible;}
|
||||
.layui-layer-tab .layui-layer-title span{position:relative; float:left; min-width:80px; max-width: 300px; padding:0 20px; text-align:center; cursor:default; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; cursor: pointer;}
|
||||
.layui-layer-tab .layui-layer-title span.layui-this{height: 51px; border-left: 1px solid #eee; border-right: 1px solid #eee; background-color: #fff; z-index: 10;}
|
||||
.layui-layer-tab .layui-layer-title span:first-child{border-left:none;}
|
||||
.layui-layer-tabmain{line-height:24px; clear:both;}
|
||||
.layui-layer-tabmain .layui-layer-tabli{display:none;}
|
||||
.layui-layer-tabmain .layui-layer-tabli.layui-this{display: block;}
|
||||
|
||||
/* photo模式 */
|
||||
.layui-layer-photos{background: none; box-shadow: none;}
|
||||
.layui-layer-photos .layui-layer-content{overflow:hidden; text-align: center;}
|
||||
.layui-layer-photos .layui-layer-phimg img{position: relative; width:100%; display: inline-block; *display:inline; *zoom:1; vertical-align:top;}
|
||||
.layui-layer-imgprev, .layui-layer-imgnext{position: fixed; top: 50%; width: 27px; _width: 44px; height: 44px; margin-top:-22px; outline:none;blr:expression(this.onFocus=this.blur());}
|
||||
.layui-layer-imgprev{left: 30px; background-position:-5px -5px; _background-position:-70px -5px;}
|
||||
.layui-layer-imgprev:hover{background-position:-33px -5px; _background-position:-120px -5px;}
|
||||
.layui-layer-imgnext{right: 30px; _right:8px; background-position:-5px -50px; _background-position:-70px -50px;}
|
||||
.layui-layer-imgnext:hover{background-position: -33px -50px; _background-position: -120px -50px;}
|
||||
.layui-layer-imgbar{position: fixed; left:0; right: 0; bottom:0; width:100%; height: 40px; line-height: 40px; background-color:#000\9; filter:Alpha(opacity=60); background-color: rgba(2,0,0,.35); color: #fff; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; font-size:0;}
|
||||
.layui-layer-imgtit{/*position:absolute; left:20px;*/}
|
||||
.layui-layer-imgtit *{display:inline-block; *display:inline; *zoom:1; vertical-align:top; font-size:12px;}
|
||||
.layui-layer-imgtit a{max-width:65%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; color:#fff;}
|
||||
.layui-layer-imgtit a:hover{color:#fff; text-decoration:underline;}
|
||||
.layui-layer-imgtit em{padding-left:10px; font-style: normal;}
|
||||
|
||||
/* 关闭动画 */
|
||||
@-webkit-keyframes layer-bounceOut {
|
||||
100% {opacity: 0; -webkit-transform: scale(.7); transform: scale(.7)}
|
||||
30% {-webkit-transform: scale(1.05); transform: scale(1.05)}
|
||||
0% {-webkit-transform: scale(1); transform: scale(1);}
|
||||
}
|
||||
@keyframes layer-bounceOut {
|
||||
100% {opacity: 0; -webkit-transform: scale(.7); -ms-transform: scale(.7); transform: scale(.7);}
|
||||
30% {-webkit-transform: scale(1.05); -ms-transform: scale(1.05); transform: scale(1.05);}
|
||||
0% {-webkit-transform: scale(1); -ms-transform: scale(1);transform: scale(1);}
|
||||
}
|
||||
.layer-anim-close{-webkit-animation-name: layer-bounceOut; animation-name: layer-bounceOut; -webkit-animation-fill-mode: both; animation-fill-mode: both; -webkit-animation-duration:.2s; animation-duration:.2s;}
|
||||
|
||||
@media screen and (max-width: 1100px) {
|
||||
.layui-layer-iframe{overflow-y: auto; -webkit-overflow-scrolling: touch;}
|
||||
}
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 701 B |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 299 KiB |
@@ -1,754 +0,0 @@
|
||||
|
||||
/*!
|
||||
* Layui
|
||||
* Classic modular Front-End UI library
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
;!function(win){
|
||||
"use strict";
|
||||
|
||||
var doc = win.document, config = {
|
||||
modules: {} //记录模块物理路径
|
||||
,status: {} //记录模块加载状态
|
||||
,timeout: 10 //符合规范的模块请求最长等待秒数
|
||||
,event: {} //记录模块自定义事件
|
||||
}
|
||||
|
||||
,Layui = function(){
|
||||
this.v = '2.6.8'; // layui 版本号
|
||||
}
|
||||
|
||||
//识别预先可能定义的指定全局对象
|
||||
,GLOBAL = win.LAYUI_GLOBAL || {}
|
||||
|
||||
//获取 layui 所在目录
|
||||
,getPath = function(){
|
||||
var jsPath = doc.currentScript ? doc.currentScript.src : function(){
|
||||
var js = doc.scripts
|
||||
,last = js.length - 1
|
||||
,src;
|
||||
for(var i = last; i > 0; i--){
|
||||
if(js[i].readyState === 'interactive'){
|
||||
src = js[i].src;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return src || js[last].src;
|
||||
}();
|
||||
|
||||
return config.dir = GLOBAL.dir || jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
|
||||
}()
|
||||
|
||||
//异常提示
|
||||
,error = function(msg, type){
|
||||
type = type || 'log';
|
||||
win.console && console[type] && console[type]('layui error hint: ' + msg);
|
||||
}
|
||||
|
||||
,isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]'
|
||||
|
||||
//内置模块
|
||||
,modules = config.builtin = {
|
||||
lay: 'lay' //基础 DOM 操作
|
||||
,layer: 'layer' //弹层
|
||||
,laydate: 'laydate' //日期
|
||||
,laypage: 'laypage' //分页
|
||||
,laytpl: 'laytpl' //模板引擎
|
||||
,layedit: 'layedit' //富文本编辑器
|
||||
,form: 'form' //表单集
|
||||
,upload: 'upload' //上传
|
||||
,dropdown: 'dropdown' //下拉菜单
|
||||
,transfer: 'transfer' //穿梭框
|
||||
,tree: 'tree' //树结构
|
||||
,table: 'table' //表格
|
||||
,element: 'element' //常用元素操作
|
||||
,rate: 'rate' //评分组件
|
||||
,colorpicker: 'colorpicker' //颜色选择器
|
||||
,slider: 'slider' //滑块
|
||||
,carousel: 'carousel' //轮播
|
||||
,flow: 'flow' //流加载
|
||||
,util: 'util' //工具块
|
||||
,code: 'code' //代码修饰器
|
||||
,jquery: 'jquery' //DOM 库(第三方)
|
||||
|
||||
,all: 'all'
|
||||
,'layui.all': 'layui.all' //聚合标识(功能性的,非真实模块)
|
||||
};
|
||||
|
||||
//记录基础数据
|
||||
Layui.prototype.cache = config;
|
||||
|
||||
//定义模块
|
||||
Layui.prototype.define = function(deps, factory){
|
||||
var that = this
|
||||
,type = typeof deps === 'function'
|
||||
,callback = function(){
|
||||
var setApp = function(app, exports){
|
||||
layui[app] = exports;
|
||||
config.status[app] = true;
|
||||
};
|
||||
typeof factory === 'function' && factory(function(app, exports){
|
||||
setApp(app, exports);
|
||||
config.callback[app] = function(){
|
||||
factory(setApp);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
type && (
|
||||
factory = deps,
|
||||
deps = []
|
||||
);
|
||||
|
||||
that.use(deps, callback, null, 'define');
|
||||
return that;
|
||||
};
|
||||
|
||||
//使用特定模块
|
||||
Layui.prototype.use = function(apps, callback, exports, from){
|
||||
var that = this
|
||||
,dir = config.dir = config.dir ? config.dir : getPath
|
||||
,head = doc.getElementsByTagName('head')[0];
|
||||
|
||||
apps = function(){
|
||||
if(typeof apps === 'string'){
|
||||
return [apps];
|
||||
}
|
||||
//当第一个参数为 function 时,则自动加载所有内置模块,且执行的回调即为该 function 参数;
|
||||
else if(typeof apps === 'function'){
|
||||
callback = apps;
|
||||
return ['all'];
|
||||
}
|
||||
return apps;
|
||||
}();
|
||||
|
||||
//如果页面已经存在 jQuery 1.7+ 库且所定义的模块依赖 jQuery,则不加载内部 jquery 模块
|
||||
if(win.jQuery && jQuery.fn.on){
|
||||
that.each(apps, function(index, item){
|
||||
if(item === 'jquery'){
|
||||
apps.splice(index, 1);
|
||||
}
|
||||
});
|
||||
layui.jquery = layui.$ = jQuery;
|
||||
}
|
||||
|
||||
var item = apps[0]
|
||||
,timeout = 0;
|
||||
exports = exports || [];
|
||||
|
||||
//静态资源host
|
||||
config.host = config.host || (dir.match(/\/\/([\s\S]+?)\//)||['//'+ location.host +'/'])[0];
|
||||
|
||||
//加载完毕
|
||||
function onScriptLoad(e, url){
|
||||
var readyRegExp = navigator.platform === 'PLaySTATION 3' ? /^complete$/ : /^(complete|loaded)$/
|
||||
if (e.type === 'load' || (readyRegExp.test((e.currentTarget || e.srcElement).readyState))) {
|
||||
config.modules[item] = url;
|
||||
head.removeChild(node);
|
||||
(function poll() {
|
||||
if(++timeout > config.timeout * 1000 / 4){
|
||||
return error(item + ' is not a valid module', 'error');
|
||||
};
|
||||
config.status[item] ? onCallback() : setTimeout(poll, 4);
|
||||
}());
|
||||
}
|
||||
}
|
||||
|
||||
//回调
|
||||
function onCallback(){
|
||||
exports.push(layui[item]);
|
||||
apps.length > 1 ?
|
||||
that.use(apps.slice(1), callback, exports, from)
|
||||
: ( typeof callback === 'function' && function(){
|
||||
//保证文档加载完毕再执行回调
|
||||
if(layui.jquery && typeof layui.jquery === 'function' && from !== 'define'){
|
||||
return layui.jquery(function(){
|
||||
callback.apply(layui, exports);
|
||||
});
|
||||
}
|
||||
callback.apply(layui, exports);
|
||||
}() );
|
||||
}
|
||||
|
||||
//如果引入了聚合板,内置的模块则不必重复加载
|
||||
if( apps.length === 0 || (layui['layui.all'] && modules[item]) ){
|
||||
return onCallback(), that;
|
||||
}
|
||||
|
||||
//获取加载的模块 URL
|
||||
//如果是内置模块,则按照 dir 参数拼接模块路径
|
||||
//如果是扩展模块,则判断模块路径值是否为 {/} 开头,
|
||||
//如果路径值是 {/} 开头,则模块路径即为后面紧跟的字符。
|
||||
//否则,则按照 base 参数拼接模块路径
|
||||
|
||||
var url = ( modules[item] ? (dir + 'modules/')
|
||||
: (/^\{\/\}/.test(that.modules[item]) ? '' : (config.base || ''))
|
||||
) + (that.modules[item] || item) + '.js';
|
||||
url = url.replace(/^\{\/\}/, '');
|
||||
|
||||
//如果扩展模块(即:非内置模块)对象已经存在,则不必再加载
|
||||
if(!config.modules[item] && layui[item]){
|
||||
config.modules[item] = url; //并记录起该扩展模块的 url
|
||||
}
|
||||
|
||||
//首次加载模块
|
||||
if(!config.modules[item]){
|
||||
var node = doc.createElement('script');
|
||||
|
||||
node.async = true;
|
||||
node.charset = 'utf-8';
|
||||
node.src = url + function(){
|
||||
var version = config.version === true
|
||||
? (config.v || (new Date()).getTime())
|
||||
: (config.version||'');
|
||||
return version ? ('?v=' + version) : '';
|
||||
}();
|
||||
|
||||
head.appendChild(node);
|
||||
|
||||
if(node.attachEvent && !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && !isOpera){
|
||||
node.attachEvent('onreadystatechange', function(e){
|
||||
onScriptLoad(e, url);
|
||||
});
|
||||
} else {
|
||||
node.addEventListener('load', function(e){
|
||||
onScriptLoad(e, url);
|
||||
}, false);
|
||||
}
|
||||
|
||||
config.modules[item] = url;
|
||||
} else { //缓存
|
||||
(function poll() {
|
||||
if(++timeout > config.timeout * 1000 / 4){
|
||||
return error(item + ' is not a valid module', 'error');
|
||||
};
|
||||
(typeof config.modules[item] === 'string' && config.status[item])
|
||||
? onCallback()
|
||||
: setTimeout(poll, 4);
|
||||
}());
|
||||
}
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
//获取节点的 style 属性值
|
||||
Layui.prototype.getStyle = function(node, name){
|
||||
var style = node.currentStyle ? node.currentStyle : win.getComputedStyle(node, null);
|
||||
return style[style.getPropertyValue ? 'getPropertyValue' : 'getAttribute'](name);
|
||||
};
|
||||
|
||||
//css外部加载器
|
||||
Layui.prototype.link = function(href, fn, cssname){
|
||||
var that = this
|
||||
,head = doc.getElementsByTagName('head')[0]
|
||||
,link = doc.createElement('link');
|
||||
|
||||
if(typeof fn === 'string') cssname = fn;
|
||||
|
||||
var app = (cssname || href).replace(/\.|\//g, '')
|
||||
,id = link.id = 'layuicss-'+ app
|
||||
,STAUTS_NAME = 'creating'
|
||||
,timeout = 0;
|
||||
|
||||
link.rel = 'stylesheet';
|
||||
link.href = href + (config.debug ? '?v='+new Date().getTime() : '');
|
||||
link.media = 'all';
|
||||
|
||||
if(!doc.getElementById(id)){
|
||||
head.appendChild(link);
|
||||
}
|
||||
|
||||
if(typeof fn !== 'function') return that;
|
||||
|
||||
//轮询 css 是否加载完毕
|
||||
(function poll(status) {
|
||||
var delay = 100
|
||||
,getLinkElem = doc.getElementById(id); //获取动态插入的 link 元素
|
||||
|
||||
//如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范
|
||||
if(++timeout > config.timeout * 1000 / delay){
|
||||
return error(href + ' timeout');
|
||||
};
|
||||
|
||||
//css 加载就绪
|
||||
if(parseInt(that.getStyle(getLinkElem, 'width')) === 1989){
|
||||
//如果参数来自于初始轮询(即未加载就绪时的),则移除 link 标签状态
|
||||
if(status === STAUTS_NAME) getLinkElem.removeAttribute('lay-status');
|
||||
//如果 link 标签的状态仍为「创建中」,则继续进入轮询,直到状态改变,则执行回调
|
||||
getLinkElem.getAttribute('lay-status') === STAUTS_NAME ? setTimeout(poll, delay) : fn();
|
||||
} else {
|
||||
getLinkElem.setAttribute('lay-status', STAUTS_NAME);
|
||||
setTimeout(function(){
|
||||
poll(STAUTS_NAME);
|
||||
}, delay);
|
||||
}
|
||||
}());
|
||||
|
||||
//轮询css是否加载完毕
|
||||
/*
|
||||
(function poll() {
|
||||
if(++timeout > config.timeout * 1000 / 100){
|
||||
return error(href + ' timeout');
|
||||
};
|
||||
parseInt(that.getStyle(doc.getElementById(id), 'width')) === 1989 ? function(){
|
||||
fn();
|
||||
}() : setTimeout(poll, 100);
|
||||
}());
|
||||
*/
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
//css 内部加载器
|
||||
Layui.prototype.addcss = function(firename, fn, cssname){
|
||||
return layui.link(config.dir + 'css/' + firename, fn, cssname);
|
||||
};
|
||||
|
||||
//存储模块的回调
|
||||
config.callback = {};
|
||||
|
||||
//重新执行模块的工厂函数
|
||||
Layui.prototype.factory = function(modName){
|
||||
if(layui[modName]){
|
||||
return typeof config.callback[modName] === 'function'
|
||||
? config.callback[modName]
|
||||
: null;
|
||||
}
|
||||
};
|
||||
|
||||
//图片预加载
|
||||
Layui.prototype.img = function(url, callback, error) {
|
||||
var img = new Image();
|
||||
img.src = url;
|
||||
if(img.complete){
|
||||
return callback(img);
|
||||
}
|
||||
img.onload = function(){
|
||||
img.onload = null;
|
||||
typeof callback === 'function' && callback(img);
|
||||
};
|
||||
img.onerror = function(e){
|
||||
img.onerror = null;
|
||||
typeof error === 'function' && error(e);
|
||||
};
|
||||
};
|
||||
|
||||
//全局配置
|
||||
Layui.prototype.config = function(options){
|
||||
options = options || {};
|
||||
for(var key in options){
|
||||
config[key] = options[key];
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
//记录全部模块
|
||||
Layui.prototype.modules = function(){
|
||||
var clone = {};
|
||||
for(var o in modules){
|
||||
clone[o] = modules[o];
|
||||
}
|
||||
return clone;
|
||||
}();
|
||||
|
||||
//拓展模块
|
||||
Layui.prototype.extend = function(options){
|
||||
var that = this;
|
||||
|
||||
//验证模块是否被占用
|
||||
options = options || {};
|
||||
for(var o in options){
|
||||
if(that[o] || that.modules[o]){
|
||||
error(o+ ' Module already exists', 'error');
|
||||
} else {
|
||||
that.modules[o] = options[o];
|
||||
}
|
||||
}
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
// location.hash 路由解析
|
||||
Layui.prototype.router = function(hash){
|
||||
var that = this
|
||||
,hash = hash || location.hash
|
||||
,data = {
|
||||
path: []
|
||||
,search: {}
|
||||
,hash: (hash.match(/[^#](#.*$)/) || [])[1] || ''
|
||||
};
|
||||
|
||||
if(!/^#\//.test(hash)) return data; //禁止非路由规范
|
||||
hash = hash.replace(/^#\//, '');
|
||||
data.href = '/' + hash;
|
||||
hash = hash.replace(/([^#])(#.*$)/, '$1').split('/') || [];
|
||||
|
||||
//提取 Hash 结构
|
||||
that.each(hash, function(index, item){
|
||||
/^\w+=/.test(item) ? function(){
|
||||
item = item.split('=');
|
||||
data.search[item[0]] = item[1];
|
||||
}() : data.path.push(item);
|
||||
});
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
//URL 解析
|
||||
Layui.prototype.url = function(href){
|
||||
var that = this
|
||||
,data = {
|
||||
//提取 url 路径
|
||||
pathname: function(){
|
||||
var pathname = href
|
||||
? function(){
|
||||
var str = (href.match(/\.[^.]+?\/.+/) || [])[0] || '';
|
||||
return str.replace(/^[^\/]+/, '').replace(/\?.+/, '');
|
||||
}()
|
||||
: location.pathname;
|
||||
return pathname.replace(/^\//, '').split('/');
|
||||
}()
|
||||
|
||||
//提取 url 参数
|
||||
,search: function(){
|
||||
var obj = {}
|
||||
,search = (href
|
||||
? function(){
|
||||
var str = (href.match(/\?.+/) || [])[0] || '';
|
||||
return str.replace(/\#.+/, '');
|
||||
}()
|
||||
: location.search
|
||||
).replace(/^\?+/, '').split('&'); //去除 ?,按 & 分割参数
|
||||
|
||||
//遍历分割后的参数
|
||||
that.each(search, function(index, item){
|
||||
var _index = item.indexOf('=')
|
||||
,key = function(){ //提取 key
|
||||
if(_index < 0){
|
||||
return item.substr(0, item.length);
|
||||
} else if(_index === 0){
|
||||
return false;
|
||||
} else {
|
||||
return item.substr(0, _index);
|
||||
}
|
||||
}();
|
||||
//提取 value
|
||||
if(key){
|
||||
obj[key] = _index > 0 ? item.substr(_index + 1) : null;
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
}()
|
||||
|
||||
//提取 Hash
|
||||
,hash: that.router(function(){
|
||||
return href
|
||||
? ((href.match(/#.+/) || [])[0] || '/')
|
||||
: location.hash;
|
||||
}())
|
||||
};
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
//本地持久性存储
|
||||
Layui.prototype.data = function(table, settings, storage){
|
||||
table = table || 'layui';
|
||||
storage = storage || localStorage;
|
||||
|
||||
if(!win.JSON || !win.JSON.parse) return;
|
||||
|
||||
//如果settings为null,则删除表
|
||||
if(settings === null){
|
||||
return delete storage[table];
|
||||
}
|
||||
|
||||
settings = typeof settings === 'object'
|
||||
? settings
|
||||
: {key: settings};
|
||||
|
||||
try{
|
||||
var data = JSON.parse(storage[table]);
|
||||
} catch(e){
|
||||
var data = {};
|
||||
}
|
||||
|
||||
if('value' in settings) data[settings.key] = settings.value;
|
||||
if(settings.remove) delete data[settings.key];
|
||||
storage[table] = JSON.stringify(data);
|
||||
|
||||
return settings.key ? data[settings.key] : data;
|
||||
};
|
||||
|
||||
//本地会话性存储
|
||||
Layui.prototype.sessionData = function(table, settings){
|
||||
return this.data(table, settings, sessionStorage);
|
||||
}
|
||||
|
||||
//设备信息
|
||||
Layui.prototype.device = function(key){
|
||||
var agent = navigator.userAgent.toLowerCase()
|
||||
|
||||
//获取版本号
|
||||
,getVersion = function(label){
|
||||
var exp = new RegExp(label + '/([^\\s\\_\\-]+)');
|
||||
label = (agent.match(exp)||[])[1];
|
||||
return label || false;
|
||||
}
|
||||
|
||||
//返回结果集
|
||||
,result = {
|
||||
os: function(){ //底层操作系统
|
||||
if(/windows/.test(agent)){
|
||||
return 'windows';
|
||||
} else if(/linux/.test(agent)){
|
||||
return 'linux';
|
||||
} else if(/iphone|ipod|ipad|ios/.test(agent)){
|
||||
return 'ios';
|
||||
} else if(/mac/.test(agent)){
|
||||
return 'mac';
|
||||
}
|
||||
}()
|
||||
,ie: function(){ //ie版本
|
||||
return (!!win.ActiveXObject || "ActiveXObject" in win) ? (
|
||||
(agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于ie11并没有msie的标识
|
||||
) : false;
|
||||
}()
|
||||
,weixin: getVersion('micromessenger') //是否微信
|
||||
};
|
||||
|
||||
//任意的key
|
||||
if(key && !result[key]){
|
||||
result[key] = getVersion(key);
|
||||
}
|
||||
|
||||
//移动设备
|
||||
result.android = /android/.test(agent);
|
||||
result.ios = result.os === 'ios';
|
||||
result.mobile = (result.android || result.ios) ? true : false;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
//提示
|
||||
Layui.prototype.hint = function(){
|
||||
return {
|
||||
error: error
|
||||
};
|
||||
};
|
||||
|
||||
//typeof 类型细分 -> string/number/boolean/undefined/null、object/array/function/…
|
||||
Layui.prototype._typeof = function(operand){
|
||||
if(operand === null) return String(operand);
|
||||
|
||||
//细分引用类型
|
||||
return (typeof operand === 'object' || typeof operand === 'function') ? function(){
|
||||
var type = Object.prototype.toString.call(operand).match(/\s(.+)\]$/) || [] //匹配类型字符
|
||||
,classType = 'Function|Array|Date|RegExp|Object|Error|Symbol'; //常见类型字符
|
||||
|
||||
type = type[1] || 'Object';
|
||||
|
||||
//除匹配到的类型外,其他对象均返回 object
|
||||
return new RegExp('\\b('+ classType + ')\\b').test(type)
|
||||
? type.toLowerCase()
|
||||
: 'object';
|
||||
}() : typeof operand;
|
||||
};
|
||||
|
||||
//对象是否具备数组结构(此处为兼容 jQuery 对象)
|
||||
Layui.prototype._isArray = function(obj){
|
||||
var that = this
|
||||
,len
|
||||
,type = that._typeof(obj);
|
||||
|
||||
if(!obj || (typeof obj !== 'object') || obj === win) return false;
|
||||
|
||||
len = 'length' in obj && obj.length; //兼容 ie
|
||||
return type === 'array' || len === 0 || (
|
||||
typeof len === 'number' && len > 0 && (len - 1) in obj //兼容 jQuery 对象
|
||||
);
|
||||
};
|
||||
|
||||
//遍历
|
||||
Layui.prototype.each = function(obj, fn){
|
||||
var key
|
||||
,that = this
|
||||
,callFn = function(key, obj){ //回调
|
||||
return fn.call(obj[key], key, obj[key])
|
||||
};
|
||||
|
||||
if(typeof fn !== 'function') return that;
|
||||
obj = obj || [];
|
||||
|
||||
//优先处理数组结构
|
||||
if(that._isArray(obj)){
|
||||
for(key = 0; key < obj.length; key++){
|
||||
if(callFn(key, obj)) break;
|
||||
}
|
||||
} else {
|
||||
for(key in obj){
|
||||
if(callFn(key, obj)) break;
|
||||
}
|
||||
}
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
//将数组中的对象按其某个成员排序
|
||||
Layui.prototype.sort = function(obj, key, desc){
|
||||
var clone = JSON.parse(
|
||||
JSON.stringify(obj || [])
|
||||
);
|
||||
|
||||
if(!key) return clone;
|
||||
|
||||
//如果是数字,按大小排序;如果是非数字,则按字典序排序
|
||||
clone.sort(function(o1, o2){
|
||||
var v1 = o1[key]
|
||||
,v2 = o2[key]
|
||||
,isNum = [
|
||||
!isNaN(v1)
|
||||
,!isNaN(v2)
|
||||
];
|
||||
|
||||
|
||||
//若为数字比较
|
||||
if(isNum[0] && isNum[1]){
|
||||
if(v1 && (!v2 && v2 !== 0)){ //数字 vs 空
|
||||
return 1;
|
||||
} else if((!v1 && v1 !== 0) && v2){ //空 vs 数字
|
||||
return -1;
|
||||
} else { //数字 vs 数字
|
||||
return v1 - v2;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 字典序排序
|
||||
*/
|
||||
|
||||
//若为非数字比较
|
||||
if(!isNum[0] && !isNum[1]){
|
||||
//字典序比较
|
||||
if(v1 > v2){
|
||||
return 1;
|
||||
} else if (v1 < v2) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//若为混合比较
|
||||
if(isNum[0] || !isNum[1]){ //数字 vs 非数字
|
||||
return -1;
|
||||
} else if(!isNum[0] || isNum[1]) { //非数字 vs 数字
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
//老版本
|
||||
if(v1 && !v2){
|
||||
return 1;
|
||||
} else if(!v1 && v2){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(v1 > v2){
|
||||
return 1;
|
||||
} else if (v1 < v2) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
desc && clone.reverse(); //倒序
|
||||
return clone;
|
||||
};
|
||||
|
||||
//阻止事件冒泡
|
||||
Layui.prototype.stope = function(thisEvent){
|
||||
thisEvent = thisEvent || win.event;
|
||||
try { thisEvent.stopPropagation() } catch(e){
|
||||
thisEvent.cancelBubble = true;
|
||||
}
|
||||
};
|
||||
|
||||
//字符常理
|
||||
var EV_REMOVE = 'LAYUI-EVENT-REMOVE';
|
||||
|
||||
//自定义模块事件
|
||||
Layui.prototype.onevent = function(modName, events, callback){
|
||||
if(typeof modName !== 'string'
|
||||
|| typeof callback !== 'function') return this;
|
||||
|
||||
return Layui.event(modName, events, null, callback);
|
||||
};
|
||||
|
||||
//执行自定义模块事件
|
||||
Layui.prototype.event = Layui.event = function(modName, events, params, fn){
|
||||
var that = this
|
||||
,result = null
|
||||
,filter = (events || '').match(/\((.*)\)$/)||[] //提取事件过滤器字符结构,如:select(xxx)
|
||||
,eventName = (modName + '.'+ events).replace(filter[0], '') //获取事件名称,如:form.select
|
||||
,filterName = filter[1] || '' //获取过滤器名称,,如:xxx
|
||||
,callback = function(_, item){
|
||||
var res = item && item.call(that, params);
|
||||
res === false && result === null && (result = false);
|
||||
};
|
||||
|
||||
//如果参数传入特定字符,则执行移除事件
|
||||
if(params === EV_REMOVE){
|
||||
delete (that.cache.event[eventName] || {})[filterName];
|
||||
return that;
|
||||
}
|
||||
|
||||
//添加事件
|
||||
if(fn){
|
||||
config.event[eventName] = config.event[eventName] || {};
|
||||
|
||||
//这里不再对重复事件做支持
|
||||
//config.event[eventName][filterName] ? config.event[eventName][filterName].push(fn) :
|
||||
config.event[eventName][filterName] = [fn];
|
||||
return this;
|
||||
}
|
||||
|
||||
//执行事件回调
|
||||
layui.each(config.event[eventName], function(key, item){
|
||||
//执行当前模块的全部事件
|
||||
if(filterName === '{*}'){
|
||||
layui.each(item, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
//执行指定事件
|
||||
key === '' && layui.each(item, callback);
|
||||
(filterName && key === filterName) && layui.each(item, callback);
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
//新增模块事件
|
||||
Layui.prototype.on = function(events, modName, callback){
|
||||
var that = this;
|
||||
return that.onevent.call(that, modName, events, callback);
|
||||
}
|
||||
|
||||
//移除模块事件
|
||||
Layui.prototype.off = function(events, modName){
|
||||
var that = this;
|
||||
return that.event.call(that, modName, events, EV_REMOVE);
|
||||
};
|
||||
|
||||
//exports layui
|
||||
win.layui = new Layui();
|
||||
|
||||
}(window); //gulp build: layui-footer
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
|
||||
/*!
|
||||
* 用于加载所有内置模块
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
layui.define(function(){
|
||||
var mods = []
|
||||
,builtin = layui.cache.builtin;
|
||||
layui.each(builtin, function(modName){
|
||||
(modName === 'all' || modName === 'layui.all') || mods.push(modName);
|
||||
});
|
||||
layui.cache.startTime = new Date().getTime();
|
||||
|
||||
return mods;
|
||||
}(), function(exports){
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = 'all'
|
||||
|
||||
//外部接口
|
||||
,all = {
|
||||
config: {}
|
||||
,time: function(){
|
||||
var time = new Date().getTime() - layui.cache.startTime;
|
||||
delete layui.cache.startTime;
|
||||
return time;
|
||||
}()
|
||||
};
|
||||
|
||||
exports(MOD_NAME, all);
|
||||
});
|
||||
@@ -1,313 +0,0 @@
|
||||
|
||||
/*!
|
||||
* carousel 轮播模块
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
//外部接口
|
||||
,carousel = {
|
||||
config: {} //全局配置项
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'carousel', ELEM = '.layui-carousel', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled'
|
||||
|
||||
,ELEM_ITEM = '>*[carousel-item]>*', ELEM_LEFT = 'layui-carousel-left', ELEM_RIGHT = 'layui-carousel-right', ELEM_PREV = 'layui-carousel-prev', ELEM_NEXT = 'layui-carousel-next', ELEM_ARROW = 'layui-carousel-arrow', ELEM_IND = 'layui-carousel-ind'
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, carousel.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
width: '600px'
|
||||
,height: '280px'
|
||||
,full: false //是否全屏
|
||||
,arrow: 'hover' //切换箭头默认显示状态:hover/always/none
|
||||
,indicator: 'inside' //指示器位置:inside/outside/none
|
||||
,autoplay: true //是否自动切换
|
||||
,interval: 3000 //自动切换的时间间隔,不能低于800ms
|
||||
,anim: '' //动画类型:default/updown/fade
|
||||
,trigger: 'click' //指示器的触发方式:click/hover
|
||||
,index: 0 //初始开始的索引
|
||||
};
|
||||
|
||||
//轮播渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
options.elem = $(options.elem);
|
||||
if(!options.elem[0]) return;
|
||||
that.elemItem = options.elem.find(ELEM_ITEM);
|
||||
|
||||
if(options.index < 0) options.index = 0;
|
||||
if(options.index >= that.elemItem.length) options.index = that.elemItem.length - 1;
|
||||
if(options.interval < 800) options.interval = 800;
|
||||
|
||||
//是否全屏模式
|
||||
if(options.full){
|
||||
options.elem.css({
|
||||
position: 'fixed'
|
||||
,width: '100%'
|
||||
,height: '100%'
|
||||
,zIndex: 9999
|
||||
});
|
||||
} else {
|
||||
options.elem.css({
|
||||
width: options.width
|
||||
,height: options.height
|
||||
});
|
||||
}
|
||||
|
||||
options.elem.attr('lay-anim', options.anim);
|
||||
|
||||
//初始焦点状态
|
||||
that.elemItem.eq(options.index).addClass(THIS);
|
||||
|
||||
//指示器等动作
|
||||
if(that.elemItem.length <= 1) return;
|
||||
that.indicator();
|
||||
that.arrow();
|
||||
that.autoplay();
|
||||
that.events();
|
||||
};
|
||||
|
||||
//重置轮播
|
||||
Class.prototype.reload = function(options){
|
||||
var that = this;
|
||||
clearInterval(that.timer);
|
||||
that.config = $.extend({}, that.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//获取上一个等待条目的索引
|
||||
Class.prototype.prevIndex = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
var prevIndex = options.index - 1;
|
||||
if(prevIndex < 0){
|
||||
prevIndex = that.elemItem.length - 1;
|
||||
}
|
||||
return prevIndex;
|
||||
};
|
||||
|
||||
//获取下一个等待条目的索引
|
||||
Class.prototype.nextIndex = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
var nextIndex = options.index + 1;
|
||||
if(nextIndex >= that.elemItem.length){
|
||||
nextIndex = 0;
|
||||
}
|
||||
return nextIndex;
|
||||
};
|
||||
|
||||
//索引递增
|
||||
Class.prototype.addIndex = function(num){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
num = num || 1;
|
||||
options.index = options.index + num;
|
||||
|
||||
//index不能超过轮播总数量
|
||||
if(options.index >= that.elemItem.length){
|
||||
options.index = 0;
|
||||
}
|
||||
};
|
||||
|
||||
//索引递减
|
||||
Class.prototype.subIndex = function(num){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
num = num || 1;
|
||||
options.index = options.index - num;
|
||||
|
||||
//index不能超过轮播总数量
|
||||
if(options.index < 0){
|
||||
options.index = that.elemItem.length - 1;
|
||||
}
|
||||
};
|
||||
|
||||
//自动轮播
|
||||
Class.prototype.autoplay = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
if(!options.autoplay) return;
|
||||
clearInterval(that.timer);
|
||||
|
||||
that.timer = setInterval(function(){
|
||||
that.slide();
|
||||
}, options.interval);
|
||||
};
|
||||
|
||||
//箭头
|
||||
Class.prototype.arrow = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//模板
|
||||
var tplArrow = $([
|
||||
'<button class="layui-icon '+ ELEM_ARROW +'" lay-type="sub">'+ (options.anim === 'updown' ? '' : '') +'</button>'
|
||||
,'<button class="layui-icon '+ ELEM_ARROW +'" lay-type="add">'+ (options.anim === 'updown' ? '' : '') +'</button>'
|
||||
].join(''));
|
||||
|
||||
//预设基础属性
|
||||
options.elem.attr('lay-arrow', options.arrow);
|
||||
|
||||
//避免重复插入
|
||||
if(options.elem.find('.'+ELEM_ARROW)[0]){
|
||||
options.elem.find('.'+ELEM_ARROW).remove();
|
||||
};
|
||||
options.elem.append(tplArrow);
|
||||
|
||||
//事件
|
||||
tplArrow.on('click', function(){
|
||||
var othis = $(this)
|
||||
,type = othis.attr('lay-type')
|
||||
that.slide(type);
|
||||
});
|
||||
};
|
||||
|
||||
//指示器
|
||||
Class.prototype.indicator = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//模板
|
||||
var tplInd = that.elemInd = $(['<div class="'+ ELEM_IND +'"><ul>'
|
||||
,function(){
|
||||
var li = [];
|
||||
layui.each(that.elemItem, function(index){
|
||||
li.push('<li'+ (options.index === index ? ' class="layui-this"' : '') +'></li>');
|
||||
});
|
||||
return li.join('');
|
||||
}()
|
||||
,'</ul></div>'].join(''));
|
||||
|
||||
//预设基础属性
|
||||
options.elem.attr('lay-indicator', options.indicator);
|
||||
|
||||
//避免重复插入
|
||||
if(options.elem.find('.'+ELEM_IND)[0]){
|
||||
options.elem.find('.'+ELEM_IND).remove();
|
||||
};
|
||||
options.elem.append(tplInd);
|
||||
|
||||
if(options.anim === 'updown'){
|
||||
tplInd.css('margin-top', -(tplInd.height()/2));
|
||||
}
|
||||
|
||||
//事件
|
||||
tplInd.find('li').on(options.trigger === 'hover' ? 'mouseover' : options.trigger, function(){
|
||||
var othis = $(this)
|
||||
,index = othis.index();
|
||||
if(index > options.index){
|
||||
that.slide('add', index - options.index);
|
||||
} else if(index < options.index){
|
||||
that.slide('sub', options.index - index);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//滑动切换
|
||||
Class.prototype.slide = function(type, num){
|
||||
var that = this
|
||||
,elemItem = that.elemItem
|
||||
,options = that.config
|
||||
,thisIndex = options.index
|
||||
,filter = options.elem.attr('lay-filter');
|
||||
|
||||
if(that.haveSlide) return;
|
||||
|
||||
//滑动方向
|
||||
if(type === 'sub'){
|
||||
that.subIndex(num);
|
||||
elemItem.eq(options.index).addClass(ELEM_PREV);
|
||||
setTimeout(function(){
|
||||
elemItem.eq(thisIndex).addClass(ELEM_RIGHT);
|
||||
elemItem.eq(options.index).addClass(ELEM_RIGHT);
|
||||
}, 50);
|
||||
} else { //默认递增滑
|
||||
that.addIndex(num);
|
||||
elemItem.eq(options.index).addClass(ELEM_NEXT);
|
||||
setTimeout(function(){
|
||||
elemItem.eq(thisIndex).addClass(ELEM_LEFT);
|
||||
elemItem.eq(options.index).addClass(ELEM_LEFT);
|
||||
}, 50);
|
||||
};
|
||||
|
||||
//移除过度类
|
||||
setTimeout(function(){
|
||||
elemItem.removeClass(THIS + ' ' + ELEM_PREV + ' ' + ELEM_NEXT + ' ' + ELEM_LEFT + ' ' + ELEM_RIGHT);
|
||||
elemItem.eq(options.index).addClass(THIS);
|
||||
that.haveSlide = false; //解锁
|
||||
}, 300);
|
||||
|
||||
//指示器焦点
|
||||
that.elemInd.find('li').eq(options.index).addClass(THIS)
|
||||
.siblings().removeClass(THIS);
|
||||
|
||||
that.haveSlide = true;
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'change('+ filter +')', {
|
||||
index: options.index
|
||||
,prevIndex: thisIndex
|
||||
,item: elemItem.eq(options.index)
|
||||
});
|
||||
};
|
||||
|
||||
//事件处理
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
if(options.elem.data('haveEvents')) return;
|
||||
|
||||
//移入移出容器
|
||||
options.elem.on('mouseenter', function(){
|
||||
clearInterval(that.timer);
|
||||
}).on('mouseleave', function(){
|
||||
that.autoplay();
|
||||
});
|
||||
|
||||
options.elem.data('haveEvents', true);
|
||||
};
|
||||
|
||||
//核心入口
|
||||
carousel.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return inst;
|
||||
};
|
||||
|
||||
exports(MOD_NAME, carousel);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
|
||||
/**
|
||||
* code 代码修饰器
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$;
|
||||
|
||||
exports('code', function(options){
|
||||
var elems = [];
|
||||
options = options || {};
|
||||
options.elem = $(options.elem||'.layui-code');
|
||||
options.lang = 'lang' in options ? options.lang : 'code';
|
||||
|
||||
options.elem.each(function(){
|
||||
elems.push(this);
|
||||
});
|
||||
|
||||
layui.each(elems.reverse(), function(index, item){
|
||||
var othis = $(item), html = othis.html();
|
||||
|
||||
//转义HTML标签
|
||||
if(othis.attr('lay-encode') || options.encode){
|
||||
html = html.replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
|
||||
.replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/"/g, '"')
|
||||
}
|
||||
|
||||
othis.html('<ol class="layui-code-ol"><li>' + html.replace(/[\r\t\n]+/g, '</li><li>') + '</li></ol>')
|
||||
|
||||
if(!othis.find('>.layui-code-h3')[0]){
|
||||
othis.prepend('<h3 class="layui-code-h3">'+ (othis.attr('lay-title')||options.title||'</>') + '<a href="javascript:;">'+ (othis.attr('lay-lang')||options.lang||'') +'</a>' + '</h3>');
|
||||
}
|
||||
|
||||
var ol = othis.find('>.layui-code-ol');
|
||||
othis.addClass('layui-box layui-code-view');
|
||||
|
||||
//识别皮肤
|
||||
if(othis.attr('lay-skin') || options.skin){
|
||||
othis.addClass('layui-code-' +(othis.attr('lay-skin') || options.skin));
|
||||
}
|
||||
|
||||
//按行数适配左边距
|
||||
if((ol.find('li').length/100|0) > 0){
|
||||
ol.css('margin-left', (ol.find('li').length/100|0) + 'px');
|
||||
}
|
||||
|
||||
//设置最大高度
|
||||
if(othis.attr('lay-height') || options.height){
|
||||
ol.css('max-height', othis.attr('lay-height') || options.height);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}).addcss('modules/code.css?v=2', 'skincodecss');
|
||||
|
||||
@@ -1,691 +0,0 @@
|
||||
|
||||
/*!
|
||||
* colorpicker
|
||||
* 颜色选择组件
|
||||
*/
|
||||
|
||||
layui.define(['jquery', 'lay'], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery
|
||||
,lay = layui.lay
|
||||
,device = layui.device()
|
||||
,clickOrMousedown = (device.mobile ? 'click' : 'mousedown')
|
||||
|
||||
//外部接口
|
||||
,colorpicker = {
|
||||
config: {}
|
||||
,index: layui.colorpicker ? (layui.colorpicker.index + 10000) : 0
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, 'colorpicker', events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisColorPicker = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
return {
|
||||
config: options
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'colorpicker', SHOW = 'layui-show', THIS = 'layui-this', ELEM = 'layui-colorpicker'
|
||||
|
||||
,ELEM_MAIN = '.layui-colorpicker-main', ICON_PICKER_DOWN = 'layui-icon-down', ICON_PICKER_CLOSE = 'layui-icon-close'
|
||||
,PICKER_TRIG_SPAN = 'layui-colorpicker-trigger-span', PICKER_TRIG_I = 'layui-colorpicker-trigger-i', PICKER_SIDE = 'layui-colorpicker-side', PICKER_SIDE_SLIDER = 'layui-colorpicker-side-slider'
|
||||
,PICKER_BASIS = 'layui-colorpicker-basis', PICKER_ALPHA_BG = 'layui-colorpicker-alpha-bgcolor', PICKER_ALPHA_SLIDER = 'layui-colorpicker-alpha-slider', PICKER_BASIS_CUR = 'layui-colorpicker-basis-cursor', PICKER_INPUT = 'layui-colorpicker-main-input'
|
||||
|
||||
//RGB转HSB
|
||||
,RGBToHSB = function(rgb){
|
||||
var hsb = {h:0, s:0, b:0};
|
||||
var min = Math.min(rgb.r, rgb.g, rgb.b);
|
||||
var max = Math.max(rgb.r, rgb.g, rgb.b);
|
||||
var delta = max - min;
|
||||
hsb.b = max;
|
||||
hsb.s = max != 0 ? 255*delta/max : 0;
|
||||
if(hsb.s != 0){
|
||||
if(rgb.r == max){
|
||||
hsb.h = (rgb.g - rgb.b) / delta;
|
||||
}else if(rgb.g == max){
|
||||
hsb.h = 2 + (rgb.b - rgb.r) / delta;
|
||||
}else{
|
||||
hsb.h = 4 + (rgb.r - rgb.g) / delta;
|
||||
}
|
||||
}else{
|
||||
hsb.h = -1;
|
||||
};
|
||||
if(max == min){
|
||||
hsb.h = 0;
|
||||
};
|
||||
hsb.h *= 60;
|
||||
if(hsb.h < 0) {
|
||||
hsb.h += 360;
|
||||
};
|
||||
hsb.s *= 100/255;
|
||||
hsb.b *= 100/255;
|
||||
return hsb;
|
||||
}
|
||||
|
||||
//HEX转HSB
|
||||
,HEXToHSB = function(hex){
|
||||
var hex = hex.indexOf('#') > -1 ? hex.substring(1) : hex;
|
||||
if(hex.length == 3){
|
||||
var num = hex.split("");
|
||||
hex = num[0]+num[0]+num[1]+num[1]+num[2]+num[2]
|
||||
};
|
||||
hex = parseInt(hex, 16);
|
||||
var rgb = {r:hex >> 16, g:(hex & 0x00FF00) >> 8, b:(hex & 0x0000FF)};
|
||||
return RGBToHSB(rgb);
|
||||
}
|
||||
|
||||
//HSB转RGB
|
||||
,HSBToRGB = function(hsb){
|
||||
var rgb = {};
|
||||
var h = hsb.h;
|
||||
var s = hsb.s*255/100;
|
||||
var b = hsb.b*255/100;
|
||||
if(s == 0){
|
||||
rgb.r = rgb.g = rgb.b = b;
|
||||
}else{
|
||||
var t1 = b;
|
||||
var t2 = (255 - s) * b /255;
|
||||
var t3 = (t1 - t2) * (h % 60) /60;
|
||||
if(h == 360) h = 0;
|
||||
if(h < 60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
|
||||
else if(h < 120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
|
||||
else if(h < 180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
|
||||
else if(h < 240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
|
||||
else if(h < 300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
|
||||
else if(h < 360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
|
||||
else {rgb.r=0; rgb.g=0; rgb.b=0}
|
||||
}
|
||||
return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
|
||||
}
|
||||
|
||||
//HSB转HEX
|
||||
,HSBToHEX = function(hsb){
|
||||
var rgb = HSBToRGB(hsb);
|
||||
var hex = [
|
||||
rgb.r.toString(16)
|
||||
,rgb.g.toString(16)
|
||||
,rgb.b.toString(16)
|
||||
];
|
||||
$.each(hex, function(nr, val){
|
||||
if(val.length == 1){
|
||||
hex[nr] = '0' + val;
|
||||
}
|
||||
});
|
||||
return hex.join('');
|
||||
}
|
||||
|
||||
//转化成所需rgb格式
|
||||
,RGBSTo = function(rgbs){
|
||||
var regexp = /[0-9]{1,3}/g;
|
||||
var re = rgbs.match(regexp) || [];
|
||||
return {r:re[0], g:re[1], b:re[2]};
|
||||
}
|
||||
|
||||
,$win = $(window)
|
||||
,$doc = $(document)
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.index = ++colorpicker.index;
|
||||
that.config = $.extend({}, that.config, colorpicker.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
color: '' //默认颜色,默认没有
|
||||
,size: null //选择器大小
|
||||
,alpha: false //是否开启透明度
|
||||
,format: 'hex' //颜色显示/输入格式,可选 rgb,hex
|
||||
,predefine: false //预定义颜色是否开启
|
||||
,colors: [ //默认预定义颜色列表
|
||||
'#009688', '#5FB878', '#1E9FFF', '#FF5722', '#FFB800', '#01AAED', '#999', '#c00', '#ff8c00','#ffd700'
|
||||
,'#90ee90', '#00ced1', '#1e90ff', '#c71585', 'rgb(0, 186, 189)', 'rgb(255, 120, 0)', 'rgb(250, 212, 0)', '#393D49', 'rgba(0,0,0,.5)', 'rgba(255, 69, 0, 0.68)', 'rgba(144, 240, 144, 0.5)', 'rgba(31, 147, 255, 0.73)'
|
||||
]
|
||||
};
|
||||
|
||||
//初始颜色选择框
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
|
||||
//颜色选择框对象
|
||||
,elemColorBox = $(['<div class="layui-unselect layui-colorpicker">'
|
||||
,'<span '+ (options.format == 'rgb' && options.alpha
|
||||
? 'class="layui-colorpicker-trigger-bgcolor"'
|
||||
: '') +'>'
|
||||
,'<span class="layui-colorpicker-trigger-span" '
|
||||
,'lay-type="'+ (options.format == 'rgb' ? (options.alpha ? 'rgba' : 'torgb') : '') +'" '
|
||||
,'style="'+ function(){
|
||||
var bgstr = '';
|
||||
if(options.color){
|
||||
bgstr = options.color;
|
||||
|
||||
if((options.color.match(/[0-9]{1,3}/g) || []).length > 3){ //需要优化
|
||||
if(!(options.alpha && options.format == 'rgb')){
|
||||
bgstr = '#' + HSBToHEX(RGBToHSB(RGBSTo(options.color)))
|
||||
}
|
||||
}
|
||||
|
||||
return 'background: '+ bgstr;
|
||||
}
|
||||
|
||||
return bgstr;
|
||||
}() +'">'
|
||||
,'<i class="layui-icon layui-colorpicker-trigger-i '+ (options.color
|
||||
? ICON_PICKER_DOWN
|
||||
: ICON_PICKER_CLOSE) +'"></i>'
|
||||
,'</span>'
|
||||
,'</span>'
|
||||
,'</div>'].join(''))
|
||||
|
||||
//初始化颜色选择框
|
||||
var othis = $(options.elem);
|
||||
options.size && elemColorBox.addClass('layui-colorpicker-'+ options.size); //初始化颜色选择框尺寸
|
||||
|
||||
//插入颜色选择框
|
||||
othis.addClass('layui-inline').html(
|
||||
that.elemColorBox = elemColorBox
|
||||
);
|
||||
|
||||
//获取背景色值
|
||||
that.color = that.elemColorBox.find('.'+ PICKER_TRIG_SPAN)[0].style.background;
|
||||
|
||||
//相关事件
|
||||
that.events();
|
||||
};
|
||||
|
||||
//渲染颜色选择器
|
||||
Class.prototype.renderPicker = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemColorBox = that.elemColorBox[0]
|
||||
|
||||
//颜色选择器对象
|
||||
,elemPicker = that.elemPicker = $(['<div id="layui-colorpicker'+ that.index +'" data-index="'+ that.index +'" class="layui-anim layui-anim-downbit layui-colorpicker-main">'
|
||||
//颜色面板
|
||||
,'<div class="layui-colorpicker-main-wrapper">'
|
||||
,'<div class="layui-colorpicker-basis">'
|
||||
,'<div class="layui-colorpicker-basis-white"></div>'
|
||||
,'<div class="layui-colorpicker-basis-black"></div>'
|
||||
,'<div class="layui-colorpicker-basis-cursor"></div>'
|
||||
,'</div>'
|
||||
,'<div class="layui-colorpicker-side">'
|
||||
,'<div class="layui-colorpicker-side-slider"></div>'
|
||||
,'</div>'
|
||||
,'</div>'
|
||||
|
||||
//透明度条块
|
||||
,'<div class="layui-colorpicker-main-alpha '+ (options.alpha ? SHOW : '') +'">'
|
||||
,'<div class="layui-colorpicker-alpha-bgcolor">'
|
||||
,'<div class="layui-colorpicker-alpha-slider"></div>'
|
||||
,'</div>'
|
||||
,'</div>'
|
||||
|
||||
//预设颜色列表
|
||||
,function(){
|
||||
if(options.predefine){
|
||||
var list = ['<div class="layui-colorpicker-main-pre">'];
|
||||
layui.each(options.colors, function(i, v){
|
||||
list.push(['<div class="layui-colorpicker-pre'+ ((v.match(/[0-9]{1,3}/g) || []).length > 3
|
||||
? ' layui-colorpicker-pre-isalpha'
|
||||
: '') +'">'
|
||||
,'<div style="background:'+ v +'"></div>'
|
||||
,'</div>'].join(''));
|
||||
});
|
||||
list.push('</div>');
|
||||
return list.join('');
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}()
|
||||
|
||||
//底部表单元素区域
|
||||
,'<div class="layui-colorpicker-main-input">'
|
||||
,'<div class="layui-inline">'
|
||||
,'<input type="text" class="layui-input">'
|
||||
,'</div>'
|
||||
,'<div class="layui-btn-container">'
|
||||
,'<button class="layui-btn layui-btn-primary layui-btn-sm" colorpicker-events="clear">清空</button>'
|
||||
,'<button class="layui-btn layui-btn-sm" colorpicker-events="confirm">确定</button>'
|
||||
,'</div'
|
||||
,'</div>'
|
||||
,'</div>'].join(''))
|
||||
|
||||
,elemColorBoxSpan = that.elemColorBox.find('.' + PICKER_TRIG_SPAN)[0];
|
||||
|
||||
//如果当前点击的颜色盒子已经存在选择器,则关闭
|
||||
if($(ELEM_MAIN)[0] && $(ELEM_MAIN).data('index') == that.index){
|
||||
that.removePicker(Class.thisElemInd);
|
||||
} else { //插入颜色选择器
|
||||
that.removePicker(Class.thisElemInd);
|
||||
$('body').append(elemPicker);
|
||||
}
|
||||
|
||||
Class.thisElemInd = that.index; //记录最新打开的选择器索引
|
||||
Class.thisColor = elemColorBox.style.background //记录最新打开的选择器颜色选中值
|
||||
|
||||
that.position();
|
||||
that.pickerEvents();
|
||||
};
|
||||
|
||||
//颜色选择器移除
|
||||
Class.prototype.removePicker = function(index){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
$('#layui-colorpicker'+ (index || that.index)).remove();
|
||||
return that;
|
||||
};
|
||||
|
||||
//定位算法
|
||||
Class.prototype.position = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
lay.position(that.bindElem || that.elemColorBox[0], that.elemPicker[0], {
|
||||
position: options.position
|
||||
,align: 'center'
|
||||
});
|
||||
return that;
|
||||
};
|
||||
|
||||
//颜色选择器赋值
|
||||
Class.prototype.val = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
|
||||
,elemColorBox = that.elemColorBox.find('.' + PICKER_TRIG_SPAN)
|
||||
,elemPickerInput = that.elemPicker.find('.' + PICKER_INPUT)
|
||||
,e = elemColorBox[0]
|
||||
,bgcolor = e.style.backgroundColor;
|
||||
|
||||
//判断是否有背景颜色
|
||||
if(bgcolor){
|
||||
|
||||
//转化成hsb格式
|
||||
var hsb = RGBToHSB(RGBSTo(bgcolor))
|
||||
,type = elemColorBox.attr('lay-type');
|
||||
|
||||
//同步滑块的位置及颜色选择器的选择
|
||||
that.select(hsb.h, hsb.s, hsb.b);
|
||||
|
||||
//如果格式要求为rgb
|
||||
if(type === 'torgb'){
|
||||
elemPickerInput.find('input').val(bgcolor);
|
||||
};
|
||||
|
||||
//如果格式要求为rgba
|
||||
if(type === 'rgba'){
|
||||
var rgb = RGBSTo(bgcolor);
|
||||
|
||||
//如果开启透明度而没有设置,则给默认值
|
||||
if((bgcolor.match(/[0-9]{1,3}/g) || []).length == 3){
|
||||
elemPickerInput.find('input').val('rgba('+ rgb.r +', '+ rgb.g +', '+ rgb.b +', 1)');
|
||||
that.elemPicker.find('.'+ PICKER_ALPHA_SLIDER).css("left", 280);
|
||||
} else {
|
||||
elemPickerInput.find('input').val(bgcolor);
|
||||
var left = bgcolor.slice(bgcolor.lastIndexOf(",") + 1, bgcolor.length - 1) * 280;
|
||||
that.elemPicker.find('.'+ PICKER_ALPHA_SLIDER).css("left", left);
|
||||
};
|
||||
|
||||
//设置span背景色
|
||||
that.elemPicker.find('.'+ PICKER_ALPHA_BG)[0].style.background = 'linear-gradient(to right, rgba('+ rgb.r +', '+ rgb.g +', '+ rgb.b +', 0), rgb('+ rgb.r +', '+ rgb.g +', '+ rgb.b +'))';
|
||||
};
|
||||
|
||||
}else{
|
||||
//如果没有背景颜色则默认到最初始的状态
|
||||
that.select(0,100,100);
|
||||
elemPickerInput.find('input').val("");
|
||||
that.elemPicker.find('.'+ PICKER_ALPHA_BG)[0].style.background = '';
|
||||
that.elemPicker.find('.'+ PICKER_ALPHA_SLIDER).css("left", 280);
|
||||
}
|
||||
};
|
||||
|
||||
//颜色选择器滑动 / 点击
|
||||
Class.prototype.side = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
|
||||
,span = that.elemColorBox.find('.' + PICKER_TRIG_SPAN)
|
||||
,type = span.attr('lay-type')
|
||||
|
||||
,side = that.elemPicker.find('.' + PICKER_SIDE)
|
||||
,slider = that.elemPicker.find('.' + PICKER_SIDE_SLIDER)
|
||||
,basis = that.elemPicker.find('.' + PICKER_BASIS)
|
||||
,choose = that.elemPicker.find('.' + PICKER_BASIS_CUR)
|
||||
,alphacolor = that.elemPicker.find('.' + PICKER_ALPHA_BG)
|
||||
,alphaslider = that.elemPicker.find('.' + PICKER_ALPHA_SLIDER)
|
||||
|
||||
,_h = slider[0].offsetTop/180*360
|
||||
,_b = 100 - (choose[0].offsetTop + 3)/180*100
|
||||
,_s = (choose[0].offsetLeft + 3)/260*100
|
||||
,_a = Math.round(alphaslider[0].offsetLeft/280*100)/100
|
||||
|
||||
,i = that.elemColorBox.find('.' + PICKER_TRIG_I)
|
||||
,pre = that.elemPicker.find('.layui-colorpicker-pre').children('div')
|
||||
|
||||
,change = function(x,y,z,a){
|
||||
that.select(x, y, z);
|
||||
var rgb = HSBToRGB({h:x, s:y, b:z});
|
||||
i.addClass(ICON_PICKER_DOWN).removeClass(ICON_PICKER_CLOSE);
|
||||
span[0].style.background = 'rgb('+ rgb.r +', '+ rgb.g +', '+ rgb.b +')';
|
||||
|
||||
if(type === 'torgb'){
|
||||
that.elemPicker.find('.' + PICKER_INPUT).find('input').val('rgb('+ rgb.r +', '+ rgb.g +', '+ rgb.b +')');
|
||||
};
|
||||
|
||||
if(type === 'rgba'){
|
||||
var left = 0;
|
||||
left = a * 280;
|
||||
alphaslider.css("left", left);
|
||||
that.elemPicker.find('.' + PICKER_INPUT).find('input').val('rgba('+ rgb.r +', '+ rgb.g +', '+ rgb.b +', '+ a +')');
|
||||
span[0].style.background = 'rgba('+ rgb.r +', '+ rgb.g +', '+ rgb.b +', '+ a +')';
|
||||
alphacolor[0].style.background = 'linear-gradient(to right, rgba('+ rgb.r +', '+ rgb.g +', '+ rgb.b +', 0), rgb('+ rgb.r +', '+ rgb.g +', '+ rgb.b +'))'
|
||||
};
|
||||
|
||||
//回调更改的颜色
|
||||
options.change && options.change(that.elemPicker.find('.' + PICKER_INPUT).find('input').val());
|
||||
}
|
||||
|
||||
//拖拽元素
|
||||
,elemMove = $(['<div class="layui-auxiliar-moving" id="LAY-colorpicker-moving"></div>'].join(''))
|
||||
,createMoveElem = function(call){
|
||||
$('#LAY-colorpicker-moving')[0] || $('body').append(elemMove);
|
||||
elemMove.on('mousemove', call);
|
||||
elemMove.on('mouseup', function(){
|
||||
elemMove.remove();
|
||||
}).on('mouseleave', function(){
|
||||
elemMove.remove();
|
||||
});
|
||||
};
|
||||
|
||||
//右侧主色选择
|
||||
slider.on('mousedown', function(e){
|
||||
var oldtop = this.offsetTop
|
||||
,oldy = e.clientY;
|
||||
var move = function(e){
|
||||
var top = oldtop + (e.clientY - oldy)
|
||||
,maxh = side[0].offsetHeight;
|
||||
if(top < 0)top = 0;
|
||||
if(top > maxh)top = maxh;
|
||||
var h = top/180*360;
|
||||
_h = h;
|
||||
change(h, _s, _b, _a);
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
createMoveElem(move);
|
||||
//layui.stope(e);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
side.on('click', function(e){
|
||||
var top = e.clientY - $(this).offset().top;
|
||||
if(top < 0)top = 0;
|
||||
if(top > this.offsetHeight)top = this.offsetHeight;
|
||||
var h = top/180*360;
|
||||
_h = h;
|
||||
change(h, _s, _b, _a);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
//中间小圆点颜色选择
|
||||
choose.on('mousedown', function(e){
|
||||
var oldtop = this.offsetTop
|
||||
,oldleft = this.offsetLeft
|
||||
,oldy = e.clientY
|
||||
,oldx = e.clientX;
|
||||
var move = function(e){
|
||||
var top = oldtop + (e.clientY - oldy)
|
||||
,left = oldleft + (e.clientX - oldx)
|
||||
,maxh = basis[0].offsetHeight - 3
|
||||
,maxw = basis[0].offsetWidth - 3;
|
||||
if(top < -3)top = -3;
|
||||
if(top > maxh)top = maxh;
|
||||
if(left < -3)left = -3;
|
||||
if(left > maxw)left = maxw;
|
||||
var s = (left + 3)/260*100
|
||||
,b = 100 - (top + 3)/180*100;
|
||||
_b = b;
|
||||
_s = s;
|
||||
change(_h, s, b, _a);
|
||||
e.preventDefault();
|
||||
};
|
||||
layui.stope(e);
|
||||
createMoveElem(move);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
basis.on('mousedown', function(e){
|
||||
var top = e.clientY - $(this).offset().top - 3 + $win.scrollTop()
|
||||
,left = e.clientX - $(this).offset().left - 3 + $win.scrollLeft()
|
||||
if(top < -3)top = -3;
|
||||
if(top > this.offsetHeight - 3)top = this.offsetHeight - 3;
|
||||
if(left < -3)left = -3;
|
||||
if(left > this.offsetWidth - 3)left = this.offsetWidth - 3;
|
||||
var s = (left + 3)/260*100
|
||||
,b = 100 - (top + 3)/180*100;
|
||||
_b = b;
|
||||
_s = s;
|
||||
change(_h, s, b, _a);
|
||||
layui.stope(e);
|
||||
e.preventDefault();
|
||||
choose.trigger(e, 'mousedown');
|
||||
});
|
||||
|
||||
//底部透明度选择
|
||||
alphaslider.on('mousedown', function(e){
|
||||
var oldleft = this.offsetLeft
|
||||
,oldx = e.clientX;
|
||||
var move = function(e){
|
||||
var left = oldleft + (e.clientX - oldx)
|
||||
,maxw = alphacolor[0].offsetWidth;
|
||||
if(left < 0)left = 0;
|
||||
if(left > maxw)left = maxw;
|
||||
var a = Math.round(left /280*100) /100;
|
||||
_a = a;
|
||||
change(_h, _s, _b, a);
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
createMoveElem(move);
|
||||
e.preventDefault();
|
||||
});
|
||||
alphacolor.on('click', function(e){
|
||||
var left = e.clientX - $(this).offset().left
|
||||
if(left < 0)left = 0;
|
||||
if(left > this.offsetWidth)left = this.offsetWidth;
|
||||
var a = Math.round(left /280*100) /100;
|
||||
_a = a;
|
||||
change(_h, _s, _b, a);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
//预定义颜色选择
|
||||
pre.each(function(){
|
||||
$(this).on('click', function(){
|
||||
$(this).parent('.layui-colorpicker-pre').addClass('selected').siblings().removeClass('selected');
|
||||
var color = this.style.backgroundColor
|
||||
,hsb = RGBToHSB(RGBSTo(color))
|
||||
,a = color.slice(color.lastIndexOf(",") + 1, color.length - 1),left;
|
||||
_h = hsb.h;
|
||||
_s = hsb.s;
|
||||
_b = hsb.b;
|
||||
if((color.match(/[0-9]{1,3}/g) || []).length == 3) a = 1;
|
||||
_a = a;
|
||||
left = a * 280;
|
||||
change(hsb.h, hsb.s, hsb.b, a);
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
//颜色选择器hsb转换
|
||||
Class.prototype.select = function(h, s, b, type){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,hex = HSBToHEX({h:h, s:100, b:100})
|
||||
,color = HSBToHEX({h:h, s:s, b:b})
|
||||
,sidetop = h/360*180
|
||||
,top = 180 - b/100*180 - 3
|
||||
,left = s/100*260 - 3;
|
||||
|
||||
that.elemPicker.find('.' + PICKER_SIDE_SLIDER).css("top", sidetop); //滑块的top
|
||||
that.elemPicker.find('.' + PICKER_BASIS)[0].style.background = '#' + hex; //颜色选择器的背景
|
||||
|
||||
//选择器的top left
|
||||
that.elemPicker.find('.' + PICKER_BASIS_CUR).css({
|
||||
"top": top
|
||||
,"left": left
|
||||
});
|
||||
|
||||
if(type === 'change') return;
|
||||
|
||||
//选中的颜色
|
||||
that.elemPicker.find('.' + PICKER_INPUT).find('input').val('#' + color);
|
||||
};
|
||||
|
||||
Class.prototype.pickerEvents = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
|
||||
,elemColorBoxSpan = that.elemColorBox.find('.' + PICKER_TRIG_SPAN) //颜色盒子
|
||||
,elemPickerInput = that.elemPicker.find('.' + PICKER_INPUT + ' input') //颜色选择器表单
|
||||
|
||||
,pickerEvents = {
|
||||
//清空
|
||||
clear: function(othis){
|
||||
elemColorBoxSpan[0].style.background ='';
|
||||
that.elemColorBox.find('.' + PICKER_TRIG_I).removeClass(ICON_PICKER_DOWN).addClass(ICON_PICKER_CLOSE);
|
||||
that.color = '';
|
||||
|
||||
options.done && options.done('');
|
||||
that.removePicker();
|
||||
}
|
||||
|
||||
//确认
|
||||
,confirm: function(othis, change){
|
||||
var value = elemPickerInput.val()
|
||||
,colorValue = value
|
||||
,hsb = {};
|
||||
|
||||
if(value.indexOf(',') > -1){
|
||||
hsb = RGBToHSB(RGBSTo(value));
|
||||
that.select(hsb.h, hsb.s, hsb.b);
|
||||
elemColorBoxSpan[0].style.background = (colorValue = '#' + HSBToHEX(hsb));
|
||||
|
||||
if((value.match(/[0-9]{1,3}/g) || []).length > 3 && elemColorBoxSpan.attr('lay-type') === 'rgba'){
|
||||
var left = value.slice(value.lastIndexOf(",") + 1, value.length - 1) * 280;
|
||||
that.elemPicker.find('.' + PICKER_ALPHA_SLIDER).css("left", left);
|
||||
elemColorBoxSpan[0].style.background = value;
|
||||
colorValue = value;
|
||||
};
|
||||
} else {
|
||||
hsb = HEXToHSB(value);
|
||||
elemColorBoxSpan[0].style.background = (colorValue = '#' + HSBToHEX(hsb));
|
||||
that.elemColorBox.find('.' + PICKER_TRIG_I).removeClass(ICON_PICKER_CLOSE).addClass(ICON_PICKER_DOWN);
|
||||
};
|
||||
|
||||
if(change === 'change'){
|
||||
that.select(hsb.h, hsb.s, hsb.b, change);
|
||||
options.change && options.change(colorValue);
|
||||
return;
|
||||
}
|
||||
that.color = value;
|
||||
|
||||
options.done && options.done(value);
|
||||
that.removePicker();
|
||||
}
|
||||
};
|
||||
|
||||
//选择器面板点击事件
|
||||
that.elemPicker.on('click', '*[colorpicker-events]', function(){
|
||||
var othis = $(this)
|
||||
,attrEvent = othis.attr('colorpicker-events');
|
||||
pickerEvents[attrEvent] && pickerEvents[attrEvent].call(this, othis);
|
||||
});
|
||||
|
||||
//输入框事件
|
||||
elemPickerInput.on('keyup', function(e){
|
||||
var othis = $(this)
|
||||
pickerEvents.confirm.call(this, othis, e.keyCode === 13 ? null : 'change');
|
||||
});
|
||||
}
|
||||
|
||||
//颜色选择器输入
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
|
||||
,elemColorBoxSpan = that.elemColorBox.find('.' + PICKER_TRIG_SPAN)
|
||||
|
||||
//弹出颜色选择器
|
||||
that.elemColorBox.on('click' , function(){
|
||||
that.renderPicker();
|
||||
if($(ELEM_MAIN)[0]){
|
||||
that.val();
|
||||
that.side();
|
||||
};
|
||||
});
|
||||
|
||||
if(!options.elem[0] || that.elemColorBox[0].eventHandler) return;
|
||||
|
||||
//绑定关闭控件事件
|
||||
$doc.on(clickOrMousedown, function(e){
|
||||
//如果点击的元素是颜色框
|
||||
if($(e.target).hasClass(ELEM)
|
||||
|| $(e.target).parents('.'+ELEM)[0]
|
||||
) return;
|
||||
|
||||
//如果点击的元素是选择器
|
||||
if($(e.target).hasClass(ELEM_MAIN.replace(/\./g, ''))
|
||||
|| $(e.target).parents(ELEM_MAIN)[0]
|
||||
) return;
|
||||
|
||||
if(!that.elemPicker) return;
|
||||
|
||||
if(that.color){
|
||||
var hsb = RGBToHSB(RGBSTo(that.color));
|
||||
that.select(hsb.h, hsb.s, hsb.b);
|
||||
} else {
|
||||
that.elemColorBox.find('.' + PICKER_TRIG_I).removeClass(ICON_PICKER_DOWN).addClass(ICON_PICKER_CLOSE);
|
||||
}
|
||||
elemColorBoxSpan[0].style.background = that.color || '';
|
||||
|
||||
that.removePicker();
|
||||
});
|
||||
|
||||
//自适应定位
|
||||
$win.on('resize', function(){
|
||||
if(!that.elemPicker || !$(ELEM_MAIN)[0]){
|
||||
return false;
|
||||
}
|
||||
that.position();
|
||||
});
|
||||
|
||||
that.elemColorBox[0].eventHandler = true;
|
||||
};
|
||||
|
||||
//核心入口
|
||||
colorpicker.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisColorPicker.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, colorpicker);
|
||||
});
|
||||
@@ -1,135 +0,0 @@
|
||||
|
||||
/*!
|
||||
* MODULE_DEMO_NAME 模块组件通用结构
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
layui.define([''], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
|
||||
//模块名
|
||||
,MOD_NAME = 'MODULE_DEMO_NAME'
|
||||
,MOD_INDEX = 'layui_'+ MOD_NAME +'_index' //模块索引名
|
||||
|
||||
//外部接口
|
||||
,MODULE_DEMO_NAME = {
|
||||
config: {}
|
||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisModule = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,id = options.id || that.index;
|
||||
|
||||
thisModule.that[id] = that; //记录当前实例对象
|
||||
|
||||
return {
|
||||
config: options
|
||||
//重置实例
|
||||
,reload: function(options){
|
||||
that.reload.call(that, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,STR_ELEM = 'layui-MODULE_DEMO_NAME', STR_HIDE = 'layui-hide', STR_DISABLED = 'layui-disabled', STR_NONE = 'layui-none'
|
||||
|
||||
//主模板
|
||||
,TPL_MAIN = [''].join('')
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.index = ++MODULE_DEMO_NAME.index;
|
||||
that.config = $.extend({}, that.config, MODULE_DEMO_NAME.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
|
||||
};
|
||||
|
||||
//重载实例
|
||||
Class.prototype.reload = function(options){
|
||||
var that = this;
|
||||
|
||||
//防止数组深度合并
|
||||
layui.each(options, function(key, item){
|
||||
if(layui._typeof(item) === 'array') delete that.config[key];
|
||||
});
|
||||
|
||||
that.config = $.extend(true, {}, that.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//解析模板
|
||||
var thisElem = that.elem = $(laytpl(TPL_MAIN).render({
|
||||
data: options
|
||||
,index: that.index //索引
|
||||
}));
|
||||
|
||||
var othis = options.elem = $(options.elem);
|
||||
if(!othis[0]) return;
|
||||
|
||||
|
||||
|
||||
that.events(); //事件
|
||||
};
|
||||
|
||||
//事件
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
|
||||
};
|
||||
|
||||
//记录所有实例
|
||||
thisModule.that = {}; //记录所有实例对象
|
||||
|
||||
//获取当前实例对象
|
||||
thisModule.getThis = function(id){
|
||||
var that = thisModule.that[id];
|
||||
if(!that) hint.error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
|
||||
return that
|
||||
};
|
||||
|
||||
//重载实例
|
||||
MODULE_DEMO_NAME.reload = function(id, options){
|
||||
var that = thisModule.that[id];
|
||||
that.reload(options);
|
||||
|
||||
return thisModule.call(that);
|
||||
};
|
||||
|
||||
//核心入口
|
||||
MODULE_DEMO_NAME.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisModule.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, MODULE_DEMO_NAME);
|
||||
});
|
||||
@@ -1,528 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:dropdown 下拉菜单组件
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,laytpl = layui.laytpl
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
,clickOrMousedown = (device.mobile ? 'click' : 'mousedown')
|
||||
|
||||
//模块名
|
||||
,MOD_NAME = 'dropdown'
|
||||
,MOD_INDEX = 'layui_'+ MOD_NAME +'_index' //模块索引名
|
||||
|
||||
//外部接口
|
||||
,dropdown = {
|
||||
config: {}
|
||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisModule = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,id = options.id;
|
||||
|
||||
thisModule.that[id] = that; //记录当前实例对象
|
||||
|
||||
return {
|
||||
config: options
|
||||
//重置实例
|
||||
,reload: function(options){
|
||||
that.reload.call(that, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,STR_ELEM = 'layui-dropdown', STR_HIDE = 'layui-hide', STR_DISABLED = 'layui-disabled', STR_NONE = 'layui-none'
|
||||
,STR_ITEM_UP = 'layui-menu-item-up', STR_ITEM_DOWN = 'layui-menu-item-down', STR_MENU_TITLE = 'layui-menu-body-title', STR_ITEM_GROUP = 'layui-menu-item-group', STR_ITEM_PARENT = 'layui-menu-item-parent', STR_ITEM_DIV = 'layui-menu-item-divider', STR_ITEM_CHECKED = 'layui-menu-item-checked', STR_ITEM_CHECKED2 = 'layui-menu-item-checked2', STR_MENU_PANEL = 'layui-menu-body-panel', STR_MENU_PANEL_L = 'layui-menu-body-panel-left'
|
||||
|
||||
,STR_GROUP_TITLE = '.'+ STR_ITEM_GROUP + '>.'+ STR_MENU_TITLE
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.index = ++dropdown.index;
|
||||
that.config = $.extend({}, that.config, dropdown.config, options);
|
||||
that.init();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
trigger: 'click' //事件类型
|
||||
,content: '' //自定义菜单内容
|
||||
,className: '' //自定义样式类名
|
||||
,style: '' //设置面板 style 属性
|
||||
,show: false //是否初始即显示菜单面板
|
||||
,isAllowSpread: true //是否允许菜单组展开收缩
|
||||
,isSpreadItem: true //是否初始展开子菜单
|
||||
,data: [] //菜单数据结构
|
||||
,delay: 300 //延迟关闭的毫秒数,若 trigger 为 hover 时才生效
|
||||
};
|
||||
|
||||
//重载实例
|
||||
Class.prototype.reload = function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
that.init(true);
|
||||
};
|
||||
|
||||
//初始化准备
|
||||
Class.prototype.init = function(rerender){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elem = options.elem = $(options.elem);
|
||||
|
||||
//若 elem 非唯一
|
||||
if(elem.length > 1){
|
||||
layui.each(elem, function(){
|
||||
dropdown.render($.extend({}, options, {
|
||||
elem: this
|
||||
}));
|
||||
});
|
||||
return that;
|
||||
}
|
||||
|
||||
//若重复执行 render,则视为 reload 处理
|
||||
if(!rerender && elem[0] && elem.data(MOD_INDEX)){;
|
||||
var newThat = thisModule.getThis(elem.data(MOD_INDEX));
|
||||
if(!newThat) return;
|
||||
|
||||
return newThat.reload(options);
|
||||
};
|
||||
|
||||
//初始化 id 参数
|
||||
options.id = ('id' in options) ? options.id : that.index;
|
||||
|
||||
if(options.show) that.render(rerender); //初始即显示
|
||||
that.events(); //事件
|
||||
};
|
||||
|
||||
//渲染
|
||||
Class.prototype.render = function(rerender){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemBody = $('body')
|
||||
|
||||
//默认菜单内容
|
||||
,getDefaultView = function(){
|
||||
var elemUl = $('<ul class="layui-menu layui-dropdown-menu"></ul>');
|
||||
if(options.data.length > 0 ){
|
||||
eachItemView(elemUl, options.data)
|
||||
} else {
|
||||
elemUl.html('<li class="layui-menu-item-none">no menu</li>');
|
||||
}
|
||||
return elemUl;
|
||||
}
|
||||
|
||||
//遍历菜单项
|
||||
,eachItemView = function(views, data){
|
||||
//var views = [];
|
||||
layui.each(data, function(index, item){
|
||||
//是否存在子级
|
||||
var isChild = item.child && item.child.length > 0
|
||||
,isSpreadItem = ('isSpreadItem' in item) ? item.isSpreadItem : options.isSpreadItem
|
||||
,title = item.templet
|
||||
? laytpl(item.templet).render(item)
|
||||
: (options.templet ? laytpl(options.templet).render(item) : item.title)
|
||||
|
||||
//初始类型
|
||||
,type = function(){
|
||||
if(isChild){
|
||||
item.type = item.type || 'parent';
|
||||
}
|
||||
if(item.type){
|
||||
return ({
|
||||
group: 'group'
|
||||
,parent: 'parent'
|
||||
,'-': '-'
|
||||
})[item.type] || 'parent';
|
||||
}
|
||||
return '';
|
||||
}();
|
||||
|
||||
if(type !== '-' && (!item.title && !item.id && !isChild)) return;
|
||||
|
||||
//列表元素
|
||||
var viewLi = $(['<li'+ function(){
|
||||
var className = {
|
||||
group: 'layui-menu-item-group'+ (
|
||||
options.isAllowSpread ? (
|
||||
isSpreadItem ? ' layui-menu-item-down' : ' layui-menu-item-up'
|
||||
) : ''
|
||||
)
|
||||
,parent: STR_ITEM_PARENT
|
||||
,'-': 'layui-menu-item-divider'
|
||||
};
|
||||
if(isChild || type){
|
||||
return ' class="'+ className[type] +'"';
|
||||
}
|
||||
return '';
|
||||
}() +'>'
|
||||
|
||||
//标题区
|
||||
,function(){
|
||||
//是否超文本
|
||||
var viewText = ('href' in item) ? (
|
||||
'<a href="'+ item.href +'" target="'+ (item.target || '_self') +'">'+ title +'</a>'
|
||||
) : title;
|
||||
|
||||
//是否存在子级
|
||||
if(isChild){
|
||||
return '<div class="'+ STR_MENU_TITLE +'">'+ viewText + function(){
|
||||
if(type === 'parent'){
|
||||
return '<i class="layui-icon layui-icon-right"></i>';
|
||||
} else if(type === 'group' && options.isAllowSpread){
|
||||
return '<i class="layui-icon layui-icon-'+ (isSpreadItem ? 'up' : 'down') +'"></i>';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}() +'</div>'
|
||||
|
||||
}
|
||||
return '<div class="'+ STR_MENU_TITLE +'">'+ viewText +'</div>';
|
||||
}()
|
||||
,'</li>'].join(''));
|
||||
|
||||
viewLi.data('item', item);
|
||||
|
||||
//子级区
|
||||
if(isChild){
|
||||
var elemPanel = $('<div class="layui-panel layui-menu-body-panel"></div>')
|
||||
,elemUl = $('<ul></ul>');
|
||||
|
||||
if(type === 'parent'){
|
||||
elemPanel.append(eachItemView(elemUl, item.child));
|
||||
viewLi.append(elemPanel);
|
||||
} else {
|
||||
viewLi.append(eachItemView(elemUl, item.child));
|
||||
}
|
||||
}
|
||||
|
||||
views.append(viewLi);
|
||||
});
|
||||
return views;
|
||||
}
|
||||
|
||||
//主模板
|
||||
,TPL_MAIN = ['<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit">'
|
||||
,'</div>'].join('');
|
||||
|
||||
//如果是右键事件,则每次触发事件时,将允许重新渲染
|
||||
if(options.trigger === 'contextmenu' || lay.isTopElem(options.elem[0])) rerender = true;
|
||||
|
||||
//判断是否已经打开了下拉菜单面板
|
||||
if(!rerender && options.elem.data(MOD_INDEX +'_opened')) return;
|
||||
|
||||
//记录模板对象
|
||||
that.elemView = $(TPL_MAIN);
|
||||
that.elemView.append(options.content || getDefaultView());
|
||||
|
||||
//初始化某些属性
|
||||
if(options.className) that.elemView.addClass(options.className);
|
||||
if(options.style) that.elemView.attr('style', options.style);
|
||||
|
||||
|
||||
//记录当前执行的实例索引
|
||||
dropdown.thisId = options.id;
|
||||
|
||||
//插入视图
|
||||
that.remove(); //移除非当前绑定元素的面板
|
||||
elemBody.append(that.elemView);
|
||||
options.elem.data(MOD_INDEX +'_opened', true);
|
||||
|
||||
//坐标定位
|
||||
that.position();
|
||||
thisModule.prevElem = that.elemView; //记录当前打开的元素,以便在下次关闭
|
||||
thisModule.prevElem.data('prevElem', options.elem); //将当前绑定的元素,记录在打开元素的 data 对象中
|
||||
|
||||
//阻止全局事件
|
||||
that.elemView.find('.layui-menu').on(clickOrMousedown, function(e){
|
||||
layui.stope(e);
|
||||
});
|
||||
|
||||
//触发菜单列表事件
|
||||
that.elemView.find('.layui-menu li').on('click', function(e){
|
||||
var othis = $(this)
|
||||
,data = othis.data('item') || {}
|
||||
,isChild = data.child && data.child.length > 0;
|
||||
|
||||
if(!isChild && data.type !== '-'){
|
||||
that.remove();
|
||||
typeof options.click === 'function' && options.click(data, othis);
|
||||
}
|
||||
});
|
||||
|
||||
//触发菜单组展开收缩
|
||||
that.elemView.find(STR_GROUP_TITLE).on('click', function(e){
|
||||
var othis = $(this)
|
||||
,elemGroup = othis.parent()
|
||||
,data = elemGroup.data('item') || {}
|
||||
|
||||
if(data.type === 'group' && options.isAllowSpread){
|
||||
thisModule.spread(elemGroup);
|
||||
}
|
||||
});
|
||||
|
||||
//如果是鼠标移入事件,则鼠标移出时自动关闭
|
||||
if(options.trigger === 'mouseenter'){
|
||||
that.elemView.on('mouseenter', function(){
|
||||
clearTimeout(thisModule.timer);
|
||||
}).on('mouseleave', function(){
|
||||
that.delayRemove();
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//位置定位
|
||||
Class.prototype.position = function(obj){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
lay.position(options.elem[0], that.elemView[0], {
|
||||
position: options.position
|
||||
,e: that.e
|
||||
,clickType: options.trigger === 'contextmenu' ? 'right' : null
|
||||
,align: options.align || null
|
||||
});
|
||||
};
|
||||
|
||||
//删除视图
|
||||
Class.prototype.remove = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemPrev = thisModule.prevElem;
|
||||
|
||||
//若存在已打开的面板元素,则移除
|
||||
if(elemPrev){
|
||||
elemPrev.data('prevElem') && (
|
||||
elemPrev.data('prevElem').data(MOD_INDEX +'_opened', false)
|
||||
);
|
||||
elemPrev.remove();
|
||||
}
|
||||
};
|
||||
|
||||
//延迟删除视图
|
||||
Class.prototype.delayRemove = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
clearTimeout(thisModule.timer);
|
||||
|
||||
thisModule.timer = setTimeout(function(){
|
||||
that.remove();
|
||||
}, options.delay);
|
||||
};
|
||||
|
||||
//事件
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//如果传入 hover,则解析为 mouseenter
|
||||
if(options.trigger === 'hover') options.trigger = 'mouseenter';
|
||||
|
||||
//解除上一个事件
|
||||
if(that.prevElem) that.prevElem.off(options.trigger, that.prevElemCallback);
|
||||
|
||||
//记录被绑定的元素及回调
|
||||
that.prevElem = options.elem;
|
||||
that.prevElemCallback = function(e){
|
||||
clearTimeout(thisModule.timer);
|
||||
that.e = e;
|
||||
that.render();
|
||||
e.preventDefault();
|
||||
|
||||
//组件打开完毕的时间
|
||||
typeof options.ready === 'function' && options.ready(that.elemView, options.elem, that.e.target);
|
||||
};
|
||||
|
||||
//触发元素事件
|
||||
options.elem.on(options.trigger, that.prevElemCallback);
|
||||
|
||||
//如果是鼠标移入事件
|
||||
if(options.trigger === 'mouseenter'){
|
||||
//直行鼠标移出事件
|
||||
options.elem.on('mouseleave', function(){
|
||||
that.delayRemove();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//记录所有实例
|
||||
thisModule.that = {}; //记录所有实例对象
|
||||
|
||||
//获取当前实例对象
|
||||
thisModule.getThis = function(id){
|
||||
var that = thisModule.that[id];
|
||||
if(!that) hint.error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
|
||||
return that;
|
||||
};
|
||||
|
||||
//设置菜单组展开和收缩状态
|
||||
thisModule.spread = function(othis){
|
||||
//菜单组展开和收缩
|
||||
var elemIcon = othis.children('.'+ STR_MENU_TITLE).find('.layui-icon');
|
||||
if(othis.hasClass(STR_ITEM_UP)){
|
||||
othis.removeClass(STR_ITEM_UP).addClass(STR_ITEM_DOWN);
|
||||
elemIcon.removeClass('layui-icon-down').addClass('layui-icon-up');
|
||||
} else {
|
||||
othis.removeClass(STR_ITEM_DOWN).addClass(STR_ITEM_UP);
|
||||
elemIcon.removeClass('layui-icon-up').addClass('layui-icon-down')
|
||||
}
|
||||
};
|
||||
|
||||
//全局事件
|
||||
;!function(){
|
||||
var _WIN = $(window)
|
||||
,_DOC = $(document);
|
||||
|
||||
//自适应定位
|
||||
_WIN.on('resize', function(){
|
||||
if(!dropdown.thisId) return;
|
||||
var that = thisModule.getThis(dropdown.thisId);
|
||||
if(!that) return;
|
||||
|
||||
if(!that.elemView[0] || !$('.'+ STR_ELEM)[0]){
|
||||
return false;
|
||||
}
|
||||
|
||||
var options = that.config;
|
||||
|
||||
if(options.trigger === 'contextmenu'){
|
||||
that.remove();
|
||||
} else {
|
||||
that.position();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
//点击任意处关闭
|
||||
_DOC.on(clickOrMousedown, function(e){
|
||||
if(!dropdown.thisId) return;
|
||||
var that = thisModule.getThis(dropdown.thisId)
|
||||
if(!that) return;
|
||||
|
||||
var options = that.config;
|
||||
|
||||
//如果触发的是绑定的元素,或者属于绑定元素的子元素,则不关闭
|
||||
//满足条件:当前绑定的元素不是 body document,或者不是鼠标右键事件
|
||||
if(!(lay.isTopElem(options.elem[0]) || options.trigger === 'contextmenu')){
|
||||
if(
|
||||
e.target === options.elem[0] ||
|
||||
options.elem.find(e.target)[0] ||
|
||||
e.target === that.elemView[0] ||
|
||||
(that.elemView && that.elemView.find(e.target)[0])
|
||||
) return;
|
||||
}
|
||||
|
||||
that.remove();
|
||||
});
|
||||
|
||||
//基础菜单的静态元素事件
|
||||
var ELEM_LI = '.layui-menu:not(.layui-dropdown-menu) li';
|
||||
_DOC.on('click', ELEM_LI, function(e){
|
||||
var othis = $(this)
|
||||
,parent = othis.parents('.layui-menu').eq(0)
|
||||
,isChild = othis.hasClass(STR_ITEM_GROUP) || othis.hasClass(STR_ITEM_PARENT)
|
||||
,filter = parent.attr('lay-filter') || parent.attr('id')
|
||||
,options = lay.options(this);
|
||||
|
||||
//非触发元素
|
||||
if(othis.hasClass(STR_ITEM_DIV)) return;
|
||||
|
||||
//非菜单组
|
||||
if(!isChild){
|
||||
//选中
|
||||
parent.find('.'+ STR_ITEM_CHECKED).removeClass(STR_ITEM_CHECKED); //清除选中样式
|
||||
parent.find('.'+ STR_ITEM_CHECKED2).removeClass(STR_ITEM_CHECKED2); //清除父级菜单选中样式
|
||||
othis.addClass(STR_ITEM_CHECKED); //添加选中样式
|
||||
othis.parents('.'+ STR_ITEM_PARENT).addClass(STR_ITEM_CHECKED2); //添加父级菜单选中样式
|
||||
|
||||
//触发事件
|
||||
layui.event.call(this, MOD_NAME, 'click('+ filter +')', options);
|
||||
}
|
||||
});
|
||||
|
||||
//基础菜单的展开收缩事件
|
||||
_DOC.on('click', (ELEM_LI + STR_GROUP_TITLE), function(e){
|
||||
var othis = $(this)
|
||||
,elemGroup = othis.parents('.'+ STR_ITEM_GROUP +':eq(0)')
|
||||
,options = lay.options(elemGroup[0]);
|
||||
|
||||
if(('isAllowSpread' in options) ? options.isAllowSpread : true){
|
||||
thisModule.spread(elemGroup);
|
||||
};
|
||||
});
|
||||
|
||||
//判断子级菜单是否超出屏幕
|
||||
var ELEM_LI_PAR = '.layui-menu .'+ STR_ITEM_PARENT
|
||||
_DOC.on('mouseenter', ELEM_LI_PAR, function(e){
|
||||
var othis = $(this)
|
||||
,elemPanel = othis.find('.'+ STR_MENU_PANEL);
|
||||
|
||||
if(!elemPanel[0]) return;
|
||||
var rect = elemPanel[0].getBoundingClientRect();
|
||||
|
||||
//是否超出右侧屏幕
|
||||
if(rect.right > _WIN.width()){
|
||||
elemPanel.addClass(STR_MENU_PANEL_L);
|
||||
//不允许超出左侧屏幕
|
||||
rect = elemPanel[0].getBoundingClientRect();
|
||||
if(rect.left < 0){
|
||||
elemPanel.removeClass(STR_MENU_PANEL_L);
|
||||
}
|
||||
}
|
||||
|
||||
//是否超出底部屏幕
|
||||
if(rect.bottom > _WIN.height()){
|
||||
elemPanel.eq(0).css('margin-top', -(rect.bottom - _WIN.height()));
|
||||
};
|
||||
}).on('mouseleave', ELEM_LI_PAR, function(e){
|
||||
var othis = $(this)
|
||||
,elemPanel = othis.children('.'+ STR_MENU_PANEL);
|
||||
|
||||
elemPanel.removeClass(STR_MENU_PANEL_L);
|
||||
elemPanel.css('margin-top', 0);
|
||||
});
|
||||
|
||||
}();
|
||||
|
||||
//重载实例
|
||||
dropdown.reload = function(id, options){
|
||||
var that = thisModule.getThis(id);
|
||||
if(!that) return this;
|
||||
|
||||
that.reload(options);
|
||||
return thisModule.call(that);
|
||||
};
|
||||
|
||||
//核心入口
|
||||
dropdown.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisModule.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, dropdown);
|
||||
});
|
||||
@@ -1,510 +0,0 @@
|
||||
|
||||
/*!
|
||||
* element 常用元素操作
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
,MOD_NAME = 'element', THIS = 'layui-this', SHOW = 'layui-show'
|
||||
|
||||
,Element = function(){
|
||||
this.config = {};
|
||||
};
|
||||
|
||||
//全局设置
|
||||
Element.prototype.set = function(options){
|
||||
var that = this;
|
||||
$.extend(true, that.config, options);
|
||||
return that;
|
||||
};
|
||||
|
||||
//表单事件
|
||||
Element.prototype.on = function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
};
|
||||
|
||||
//外部Tab新增
|
||||
Element.prototype.tabAdd = function(filter, options){
|
||||
var TITLE = '.layui-tab-title'
|
||||
,tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children(TITLE)
|
||||
,barElem = titElem.children('.layui-tab-bar')
|
||||
,contElem = tabElem.children('.layui-tab-content')
|
||||
,li = '<li'+ function(){
|
||||
var layAttr = [];
|
||||
layui.each(options, function(key, value){
|
||||
if(/^(title|content)$/.test(key)) return;
|
||||
layAttr.push('lay-'+ key +'="'+ value +'"');
|
||||
});
|
||||
if(layAttr.length > 0) layAttr.unshift(''); //向前插,预留空格
|
||||
return layAttr.join(' ');
|
||||
}() +'>'+ (options.title || 'unnaming') +'</li>';
|
||||
|
||||
barElem[0] ? barElem.before(li) : titElem.append(li);
|
||||
contElem.append('<div class="layui-tab-item">'+ (options.content || '') +'</div>');
|
||||
call.hideTabMore(true);
|
||||
call.tabAuto();
|
||||
return this;
|
||||
};
|
||||
|
||||
//外部Tab删除
|
||||
Element.prototype.tabDelete = function(filter, layid){
|
||||
var TITLE = '.layui-tab-title'
|
||||
,tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children(TITLE)
|
||||
,liElem = titElem.find('>li[lay-id="'+ layid +'"]');
|
||||
call.tabDelete(null, liElem);
|
||||
return this;
|
||||
};
|
||||
|
||||
//外部Tab切换
|
||||
Element.prototype.tabChange = function(filter, layid){
|
||||
var TITLE = '.layui-tab-title'
|
||||
,tabElem = $('.layui-tab[lay-filter='+ filter +']')
|
||||
,titElem = tabElem.children(TITLE)
|
||||
,liElem = titElem.find('>li[lay-id="'+ layid +'"]');
|
||||
call.tabClick.call(liElem[0], null, null, liElem);
|
||||
return this;
|
||||
};
|
||||
|
||||
//自定义Tab选项卡
|
||||
Element.prototype.tab = function(options){
|
||||
options = options || {};
|
||||
dom.on('click', options.headerElem, function(e){
|
||||
var index = $(this).index();
|
||||
call.tabClick.call(this, e, index, null, options);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//动态改变进度条
|
||||
Element.prototype.progress = function(filter, percent){
|
||||
var ELEM = 'layui-progress'
|
||||
,elem = $('.'+ ELEM +'[lay-filter='+ filter +']')
|
||||
,elemBar = elem.find('.'+ ELEM +'-bar')
|
||||
,text = elemBar.find('.'+ ELEM +'-text');
|
||||
elemBar.css('width', percent).attr('lay-percent', percent);
|
||||
text.text(percent);
|
||||
return this;
|
||||
};
|
||||
|
||||
var NAV_ELEM = '.layui-nav', NAV_ITEM = 'layui-nav-item', NAV_BAR = 'layui-nav-bar'
|
||||
,NAV_TREE = 'layui-nav-tree', NAV_CHILD = 'layui-nav-child', NAV_CHILD_C = 'layui-nav-child-c'
|
||||
,NAV_MORE = 'layui-nav-more', NAV_DOWN = 'layui-icon-down', NAV_ANIM = 'layui-anim layui-anim-upbit'
|
||||
|
||||
//基础事件体
|
||||
,call = {
|
||||
//Tab 点击
|
||||
tabClick: function(e, index, liElem, options){
|
||||
options = options || {};
|
||||
var othis = liElem || $(this)
|
||||
,index = index || othis.parent().children('li').index(othis)
|
||||
,parents = options.headerElem ? othis.parent() : othis.parents('.layui-tab').eq(0)
|
||||
,item = options.bodyElem ? $(options.bodyElem) : parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,elemA = othis.find('a')
|
||||
,isJump = elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank' //是否存在跳转
|
||||
,unselect = typeof othis.attr('lay-unselect') === 'string' //是否禁用选中
|
||||
,filter = parents.attr('lay-filter');
|
||||
|
||||
//执行切换
|
||||
if(!(isJump || unselect)){
|
||||
othis.addClass(THIS).siblings().removeClass(THIS);
|
||||
item.eq(index).addClass(SHOW).siblings().removeClass(SHOW);
|
||||
}
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'tab('+ filter +')', {
|
||||
elem: parents
|
||||
,index: index
|
||||
});
|
||||
}
|
||||
|
||||
//Tab删除
|
||||
,tabDelete: function(e, othis){
|
||||
var li = othis || $(this).parent(), index = li.index()
|
||||
,parents = li.parents('.layui-tab').eq(0)
|
||||
,item = parents.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,filter = parents.attr('lay-filter');
|
||||
|
||||
if(li.hasClass(THIS)){
|
||||
if(li.next()[0]){
|
||||
call.tabClick.call(li.next()[0], null, index + 1);
|
||||
} else if(li.prev()[0]){
|
||||
call.tabClick.call(li.prev()[0], null, index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
li.remove();
|
||||
item.eq(index).remove();
|
||||
setTimeout(function(){
|
||||
call.tabAuto();
|
||||
}, 50);
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'tabDelete('+ filter +')', {
|
||||
elem: parents
|
||||
,index: index
|
||||
});
|
||||
}
|
||||
|
||||
//Tab自适应
|
||||
,tabAuto: function(){
|
||||
var SCROLL = 'layui-tab-scroll', MORE = 'layui-tab-more', BAR = 'layui-tab-bar'
|
||||
,CLOSE = 'layui-tab-close', that = this;
|
||||
|
||||
$('.layui-tab').each(function(){
|
||||
var othis = $(this)
|
||||
,title = othis.children('.layui-tab-title')
|
||||
,item = othis.children('.layui-tab-content').children('.layui-tab-item')
|
||||
,STOPE = 'lay-stope="tabmore"'
|
||||
,span = $('<span class="layui-unselect layui-tab-bar" '+ STOPE +'><i '+ STOPE +' class="layui-icon"></i></span>');
|
||||
|
||||
if(that === window && device.ie != 8){
|
||||
call.hideTabMore(true)
|
||||
}
|
||||
|
||||
//允许关闭
|
||||
if(othis.attr('lay-allowClose')){
|
||||
title.find('li').each(function(){
|
||||
var li = $(this);
|
||||
if(!li.find('.'+CLOSE)[0]){
|
||||
var close = $('<i class="layui-icon layui-icon-close layui-unselect '+ CLOSE +'"></i>');
|
||||
close.on('click', call.tabDelete);
|
||||
li.append(close);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(typeof othis.attr('lay-unauto') === 'string') return;
|
||||
|
||||
//响应式
|
||||
if(title.prop('scrollWidth') > title.outerWidth()+1){
|
||||
if(title.find('.'+BAR)[0]) return;
|
||||
title.append(span);
|
||||
othis.attr('overflow', '');
|
||||
span.on('click', function(e){
|
||||
title[this.title ? 'removeClass' : 'addClass'](MORE);
|
||||
this.title = this.title ? '' : '收缩';
|
||||
});
|
||||
} else {
|
||||
title.find('.'+BAR).remove();
|
||||
othis.removeAttr('overflow');
|
||||
}
|
||||
});
|
||||
}
|
||||
//隐藏更多Tab
|
||||
,hideTabMore: function(e){
|
||||
var tsbTitle = $('.layui-tab-title');
|
||||
if(e === true || $(e.target).attr('lay-stope') !== 'tabmore'){
|
||||
tsbTitle.removeClass('layui-tab-more');
|
||||
tsbTitle.find('.layui-tab-bar').attr('title','');
|
||||
}
|
||||
}
|
||||
|
||||
//点击一级菜单
|
||||
/*
|
||||
,clickThis: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,elemA = othis.find('a')
|
||||
,unselect = typeof othis.attr('lay-unselect') === 'string';
|
||||
|
||||
if(othis.find('.'+NAV_CHILD)[0]) return;
|
||||
|
||||
if(!(elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank') && !unselect){
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
othis.addClass(THIS);
|
||||
}
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'nav('+ filter +')', othis);
|
||||
}
|
||||
)
|
||||
*/
|
||||
|
||||
//点击菜单 - a标签触发
|
||||
,clickThis: function(){
|
||||
var othis = $(this)
|
||||
,parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,parent = othis.parent()
|
||||
,child = othis.siblings('.'+NAV_CHILD)
|
||||
,unselect = typeof parent.attr('lay-unselect') === 'string'; //是否禁用选中
|
||||
|
||||
if(!(othis.attr('href') !== 'javascript:;' && othis.attr('target') === '_blank') && !unselect){
|
||||
if(!child[0]){
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
parent.addClass(THIS);
|
||||
}
|
||||
}
|
||||
|
||||
//如果是垂直菜单
|
||||
if(parents.hasClass(NAV_TREE)){
|
||||
child.removeClass(NAV_ANIM);
|
||||
|
||||
//如果有子菜单,则展开
|
||||
if(child[0]){
|
||||
parent[child.css('display') === 'none' ? 'addClass': 'removeClass'](NAV_ITEM+'ed');
|
||||
if(parents.attr('lay-shrink') === 'all'){
|
||||
parent.siblings().removeClass(NAV_ITEM + 'ed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'nav('+ filter +')', othis);
|
||||
}
|
||||
|
||||
//点击子菜单选中
|
||||
/*
|
||||
,clickChild: function(){
|
||||
var othis = $(this), parents = othis.parents(NAV_ELEM)
|
||||
,filter = parents.attr('lay-filter');
|
||||
parents.find('.'+THIS).removeClass(THIS);
|
||||
othis.addClass(THIS);
|
||||
layui.event.call(this, MOD_NAME, 'nav('+ filter +')', othis);
|
||||
}
|
||||
*/
|
||||
|
||||
//折叠面板
|
||||
,collapse: function(){
|
||||
var othis = $(this), icon = othis.find('.layui-colla-icon')
|
||||
,elemCont = othis.siblings('.layui-colla-content')
|
||||
,parents = othis.parents('.layui-collapse').eq(0)
|
||||
,filter = parents.attr('lay-filter')
|
||||
,isNone = elemCont.css('display') === 'none';
|
||||
|
||||
//是否手风琴
|
||||
if(typeof parents.attr('lay-accordion') === 'string'){
|
||||
var show = parents.children('.layui-colla-item').children('.'+SHOW);
|
||||
show.siblings('.layui-colla-title').children('.layui-colla-icon').html('');
|
||||
show.removeClass(SHOW);
|
||||
}
|
||||
|
||||
elemCont[isNone ? 'addClass' : 'removeClass'](SHOW);
|
||||
icon.html(isNone ? '' : '');
|
||||
|
||||
layui.event.call(this, MOD_NAME, 'collapse('+ filter +')', {
|
||||
title: othis
|
||||
,content: elemCont
|
||||
,show: isNone
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//初始化元素操作
|
||||
Element.prototype.init = function(type, filter){
|
||||
var that = this, elemFilter = function(){
|
||||
return filter ? ('[lay-filter="' + filter +'"]') : '';
|
||||
}(), items = {
|
||||
|
||||
//Tab选项卡
|
||||
tab: function(){
|
||||
call.tabAuto.call({});
|
||||
}
|
||||
|
||||
//导航菜单
|
||||
,nav: function(){
|
||||
var TIME = 200, timer = {}, timerMore = {}, timeEnd = {}, NAV_TITLE = 'layui-nav-title'
|
||||
|
||||
//滑块跟随
|
||||
,follow = function(bar, nav, index){
|
||||
var othis = $(this), child = othis.find('.'+NAV_CHILD);
|
||||
if(nav.hasClass(NAV_TREE)){
|
||||
//无子菜单时跟随
|
||||
if(!child[0]){
|
||||
var thisA = othis.children('.'+ NAV_TITLE);
|
||||
bar.css({
|
||||
top: othis.offset().top - nav.offset().top
|
||||
,height: (thisA[0] ? thisA : othis).outerHeight()
|
||||
,opacity: 1
|
||||
});
|
||||
}
|
||||
} else {
|
||||
child.addClass(NAV_ANIM);
|
||||
|
||||
//若居中对齐
|
||||
if(child.hasClass(NAV_CHILD_C)) child.css({
|
||||
left: -(child.outerWidth() - othis.width())/2
|
||||
});
|
||||
|
||||
//滑块定位
|
||||
if(child[0]){ //若有子菜单,则滑块消失
|
||||
bar.css({
|
||||
left: bar.position().left + bar.width()/2
|
||||
,width: 0
|
||||
,opacity: 0
|
||||
});
|
||||
} else { //bar 跟随
|
||||
bar.css({
|
||||
left: othis.position().left + parseFloat(othis.css('marginLeft'))
|
||||
,top: othis.position().top + othis.height() - bar.height()
|
||||
});
|
||||
}
|
||||
|
||||
//渐显滑块并适配宽度
|
||||
timer[index] = setTimeout(function(){
|
||||
bar.css({
|
||||
width: child[0] ? 0 : othis.width()
|
||||
,opacity: child[0] ? 0 : 1
|
||||
});
|
||||
}, device.ie && device.ie < 10 ? 0 : TIME);
|
||||
|
||||
//显示子菜单
|
||||
clearTimeout(timeEnd[index]);
|
||||
if(child.css('display') === 'block'){
|
||||
clearTimeout(timerMore[index]);
|
||||
}
|
||||
timerMore[index] = setTimeout(function(){
|
||||
child.addClass(SHOW);
|
||||
othis.find('.'+NAV_MORE).addClass(NAV_MORE+'d');
|
||||
}, 300);
|
||||
}
|
||||
};
|
||||
|
||||
//遍历导航
|
||||
$(NAV_ELEM + elemFilter).each(function(index){
|
||||
var othis = $(this)
|
||||
,bar = $('<span class="'+ NAV_BAR +'"></span>')
|
||||
,itemElem = othis.find('.'+NAV_ITEM);
|
||||
|
||||
//hover 滑动效果
|
||||
if(!othis.find('.'+NAV_BAR)[0]){
|
||||
othis.append(bar);
|
||||
(othis.hasClass(NAV_TREE)
|
||||
? itemElem.find('dd,>.'+ NAV_TITLE)
|
||||
: itemElem).on('mouseenter', function(){
|
||||
follow.call(this, bar, othis, index);
|
||||
}).on('mouseleave', function(){ //鼠标移出
|
||||
//是否为垂直导航
|
||||
if(othis.hasClass(NAV_TREE)){
|
||||
bar.css({
|
||||
height: 0
|
||||
,opacity: 0
|
||||
});
|
||||
} else {
|
||||
//隐藏子菜单
|
||||
clearTimeout(timerMore[index]);
|
||||
timerMore[index] = setTimeout(function(){
|
||||
othis.find('.'+NAV_CHILD).removeClass(SHOW);
|
||||
othis.find('.'+NAV_MORE).removeClass(NAV_MORE+'d');
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
othis.on('mouseleave', function(){
|
||||
clearTimeout(timer[index])
|
||||
timeEnd[index] = setTimeout(function(){
|
||||
if(!othis.hasClass(NAV_TREE)){
|
||||
bar.css({
|
||||
width: 0
|
||||
,left: bar.position().left + bar.width()/2
|
||||
,opacity: 0
|
||||
});
|
||||
}
|
||||
}, TIME);
|
||||
});
|
||||
}
|
||||
|
||||
//展开子菜单
|
||||
itemElem.find('a').each(function(){
|
||||
var thisA = $(this)
|
||||
,parent = thisA.parent()
|
||||
,child = thisA.siblings('.'+NAV_CHILD);
|
||||
|
||||
//输出小箭头
|
||||
if(child[0] && !thisA.children('.'+NAV_MORE)[0]){
|
||||
thisA.append('<i class="layui-icon '+ NAV_DOWN +' '+ NAV_MORE +'"></i>');
|
||||
}
|
||||
|
||||
thisA.off('click', call.clickThis).on('click', call.clickThis); //点击菜单
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//面包屑
|
||||
,breadcrumb: function(){
|
||||
var ELEM = '.layui-breadcrumb';
|
||||
|
||||
$(ELEM + elemFilter).each(function(){
|
||||
var othis = $(this)
|
||||
,ATTE_SPR = 'lay-separator'
|
||||
,separator = othis.attr(ATTE_SPR) || '/'
|
||||
,aNode = othis.find('a');
|
||||
if(aNode.next('span['+ ATTE_SPR +']')[0]) return;
|
||||
aNode.each(function(index){
|
||||
if(index === aNode.length - 1) return;
|
||||
$(this).after('<span '+ ATTE_SPR +'>'+ separator +'</span>');
|
||||
});
|
||||
othis.css('visibility', 'visible');
|
||||
});
|
||||
}
|
||||
|
||||
//进度条
|
||||
,progress: function(){
|
||||
var ELEM = 'layui-progress';
|
||||
$('.' + ELEM + elemFilter).each(function(){
|
||||
var othis = $(this)
|
||||
,elemBar = othis.find('.layui-progress-bar')
|
||||
,percent = elemBar.attr('lay-percent');
|
||||
|
||||
elemBar.css('width', function(){
|
||||
return /^.+\/.+$/.test(percent)
|
||||
? (new Function('return '+ percent)() * 100) + '%'
|
||||
: percent;
|
||||
}());
|
||||
|
||||
if(othis.attr('lay-showPercent')){
|
||||
setTimeout(function(){
|
||||
elemBar.html('<span class="'+ ELEM +'-text">'+ percent +'</span>');
|
||||
},350);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//折叠面板
|
||||
,collapse: function(){
|
||||
var ELEM = 'layui-collapse';
|
||||
|
||||
$('.' + ELEM + elemFilter).each(function(){
|
||||
var elemItem = $(this).find('.layui-colla-item')
|
||||
elemItem.each(function(){
|
||||
var othis = $(this)
|
||||
,elemTitle = othis.find('.layui-colla-title')
|
||||
,elemCont = othis.find('.layui-colla-content')
|
||||
,isNone = elemCont.css('display') === 'none';
|
||||
|
||||
//初始状态
|
||||
elemTitle.find('.layui-colla-icon').remove();
|
||||
elemTitle.append('<i class="layui-icon layui-colla-icon">'+ (isNone ? '' : '') +'</i>');
|
||||
|
||||
//点击标题
|
||||
elemTitle.off('click', call.collapse).on('click', call.collapse);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return items[type] ? items[type]() : layui.each(items, function(index, item){
|
||||
item();
|
||||
});
|
||||
};
|
||||
|
||||
Element.prototype.render = Element.prototype.init;
|
||||
|
||||
var element = new Element(), dom = $(document);
|
||||
|
||||
$(function(){
|
||||
element.render();
|
||||
});
|
||||
|
||||
var TITLE = '.layui-tab-title li';
|
||||
dom.on('click', TITLE, call.tabClick); //Tab切换
|
||||
dom.on('click', call.hideTabMore); //隐藏展开的Tab
|
||||
$(window).on('resize', call.tabAuto); //自适应
|
||||
|
||||
exports(MOD_NAME, element);
|
||||
});
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name flow 流加载组件
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$, Flow = function(options){}
|
||||
,ELEM_MORE = 'layui-flow-more'
|
||||
,ELEM_LOAD = '<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon "></i>';
|
||||
|
||||
//主方法
|
||||
Flow.prototype.load = function(options){
|
||||
var that = this, page = 0, lock, isOver, lazyimg, timer;
|
||||
options = options || {};
|
||||
|
||||
var elem = $(options.elem); if(!elem[0]) return;
|
||||
var scrollElem = $(options.scrollElem || document); //滚动条所在元素
|
||||
var mb = options.mb || 50; //与底部的临界距离
|
||||
var isAuto = 'isAuto' in options ? options.isAuto : true; //是否自动滚动加载
|
||||
var end = options.end || '没有更多了'; //“末页”显示文案
|
||||
|
||||
//滚动条所在元素是否为document
|
||||
var notDocment = options.scrollElem && options.scrollElem !== document;
|
||||
|
||||
//加载更多
|
||||
var ELEM_TEXT = '<cite>加载更多</cite>'
|
||||
,more = $('<div class="layui-flow-more"><a href="javascript:;">'+ ELEM_TEXT +'</a></div>');
|
||||
|
||||
if(!elem.find('.layui-flow-more')[0]){
|
||||
elem.append(more);
|
||||
}
|
||||
|
||||
//加载下一个元素
|
||||
var next = function(html, over){
|
||||
html = $(html);
|
||||
more.before(html);
|
||||
over = over == 0 ? true : null;
|
||||
over ? more.html(end) : more.find('a').html(ELEM_TEXT);
|
||||
isOver = over;
|
||||
lock = null;
|
||||
lazyimg && lazyimg();
|
||||
};
|
||||
|
||||
//触发请求
|
||||
var done = function(){
|
||||
lock = true;
|
||||
more.find('a').html(ELEM_LOAD);
|
||||
typeof options.done === 'function' && options.done(++page, next);
|
||||
};
|
||||
|
||||
done();
|
||||
|
||||
//不自动滚动加载
|
||||
more.find('a').on('click', function(){
|
||||
var othis = $(this);
|
||||
if(isOver) return;
|
||||
lock || done();
|
||||
});
|
||||
|
||||
//如果允许图片懒加载
|
||||
if(options.isLazyimg){
|
||||
var lazyimg = that.lazyimg({
|
||||
elem: options.elem + ' img'
|
||||
,scrollElem: options.scrollElem
|
||||
});
|
||||
}
|
||||
|
||||
if(!isAuto) return that;
|
||||
|
||||
scrollElem.on('scroll', function(){
|
||||
var othis = $(this), top = othis.scrollTop();
|
||||
|
||||
if(timer) clearTimeout(timer);
|
||||
if(isOver || !elem.width()) return; //如果已经结束,或者元素处于隐藏状态,则不执行滚动加载
|
||||
|
||||
timer = setTimeout(function(){
|
||||
//计算滚动所在容器的可视高度
|
||||
var height = notDocment ? othis.height() : $(window).height();
|
||||
|
||||
//计算滚动所在容器的实际高度
|
||||
var scrollHeight = notDocment
|
||||
? othis.prop('scrollHeight')
|
||||
: document.documentElement.scrollHeight;
|
||||
|
||||
//临界点
|
||||
if(scrollHeight - top - height <= mb){
|
||||
lock || done();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
//图片懒加载
|
||||
Flow.prototype.lazyimg = function(options){
|
||||
var that = this, index = 0, haveScroll;
|
||||
options = options || {};
|
||||
|
||||
var scrollElem = $(options.scrollElem || document); //滚动条所在元素
|
||||
var elem = options.elem || 'img';
|
||||
|
||||
//滚动条所在元素是否为document
|
||||
var notDocment = options.scrollElem && options.scrollElem !== document;
|
||||
|
||||
//显示图片
|
||||
var show = function(item, height){
|
||||
var start = scrollElem.scrollTop(), end = start + height;
|
||||
var elemTop = notDocment ? function(){
|
||||
return item.offset().top - scrollElem.offset().top + start;
|
||||
}() : item.offset().top;
|
||||
|
||||
/* 始终只加载在当前屏范围内的图片 */
|
||||
if(elemTop >= start && elemTop <= end){
|
||||
if(item.attr('lay-src')){
|
||||
var src = item.attr('lay-src');
|
||||
layui.img(src, function(){
|
||||
var next = that.lazyimg.elem.eq(index);
|
||||
item.attr('src', src).removeAttr('lay-src');
|
||||
|
||||
/* 当前图片加载就绪后,检测下一个图片是否在当前屏 */
|
||||
next[0] && render(next);
|
||||
index++;
|
||||
}, function(){
|
||||
var next = that.lazyimg.elem.eq(index);
|
||||
item.removeAttr('lay-src');
|
||||
});
|
||||
}
|
||||
}
|
||||
}, render = function(othis, scroll){
|
||||
|
||||
//计算滚动所在容器的可视高度
|
||||
var height = notDocment ? (scroll||scrollElem).height() : $(window).height();
|
||||
var start = scrollElem.scrollTop(), end = start + height;
|
||||
|
||||
that.lazyimg.elem = $(elem);
|
||||
|
||||
if(othis){
|
||||
show(othis, height);
|
||||
} else {
|
||||
//计算未加载过的图片
|
||||
for(var i = 0; i < that.lazyimg.elem.length; i++){
|
||||
var item = that.lazyimg.elem.eq(i), elemTop = notDocment ? function(){
|
||||
return item.offset().top - scrollElem.offset().top + start;
|
||||
}() : item.offset().top;
|
||||
|
||||
show(item, height);
|
||||
index = i;
|
||||
|
||||
//如果图片的top坐标,超出了当前屏,则终止后续图片的遍历
|
||||
if(elemTop > end) break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
render();
|
||||
|
||||
if(!haveScroll){
|
||||
var timer;
|
||||
scrollElem.on('scroll', function(){
|
||||
var othis = $(this);
|
||||
if(timer) clearTimeout(timer)
|
||||
timer = setTimeout(function(){
|
||||
render(null, othis);
|
||||
}, 50);
|
||||
});
|
||||
haveScroll = true;
|
||||
}
|
||||
return render;
|
||||
};
|
||||
|
||||
//暴露接口
|
||||
exports('flow', new Flow());
|
||||
});
|
||||
@@ -1,742 +0,0 @@
|
||||
|
||||
/*!
|
||||
* form 表单组件
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
layui.define('layer', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,layer = layui.layer
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
,MOD_NAME = 'form', ELEM = '.layui-form', THIS = 'layui-this'
|
||||
,SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled'
|
||||
|
||||
,Form = function(){
|
||||
this.config = {
|
||||
verify: {
|
||||
required: [
|
||||
/[\S]+/
|
||||
,'必填项不能为空'
|
||||
]
|
||||
,phone: [
|
||||
/^1\d{10}$/
|
||||
,'请输入正确的手机号'
|
||||
]
|
||||
,email: [
|
||||
/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
|
||||
,'邮箱格式不正确'
|
||||
]
|
||||
,url: [
|
||||
/^(#|(http(s?)):\/\/|\/\/)[^\s]+\.[^\s]+$/
|
||||
,'链接格式不正确'
|
||||
]
|
||||
,number: function(value){
|
||||
if(!value || isNaN(value)) return '只能填写数字'
|
||||
}
|
||||
,date: [
|
||||
/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/
|
||||
,'日期格式不正确'
|
||||
]
|
||||
,identity: [
|
||||
/(^\d{15}$)|(^\d{17}(x|X|\d)$)/
|
||||
,'请输入正确的身份证号'
|
||||
]
|
||||
}
|
||||
,autocomplete: null //全局 autocomplete 状态。null 表示不干预
|
||||
};
|
||||
};
|
||||
|
||||
//全局设置
|
||||
Form.prototype.set = function(options){
|
||||
var that = this;
|
||||
$.extend(true, that.config, options);
|
||||
return that;
|
||||
};
|
||||
|
||||
//验证规则设定
|
||||
Form.prototype.verify = function(settings){
|
||||
var that = this;
|
||||
$.extend(true, that.config.verify, settings);
|
||||
return that;
|
||||
};
|
||||
|
||||
//表单事件
|
||||
Form.prototype.on = function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
};
|
||||
|
||||
//赋值/取值
|
||||
Form.prototype.val = function(filter, object){
|
||||
var that = this
|
||||
,formElem = $(ELEM + '[lay-filter="' + filter +'"]');
|
||||
|
||||
//遍历
|
||||
formElem.each(function(index, item){
|
||||
var itemForm = $(this);
|
||||
|
||||
//赋值
|
||||
layui.each(object, function(key, value){
|
||||
var itemElem = itemForm.find('[name="'+ key +'"]')
|
||||
,type;
|
||||
|
||||
//如果对应的表单不存在,则不执行
|
||||
if(!itemElem[0]) return;
|
||||
type = itemElem[0].type;
|
||||
|
||||
//如果为复选框
|
||||
if(type === 'checkbox'){
|
||||
itemElem[0].checked = value;
|
||||
} else if(type === 'radio') { //如果为单选框
|
||||
itemElem.each(function(){
|
||||
if(this.value == value ){
|
||||
this.checked = true
|
||||
}
|
||||
});
|
||||
} else { //其它类型的表单
|
||||
itemElem.val(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
form.render(null, filter);
|
||||
|
||||
//返回值
|
||||
return that.getValue(filter);
|
||||
};
|
||||
|
||||
//取值
|
||||
Form.prototype.getValue = function(filter, itemForm){
|
||||
itemForm = itemForm || $(ELEM + '[lay-filter="' + filter +'"]').eq(0);
|
||||
|
||||
var nameIndex = {} //数组 name 索引
|
||||
,field = {}
|
||||
,fieldElem = itemForm.find('input,select,textarea') //获取所有表单域
|
||||
|
||||
layui.each(fieldElem, function(_, item){
|
||||
var othis = $(this)
|
||||
,init_name; //初始 name
|
||||
|
||||
item.name = (item.name || '').replace(/^\s*|\s*&/, '');
|
||||
if(!item.name) return;
|
||||
|
||||
//用于支持数组 name
|
||||
if(/^.*\[\]$/.test(item.name)){
|
||||
var key = item.name.match(/^(.*)\[\]$/g)[0];
|
||||
nameIndex[key] = nameIndex[key] | 0;
|
||||
init_name = item.name.replace(/^(.*)\[\]$/, '$1['+ (nameIndex[key]++) +']');
|
||||
}
|
||||
|
||||
if(/^checkbox|radio$/.test(item.type) && !item.checked) return; //复选框和单选框未选中,不记录字段
|
||||
field[init_name || item.name] = item.value;
|
||||
});
|
||||
|
||||
return field;
|
||||
};
|
||||
|
||||
//表单控件渲染
|
||||
Form.prototype.render = function(type, filter){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemForm = $(ELEM + function(){
|
||||
return filter ? ('[lay-filter="' + filter +'"]') : '';
|
||||
}())
|
||||
,items = {
|
||||
//输入框
|
||||
input: function(){
|
||||
var inputs = elemForm.find('input,textarea');
|
||||
|
||||
//初始化全局的 autocomplete
|
||||
options.autocomplete && inputs.attr('autocomplete', options.autocomplete);
|
||||
}
|
||||
|
||||
//下拉选择框
|
||||
,select: function(){
|
||||
var TIPS = '请选择', CLASS = 'layui-form-select', TITLE = 'layui-select-title'
|
||||
,NONE = 'layui-select-none', initValue = '', thatInput
|
||||
,selects = elemForm.find('select')
|
||||
|
||||
//隐藏 select
|
||||
,hide = function(e, clear){
|
||||
if(!$(e.target).parent().hasClass(TITLE) || clear){
|
||||
$('.'+CLASS).removeClass(CLASS+'ed ' + CLASS+'up');
|
||||
thatInput && initValue && thatInput.val(initValue);
|
||||
}
|
||||
thatInput = null;
|
||||
}
|
||||
|
||||
//各种事件
|
||||
,events = function(reElem, disabled, isSearch){
|
||||
var select = $(this)
|
||||
,title = reElem.find('.' + TITLE)
|
||||
,input = title.find('input')
|
||||
,dl = reElem.find('dl')
|
||||
,dds = dl.children('dd')
|
||||
,index = this.selectedIndex //当前选中的索引
|
||||
,nearElem; //select 组件当前选中的附近元素,用于辅助快捷键功能
|
||||
|
||||
if(disabled) return;
|
||||
|
||||
//展开下拉
|
||||
var showDown = function(){
|
||||
var top = reElem.offset().top + reElem.outerHeight() + 5 - $win.scrollTop()
|
||||
,dlHeight = dl.outerHeight();
|
||||
|
||||
index = select[0].selectedIndex; //获取最新的 selectedIndex
|
||||
reElem.addClass(CLASS+'ed');
|
||||
dds.removeClass(HIDE);
|
||||
nearElem = null;
|
||||
|
||||
//初始选中样式
|
||||
dds.eq(index).addClass(THIS).siblings().removeClass(THIS);
|
||||
|
||||
//上下定位识别
|
||||
if(top + dlHeight > $win.height() && top >= dlHeight){
|
||||
reElem.addClass(CLASS + 'up');
|
||||
}
|
||||
|
||||
followScroll();
|
||||
}
|
||||
|
||||
//隐藏下拉
|
||||
,hideDown = function(choose){
|
||||
reElem.removeClass(CLASS+'ed ' + CLASS+'up');
|
||||
input.blur();
|
||||
nearElem = null;
|
||||
|
||||
if(choose) return;
|
||||
|
||||
notOption(input.val(), function(none){
|
||||
var selectedIndex = select[0].selectedIndex;
|
||||
|
||||
//未查询到相关值
|
||||
if(none){
|
||||
initValue = $(select[0].options[selectedIndex]).html(); //重新获得初始选中值
|
||||
|
||||
//如果是第一项,且文本值等于 placeholder,则清空初始值
|
||||
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
||||
initValue = '';
|
||||
};
|
||||
|
||||
//如果有选中值,则将输入框纠正为该值。否则清空输入框
|
||||
input.val(initValue || '');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//定位下拉滚动条
|
||||
,followScroll = function(){
|
||||
var thisDd = dl.children('dd.'+ THIS);
|
||||
|
||||
if(!thisDd[0]) return;
|
||||
|
||||
var posTop = thisDd.position().top
|
||||
,dlHeight = dl.height()
|
||||
,ddHeight = thisDd.height();
|
||||
|
||||
//若选中元素在滚动条不可见底部
|
||||
if(posTop > dlHeight){
|
||||
dl.scrollTop(posTop + dl.scrollTop() - dlHeight + ddHeight - 5);
|
||||
}
|
||||
|
||||
//若选择玄素在滚动条不可见顶部
|
||||
if(posTop < 0){
|
||||
dl.scrollTop(posTop + dl.scrollTop() - 5);
|
||||
}
|
||||
};
|
||||
|
||||
//点击标题区域
|
||||
title.on('click', function(e){
|
||||
reElem.hasClass(CLASS+'ed') ? (
|
||||
hideDown()
|
||||
) : (
|
||||
hide(e, true),
|
||||
showDown()
|
||||
);
|
||||
dl.find('.'+NONE).remove();
|
||||
});
|
||||
|
||||
//点击箭头获取焦点
|
||||
title.find('.layui-edge').on('click', function(){
|
||||
input.focus();
|
||||
});
|
||||
|
||||
//select 中 input 键盘事件
|
||||
input.on('keyup', function(e){ //键盘松开
|
||||
var keyCode = e.keyCode;
|
||||
|
||||
//Tab键展开
|
||||
if(keyCode === 9){
|
||||
showDown();
|
||||
}
|
||||
}).on('keydown', function(e){ //键盘按下
|
||||
var keyCode = e.keyCode;
|
||||
|
||||
//Tab键隐藏
|
||||
if(keyCode === 9){
|
||||
hideDown();
|
||||
}
|
||||
|
||||
//标注 dd 的选中状态
|
||||
var setThisDd = function(prevNext, thisElem1){
|
||||
var nearDd, cacheNearElem
|
||||
e.preventDefault();
|
||||
|
||||
//得到当前队列元素
|
||||
var thisElem = function(){
|
||||
var thisDd = dl.children('dd.'+ THIS);
|
||||
|
||||
//如果是搜索状态,且按 Down 键,且当前可视 dd 元素在选中元素之前,
|
||||
//则将当前可视 dd 元素的上一个元素作为虚拟的当前选中元素,以保证递归不中断
|
||||
if(dl.children('dd.'+ HIDE)[0] && prevNext === 'next'){
|
||||
var showDd = dl.children('dd:not(.'+ HIDE +',.'+ DISABLED +')')
|
||||
,firstIndex = showDd.eq(0).index();
|
||||
if(firstIndex >=0 && firstIndex < thisDd.index() && !showDd.hasClass(THIS)){
|
||||
return showDd.eq(0).prev()[0] ? showDd.eq(0).prev() : dl.children(':last');
|
||||
}
|
||||
}
|
||||
|
||||
if(thisElem1 && thisElem1[0]){
|
||||
return thisElem1;
|
||||
}
|
||||
if(nearElem && nearElem[0]){
|
||||
return nearElem;
|
||||
}
|
||||
|
||||
return thisDd;
|
||||
//return dds.eq(index);
|
||||
}();
|
||||
|
||||
cacheNearElem = thisElem[prevNext](); //当前元素的附近元素
|
||||
nearDd = thisElem[prevNext]('dd:not(.'+ HIDE +')'); //当前可视元素的 dd 元素
|
||||
|
||||
//如果附近的元素不存在,则停止执行,并清空 nearElem
|
||||
if(!cacheNearElem[0]) return nearElem = null;
|
||||
|
||||
//记录附近的元素,让其成为下一个当前元素
|
||||
nearElem = thisElem[prevNext]();
|
||||
|
||||
//如果附近不是 dd ,或者附近的 dd 元素是禁用状态,则进入递归查找
|
||||
if((!nearDd[0] || nearDd.hasClass(DISABLED)) && nearElem[0]){
|
||||
return setThisDd(prevNext, nearElem);
|
||||
}
|
||||
|
||||
nearDd.addClass(THIS).siblings().removeClass(THIS); //标注样式
|
||||
followScroll(); //定位滚动条
|
||||
};
|
||||
|
||||
if(keyCode === 38) setThisDd('prev'); //Up 键
|
||||
if(keyCode === 40) setThisDd('next'); //Down 键
|
||||
|
||||
//Enter 键
|
||||
if(keyCode === 13){
|
||||
e.preventDefault();
|
||||
dl.children('dd.'+THIS).trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
//检测值是否不属于 select 项
|
||||
var notOption = function(value, callback, origin){
|
||||
var num = 0;
|
||||
layui.each(dds, function(){
|
||||
var othis = $(this)
|
||||
,text = othis.text()
|
||||
,not = text.indexOf(value) === -1;
|
||||
if(value === '' || (origin === 'blur') ? value !== text : not) num++;
|
||||
origin === 'keyup' && othis[not ? 'addClass' : 'removeClass'](HIDE);
|
||||
});
|
||||
var none = num === dds.length;
|
||||
return callback(none), none;
|
||||
};
|
||||
|
||||
//搜索匹配
|
||||
var search = function(e){
|
||||
var value = this.value, keyCode = e.keyCode;
|
||||
|
||||
if(keyCode === 9 || keyCode === 13
|
||||
|| keyCode === 37 || keyCode === 38
|
||||
|| keyCode === 39 || keyCode === 40
|
||||
){
|
||||
return false;
|
||||
}
|
||||
|
||||
notOption(value, function(none){
|
||||
if(none){
|
||||
dl.find('.'+NONE)[0] || dl.append('<p class="'+ NONE +'">无匹配项</p>');
|
||||
} else {
|
||||
dl.find('.'+NONE).remove();
|
||||
}
|
||||
}, 'keyup');
|
||||
|
||||
if(value === ''){
|
||||
dl.find('.'+NONE).remove();
|
||||
}
|
||||
|
||||
followScroll(); //定位滚动条
|
||||
};
|
||||
|
||||
if(isSearch){
|
||||
input.on('keyup', search).on('blur', function(e){
|
||||
var selectedIndex = select[0].selectedIndex;
|
||||
|
||||
thatInput = input; //当前的 select 中的 input 元素
|
||||
initValue = $(select[0].options[selectedIndex]).html(); //重新获得初始选中值
|
||||
|
||||
//如果是第一项,且文本值等于 placeholder,则清空初始值
|
||||
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
||||
initValue = '';
|
||||
};
|
||||
|
||||
setTimeout(function(){
|
||||
notOption(input.val(), function(none){
|
||||
initValue || input.val(''); //none && !initValue
|
||||
}, 'blur');
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
|
||||
//选择
|
||||
dds.on('click', function(){
|
||||
var othis = $(this), value = othis.attr('lay-value');
|
||||
var filter = select.attr('lay-filter'); //获取过滤器
|
||||
|
||||
if(othis.hasClass(DISABLED)) return false;
|
||||
|
||||
if(othis.hasClass('layui-select-tips')){
|
||||
input.val('');
|
||||
} else {
|
||||
input.val(othis.text());
|
||||
othis.addClass(THIS);
|
||||
}
|
||||
|
||||
othis.siblings().removeClass(THIS);
|
||||
select.val(value).removeClass('layui-form-danger')
|
||||
layui.event.call(this, MOD_NAME, 'select('+ filter +')', {
|
||||
elem: select[0]
|
||||
,value: value
|
||||
,othis: reElem
|
||||
});
|
||||
|
||||
hideDown(true);
|
||||
return false;
|
||||
});
|
||||
|
||||
reElem.find('dl>dt').on('click', function(e){
|
||||
return false;
|
||||
});
|
||||
|
||||
$(document).off('click', hide).on('click', hide); //点击其它元素关闭 select
|
||||
}
|
||||
|
||||
selects.each(function(index, select){
|
||||
var othis = $(this)
|
||||
,hasRender = othis.next('.'+CLASS)
|
||||
,disabled = this.disabled
|
||||
,value = select.value
|
||||
,selected = $(select.options[select.selectedIndex]) //获取当前选中项
|
||||
,optionsFirst = select.options[0];
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
|
||||
var isSearch = typeof othis.attr('lay-search') === 'string'
|
||||
,placeholder = optionsFirst ? (
|
||||
optionsFirst.value ? TIPS : (optionsFirst.innerHTML || TIPS)
|
||||
) : TIPS;
|
||||
|
||||
//替代元素
|
||||
var reElem = $(['<div class="'+ (isSearch ? '' : 'layui-unselect ') + CLASS
|
||||
,(disabled ? ' layui-select-disabled' : '') +'">'
|
||||
,'<div class="'+ TITLE +'">'
|
||||
,('<input type="text" placeholder="'+ $.trim(placeholder) +'" '
|
||||
+('value="'+ $.trim(value ? selected.html() : '') +'"') //默认值
|
||||
+((!disabled && isSearch) ? '' : ' readonly') //是否开启搜索
|
||||
+' class="layui-input'
|
||||
+(isSearch ? '' : ' layui-unselect')
|
||||
+ (disabled ? (' ' + DISABLED) : '') +'">') //禁用状态
|
||||
,'<i class="layui-edge"></i></div>'
|
||||
,'<dl class="layui-anim layui-anim-upbit'+ (othis.find('optgroup')[0] ? ' layui-select-group' : '') +'">'
|
||||
,function(options){
|
||||
var arr = [];
|
||||
layui.each(options, function(index, item){
|
||||
if(index === 0 && !item.value){
|
||||
arr.push('<dd lay-value="" class="layui-select-tips">'+ $.trim(item.innerHTML || TIPS) +'</dd>');
|
||||
} else if(item.tagName.toLowerCase() === 'optgroup'){
|
||||
arr.push('<dt>'+ item.label +'</dt>');
|
||||
} else {
|
||||
arr.push('<dd lay-value="'+ item.value +'" class="'+ (value === item.value ? THIS : '') + (item.disabled ? (' '+DISABLED) : '') +'">'+ $.trim(item.innerHTML) +'</dd>');
|
||||
}
|
||||
});
|
||||
arr.length === 0 && arr.push('<dd lay-value="" class="'+ DISABLED +'">没有选项</dd>');
|
||||
return arr.join('');
|
||||
}(othis.find('*')) +'</dl>'
|
||||
,'</div>'].join(''));
|
||||
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
othis.after(reElem);
|
||||
events.call(this, reElem, disabled, isSearch);
|
||||
});
|
||||
}
|
||||
|
||||
//复选框/开关
|
||||
,checkbox: function(){
|
||||
var CLASS = {
|
||||
checkbox: ['layui-form-checkbox', 'layui-form-checked', 'checkbox']
|
||||
,_switch: ['layui-form-switch', 'layui-form-onswitch', 'switch']
|
||||
}
|
||||
,checks = elemForm.find('input[type=checkbox]')
|
||||
|
||||
,events = function(reElem, RE_CLASS){
|
||||
var check = $(this);
|
||||
|
||||
//勾选
|
||||
reElem.on('click', function(){
|
||||
var filter = check.attr('lay-filter') //获取过滤器
|
||||
,text = (check.attr('lay-text')||'').split('|');
|
||||
|
||||
if(check[0].disabled) return;
|
||||
|
||||
check[0].checked ? (
|
||||
check[0].checked = false
|
||||
,reElem.removeClass(RE_CLASS[1]).find('em').text(text[1])
|
||||
) : (
|
||||
check[0].checked = true
|
||||
,reElem.addClass(RE_CLASS[1]).find('em').text(text[0])
|
||||
);
|
||||
|
||||
layui.event.call(check[0], MOD_NAME, RE_CLASS[2]+'('+ filter +')', {
|
||||
elem: check[0]
|
||||
,value: check[0].value
|
||||
,othis: reElem
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
checks.each(function(index, check){
|
||||
var othis = $(this), skin = othis.attr('lay-skin')
|
||||
,text = (othis.attr('lay-text') || '').split('|'), disabled = this.disabled;
|
||||
if(skin === 'switch') skin = '_'+skin;
|
||||
var RE_CLASS = CLASS[skin] || CLASS.checkbox;
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
|
||||
//替代元素
|
||||
var hasRender = othis.next('.' + RE_CLASS[0])
|
||||
,reElem = $(['<div class="layui-unselect '+ RE_CLASS[0]
|
||||
,(check.checked ? (' '+ RE_CLASS[1]) : '') //选中状态
|
||||
,(disabled ? ' layui-checkbox-disabled '+ DISABLED : '') //禁用状态
|
||||
,'"'
|
||||
,(skin ? ' lay-skin="'+ skin +'"' : '') //风格
|
||||
,'>'
|
||||
,function(){ //不同风格的内容
|
||||
var title = check.title.replace(/\s/g, '')
|
||||
,type = {
|
||||
//复选框
|
||||
checkbox: [
|
||||
(title ? ('<span>'+ check.title +'</span>') : '')
|
||||
,'<i class="layui-icon layui-icon-ok"></i>'
|
||||
].join('')
|
||||
|
||||
//开关
|
||||
,_switch: '<em>'+ ((check.checked ? text[0] : text[1]) || '') +'</em><i></i>'
|
||||
};
|
||||
return type[skin] || type['checkbox'];
|
||||
}()
|
||||
,'</div>'].join(''));
|
||||
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
othis.after(reElem);
|
||||
events.call(this, reElem, RE_CLASS);
|
||||
});
|
||||
}
|
||||
|
||||
//单选框
|
||||
,radio: function(){
|
||||
var CLASS = 'layui-form-radio', ICON = ['', '']
|
||||
,radios = elemForm.find('input[type=radio]')
|
||||
|
||||
,events = function(reElem){
|
||||
var radio = $(this), ANIM = 'layui-anim-scaleSpring';
|
||||
|
||||
reElem.on('click', function(){
|
||||
var name = radio[0].name, forms = radio.parents(ELEM);
|
||||
var filter = radio.attr('lay-filter'); //获取过滤器
|
||||
var sameRadio = forms.find('input[name='+ name.replace(/(\.|#|\[|\])/g, '\\$1') +']'); //找到相同name的兄弟
|
||||
|
||||
if(radio[0].disabled) return;
|
||||
|
||||
layui.each(sameRadio, function(){
|
||||
var next = $(this).next('.'+CLASS);
|
||||
this.checked = false;
|
||||
next.removeClass(CLASS+'ed');
|
||||
next.find('.layui-icon').removeClass(ANIM).html(ICON[1]);
|
||||
});
|
||||
|
||||
radio[0].checked = true;
|
||||
reElem.addClass(CLASS+'ed');
|
||||
reElem.find('.layui-icon').addClass(ANIM).html(ICON[0]);
|
||||
|
||||
layui.event.call(radio[0], MOD_NAME, 'radio('+ filter +')', {
|
||||
elem: radio[0]
|
||||
,value: radio[0].value
|
||||
,othis: reElem
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
radios.each(function(index, radio){
|
||||
var othis = $(this), hasRender = othis.next('.' + CLASS), disabled = this.disabled;
|
||||
|
||||
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
|
||||
//替代元素
|
||||
var reElem = $(['<div class="layui-unselect '+ CLASS
|
||||
,(radio.checked ? (' '+CLASS+'ed') : '') //选中状态
|
||||
,(disabled ? ' layui-radio-disabled '+DISABLED : '') +'">' //禁用状态
|
||||
,'<i class="layui-anim layui-icon">'+ ICON[radio.checked ? 0 : 1] +'</i>'
|
||||
,'<div>'+ function(){
|
||||
var title = radio.title || '';
|
||||
if(typeof othis.next().attr('lay-radio') === 'string'){
|
||||
title = othis.next().html();
|
||||
//othis.next().remove();
|
||||
}
|
||||
return title
|
||||
}() +'</div>'
|
||||
,'</div>'].join(''));
|
||||
|
||||
othis.after(reElem);
|
||||
events.call(this, reElem);
|
||||
});
|
||||
}
|
||||
};
|
||||
type ? (
|
||||
items[type] ? items[type]() : hint.error('不支持的 "'+ type + '" 表单渲染')
|
||||
) : layui.each(items, function(index, item){
|
||||
item();
|
||||
});
|
||||
return that;
|
||||
};
|
||||
|
||||
//表单提交校验
|
||||
var submit = function(){
|
||||
var stop = null //验证不通过状态
|
||||
,verify = form.config.verify //验证规则
|
||||
,DANGER = 'layui-form-danger' //警示样式
|
||||
,field = {} //字段集合
|
||||
,button = $(this) //当前触发的按钮
|
||||
,elem = button.parents(ELEM).eq(0) //当前所在表单域
|
||||
,verifyElem = elem.find('*[lay-verify]') //获取需要校验的元素
|
||||
,formElem = button.parents('form')[0] //获取当前所在的 form 元素,如果存在的话
|
||||
,filter = button.attr('lay-filter'); //获取过滤器
|
||||
|
||||
|
||||
//开始校验
|
||||
layui.each(verifyElem, function(_, item){
|
||||
var othis = $(this)
|
||||
,vers = othis.attr('lay-verify').split('|')
|
||||
,verType = othis.attr('lay-verType') //提示方式
|
||||
,value = othis.val();
|
||||
|
||||
othis.removeClass(DANGER); //移除警示样式
|
||||
|
||||
//遍历元素绑定的验证规则
|
||||
layui.each(vers, function(_, thisVer){
|
||||
var isTrue //是否命中校验
|
||||
,errorText = '' //错误提示文本
|
||||
,isFn = typeof verify[thisVer] === 'function';
|
||||
|
||||
//匹配验证规则
|
||||
if(verify[thisVer]){
|
||||
var isTrue = isFn ? errorText = verify[thisVer](value, item) : !verify[thisVer][0].test(value)
|
||||
//是否属于美化替换后的表单元素
|
||||
,isForm2Elem = item.tagName.toLowerCase() === 'select' || /^checkbox|radio$/.test(item.type);
|
||||
|
||||
errorText = errorText || verify[thisVer][1];
|
||||
|
||||
if(thisVer === 'required'){
|
||||
errorText = othis.attr('lay-reqText') || errorText;
|
||||
}
|
||||
|
||||
//如果是必填项或者非空命中校验,则阻止提交,弹出提示
|
||||
if(isTrue){
|
||||
//提示层风格
|
||||
if(verType === 'tips'){
|
||||
layer.tips(errorText, function(){
|
||||
if(typeof othis.attr('lay-ignore') !== 'string'){
|
||||
if(isForm2Elem){
|
||||
return othis.next();
|
||||
}
|
||||
}
|
||||
return othis;
|
||||
}(), {tips: 1});
|
||||
} else if(verType === 'alert') {
|
||||
layer.alert(errorText, {title: '提示', shadeClose: true});
|
||||
}
|
||||
//如果返回的为字符或数字,则自动弹出默认提示框;否则由 verify 方法中处理提示
|
||||
else if(/\bstring|number\b/.test(typeof errorText)){
|
||||
layer.msg(errorText, {icon: 5, shift: 6});
|
||||
}
|
||||
|
||||
//非移动设备自动定位焦点
|
||||
if(!device.mobile){
|
||||
setTimeout(function(){
|
||||
(isForm2Elem ? othis.next().find('input') : item).focus();
|
||||
}, 7);
|
||||
} else { //移动设备定位
|
||||
$dom.scrollTop(function(){
|
||||
try {
|
||||
return (isForm2Elem ? othis.next() : othis).offset().top - 15
|
||||
} catch(e){
|
||||
return 0;
|
||||
}
|
||||
}());
|
||||
}
|
||||
|
||||
othis.addClass(DANGER);
|
||||
return stop = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if(stop) return stop;
|
||||
});
|
||||
|
||||
if(stop) return false;
|
||||
|
||||
//获取当前表单值
|
||||
field = form.getValue(null, elem);
|
||||
|
||||
//返回字段
|
||||
return layui.event.call(this, MOD_NAME, 'submit('+ filter +')', {
|
||||
elem: this
|
||||
,form: formElem
|
||||
,field: field
|
||||
});
|
||||
};
|
||||
|
||||
//自动完成渲染
|
||||
var form = new Form()
|
||||
,$dom = $(document), $win = $(window);
|
||||
|
||||
$(function(){
|
||||
form.render();
|
||||
});
|
||||
|
||||
//表单reset重置渲染
|
||||
$dom.on('reset', ELEM, function(){
|
||||
var filter = $(this).attr('lay-filter');
|
||||
setTimeout(function(){
|
||||
form.render(null, filter);
|
||||
}, 50);
|
||||
});
|
||||
|
||||
//表单提交事件
|
||||
$dom.on('submit', ELEM, submit)
|
||||
.on('click', '*[lay-submit]', submit);
|
||||
|
||||
exports(MOD_NAME, form);
|
||||
});
|
||||
|
||||
|
||||
4
static/Layui/v2.6.8/modules/jquery.js
vendored
@@ -1,418 +0,0 @@
|
||||
|
||||
/*! lay 基础 DOM 操作 | MIT Licensed */
|
||||
|
||||
;!function(window){ //gulp build: lay-header
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = 'lay' //模块名
|
||||
,document = window.document
|
||||
|
||||
//DOM查找
|
||||
,lay = function(selector){
|
||||
return new LAY(selector);
|
||||
}
|
||||
|
||||
//DOM构造器
|
||||
,LAY = function(selector){
|
||||
var index = 0
|
||||
,nativeDOM = typeof selector === 'object' ? [selector] : (
|
||||
this.selector = selector
|
||||
,document.querySelectorAll(selector || null)
|
||||
);
|
||||
for(; index < nativeDOM.length; index++){
|
||||
this.push(nativeDOM[index]);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
lay 对象操作
|
||||
*/
|
||||
|
||||
LAY.prototype = [];
|
||||
LAY.prototype.constructor = LAY;
|
||||
|
||||
//普通对象深度扩展
|
||||
lay.extend = function(){
|
||||
var ai = 1, args = arguments
|
||||
,clone = function(target, obj){
|
||||
target = target || (layui._typeof(obj) === 'array' ? [] : {}); //目标对象
|
||||
for(var i in obj){
|
||||
//如果值为普通对象,则进入递归,继续深度合并
|
||||
target[i] = (obj[i] && obj[i].constructor === Object)
|
||||
? clone(target[i], obj[i])
|
||||
: obj[i];
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
args[0] = typeof args[0] === 'object' ? args[0] : {};
|
||||
|
||||
for(; ai < args.length; ai++){
|
||||
if(typeof args[ai] === 'object'){
|
||||
clone(args[0], args[ai]);
|
||||
}
|
||||
}
|
||||
return args[0];
|
||||
};
|
||||
|
||||
//lay 模块版本
|
||||
lay.v = '1.0.8';
|
||||
|
||||
//ie版本
|
||||
lay.ie = function(){
|
||||
var agent = navigator.userAgent.toLowerCase();
|
||||
return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
|
||||
(agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于 ie11 并没有 msie 的标识
|
||||
) : false;
|
||||
}();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取 layui 常见方法,以便用于组件单独版
|
||||
*/
|
||||
|
||||
lay.layui = layui || {};
|
||||
lay.getPath = layui.cache.dir; //获取当前 JS 所在目录
|
||||
lay.stope = layui.stope; //中止冒泡
|
||||
lay.each = function(){ //遍历
|
||||
layui.each.apply(layui, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//数字前置补零
|
||||
lay.digit = function(num, length, end){
|
||||
var str = '';
|
||||
num = String(num);
|
||||
length = length || 2;
|
||||
for(var i = num.length; i < length; i++){
|
||||
str += '0';
|
||||
}
|
||||
return num < Math.pow(10, length) ? str + (num|0) : num;
|
||||
};
|
||||
|
||||
//创建元素
|
||||
lay.elem = function(elemName, attr){
|
||||
var elem = document.createElement(elemName);
|
||||
lay.each(attr || {}, function(key, value){
|
||||
elem.setAttribute(key, value);
|
||||
});
|
||||
return elem;
|
||||
};
|
||||
|
||||
//当前页面是否存在滚动条
|
||||
lay.hasScrollbar = function(){
|
||||
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight);
|
||||
};
|
||||
|
||||
//元素定位
|
||||
lay.position = function(elem, elemView, obj){
|
||||
if(!elemView) return;
|
||||
obj = obj || {};
|
||||
|
||||
//如果绑定的是 document 或 body 元素,则直接获取鼠标坐标
|
||||
if(elem === document || elem === lay('body')[0]){
|
||||
obj.clickType = 'right';
|
||||
}
|
||||
|
||||
//绑定绑定元素的坐标
|
||||
var rect = obj.clickType === 'right' ? function(){
|
||||
var e = obj.e || window.event || {};
|
||||
return {
|
||||
left: e.clientX
|
||||
,top: e.clientY
|
||||
,right: e.clientX
|
||||
,bottom: e.clientY
|
||||
}
|
||||
}() : elem.getBoundingClientRect()
|
||||
,elemWidth = elemView.offsetWidth //控件的宽度
|
||||
,elemHeight = elemView.offsetHeight //控件的高度
|
||||
|
||||
//滚动条高度
|
||||
,scrollArea = function(type){
|
||||
type = type ? 'scrollLeft' : 'scrollTop';
|
||||
return document.body[type] | document.documentElement[type];
|
||||
}
|
||||
|
||||
//窗口宽高
|
||||
,winArea = function(type){
|
||||
return document.documentElement[type ? 'clientWidth' : 'clientHeight']
|
||||
}, margin = 5, left = rect.left, top = rect.bottom;
|
||||
|
||||
//相对元素居中
|
||||
if(obj.align === 'center'){
|
||||
left = left - (elemWidth - elem.offsetWidth)/2;
|
||||
} else if(obj.align === 'right'){
|
||||
left = left - elemWidth + elem.offsetWidth;
|
||||
}
|
||||
|
||||
//判断右侧是否超出边界
|
||||
if(left + elemWidth + margin > winArea('width')){
|
||||
left = winArea('width') - elemWidth - margin; //如果超出右侧,则将面板向右靠齐
|
||||
}
|
||||
//左侧是否超出边界
|
||||
if(left < margin) left = margin;
|
||||
|
||||
//判断底部和顶部是否超出边界
|
||||
if(top + elemHeight + margin > winArea()){
|
||||
//优先顶部是否有足够区域显示完全
|
||||
if(rect.top > elemHeight + margin){
|
||||
top = rect.top - elemHeight - margin*2; //顶部有足够的区域显示
|
||||
} else {
|
||||
//如果面板是鼠标右键弹出,且顶部没有足够区域显示,则将面板向底部靠齐
|
||||
if(obj.clickType === 'right'){
|
||||
top = winArea() - elemHeight - margin*2;
|
||||
if(top < 0) top = 0; //不能溢出窗口顶部
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//定位类型
|
||||
var position = obj.position;
|
||||
if(position) elemView.style.position = position;
|
||||
|
||||
//设置坐标
|
||||
elemView.style.left = left + (position === 'fixed' ? 0 : scrollArea(1)) + 'px';
|
||||
elemView.style.top = top + (position === 'fixed' ? 0 : scrollArea()) + 'px';
|
||||
|
||||
//防止页面无滚动条时,又因为弹出面板而出现滚动条导致的坐标计算偏差
|
||||
if(!lay.hasScrollbar()){
|
||||
var rect1 = elemView.getBoundingClientRect();
|
||||
//如果弹出面板的溢出窗口底部,则表示将出现滚动条,此时需要重新计算坐标
|
||||
if(!obj.SYSTEM_RELOAD && (rect1.bottom + margin) > winArea()){
|
||||
obj.SYSTEM_RELOAD = true;
|
||||
setTimeout(function(){
|
||||
lay.position(elem, elemView, obj);
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//获取元素上的参数配置上
|
||||
lay.options = function(elem, attr){
|
||||
var othis = lay(elem)
|
||||
,attrName = attr || 'lay-options';
|
||||
try {
|
||||
return new Function('return '+ (othis.attr(attrName) || '{}'))();
|
||||
} catch(ev) {
|
||||
hint.error('parseerror:'+ ev, 'error');
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
//元素是否属于顶级元素(document 或 body)
|
||||
lay.isTopElem = function(elem){
|
||||
var topElems = [document, lay('body')[0]]
|
||||
,matched = false;
|
||||
lay.each(topElems, function(index, item){
|
||||
if(item === elem){
|
||||
return matched = true
|
||||
}
|
||||
});
|
||||
return matched;
|
||||
};
|
||||
|
||||
//追加字符
|
||||
LAY.addStr = function(str, new_str){
|
||||
str = str.replace(/\s+/, ' ');
|
||||
new_str = new_str.replace(/\s+/, ' ').split(' ');
|
||||
lay.each(new_str, function(ii, item){
|
||||
if(!new RegExp('\\b'+ item + '\\b').test(str)){
|
||||
str = str + ' ' + item;
|
||||
}
|
||||
});
|
||||
return str.replace(/^\s|\s$/, '');
|
||||
};
|
||||
|
||||
//移除值
|
||||
LAY.removeStr = function(str, new_str){
|
||||
str = str.replace(/\s+/, ' ');
|
||||
new_str = new_str.replace(/\s+/, ' ').split(' ');
|
||||
lay.each(new_str, function(ii, item){
|
||||
var exp = new RegExp('\\b'+ item + '\\b')
|
||||
if(exp.test(str)){
|
||||
str = str.replace(exp, '');
|
||||
}
|
||||
});
|
||||
return str.replace(/\s+/, ' ').replace(/^\s|\s$/, '');
|
||||
};
|
||||
|
||||
//查找子元素
|
||||
LAY.prototype.find = function(selector){
|
||||
var that = this;
|
||||
var index = 0, arr = []
|
||||
,isObject = typeof selector === 'object';
|
||||
|
||||
this.each(function(i, item){
|
||||
var nativeDOM = isObject ? item.contains(selector) : item.querySelectorAll(selector || null);
|
||||
for(; index < nativeDOM.length; index++){
|
||||
arr.push(nativeDOM[index]);
|
||||
}
|
||||
that.shift();
|
||||
});
|
||||
|
||||
if(!isObject){
|
||||
that.selector = (that.selector ? that.selector + ' ' : '') + selector
|
||||
}
|
||||
|
||||
lay.each(arr, function(i, item){
|
||||
that.push(item);
|
||||
});
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
//DOM遍历
|
||||
LAY.prototype.each = function(fn){
|
||||
return lay.each.call(this, this, fn);
|
||||
};
|
||||
|
||||
//添加css类
|
||||
LAY.prototype.addClass = function(className, type){
|
||||
return this.each(function(index, item){
|
||||
item.className = LAY[type ? 'removeStr' : 'addStr'](item.className, className)
|
||||
});
|
||||
};
|
||||
|
||||
//移除 css 类
|
||||
LAY.prototype.removeClass = function(className){
|
||||
return this.addClass(className, true);
|
||||
};
|
||||
|
||||
//是否包含 css 类
|
||||
LAY.prototype.hasClass = function(className){
|
||||
var has = false;
|
||||
this.each(function(index, item){
|
||||
if(new RegExp('\\b'+ className +'\\b').test(item.className)){
|
||||
has = true;
|
||||
}
|
||||
});
|
||||
return has;
|
||||
};
|
||||
|
||||
//添加或获取 css style
|
||||
LAY.prototype.css = function(key, value){
|
||||
var that = this
|
||||
,parseValue = function(v){
|
||||
return isNaN(v) ? v : (v +'px');
|
||||
};
|
||||
return (typeof key === 'string' && value === undefined) ? function(){
|
||||
if(that.length > 0) return that[0].style[key];
|
||||
}() : that.each(function(index, item){
|
||||
typeof key === 'object' ? lay.each(key, function(thisKey, thisValue){
|
||||
item.style[thisKey] = parseValue(thisValue);
|
||||
}) : item.style[key] = parseValue(value);
|
||||
});
|
||||
};
|
||||
|
||||
//添加或获取宽度
|
||||
LAY.prototype.width = function(value){
|
||||
var that = this;
|
||||
return value === undefined ? function(){
|
||||
if(that.length > 0) return that[0].offsetWidth; //此处还需做兼容
|
||||
}() : that.each(function(index, item){
|
||||
that.css('width', value);
|
||||
});
|
||||
};
|
||||
|
||||
//添加或获取高度
|
||||
LAY.prototype.height = function(value){
|
||||
var that = this;
|
||||
return value === undefined ? function(){
|
||||
if(that.length > 0) return that[0].offsetHeight; //此处还需做兼容
|
||||
}() : that.each(function(index, item){
|
||||
that.css('height', value);
|
||||
});
|
||||
};
|
||||
|
||||
//添加或获取属性
|
||||
LAY.prototype.attr = function(key, value){
|
||||
var that = this;
|
||||
return value === undefined ? function(){
|
||||
if(that.length > 0) return that[0].getAttribute(key);
|
||||
}() : that.each(function(index, item){
|
||||
item.setAttribute(key, value);
|
||||
});
|
||||
};
|
||||
|
||||
//移除属性
|
||||
LAY.prototype.removeAttr = function(key){
|
||||
return this.each(function(index, item){
|
||||
item.removeAttribute(key);
|
||||
});
|
||||
};
|
||||
|
||||
//设置或获取 HTML 内容
|
||||
LAY.prototype.html = function(html){
|
||||
var that = this;
|
||||
return html === undefined ? function(){
|
||||
if(that.length > 0) return that[0].innerHTML;
|
||||
}() : this.each(function(index, item){
|
||||
item.innerHTML = html;
|
||||
});
|
||||
};
|
||||
|
||||
//设置或获取值
|
||||
LAY.prototype.val = function(value){
|
||||
var that = this;
|
||||
return value === undefined ? function(){
|
||||
if(that.length > 0) return that[0].value;
|
||||
}() : this.each(function(index, item){
|
||||
item.value = value;
|
||||
});
|
||||
};
|
||||
|
||||
//追加内容
|
||||
LAY.prototype.append = function(elem){
|
||||
return this.each(function(index, item){
|
||||
typeof elem === 'object'
|
||||
? item.appendChild(elem)
|
||||
: item.innerHTML = item.innerHTML + elem;
|
||||
});
|
||||
};
|
||||
|
||||
//移除内容
|
||||
LAY.prototype.remove = function(elem){
|
||||
return this.each(function(index, item){
|
||||
elem ? item.removeChild(elem) : item.parentNode.removeChild(item);
|
||||
});
|
||||
};
|
||||
|
||||
//事件绑定
|
||||
LAY.prototype.on = function(eventName, fn){
|
||||
return this.each(function(index, item){
|
||||
item.attachEvent ? item.attachEvent('on' + eventName, function(e){
|
||||
e.target = e.srcElement;
|
||||
fn.call(item, e);
|
||||
}) : item.addEventListener(eventName, fn, false);
|
||||
});
|
||||
};
|
||||
|
||||
//解除事件
|
||||
LAY.prototype.off = function(eventName, fn){
|
||||
return this.each(function(index, item){
|
||||
item.detachEvent
|
||||
? item.detachEvent('on'+ eventName, fn)
|
||||
: item.removeEventListener(eventName, fn, false);
|
||||
});
|
||||
};
|
||||
|
||||
//暴露 lay 到全局作用域
|
||||
window.lay = lay;
|
||||
|
||||
//如果在 layui 体系中
|
||||
if(window.layui && layui.define){
|
||||
layui.define(function(exports){ //layui 加载
|
||||
exports(MOD_NAME, lay);
|
||||
});
|
||||
}
|
||||
|
||||
}(window, window.document);
|
||||
|
||||
@@ -1,648 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layedit 富文本编辑器
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(['layer', 'form'], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,layer = layui.layer
|
||||
,form = layui.form
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
,MOD_NAME = 'layedit', THIS = 'layui-this', SHOW = 'layui-show', ABLED = 'layui-disabled'
|
||||
|
||||
,Edit = function(){
|
||||
var that = this;
|
||||
that.index = 0;
|
||||
|
||||
//全局配置
|
||||
that.config = {
|
||||
//默认工具bar
|
||||
tool: [
|
||||
'strong', 'italic', 'underline', 'del'
|
||||
,'|'
|
||||
,'left', 'center', 'right'
|
||||
,'|'
|
||||
,'link', 'unlink', 'face', 'image'
|
||||
]
|
||||
,hideTool: []
|
||||
,height: 280 //默认高
|
||||
};
|
||||
};
|
||||
|
||||
//全局设置
|
||||
Edit.prototype.set = function(options){
|
||||
var that = this;
|
||||
$.extend(true, that.config, options);
|
||||
return that;
|
||||
};
|
||||
|
||||
//事件
|
||||
Edit.prototype.on = function(events, callback){
|
||||
return layui.onevent(MOD_NAME, events, callback);
|
||||
};
|
||||
|
||||
//建立编辑器
|
||||
Edit.prototype.build = function(id, settings){
|
||||
settings = settings || {};
|
||||
|
||||
var that = this
|
||||
,config = that.config
|
||||
,ELEM = 'layui-layedit', textArea = $(typeof(id)=='string'?'#'+id:id)
|
||||
,name = 'LAY_layedit_'+ (++that.index)
|
||||
,haveBuild = textArea.next('.'+ELEM)
|
||||
|
||||
,set = $.extend({}, config, settings)
|
||||
|
||||
,tool = function(){
|
||||
var node = [], hideTools = {};
|
||||
layui.each(set.hideTool, function(_, item){
|
||||
hideTools[item] = true;
|
||||
});
|
||||
layui.each(set.tool, function(_, item){
|
||||
if(tools[item] && !hideTools[item]){
|
||||
node.push(tools[item]);
|
||||
}
|
||||
});
|
||||
return node.join('');
|
||||
}()
|
||||
|
||||
|
||||
,editor = $(['<div class="'+ ELEM +'">'
|
||||
,'<div class="layui-unselect layui-layedit-tool">'+ tool +'</div>'
|
||||
,'<div class="layui-layedit-iframe">'
|
||||
,'<iframe id="'+ name +'" name="'+ name +'" textarea="'+ id +'" frameborder="0"></iframe>'
|
||||
,'</div>'
|
||||
,'</div>'].join(''))
|
||||
|
||||
//编辑器不兼容ie8以下
|
||||
if(device.ie && device.ie < 8){
|
||||
return textArea.removeClass('layui-hide').addClass(SHOW);
|
||||
}
|
||||
|
||||
haveBuild[0] && (haveBuild.remove());
|
||||
|
||||
setIframe.call(that, editor, textArea[0], set)
|
||||
textArea.addClass('layui-hide').after(editor);
|
||||
|
||||
return that.index;
|
||||
};
|
||||
|
||||
//获得编辑器中内容
|
||||
Edit.prototype.getContent = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
return toLower(iframeWin[0].document.body.innerHTML);
|
||||
};
|
||||
|
||||
//获得编辑器中纯文本内容
|
||||
Edit.prototype.getText = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
return $(iframeWin[0].document.body).text();
|
||||
};
|
||||
/**
|
||||
* 设置编辑器内容
|
||||
* @param {[type]} index 编辑器索引
|
||||
* @param {[type]} content 要设置的内容
|
||||
* @param {[type]} flag 是否追加模式
|
||||
*/
|
||||
Edit.prototype.setContent = function(index, content, flag){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
if(flag){
|
||||
$(iframeWin[0].document.body).append(content)
|
||||
}else{
|
||||
$(iframeWin[0].document.body).html(content)
|
||||
};
|
||||
layedit.sync(index)
|
||||
};
|
||||
//将编辑器内容同步到textarea(一般用于异步提交时)
|
||||
Edit.prototype.sync = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
var textarea = $('#'+iframeWin[1].attr('textarea'));
|
||||
textarea.val(toLower(iframeWin[0].document.body.innerHTML));
|
||||
};
|
||||
|
||||
//获取编辑器选中内容
|
||||
Edit.prototype.getSelection = function(index){
|
||||
var iframeWin = getWin(index);
|
||||
if(!iframeWin[0]) return;
|
||||
var range = Range(iframeWin[0].document);
|
||||
return document.selection ? range.text : range.toString();
|
||||
};
|
||||
|
||||
//iframe初始化
|
||||
var setIframe = function(editor, textArea, set){
|
||||
var that = this, iframe = editor.find('iframe');
|
||||
|
||||
iframe.css({
|
||||
height: set.height
|
||||
}).on('load', function(){
|
||||
var conts = iframe.contents()
|
||||
,iframeWin = iframe.prop('contentWindow')
|
||||
,head = conts.find('head')
|
||||
,style = $(['<style>'
|
||||
,'*{margin: 0; padding: 0;}'
|
||||
,'body{padding: 10px; line-height: 20px; overflow-x: hidden; word-wrap: break-word; font: 14px Helvetica Neue,Helvetica,PingFang SC,Microsoft YaHei,Tahoma,Arial,sans-serif; -webkit-box-sizing: border-box !important; -moz-box-sizing: border-box !important; box-sizing: border-box !important;}'
|
||||
,'a{color:#01AAED; text-decoration:none;}a:hover{color:#c00}'
|
||||
,'p{margin-bottom: 10px;}'
|
||||
,'img{display: inline-block; border: none; vertical-align: middle;}'
|
||||
,'pre{margin: 10px 0; padding: 10px; line-height: 20px; border: 1px solid #ddd; border-left-width: 6px; background-color: #F2F2F2; color: #333; font-family: Courier New; font-size: 12px;}'
|
||||
,'</style>'].join(''))
|
||||
,body = conts.find('body');
|
||||
|
||||
head.append(style);
|
||||
body.attr('contenteditable', 'true').css({
|
||||
'min-height': set.height
|
||||
}).html(textArea.value||'');
|
||||
|
||||
hotkey.apply(that, [iframeWin, iframe, textArea, set]); //快捷键处理
|
||||
toolActive.call(that, iframeWin, editor, set); //触发工具
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//获得iframe窗口对象
|
||||
,getWin = function(index){
|
||||
var iframe = $('#LAY_layedit_'+ index)
|
||||
,iframeWin = iframe.prop('contentWindow');
|
||||
return [iframeWin, iframe];
|
||||
}
|
||||
|
||||
//IE8下将标签处理成小写
|
||||
,toLower = function(html){
|
||||
if(device.ie == 8){
|
||||
html = html.replace(/<.+>/g, function(str){
|
||||
return str.toLowerCase();
|
||||
});
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
//快捷键处理
|
||||
,hotkey = function(iframeWin, iframe, textArea, set){
|
||||
var iframeDOM = iframeWin.document, body = $(iframeDOM.body);
|
||||
body.on('keydown', function(e){
|
||||
var keycode = e.keyCode;
|
||||
//处理回车
|
||||
if(keycode === 13){
|
||||
var range = Range(iframeDOM);
|
||||
var container = getContainer(range)
|
||||
,parentNode = container.parentNode;
|
||||
|
||||
if(parentNode.tagName.toLowerCase() === 'pre'){
|
||||
if(e.shiftKey) return
|
||||
layer.msg('请暂时用shift+enter');
|
||||
return false;
|
||||
}
|
||||
iframeDOM.execCommand('formatBlock', false, '<p>');
|
||||
}
|
||||
});
|
||||
|
||||
//给textarea同步内容
|
||||
$(textArea).parents('form').on('submit', function(){
|
||||
var html = body.html();
|
||||
//IE8下将标签处理成小写
|
||||
if(device.ie == 8){
|
||||
html = html.replace(/<.+>/g, function(str){
|
||||
return str.toLowerCase();
|
||||
});
|
||||
}
|
||||
textArea.value = html;
|
||||
});
|
||||
|
||||
//处理粘贴
|
||||
body.on('paste', function(e){
|
||||
iframeDOM.execCommand('formatBlock', false, '<p>');
|
||||
setTimeout(function(){
|
||||
filter.call(iframeWin, body);
|
||||
textArea.value = body.html();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
//标签过滤
|
||||
,filter = function(body){
|
||||
var iframeWin = this
|
||||
,iframeDOM = iframeWin.document;
|
||||
|
||||
//清除影响版面的css属性
|
||||
body.find('*[style]').each(function(){
|
||||
var textAlign = this.style.textAlign;
|
||||
this.removeAttribute('style');
|
||||
$(this).css({
|
||||
'text-align': textAlign || ''
|
||||
})
|
||||
});
|
||||
|
||||
//修饰表格
|
||||
body.find('table').addClass('layui-table');
|
||||
|
||||
//移除不安全的标签
|
||||
body.find('script,link').remove();
|
||||
}
|
||||
|
||||
//Range对象兼容性处理
|
||||
,Range = function(iframeDOM){
|
||||
return iframeDOM.selection
|
||||
? iframeDOM.selection.createRange()
|
||||
: iframeDOM.getSelection().getRangeAt(0);
|
||||
}
|
||||
|
||||
//当前Range对象的endContainer兼容性处理
|
||||
,getContainer = function(range){
|
||||
return range.endContainer || range.parentElement().childNodes[0]
|
||||
}
|
||||
|
||||
//在选区插入内联元素
|
||||
,insertInline = function(tagName, attr, range){
|
||||
var iframeDOM = this.document
|
||||
,elem = document.createElement(tagName)
|
||||
for(var key in attr){
|
||||
elem.setAttribute(key, attr[key]);
|
||||
}
|
||||
elem.removeAttribute('text');
|
||||
|
||||
if(iframeDOM.selection){ //IE
|
||||
var text = range.text || attr.text;
|
||||
if(tagName === 'a' && !text) return;
|
||||
if(text){
|
||||
elem.innerHTML = text;
|
||||
}
|
||||
range.pasteHTML($(elem).prop('outerHTML'));
|
||||
range.select();
|
||||
} else { //非IE
|
||||
var text = range.toString() || attr.text;
|
||||
if(tagName === 'a' && !text) return;
|
||||
if(text){
|
||||
elem.innerHTML = text;
|
||||
}
|
||||
range.deleteContents();
|
||||
range.insertNode(elem);
|
||||
}
|
||||
}
|
||||
|
||||
//工具选中
|
||||
,toolCheck = function(tools, othis){
|
||||
var iframeDOM = this.document
|
||||
,CHECK = 'layedit-tool-active'
|
||||
,container = getContainer(Range(iframeDOM))
|
||||
,item = function(type){
|
||||
return tools.find('.layedit-tool-'+type)
|
||||
}
|
||||
|
||||
if(othis){
|
||||
othis[othis.hasClass(CHECK) ? 'removeClass' : 'addClass'](CHECK);
|
||||
}
|
||||
|
||||
tools.find('>i').removeClass(CHECK);
|
||||
item('unlink').addClass(ABLED);
|
||||
|
||||
$(container).parents().each(function(){
|
||||
var tagName = this.tagName.toLowerCase()
|
||||
,textAlign = this.style.textAlign;
|
||||
|
||||
//文字
|
||||
if(tagName === 'b' || tagName === 'strong'){
|
||||
item('b').addClass(CHECK)
|
||||
}
|
||||
if(tagName === 'i' || tagName === 'em'){
|
||||
item('i').addClass(CHECK)
|
||||
}
|
||||
if(tagName === 'u'){
|
||||
item('u').addClass(CHECK)
|
||||
}
|
||||
if(tagName === 'strike'){
|
||||
item('d').addClass(CHECK)
|
||||
}
|
||||
|
||||
//对齐
|
||||
if(tagName === 'p'){
|
||||
if(textAlign === 'center'){
|
||||
item('center').addClass(CHECK);
|
||||
} else if(textAlign === 'right'){
|
||||
item('right').addClass(CHECK);
|
||||
} else {
|
||||
item('left').addClass(CHECK);
|
||||
}
|
||||
}
|
||||
|
||||
//超链接
|
||||
if(tagName === 'a'){
|
||||
item('link').addClass(CHECK);
|
||||
item('unlink').removeClass(ABLED);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//触发工具
|
||||
,toolActive = function(iframeWin, editor, set){
|
||||
var iframeDOM = iframeWin.document
|
||||
,body = $(iframeDOM.body)
|
||||
,toolEvent = {
|
||||
//超链接
|
||||
link: function(range){
|
||||
var container = getContainer(range)
|
||||
,parentNode = $(container).parent();
|
||||
|
||||
link.call(body, {
|
||||
href: parentNode.attr('href')
|
||||
,target: parentNode.attr('target')
|
||||
}, function(field){
|
||||
var parent = parentNode[0];
|
||||
if(parent.tagName === 'A'){
|
||||
parent.href = field.url;
|
||||
} else {
|
||||
insertInline.call(iframeWin, 'a', {
|
||||
target: field.target
|
||||
,href: field.url
|
||||
,text: field.url
|
||||
}, range);
|
||||
}
|
||||
});
|
||||
}
|
||||
//清除超链接
|
||||
,unlink: function(range){
|
||||
iframeDOM.execCommand('unlink');
|
||||
}
|
||||
//表情
|
||||
,face: function(range){
|
||||
face.call(this, function(img){
|
||||
insertInline.call(iframeWin, 'img', {
|
||||
src: img.src
|
||||
,alt: img.alt
|
||||
}, range);
|
||||
});
|
||||
}
|
||||
//图片
|
||||
,image: function(range){
|
||||
var that = this;
|
||||
layui.use('upload', function(upload){
|
||||
var uploadImage = set.uploadImage || {};
|
||||
upload.render({
|
||||
url: uploadImage.url
|
||||
,method: uploadImage.type
|
||||
,elem: $(that).find('input')[0]
|
||||
,done: function(res){
|
||||
if(res.code == 0){
|
||||
res.data = res.data || {};
|
||||
insertInline.call(iframeWin, 'img', {
|
||||
src: res.data.src
|
||||
,alt: res.data.title
|
||||
}, range);
|
||||
} else {
|
||||
layer.msg(res.msg||'上传失败');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//插入代码
|
||||
,code: function(range){
|
||||
code.call(body, function(pre){
|
||||
insertInline.call(iframeWin, 'pre', {
|
||||
text: pre.code
|
||||
,'lay-lang': pre.lang
|
||||
}, range);
|
||||
});
|
||||
}
|
||||
//帮助
|
||||
,help: function(){
|
||||
layer.open({
|
||||
type: 2
|
||||
,title: '帮助'
|
||||
,area: ['600px', '380px']
|
||||
,shadeClose: true
|
||||
,shade: 0.1
|
||||
,skin: 'layui-layer-msg'
|
||||
,content: ['', 'no']
|
||||
});
|
||||
}
|
||||
}
|
||||
,tools = editor.find('.layui-layedit-tool')
|
||||
|
||||
,click = function(){
|
||||
var othis = $(this)
|
||||
,events = othis.attr('layedit-event')
|
||||
,command = othis.attr('lay-command');
|
||||
|
||||
if(othis.hasClass(ABLED)) return;
|
||||
|
||||
body.focus();
|
||||
|
||||
var range = Range(iframeDOM)
|
||||
,container = range.commonAncestorContainer
|
||||
|
||||
if(command){
|
||||
iframeDOM.execCommand(command);
|
||||
if(/justifyLeft|justifyCenter|justifyRight/.test(command)){
|
||||
iframeDOM.execCommand('formatBlock', false, '<p>');
|
||||
}
|
||||
setTimeout(function(){
|
||||
body.focus();
|
||||
}, 10);
|
||||
} else {
|
||||
toolEvent[events] && toolEvent[events].call(this, range);
|
||||
}
|
||||
toolCheck.call(iframeWin, tools, othis);
|
||||
}
|
||||
|
||||
,isClick = /image/
|
||||
|
||||
tools.find('>i').on('mousedown', function(){
|
||||
var othis = $(this)
|
||||
,events = othis.attr('layedit-event');
|
||||
if(isClick.test(events)) return;
|
||||
click.call(this)
|
||||
}).on('click', function(){
|
||||
var othis = $(this)
|
||||
,events = othis.attr('layedit-event');
|
||||
if(!isClick.test(events)) return;
|
||||
click.call(this)
|
||||
});
|
||||
|
||||
//触发内容区域
|
||||
body.on('click', function(){
|
||||
toolCheck.call(iframeWin, tools);
|
||||
layer.close(face.index);
|
||||
});
|
||||
}
|
||||
|
||||
//超链接面板
|
||||
,link = function(options, callback){
|
||||
var body = this, index = layer.open({
|
||||
type: 1
|
||||
,id: 'LAY_layedit_link'
|
||||
,area: '350px'
|
||||
,shade: 0.05
|
||||
,shadeClose: true
|
||||
,moveType: 1
|
||||
,title: '超链接'
|
||||
,skin: 'layui-layer-msg'
|
||||
,content: ['<ul class="layui-form" style="margin: 15px;">'
|
||||
,'<li class="layui-form-item">'
|
||||
,'<label class="layui-form-label" style="width: 60px;">URL</label>'
|
||||
,'<div class="layui-input-block" style="margin-left: 90px">'
|
||||
,'<input name="url" lay-verify="url" value="'+ (options.href||'') +'" autofocus="true" autocomplete="off" class="layui-input">'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item">'
|
||||
,'<label class="layui-form-label" style="width: 60px;">打开方式</label>'
|
||||
,'<div class="layui-input-block" style="margin-left: 90px">'
|
||||
,'<input type="radio" name="target" value="_self" class="layui-input" title="当前窗口"'
|
||||
+ ((options.target==='_self' || !options.target) ? 'checked' : '') +'>'
|
||||
,'<input type="radio" name="target" value="_blank" class="layui-input" title="新窗口" '
|
||||
+ (options.target==='_blank' ? 'checked' : '') +'>'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item" style="text-align: center;">'
|
||||
,'<button type="button" lay-submit lay-filter="layedit-link-yes" class="layui-btn"> 确定 </button>'
|
||||
,'<button style="margin-left: 20px;" type="button" class="layui-btn layui-btn-primary"> 取消 </button>'
|
||||
,'</li>'
|
||||
,'</ul>'].join('')
|
||||
,success: function(layero, index){
|
||||
var eventFilter = 'submit(layedit-link-yes)';
|
||||
form.render('radio');
|
||||
layero.find('.layui-btn-primary').on('click', function(){
|
||||
layer.close(index);
|
||||
body.focus();
|
||||
});
|
||||
form.on(eventFilter, function(data){
|
||||
layer.close(link.index);
|
||||
callback && callback(data.field);
|
||||
});
|
||||
}
|
||||
});
|
||||
link.index = index;
|
||||
}
|
||||
|
||||
//表情面板
|
||||
,face = function(callback){
|
||||
//表情库
|
||||
var faces = function(){
|
||||
var alt = ["[微笑]", "[嘻嘻]", "[哈哈]", "[可爱]", "[可怜]", "[挖鼻]", "[吃惊]", "[害羞]", "[挤眼]", "[闭嘴]", "[鄙视]", "[爱你]", "[泪]", "[偷笑]", "[亲亲]", "[生病]", "[太开心]", "[白眼]", "[右哼哼]", "[左哼哼]", "[嘘]", "[衰]", "[委屈]", "[吐]", "[哈欠]", "[抱抱]", "[怒]", "[疑问]", "[馋嘴]", "[拜拜]", "[思考]", "[汗]", "[困]", "[睡]", "[钱]", "[失望]", "[酷]", "[色]", "[哼]", "[鼓掌]", "[晕]", "[悲伤]", "[抓狂]", "[黑线]", "[阴险]", "[怒骂]", "[互粉]", "[心]", "[伤心]", "[猪头]", "[熊猫]", "[兔子]", "[ok]", "[耶]", "[good]", "[NO]", "[赞]", "[来]", "[弱]", "[草泥马]", "[神马]", "[囧]", "[浮云]", "[给力]", "[围观]", "[威武]", "[奥特曼]", "[礼物]", "[钟]", "[话筒]", "[蜡烛]", "[蛋糕]"], arr = {};
|
||||
layui.each(alt, function(index, item){
|
||||
arr[item] = layui.cache.dir + 'images/face/'+ index + '.gif';
|
||||
});
|
||||
return arr;
|
||||
}();
|
||||
face.hide = face.hide || function(e){
|
||||
if($(e.target).attr('layedit-event') !== 'face'){
|
||||
layer.close(face.index);
|
||||
}
|
||||
}
|
||||
return face.index = layer.tips(function(){
|
||||
var content = [];
|
||||
layui.each(faces, function(key, item){
|
||||
content.push('<li title="'+ key +'"><img src="'+ item +'" alt="'+ key +'"></li>');
|
||||
});
|
||||
return '<ul class="layui-clear">' + content.join('') + '</ul>';
|
||||
}(), this, {
|
||||
tips: 1
|
||||
,time: 0
|
||||
,skin: 'layui-box layui-util-face'
|
||||
,maxWidth: 500
|
||||
,success: function(layero, index){
|
||||
layero.css({
|
||||
marginTop: -4
|
||||
,marginLeft: -10
|
||||
}).find('.layui-clear>li').on('click', function(){
|
||||
callback && callback({
|
||||
src: faces[this.title]
|
||||
,alt: this.title
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
$(document).off('click', face.hide).on('click', face.hide);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//插入代码面板
|
||||
,code = function(callback){
|
||||
var body = this, index = layer.open({
|
||||
type: 1
|
||||
,id: 'LAY_layedit_code'
|
||||
,area: '550px'
|
||||
,shade: 0.05
|
||||
,shadeClose: true
|
||||
,moveType: 1
|
||||
,title: '插入代码'
|
||||
,skin: 'layui-layer-msg'
|
||||
,content: ['<ul class="layui-form layui-form-pane" style="margin: 15px;">'
|
||||
,'<li class="layui-form-item">'
|
||||
,'<label class="layui-form-label">请选择语言</label>'
|
||||
,'<div class="layui-input-block">'
|
||||
,'<select name="lang">'
|
||||
,'<option value="JavaScript">JavaScript</option>'
|
||||
,'<option value="HTML">HTML</option>'
|
||||
,'<option value="CSS">CSS</option>'
|
||||
,'<option value="Java">Java</option>'
|
||||
,'<option value="PHP">PHP</option>'
|
||||
,'<option value="C#">C#</option>'
|
||||
,'<option value="Python">Python</option>'
|
||||
,'<option value="Ruby">Ruby</option>'
|
||||
,'<option value="Go">Go</option>'
|
||||
,'</select>'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item layui-form-text">'
|
||||
,'<label class="layui-form-label">代码</label>'
|
||||
,'<div class="layui-input-block">'
|
||||
,'<textarea name="code" lay-verify="required" autofocus="true" class="layui-textarea" style="height: 200px;"></textarea>'
|
||||
,'</div>'
|
||||
,'</li>'
|
||||
,'<li class="layui-form-item" style="text-align: center;">'
|
||||
,'<button type="button" lay-submit lay-filter="layedit-code-yes" class="layui-btn"> 确定 </button>'
|
||||
,'<button style="margin-left: 20px;" type="button" class="layui-btn layui-btn-primary"> 取消 </button>'
|
||||
,'</li>'
|
||||
,'</ul>'].join('')
|
||||
,success: function(layero, index){
|
||||
var eventFilter = 'submit(layedit-code-yes)';
|
||||
form.render('select');
|
||||
layero.find('.layui-btn-primary').on('click', function(){
|
||||
layer.close(index);
|
||||
body.focus();
|
||||
});
|
||||
form.on(eventFilter, function(data){
|
||||
layer.close(code.index);
|
||||
callback && callback(data.field);
|
||||
});
|
||||
}
|
||||
});
|
||||
code.index = index;
|
||||
}
|
||||
|
||||
//全部工具
|
||||
,tools = {
|
||||
html: '<i class="layui-icon layedit-tool-html" title="HTML源代码" lay-command="html" layedit-event="html""></i><span class="layedit-tool-mid"></span>'
|
||||
,strong: '<i class="layui-icon layedit-tool-b" title="加粗" lay-command="Bold" layedit-event="b""></i>'
|
||||
,italic: '<i class="layui-icon layedit-tool-i" title="斜体" lay-command="italic" layedit-event="i""></i>'
|
||||
,underline: '<i class="layui-icon layedit-tool-u" title="下划线" lay-command="underline" layedit-event="u""></i>'
|
||||
,del: '<i class="layui-icon layedit-tool-d" title="删除线" lay-command="strikeThrough" layedit-event="d""></i>'
|
||||
|
||||
,'|': '<span class="layedit-tool-mid"></span>'
|
||||
|
||||
,left: '<i class="layui-icon layedit-tool-left" title="左对齐" lay-command="justifyLeft" layedit-event="left""></i>'
|
||||
,center: '<i class="layui-icon layedit-tool-center" title="居中对齐" lay-command="justifyCenter" layedit-event="center""></i>'
|
||||
,right: '<i class="layui-icon layedit-tool-right" title="右对齐" lay-command="justifyRight" layedit-event="right""></i>'
|
||||
,link: '<i class="layui-icon layedit-tool-link" title="插入链接" layedit-event="link""></i>'
|
||||
,unlink: '<i class="layui-icon layedit-tool-unlink layui-disabled" title="清除链接" lay-command="unlink" layedit-event="unlink""></i>'
|
||||
,face: '<i class="layui-icon layedit-tool-face" title="表情" layedit-event="face""></i>'
|
||||
,image: '<i class="layui-icon layedit-tool-image" title="图片" layedit-event="image"><input type="file" name="file"></i>'
|
||||
,code: '<i class="layui-icon layedit-tool-code" title="插入代码" layedit-event="code"></i>'
|
||||
|
||||
,help: '<i class="layui-icon layedit-tool-help" title="帮助" layedit-event="help"></i>'
|
||||
}
|
||||
|
||||
,edit = new Edit();
|
||||
|
||||
exports(MOD_NAME, edit);
|
||||
});
|
||||
@@ -1,309 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name : laypage 分页组件
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
"use strict";
|
||||
|
||||
var doc = document
|
||||
,id = 'getElementById'
|
||||
,tag = 'getElementsByTagName'
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'laypage', DISABLED = 'layui-disabled'
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.config = options || {};
|
||||
that.config.index = ++laypage.index;
|
||||
that.render(true);
|
||||
};
|
||||
|
||||
//判断传入的容器类型
|
||||
Class.prototype.type = function(){
|
||||
var config = this.config;
|
||||
if(typeof config.elem === 'object'){
|
||||
return config.elem.length === undefined ? 2 : 3;
|
||||
}
|
||||
};
|
||||
|
||||
//分页视图
|
||||
Class.prototype.view = function(){
|
||||
var that = this
|
||||
,config = that.config
|
||||
,groups = config.groups = 'groups' in config ? (config.groups|0) : 5; //连续页码个数
|
||||
|
||||
//排版
|
||||
config.layout = typeof config.layout === 'object'
|
||||
? config.layout
|
||||
: ['prev', 'page', 'next'];
|
||||
|
||||
config.count = config.count|0; //数据总数
|
||||
config.curr = (config.curr|0) || 1; //当前页
|
||||
|
||||
//每页条数的选择项
|
||||
config.limits = typeof config.limits === 'object'
|
||||
? config.limits
|
||||
: [10, 20, 30, 40, 50];
|
||||
config.limit = (config.limit|0) || 10; //默认条数
|
||||
|
||||
//总页数
|
||||
config.pages = Math.ceil(config.count/config.limit) || 1;
|
||||
|
||||
//当前页不能超过总页数
|
||||
if(config.curr > config.pages){
|
||||
config.curr = config.pages;
|
||||
}
|
||||
|
||||
//连续分页个数不能低于0且不能大于总页数
|
||||
if(groups < 0){
|
||||
groups = 1;
|
||||
} else if (groups > config.pages){
|
||||
groups = config.pages;
|
||||
}
|
||||
|
||||
config.prev = 'prev' in config ? config.prev : '上一页'; //上一页文本
|
||||
config.next = 'next' in config ? config.next : '下一页'; //下一页文本
|
||||
|
||||
//计算当前组
|
||||
var index = config.pages > groups
|
||||
? Math.ceil( (config.curr + (groups > 1 ? 1 : 0)) / (groups > 0 ? groups : 1) )
|
||||
: 1
|
||||
|
||||
//视图片段
|
||||
,views = {
|
||||
//上一页
|
||||
prev: function(){
|
||||
return config.prev
|
||||
? '<a href="javascript:;" class="layui-laypage-prev'+ (config.curr == 1 ? (' ' + DISABLED) : '') +'" data-page="'+ (config.curr - 1) +'">'+ config.prev +'</a>'
|
||||
: '';
|
||||
}()
|
||||
|
||||
//页码
|
||||
,page: function(){
|
||||
var pager = [];
|
||||
|
||||
//数据量为0时,不输出页码
|
||||
if(config.count < 1){
|
||||
return '';
|
||||
}
|
||||
|
||||
//首页
|
||||
if(index > 1 && config.first !== false && groups !== 0){
|
||||
pager.push('<a href="javascript:;" class="layui-laypage-first" data-page="1" title="首页">'+ (config.first || 1) +'</a>');
|
||||
}
|
||||
|
||||
//计算当前页码组的起始页
|
||||
var halve = Math.floor((groups-1)/2) //页码数等分
|
||||
,start = index > 1 ? config.curr - halve : 1
|
||||
,end = index > 1 ? (function(){
|
||||
var max = config.curr + (groups - halve - 1);
|
||||
return max > config.pages ? config.pages : max;
|
||||
}()) : groups;
|
||||
|
||||
//防止最后一组出现“不规定”的连续页码数
|
||||
if(end - start < groups - 1){
|
||||
start = end - groups + 1;
|
||||
}
|
||||
|
||||
//输出左分割符
|
||||
if(config.first !== false && start > 2){
|
||||
pager.push('<span class="layui-laypage-spr">…</span>')
|
||||
}
|
||||
|
||||
//输出连续页码
|
||||
for(; start <= end; start++){
|
||||
if(start === config.curr){
|
||||
//当前页
|
||||
pager.push('<span class="layui-laypage-curr"><em class="layui-laypage-em" '+ (/^#/.test(config.theme) ? 'style="background-color:'+ config.theme +';"' : '') +'></em><em>'+ start +'</em></span>');
|
||||
} else {
|
||||
pager.push('<a href="javascript:;" data-page="'+ start +'">'+ start +'</a>');
|
||||
}
|
||||
}
|
||||
|
||||
//输出输出右分隔符 & 末页
|
||||
if(config.pages > groups && config.pages > end && config.last !== false){
|
||||
if(end + 1 < config.pages){
|
||||
pager.push('<span class="layui-laypage-spr">…</span>');
|
||||
}
|
||||
if(groups !== 0){
|
||||
pager.push('<a href="javascript:;" class="layui-laypage-last" title="尾页" data-page="'+ config.pages +'">'+ (config.last || config.pages) +'</a>');
|
||||
}
|
||||
}
|
||||
|
||||
return pager.join('');
|
||||
}()
|
||||
|
||||
//下一页
|
||||
,next: function(){
|
||||
return config.next
|
||||
? '<a href="javascript:;" class="layui-laypage-next'+ (config.curr == config.pages ? (' ' + DISABLED) : '') +'" data-page="'+ (config.curr + 1) +'">'+ config.next +'</a>'
|
||||
: '';
|
||||
}()
|
||||
|
||||
//数据总数
|
||||
,count: '<span class="layui-laypage-count">共 '+ config.count +' 条</span>'
|
||||
|
||||
//每页条数
|
||||
,limit: function(){
|
||||
var options = ['<span class="layui-laypage-limits"><select lay-ignore>'];
|
||||
layui.each(config.limits, function(index, item){
|
||||
options.push(
|
||||
'<option value="'+ item +'"'
|
||||
+(item === config.limit ? 'selected' : '')
|
||||
+'>'+ item +' 条/页</option>'
|
||||
);
|
||||
});
|
||||
return options.join('') +'</select></span>';
|
||||
}()
|
||||
|
||||
//刷新当前页
|
||||
,refresh: ['<a href="javascript:;" data-page="'+ config.curr +'" class="layui-laypage-refresh">'
|
||||
,'<i class="layui-icon layui-icon-refresh"></i>'
|
||||
,'</a>'].join('')
|
||||
|
||||
//跳页区域
|
||||
,skip: function(){
|
||||
return ['<span class="layui-laypage-skip">到第'
|
||||
,'<input type="text" min="1" value="'+ config.curr +'" class="layui-input">'
|
||||
,'页<button type="button" class="layui-laypage-btn">确定</button>'
|
||||
,'</span>'].join('');
|
||||
}()
|
||||
};
|
||||
|
||||
return ['<div class="layui-box layui-laypage layui-laypage-'+ (config.theme ? (
|
||||
/^#/.test(config.theme) ? 'molv' : config.theme
|
||||
) : 'default') +'" id="layui-laypage-'+ config.index +'">'
|
||||
,function(){
|
||||
var plate = [];
|
||||
layui.each(config.layout, function(index, item){
|
||||
if(views[item]){
|
||||
plate.push(views[item])
|
||||
}
|
||||
});
|
||||
return plate.join('');
|
||||
}()
|
||||
,'</div>'].join('');
|
||||
};
|
||||
|
||||
//跳页的回调
|
||||
Class.prototype.jump = function(elem, isskip){
|
||||
if(!elem) return;
|
||||
var that = this
|
||||
,config = that.config
|
||||
,childs = elem.children
|
||||
,btn = elem[tag]('button')[0]
|
||||
,input = elem[tag]('input')[0]
|
||||
,select = elem[tag]('select')[0]
|
||||
,skip = function(){
|
||||
var curr = input.value.replace(/\s|\D/g, '')|0;
|
||||
if(curr){
|
||||
config.curr = curr;
|
||||
that.render();
|
||||
}
|
||||
};
|
||||
|
||||
if(isskip) return skip();
|
||||
|
||||
//页码
|
||||
for(var i = 0, len = childs.length; i < len; i++){
|
||||
if(childs[i].nodeName.toLowerCase() === 'a'){
|
||||
laypage.on(childs[i], 'click', function(){
|
||||
var curr = this.getAttribute('data-page')|0;
|
||||
if(curr < 1 || curr > config.pages) return;
|
||||
config.curr = curr;
|
||||
that.render();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//条数
|
||||
if(select){
|
||||
laypage.on(select, 'change', function(){
|
||||
var value = this.value;
|
||||
if(config.curr*value > config.count){
|
||||
config.curr = Math.ceil(config.count/value);
|
||||
}
|
||||
config.limit = value;
|
||||
that.render();
|
||||
});
|
||||
}
|
||||
|
||||
//确定
|
||||
if(btn){
|
||||
laypage.on(btn, 'click', function(){
|
||||
skip();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//输入页数字控制
|
||||
Class.prototype.skip = function(elem){
|
||||
if(!elem) return;
|
||||
var that = this, input = elem[tag]('input')[0];
|
||||
if(!input) return;
|
||||
laypage.on(input, 'keyup', function(e){
|
||||
var value = this.value
|
||||
,keyCode = e.keyCode;
|
||||
if(/^(37|38|39|40)$/.test(keyCode)) return;
|
||||
if(/\D/.test(value)){
|
||||
this.value = value.replace(/\D/, '');
|
||||
}
|
||||
if(keyCode === 13){
|
||||
that.jump(elem, true)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//渲染分页
|
||||
Class.prototype.render = function(load){
|
||||
var that = this
|
||||
,config = that.config
|
||||
,type = that.type()
|
||||
,view = that.view();
|
||||
|
||||
if(type === 2){
|
||||
config.elem && (config.elem.innerHTML = view);
|
||||
} else if(type === 3){
|
||||
config.elem.html(view);
|
||||
} else {
|
||||
if(doc[id](config.elem)){
|
||||
doc[id](config.elem).innerHTML = view;
|
||||
}
|
||||
}
|
||||
|
||||
config.jump && config.jump(config, load);
|
||||
|
||||
var elem = doc[id]('layui-laypage-' + config.index);
|
||||
that.jump(elem);
|
||||
|
||||
if(config.hash && !load){
|
||||
location.hash = '!'+ config.hash +'='+ config.curr;
|
||||
}
|
||||
|
||||
that.skip(elem);
|
||||
};
|
||||
|
||||
//外部接口
|
||||
var laypage = {
|
||||
//分页渲染
|
||||
render: function(options){
|
||||
var o = new Class(options);
|
||||
return o.index;
|
||||
}
|
||||
,index: layui.laypage ? (layui.laypage.index + 10000) : 0
|
||||
,on: function(elem, even, fn){
|
||||
elem.attachEvent ? elem.attachEvent('on'+ even, function(e){ //for ie
|
||||
e.target = e.srcElement;
|
||||
fn.call(elem, e);
|
||||
}) : elem.addEventListener(even, fn, false);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
exports(MOD_NAME, laypage);
|
||||
});
|
||||
@@ -1,122 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name : laytpl 模板引擎
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
|
||||
"use strict";
|
||||
|
||||
var config = {
|
||||
open: '{{',
|
||||
close: '}}'
|
||||
};
|
||||
|
||||
var tool = {
|
||||
exp: function(str){
|
||||
return new RegExp(str, 'g');
|
||||
},
|
||||
//匹配满足规则内容
|
||||
query: function(type, _, __){
|
||||
var types = [
|
||||
'#([\\s\\S])+?', //js语句
|
||||
'([^{#}])*?' //普通字段
|
||||
][type || 0];
|
||||
return exp((_||'') + config.open + types + config.close + (__||''));
|
||||
},
|
||||
escape: function(html){
|
||||
return String(html||'').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
|
||||
.replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/"/g, '"');
|
||||
},
|
||||
error: function(e, tplog){
|
||||
var error = 'Laytpl Error: ';
|
||||
typeof console === 'object' && console.error(error + e + '\n'+ (tplog || ''));
|
||||
return error + e;
|
||||
}
|
||||
};
|
||||
|
||||
var exp = tool.exp, Tpl = function(tpl){
|
||||
this.tpl = tpl;
|
||||
};
|
||||
|
||||
Tpl.pt = Tpl.prototype;
|
||||
|
||||
window.errors = 0;
|
||||
|
||||
//编译模版
|
||||
Tpl.pt.parse = function(tpl, data){
|
||||
var that = this, tplog = tpl;
|
||||
var jss = exp('^'+config.open+'#', ''), jsse = exp(config.close+'$', '');
|
||||
|
||||
tpl = tpl.replace(/\s+|\r|\t|\n/g, ' ')
|
||||
.replace(exp(config.open+'#'), config.open+'# ')
|
||||
.replace(exp(config.close+'}'), '} '+config.close).replace(/\\/g, '\\\\')
|
||||
|
||||
//不匹配指定区域的内容
|
||||
.replace(exp(config.open + '!(.+?)!' + config.close), function(str){
|
||||
str = str.replace(exp('^'+ config.open + '!'), '')
|
||||
.replace(exp('!'+ config.close), '')
|
||||
.replace(exp(config.open + '|' + config.close), function(tag){
|
||||
return tag.replace(/(.)/g, '\\$1')
|
||||
});
|
||||
return str
|
||||
})
|
||||
|
||||
//匹配JS规则内容
|
||||
.replace(/(?="|')/g, '\\').replace(tool.query(), function(str){
|
||||
str = str.replace(jss, '').replace(jsse, '');
|
||||
return '";' + str.replace(/\\(.)/g, '$1') + ';view+="';
|
||||
})
|
||||
|
||||
//匹配普通字段
|
||||
.replace(tool.query(1), function(str){
|
||||
var start = '"+(';
|
||||
if(str.replace(/\s/g, '') === config.open+config.close){
|
||||
return '';
|
||||
}
|
||||
str = str.replace(exp(config.open+'|'+config.close), '');
|
||||
if(/^=/.test(str)){
|
||||
str = str.replace(/^=/, '');
|
||||
start = '"+_escape_(';
|
||||
}
|
||||
return start + str.replace(/\\(.)/g, '$1') + ')+"';
|
||||
});
|
||||
|
||||
tpl = '"use strict";var view = "' + tpl + '";return view;';
|
||||
|
||||
try{
|
||||
that.cache = tpl = new Function('d, _escape_', tpl);
|
||||
return tpl(data, tool.escape);
|
||||
} catch(e){
|
||||
delete that.cache;
|
||||
return tool.error(e, tplog);
|
||||
}
|
||||
};
|
||||
|
||||
Tpl.pt.render = function(data, callback){
|
||||
var that = this, tpl;
|
||||
if(!data) return tool.error('no data');
|
||||
tpl = that.cache ? that.cache(data, tool.escape) : that.parse(that.tpl, data);
|
||||
if(!callback) return tpl;
|
||||
callback(tpl);
|
||||
};
|
||||
|
||||
var laytpl = function(tpl){
|
||||
if(typeof tpl !== 'string') return tool.error('Template not found');
|
||||
return new Tpl(tpl);
|
||||
};
|
||||
|
||||
laytpl.config = function(options){
|
||||
options = options || {};
|
||||
for(var i in options){
|
||||
config[i] = options[i];
|
||||
}
|
||||
};
|
||||
|
||||
laytpl.v = '1.2.0';
|
||||
|
||||
exports('laytpl', laytpl);
|
||||
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
|
||||
/*!
|
||||
* 用于打包聚合版,该文件不会存在于构建后的目录
|
||||
*/
|
||||
|
||||
layui.define(function(exports){
|
||||
var cache = layui.cache;
|
||||
layui.config({
|
||||
dir: cache.dir.replace(/lay\/dest\/$/, '')
|
||||
});
|
||||
exports('layui.all', layui.v);
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:layui 移动模块入口 | 构建后则为移动模块集合
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
|
||||
if(!layui['layui.mobile']){
|
||||
layui.config({
|
||||
base: layui.cache.dir + 'lay/modules/mobile/'
|
||||
}).extend({
|
||||
'layer-mobile': 'layer-mobile'
|
||||
,'zepto': 'zepto'
|
||||
,'upload-mobile': 'upload-mobile'
|
||||
,'layim-mobile': 'layim-mobile'
|
||||
});
|
||||
}
|
||||
|
||||
layui.define([
|
||||
'layer-mobile'
|
||||
,'zepto'
|
||||
,'layim-mobile'
|
||||
], function(exports){
|
||||
exports('mobile', {
|
||||
layer: layui['layer-mobile'] //弹层
|
||||
,layim: layui['layim-mobile'] //WebIM
|
||||
});
|
||||
});
|
||||
@@ -1,218 +0,0 @@
|
||||
/**
|
||||
|
||||
@Title: rate 评分评星组件
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery',function(exports){
|
||||
"use strict";
|
||||
var $ = layui.jquery
|
||||
|
||||
//外部接口
|
||||
,rate = {
|
||||
config: {}
|
||||
,index: layui.rate ? (layui.rate.index + 10000) : 0
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisRate = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
return {
|
||||
setvalue: function(value){
|
||||
that.setvalue.call(that, value);
|
||||
}
|
||||
,config: options
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'rate',ELEM_VIEW = 'layui-rate', ICON_RATE = 'layui-icon-rate', ICON_RATE_SOLID = 'layui-icon-rate-solid', ICON_RATE_HALF = 'layui-icon-rate-half'
|
||||
|
||||
,ICON_SOLID_HALF = 'layui-icon-rate-solid layui-icon-rate-half', ICON_SOLID_RATE = 'layui-icon-rate-solid layui-icon-rate', ICON_HALF_RATE = 'layui-icon-rate layui-icon-rate-half'
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.index = ++rate.index;
|
||||
that.config = $.extend({}, that.config, rate.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
length: 5 //初始长度
|
||||
,text: false //是否显示评分等级
|
||||
,readonly: false //是否只读
|
||||
,half: false //是否可以半星
|
||||
,value: 0 //星星选中个数
|
||||
,theme: ''
|
||||
};
|
||||
|
||||
//评分渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,style = options.theme ? ('style="color: '+ options.theme + ';"') : '';
|
||||
|
||||
options.elem = $(options.elem);
|
||||
|
||||
//最大值不能大于总长度
|
||||
if(options.value > options.length){
|
||||
options.value = options.length;
|
||||
}
|
||||
|
||||
//如果没有选择半星的属性,却给了小数的数值,统一向上或向下取整
|
||||
if(parseInt(options.value) !== options.value){
|
||||
if(!options.half){
|
||||
options.value = (Math.ceil(options.value) - options.value) < 0.5 ? Math.ceil(options.value): Math.floor(options.value)
|
||||
}
|
||||
}
|
||||
|
||||
//组件模板
|
||||
var temp = '<ul class="layui-rate" '+ (options.readonly ? 'readonly' : '') +'>';
|
||||
for(var i = 1;i <= options.length;i++){
|
||||
var item = '<li class="layui-inline"><i class="layui-icon '
|
||||
+ (i>Math.floor(options.value)?ICON_RATE:ICON_RATE_SOLID)
|
||||
+ '" '+ style +'></i></li>';
|
||||
|
||||
if(options.half){
|
||||
if(parseInt(options.value) !== options.value){
|
||||
if(i == Math.ceil(options.value)){
|
||||
temp = temp + '<li><i class="layui-icon layui-icon-rate-half" '+ style +'></i></li>';
|
||||
}else{
|
||||
temp = temp + item
|
||||
}
|
||||
}else{
|
||||
temp = temp + item
|
||||
}
|
||||
}else{
|
||||
temp = temp +item;
|
||||
}
|
||||
}
|
||||
temp += '</ul>' + (options.text ? ('<span class="layui-inline">'+ options.value + '星') : '') + '</span>';
|
||||
|
||||
//开始插入替代元素
|
||||
var othis = options.elem
|
||||
,hasRender = othis.next('.' + ELEM_VIEW);
|
||||
|
||||
//生成替代元素
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
|
||||
that.elemTemp = $(temp);
|
||||
|
||||
options.span = that.elemTemp.next('span');
|
||||
|
||||
options.setText && options.setText(options.value);
|
||||
|
||||
othis.html(that.elemTemp);
|
||||
|
||||
othis.addClass("layui-inline");
|
||||
|
||||
//如果不是只读,那么进行触控事件
|
||||
if(!options.readonly) that.action();
|
||||
|
||||
};
|
||||
|
||||
//评分重置
|
||||
Class.prototype.setvalue = function(value){
|
||||
var that = this
|
||||
,options = that.config ;
|
||||
|
||||
options.value = value ;
|
||||
that.render();
|
||||
};
|
||||
|
||||
//li触控事件
|
||||
Class.prototype.action = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,_ul = that.elemTemp
|
||||
,wide = _ul.find("i").width();
|
||||
|
||||
_ul.children("li").each(function(index){
|
||||
var ind = index + 1
|
||||
,othis = $(this);
|
||||
|
||||
//点击
|
||||
othis.on('click', function(e){
|
||||
//将当前点击li的索引值赋给value
|
||||
options.value = ind;
|
||||
if(options.half){
|
||||
//获取鼠标在li上的位置
|
||||
var x = e.pageX - $(this).offset().left;
|
||||
if(x <= wide / 2){
|
||||
options.value = options.value - 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
if(options.text) _ul.next("span").text(options.value + "星");
|
||||
|
||||
options.choose && options.choose(options.value);
|
||||
options.setText && options.setText(options.value);
|
||||
});
|
||||
|
||||
//移入
|
||||
othis.on('mousemove', function(e){
|
||||
_ul.find("i").each(function(){
|
||||
$(this).addClass(ICON_RATE).removeClass(ICON_SOLID_HALF)
|
||||
});
|
||||
_ul.find("i:lt(" + ind + ")").each(function(){
|
||||
$(this).addClass(ICON_RATE_SOLID).removeClass(ICON_HALF_RATE)
|
||||
});
|
||||
// 如果设置可选半星,那么判断鼠标相对li的位置
|
||||
if(options.half){
|
||||
var x = e.pageX - $(this).offset().left;
|
||||
if(x <= wide / 2){
|
||||
othis.children("i").addClass(ICON_RATE_HALF).removeClass(ICON_RATE_SOLID)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
//移出
|
||||
othis.on('mouseleave', function(){
|
||||
_ul.find("i").each(function(){
|
||||
$(this).addClass(ICON_RATE).removeClass(ICON_SOLID_HALF)
|
||||
});
|
||||
_ul.find("i:lt(" + Math.floor(options.value) + ")").each(function(){
|
||||
$(this).addClass(ICON_RATE_SOLID).removeClass(ICON_HALF_RATE)
|
||||
});
|
||||
//如果设置可选半星,根据分数判断是否有半星
|
||||
if(options.half){
|
||||
if(parseInt(options.value) !== options.value){
|
||||
_ul.children("li:eq(" + Math.floor(options.value) + ")").children("i").addClass(ICON_RATE_HALF).removeClass(ICON_SOLID_RATE)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
};
|
||||
|
||||
//事件处理
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
};
|
||||
|
||||
//核心入口
|
||||
rate.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisRate.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, rate);
|
||||
})
|
||||
@@ -1,383 +0,0 @@
|
||||
/**
|
||||
|
||||
@Title: slider 滑块组件
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
var $ = layui.jquery
|
||||
|
||||
//外部接口
|
||||
,slider = {
|
||||
config: {}
|
||||
,index: layui.slider ? (layui.slider.index + 10000) : 0
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisSlider = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
return {
|
||||
setValue: function(value, index){ //设置值
|
||||
options.value = value;
|
||||
return that.slide('set', value, index || 0);
|
||||
}
|
||||
,config: options
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'slider', DISABLED = 'layui-disabled', ELEM_VIEW = 'layui-slider', SLIDER_BAR = 'layui-slider-bar', SLIDER_WRAP = 'layui-slider-wrap', SLIDER_WRAP_BTN = 'layui-slider-wrap-btn', SLIDER_TIPS = 'layui-slider-tips', SLIDER_INPUT = 'layui-slider-input', SLIDER_INPUT_TXT = 'layui-slider-input-txt', SLIDER_INPUT_BTN = 'layui-slider-input-btn', ELEM_HOVER = 'layui-slider-hover'
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.index = ++slider.index;
|
||||
that.config = $.extend({}, that.config, slider.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
type: 'default' //滑块类型,垂直:vertical
|
||||
,min: 0 //最小值
|
||||
,max: 100 //最大值,默认100
|
||||
,value: 0 //初始值,默认为0
|
||||
,step: 1 //间隔值
|
||||
,showstep: false //间隔点开启
|
||||
,tips: true //文字提示,开启
|
||||
,input: false //输入框,关闭
|
||||
,range: false //范围选择,与输入框不能同时开启,默认关闭
|
||||
,height: 200 //配合 type:"vertical" 使用,默认200px
|
||||
,disabled: false //滑块禁用,默认关闭
|
||||
,theme: '#009688' //主题颜色
|
||||
};
|
||||
|
||||
//滑块渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//间隔值不能小于 1
|
||||
if(options.step < 1) options.step = 1;
|
||||
|
||||
//最大值不能小于最小值
|
||||
if(options.max < options.min) options.max = options.min + options.step;
|
||||
|
||||
|
||||
|
||||
//判断是否开启双滑块
|
||||
if(options.range){
|
||||
options.value = typeof(options.value) == 'object' ? options.value : [options.min, options.value];
|
||||
var minValue = Math.min(options.value[0], options.value[1])
|
||||
,maxValue = Math.max(options.value[0], options.value[1]);
|
||||
options.value[0] = minValue > options.min ? minValue : options.min;
|
||||
options.value[1] = maxValue > options.min ? maxValue : options.min;
|
||||
options.value[0] = options.value[0] > options.max ? options.max : options.value[0];
|
||||
options.value[1] = options.value[1] > options.max ? options.max : options.value[1];
|
||||
|
||||
var scaleFir = Math.floor((options.value[0] - options.min) / (options.max - options.min) * 100)
|
||||
,scaleSec = Math.floor((options.value[1] - options.min) / (options.max - options.min) * 100)
|
||||
,scale = scaleSec - scaleFir + '%';
|
||||
scaleFir = scaleFir + '%';
|
||||
scaleSec = scaleSec + '%';
|
||||
} else {
|
||||
//如果初始值是一个数组,则获取数组的最小值
|
||||
if(typeof options.value == 'object'){
|
||||
options.value = Math.min.apply(null, options.value);
|
||||
}
|
||||
|
||||
//初始值不能小于最小值且不能大于最大值
|
||||
if(options.value < options.min) options.value = options.min;
|
||||
if(options.value > options.max) options.value = options.max;
|
||||
|
||||
var scale = Math.floor((options.value - options.min) / (options.max - options.min) * 100) + '%';
|
||||
};
|
||||
|
||||
|
||||
//如果禁用,颜色为统一的灰色
|
||||
var theme = options.disabled ? '#c2c2c2' : options.theme;
|
||||
|
||||
//滑块
|
||||
var temp = '<div class="layui-slider '+ (options.type === 'vertical' ? 'layui-slider-vertical' : '') +'">'+ (options.tips ? '<div class="layui-slider-tips"></div>' : '') +
|
||||
'<div class="layui-slider-bar" style="background:'+ theme +'; '+ (options.type === 'vertical' ? 'height' : 'width') +':'+ scale +';'+ (options.type === 'vertical' ? 'bottom' : 'left') +':'+ (scaleFir || 0) +';"></div><div class="layui-slider-wrap" style="'+ (options.type === 'vertical' ? 'bottom' : 'left') +':'+ (scaleFir || scale) +';">' +
|
||||
'<div class="layui-slider-wrap-btn" style="border: 2px solid '+ theme +';"></div></div>'+ (options.range ? '<div class="layui-slider-wrap" style="'+ (options.type === 'vertical' ? 'bottom' : 'left') +':'+ scaleSec +';"><div class="layui-slider-wrap-btn" style="border: 2px solid '+ theme +';"></div></div>' : '') +'</div>';
|
||||
|
||||
var othis = $(options.elem)
|
||||
,hasRender = othis.next('.' + ELEM_VIEW);
|
||||
//生成替代元素
|
||||
hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
|
||||
that.elemTemp = $(temp);
|
||||
|
||||
//把数据缓存到滑块上
|
||||
if(options.range){
|
||||
that.elemTemp.find('.' + SLIDER_WRAP).eq(0).data('value', options.value[0]);
|
||||
that.elemTemp.find('.' + SLIDER_WRAP).eq(1).data('value', options.value[1]);
|
||||
}else{
|
||||
that.elemTemp.find('.' + SLIDER_WRAP).data('value', options.value);
|
||||
};
|
||||
|
||||
//插入替代元素
|
||||
othis.html(that.elemTemp);
|
||||
|
||||
//垂直滑块
|
||||
if(options.type === 'vertical'){
|
||||
that.elemTemp.height(options.height + 'px');
|
||||
};
|
||||
|
||||
//显示间断点
|
||||
if(options.showstep){
|
||||
var number = (options.max - options.min) / options.step, item = '';
|
||||
for(var i = 1; i < number + 1; i++) {
|
||||
var step = i * 100 / number;
|
||||
if(step < 100){
|
||||
item += '<div class="layui-slider-step" style="'+ (options.type === 'vertical' ? 'bottom' : 'left') +':'+ step +'%"></div>'
|
||||
}
|
||||
};
|
||||
that.elemTemp.append(item);
|
||||
};
|
||||
|
||||
//插入输入框
|
||||
if(options.input && !options.range){
|
||||
var elemInput = $('<div class="layui-slider-input layui-input"><div class="layui-slider-input-txt"><input type="text" class="layui-input"></div><div class="layui-slider-input-btn"><i class="layui-icon layui-icon-up"></i><i class="layui-icon layui-icon-down"></i></div></div>');
|
||||
othis.css("position","relative");
|
||||
othis.append(elemInput);
|
||||
othis.find('.' + SLIDER_INPUT_TXT).children('input').val(options.value);
|
||||
if(options.type === 'vertical'){
|
||||
elemInput.css({
|
||||
left: 0
|
||||
,top: -48
|
||||
});
|
||||
} else {
|
||||
that.elemTemp.css("margin-right", elemInput.outerWidth() + 15);
|
||||
}
|
||||
};
|
||||
|
||||
//给未禁止的滑块滑动事件
|
||||
if(!options.disabled){
|
||||
that.slide();
|
||||
}else{
|
||||
that.elemTemp.addClass(DISABLED);
|
||||
that.elemTemp.find('.' + SLIDER_WRAP_BTN).addClass(DISABLED);
|
||||
};
|
||||
|
||||
//划过滑块显示数值
|
||||
that.elemTemp.find('.' + SLIDER_WRAP_BTN).on('mouseover', function(){
|
||||
var sliderWidth = options.type === 'vertical' ? options.height : that.elemTemp[0].offsetWidth
|
||||
,sliderWrap = that.elemTemp.find('.' + SLIDER_WRAP)
|
||||
,tipsLeft = options.type === 'vertical' ? (sliderWidth - $(this).parent()[0].offsetTop - sliderWrap.height()) : $(this).parent()[0].offsetLeft
|
||||
,left = tipsLeft / sliderWidth * 100
|
||||
,value = $(this).parent().data('value')
|
||||
,tipsTxt = options.setTips ? options.setTips(value) : value;
|
||||
that.elemTemp.find('.' + SLIDER_TIPS).html(tipsTxt);
|
||||
if(options.type === 'vertical'){
|
||||
that.elemTemp.find('.' + SLIDER_TIPS).css({"bottom":left + '%', "margin-bottom":"20px", "display":"inline-block"});
|
||||
}else{
|
||||
that.elemTemp.find('.' + SLIDER_TIPS).css({"left":left + '%', "display":"inline-block"});
|
||||
};
|
||||
}).on('mouseout', function(){
|
||||
that.elemTemp.find('.' + SLIDER_TIPS).css("display", "none");
|
||||
});
|
||||
};
|
||||
|
||||
//滑块滑动
|
||||
Class.prototype.slide = function(setValue, value, i){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,sliderAct = that.elemTemp
|
||||
,sliderWidth = function(){
|
||||
return options.type === 'vertical' ? options.height : sliderAct[0].offsetWidth
|
||||
}
|
||||
,sliderWrap = sliderAct.find('.' + SLIDER_WRAP)
|
||||
,sliderTxt = sliderAct.next('.' + SLIDER_INPUT)
|
||||
,inputValue = sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').val()
|
||||
,step = 100 / ((options.max - options.min) / Math.ceil(options.step))
|
||||
,change = function(offsetValue, index){
|
||||
if(Math.ceil(offsetValue) * step > 100){
|
||||
offsetValue = Math.ceil(offsetValue) * step
|
||||
}else{
|
||||
offsetValue = Math.round(offsetValue) * step
|
||||
};
|
||||
offsetValue = offsetValue > 100 ? 100: offsetValue;
|
||||
sliderWrap.eq(index).css((options.type === 'vertical' ?'bottom':'left'), offsetValue + '%');
|
||||
var firLeft = valueTo(sliderWrap[0].offsetLeft)
|
||||
,secLeft = options.range ? valueTo(sliderWrap[1].offsetLeft) : 0;
|
||||
if(options.type === 'vertical'){
|
||||
sliderAct.find('.' + SLIDER_TIPS).css({"bottom":offsetValue + '%', "margin-bottom":"20px"});
|
||||
firLeft = valueTo(sliderWidth() - sliderWrap[0].offsetTop - sliderWrap.height());
|
||||
secLeft = options.range ? valueTo(sliderWidth() - sliderWrap[1].offsetTop - sliderWrap.height()) : 0;
|
||||
}else{
|
||||
sliderAct.find('.' + SLIDER_TIPS).css("left",offsetValue + '%');
|
||||
};
|
||||
firLeft = firLeft > 100 ? 100: firLeft;
|
||||
secLeft = secLeft > 100 ? 100: secLeft;
|
||||
var minLeft = Math.min(firLeft, secLeft)
|
||||
,wrapWidth = Math.abs(firLeft - secLeft);
|
||||
if(options.type === 'vertical'){
|
||||
sliderAct.find('.' + SLIDER_BAR).css({"height":wrapWidth + '%', "bottom":minLeft + '%'});
|
||||
}else{
|
||||
sliderAct.find('.' + SLIDER_BAR).css({"width":wrapWidth + '%', "left":minLeft + '%'});
|
||||
};
|
||||
var selfValue = options.min + Math.round((options.max - options.min) * offsetValue / 100);
|
||||
inputValue = selfValue;
|
||||
sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').val(inputValue);
|
||||
sliderWrap.eq(index).data('value', selfValue);
|
||||
sliderAct.find('.' + SLIDER_TIPS).html(options.setTips ? options.setTips(selfValue) : selfValue);
|
||||
|
||||
//如果开启范围选择,则返回数组值
|
||||
if(options.range){
|
||||
var arrValue = [
|
||||
sliderWrap.eq(0).data('value')
|
||||
,sliderWrap.eq(1).data('value')
|
||||
];
|
||||
if(arrValue[0] > arrValue[1]) arrValue.reverse(); //如果前面的圆点超过了后面的圆点值,则调换顺序
|
||||
}
|
||||
|
||||
//回调
|
||||
options.change && options.change(options.range ? arrValue : selfValue);
|
||||
}
|
||||
,valueTo = function(value){
|
||||
var oldLeft = value / sliderWidth() * 100 / step
|
||||
,left = Math.round(oldLeft) * step;
|
||||
if(value == sliderWidth()){
|
||||
left = Math.ceil(oldLeft) * step;
|
||||
};
|
||||
return left;
|
||||
}
|
||||
|
||||
//拖拽元素
|
||||
,elemMove = $(['<div class="layui-auxiliar-moving" id="LAY-slider-moving"></div'].join(''))
|
||||
,createMoveElem = function(move, up){
|
||||
var upCall = function(){
|
||||
up && up();
|
||||
elemMove.remove();
|
||||
};
|
||||
$('#LAY-slider-moving')[0] || $('body').append(elemMove);
|
||||
elemMove.on('mousemove', move);
|
||||
elemMove.on('mouseup', upCall).on('mouseleave', upCall);
|
||||
};
|
||||
|
||||
//动态赋值
|
||||
if(setValue === 'set') return change(value, i);
|
||||
|
||||
//滑块滑动
|
||||
sliderAct.find('.' + SLIDER_WRAP_BTN).each(function(index){
|
||||
var othis = $(this);
|
||||
othis.on('mousedown', function(e){
|
||||
e = e || window.event;
|
||||
|
||||
var oldleft = othis.parent()[0].offsetLeft
|
||||
,oldx = e.clientX;
|
||||
if(options.type === 'vertical'){
|
||||
oldleft = sliderWidth() - othis.parent()[0].offsetTop - sliderWrap.height()
|
||||
oldx = e.clientY;
|
||||
};
|
||||
|
||||
var move = function(e){
|
||||
e = e || window.event;
|
||||
var left = oldleft + (options.type === 'vertical' ? (oldx - e.clientY) : (e.clientX - oldx));
|
||||
if(left < 0)left = 0;
|
||||
if(left > sliderWidth())left = sliderWidth();
|
||||
var reaLeft = left / sliderWidth() * 100 / step;
|
||||
change(reaLeft, index);
|
||||
othis.addClass(ELEM_HOVER);
|
||||
sliderAct.find('.' + SLIDER_TIPS).show();
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
var up = function(){
|
||||
othis.removeClass(ELEM_HOVER);
|
||||
sliderAct.find('.' + SLIDER_TIPS).hide();
|
||||
};
|
||||
|
||||
createMoveElem(move, up)
|
||||
});
|
||||
});
|
||||
|
||||
//点击滑块
|
||||
sliderAct.on('click', function(e){
|
||||
var main = $('.' + SLIDER_WRAP_BTN);
|
||||
if(!main.is(event.target) && main.has(event.target).length === 0 && main.length){
|
||||
var left = options.type === 'vertical' ? (sliderWidth() - e.clientY + $(this).offset().top):(e.clientX - $(this).offset().left), index;
|
||||
if(left < 0)left = 0;
|
||||
if(left > sliderWidth())left = sliderWidth();
|
||||
var reaLeft = left / sliderWidth() * 100 / step;
|
||||
if(options.range){
|
||||
if(options.type === 'vertical'){
|
||||
index = Math.abs(left - parseInt($(sliderWrap[0]).css('bottom'))) > Math.abs(left - parseInt($(sliderWrap[1]).css('bottom'))) ? 1 : 0;
|
||||
}else{
|
||||
index = Math.abs(left - sliderWrap[0].offsetLeft) > Math.abs(left - sliderWrap[1].offsetLeft) ? 1 : 0;
|
||||
}
|
||||
}else{
|
||||
index = 0;
|
||||
};
|
||||
change(reaLeft, index);
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
//点击加减输入框
|
||||
sliderTxt.children('.' + SLIDER_INPUT_BTN).children('i').each(function(index){
|
||||
$(this).on('click', function(){
|
||||
inputValue = sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').val();
|
||||
if(index == 1){ //减
|
||||
inputValue = inputValue - options.step < options.min
|
||||
? options.min
|
||||
: Number(inputValue) - options.step;
|
||||
}else{
|
||||
inputValue = Number(inputValue) + options.step > options.max
|
||||
? options.max
|
||||
: Number(inputValue) + options.step;
|
||||
};
|
||||
var inputScale = (inputValue - options.min) / (options.max - options.min) * 100 / step;
|
||||
change(inputScale, 0);
|
||||
});
|
||||
});
|
||||
|
||||
//获取输入框值
|
||||
var getInputValue = function(){
|
||||
var realValue = this.value;
|
||||
realValue = isNaN(realValue) ? 0 : realValue;
|
||||
realValue = realValue < options.min ? options.min : realValue;
|
||||
realValue = realValue > options.max ? options.max : realValue;
|
||||
this.value = realValue;
|
||||
var inputScale = (realValue - options.min) / (options.max - options.min) * 100 / step;
|
||||
change(inputScale, 0);
|
||||
};
|
||||
sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').on('keydown', function(e){
|
||||
if(e.keyCode === 13){
|
||||
e.preventDefault();
|
||||
getInputValue.call(this);
|
||||
}
|
||||
}).on('change', getInputValue);
|
||||
};
|
||||
|
||||
//事件处理
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
};
|
||||
|
||||
//核心入口
|
||||
slider.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisSlider.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, slider);
|
||||
})
|
||||
@@ -1,437 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:transfer 穿梭框组件
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define(['laytpl', 'form'], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,laytpl = layui.laytpl
|
||||
,form = layui.form
|
||||
|
||||
//模块名
|
||||
,MOD_NAME = 'transfer'
|
||||
|
||||
//外部接口
|
||||
,transfer = {
|
||||
config: {}
|
||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisModule = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,id = options.id || that.index;
|
||||
|
||||
thisModule.that[id] = that; //记录当前实例对象
|
||||
thisModule.config[id] = options; //记录当前实例配置项
|
||||
|
||||
return {
|
||||
config: options
|
||||
//重置实例
|
||||
,reload: function(options){
|
||||
that.reload.call(that, options);
|
||||
}
|
||||
//获取右侧数据
|
||||
,getData: function(){
|
||||
return that.getData.call(that);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前实例配置项
|
||||
,getThisModuleConfig = function(id){
|
||||
var config = thisModule.config[id];
|
||||
if(!config) hint.error('The ID option was not found in the '+ MOD_NAME +' instance');
|
||||
return config || null;
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,ELEM = 'layui-transfer', HIDE = 'layui-hide', DISABLED = 'layui-btn-disabled', NONE = 'layui-none'
|
||||
,ELEM_BOX = 'layui-transfer-box', ELEM_HEADER = 'layui-transfer-header', ELEM_SEARCH = 'layui-transfer-search', ELEM_ACTIVE = 'layui-transfer-active', ELEM_DATA = 'layui-transfer-data'
|
||||
|
||||
//穿梭框模板
|
||||
,TPL_BOX = function(obj){
|
||||
obj = obj || {};
|
||||
return ['<div class="layui-transfer-box" data-index="'+ obj.index +'">'
|
||||
,'<div class="layui-transfer-header">'
|
||||
,'<input type="checkbox" name="'+ obj.checkAllName +'" lay-filter="layTransferCheckbox" lay-type="all" lay-skin="primary" title="{{ d.data.title['+ obj.index +'] || \'list'+ (obj.index + 1) +'\' }}">'
|
||||
,'</div>'
|
||||
,'{{# if(d.data.showSearch){ }}'
|
||||
,'<div class="layui-transfer-search">'
|
||||
,'<i class="layui-icon layui-icon-search"></i>'
|
||||
,'<input type="input" class="layui-input" placeholder="关键词搜索">'
|
||||
,'</div>'
|
||||
,'{{# } }}'
|
||||
,'<ul class="layui-transfer-data"></ul>'
|
||||
,'</div>'].join('');
|
||||
}
|
||||
|
||||
//主模板
|
||||
,TPL_MAIN = ['<div class="layui-transfer layui-form layui-border-box" lay-filter="LAY-transfer-{{ d.index }}">'
|
||||
,TPL_BOX({
|
||||
index: 0
|
||||
,checkAllName: 'layTransferLeftCheckAll'
|
||||
})
|
||||
,'<div class="layui-transfer-active">'
|
||||
,'<button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-btn-disabled" data-index="0">'
|
||||
,'<i class="layui-icon layui-icon-next"></i>'
|
||||
,'</button>'
|
||||
,'<button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-btn-disabled" data-index="1">'
|
||||
,'<i class="layui-icon layui-icon-prev"></i>'
|
||||
,'</button>'
|
||||
,'</div>'
|
||||
,TPL_BOX({
|
||||
index: 1
|
||||
,checkAllName: 'layTransferRightCheckAll'
|
||||
})
|
||||
,'</div>'].join('')
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.index = ++transfer.index;
|
||||
that.config = $.extend({}, that.config, transfer.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
title: ['列表一', '列表二']
|
||||
,width: 200
|
||||
,height: 360
|
||||
,data: [] //数据源
|
||||
,value: [] //选中的数据
|
||||
,showSearch: false //是否开启搜索
|
||||
,id: '' //唯一索引,默认自增 index
|
||||
,text: {
|
||||
none: '无数据'
|
||||
,searchNone: '无匹配数据'
|
||||
}
|
||||
};
|
||||
|
||||
//重载实例
|
||||
Class.prototype.reload = function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//解析模板
|
||||
var thisElem = that.elem = $(laytpl(TPL_MAIN).render({
|
||||
data: options
|
||||
,index: that.index //索引
|
||||
}));
|
||||
|
||||
var othis = options.elem = $(options.elem);
|
||||
if(!othis[0]) return;
|
||||
|
||||
//初始化属性
|
||||
options.data = options.data || [];
|
||||
options.value = options.value || [];
|
||||
|
||||
//索引
|
||||
that.key = options.id || that.index;
|
||||
|
||||
//插入组件结构
|
||||
othis.html(that.elem);
|
||||
|
||||
//各级容器
|
||||
that.layBox = that.elem.find('.'+ ELEM_BOX)
|
||||
that.layHeader = that.elem.find('.'+ ELEM_HEADER)
|
||||
that.laySearch = that.elem.find('.'+ ELEM_SEARCH)
|
||||
that.layData = thisElem.find('.'+ ELEM_DATA);
|
||||
that.layBtn = thisElem.find('.'+ ELEM_ACTIVE + ' .layui-btn');
|
||||
|
||||
//初始化尺寸
|
||||
that.layBox.css({
|
||||
width: options.width
|
||||
,height: options.height
|
||||
});
|
||||
that.layData.css({
|
||||
height: function(){
|
||||
return options.height - that.layHeader.outerHeight() - that.laySearch.outerHeight() - 2
|
||||
}()
|
||||
});
|
||||
|
||||
that.renderData(); //渲染数据
|
||||
that.events(); //事件
|
||||
};
|
||||
|
||||
//渲染数据
|
||||
Class.prototype.renderData = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//左右穿梭框差异数据
|
||||
var arr = [{
|
||||
checkName: 'layTransferLeftCheck'
|
||||
,views: []
|
||||
}, {
|
||||
checkName: 'layTransferRightCheck'
|
||||
,views: []
|
||||
}];
|
||||
|
||||
//解析格式
|
||||
that.parseData(function(item){
|
||||
//标注为 selected 的为右边的数据
|
||||
var _index = item.selected ? 1 : 0
|
||||
,listElem = ['<li>'
|
||||
,'<input type="checkbox" name="'+ arr[_index].checkName +'" lay-skin="primary" lay-filter="layTransferCheckbox" title="'+ item.title +'"'+ (item.disabled ? ' disabled' : '') + (item.checked ? ' checked' : '') +' value="'+ item.value +'">'
|
||||
,'</li>'].join('');
|
||||
arr[_index].views.push(listElem);
|
||||
delete item.selected;
|
||||
});
|
||||
|
||||
that.layData.eq(0).html(arr[0].views.join(''));
|
||||
that.layData.eq(1).html(arr[1].views.join(''));
|
||||
|
||||
that.renderCheckBtn();
|
||||
}
|
||||
|
||||
//渲染表单
|
||||
Class.prototype.renderForm = function(type){
|
||||
form.render(type, 'LAY-transfer-'+ this.index);
|
||||
};
|
||||
|
||||
//同步复选框和按钮状态
|
||||
Class.prototype.renderCheckBtn = function(obj){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
obj = obj || {};
|
||||
|
||||
that.layBox.each(function(_index){
|
||||
var othis = $(this)
|
||||
,thisDataElem = othis.find('.'+ ELEM_DATA)
|
||||
,allElemCheckbox = othis.find('.'+ ELEM_HEADER).find('input[type="checkbox"]')
|
||||
,listElemCheckbox = thisDataElem.find('input[type="checkbox"]');
|
||||
|
||||
//同步复选框和按钮状态
|
||||
var nums = 0
|
||||
,haveChecked = false;
|
||||
listElemCheckbox.each(function(){
|
||||
var isHide = $(this).data('hide');
|
||||
if(this.checked || this.disabled || isHide){
|
||||
nums++;
|
||||
}
|
||||
if(this.checked && !isHide){
|
||||
haveChecked = true;
|
||||
}
|
||||
});
|
||||
|
||||
allElemCheckbox.prop('checked', haveChecked && nums === listElemCheckbox.length); //全选复选框状态
|
||||
that.layBtn.eq(_index)[haveChecked ? 'removeClass' : 'addClass'](DISABLED); //对应的按钮状态
|
||||
|
||||
//无数据视图
|
||||
if(!obj.stopNone){
|
||||
var isNone = thisDataElem.children('li:not(.'+ HIDE +')').length
|
||||
that.noneView(thisDataElem, isNone ? '' : options.text.none);
|
||||
}
|
||||
});
|
||||
|
||||
that.renderForm('checkbox');
|
||||
};
|
||||
|
||||
//无数据视图
|
||||
Class.prototype.noneView = function(thisDataElem, text){
|
||||
var createNoneElem = $('<p class="layui-none">'+ (text || '') +'</p>');
|
||||
if(thisDataElem.find('.'+ NONE)[0]){
|
||||
thisDataElem.find('.'+ NONE).remove();
|
||||
}
|
||||
text.replace(/\s/g, '') && thisDataElem.append(createNoneElem);
|
||||
};
|
||||
|
||||
//同步 value 属性值
|
||||
Class.prototype.setValue = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,arr = [];
|
||||
that.layBox.eq(1).find('.'+ ELEM_DATA +' input[type="checkbox"]').each(function(){
|
||||
var isHide = $(this).data('hide');
|
||||
isHide || arr.push(this.value);
|
||||
});
|
||||
options.value = arr;
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
//解析数据
|
||||
Class.prototype.parseData = function(callback){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,newData = [];
|
||||
|
||||
layui.each(options.data, function(index, item){
|
||||
//解析格式
|
||||
item = (typeof options.parseData === 'function'
|
||||
? options.parseData(item)
|
||||
: item) || item;
|
||||
|
||||
newData.push(item = $.extend({}, item))
|
||||
|
||||
layui.each(options.value, function(index2, item2){
|
||||
if(item2 == item.value){
|
||||
item.selected = true;
|
||||
}
|
||||
});
|
||||
callback && callback(item);
|
||||
});
|
||||
|
||||
options.data = newData;
|
||||
return that;
|
||||
};
|
||||
|
||||
//获得右侧面板数据
|
||||
Class.prototype.getData = function(value){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,selectedData = [];
|
||||
|
||||
that.setValue();
|
||||
|
||||
layui.each(value || options.value, function(index, item){
|
||||
layui.each(options.data, function(index2, item2){
|
||||
delete item2.selected;
|
||||
if(item == item2.value){
|
||||
selectedData.push(item2);
|
||||
};
|
||||
});
|
||||
});
|
||||
return selectedData;
|
||||
};
|
||||
|
||||
//事件
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//左右复选框
|
||||
that.elem.on('click', 'input[lay-filter="layTransferCheckbox"]+', function(){
|
||||
var thisElemCheckbox = $(this).prev()
|
||||
,checked = thisElemCheckbox[0].checked
|
||||
,thisDataElem = thisElemCheckbox.parents('.'+ ELEM_BOX).eq(0).find('.'+ ELEM_DATA);
|
||||
|
||||
if(thisElemCheckbox[0].disabled) return;
|
||||
|
||||
//判断是否全选
|
||||
if(thisElemCheckbox.attr('lay-type') === 'all'){
|
||||
thisDataElem.find('input[type="checkbox"]').each(function(){
|
||||
if(this.disabled) return;
|
||||
this.checked = checked;
|
||||
});
|
||||
}
|
||||
|
||||
that.renderCheckBtn({stopNone: true});
|
||||
});
|
||||
|
||||
//按钮事件
|
||||
that.layBtn.on('click', function(){
|
||||
var othis = $(this)
|
||||
,_index = othis.data('index')
|
||||
,thisBoxElem = that.layBox.eq(_index)
|
||||
,arr = [];
|
||||
if(othis.hasClass(DISABLED)) return;
|
||||
|
||||
that.layBox.eq(_index).each(function(_index){
|
||||
var othis = $(this)
|
||||
,thisDataElem = othis.find('.'+ ELEM_DATA);
|
||||
|
||||
thisDataElem.children('li').each(function(){
|
||||
var thisList = $(this)
|
||||
,thisElemCheckbox = thisList.find('input[type="checkbox"]')
|
||||
,isHide = thisElemCheckbox.data('hide');
|
||||
|
||||
if(thisElemCheckbox[0].checked && !isHide){
|
||||
thisElemCheckbox[0].checked = false;
|
||||
thisBoxElem.siblings('.'+ ELEM_BOX).find('.'+ ELEM_DATA).append(thisList.clone());
|
||||
thisList.remove();
|
||||
|
||||
//记录当前穿梭的数据
|
||||
arr.push(thisElemCheckbox[0].value);
|
||||
}
|
||||
|
||||
that.setValue();
|
||||
});
|
||||
});
|
||||
|
||||
that.renderCheckBtn();
|
||||
|
||||
//穿梭时,如果另外一个框正在搜索,则触发匹配
|
||||
var siblingInput = thisBoxElem.siblings('.'+ ELEM_BOX).find('.'+ ELEM_SEARCH +' input')
|
||||
siblingInput.val() === '' || siblingInput.trigger('keyup');
|
||||
|
||||
//穿梭时的回调
|
||||
options.onchange && options.onchange(that.getData(arr), _index);
|
||||
});
|
||||
|
||||
//搜索
|
||||
that.laySearch.find('input').on('keyup', function(){
|
||||
var value = this.value
|
||||
,thisDataElem = $(this).parents('.'+ ELEM_SEARCH).eq(0).siblings('.'+ ELEM_DATA)
|
||||
,thisListElem = thisDataElem.children('li');
|
||||
|
||||
thisListElem.each(function(){
|
||||
var thisList = $(this)
|
||||
,thisElemCheckbox = thisList.find('input[type="checkbox"]')
|
||||
,isMatch = thisElemCheckbox[0].title.indexOf(value) !== -1;
|
||||
|
||||
thisList[isMatch ? 'removeClass': 'addClass'](HIDE);
|
||||
thisElemCheckbox.data('hide', isMatch ? false : true);
|
||||
});
|
||||
|
||||
that.renderCheckBtn();
|
||||
|
||||
//无匹配数据视图
|
||||
var isNone = thisListElem.length === thisDataElem.children('li.'+ HIDE).length;
|
||||
that.noneView(thisDataElem, isNone ? options.text.searchNone : '');
|
||||
});
|
||||
};
|
||||
|
||||
//记录所有实例
|
||||
thisModule.that = {}; //记录所有实例对象
|
||||
thisModule.config = {}; //记录所有实例配置项
|
||||
|
||||
//重载实例
|
||||
transfer.reload = function(id, options){
|
||||
var that = thisModule.that[id];
|
||||
that.reload(options);
|
||||
|
||||
return thisModule.call(that);
|
||||
};
|
||||
|
||||
//获得选中的数据(右侧面板)
|
||||
transfer.getData = function(id){
|
||||
var that = thisModule.that[id];
|
||||
return that.getData();
|
||||
};
|
||||
|
||||
//核心入口
|
||||
transfer.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisModule.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, transfer);
|
||||
});
|
||||
@@ -1,816 +0,0 @@
|
||||
/**
|
||||
|
||||
@Name:tree 树组件
|
||||
@License:MIT
|
||||
|
||||
*/
|
||||
|
||||
layui.define('form', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,form = layui.form
|
||||
,layer = layui.layer
|
||||
|
||||
//模块名
|
||||
,MOD_NAME = 'tree'
|
||||
|
||||
//外部接口
|
||||
,tree = {
|
||||
config: {}
|
||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisModule = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,id = options.id || that.index;
|
||||
|
||||
thisModule.that[id] = that; //记录当前实例对象
|
||||
thisModule.config[id] = options; //记录当前实例配置项
|
||||
|
||||
return {
|
||||
config: options
|
||||
//重置实例
|
||||
,reload: function(options){
|
||||
that.reload.call(that, options);
|
||||
}
|
||||
,getChecked: function(){
|
||||
return that.getChecked.call(that);
|
||||
}
|
||||
,setChecked: function(id){//设置值
|
||||
return that.setChecked.call(that, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前实例配置项
|
||||
,getThisModuleConfig = function(id){
|
||||
var config = thisModule.config[id];
|
||||
if(!config) hint.error('The ID option was not found in the '+ MOD_NAME +' instance');
|
||||
return config || null;
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,SHOW = 'layui-show', HIDE = 'layui-hide', NONE = 'layui-none', DISABLED = 'layui-disabled'
|
||||
|
||||
,ELEM_VIEW = 'layui-tree', ELEM_SET = 'layui-tree-set', ICON_CLICK = 'layui-tree-iconClick'
|
||||
,ICON_ADD = 'layui-icon-addition', ICON_SUB = 'layui-icon-subtraction', ELEM_ENTRY = 'layui-tree-entry', ELEM_MAIN = 'layui-tree-main', ELEM_TEXT = 'layui-tree-txt', ELEM_PACK = 'layui-tree-pack', ELEM_SPREAD = 'layui-tree-spread'
|
||||
,ELEM_LINE_SHORT = 'layui-tree-setLineShort', ELEM_SHOW = 'layui-tree-showLine', ELEM_EXTEND = 'layui-tree-lineExtend'
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.index = ++tree.index;
|
||||
that.config = $.extend({}, that.config, tree.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
data: [] //数据
|
||||
|
||||
,showCheckbox: false //是否显示复选框
|
||||
,showLine: true //是否开启连接线
|
||||
,accordion: false //是否开启手风琴模式
|
||||
,onlyIconControl: false //是否仅允许节点左侧图标控制展开收缩
|
||||
,isJump: false //是否允许点击节点时弹出新窗口跳转
|
||||
,edit: false //是否开启节点的操作图标
|
||||
|
||||
,text: {
|
||||
defaultNodeName: '未命名' //节点默认名称
|
||||
,none: '无数据' //数据为空时的文本提示
|
||||
}
|
||||
};
|
||||
|
||||
//重载实例
|
||||
Class.prototype.reload = function(options){
|
||||
var that = this;
|
||||
|
||||
layui.each(options, function(key, item){
|
||||
if(layui._typeof(item) === 'array') delete that.config[key];
|
||||
});
|
||||
|
||||
that.config = $.extend(true, {}, that.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//主体渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
that.checkids = [];
|
||||
|
||||
var temp = $('<div class="layui-tree'+ (options.showCheckbox ? " layui-form" : "") + (options.showLine ? " layui-tree-line" : "") +'" lay-filter="LAY-tree-'+ that.index +'"></div>');
|
||||
that.tree(temp);
|
||||
|
||||
var othis = options.elem = $(options.elem);
|
||||
if(!othis[0]) return;
|
||||
|
||||
//索引
|
||||
that.key = options.id || that.index;
|
||||
|
||||
//插入组件结构
|
||||
that.elem = temp;
|
||||
that.elemNone = $('<div class="layui-tree-emptyText">'+ options.text.none +'</div>');
|
||||
othis.html(that.elem);
|
||||
|
||||
if(that.elem.find('.layui-tree-set').length == 0){
|
||||
return that.elem.append(that.elemNone);
|
||||
};
|
||||
|
||||
//复选框渲染
|
||||
if(options.showCheckbox){
|
||||
that.renderForm('checkbox');
|
||||
};
|
||||
|
||||
that.elem.find('.layui-tree-set').each(function(){
|
||||
var othis = $(this);
|
||||
//最外层
|
||||
if(!othis.parent('.layui-tree-pack')[0]){
|
||||
othis.addClass('layui-tree-setHide');
|
||||
};
|
||||
|
||||
//没有下一个节点 上一层父级有延伸线
|
||||
if(!othis.next()[0] && othis.parents('.layui-tree-pack').eq(1).hasClass('layui-tree-lineExtend')){
|
||||
othis.addClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
|
||||
//没有下一个节点 外层最后一个
|
||||
if(!othis.next()[0] && !othis.parents('.layui-tree-set').eq(0).next()[0]){
|
||||
othis.addClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
});
|
||||
|
||||
that.events();
|
||||
};
|
||||
|
||||
//渲染表单
|
||||
Class.prototype.renderForm = function(type){
|
||||
form.render(type, 'LAY-tree-'+ this.index);
|
||||
};
|
||||
|
||||
//节点解析
|
||||
Class.prototype.tree = function(elem, children){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,data = children || options.data;
|
||||
|
||||
//遍历数据
|
||||
layui.each(data, function(index, item){
|
||||
var hasChild = item.children && item.children.length > 0
|
||||
,packDiv = $('<div class="layui-tree-pack" '+ (item.spread ? 'style="display: block;"' : '') +'></div>')
|
||||
,entryDiv = $(['<div data-id="'+ item.id +'" class="layui-tree-set'+ (item.spread ? " layui-tree-spread" : "") + (item.checked ? " layui-tree-checkedFirst" : "") +'">'
|
||||
,'<div class="layui-tree-entry">'
|
||||
,'<div class="layui-tree-main">'
|
||||
//箭头
|
||||
,function(){
|
||||
if(options.showLine){
|
||||
if(hasChild){
|
||||
return '<span class="layui-tree-iconClick layui-tree-icon"><i class="layui-icon '+ (item.spread ? "layui-icon-subtraction" : "layui-icon-addition") +'"></i></span>';
|
||||
}else{
|
||||
return '<span class="layui-tree-iconClick"><i class="layui-icon layui-icon-file"></i></span>';
|
||||
};
|
||||
}else{
|
||||
return '<span class="layui-tree-iconClick"><i class="layui-tree-iconArrow '+ (hasChild ? "": HIDE) +'"></i></span>';
|
||||
};
|
||||
}()
|
||||
|
||||
//复选框
|
||||
,function(){
|
||||
return options.showCheckbox ? '<input type="checkbox" name="'+ (item.field || ('layuiTreeCheck_'+ item.id)) +'" same="layuiTreeCheck" lay-skin="primary" '+ (item.disabled ? "disabled" : "") +' value="'+ item.id +'">' : '';
|
||||
}()
|
||||
|
||||
//节点
|
||||
,function(){
|
||||
if(options.isJump && item.href){
|
||||
return '<a href="'+ item.href +'" target="_blank" class="'+ ELEM_TEXT +'">'+ (item.title || item.label || options.text.defaultNodeName) +'</a>';
|
||||
}else{
|
||||
return '<span class="'+ ELEM_TEXT + (item.disabled ? ' '+ DISABLED : '') +'">'+ (item.title || item.label || options.text.defaultNodeName) +'</span>';
|
||||
}
|
||||
}()
|
||||
,'</div>'
|
||||
|
||||
//节点操作图标
|
||||
,function(){
|
||||
if(!options.edit) return '';
|
||||
|
||||
var editIcon = {
|
||||
add: '<i class="layui-icon layui-icon-add-1" data-type="add"></i>'
|
||||
,update: '<i class="layui-icon layui-icon-edit" data-type="update"></i>'
|
||||
,del: '<i class="layui-icon layui-icon-delete" data-type="del"></i>'
|
||||
}, arr = ['<div class="layui-btn-group layui-tree-btnGroup">'];
|
||||
|
||||
if(options.edit === true){
|
||||
options.edit = ['update', 'del']
|
||||
}
|
||||
|
||||
if(typeof options.edit === 'object'){
|
||||
layui.each(options.edit, function(i, val){
|
||||
arr.push(editIcon[val] || '')
|
||||
});
|
||||
return arr.join('') + '</div>';
|
||||
}
|
||||
}()
|
||||
,'</div></div>'].join(''));
|
||||
|
||||
//如果有子节点,则递归继续生成树
|
||||
if(hasChild){
|
||||
entryDiv.append(packDiv);
|
||||
that.tree(packDiv, item.children);
|
||||
};
|
||||
|
||||
elem.append(entryDiv);
|
||||
|
||||
//若有前置节点,前置节点加连接线
|
||||
if(entryDiv.prev('.'+ELEM_SET)[0]){
|
||||
entryDiv.prev().children('.layui-tree-pack').addClass('layui-tree-showLine');
|
||||
};
|
||||
|
||||
//若无子节点,则父节点加延伸线
|
||||
if(!hasChild){
|
||||
entryDiv.parent('.layui-tree-pack').addClass('layui-tree-lineExtend');
|
||||
};
|
||||
|
||||
//展开节点操作
|
||||
that.spread(entryDiv, item);
|
||||
|
||||
//选择框
|
||||
if(options.showCheckbox){
|
||||
item.checked && that.checkids.push(item.id);
|
||||
that.checkClick(entryDiv, item);
|
||||
}
|
||||
|
||||
//操作节点
|
||||
options.edit && that.operate(entryDiv, item);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
//展开节点
|
||||
Class.prototype.spread = function(elem, item){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,entry = elem.children('.'+ELEM_ENTRY)
|
||||
,elemMain = entry.children('.'+ ELEM_MAIN)
|
||||
,elemIcon = entry.find('.'+ ICON_CLICK)
|
||||
,elemText = entry.find('.'+ ELEM_TEXT)
|
||||
,touchOpen = options.onlyIconControl ? elemIcon : elemMain //判断展开通过节点还是箭头图标
|
||||
,state = '';
|
||||
|
||||
//展开收缩
|
||||
touchOpen.on('click', function(e){
|
||||
var packCont = elem.children('.'+ELEM_PACK)
|
||||
,iconClick = touchOpen.children('.layui-icon')[0] ? touchOpen.children('.layui-icon') : touchOpen.find('.layui-tree-icon').children('.layui-icon');
|
||||
|
||||
//若没有子节点
|
||||
if(!packCont[0]){
|
||||
state = 'normal';
|
||||
}else{
|
||||
if(elem.hasClass(ELEM_SPREAD)){
|
||||
elem.removeClass(ELEM_SPREAD);
|
||||
packCont.slideUp(200);
|
||||
iconClick.removeClass(ICON_SUB).addClass(ICON_ADD);
|
||||
}else{
|
||||
elem.addClass(ELEM_SPREAD);
|
||||
packCont.slideDown(200);
|
||||
iconClick.addClass(ICON_SUB).removeClass(ICON_ADD);
|
||||
|
||||
//是否手风琴
|
||||
if(options.accordion){
|
||||
var sibls = elem.siblings('.'+ELEM_SET);
|
||||
sibls.removeClass(ELEM_SPREAD);
|
||||
sibls.children('.'+ELEM_PACK).slideUp(200);
|
||||
sibls.find('.layui-tree-icon').children('.layui-icon').removeClass(ICON_SUB).addClass(ICON_ADD);
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
//点击回调
|
||||
elemText.on('click', function(){
|
||||
var othis = $(this);
|
||||
|
||||
//判断是否禁用状态
|
||||
if(othis.hasClass(DISABLED)) return;
|
||||
|
||||
//判断展开收缩状态
|
||||
if(elem.hasClass(ELEM_SPREAD)){
|
||||
state = options.onlyIconControl ? 'open' : 'close';
|
||||
} else {
|
||||
state = options.onlyIconControl ? 'close' : 'open';
|
||||
}
|
||||
|
||||
//点击产生的回调
|
||||
options.click && options.click({
|
||||
elem: elem
|
||||
,state: state
|
||||
,data: item
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
//计算复选框选中状态
|
||||
Class.prototype.setCheckbox = function(elem, item, elemCheckbox){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,checked = elemCheckbox.prop('checked');
|
||||
|
||||
if(elemCheckbox.prop('disabled')) return;
|
||||
|
||||
//同步子节点选中状态
|
||||
if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){
|
||||
var childs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]');
|
||||
childs.each(function(){
|
||||
if(this.disabled) return; //不可点击则跳过
|
||||
this.checked = checked;
|
||||
});
|
||||
};
|
||||
|
||||
//同步父节点选中状态
|
||||
var setParentsChecked = function(thisNodeElem){
|
||||
//若无父节点,则终止递归
|
||||
if(!thisNodeElem.parents('.'+ ELEM_SET)[0]) return;
|
||||
|
||||
var state
|
||||
,parentPack = thisNodeElem.parent('.'+ ELEM_PACK)
|
||||
,parentNodeElem = parentPack.parent()
|
||||
,parentCheckbox = parentPack.prev().find('input[same="layuiTreeCheck"]');
|
||||
|
||||
//如果子节点有任意一条选中,则父节点为选中状态
|
||||
if(checked){
|
||||
parentCheckbox.prop('checked', checked);
|
||||
} else { //如果当前节点取消选中,则根据计算“兄弟和子孙”节点选中状态,来同步父节点选中状态
|
||||
parentPack.find('input[same="layuiTreeCheck"]').each(function(){
|
||||
if(this.checked){
|
||||
state = true;
|
||||
}
|
||||
});
|
||||
|
||||
//如果兄弟子孙节点全部未选中,则父节点也应为非选中状态
|
||||
state || parentCheckbox.prop('checked', false);
|
||||
}
|
||||
|
||||
//向父节点递归
|
||||
setParentsChecked(parentNodeElem);
|
||||
};
|
||||
|
||||
setParentsChecked(elem);
|
||||
|
||||
that.renderForm('checkbox');
|
||||
};
|
||||
|
||||
//复选框选择
|
||||
Class.prototype.checkClick = function(elem, item){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,entry = elem.children('.'+ ELEM_ENTRY)
|
||||
,elemMain = entry.children('.'+ ELEM_MAIN);
|
||||
|
||||
|
||||
|
||||
//点击复选框
|
||||
elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){
|
||||
layui.stope(e); //阻止点击节点事件
|
||||
|
||||
var elemCheckbox = $(this).prev()
|
||||
,checked = elemCheckbox.prop('checked');
|
||||
|
||||
if(elemCheckbox.prop('disabled')) return;
|
||||
|
||||
that.setCheckbox(elem, item, elemCheckbox);
|
||||
|
||||
//复选框点击产生的回调
|
||||
options.oncheck && options.oncheck({
|
||||
elem: elem
|
||||
,checked: checked
|
||||
,data: item
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
//节点操作
|
||||
Class.prototype.operate = function(elem, item){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,entry = elem.children('.'+ ELEM_ENTRY)
|
||||
,elemMain = entry.children('.'+ ELEM_MAIN);
|
||||
|
||||
entry.children('.layui-tree-btnGroup').on('click', '.layui-icon', function(e){
|
||||
layui.stope(e); //阻止节点操作
|
||||
|
||||
var type = $(this).data("type")
|
||||
,packCont = elem.children('.'+ELEM_PACK)
|
||||
,returnObj = {
|
||||
data: item
|
||||
,type: type
|
||||
,elem:elem
|
||||
};
|
||||
//增加
|
||||
if(type == 'add'){
|
||||
//若节点本身无子节点
|
||||
if(!packCont[0]){
|
||||
//若开启连接线,更改图标样式
|
||||
if(options.showLine){
|
||||
elemMain.find('.'+ICON_CLICK).addClass('layui-tree-icon');
|
||||
elemMain.find('.'+ICON_CLICK).children('.layui-icon').addClass(ICON_ADD).removeClass('layui-icon-file');
|
||||
//若未开启连接线,显示箭头
|
||||
}else{
|
||||
elemMain.find('.layui-tree-iconArrow').removeClass(HIDE);
|
||||
};
|
||||
//节点添加子节点容器
|
||||
elem.append('<div class="layui-tree-pack"></div>');
|
||||
};
|
||||
|
||||
//新增节点
|
||||
var key = options.operate && options.operate(returnObj)
|
||||
,obj = {};
|
||||
obj.title = options.text.defaultNodeName;
|
||||
obj.id = key;
|
||||
that.tree(elem.children('.'+ELEM_PACK), [obj]);
|
||||
|
||||
//放在新增后面,因为要对元素进行操作
|
||||
if(options.showLine){
|
||||
//节点本身无子节点
|
||||
if(!packCont[0]){
|
||||
//遍历兄弟节点,判断兄弟节点是否有子节点
|
||||
var siblings = elem.siblings('.'+ELEM_SET), num = 1
|
||||
,parentPack = elem.parent('.'+ELEM_PACK);
|
||||
layui.each(siblings, function(index, i){
|
||||
if(!$(i).children('.'+ELEM_PACK)[0]){
|
||||
num = 0;
|
||||
};
|
||||
});
|
||||
|
||||
//若兄弟节点都有子节点
|
||||
if(num == 1){
|
||||
//兄弟节点添加连接线
|
||||
siblings.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
||||
siblings.children('.'+ELEM_PACK).children('.'+ELEM_SET).removeClass(ELEM_LINE_SHORT);
|
||||
elem.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
||||
//父级移除延伸线
|
||||
parentPack.removeClass(ELEM_EXTEND);
|
||||
//同层节点最后一个更改线的状态
|
||||
parentPack.children('.'+ELEM_SET).last().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||
}else{
|
||||
elem.children('.'+ELEM_PACK).children('.'+ELEM_SET).addClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
}else{
|
||||
//添加延伸线
|
||||
if(!packCont.hasClass(ELEM_EXTEND)){
|
||||
packCont.addClass(ELEM_EXTEND);
|
||||
};
|
||||
//子节点添加延伸线
|
||||
elem.find('.'+ELEM_PACK).each(function(){
|
||||
$(this).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||
});
|
||||
//如果前一个节点有延伸线
|
||||
if(packCont.children('.'+ELEM_SET).last().prev().hasClass(ELEM_LINE_SHORT)){
|
||||
packCont.children('.'+ELEM_SET).last().prev().removeClass(ELEM_LINE_SHORT);
|
||||
}else{
|
||||
//若之前的没有,说明处于连接状态
|
||||
packCont.children('.'+ELEM_SET).last().removeClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
//若是最外层,要始终保持相连的状态
|
||||
if(!elem.parent('.'+ELEM_PACK)[0] && elem.next()[0]){
|
||||
packCont.children('.'+ELEM_SET).last().removeClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
};
|
||||
};
|
||||
if(!options.showCheckbox) return;
|
||||
//若开启复选框,同步新增节点状态
|
||||
if(elemMain.find('input[same="layuiTreeCheck"]')[0].checked){
|
||||
var packLast = elem.children('.'+ELEM_PACK).children('.'+ELEM_SET).last();
|
||||
packLast.find('input[same="layuiTreeCheck"]')[0].checked = true;
|
||||
};
|
||||
that.renderForm('checkbox');
|
||||
|
||||
//修改
|
||||
}else if(type == 'update'){
|
||||
var text = elemMain.children('.'+ ELEM_TEXT).html();
|
||||
elemMain.children('.'+ ELEM_TEXT).html('');
|
||||
//添加输入框,覆盖在文字上方
|
||||
elemMain.append('<input type="text" class="layui-tree-editInput">');
|
||||
//获取焦点
|
||||
elemMain.children('.layui-tree-editInput').val(text).focus();
|
||||
//嵌入文字移除输入框
|
||||
var getVal = function(input){
|
||||
var textNew = input.val().trim();
|
||||
textNew = textNew ? textNew : options.text.defaultNodeName;
|
||||
input.remove();
|
||||
elemMain.children('.'+ ELEM_TEXT).html(textNew);
|
||||
|
||||
//同步数据
|
||||
returnObj.data.title = textNew;
|
||||
|
||||
//节点修改的回调
|
||||
options.operate && options.operate(returnObj);
|
||||
};
|
||||
//失去焦点
|
||||
elemMain.children('.layui-tree-editInput').blur(function(){
|
||||
getVal($(this));
|
||||
});
|
||||
//回车
|
||||
elemMain.children('.layui-tree-editInput').on('keydown', function(e){
|
||||
if(e.keyCode === 13){
|
||||
e.preventDefault();
|
||||
getVal($(this));
|
||||
};
|
||||
});
|
||||
|
||||
//删除
|
||||
} else {
|
||||
layer.confirm('确认删除该节点 "<span style="color: #999;">'+ (item.title || '') +'</span>" 吗?', function(index){
|
||||
options.operate && options.operate(returnObj); //节点删除的回调
|
||||
returnObj.status = 'remove'; //标注节点删除
|
||||
|
||||
layer.close(index);
|
||||
|
||||
//若删除最后一个,显示空数据提示
|
||||
if(!elem.prev('.'+ELEM_SET)[0] && !elem.next('.'+ELEM_SET)[0] && !elem.parent('.'+ELEM_PACK)[0]){
|
||||
elem.remove();
|
||||
that.elem.append(that.elemNone);
|
||||
return;
|
||||
};
|
||||
//若有兄弟节点
|
||||
if(elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY)[0]){
|
||||
//若开启复选框
|
||||
if(options.showCheckbox){
|
||||
//若开启复选框,进行下步操作
|
||||
var elemDel = function(elem){
|
||||
//若无父结点,则不执行
|
||||
if(!elem.parents('.'+ELEM_SET)[0]) return;
|
||||
var siblingTree = elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY)
|
||||
,parentTree = elem.parent('.'+ELEM_PACK).prev()
|
||||
,checkState = parentTree.find('input[same="layuiTreeCheck"]')[0]
|
||||
,state = 1, num = 0;
|
||||
//若父节点未勾选
|
||||
if(checkState.checked == false){
|
||||
//遍历兄弟节点
|
||||
siblingTree.each(function(i, item1){
|
||||
var input = $(item1).find('input[same="layuiTreeCheck"]')[0]
|
||||
if(input.checked == false && !input.disabled){
|
||||
state = 0;
|
||||
};
|
||||
//判断是否全为不可勾选框
|
||||
if(!input.disabled){
|
||||
num = 1;
|
||||
};
|
||||
});
|
||||
//若有可勾选选择框并且已勾选
|
||||
if(state == 1 && num == 1){
|
||||
//勾选父节点
|
||||
checkState.checked = true;
|
||||
that.renderForm('checkbox');
|
||||
//向上遍历祖先节点
|
||||
elemDel(parentTree.parent('.'+ELEM_SET));
|
||||
};
|
||||
};
|
||||
};
|
||||
elemDel(elem);
|
||||
};
|
||||
//若开启连接线
|
||||
if(options.showLine){
|
||||
//遍历兄弟节点,判断兄弟节点是否有子节点
|
||||
var siblings = elem.siblings('.'+ELEM_SET), num = 1
|
||||
,parentPack = elem.parent('.'+ELEM_PACK);
|
||||
layui.each(siblings, function(index, i){
|
||||
if(!$(i).children('.'+ELEM_PACK)[0]){
|
||||
num = 0;
|
||||
};
|
||||
});
|
||||
//若兄弟节点都有子节点
|
||||
if(num == 1){
|
||||
//若节点本身无子节点
|
||||
if(!packCont[0]){
|
||||
//父级去除延伸线,因为此时子节点里没有空节点
|
||||
parentPack.removeClass(ELEM_EXTEND);
|
||||
siblings.children('.'+ELEM_PACK).addClass(ELEM_SHOW);
|
||||
siblings.children('.'+ELEM_PACK).children('.'+ELEM_SET).removeClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
//若为最后一个节点
|
||||
if(!elem.next()[0]){
|
||||
elem.prev().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||
}else{
|
||||
parentPack.children('.'+ELEM_SET).last().children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
//若为最外层最后一个节点,去除前一个结点的连接线
|
||||
if(!elem.next()[0] && !elem.parents('.'+ELEM_SET)[1] && !elem.parents('.'+ELEM_SET).eq(0).next()[0]){
|
||||
elem.prev('.'+ELEM_SET).addClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
}else{
|
||||
//若为最后一个节点且有延伸线
|
||||
if(!elem.next()[0] && elem.hasClass(ELEM_LINE_SHORT)){
|
||||
elem.prev().addClass(ELEM_LINE_SHORT);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
}else{
|
||||
//若无兄弟节点
|
||||
var prevDiv = elem.parent('.'+ELEM_PACK).prev();
|
||||
//若开启了连接线
|
||||
if(options.showLine){
|
||||
prevDiv.find('.'+ICON_CLICK).removeClass('layui-tree-icon');
|
||||
prevDiv.find('.'+ICON_CLICK).children('.layui-icon').removeClass(ICON_SUB).addClass('layui-icon-file');
|
||||
//父节点所在层添加延伸线
|
||||
var pare = prevDiv.parents('.'+ELEM_PACK).eq(0);
|
||||
pare.addClass(ELEM_EXTEND);
|
||||
|
||||
//兄弟节点最后子节点添加延伸线
|
||||
pare.children('.'+ELEM_SET).each(function(){
|
||||
$(this).children('.'+ELEM_PACK).children('.'+ELEM_SET).last().addClass(ELEM_LINE_SHORT);
|
||||
});
|
||||
}else{
|
||||
//父节点隐藏箭头
|
||||
prevDiv.find('.layui-tree-iconArrow').addClass(HIDE);
|
||||
};
|
||||
//移除展开属性
|
||||
elem.parents('.'+ELEM_SET).eq(0).removeClass(ELEM_SPREAD);
|
||||
//移除节点容器
|
||||
elem.parent('.'+ELEM_PACK).remove();
|
||||
};
|
||||
|
||||
elem.remove();
|
||||
});
|
||||
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
//部分事件
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,checkWarp = that.elem.find('.layui-tree-checkedFirst');
|
||||
|
||||
//初始选中
|
||||
that.setChecked(that.checkids);
|
||||
|
||||
//搜索
|
||||
that.elem.find('.layui-tree-search').on('keyup', function(){
|
||||
var input = $(this)
|
||||
,val = input.val()
|
||||
,pack = input.nextAll()
|
||||
,arr = [];
|
||||
|
||||
//遍历所有的值
|
||||
pack.find('.'+ ELEM_TEXT).each(function(){
|
||||
var entry = $(this).parents('.'+ELEM_ENTRY);
|
||||
//若值匹配,加一个类以作标识
|
||||
if($(this).html().indexOf(val) != -1){
|
||||
arr.push($(this).parent());
|
||||
|
||||
var select = function(div){
|
||||
div.addClass('layui-tree-searchShow');
|
||||
//向上父节点渲染
|
||||
if(div.parent('.'+ELEM_PACK)[0]){
|
||||
select(div.parent('.'+ELEM_PACK).parent('.'+ELEM_SET));
|
||||
};
|
||||
};
|
||||
select(entry.parent('.'+ELEM_SET));
|
||||
};
|
||||
});
|
||||
|
||||
//根据标志剔除
|
||||
pack.find('.'+ELEM_ENTRY).each(function(){
|
||||
var parent = $(this).parent('.'+ELEM_SET);
|
||||
if(!parent.hasClass('layui-tree-searchShow')){
|
||||
parent.addClass(HIDE);
|
||||
};
|
||||
});
|
||||
if(pack.find('.layui-tree-searchShow').length == 0){
|
||||
that.elem.append(that.elemNone);
|
||||
};
|
||||
|
||||
//节点过滤的回调
|
||||
options.onsearch && options.onsearch({
|
||||
elem: arr
|
||||
});
|
||||
});
|
||||
|
||||
//还原搜索初始状态
|
||||
that.elem.find('.layui-tree-search').on('keydown', function(){
|
||||
$(this).nextAll().find('.'+ELEM_ENTRY).each(function(){
|
||||
var parent = $(this).parent('.'+ELEM_SET);
|
||||
parent.removeClass('layui-tree-searchShow '+ HIDE);
|
||||
});
|
||||
if($('.layui-tree-emptyText')[0]) $('.layui-tree-emptyText').remove();
|
||||
});
|
||||
};
|
||||
|
||||
//得到选中节点
|
||||
Class.prototype.getChecked = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,checkId = []
|
||||
,checkData = [];
|
||||
|
||||
//遍历节点找到选中索引
|
||||
that.elem.find('.layui-form-checked').each(function(){
|
||||
checkId.push($(this).prev()[0].value);
|
||||
});
|
||||
|
||||
//遍历节点
|
||||
var eachNodes = function(data, checkNode){
|
||||
layui.each(data, function(index, item){
|
||||
layui.each(checkId, function(index2, item2){
|
||||
if(item.id == item2){
|
||||
var cloneItem = $.extend({}, item);
|
||||
delete cloneItem.children;
|
||||
|
||||
checkNode.push(cloneItem);
|
||||
|
||||
if(item.children){
|
||||
cloneItem.children = [];
|
||||
eachNodes(item.children, cloneItem.children);
|
||||
}
|
||||
return true
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
eachNodes($.extend({}, options.data), checkData);
|
||||
|
||||
return checkData;
|
||||
};
|
||||
|
||||
//设置选中节点
|
||||
Class.prototype.setChecked = function(checkedId){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
//初始选中
|
||||
that.elem.find('.'+ELEM_SET).each(function(i, item){
|
||||
var thisId = $(this).data('id')
|
||||
,input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]')
|
||||
,reInput = input.next();
|
||||
|
||||
//若返回数字
|
||||
if(typeof checkedId === 'number'){
|
||||
if(thisId == checkedId){
|
||||
if(!input[0].checked){
|
||||
reInput.click();
|
||||
};
|
||||
return false;
|
||||
};
|
||||
}
|
||||
//若返回数组
|
||||
else if(typeof checkedId === 'object'){
|
||||
layui.each(checkedId, function(index, value){
|
||||
if(value == thisId && !input[0].checked){
|
||||
reInput.click();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
//记录所有实例
|
||||
thisModule.that = {}; //记录所有实例对象
|
||||
thisModule.config = {}; //记录所有实例配置项
|
||||
|
||||
//重载实例
|
||||
tree.reload = function(id, options){
|
||||
var that = thisModule.that[id];
|
||||
that.reload(options);
|
||||
|
||||
return thisModule.call(that);
|
||||
};
|
||||
|
||||
//获得选中的节点数据
|
||||
tree.getChecked = function(id){
|
||||
var that = thisModule.that[id];
|
||||
return that.getChecked();
|
||||
};
|
||||
|
||||
//设置选中节点
|
||||
tree.setChecked = function(id, checkedId){
|
||||
var that = thisModule.that[id];
|
||||
return that.setChecked(checkedId);
|
||||
};
|
||||
|
||||
//核心入口
|
||||
tree.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisModule.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, tree);
|
||||
})
|
||||
@@ -1,565 +0,0 @@
|
||||
|
||||
/*!
|
||||
* upload 文件上传组件
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
layui.define('layer' , function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,layer = layui.layer
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
|
||||
//外部接口
|
||||
,upload = {
|
||||
config: {} //全局配置项
|
||||
|
||||
//设置全局项
|
||||
,set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
|
||||
//事件
|
||||
,on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
|
||||
//操作当前实例
|
||||
,thisUpload = function(){
|
||||
var that = this;
|
||||
return {
|
||||
upload: function(files){
|
||||
that.upload.call(that, files);
|
||||
}
|
||||
,reload: function(options){
|
||||
that.reload.call(that, options);
|
||||
}
|
||||
,config: that.config
|
||||
}
|
||||
}
|
||||
|
||||
//字符常量
|
||||
,MOD_NAME = 'upload', ELEM = 'layui-upload', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled'
|
||||
|
||||
,ELEM_FILE = 'layui-upload-file', ELEM_FORM = 'layui-upload-form', ELEM_IFRAME = 'layui-upload-iframe', ELEM_CHOOSE = 'layui-upload-choose', ELEM_DRAG = 'layui-upload-drag'
|
||||
|
||||
|
||||
//构造器
|
||||
,Class = function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, upload.config, options);
|
||||
that.render();
|
||||
};
|
||||
|
||||
//默认配置
|
||||
Class.prototype.config = {
|
||||
accept: 'images' //允许上传的文件类型:images/file/video/audio
|
||||
,exts: '' //允许上传的文件后缀名
|
||||
,auto: true //是否选完文件后自动上传
|
||||
,bindAction: '' //手动上传触发的元素
|
||||
,url: '' //上传地址
|
||||
,field: 'file' //文件字段名
|
||||
,acceptMime: '' //筛选出的文件类型,默认为所有文件
|
||||
,method: 'post' //请求上传的 http 类型
|
||||
,data: {} //请求上传的额外参数
|
||||
,drag: true //是否允许拖拽上传
|
||||
,size: 0 //文件限制大小,默认不限制
|
||||
,number: 0 //允许同时上传的文件数,默认不限制
|
||||
,multiple: false //是否允许多文件上传,不支持ie8-9
|
||||
};
|
||||
|
||||
//初始渲染
|
||||
Class.prototype.render = function(options){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
|
||||
options.elem = $(options.elem);
|
||||
options.bindAction = $(options.bindAction);
|
||||
|
||||
that.file();
|
||||
that.events();
|
||||
};
|
||||
|
||||
//追加文件域
|
||||
Class.prototype.file = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemFile = that.elemFile = $([
|
||||
'<input class="'+ ELEM_FILE +'" type="file" accept="'+ options.acceptMime +'" name="'+ options.field +'"'
|
||||
,(options.multiple ? ' multiple' : '')
|
||||
,'>'
|
||||
].join(''))
|
||||
,next = options.elem.next();
|
||||
|
||||
if(next.hasClass(ELEM_FILE) || next.hasClass(ELEM_FORM)){
|
||||
next.remove();
|
||||
}
|
||||
|
||||
//包裹ie8/9容器
|
||||
if(device.ie && device.ie < 10){
|
||||
options.elem.wrap('<div class="layui-upload-wrap"></div>');
|
||||
}
|
||||
|
||||
that.isFile() ? (
|
||||
that.elemFile = options.elem
|
||||
,options.field = options.elem[0].name
|
||||
) : options.elem.after(elemFile);
|
||||
|
||||
//初始化ie8/9的Form域
|
||||
if(device.ie && device.ie < 10){
|
||||
that.initIE();
|
||||
}
|
||||
};
|
||||
|
||||
//ie8-9初始化
|
||||
Class.prototype.initIE = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,iframe = $('<iframe id="'+ ELEM_IFRAME +'" class="'+ ELEM_IFRAME +'" name="'+ ELEM_IFRAME +'" frameborder="0"></iframe>')
|
||||
,elemForm = $(['<form target="'+ ELEM_IFRAME +'" class="'+ ELEM_FORM +'" method="post" key="set-mine" enctype="multipart/form-data" action="'+ options.url +'">'
|
||||
,'</form>'].join(''));
|
||||
|
||||
//插入iframe
|
||||
$('#'+ ELEM_IFRAME)[0] || $('body').append(iframe);
|
||||
|
||||
//包裹文件域
|
||||
if(!options.elem.next().hasClass(ELEM_FORM)){
|
||||
that.elemFile.wrap(elemForm);
|
||||
|
||||
//追加额外的参数
|
||||
options.elem.next('.'+ ELEM_FORM).append(function(){
|
||||
var arr = [];
|
||||
layui.each(options.data, function(key, value){
|
||||
value = typeof value === 'function' ? value() : value;
|
||||
arr.push('<input type="hidden" name="'+ key +'" value="'+ value +'">')
|
||||
});
|
||||
return arr.join('');
|
||||
}());
|
||||
}
|
||||
};
|
||||
|
||||
//异常提示
|
||||
Class.prototype.msg = function(content){
|
||||
return layer.msg(content, {
|
||||
icon: 2
|
||||
,shift: 6
|
||||
});
|
||||
};
|
||||
|
||||
//判断绑定元素是否为文件域本身
|
||||
Class.prototype.isFile = function(){
|
||||
var elem = this.config.elem[0];
|
||||
if(!elem) return;
|
||||
return elem.tagName.toLocaleLowerCase() === 'input' && elem.type === 'file'
|
||||
}
|
||||
|
||||
//预读图片信息
|
||||
Class.prototype.preview = function(callback){
|
||||
var that = this;
|
||||
if(window.FileReader){
|
||||
layui.each(that.chooseFiles, function(index, file){
|
||||
var reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = function(){
|
||||
callback && callback(index, file, this.result);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//执行上传
|
||||
Class.prototype.upload = function(files, type){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemFile = that.elemFile[0]
|
||||
|
||||
//高级浏览器处理方式,支持跨域
|
||||
,ajaxSend = function(){
|
||||
var successful = 0, aborted = 0
|
||||
,items = files || that.files || that.chooseFiles || elemFile.files
|
||||
,allDone = function(){ //多文件全部上传完毕的回调
|
||||
if(options.multiple && successful + aborted === that.fileLength){
|
||||
typeof options.allDone === 'function' && options.allDone({
|
||||
total: that.fileLength
|
||||
,successful: successful
|
||||
,aborted: aborted
|
||||
});
|
||||
}
|
||||
};
|
||||
layui.each(items, function(index, file){
|
||||
var formData = new FormData();
|
||||
|
||||
formData.append(options.field, file);
|
||||
|
||||
//追加额外的参数
|
||||
layui.each(options.data, function(key, value){
|
||||
value = typeof value === 'function' ? value() : value;
|
||||
formData.append(key, value);
|
||||
});
|
||||
|
||||
//提交文件
|
||||
var opts = {
|
||||
url: options.url
|
||||
,type: 'post' //统一采用 post 上传
|
||||
,data: formData
|
||||
,contentType: false
|
||||
,processData: false
|
||||
,dataType: 'json'
|
||||
,headers: options.headers || {}
|
||||
//成功回调
|
||||
,success: function(res){
|
||||
successful++;
|
||||
done(index, res);
|
||||
allDone();
|
||||
}
|
||||
//异常回调
|
||||
,error: function(){
|
||||
aborted++;
|
||||
that.msg('请求上传接口出现异常');
|
||||
error(index);
|
||||
allDone();
|
||||
}
|
||||
};
|
||||
//进度条
|
||||
if(typeof options.progress === 'function'){
|
||||
opts.xhr = function(){
|
||||
var xhr = $.ajaxSettings.xhr();
|
||||
//上传进度
|
||||
xhr.upload.addEventListener("progress", function (obj) {
|
||||
if(obj.lengthComputable){
|
||||
var percent = Math.floor((obj.loaded/obj.total)* 100); //百分比
|
||||
options.progress(percent, (options.item ? options.item[0] : options.elem[0]) , obj, index);
|
||||
}
|
||||
});
|
||||
return xhr;
|
||||
}
|
||||
}
|
||||
$.ajax(opts);
|
||||
});
|
||||
}
|
||||
|
||||
//低版本IE处理方式,不支持跨域
|
||||
,iframeSend = function(){
|
||||
var iframe = $('#'+ ELEM_IFRAME);
|
||||
|
||||
that.elemFile.parent().submit();
|
||||
|
||||
//获取响应信息
|
||||
clearInterval(Class.timer);
|
||||
Class.timer = setInterval(function() {
|
||||
var res, iframeBody = iframe.contents().find('body');
|
||||
try {
|
||||
res = iframeBody.text();
|
||||
} catch(e) {
|
||||
that.msg('获取上传后的响应信息出现异常');
|
||||
clearInterval(Class.timer);
|
||||
error();
|
||||
}
|
||||
if(res){
|
||||
clearInterval(Class.timer);
|
||||
iframeBody.html('');
|
||||
done(0, res);
|
||||
}
|
||||
}, 30);
|
||||
}
|
||||
|
||||
//统一回调
|
||||
,done = function(index, res){
|
||||
that.elemFile.next('.'+ ELEM_CHOOSE).remove();
|
||||
elemFile.value = '';
|
||||
if(typeof res !== 'object'){
|
||||
try {
|
||||
res = JSON.parse(res);
|
||||
} catch(e){
|
||||
res = {};
|
||||
return that.msg('请对上传接口返回有效JSON');
|
||||
}
|
||||
}
|
||||
typeof options.done === 'function' && options.done(res, index || 0, function(files){
|
||||
that.upload(files);
|
||||
});
|
||||
}
|
||||
|
||||
//统一网络异常回调
|
||||
,error = function(index){
|
||||
if(options.auto){
|
||||
elemFile.value = '';
|
||||
}
|
||||
typeof options.error === 'function' && options.error(index || 0, function(files){
|
||||
that.upload(files);
|
||||
});
|
||||
}
|
||||
|
||||
,exts = options.exts
|
||||
,check ,value = function(){
|
||||
var arr = [];
|
||||
layui.each(files || that.chooseFiles, function(i, item){
|
||||
arr.push(item.name);
|
||||
});
|
||||
return arr;
|
||||
}()
|
||||
|
||||
//回调返回的参数
|
||||
,args = {
|
||||
//预览
|
||||
preview: function(callback){
|
||||
that.preview(callback);
|
||||
}
|
||||
//上传
|
||||
,upload: function(index, file){
|
||||
var thisFile = {};
|
||||
thisFile[index] = file;
|
||||
that.upload(thisFile);
|
||||
}
|
||||
//追加文件到队列
|
||||
,pushFile: function(){
|
||||
that.files = that.files || {};
|
||||
layui.each(that.chooseFiles, function(index, item){
|
||||
that.files[index] = item;
|
||||
});
|
||||
return that.files;
|
||||
}
|
||||
//重置文件
|
||||
,resetFile: function(index, file, filename){
|
||||
var newFile = new File([file], filename);
|
||||
that.files = that.files || {};
|
||||
that.files[index] = newFile;
|
||||
}
|
||||
}
|
||||
|
||||
//提交上传
|
||||
,send = function(){
|
||||
//选择文件的回调
|
||||
if(type === 'choose' || options.auto){
|
||||
options.choose && options.choose(args);
|
||||
if(type === 'choose'){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//上传前的回调 - 如果回调函数明确返回false,则停止上传(#pulls55)
|
||||
if(options.before && (options.before(args) === false)) return;
|
||||
|
||||
//IE兼容处理
|
||||
if(device.ie){
|
||||
return device.ie > 9 ? ajaxSend() : iframeSend();
|
||||
}
|
||||
|
||||
ajaxSend();
|
||||
}
|
||||
|
||||
//校验文件格式
|
||||
value = value.length === 0
|
||||
? ((elemFile.value.match(/[^\/\\]+\..+/g)||[]) || '')
|
||||
: value;
|
||||
|
||||
if(value.length === 0) return;
|
||||
|
||||
switch(options.accept){
|
||||
case 'file': //一般文件
|
||||
if(exts && !RegExp('\\w\\.('+ exts +')$', 'i').test(escape(value))){
|
||||
that.msg('选择的文件中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
case 'video': //视频文件
|
||||
if(!RegExp('\\w\\.('+ (exts || 'avi|mp4|wma|rmvb|rm|flash|3gp|flv') +')$', 'i').test(escape(value))){
|
||||
that.msg('选择的视频中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
case 'audio': //音频文件
|
||||
if(!RegExp('\\w\\.('+ (exts || 'mp3|wav|mid') +')$', 'i').test(escape(value))){
|
||||
that.msg('选择的音频中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
default: //图片文件
|
||||
layui.each(value, function(i, item){
|
||||
if(!RegExp('\\w\\.('+ (exts || 'jpg|png|gif|bmp|jpeg$') +')', 'i').test(escape(item))){
|
||||
check = true;
|
||||
}
|
||||
});
|
||||
if(check){
|
||||
that.msg('选择的图片中包含不支持的格式');
|
||||
return elemFile.value = '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//检验文件数量
|
||||
that.fileLength = function(){
|
||||
var length = 0
|
||||
,items = files || that.files || that.chooseFiles || elemFile.files;
|
||||
layui.each(items, function(){
|
||||
length++;
|
||||
});
|
||||
return length;
|
||||
}();
|
||||
if(options.number && that.fileLength > options.number){
|
||||
return that.msg('同时最多只能上传的数量为:'+ options.number);
|
||||
}
|
||||
|
||||
//检验文件大小
|
||||
if(options.size > 0 && !(device.ie && device.ie < 10)){
|
||||
var limitSize;
|
||||
|
||||
layui.each(that.chooseFiles, function(index, file){
|
||||
if(file.size > 1024*options.size){
|
||||
var size = options.size/1024;
|
||||
size = size >= 1 ? (size.toFixed(2) + 'MB') : options.size + 'KB'
|
||||
elemFile.value = '';
|
||||
limitSize = size;
|
||||
}
|
||||
});
|
||||
if(limitSize) return that.msg('文件不能超过'+ limitSize);
|
||||
}
|
||||
send();
|
||||
};
|
||||
|
||||
//重置方法
|
||||
Class.prototype.reload = function(options){
|
||||
options = options || {};
|
||||
delete options.elem;
|
||||
delete options.bindAction;
|
||||
|
||||
var that = this
|
||||
,options = that.config = $.extend({}, that.config, upload.config, options)
|
||||
,next = options.elem.next();
|
||||
|
||||
//更新文件域相关属性
|
||||
next.attr({
|
||||
name: options.name
|
||||
,accept: options.acceptMime
|
||||
,multiple: options.multiple
|
||||
});
|
||||
};
|
||||
|
||||
//事件处理
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
|
||||
//设置当前选择的文件队列
|
||||
,setChooseFile = function(files){
|
||||
that.chooseFiles = {};
|
||||
layui.each(files, function(i, item){
|
||||
var time = new Date().getTime();
|
||||
that.chooseFiles[time + '-' + i] = item;
|
||||
});
|
||||
}
|
||||
|
||||
//设置选择的文本
|
||||
,setChooseText = function(files, filename){
|
||||
var elemFile = that.elemFile
|
||||
,item = options.item ? options.item : options.elem
|
||||
,value = files.length > 1
|
||||
? files.length + '个文件'
|
||||
: ((files[0] || {}).name || (elemFile[0].value.match(/[^\/\\]+\..+/g)||[]) || '');
|
||||
|
||||
if(elemFile.next().hasClass(ELEM_CHOOSE)){
|
||||
elemFile.next().remove();
|
||||
}
|
||||
that.upload(null, 'choose');
|
||||
if(that.isFile() || options.choose) return;
|
||||
elemFile.after('<span class="layui-inline '+ ELEM_CHOOSE +'">'+ value +'</span>');
|
||||
};
|
||||
|
||||
//点击上传容器
|
||||
options.elem.off('upload.start').on('upload.start', function(){
|
||||
var othis = $(this), data = othis.attr('lay-data');
|
||||
|
||||
if(data){
|
||||
try{
|
||||
data = new Function('return '+ data)();
|
||||
that.config = $.extend({}, options, data);
|
||||
} catch(e){
|
||||
hint.error('Upload element property lay-data configuration item has a syntax error: ' + data)
|
||||
}
|
||||
}
|
||||
|
||||
that.config.item = othis;
|
||||
that.elemFile[0].click();
|
||||
});
|
||||
|
||||
//拖拽上传
|
||||
if(!(device.ie && device.ie < 10)){
|
||||
options.elem.off('upload.over').on('upload.over', function(){
|
||||
var othis = $(this)
|
||||
othis.attr('lay-over', '');
|
||||
})
|
||||
.off('upload.leave').on('upload.leave', function(){
|
||||
var othis = $(this)
|
||||
othis.removeAttr('lay-over');
|
||||
})
|
||||
.off('upload.drop').on('upload.drop', function(e, param){
|
||||
var othis = $(this), files = param.originalEvent.dataTransfer.files || [];
|
||||
|
||||
othis.removeAttr('lay-over');
|
||||
setChooseFile(files);
|
||||
|
||||
if(options.auto){
|
||||
that.upload(files);
|
||||
} else {
|
||||
setChooseText(files);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//文件选择
|
||||
that.elemFile.off('upload.change').on('upload.change', function(){
|
||||
var files = this.files || [];
|
||||
setChooseFile(files);
|
||||
options.auto ? that.upload() : setChooseText(files); //是否自动触发上传
|
||||
});
|
||||
|
||||
//手动触发上传
|
||||
options.bindAction.off('upload.action').on('upload.action', function(){
|
||||
that.upload();
|
||||
});
|
||||
|
||||
//防止事件重复绑定
|
||||
if(options.elem.data('haveEvents')) return;
|
||||
|
||||
that.elemFile.on('change', function(){
|
||||
$(this).trigger('upload.change');
|
||||
});
|
||||
|
||||
options.elem.on('click', function(){
|
||||
if(that.isFile()) return;
|
||||
$(this).trigger('upload.start');
|
||||
});
|
||||
|
||||
if(options.drag){
|
||||
options.elem.on('dragover', function(e){
|
||||
e.preventDefault();
|
||||
$(this).trigger('upload.over');
|
||||
}).on('dragleave', function(e){
|
||||
$(this).trigger('upload.leave');
|
||||
}).on('drop', function(e){
|
||||
e.preventDefault();
|
||||
$(this).trigger('upload.drop', e);
|
||||
});
|
||||
}
|
||||
|
||||
options.bindAction.on('click', function(){
|
||||
$(this).trigger('upload.action');
|
||||
});
|
||||
|
||||
options.elem.data('haveEvents', true);
|
||||
};
|
||||
|
||||
//核心入口
|
||||
upload.render = function(options){
|
||||
var inst = new Class(options);
|
||||
return thisUpload.call(inst);
|
||||
};
|
||||
|
||||
exports(MOD_NAME, upload);
|
||||
});
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
|
||||
/*!
|
||||
* util 工具组件
|
||||
*/
|
||||
|
||||
layui.define('jquery', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,hint = layui.hint()
|
||||
|
||||
//外部接口
|
||||
,util = {
|
||||
//固定块
|
||||
fixbar: function(options){
|
||||
var ELEM = 'layui-fixbar', TOP_BAR = 'layui-fixbar-top'
|
||||
,dom = $(document), body = $('body')
|
||||
,is, timer;
|
||||
|
||||
options = $.extend({
|
||||
showHeight: 200 //出现TOP的滚动条高度临界值
|
||||
}, options);
|
||||
|
||||
options.bar1 = options.bar1 === true ? '' : options.bar1;
|
||||
options.bar2 = options.bar2 === true ? '' : options.bar2;
|
||||
options.bgcolor = options.bgcolor ? ('background-color:' + options.bgcolor) : '';
|
||||
|
||||
var icon = [options.bar1, options.bar2, ''] //图标:信息、问号、TOP
|
||||
,elem = $(['<ul class="'+ ELEM +'">'
|
||||
,options.bar1 ? '<li class="layui-icon" lay-type="bar1" style="'+ options.bgcolor +'">'+ icon[0] +'</li>' : ''
|
||||
,options.bar2 ? '<li class="layui-icon" lay-type="bar2" style="'+ options.bgcolor +'">'+ icon[1] +'</li>' : ''
|
||||
,'<li class="layui-icon '+ TOP_BAR +'" lay-type="top" style="'+ options.bgcolor +'">'+ icon[2] +'</li>'
|
||||
,'</ul>'].join(''))
|
||||
,topBar = elem.find('.'+TOP_BAR)
|
||||
,scroll = function(){
|
||||
var stop = dom.scrollTop();
|
||||
if(stop >= (options.showHeight)){
|
||||
is || (topBar.show(), is = 1);
|
||||
} else {
|
||||
is && (topBar.hide(), is = 0);
|
||||
}
|
||||
};
|
||||
if($('.'+ ELEM)[0]) return;
|
||||
|
||||
typeof options.css === 'object' && elem.css(options.css);
|
||||
body.append(elem), scroll();
|
||||
|
||||
//bar点击事件
|
||||
elem.find('li').on('click', function(){
|
||||
var othis = $(this), type = othis.attr('lay-type');
|
||||
if(type === 'top'){
|
||||
$('html,body').animate({
|
||||
scrollTop : 0
|
||||
}, 200);
|
||||
}
|
||||
options.click && options.click.call(this, type);
|
||||
});
|
||||
|
||||
//Top显示控制
|
||||
dom.on('scroll', function(){
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function(){
|
||||
scroll();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
//倒计时
|
||||
,countdown: function(endTime, serverTime, callback){
|
||||
var that = this
|
||||
,type = typeof serverTime === 'function'
|
||||
,end = new Date(endTime).getTime()
|
||||
,now = new Date((!serverTime || type) ? new Date().getTime() : serverTime).getTime()
|
||||
,count = end - now
|
||||
,time = [
|
||||
Math.floor(count/(1000*60*60*24)) //天
|
||||
,Math.floor(count/(1000*60*60)) % 24 //时
|
||||
,Math.floor(count/(1000*60)) % 60 //分
|
||||
,Math.floor(count/1000) % 60 //秒
|
||||
];
|
||||
|
||||
if(type) callback = serverTime;
|
||||
|
||||
var timer = setTimeout(function(){
|
||||
that.countdown(endTime, now + 1000, callback);
|
||||
}, 1000);
|
||||
|
||||
callback && callback(count > 0 ? time : [0,0,0,0], serverTime, timer);
|
||||
|
||||
if(count <= 0) clearTimeout(timer);
|
||||
return timer;
|
||||
}
|
||||
|
||||
//某个时间在当前时间的多久前
|
||||
,timeAgo: function(time, onlyDate){
|
||||
var that = this
|
||||
,arr = [[], []]
|
||||
,stamp = new Date().getTime() - new Date(time).getTime();
|
||||
|
||||
//返回具体日期
|
||||
if(stamp > 1000*60*60*24*31){
|
||||
stamp = new Date(time);
|
||||
arr[0][0] = that.digit(stamp.getFullYear(), 4);
|
||||
arr[0][1] = that.digit(stamp.getMonth() + 1);
|
||||
arr[0][2] = that.digit(stamp.getDate());
|
||||
|
||||
//是否输出时间
|
||||
if(!onlyDate){
|
||||
arr[1][0] = that.digit(stamp.getHours());
|
||||
arr[1][1] = that.digit(stamp.getMinutes());
|
||||
arr[1][2] = that.digit(stamp.getSeconds());
|
||||
}
|
||||
return arr[0].join('-') + ' ' + arr[1].join(':');
|
||||
}
|
||||
|
||||
//30天以内,返回“多久前”
|
||||
if(stamp >= 1000*60*60*24){
|
||||
return ((stamp/1000/60/60/24)|0) + '天前';
|
||||
} else if(stamp >= 1000*60*60){
|
||||
return ((stamp/1000/60/60)|0) + '小时前';
|
||||
} else if(stamp >= 1000*60*3){ //3分钟以内为:刚刚
|
||||
return ((stamp/1000/60)|0) + '分钟前';
|
||||
} else if(stamp < 0){
|
||||
return '未来';
|
||||
} else {
|
||||
return '刚刚';
|
||||
}
|
||||
}
|
||||
|
||||
//数字前置补零
|
||||
,digit: function(num, length){
|
||||
var str = '';
|
||||
num = String(num);
|
||||
length = length || 2;
|
||||
for(var i = num.length; i < length; i++){
|
||||
str += '0';
|
||||
}
|
||||
return num < Math.pow(10, length) ? str + (num|0) : num;
|
||||
}
|
||||
|
||||
//转化为日期格式字符
|
||||
,toDateString: function(time, format){
|
||||
//若 null 或空字符,则返回空字符
|
||||
if(time === null || time === '') return '';
|
||||
|
||||
var that = this
|
||||
,date = new Date(function(){
|
||||
if(!time) return;
|
||||
return isNaN(time) ? time : (typeof time === 'string' ? parseInt(time) : time)
|
||||
}() || new Date())
|
||||
,ymd = [
|
||||
that.digit(date.getFullYear(), 4)
|
||||
,that.digit(date.getMonth() + 1)
|
||||
,that.digit(date.getDate())
|
||||
]
|
||||
,hms = [
|
||||
that.digit(date.getHours())
|
||||
,that.digit(date.getMinutes())
|
||||
,that.digit(date.getSeconds())
|
||||
];
|
||||
|
||||
if(!date.getDate()) return hint.error('Invalid Msec for "util.toDateString(Msec)"'), '';
|
||||
|
||||
format = format || 'yyyy-MM-dd HH:mm:ss';
|
||||
return format.replace(/yyyy/g, ymd[0])
|
||||
.replace(/MM/g, ymd[1])
|
||||
.replace(/dd/g, ymd[2])
|
||||
.replace(/HH/g, hms[0])
|
||||
.replace(/mm/g, hms[1])
|
||||
.replace(/ss/g, hms[2]);
|
||||
}
|
||||
|
||||
//转义 html,防 xss 攻击
|
||||
,escape: function(html){
|
||||
return String(html || '').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
|
||||
.replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/'/g, ''').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
//还原转义的 html
|
||||
,unescape: function(str){
|
||||
return String(str || '').replace(/\&/g, '&')
|
||||
.replace(/\</g, '<').replace(/\>/g, '>')
|
||||
.replace(/\'/, '\'').replace(/\"/, '"');
|
||||
}
|
||||
|
||||
//让指定的元素保持在可视区域
|
||||
,toVisibleArea: function(options){
|
||||
options = $.extend({
|
||||
margin: 160 //触发动作的边界值
|
||||
,duration: 200 //动画持续毫秒数
|
||||
,type: 'y' //触发方向,x 水平、y 垂直
|
||||
}, options);
|
||||
|
||||
if(!options.scrollElem[0] || !options.thisElem[0]) return;
|
||||
|
||||
var scrollElem = options.scrollElem //滚动元素
|
||||
,thisElem = options.thisElem //目标元素
|
||||
,vertical = options.type === 'y' //是否垂直方向
|
||||
,SCROLL_NAME = vertical ? 'scrollTop' : 'scrollLeft' //滚动方法
|
||||
,OFFSET_NAME = vertical ? 'top' : 'left' //坐标方式
|
||||
,scrollValue = scrollElem[SCROLL_NAME]() //当前滚动距离
|
||||
,size = scrollElem[vertical ? 'height' : 'width']() //滚动元素的尺寸
|
||||
,scrollOffet = scrollElem.offset()[OFFSET_NAME] //滚动元素所处位置
|
||||
,thisOffset = thisElem.offset()[OFFSET_NAME] - scrollOffet //目标元素当前的所在位置
|
||||
,obj = {};
|
||||
|
||||
//边界满足条件
|
||||
if(thisOffset > size - options.margin || thisOffset < options.margin){
|
||||
obj[SCROLL_NAME] = thisOffset - size/2 + scrollValue
|
||||
scrollElem.animate(obj, options.duration);
|
||||
}
|
||||
}
|
||||
|
||||
//批量事件
|
||||
,event: function(attr, obj, eventType){
|
||||
var _body = $('body');
|
||||
eventType = eventType || 'click';
|
||||
|
||||
//记录事件回调集合
|
||||
obj = util.event[attr] = $.extend(true, util.event[attr], obj) || {};
|
||||
|
||||
//清除委托事件
|
||||
util.event.UTIL_EVENT_CALLBACK = util.event.UTIL_EVENT_CALLBACK || {};
|
||||
_body.off(eventType, '*['+ attr +']', util.event.UTIL_EVENT_CALLBACK[attr])
|
||||
|
||||
//绑定委托事件
|
||||
util.event.UTIL_EVENT_CALLBACK[attr] = function(){
|
||||
var othis = $(this)
|
||||
,key = othis.attr(attr);
|
||||
(typeof obj[key] === 'function') && obj[key].call(this, othis);
|
||||
};
|
||||
|
||||
//清除旧事件,绑定新事件
|
||||
_body.on(eventType, '*['+ attr +']', util.event.UTIL_EVENT_CALLBACK[attr]);
|
||||
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
// DOM 尺寸变化,该创意来自:http://benalman.com/projects/jquery-resize-plugin/
|
||||
/*
|
||||
!function(a,b,c){"$:nomunge";function l(){f=b[g](function(){d.each(function(){var b=a(this),c=b.width(),d=b.height(),e=a.data(this,i);(c!==e.w||d!==e.h)&&b.trigger(h,[e.w=c,e.h=d])}),l()},e[j])}var f,d=a([]),e=a.resize=a.extend(a.resize,{}),g="setTimeout",h="resize",i=h+"-special-event",j="delay",k="throttleWindow";e[j]=250,e[k]=!0,a.event.special[h]={setup:function(){if(!e[k]&&this[g])return!1;var b=a(this);d=d.add(b),a.data(this,i,{w:b.width(),h:b.height()}),1===d.length&&l()},teardown:function(){if(!e[k]&&this[g])return!1;var b=a(this);d=d.not(b),b.removeData(i),d.length||clearTimeout(f)},add:function(b){function f(b,e,f){var g=a(this),h=a.data(this,i)||{};h.w=e!==c?e:g.width(),h.h=f!==c?f:g.height(),d.apply(this,arguments)}if(!e[k]&&this[g])return!1;var d;return a.isFunction(b)?(d=b,f):(d=b.handler,b.handler=f,void 0)}}}($,window);
|
||||
*/
|
||||
|
||||
//暴露接口
|
||||
exports('util', util);
|
||||
});
|
||||
1
static/Layui/v2.9.18/css/layui.css
Normal file
BIN
static/Layui/v2.9.18/font/iconfont.eot
Normal file
405
static/Layui/v2.9.18/font/iconfont.svg
Normal file
|
After Width: | Height: | Size: 322 KiB |
BIN
static/Layui/v2.9.18/font/iconfont.ttf
Normal file
BIN
static/Layui/v2.9.18/font/iconfont.woff
Normal file
BIN
static/Layui/v2.9.18/font/iconfont.woff2
Normal file
1
static/Layui/v2.9.18/layui.js
Normal file
167
system/ATool.php
@@ -27,6 +27,13 @@ if($config['switch'] === 1){
|
||||
exit;
|
||||
}
|
||||
|
||||
$layui_dir = "../static/Layui";
|
||||
foreach(scandir($layui_dir) as $value) {
|
||||
if(is_dir($layui_dir . '/' . $value) && preg_match('/^v\d+\.\d+\.\d+$/', $value) && is_file("{$layui_dir}/$value/layui.js")) {
|
||||
$layui['js'] = "../static/Layui/{$value}/layui.js";
|
||||
$layui['css'] = "../static/Layui/{$value}/css/layui.css";
|
||||
}
|
||||
}
|
||||
session_name('ATool_SSID');
|
||||
session_start();
|
||||
|
||||
@@ -84,7 +91,7 @@ if(!empty($_GET['type'])){
|
||||
$user_group['root'] = '站长';
|
||||
$user_group['default'] = '默认';
|
||||
foreach ($datas as $key => $data){
|
||||
$datas[$key]['UserGroupName'] = $user_group[$data['UserGroup']]??'Null';
|
||||
$datas[$key]['UserGroupName'] = $user_group[$data['UserGroup']]??$data['UserGroup'];
|
||||
}
|
||||
}
|
||||
msgA(['code'=>1,'msg'=>'获取成功','count'=>$count,'data'=>$datas]);
|
||||
@@ -97,6 +104,7 @@ if(!empty($_GET['type'])){
|
||||
msg(-1,'密码不能为空');
|
||||
}
|
||||
$RegTime = get_db('global_user','RegTime',['ID'=>$_POST['ID']]);
|
||||
delete_db( "user_login_info", ["uid"=>$_POST['ID']] );
|
||||
update_db('global_user',['Password'=>Get_MD5_Password($_POST['new_pwd'],$RegTime)],["ID" => $_POST['ID'] ],[1,'修改成功']);
|
||||
}elseif($_GET['type'] == 'set_root'){
|
||||
update_db('global_user',['UserGroup'=>'root'],["ID" => $_POST['ID'] ],[1,'修改成功']);
|
||||
@@ -108,6 +116,10 @@ if(!empty($_GET['type'])){
|
||||
}elseif($_GET['type'] == 'set_close_Maintenance'){
|
||||
$global_config['Maintenance'] = 0;
|
||||
update_db("global_config", ["v" => $global_config], ["k" => "o_config"],[1,'设置成功']);
|
||||
//开启调试模式
|
||||
}elseif($_GET['type'] == 'set_open_debug'){
|
||||
$global_config['Debug'] = 1;
|
||||
update_db("global_config", ["v" => $global_config], ["k" => "o_config"],[1,'设置成功']);
|
||||
//重置静态路径
|
||||
}elseif($_GET['type'] == 'Set_Libs'){
|
||||
$global_config['Libs'] = "./static";
|
||||
@@ -119,6 +131,10 @@ if(!empty($_GET['type'])){
|
||||
opcache_reset(); //清理PHP缓存
|
||||
}
|
||||
msgA(['code'=>1,'msg'=>'操作成功']);
|
||||
//清空统计
|
||||
}elseif($_GET['type'] == 'del_tongji'){
|
||||
delete_db('user_count',[]);
|
||||
msgA(['code'=>1,'msg'=>'操作成功']);
|
||||
//改账号
|
||||
}elseif($_GET['type'] == 'set_user_name'){
|
||||
//新用户名是否合规
|
||||
@@ -165,6 +181,22 @@ if(!empty($_GET['type'])){
|
||||
update_db("user_login_info", ["user" => $_POST['new_user_name']], ["user" => $USER['User']]);
|
||||
update_db("user_log", ["user" => $_POST['new_user_name']], ["user" => $USER['User']]);
|
||||
update_db("global_user", ["User" => $_POST['new_user_name']], ["ID" => $_POST['ID']],[1,'操作成功']);
|
||||
}elseif($_GET['type'] == 'del_otp'){
|
||||
$user_data = get_db('global_user','*',['ID'=>$_POST['ID']]);
|
||||
$LoginConfig = unserialize($user_data['LoginConfig']);
|
||||
if(empty($LoginConfig['totp_key'])){
|
||||
msgA(['code'=>-1,'msg'=>'当前账号未开启OTP双重验证']);
|
||||
}
|
||||
$LoginConfig['totp_key'] = '';
|
||||
update_db("global_user", ["LoginConfig" => $LoginConfig], ["ID" => $_POST['ID']],[1,'操作成功']);
|
||||
}elseif($_GET['type'] == 'get_pwd2'){
|
||||
$user_data = get_db('global_user','*',['ID'=>$_POST['ID']]);
|
||||
$LoginConfig = unserialize($user_data['LoginConfig']);
|
||||
if(empty($LoginConfig['Password2'])){
|
||||
msgA(['code'=>-1,'msg'=>'当前账号未设置二级密码']);
|
||||
}else{
|
||||
msgA(['code'=>1,'msg'=> "当前账号: {$user_data['User']}<br />二级密码: {$LoginConfig['Password2']}"]);
|
||||
}
|
||||
}
|
||||
|
||||
msgA(['code'=>-1,'msg'=>'请求类型错误']);
|
||||
@@ -192,9 +224,10 @@ function Load_db(){
|
||||
}catch (Exception $e) {
|
||||
Amsg(-1,'载入数据库失败'.$db_config['path']);
|
||||
}
|
||||
}elseif($db_config['type'] == 'mysql'){
|
||||
}elseif($db_config['type'] == 'mysql' || $db_config['type'] == 'mariadb'){
|
||||
try {
|
||||
$db = new Medoo\Medoo(['type' => 'mysql',
|
||||
$db = new Medoo\Medoo([
|
||||
'type' => $db_config['type'],
|
||||
'host' => $db_config['host'],
|
||||
'port' => $db_config['port'],
|
||||
'database' => $db_config['name'],
|
||||
@@ -218,7 +251,7 @@ function echo_Atool(){
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ATool 工具箱</title>
|
||||
<link rel="stylesheet" href="../static/Layui/v2.6.8/css/layui.css">
|
||||
<link rel="stylesheet" href="<?php echo $GLOBALS['layui']['css']; ?>">
|
||||
<style>
|
||||
html, body {min-width: 1200px;background-color: #fff;position: relative;}
|
||||
.page-wrapper {width: 1200px;margin: 0 auto;padding: 0 15px;}
|
||||
@@ -235,9 +268,11 @@ function echo_Atool(){
|
||||
<a class="layui-btn layui-btn-sm layui-btn-primary" href="../index.php?c=<?php echo $global_config['Register'];?>" target="_blank"><i class="layui-icon layui-icon-add-1"></i>打开注册页</a>
|
||||
<button type="set_allow_register" class="set layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-set-sm"></i>允许注册</button>
|
||||
<button type="set_close_Maintenance" class="set layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-set-sm"></i>关闭维护模式</button>
|
||||
<button type="set_open_debug" class="set layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-set-sm"></i>打开调试模式</button>
|
||||
<button type="Set_Libs" class="set layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-set-sm"></i>重置静态路径</button>
|
||||
<button type="Set_clear_cache" class="set layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-set-sm"></i>清除缓存</button>
|
||||
<a class="layui-btn layui-btn-sm layui-btn-primary" href="https://gitee.com/tznb/TwoNav/wikis/pages?sort_id=7993451&doc_id=3767990" target="_blank"><i class="layui-icon layui-icon-align-left"></i>帮助</a>
|
||||
<button type="del_tongji" class="del_tongji layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-set-sm"></i>清空统计</button>
|
||||
<a class="layui-btn layui-btn-sm layui-btn-primary" href="https://docs.twonav.cn/#/books/start-07" target="_blank"><i class="layui-icon layui-icon-align-left"></i>帮助</a>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="layui-inline layui-form" style="padding-bottom: 5px;">
|
||||
@@ -264,23 +299,22 @@ function echo_Atool(){
|
||||
<!-- 表格操作列 -->
|
||||
<script type="text/html" id="tablebar">
|
||||
<div class="layui-btn-group">
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="set_pwd">改密码</a>
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="set_root">设站长</a>
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="set_user_name">改账号</a>
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="more">操作 <i class="layui-icon layui-icon-down"></i></a>
|
||||
</div>
|
||||
</script>
|
||||
<script src="../static/Layui/v2.6.8/layui.js"></script>
|
||||
<script src="<?php echo $GLOBALS['layui']['js']; ?>"></script>
|
||||
<script src="../static/jquery/jquery-3.6.0.min.js"></script>
|
||||
<script src="../static/jquery/jquery.md5.js"></script>
|
||||
<script src="../templates/admin/js/public.js?v=<?php echo time();?>"></script>
|
||||
<script>
|
||||
layui.use(['layer','table'], function () {
|
||||
layui.use(function () {
|
||||
var $ = layui.jquery;
|
||||
var layer = layui.layer;
|
||||
var table = layui.table;
|
||||
var dropdown = layui.dropdown;
|
||||
var cols = [[
|
||||
{field:'ID',title:'ID',width:60,sort:true}
|
||||
,{title:'操作',toolbar:'#tablebar',width:175}
|
||||
,{title:'操作',toolbar:'#tablebar',width:90}
|
||||
,{field:'User',title:'账号',minWidth:120,templet:function(d){
|
||||
return '<a style="color:#3c78d8" title="打开用户主页" target="_blank" href="../?u='+d.User+'">'+d.User+'</a>'
|
||||
}}
|
||||
@@ -292,6 +326,7 @@ function echo_Atool(){
|
||||
,{field:'RegTime',title: '注册时间',minWidth:100,templet:function(d){
|
||||
return d.RegTime == null ? '' : timestampToTime(d.RegTime,true);
|
||||
}}
|
||||
|
||||
]]
|
||||
//用户表渲染
|
||||
table.render({
|
||||
@@ -327,39 +362,67 @@ function echo_Atool(){
|
||||
table.on('tool(table)', function (obj) {
|
||||
console.log(obj.data);
|
||||
var data = obj.data;
|
||||
if (obj.event == 'set_pwd') {
|
||||
layer.prompt({formType: 3,value: '',title: '请输入新密码'}, function(value, index, elem){
|
||||
$.post('./ATool.php?type=set_pwd',{ID:data.ID,new_pwd:$.md5(value)},function(data,status){
|
||||
if(data.code == 1) {
|
||||
layer.close(index);
|
||||
layer.msg(data.msg, {icon: 1});
|
||||
}else{
|
||||
layer.msg(data.msg, {icon: 5});
|
||||
if(obj.event == 'more'){
|
||||
dropdown.render({
|
||||
elem: this,
|
||||
show: true,
|
||||
data: [{
|
||||
title: '修改密码',
|
||||
id: 'set_pwd'
|
||||
},{
|
||||
title: '设为站长',
|
||||
id: 'set_root'
|
||||
},{
|
||||
title: '修改账号',
|
||||
id: 'set_user_name'
|
||||
},{
|
||||
title: '取消双重验证',
|
||||
id: 'del_otp'
|
||||
},{
|
||||
title: '查看二级密码',
|
||||
id: 'get_pwd2'
|
||||
}
|
||||
],
|
||||
click: function(menu, othis){
|
||||
if(menu.id == 'set_pwd'){
|
||||
layer.prompt({formType: 3,value: '',title: '请输入新密码'}, function(value, index, elem){
|
||||
$.post('./ATool.php?type=set_pwd',{ID:data.ID,new_pwd:$.md5(value)},function(data,status){
|
||||
if(data.code == 1) {
|
||||
layer.close(index);
|
||||
layer.msg(data.msg, {icon: 1});
|
||||
}else{
|
||||
layer.msg(data.msg, {icon: 5});
|
||||
}
|
||||
});
|
||||
});
|
||||
}else if(menu.id == 'set_user_name'){
|
||||
layer.prompt({formType: 3,value: '',title:'请输入新账号 (原账号:'+data.User+')'}, function(value, index, elem){
|
||||
$.post('./ATool.php?type=set_user_name',{ID:data.ID,new_user_name:value},function(data,status){
|
||||
if(data.code == 1) {
|
||||
layer.close(index);
|
||||
table.reload('table');
|
||||
layer.msg(data.msg, {icon: 1});
|
||||
}else{
|
||||
layer.msg(data.msg, {icon: 5});
|
||||
}
|
||||
});
|
||||
});
|
||||
}else if(menu.id == 'set_root' || menu.id == 'del_otp' || menu.id == 'get_pwd2'){
|
||||
$.post('./ATool.php?type=' + menu.id,{ID:data.ID},function(data,status){
|
||||
if(data.code == 1) {
|
||||
table.reload('table');
|
||||
layer.msg(data.msg, {icon: 1});
|
||||
}else{
|
||||
layer.msg(data.msg, {icon: 5});
|
||||
}
|
||||
});
|
||||
}else{
|
||||
layer.msg('无效操作', {icon: 5});
|
||||
}
|
||||
});
|
||||
});
|
||||
}else if(obj.event == 'set_root'){
|
||||
$.post('./ATool.php?type=set_root',{ID:data.ID},function(data,status){
|
||||
if(data.code == 1) {
|
||||
table.reload('table');
|
||||
layer.msg(data.msg, {icon: 1});
|
||||
}else{
|
||||
layer.msg(data.msg, {icon: 5});
|
||||
}
|
||||
});
|
||||
}else if(obj.event == 'set_user_name'){
|
||||
layer.prompt({formType: 3,value: '',title:'请输入新账号 (原账号:'+data.User+')'}, function(value, index, elem){
|
||||
$.post('./ATool.php?type=set_user_name',{ID:data.ID,new_user_name:value},function(data,status){
|
||||
if(data.code == 1) {
|
||||
layer.close(index);
|
||||
table.reload('table');
|
||||
layer.msg(data.msg, {icon: 1});
|
||||
}else{
|
||||
layer.msg(data.msg, {icon: 5});
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.set').click(function () {
|
||||
let type = $(this).attr("type");
|
||||
@@ -372,6 +435,22 @@ function echo_Atool(){
|
||||
});
|
||||
return false;
|
||||
});
|
||||
//清空统计
|
||||
$('.del_tongji').on('click', function(){
|
||||
layer.confirm('确认后将删除所有账号的统计数据(访问统计/点击统计/报表统计),是否继续?',{icon: 3, title:'此操作不可逆'}, function(index){
|
||||
$.post('./ATool.php?type=del_tongji',function(data,status){
|
||||
layer.closeLast('loading');
|
||||
if(data.code == 1){
|
||||
layer.msg(data.msg,{icon: 1})
|
||||
} else{
|
||||
layer.msg(data.msg,{icon: 5});
|
||||
}
|
||||
}).fail(function(xhr, textStatus, errorThrown) {
|
||||
layer.closeLast('loading');
|
||||
layer.alert('请求失败');
|
||||
});
|
||||
});
|
||||
});
|
||||
$('#logout').click(function () {
|
||||
layer.confirm('退出后ATool将被关闭并重置Key',{icon: 3, title:'为了您的站点安全:'}, function(index){
|
||||
$.post('./ATool.php?type=logout',function(re,status){
|
||||
@@ -398,7 +477,7 @@ function echo_verify(){ ?>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ATool 工具箱</title>
|
||||
<link rel="stylesheet" href="../static/Layui/v2.6.8/css/layui.css">
|
||||
<link rel="stylesheet" href="<?php echo $GLOBALS['layui']['css']; ?>">
|
||||
<link rel="stylesheet" href="../static/Other/login.css">
|
||||
</head>
|
||||
<body>
|
||||
@@ -421,9 +500,9 @@ function echo_verify(){ ?>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>$G
|
||||
<script src = "../static/jquery/jquery-3.6.0.min.js"></script>
|
||||
<script src = "../static/Layui/v2.6.8/layui.js"></script>
|
||||
<script src = "<?php echo $GLOBALS['layui']['js']; ?>"></script>
|
||||
<script src = '../static/jquery/jquery.md5.js'></script>
|
||||
<script>
|
||||
layui.use(['form','jquery'], function () {
|
||||
|
||||
161
system/Authenticator.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
class PHPGangsta_GoogleAuthenticator
|
||||
{
|
||||
protected $_codeLength = 6;
|
||||
public function createSecret($secretLength = 16)
|
||||
{
|
||||
$validChars = $this->_getBase32LookupTable();
|
||||
if ($secretLength < 16 || $secretLength > 128) {
|
||||
throw new Exception('Bad secret length');
|
||||
}
|
||||
$secret = '';
|
||||
$rnd = false;
|
||||
if (function_exists('random_bytes')) {
|
||||
$rnd = random_bytes($secretLength);
|
||||
} elseif (function_exists('mcrypt_create_iv')) {
|
||||
$rnd = mcrypt_create_iv($secretLength, MCRYPT_DEV_URANDOM);
|
||||
} elseif (function_exists('openssl_random_pseudo_bytes')) {
|
||||
$rnd = openssl_random_pseudo_bytes($secretLength, $cryptoStrong);
|
||||
if (!$cryptoStrong) {
|
||||
$rnd = false;
|
||||
}
|
||||
}
|
||||
if ($rnd !== false) {
|
||||
for ($i = 0; $i < $secretLength; ++$i) {
|
||||
$secret .= $validChars[ord($rnd[$i]) & 31];
|
||||
}
|
||||
} else {
|
||||
throw new Exception('No source of secure random');
|
||||
}
|
||||
|
||||
return $secret;
|
||||
}
|
||||
public function getCode($secret, $timeSlice = null)
|
||||
{
|
||||
if ($timeSlice === null) {
|
||||
$timeSlice = floor(time() / 30);
|
||||
}
|
||||
|
||||
$secretkey = $this->_base32Decode($secret);
|
||||
$time = chr(0). chr(0) .chr(0). chr(0) .pack('N*', $timeSlice);
|
||||
$hm = hash_hmac('SHA1', $time, $secretkey, true);
|
||||
$offset = ord(substr($hm, -1)) & 0x0F;
|
||||
$hashpart = substr($hm, $offset, 4);
|
||||
$value = unpack('N', $hashpart);
|
||||
$value = $value[1];
|
||||
$value = $value & 0x7FFFFFFF;
|
||||
$modulo = pow(10, $this->_codeLength);
|
||||
return str_pad($value % $modulo, $this->_codeLength, '0', STR_PAD_LEFT);
|
||||
}
|
||||
public function getQRCodeGoogleUrl($name, $secret, $title = null, $params = array())
|
||||
{
|
||||
$width = !empty($params['width']) && (int) $params['width'] > 0 ? (int) $params['width'] : 200;
|
||||
$height = !empty($params['height']) && (int) $params['height'] > 0 ? (int) $params['height'] : 200;
|
||||
$level = !empty($params['level']) && array_search($params['level'], array('L', 'M', 'Q', 'H')) !== false ? $params['level'] : 'M';
|
||||
|
||||
$urlencoded = urlencode('otpauth://totp/'.$name.'?secret='.$secret.'');
|
||||
if (isset($title)) {
|
||||
$urlencoded .= urlencode('&issuer='.urlencode($title));
|
||||
}
|
||||
|
||||
return "https://api.qrserver.com/v1/create-qr-code/?data=$urlencoded&size=${width}x${height}&ecc=$level";
|
||||
}
|
||||
|
||||
public function verifyCode($secret, $code, $discrepancy = 1, $currentTimeSlice = null)
|
||||
{
|
||||
if ($currentTimeSlice === null) {
|
||||
$currentTimeSlice = floor(time() / 30);
|
||||
}
|
||||
|
||||
if (strlen($code) != 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = -$discrepancy; $i <= $discrepancy; ++$i) {
|
||||
$calculatedCode = $this->getCode($secret, $currentTimeSlice + $i);
|
||||
if ($this->timingSafeEquals($calculatedCode, $code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setCodeLength($length)
|
||||
{
|
||||
$this->_codeLength = $length;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _base32Decode($secret)
|
||||
{
|
||||
if (empty($secret)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$base32chars = $this->_getBase32LookupTable();
|
||||
$base32charsFlipped = array_flip($base32chars);
|
||||
|
||||
$paddingCharCount = substr_count($secret, $base32chars[32]);
|
||||
$allowedValues = array(6, 4, 3, 1, 0);
|
||||
if (!in_array($paddingCharCount, $allowedValues)) {
|
||||
return false;
|
||||
}
|
||||
for ($i = 0; $i < 4; ++$i) {
|
||||
if ($paddingCharCount == $allowedValues[$i] &&
|
||||
substr($secret, -($allowedValues[$i])) != str_repeat($base32chars[32], $allowedValues[$i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$secret = str_replace('=', '', $secret);
|
||||
$secret = str_split($secret);
|
||||
$binaryString = '';
|
||||
for ($i = 0; $i < count($secret); $i = $i + 8) {
|
||||
$x = '';
|
||||
if (!in_array($secret[$i], $base32chars)) {
|
||||
return false;
|
||||
}
|
||||
for ($j = 0; $j < 8; ++$j) {
|
||||
$x .= str_pad(base_convert(@$base32charsFlipped[@$secret[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);
|
||||
}
|
||||
$eightBits = str_split($x, 8);
|
||||
for ($z = 0; $z < count($eightBits); ++$z) {
|
||||
$binaryString .= (($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48) ? $y : '';
|
||||
}
|
||||
}
|
||||
|
||||
return $binaryString;
|
||||
}
|
||||
|
||||
protected function _getBase32LookupTable()
|
||||
{
|
||||
return array(
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', '2', '3', '4', '5', '6', '7',
|
||||
'=',
|
||||
);
|
||||
}
|
||||
|
||||
private function timingSafeEquals($safeString, $userString)
|
||||
{
|
||||
if (function_exists('hash_equals')) {
|
||||
return hash_equals($safeString, $userString);
|
||||
}
|
||||
$safeLen = strlen($safeString);
|
||||
$userLen = strlen($userString);
|
||||
|
||||
if ($userLen != $safeLen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = 0;
|
||||
|
||||
for ($i = 0; $i < $userLen; ++$i) {
|
||||
$result |= (ord($safeString[$i]) ^ ord($userString[$i]));
|
||||
}
|
||||
return $result === 0;
|
||||
}
|
||||
}
|
||||
1842
system/Medoo.php
13
system/MySQL/20230518.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql ="
|
||||
ALTER TABLE `user_links` CHANGE `title` `title` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '标题';
|
||||
ALTER TABLE `user_links` CHANGE `url` `url` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主链接';
|
||||
ALTER TABLE `user_links` CHANGE `description` `description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '描述';
|
||||
ALTER TABLE `user_categorys` CHANGE `name` `name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '名称';
|
||||
ALTER TABLE `user_categorys` CHANGE `description` `description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '描述';
|
||||
";
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
23
system/MySQL/20230522.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql ="
|
||||
CREATE TABLE IF NOT EXISTS `global_icon` (
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`url_md5` varchar(32) NOT NULL COMMENT 'url_md5',
|
||||
`url` text NOT NULL COMMENT 'url',
|
||||
`ico_url` text NOT NULL COMMENT 'url_ico',
|
||||
`add_time` int(10) UNSIGNED NOT NULL COMMENT '创建时间',
|
||||
`update_time` int(10) UNSIGNED NOT NULL COMMENT '更新时间',
|
||||
`file_name` text NOT NULL COMMENT '文件名',
|
||||
`file_mime` text NOT NULL COMMENT 'MIME类型',
|
||||
`extend` text NOT NULL COMMENT '预留扩展',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
INSERT INTO `purview_list` (`code`, `name`, `description`) VALUES
|
||||
('icon_pull', '图标拉取', '允许用户拉取链接图标');
|
||||
";
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
17
system/MySQL/20230605.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql ="
|
||||
ALTER TABLE `global_user` CHANGE `RegIP` `RegIP` VARCHAR( 64 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '注册IP';
|
||||
ALTER TABLE `user_apply` CHANGE `ip` `ip` VARCHAR( 64 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'ip';
|
||||
ALTER TABLE `user_apply` CHANGE `ua` `ua` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '浏览器UA';
|
||||
ALTER TABLE `user_share` CHANGE `description` `description` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '备注';
|
||||
ALTER TABLE `user_log` CHANGE `ip` `ip` VARCHAR( 64 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '请求ip';
|
||||
ALTER TABLE `user_log` CHANGE `description` `description` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '描述';
|
||||
ALTER TABLE `user_login_info` CHANGE `ip` `ip` VARCHAR( 64 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '登录IP';
|
||||
ALTER TABLE `user_login_info` CHANGE `ua` `ua` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '浏览器UA';
|
||||
|
||||
";
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
9
system/MySQL/20230715.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql ="
|
||||
ALTER TABLE `user_links` ADD `keywords` TEXT NOT NULL DEFAULT '' COMMENT '关键字' AFTER `weight` ;
|
||||
";
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
32
system/MySQL/20230723.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql =<<<EOF
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `user_article_list` (
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uid` varchar(32) NOT NULL COMMENT '用户id',
|
||||
`title` text NOT NULL COMMENT '标题',
|
||||
`category` int(10) UNSIGNED NOT NULL COMMENT '分类id',
|
||||
`state` int(10) UNSIGNED NOT NULL COMMENT '状态',
|
||||
`password` text NOT NULL COMMENT '访问密码',
|
||||
`top` int(10) UNSIGNED NOT NULL COMMENT '置顶',
|
||||
`add_time` int(10) UNSIGNED NOT NULL COMMENT '创建时间',
|
||||
`up_time` int(10) UNSIGNED NOT NULL COMMENT '修改时间',
|
||||
`browse_count` int(10) UNSIGNED NOT NULL COMMENT '浏览次数',
|
||||
`summary` text NOT NULL COMMENT '摘要',
|
||||
`content` text NOT NULL COMMENT '内容',
|
||||
`cover` text NOT NULL COMMENT '封面',
|
||||
`extend` text NOT NULL COMMENT '扩展',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
ALTER TABLE `user_count` ADD `e` TEXT NOT NULL DEFAULT '' COMMENT '扩展';
|
||||
|
||||
INSERT INTO `purview_list` (`code`, `name`, `description`) VALUES
|
||||
('article', '文章管理', '允许使用文章管理功能'),
|
||||
('article_image', '文章图片', '允许在文章编辑器上传图片');
|
||||
EOF;
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
16
system/MySQL/20240720.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql ='
|
||||
CREATE INDEX category_idx_1
|
||||
ON user_categorys (fid, uid, status, property, pid, weight);
|
||||
|
||||
CREATE INDEX link_idx_1
|
||||
ON user_links (uid, fid, status, property, pid, add_time, click);
|
||||
';
|
||||
//创建索引用于优化效率
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ CREATE TABLE IF NOT EXISTS `user_count` (
|
||||
`uid` int(10) UNSIGNED NOT NULL COMMENT '用户ID',
|
||||
`k` varchar(32) NOT NULL COMMENT '键',
|
||||
`v` bigint(10) UNSIGNED DEFAULT '0' COMMENT '值',
|
||||
`t` varchar(32) NOT NULL COMMENT '类型'
|
||||
`t` varchar(32) NOT NULL COMMENT '类型',
|
||||
`e` text NOT NULL DEFAULT ''
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
@@ -44,6 +45,13 @@ CREATE TABLE IF NOT EXISTS `updatadb_logs` (
|
||||
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230417.php', '1681719049', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230420.php', '1681977368', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230518.php', '1684393068', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230522.php', '1684762253', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230715.php', '1689427853', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230723.php', '1690119053', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20231218.php', '1702828800', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20240328.php', '1711296000', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20240720.php', '1721404800', 'TRUE', '');
|
||||
|
||||
-- 创建用户表
|
||||
DROP TABLE IF EXISTS `global_user`;
|
||||
@@ -56,11 +64,13 @@ CREATE TABLE IF NOT EXISTS `global_user` (
|
||||
`Email` varchar(32) NOT NULL COMMENT '邮箱',
|
||||
`SecretKey` varchar(32) NOT NULL DEFAULT '' COMMENT 'SecretKey',
|
||||
`Token` varchar(32) NOT NULL DEFAULT '' COMMENT 'Token',
|
||||
`RegIP` varchar(15) NOT NULL COMMENT '注册IP',
|
||||
`RegIP` varchar(64) NOT NULL DEFAULT '' COMMENT '注册IP',
|
||||
`RegTime` int(10) UNSIGNED NOT NULL COMMENT '注册时间',
|
||||
`Login` varchar(16) NOT NULL COMMENT '登录入口',
|
||||
`LoginConfig` text NOT NULL COMMENT '登陆配置',
|
||||
`kct` int(10) UNSIGNED DEFAULT '0' COMMENT 'Key清理时间',
|
||||
`domain` text NOT NULL COMMENT '个性域名',
|
||||
`phone` text NOT NULL COMMENT '手机号',
|
||||
`Extend1` text NOT NULL COMMENT '扩展1',
|
||||
`Extend2` text NOT NULL COMMENT '扩展2',
|
||||
PRIMARY KEY (`ID`),
|
||||
@@ -78,20 +88,22 @@ CREATE TABLE IF NOT EXISTS `user_categorys` (
|
||||
`pid` int(10) UNSIGNED NOT NULL COMMENT '加密组id',
|
||||
`status` int(1) NOT NULL COMMENT '状态',
|
||||
`property` int(1) NOT NULL COMMENT '私有',
|
||||
`name` varchar(128) NOT NULL COMMENT '名称',
|
||||
`name` text NOT NULL COMMENT '名称',
|
||||
`add_time` int(10) UNSIGNED NOT NULL COMMENT '添加时间',
|
||||
`up_time` int(10) UNSIGNED NOT NULL COMMENT '更新时间',
|
||||
`weight` int(10) NOT NULL COMMENT '权重',
|
||||
`description` varchar(128) NOT NULL DEFAULT '' COMMENT '描述',
|
||||
`description` text NOT NULL DEFAULT '' COMMENT '描述',
|
||||
`font_icon` text NOT NULL COMMENT '字体图标',
|
||||
`icon` text NOT NULL DEFAULT '' COMMENT '个性图标',
|
||||
`category_type` VARCHAR(255) NOT NULL DEFAULT 'link' COMMENT '分类类型',
|
||||
`max` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '显示数量',
|
||||
`extend` text NOT NULL COMMENT '扩展',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='用户分类';
|
||||
|
||||
INSERT INTO `user_categorys` (`id`, `cid`, `fid`, `uid`, `pid`, `status`, `property`, `name`, `add_time`, `up_time`, `weight`, `description`, `font_icon`, `icon`, `extend`) VALUES
|
||||
(1, 1, 0, 0, 0, 1, 0, '默认分类', 1672502400, 1672502400, 0, 'TwoNav默认分类', 'fa fa-book', '', '');
|
||||
|
||||
CREATE INDEX category_idx_1 ON user_categorys (fid, uid, status, property, pid, weight);
|
||||
|
||||
-- 用户链接表
|
||||
DROP TABLE IF EXISTS `user_links`;
|
||||
@@ -103,11 +115,12 @@ CREATE TABLE IF NOT EXISTS `user_links` (
|
||||
`pid` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '加密组id',
|
||||
`status` int(1) NOT NULL DEFAULT '1' COMMENT '状态',
|
||||
`property` int(1) NOT NULL DEFAULT '0' COMMENT '私有',
|
||||
`title` varchar(128) NOT NULL COMMENT '标题',
|
||||
`url` varchar(1024) NOT NULL COMMENT '主链接',
|
||||
`title` text NOT NULL COMMENT '标题',
|
||||
`url` text NOT NULL COMMENT '主链接',
|
||||
`url_standby` text NOT NULL COMMENT '备用链接',
|
||||
`weight` int(11) NOT NULL DEFAULT '0' COMMENT '权重',
|
||||
`description` varchar(128) NOT NULL DEFAULT '' COMMENT '描述',
|
||||
`keywords` text NOT NULL DEFAULT '' COMMENT '关键字',
|
||||
`description` text NOT NULL DEFAULT '' COMMENT '描述',
|
||||
`icon` text NOT NULL DEFAULT '' COMMENT '图标',
|
||||
`click` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '点击数',
|
||||
`add_time` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '添加时间',
|
||||
@@ -121,7 +134,7 @@ INSERT INTO `user_links` (`id`, `lid`, `uid`, `fid`, `pid`, `status`, `property`
|
||||
(1, 1, 0, 1, 0, 1, 0, 'TwoNav 源码', 'https://gitee.com/tznb/TwoNav', '', 0, '项目开源地址', '', 0, 1672502400, 1672502400, ''),
|
||||
(2, 2, 0, 1, 0, 1, 0, '使用说明', 'https://gitee.com/tznb/TwoNav/wikis', '', 0, '使用说明', '', 0, 1672502400, 1672502400, '');
|
||||
|
||||
|
||||
CREATE INDEX link_idx_1 ON user_links (uid, fid, status, property, pid, add_time, click);
|
||||
|
||||
-- 登录信息表
|
||||
DROP TABLE IF EXISTS `user_login_info`;
|
||||
@@ -129,8 +142,8 @@ CREATE TABLE IF NOT EXISTS `user_login_info` (
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uid` int(10) UNSIGNED NOT NULL COMMENT '用户id',
|
||||
`user` varchar(32) NOT NULL COMMENT '用户名',
|
||||
`ip` varchar(15) NOT NULL COMMENT '登录IP',
|
||||
`ua` varchar(256) NOT NULL COMMENT '浏览器UA',
|
||||
`ip` varchar(64) NOT NULL DEFAULT '' COMMENT '登录IP',
|
||||
`ua` TEXT NOT NULL DEFAULT '' COMMENT '浏览器UA',
|
||||
`login_time` int(10) UNSIGNED NOT NULL COMMENT '登录时间',
|
||||
`last_time` int(10) UNSIGNED NOT NULL COMMENT '最后访问时间',
|
||||
`expire_time` int(10) UNSIGNED NOT NULL COMMENT '过期时间',
|
||||
@@ -144,11 +157,11 @@ CREATE TABLE IF NOT EXISTS `user_log` (
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uid` int(10) UNSIGNED NOT NULL COMMENT '用户id',
|
||||
`user` varchar(32) NOT NULL COMMENT '用户名',
|
||||
`ip` varchar(15) NOT NULL COMMENT '请求ip',
|
||||
`ip` varchar(64) NOT NULL DEFAULT '' COMMENT '请求ip',
|
||||
`time` varchar(13) NOT NULL COMMENT '请求时间',
|
||||
`type` varchar(16) NOT NULL COMMENT '日志类型',
|
||||
`content` text NOT NULL COMMENT '请求内容',
|
||||
`description` varchar(128) NOT NULL COMMENT '描述',
|
||||
`description` text NOT NULL DEFAULT '' COMMENT '描述',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='日志';
|
||||
|
||||
@@ -190,7 +203,10 @@ INSERT INTO `purview_list` (`code`, `name`, `description`) VALUES
|
||||
('guestbook', '留言板', '允许使用留言板功能'),
|
||||
('link_extend', '链接扩展', '允许使用链接扩展字段'),
|
||||
('theme_in', '主题设置', '后台显示主题设置菜单'),
|
||||
('theme_set', '主题配置', '允许自定义主题配置');
|
||||
('theme_set', '主题配置', '允许自定义主题配置'),
|
||||
('icon_pull', '图标拉取', '允许用户拉取链接图标'),
|
||||
('article', '文章管理', '允许使用文章管理功能'),
|
||||
('article_image', '文章图片', '允许在文章编辑器上传图片');
|
||||
|
||||
-- 注册码列表
|
||||
DROP TABLE IF EXISTS `regcode_list`;
|
||||
@@ -227,9 +243,9 @@ CREATE TABLE IF NOT EXISTS `user_apply` (
|
||||
`iconurl` varchar(512) NOT NULL COMMENT '图标url',
|
||||
`title` varchar(512) NOT NULL COMMENT '标题',
|
||||
`url` varchar(512) NOT NULL COMMENT '链接',
|
||||
`ip` varchar(16) NOT NULL DEFAULT '' COMMENT 'ip',
|
||||
`ip` varchar(64) NOT NULL DEFAULT '' COMMENT 'ip',
|
||||
`email` varchar(128) NOT NULL DEFAULT '' COMMENT '邮箱',
|
||||
`ua` varchar(512) NOT NULL DEFAULT '' COMMENT '浏览器UA',
|
||||
`ua` TEXT NOT NULL DEFAULT '' COMMENT '浏览器UA',
|
||||
`time` int(10) NOT NULL DEFAULT '0' COMMENT '时间',
|
||||
`state` int(1) NOT NULL DEFAULT '0' COMMENT '状态',
|
||||
`category_id` int(10) NOT NULL DEFAULT '0' COMMENT '分类id',
|
||||
@@ -250,10 +266,62 @@ CREATE TABLE IF NOT EXISTS `user_share` (
|
||||
`up_time` Bigint(13) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
`expire_time` Bigint(13) UNSIGNED NOT NULL DEFAULT '0' COMMENT '到期时间',
|
||||
`views` Bigint(13) NOT NULL DEFAULT '0' COMMENT '浏览数',
|
||||
`description` varchar(13) NOT NULL DEFAULT '' COMMENT '备注',
|
||||
`description` TEXT NOT NULL DEFAULT '' COMMENT '备注',
|
||||
`type` int(1) NOT NULL COMMENT '类型',
|
||||
`data` text NOT NULL COMMENT '数据',
|
||||
`pv` int(1) NOT NULL COMMENT '私有可见',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- 图标缓存
|
||||
CREATE TABLE IF NOT EXISTS `global_icon` (
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`url_md5` varchar(32) NOT NULL COMMENT 'url_md5',
|
||||
`url` text NOT NULL COMMENT 'url',
|
||||
`ico_url` text NOT NULL COMMENT 'url_ico',
|
||||
`add_time` int(10) UNSIGNED NOT NULL COMMENT '创建时间',
|
||||
`update_time` int(10) UNSIGNED NOT NULL COMMENT '更新时间',
|
||||
`file_name` text NOT NULL COMMENT '文件名',
|
||||
`file_mime` text NOT NULL COMMENT 'MIME类型',
|
||||
`extend` text NOT NULL COMMENT '预留扩展',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
-- 用户文章列表
|
||||
CREATE TABLE IF NOT EXISTS `user_article_list` (
|
||||
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uid` varchar(32) NOT NULL COMMENT '用户id',
|
||||
`title` text NOT NULL COMMENT '标题',
|
||||
`category` int(10) UNSIGNED NOT NULL COMMENT '分类id',
|
||||
`state` int(10) UNSIGNED NOT NULL COMMENT '状态',
|
||||
`password` text NOT NULL COMMENT '访问密码',
|
||||
`top` int(10) UNSIGNED NOT NULL COMMENT '置顶',
|
||||
`add_time` int(10) UNSIGNED NOT NULL COMMENT '创建时间',
|
||||
`up_time` int(10) UNSIGNED NOT NULL COMMENT '修改时间',
|
||||
`browse_count` int(10) UNSIGNED NOT NULL COMMENT '浏览次数',
|
||||
`summary` text NOT NULL COMMENT '摘要',
|
||||
`content` text NOT NULL COMMENT '内容',
|
||||
`cover` text NOT NULL COMMENT '封面',
|
||||
`extend` text NOT NULL COMMENT '扩展',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- 第三方用户表
|
||||
CREATE TABLE IF NOT EXISTS `third_party_user` (
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uid` int UNSIGNED NOT NULL COMMENT '用户id',
|
||||
`inlet` text NOT NULL COMMENT '入口',
|
||||
`provider` text NOT NULL COMMENT '提供商',
|
||||
`nickname` text NOT NULL COMMENT '昵称',
|
||||
`openid` text NOT NULL COMMENT '第三方用户标识',
|
||||
`access_token` text NOT NULL COMMENT '访问令牌',
|
||||
`refresh_token` text NOT NULL COMMENT '刷新令牌',
|
||||
`faceimg` text NOT NULL COMMENT '头像URL',
|
||||
`bind_time` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '绑定时间',
|
||||
`login_time` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '登录时间',
|
||||
`expires` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '到期时间',
|
||||
`extend` text NOT NULL COMMENT '扩展',
|
||||
FOREIGN KEY (`uid`) REFERENCES `global_user` (`ID`) ON DELETE CASCADE,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
|
||||
@@ -4,21 +4,10 @@ if($global_config['Maintenance'] != 0){Amsg(-1,'网站正在进行维护,请稍
|
||||
$global_templates = unserialize(get_db("global_config",'v', ["k" => "s_templates"]));
|
||||
//如果是Get请求则载入登录模板
|
||||
if($_SERVER['REQUEST_METHOD'] === 'GET'){
|
||||
$t_name = $global_templates['register'];
|
||||
$t_dir = "./templates/register/".$t_name; //模板目录
|
||||
$t_path = "./templates/register/{$t_name}/index.php"; //模板路径
|
||||
//如果不存在则使用默认模板
|
||||
if(!file_exists($t_path)){
|
||||
$t_name = 'default';
|
||||
$t_dir ='./templates/register/default';
|
||||
$t_path = './templates/register/default/index.php';
|
||||
$global_templates['register'] = 'default';
|
||||
update_db("global_config", ["v" => $global_templates], ["k"=>"s_templates"]);
|
||||
}
|
||||
$copyright = empty($global_config['copyright'])?'<a target="_blank" href="https://gitee.com/tznb/TwoNav">Copyright © TwoNav</a>':$global_config['copyright'];
|
||||
$ICP = empty($global_config['ICP'])?'':'<a target="_blank" href="https://beian.miit.gov.cn">'.$global_config['ICP'].'</a>';
|
||||
$reg_tips = get_db('global_config','v',['k'=>'reg_tips']);
|
||||
require $t_path;
|
||||
//通用数据初始化
|
||||
require DIR."/system/templates.php";
|
||||
$reg_tips = get_db('global_config','v',['k'=>'reg_tips']); //注册提示
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -58,192 +47,8 @@ if(!preg_match('/^[A-Za-z0-9]{4,13}$/', $user)){
|
||||
msg(-1,'POST提交的密码异常≠32!');
|
||||
}elseif(preg_match("/^(system|data|static|templates|index|root|admin)$/i",$user) ) {
|
||||
msg(-1,'改用户名已被系统保留!');
|
||||
}elseif(!empty(get_db('global_user','ID',['User'=>$user ]))){
|
||||
msg(-1,'该账号已被注册!');
|
||||
}elseif(!empty(get_db('global_user','ID',['Email'=>$Email ]))){
|
||||
msg(-1,'该邮箱已被使用!');
|
||||
}elseif(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$Email)){
|
||||
msg(-1,'邮箱错误!');
|
||||
}elseif(username_retain_verify($user)){
|
||||
msg(-1,'该账号已被站长保留!');
|
||||
}
|
||||
|
||||
//读取邮件配置
|
||||
$mail_config = get_db("global_config","v",["k"=>"mail_config"]);
|
||||
if(!empty($mail_config)){
|
||||
$mail_config = unserialize($mail_config);
|
||||
if($mail_config['verify_email'] == 1 && $_GET['type'] == 'getcode'){
|
||||
//判断是否频繁发送
|
||||
$send_interval = intval($mail_config['send_interval']);
|
||||
if($send_interval > 0 && has_db('user_log',['type'=>'send_email','ip'=>$IP,'time[>]'=>time() - $send_interval])){
|
||||
msg(-1,'请勿频繁获取验证码');
|
||||
}
|
||||
$mail_config['addressee'] = $_POST['Email'];
|
||||
$mail_config['Subject'] = '验证码';
|
||||
$code = mt_rand(100000,999999);
|
||||
|
||||
if(!strstr($mail_config['verify_template'],'$code')){
|
||||
$mail_config['verify_template'] = '您的验证:$code';
|
||||
}
|
||||
$mail_config['Body'] = empty($mail_config['verify_template']) ? '您的验证:'.$code:str_replace('$code', $code, $mail_config['verify_template']);
|
||||
$mail_config['return']='bool';
|
||||
if(send_email($mail_config)){
|
||||
session_start();
|
||||
$_SESSION["{$_POST['Email']}"]['code'] = "$code";
|
||||
$_SESSION["{$_POST['Email']}"]['time'] = time();
|
||||
insert_db("user_log", ["uid" => 0,"user"=>$user,"ip"=>$IP,"time"=>time(),"type" => 'send_email',"content"=>Get_Request_Content(),"description"=>"发送注册验证码:".$code.', 接收邮箱: '.$_POST['Email']]);
|
||||
msg(1,'发送成功');
|
||||
}else{
|
||||
msg(-1,'发送失败');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
//验证码效验
|
||||
if(!empty($mail_config['verify_email']) && $mail_config['verify_email'] == 1){
|
||||
session_start();
|
||||
if(empty($_POST['code'])){
|
||||
msg(-1,'请输入验证码');
|
||||
}elseif ($_POST['code'] != $_SESSION["{$_POST['Email']}"]['code']) {
|
||||
msg(-1,'验证码错误'.$_SESSION["{$_POST['Email']}"]['code']);
|
||||
}elseif($_SESSION["{$_POST['Email']}"]['time'] + 300 < time()){
|
||||
msg(-1,'验证码已过期');
|
||||
}
|
||||
unset($_SESSION["{$_POST['Email']}"]);
|
||||
}
|
||||
//插入用户表和创建初始数据库
|
||||
$RegTime = time();
|
||||
$PassMD5 = Get_MD5_Password($pass,$RegTime);
|
||||
$Elogin = Get_Exclusive_Login($user);
|
||||
|
||||
//用户组
|
||||
if(!empty($regcode_info['u_group'])){
|
||||
$UserGroup = $regcode_info['u_group'];
|
||||
}elseif(!empty($global_config['default_UserGroup'])){
|
||||
$UserGroup = $global_config['default_UserGroup'];
|
||||
}else{
|
||||
$UserGroup = 'default';
|
||||
}
|
||||
|
||||
//读取用户组信息,如果用户组不存在则设为默认用户组
|
||||
if($UserGroup != 'default'){
|
||||
$Group = get_db('user_group','*',['code' => $UserGroup]);
|
||||
if(empty( $Group )){
|
||||
$UserGroup = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
$blueprint = !empty(get_db('global_user','ID',['ID'=>$Group['uid']]));
|
||||
|
||||
if($blueprint){
|
||||
$LoginConfig = unserialize(get_db('global_user','LoginConfig',['ID'=>$Group['uid']]));
|
||||
$LoginConfig['Password2'] = '';
|
||||
}else{
|
||||
//不需要修改内容,无需反序化
|
||||
$LoginConfig = get_db('global_config','v',['k'=>'LoginConfig']);
|
||||
}
|
||||
//父ID
|
||||
if(!empty($regcode_info['user'])){
|
||||
$FID = get_db('global_user','ID',['User'=>$regcode_info['user']]);
|
||||
}else{
|
||||
$FID = 0;
|
||||
}
|
||||
|
||||
|
||||
insert_db("global_user", [
|
||||
"FID"=>$FID,
|
||||
"User"=>$user,
|
||||
"Password"=>$PassMD5,
|
||||
"UserGroup"=>$UserGroup,
|
||||
"Email"=>$Email,
|
||||
"SecretKey"=>'',
|
||||
"Token"=>'',
|
||||
"RegIP"=>$IP,
|
||||
"RegTime"=>$RegTime,
|
||||
"Login"=>$Elogin,
|
||||
"LoginConfig"=>$LoginConfig
|
||||
]);
|
||||
|
||||
//读取用户信息
|
||||
$USER_DB = get_db("global_user", "*", ["User"=>$user]);
|
||||
//记录日志
|
||||
insert_db("user_log", ["uid" => $USER_DB['ID'],"user"=>$USER_DB['User'],"ip"=>$IP,"time"=>time(),"type" => 'register',"content"=>Get_Request_Content(),"description"=>"注册账号"]);
|
||||
//生成Cookie
|
||||
Set_key($USER_DB);
|
||||
|
||||
//注册码注册时回写数据
|
||||
if(!empty($regcode_info)){
|
||||
update_db('regcode_list',['use_time'=>time(),'use_state'=>'已使用,用户名:'.$user],['id'=>$regcode_info['id']]);
|
||||
}
|
||||
|
||||
//写默认站点配置
|
||||
if($blueprint){
|
||||
$s_site = get_db('user_config','v',['k'=>'s_site','uid'=>$Group['uid']]);
|
||||
}else{
|
||||
$s_site = get_db('global_config','v',['k'=>'s_site']);
|
||||
}
|
||||
|
||||
insert_db("user_config", ["uid"=>$USER_DB['ID'], "k" => "s_site","v" => $s_site,"d" => '站点配置','t'=>'config']);
|
||||
|
||||
//写默认模板
|
||||
if($blueprint){
|
||||
$global_templates = unserialize(get_db('user_config','v',['k'=>'s_templates','uid'=>$Group['uid']]));
|
||||
}else{
|
||||
$global_templates = unserialize(get_db('global_config','v',['k'=>'s_templates']));
|
||||
}
|
||||
|
||||
insert_db("user_config", ["uid" => $USER_DB['ID'],"k"=>"s_templates","v"=>$global_templates,"t"=>"config","d" => '默认模板']);
|
||||
|
||||
//写初始分类和链接
|
||||
$time = time();
|
||||
if($blueprint){
|
||||
$categorys = select_db('user_categorys','*',['uid'=>$Group['uid']]);
|
||||
$links = select_db('user_links','*',['uid'=>$Group['uid']]);
|
||||
}else{
|
||||
$categorys = select_db('user_categorys','*',['uid'=>0]);
|
||||
$links = select_db('user_links','*',['uid'=>0]);
|
||||
}
|
||||
|
||||
foreach ($categorys as $key => $data){
|
||||
$data['uid'] = $USER_DB['ID'];
|
||||
$data['add_time'] = $time;
|
||||
$data['up_time'] = $time;
|
||||
unset($data['id']);
|
||||
insert_db('user_categorys',$data);
|
||||
}
|
||||
|
||||
foreach ($links as $key => $data){
|
||||
$data['uid'] = $USER_DB['ID'];
|
||||
$data['add_time'] = $time;
|
||||
$data['up_time'] = $time;
|
||||
unset($data['id']);
|
||||
insert_db('user_links',$data);
|
||||
}
|
||||
|
||||
//写初始ID
|
||||
$link_id = intval(max_db('user_links','lid',['uid'=>$USER_DB['ID']])) +1;
|
||||
insert_db("user_config", ["uid"=>$USER_DB['ID'],"k"=>"link_id","v"=>$link_id,"t"=>"max_id","d"=>'链接ID']);
|
||||
$category_id = intval(max_db('user_categorys','cid',['uid'=>$USER_DB['ID']])) +1;
|
||||
insert_db("user_config", ["uid"=>$USER_DB['ID'],"k"=>"category_id","v"=>$category_id,"t"=>"max_id","d"=>'分类ID']);
|
||||
insert_db("user_config", ["uid"=>$USER_DB['ID'],"k"=>"pwd_group_id","v"=>1,"t"=>"max_id","d"=>'加密组ID']);
|
||||
|
||||
|
||||
//账号保留
|
||||
function username_retain_verify($username){
|
||||
$list = get_db("global_config", "v", ["k" => "username_retain"]);
|
||||
if(empty($list)){
|
||||
return false;
|
||||
}
|
||||
$patterns = explode("\n", $list);
|
||||
foreach($patterns as $pattern){
|
||||
if (preg_match($pattern, $username)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//返回注册成功
|
||||
msg(1,'注册成功');
|
||||
|
||||
|
||||
msg(-1,'免费版不支持此功能<br /> <a href="https://gitee.com/tznb/TwoNav/wikis/pages?sort_id=7968669&doc_id=3767990" target="_blank" style="color: #1e9fff;">点击此处前往购买页面</a>');
|
||||
|
||||
22
system/SQLite/20230522.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql =<<<EOF
|
||||
CREATE TABLE IF NOT EXISTS "global_icon" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"url_md5" text(32) NOT NULL DEFAULT "",
|
||||
"url" text NOT NULL DEFAULT "",
|
||||
"ico_url" text NOT NULL DEFAULT "",
|
||||
"add_time" integer(10) NOT NULL,
|
||||
"update_time" integer(10) NOT NULL,
|
||||
"file_name" text NOT NULL DEFAULT "",
|
||||
"file_mime" text NOT NULL DEFAULT "",
|
||||
"extend" text NOT NULL DEFAULT "",
|
||||
CONSTRAINT "id" UNIQUE ("id" ASC)
|
||||
);
|
||||
INSERT INTO `purview_list` (`code`, `name`, `description`) VALUES
|
||||
('icon_pull', '图标拉取', '允许用户拉取链接图标');
|
||||
EOF;
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
9
system/SQLite/20230715.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql ='
|
||||
ALTER TABLE user_links ADD keywords TEXT(128) NOT NULL DEFAULT "";
|
||||
';
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
31
system/SQLite/20230723.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql =<<<EOF
|
||||
CREATE TABLE "user_article_list" (
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT,
|
||||
"uid" integer(10) NOT NULL,
|
||||
"title" TEXT NOT NULL DEFAULT "",
|
||||
"category" integer NOT NULL,
|
||||
"state" integer(1) DEFAULT 0,
|
||||
"password" TEXT NOT NULL DEFAULT "",
|
||||
"top" integer(10),
|
||||
"add_time" integer(10),
|
||||
"up_time" integer(10),
|
||||
"browse_count" integer DEFAULT 0,
|
||||
"summary" TEXT,
|
||||
"content" TEXT,
|
||||
"cover" TEXT,
|
||||
"extend" TEXT,
|
||||
CONSTRAINT "id" UNIQUE ("id" ASC)
|
||||
);
|
||||
|
||||
ALTER TABLE user_count ADD e TEXT NOT NULL DEFAULT "";
|
||||
|
||||
INSERT INTO `purview_list` (`code`, `name`, `description`) VALUES
|
||||
('article', '文章管理', '允许使用文章管理功能'),
|
||||
('article_image', '文章图片', '允许在文章编辑器上传图片');
|
||||
EOF;
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
16
system/SQLite/20240720.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
$sql ='
|
||||
CREATE INDEX "category_idx_1"
|
||||
ON "user_categorys" ("fid","uid","status","property","pid","weight");
|
||||
|
||||
CREATE INDEX "link_idx_1"
|
||||
ON "user_links" ("uid","fid","status","property","pid","add_time","click");
|
||||
';
|
||||
//创建索引用于优化效率
|
||||
if(exe_sql($sql)){
|
||||
insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}else{
|
||||
msg(-1,'数据库更新失败');
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ CREATE TABLE IF NOT EXISTS "user_count" (
|
||||
"uid" integer(10) NOT NULL,
|
||||
"k" text(32) NOT NULL DEFAULT "",
|
||||
"v" integer(10) NOT NULL DEFAULT 0,
|
||||
"t" text(32) NOT NULL DEFAULT ""
|
||||
"t" text(32) NOT NULL DEFAULT "",
|
||||
"e" text NOT NULL DEFAULT ""
|
||||
);
|
||||
|
||||
-- 数据库升级记录
|
||||
@@ -37,6 +38,12 @@ CREATE TABLE IF NOT EXISTS "updatadb_logs" (
|
||||
);
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230417.php', '1681719049', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230420.php', '1681977368', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230522.php', '1684762253', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230715.php', '1689427853', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20230723.php', '1690119053', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20231218.php', '1702828800', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20240328.php', '1711296000', 'TRUE', '');
|
||||
INSERT INTO "updatadb_logs" ("file_name", "update_time", "status", "extra") VALUES ('20240720.php', '1721404800', 'TRUE', '');
|
||||
|
||||
-- 创建用户表
|
||||
CREATE TABLE IF NOT EXISTS "global_user" (
|
||||
@@ -48,11 +55,13 @@ CREATE TABLE IF NOT EXISTS "global_user" (
|
||||
"Email" TEXT(32) NOT NULL,
|
||||
"SecretKey" TEXT(32) NOT NULL DEFAULT "",
|
||||
"Token" TEXT(32) NOT NULL DEFAULT "",
|
||||
"RegIP" TEXT(15) NOT NULL,
|
||||
"RegIP" TEXT(64) NOT NULL DEFAULT "",
|
||||
"RegTime" integer(10) NOT NULL,
|
||||
"Login" TEXT(16) NOT NULL,
|
||||
"LoginConfig" TEXT NOT NULL,
|
||||
"kct" integer(10) DEFAULT 0,
|
||||
"domain" TEXT NOT NULL DEFAULT "",
|
||||
"phone" TEXT NOT NULL DEFAULT "",
|
||||
"Extend1" TEXT NOT NULL DEFAULT "",
|
||||
"Extend2" TEXT NOT NULL DEFAULT "",
|
||||
CONSTRAINT "User" UNIQUE ("User" ASC, "Email" ASC)
|
||||
@@ -74,10 +83,13 @@ CREATE TABLE IF NOT EXISTS "user_categorys" (
|
||||
"description" TEXT(128) NOT NULL DEFAULT "",
|
||||
"font_icon" TEXT DEFAULT "",
|
||||
"icon" TEXT DEFAULT "",
|
||||
"category_type" TEXT DEFAULT "link",
|
||||
"max" text DEFAULT "",
|
||||
"extend" TEXT DEFAULT ""
|
||||
);
|
||||
|
||||
INSERT INTO "user_categorys"("id", "cid", "fid", "uid", "pid", "status", "property", "name", "add_time", "up_time", "weight", "description", "font_icon", "icon", "extend") VALUES (1, 1, 0, 0, 0, 1, 0, '默认分类', 1672502400, 1672502400, 0, 'TwoNav默认分类', 'fa fa-book', '', '');
|
||||
CREATE INDEX "category_idx_1" ON "user_categorys" ("fid","uid","status","property","pid","weight");
|
||||
|
||||
-- 用户链接表
|
||||
CREATE TABLE IF NOT EXISTS "user_links" (
|
||||
@@ -92,6 +104,7 @@ CREATE TABLE IF NOT EXISTS "user_links" (
|
||||
"url" TEXT(1024) NOT NULL,
|
||||
"url_standby" text NOT NULL DEFAULT "",
|
||||
"weight" integer(11) NOT NULL DEFAULT 0,
|
||||
"keywords" TEXT(128) NOT NULL DEFAULT "",
|
||||
"description" TEXT(128) NOT NULL DEFAULT "",
|
||||
"icon" text NOT NULL DEFAULT "",
|
||||
"click" integer(10) NOT NULL DEFAULT 0,
|
||||
@@ -101,14 +114,15 @@ CREATE TABLE IF NOT EXISTS "user_links" (
|
||||
);
|
||||
INSERT INTO "user_links"("id", "lid", "uid", "fid", "pid", "status", "property", "title", "url", "url_standby", "weight", "description", "icon", "click", "add_time", "up_time", "extend") VALUES (1, 1, 0, 1, 0, 1, 0, 'TwoNav 源码', 'https://gitee.com/tznb/TwoNav', '', 0, '项目开源地址', '', 0, 1672502400, 1672502400, '');
|
||||
INSERT INTO "user_links"("id", "lid", "uid", "fid", "pid", "status", "property", "title", "url", "url_standby", "weight", "description", "icon", "click", "add_time", "up_time", "extend") VALUES (2, 2, 0, 1, 0, 1, 0, '使用说明', 'https://gitee.com/tznb/TwoNav/wikis', '', 0, '使用说明', '', 0, 1672502400, 1672502400, '');
|
||||
|
||||
CREATE INDEX "link_idx_1" ON "user_links" ("uid","fid","status","property","pid","add_time","click");
|
||||
|
||||
-- 登录信息表
|
||||
CREATE TABLE IF NOT EXISTS "user_login_info" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"uid" integer(10) NOT NULL,
|
||||
"user" TEXT(32) NOT NULL,
|
||||
"ip" TEXT(15) NOT NULL,
|
||||
"ua" TEXT(256) NOT NULL,
|
||||
"ip" TEXT(64) NOT NULL,
|
||||
"ua" TEXT NOT NULL,
|
||||
"login_time" integer(10) NOT NULL,
|
||||
"last_time" integer(10) NOT NULL,
|
||||
"expire_time" integer(10) NOT NULL,
|
||||
@@ -120,11 +134,11 @@ CREATE TABLE IF NOT EXISTS "user_log" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"uid" integer(10) NOT NULL,
|
||||
"user" TEXT(32) NOT NULL,
|
||||
"ip" TEXT(15) NOT NULL,
|
||||
"ip" TEXT(64) NOT NULL,
|
||||
"time" TEXT(13) NOT NULL,
|
||||
"type" TEXT(16) NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"description" TEXT(128) NOT NULL
|
||||
"description" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- 用户组
|
||||
@@ -163,7 +177,10 @@ INSERT INTO `purview_list` (`code`, `name`, `description`) VALUES
|
||||
('guestbook', '留言板', '允许使用留言板功能'),
|
||||
('link_extend', '链接扩展', '允许使用链接扩展字段'),
|
||||
('theme_in', '主题设置', '后台显示主题设置菜单'),
|
||||
('theme_set', '主题配置', '允许自定义主题配置');
|
||||
('theme_set', '主题配置', '允许自定义主题配置'),
|
||||
('icon_pull', '图标拉取', '允许用户拉取链接图标'),
|
||||
('article', '文章管理', '允许使用文章管理功能'),
|
||||
('article_image', '文章图片', '允许在文章编辑器上传图片');
|
||||
|
||||
-- 注册码列表
|
||||
CREATE TABLE IF NOT EXISTS "regcode_list" (
|
||||
@@ -197,8 +214,8 @@ CREATE TABLE IF NOT EXISTS "user_apply" (
|
||||
"title" TEXT(512) DEFAULT "",
|
||||
"url" TEXT(512) DEFAULT "",
|
||||
"email" TEXT(128) DEFAULT "",
|
||||
"ip" TEXT(16) DEFAULT "",
|
||||
"ua" TEXT(512) DEFAULT "",
|
||||
"ip" TEXT(64) DEFAULT "",
|
||||
"ua" TEXT DEFAULT "",
|
||||
"time" integer DEFAULT "0",
|
||||
"state" integer DEFAULT "0",
|
||||
"category_id" INTEGER DEFAULT "0",
|
||||
@@ -217,8 +234,59 @@ CREATE TABLE IF NOT EXISTS "user_share" (
|
||||
"up_time" integer(13) DEFAULT "0",
|
||||
"expire_time" integer(13) DEFAULT "0",
|
||||
"views" integer(13) DEFAULT "0",
|
||||
"description" TEXT(13) DEFAULT "",
|
||||
"description" TEXT DEFAULT "",
|
||||
"type" integer(1) NOT NULL,
|
||||
"data" TEXT,
|
||||
"pv" integer(1) DEFAULT "0"
|
||||
);
|
||||
|
||||
-- 图标缓存
|
||||
CREATE TABLE IF NOT EXISTS "global_icon" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"url_md5" text(32) NOT NULL DEFAULT "",
|
||||
"url" text NOT NULL DEFAULT "",
|
||||
"ico_url" text NOT NULL DEFAULT "",
|
||||
"add_time" integer(10) NOT NULL,
|
||||
"update_time" integer(10) NOT NULL,
|
||||
"file_name" text NOT NULL DEFAULT "",
|
||||
"file_mime" text NOT NULL DEFAULT "",
|
||||
"extend" text NOT NULL DEFAULT "",
|
||||
CONSTRAINT "id" UNIQUE ("id" ASC)
|
||||
);
|
||||
|
||||
-- 用户文章列表
|
||||
CREATE TABLE "user_article_list" (
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT,
|
||||
"uid" integer(10) NOT NULL,
|
||||
"title" TEXT NOT NULL DEFAULT "",
|
||||
"category" integer NOT NULL,
|
||||
"state" integer(1) DEFAULT 0,
|
||||
"password" TEXT NOT NULL DEFAULT "",
|
||||
"top" integer(10),
|
||||
"add_time" integer(10),
|
||||
"up_time" integer(10),
|
||||
"browse_count" integer DEFAULT 0,
|
||||
"summary" TEXT,
|
||||
"content" TEXT,
|
||||
"cover" TEXT,
|
||||
"extend" TEXT,
|
||||
CONSTRAINT "id" UNIQUE ("id" ASC)
|
||||
);
|
||||
|
||||
-- 第三方用户表
|
||||
CREATE TABLE "third_party_user" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"uid" INTEGER NOT NULL,
|
||||
"inlet" TEXT NOT NULL DEFAULT "",
|
||||
"provider" TEXT NOT NULL DEFAULT "",
|
||||
"nickname" TEXT NOT NULL DEFAULT "",
|
||||
"openid" TEXT NOT NULL DEFAULT "",
|
||||
"access_token" TEXT NOT NULL DEFAULT "",
|
||||
"refresh_token" TEXT NOT NULL DEFAULT "",
|
||||
"faceimg" TEXT NOT NULL DEFAULT "",
|
||||
"bind_time" integer NOT NULL DEFAULT 0,
|
||||
"login_time" integer NOT NULL DEFAULT 0,
|
||||
"expires" integer NOT NULL DEFAULT 0,
|
||||
"extend" TEXT NOT NULL DEFAULT "",
|
||||
CONSTRAINT "uid" FOREIGN KEY ("uid") REFERENCES "global_user" ("ID") ON DELETE CASCADE
|
||||
);
|
||||
@@ -18,7 +18,7 @@ if($_GET['type'] == 'upload'){
|
||||
|
||||
//取后缀并判断是否支持
|
||||
$suffix = strtolower(end(explode('.',$_FILES["file"]["name"])));
|
||||
if(!preg_match('/^(db3|html)$/i',$suffix)){
|
||||
if(!preg_match('/^(db3|html|itabdata)$/i',$suffix)){
|
||||
@unlink($_FILES["file"]["tmp_name"]);
|
||||
msg(-1,'文件格式不被支持!');
|
||||
}
|
||||
@@ -384,6 +384,87 @@ if($_GET['type'] == 'upload'){
|
||||
}
|
||||
}
|
||||
msg(-1,'导入失败.');
|
||||
|
||||
}elseif($_GET['type'] == 'itabdata'){
|
||||
$temp_path = $_SESSION['upload_bookmark'][UID][$sid];
|
||||
$content = file_get_contents($temp_path);
|
||||
$data = json_decode($content, true);
|
||||
if(!isset($data['navConfig']) || empty($data['navConfig'])){
|
||||
msg(-1,'数据解析失败,请确认导入的是iTab备份的数据,且导出内容包含图标');
|
||||
}
|
||||
$time = time();
|
||||
$success = 0; $fail = 0; $total = 0;$res = '';
|
||||
$res='<table class="layui-table" lay-even><colgroup><col width="200"><col width="250"><col></colgroup><thead><tr><th>标题</th><th>URL</th><th>失败原因</th></tr></thead><tbody>';
|
||||
foreach($data['navConfig'] as $key => $category){
|
||||
if(!isset($category['children']) || empty($category['children'])){
|
||||
continue; //分类下没数据则跳过
|
||||
}
|
||||
//分类名称不错在时创建
|
||||
if(!has_db('user_categorys',['name'=>$category['name']]) ){
|
||||
insert_db('user_categorys',[
|
||||
'uid'=>UID,
|
||||
'cid'=>get_maxid('category_id'),
|
||||
'fid'=>0,
|
||||
'pid'=>0,
|
||||
'status'=>1,
|
||||
'property'=>1,
|
||||
'name'=>$category['name'],
|
||||
'add_time'=>$time,
|
||||
'up_time'=>$time,
|
||||
'weight'=>0,
|
||||
'description'=>'',
|
||||
'font_icon'=>'fa fa-user',
|
||||
'icon'=>''
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// 读取分类ID
|
||||
$category_id = get_db('user_categorys','cid',['uid'=>UID,'name'=>$category['name']]);
|
||||
if(empty($category_id)){
|
||||
msg(-1,'意外结束:创建或读取分类信息失败!');
|
||||
}
|
||||
$total += count($category['children']);
|
||||
//遍历链接
|
||||
foreach($category['children'] as $link){
|
||||
$id = get_db('user_links','id',['uid'=>UID,'url'=>$link['url'] ]);
|
||||
if(!empty($id)){
|
||||
$res=$res.'<tr><td>'.mb_substr($link['name'], 0, 30).'</td><td>'.mb_substr($link['url'], 0, 40).'</td><td>URL重复'.'</td></tr>';
|
||||
$fail++;
|
||||
continue;
|
||||
}
|
||||
if(empty($id) && strpos($link['url'], "http") === 0 ){
|
||||
insert_db('user_links',[
|
||||
'uid' => UID,
|
||||
'lid' => get_maxid('link_id'),
|
||||
'fid' => $category_id,
|
||||
'add_time' => $time,
|
||||
'up_time' => $time,
|
||||
'weight' => 0,
|
||||
'title' => $link['name'] ,
|
||||
'url' => $link['url'],
|
||||
'property' => 0,
|
||||
'icon' => '', // "{$link['src']}",
|
||||
'status' => 1
|
||||
]);
|
||||
$success++;
|
||||
}else{
|
||||
$res=$res.'<tr><td>'.mb_substr($link['name'], 0, 30).'</td><td>'.mb_substr($link['url'], 0, 40).'</td><td>'.$link['name'].' >> 不是链接'.'</td></tr>';
|
||||
$fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'code' => 1,
|
||||
'msg' => '总数:'.$total.' 成功:'.$success.' 失败:'.$fail,
|
||||
'res' => $res.'</tbody></table>',
|
||||
'fail' => $fail
|
||||
];
|
||||
//删除文件和变量
|
||||
unlink($temp_path);
|
||||
unset($_SESSION['upload_bookmark'][UID][$sid]);
|
||||
msgA($data);
|
||||
}elseif($_GET['type'] == 'data_empty'){
|
||||
//验证密码
|
||||
global $USER_DB;
|
||||
@@ -392,7 +473,7 @@ if($_GET['type'] == 'upload'){
|
||||
}
|
||||
//数据库清除
|
||||
if(!empty($_POST['TABLE'])){
|
||||
$TABLE = ["user_categorys","user_links","user_pwd_group","user_share","user_apply"];
|
||||
$TABLE = ["user_categorys","user_links","user_pwd_group","user_share","user_apply","user_article_list"];
|
||||
foreach($_POST['TABLE'] as $key =>$value){
|
||||
if(in_array($key,$TABLE)){
|
||||
delete_db($key,['uid'=>UID]);
|
||||
@@ -418,7 +499,7 @@ if($_GET['type'] == 'upload'){
|
||||
|
||||
//文件删除
|
||||
if(!empty($_POST['FILE'])){
|
||||
$FILE = ["MessageBoard","favicon"];
|
||||
$FILE = ["MessageBoard","favicon","upload"];
|
||||
foreach($_POST['FILE'] as $key =>$value){
|
||||
$path = DIR.'/data/user/'.U.'/'.$key;
|
||||
if(in_array($key,$FILE) && is_dir($path)){
|
||||
|
||||
@@ -4,344 +4,5 @@ if(!defined('DIR')){
|
||||
header("status: 404 Not Found");
|
||||
exit;
|
||||
}else{
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,"未检测到有效授权,无法使用该功能!");
|
||||
}
|
||||
|
||||
if($_GET['type'] == 'list'){
|
||||
$backup_dir = DIR."/data/backup/".U."/"; //备份目录
|
||||
$file_list = glob("{$backup_dir}*.info"); //扫描文件
|
||||
$num = count($file_list); //取列表数
|
||||
rsort($file_list,2); //按时间从大到小重排序
|
||||
//备份文件数大于20个时删除旧数据
|
||||
if( $num > 20 ) {
|
||||
for ($i=$num; $i > 20; $i--) {
|
||||
$path = pathinfo($file_list[$i-1]);
|
||||
$path = $path['dirname'] .'/'. $path['filename'];
|
||||
unlink($path.'.info');
|
||||
unlink($path.'.db3');
|
||||
unlink($path.'.tar');
|
||||
array_pop($file_list);
|
||||
}
|
||||
$count = 20;
|
||||
}else{
|
||||
$count = $num;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
//遍历读入备份信息
|
||||
foreach ($file_list as $key => $filePath) {
|
||||
$file = pathinfo($filePath);
|
||||
$info_file = @file_get_contents("{$file['dirname']}/{$file['filename']}.info");
|
||||
$info = json_decode($info_file,true);
|
||||
if($info != false){
|
||||
array_push($data,$info);
|
||||
}
|
||||
}
|
||||
msgA( ['code' => 1,'msg' => '','count' => $count,'data' => $data] );
|
||||
}elseif($_GET['type'] == 'backup'){
|
||||
//初始信息
|
||||
$info['user_dir'] = DIR."/data/user/".U;
|
||||
$info['backup_dir'] = DIR."/data/backup/".U; //备份目录
|
||||
$info['file'] = SysVer . "_".date("ymdHis",time())."_".Get_Rand_Str(5);
|
||||
$info['file_db'] = $info['backup_dir'] .'/'. $info['file'].'.db3';
|
||||
$info['file_info'] = $info['backup_dir'] .'/'. $info['file'].'.info';
|
||||
$info['file_gz'] = $info['backup_dir'] .'/'. $info['file'].'.tar';
|
||||
$info['table_arr'] = ['user_config','user_categorys','user_links','user_pwd_group','user_apply','user_share'];
|
||||
$info['lock'] = DIR.'/data/user/'.U.'/lock.'.UID;
|
||||
if (!extension_loaded('phar')) {
|
||||
msg(-1,'不支持phar扩展');
|
||||
}elseif(!is_dir($info['backup_dir']) && !mkdir($info['backup_dir'],0755,true) ){
|
||||
msg(-1,'创建backup目录失败');
|
||||
}elseif(!is_file($info['lock']) && !file_put_contents($info['lock'],'TwoNav')){
|
||||
msg(-1,'创建lock文件失败');
|
||||
}
|
||||
|
||||
//打包用户文件
|
||||
try {
|
||||
$phar = new PharData($info['file_gz']);
|
||||
$phar->buildFromDirectory($info['user_dir']);
|
||||
} catch (Exception $e) {
|
||||
msg(-1,'打包用户数据发生异常>'.$e->getMessage());
|
||||
}
|
||||
//创建数据
|
||||
try {
|
||||
$MyDB = new Medoo\Medoo(['type'=>'sqlite','database'=>$info['file_db']]);
|
||||
$MyDB->query('CREATE TABLE IF NOT EXISTS "backup" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"name" TEXT,"data" TEXT,CONSTRAINT "id" UNIQUE ("id" ASC));')->fetchAll();
|
||||
$MyDB->insert('backup',['name'=>'ver','data'=>SysVer]); //记系统版本
|
||||
$MyDB->insert('backup',['name'=>'backup_time','data'=>time()]); //记备份时间
|
||||
$MyDB->insert('backup',['name'=>'database_type','data'=>$GLOBALS['db_config']['type']]); //数据库类型
|
||||
}catch (Exception $e) {
|
||||
Amsg(-1,'创建备份数据库失败');
|
||||
}
|
||||
|
||||
//开始备份数据
|
||||
$table_info = [];
|
||||
foreach($info['table_arr'] as $table_name){
|
||||
$count = count_db($table_name,['uid'=>UID]); //总条数
|
||||
$limit = 100; //每页数量
|
||||
$pages= ceil($count/$limit); //总页数
|
||||
//分页逐条处理
|
||||
for ($page=1; $page<=$pages; $page++) {
|
||||
$where['uid'] = UID;
|
||||
$where['LIMIT'] = [($page - 1) * $limit,$limit];
|
||||
$datas = select_db($table_name,'*',$where);
|
||||
foreach($datas as $data){
|
||||
try {
|
||||
if(isset($data['id'])){
|
||||
unset($data['id']);
|
||||
}
|
||||
$MyDB->insert('backup',['name'=>$table_name,'data'=>$data]);
|
||||
}catch (Exception $e) {
|
||||
Amsg(-1,'插入数据时发生异常');
|
||||
}
|
||||
}
|
||||
}
|
||||
$table_info[$table_name] = ['count'=>$count,'pages'=>$pages];
|
||||
}
|
||||
|
||||
//备份信息
|
||||
$info['info'] = [
|
||||
"name" => $info['file'],
|
||||
"db_size" => filesize($info['file_db']),
|
||||
"db_md5" => md5_file($info['file_db']),
|
||||
"tar_size" => filesize($info['file_gz']),
|
||||
"tar_md5" => md5_file($info['file_gz']),
|
||||
"backup_time" => time(),
|
||||
"version" => SysVer,
|
||||
"desc" => "{$_POST['desc']}"
|
||||
];
|
||||
$info['info'] = array_merge($table_info,$info['info']);
|
||||
$info['info'] = json_encode($info['info']);
|
||||
//写到文件
|
||||
if(file_put_contents($info['file_info'], $info['info']) === false){
|
||||
msg(-1,'写备份信息失败');
|
||||
}
|
||||
msg(1,'备份成功');
|
||||
//删除备份
|
||||
}elseif($_GET['type'] == 'del'){
|
||||
$path = DIR."/data/backup/".U."/".$_POST['name'];
|
||||
if( !preg_match_all('/^v\d+\.\d+\.\d+-\d{8}_\d{12}_[A-Za-z0-9]{5}$/',$_POST['name']) ) {
|
||||
msg(-1,'数据库名称不合法');
|
||||
}elseif(!is_file($path.'.info')){
|
||||
msg(-1,'备份不存在');
|
||||
}elseif(!extension_loaded('phar')) {
|
||||
msg(-1,'不支持phar扩展');
|
||||
}
|
||||
try {
|
||||
unlink($path.'.info');
|
||||
unlink($path.'.db3');
|
||||
unlink($path.'.tar');
|
||||
msg(1,'备份数据库已被删除');
|
||||
} catch (\Throwable $th) {
|
||||
msg(-1,"删除失败,请检查目录权限");
|
||||
}
|
||||
//回滚备份
|
||||
}elseif($_GET['type'] == 'restore'){
|
||||
try {
|
||||
global $db;
|
||||
header('Content-Type:application/json; charset=utf-8');
|
||||
//使用事务来处理
|
||||
$db->action(function($db) {
|
||||
//检测是否符合回滚要求
|
||||
$path = DIR."/data/backup/".U."/".$_POST['name'];
|
||||
if( !preg_match_all('/^v\d+\.\d+\.\d+-\d{8}_\d{12}_[A-Za-z0-9]{5}$/',$_POST['name']) ) {
|
||||
msg(-1,'数据库名称不合法');
|
||||
}
|
||||
$info_file = @file_get_contents($path.'.info');
|
||||
$info = json_decode($info_file,true);
|
||||
if($info == false){
|
||||
msg(-1,'读取备份信息失败');
|
||||
}elseif($info['db_md5'] != md5_file($path.'.db3')){
|
||||
msg(-1,'db3文件效验失败');
|
||||
}elseif($info['tar_md5'] != md5_file($path.'.tar')){
|
||||
msg(-1,'tar文件效验失败');
|
||||
}
|
||||
|
||||
//载入数据库
|
||||
try {
|
||||
$MyDB = new Medoo\Medoo(['type'=>'sqlite','database'=>$path.'.db3']);
|
||||
}catch (Exception $e) {
|
||||
msg(-1,'载入备份数据库失败');
|
||||
return false;
|
||||
}
|
||||
|
||||
//遍历删除用户数据
|
||||
$info['table_arr'] = ['user_config','user_categorys','user_links','user_pwd_group','user_apply','user_share'];
|
||||
foreach($info['table_arr'] as $table_name){
|
||||
|
||||
//删除数据
|
||||
delete_db($table_name,['uid'=>UID]);
|
||||
|
||||
//确保数据已删除
|
||||
if($db->has($table_name,['uid'=>UID])){
|
||||
msg(-1,'del ' . $table_name . ' fail');
|
||||
}
|
||||
|
||||
//读取条数,分页逐条导入
|
||||
$count = $MyDB->count('backup',['name'=>$table_name]); //总条数
|
||||
$limit = 100; //每页数量
|
||||
$pages= ceil($count/$limit); //总页数
|
||||
for ($page=1; $page<=$pages; $page++) {
|
||||
$where['name'] = $table_name;
|
||||
$where['LIMIT'] = [($page - 1) * $limit,$limit];
|
||||
$datas = $MyDB->select('backup','data',$where);
|
||||
foreach($datas as $data){
|
||||
$data = unserialize($data);
|
||||
if(isset($data['id'])){
|
||||
unset($data['id']);
|
||||
}
|
||||
$data['uid'] = UID;
|
||||
insert_db($table_name,$data);
|
||||
}
|
||||
}
|
||||
|
||||
//确保数据已导入
|
||||
if($count != count_db($table_name,['uid'=>UID])){
|
||||
msg(-1,'restore ' . $table_name . ' fail');
|
||||
}
|
||||
}
|
||||
|
||||
//删除用户目录
|
||||
$user_dir = DIR."/data/user/".U;
|
||||
if(is_dir($user_dir) && !deldir($user_dir)){
|
||||
msg(-1,'删除用户目录失败');
|
||||
}
|
||||
//创建用户目录
|
||||
if(!is_dir($user_dir) && !mkdir($user_dir,0755,true)){
|
||||
msg(-1,'创建用户目录失败');
|
||||
}
|
||||
//回滚用户目录
|
||||
try {
|
||||
$phar = new PharData($path.'.tar');
|
||||
$phar->extractTo($user_dir, null, true);
|
||||
} catch (Exception $e) {
|
||||
msg(-1,'回滚用户数据失败');
|
||||
}
|
||||
//返回信息,直接msg会导致回滚
|
||||
header('Content-Type:application/json; charset=utf-8');
|
||||
echo(json_encode(['code'=>1,'msg'=>'回滚成功']));
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
msg(-1,"回滚失败");
|
||||
}
|
||||
//导出密码验证
|
||||
}elseif($_GET['type'] == 'create'){
|
||||
global $USER_DB;
|
||||
$pwd = Get_MD5_Password($_POST['pwd'],$USER_DB["RegTime"]) === $USER_DB["Password"];
|
||||
if(!$pwd){
|
||||
msg(-1,'密码错误');
|
||||
}elseif(empty($_POST['name'])){
|
||||
msg(-1,'文件名不能为空');
|
||||
}elseif(!extension_loaded('phar')) {
|
||||
msg(-1,'不支持phar扩展');
|
||||
}
|
||||
|
||||
$path = DIR."/data/backup/".U."/".$_POST['name'];
|
||||
if(!is_file($path.'.info')){
|
||||
msg(-1,'info文件不存在');
|
||||
}elseif(!is_file($path.'.db3')){
|
||||
msg(-1,'db3文件不存在');
|
||||
}elseif(!is_file($path.'.tar')){
|
||||
msg(-1,'tar文件不存在');
|
||||
}
|
||||
|
||||
session_start();
|
||||
$key = md5(uniqid().Get_Rand_Str(8));
|
||||
try {
|
||||
$temp_dir = DIR."/data/temp/{$key}";
|
||||
if(!is_dir($temp_dir) && !mkdir($temp_dir,0755,true)){
|
||||
msg(-1,'创建临时目录失败');
|
||||
}
|
||||
copy($path.'.info',"{$temp_dir}/{$_POST['name']}.info");
|
||||
copy($path.'.db3',"{$temp_dir}/{$_POST['name']}.db3");
|
||||
copy($path.'.tar',"{$temp_dir}/{$_POST['name']}.tar");
|
||||
$backup_path = "{$temp_dir}/TwoNav_{$_POST['name']}.tar";
|
||||
$phar = new PharData($backup_path);
|
||||
$phar->buildFromDirectory($temp_dir);
|
||||
$phar->compress(Phar::GZ);
|
||||
$backup_path .= ".gz";
|
||||
if(!is_file($backup_path)){
|
||||
msg(-1,'打包数据失败');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
msg(-1,'压缩数据异常');
|
||||
}
|
||||
$_SESSION['download'][$key] = $backup_path;
|
||||
msgA(['code'=>1,'msg'=>'success','key'=>$key]);
|
||||
//下载备份数据
|
||||
}elseif($_GET['type'] == 'download'){
|
||||
session_start();
|
||||
if(empty($_GET['key']) || !isset($_SESSION['download'][$_GET['key']])){
|
||||
msg(-1,'Key不存在,请重新导出');
|
||||
}
|
||||
$path = $_SESSION['download'][$_GET['key']];
|
||||
if(!is_file($path)){
|
||||
msg(-1,'文件不存在,请重新导出');
|
||||
}
|
||||
|
||||
$filename = pathinfo($path,PATHINFO_BASENAME);
|
||||
header("Cache-Control: public");
|
||||
header("Content-Description: File Transfer");
|
||||
header('Content-disposition: attachment; filename='.$filename); //文件名
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
|
||||
header('Content-Length: '. filesize($path)); //告诉浏览器,文件大小
|
||||
readfile($path); //返回文件
|
||||
unlink ($path);//删除临时文件
|
||||
unset($_SESSION['download'][$_GET['key']]); //删除Key
|
||||
deldir(DIR."/data/temp/{$_GET['key']}"); //删除临时目录
|
||||
//导入
|
||||
}elseif($_GET['type'] == 'local_import'){
|
||||
if (!extension_loaded('phar')) {
|
||||
msg(-1,'不支持phar扩展');
|
||||
}
|
||||
$key = md5(uniqid().Get_Rand_Str(8));
|
||||
$temp_dir = DIR."/data/temp/{$key}";
|
||||
if(!is_dir($temp_dir) && !mkdir($temp_dir,0755,true)){
|
||||
msg(-1,'创建临时目录失败');
|
||||
}
|
||||
//解压数据
|
||||
try {
|
||||
copy($_FILES['file']['tmp_name'],"{$temp_dir}/{$_FILES['file']['name']}");
|
||||
$phar = new PharData("{$temp_dir}/{$_FILES['file']['name']}");
|
||||
$phar->extractTo($temp_dir, null, true);
|
||||
unlink("{$temp_dir}/{$_FILES['file']['name']}");
|
||||
} catch (Exception $e) {
|
||||
deldir($temp_dir);
|
||||
msg(-1,'解压数据失败');
|
||||
}
|
||||
//获取备份信息
|
||||
$file = glob("{$temp_dir}/*.info");
|
||||
if(count($file) != 1){
|
||||
deldir($temp_dir);
|
||||
msg(-1,'读取备份信息失败');
|
||||
}
|
||||
$file = pathinfo($file[0]);
|
||||
$info = @file_get_contents("{$temp_dir}/{$file['basename']}");
|
||||
$info = json_decode($info,true);
|
||||
if($info == false){
|
||||
deldir($temp_dir);
|
||||
msg(-1,'解析备份信息失败');
|
||||
}elseif($info['db_md5'] != md5_file("{$temp_dir}/{$info['name']}.db3")){
|
||||
deldir($temp_dir);
|
||||
msg(-1,'db3文件效验失败'.$info['db_md5']);
|
||||
}elseif($info['tar_md5'] != md5_file("{$temp_dir}/{$info['name']}.tar")){
|
||||
deldir($temp_dir);
|
||||
msg(-1,'tar文件效验失败');
|
||||
}
|
||||
//复制到用户数据
|
||||
try {
|
||||
$backup_dir = DIR."/data/backup/".U."/";
|
||||
copy("{$temp_dir}/{$info['name']}.info","{$backup_dir}{$info['name']}.info");
|
||||
copy("{$temp_dir}/{$info['name']}.db3", "{$backup_dir}{$info['name']}.db3");
|
||||
copy("{$temp_dir}/{$info['name']}.tar", "{$backup_dir}{$info['name']}.tar");
|
||||
deldir($temp_dir);
|
||||
msg(1,'导入成功');
|
||||
} catch (Exception $e) {
|
||||
deldir($temp_dir);
|
||||
msg(-1,'复制数据失败,请检查目录权限');
|
||||
}
|
||||
//结束
|
||||
}
|
||||
msg_tip();
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ if($_POST['step'] == 2){
|
||||
'add_time'=>$data['add_time'] ?? time(),
|
||||
'up_time'=>$data['up_time'] ?? time(),
|
||||
'weight'=>0,
|
||||
'description'=>htmlspecialchars($data['description'],ENT_QUOTES),
|
||||
'description'=>htmlspecialchars($data['description'],ENT_QUOTES) ?? '',
|
||||
'font_icon'=> strstr($data['Icon'],'fa') ? 'fa '.$data['Icon'] : 'fa fa-folder',
|
||||
'icon'=>''
|
||||
]
|
||||
@@ -149,7 +149,7 @@ if($_POST['step'] == 2){
|
||||
'title' => $data['title'],
|
||||
'url' => $data['url'],
|
||||
'url_standby' => empty($data['url_standby']) ? '': [$data['url_standby']] ,
|
||||
'description' => $data['description'],
|
||||
'description' => $data['description']?? '',
|
||||
'add_time' => $data['add_time'] ?? time(),
|
||||
'up_time' => $data['up_time'] ?? time(),
|
||||
'click' => $data['click'] ?? 0,
|
||||
|
||||
184
system/admin.php
@@ -1,21 +1,18 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}AccessControl();
|
||||
|
||||
//获取请求参数
|
||||
$page = trim($_GET['page']);
|
||||
|
||||
//layui版本路径,方便后期切换版本
|
||||
$layui['js'] = $libs.'/Layui/v2.6.8/layui.js';$layui['css'] = $libs.'/Layui/v2.6.8/css/layui.css';
|
||||
$Ver = !Debug?SysVer:SysVer.'.'.time();
|
||||
$LoginConfig = unserialize($USER_DB['LoginConfig']);
|
||||
define('offline',$global_config['offline'] == 1);
|
||||
define('is_login',is_login());
|
||||
$page = trim($_GET['page']); //获取请求参数
|
||||
$Ver = !Debug?SysVer:SysVer.'.'.time(); //版本
|
||||
$LoginConfig = unserialize($USER_DB['LoginConfig']); //登录配置
|
||||
define('offline',$global_config['offline'] == 1); //是否离线模式
|
||||
//未登录,载入登录提示页
|
||||
if(!is_login){
|
||||
require(DIR.'/templates/admin/page/LoginPrompt.php');
|
||||
exit;
|
||||
}//已登录,检查是否需要验证二级密码
|
||||
elseif(!empty($LoginConfig['Password2']) && !Check_Password2($LoginConfig)){
|
||||
require DIR.'/templates/admin/other/verify_pwd2.php';
|
||||
$c = 'verify';$_GET['c'] = 'pwd2';
|
||||
require DIR."/system/templates.php";
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -68,10 +65,15 @@ if($page == 'config_home'){
|
||||
$theme_config = empty($theme_config['config']) ? []:$theme_config['config'];
|
||||
|
||||
//读取用户主题配置
|
||||
if(!in_array($_GET['fn'],['home','login','register','transit','guide'])){
|
||||
if(!in_array($_GET['fn'],['home','login','register','transit','guide','article','verify','guestbook','apply'])){
|
||||
msg(-1,"参数错误");
|
||||
}
|
||||
$theme_config_db = get_db('user_config','v',['t'=>'theme_'.$_GET['fn'],'k'=>$theme,'uid'=>UID]);
|
||||
if(in_array($_GET['fn'],['guide','register'])){
|
||||
$theme_config_db = get_db('global_config','v',['k'=>"theme_{$_GET['fn']}_{$theme}"]);
|
||||
}else{
|
||||
$theme_config_db = get_db('user_config','v',['t'=>'theme_'.$_GET['fn'],'k'=>$theme,'uid'=>UID]);
|
||||
}
|
||||
|
||||
$theme_config_db = unserialize($theme_config_db);
|
||||
|
||||
//如果不为空则合并数据
|
||||
@@ -86,150 +88,6 @@ if($page == 'config_home'){
|
||||
exit;
|
||||
}
|
||||
|
||||
//主题设置页面
|
||||
if( $page == 'theme_home' || $page == 'theme_login' || $page == 'theme_transit' || $page == 'theme_register' || $page == 'theme_guide') {
|
||||
if(!check_purview('theme_in',1)){
|
||||
require(DIR.'/templates/admin/page/404.php');
|
||||
exit;
|
||||
}
|
||||
$fn = str_replace('theme_','',$page);
|
||||
$dirs = get_dir_list(DIR.'/templates/'.$fn);
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
$path = DIR.'/templates/'.$fn.'/'.$dir; //目录完整路径
|
||||
//没有信息文件则跳过
|
||||
if(!is_file($path.'/info.json') ) {continue;}
|
||||
//读取主题信息
|
||||
$themes[$dir]['info'] = json_decode(@file_get_contents($path.'/info.json'),true);
|
||||
//是否支持配置
|
||||
$themes[$dir]['info']['config'] = is_file($path.'/config.php') ? '1':'0';
|
||||
//预览图优先顺序:png>jpg>info>default
|
||||
if(is_file($path.'/screenshot.jpg')){
|
||||
$themes[$dir]['info']['screenshot'] = "./templates/$fn/$dir/screenshot.jpg";
|
||||
}elseif(is_file($path.'/screenshot.png')){
|
||||
$themes[$dir]['info']['screenshot'] = "./templates/$fn/$dir/screenshot.png";
|
||||
}elseif(empty($themes[$dir]['info']['screenshot'])){
|
||||
$themes[$dir]['info']['screenshot'] = "./templates/admin/static/42ed3ef2c4a50f6d.png";
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前主题
|
||||
require "./system/templates.php";
|
||||
|
||||
//在线主题处理
|
||||
if ( !$global_config['offline'] && $USER_DB['UserGroup'] === 'root'){
|
||||
|
||||
if(preg_match('/^v.+-(\d{8})$/i',SysVer,$matches)){
|
||||
$sysver = intval( $matches[1] );//取版本中的日期
|
||||
}else{
|
||||
exit("获取程序版本异常");
|
||||
}
|
||||
|
||||
//读取缓存
|
||||
$template = get_db('global_config','v',['k'=>$page.'_cache']);
|
||||
if(!empty($template)){
|
||||
$data = json_decode($template, true);
|
||||
}
|
||||
|
||||
//没有缓存 或 禁止缓存 或 缓存过时
|
||||
if(empty($template) || $_GET['cache'] === 'no' || time() - $data["time"] > 1800 ){
|
||||
$urls = [ "https://update.lm21.top/TwoNav/{$fn}_template.json"];
|
||||
}else{
|
||||
$cache = true;
|
||||
}
|
||||
|
||||
//远程获取
|
||||
foreach($urls as $url){
|
||||
$Res = ccurl($url,3);
|
||||
$data = json_decode($Res["content"], true);
|
||||
if($data["code"] == 200 ){ //如果获取成功
|
||||
$data["time"] = time(); //记录当前时间
|
||||
write_global_config($page.'_cache',json_encode($data),$fn.'_模板缓存');
|
||||
break; //跳出循环.
|
||||
}
|
||||
}
|
||||
//解析
|
||||
foreach($data["data"] as $key){
|
||||
$path = DIR.'/templates/'.$fn.'/'.$key["dir"];
|
||||
if( is_dir($path) ) { //本地存在
|
||||
$value = $key["dir"];
|
||||
//检查是否可以更新
|
||||
$update = str_replace('/','',$themes[$value]['info']['update']); //本地主题版本
|
||||
$update_new = str_replace('/','',$key["update"]); //远程主题版本
|
||||
if( $sysver >= intval($key["low"]) && $sysver <= intval($key["high"]) && $update < $update_new ){
|
||||
$themes[$value]['info']['up'] = '1';
|
||||
}
|
||||
}else{
|
||||
//判断是否适配当前系统版本
|
||||
if( $sysver >= intval($key["low"]) && $sysver <= intval($key["high"]) ){
|
||||
$value = $key["dir"];
|
||||
$themes[$value]['info'] = json_decode(json_encode($key),true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//来源策略 (用于Gitee作为图床反防盗链)
|
||||
if(!empty($data['referrer'])){
|
||||
define('referrer',$data['referrer']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//菜单接口
|
||||
if ($page == 'menu') {
|
||||
$menu = [];
|
||||
if(check_purview('site_info',1)){
|
||||
array_push($menu,['title'=>'站点设置','href'=>'SiteSetting','icon'=>'fa fa-cog']);
|
||||
}
|
||||
if(check_purview('theme_in',1)){
|
||||
array_push($menu,['title'=>'主题设置','href'=>'theme_home','icon'=>'fa fa-magic']);
|
||||
}
|
||||
array_push($menu,
|
||||
['title'=>'分类管理','href'=>'category_list','icon'=>'fa fa-list-ul'],
|
||||
['title'=>'加密管理','href'=>'pwd_group','icon'=>'fa fa-lock'],
|
||||
['title'=>'链接管理','icon'=>'fa fa-folder-open-o','href'=>'','child'=>
|
||||
[
|
||||
['title'=>'链接列表','href'=>'link_list','icon'=>'fa fa-link'],
|
||||
['title'=>'添加链接','href'=>'link_add','icon'=>'fa fa-plus-square-o'],
|
||||
['title'=>'书签分享','href'=>'share','icon'=>'fa fa-external-link'],
|
||||
['title'=>'导出导入','href'=>'data_control','icon'=>'fa fa-retweet'],
|
||||
]
|
||||
]);
|
||||
|
||||
//扩展功能
|
||||
$extend = [];
|
||||
if($global_config['apply'] == 1 && check_purview('apply',1)){
|
||||
array_push($extend,['title'=>'收录管理','href'=>'expand/apply-admin','icon'=>'fa fa-pencil']);
|
||||
}
|
||||
if($global_config['guestbook'] == 1 && check_purview('guestbook',1)){
|
||||
array_push($extend,['title'=>'留言管理','href'=>'expand/guestbook-admin','icon'=>'fa fa-commenting-o']);
|
||||
}
|
||||
|
||||
if(!empty($extend)){
|
||||
$extend = ['title'=>'扩展功能','icon'=>'fa fa-folder-open-o','href'=>'','child'=> $extend];
|
||||
array_push($menu,$extend);
|
||||
}
|
||||
|
||||
//如果是管理员则追加菜单
|
||||
if($USER_DB['UserGroup'] == 'root'){
|
||||
array_push($menu,
|
||||
['title'=>'网站管理','icon'=>'fa fa-wrench','href'=>'','child'=>
|
||||
[
|
||||
['title'=>'系统设置','href'=>'root/sys_setting','icon'=>'fa fa-gears'],
|
||||
['title'=>'授权管理','href'=>'root/vip','icon'=>'fa fa-diamond'],
|
||||
['title'=>'默认设置','href'=>'root/default_setting','icon'=>'fa fa-heart-o'],
|
||||
['title'=>'用户管理','href'=>'root/user_control','icon'=>'fa fa-user'],
|
||||
['title'=>'用户分组','href'=>'root/users_control','icon'=>'fa fa-users'],
|
||||
['title'=>'注册管理','href'=>'root/reg_control','icon'=>'fa fa-user-plus'],
|
||||
['title'=>'站长工具','href'=>'root/tool','icon'=>'fa fa-exclamation-triangle'],
|
||||
]
|
||||
]);
|
||||
}
|
||||
$init = array( 'homeInfo'=>['title'=>'概要','href'=>'home'],'logoInfo'=>['title'=>'TwoNav','image'=>'./templates/admin/img/logo.png','href'=>'./?u='.U],'menuInfo'=>$menu);
|
||||
header('Content-Type:application/json; charset=utf-8');
|
||||
exit(json_encode($init));
|
||||
}
|
||||
|
||||
//不带参数是载入框架
|
||||
if(empty($page)){
|
||||
$site = unserialize(get_db('user_config','v',['uid'=>UID,'k'=>'s_site']));
|
||||
@@ -238,6 +96,13 @@ if(empty($page)){
|
||||
exit;
|
||||
}
|
||||
|
||||
// 插件编辑链接跳转
|
||||
if($page === 'edit_link' && !empty($_GET['id'])){
|
||||
header("HTTP/1.1 302 Moved Permanently");
|
||||
header("Location: ./index.php?c=admin&page=link_edit&u=".U."&id=".$_GET['id']);
|
||||
exit;
|
||||
}
|
||||
|
||||
//页面文件不存在时载入404
|
||||
if(!empty($page)){
|
||||
if(!is_file(DIR.'/templates/admin/page/'.$page.'.php')){
|
||||
@@ -253,18 +118,19 @@ if(!empty($page)){
|
||||
function load_static($type){
|
||||
if($type == 'css'){
|
||||
echo
|
||||
'<link rel="stylesheet" href="'.$GLOBALS['libs'].'/Layui/v2.6.8/css/layui.css" media="all">
|
||||
'<link rel="stylesheet" href="'.$GLOBALS['layui']['css'].'" media="all">
|
||||
<link rel="stylesheet" href="./templates/admin/css/public.css?v='.$GLOBALS['Ver'].'" media="all">
|
||||
';
|
||||
}elseif($type == 'js'){
|
||||
echo
|
||||
'<script src="'.$GLOBALS['libs'].'/Layui/v2.6.8/layui.js" charset="utf-8"></script>
|
||||
'<script src="'.$GLOBALS['layui']['js'].'" charset="utf-8"></script>
|
||||
<script src="./templates/admin/js/lay-config.js?v='.$GLOBALS['Ver'].'" charset="utf-8"></script>
|
||||
<script>layui.config({version:"'.$GLOBALS['Ver'].'"})</script>
|
||||
';
|
||||
}elseif($type == 'js.layui'){
|
||||
echo
|
||||
'<script src="'.$GLOBALS['libs'].'/Layui/v2.6.8/layui.js" charset="utf-8"></script>
|
||||
'<script src="'.$GLOBALS['layui']['js'].'" charset="utf-8"></script>
|
||||
<script src="./templates/admin/js/lay-config.js?v='.$GLOBALS['Ver'].'" charset="utf-8"></script>
|
||||
<script>layui.config({version:"'.$GLOBALS['Ver'].'"})</script>
|
||||
';
|
||||
}
|
||||
|
||||
919
system/api.php
20
system/api_article.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
|
||||
$type = htmlspecialchars(trim($_GET['type']),ENT_QUOTES);
|
||||
|
||||
if (function_exists($type) ) {
|
||||
if($GLOBALS['global_config']['article'] < 1 || !check_purview('article',1)){
|
||||
msg_tip();
|
||||
}
|
||||
$type();
|
||||
}else{
|
||||
Amsg(-1,'请求类型错误 >> '.$type);
|
||||
}
|
||||
|
||||
//获取文章列表
|
||||
function article_list(){
|
||||
msg_tip();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
|
||||
if ( in_array($method,['link_list','get_a_link','q_category_link','category_list','get_a_category','check_login','add_link']) && function_exists($method) ) {
|
||||
if (function_exists($method)) {
|
||||
$method();
|
||||
}else{
|
||||
Amsg(-1,'方法未找到 >> '.$method);
|
||||
@@ -42,17 +42,83 @@ function add_link(){
|
||||
insert_db('user_links',$data);
|
||||
msgA(['code'=>0,'id'=>$lid]);
|
||||
}
|
||||
|
||||
//编辑链接
|
||||
function edit_link(){
|
||||
$lid = intval(@$_POST['id']);
|
||||
$fid = intval(@$_POST['fid']);
|
||||
$title = $_POST['title'];
|
||||
$url = $_POST['url'];
|
||||
$description = empty($_POST['description']) ? '' : $_POST['description'];
|
||||
$property = empty($_POST['property']) ? 0 : 1;
|
||||
//检测链接是否合法
|
||||
check_link($fid,$title,$url,'');
|
||||
//描述长度检测
|
||||
$length_limit = unserialize(get_db("global_config","v",["k"=>"length_limit"]));
|
||||
if($length_limit['l_desc'] > 0 && strlen($description) > $length_limit['l_desc'] ){
|
||||
msg(-1,'描述长度不能大于'.$length_limit['l_desc'].'个字节');
|
||||
}
|
||||
//关键字长度检测
|
||||
if($length_limit['l_key'] > 0 && strlen($keywords) > $length_limit['l_key'] ){
|
||||
msg(-1,'关键字长度不能大于'.$length_limit['l_key'].'个字节');
|
||||
}
|
||||
//检查链接是否已存在
|
||||
if(has_db('user_links',['uid'=>UID ,'lid[!]'=>$lid, "url" => $url])){msg(-1011,'链接已存在!');}
|
||||
//检查链接ID是否存在
|
||||
if(!has_db('user_links',['uid'=>UID ,'lid'=>$lid])){msg(-1012,'链接ID不存在!');}
|
||||
$data = [
|
||||
'fid' => $fid,
|
||||
'title' => htmlspecialchars($title,ENT_QUOTES),
|
||||
'url' => $url,
|
||||
'description' => htmlspecialchars($description,ENT_QUOTES),
|
||||
'up_time' => time(),
|
||||
'property' => $property
|
||||
];
|
||||
|
||||
//更新数据
|
||||
update_db('user_links',$data,['uid'=>UID,'lid'=>$lid ]);
|
||||
msgA(['code'=>0,'msg'=>'successful']);
|
||||
}
|
||||
|
||||
|
||||
//删除链接
|
||||
function del_link(){
|
||||
$lid = intval(trim($_REQUEST['id']));
|
||||
if(empty($lid)){
|
||||
msg(-1010,'链接ID不能为空');
|
||||
}
|
||||
$where['lid'] = $lid;
|
||||
$where['uid'] = UID;
|
||||
if(!has_db('user_links',$where)){
|
||||
msg(-1010,'链接id不存在');
|
||||
}
|
||||
delete_db('user_links',$where,[0,'删除成功']);
|
||||
}
|
||||
|
||||
//搜索链接
|
||||
function global_search(){
|
||||
$keyword = htmlspecialchars($_REQUEST['keyword']);
|
||||
if( strlen($keyword) < 2 ) {
|
||||
msg(-2000,'关键字的长度太短');
|
||||
}elseif( strlen($keyword) > 32 ) {
|
||||
msg(-2000,'关键字长度过长');
|
||||
}
|
||||
$where['uid'] = UID;
|
||||
$where['status'] = 1;
|
||||
$where['AND']['OR'] = ["title[~]" => $keyword,"url[~]" => $keyword, "url_standby[~]" => $keyword,"description[~]" => $keyword];
|
||||
$where['ORDER'] = ['weight'=>'DESC'];
|
||||
$field = ['lid(id)','fid','status','property','title','url','url_standby','weight','description','click','add_time','up_time'];
|
||||
$datas = select_db('user_links',$field,$where);
|
||||
links_add_category_field($datas); //添加分类信息
|
||||
msgA(['code'=>0,'msg'=>'获取成功','count'=>count($datas),'data'=>$datas]);
|
||||
}
|
||||
//查询链接列表
|
||||
function link_list(){
|
||||
$page = empty(intval($_REQUEST['page'])) ? 1 : intval($_REQUEST['page']);
|
||||
$limit = empty(intval($_REQUEST['limit'])) ? 50 : intval($_REQUEST['limit']);
|
||||
$offset = ($page - 1) * $limit; //起始行号
|
||||
$where['uid'] = UID;
|
||||
$where['AND']['status'] = 1;
|
||||
if(Access_Type != 'all'){
|
||||
$where['property'] = 0;
|
||||
}
|
||||
|
||||
$where['status'] = 1;
|
||||
$count = count_db('user_links',$where); //统计条数
|
||||
//权重排序(数字小的排前面)
|
||||
$where['ORDER']['weight'] = 'ASC';
|
||||
@@ -61,6 +127,7 @@ function link_list(){
|
||||
$where['LIMIT'] = [$offset,$limit];
|
||||
//查询
|
||||
$datas = select_db('user_links',['lid(id)','fid','property','title','url','url_standby','weight','description','icon','click','add_time','up_time'],$where);
|
||||
links_add_category_field($datas); //添加分类信息
|
||||
msgA(['code'=>0,'msg'=>'获取成功','count'=>$count,'data'=>$datas]);
|
||||
}
|
||||
//查询单个链接
|
||||
@@ -68,7 +135,6 @@ function get_a_link(){
|
||||
$lid = intval(trim($_REQUEST['id']));
|
||||
if(empty($lid)){
|
||||
msg(-1,'id不能为空');
|
||||
|
||||
}
|
||||
$where['lid'] = $lid;
|
||||
$where['uid'] = UID;
|
||||
@@ -76,11 +142,7 @@ function get_a_link(){
|
||||
if(empty($link_info)){
|
||||
msgA(['code'=>-1,'msg'=>'没有找到链接信息','data'=>[]]);
|
||||
}else{
|
||||
if(Access_Type == 'all' || $link_info['property'] == 0){
|
||||
msgA(['code'=>0,'data'=>$link_info]);
|
||||
}else{
|
||||
msgA(['code'=>-1,'msg'=>'私有链接,无权查看','data'=>[]]);
|
||||
}
|
||||
msgA(['code'=>0,'data'=>$link_info]);
|
||||
}
|
||||
}
|
||||
//查询指定分类的链接
|
||||
@@ -92,9 +154,6 @@ function q_category_link(){
|
||||
$where['uid'] = UID;
|
||||
$where['AND']['status'] = 1;
|
||||
$where['AND']['fid'] = $category_id;
|
||||
if(Access_Type != 'all'){
|
||||
$where['property'] = 0;
|
||||
}
|
||||
|
||||
$count = count_db('user_links',$where); //统计条数
|
||||
//权重排序(数字小的排前面)
|
||||
@@ -104,17 +163,120 @@ function q_category_link(){
|
||||
$where['LIMIT'] = [$offset,$limit];
|
||||
//查询
|
||||
$datas = select_db('user_links',['lid(id)','fid','property','title','url','url_standby','weight','description','icon','click','add_time','up_time'],$where);
|
||||
links_add_category_field($datas); //添加分类信息
|
||||
|
||||
|
||||
msgA(['code'=>0,'msg'=>'获取成功','count'=>$count,'data'=>$datas]);
|
||||
}
|
||||
//查询分类列表
|
||||
function category_list(){
|
||||
$where = ['uid'=>UID,'status'=>1,'ORDER' => ['weight'=>'ASC']];
|
||||
if(Access_Type != 'all'){
|
||||
$where['property'] = 0;
|
||||
}
|
||||
$datas = select_db('user_categorys',['cid(id)','fid','property','name','add_time','up_time','weight','description','font_icon'],$where);
|
||||
msgA(['code'=>0,'msg'=>'获取成功','count'=>count($datas),'data'=>$datas ]);
|
||||
}
|
||||
|
||||
//添加分类
|
||||
function add_category(){
|
||||
if(empty($_POST['name'])){
|
||||
msg(-1,'分类名称不能为空');
|
||||
}elseif(!preg_match('/^(fa fa-|layui-icon layui-icon-)([A-Za-z0-9]|-)+$/',$_POST['font_icon'])){
|
||||
$_POST['font_icon'] = 'fa fa-star-o';
|
||||
}
|
||||
//分类名查重
|
||||
if(get_db('user_categorys','cid',['uid'=>UID ,"name" => $_POST['name']])){
|
||||
msg(-1,'分类名称已存在');
|
||||
}
|
||||
//父分类不能是二级分类
|
||||
if(intval($_POST['fid']) !=0 && get_db('user_categorys','fid',['uid'=>UID ,"cid" => intval($_POST['fid']) ]) !=0 ){
|
||||
msg(-1,'父分类不能是二级分类');
|
||||
}
|
||||
|
||||
//长度检测
|
||||
$length_limit = unserialize(get_db("global_config","v",["k"=>"length_limit"]));
|
||||
if($length_limit['c_name'] > 0 && strlen($_POST['name']) > $length_limit['c_name'] ){
|
||||
msg(-1,'名称长度不能大于'.$length_limit['c_name'].'个字节');
|
||||
}
|
||||
if($length_limit['c_desc'] > 0 && strlen($_POST['description']) > $length_limit['c_desc'] ){
|
||||
msg(-1,'名称长度不能大于'.$length_limit['c_desc'].'个字节');
|
||||
}
|
||||
//取最大CID
|
||||
$cid = get_maxid('category_id');
|
||||
//插入数据库
|
||||
insert_db('user_categorys',[
|
||||
'uid'=>UID,
|
||||
'cid'=>$cid,
|
||||
'fid'=>intval($_POST['fid']??'0'),
|
||||
'pid'=>0,
|
||||
'status'=>1,
|
||||
'property'=>intval($_POST['property']??'0'),
|
||||
'name'=>htmlspecialchars($_POST['name'],ENT_QUOTES),
|
||||
'add_time'=>time(),
|
||||
'up_time'=>time(),
|
||||
'weight'=>$cid,
|
||||
'description'=>htmlspecialchars($_POST['description'],ENT_QUOTES),
|
||||
'font_icon'=>$_POST['font_icon'],
|
||||
'icon'=>''
|
||||
],[0,'添加成功']
|
||||
);
|
||||
}
|
||||
//编辑分类
|
||||
function edit_category(){
|
||||
if(empty($_POST['name'])){
|
||||
msg(-1,'分类名称不能为空');
|
||||
}elseif(!preg_match('/^(fa fa-|layui-icon layui-icon-)([A-Za-z0-9]|-)+$/',$_POST['font_icon'])){
|
||||
$_POST['font_icon'] = 'fa fa-star-o';
|
||||
}
|
||||
//父分类不能是自己
|
||||
if($_POST['id'] == $_POST['fid']){
|
||||
msg(-1,'父分类不能是自己');
|
||||
}
|
||||
//查CID是否存在
|
||||
if(!get_db('user_categorys','cid',['uid'=>UID ,"cid" => intval($_POST['id'])])){
|
||||
msg(-1,'分类不存在');
|
||||
}
|
||||
//分类名查重(排除自身)
|
||||
if(get_db('user_categorys','cid',['uid'=>UID,'cid[!]'=>intval($_POST['id']),"name" => $_POST['name']])){
|
||||
msg(-1,'分类名称已存在');
|
||||
}
|
||||
//父分类不能是二级分类
|
||||
if(intval($_POST['fid']) !=0 && get_db('user_categorys','fid',['uid'=>UID ,"cid" => intval($_POST['fid']) ]) !=0 ){
|
||||
msg(-1,'父分类不能是二级分类');
|
||||
}
|
||||
//分类下存在子分类,禁止修改父分类
|
||||
if( $_POST['fid']!=0 && count_db('user_categorys',['uid'=>UID,'fid'=>$_POST['id']])>0){
|
||||
msg(-1,'该分类下已存在子分类!');
|
||||
}
|
||||
//查父分类是否存在
|
||||
if( $_POST['fid'] !=0 && !get_db('user_categorys','cid',['uid'=>UID ,"cid" => intval($_POST['fid'])])){
|
||||
msg(-1,'父分类不存在');
|
||||
}
|
||||
//长度检测
|
||||
$length_limit = unserialize(get_db("global_config","v",["k"=>"length_limit"]));
|
||||
if($length_limit['c_name'] > 0 && strlen($_POST['name']) > $length_limit['c_name'] ){
|
||||
msg(-1,'名称长度不能大于'.$length_limit['c_name'].'个字节');
|
||||
}
|
||||
if($length_limit['c_desc'] > 0 && strlen($_POST['description']) > $length_limit['c_desc'] ){
|
||||
msg(-1,'名称长度不能大于'.$length_limit['c_desc'].'个字节');
|
||||
}
|
||||
|
||||
//更新数据
|
||||
$data = [
|
||||
'fid'=>$_POST['fid'],
|
||||
'property'=>intval($_POST['property']??'0'),
|
||||
'name'=>$_POST['name'],
|
||||
'up_time'=>time(),
|
||||
'description'=>$_POST['description']??'',
|
||||
'font_icon'=>$_POST['font_icon'],
|
||||
];
|
||||
if(!isset($_POST['fid'])){ //为空时不修改父id,避免二级变一级
|
||||
unset($data['fid']);
|
||||
}
|
||||
if(!isset($_POST['font_icon'])){
|
||||
unset($data['font_icon']);
|
||||
}
|
||||
update_db('user_categorys',$data,['uid'=>UID ,"cid"=>intval($_POST['id'])],[0,'successful']);
|
||||
}
|
||||
|
||||
//查询单个分类信息
|
||||
function get_a_category(){
|
||||
$cid = intval(trim($_REQUEST['id']));
|
||||
@@ -127,19 +289,34 @@ function get_a_category(){
|
||||
if(empty($category_info)){
|
||||
msgA(['code'=>-1,'msg'=>'没有找到分类信息','data'=>[]]);
|
||||
}else{
|
||||
if(Access_Type == 'all' || $category_info['property'] == 0){
|
||||
msgA(['code'=>0,'data'=>$category_info]);
|
||||
}else{
|
||||
msgA(['code'=>-1,'msg'=>'私有分类,无权查看','data'=>[]]);
|
||||
}
|
||||
msgA(['code'=>0,'data'=>$category_info]);
|
||||
}
|
||||
}
|
||||
|
||||
//是否已登录
|
||||
//获取TwoNav信息
|
||||
function app_info(){
|
||||
$data['php_version'] = floatval(PHP_VERSION);
|
||||
$data['onenav_version'] = 'v0.9.35-20240318'; //模拟版本号用于解决新版插件检测版本>1提示发生异常
|
||||
$data['twonav_version'] = SysVer;
|
||||
$data['cat_num'] = count_db('user_categorys',['uid'=>UID])??0;
|
||||
$data['link_num'] = count_db('user_links',['uid'=>UID])??0;
|
||||
$data['username'] = U;
|
||||
msgA(['code'=>200,'msg'=>'success','data'=>$data]);
|
||||
}
|
||||
|
||||
//是否已登录,由于上游已经拦截未登录状态,所以这里固定返回已登录
|
||||
function check_login(){
|
||||
if(Access_Type == 'open'){
|
||||
msgA(['code'=>-1002,'data'=>'false','err_msg'=>'Authorization failure!']);
|
||||
}else{
|
||||
msgA(['code'=>200,'data'=>'true','msg'=>'success']);
|
||||
msgA(['code'=>200,'data'=>'true','msg'=>'success']);
|
||||
}
|
||||
//给链接数组添加分类字段
|
||||
function links_add_category_field(&$arr){
|
||||
$where['uid'] = UID;
|
||||
$where['status'] = 1;
|
||||
$categorys = select_db('user_categorys',['cid(id)','name'],$where);
|
||||
$newCategorys = array_column($categorys,'name','id');
|
||||
foreach ($arr as &$data) {
|
||||
$data['category_name'] = $newCategorys[$data['fid']];
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,66 +33,52 @@ function other_upsys(){
|
||||
msg(-1,"文件夹不可写 >> $path");
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION['upsys']['sysver'] = intval($matches[1]);
|
||||
usleep(1000*300); //延迟300毫秒
|
||||
msg(1,'success');
|
||||
}
|
||||
//下载更新包
|
||||
if($_POST['i'] == 2){
|
||||
//检查授权状态
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,'未检测到有效授权,请
|
||||
<a href="https://gitee.com/tznb/TwoNav/wikis/pages?sort_id=7968669&doc_id=3767990" target="_blank" style="color: #01AAED;">购买授权</a>
|
||||
或
|
||||
<a href="https://gitee.com/tznb/TwoNav/wikis/pages?sort_id=8013447&doc_id=3767990" target="_blank" style="color: #01AAED;">手动更新</a>');
|
||||
}
|
||||
$subscribe = unserialize(get_db('global_config','v',["k" => "s_subscribe"]));
|
||||
if(!isset($subscribe['public']) || empty($subscribe['public'])){
|
||||
msg(-1,'
|
||||
错误原因: 未检测到授权秘钥<br />如何处理: <br />
|
||||
1. 转到<a href="./index.php?c=admin&u='.U.'#root/vip" target="_blank" style="color: #01AAED;">授权管理</a>页面点击保存设置<br />
|
||||
2. 提示保存成功后在尝试更新');
|
||||
}
|
||||
$_SESSION['upsys']['sysver'] = intval($matches[1]);
|
||||
usleep(1000*300); //延迟300毫秒
|
||||
msg(1,'success');
|
||||
}
|
||||
//下载更新包
|
||||
if($_POST['i'] == 2){
|
||||
//设置执行最长时间,0为无限制。单位秒!
|
||||
set_time_limit(5*60);
|
||||
//加载远程数据
|
||||
$urls = [ "https://update.lm21.top/TwoNav/updata.json"];
|
||||
foreach($urls as $url){
|
||||
$Res = ccurl($url,3);
|
||||
$data = json_decode($Res["content"], true);
|
||||
if($data["code"] == 200 ){ //如果获取成功
|
||||
break; //跳出循环.
|
||||
}
|
||||
}
|
||||
|
||||
$overtime = !isset($GLOBALS['global_config']['Update_Overtime']) ? 3 : ($GLOBALS['global_config']['Update_Overtime'] < 3 || $GLOBALS['global_config']['Update_Overtime'] > 60 ? 3 : $GLOBALS['global_config']['Update_Overtime']);
|
||||
|
||||
//请求获取更新包
|
||||
$node = intval($GLOBALS['global_config']['Update_Source']);
|
||||
$Res = ccurl("http://service.twonav.cn/service.php",30,true,data_encryption('updateSystem',['node'=>$node]));
|
||||
$data = json_decode($Res["content"], true);
|
||||
|
||||
if($data["code"] != '200'){
|
||||
msg(-1,'获取更新信息失败,请稍后再试..');
|
||||
msg(-1,$data['msg'] ?? '获取更新信息失败,请稍后再试..');
|
||||
}
|
||||
|
||||
foreach($data["data"] as $key){
|
||||
if( $_SESSION['upsys']['sysver'] >= $key["low"] && $_SESSION['upsys']['sysver'] <= $key["high"] && $key["update"] > $_SESSION['upsys']['sysver']){
|
||||
$file = "System_Upgrade.tar.gz";
|
||||
$filePath = "./data/temp/{$file}";
|
||||
$data = $key;
|
||||
break; //找到跳出
|
||||
}
|
||||
}
|
||||
if(empty($file)){
|
||||
msg(-1,'暂无可用更新');
|
||||
}
|
||||
$file = "System_Upgrade.tar.gz";
|
||||
$filePath = "./data/temp/{$file}";
|
||||
|
||||
//下载升级包
|
||||
unlink($filePath);
|
||||
foreach($data["url"] as $url){
|
||||
if(downFile($url,$file,'./data/temp/')){
|
||||
$file_md5 = md5_file($filePath);
|
||||
if($file_md5 === $data['md5']){
|
||||
break; //下载成功,跳出循环
|
||||
}else{
|
||||
unlink($filePath); //下载失败,删除文件
|
||||
}
|
||||
if(downFile($data['url'],$file,'./data/temp/')){
|
||||
$file_md5 = md5_file($filePath);
|
||||
if($file_md5 != $data['md5']){
|
||||
unlink($filePath);
|
||||
msg(-1,'更新包校验失败,请重试或联系客服');
|
||||
}
|
||||
}
|
||||
//检查下载结果
|
||||
if(empty($file_md5) ){
|
||||
}else{
|
||||
msg(-1,'下载更新包失败');
|
||||
}elseif($file_md5 != $data['md5']){
|
||||
msgA(['code'=>-1,'msg'=> '升级包效验失败','correct_md5'=> $data['md5'],'reality_md5'=>$file_md5]);
|
||||
}
|
||||
//sleep(1);
|
||||
msg(1,'success');
|
||||
}
|
||||
|
||||
@@ -118,10 +104,11 @@ function other_upsys(){
|
||||
|
||||
//检测是否需要更新数据库
|
||||
if($_POST['i'] == 4){
|
||||
clean_cache();
|
||||
set_time_limit(5*60);
|
||||
try {
|
||||
//根据数据库类型扫描不同目录,并声明执行SQL语句的函数
|
||||
if($GLOBALS['db_config']['type'] == 'mysql'){
|
||||
if($GLOBALS['db_config']['type'] == 'mysql' || $GLOBALS['db_config']['type'] == 'mariadb'){
|
||||
$dir = './system/MySQL';
|
||||
function exe_sql($content) {
|
||||
global $db;
|
||||
@@ -165,8 +152,6 @@ function other_upsys(){
|
||||
//查找数据库是否已安装更新
|
||||
if(empty(get_db('updatadb_logs','*',['file_name'=>$file_name]))){
|
||||
require $filePath; //载入升级脚本
|
||||
//脚本规范:头部判断是否有DIR常量来避免被直接访问,中间执行升级脚本!底部将执行记录写入数据库!
|
||||
//insert_db('updatadb_logs',['file_name'=>$file_name,'update_time'=>time(),'status'=>'TRUE','extra'=>'']);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
@@ -176,7 +161,6 @@ function other_upsys(){
|
||||
$updatadb_logs = select_db('updatadb_logs','file_name',['file_name[!]'=>'install.sql']);
|
||||
$msg .= "当前版本:" . SysVer . "\n";
|
||||
$msg .= "数据储存:{$GLOBALS['db_config']['type']}\n";
|
||||
//$msg .= "脚本列表:".(empty($file_list)?'无': "\n".implode("\n",$file_list))."\n" ;
|
||||
$msg .= "更新记录:".(empty($updatadb_logs)?'无':"\n".implode("\n",$updatadb_logs))."\n";
|
||||
msg(1,$msg);
|
||||
}else{
|
||||
@@ -189,6 +173,7 @@ function other_upsys(){
|
||||
msgA(['code'=>-1,'msg'=>'步骤错误']);
|
||||
}
|
||||
|
||||
|
||||
//读用户列表
|
||||
function read_user_list(){
|
||||
$query = $_POST['query'];
|
||||
@@ -248,258 +233,71 @@ function read_purview_list(){
|
||||
|
||||
//读用户组列表
|
||||
function read_users_list(){
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,'未检测到有效授权');
|
||||
}
|
||||
$purview_list = select_db('purview_list','name','');
|
||||
$datas = select_db('user_group',['id','name','allow','code','codes','uname'],'');
|
||||
foreach ($datas as $key => $data){
|
||||
$datas[$key]['codes'] = unserialize($datas[$key]['codes']);
|
||||
if(empty($datas[$key]['codes'])){
|
||||
$datas[$key]['disable'] = $purview_list;//为空表示全部
|
||||
}else{
|
||||
$datas[$key]['disable'] = array_diff($purview_list,explode(",", $data['allow']));
|
||||
}
|
||||
|
||||
$datas[$key]['disable'] = implode(',',$datas[$key]['disable']); //数组转文本
|
||||
}
|
||||
msgA(['code'=>1,'msg'=>'获取成功','count'=>count($datas),'data'=>$datas]);
|
||||
msg_tip();
|
||||
}
|
||||
|
||||
//写用户组
|
||||
function write_users(){
|
||||
//验证代号是否合规
|
||||
if(!preg_match('/^[A-Za-z0-9]+$/',$_POST['code'])){
|
||||
msg(-1,'分组代号只能是字母和数字');
|
||||
}elseif($_POST['code'] == 'root' || $_POST['code'] == 'default'){
|
||||
msg(-1,'不能使用系统预设的代号');
|
||||
}elseif(htmlspecialchars(trim($_POST['name'])) != $_POST['name']){
|
||||
msg(-1,'分组名称不能含有特殊字符');
|
||||
}
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,'未检测到有效授权');
|
||||
}
|
||||
$USER = $_POST['uname'];
|
||||
$USER_ID = '';
|
||||
if(!empty($USER)){
|
||||
$USER_ID = get_db("global_user", "ID", ["User"=>$USER]);
|
||||
if(empty($USER_ID)){msg(-1,'蓝图用户不存在');}
|
||||
}
|
||||
|
||||
if($_GET['type'] == 'add'){
|
||||
if(!empty(get_db('user_group','code',['code' => $_POST['code']]))){
|
||||
msg(-1,'分组代号已存在');
|
||||
}elseif(!empty(get_db('user_group','name',['name' => $_POST['name']]))){
|
||||
msg(-1,'分组名称已存在');
|
||||
}
|
||||
|
||||
insert_db('user_group',["uname"=>$USER,"uid"=>$USER_ID,"code"=>$_POST['code'],"name"=>$_POST['name'],"allow"=>$_POST['allow_list'],"codes"=>json_decode($_POST['allow_code_list'])],[1,'添加成功']);
|
||||
}elseif($_GET['type'] == 'edit'){
|
||||
if(empty(get_db('user_group','code',['code' => $_POST['code']]))){
|
||||
msg(-1,'此分组代号不存在');
|
||||
}elseif(!empty(get_db('user_group','name',['name' => $_POST['name'],'code[!]'=>$_POST['code']]))){
|
||||
msg(-1,'分组名称已存在');
|
||||
}
|
||||
update_db('user_group',["uname"=>$USER,"uid"=>$USER_ID,"name"=>$_POST['name'],'allow'=>$_POST['allow_list'],'codes'=>json_decode($_POST['allow_code_list']) ],['code'=>$_POST['code']],[1,'保存成功']);
|
||||
}elseif($_GET['type'] == 'del'){
|
||||
global $global_config;
|
||||
if(!empty(get_db('global_user','ID',['UserGroup' => $_POST['code']]))){
|
||||
msg(-1,'无法删除,有用户正在使用此用户组');
|
||||
}elseif(!empty(get_db('regcode_list','regcode',['u_group' => $_POST['code']]))){
|
||||
msg(-1,'无法删除,存在使用此用户组的注册码');
|
||||
}elseif($global_config['default_UserGroup'] == $_POST['code']){
|
||||
msg(-1,'无法删除,正在被使用:系统设置>默认分组');
|
||||
}
|
||||
delete_db('user_group',["code" => $_POST['code'] ],[1,'删除成功']);
|
||||
}
|
||||
msg_tip();
|
||||
}
|
||||
|
||||
|
||||
//写用户信息
|
||||
function write_user_info(){
|
||||
switch ($_GET['type']) {
|
||||
//删除
|
||||
case "Del":
|
||||
$uids = json_decode($_POST['ID']);
|
||||
$USER_S = select_db('global_user','User',['ID'=>$uids]);
|
||||
foreach($USER_S as $USER){
|
||||
if(is_dir(DIR.'/data/user/'.$USER)){
|
||||
deldir(DIR.'/data/user/'.$USER);
|
||||
if(is_dir(DIR.'/data/user/'.$USER)){
|
||||
msg(1,'删除用户数据目录失败,用户名:'.$USER);
|
||||
}
|
||||
}
|
||||
if(is_dir(DIR.'/data/backup/'.$USER)){
|
||||
deldir(DIR.'/data/backup/'.$USER);
|
||||
if(is_dir(DIR.'/data/backup/'.$USER)){
|
||||
msg(1,'删除用户备份目录失败,用户名:'.$USER);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (['regcode_list','user_categorys','user_config','user_count','user_links','user_log','user_login_info'] as $table){
|
||||
delete_db($table,[ "uid" => $uids ]);
|
||||
}
|
||||
delete_db('global_user',["ID" => $uids]);
|
||||
msg(1,'删除成功');
|
||||
break;
|
||||
//设用户组
|
||||
case "set_UserGroup":
|
||||
if(empty($_POST['UserGroup'])){
|
||||
msg(-1,'用户组不能为空');
|
||||
}elseif(!in_array($_POST['UserGroup'],['default','root']) && empty(get_db('user_group','code',['code' => $_POST['UserGroup']]))){
|
||||
msg(-1,'用户组不存在');
|
||||
}
|
||||
update_db('global_user',['UserGroup'=>$_POST['UserGroup']],["ID" => json_decode($_POST['ID']) ],[1,'修改成功']);
|
||||
break;
|
||||
//设密码
|
||||
case "set_pwd":
|
||||
if(!has_db('global_user',['ID'=>$_POST['ID']])){
|
||||
msg(-1,'用户不存在!');
|
||||
}
|
||||
//空字符串md5 防止意外出现空密码
|
||||
if( $_POST['new_pwd']== 'd41d8cd98f00b204e9800998ecf8427e'){
|
||||
msg(-1,'密码不能为空');
|
||||
}
|
||||
$RegTime = get_db('global_user','RegTime',['ID'=>$_POST['ID']]);
|
||||
update_db('global_user',['Password'=>Get_MD5_Password($_POST['new_pwd'],$RegTime)],["ID" => $_POST['ID'] ],[1,'修改成功']);
|
||||
break;
|
||||
//设邮箱
|
||||
case "set_email":
|
||||
if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$_POST['new_email'])){
|
||||
msg(-1,'邮箱错误!');
|
||||
}
|
||||
if(has_db('global_user',['Email'=>$_POST['new_email']])){
|
||||
msg(-1,'邮箱已存在!');
|
||||
}
|
||||
update_db('global_user',['Email'=>$_POST['new_email']],["ID" => $_POST['ID'] ],[1,'修改成功']);
|
||||
break;
|
||||
|
||||
default:
|
||||
msg(-1,'操作类型错误');
|
||||
}
|
||||
msg_tip();
|
||||
}
|
||||
|
||||
//读注册码列表
|
||||
function read_regcode_list(){
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,'未检测到有效授权');
|
||||
}
|
||||
$page = empty(intval($_REQUEST['page'])) ? 1 : intval($_REQUEST['page']);
|
||||
$limit = empty(intval($_REQUEST['limit'])) ? 50 : intval($_REQUEST['limit']);
|
||||
$offset = ($page - 1) * $limit; //起始行号
|
||||
$where = [];
|
||||
|
||||
//统计条数
|
||||
$count = count_db('regcode_list',$where);
|
||||
//分页
|
||||
$where['LIMIT'] = [$offset,$limit];
|
||||
//排序
|
||||
$where['ORDER']['id'] = 'DESC';
|
||||
//查询
|
||||
$datas = select_db('regcode_list','*',$where);
|
||||
//用户组处理
|
||||
if(!empty($datas)){
|
||||
$user_group = select_db('user_group',['name','code'],'');//读用户组
|
||||
$user_group = array_column($user_group, 'name', 'code');//以代号为键
|
||||
$user_group['root'] = '站长';
|
||||
$user_group['default'] = '默认';
|
||||
foreach ($datas as $key => $data){
|
||||
$datas[$key]['UserGroupName'] = $user_group[$data['u_group']]??'Null';
|
||||
}
|
||||
}
|
||||
msgA(['code'=>1,'msg'=>'获取成功','count'=>$count,'data'=>$datas]);
|
||||
msg_tip();
|
||||
}
|
||||
|
||||
//写注册码
|
||||
function write_regcode(){
|
||||
global $db;
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,'未检测到有效授权');
|
||||
}
|
||||
if($_GET['type'] == 'generate'){
|
||||
if(!in_array($_POST['group'] ,['default']) && empty(get_db('user_group','code',['code' => $_POST['group'] ]))){
|
||||
msg(-1,'用户组不存在');
|
||||
}
|
||||
|
||||
$t = time();
|
||||
for ($i=1; $i<=$_POST['number']??1; $i++){
|
||||
if($_POST['regcode_length'] == 8){
|
||||
$regcode = hash("crc32b",uniqid());
|
||||
}elseif($_POST['regcode_length'] == 36){
|
||||
$regcode = $db::raw("UUID()");
|
||||
}else{
|
||||
$regcode = md5(uniqid());
|
||||
}
|
||||
insert_db('regcode_list',["uid"=>UID,"regcode"=>$regcode,"u_group"=>$_POST['group'],"use_state"=>'未使用',"add_time"=>$t,"use_time"=>0]);
|
||||
}
|
||||
|
||||
msg(1,'注册码已生成');
|
||||
}elseif($_GET['type'] == 'set'){
|
||||
write_global_config('reg_tips',$_POST['content'],'注册提示');
|
||||
msg(1,'保存成功');
|
||||
}elseif($_GET['type'] == 'del'){
|
||||
delete_db("regcode_list",[ "id" => json_decode($_POST['id'])]);
|
||||
msg(1,'删除成功');
|
||||
}
|
||||
|
||||
msg(-1,'无效的请求类型');
|
||||
msg_tip();
|
||||
}
|
||||
|
||||
|
||||
//写订阅信息
|
||||
function write_subscribe(){
|
||||
global $USER_DB;
|
||||
$data['order_id'] = htmlspecialchars( trim($_REQUEST['order_id']) ); //获取订单ID
|
||||
$data['email'] = htmlspecialchars( trim($_REQUEST['email']) ); //获取邮箱
|
||||
$data['end_time'] = htmlspecialchars( trim($_REQUEST['end_time']) );//到期时间
|
||||
$data['domain'] = htmlspecialchars( trim($_REQUEST['domain']) );//支持域名
|
||||
$data['host'] = $_SERVER['HTTP_HOST']; //当前域名
|
||||
if(empty($data['order_id']) && empty($data['email']) && empty($data['end_time'])){
|
||||
write_global_config('s_subscribe','','订阅信息');
|
||||
msg(1,'清除成功');
|
||||
}
|
||||
if($data['end_time'] < time()){
|
||||
msg(-1,"您的订阅已过期!");
|
||||
}
|
||||
//判断是否为IP
|
||||
if(preg_match("/^(\d+\.\d+\.\d+\.\d+):*\d*$/",$data['host'],$host)) {
|
||||
$data['host'] = $host[1]; //取出IP(不含端口)
|
||||
}else{
|
||||
$host = explode(".", $data['host']);
|
||||
$count = count($host);
|
||||
if($count != 2){
|
||||
$data['host'] = $host[$count-2].'.'.$host[$count-1];
|
||||
//如果存在端口则去除
|
||||
if(preg_match("/(.+):\d+/",$data['host'],$host)) {
|
||||
$data['host'] = $host[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(stristr($data['domain'],$data['host'])){
|
||||
write_global_config('s_subscribe',$data,'订阅信息');
|
||||
msg(1,'保存成功');
|
||||
}else{
|
||||
msg(-1,"您的订阅不支持当前域名 >> ".$_SERVER['HTTP_HOST']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 写系统设置
|
||||
function write_sys_settings(){
|
||||
global $USER_DB;
|
||||
if($_POST['Login'] == $_POST['Register']){
|
||||
msg(-1,'注册入口名不能和登录入口名相同');
|
||||
}elseif(!preg_match("/^[a-zA-Z0-9]+$/",$_POST['Register'])){
|
||||
msg(-1,'注册入口错误,仅允许使用字母和数字');
|
||||
msg(-1,'注册入口错误,仅允许使用字母和数字');
|
||||
}elseif(!preg_match("/^[a-zA-Z0-9]+$/",$_POST['Login'])){
|
||||
msg(-1,'登陆入口错误,仅允许使用字母和数字');
|
||||
msg(-1,'登陆入口错误,仅允许使用字母和数字');
|
||||
}elseif(empty($_POST['Default_User']) || !get_db("global_user", "User", [ "User"=>$_POST['Default_User'] ]) ){
|
||||
msg(-1,'默认账号不存在');
|
||||
}elseif(!empty($_POST['default_UserGroup']) && empty(get_db('user_group','code',['code' => $_POST['default_UserGroup']]))){
|
||||
msg(-1,'默认分组代号不存在');
|
||||
}elseif($_POST['Sub_domain'] == 1){
|
||||
if(preg_match('/\.(com|net|org|gov|edu)\.cn$/', $_SERVER["HTTP_HOST"])){
|
||||
msg(-1,'不支持此类域名');
|
||||
}
|
||||
if(filter_var($_SERVER["HTTP_HOST"], FILTER_VALIDATE_IP) != false){
|
||||
msg(-1,'不支持IP访问开启二级域名');
|
||||
}
|
||||
if(preg_match('/\.(\d+|:\d+)$/', preg_replace('/:\d+$/','',$_SERVER['HTTP_HOST'])) || substr_count($_SERVER["HTTP_HOST"],':') > 2){
|
||||
msg(-1,'不支持IP访问开启二级域名,如有误判请联系技术支持!');
|
||||
}
|
||||
}
|
||||
|
||||
//自定义登录入口和注册入口检测
|
||||
$prohibits = ['admin','click','api','ico','icon','verify','apply','guestbook','article','sitemap'];
|
||||
if(in_array($_POST['Login'],$prohibits)){
|
||||
msg(-1,'此登录入口名已被系统使用');
|
||||
}
|
||||
if(in_array($_POST['Register'],$prohibits)){
|
||||
msg(-1,'此注册入口名已被系统使用');
|
||||
}
|
||||
//长度限制
|
||||
foreach (['c_name','c_desc','l_name','l_url','l_key','l_desc'] as $name){
|
||||
$length_limit[$name] = is_subscribe('bool') ? intval($_POST[$name]) : 0;
|
||||
}
|
||||
write_global_config("length_limit",$length_limit,'长度限制');
|
||||
|
||||
//全局配置
|
||||
$datas = [
|
||||
'Login'=>['empty'=>false,'msg'=>'登录入口不能为空'],
|
||||
'Register'=>['empty'=>false,'msg'=>'注册入口不能为空'],
|
||||
@@ -516,14 +314,19 @@ function write_sys_settings(){
|
||||
'Sub_domain'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'二级域名参数错误'],
|
||||
'Privacy'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'强制私有参数错误'],
|
||||
'default_page'=>['int'=>true,'min'=>0,'max'=>2,'msg'=>'默认页面参数错误'],
|
||||
'copyright'=>['empty'=>true],
|
||||
'global_header'=>['empty'=>true],
|
||||
'global_footer'=>['empty'=>true],
|
||||
'api_extend'=>['empty'=>true],
|
||||
'c_code'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'自定义代码参数错误'],
|
||||
'static_link'=>['int'=>true,'min'=>0,'max'=>2,'msg'=>'静态链接参数错误'],
|
||||
//更新设置
|
||||
'Update_Source'=>['empty'=>true],
|
||||
'Update_Overtime'=>['int'=>true,'min'=>3,'max'=>60,'msg'=>'资源超时参数错误'],
|
||||
//扩展功能-(全局开关)
|
||||
'apply'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'收录管理参数错误'],
|
||||
'guestbook'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'留言管理参数错误'],
|
||||
'link_extend'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'链接扩展参数错误'],
|
||||
'article'=>['int'=>true,'min'=>0,'max'=>2,'msg'=>'文章管理参数错误']
|
||||
];
|
||||
$o_config = [];
|
||||
foreach ($datas as $key => $data){
|
||||
@@ -541,67 +344,15 @@ function write_sys_settings(){
|
||||
if(!empty($_POST['copyright'])){$o_config['copyright'] = "";$filter = true;}
|
||||
if(!empty($_POST['global_header'])){$o_config['global_header'] = "";$filter = true;}
|
||||
if(!empty($_POST['global_footer'])){$o_config['global_footer'] = "";$filter = true;}
|
||||
if($_POST['apply'] == 1){$o_config['apply'] = 0;$filter = true;}
|
||||
if($_POST['guestbook'] == 1){$o_config['guestbook'] = 0;$filter = true;}
|
||||
if($_POST['link_extend'] == 1){$o_config['link_extend'] = 0;$filter = true;}
|
||||
if($_POST['static_link'] == 1){$o_config['static_link'] = 0;$filter = true;}
|
||||
}
|
||||
|
||||
update_db("global_config", ["v" => $o_config], ["k" => "o_config"],[1,($filter ?"保存成功,未检测到有效授权,带*号的配置无法为你保存":"保存成功")]);
|
||||
}
|
||||
|
||||
//写默认设置
|
||||
function write_default_settings(){
|
||||
global $USER_DB;
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,'未检测到有效授权');
|
||||
}
|
||||
if( $_POST['KeyClear'] > $_POST['Session']){
|
||||
msg(-1,'Key清理时间不能大于登录保持时间');
|
||||
}
|
||||
// 安全配置(登录配置)
|
||||
$datas = [
|
||||
'Session'=>['int'=>true,'min'=>0,'max'=>360,'msg'=>'登录保持参数错误'],
|
||||
'HttpOnly'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'HttpOnly参数错误'],
|
||||
'KeySecurity'=>['int'=>true,'min'=>0,'max'=>2,'msg'=>'Key安全参数错误'],
|
||||
'KeyClear'=>['int'=>true,'min'=>1,'max'=>60,'msg'=>'Key清理参数错误'],
|
||||
'api_model'=>['v'=>['security','compatible','compatible+open'],'msg'=>'API模式参数错误']
|
||||
];
|
||||
foreach ($datas as $key => $data){
|
||||
if($data['int']){
|
||||
$LoginConfig[$key] = ($_POST[$key] >= $data['min'] && $_POST[$key] <= $data['max'])?intval($_POST[$key]):msg(-1,$data['msg']);
|
||||
}elseif(isset($data['v'])){
|
||||
$LoginConfig[$key] = in_array($_POST[$key],$data['v']) ? $_POST[$key]:msg(-1,$data['msg']);
|
||||
}else{
|
||||
$LoginConfig[$key] = $data['empty']?$_POST[$key]:(!empty($_POST[$key])?$_POST[$key]:msg(-1,$data['msg']));
|
||||
}
|
||||
}
|
||||
$LoginConfig['Login'] = '0';
|
||||
$LoginConfig['Password2'] = '';
|
||||
update_db("global_config",["v"=>$LoginConfig],["k"=>'LoginConfig']);
|
||||
|
||||
//站点配置
|
||||
$datas = [
|
||||
'title'=>['empty'=>false,'msg'=>'主标题不能为空'],
|
||||
'subtitle'=>['empty'=>true],
|
||||
'logo'=>['empty'=>true],
|
||||
'keywords'=>['empty'=>true],
|
||||
'description'=>['empty'=>true],
|
||||
'link_model'=>['v'=>['direct','Privacy','302','Transition'],'msg'=>'链接模式参数错误'],
|
||||
'link_icon'=>['int'=>true,'min'=>0,'max'=>6,'msg'=>'链接图标参数错误'],
|
||||
'custom_header'=>['empty'=>true],
|
||||
'custom_footer'=>['empty'=>true]
|
||||
];
|
||||
$s_site = [];
|
||||
foreach ($datas as $key => $data){
|
||||
if($data['int']){
|
||||
$s_site[$key] = ($_POST[$key] >= $data['min'] && $_POST[$key] <= $data['max'])?intval($_POST[$key]):msg(-1,$data['msg']);
|
||||
}elseif(isset($data['v'])){
|
||||
$s_site[$key] = in_array($_POST[$key],$data['v']) ? $_POST[$key]:msg(-1,$data['msg']);
|
||||
}else{
|
||||
$s_site[$key] = $data['empty']?$_POST[$key]:(!empty($_POST[$key])?$_POST[$key]:msg(-1,$data['msg']));
|
||||
}
|
||||
}
|
||||
update_db("global_config",["v"=>$s_site],["k"=>'s_site'],[1,'保存成功']);
|
||||
msg_tip();
|
||||
}
|
||||
//读日志
|
||||
function read_log(){
|
||||
@@ -645,6 +396,7 @@ function other_root(){
|
||||
delfile($dir,30);
|
||||
$size = $_SESSION['CleanCacheSize'];
|
||||
unset($_SESSION['CleanCacheSize']);
|
||||
clean_cache();
|
||||
if($size == 0){
|
||||
msg(1,'暂无可清理缓存');
|
||||
}
|
||||
@@ -656,50 +408,138 @@ function other_root(){
|
||||
$data = get_db("global_config", "v", ["k" => "username_retain"]);
|
||||
msgA(['code'=>1,'msg'=>'获取成功','data'=>$data]);
|
||||
}elseif($_GET['type'] == 'write_username_retain'){
|
||||
//遍历检测语法
|
||||
$patterns = explode("\n",$_POST['username_retain']);
|
||||
foreach($patterns as $pattern){
|
||||
if (@preg_match($pattern, '') === false) {
|
||||
msg(-1,'正则表达式语法错误,请检查');
|
||||
}
|
||||
}
|
||||
if(!is_subscribe('bool')){
|
||||
msg(-1,'未检测到有效授权');
|
||||
}
|
||||
write_global_config('username_retain',$_POST['username_retain'],'账号保留');
|
||||
msg(1,'保存成功');
|
||||
msg_tip();
|
||||
}elseif($_GET['type'] == 'write_mail_config'){
|
||||
if($GLOBALS['global_config']['offline'] == '1'){msg(-1,"离线模式无法使用此功能");}
|
||||
if(!is_subscribe('bool')){msg(-1,"未检测到有效授权,无法使用该功能!");}
|
||||
//检测PHPMailer是否存在
|
||||
clearstatcache();
|
||||
if(!is_file(DIR.'/system/PHPMailer/PHPMailer.php')){
|
||||
$filePath = "./data/temp/PHPMailer_6.8.0.tar.gz";
|
||||
if(downFile('https://update.lm21.top/TwoNav/updata/PHPMailer_6.8.0.tar.gz','PHPMailer_6.8.0.tar.gz','./data/temp/')){
|
||||
$file_md5 = md5_file($filePath);
|
||||
if($file_md5 != "07251997fb7ebf3bf2d296d4214ccf0a"){
|
||||
unlink($filePath);
|
||||
msg(-1,'效验PHPMailer失败<br/>!');
|
||||
}
|
||||
}else{
|
||||
msg(-1,'下载PHPMailer失败,请重试!<br/>如需手动安装可联系技术支持!');
|
||||
}
|
||||
try {
|
||||
$phar = new PharData($filePath);
|
||||
$phar->extractTo('./system/', null, true);
|
||||
unlink($filePath);
|
||||
clearstatcache();
|
||||
} catch (Exception $e) {
|
||||
msg(-1,'安装PHPMailer失败');
|
||||
msg_tip();
|
||||
}elseif($_GET['type'] == 'write_mail_test'){
|
||||
msg_tip();
|
||||
}elseif($_GET['type'] == 'write_icon_config'){
|
||||
msg_tip();
|
||||
}elseif($_GET['type'] == 'write_icon_del_cache'){
|
||||
//删除数据库缓存信息
|
||||
if(empty(count_db('global_icon','*'))){
|
||||
msg(-1,'无缓存记录..');
|
||||
}
|
||||
delete_db('global_icon','*');
|
||||
|
||||
//删除缓存目录下的所有文件
|
||||
$files = glob(DIR.'/data/icon' . '/*');
|
||||
if (empty($files)) {
|
||||
msg(-1,'无缓存文件..');
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
write_global_config('mail_config',$_POST,'账号保留');
|
||||
msg(1,'保存成功');
|
||||
}elseif($_GET['type'] == 'write_mail_test'){
|
||||
$_POST['Subject'] = 'TwoNav 测试邮件' . time();
|
||||
$_POST['Body'] = '<h1>TwoNav 测试邮件</h1>' . date('Y-m-d H:i:s');
|
||||
send_email($_POST);
|
||||
|
||||
msg(1,'操作成功');
|
||||
}elseif($_GET['type'] == 'write_sitemap_config'){
|
||||
msg_tip();
|
||||
}
|
||||
}
|
||||
|
||||
// 通用类请求官方服务器
|
||||
function other_services(){
|
||||
// 生成请求数据
|
||||
$domain = preg_replace('/:\d+$/','',$_SERVER['HTTP_HOST']);
|
||||
$post = [
|
||||
'domain' => $domain,
|
||||
'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "",
|
||||
'email' => isset($_POST['email']) ? $_POST['email'] : "",
|
||||
'order_id' => isset($_POST['order_id']) ? $_POST['order_id'] : "",
|
||||
'sysver' => SysVer,
|
||||
'ip' => Get_IP(),
|
||||
'method' => $_GET['type'],
|
||||
'sys' => $_POST['sys']
|
||||
];
|
||||
$overtime = 30;
|
||||
// 判断操作类型
|
||||
if($_GET['type'] == 'query_key' || $_GET['type'] == 'save_key'){
|
||||
$Res = ccurl("http://service.twonav.cn/service.php",$overtime,true,$post);
|
||||
if($Res['code'] != 200){
|
||||
msg(-1,'请求官方服务器失败,请稍后再试');
|
||||
}
|
||||
$data = json_decode($Res["content"], true);
|
||||
$msg = $data['msg'];
|
||||
// 如果是保存设置
|
||||
if($_GET['type'] == 'save_key'){
|
||||
$data = $data['data'];
|
||||
if(!isset($data['order_id']) || empty($data['order_id'])){
|
||||
msg(-1,empty($msg) ? '保存失败,请核对信息是否有误<br />' : $msg);
|
||||
}
|
||||
//判断是否为IP
|
||||
if(preg_match("/^(\d+\.\d+\.\d+\.\d+):*\d*$/",$domain,$host)) {
|
||||
$data['host'] = $host[1]; //取出IP(不含端口)
|
||||
}else{
|
||||
$host = explode(".", $domain);
|
||||
$count = count($host);
|
||||
if($count != 2){
|
||||
$data['host'] = $host[$count-2].'.'.$host[$count-1];
|
||||
//如果存在端口则去除
|
||||
if(preg_match("/(.+):\d+/",$data['host'],$host)) {
|
||||
$data['host'] = $host[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
write_global_config('s_subscribe',$data,'订阅信息');
|
||||
clean_cache();
|
||||
msgA(['code'=>200,'msg'=>'保存成功','data'=>['order_id'=>$data['order_id'],'end_time'=>$data['end_time'],'type_name'=>$data['type_name']]]);
|
||||
}
|
||||
msgA($data);
|
||||
}elseif($_GET['type'] == 'del_key'){
|
||||
$subscribe = unserialize(get_db('global_config','v',["k" => "s_subscribe"]));
|
||||
if(!isset($subscribe['order_id']) || empty($subscribe['order_id'])){
|
||||
msg(200,'清除成功');
|
||||
}
|
||||
ccurl("http://service.twonav.cn/service.php",$overtime,true,$post);
|
||||
write_global_config('s_subscribe','','订阅信息');
|
||||
clean_cache();
|
||||
msg(200,'删除成功');
|
||||
}elseif($_GET['type'] == 'validate'){
|
||||
$Res = ccurl("http://service.twonav.cn/service.php",$overtime,true,data_encryption('validate'));
|
||||
$data = json_decode($Res["content"], true);
|
||||
if($data["code"] != '200'){
|
||||
msg(-1,$data['msg'] ?? '验证失败');
|
||||
}
|
||||
msgA($data);
|
||||
}elseif($_GET['type'] == 'get_notice'){
|
||||
//读取缓存数据
|
||||
$Notice = get_db('global_config','v',['k'=>'notice']);$data=[];
|
||||
//如果不为空,则解析数据
|
||||
if(!empty($Notice)){
|
||||
$data = json_decode($Notice, true);
|
||||
$cache_time = Debug ? 0 : 60; //缓存时间(秒);
|
||||
$reload = time() > $data["download_time"] + $cache_time; //是否更新
|
||||
}else{
|
||||
$reload = true; //需要刷新
|
||||
}
|
||||
if($GLOBALS['global_config']['offline'] == '1'){
|
||||
msgA(['code'=>200,'message'=>"已开启离线模式,无法获取最新动态/官方公告/下载模板/更新系统等。"]);
|
||||
}
|
||||
// 判断是否刷新数据
|
||||
if(!$global_config['offline'] && $reload){
|
||||
if(is_subscribe('bool')){
|
||||
$Res = ccurl('http://service.twonav.cn/service.php',$overtime,true,data_encryption('get_new_ver',['ver'=>SysVer]));
|
||||
}else{
|
||||
$Res = ccurl('http://gitee.com/tznb/TwoNav_Resource/raw/master/Notice.json',$overtime);
|
||||
}
|
||||
$new_data = json_decode($Res['content'], true);
|
||||
if($new_data["code"] == 200 ){
|
||||
$new_data['download_time'] = time();
|
||||
$new_data['version'] = version_compare($new_data['version'],SysVer,'<') ? SysVer : $new_data['version'];
|
||||
write_global_config('notice',json_encode($new_data),'官方公告(缓存)');
|
||||
write_global_config('sys_switch',"{$new_data['sys_switch']}",'sys_switch');
|
||||
$data = $new_data;
|
||||
}
|
||||
}
|
||||
//时间检测
|
||||
if(isset($_GET['t']) && !empty($_GET['t'])){
|
||||
if (abs( time() - $_GET['t'] ) > 300) {
|
||||
$data['message'] .= "<br /><span style=\"color: #ff5722;\" >检测到客户端时间与服务器时间存在较大差异<br />这会导致部分功能无法正常使用<br />请及时校对服务器或客户端时间</span>";
|
||||
}
|
||||
}
|
||||
msgA($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
90
system/auth.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
// 鉴权接口: 账号登录
|
||||
|
||||
//忽略GET/POST以外的请求
|
||||
if(!in_array($_SERVER['REQUEST_METHOD'],['GET','POST'])){
|
||||
exit;
|
||||
}
|
||||
if(!isset($auth_mode)){
|
||||
$auth_mode = $_GET['mode'];
|
||||
}
|
||||
|
||||
//账号登录
|
||||
if($auth_mode == 'uname'){
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
$log = ["uid" => '',"user"=>$username,"ip"=>Get_IP(),"time"=>time(),"type" => 'login',"content"=>Get_Request_Content(),"description"=>""];
|
||||
//密码长度
|
||||
if(strlen($password)!==32){
|
||||
$log['description'] = '请求登录>密码错误(长度应该是32位的MD5)';
|
||||
insert_db("user_log",$log);
|
||||
msg(-1,'账号或密码错误');
|
||||
}
|
||||
//浏览器UA
|
||||
if(strlen($_SERVER['HTTP_USER_AGENT']) > 1024){
|
||||
$log['description'] = '请求登录>浏览器UA长度>1024';
|
||||
insert_db("user_log",$log);
|
||||
msg(-1,"浏览器UA长度异常,请更换浏览器!");
|
||||
}
|
||||
//读取资料
|
||||
$USER_DB = get_db("global_user", "*", ["OR"=>['User'=>$username,'Email'=>$username]]);
|
||||
if(empty($USER_DB)){
|
||||
$log['description'] = '请求登录>账号不存在';
|
||||
insert_db("user_log",$log);
|
||||
msg(-1,'账号不存在');
|
||||
}
|
||||
$log['uid'] = $USER_DB['ID'];
|
||||
//登录入口
|
||||
session_start();
|
||||
if($_SESSION['login'] != $global_config["Login"] && $_SESSION['login'] != $USER_DB['Login'] ){
|
||||
$log['description'] = '请求登录>登录入口错误';
|
||||
insert_db("user_log",$log);
|
||||
msg(-1,"请求失败,请刷新登录页面再试");
|
||||
}
|
||||
//双重验证
|
||||
$LoginConfig = unserialize( $USER_DB['LoginConfig'] );
|
||||
if(!empty($LoginConfig['totp_key'])){
|
||||
if(empty($_POST['otp_code'])){
|
||||
msgA(['code'=>2]);
|
||||
}
|
||||
require DIR . '/system/Authenticator.php';
|
||||
$totp = new PHPGangsta_GoogleAuthenticator();
|
||||
$checkResult = $totp->verifyCode($LoginConfig['totp_key'], $_POST['otp_code'], 2);
|
||||
if(!$checkResult){
|
||||
$log['description'] = '请求登录>动态口令错误';
|
||||
insert_db("user_log",$log);
|
||||
msgA(['code'=>-1,'msg'=>'动态口令错误']);
|
||||
}
|
||||
}
|
||||
//验证密码
|
||||
if(Get_MD5_Password($password,$USER_DB["RegTime"]) === $USER_DB["Password"]){
|
||||
$log['description'] = '请求登录>登录成功';
|
||||
insert_db("user_log",$log);
|
||||
//保持登录
|
||||
$keep_login = isset($_POST['keep']) && $_POST['keep'] == 'on';
|
||||
if($keep_login == true){
|
||||
$LoginConfig['Session'] = ($LoginConfig['Session'] > 0 ? $LoginConfig['Session'] : 7 );
|
||||
}else{
|
||||
$LoginConfig['Session'] = 0;
|
||||
}
|
||||
$USER_DB['LoginConfig'] = serialize($LoginConfig);
|
||||
//设置Cookie
|
||||
Set_key($USER_DB);
|
||||
if(empty($LoginConfig['login_page']) || $LoginConfig['login_page'] == 'admin'){
|
||||
$url = "./?c=admin&u={$USER_DB['User']}";
|
||||
}elseif($LoginConfig['login_page'] == 'index'){
|
||||
$url = "./?c=index&u={$USER_DB['User']}";
|
||||
}else{
|
||||
$url = preg_match('/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i',$_SERVER['HTTP_USER_AGENT']) ? "./?c=index&u={$USER_DB['User']}" : "./?c=admin&u={$USER_DB['User']}";
|
||||
}
|
||||
//默认页面
|
||||
if(!empty($global_config['default_page'])){
|
||||
setcookie('Default_User', $USER_DB['User'], strtotime("+360 day"),"/",'',false,false);
|
||||
}
|
||||
msgA(['code'=>1,'msg'=>'登录成功','url'=>$url]);
|
||||
}else{
|
||||
$log['description'] = '请求登录>账户或密码错误';
|
||||
insert_db("user_log",$log);
|
||||
msg(-1,"账户或密码错误");
|
||||
}
|
||||
}
|
||||
109
system/click.php
@@ -1,9 +1,10 @@
|
||||
<?php if(!defined('DIR')){Not_Found();}AccessControl();
|
||||
//负责过渡页/跳转/隐私保护/密码访问
|
||||
$id = intval($_GET['id']);
|
||||
|
||||
//IP数统计
|
||||
count_ip();
|
||||
//如果id为空,则显示404
|
||||
if(empty($id)){Not_Found();}
|
||||
if(empty($id)) Not_Found();
|
||||
|
||||
//查询链接信息
|
||||
$where['lid'] = $id;
|
||||
@@ -12,18 +13,7 @@ $where['status'] = 1;
|
||||
$link = get_db('user_links','*',$where);
|
||||
|
||||
//查找失败时显示404
|
||||
if(empty($link)){Not_Found();}
|
||||
|
||||
//站点设置和站点图标
|
||||
$site = unserialize(get_db('user_config','v',['uid'=>UID,'k'=>'s_site']));
|
||||
$site['Title'] = $site['title'].(empty($site['subtitle'])?'':' - '.$site['subtitle']);
|
||||
//免费用户请保留版权,谢谢!
|
||||
$copyright = empty($global_config['copyright'])?'<a target="_blank" href="https://gitee.com/tznb/TwoNav">Copyright © TwoNav</a>':$global_config['copyright'];
|
||||
$ICP = empty($global_config['ICP'])?'':'<a target="_blank" href="https://beian.miit.gov.cn">'.$global_config['ICP'].'</a>';
|
||||
$favicon = ( !empty($site['site_icon_file'])) ? $site['site_icon'] : './favicon.ico';
|
||||
|
||||
//取登录状态
|
||||
$is_login = is_login();
|
||||
if(empty($link)) Not_Found();
|
||||
|
||||
//取父分类和祖分类信息
|
||||
$info_c = ['cid','fid','property','status','pid'];
|
||||
@@ -65,83 +55,49 @@ if(!$is_login){
|
||||
if($category_ancestor['property'] == 1 && !$pv){
|
||||
exit('很抱歉,页面所属的祖分类是私有的!您无权限查看,如果您是管理员,请先登录!');
|
||||
}
|
||||
|
||||
//判断链接是否加密
|
||||
if(!empty($link['pid'])){
|
||||
$verify_type = 'link_pwd';
|
||||
$password = get_db('user_pwd_group','password',['uid'=>UID,'pid'=>$link['pid']]);
|
||||
if($_SESSION['verify']['link'][$link['lid']] != $password){
|
||||
require DIR.'/templates/admin/other/verify_link_pwd.php';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
//判断父分类是否加密
|
||||
if(empty($link['pid']) && !empty($category_parent['pid'])){
|
||||
$verify_type = 'category_pwd';
|
||||
$password = get_db('user_pwd_group','password',['uid'=>UID,'pid'=>$category_parent['pid']]);
|
||||
if($_SESSION['verify']['category'][$category_parent['cid']] != $password){
|
||||
require DIR.'/templates/admin/other/verify_link_pwd.php';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
//判断祖分类是否加密
|
||||
if(empty($link['pid']) && empty($category_parent['pid']) && !empty($category_ancestor['pid'])){
|
||||
$verify_type = 'category_pwd';
|
||||
$password = get_db('user_pwd_group','password',['uid'=>UID,'pid'=>$category_ancestor['pid']]);
|
||||
if($_SESSION['verify']['category'][$category_ancestor['cid']] != $password){
|
||||
require DIR.'/templates/admin/other/verify_link_pwd.php';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//取模板信息
|
||||
require DIR ."/system/templates.php";
|
||||
$dir_path = DIR.'/templates/transit/'.$s_templates['transit'];
|
||||
$theme_dir = str_replace(DIR.'/templates/transit',"./templates/transit",$dir_path);
|
||||
$transit_path = $dir_path.'/index.php';
|
||||
//检查是否存在,不存在则使用默认
|
||||
if(!is_file($transit_path)){
|
||||
$transit_path= DIR.'/templates/transit/default/index.php';
|
||||
}
|
||||
|
||||
//统计点击数
|
||||
write_user_count(date('Ym'),'click_Ym');
|
||||
write_user_count(date('Ymd'),'click_Ymd');
|
||||
update_db("user_links", ["click[+]"=>1],['uid'=>UID,'lid'=>$id]);
|
||||
|
||||
//通用数据初始化
|
||||
require DIR."/system/templates.php";
|
||||
|
||||
//载入过渡页设置
|
||||
$transition_page = unserialize(get_db("user_config", "v", ["uid"=>UID,"k"=>"s_transition_page"]));
|
||||
|
||||
//读取用户主题配置
|
||||
$theme_config_db = unserialize(get_db('user_config','v',['t'=>'theme_transit','k'=>$s_templates['transit'],'uid'=>UID]));
|
||||
|
||||
//读取默认主题配置
|
||||
$theme_info = json_decode(@file_get_contents($dir_path.'/info.json'),true);
|
||||
$theme_config = empty($theme_info['config']) ? []:$theme_info['config'];
|
||||
$theme_ver = !Debug?$theme_info['version']:$theme_info['version'].'.'.time();
|
||||
|
||||
//合并配置数据
|
||||
$theme_config = empty($theme_config_db) ? $theme_config : array_merge ($theme_config??[],$theme_config_db??[]);
|
||||
|
||||
//如果主题信息声明支持扩展字段
|
||||
if($global_config['link_extend'] == 1 && check_purview('link_extend',1) && in_array($theme_info['support']['link_extend'],["true","1"])){
|
||||
$extend = empty($link['extend']) ? [] : unserialize($link['extend']);
|
||||
//关键字处理
|
||||
if(!empty($link['url_standby']) || $site['link_model'] == 'Transition'){
|
||||
if(empty($link['keywords'])){
|
||||
if($transition_page['default_keywords'] == '0'){
|
||||
$link['keywords'] = $link['title'];
|
||||
}else if($transition_page['default_keywords'] == '1'){
|
||||
$link['keywords'] = $site['keywords'];
|
||||
}else{
|
||||
$link['keywords'] = $link['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//如果存在备用链接,则强制载入过渡页
|
||||
if(!empty($link['url_standby'])) {
|
||||
$link['url_standby'] = unserialize($link['url_standby']);
|
||||
//主链优先模式
|
||||
if($site['main_link_priority'] == 1){
|
||||
$code = get_http_code($link['url'],3);
|
||||
if(in_array(intval($code),[200,301,302]) ){
|
||||
if($site['main_link_priority'] == '3'){
|
||||
$site['link_model'] = $site['link_model'] == 'direct' ? '302' : $site['link_model'];
|
||||
}elseif($site['main_link_priority'] > 0 && $site['link_model'] != 'Transition'){
|
||||
$code = get_http_code($link['url'],3,($site['main_link_priority'] == 1));
|
||||
if(in_array(intval($code),[200,301,302,401]) ){
|
||||
$site['link_model'] = $site['link_model'] == 'direct' ? '302' : $site['link_model'];
|
||||
}else{
|
||||
require $transit_path;
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
require $transit_path;
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -156,9 +112,11 @@ if ($site['link_model'] == '302'){ //302重定向(临时)
|
||||
exit;
|
||||
}elseif($site['link_model'] == 'Privacy'){ //隐私保护_header
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $link['url']) > 0){
|
||||
exit ('<html lang="zh-ch"><head><title>正在保护您的隐私..</title><meta name="referrer" content="same-origin"><script>window.location.href="'.$link['url'].'"</script></head>');
|
||||
}
|
||||
header("Refresh:0;url=".$link['url']);
|
||||
echo '<html lang="zh-ch"><head><title>正在保护您的隐私..</title><meta name="referrer" content="same-origin"></head>';
|
||||
exit;
|
||||
exit ('<html lang="zh-ch"><head><title>正在保护您的隐私..</title><meta name="referrer" content="same-origin"></head>');
|
||||
}elseif($site['link_model'] == 'Privacy_js'){ //隐私保护_js
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
echo '<html lang="zh-ch"><head><title>正在保护您的隐私..</title><meta name="referrer" content="same-origin"><script>window.location.href="'.$link['url'].'"</script></head>';
|
||||
@@ -168,11 +126,6 @@ if ($site['link_model'] == '302'){ //302重定向(临时)
|
||||
echo '<html lang="zh-ch"><head><title>正在保护您的隐私..</title><meta name="referrer" content="same-origin"><meta http-equiv="refresh" content="0;url='.$link['url'].'"></head>';
|
||||
exit;
|
||||
}else{ //Transition 过渡页
|
||||
require $transit_path;
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
|
||||
//返回404
|
||||
function Not_Found() {
|
||||
header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;
|
||||
}
|
||||
|
||||
@@ -1,130 +1,11 @@
|
||||
<?php
|
||||
$apply = $global_config['apply'];
|
||||
|
||||
// 如果管理了收录功能则返回404
|
||||
if ($apply != 1 ){
|
||||
load_tip();
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header("status: 404 Not Found");
|
||||
exit;
|
||||
}
|
||||
$apply = unserialize( get_db("user_config", "v", ["k" => "apply","uid"=>UID]));
|
||||
// 用户关闭收录申请
|
||||
if ( $apply['apply'] == 0 ){
|
||||
if($_SERVER['REQUEST_METHOD'] === 'GET'){
|
||||
load_tip();
|
||||
}else{
|
||||
msg(-1,"用户已关闭收录申请");
|
||||
}
|
||||
}
|
||||
//get请求载入页面
|
||||
if($_SERVER['REQUEST_METHOD'] === 'GET'){
|
||||
require DIR.'/templates/admin/page/expand/apply-user.php';
|
||||
exit;
|
||||
}
|
||||
//载入提示页
|
||||
function load_tip() {
|
||||
$content = '站长或用户未开启申请收录功能';
|
||||
require DIR.'/templates/admin/page/404.php';
|
||||
require DIR."/system/templates.php";
|
||||
require($index_path);
|
||||
exit;
|
||||
}
|
||||
|
||||
//强制加载防火墙来过滤相关攻击!
|
||||
$global_config['XSS_WAF'] = 1; $global_config['SQL_WAF'] = 1;
|
||||
require DIR.'/system/firewall.php';
|
||||
|
||||
// 遍历请求表单,拦截可疑内容!
|
||||
foreach($_POST as $key =>$value){
|
||||
if( htmlspecialchars($value,ENT_QUOTES) != $value ){
|
||||
msg(-1,$key.' > 请避免使用<\'&">单引号,双引号等特殊字符!');
|
||||
}elseif( strlen($value) >= 256 ){
|
||||
msg(-1,$key.' > 字符串长度不允许超过256');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$title = $_POST['title'];
|
||||
$url = $_POST['url'];
|
||||
$iconurl = $_POST['iconurl'];
|
||||
$description = $_POST['description'];
|
||||
$category_id = intval ($_POST['category_id']);
|
||||
$email = $_POST['email'];
|
||||
$user_ip = Get_IP();
|
||||
if( !filter_var($url, FILTER_VALIDATE_URL) ) {
|
||||
msg(-1,'URL无效!');
|
||||
}elseif( !empty($iconurl) && !filter_var($iconurl, FILTER_VALIDATE_URL) ){
|
||||
msg(-1,'网站图标无效!');
|
||||
}elseif(!preg_match('/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/',$email)){
|
||||
msg(-1,'联系邮箱无效!');
|
||||
}elseif(!isset($_POST['category_id'])){
|
||||
msg(-1,'分类ID不能为空!');
|
||||
}elseif(!isset($_POST['title'])){
|
||||
msg(-1,'网站标题不能为空!');
|
||||
}elseif(!isset($_POST['description'])){
|
||||
msg(-1,'网站描述不能为空!');
|
||||
}
|
||||
//获取和检查分类信息
|
||||
$where['cid'] = $category_id;
|
||||
$where['uid'] = UID;
|
||||
$category_info = get_db('user_categorys',['cid','fid','property','name','font_icon','description'],$where);
|
||||
if(empty($category_info) || $category_info['property'] != 0){
|
||||
msgA(['code'=>-1,'msg'=>'没有找到分类信息']);
|
||||
}
|
||||
|
||||
//检查是否重复
|
||||
$url_data = get_db("user_apply","*",["url"=> $url,'uid'=>UID ]);
|
||||
if(isset($url_data['id'])){
|
||||
if ($url_data['state'] == 0){
|
||||
msg(-1,'审核中,请勿重复提交!');
|
||||
}elseif ($url_data['state'] == 1 || $url_data['state'] == 3 ){
|
||||
msg(-1,'已通过,请勿重复提交!');
|
||||
}elseif ($url_data['state'] == 2){
|
||||
msg(-1,'已拒绝,请勿重复提交!');
|
||||
}
|
||||
}
|
||||
|
||||
// 统计IP 24小时内提交的数量!,超限则拦截!
|
||||
$count = count_db("user_apply", ["uid"=>UID , "ip" => $user_ip ,"time[>]" => time() - 60*60*24]);
|
||||
if ($count >= 5){
|
||||
msg(-1,'您提交的申请数量已达到上限!请明天再试!');
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'uid' => UID,
|
||||
'iconurl' => $iconurl,
|
||||
'title' => $title,
|
||||
'url' => $url,
|
||||
'email' => $email,
|
||||
'ip' => $user_ip,
|
||||
'ua' => $_SERVER['HTTP_USER_AGENT'],
|
||||
'time' => time(),
|
||||
'state' => 0, // 0.待审核 1.手动通过 2.已拒绝 3.自动通过
|
||||
'category_id' => $category_id,
|
||||
'category_name' => $category_info['name'],
|
||||
'description' => $description
|
||||
];
|
||||
|
||||
//0.关闭 1.开启 2.无需审核
|
||||
if($apply['apply'] == 1){
|
||||
$data['state'] = 0 ;
|
||||
}elseif($apply['apply'] == 2){
|
||||
$data['state'] = 3 ;
|
||||
if(!empty(get_db("user_links","*",["url"=> $url,'uid'=>UID ]))){
|
||||
msg(-1,'URL已经存在!'); //存在于链接列表中!
|
||||
}
|
||||
$url_data = [
|
||||
'uid' => UID,
|
||||
'fid' => $category_id,
|
||||
'title' => $title,
|
||||
'url' => $url,
|
||||
'description' => $description,
|
||||
'add_time' => time(),
|
||||
'weight' => 0,
|
||||
'property' => 0,
|
||||
'icon' => $iconurl
|
||||
];
|
||||
insert_db('user_links',$url_data);
|
||||
}
|
||||
insert_db('user_apply',$data,[1,'提交成功!']);
|
||||
msg(-1,'免费版不支持此功能');
|
||||
?>
|
||||
|
||||
3
system/expand/article.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php if(!defined('DIR')){Not_Found();}AccessControl();
|
||||
|
||||
exit('免费版不支持此功能');
|
||||
@@ -1,71 +1,11 @@
|
||||
<?php
|
||||
if($global_config['guestbook'] != 1 || !check_purview('guestbook',1)){
|
||||
require DIR.'/templates/admin/page/404.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$s = unserialize( get_db("user_config", "v", ["k" => "guestbook","uid"=>UID]) );
|
||||
if(empty($s) || $s['allow'] != 1){
|
||||
$content = '站点已设置禁止留言';
|
||||
require DIR.'/templates/admin/page/404.php';
|
||||
exit;
|
||||
}
|
||||
if(!Check_Path("data/user/{$u}/MessageBoard")){
|
||||
exit("<h2>创建目录失败,请检查权限</h2>");
|
||||
}
|
||||
|
||||
//POST提交留言
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST'){
|
||||
if($s['allow'] != '1'){ msg(-1015,'提交失败,当前禁止留言!'); }
|
||||
$type = $_POST['type']; //类型
|
||||
$contact = $_POST['contact']; //联系方式
|
||||
$title = $_POST['title']; //标题
|
||||
$content = $_POST['content']; //内容
|
||||
if(empty($type)){
|
||||
msg(-1015,'提交失败,类型不能为空');
|
||||
}elseif(empty($contact)){
|
||||
msg(-1015,'提交失败,联系方式不能为空');
|
||||
}elseif(empty($title)){
|
||||
msg(-1015,'提交失败,标题不能为空');
|
||||
}elseif(empty($content)){
|
||||
msg(-1015,'提交失败,内容不能为空');
|
||||
}elseif(strlen($type) >= 32 || strlen($contact) >= 64 || strlen($title) >= 128 || strlen($content) >= 2048){
|
||||
msg(-1015,'提交失败,长度超限');
|
||||
}elseif(ShuLiang("data/user/{$u}/MessageBoard/") > 256){
|
||||
msg(-1015,'提交失败,留言太多了请稍后再试');
|
||||
}
|
||||
|
||||
$json_arr = array(
|
||||
'type'=>htmlentities($type),
|
||||
'contact'=>htmlentities($contact),
|
||||
'title'=>htmlentities($title),
|
||||
'content'=>htmlentities($content),
|
||||
'time'=>time(),
|
||||
'ip'=>get_IP()
|
||||
);
|
||||
//限制长度 参数
|
||||
//var_dump($json_arr);exit;
|
||||
$json = json_encode($json_arr);
|
||||
$path = "data/user/{$u}/MessageBoard/".time().'_'.crc32($json).'.json';
|
||||
if( Check_Path("data/user/{$u}/MessageBoard") && file_put_contents($path, $json)){
|
||||
msg(0,'提交成功');
|
||||
}else{
|
||||
msg(-1015,'系统错误,提交失败'); //创建目录或写入文件失败,请检查权限
|
||||
}
|
||||
msg(-1,'免费版不支持此功能');
|
||||
}
|
||||
|
||||
//获取文件数
|
||||
function ShuLiang($path){
|
||||
$sl=0;
|
||||
$arr = glob($path);
|
||||
foreach ($arr as $v){
|
||||
if(is_file($v)){
|
||||
$sl++;
|
||||
}else{
|
||||
$sl+=ShuLiang($v."/*");
|
||||
}
|
||||
}
|
||||
return $sl;
|
||||
}
|
||||
require DIR.'/templates/admin/page/expand/guestbook-user.php';
|
||||
//通用数据初始化
|
||||
require DIR."/system/templates.php";
|
||||
require $index_path;
|
||||
exit;
|
||||
8
system/expand/sitemap.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
if(!is_subscribe('bool')){exit;}
|
||||
|
||||
//设置协议头
|
||||
header('Content-Type: application/xml');
|
||||
exit;
|
||||
|
||||
?>
|
||||
1
system/expand/sitemap_create.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -11,7 +11,9 @@ foreach($_POST as $key =>$value){
|
||||
if($method =='write_site_setting' && ($key =='custom_header' || $key =='custom_footer')){
|
||||
continue;
|
||||
}
|
||||
|
||||
if($method == 'write_article'){
|
||||
continue;
|
||||
}
|
||||
if(preg_match('/<(iframe|script|body|img|layer|div|meta|style|base|object|input)/i',$value)){
|
||||
$code = 2001;
|
||||
}elseif(preg_match('/(onmouseover|onerror|onload)\=/i',$value)){
|
||||
@@ -19,7 +21,7 @@ foreach($_POST as $key =>$value){
|
||||
}
|
||||
}
|
||||
//拦截SQL注入
|
||||
if($global_config['SQL_WAF'] == 1 ){
|
||||
if(!isset($code) && $global_config['SQL_WAF'] == 1 ){
|
||||
if(preg_match("/\s+(or|xor|and)\s+(=|<|>|'|".'")/i',$value)){
|
||||
$code = 2101;
|
||||
}elseif(preg_match("/select.+(from|limit)/i",$value)){
|
||||
@@ -41,5 +43,10 @@ foreach($_POST as $key =>$value){
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($code)){msgA(['code'=>$code,'msg'=>$code.':已拦截不合法参数!','key'=>$key,'Value'=>$value,'method'=>$method ]);}
|
||||
if(!empty($code)){
|
||||
$tips = $code <= 2100 ?
|
||||
'<br />如果您是站长,请前往系统设置关闭防XSS脚本<br />如果您是用户,请联系站长处理':
|
||||
'<br />如果您是站长,请前往系统设置关闭防SQL注入<br />如果您是用户,请联系站长处理';
|
||||
msgA(['code'=>$code,'msg'=>$code.':已拦截不合法参数!'.$tips,'key'=>$key,'Value'=>$value,'method'=>$method ]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
// 来源 https://blog.mimvp.com/article/23089.html
|
||||
|
||||
function get_page_info($output, $friend_link = '', $curl_info=array()) {
|
||||
$page_info = array();
|
||||
@@ -71,16 +70,39 @@ function get_page_info($output, $friend_link = '', $curl_info=array()) {
|
||||
|
||||
preg_match('/<META\s+content="([\w\W]*?)"\s+scheme="([\w\W]*?)"/si', $meta_str, $res);
|
||||
if(!empty($res)) $meta_array[strtolower($res[2])] = $res[1];
|
||||
|
||||
// 20230716 新增匹配语法
|
||||
preg_match('/<META\s+content=[\'"](.*?)[\'"]\s+itemprop=[\'"](.*?)[\'"]\s+name=[\'"](.*?)[\'"]>/si', $meta_str, $res);
|
||||
if(!empty($res)) $meta_array[strtolower($res[3])] = $res[1];
|
||||
|
||||
preg_match('/<meta\s+itemprop=[\'"](.*?)[\'"]\s+name=[\'"](.*?)[\'"]\s+content=[\'"](.*?)[\'"]>/si', $meta_str, $res);
|
||||
if(!empty($res)) $meta_array[strtolower($res[2])] = $res[3];
|
||||
}
|
||||
|
||||
|
||||
//如果正则匹配失败则使用php函数尝试再次匹配
|
||||
if(empty($meta_array['keywords']) || empty($meta_array['description'])){
|
||||
//将html保存为临时文件
|
||||
$key = md5(uniqid().Get_Rand_Str(8));
|
||||
$tempFile = DIR ."/data/temp/".md5(uniqid().Get_Rand_Str(8)).".html";
|
||||
file_put_contents($tempFile, $output);
|
||||
$tags = get_meta_tags($tempFile);
|
||||
unlink($tempFile); //删除临时文件
|
||||
if(empty($meta_array['keywords']) && !empty($tags['keywords'])){
|
||||
$meta_array['keywords'] = $tags['keywords'];
|
||||
}
|
||||
if(empty($meta_array['description']) && !empty($tags['description'])){
|
||||
$meta_array['description'] = $tags['description'];
|
||||
}
|
||||
}
|
||||
|
||||
$page_info['site_keywords'] = $meta_array['keywords'];
|
||||
$page_info['site_description'] = $meta_array['description'];
|
||||
//$page_info['meta_array'] = $meta_array; //暂时不需要全部meta
|
||||
|
||||
|
||||
# 判断是否存在友链
|
||||
if(!empty($friend_link) && strstr($output, $friend_link) != "") {
|
||||
$page_info['friend_link_status'] = 1;
|
||||
}
|
||||
|
||||
|
||||
return $page_info;
|
||||
}
|
||||
49
system/icon.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
echo_link_type_icon();
|
||||
|
||||
function echo_icon($path,$config,$db = false){
|
||||
//文件不存在时输出固定图标(理论上执行到这里不会出现文件不存在)
|
||||
if(!is_file($path)){
|
||||
echo_icon(DIR . '/templates/admin/img/ie.svg',$config);
|
||||
}
|
||||
//如果存在mime类型则直接读取,否则根据文件类型声明(从缓存读取时才会有mime)
|
||||
if(empty($db['mime'])){
|
||||
$suffix = strtolower(end(explode('.',$path))); //文件类型
|
||||
$type = ['jpg'=>'jpeg','jpeg'=>'jpeg','svg'=>'svg+xml','ico'=>'x-icon']; //类型表
|
||||
$mime = $type[$suffix] ?? 'x-icon';
|
||||
}else{
|
||||
$mime = $db['mime'];
|
||||
}
|
||||
//MIME类型
|
||||
header("Content-Type: image/{$mime};text/html; charset=utf-8");
|
||||
//缓存时间
|
||||
$cache_time = intval($config['browse_cache_time']);
|
||||
if($cache_time > 0 ){
|
||||
header ("Last-Modified: " .gmdate("D, d M Y H:i:s", empty($db['mime']) ? filemtime($path):$db['mime'] )." GMT"); //更新时间
|
||||
header("Expires: " .gmdate("D, d M Y H:i:s", time() + $cache_time)." GMT"); //过期时间 HTTP1.0
|
||||
header("Cache-Control: public, max-age={$cache_time}"); //存活时间 HTTP1.1
|
||||
}
|
||||
//输出文件
|
||||
exit(file_get_contents($path,true));
|
||||
}
|
||||
|
||||
|
||||
//根据链接类型输出图标
|
||||
function echo_link_type_icon(){
|
||||
global $config;$config['browse_cache_time'] = 60;
|
||||
if(preg_match("/^(http:\/\/|https:\/\/)/",$GLOBALS['url'])){
|
||||
echo_icon(DIR . '/templates/admin/img/ie.svg',$config);
|
||||
}elseif(preg_match("/^(ftp:\/\/|ftps:\/\/|sftp:\/\/)/",$GLOBALS['url'])){
|
||||
echo_icon(DIR . '/templates/admin/img/ftp.svg',$config);
|
||||
}elseif(preg_match("/^magnet:?/",$GLOBALS['url'])){
|
||||
echo_icon(DIR . '/templates/admin/img/magnet.svg',$config);
|
||||
}elseif(preg_match("/^(tcp:\/\/|udp:\/\/|rtsp:\/\)/",$GLOBALS['url'])){
|
||||
echo_icon(DIR . '/templates/admin/img/tcpudp.svg',$config);
|
||||
}elseif(preg_match("/^thunder:\/\//",$GLOBALS['url'])){
|
||||
echo_icon(DIR . '/templates/admin/img/xunlei.png',$config);
|
||||
}else{
|
||||
echo_icon(DIR . '/templates/admin/img/ie.svg',$config);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
200
system/index.php
@@ -1,6 +1,60 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}AccessControl();
|
||||
//主页入口
|
||||
define('is_login',is_login());
|
||||
|
||||
//是否载入引导页
|
||||
if(@$global_config['default_page'] == 2){
|
||||
if(empty(Get('u')) && empty($_COOKIE['Default_User'])){
|
||||
$c = 'guide';
|
||||
require DIR."/system/templates.php";
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
//书签分享
|
||||
$share = Get('share');
|
||||
if(!empty($share)){
|
||||
$share = get_db('user_share','*',['uid'=>UID,'sid'=>$share]);
|
||||
if(empty($share)){
|
||||
$content = '分享已被删除,请联系作者!';
|
||||
require DIR.'/templates/admin/page/404.php';
|
||||
exit;
|
||||
}
|
||||
//判断是否过期
|
||||
if(time() > $share['expire_time']){
|
||||
$content = '分享已过期,请联系作者!';
|
||||
require DIR.'/templates/admin/page/404.php';;
|
||||
exit;
|
||||
}
|
||||
//判断是否加密
|
||||
if(!empty($share['pwd']) && !is_login()){
|
||||
session_start();
|
||||
if($_SESSION['verify']['share'][$share['id']] != $share['pwd']){
|
||||
$c = 'verify';$_GET['c'] = 'share';
|
||||
require DIR."/system/templates.php";
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$data = json_decode($share['data']);
|
||||
//判断分享类型(1.分类 2.链接)
|
||||
if($share['type'] == 1){
|
||||
$where['cid'] = $data;
|
||||
if($share['pv'] == 1){
|
||||
unset($where['property']);
|
||||
}
|
||||
}else if($share['type'] == 2){
|
||||
$category_parent = [['name' => $share['name'] ,"font_icon" =>"fa fa-bookmark-o" , "id" => 'share' ,"description" => "书签分享"]];
|
||||
$categorys = $category_parent;
|
||||
}
|
||||
|
||||
//浏览计次
|
||||
update_db("user_share", ["views[+]"=>1],['uid'=>UID,'id'=>$share['id']]);
|
||||
}
|
||||
|
||||
|
||||
//通用数据初始化
|
||||
require DIR."/system/templates.php";
|
||||
|
||||
//判断用户组,是否允许未登录时访问主页
|
||||
if(!is_login && ($global_config['Privacy'] == 1 || !check_purview('Common_home',1))){
|
||||
@@ -8,72 +62,13 @@ if(!is_login && ($global_config['Privacy'] == 1 || !check_purview('Common_home',
|
||||
header("Location: ./?c=admin&u=".U);
|
||||
exit;
|
||||
}
|
||||
//载入站点设置
|
||||
$site = unserialize(get_db('user_config','v',['uid'=>UID,'k'=>'s_site']));
|
||||
$site['Title'] = $site['title'].(empty($site['subtitle'])?'':' - '.$site['subtitle']);
|
||||
//免费用户请保留版权,谢谢!
|
||||
$copyright = empty($global_config['copyright'])?'<a target="_blank" href="https://gitee.com/tznb/TwoNav">Copyright © TwoNav</a>':$global_config['copyright'];
|
||||
$ICP = empty($global_config['ICP'])?'':'<a target="_blank" href="https://beian.miit.gov.cn">'.$global_config['ICP'].'</a>';
|
||||
$favicon = ( !empty($site['site_icon_file'])) ? $site['site_icon'] : './favicon.ico';
|
||||
|
||||
//读取默认模板信息
|
||||
require DIR ."/system/templates.php";
|
||||
//引导页
|
||||
if(!empty($global_config['default_page']) && $global_config['default_page'] == 2){
|
||||
if(empty(Get('u')) && empty($_COOKIE['Default_User'])){
|
||||
$theme = $global_templates['guide'];
|
||||
$dir_path = DIR.'/templates/guide/'.$global_templates['guide'];
|
||||
$index_path = $dir_path.'/index.php';
|
||||
if(!is_file($index_path)){
|
||||
$dir_path= DIR.'/templates/guide/default';
|
||||
$index_path = $dir_path.'/index.php';
|
||||
}
|
||||
$theme_dir = str_replace(DIR.'/templates/guide',"./templates/guide",$dir_path);
|
||||
$theme_info = json_decode(@file_get_contents($dir_path.'/info.json'),true);
|
||||
$theme_config = empty($theme_info['config']) ? []:$theme_info['config'];
|
||||
$theme_config_db = get_db('user_config','v',['t'=>'theme_guide','k'=>$theme,'uid'=>UID]);
|
||||
$theme_config_db = unserialize($theme_config_db);
|
||||
$theme_config = empty($theme_config_db) ? $theme_config : array_merge ($theme_config,$theme_config_db);
|
||||
require($index_path);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
//参数指定主题优先
|
||||
$theme = trim(@$_GET['theme']);
|
||||
if ( !empty ($theme) && check_purview('theme_in',1)){
|
||||
$dir_path = DIR.'/templates/home/'.$theme;
|
||||
$index_path = $dir_path.'/index.php';
|
||||
}else{
|
||||
$is_Pad = preg_match('/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i',$_SERVER['HTTP_USER_AGENT']);
|
||||
$theme = $is_Pad?$s_templates['home_pad']:$s_templates['home_pc'];
|
||||
$dir_path = DIR.'/templates/home/'.$theme;
|
||||
$index_path = $dir_path.'/index.php';
|
||||
}
|
||||
//检查是否存在,不存在则使用默认
|
||||
if(!is_file($index_path)){
|
||||
$dir_path= DIR.'/templates/home/default';
|
||||
$index_path = $dir_path.'/index.php';
|
||||
}
|
||||
//相对路径
|
||||
$theme_dir = str_replace(DIR.'/templates/home',"./templates/home",$dir_path);
|
||||
//主题信息
|
||||
$theme_info = json_decode(@file_get_contents($dir_path.'/info.json'),true);
|
||||
//支持属性
|
||||
$support_subitem = $theme_info['support']['subitem']??0; //0.不支持子分类 1.分类栏支持 2.链接栏支持 3.都支持
|
||||
$support_category_svg = $theme_info['support']['category_svg']??0; //0.不支持 1.支持
|
||||
//主题配置(默认)
|
||||
$theme_config = empty($theme_info['config']) ? []:$theme_info['config'];
|
||||
//主题配置(用户)
|
||||
$theme_config_db = get_db('user_config','v',['t'=>'theme_home','k'=>$theme,'uid'=>UID]);
|
||||
$theme_config_db = unserialize($theme_config_db);
|
||||
//合并配置数据
|
||||
$theme_config = empty($theme_config_db) ? $theme_config : array_merge ($theme_config,$theme_config_db);
|
||||
//主题版本(调试时追加时间戳)
|
||||
$theme_ver = !Debug?$theme_info['version']:$theme_info['version'].'.'.time();
|
||||
$site['ex_theme'] = in_array($theme,['snail-nav','heimdall']); //例外主题,不支持热门网址/最新网址/输出上限
|
||||
//例外主题,不支持热门网址/最新网址/输出上限
|
||||
$site['ex_theme'] = in_array($theme,['snail-nav','heimdall']);
|
||||
|
||||
//分类查找条件
|
||||
$categorys = []; //声明一个空数组
|
||||
$content = ['cid(id)','name','property','font_icon','icon','description'];//需要的内容
|
||||
$content = ['cid(id)','fid','name','property','font_icon','icon','description'];//需要的内容
|
||||
$where['uid'] = UID;
|
||||
$where['fid'] = 0;
|
||||
$where['status'] = 1;
|
||||
@@ -98,7 +93,7 @@ function get_category_sub($id) {
|
||||
if(!empty($share)){
|
||||
$where['cid'] = $data;
|
||||
}
|
||||
$content = ['cid(id)','name','property','font_icon','icon','description'];
|
||||
$content = ['cid(id)','name','fid','property','font_icon','icon','description'];
|
||||
$where['uid'] = UID;
|
||||
$where['fid'] = intval($id);
|
||||
$where['status'] = 1;
|
||||
@@ -125,7 +120,6 @@ function get_links($fid) {
|
||||
$where['ORDER']['lid'] = 'ASC';
|
||||
if(!is_login){
|
||||
$where['property'] = 0;
|
||||
|
||||
}
|
||||
//书签分享>私有可见
|
||||
if(isset($share['pv']) && $share['pv'] == 1){
|
||||
@@ -159,12 +153,13 @@ function get_links($fid) {
|
||||
$where['LIMIT'] = $site['max_link'];
|
||||
$max_link = true;
|
||||
}
|
||||
$links = select_db('user_links',['lid(id)','fid','property','title','url(real_url)','url_standby','description','icon','click','pid'],$where);
|
||||
foreach ($links as $key => $link) {
|
||||
$links = select_db('user_links',['lid(id)','fid','property','title','url(real_url)','url_standby','description','icon','click','pid','extend'],$where);
|
||||
$UUID = ($GLOBALS['global_config']['static_link'] == 2 ? UID : U);
|
||||
foreach ($links as &$link) {
|
||||
$click = false; $lock = false;
|
||||
|
||||
//直连模式,但存在备用链接
|
||||
if ($site['link_model'] == 'direct' && !empty($link['url_standby'])){
|
||||
if ($site['link_model'] == 'direct' && $site['main_link_priority'] != '3' && !empty($link['url_standby'])){
|
||||
$click = true;
|
||||
}
|
||||
|
||||
@@ -180,67 +175,40 @@ function get_links($fid) {
|
||||
}
|
||||
|
||||
if($click || $site['link_model'] != 'direct'){
|
||||
$links[$key]['url'] = "./index.php?c=click&id={$link['id']}&u=".U;
|
||||
$link['url'] = static_link ? "{$GLOBALS['HOST']}/click-{$UUID}-{$link['id']}.html" : "./index.php?c=click&id={$link['id']}&u={$u}";
|
||||
if($lock){
|
||||
$links[$key]['real_url'] = $links[$key]['url']; //篡改真实URL,防止泄密
|
||||
$link['real_url'] = $link['url']; //篡改真实URL,防止泄密
|
||||
if(isset($share['sid'])){
|
||||
$links[$key]['url'] .='&share='.$share['sid'];
|
||||
$link['url'] .='&share='.$share['sid'];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$links[$key]['url'] = $link['real_url'];
|
||||
$link['url'] = $link['real_url'];
|
||||
}
|
||||
|
||||
//获取图标链接
|
||||
$links[$key]['ico'] = $lock ? $GLOBALS['libs'].'/Other/lock.svg' : geticourl($site['link_icon'],$link);
|
||||
$link['ico'] = $lock ? $GLOBALS['libs'].'/Other/lock.svg' : geticourl($site['link_icon'],$link);
|
||||
$link['type'] = 'link';
|
||||
}
|
||||
//处理扩展信息
|
||||
if($GLOBALS['global_config']['link_extend'] == 1 && check_purview('link_extend',1) && in_array($GLOBALS['theme_info']['support']['link_extend'],["true","1"])){
|
||||
foreach ($links as &$link) {
|
||||
if(!empty($link['extend'])){
|
||||
$link = array_merge ($link,unserialize($link['extend']));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($max_link && $count > $site['max_link']){
|
||||
$oc_url = "./index.php?u={$u}&oc={$fid}" . (empty($_GET['theme']) ? '':"&theme={$_GET['theme']}");
|
||||
$oc_url = static_link ? "{$GLOBALS['HOST']}/category-{$UUID}-{$fid}.html" : "./index.php?u={$u}&oc={$fid}";
|
||||
array_push($links,['id'=>0,'title'=>'查看全部','url'=>$oc_url,'real_url'=>$oc_url,'description'=>'该分类共有'.$count.'条数据','ico'=>'./favicon.ico']);
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
//书签分享
|
||||
$share = Get('share');
|
||||
if(!empty($share)){
|
||||
$share = get_db('user_share','*',['uid'=>UID,'sid'=>$share]);
|
||||
if(empty($share)){
|
||||
$content = '分享已被删除,请联系作者!';
|
||||
require DIR.'/templates/admin/page/404.php';
|
||||
exit;
|
||||
}
|
||||
//判断是否过期
|
||||
if(time() > $share['expire_time']){
|
||||
$content = '分享已过期,请联系作者!';
|
||||
require DIR.'/templates/admin/page/404.php';;
|
||||
exit;
|
||||
}
|
||||
//判断是否加密
|
||||
if(!empty($share['pwd']) && !is_login){
|
||||
session_start();
|
||||
if($_SESSION['verify']['share'][$share['id']] != $share['pwd']){
|
||||
require DIR.'/templates/admin/other/verify_share_pwd.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$data = json_decode($share['data']);
|
||||
//判断分享类型(1.分类 2.链接)
|
||||
if($share['type'] == 1){
|
||||
$where['cid'] = $data;
|
||||
if($share['pv'] == 1){
|
||||
unset($where['property']);
|
||||
}
|
||||
}else if($share['type'] == 2){
|
||||
$category_parent = [['name' => $share['name'] ,"font_icon" =>"fa fa-bookmark-o" , "id" => 'share' ,"description" => "书签分享"]];
|
||||
$categorys = $category_parent;
|
||||
}
|
||||
|
||||
//浏览计次
|
||||
update_db("user_share", ["views[+]"=>1],['uid'=>UID,'id'=>$share['id']]);
|
||||
}
|
||||
|
||||
|
||||
//如果为空则查找分类
|
||||
if($category_parent == []){
|
||||
@@ -284,5 +252,7 @@ if(empty($_GET['share']) && !$site['ex_theme']){
|
||||
//访问统计
|
||||
write_user_count(date('Ym'),'index_Ym');
|
||||
write_user_count(date('Ymd'),'index_Ymd');
|
||||
count_ip();
|
||||
|
||||
//载入模板
|
||||
require($index_path);
|
||||
@@ -4,22 +4,27 @@ if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Fou
|
||||
//初始化
|
||||
session_name('TwoNav_initial');
|
||||
session_start();
|
||||
$layui_dir = "./static/Layui";
|
||||
foreach(scandir($layui_dir) as $value) {
|
||||
if(is_dir($layui_dir . '/' . $value) && preg_match('/^v\d+\.\d+\.\d+$/', $value) && is_file("{$layui_dir}/$value/layui.js")) {
|
||||
$layui['js'] = "./static/Layui/{$value}/layui.js";
|
||||
$layui['css'] = "./static/Layui/{$value}/css/layui.css";
|
||||
}
|
||||
}
|
||||
|
||||
//判断请求类型
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST'){
|
||||
if(empty($_SESSION['initial'])){ msg(-1,'当前环境无法满足程序运行条件!'); }
|
||||
define('Debug',TRUE);
|
||||
$db = null;
|
||||
$USER_DB =null;
|
||||
$USER_DB = null;
|
||||
require DIR.'/system/public.php';
|
||||
install();
|
||||
}else{
|
||||
clearstatcache();//清除缓存
|
||||
check_env();
|
||||
$libs = './static'; //使用本地静态库
|
||||
}
|
||||
|
||||
|
||||
// 环境检查
|
||||
function check_env() {
|
||||
if(!empty($_GET['diagnosis'])){
|
||||
@@ -31,8 +36,8 @@ function check_env() {
|
||||
$ext = get_loaded_extensions(); //获取组件信息
|
||||
$php_version = floatval(PHP_VERSION); //获取PHP版本
|
||||
|
||||
if( ( $php_version < 7.3 ) || ( $php_version > 8.2 ) ) {
|
||||
exit("当前PHP版本{$php_version}不满足要求,支持范围7.3 - 8.2");
|
||||
if($php_version < 7.3 ) {
|
||||
exit("当前PHP版本{$php_version}不满足要求,要求不低于7.3");
|
||||
}
|
||||
|
||||
//检查是否支持pdo_sqlite
|
||||
@@ -55,10 +60,10 @@ function diagnosis() {
|
||||
|
||||
//检查PHP版本,需要大于5.6小于8.0
|
||||
$php_version = floatval(PHP_VERSION);
|
||||
$log .= "PHP版本:{$php_version}<br />";
|
||||
$log .= "PHP版本:{$php_version} <a href='./?phpinfo=1' style='text-decoration: none;'> 显示phpinfo</a> <br />";
|
||||
$log .= "Web版本:{$_SERVER['SERVER_SOFTWARE']}<br />";
|
||||
if( ( $php_version < 7.3 ) || ( $php_version > 8.1 ) ) {
|
||||
$log .= "PHP版本:不满足要求,需要7.3 <= PHP <= 8.1 )<br />";
|
||||
if( $php_version < 7.3) {
|
||||
$log .= "PHP版本:不满足要求,要求不低于7.3<br />";
|
||||
}
|
||||
//获取加载的模块
|
||||
$ext = get_loaded_extensions();
|
||||
@@ -83,6 +88,7 @@ function diagnosis() {
|
||||
$log .= in_array("Phar",$ext) ? "Phar:支持<br />" : "Phar:不支持 (在线更新/主题下载)<br />";
|
||||
$log .= in_array("hash",$ext) ? "hash:支持<br />" : "hash:不支持 (书签分享/生成注册码)<br />";
|
||||
$log .= in_array("session",$ext) ? "session:支持<br />" : "session:不支持 (影响较大)<br />";
|
||||
$log .= in_array("intl",$ext) ? "" : "intl:不支持 (使用中文域名时可能会导致异常)\n";
|
||||
$log .= "可用模块:".implode(" ",$ext)."<br />";
|
||||
exit($log);
|
||||
}
|
||||
@@ -146,25 +152,33 @@ $db_config = array(
|
||||
}
|
||||
|
||||
// mysql
|
||||
if($_POST['db_type'] === 'mysql'){
|
||||
if($_POST['db_type'] === 'mysql' || $_POST['db_type'] === 'mariadb'){
|
||||
if( !isset($_POST['db_host']) || !isset($_POST['db_port']) || !isset($_POST['db_name']) || !isset($_POST['db_user']) || !isset($_POST['db_password']) ){
|
||||
msg(-1,'MySQL配置错误,请检查..');
|
||||
msg(-1,'数据库配置错误,请检查..');
|
||||
}
|
||||
|
||||
require (DIR.'/system/Medoo.php'); //载入框架
|
||||
try {
|
||||
$db = new Medoo\Medoo([
|
||||
'type' => 'mysql',
|
||||
'type' => $_POST['db_type'],
|
||||
'host' => $_POST['db_host'],
|
||||
'port' => $_POST['db_port'],
|
||||
'database' => $_POST['db_name'],
|
||||
'username' => $_POST['db_user'],
|
||||
'password' => $_POST['db_password']
|
||||
'password' => $_POST['db_password'],
|
||||
'charset' => 'utf8mb4'
|
||||
]);
|
||||
|
||||
//判断版本,目前基于5.6.50开发,其他版本兼容性未知,若您需要强制安装请屏蔽检测
|
||||
if(version_compare($db->info ()['version'],'5.6.0','<')) msg(-1,'MySQL数据库版本不能低于5.6,当前版本:'.$db->info ()['version']);
|
||||
//链接成功..
|
||||
$ver = $db->info ()['version'];
|
||||
if($_POST['db_type'] === 'mysql'){
|
||||
if(version_compare($ver,'5.6.0','<')){
|
||||
msg(-1,'MySQL数据库版本不能低于5.6,当前版本:'.$ver);
|
||||
}
|
||||
}else{
|
||||
preg_match('/(\d+\.\d+\.\d+)-MariaDB/', $ver, $matches);
|
||||
if(version_compare($matches[1],'10.1.0','<')){
|
||||
msg(-1,'MariaDB数据库版本不能低于10.1,当前版本:'.$ver);
|
||||
}
|
||||
}
|
||||
}catch (Exception $e) {
|
||||
$E = $e->getMessage();
|
||||
if(strstr($E,'[1044]') || strstr($E,'[1049]')){
|
||||
@@ -192,7 +206,7 @@ $db_config = array(
|
||||
$config = '<?php
|
||||
//数据库配置
|
||||
$db_config = array(
|
||||
"type" => "mysql", //类型
|
||||
"type" => "'.$_POST['db_type'].'", //类型
|
||||
"host" => "'.$_POST['db_host'].'", //地址
|
||||
"port" => '.$_POST['db_port'].', //端口
|
||||
"name" => "'.$_POST['db_name'].'", //库名
|
||||
@@ -256,7 +270,7 @@ function Write_Config(){
|
||||
$s_site['title'] = '我的书签'; //站点标题
|
||||
$s_site['subtitle'] = 'TwoNav'; //副标题
|
||||
$s_site['logo'] = '我的书签'; //站点logo
|
||||
$s_site['keywords'] = 'TwoNav,开源导航,开源书签,简洁导航,云链接,个人导航,个人书签,扩展,多用户,落幕'; //关键字
|
||||
$s_site['keywords'] = 'TwoNav,开源导航,开源书签,简洁导航,网址导航,云链接,个人导航,个人书签'; //关键字
|
||||
$s_site['description'] = 'TwoNav 是一款使用PHP + SQLite3/MySQL 开发的简约导航/书签管理器。'; //描述
|
||||
$s_site['link_model'] = '302'; //链接模式
|
||||
$s_site['link_icon'] = '0'; //链接图标
|
||||
@@ -280,18 +294,40 @@ function Write_Config(){
|
||||
insert_db("global_config", ["k" => "s_templates","v" => $templates,"d" => '默认模板']);
|
||||
|
||||
//写站点配置
|
||||
$o_config['Login'] = 'login'; //登录入口
|
||||
$o_config['Register'] = 'register'; //注册入口
|
||||
$o_config['RegOption'] = '1'; //注册配置
|
||||
$o_config['Libs'] = './static'; //静态库路径
|
||||
$o_config['Default_User'] = $_POST['User']; //默认用户
|
||||
$o_config['XSS_WAF'] = '1'; //防XSS脚本
|
||||
$o_config['SQL_WAF'] = '1'; //防SQL注入
|
||||
$o_config['offline'] = '0'; //离线模式
|
||||
$o_config['Debug'] = '0'; //调试模式
|
||||
$o_config['Maintenance'] = '0'; //维护模式
|
||||
$o_config['Sub_domain'] = '0'; //二级域名
|
||||
$o_config['copyright'] = ''; //版权信息
|
||||
$o_config['Default_User'] = $_POST['User'];
|
||||
$o_config['default_page'] = 0;
|
||||
$o_config['default_UserGroup'] = '';
|
||||
$o_config['RegOption'] = 0;
|
||||
$o_config['Register'] = 'register';
|
||||
$o_config['Login'] = 'login';
|
||||
$o_config['Libs'] = './static';
|
||||
$o_config['ICP'] = '';
|
||||
$o_config['XSS_WAF'] = 0;
|
||||
$o_config['SQL_WAF'] = 0;
|
||||
$o_config['offline'] = 0;
|
||||
$o_config['Update_Source'] = 0;
|
||||
$o_config['Update_Overtime'] = 3;
|
||||
$o_config['Debug'] = 0;
|
||||
$o_config['Maintenance'] = 0;
|
||||
$o_config['static_link'] = 0;
|
||||
$o_config['Privacy'] = 0;
|
||||
$o_config['Sub_domain'] = 0;
|
||||
$o_config['copyright'] = '';
|
||||
$o_config['global_header'] = '';
|
||||
$o_config['global_footer'] = '';
|
||||
$o_config['api_extend'] = 0;
|
||||
$o_config['apply'] = 1;
|
||||
$o_config['guestbook'] = 1;
|
||||
$o_config['link_extend'] = 0;
|
||||
$o_config['article'] = 1;
|
||||
$o_config['c_name'] = 0;
|
||||
$o_config['c_desc'] = 0;
|
||||
$o_config['l_name'] = 0;
|
||||
$o_config['l_url'] = 0;
|
||||
$o_config['l_key'] = 0;
|
||||
$o_config['l_desc'] = 0;
|
||||
$o_config['c_code'] = 0;
|
||||
|
||||
|
||||
insert_db("global_config", ["k" => "o_config","v" => $o_config,"d" => '网站配置']);
|
||||
|
||||
@@ -339,7 +375,7 @@ function Write_Config(){
|
||||
<meta charset="utf-8" />
|
||||
<title>TwoNav 安装引导</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<link rel='stylesheet' href='<?php echo $libs?>/Layui/v2.6.8/css/layui.css'>
|
||||
<link rel='stylesheet' href='<?php echo $layui['css']; ?>'>
|
||||
<style>
|
||||
body{ background-color:rgba(0, 0, 51, 0.8); }
|
||||
.login-logo h1 { color:#FFFFFF; text-align: center; }
|
||||
@@ -352,6 +388,9 @@ function Write_Config(){
|
||||
<div class="login-logo"><h1>TwoNav 安装引导</h1></div>
|
||||
<div class="layui-col-lg6 layui-col-md-offset3" style ="margin-top:4em;">
|
||||
<form class="layui-form layui-form-pane" action="">
|
||||
<div class="layui-form-mid layui-word-aux" style="width: 99%;">
|
||||
<span>禁止用于违法用途、使用者造成的一切法律后果由使用者自行承担、安装视为同意。</span>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">管理员账号</i></label>
|
||||
<div class="layui-input-block">
|
||||
@@ -375,8 +414,9 @@ function Write_Config(){
|
||||
<label class="layui-form-label">数据库类型</label>
|
||||
<div class="layui-input-block">
|
||||
<select id="db_type" name="db_type" lay-filter="db_type" >
|
||||
<option value="sqlite" selected="">SQLite ( 个人和工作室推荐 )</option>
|
||||
<option value="mysql" >MySQL ( 大量用户推荐 )</option>
|
||||
<option value="sqlite" selected="">SQLite</option>
|
||||
<option value="mysql" >MySQL ≥ 5.6.0 </option>
|
||||
<option value="mariadb" >MariaDB ≥ 10.1 </option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -390,50 +430,52 @@ function Write_Config(){
|
||||
</div>
|
||||
<!--SQLite配置-->
|
||||
|
||||
<!--MySQL配置-->
|
||||
<!--MySQL/MariaDB 配置-->
|
||||
<div id='db_mysql' style = "display:none;">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">MySQL地址</label>
|
||||
<label class="layui-form-label">地址</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="db_host" value="localhost" placeholder="请输入服务器地址" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">MySQL端口</label>
|
||||
<label class="layui-form-label">端口</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="db_port" value="3306" placeholder="请输入服务器端口" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">MySQL库名</label>
|
||||
<label class="layui-form-label">库名</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="db_name" placeholder="请输入数据库库名" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">MySQL账号</label>
|
||||
<label class="layui-form-label">账号</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="db_user" placeholder="请输入数据库账号" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">MySQL密码</label>
|
||||
<label class="layui-form-label">密码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="db_password" placeholder="请输入数据库密码" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--MySQL配置 End-->
|
||||
<div class="layui-form-mid layui-word-aux">安装方式:全新安装      </div>
|
||||
<div class="layui-form-mid layui-word-aux">推荐配置:Nginx-1.20 + PHP-8.1 </div>
|
||||
<button class="layui-btn" lay-submit lay-filter="register" style = "width:100%;">开始安装</button>
|
||||
<!--MySQL/MariaDB 配置 End-->
|
||||
<div class="layui-form-mid layui-word-aux" style="width: 99%;">
|
||||
<span>推荐环境:Nginx & PHP8+ </span>
|
||||
<a href="./?diagnosis=1" style="float: right;color: #fff;" target="_blank">info</a>
|
||||
</div>
|
||||
<button class="layui-btn" lay-submit lay-filter="install" style = "width:100%;">开始安装</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src = '<?php echo $libs?>/jquery/jquery-3.6.0.min.js'></script>
|
||||
<script src = '<?php echo $libs?>/Layui/v2.6.8/layui.js'></script>
|
||||
<script src = './static/jquery/jquery-3.6.0.min.js'></script>
|
||||
<script src = '<?php echo $layui['js']; ?>'></script>
|
||||
<script>
|
||||
|
||||
var file = "data_" + Date.now() + '_' + getRandomString(20) + ".db3" //生成文件名
|
||||
@@ -444,9 +486,28 @@ set_db_type(db_type);
|
||||
|
||||
layui.use(['form'], function(){
|
||||
var form = layui.form;
|
||||
var install = 0;
|
||||
//伪静态检测
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('GET', './static/Other/login.css?t=' + new Date().getTime(), true);
|
||||
request.onload = function() {
|
||||
if (request.status >= 200 && request.status < 400) {
|
||||
var fileContent = request.responseText;
|
||||
if (fileContent.startsWith('<!DOCTYPE html>')) {
|
||||
layer.alert(
|
||||
"系统检测到您的站点可能配置了不属于TwoNav的伪静态规则<br />通常是因为之前使用过其他程序,例如:OneNav Extend 或 OneNav <br />您需要将它清除,否则会影响到程序的正常使用 ( 如登录页异常 )<br />并在安装完成后在站长工具>生成伪静态>重新配置到站点中"
|
||||
,{title:'环境异常提示',anim: 2,closeBtn: 0,btn: ['刷新页面']},function () {
|
||||
location.reload();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
request.send();
|
||||
|
||||
|
||||
//开始安装
|
||||
form.on('submit(register)', function(data){
|
||||
form.on('submit(install)', function(data){
|
||||
var d = data.field;
|
||||
if(!/^[A-Za-z0-9]{3,13}$/.test(d.User)){
|
||||
layer.msg('账号只能是3到13位的数字和字母!', {icon: 5});
|
||||
@@ -459,24 +520,44 @@ layui.use(['form'], function(){
|
||||
return false;
|
||||
}else if(d.db_type == 'mysql'){
|
||||
if(d.db_host.length == 0 || d.db_port.length == 0 || d.db_name.length == 0 || d.db_user.length == 0 || d.db_password.length == 0){
|
||||
layer.msg('MySQL配置有误,请检查.', {icon: 5});
|
||||
layer.msg('数据库配置有误,请检查.', {icon: 5});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//防止重复安装
|
||||
if(install > 0){
|
||||
return false;
|
||||
}
|
||||
//安装标记和动态效果
|
||||
install = 1;
|
||||
layer.load(1, {shade:[0.5,'#fff']});
|
||||
layer.msg('正在安装中..', {icon: 16,time: 1000*300});
|
||||
setTimeout(function() {
|
||||
if(install == 1){
|
||||
layer.msg('如果页面长时间无响应,请检查您的运行环境和网络,然后尝试刷新页面再次操作...', {icon: 16,time: 1000*300});
|
||||
}
|
||||
}, 6000);
|
||||
$.post('./index.php?c=install',d,function(Re,status){
|
||||
if(Re.code == 1){
|
||||
install = 2;
|
||||
layer.closeLast('loading');
|
||||
open_msg(d.User,d.Password);
|
||||
}else if(Re.code == -2){ //强制安装
|
||||
layer.confirm(Re.msg,{icon: 3, title:'确定继续 ?'}, function(index){
|
||||
$.post('./index.php?c=install&f=yes',d,function(Re,status){
|
||||
layer.closeLast('loading');
|
||||
if(Re.code == 1){
|
||||
install = 2;
|
||||
open_msg(d.User,d.Password);
|
||||
}else{
|
||||
install = 0;
|
||||
layer.msg(Re.msg, {icon: 5,time: 60*1000});
|
||||
}
|
||||
});
|
||||
});
|
||||
}else{
|
||||
install = 0;
|
||||
layer.closeLast('loading');
|
||||
layer.msg(Re.msg, {icon: 5,time: 60*1000});
|
||||
}
|
||||
});
|
||||
@@ -494,7 +575,7 @@ layui.use(['form'], function(){
|
||||
//数据库类型切换
|
||||
function set_db_type(v){
|
||||
document.cookie="db_type="+v;
|
||||
if(v == 'mysql'){
|
||||
if(v == 'mysql' || v == 'mariadb'){
|
||||
$("#db_mysql").show();
|
||||
$("#db_sqlite").hide();
|
||||
}else if(v == 'sqlite'){
|
||||
@@ -508,12 +589,12 @@ function open_msg(u,p){
|
||||
layer.open({ //弹出结果
|
||||
type: 1
|
||||
,title: '安装成功'
|
||||
,area: ['230px', '220px']
|
||||
,area: ['230px', '260px']
|
||||
,maxmin: false
|
||||
,shadeClose: false
|
||||
,resize: false
|
||||
,closeBtn: 0
|
||||
,content: '<div style="padding: 15px;">管理员账号: '+u+'<br>管理员密码: '+p+'<br><h3><a href="?c=admin&u='+u+'" style="color: #0000FF;" class="fl"> <br> >>点我进入后台</a></h3><h3><a href="?u='+u+'" style="color: #0000FF;" class="fl"> <br> >>点我进入首页</a></h3></div>'
|
||||
,content: '<div style="padding: 15px;">管理员账号: '+u+'<br>管理员密码: '+p+'<br><h3><a href="?c=admin&u='+u+'" style="color: #0000FF;" class="fl"> <br> >>点我进入后台</a></h3><h3><a href="?u='+u+'" style="color: #0000FF;" class="fl"> <br> >>点我进入首页</a></h3> <h3><a href="https://gitee.com/tznb/TwoNav/wikis/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/%E5%AE%89%E5%85%A8%E9%85%8D%E7%BD%AE" style="color: #0000FF;" class="fl" target="_blank"> <br> >>安全配置说明</a></h3> </div>'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,46 +1,59 @@
|
||||
<?php if(!defined('DIR')){header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;}
|
||||
//登录入口
|
||||
require "./system/templates.php";
|
||||
|
||||
//如果是Get请求则载入登录模板
|
||||
if($_SERVER['REQUEST_METHOD'] === 'GET'){
|
||||
require DIR ."/system/templates.php";
|
||||
$t_path = DIR ."/templates/login/{$s_templates['login']}/index.php"; //模板路径
|
||||
$copyright = empty($global_config['copyright'])?'<a target="_blank" href="https://gitee.com/tznb/TwoNav">Copyright © TwoNav</a>':$global_config['copyright'];
|
||||
$ICP = empty($global_config['ICP'])?'':'<a target="_blank" href="https://beian.miit.gov.cn">'.$global_config['ICP'].'</a>';
|
||||
//检查是否存在,不存在则使用默认
|
||||
if(!is_file($t_path)){
|
||||
$t_path = DIR.'/templates/login/default/index.php';
|
||||
}
|
||||
require $t_path;
|
||||
session_start();
|
||||
$_SESSION['login'] = $c;
|
||||
require DIR."/system/templates.php";
|
||||
require $index_path;
|
||||
exit;
|
||||
}
|
||||
|
||||
AccessControl(); //访问控制
|
||||
$User = $_POST["User"];$Password = $_POST["Password"]; //获取请求数据
|
||||
|
||||
if(empty($User)){
|
||||
insert_db("user_log", ["uid" => '',"user"=>'',"ip"=>Get_IP(),"time"=>time(),"type" => 'login',"content"=>Get_Request_Content(),"description"=>"请求登录>账号为空"]);
|
||||
msg(-1,'账号不能为空!');
|
||||
}elseif($User != $USER_DB['User']){
|
||||
insert_db("user_log", ["uid" => '',"user"=>$User,"ip"=>Get_IP(),"time"=>time(),"type" => 'login',"content"=>Get_Request_Content(),"description"=>"请求登录>账号不存在"]);
|
||||
msg(-1,'账号不存在!');
|
||||
}
|
||||
|
||||
//记录请求日志
|
||||
insert_db("user_log", ["uid" => $USER_DB['ID'],"user"=>$USER_DB['User'],"ip"=>Get_IP(),"time"=>time(),"type" => 'login',"content"=>Get_Request_Content(),"description"=>"请求登录"]);
|
||||
$log_id = $db->id();
|
||||
//基础判断
|
||||
if(!isset($User)){
|
||||
update_db_db("user_log", ["description" => "请求登录>账号不能为空"], ["id"=>$log_id]);
|
||||
msg(-1,'账号不能为空!');
|
||||
}elseif(strlen($Password)!==32){
|
||||
if(strlen($Password)!==32){
|
||||
update_db("user_log", ["description" => "请求登录>密码错误(长度应该是32位的MD5)"], ["id"=>$log_id]);
|
||||
msg(-1,'密码错误!');
|
||||
}elseif($c != $global_config["Login"] && $c != $USER_DB['Login'] ){
|
||||
update_db("user_log", ["description" => "请求登录>登录入口错误"], ["id"=>$log_id]);
|
||||
msg(-1,"登录入口错误");
|
||||
}elseif(strlen($_SERVER['HTTP_USER_AGENT'])>256){
|
||||
}elseif(strlen($_SERVER['HTTP_USER_AGENT'])>1024){
|
||||
update_db("user_log", ["description" => "请求登录>浏览器UA长度异常"], ["id"=>$log_id]);
|
||||
msg(-1,"浏览器UA长度异常,请更换浏览器!");
|
||||
}
|
||||
|
||||
$LoginConfig = unserialize( $USER_DB['LoginConfig'] );
|
||||
//开启双重验证时验证OTP验证码
|
||||
if(!empty($LoginConfig['totp_key'])){
|
||||
if(empty($_POST['otp_code'])){
|
||||
msgA(['code'=>-1,'msg'=>'您已开启双重验证,请输入OTP验证码']);
|
||||
}
|
||||
require DIR . '/system/Authenticator.php';
|
||||
$totp = new PHPGangsta_GoogleAuthenticator();
|
||||
$checkResult = $totp->verifyCode($LoginConfig['totp_key'], $_POST['otp_code'], 2);
|
||||
if(!$checkResult){
|
||||
msgA(['code'=>-1,'msg'=>'OTP验证码错误,请重试!']);
|
||||
}
|
||||
}
|
||||
|
||||
//计算请求密码和数据库的对比
|
||||
if(Get_MD5_Password($Password,$USER_DB["RegTime"]) === $USER_DB["Password"]){
|
||||
update_db("user_log", ["description" => "请求登录>登录成功"], ["id"=>$log_id]);
|
||||
Set_key($USER_DB);
|
||||
$LoginConfig = unserialize( $USER_DB['LoginConfig'] );
|
||||
|
||||
if(empty($LoginConfig['login_page']) || $LoginConfig['login_page'] == 'admin'){
|
||||
$url = "./?c=admin&u={$USER_DB['User']}";
|
||||
}elseif($LoginConfig['login_page'] == 'index'){
|
||||
|
||||
@@ -234,26 +234,31 @@ function echo_pwds(){
|
||||
}
|
||||
//检查链接
|
||||
function check_link($fid,$title,$url,$url_standby_s=''){
|
||||
$pattern = "/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|sftp:\/\/|magnet:?|ed2k:\/\/|thunder:\/\/|tcp:\/\/|udp:\/\/|rtsp:\/\/).+/";
|
||||
$pattern = "/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|sftp:\/\/|magnet:?|ed2k:\/\/|thunder:\/\/|tcp:\/\/|udp:\/\/|rtsp:\/\/|wsa:\/\/|vmrc:\/\/).+/";
|
||||
$length_limit = unserialize(get_db("global_config","v",["k"=>"length_limit"]));
|
||||
if (empty($fid)) msg(-1,'分类id(fid)不能为空');
|
||||
if (empty($title)) msg(-1,'名称不能为空');
|
||||
if (strlen($title) > 64 ) msg(-1,'名称长度超限');
|
||||
if (strlen(htmlspecialchars($title,ENT_QUOTES)) > 128 ) msg(-1,'名称长度超限-2');
|
||||
if (!has_db('user_categorys',['uid'=>UID ,"cid" => $fid])) msg(-1,'分类不存在');
|
||||
if($length_limit['l_name'] > 0 && strlen($title) > $length_limit['l_name'] ){
|
||||
msg(-1,'链接名称长度不能大于'.$length_limit['l_name'].'个字节');
|
||||
}
|
||||
|
||||
//主链接检测
|
||||
if (empty($url)) msg(-1,'URL不能为空');
|
||||
if (!preg_match($pattern,$url)) msg(-1,'URL无效');
|
||||
if (strlen($url) > 1024 ) msg(-1,'URL长度超限');
|
||||
if (check_xss($url)) msg(-1,'URL存在非法字符');
|
||||
|
||||
if($length_limit['l_url'] > 0 && strlen($url) > $length_limit['l_url'] ){
|
||||
msg(-1,'主链接长度不能大于'.$length_limit['l_url'].'个字节');
|
||||
}
|
||||
//备用链接检测
|
||||
if(!empty($url_standby_s)){
|
||||
foreach ($url_standby_s as $key => $url_standby){
|
||||
//尝试匹配Markdown语法的URL,如果没有则认为直接输入
|
||||
if(preg_match('/\[(.*?)\]\((.*?)\)/', $url_standby, $match)){
|
||||
if (empty($match[1])) msg(-1,'备用链接名称不能为空,若不需要名称请直接输入URL');
|
||||
if (strlen($match[1]) > 64 ) msg(-1,'备用链接名称长度超限');
|
||||
if (strlen(htmlspecialchars($match[1],ENT_QUOTES)) > 128 ) msg(-1,'备用链接名称长度超限-2');
|
||||
if($length_limit['l_url'] > 0 && strlen($match[1]) > $length_limit['l_url'] ){
|
||||
msg(-1,'备用链接长度不能大于'.$length_limit['l_url'].'个字节');
|
||||
}
|
||||
$url = $match[2];
|
||||
}else{
|
||||
$url = $url_standby;
|
||||
@@ -261,7 +266,7 @@ function check_link($fid,$title,$url,$url_standby_s=''){
|
||||
|
||||
if(!preg_match($pattern,$url)){
|
||||
msg(-1,'备选URL无效');
|
||||
}elseif(strlen($url) > 1024){
|
||||
}elseif($length_limit['l_url'] > 0 && strlen($url) > $length_limit['l_url']){
|
||||
msg(-1,'备选URL长度超限');
|
||||
}elseif(check_xss($url)){
|
||||
msg(-1,'备用URL存在非法字符');
|
||||
@@ -286,8 +291,9 @@ function Set_key($USER_DB){
|
||||
$LoginConfig = unserialize($USER_DB['LoginConfig']);
|
||||
$session = $LoginConfig['Session']; //保持时间(单位天)
|
||||
$Expire = Get_ExpireTime($session); //计算到期时间戳
|
||||
$real_Expire = ($Expire == 0) ? time() + 86400 : $Expire;
|
||||
$time = time(); //取当前时间
|
||||
$key = Getkey($USER_DB['User'],Get_MD5_Password($USER_DB["Password"],$USER_DB["RegTime"]),$Expire,$LoginConfig['KeySecurity'],$time);
|
||||
$key = Getkey($USER_DB['User'],Get_MD5_Password($USER_DB["Password"],$USER_DB["RegTime"]),$real_Expire,$LoginConfig['KeySecurity'],$time);
|
||||
setcookie($USER_DB['User'].'_key', $key, $session == 0 ? 0 : $Expire,"/",'',false,$LoginConfig['HttpOnly']==1);
|
||||
insert_db("user_login_info", [
|
||||
"uid" => $USER_DB['ID'],
|
||||
@@ -296,8 +302,8 @@ function Set_key($USER_DB){
|
||||
"ua"=>$_SERVER['HTTP_USER_AGENT'],
|
||||
"login_time"=>$time,
|
||||
"last_time"=>$time,
|
||||
"expire_time"=>$Expire,
|
||||
"cookie_key"=>md5($key)]); //不记录用户真实key,同时防止Cookie攻击
|
||||
"expire_time"=>$real_Expire,
|
||||
"cookie_key"=>md5($key)]);
|
||||
return $key;
|
||||
}
|
||||
|
||||
@@ -330,21 +336,39 @@ function Get_ExpireTime($day =30){
|
||||
}
|
||||
//验证登录
|
||||
function is_login(){
|
||||
global $USER_DB,$db;
|
||||
global $USER_DB;
|
||||
$time = time();
|
||||
$LoginConfig = unserialize($USER_DB['LoginConfig']);
|
||||
|
||||
if (!function_exists('delete_expired_info')) {
|
||||
function delete_expired_info($time,$LoginConfig){
|
||||
global $USER_DB;
|
||||
if(empty($LoginConfig['Session'])){
|
||||
$where = [
|
||||
"uid" => $USER_DB['ID'],
|
||||
//"expire_time" => 0,
|
||||
"OR" => [
|
||||
"last_time[<]" => strtotime('-1 day'),
|
||||
"login_time[<]" => strtotime('-15 day')
|
||||
]
|
||||
];
|
||||
}else{
|
||||
$where = [
|
||||
"uid" => $USER_DB['ID'],
|
||||
"OR" => [
|
||||
"expire_time[<]" => $time,
|
||||
"last_time[<]" => strtotime("-{$LoginConfig['KeyClear']} day")
|
||||
]
|
||||
];
|
||||
}
|
||||
//var_dump(select_db('user_login_info','*',$where),$where);exit;
|
||||
delete_db("user_login_info", $where); //清理到期Key
|
||||
update_db("global_user",["kct"=>$time],["User" => $USER_DB['User']]); //记录清理时间
|
||||
}
|
||||
}
|
||||
|
||||
//清理间隔30分钟(1800秒)
|
||||
if( ($USER_DB['kct'] + 1800) < $time ){
|
||||
$lt = $time - ($LoginConfig['KeyClear'] * 24 * 60 * 60);
|
||||
$where = ["AND" =>
|
||||
[
|
||||
"uid" => $USER_DB['ID'],
|
||||
"OR" => ["expire_time[<]" => $time,"last_time[<]" => $lt]
|
||||
]
|
||||
];
|
||||
delete_db("user_login_info", $where); //清理到期Key
|
||||
update_db("global_user",["kct"=>$time],["User" => $USER_DB['User']]); //记录清理时间
|
||||
delete_expired_info($time,$LoginConfig);
|
||||
}
|
||||
|
||||
//查询登录信息
|
||||
@@ -354,26 +378,22 @@ function is_login(){
|
||||
//没找到返回未登录
|
||||
if(empty($info)){return false;}
|
||||
|
||||
|
||||
|
||||
//UA验证
|
||||
if($LoginConfig['KeySecurity'] > 0 && $_SERVER['HTTP_USER_AGENT'] != $info['ua']){return false;}
|
||||
//IP验证
|
||||
if($LoginConfig['KeySecurity'] > 1 && Get_IP() != $info['ip']){return false;}
|
||||
|
||||
//到期验证(同时重新计算)
|
||||
if( $info['expire_time'] != 0 && ($time > $info['expire_time'] || $time > ($info['login_time'] + ($LoginConfig['Session'] * 24 * 60 * 60) ) )){
|
||||
delete_db("user_login_info", $where);
|
||||
return false;
|
||||
}
|
||||
//会话Key验证(没有到期时间时如果距上次访问时间大于24小时认为无效)
|
||||
if($info['expire_time'] == 0 && ($info['last_time'] + 86400) < $time){
|
||||
delete_db("user_login_info", $where);
|
||||
return false;
|
||||
}//有到期时间,且开启了Key清理
|
||||
elseif($LoginConfig['KeyClear'] != 0 && ($info['last_time'] + ($LoginConfig['KeyClear'] * 24 * 60 * 60)) < $time ){
|
||||
delete_db("user_login_info", $where);
|
||||
return false;
|
||||
//根据登录保持选项来判断key是否有效
|
||||
if(empty($LoginConfig['Session'])){ //浏览器关闭时
|
||||
if($info['last_time'] < strtotime('-1 day') || $info['login_time'] < strtotime('-15 day')){ //上次访问超过1天 或 登录时间超过15天
|
||||
delete_expired_info($time,$LoginConfig);
|
||||
return false;
|
||||
}
|
||||
}else{ //保持天数(已到期或上次访问时间超时)
|
||||
if($info['expire_time'] < $time || $info['last_time'] < strtotime("-{$LoginConfig['KeyClear']} day")){
|
||||
delete_expired_info($time,$LoginConfig);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Key验证
|
||||
@@ -426,10 +446,10 @@ function is_subscribe($type = 'bool'){
|
||||
$count = count($host);
|
||||
if($count != 2){
|
||||
$data['host'] = $host[$count-2].'.'.$host[$count-1];
|
||||
//如果存在端口则去除
|
||||
if(preg_match("/(.+):\d+/",$data['host'],$host)) {
|
||||
$data['host'] = $host[1];
|
||||
}
|
||||
}
|
||||
//如果存在端口则去除
|
||||
if(preg_match("/(.+):\d+/",$data['host'],$host)) {
|
||||
$data['host'] = $host[1];
|
||||
}
|
||||
}
|
||||
if(!stristr($data['domain'],$data['host'])){
|
||||
@@ -484,24 +504,30 @@ function Get_IP() {
|
||||
$ip = getenv('HTTP_CLIENT_IP');
|
||||
}elseif(getenv('HTTP_X_FORWARDED_FOR')) {
|
||||
$ip = getenv('HTTP_X_FORWARDED_FOR');
|
||||
} elseif (getenv('HTTP_X_FORWARDED')) {
|
||||
}elseif (getenv('HTTP_X_FORWARDED')) {
|
||||
$ip = getenv('HTTP_X_FORWARDED');
|
||||
} elseif (getenv('HTTP_FORWARDED_FOR')) {
|
||||
}elseif (getenv('HTTP_FORWARDED_FOR')) {
|
||||
$ip = getenv('HTTP_FORWARDED_FOR');
|
||||
} elseif (getenv('HTTP_FORWARDED')) {
|
||||
}elseif (getenv('HTTP_FORWARDED')) {
|
||||
$ip = getenv('HTTP_FORWARDED');
|
||||
}else{
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
}
|
||||
if(strpos($ip, ',') != false) {
|
||||
$ip = reset(explode(",", $ip));
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
//获取URL状态码
|
||||
function get_http_code($url,$TIMEOUT = 10) {
|
||||
function get_http_code($url,$TIMEOUT = 10 ,$NOBODY = true) {
|
||||
if(!preg_match("/^(http:\/\/|https:\/\/).*/",$url)){
|
||||
return false;
|
||||
}
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HEADER, 1);
|
||||
curl_setopt($curl, CURLOPT_NOBODY, true);
|
||||
curl_setopt($curl, CURLOPT_NOBODY, $NOBODY);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $TIMEOUT);
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36');
|
||||
@@ -511,7 +537,10 @@ function get_http_code($url,$TIMEOUT = 10) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
function ccurl($url,$overtime = 3){
|
||||
function ccurl($url,$overtime = 3,$Referer = false,$post_data = false){
|
||||
if(!preg_match("/^(http:\/\/|https:\/\/).*/",$url)){
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$curl = curl_init ( $url ) ; //初始化
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $overtime ); //超时
|
||||
@@ -520,6 +549,16 @@ function ccurl($url,$overtime = 3){
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
if(!empty($post_data)){
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
|
||||
}
|
||||
|
||||
if($Referer === true){
|
||||
curl_setopt($curl, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
|
||||
}elseif(!empty($Referer)){
|
||||
curl_setopt($curl, CURLOPT_REFERER, $Referer);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36');
|
||||
$Res["content"] = curl_exec ( $curl ) ;
|
||||
$Res["code"] = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
@@ -531,31 +570,40 @@ function ccurl($url,$overtime = 3){
|
||||
return $Res;
|
||||
}
|
||||
|
||||
function downFile($url, $file = '', $savePath = './data/temp/'){
|
||||
function downFile($url, $file = '', $savePath = './data/temp/',$referer = '',$TIMEOUT = 60,$post_data = false){
|
||||
if(!preg_match("/^(http:\/\/|https:\/\/).*/",$url)){
|
||||
return false;
|
||||
}
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 60); //超时/秒
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $TIMEOUT); //超时/秒
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //不直接输出
|
||||
curl_setopt($ch, CURLOPT_HEADER, FALSE); //不需要response header
|
||||
curl_setopt($ch, CURLOPT_NOBODY, FALSE); //需要response body
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //允许重定向(适应网盘下载)
|
||||
|
||||
if(!empty($post_data)){
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||||
}
|
||||
if(!empty($referer)){
|
||||
curl_setopt($ch, CURLOPT_REFERER, $referer);
|
||||
}
|
||||
try{
|
||||
$res = curl_exec($ch);
|
||||
}finally{
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
if ($code == '200') { //状态码正常
|
||||
|
||||
if(empty($file)){ //如果文件名为空
|
||||
$file = date('Ymd_His').'.tmp';
|
||||
}
|
||||
$fullName = rtrim($savePath, '/') . '/' . $file;
|
||||
return file_put_contents($fullName, $res);
|
||||
return file_put_contents($fullName, $res) > 0;
|
||||
}elseif($code == '202'){
|
||||
return $res;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
@@ -621,6 +669,13 @@ function is_Duplicated($array, $field){
|
||||
//检查权限(有权限返回true 没有权限时根传递参数1是返回false 2是直接返回错误信息)
|
||||
function check_purview($name,$return_type){
|
||||
global $USER_DB;
|
||||
if($USER_DB == null){
|
||||
return true;
|
||||
}
|
||||
//230705新增,禁止判断默认用户是否可以使用自定义代码
|
||||
if($USER_DB['UserGroup'] == 'default' && $GLOBALS['global_config']['c_code'] != '1' && ( $name == 'header' || $name == 'footer' )){
|
||||
return false;
|
||||
}
|
||||
if($USER_DB['UserGroup'] == 'root' || $USER_DB['UserGroup'] == 'default'){
|
||||
return true;
|
||||
}
|
||||
@@ -636,6 +691,26 @@ function check_purview($name,$return_type){
|
||||
}
|
||||
|
||||
}
|
||||
//数据加密函
|
||||
function data_encryption($method,$extend = []){
|
||||
$subscribe = unserialize(get_db('global_config','v',["k" => "s_subscribe"]));
|
||||
if(!isset($subscribe['public']) || empty($subscribe['public'])){
|
||||
msg(-1,'未检测到授权秘钥,如果已经获取授权,请在授权管理页面点击保存设置后在重试!');
|
||||
}
|
||||
$data['key'] = $subscribe['order_id'];
|
||||
$data['host'] = $_SERVER['HTTP_HOST'];
|
||||
$data['sysver'] = SysVer;
|
||||
$data['time'] = time();
|
||||
$data['ip'] = Get_IP();
|
||||
$data['method'] = $method;
|
||||
$publicKey = openssl_pkey_get_public($subscribe['public']);
|
||||
openssl_public_encrypt(json_encode($data), $encryptedData, $publicKey, OPENSSL_PKCS1_PADDING);
|
||||
$data = $extend;
|
||||
$data['data'] = base64_encode($encryptedData);
|
||||
$data['md5'] = md5($subscribe['order_id']);
|
||||
$data['email'] = md5($subscribe['email']);
|
||||
return json_encode($data);
|
||||
}
|
||||
//字节格式化
|
||||
function byteFormat($bytes) {
|
||||
$sizetext = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
|
||||
@@ -664,49 +739,57 @@ function Get_Rand_Str( $length = 8 ,$extend = false){
|
||||
}
|
||||
//发送邮件
|
||||
function send_email($config){
|
||||
if(!is_file(DIR.'/system/PHPMailer/PHPMailer.php')){
|
||||
msg(-1,'未安装PHPMailer!');
|
||||
}
|
||||
msg(0,'免费版不支持此功能');
|
||||
}
|
||||
|
||||
require DIR.'/system/PHPMailer/Exception.php';
|
||||
require DIR.'/system/PHPMailer/PHPMailer.php';
|
||||
require DIR.'/system/PHPMailer/SMTP.php';
|
||||
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
|
||||
try {
|
||||
$mail->CharSet ="UTF-8";
|
||||
$mail->SMTPDebug = 0;
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $config['host'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $config['user'];
|
||||
$mail->Password = $config['pwd'];
|
||||
$mail->SMTPSecure = $config['secure'];
|
||||
$mail->Port = intval($config['port']);
|
||||
|
||||
if(preg_match('/(.+)<(.+)>/', $config['sender'], $match)){
|
||||
$mail->setFrom($match[2],$match[1]);
|
||||
}else{
|
||||
$mail->setFrom($config['sender']);
|
||||
}
|
||||
|
||||
$mail->addAddress($config['addressee']); //收件人
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $config['Subject'];
|
||||
$mail->Body = $config['Body'];
|
||||
$mail->send();
|
||||
if(!empty($config['return']) && $config['return'] == 'bool'){
|
||||
return true;
|
||||
}
|
||||
msg(1,'邮件发送成功');
|
||||
} catch (Exception $e) {
|
||||
if(!empty($config['return']) && $config['return'] == 'bool'){
|
||||
return false;
|
||||
}
|
||||
if(Debug){
|
||||
msgA(['code'=>-1,'msg'=>'发送失败:'.$mail->ErrorInfo]);
|
||||
}else{
|
||||
msg(-1,'发送失败');
|
||||
}
|
||||
//统计访问ip数
|
||||
function count_ip(){
|
||||
$ip = Get_IP(); $k = date('Ymd'); $t = 'access_ip';
|
||||
if(!has_db('user_count',['uid'=>UID,'k'=>$k,'t'=>$t,'e'=>$ip])){
|
||||
insert_db("user_count",['uid'=>UID,'k'=>$k,'t'=>$t,'e'=>$ip,'v'=>0]);
|
||||
write_user_count($k,'ip_count');//访问ip数+1
|
||||
}
|
||||
}
|
||||
|
||||
//清理缓存
|
||||
function clean_cache(){
|
||||
write_global_config('notice','','官方公告(缓存)');
|
||||
foreach(['home','login','transit','register','guide','article','apply','verify','guestbook'] as $v){
|
||||
write_global_config($v.'_cache','',$v.'_模板缓存');
|
||||
}
|
||||
}
|
||||
|
||||
//取系统版本(日期)
|
||||
function get_SysVer(){
|
||||
if(preg_match('/^v.+-(\d{8})$/i',SysVer,$matches)){
|
||||
return $matches[1];
|
||||
}else{
|
||||
return 19990101;
|
||||
}
|
||||
}
|
||||
|
||||
function get_HOST(){
|
||||
return (((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' :'http://').$_SERVER['HTTP_HOST'];
|
||||
}
|
||||
function get_UUID(){
|
||||
return ($GLOBALS['global_config']['static_link'] == 2 ? UID : U);
|
||||
}
|
||||
function get_surl($input,$id=''){
|
||||
return get_HOST().'/'.strtr($input, ['{UUID}'=>get_UUID(),'{id}'=>$id]);
|
||||
}
|
||||
function get_OEM(){
|
||||
$OEM['program_name'] = "TwoNav";
|
||||
return $OEM;
|
||||
}
|
||||
//返回404
|
||||
function Not_Found() {
|
||||
header('HTTP/1.1 404 Not Found');header("status: 404 Not Found");exit;
|
||||
}
|
||||
|
||||
function process_url_idn($url) {
|
||||
$parsed_url = parse_url($url);
|
||||
if(!preg_match('/[\x{4e00}-\x{9fa5}]/u', $parsed_url['host'])){
|
||||
return $url;
|
||||
}
|
||||
return substr_replace($url, idn_to_ascii($parsed_url['host']), strpos($url, "//") + 2, strlen($parsed_url['host']));
|
||||
}
|
||||