Commit 5d540859 by hanpeng

-mark- 肺癌靶向家园公众号通用方法

parents
define(['zepto', 'md5'], function($, md5) {
/*
*微信服务号通用方法
*/
//设置请求头
var setHeader = function() {
var headers = {};
headers['apptype'] = 'wechat_lung';
headers['user-os'] = 'wechat';
return headers;
}
//获取url上的参数
var getRequest = function(strParame) {
var args = new Object();
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');
if (pos == -1) continue;
var argname = pairs[i].substring(0, pos);
var value = pairs[i].substring(pos + 1);
value = decodeURIComponent(value);
args[argname] = value;
}
args[strParame] = args[strParame] || "";
return args[strParame];
}
//页面跳转
var pushWindow = function(urlParame) {
var ts = new Date().getTime(); //时间戳
if (urlParame.indexOf('?') == -1) {
window.location.href = urlParame + '?ts=' + ts;
} else {
window.location.href = urlParame + '&ts=' + ts;
}
}
//loading效果
var loading = function(isOpen) {
var html = '<div class="mod"><div class="cssload-spin-box"></div></div>';
$('body').append(html);
if (isOpen == 1) {
$('.mod').show();
} else {
setTimeout(function() {
$('.mod').hide();
}, 1000)
}
}
//toast 提示
var toast = function(msgParame) {
//设置消息框提示时间
var time = msgParame.time;
if (time == undefined || time == '') {
time = 2000;
}
//初始化消息框元素
var el = document.createElement("div");
el.setAttribute("class", "web-toast");
el.innerHTML = msgParame.message;
document.body.appendChild(el);
el.classList.add("fadeIn");
setTimeout(function() {
el.classList.remove("fadeIn");
el.classList.add("fadeOut");
/* 监听动画结束,移除提示信息元素 */
el.addEventListener("animationend", function() {
document.body.removeChild(el);
});
el.addEventListener("webkitAnimationEnd", function() {
document.body.removeChild(el);
});
}, time);
}
//请求函数
var submitAjax = function(opts) {
//请求参数
var ajaxParame = opts.data || '';
var params = {};
if (ajaxParame != "") {
for (var i in ajaxParame) {
params[i] = ajaxParame[i];
}
}
//是否异步请求
var async = true;
if (opts.async != undefined) {
async = opts.async;
}
//设置contentType
var type = "application/x-www-form-urlencoded";
if (opts.contentType == "application/json") {
type = "application/json";
params = JSON.stringify(params);
}
$.ajax({
url: opts.url,
type: opts.type,
headers: setHeader(),
async: opts.async,
contentType: type,
data: params,
success: function(res) {
opts.success(res);
},
error: function(res) {
opts.error(res);
}
})
}
//模块暴露
return {
setHeader: setHeader,
getRequest: getRequest,
pushWindow: pushWindow,
loading: loading,
toast: toast,
submitAjax: submitAjax
}
})
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 to comment