admin.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. $(document).ready(function() {
  2. $(document).on('click', '.new_tab', function(ev) {
  3. var title = $(this).attr('data-title') ? $(this).attr('data-title') : $(this).text();
  4. var href = $(this).attr('href');
  5. var icon = $(this).attr('data-icon') ? $(this).attr('data-icon') : $(this).find('i').attr('data-icon');
  6. if (parent && parent.Tab) {
  7. parent.Tab.tabAdd({
  8. title: title,
  9. href: href,
  10. icon: icon
  11. });
  12. }
  13. else {
  14. Tab.tabAdd({
  15. title: title,
  16. href: href,
  17. icon: icon
  18. });
  19. }
  20. if (ev && ev.preventDefault)
  21. ev.preventDefault();
  22. else
  23. window.event.returnValue = false;
  24. return false;
  25. })
  26. .on('click', '.javascript', function(ev) {
  27. var callback;
  28. if (callback = $(this).attr('rel')) {
  29. if (window[callback]) {
  30. window[callback].call(this);
  31. }
  32. }
  33. if (ev && ev.preventDefault)
  34. ev.preventDefault();
  35. else
  36. window.event.returnValue = false;
  37. return false;
  38. });
  39. $('.tooltip').hover(function() {
  40. var text = $(this).attr('data-tip-text');
  41. var type = $(this).attr('data-tip-type') ? $(this).attr('data-tip-type') : 2;
  42. var bg = $(this).attr('data-tip-bg') ? $(this).attr('data-tip-bg') : '#393D49';
  43. if (text) {
  44. layer.tips(text, $(this), {
  45. tips: [type, bg],
  46. time: 0
  47. });
  48. }
  49. }, function() {
  50. layer.close(layer.tips());
  51. })
  52. });
  53. var HKUC = {
  54. nl2br: function(str) {
  55. if (typeof(str) == 'string')
  56. return str.replace(/\r?\n/g, '<br />');
  57. else
  58. return str;
  59. },
  60. parse_serial_array: function(input, cols_type) {
  61. if (!cols_type)
  62. cols_type = {}
  63. var tmp = {};
  64. for (var i = 0; i < input.length; i++) {
  65. switch (cols_type[input[i].name]) {
  66. case 'checker':
  67. input[i].value = !!parseInt(input[i].value);
  68. break;
  69. case 'integer':
  70. input[i].value = parseInt(input[i].value);
  71. break;
  72. }
  73. var eval_str = 'tmp.' + input[i].name;
  74. var append = false;
  75. if (eval_str.substr(eval_str.length - 2) == '[]') {
  76. eval_str = eval_str.substring(0, eval_str.length - 2);
  77. append = true;
  78. }
  79. eval_str = eval_str.replace(/\[/g, '["').replace(/\]/g, '"]');
  80. var checkpos = 4;
  81. while ((checkpos = eval_str.indexOf('[', checkpos)) !== -1) {
  82. if (!eval(eval_str.substr(0, checkpos))) {
  83. eval(eval_str.substr(0, checkpos) + '={}');
  84. }
  85. checkpos += 1;
  86. }
  87. if (append) {
  88. if (!eval(eval_str))
  89. eval(eval_str + '=[]');
  90. var max_index = eval('Array.prototype.push.call(' + eval_str + ',input[i].value)');
  91. if (!eval(eval_str + '.length'))
  92. eval(eval_str + '[' + max_index + ']=input[i].value')
  93. }
  94. else {
  95. eval(eval_str + '=input[i].value');
  96. }
  97. }
  98. return tmp;
  99. },
  100. isJsonValidate: function isJsonValidate(str) {
  101. return str.match(/^(\[|\{).*(\}|\])$/);
  102. },
  103. default_successHandler: function(msg, data) {
  104. if (msg)
  105. alert(msg);
  106. else
  107. alert('提交成功');//提交成功
  108. return true;
  109. },
  110. default_failHandler: function(msg, data) {
  111. if (msg)
  112. alert(msg);
  113. else
  114. alert('提交失败');//提交失败
  115. return false;
  116. },
  117. ajax_request: function(url, data, successHandlers, errorHandlers) {
  118. successHandlers = $.extend({}, arguments.callee.defaultSuccessHandlers, successHandlers);
  119. errorHandlers = $.extend({}, arguments.callee.defaultErrorHandlers, errorHandlers);
  120. return $.ajax({
  121. 'url': url,
  122. 'data': data,
  123. 'type': data ? 'post' : 'get',
  124. 'success': $.proxy(
  125. function(response) {
  126. if (HKUC.isJsonValidate($.trim(response))) {
  127. var rslt = eval('(' + response + ')');
  128. if (this.handler[rslt.result]) {
  129. return this.handler[rslt.result].call(this.self, rslt.message, rslt.data, this.run);
  130. }
  131. return false;
  132. }
  133. else {
  134. if (this.handler['_']) {
  135. this.handler['_'].call(this.self, response, this.run);
  136. }
  137. else {
  138. alert(response);
  139. }
  140. }
  141. },
  142. {
  143. 'self': this,
  144. 'handler': successHandlers ? successHandlers : {},
  145. 'run': $.proxy(
  146. function() {
  147. return this.arguments.callee.apply(this.self, this.arguments);
  148. },
  149. {
  150. 'arguments': arguments,
  151. 'self': this
  152. }
  153. )
  154. }
  155. ),
  156. 'error': $.proxy(
  157. function(XMLHttpRequest, textStatus, errorThrown) {
  158. if (this.handler[XMLHttpRequest.status]) {
  159. return this.handler[XMLHttpRequest.status].call(this.self, errorThrown, this.run);
  160. }
  161. else if (this.handler['_']) {
  162. return this.handler['_'].call(this.self, errorThrown, this.run);
  163. }
  164. },
  165. {
  166. 'self': this,
  167. 'handler': errorHandlers ? errorHandlers : {},
  168. 'run': $.proxy(
  169. function() {
  170. return this.arguments.callee.apply(this.self, this.arguments);
  171. },
  172. {
  173. 'arguments': arguments,
  174. 'self': this
  175. }
  176. )
  177. }
  178. )
  179. })
  180. },
  181. imgFit: function(obj, width, height, shrink) {
  182. var imageRate1 = 0, imageRate2 = 0;
  183. if (!obj)
  184. return;
  185. var temp_img = new Image();
  186. temp_img.src = obj.src;
  187. if (temp_img.width > width || temp_img.height > height)
  188. {
  189. if (width)
  190. imageRate1 = temp_img.width / width;
  191. if (height)
  192. imageRate2 = temp_img.height / height;
  193. if (height) {
  194. if (width) {
  195. if (imageRate2 > imageRate1) {
  196. obj.style.height = temp_img.height / imageRate2 + "px";
  197. obj.style.width = 'auto';
  198. }
  199. else {
  200. obj.style.width = temp_img.width / imageRate1 + "px";
  201. obj.style.height = 'auto';
  202. }
  203. }
  204. else {
  205. obj.style.height = temp_img.height / imageRate2 + "px";
  206. obj.style.width = 'auto';
  207. }
  208. }
  209. else {
  210. obj.style.width = temp_img.width / imageRate1 + "px";
  211. obj.style.height = 'auto';
  212. }
  213. }
  214. if (shrink && temp_img.height <= obj.offsetHeight && temp_img.width <= obj.offsetWidth) {
  215. obj.style.height = temp_img.height + "px";
  216. obj.style.width = temp_img.width + "px";
  217. }
  218. },
  219. imgCache: function(url) {
  220. if (!arguments.callee.cache)
  221. arguments.callee.cache = [];
  222. var temp_img = new Image();
  223. temp_img.src = url;
  224. arguments.callee.cache.push(temp_img);
  225. },
  226. dummy: 'dummy'
  227. }
  228. $(function() {
  229. // 显示隐藏预览图 start
  230. $('.show_image').hover(
  231. function() {
  232. $(this).next().css('display', 'block');
  233. },
  234. function() {
  235. $(this).next().css('display', 'none');
  236. }
  237. );
  238. // 全选 start
  239. $('.checkall').click(function() {
  240. var _self = this.checked;
  241. $('.checkitem').each(function() {
  242. $(this).prop('checked', _self);
  243. });
  244. $('.checkall').prop('checked', _self);
  245. });
  246. // 表格鼠标悬停变色 start
  247. $("tbody tr").hover(
  248. function() {
  249. $(this).css({background: "#FBFBFB"});
  250. },
  251. function() {
  252. $(this).css({background: "#FFF"});
  253. });
  254. // 可编辑列(input)变色
  255. $('.editable').hover(
  256. function() {
  257. $(this).removeClass('editable').addClass('editable2');
  258. },
  259. function() {
  260. $(this).removeClass('editable2').addClass('editable');
  261. }
  262. );
  263. // 提示操作 展开与隐藏
  264. $("#checkZoom").click(function() {
  265. $(this).next("ul").toggle(800);
  266. $(this).find(".arrow").toggleClass("up");
  267. });
  268. // 可编辑列(area)变色
  269. $('.editable-tarea').hover(
  270. function() {
  271. $(this).removeClass('editable-tarea').addClass('editable-tarea2');
  272. },
  273. function() {
  274. $(this).removeClass('editable-tarea2').addClass('editable-tarea');
  275. }
  276. );
  277. });
  278. /**
  279. * Layer 通用ifram弹出窗口
  280. */
  281. function dsLayerOpen(url, title,width,height) {
  282. if (!width) width = '900px';
  283. if (!height) height = '500px';
  284. layer.open({
  285. type: 2,
  286. title: title,
  287. area: [width,height],
  288. fixed: false, //不固定
  289. maxmin: true,
  290. content: url
  291. });
  292. }
  293. /**
  294. * Layer 通用confirm弹出窗口
  295. */
  296. function dsLayerConfirm(url, title) {
  297. layer.confirm(title, {
  298. btn: ['确定', '取消'],
  299. title: false,
  300. }, function () {
  301. $.ajax({
  302. url: url,
  303. type: "get",
  304. dataType: "json",
  305. success: function (data) {
  306. if(data.code == 10000){
  307. location.reload();
  308. }else{
  309. layer.msg(data.message, {icon: 2})
  310. }
  311. }
  312. });
  313. });
  314. }
  315. /**
  316. * 批量删除
  317. */
  318. function submit_delete_batch() {
  319. /* 获取选中的项 */
  320. var items = '';
  321. $('.checkitem:checked').each(function () {
  322. items += this.value + ',';
  323. });
  324. if (items != '') {
  325. items = items.substr(0, (items.length - 1));
  326. submit_delete(items);
  327. }
  328. }