123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- 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<list.length; i++){
- list[i].className = "";
- }
- list[stemp].className = 'active';
- if (stemp == list.length - 1) {
- stemp = 0
- } else {
- stemp++
- }
-
- }, 200)
- })();
- } catch (e){
- }
- /**
- * 绑定快捷方法
- * */
- var bindFast = function (ele, cla, obj) {
- if (cla == 'time') {
- ele.jeDate({
- isTime: true,
- format: "YYYY-MM-DD hh:mm:ss",
- // minDate: nowTime()+' 00:00',
- okfun:function () {
- var element = arguments[0] || ele,
- val = arguments[1];
- if(!/:/g.test(val)){
- if(element.attr('data-change-name') == 't1' || element.attr('data-change-name') == 't7'){
- element.val(val+' 9:00')
- }else if(element.attr('data-change-name') == 't9' || element.attr('data-change-name') == 't2'){
- element.val(val+' 18:00')
- }else{
- element.val(val);
- }
- }
- element.focus();
- }
- });
- }
- else if(cla == 'timer'){
- ele.jeDate({
- isTime: false,
- format: "YYYY-MM-DD",
- okfun:function () {
- var element = arguments[0] || ele,
- val = arguments[1];
- element.focus();
- }
- });
- }
- else if(cla == 'multiple'){
- ele.multiSelect({
- selectableHeader: (obj ? obj.noSelect : "") +"<input type='text' style='margin-bottom: 10px' class='search-input form-control' autocomplete='off' placeholder='筛选'>",
- selectionHeader: (obj ? obj.selected : "") +"<input type='text' style='margin-bottom: 10px' class='search-input form-control' autocomplete='off' placeholder='筛选'>",
- 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 = $('<div class="hover-tip-he">'+ tip +'</div>');
- $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;
-
- })
- },
- }
|