public.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. var TOKEN = localStorage.getItem('token');
  2. //var USER = JSON.parse(localStorage.getItem('user'));
  3. var userName = localStorage.getItem('realname');
  4. var TAG = JSON.parse(localStorage.getItem('tag'));
  5. var JURISDICTION = JSON.parse(localStorage.getItem('jurisdiction'));
  6. var GOTO = JSON.parse(localStorage.getItem('goto'));
  7. console.log(TOKEN)
  8. // ------
  9. if(GOTO == 1){
  10. $('#header').remove();
  11. $('#slidebar').remove();
  12. $('.page-container').css({'padding':'0'})
  13. $('.page-container .page-content').css({'padding':'0'})
  14. }
  15. if(!TOKEN || !userName){
  16. window.location = '/login'
  17. }
  18. // 初始化loading
  19. try {
  20. (function () {
  21. var list = document.getElementById('size').children;
  22. var stemp = 0;
  23. window.setInterval(function () {
  24. for(var i = 0;i<list.length; i++){
  25. list[i].className = "";
  26. }
  27. list[stemp].className = 'active';
  28. if (stemp == list.length - 1) {
  29. stemp = 0
  30. } else {
  31. stemp++
  32. }
  33. }, 200)
  34. })();
  35. } catch (e){
  36. }
  37. /**
  38. * 绑定快捷方法
  39. * */
  40. var bindFast = function (ele, cla, obj) {
  41. if (cla == 'time') {
  42. ele.jeDate({
  43. isTime: true,
  44. format: "YYYY-MM-DD hh:mm:ss",
  45. // minDate: nowTime()+' 00:00',
  46. okfun:function () {
  47. var element = arguments[0] || ele,
  48. val = arguments[1];
  49. if(!/:/g.test(val)){
  50. if(element.attr('data-change-name') == 't1' || element.attr('data-change-name') == 't7'){
  51. element.val(val+' 9:00')
  52. }else if(element.attr('data-change-name') == 't9' || element.attr('data-change-name') == 't2'){
  53. element.val(val+' 18:00')
  54. }else{
  55. element.val(val);
  56. }
  57. }
  58. element.focus();
  59. }
  60. });
  61. }
  62. else if(cla == 'timer'){
  63. ele.jeDate({
  64. isTime: false,
  65. format: "YYYY-MM-DD",
  66. okfun:function () {
  67. var element = arguments[0] || ele,
  68. val = arguments[1];
  69. element.focus();
  70. }
  71. });
  72. }
  73. else if(cla == 'multiple'){
  74. ele.multiSelect({
  75. selectableHeader: (obj ? obj.noSelect : "") +"<input type='text' style='margin-bottom: 10px' class='search-input form-control' autocomplete='off' placeholder='筛选'>",
  76. selectionHeader: (obj ? obj.selected : "") +"<input type='text' style='margin-bottom: 10px' class='search-input form-control' autocomplete='off' placeholder='筛选'>",
  77. afterInit: function(ms){
  78. var that = this,$selectable = that.$selectableUl.prev(),$selection = that.$selectionUl.prev();
  79. $selectable.keyup(function(){
  80. var val = $(this).val();
  81. that.$selectableUl.children().each(function(){
  82. // if($(this).hasClass('ms-optgroup-container')){
  83. // $(this).children().children().each(function(){
  84. // if(!$(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){
  85. // $(this).show()
  86. // }else{
  87. // $(this).hide()
  88. // }
  89. // })
  90. // }
  91. if(!$(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){
  92. $(this).show()
  93. }else{
  94. $(this).hide()
  95. }
  96. })
  97. });
  98. $selection.keyup(function(){
  99. var val = $(this).val();
  100. that.$selectionUl.children().each(function(){
  101. // if($(this).hasClass('ms-optgroup-container')){
  102. // $(this).children().children().each(function(){
  103. // if($(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){
  104. // $(this).show()
  105. // }else{
  106. // $(this).hide()
  107. // }
  108. // })
  109. // }
  110. if($(this).hasClass('ms-selected') && $(this).text().indexOf(val) != -1){
  111. $(this).show()
  112. }else{
  113. $(this).hide()
  114. }
  115. })
  116. })
  117. }
  118. });
  119. }
  120. };
  121. var showLoading = function(){
  122. $('.opacity').fadeIn('fast')
  123. }
  124. var hideLoading = function(){
  125. $('.opacity').fadeOut('fast')
  126. }
  127. /**
  128. * 获取请求ajax数据
  129. * */
  130. var getAjax = function (data, type, url, callback, alert, upload) {
  131. // showLoading();
  132. var obj = {
  133. url: url,
  134. type: type,
  135. dataType: 'JSON',
  136. beforeSend: function(request) {
  137. //request.setRequestHeader("Authorization", 'Bearer '+ TOKEN);
  138. request.setRequestHeader("token",TOKEN);
  139. },
  140. data: data,
  141. success: function (result) {
  142. if (result.Status == 0 || result.Status == 401) {
  143. typeof callback == 'function' ? callback(result) : null;
  144. if (alert) weile.F.alert(result.msg || " ");
  145. // hideLoading();
  146. } else if(result.Status == 403){
  147. window.location = '/login';
  148. weile.F.alert(result.msg || " ");
  149. hideLoading();
  150. }
  151. },
  152. error: function (err) {
  153. if((err.state == 403 || err.Status == 403)){
  154. window.location = '/login';
  155. }
  156. weile.F.alert(err.toString() || " ");
  157. hideLoading();
  158. }
  159. }
  160. if(upload){
  161. obj.contentType = false;
  162. obj.cache = false;
  163. obj.processData = false;
  164. }
  165. $.ajax(obj)
  166. };
  167. /**
  168. * Promise.all 并发请求
  169. * @param {requestAry 需要请求的地址 数组}
  170. * @param {success 成功回调}
  171. * @param {error 失败回调}
  172. * @return {null}
  173. */
  174. var promiseAll = function(requestAry, success, error){
  175. var self = this;
  176. Promise.all(requestAry).then(function(result){
  177. var res1 = result[0];
  178. var res2 = result[1];
  179. if((res1.state == 0 || res1.status == 0) && (res2.state == 0 || res2.status == 0)){
  180. typeof success == 'function' ? success(res1,res2) : null;
  181. }else{
  182. typeof error == 'function' ? error(res1,res2) : weile.F.alert('请求错误');
  183. $('.opacity').fadeOut('fast');
  184. }
  185. },function(error){
  186. weile.F.alert(error.toString());
  187. $('.opacity').fadeOut('fast');
  188. })
  189. }
  190. /**
  191. * 深度拷贝对象
  192. * @param {obj 需要拷贝的对象}
  193. * @return {returnObj 拷贝后的对象}
  194. */
  195. function deepCopy(obj){
  196. var returnObj = {};
  197. try{
  198. returnObj = JSON.parse(JSON.stringify(obj));
  199. } catch(e){
  200. returnObj = {};
  201. for(var k in obj){
  202. returnObj[k] = obj[k];
  203. }
  204. console.log(obj ,returnObj)
  205. }
  206. return returnObj
  207. }
  208. var hoverEl = function(eles){
  209. var htmlStr = function(tip,el){
  210. var top = parseFloat(el.css('height')) + 11;
  211. var left = parseFloat(el.css('width')) / 2 - 11;
  212. var $html = $('<div class="hover-tip-he">'+ tip +'</div>');
  213. $html.css({'top':top+'px', right:left+'px'});
  214. return $html;
  215. }
  216. eles.hover(function(){
  217. $(this).css('position','relative');
  218. var tip = $(this).attr('data-tip') || '';
  219. $(this).append(htmlStr(tip, $(this)));
  220. },function(){
  221. $(this).find('.hover-tip-he').remove();
  222. $(this).css('position','initial');
  223. })
  224. };
  225. var getURL = function(search, name) {
  226. var reg = new RegExp("[?&]" + name + "=([^&]*)(&|$)", "i");
  227. var r = search.match(reg);
  228. if (r != null) return unescape(r[1]);
  229. return null;
  230. };
  231. var getTime = function(){
  232. var newDate = new Date();
  233. var YYYY = newDate.getFullYear();
  234. var MM = newDate.getMonth()+1;
  235. var DD = newDate.getDate();
  236. return YYYY+'-'+MM+'-'+DD;
  237. }
  238. var AppFun = {
  239. // relChannel: function(){
  240. // var channel_id = this.search.data.channel_id;
  241. // if(channel_id == '0'){
  242. // this.search.product_list = this.info.products;
  243. // }else{
  244. // this.search.product_list = this.info.channels[channel_id].product || {};
  245. // }
  246. // },
  247. // relApp: function(){
  248. // },
  249. // relProduct: function(){
  250. // },
  251. // channelProduct
  252. initREL: function(suc){
  253. var _this = this;
  254. promiseAll([
  255. $.ajax({
  256. url: '/api/channel_product',
  257. type: 'GET',
  258. dataType: 'JSON',
  259. beforeSend: function(request) {
  260. request.setRequestHeader("Authorization", 'Bearer '+ TOKEN);
  261. },
  262. data: {}
  263. }),
  264. $.ajax({
  265. url: '/api/product_channel',
  266. type: 'GET',
  267. dataType: 'JSON',
  268. beforeSend: function(request) {
  269. request.setRequestHeader("Authorization", 'Bearer '+ TOKEN);
  270. },
  271. data: {}
  272. }),
  273. ], function(res1, res2){
  274. _this.info.channels = res1.data;
  275. _this.info.products = res2.data;
  276. typeof suc == 'function' ? suc(res1, res2) : null;
  277. })
  278. },
  279. // channelApp
  280. initREL2: function(suc){
  281. var _this = this;
  282. promiseAll([
  283. $.ajax({
  284. url: '/api/channel_app',
  285. type: 'GET',
  286. dataType: 'JSON',
  287. beforeSend: function(request) {
  288. request.setRequestHeader("Authorization", 'Bearer '+ TOKEN);
  289. },
  290. data: {}
  291. }),
  292. $.ajax({
  293. url: '/api/app_channel',
  294. type: 'GET',
  295. dataType: 'JSON',
  296. beforeSend: function(request) {
  297. request.setRequestHeader("Authorization", 'Bearer '+ TOKEN);
  298. },
  299. data: {}
  300. }),
  301. ], function(res1, res2){
  302. _this.info.channels = res1.data;
  303. _this.info.apps = res2.data;
  304. typeof suc == 'function' ? suc(res1, res2) : null;
  305. })
  306. },
  307. }