common.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* Fixed Internet Explorer 10 和 Windows Phone 8 媒体查询功能 */
  2. if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  3. var msViewportStyle = document.createElement("style")
  4. msViewportStyle.appendChild(
  5. document.createTextNode(
  6. "@-ms-viewport{width:auto!important}"
  7. )
  8. )
  9. document.getElementsByTagName("head")[0].appendChild(msViewportStyle)
  10. }
  11. //客户端存储
  12. var storage_prefix = ''; //存储key的前缀
  13. var storage = {
  14. hname:location.hostname?location.hostname:'localStatus',
  15. isLocalStorage:window.localStorage?true:false,
  16. dataDom:null,
  17. initDom:function(){ //初始化userData
  18. if(!this.dataDom){
  19. try{
  20. this.dataDom = document.createElement('input');//这里使用hidden的input元素
  21. this.dataDom.type = 'hidden';
  22. this.dataDom.style.display = "none";
  23. this.dataDom.addBehavior('#default#userData');//这是userData的语法
  24. document.body.appendChild(this.dataDom);
  25. var exDate = new Date();
  26. exDate = exDate.getDate()+30;
  27. this.dataDom.expires = exDate.toUTCString();//设定过期时间
  28. }catch(ex){
  29. return false;
  30. }
  31. }
  32. return true;
  33. },
  34. setItem:function(key,value,noPrefix){
  35. if (noPrefix == null || !noPrefix){
  36. key = storage_prefix + key;
  37. }
  38. if(this.isLocalStorage){
  39. window.localStorage.setItem(key, JSON.stringify(value));
  40. }else{
  41. if(this.initDom()){
  42. this.dataDom.load(this.hname);
  43. this.dataDom.setAttribute(key, JSON.stringify(value));
  44. this.dataDom.save(this.hname)
  45. }
  46. }
  47. },
  48. getItem:function(key,noPrefix){
  49. if (noPrefix == null || !noPrefix){
  50. key = storage_prefix + key;
  51. }
  52. if(this.isLocalStorage){
  53. var t = window.localStorage.getItem(key);
  54. if (t === null){
  55. return t;
  56. } else {
  57. return JSON.parse(t);
  58. }
  59. }else{
  60. if(this.initDom()){
  61. this.dataDom.load(this.hname);
  62. var t = this.dataDom.getAttribute(key);
  63. if (t === null){
  64. return t;
  65. } else {
  66. return JSON.parse(t);
  67. }
  68. }
  69. }
  70. },
  71. removeItem:function(key,noPrefix){
  72. if (noPrefix == null || !noPrefix){
  73. key = storage_prefix + key;
  74. }
  75. if(this.isLocalStorage){
  76. localStorage.removeItem(key);
  77. }else{
  78. if(this.initDom()){
  79. this.dataDom.load(this.hname);
  80. this.dataDom.removeAttribute(key);
  81. this.dataDom.save(this.hname)
  82. }
  83. }
  84. }
  85. };
  86. /**
  87. * summary: 用户操作确认组件,默认为删除理由
  88. * author: justin
  89. * date: 2014.03.07
  90. */
  91. $.messager.confirm_action = function(options){
  92. var defaults = {
  93. title: '确认操作吗?',
  94. module: '',
  95. value: '',
  96. editable: false,
  97. push_switch: false,
  98. callback: null,
  99. }
  100. var option = $.extend({}, defaults, options);
  101. var dialog_id = 'easyui_confirm_action';
  102. var select_id = dialog_id + '_select';
  103. if ($('#' + dialog_id).length == 0){
  104. var html = '<div style="margin: 30px 50px;"><span>理由: </span><input id="' + select_id + '" /></div>';
  105. $('body').append('<div id="' + dialog_id + '">' + html + '</div>');
  106. }
  107. if (typeof(site_root) == 'undefined'){
  108. site_root = 'http://admin.yiguanjia.club';
  109. }
  110. var jq_cd = $('#' + dialog_id);
  111. var jq_cds = $('#' + select_id);
  112. jq_cds.combobox({
  113. width: 220,
  114. editable: option.editable,
  115. url: site_root + '/index.php?r=api/getActionReason&module=' + option.module,
  116. value: option.value,
  117. onLoadSuccess: function(){
  118. if ($(this).combobox('getData').length > 0){
  119. $(this).combobox('showPanel');
  120. }
  121. }
  122. })
  123. jq_cd.dialog({
  124. title: option.title,
  125. width: 400,
  126. height: 160,
  127. cache: false,
  128. modal: true,
  129. buttons:[{
  130. text: '确认',
  131. iconCls: 'icon-ok',
  132. handler: function(){
  133. if (option.callback && typeof(option.callback) == 'function'){
  134. var t = option.callback(jq_cds.combobox('getText'));
  135. if (typeof(t) == 'undefined' || t){
  136. jq_cd.dialog('close');
  137. }
  138. }
  139. }
  140. },{
  141. text: '取消',
  142. iconCls: 'icon-cancel',
  143. handler: function(){
  144. jq_cd.dialog('close');
  145. }
  146. }]
  147. });
  148. }
  149. /**
  150. * summary: 获取字符串的参数对象
  151. * author: justin
  152. * date: 2014.04.24
  153. */
  154. function get_param_from_str(str){
  155. var param = {};
  156. if (str.indexOf('?') != -1){
  157. var t = str.slice(str.indexOf('?') + 1);
  158. var t1 = t.split('&');
  159. for (var i = 0;i < t1.length;i ++){
  160. var t2 = t1[i].split('=');
  161. param[t2[0]] = decodeURI(t2[1]);
  162. }
  163. }
  164. return param;
  165. }
  166. /**
  167. * summary: 获取链接中的参数对象
  168. * author: justin
  169. * date: 2014.03.21
  170. */
  171. function get_param_obj(){
  172. var refresh = sessionStorage.getItem('refresh');
  173. if (refresh) {
  174. var param = {};
  175. } else {
  176. var param = get_param_from_str(window.location.href);
  177. }
  178. return param;
  179. }
  180. /**
  181. * summary: 默认刷新页面,由各模块重写实现不跳转刷新结果
  182. * author: justin
  183. * date: 2014.04.24
  184. */
  185. function refresh_page(url){
  186. if (typeof jq_dg_content != 'undefined'){
  187. // var old_param = jq_dg_content.datagrid('options').queryParams;
  188. var old_param = {};
  189. old_param['search'] = '';
  190. var new_param = $.extend(true, old_param, get_param_from_str(url));
  191. jq_dg_content.datagrid({
  192. queryParams: new_param,
  193. pageNumber: 1
  194. });
  195. } else {
  196. location.href = url;
  197. }
  198. }
  199. /**
  200. * summary: 根据combobox data获取datagrid filed的显示名称
  201. * author: justin
  202. * date: 2014.05.13
  203. */
  204. function get_filed_text(value, data){
  205. var val = '';
  206. for (var i = 0;i < data.length;i ++){
  207. var t = data[i];
  208. if (t['value'] == value){
  209. var style = '';
  210. if (!!t.attributes && !!t.attributes.color){
  211. style = ' style="color:' + t['attributes']['color'] + '"';
  212. val = '<span' + style + '>' + t['text'] + '</span>';
  213. } else {
  214. val = t['text'];
  215. }
  216. break;
  217. }
  218. }
  219. return val;
  220. }
  221. /**
  222. * summary: 获取debug的链接
  223. * author: justin
  224. * date: 2014.05.15
  225. */
  226. function get_debug_url(url){
  227. var debug_url = url;
  228. if (!!get_param_obj().debug){
  229. debug_url = '';
  230. var t = url.split('?');
  231. if (t.length == 1){
  232. debug_url = t[0] + '?debug=1';
  233. } else {
  234. debug_url = url + '&debug=1';
  235. }
  236. }
  237. return debug_url;
  238. }
  239. function format_time_stamp(time,full)
  240. {
  241. var d = new Date(time*1000);
  242. if(full){
  243. return(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
  244. }else{
  245. return(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate());
  246. }
  247. }
  248. $(function(){
  249. /**
  250. * 统一对所有的ajax请求进行debug预处理
  251. */
  252. var ajax_default_data = {};
  253. if (parent != window){
  254. }
  255. if (!!get_param_obj().debug){
  256. ajax_default_data['debug'] = 1;
  257. }
  258. $.ajaxSetup({
  259. data: ajax_default_data
  260. });
  261. });