var TOKEN = localStorage.getItem('token'); //var USER = JSON.parse(localStorage.getItem('user')); var userName = localStorage.getItem('realname'); var TAG = JSON.parse(localStorage.getItem('tag')); var JURISDICTION = JSON.parse(localStorage.getItem('jurisdiction')); var GOTO = JSON.parse(localStorage.getItem('goto')); console.log(TOKEN) // ------ if(GOTO == 1){ $('#header').remove(); $('#slidebar').remove(); $('.page-container').css({'padding':'0'}) $('.page-container .page-content').css({'padding':'0'}) } if(!TOKEN || !userName){ window.location = '/login' } // 初始化loading try { (function () { var list = document.getElementById('size').children; var stemp = 0; window.setInterval(function () { for(var i = 0;i", selectionHeader: (obj ? obj.selected : "") +"", afterInit: function(ms){ var that = this,$selectable = that.$selectableUl.prev(),$selection = that.$selectionUl.prev(); $selectable.keyup(function(){ var val = $(this).val(); that.$selectableUl.children().each(function(){ // if($(this).hasClass('ms-optgroup-container')){ // $(this).children().children().each(function(){ // if(!$(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){ // $(this).show() // }else{ // $(this).hide() // } // }) // } if(!$(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){ $(this).show() }else{ $(this).hide() } }) }); $selection.keyup(function(){ var val = $(this).val(); that.$selectionUl.children().each(function(){ // if($(this).hasClass('ms-optgroup-container')){ // $(this).children().children().each(function(){ // if($(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){ // $(this).show() // }else{ // $(this).hide() // } // }) // } if($(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){ $(this).show() }else{ $(this).hide() } }) }) } }); } }; var showLoading = function(){ $('.opacity').fadeIn('fast') } var hideLoading = function(){ $('.opacity').fadeOut('fast') } /** * 获取请求ajax数据 * */ var getAjax = function (data, type, url, callback, alert, upload) { // showLoading(); var obj = { url: url, type: type, dataType: 'JSON', beforeSend: function(request) { //request.setRequestHeader("Authorization", 'Bearer '+ TOKEN); request.setRequestHeader("token",TOKEN); }, data: data, success: function (result) { if (result.Status == 0 || result.Status == 401) { typeof callback == 'function' ? callback(result) : null; if (alert) weile.F.alert(result.msg || " "); // hideLoading(); } else if(result.Status == 403){ window.location = '/login'; weile.F.alert(result.msg || " "); hideLoading(); } }, error: function (err) { if((err.state == 403 || err.Status == 403)){ window.location = '/login'; } weile.F.alert(err.toString() || " "); hideLoading(); } } if(upload){ obj.contentType = false; obj.cache = false; obj.processData = false; } $.ajax(obj) }; /** * Promise.all 并发请求 * @param {requestAry 需要请求的地址 数组} * @param {success 成功回调} * @param {error 失败回调} * @return {null} */ var promiseAll = function(requestAry, success, error){ var self = this; Promise.all(requestAry).then(function(result){ var res1 = result[0]; var res2 = result[1]; if((res1.state == 0 || res1.status == 0) && (res2.state == 0 || res2.status == 0)){ typeof success == 'function' ? success(res1,res2) : null; }else{ typeof error == 'function' ? error(res1,res2) : weile.F.alert('请求错误'); $('.opacity').fadeOut('fast'); } },function(error){ weile.F.alert(error.toString()); $('.opacity').fadeOut('fast'); }) } /** * 深度拷贝对象 * @param {obj 需要拷贝的对象} * @return {returnObj 拷贝后的对象} */ function deepCopy(obj){ var returnObj = {}; try{ returnObj = JSON.parse(JSON.stringify(obj)); } catch(e){ returnObj = {}; for(var k in obj){ returnObj[k] = obj[k]; } console.log(obj ,returnObj) } return returnObj } var hoverEl = function(eles){ var htmlStr = function(tip,el){ var top = parseFloat(el.css('height')) + 11; var left = parseFloat(el.css('width')) / 2 - 11; var $html = $('
'+ tip +'
'); $html.css({'top':top+'px', right:left+'px'}); return $html; } eles.hover(function(){ $(this).css('position','relative'); var tip = $(this).attr('data-tip') || ''; $(this).append(htmlStr(tip, $(this))); },function(){ $(this).find('.hover-tip-he').remove(); $(this).css('position','initial'); }) }; var getURL = function(search, name) { var reg = new RegExp("[?&]" + name + "=([^&]*)(&|$)", "i"); var r = search.match(reg); if (r != null) return unescape(r[1]); return null; }; var getTime = function(){ var newDate = new Date(); var YYYY = newDate.getFullYear(); var MM = newDate.getMonth()+1; var DD = newDate.getDate(); return YYYY+'-'+MM+'-'+DD; } var AppFun = { // relChannel: function(){ // var channel_id = this.search.data.channel_id; // if(channel_id == '0'){ // this.search.product_list = this.info.products; // }else{ // this.search.product_list = this.info.channels[channel_id].product || {}; // } // }, // relApp: function(){ // }, // relProduct: function(){ // }, // channelProduct initREL: function(suc){ var _this = this; promiseAll([ $.ajax({ url: '/api/channel_product', type: 'GET', dataType: 'JSON', beforeSend: function(request) { request.setRequestHeader("Authorization", 'Bearer '+ TOKEN); }, data: {} }), $.ajax({ url: '/api/product_channel', type: 'GET', dataType: 'JSON', beforeSend: function(request) { request.setRequestHeader("Authorization", 'Bearer '+ TOKEN); }, data: {} }), ], function(res1, res2){ _this.info.channels = res1.data; _this.info.products = res2.data; typeof suc == 'function' ? suc(res1, res2) : null; }) }, // channelApp initREL2: function(suc){ var _this = this; promiseAll([ $.ajax({ url: '/api/channel_app', type: 'GET', dataType: 'JSON', beforeSend: function(request) { request.setRequestHeader("Authorization", 'Bearer '+ TOKEN); }, data: {} }), $.ajax({ url: '/api/app_channel', type: 'GET', dataType: 'JSON', beforeSend: function(request) { request.setRequestHeader("Authorization", 'Bearer '+ TOKEN); }, data: {} }), ], function(res1, res2){ _this.info.channels = res1.data; _this.info.apps = res2.data; typeof suc == 'function' ? suc(res1, res2) : null; }) }, }