ui
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,53 +1,59 @@
|
||||
layui.define(['jquery'], function(exports) {
|
||||
layui.define(['jquery'], function (exports) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button component
|
||||
* */
|
||||
var MOD_NAME = 'button',
|
||||
$ = layui.jquery;
|
||||
|
||||
var button = function(opt) {
|
||||
var button = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button start loading
|
||||
* */
|
||||
button.prototype.load = function(opt) {
|
||||
|
||||
var option = {
|
||||
button.prototype.load = function (opt) {
|
||||
|
||||
var options = {
|
||||
elem: opt.elem,
|
||||
time: opt.time ? opt.time : false,
|
||||
done: opt.done ? opt.done : function(){}
|
||||
done: opt.done ? opt.done : function () { }
|
||||
}
|
||||
var text = $(option.elem).html();
|
||||
|
||||
$(option.elem).html("<i class='layui-anim layui-anim-rotate layui-icon layui-anim-loop layui-icon-loading'/>");
|
||||
|
||||
$(option.elem).attr("disabled", "disabled");
|
||||
|
||||
var buttons = $(option.elem);
|
||||
|
||||
if (option.time != "" || option.time !=false) {
|
||||
setTimeout(function() {
|
||||
$(option.elem).attr("disabled", false);
|
||||
buttons.html(text);
|
||||
option.done();
|
||||
}, option.time);
|
||||
|
||||
var text = $(options.elem).html();
|
||||
|
||||
$(options.elem).html("<i class='layui-anim layui-anim-rotate layui-icon layui-anim-loop layui-icon-loading'/>");
|
||||
$(options.elem).attr("disabled", "disabled");
|
||||
|
||||
var $button = $(options.elem);
|
||||
|
||||
if (options.time != "" || options.time != false) {
|
||||
setTimeout(function () {
|
||||
$button.attr("disabled", false);
|
||||
$button.html(text);
|
||||
options.done();
|
||||
}, options.time);
|
||||
}
|
||||
option.text = text;
|
||||
return new button(option);
|
||||
options.text = text;
|
||||
return new button(options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button stop loaded
|
||||
* */
|
||||
button.prototype.stop = function(success) {
|
||||
button.prototype.stop = function (success) {
|
||||
$(this.option.elem).attr("disabled", false);
|
||||
$(this.option.elem).html(this.option.text);
|
||||
success && success();
|
||||
}
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new button());
|
||||
});
|
||||
|
||||
37
web/statics/component/pear/module/extends/count.js
Normal file
37
web/statics/component/pear/module/extends/count.js
Normal file
@@ -0,0 +1,37 @@
|
||||
layui.define(['jquery', 'element'], function(exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = 'count',
|
||||
$ = layui.jquery,
|
||||
element = layui.element;
|
||||
|
||||
var count = new function() {
|
||||
|
||||
this.up = function(targetEle, options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
var $this = document.getElementById(targetEle),
|
||||
time = options.time,
|
||||
finalNum = options.num,
|
||||
regulator = options.regulator,
|
||||
step = finalNum / (time / regulator),
|
||||
count = 0.00,
|
||||
initial = 0;
|
||||
|
||||
var timer = setInterval(function() {
|
||||
count = count + step;
|
||||
if (count >= finalNum) {
|
||||
clearInterval(timer);
|
||||
count = finalNum;
|
||||
}
|
||||
var t = count.toFixed(options.bit?options.bit:0);;
|
||||
if (t == initial) return;
|
||||
initial = t;
|
||||
$this.innerHTML = initial;
|
||||
}, 30);
|
||||
}
|
||||
|
||||
}
|
||||
exports(MOD_NAME, count);
|
||||
});
|
||||
95172
web/statics/component/pear/module/extends/echarts.js
Normal file
95172
web/statics/component/pear/module/extends/echarts.js
Normal file
File diff suppressed because it is too large
Load Diff
450
web/statics/component/pear/module/extends/echartsTheme.js
Normal file
450
web/statics/component/pear/module/extends/echartsTheme.js
Normal file
@@ -0,0 +1,450 @@
|
||||
layui.define(function (exports) {
|
||||
exports('echartsTheme',
|
||||
{
|
||||
"color": [
|
||||
"#3fb1e3",
|
||||
"#6be6c1",
|
||||
"#626c91",
|
||||
"#a0a7e6",
|
||||
"#c4ebad",
|
||||
"#96dee8"
|
||||
],
|
||||
"backgroundColor": "rgba(252,252,252,0)",
|
||||
"textStyle": {},
|
||||
"title": {
|
||||
"textStyle": {
|
||||
"color": "#666666"
|
||||
},
|
||||
"subtextStyle": {
|
||||
"color": "#999999"
|
||||
}
|
||||
},
|
||||
"line": {
|
||||
"itemStyle": {
|
||||
"borderWidth": "3"
|
||||
},
|
||||
"lineStyle": {
|
||||
"width": "4"
|
||||
},
|
||||
"symbolSize": "10",
|
||||
"symbol": "emptyCircle",
|
||||
"smooth": true
|
||||
},
|
||||
"radar": {
|
||||
"itemStyle": {
|
||||
"borderWidth": "3"
|
||||
},
|
||||
"lineStyle": {
|
||||
"width": "4"
|
||||
},
|
||||
"symbolSize": "10",
|
||||
"symbol": "emptyCircle",
|
||||
"smooth": true
|
||||
},
|
||||
"bar": {
|
||||
"itemStyle": {
|
||||
"barBorderWidth": 0,
|
||||
"barBorderColor": "#ccc"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"barBorderWidth": 0,
|
||||
"barBorderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"pie": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"scatter": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"boxplot": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parallel": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sankey": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"funnel": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gauge": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
}
|
||||
}
|
||||
},
|
||||
"candlestick": {
|
||||
"itemStyle": {
|
||||
"color": "#e6a0d2",
|
||||
"color0": "transparent",
|
||||
"borderColor": "#e6a0d2",
|
||||
"borderColor0": "#3fb1e3",
|
||||
"borderWidth": "2"
|
||||
}
|
||||
},
|
||||
"graph": {
|
||||
"itemStyle": {
|
||||
"borderWidth": 0,
|
||||
"borderColor": "#ccc"
|
||||
},
|
||||
"lineStyle": {
|
||||
"width": "1",
|
||||
"color": "#cccccc"
|
||||
},
|
||||
"symbolSize": "10",
|
||||
"symbol": "emptyCircle",
|
||||
"smooth": true,
|
||||
"color": [
|
||||
"#3fb1e3",
|
||||
"#6be6c1",
|
||||
"#626c91",
|
||||
"#a0a7e6",
|
||||
"#c4ebad",
|
||||
"#96dee8"
|
||||
],
|
||||
"label": {
|
||||
"color": "#ffffff"
|
||||
}
|
||||
},
|
||||
"map": {
|
||||
"itemStyle": {
|
||||
"areaColor": "#eeeeee",
|
||||
"borderColor": "#aaaaaa",
|
||||
"borderWidth": 0.5
|
||||
},
|
||||
"label": {
|
||||
"color": "#ffffff"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"areaColor": "rgba(63,177,227,0.25)",
|
||||
"borderColor": "#3fb1e3",
|
||||
"borderWidth": 1
|
||||
},
|
||||
"label": {
|
||||
"color": "rgb(63,177,227)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"geo": {
|
||||
"itemStyle": {
|
||||
"areaColor": "#eeeeee",
|
||||
"borderColor": "#aaaaaa",
|
||||
"borderWidth": 0.5
|
||||
},
|
||||
"label": {
|
||||
"color": "#ffffff"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"areaColor": "rgba(63,177,227,0.25)",
|
||||
"borderColor": "#3fb1e3",
|
||||
"borderWidth": 1
|
||||
},
|
||||
"label": {
|
||||
"color": "rgb(63,177,227)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"categoryAxis": {
|
||||
"axisLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": "#cccccc"
|
||||
}
|
||||
},
|
||||
"axisTick": {
|
||||
"show": false,
|
||||
"lineStyle": {
|
||||
"color": "#333"
|
||||
}
|
||||
},
|
||||
"axisLabel": {
|
||||
"show": true,
|
||||
|
||||
"color": "#999999"
|
||||
|
||||
},
|
||||
"splitLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": [
|
||||
"#eeeeee"
|
||||
]
|
||||
}
|
||||
},
|
||||
"splitArea": {
|
||||
"show": false,
|
||||
"areaStyle": {
|
||||
"color": [
|
||||
"rgba(250,250,250,0.05)",
|
||||
"rgba(200,200,200,0.02)"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"valueAxis": {
|
||||
"axisLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": "#cccccc"
|
||||
}
|
||||
},
|
||||
"axisTick": {
|
||||
"show": false,
|
||||
"lineStyle": {
|
||||
"color": "#333"
|
||||
}
|
||||
},
|
||||
"axisLabel": {
|
||||
"show": true,
|
||||
"color": "#999999"
|
||||
|
||||
},
|
||||
"splitLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": [
|
||||
"#eeeeee"
|
||||
]
|
||||
}
|
||||
},
|
||||
"splitArea": {
|
||||
"show": false,
|
||||
"areaStyle": {
|
||||
"color": [
|
||||
"rgba(250,250,250,0.05)",
|
||||
"rgba(200,200,200,0.02)"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"logAxis": {
|
||||
"axisLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": "#cccccc"
|
||||
}
|
||||
},
|
||||
"axisTick": {
|
||||
"show": false,
|
||||
"lineStyle": {
|
||||
"color": "#333"
|
||||
}
|
||||
},
|
||||
"axisLabel": {
|
||||
"show": true,
|
||||
"color": "#999999"
|
||||
|
||||
},
|
||||
"splitLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": [
|
||||
"#eeeeee"
|
||||
]
|
||||
}
|
||||
},
|
||||
"splitArea": {
|
||||
"show": false,
|
||||
"areaStyle": {
|
||||
"color": [
|
||||
"rgba(250,250,250,0.05)",
|
||||
"rgba(200,200,200,0.02)"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"timeAxis": {
|
||||
"axisLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": "#cccccc"
|
||||
}
|
||||
},
|
||||
"axisTick": {
|
||||
"show": false,
|
||||
"lineStyle": {
|
||||
"color": "#333"
|
||||
}
|
||||
},
|
||||
"axisLabel": {
|
||||
"show": true,
|
||||
|
||||
"color": "#999999"
|
||||
|
||||
},
|
||||
"splitLine": {
|
||||
"show": true,
|
||||
"lineStyle": {
|
||||
"color": [
|
||||
"#eeeeee"
|
||||
]
|
||||
}
|
||||
},
|
||||
"splitArea": {
|
||||
"show": false,
|
||||
"areaStyle": {
|
||||
"color": [
|
||||
"rgba(250,250,250,0.05)",
|
||||
"rgba(200,200,200,0.02)"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"toolbox": {
|
||||
"iconStyle": {
|
||||
"borderColor": "#999999"
|
||||
},
|
||||
"emphasis": {
|
||||
"iconStyle": {
|
||||
"borderColor": "#666666"
|
||||
}
|
||||
}
|
||||
},
|
||||
"legend": {
|
||||
"textStyle": {
|
||||
"color": "#999999"
|
||||
}
|
||||
},
|
||||
"tooltip": {
|
||||
"axisPointer": {
|
||||
"lineStyle": {
|
||||
"color": "#cccccc",
|
||||
"width": 1
|
||||
},
|
||||
"crossStyle": {
|
||||
"color": "#cccccc",
|
||||
"width": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
"timeline": {
|
||||
"lineStyle": {
|
||||
"color": "#626c91",
|
||||
"width": 1
|
||||
},
|
||||
"itemStyle": {
|
||||
"color": "#626c91",
|
||||
"borderWidth": 1
|
||||
|
||||
},
|
||||
"controlStyle": {
|
||||
"color": "#626c91",
|
||||
"borderColor": "#626c91",
|
||||
"borderWidth": 0.5
|
||||
},
|
||||
"checkpointStyle": {
|
||||
"color": "#3fb1e3",
|
||||
"borderColor": "rgba(63,177,227,0.15)"
|
||||
},
|
||||
"label": {
|
||||
"color": "#626c91"
|
||||
},
|
||||
"emphasis": {
|
||||
"itemStyle": {
|
||||
"color": "#626c91"
|
||||
},
|
||||
"controlStyle": {
|
||||
"color": "#626c91",
|
||||
"borderColor": "#626c91",
|
||||
"borderWidth": 0.5
|
||||
},
|
||||
"label": {
|
||||
"color": "#626c91"
|
||||
}
|
||||
}
|
||||
},
|
||||
"visualMap": {
|
||||
"color": [
|
||||
"#2a99c9",
|
||||
"#afe8ff"
|
||||
]
|
||||
},
|
||||
"dataZoom": {
|
||||
"backgroundColor": "rgba(255,255,255,0)",
|
||||
"dataBackgroundColor": "rgba(222,222,222,1)",
|
||||
"fillerColor": "rgba(114,230,212,0.25)",
|
||||
"handleColor": "#cccccc",
|
||||
"handleSize": "100%",
|
||||
"textStyle": {
|
||||
"color": "#999999"
|
||||
}
|
||||
},
|
||||
"markPoint": {
|
||||
"label": {
|
||||
"color": "#ffffff"
|
||||
},
|
||||
"emphasis": {
|
||||
"label": {
|
||||
"color": "#ffffff"
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
503
web/statics/component/pear/module/extends/nprogress.js
Normal file
503
web/statics/component/pear/module/extends/nprogress.js
Normal file
@@ -0,0 +1,503 @@
|
||||
/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
|
||||
* @license MIT */
|
||||
|
||||
;(function(root, factory) {
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.NProgress = factory();
|
||||
}
|
||||
|
||||
})(this, function() {
|
||||
var NProgress = {};
|
||||
|
||||
NProgress.version = '0.2.0';
|
||||
|
||||
var Settings = NProgress.settings = {
|
||||
minimum: 0.08,
|
||||
easing: 'linear',
|
||||
positionUsing: '',
|
||||
speed: 200,
|
||||
trickle: true,
|
||||
trickleSpeed: 200,
|
||||
showSpinner: true,
|
||||
barSelector: '[role="bar"]',
|
||||
spinnerSelector: '[role="spinner"]',
|
||||
parent: 'body',
|
||||
template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates configuration.
|
||||
*
|
||||
* NProgress.configure({
|
||||
* minimum: 0.1
|
||||
* });
|
||||
*/
|
||||
NProgress.configure = function(options) {
|
||||
var key, value;
|
||||
for (key in options) {
|
||||
value = options[key];
|
||||
if (value !== undefined && options.hasOwnProperty(key)) Settings[key] = value;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Last number.
|
||||
*/
|
||||
|
||||
NProgress.status = null;
|
||||
|
||||
/**
|
||||
* Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
|
||||
*
|
||||
* NProgress.set(0.4);
|
||||
* NProgress.set(1.0);
|
||||
*/
|
||||
|
||||
NProgress.set = function(n) {
|
||||
var started = NProgress.isStarted();
|
||||
|
||||
n = clamp(n, Settings.minimum, 1);
|
||||
NProgress.status = (n === 1 ? null : n);
|
||||
|
||||
var progress = NProgress.render(!started),
|
||||
bar = progress.querySelector(Settings.barSelector),
|
||||
speed = Settings.speed,
|
||||
ease = Settings.easing;
|
||||
|
||||
progress.offsetWidth; /* Repaint */
|
||||
|
||||
queue(function(next) {
|
||||
// Set positionUsing if it hasn't already been set
|
||||
if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS();
|
||||
|
||||
// Add transition
|
||||
css(bar, barPositionCSS(n, speed, ease));
|
||||
|
||||
if (n === 1) {
|
||||
// Fade out
|
||||
css(progress, {
|
||||
transition: 'none',
|
||||
opacity: 1
|
||||
});
|
||||
progress.offsetWidth; /* Repaint */
|
||||
|
||||
setTimeout(function() {
|
||||
css(progress, {
|
||||
transition: 'all ' + speed + 'ms linear',
|
||||
opacity: 0
|
||||
});
|
||||
setTimeout(function() {
|
||||
NProgress.remove();
|
||||
next();
|
||||
}, speed);
|
||||
}, speed);
|
||||
} else {
|
||||
setTimeout(next, speed);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
NProgress.isStarted = function() {
|
||||
return typeof NProgress.status === 'number';
|
||||
};
|
||||
|
||||
/**
|
||||
* Shows the progress bar.
|
||||
* This is the same as setting the status to 0%, except that it doesn't go backwards.
|
||||
*
|
||||
* NProgress.start();
|
||||
*
|
||||
*/
|
||||
NProgress.start = function() {
|
||||
if (!NProgress.status) NProgress.set(0);
|
||||
|
||||
var work = function() {
|
||||
setTimeout(function() {
|
||||
if (!NProgress.status) return;
|
||||
NProgress.trickle();
|
||||
work();
|
||||
}, Settings.trickleSpeed);
|
||||
};
|
||||
|
||||
if (Settings.trickle) work();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hides the progress bar.
|
||||
* This is the *sort of* the same as setting the status to 100%, with the
|
||||
* difference being `done()` makes some placebo effect of some realistic motion.
|
||||
*
|
||||
* NProgress.done();
|
||||
*
|
||||
* If `true` is passed, it will show the progress bar even if its hidden.
|
||||
*
|
||||
* NProgress.done(true);
|
||||
*/
|
||||
|
||||
NProgress.done = function(force) {
|
||||
if (!force && !NProgress.status) return this;
|
||||
|
||||
return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Increments by a random amount.
|
||||
*/
|
||||
|
||||
NProgress.inc = function(amount) {
|
||||
var n = NProgress.status;
|
||||
|
||||
if (!n) {
|
||||
return NProgress.start();
|
||||
} else if(n > 1) {
|
||||
return;
|
||||
} else {
|
||||
if (typeof amount !== 'number') {
|
||||
if (n >= 0 && n < 0.2) { amount = 0.1; }
|
||||
else if (n >= 0.2 && n < 0.5) { amount = 0.04; }
|
||||
else if (n >= 0.5 && n < 0.8) { amount = 0.02; }
|
||||
else if (n >= 0.8 && n < 0.99) { amount = 0.005; }
|
||||
else { amount = 0; }
|
||||
}
|
||||
|
||||
n = clamp(n + amount, 0, 0.994);
|
||||
return NProgress.set(n);
|
||||
}
|
||||
};
|
||||
|
||||
NProgress.trickle = function() {
|
||||
return NProgress.inc();
|
||||
};
|
||||
|
||||
/**
|
||||
* Waits for all supplied jQuery promises and
|
||||
* increases the progress as the promises resolve.
|
||||
*
|
||||
* @param $promise jQUery Promise
|
||||
*/
|
||||
(function() {
|
||||
var initial = 0, current = 0;
|
||||
|
||||
NProgress.promise = function($promise) {
|
||||
if (!$promise || $promise.state() === "resolved") {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (current === 0) {
|
||||
NProgress.start();
|
||||
}
|
||||
|
||||
initial++;
|
||||
current++;
|
||||
|
||||
$promise.always(function() {
|
||||
current--;
|
||||
if (current === 0) {
|
||||
initial = 0;
|
||||
NProgress.done();
|
||||
} else {
|
||||
NProgress.set((initial - current) / initial);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
/**
|
||||
* (Internal) renders the progress bar markup based on the `template`
|
||||
* setting.
|
||||
*/
|
||||
|
||||
NProgress.render = function(fromStart) {
|
||||
if (NProgress.isRendered()) return document.getElementById('nprogress');
|
||||
|
||||
addClass(document.documentElement, 'nprogress-busy');
|
||||
|
||||
var progress = document.createElement('div');
|
||||
progress.id = 'nprogress';
|
||||
progress.innerHTML = Settings.template;
|
||||
|
||||
|
||||
|
||||
var bar = progress.querySelector(Settings.barSelector),
|
||||
perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
|
||||
parent = isDOM(Settings.parent)
|
||||
? Settings.parent
|
||||
: document.querySelector(Settings.parent),
|
||||
spinner
|
||||
|
||||
css(bar, {
|
||||
transition: 'all 0 linear',
|
||||
transform: 'translate3d(' + perc + '%,0,0)'
|
||||
});
|
||||
|
||||
if (!Settings.showSpinner) {
|
||||
spinner = progress.querySelector(Settings.spinnerSelector);
|
||||
spinner && removeElement(spinner);
|
||||
}
|
||||
|
||||
if (parent != document.body) {
|
||||
addClass(parent, 'nprogress-custom-parent');
|
||||
}
|
||||
|
||||
parent.appendChild(progress);
|
||||
return progress;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the element. Opposite of render().
|
||||
*/
|
||||
|
||||
NProgress.remove = function() {
|
||||
removeClass(document.documentElement, 'nprogress-busy');
|
||||
var parent = isDOM(Settings.parent)
|
||||
? Settings.parent
|
||||
: document.querySelector(Settings.parent)
|
||||
removeClass(parent, 'nprogress-custom-parent')
|
||||
var progress = document.getElementById('nprogress');
|
||||
progress && removeElement(progress);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the progress bar is rendered.
|
||||
*/
|
||||
|
||||
NProgress.isRendered = function() {
|
||||
return !!document.getElementById('nprogress');
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine which positioning CSS rule to use.
|
||||
*/
|
||||
|
||||
NProgress.getPositioningCSS = function() {
|
||||
// Sniff on document.body.style
|
||||
var bodyStyle = document.body.style;
|
||||
|
||||
// Sniff prefixes
|
||||
var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' :
|
||||
('MozTransform' in bodyStyle) ? 'Moz' :
|
||||
('msTransform' in bodyStyle) ? 'ms' :
|
||||
('OTransform' in bodyStyle) ? 'O' : '';
|
||||
|
||||
if (vendorPrefix + 'Perspective' in bodyStyle) {
|
||||
// Modern browsers with 3D support, e.g. Webkit, IE10
|
||||
return 'translate3d';
|
||||
} else if (vendorPrefix + 'Transform' in bodyStyle) {
|
||||
// Browsers without 3D support, e.g. IE9
|
||||
return 'translate';
|
||||
} else {
|
||||
// Browsers without translate() support, e.g. IE7-8
|
||||
return 'margin';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function isDOM (obj) {
|
||||
if (typeof HTMLElement === 'object') {
|
||||
return obj instanceof HTMLElement
|
||||
}
|
||||
return (
|
||||
obj &&
|
||||
typeof obj === 'object' &&
|
||||
obj.nodeType === 1 &&
|
||||
typeof obj.nodeName === 'string'
|
||||
)
|
||||
}
|
||||
|
||||
function clamp(n, min, max) {
|
||||
if (n < min) return min;
|
||||
if (n > max) return max;
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) converts a percentage (`0..1`) to a bar translateX
|
||||
* percentage (`-100%..0%`).
|
||||
*/
|
||||
|
||||
function toBarPerc(n) {
|
||||
return (-1 + n) * 100;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (Internal) returns the correct CSS for changing the bar's
|
||||
* position given an n percentage, and speed and ease from Settings
|
||||
*/
|
||||
|
||||
function barPositionCSS(n, speed, ease) {
|
||||
var barCSS;
|
||||
|
||||
if (Settings.positionUsing === 'translate3d') {
|
||||
barCSS = { transform: 'translate3d('+toBarPerc(n)+'%,0,0)' };
|
||||
} else if (Settings.positionUsing === 'translate') {
|
||||
barCSS = { transform: 'translate('+toBarPerc(n)+'%,0)' };
|
||||
} else {
|
||||
barCSS = { 'margin-left': toBarPerc(n)+'%' };
|
||||
}
|
||||
|
||||
barCSS.transition = 'all '+speed+'ms '+ease;
|
||||
|
||||
return barCSS;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Queues a function to be executed.
|
||||
*/
|
||||
|
||||
var queue = (function() {
|
||||
var pending = [];
|
||||
|
||||
function next() {
|
||||
var fn = pending.shift();
|
||||
if (fn) {
|
||||
fn(next);
|
||||
}
|
||||
}
|
||||
|
||||
return function(fn) {
|
||||
pending.push(fn);
|
||||
if (pending.length == 1) next();
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* (Internal) Applies css properties to an element, similar to the jQuery
|
||||
* css method.
|
||||
*
|
||||
* While this helper does assist with vendor prefixed property names, it
|
||||
* does not perform any manipulation of values prior to setting styles.
|
||||
*/
|
||||
|
||||
var css = (function() {
|
||||
var cssPrefixes = [ 'Webkit', 'O', 'Moz', 'ms' ],
|
||||
cssProps = {};
|
||||
|
||||
function camelCase(string) {
|
||||
return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function(match, letter) {
|
||||
return letter.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function getVendorProp(name) {
|
||||
var style = document.body.style;
|
||||
if (name in style) return name;
|
||||
|
||||
var i = cssPrefixes.length,
|
||||
capName = name.charAt(0).toUpperCase() + name.slice(1),
|
||||
vendorName;
|
||||
while (i--) {
|
||||
vendorName = cssPrefixes[i] + capName;
|
||||
if (vendorName in style) return vendorName;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
function getStyleProp(name) {
|
||||
name = camelCase(name);
|
||||
return cssProps[name] || (cssProps[name] = getVendorProp(name));
|
||||
}
|
||||
|
||||
function applyCss(element, prop, value) {
|
||||
prop = getStyleProp(prop);
|
||||
element.style[prop] = value;
|
||||
}
|
||||
|
||||
return function(element, properties) {
|
||||
var args = arguments,
|
||||
prop,
|
||||
value;
|
||||
|
||||
if (args.length == 2) {
|
||||
for (prop in properties) {
|
||||
value = properties[prop];
|
||||
if (value !== undefined && properties.hasOwnProperty(prop)) applyCss(element, prop, value);
|
||||
}
|
||||
} else {
|
||||
applyCss(element, args[1], args[2]);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* (Internal) Determines if an element or space separated list of class names contains a class name.
|
||||
*/
|
||||
|
||||
function hasClass(element, name) {
|
||||
var list = typeof element == 'string' ? element : classList(element);
|
||||
return list.indexOf(' ' + name + ' ') >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Adds a class to an element.
|
||||
*/
|
||||
|
||||
function addClass(element, name) {
|
||||
var oldList = classList(element),
|
||||
newList = oldList + name;
|
||||
|
||||
if (hasClass(oldList, name)) return;
|
||||
|
||||
// Trim the opening space.
|
||||
element.className = newList.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Removes a class from an element.
|
||||
*/
|
||||
|
||||
function removeClass(element, name) {
|
||||
var oldList = classList(element),
|
||||
newList;
|
||||
|
||||
if (!hasClass(element, name)) return;
|
||||
|
||||
// Replace the class name.
|
||||
newList = oldList.replace(' ' + name + ' ', ' ');
|
||||
|
||||
// Trim the opening and closing spaces.
|
||||
element.className = newList.substring(1, newList.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Gets a space separated list of the class names on the element.
|
||||
* The list is wrapped with a single space on each end to facilitate finding
|
||||
* matches within the list.
|
||||
*/
|
||||
|
||||
function classList(element) {
|
||||
return (' ' + (element && element.className || '') + ' ').replace(/\s+/gi, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal) Removes an element from the DOM.
|
||||
*/
|
||||
|
||||
function removeElement(element) {
|
||||
element && element.parentNode && element.parentNode.removeChild(element);
|
||||
}
|
||||
|
||||
return NProgress;
|
||||
});
|
||||
|
||||
layui.define([], function(exports) {
|
||||
exports('nprogress', NProgress);
|
||||
});
|
||||
47
web/statics/component/pear/module/extends/popup.js
Normal file
47
web/statics/component/pear/module/extends/popup.js
Normal file
@@ -0,0 +1,47 @@
|
||||
layui.define(['layer'], function(exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = 'popup',
|
||||
layer = layui.layer;
|
||||
|
||||
var popup = new function() {
|
||||
|
||||
this.success = function(msg) {
|
||||
layer.msg(msg, {
|
||||
icon: 1,
|
||||
time: 1000
|
||||
})
|
||||
},
|
||||
this.failure = function(msg) {
|
||||
layer.msg(msg, {
|
||||
icon: 2,
|
||||
time: 1000
|
||||
})
|
||||
},
|
||||
this.warning = function(msg) {
|
||||
layer.msg(msg, {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
})
|
||||
},
|
||||
this.success = function(msg, callback) {
|
||||
layer.msg(msg, {
|
||||
icon: 1,
|
||||
time: 1000
|
||||
}, callback);
|
||||
},
|
||||
this.failure = function(msg, callback) {
|
||||
layer.msg(msg, {
|
||||
icon: 2,
|
||||
time: 1000
|
||||
}, callback);
|
||||
},
|
||||
this.warming = function(msg, callback) {
|
||||
layer.msg(msg, {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
}, callback);
|
||||
}
|
||||
};
|
||||
exports(MOD_NAME, popup);
|
||||
})
|
||||
1225
web/statics/component/pear/module/extends/toast.js
Normal file
1225
web/statics/component/pear/module/extends/toast.js
Normal file
File diff suppressed because it is too large
Load Diff
2057
web/statics/component/pear/module/extends/yaml.js
Normal file
2057
web/statics/component/pear/module/extends/yaml.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,35 +1,39 @@
|
||||
layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'frame', 'theme', 'convert'],
|
||||
function(exports) {
|
||||
"use strict";
|
||||
layui.define(['jquery', 'element'],
|
||||
function (exports) {
|
||||
|
||||
var $ = layui.jquery;
|
||||
var defer = $.Deferred();
|
||||
var fullScreen = new function() {
|
||||
var fullScreen = new function () {
|
||||
|
||||
this.func = null;
|
||||
this.onFullchange = function(func){
|
||||
|
||||
this.onFullchange = function (func) {
|
||||
this.func = func;
|
||||
var evts = ['fullscreenchange','webkitfullscreenchange','mozfullscreenchange','MSFullscreenChange'];
|
||||
for(var i=0;i<evts.length && func;i++) {
|
||||
var evts = ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange'];
|
||||
for (var i = 0; i < evts.length && func; i++) {
|
||||
window.addEventListener(evts[i], this.func);
|
||||
}
|
||||
}
|
||||
this.fullScreen = function(dom){
|
||||
var docElm = dom && document.querySelector(dom) || document.documentElement;
|
||||
if (docElm.requestFullscreen) {
|
||||
docElm.requestFullscreen();
|
||||
} else if (docElm.mozRequestFullScreen) {
|
||||
docElm.mozRequestFullScreen();
|
||||
} else if (docElm.webkitRequestFullScreen) {
|
||||
docElm.webkitRequestFullScreen();
|
||||
} else if (docElm.msRequestFullscreen) {
|
||||
docElm.msRequestFullscreen();
|
||||
}else{
|
||||
defer.reject("");
|
||||
}
|
||||
defer.resolve("返回值");
|
||||
|
||||
this.fullScreen = function (dom) {
|
||||
var docElm = dom && document.querySelector(dom) || document.documentElement;
|
||||
if (docElm.requestFullscreen) {
|
||||
docElm.requestFullscreen();
|
||||
} else if (docElm.mozRequestFullScreen) {
|
||||
docElm.mozRequestFullScreen();
|
||||
} else if (docElm.webkitRequestFullScreen) {
|
||||
docElm.webkitRequestFullScreen();
|
||||
} else if (docElm.msRequestFullscreen) {
|
||||
docElm.msRequestFullscreen();
|
||||
} else {
|
||||
defer.reject("");
|
||||
}
|
||||
defer.resolve("返回值");
|
||||
return defer.promise();
|
||||
}
|
||||
this.fullClose = function(){
|
||||
if(this.isFullscreen()) {
|
||||
|
||||
this.fullClose = function () {
|
||||
if (this.isFullscreen()) {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
} else if (document.mozCancelFullScreen) {
|
||||
@@ -43,12 +47,14 @@ layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'm
|
||||
defer.resolve("返回值");
|
||||
return defer.promise();
|
||||
}
|
||||
this.isFullscreen = function(){
|
||||
|
||||
this.isFullscreen = function () {
|
||||
return document.fullscreenElement ||
|
||||
document.msFullscreenElement ||
|
||||
document.mozFullScreenElement ||
|
||||
document.webkitFullscreenElement || false;
|
||||
}
|
||||
};
|
||||
|
||||
exports('fullscreen', fullScreen);
|
||||
})
|
||||
|
||||
@@ -5,31 +5,34 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
$ = layui.jquery,
|
||||
element = layui.element;
|
||||
|
||||
var pearMenu = function (opt) {
|
||||
var menu = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
pearMenu.prototype.render = function (opt) {
|
||||
menu.prototype.render = function (opt) {
|
||||
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
async: opt.async,
|
||||
async: opt.async || true,
|
||||
parseData: opt.parseData,
|
||||
url: opt.url,
|
||||
method: opt.method ? opt.method : "GET",
|
||||
defaultOpen: opt.defaultOpen,
|
||||
defaultSelect: opt.defaultSelect,
|
||||
control: opt.control,
|
||||
defaultMenu: opt.defaultMenu,
|
||||
controlWidth: opt.controlWidth ? opt.controlWidth : "auto",
|
||||
defaultMenu: opt.defaultMenu || 0,
|
||||
accordion: opt.accordion,
|
||||
height: opt.height,
|
||||
theme: opt.theme,
|
||||
height: opt.height || "100%",
|
||||
theme: opt.theme || "dark-theme",
|
||||
data: opt.data ? opt.data : [],
|
||||
change: opt.change ? opt.change : function () { },
|
||||
done: opt.done ? opt.done : function () { }
|
||||
}
|
||||
|
||||
var tempDone = option.done;
|
||||
option.done = function(){
|
||||
|
||||
option.done = function () {
|
||||
if (option.control) {
|
||||
rationalizeHeaderControlWidthAuto(option);
|
||||
}
|
||||
@@ -49,18 +52,45 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 延时返回,和 javascript 执行时序关联
|
||||
window.setTimeout(function () { renderMenu(option); }, 500);
|
||||
}
|
||||
|
||||
// 处理高度
|
||||
$("#" + opt.elem).height(option.height)
|
||||
|
||||
setTimeout(function () {
|
||||
$("#" + opt.control + " .control").on("mousewheel DOMMouseScroll", function (event) {
|
||||
|
||||
return new pearMenu(option);
|
||||
var delta = (event.originalEvent.wheelDelta && (event.originalEvent.wheelDelta > 0 ? 1 : -1)) || // chrome & ie
|
||||
(event.originalEvent.detail && (event.originalEvent.detail > 0 ? -1 : 1)); // firefox
|
||||
|
||||
if (delta > 0) {
|
||||
for (var num = 1; num < 20; num++) {
|
||||
setTimeout(function () {
|
||||
if ($("#" + opt.control + " .control ul").css('left').replace("px", "") < 0) {
|
||||
$("#" + opt.control + " .control ul").css("left", "+=2px");
|
||||
}
|
||||
}, 10)
|
||||
}
|
||||
} else if (delta < 0) {
|
||||
if (((Number)($("#" + opt.control + " .control ul").css("left").replace("px", "")) + ($("#" + opt.control + " .control ul").width() - $("#" + opt.control + " .control").width())) > 0) {
|
||||
for (var num = 1; num < 20; num++) {
|
||||
setTimeout(function () {
|
||||
$("#" + opt.control + " .control ul").css("left", "-=2px");
|
||||
}, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 1000)
|
||||
|
||||
return new menu(option);
|
||||
}
|
||||
|
||||
pearMenu.prototype.click = function (clickEvent) {
|
||||
menu.prototype.cache = function () {
|
||||
return this.option.data;
|
||||
}
|
||||
|
||||
menu.prototype.click = function (clickEvent) {
|
||||
var _this = this;
|
||||
$("body").on("click", "#" + _this.option.elem + " .site-demo-active", function () {
|
||||
var dom = $(this);
|
||||
@@ -70,7 +100,8 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
menuPath: dom.attr("menu-title"),
|
||||
menuIcon: dom.attr("menu-icon"),
|
||||
menuUrl: dom.attr("menu-url"),
|
||||
openType: dom.attr("open-type")
|
||||
menuType: dom.attr("menu-type"),
|
||||
menuOpenType: dom.attr("menu-open-type")
|
||||
};
|
||||
var doms = hash(dom);
|
||||
if (doms != null) {
|
||||
@@ -113,14 +144,14 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
return d;
|
||||
}
|
||||
|
||||
pearMenu.prototype.skin = function (skin) {
|
||||
menu.prototype.skin = function (skin) {
|
||||
var menu = $(".pear-nav-tree[lay-filter='" + this.option.elem + "']").parent();
|
||||
menu.removeClass("dark-theme");
|
||||
menu.removeClass("light-theme");
|
||||
menu.addClass(skin);
|
||||
}
|
||||
|
||||
pearMenu.prototype.selectItem = function (pearId) {
|
||||
menu.prototype.selectItem = function (pearId) {
|
||||
if (this.option.control != false) {
|
||||
$("#" + this.option.elem + " a[menu-id='" + pearId + "']").parents(".layui-side-scroll ").find("ul").css({
|
||||
display: "none"
|
||||
@@ -183,7 +214,7 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
}
|
||||
|
||||
var activeMenus;
|
||||
pearMenu.prototype.collapse = function (time) {
|
||||
menu.prototype.collapse = function (time) {
|
||||
var elem = this.option.elem;
|
||||
var config = this.option;
|
||||
if ($("#" + this.option.elem).is(".pear-nav-mini")) {
|
||||
@@ -197,12 +228,12 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
isHoverMenu(false, config);
|
||||
var that = this;
|
||||
$("#" + this.option.elem)
|
||||
.promise()
|
||||
.done(function () {
|
||||
if (that.option.control) {
|
||||
rationalizeHeaderControlWidth(that.option);
|
||||
}
|
||||
})
|
||||
.promise()
|
||||
.done(function () {
|
||||
if (that.option.control) {
|
||||
rationalizeHeaderControlWidth(that.option);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
activeMenus = $("#" + this.option.elem).find(".layui-nav-itemed>a");
|
||||
$("#" + this.option.elem).find(".layui-nav-itemed").removeClass("layui-nav-itemed");
|
||||
@@ -212,13 +243,13 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
}, 400);
|
||||
var that = this;
|
||||
$("#" + this.option.elem)
|
||||
.promise()
|
||||
.done(function () {
|
||||
isHoverMenu(true, config);
|
||||
if (that.option.control) {
|
||||
rationalizeHeaderControlWidth(that.option);
|
||||
}
|
||||
})
|
||||
.promise()
|
||||
.done(function () {
|
||||
isHoverMenu(true, config);
|
||||
if (that.option.control) {
|
||||
rationalizeHeaderControlWidth(that.option);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,13 +283,12 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
}
|
||||
}
|
||||
element.init();
|
||||
downShow(option);
|
||||
option.done();
|
||||
}
|
||||
|
||||
function createMenu(option) {
|
||||
var menuHtml = '<div style="height:100%!important;" class="pear-side-scroll layui-side-scroll ' + option.theme + '"><ul lay-filter="' + option.elem +
|
||||
'" class="layui-nav arrow pear-menu layui-nav-tree pear-nav-tree">'
|
||||
'" class="layui-nav arrow pear-menu layui-nav-tree pear-nav-tree" ' + (option.accordion ? "lay-accordion" : "") + '>'
|
||||
$.each(option.data, function (i, item) {
|
||||
var content = '<li class="layui-nav-item" >';
|
||||
if (i == option.defaultOpen) {
|
||||
@@ -278,7 +308,7 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
'" ' + target + '><i class="' + item.icon + '"></i><span>' + item.title +
|
||||
'</span></a>';
|
||||
} else if (item.type == 1) {
|
||||
content += '<a class="' + className + '" menu-type="' + item.type + '" menu-url="' + item.href + '" menu-id="' +
|
||||
content += '<a class="' + className + '" menu-type="' + item.type + '" menu-open-type="' + item.openType + '" menu-url="' + item.href + '" menu-id="' +
|
||||
item.id +
|
||||
'" menu-title="' + item.title + '" href="' + href + '" ' + target + '><i class="' + item.icon +
|
||||
'"></i><span>' + item.title + '</span></a>';
|
||||
@@ -296,8 +326,7 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
}
|
||||
|
||||
function createMenuAndControl(option) {
|
||||
var control = '<div class="control"><ul class="layui-nav pear-nav-control pc layui-hide-xs" style="width: fit-content;">';
|
||||
control+= '<li class="layui-nav-item tabdrop layui-hide" style="float:right !important;"><a href="javascript:;"><i class="layui-icon layui-icon-more layui-font-20"></i></a><dl class="layui-nav-child"></dl></li>';
|
||||
var control = '<div style="width: ' + option.controlWidth + 'px;white-space: nowrap;overflow-x: scroll;overflow: hidden;" class="control"><ul class="layui-nav pear-nav-control pc layui-hide-xs" style="width: fit-content;">';
|
||||
var controlPe = '<ul class="layui-nav pear-nav-control layui-hide-sm">';
|
||||
// 声 明 头 部
|
||||
var menu = '<div class="layui-side-scroll ' + option.theme + '">'
|
||||
@@ -349,7 +378,7 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
'</span></a>';
|
||||
} else if (note.type == 1) {
|
||||
// 创 建 菜 单 结 构
|
||||
content += '<a ' + target + ' class="' + className + '" menu-type="' + note.type + '" menu-url="' + note.href +
|
||||
content += '<a ' + target + ' class="' + className + '" menu-open-type="' + note.openType + '" menu-type="' + note.type + '" menu-url="' + note.href +
|
||||
'" menu-id="' + note.id +
|
||||
'" menu-title="' + note.title + '" href="' + href + '"><i class="' + note.icon +
|
||||
'"></i><span>' + note.title + '</span></a>';
|
||||
@@ -408,7 +437,7 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
'"><i class="' + note.icon + '"></i><span>' + note.title + '</span></a>';
|
||||
} else if (note.type == 1) {
|
||||
// 创 建 菜 单 结 构
|
||||
content += '<a ' + target + ' class="' + className + '" menu-type="' + note.type + '" menu-url="' + note.href +
|
||||
content += '<a ' + target + ' class="' + className + '" menu-open-type="' + note.openType + '" menu-type="' + note.type + '" menu-url="' + note.href +
|
||||
'" menu-id="' + note.id + '" menu-title="' + note.title + '" menu-icon="' + note.icon + '" href="' + href +
|
||||
'" ><i class="' + note.icon + '"></i><span>' + note.title + '</span></a>';
|
||||
}
|
||||
@@ -425,48 +454,6 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
return content;
|
||||
}
|
||||
|
||||
function downShow(option) {
|
||||
$("body #" + option.elem).on("click", "a[menu-type='0']", function () {
|
||||
if (!$("#" + option.elem).is(".pear-nav-mini")) {
|
||||
var superEle = $(this).parent();
|
||||
var ele = $(this).next('.layui-nav-child');
|
||||
var heights = ele.children("dd").length * 48;
|
||||
|
||||
if ($(this).parent().is(".layui-nav-itemed")) {
|
||||
if (option.accordion) {
|
||||
var currentDom = $(this).parent().siblings('.layui-nav-itemed').children('.layui-nav-child');
|
||||
currentDom.animate({
|
||||
height: '0px'
|
||||
}, 240, function () {
|
||||
currentDom.css({
|
||||
height: "auto",
|
||||
});
|
||||
$(this).parent().removeClass("layui-nav-itemed");
|
||||
$(this).find('.layui-nav-itemed').removeClass("layui-nav-itemed");
|
||||
});
|
||||
}
|
||||
ele.height(0);
|
||||
ele.animate({
|
||||
height: heights + "px"
|
||||
}, 240, function () {
|
||||
ele.css({
|
||||
height: "auto"
|
||||
});
|
||||
});
|
||||
} else {
|
||||
ele.animate({
|
||||
height: "0px"
|
||||
}, 240, function () {
|
||||
ele.css({
|
||||
height: "auto"
|
||||
});
|
||||
$(this).parent().removeClass("layui-nav-itemed");
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 二 级 悬 浮 菜 单*/
|
||||
function isHoverMenu(b, option) {
|
||||
if (b) {
|
||||
@@ -525,68 +512,22 @@ layui.define(['table', 'jquery', 'element'], function (exports) {
|
||||
rationalizeWidth = $headerControl.parent().innerWidth() - $headerControl.position().left;
|
||||
}
|
||||
|
||||
$("#" + option.control + " .control").css({"width": rationalizeWidth});
|
||||
|
||||
var navobj = $("#" + option.control+' ul.pear-nav-control.pc');
|
||||
var dropdown = $(".tabdrop", navobj);
|
||||
|
||||
var collection = 0;
|
||||
var maxwidth = rationalizeWidth - 60;
|
||||
|
||||
var liwidth = 0;
|
||||
//检查超过一行的标签页
|
||||
$('.tabdrop').find('dd').each(function(){
|
||||
var newLI = $('<li></li>').html($(this).html());
|
||||
newLI.addClass('layui-nav-item');
|
||||
newLI.attr('pear-href', $(this).attr('pear-href'));
|
||||
newLI.attr('pear-title', $(this).attr('pear-title'));
|
||||
newLI.attr('pear-id', $(this).attr('pear-id'));
|
||||
navobj.append(newLI);
|
||||
$(this).remove();
|
||||
|
||||
})
|
||||
var litabs = navobj.find('>li').not('.tabdrop');
|
||||
|
||||
var totalwidth = 0;
|
||||
litabs.each(function () {
|
||||
totalwidth += $(this).outerWidth(true);
|
||||
});
|
||||
|
||||
if (rationalizeWidth < totalwidth) {
|
||||
litabs.each(function () {
|
||||
liwidth += $(this).outerWidth(true);
|
||||
if (liwidth > maxwidth) {
|
||||
var newDD = $('<dd></dd>').html($(this).html());
|
||||
newDD.attr('pear-href', $(this).attr('pear-href'));
|
||||
newDD.attr('pear-title', $(this).attr('pear-title'));
|
||||
newDD.attr('pear-id', $(this).attr('pear-id'));
|
||||
dropdown.find('dl').append(newDD);
|
||||
collection++;
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
if (collection > 0) {
|
||||
dropdown.removeClass('layui-hide');
|
||||
if (dropdown.find('.active').length === 1) {
|
||||
dropdown.addClass('active');
|
||||
} else {
|
||||
dropdown.removeClass('active');
|
||||
}
|
||||
}
|
||||
}else {
|
||||
dropdown.addClass('layui-hide');
|
||||
}
|
||||
if (option.controlWidth && rationalizeWidth >= option.controlWidth) {
|
||||
rationalizeWidth = option.controlWidth;
|
||||
}
|
||||
$("#" + option.control + " .control").css({ "width": rationalizeWidth, "transition": "width .15s" });
|
||||
}
|
||||
|
||||
function rationalizeHeaderControlWidthAuto(option){
|
||||
function rationalizeHeaderControlWidthAuto(option) {
|
||||
$(window).on('resize', function () {
|
||||
rationalizeHeaderControlWidth(option);
|
||||
})
|
||||
|
||||
$(document).ready(function () {
|
||||
rationalizeHeaderControlWidth(option);
|
||||
setTimeout(() => {
|
||||
rationalizeHeaderControlWidth(option);
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new pearMenu());
|
||||
})
|
||||
exports(MOD_NAME, new menu());
|
||||
})
|
||||
233
web/statics/component/pear/module/menuSearch.js
Normal file
233
web/statics/component/pear/module/menuSearch.js
Normal file
@@ -0,0 +1,233 @@
|
||||
layui.define(['jquery', 'tools'], function (exports) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button component
|
||||
* */
|
||||
var MOD_NAME = 'menuSearch',
|
||||
tools = layui.tools,
|
||||
$ = layui.jquery;
|
||||
|
||||
var menuSearch = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Button start loading
|
||||
* */
|
||||
menuSearch.prototype.render = function (opt) {
|
||||
|
||||
var options = {
|
||||
select: opt.select,
|
||||
elem: opt.elem,
|
||||
dataProvider: opt.dataProvider,
|
||||
}
|
||||
|
||||
$('body').on("click", options.elem, function () {
|
||||
|
||||
var _html = [
|
||||
`<div class="menu-search-content">
|
||||
<div class="layui-form menu-search-input-wrapper">
|
||||
<div class=" layui-input-wrap layui-input-wrap-prefix">
|
||||
<div class="layui-input-prefix">
|
||||
<i class="layui-icon layui-icon-search"></i>
|
||||
</div>
|
||||
<input type="text" name="menuSearch" value="" placeholder="搜索菜单" autocomplete="off" class="layui-input" lay-affix="clear">
|
||||
</div>
|
||||
</div>
|
||||
<div class="menu-search-no-data">暂 无 信 息</div>
|
||||
<ul class="menu-search-list">
|
||||
</ul>
|
||||
<div class="menu-search-tips">
|
||||
<div>
|
||||
<span class="mr-1">选择</span><kbd class="mr-1 w-5"> ↑ </kbd><kbd class="mr-5 w-5"> ↓ </kbd>
|
||||
<span class="mr-1">确定</span><kbd class="mr-5"> Enter </kbd><span class="mr-1">关闭</span><kbd class="mr-1"> Esc </kbd>
|
||||
</div>
|
||||
</div>
|
||||
</div>`
|
||||
].join('');
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
offset: "10%",
|
||||
area: ['600px'],
|
||||
title: false,
|
||||
closeBtn: 0,
|
||||
shadeClose: true,
|
||||
anim: 0,
|
||||
move: false,
|
||||
content: _html,
|
||||
success: function (layero, layeridx) {
|
||||
|
||||
var $layer = layero;
|
||||
var $content = $(layero).children('.layui-layer-content');
|
||||
var $input = $(".menu-search-input-wrapper input");
|
||||
var $noData = $(".menu-search-no-data");
|
||||
var $list = $(".menu-search-list");
|
||||
var menuData = options.dataProvider();
|
||||
|
||||
$layer.css("border-radius", "6px");
|
||||
$input.off("focus").focus();
|
||||
|
||||
// 搜索输入事件
|
||||
$input.off("input").on("input", tools.debounce(function () {
|
||||
var keywords = $input.val().trim();
|
||||
var filteredMenus = filterHandle(menuData, keywords);
|
||||
|
||||
if (filteredMenus.length) {
|
||||
var tiledMenus = tiledHandle(filteredMenus);
|
||||
var listHtml = createList(tiledMenus);
|
||||
$noData.css("display", "none");
|
||||
$list.html("").append(listHtml).children(":first").addClass("this")
|
||||
} else {
|
||||
$list.html("");
|
||||
$noData.css("display", "flex");
|
||||
}
|
||||
var currentHeight = $(".menu-search-content").outerHeight()
|
||||
$layer.css("height", currentHeight);
|
||||
$content.css("height", currentHeight);
|
||||
}, 500)
|
||||
)
|
||||
|
||||
// 列表点击事件
|
||||
$list.off("click").on("click", "li", function () {
|
||||
var id = $(this).attr("smenu-id");
|
||||
var title = $(this).attr("smenu-title");
|
||||
var url = $(this).attr("smenu-url");
|
||||
var type = $(this).attr("smenu-type");
|
||||
var openType = $(this).attr("smenu-open-type");
|
||||
|
||||
options.select({ id, title, url, type, openType });
|
||||
|
||||
layer.close(layeridx);
|
||||
})
|
||||
|
||||
$list.off('mouseenter').on("mouseenter", "li", function () {
|
||||
$(".menu-search-list li.this").removeClass("this");
|
||||
$(this).addClass("this");
|
||||
}).off("mouseleave").on("mouseleave", "li", function () {
|
||||
$(this).removeClass("this");
|
||||
})
|
||||
|
||||
// 监听键盘事件
|
||||
$('.menu-search-content').off("keydown").keydown(function (e) {
|
||||
if (e.keyCode === 13 || e.keyCode === 32) {
|
||||
e.preventDefault();
|
||||
var that = $(".menu-search-list li.this");
|
||||
var id = that.attr("smenu-id");
|
||||
var title = that.attr("smenu-title");
|
||||
var url = that.attr("smenu-url");
|
||||
var type = that.attr("smenu-type");
|
||||
var openType = that.attr("smenu-open-type");
|
||||
|
||||
options.select({ id, title, url, type, openType });
|
||||
|
||||
layer.close(layeridx);
|
||||
} else if (e.keyCode === 38) {
|
||||
e.preventDefault();
|
||||
var prevEl = $(".menu-search-list li.this").prev();
|
||||
$(".menu-search-list li.this").removeClass("this");
|
||||
if (prevEl.length !== 0) {
|
||||
prevEl.addClass("this");
|
||||
} else {
|
||||
$list.children().last().addClass("this");
|
||||
}
|
||||
} else if (e.keyCode === 40) {
|
||||
e.preventDefault();
|
||||
var nextEl = $(".menu-search-list li.this").next();
|
||||
$(".menu-search-list li.this").removeClass("this");
|
||||
if (nextEl.length !== 0) {
|
||||
nextEl.addClass("this");
|
||||
} else {
|
||||
$list.children().first().addClass("this");
|
||||
}
|
||||
} else if (e.keyCode === 27) {
|
||||
e.preventDefault();
|
||||
layer.close(layeridx);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return new menuSearch(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 创建结果列表
|
||||
*/
|
||||
var createList = function (data) {
|
||||
var listHtml = '';
|
||||
$.each(data, function (index, item) {
|
||||
listHtml += `<li smenu-open-type="${item.info.openType}" smenu-id="${item.info.id}" smenu-icon="'${item.info.icon}" smenu-url="${item.info.href}" smenu-title="${item.info.title}" smenu-type="${item.info.type}">
|
||||
<span><i style="margin-right:10px" class="${item.info.icon}"></i>${item.path}</span>
|
||||
<i class="layui-icon layui-icon-right"></i>
|
||||
</li>`
|
||||
})
|
||||
return listHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* Tree 转 path 列表
|
||||
*/
|
||||
var tiledHandle = function (data) {
|
||||
var tiledMenus = [];
|
||||
var treeTiled = function (data, content) {
|
||||
var path = "";
|
||||
var separator = " / ";
|
||||
if (!content) content = "";
|
||||
$.each(data, function (index, item) {
|
||||
if (item.children && item.children.length) {
|
||||
path += content + item.title + separator;
|
||||
var childPath = treeTiled(item.children, path);
|
||||
path += childPath;
|
||||
if (!childPath) path = ""; // 重置路径
|
||||
} else {
|
||||
path += content + item.title
|
||||
tiledMenus.push({ path: path, info: item });
|
||||
path = ""; //重置路径
|
||||
}
|
||||
})
|
||||
return path;
|
||||
};
|
||||
treeTiled(data);
|
||||
|
||||
return tiledMenus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 查询匹配算法
|
||||
*/
|
||||
var filterHandle = function (filterData, val) {
|
||||
if (!val) return [];
|
||||
var filteredMenus = [];
|
||||
filterData = $.extend(true, {}, filterData);
|
||||
$.each(filterData, function (index, item) {
|
||||
if (item.children && item.children.length) {
|
||||
var children = filterHandle(item.children, val)
|
||||
var obj = $.extend({}, item, { children: children });
|
||||
if (children && children.length) {
|
||||
filteredMenus.push(obj);
|
||||
} else if (item.title.indexOf(val) >= 0) {
|
||||
item.children = []; // 父级匹配但子级不匹配,就去除子级
|
||||
filteredMenus.push($.extend({}, item));
|
||||
}
|
||||
} else if (item.title.indexOf(val) >= 0) {
|
||||
filteredMenus.push(item);
|
||||
}
|
||||
})
|
||||
return filteredMenus;
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new menuSearch());
|
||||
});
|
||||
85
web/statics/component/pear/module/messageCenter.js
Normal file
85
web/statics/component/pear/module/messageCenter.js
Normal file
@@ -0,0 +1,85 @@
|
||||
layui.define(['table', 'jquery', 'element', 'dropdown'], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = 'messageCenter',
|
||||
$ = layui.jquery,
|
||||
dropdown = layui.dropdown;
|
||||
|
||||
var message = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
message.prototype.render = function (opt) {
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
url: opt.url ? opt.url : false,
|
||||
height: opt.height,
|
||||
data: opt.data
|
||||
}
|
||||
if (option.url != false) {
|
||||
$.get(option.url, function (result) {
|
||||
const { code, success, data } = result;
|
||||
$(`${opt.elem}`).append(`<li class="layui-nav-item" lay-unselect="">
|
||||
<a href="#" class="notice layui-icon layui-icon-notice"></a>
|
||||
</li>`);
|
||||
if (code == 200 || success) {
|
||||
option.data = data;
|
||||
dropdown.render({
|
||||
elem: option.elem,
|
||||
align: "center",
|
||||
content: createHtml(option),
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
return new message(option);
|
||||
}
|
||||
|
||||
message.prototype.click = function (callback) {
|
||||
$("*[notice-id]").click(function (event) {
|
||||
event.preventDefault();
|
||||
var id = $(this).attr("notice-id");
|
||||
var title = $(this).attr("notice-title");
|
||||
var context = $(this).attr("notice-context");
|
||||
var form = $(this).attr("notice-form");
|
||||
callback(id, title, context, form);
|
||||
})
|
||||
}
|
||||
|
||||
function createHtml(option) {
|
||||
|
||||
var count = 0;
|
||||
var notice = '<div class="pear-message-center"><div class="layui-tab layui-tab-brief">'
|
||||
var noticeTitle = '<ul class="layui-tab-title">';
|
||||
var noticeContent = '<div class="layui-tab-content" style="height:' + option.height + ';overflow-x: hidden;padding:0px;">';
|
||||
|
||||
$.each(option.data, function (i, item) {
|
||||
|
||||
noticeTitle += `<li class="${i === 0 ? 'layui-this' : ''}">${item.title}</li>`;
|
||||
noticeContent += '<div class="layui-tab-item layui-show">';
|
||||
|
||||
|
||||
$.each(item.children, function (i, note) {
|
||||
count++;
|
||||
noticeContent += '<div class="message-item" notice-form="' + note.form + '" notice-context="' + note.context +
|
||||
'" notice-title="' + note.title + '" notice-id="' + note.id + '">';
|
||||
|
||||
noticeContent += '<img src="' + note.avatar + '"/><div style="display:inline-block;">' + note.title + '</div>' +
|
||||
'<div class="extra">' + note.time + '</div>' +
|
||||
'</div>';
|
||||
})
|
||||
|
||||
noticeContent += '</div>';
|
||||
})
|
||||
|
||||
noticeTitle += '</ul>';
|
||||
noticeContent += '</div>';
|
||||
notice += noticeTitle;
|
||||
notice += noticeContent;
|
||||
notice += "</div></div>"
|
||||
|
||||
return notice;
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new message());
|
||||
})
|
||||
119
web/statics/component/pear/module/page.js
Normal file
119
web/statics/component/pear/module/page.js
Normal file
@@ -0,0 +1,119 @@
|
||||
layui.define(['jquery', 'element'], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var $ = layui.jquery;
|
||||
var element = layui.element;
|
||||
|
||||
var page = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 创建 Page 页面
|
||||
*/
|
||||
page.prototype.render = function (opt) {
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
url: opt.url,
|
||||
width: opt.width || "100%",
|
||||
height: opt.height || "100%",
|
||||
title: opt.title
|
||||
}
|
||||
renderContent(option);
|
||||
return new page(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 切换 Page 页面
|
||||
*/
|
||||
page.prototype.changePage = function (options) {
|
||||
const $frame = $(`#${this.option.elem} .pear-page-content`);
|
||||
if (options.type === "_iframe") {
|
||||
$frame.html(`<iframe src='${options.href}' scrolling='auto' frameborder='0' allowfullscreen='true'></iframe>`);
|
||||
} else {
|
||||
$.ajax({
|
||||
url: options.href,
|
||||
type: 'get',
|
||||
dataType: 'html',
|
||||
success: function (data) {
|
||||
$frame.html(data)
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!');
|
||||
}
|
||||
});
|
||||
}
|
||||
$frame.attr("type", options.type);
|
||||
$frame.attr("href", options.href);
|
||||
}
|
||||
|
||||
page.prototype.refresh = function (loading) {
|
||||
var $frameLoad = $(`#${this.option.elem} .pear-page-loading`);
|
||||
var $frame = $(`#${this.option.elem} .pear-page-content`);
|
||||
if (loading) {
|
||||
$frameLoad.css({
|
||||
display: 'block'
|
||||
});
|
||||
}
|
||||
if ($frame.attr("type") === "_iframe") {
|
||||
$frame.html(`<iframe src='${$frame.attr("href")}' scrolling='auto' frameborder='0' allowfullscreen='true'></iframe>`);
|
||||
const $contentFrame = $frame.find("iframe");
|
||||
$contentFrame.on("load", () => {
|
||||
$frameLoad.fadeOut(1000);
|
||||
})
|
||||
} else {
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: $frame.attr("href"),
|
||||
dataType: 'html',
|
||||
success: function (data) {
|
||||
$frame.html(data)
|
||||
$frameLoad.fadeOut(1000);
|
||||
element.init();
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function renderContent(option) {
|
||||
$("#" + option.elem).html(`
|
||||
<div class='pear-page'>
|
||||
<div class='pear-page-content' type='${option.type}' href='${option.url}'></div>
|
||||
<div class="pear-page-loading">
|
||||
<div class="ball-loader">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>`);
|
||||
|
||||
var $frame = $("#" + option.elem).find(".pear-page-content");
|
||||
|
||||
if (option.type === "_iframe") {
|
||||
$frame.html(`<iframe src='${option.url}' scrolling='auto' frameborder='0' allowfullscreen='true'></iframe>`);
|
||||
} else {
|
||||
$.ajax({
|
||||
url: option.url,
|
||||
type: 'get',
|
||||
dataType: 'html',
|
||||
success: function (data) {
|
||||
$frame.html(data);
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports('page', new page());
|
||||
});
|
||||
@@ -1,11 +1,11 @@
|
||||
layui.define(['jquery', 'element'], function(exports) {
|
||||
layui.define(['jquery', 'element'], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = 'tab',
|
||||
$ = layui.jquery,
|
||||
element = layui.element;
|
||||
|
||||
var pearTab = function(opt) {
|
||||
var pearTab = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
var tabDataCurrent = 0;
|
||||
var contextTabDOM;
|
||||
|
||||
pearTab.prototype.render = function(opt) {
|
||||
pearTab.prototype.render = function (opt) {
|
||||
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
@@ -27,7 +27,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
session: opt.session ? opt.session : false,
|
||||
preload: opt.preload ? opt.preload : false,
|
||||
closeEvent: opt.closeEvent,
|
||||
success: opt.success ? opt.success : function(id) {}
|
||||
success: opt.success ? opt.success : function (id) { }
|
||||
}
|
||||
|
||||
if (option.session) {
|
||||
@@ -35,7 +35,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
tabData = JSON.parse(sessionStorage.getItem(option.elem + "-pear-tab-data"));
|
||||
option.data = JSON.parse(sessionStorage.getItem(option.elem + "-pear-tab-data"));
|
||||
tabDataCurrent = sessionStorage.getItem(option.elem + "-pear-tab-data-current");
|
||||
tabData.forEach(function(item, index) {
|
||||
tabData.forEach(function (item, index) {
|
||||
if (item.id == tabDataCurrent) {
|
||||
option.index = index;
|
||||
}
|
||||
@@ -48,10 +48,10 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
var lastIndex;
|
||||
var tab = createTab(option);
|
||||
$("#" + option.elem).html(tab);
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-prev").click(function() {
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-prev").click(function () {
|
||||
rollPage("left", option);
|
||||
})
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-next").click(function() {
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-next").click(function () {
|
||||
rollPage("right", option);
|
||||
})
|
||||
element.init();
|
||||
@@ -66,7 +66,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
option.success(sessionStorage.getItem(option.elem + "-pear-tab-data-current"));
|
||||
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title").on("contextmenu", "li",
|
||||
function(e) {
|
||||
function (e) {
|
||||
// 获取当前元素位置
|
||||
var top = e.clientY;
|
||||
var left = e.clientX;
|
||||
@@ -95,23 +95,23 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
isOutAnim: false,
|
||||
offset: [top, left],
|
||||
content: menu, //iframe的url,
|
||||
success: function(layero, index) {
|
||||
success: function (layero, index) {
|
||||
layer.close(lastIndex);
|
||||
lastIndex = index;
|
||||
menuEvent(option, index);
|
||||
var timer;
|
||||
$(layero).on('mouseout', function() {
|
||||
timer = setTimeout(function() {
|
||||
$(layero).on('mouseout', function () {
|
||||
timer = setTimeout(function () {
|
||||
layer.close(index);
|
||||
}, 30)
|
||||
});
|
||||
|
||||
$(layero).on('mouseover', function() {
|
||||
$(layero).on('mouseover', function () {
|
||||
clearTimeout(timer);
|
||||
});
|
||||
|
||||
// 清除 item 右击
|
||||
$(layero).on('contextmenu', function() {
|
||||
$(layero).on('contextmenu', function () {
|
||||
return false;
|
||||
})
|
||||
|
||||
@@ -124,10 +124,10 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
return new pearTab(option);
|
||||
}
|
||||
|
||||
pearTab.prototype.click = function(callback) {
|
||||
pearTab.prototype.click = function (callback) {
|
||||
var elem = this.option.elem;
|
||||
var option = this.option;
|
||||
element.on('tab(' + this.option.elem + ')', function(data) {
|
||||
element.on('tab(' + this.option.elem + ')', function (data) {
|
||||
var id = $("#" + elem + " .layui-tab-title .layui-this").attr("lay-id");
|
||||
sessionStorage.setItem(option.elem + "-pear-tab-data-current", id);
|
||||
if (!option.preload) {
|
||||
@@ -136,7 +136,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
var iframeUrl = $iframe.attr("src");
|
||||
if (!iframeUrl || iframeUrl === "about:blank") {
|
||||
// 获取 url 并重载
|
||||
tabData.forEach(function(item, index) {
|
||||
tabData.forEach(function (item, index) {
|
||||
if (item.id === id) {
|
||||
iframeUrl = item.url;
|
||||
}
|
||||
@@ -149,10 +149,10 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
});
|
||||
}
|
||||
|
||||
pearTab.prototype.positionTab = function() {
|
||||
pearTab.prototype.positionTab = function () {
|
||||
var $tabTitle = $('.layui-tab[lay-filter=' + this.option.elem + '] .layui-tab-title');
|
||||
var autoLeft = 0;
|
||||
$tabTitle.children("li").each(function() {
|
||||
$tabTitle.children("li").each(function () {
|
||||
if ($(this).hasClass('layui-this')) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -164,12 +164,12 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}, 200);
|
||||
}
|
||||
|
||||
pearTab.prototype.clear = function() {
|
||||
pearTab.prototype.clear = function () {
|
||||
sessionStorage.removeItem(this.option.elem + "-pear-tab-data");
|
||||
sessionStorage.removeItem(this.option.elem + "-pear-tab-data-current");
|
||||
}
|
||||
|
||||
pearTab.prototype.addTab = function(opt) {
|
||||
pearTab.prototype.addTab = function (opt) {
|
||||
var title = '';
|
||||
if (opt.close) {
|
||||
title += '<span class="pear-tab-active"></span><span class="able-close title">' + opt.title +
|
||||
@@ -193,25 +193,25 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
|
||||
var index = 0;
|
||||
// 根据过滤 fliter 标识, 重置选项卡标题
|
||||
pearTab.prototype.changeTabTitleById = function(elem, id, title) {
|
||||
pearTab.prototype.changeTabTitleById = function (elem, id, title) {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title [lay-id='" + id +
|
||||
"'] .title");
|
||||
currentTab.html(title);
|
||||
}
|
||||
|
||||
// 根据过滤 filter 标识, 删除指定选项卡
|
||||
pearTab.prototype.delTabByElem = function(elem, id, callback) {
|
||||
pearTab.prototype.delTabByElem = function (elem, id, callback) {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title [lay-id='" + id + "']");
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
tabDelete(elem, id, callback);
|
||||
}
|
||||
}
|
||||
// 根据过滤 filter 标识, 删除其他选项卡
|
||||
pearTab.prototype.delOtherTabByElem = function(elem, callback) {
|
||||
pearTab.prototype.delOtherTabByElem = function (elem, callback) {
|
||||
var currentId = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this").attr(
|
||||
"lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function(i) {
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(elem, $(this).attr("lay-id"), callback);
|
||||
@@ -221,18 +221,18 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}
|
||||
|
||||
// 根据过滤 filter 标识, 删除全部选项卡
|
||||
pearTab.prototype.delAllTabByElem = function(elem, callback) {
|
||||
pearTab.prototype.delAllTabByElem = function (elem, callback) {
|
||||
var currentId = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this").attr(
|
||||
"lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function(i) {
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(elem, $(this).attr("lay-id"), callback);
|
||||
}
|
||||
})
|
||||
}
|
||||
// 根据过滤 filter 标识, 删除当前选项卡
|
||||
pearTab.prototype.delCurrentTabByElem = function(elem, callback) {
|
||||
pearTab.prototype.delCurrentTabByElem = function (elem, callback) {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this");
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
var currentId = currentTab.attr("lay-id");
|
||||
@@ -241,7 +241,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}
|
||||
|
||||
// 通过过滤 filter 标识, 新增标签页
|
||||
pearTab.prototype.addTabOnlyByElem = function(elem, opt, time) {
|
||||
pearTab.prototype.addTabOnlyByElem = function (elem, opt, time) {
|
||||
var title = '';
|
||||
if (opt.close) {
|
||||
title += '<span class="pear-tab-active"></span><span class="able-close title">' + opt.title +
|
||||
@@ -265,7 +265,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData));
|
||||
} else {
|
||||
var isData = false;
|
||||
$.each($(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li[lay-id]"), function() {
|
||||
$.each($(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li[lay-id]"), function () {
|
||||
if ($(this).attr("lay-id") == opt.id) {
|
||||
isData = true;
|
||||
}
|
||||
@@ -292,7 +292,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}
|
||||
|
||||
/** 添 加 唯 一 选 项 卡 */
|
||||
pearTab.prototype.addTabOnly = function(opt, time) {
|
||||
pearTab.prototype.addTabOnly = function (opt, time) {
|
||||
var title = '';
|
||||
if (opt.close) {
|
||||
title += '<span class="pear-tab-active"></span><span class="able-close title">' + opt.title +
|
||||
@@ -319,7 +319,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
} else {
|
||||
var isData = false;
|
||||
$.each($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]"),
|
||||
function() {
|
||||
function () {
|
||||
if ($(this).attr("lay-id") == opt.id) {
|
||||
isData = true;
|
||||
}
|
||||
@@ -358,7 +358,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}
|
||||
|
||||
// 刷 新 指 定 的 选 项 卡
|
||||
pearTab.prototype.refresh = function(time) {
|
||||
pearTab.prototype.refresh = function (time) {
|
||||
// 刷 新 指 定 的 选 项 卡
|
||||
var $iframe = $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-content .layui-show")
|
||||
.find("iframe");
|
||||
@@ -385,8 +385,8 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
display: "block"
|
||||
});
|
||||
index++;
|
||||
$iframe.on("load", function() {
|
||||
pearLoad.fadeOut(1000, function() {
|
||||
$iframe.on("load", function () {
|
||||
pearLoad.fadeOut(1000, function () {
|
||||
pearLoad.remove();
|
||||
});
|
||||
})
|
||||
@@ -402,12 +402,12 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
if (!removeTab.hasClass("layui-this")) {
|
||||
removeTab.remove();
|
||||
var tabContent = $(".layui-tab[lay-filter='" + elem + "']").find("iframe[id='" + id + "']")
|
||||
.parent();
|
||||
.parent();
|
||||
tabContent.remove();
|
||||
|
||||
tabData = JSON.parse(sessionStorage.getItem(elem + "-pear-tab-data"));
|
||||
tabDataCurrent = sessionStorage.getItem(elem + "-pear-tab-data-current");
|
||||
tabData = tabData.filter(function(item) {
|
||||
tabData = tabData.filter(function (item) {
|
||||
return item.id != id;
|
||||
})
|
||||
sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData));
|
||||
@@ -428,7 +428,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
callback(currId);
|
||||
tabData = JSON.parse(sessionStorage.getItem(elem + "-pear-tab-data"));
|
||||
tabDataCurrent = sessionStorage.getItem(elem + "-pear-tab-data-current");
|
||||
tabData = tabData.filter(function(item) {
|
||||
tabData = tabData.filter(function (item) {
|
||||
return item.id != id;
|
||||
})
|
||||
sessionStorage.setItem(elem + "-pear-tab-data", JSON.stringify(tabData));
|
||||
@@ -463,7 +463,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
|
||||
// 处 理 选 项 卡 头 部
|
||||
var index = 0;
|
||||
$.each(option.data, function(i, item) {
|
||||
$.each(option.data, function (i, item) {
|
||||
var TitleItem = '';
|
||||
if (option.index == index) {
|
||||
TitleItem += '<li lay-id="' + item.id +
|
||||
@@ -531,7 +531,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}
|
||||
|
||||
function closeEvent(option) {
|
||||
$(".layui-tab[lay-filter='" + option.elem + "']").on("click", ".layui-tab-close", function() {
|
||||
$(".layui-tab[lay-filter='" + option.elem + "']").on("click", ".layui-tab-close", function () {
|
||||
var layid = $(this).parent().attr("lay-id");
|
||||
tabDelete(option.elem, layid, option.closeEvent, option);
|
||||
})
|
||||
@@ -539,7 +539,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
|
||||
function menuEvent(option, index) {
|
||||
|
||||
$("#" + option.elem + "closeThis").click(function() {
|
||||
$("#" + option.elem + "closeThis").click(function () {
|
||||
var currentTab = contextTabDOM;
|
||||
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
@@ -554,10 +554,10 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
layer.close(index);
|
||||
})
|
||||
|
||||
$("#" + option.elem + "closeOther").click(function() {
|
||||
$("#" + option.elem + "closeOther").click(function () {
|
||||
var currentId = contextTabDOM.attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function(i) {
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
|
||||
@@ -568,10 +568,10 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
layer.close(index);
|
||||
})
|
||||
|
||||
$("#" + option.elem + "closeAll").click(function() {
|
||||
$("#" + option.elem + "closeAll").click(function () {
|
||||
var currentId = contextTabDOM.attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function(i) {
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
|
||||
}
|
||||
@@ -581,7 +581,7 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}
|
||||
|
||||
function toolEvent(option) {
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeThis", function() {
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeThis", function () {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + option.elem +
|
||||
"'] .layui-tab-title .layui-this");
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
@@ -595,11 +595,11 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
}
|
||||
})
|
||||
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeOther", function() {
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeOther", function () {
|
||||
var currentId = $(".layui-tab[lay-filter='" + option.elem +
|
||||
"'] .layui-tab-title .layui-this").attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function(i) {
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
|
||||
@@ -609,11 +609,11 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
})
|
||||
})
|
||||
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeAll", function() {
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "']").on("click", "#closeAll", function () {
|
||||
var currentId = $(".layui-tab[lay-filter='" + option.elem +
|
||||
"'] .layui-tab-title .layui-this").attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function(i) {
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
|
||||
}
|
||||
@@ -626,10 +626,10 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
var $tabTitle = $('#' + option.elem + ' .layui-tab-title');
|
||||
var mouseScrollStep = 100
|
||||
// 鼠标滚轮
|
||||
$bodyTab.on("mousewheel DOMMouseScroll", function(e) {
|
||||
$bodyTab.on("mousewheel DOMMouseScroll", function (e) {
|
||||
e.originalEvent.preventDefault()
|
||||
var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? "top" :
|
||||
"down")) || // chrome & ie
|
||||
"down")) || // chrome & ie
|
||||
(e.originalEvent.detail && (e.originalEvent.detail > 0 ? "down" : "top")); // firefox
|
||||
var scrollLeft = $tabTitle.scrollLeft();
|
||||
|
||||
@@ -643,11 +643,11 @@ layui.define(['jquery', 'element'], function(exports) {
|
||||
|
||||
// 触摸移动
|
||||
var touchX = 0;
|
||||
$bodyTab.on("touchstart", function(e) {
|
||||
$bodyTab.on("touchstart", function (e) {
|
||||
var touch = e.originalEvent.targetTouches[0];
|
||||
touchX = touch.pageX
|
||||
})
|
||||
$bodyTab.on("touchmove", function(e) {
|
||||
$bodyTab.on("touchmove", function (e) {
|
||||
var event = e.originalEvent;
|
||||
if (event.targetTouches.length > 1) return;
|
||||
event.preventDefault();
|
||||
|
||||
668
web/statics/component/pear/module/tabPage.js
Normal file
668
web/statics/component/pear/module/tabPage.js
Normal file
@@ -0,0 +1,668 @@
|
||||
layui.define(['jquery', 'element', 'dropdown'], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var MOD_NAME = 'tabPage',
|
||||
$ = layui.jquery,
|
||||
dropdown = layui.dropdown,
|
||||
element = layui.element;
|
||||
|
||||
var tabPage = function (opt) {
|
||||
this.option = opt;
|
||||
};
|
||||
|
||||
var tabData = new Array();
|
||||
var tabDataCurrent = 0;
|
||||
var contextTabDOM;
|
||||
|
||||
tabPage.prototype.render = function (opt) {
|
||||
|
||||
var option = {
|
||||
elem: opt.elem,
|
||||
data: opt.data,
|
||||
index: opt.index,
|
||||
tool: opt.tool || true,
|
||||
roll: opt.roll || true,
|
||||
success: opt.success ? opt.success : function (id) { },
|
||||
session: opt.session ? opt.session : false,
|
||||
preload: opt.preload ? opt.preload : false,
|
||||
height: opt.height || "100%",
|
||||
width: opt.width || "100%",
|
||||
closeEvent: opt.closeEvent,
|
||||
tabMax: opt.tabMax,
|
||||
}
|
||||
|
||||
if (option.session) {
|
||||
if (sessionStorage.getItem(option.elem + "-pear-tab-page-data") != null) {
|
||||
tabData = JSON.parse(sessionStorage.getItem(option.elem + "-pear-tab-page-data"));
|
||||
option.data = JSON.parse(sessionStorage.getItem(option.elem + "-pear-tab-page-data"));
|
||||
tabDataCurrent = sessionStorage.getItem(option.elem + "-pear-tab-page-data-current");
|
||||
tabData.forEach(function (item, index) {
|
||||
if (item.id == tabDataCurrent) {
|
||||
option.index = index;
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tabData = opt.data;
|
||||
}
|
||||
}
|
||||
|
||||
var lastIndex;
|
||||
var tab = createTab(option);
|
||||
$("#" + option.elem).html(tab);
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-prev").click(function () {
|
||||
rollPage("left", option);
|
||||
})
|
||||
$(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-next").click(function () {
|
||||
rollPage("right", option);
|
||||
})
|
||||
element.init();
|
||||
|
||||
$("#" + option.elem).width(opt.width);
|
||||
$("#" + option.elem).height(opt.height);
|
||||
$("#" + option.elem).css({
|
||||
position: "relative"
|
||||
});
|
||||
|
||||
closeEvent(option);
|
||||
|
||||
option.success(sessionStorage.getItem(option.elem + "-pear-tab-page-data-current"));
|
||||
|
||||
dropdown.render({
|
||||
elem: `#${option.elem} .layui-tab-control > .layui-icon-down`,
|
||||
trigger: 'hover',
|
||||
data: [{
|
||||
title: '关 闭 当 前',
|
||||
id: 1
|
||||
}, {
|
||||
title: '关 闭 其 他',
|
||||
id: 2
|
||||
}, {
|
||||
title: '关 闭 全 部',
|
||||
id: 3
|
||||
}],
|
||||
click: function (obj) {
|
||||
|
||||
const id = obj.id;
|
||||
|
||||
if (id === 1) {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + option.elem +
|
||||
"'] .layui-tab-title .layui-this");
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
var currentId = currentTab.attr("lay-id");
|
||||
tabDelete(option.elem, currentId, option.closeEvent, option);
|
||||
} else {
|
||||
layer.msg("当前页面不允许关闭", {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
})
|
||||
}
|
||||
} else if (id === 2) {
|
||||
var currentId = $(".layui-tab[lay-filter='" + option.elem +
|
||||
"'] .layui-tab-title .layui-this").attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
|
||||
option);
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
var currentId = $(".layui-tab[lay-filter='" + option.elem +
|
||||
"'] .layui-tab-title .layui-this").attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
$("body .layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title").on("contextmenu", "li",
|
||||
function (e) {
|
||||
var top = e.clientY;
|
||||
var left = e.clientX;
|
||||
var menuWidth = 100;
|
||||
var menu = `<ul>
|
||||
<li class='item' id='${option.elem}closeThis'>关闭当前</li>
|
||||
<li class='item' id='${option.elem}closeOther'>关闭其他</li>
|
||||
<li class='item' id='${option.elem}closeAll'>关闭所有</li>
|
||||
</ul>`;
|
||||
|
||||
contextTabDOM = $(this);
|
||||
var isOutsideBounds = (left + menuWidth) > $(window).width();
|
||||
if (isOutsideBounds) {
|
||||
left = $(window).width() - menuWidth;
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: false,
|
||||
shade: false,
|
||||
skin: 'pear-tab-page-menu',
|
||||
closeBtn: false,
|
||||
area: [menuWidth + 'px', '108px'],
|
||||
fixed: true,
|
||||
anim: false,
|
||||
isOutAnim: false,
|
||||
offset: [top, left],
|
||||
content: menu,
|
||||
success: function (layero, index) {
|
||||
layer.close(lastIndex);
|
||||
lastIndex = index;
|
||||
menuEvent(option, index);
|
||||
var timer;
|
||||
$(layero).on('mouseout', function () {
|
||||
timer = setTimeout(function () {
|
||||
layer.close(index);
|
||||
}, 30)
|
||||
});
|
||||
|
||||
$(layero).on('mouseover', function () {
|
||||
clearTimeout(timer);
|
||||
});
|
||||
|
||||
$(layero).on('contextmenu', function () {
|
||||
return false;
|
||||
})
|
||||
}
|
||||
});
|
||||
return false;
|
||||
})
|
||||
|
||||
mousewheelAndTouchmoveHandler(option)
|
||||
return new tabPage(option);
|
||||
}
|
||||
|
||||
tabPage.prototype.click = function (callback) {
|
||||
var option = this.option;
|
||||
var elem = this.option.elem;
|
||||
element.on('tab(' + this.option.elem + ')', function (data) {
|
||||
var id = $("#" + elem + " .layui-tab-title .layui-this").attr("lay-id");
|
||||
sessionStorage.setItem(option.elem + "-pear-tab-page-data-current", id);
|
||||
callback(id);
|
||||
});
|
||||
}
|
||||
|
||||
tabPage.prototype.positionTab = function () {
|
||||
var $tabTitle = $('.layui-tab[lay-filter=' + this.option.elem + '] .layui-tab-title');
|
||||
var autoLeft = 0;
|
||||
$tabTitle.children("li").each(function () {
|
||||
var id = $(this).attr('lay-id');
|
||||
if ($(this).hasClass('layui-this')) {
|
||||
var isrc = $('.layui-tab-content .layui-show').find('iframe').attr('src');
|
||||
if (isrc === '') {
|
||||
$('.layui-tab-content .layui-show').find('iframe').attr('src', id);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
autoLeft += $(this).outerWidth();
|
||||
}
|
||||
});
|
||||
$tabTitle.animate({
|
||||
scrollLeft: autoLeft - $tabTitle.width() / 3
|
||||
}, 200);
|
||||
}
|
||||
|
||||
tabPage.prototype.clear = function () {
|
||||
sessionStorage.removeItem(this.option.elem + "-pear-tab-page-data");
|
||||
sessionStorage.removeItem(this.option.elem + "-pear-tab-page-data-current");
|
||||
}
|
||||
|
||||
tabPage.prototype.changeTabTitleById = function (id, title) {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title [lay-id='" + id + "'] .title");
|
||||
currentTab.html(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 删除指定选项卡
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
tabPage.prototype.removeTab = function (id) {
|
||||
var elem = this.option.elem;
|
||||
if (id != undefined) {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title [lay-id='" + id + "']");
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
tabDelete(elem, id, () => { });
|
||||
}
|
||||
} else {
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function () {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(elem, $(this).attr("lay-id"), () => { });
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 删除其他选项卡
|
||||
*/
|
||||
tabPage.prototype.removeOtherTab = function () {
|
||||
var elem = this.option.elem;
|
||||
var currentId = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title .layui-this").attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function () {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(elem, $(this).attr("lay-id"), () => { });
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 删除选中选项卡
|
||||
*/
|
||||
tabPage.prototype.removeCurrentTab = function () {
|
||||
var currentTab = $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title .layui-this");
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
var currentId = currentTab.attr("lay-id");
|
||||
tabDelete(this.option.elem, currentId, () => { });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*
|
||||
* 切换选项卡
|
||||
*
|
||||
* @param opt 内容
|
||||
*/
|
||||
tabPage.prototype.changePage = function (opt) {
|
||||
|
||||
var title = `<span class="pear-tab-page-active"></span>
|
||||
<span class="${opt.close ? 'able-close' : 'disable-close'} title">${opt.title}</span>
|
||||
<i class="layui-icon layui-unselect layui-tab-close">ဆ</i>`;
|
||||
|
||||
if ($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]").length <=
|
||||
0) {
|
||||
|
||||
var that = this;
|
||||
|
||||
if (opt.type === "_iframe") {
|
||||
|
||||
element.tabAdd(this.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<iframe id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" scrolling="auto" frameborder="0" src="${opt.url}" style="width:100%;height:100%;" allowfullscreen="true"></iframe>`
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
$.ajax({
|
||||
url: opt.url,
|
||||
type: 'get',
|
||||
dataType: 'html',
|
||||
async: false,
|
||||
success: function (data) {
|
||||
element.tabAdd(that.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<div id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" src="${opt.url}">${data}</div>`,
|
||||
});
|
||||
},
|
||||
error: function (xhr, textstatus, thrown) {
|
||||
return layer.msg('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
tabData.push(opt);
|
||||
sessionStorage.setItem(that.option.elem + "-pear-tab-page-data", JSON.stringify(tabData));
|
||||
sessionStorage.setItem(that.option.elem + "-pear-tab-page-data-current", opt.id);
|
||||
|
||||
} else {
|
||||
|
||||
var isData = false;
|
||||
$.each($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]"),
|
||||
function () {
|
||||
if ($(this).attr("lay-id") == opt.id) {
|
||||
isData = true;
|
||||
}
|
||||
})
|
||||
|
||||
if (isData == false) {
|
||||
|
||||
if (this.option.tabMax != false) {
|
||||
if ($(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-title li[lay-id]")
|
||||
.length >= this.option.tabMax) {
|
||||
layer.msg("最多打开" + this.option.tabMax + "个标签页", {
|
||||
icon: 2,
|
||||
time: 1000,
|
||||
shift: 6
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var that = this;
|
||||
if (opt.type === "_iframe") {
|
||||
element.tabAdd(this.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<iframe id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" scrolling="auto" frameborder="0" src="${opt.url}" style="width:100%;height:100%;" allowfullscreen="true"></iframe>`
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
url: opt.url,
|
||||
type: 'get',
|
||||
dataType: 'html',
|
||||
async: false,
|
||||
success: function (data) {
|
||||
element.tabAdd(that.option.elem, {
|
||||
id: opt.id,
|
||||
title: title,
|
||||
content: `<div id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" src="${opt.url}">${data}</div>`,
|
||||
});
|
||||
},
|
||||
error: function (xhr, textstatus, thrown) {
|
||||
return layer.msg('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!');
|
||||
}
|
||||
});
|
||||
}
|
||||
tabData.push(opt);
|
||||
sessionStorage.setItem(that.option.elem + "-pear-tab-page-data", JSON.stringify(tabData));
|
||||
sessionStorage.setItem(that.option.elem + "-pear-tab-page-data-current", opt.id);
|
||||
}
|
||||
}
|
||||
element.tabChange(this.option.elem, opt.id);
|
||||
sessionStorage.setItem(this.option.elem + "-pear-tab-page-data-current", opt.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新当前选型卡
|
||||
*
|
||||
* @param time 动画时长
|
||||
*/
|
||||
tabPage.prototype.refresh = function (time) {
|
||||
|
||||
var $iframe = $(".layui-tab[lay-filter='" + this.option.elem + "'] .layui-tab-content .layui-show > *");
|
||||
var $iframeLoad;
|
||||
|
||||
if (time != false && time != 0) {
|
||||
$iframeLoad = $("#" + this.option.elem).find(".pear-tab-page-loading");
|
||||
$iframeLoad.css({
|
||||
display: "block"
|
||||
});
|
||||
}
|
||||
|
||||
if ($iframe.attr("type") === "_iframe") {
|
||||
$iframe.attr("src", $iframe.attr("src"));
|
||||
$iframe.on("load", function () {
|
||||
$iframeLoad.fadeOut(1000, function () {
|
||||
$iframeLoad.css({
|
||||
display: "none"
|
||||
});
|
||||
});
|
||||
})
|
||||
} else {
|
||||
$.ajax({
|
||||
url: $iframe.attr("src"),
|
||||
type: 'get',
|
||||
dataType: 'html',
|
||||
success: function (data) {
|
||||
$iframe.html(data);
|
||||
if ($iframeLoad != undefined) {
|
||||
$iframeLoad.fadeOut(1000, function () {
|
||||
$iframeLoad.css({
|
||||
display: "none"
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function tabDelete(elem, id, callback) {
|
||||
var tabTitle = $(".layui-tab[lay-filter='" + elem + "']").find(".layui-tab-title");
|
||||
var removeTab = tabTitle.find("li[lay-id='" + id + "']");
|
||||
var nextNode = removeTab.next("li");
|
||||
if (!removeTab.hasClass("layui-this")) {
|
||||
removeTab.remove();
|
||||
var tabContent = $(".layui-tab[lay-filter='" + elem + "']").find("*[id='" + id + "']")
|
||||
.parent();
|
||||
tabContent.remove();
|
||||
|
||||
tabData = JSON.parse(sessionStorage.getItem(elem + "-pear-tab-page-data"));
|
||||
tabDataCurrent = sessionStorage.getItem(elem + "-pear-tab-page-data-current");
|
||||
tabData = tabData.filter(function (item) {
|
||||
return item.id != id;
|
||||
})
|
||||
sessionStorage.setItem(elem + "-pear-tab-page-data", JSON.stringify(tabData));
|
||||
return false;
|
||||
}
|
||||
|
||||
var currId;
|
||||
if (nextNode.length) {
|
||||
nextNode.addClass("layui-this");
|
||||
currId = nextNode.attr("lay-id");
|
||||
$("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
|
||||
} else {
|
||||
var prevNode = removeTab.prev("li");
|
||||
prevNode.addClass("layui-this");
|
||||
currId = prevNode.attr("lay-id");
|
||||
$("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
|
||||
}
|
||||
callback(currId);
|
||||
tabData = JSON.parse(sessionStorage.getItem(elem + "-pear-tab-page-data"));
|
||||
tabDataCurrent = sessionStorage.getItem(elem + "-pear-tab-page-data-current");
|
||||
tabData = tabData.filter(function (item) {
|
||||
return item.id != id;
|
||||
})
|
||||
sessionStorage.setItem(elem + "-pear-tab-page-data", JSON.stringify(tabData));
|
||||
sessionStorage.setItem(elem + "-pear-tab-page-data-current", currId);
|
||||
removeTab.remove();
|
||||
var tabContent = $(".layui-tab[lay-filter='" + elem + "']").find("*[id='" + id + "']").parent();
|
||||
tabContent.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Pear Admin 4.0
|
||||
*/
|
||||
function createTab(option) {
|
||||
|
||||
var type = "";
|
||||
if (option.roll == true) {
|
||||
type = "layui-tab-roll";
|
||||
}
|
||||
if (option.tool != false) {
|
||||
type = "layui-tab-tool";
|
||||
}
|
||||
if (option.roll == true && option.tool != false) {
|
||||
type = "layui-tab-rollTool";
|
||||
}
|
||||
var tab = '<div class="pear-tab-page ' + type + ' layui-tab" lay-filter="' + option.elem +
|
||||
'" lay-allowClose="true">';
|
||||
|
||||
var headers = '<ul class="layui-tab-title">';
|
||||
var content = '<div class="layui-tab-content">';
|
||||
var loading = '<div class="pear-tab-page-loading"><div class="ball-loader"><span></span><span></span><span></span><span></span></div></div>'
|
||||
var control = `<div class="layui-tab-control">
|
||||
<li class="layui-tab-prev layui-icon layui-icon-left"></li>
|
||||
<li class="layui-tab-next layui-icon layui-icon-right"></li>
|
||||
<li class="layui-tab-tool layui-icon layui-icon-down"></li>
|
||||
</div>`;
|
||||
|
||||
// 处 理 选 项 卡 头 部
|
||||
var index = 0;
|
||||
|
||||
$.each(option.data, function (i, item) {
|
||||
|
||||
var titleItem = `<li lay-id="${item.id}" class="${option.index == index ? 'layui-this' : ''}">
|
||||
<span class="pear-tab-page-active"></span>
|
||||
<span class="${item.close ? 'able-close' : 'disable-close'} title">
|
||||
${item.title}
|
||||
</span>
|
||||
<i class="layui-icon layui-unselect layui-tab-close">ဆ</i></li>
|
||||
</li>`;
|
||||
|
||||
headers += titleItem;
|
||||
|
||||
if (item.type === "_iframe") {
|
||||
|
||||
// console.log("itemid: ", item.id);
|
||||
// console.log("itemurl: ", item.url);
|
||||
tabDataCurrent = sessionStorage.getItem(option.elem + "-pear-tab-page-data-current");
|
||||
// console.log("current: ", tabDataCurrent);
|
||||
if (tabDataCurrent != item.url) {
|
||||
item.url = '';
|
||||
}
|
||||
|
||||
content += `<div class="${option.index == index ? 'layui-show' : ''} layui-tab-item"><iframe id="${item.id}" type="${item.type}" data-frameid="${item.id}" scrolling="auto" frameborder="0" src="${item.url}" style="width:100%;height:100%;" allowfullscreen="true"></iframe></div>`
|
||||
|
||||
} else {
|
||||
$.ajax({
|
||||
url: item.url,
|
||||
type: 'get',
|
||||
dataType: 'html',
|
||||
async: false,
|
||||
success: function (data) {
|
||||
content += `<div class="${option.index == index ? 'layui-show' : ''} layui-tab-item"><div id="${item.id}" type="${item.type}" data-frameid="${item.id}" src="${item.url}">${data}</div></div>`;
|
||||
},
|
||||
error: function (xhr) {
|
||||
return layer.msg('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
index++;
|
||||
});
|
||||
|
||||
headers += '</ul>';
|
||||
content += '</div>';
|
||||
|
||||
tab += headers;
|
||||
tab += control;
|
||||
tab += content;
|
||||
tab += loading;
|
||||
tab += '</div>';
|
||||
tab += ''
|
||||
return tab;
|
||||
}
|
||||
|
||||
function rollPage(d, option) {
|
||||
var $tabTitle = $('#' + option.elem + ' .layui-tab-title');
|
||||
var left = $tabTitle.scrollLeft();
|
||||
if ('left' === d) {
|
||||
$tabTitle.animate({
|
||||
scrollLeft: left - 450
|
||||
}, 200);
|
||||
} else {
|
||||
$tabTitle.animate({
|
||||
scrollLeft: left + 450
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
|
||||
function closeEvent(option) {
|
||||
$(".layui-tab[lay-filter='" + option.elem + "']")
|
||||
.on("click", ".layui-tab-close", function () {
|
||||
var layid = $(this).parent().attr("lay-id");
|
||||
tabDelete(option.elem, layid, option.closeEvent, option);
|
||||
})
|
||||
.on("mousedown", ".layui-tab-title li", function (e) {
|
||||
if (e.buttons === 4 && $(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function menuEvent(option, index) {
|
||||
|
||||
$("#" + option.elem + "closeThis").click(function () {
|
||||
var currentTab = contextTabDOM;
|
||||
|
||||
if (currentTab.find("span").is(".able-close")) {
|
||||
var currentId = currentTab.attr("lay-id");
|
||||
tabDelete(option.elem, currentId, option.closeEvent, option);
|
||||
} else {
|
||||
layer.msg("当前页面不允许关闭", {
|
||||
icon: 3,
|
||||
time: 800
|
||||
})
|
||||
}
|
||||
layer.close(index);
|
||||
})
|
||||
|
||||
$("#" + option.elem + "closeOther").click(function () {
|
||||
var currentId = contextTabDOM.attr("lay-id");
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).attr("lay-id") != currentId) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
|
||||
option);
|
||||
}
|
||||
}
|
||||
})
|
||||
layer.close(index);
|
||||
})
|
||||
|
||||
$("#" + option.elem + "closeAll").click(function () {
|
||||
var tabtitle = $(".layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title li");
|
||||
$.each(tabtitle, function (i) {
|
||||
if ($(this).find("span").is(".able-close")) {
|
||||
tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
|
||||
}
|
||||
})
|
||||
layer.close(index);
|
||||
})
|
||||
}
|
||||
|
||||
function mousewheelAndTouchmoveHandler(option) {
|
||||
var $bodyTab = $("body .layui-tab[lay-filter='" + option.elem + "'] .layui-tab-title")
|
||||
var $tabTitle = $('#' + option.elem + ' .layui-tab-title');
|
||||
var mouseScrollStep = 100
|
||||
// 鼠标滚轮
|
||||
$bodyTab.on("mousewheel DOMMouseScroll", function (e) {
|
||||
e.originalEvent.preventDefault()
|
||||
var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? "top" :
|
||||
"down")) || // chrome & ie
|
||||
(e.originalEvent.detail && (e.originalEvent.detail > 0 ? "down" : "top")); // firefox
|
||||
var scrollLeft = $tabTitle.scrollLeft();
|
||||
|
||||
if (delta === "top") {
|
||||
scrollLeft -= mouseScrollStep
|
||||
} else if (delta === "down") {
|
||||
scrollLeft += mouseScrollStep
|
||||
}
|
||||
$tabTitle.scrollLeft(scrollLeft)
|
||||
});
|
||||
|
||||
// 触摸移动
|
||||
var touchX = 0;
|
||||
$bodyTab.on("touchstart", function (e) {
|
||||
var touch = e.originalEvent.targetTouches[0];
|
||||
touchX = touch.pageX
|
||||
})
|
||||
|
||||
$bodyTab.on("touchmove", function (e) {
|
||||
var event = e.originalEvent;
|
||||
if (event.targetTouches.length > 1) return;
|
||||
event.preventDefault();
|
||||
var touch = event.targetTouches[0];
|
||||
var distanceX = touchX - touch.pageX
|
||||
var scrollLeft = $tabTitle.scrollLeft();
|
||||
touchX = touch.pageX
|
||||
$tabTitle.scrollLeft(scrollLeft += distanceX)
|
||||
});
|
||||
}
|
||||
|
||||
exports(MOD_NAME, new tabPage());
|
||||
})
|
||||
40
web/statics/component/pear/module/tools.js
Normal file
40
web/statics/component/pear/module/tools.js
Normal file
@@ -0,0 +1,40 @@
|
||||
layui.define(['jquery', 'element'],
|
||||
function (exports) {
|
||||
|
||||
var $ = layui.jquery;
|
||||
var tools = new function () {
|
||||
|
||||
/**
|
||||
* @since 防抖算法
|
||||
*
|
||||
* @param fn 要执行的方法
|
||||
* @param time 防抖时间参数
|
||||
*/
|
||||
this.debounce = function (fn, time) {
|
||||
var timer = null
|
||||
return function () {
|
||||
var arguments = arguments[0]
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
timer = setTimeout(function () {
|
||||
fn(arguments)
|
||||
}, time)
|
||||
}
|
||||
}
|
||||
|
||||
// image 转 base64
|
||||
this.imageToBase64 = function (img) {
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
var ctx = canvas.getContext("2d");
|
||||
ctx.drawImage(img, 0, 0, img.width, img.height);
|
||||
var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
|
||||
var dataURL = canvas.toDataURL("image/" + ext);
|
||||
return dataURL;
|
||||
}
|
||||
};
|
||||
|
||||
exports('tools', tools);
|
||||
})
|
||||
Reference in New Issue
Block a user