Commit 85345be1 by 肖康

公共组件代码

parent 84d82062
......@@ -15,3 +15,61 @@
.tip-con{padding-left:20px;padding-right:20px;min-width: 84px;}
}
/**加载层**/
.pop-loding{
position: fixed;
top:0px;
left:0px;
right:0px;
bottom:0px;
z-index: 999999;
img{position: absolute;top:50%;left:50%;margin-left: -18px;margin-top: -18px;}
}
/**确认框**/
.pop-confirm{
width: 510px;
padding:25px;
padding-bottom: 40px;
background:rgba(1, 22, 51, 0.6);
border-radius: 8px;
position: fixed;
z-index: 99999;
top:50%;
left:50%;
margin-left: -280px;
margin-top:-175px;
color:#fff;
.phead{
font-size: 22px;
text-align: right;
i{cursor: pointer;}
}
.pbody{
font-size: 22px;
text-align: center;
padding-top:70px;
height:120px;
line-height: 24px;
}
.pfoot{
.but{
width: 110px;
height: 48px;
border: 1px solid #FFFFFF;
border-radius: 6px;
line-height: 48px;
text-align: center;
color: #FAFAFA;
font-size: 18px;
cursor: pointer;
&.sure{
color: #164D9A;
background: #fff;
margin-left: 92px;
}
}
}
}
\ No newline at end of file
.pop-tip{height:32px;background:rgba(0,0,0,0.5);text-align:center;font-size:14px;line-height:32px;font-weight:bold;position:fixed;top:150px;color:#fff;z-index:99999;display:block}.pop-tip .tip-con{padding-left:20px;padding-right:20px;min-width:84px}
\ No newline at end of file
.pop-tip{height:32px;background:rgba(0,0,0,0.5);text-align:center;font-size:14px;line-height:32px;font-weight:bold;position:fixed;top:150px;color:#fff;z-index:99999;display:block}.pop-tip .tip-con{padding-left:20px;padding-right:20px;min-width:84px}.pop-loding{position:fixed;top:0px;left:0px;right:0px;bottom:0px;z-index:999999}.pop-loding img{position:absolute;top:50%;left:50%;margin-left:-18px;margin-top:-18px}.pop-confirm{width:510px;padding:25px;padding-bottom:40px;background:rgba(1,22,51,0.6);border-radius:8px;position:fixed;z-index:99999;top:50%;left:50%;margin-left:-280px;margin-top:-175px;color:#fff}.pop-confirm .phead{font-size:22px;text-align:right}.pop-confirm .phead i{cursor:pointer}.pop-confirm .pbody{font-size:22px;text-align:center;padding-top:70px;height:120px;line-height:24px}.pop-confirm .pfoot .but{width:110px;height:48px;border:1px solid #FFFFFF;border-radius:6px;line-height:48px;text-align:center;color:#FAFAFA;font-size:18px;cursor:pointer}.pop-confirm .pfoot .but.sure{color:#164D9A;background:#fff;margin-left:92px}
\ No newline at end of file
......@@ -3,10 +3,12 @@ seajs.config({
alias: {
'jquery':"common/jquery-1.8.3.min",//jquery
'tool':"common/tool",//工具
'liexin_ajax':"common/liexin_ajax" ,
'liexin_pop':"common/liexin_pop",
'liexin_ajax':"common/liexin_ajax.js" ,
'liexin_pop':"common/liexin_pop.js",
},
charset: 'utf-8',// 文件编码,
map:[
['.js','.js?v='+Date.now()]
],
preload: ['jquery','liexin_ajax']//预加载模块
});
\ No newline at end of file
define('liexin_ajax',[],function(require, exports, module) {
define('liexin_ajax', ['liexin_pop'], function (require, exports, module) {
var liexin_pop=require("liexin_pop")
//挂载到 $ 上方便操作 直接预加载
jQuery.extend({
liexin_ajax: function (url, type, param, callback, isload) {
if (!isload ) {
liexin_pop.Loading();
}
//设置携带cookie
$.ajaxSetup({
xhrFields: {
withCredentials: true
}
});
module.exports.liexin_ajax=function(){
var params = $.extend({}, param);
$.ajax({
type: type,
url: url,
data: params,
xhrFields: { withCredentials: true },
timeout: 10000,
success: function (data) {
typeof callback == 'function' && callback(data);
if (isload == undefined) {
liexin_pop.LoadingHide();
}
},
error: function () {
liexin_pop.LoadingHide();
layer.msg('网络出现问题,请重试!');
}
});
}
})
});
\ No newline at end of file
......@@ -4,20 +4,20 @@ define('liexin_pop', [], function (require, exports, module) {
var el = document.createElement('link');
el.rel = 'stylesheet';
el.type = 'text/css';
el.href = PUBLICXK + '/assets/css/common/pop.min.css';
el.href = PUBLICXK + '/assets/css/common/pop.min.css?v=' + Date.now();
$("body").before($(el))
//提示消息 tips opt={time:2000,title:"放开那个女孩"}
module.exports.Tip = function (opt) {
var time_ = opt.time || 2200;
$(".pop-tip").remove();
var temp = '<div class="pop-tip" ><div class="tip-con">' + opt.text + '</div></div>';
var temp = '<div class="pop-tip" ><div class="tip-con">' + opt.title + '</div></div>';
$("body").append(temp);
var ele = $(".pop-tip .tip-con");
var width_ = ele.width();
console.log(width_)
$(".pop-tip").css({
left: "50%",
// "margin-left": -0.5 * width_
"margin-left": -0.5 * width_
})
setTimeout(function () {
$(".pop-tip").fadeOut(300);
......@@ -30,4 +30,41 @@ define('liexin_pop', [], function (require, exports, module) {
})
}
//加载 LoadingHide()关闭加载 挂载在window上
module.exports.Loading = function () {
$(".pop-loding").remove();
var temp = '<div class="pop-loding"><img src="' + PUBLICXK + '/assets/images/common/loading.gif" /></div>';
$("body").append(temp);
window.LoadingHide = function () {
$(".pop-loding").remove();
}
}
module.exports.LoadingHide = function () {
$(".pop-loding").remove();
}
//确认框 Confirm opt={title:"你确定不放开那个女孩吗?",success:function(ele){
//逻辑代码 ...
//ele.fadeOut(300) //关闭弹窗
//}}
module.exports.Confirm = function (opt) {
var text_ = opt.title || 'Are you sure?'
$(".pop-confirm").remove();
var html_ = '<div class="pop-confirm"><div class="pop-confirm-con"><div class="phead"><i class="icon iconfont icon-guanbi confirm-close"></i></div>'
html_ += '<div class="pbody">' + text_ + '</div><div class="pfoot row rowCenter"><div class="but cancel">no</div>'
html_ += '<div class="but sure">yes</div></div></div></div>'
$("body").append(html_);
$(".pop-confirm").show();
var ele = $(".pop-confirm .cancel"), ele2 = $(".pop-confirm .sure"), closeele = $(".pop-confirm .confirm-close");
closeele.unbind("click").click(function () {
$(".pop-confirm").fadeOut(300);
})
ele.unbind("click").click(function () {
$(".pop-confirm").fadeOut(300);
})
ele2.unbind("click").click(function () {
opt.success($(".pop-confirm"));
})
}
});
\ No newline at end of file
define(function(require, exports, module) {
define(function (require, exports, module) {
//创建cookie
module.exports.setCookie= function(name, value, time, domain) //两个参数,一个是cookie的名子,一个是值,一个是天数
module.exports.setCookie = function (name, value, time, domain) //两个参数,一个是cookie的名子,一个是值,一个是天数
{
domain = domain ? ";domain=" + domain : "";
var Days = time; //此 cookie 将被保存 30 天
......@@ -9,7 +9,7 @@ define(function(require, exports, module) {
document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exp.toGMTString() + ";path=/" + domain;
return true;
}
module.exports.getCookie = function(name) //取cookies函数
module.exports.getCookie = function (name) //取cookies函数
{
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]);
......@@ -17,11 +17,36 @@ define(function(require, exports, module) {
}
//标准获取地址栏参数,不乱码
module.exports.getRequest=function(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
module.exports.getRequest = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
if (r != null) return unescape(r[2]); return null;
}
//debounce 防抖函数
//如 $("body").on("input propertychange focus", '.inquirybuyerx', debounce(function (e) {}, 300))
module.exports.debounce = function (fn, delay) {
// 定时器,用来 setTimeout
var timer
// 返回一个函数,这个函数会在一个时间区间结束后的 delay 毫秒时执行 fn 函数
return function () {
// 保存函数调用时的上下文和参数,传递给 fn
var context = this
var args = arguments
// 每次这个返回的函数被调用,就清除定时器,以保证不执行 fn
clearTimeout(timer)
// 当返回的函数被最后一次调用后(也就是用户停止了某个连续的操作),
// 再过 delay 毫秒就执行 fn
timer = setTimeout(function () {
fn.apply(context, args)
}, delay)
}
}
});
\ No newline at end of file
define('home', ['tool','liexin_pop'], function (require, exports, module) {
var tool=require("tool");
var liexin_pop=require("liexin_pop");
var home = {
init: function () {
home.handle();
liexin_pop.Tip({text:"测试室阿萨德",time:100000})
},
handle:function(){
$(".gw-header-top .topclose").click(function(){
$(".gw-header-top").slideUp(500);
tool.setCookie("topclose",1,30);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment