common.js 6.99 KB
Newer Older
txy committed
1 2

// 公共变量
txy committed
3
var activityCode = typeof rules !== 'undefined' ? rules.acActivity.code : '';
txy committed
4
var baseUrl = "https://space-api.check.icaremgt.com";
txy committed
5
var manageUrl = "http://api-admin-manage.check.icaremgt.com";
txy committed
6

txy committed
7 8 9
if(typeof data !== 'undefined'){
  data.htmlJson = JSON.parse(data.htmlJson);
}
txy committed
10

txy committed
11 12 13 14 15 16 17 18 19
// 设置token
function setToken(){
  if(user.token !== '') {
    sessionStorage.setItem('x-token', user.token);
  }else {
    sessionStorage.setItem('x-token', '');
  }
}

胡畅 committed
20 21 22 23 24 25 26 27 28 29 30 31
// 机构id
function orgIdFn(id) {
    var signupOrg = rules.acActivityOrgs
    var org = signupOrg && signupOrg.filter(function(item){
        return id == item.id
    })
    if(org.length == 1) {
        return org[0]
    }else {
        return null
    }
}
txy committed
32 33 34 35 36 37
// 获取token
function getToken() {
  var t = sessionStorage.getItem('x-token');
  return t
}

txy committed
38 39
// 获取域名及二级目录
function getBaseOrigin(){
txy committed
40
  var _base = '';
txy committed
41 42 43 44
  var _origin = window.location.origin;
  var _pathname = window.location.pathname;
  var index = _pathname.indexOf('/ACTIVITY');
  var _secondFolder = '';
txy committed
45 46
  
  if(index !== 0){
txy committed
47
      _secondFolder = _pathname.slice(0,index);
txy committed
48
  }
txy committed
49
  _base = _origin + _secondFolder;
txy committed
50 51 52 53 54 55 56 57 58 59

  return _base;
}

// 页面跳转
function transPage(_pageNumber, _activityCode, _token, _addParam) {
  var url = '';
  var _base = '';
  var _urlParam = window.location.search;
  _base = getBaseOrigin();
txy committed
60
 
txy committed
61
  if (typeof _urlParam !== 'undefined' && _urlParam !== '') {
txy committed
62
      url = _base + "/ACTIVITY/view/" + _activityCode + "/" + _pageNumber + _urlParam + (_addParam !== undefined ? ('&' + _addParam) : '');
txy committed
63
  } else {
txy committed
64
      url = _base + "/ACTIVITY/view/" + _activityCode + "/" + _pageNumber + (_addParam !== undefined ? ('?' + _addParam) : '');
txy committed
65 66
  }

txy committed
67 68 69 70
  // var _form = document.createElement('form');
  // _form.action = url;
  // _form.method = "post";
  // _form.style.display = "none";
txy committed
71

txy committed
72 73 74 75 76 77 78
  // var inputToken = document.createElement('input');
  // inputToken.value = _token;
  // inputToken.name = 'x-token';
  // _form.appendChild(inputToken);
  // document.body.appendChild(_form);
  // _form.submit();
  window.location.href = url;
txy committed
79 80 81 82 83 84 85 86 87 88 89 90
}

// 获取URL中指定参数
function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
      return unescape(r[2]);
  }
  return null;
}

txy committed
91

txy committed
92 93 94
// 加载HTML结构
function loadHtmlJson() {
  $('body').prepend(json2html(data.htmlJson));
txy committed
95
  var _relationship = JSON.parse(data.relationship);
txy committed
96 97 98 99 100 101
  for(var i=0;i<_relationship.childs.length;i++) {
      var _page = _relationship.childs[i].page
      var _pageNumber = _relationship.childs[i].pageNumber
      $('body').prepend(json2html(JSON.parse(data[_page].htmlJson)));
      $('#html-template-'+_pageNumber).addClass('global-none')
  }
txy committed
102 103 104 105
}

// 关注弹出框
function appendAttentionDialog() {
txy committed
106 107 108 109
// var orgId = getQueryString("orgId");
// var orgInfo = orgIdFn(orgId);
// var orgName = orgInfo !== null ? orgInfo.orgName : '';

txy committed
110
var str = '<section id="html-container-attention" style="display: none;">'+
txy committed
111 112 113 114 115 116 117 118 119 120
            '<div>'+
              '<div class="c-modal-wrap">'+
                '<div class="mshe-mask"></div> '+
                '<div class="c-modal">'+
                  '<div class="modal-dialog">'+
                    '<div c_type="dialog" c_typename="dialog_playerVote1" class="modal-content" style="background: rgb(255, 255, 255);">'+
                    '<div class="modal-header">'+
                      '<img src="http://qnfile.icareyou.net/363a344aa7424d219a5fc86eff7265751561343712294.jpg" class="header-pic">'+
                    '</div>'+ 
                    '<div class="modal-body">'+
txy committed
121
                      '<p class="struct">长按关注后继续活动</p>'+
txy committed
122
                      '<div>'+
txy committed
123
                        '<img src="http://qnfile.icareyou.net/55c7553ba1a44465be91c57d19a69d3e1562894997132.jpg" alt="" style="width: 100%;">'+
txy committed
124 125 126 127 128 129 130 131 132 133
                      '</div>'+
                    '</div>'+
                    '<div class="modal-close">'+
                      '<img src="http://qnfile.icareyou.net/ddae57885c424abdb13d37c78038c6a01561343787282.jpg">'+
                    '</div>'+
                    '</div>'+
                  '</div>'+
                '</div>'+
              '</div>'+
            '</div>'+
txy committed
134
          '</section>';
txy committed
135 136

  $('body').prepend(str);
txy committed
137 138
  // 事件绑定
  $("#html-container-attention .modal-close").off("click").on("click", function(){
txy committed
139
    $("#html-container-attention").fadeOut();
txy committed
140 141 142
  });

  // 未关注过默认显示弹出框  
txy committed
143
  if (!user.attention){
txy committed
144
    $("#html-container-attention").fadeIn();
txy committed
145 146 147
  }
}

txy committed
148 149 150 151
// 显示强关弹出框
function showAttentionDialog() {
  $("#html-container-attention").fadeIn();
}
txy committed
152

txy committed
153 154 155 156 157 158 159
// 隐藏强关弹出框
function hideAttentionDialog() {
  $("#html-container-attention").hide();
}

// 不在审核页面插入强关弹出框
if(typeof user !== 'undefined' && $("#examineTitle").length === 0){
txy committed
160 161
  appendAttentionDialog();
}
txy committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

// 判断是否关注
function isAttention(successCallback,errorCallback) {
  // 未关注
  if(!user.attention){
    if(errorCallback) {
      errorCallback();
    }else {
      // 强关弹出框
      showAttentionDialog();
    }
  } else {
    successCallback && successCallback();
  }
}
txy committed
177

txy committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
// 是否报名
function isSignUp(successCallback,errorCallback) {
  var _t = getToken();
  // 已报名
  if(user.reviewStatus !== '') {
      switch (user.reviewStatus) {
          // 0-待审核
          case 0:
              alert('您的报名信息正在审核中...');
          break;
          // 1-审核通过
          case 1:
            if(successCallback){
              successCallback();
            }else {
              alert('您当前已通过报名,请到个人主页去拉票!');
            }
          break;
          // 2-审核未通过
          case 2:
              alert('审核未通过!');
              transPage('2',activityCode,_t);
          break;
          default:
              break;
      }
  } else {// 未报名
    if(errorCallback) {
      errorCallback();
    }else {
      // 跳转到报名页面 
      transPage('2',activityCode,_t);
    }
  }
txy committed
212 213 214 215 216 217 218 219 220 221 222 223
}

// 获取活动名称
function getActivityTitle() {
  var activityCode = getQueryString('activityCode');
  var params = {
    activityCode: activityCode
  }
  $.ajax({
      type: 'GET',
      url: baseUrl + '/ACTIVITY/'+ activityCode +'/settings',
      data: params,
txy committed
224 225 226
      headers: {
        'x-token': getToken()
      },
txy committed
227 228 229 230
      success: function(data) {
          if(data.status == 200) {
            var title = data.result.settings.szText.h5Title;
            document.title = title;
txy committed
231 232

            var $body = $('body');
txy committed
233
            var $iframe = $('<iframe src=""></iframe>');
txy committed
234 235 236 237 238
            $iframe.on('load',function() {
              setTimeout(function() {
                  $iframe.off('load').remove();
              }, 0);
            }).appendTo($body);
txy committed
239 240 241 242 243 244 245 246 247 248
          }
      },
      error: function() {
          $.dialog({
              type : 'tips',
              autoClose : 3000,
              infoText : '请求超时,请尝试刷新页面!'
          });
      }
  })
txy committed
249
}