123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- const qs = require('qs');
- const config = {
- pushInner:'/api/icss/push/pushInner',
- calculate:'/api/icss/calc/calculate',
- }
- const imageUrlPrefix = 'http://192.168.2.241:82';
- const getUrlArgObject = (parm) => {
- var query = window.location.search;
- // console.log(window.location)
- // var query = '?'+url.split('?')[1];
- var args = qs.parse(query.substr(1));
- return args[parm];//返回对象
- }
- const post = function(url,data){
- return new Promise((resolve,reject)=>{
- $.ajax({
- method:'post',
- url:url,
- data:JSON.stringify(data),
- contentType:"application/json; charset=UTF-8",
- success:function(res){
- resolve({data:res});
- },
- error:function(error){
- reject(error);
- },
- });
- });
- }
- const throttle = function throttle(fn, threshhold) {
- var timeout
- var start = new Date;
- var threshhold = threshhold || 160
- return function () {
-
- var context = this, args = arguments, curr = new Date() - 0
-
- clearTimeout(timeout)//总是干掉事件回调
- if(curr - start >= threshhold){
- // console.log("now", curr, curr - start)//注意这里相减的结果,都差不多是160左右
- fn.apply(context, args) //只执行一部分方法,这些方法是在某个时间段内执行一次
- start = curr
- }else{
- //让方法在脱离事件后也能执行一次
- timeout = setTimeout(function(){
- fn.apply(context, args)
- }, threshhold);
- }
- }
- }
- export {
- config,
- post,
- getUrlArgObject,
- imageUrlPrefix,
- throttle
- }
|