feehi.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. yii.confirm = function(message, ok, cancel) {
  2. var url = $(this).attr('href');
  3. var if_pjax = $(this).attr('data-pjax') ? $(this).attr('data-pjax') : 0;
  4. var method = $(this).attr('data-method') ? $(this).attr('data-method') : "post";
  5. var data = $(this).attr('data-params') ? JSON.parse( $(this).attr('data-params') ) : '';
  6. layer.confirm(message, {
  7. title:tips.confirmTitle,
  8. btn: [tips.ok, tips.cancel] //按钮
  9. }, function(){//ok
  10. if( parseInt( if_pjax ) ){
  11. !ok || ok();
  12. }else {
  13. $.ajax({
  14. "url": url,
  15. "dataType": "json",
  16. "type": method,
  17. "data": data,
  18. beforeSend: function () {
  19. layer.load(2,{
  20. shade: [0.1,'#fff'] //0.1透明度的白色背景
  21. });
  22. },
  23. "success": function (data) {
  24. location.reload();
  25. },
  26. "error": function (jqXHR, textStatus, errorThrown) {
  27. if( jqXHR.hasOwnProperty("responseJSON") ){
  28. layer.alert(jqXHR.responseJSON.message, {
  29. title:tips.error,
  30. btn: [tips.ok],
  31. icon: 2,
  32. skin: 'layer-ext-moon'
  33. })
  34. }else{
  35. layer.alert(jqXHR.responseText, {
  36. title:tips.error,
  37. btn: [tips.ok],
  38. icon: 2,
  39. skin: 'layer-ext-moon'
  40. })
  41. }
  42. },
  43. "complete": function () {
  44. layer.closeAll('loading');
  45. }
  46. });
  47. }
  48. }, function(){//cancel
  49. !cancel || cancel();
  50. });
  51. }
  52. function viewLayer(url, obj)
  53. {
  54. var area = ['80%', ($(window).height() - 100) + 'px'];
  55. if( isMobile || $(window).width() < 640) {
  56. area = ['100%', '100%']
  57. }
  58. layer.open({
  59. type: 2,
  60. title: obj.attr('title'),
  61. maxmin: true,
  62. shadeClose: true, //点击遮罩关闭层
  63. area: area,
  64. content: url
  65. });
  66. }
  67. function adaptPhone()
  68. {
  69. var windowWidth = $(window).width();
  70. var tables = document.getElementsByTagName("table");
  71. if( tables.length <=0 ) return;
  72. var table = tables[0];
  73. var rows = table.rows;
  74. var columns = rows[0].cells.length;
  75. var displayColumns = 4;
  76. var lastColumnIndex = columns - 1;
  77. var i,j = 0;
  78. var display = "";
  79. if( columns > displayColumns ) {
  80. if(windowWidth < 640 || isMobile){
  81. display = "none";
  82. }
  83. for (i = 0; i < rows.length; i++) {
  84. for (j = displayColumns ; j < lastColumnIndex; j++) {
  85. if( !rows.hasOwnProperty(i) ) continue;
  86. if( !rows[i].cells.hasOwnProperty(j) ) continue;
  87. rows[i].cells[j].style.display = display;
  88. }
  89. }
  90. }
  91. }
  92. var isMobile = false;
  93. var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
  94. for (var v = 0; v < Agents.length; v++) {
  95. if (navigator.userAgent.indexOf(Agents[v]) > 0) {
  96. isMobile = true;
  97. break;
  98. }
  99. }
  100. $(document).ready(function(){
  101. //$('.info').animate({opacity: 1.0}, 3000).fadeOut('slow');
  102. adaptPhone();
  103. $(window).resize(adaptPhone());
  104. //多选后处理
  105. $(".multi-operate").click(function () {
  106. var that = $(this);
  107. var url = $(this).attr('href');
  108. var method = $(this).attr('data-method') ? $(this).attr('data-method') : "post";
  109. var paramSign = that.attr('param-sign') ? that.attr('param-sign') : "id";
  110. var ids = [];
  111. $("tr td input[type=checkbox]:checked").each(function(){
  112. ids.push($(this).val());
  113. });
  114. if(ids.length <= 0){
  115. layer.alert(tips.noItemSelected, {
  116. title:tips.error,
  117. btn: [tips.ok],
  118. icon: 2,
  119. skin: 'layer-ext-moon'
  120. })
  121. return false;
  122. }
  123. layer.confirm($(this).attr("data-confirm") + "<br>" + paramSign + ": " + ids.join(","), {
  124. title:tips.confirmTitle,
  125. btn: [tips.ok, tips.cancel] //按钮
  126. }, function() {//ok
  127. if( that.hasClass("jump") ){//含有jump的class不做ajax处理,跳转页面
  128. var jumpUrl = url.indexOf('?') !== -1 ? url + '&' + paramSign + '=' + ids : url + '?' + paramSign + '=' + ids;
  129. location.href = jumpUrl;
  130. return false;
  131. }
  132. var data = {};
  133. data[paramSign] = JSON.stringify(ids);
  134. $.ajax({
  135. "url":url,
  136. "dataType" : "json",
  137. "type" : method,
  138. "data":data,
  139. beforeSend: function () {
  140. layer.load(2,{
  141. shade: [0.1,'#fff'] //0.1透明度的白色背景
  142. });
  143. },
  144. "success" : function (data) {
  145. location.reload();
  146. },
  147. "error": function (jqXHR, textStatus, errorThrown) {
  148. if( jqXHR.hasOwnProperty("responseJSON") ) {
  149. layer.alert(jqXHR.responseJSON.message, {
  150. title: tips.error,
  151. btn: [tips.ok],
  152. icon: 2,
  153. skin: 'layer-ext-moon'
  154. })
  155. }else{
  156. layer.alert(jqXHR.responseText, {
  157. title:tips.error,
  158. btn: [tips.ok],
  159. icon: 2,
  160. skin: 'layer-ext-moon'
  161. })
  162. }
  163. },
  164. "complete": function () {
  165. layer.closeAll('loading');
  166. }
  167. });
  168. }, function (index) {
  169. layer.close(index);
  170. })
  171. return false;
  172. })
  173. $("a.close-link").click(function () {
  174. var node = $(this).parents("div.ibox:first");
  175. node.hide();
  176. if(node.length == 0){
  177. $(this).parents("div.ibox-title").hide();
  178. $(this).parents("div.ibox-title:first").next().hide();
  179. }
  180. $(this).parents("div.ibox:first").hide();
  181. })
  182. $("a.collapse-link").click(function () {
  183. var node = $(this).parents("div.ibox:first").children("div.ibox-content");
  184. node.slideToggle();
  185. var iClass = $(this).children("i:first").attr('class');
  186. if(iClass == 'fa fa-chevron-up'){
  187. $(this).children("i:first").attr('class', 'fa fa-chevron-down');
  188. }else{
  189. $(this).children("i:first").attr('class', 'fa fa-chevron-up');
  190. }
  191. if(node.length == 0){
  192. $(this).parents("div.ibox-title:first").next().slideToggle();
  193. }
  194. })
  195. $('input.sort').blur(indexSort);
  196. $('a.refresh').click(function(){
  197. location.reload();
  198. return false;
  199. });
  200. //prettyFile文件选矿change后如果是图片显示图片
  201. $('input[type=file].pretty-file').bind('change', function () {
  202. if (typeof FileReader === 'undefined') {
  203. return;
  204. }
  205. var that = $(this);
  206. var files = $( this )[0].files;
  207. if(that.parent().parent().attr('class').indexOf("image") >= 0){
  208. if(!/image\/\w+/.test(files[0].type)){
  209. layer.tips(tips.onlyPictureCanBeSelected, that.parent().parent());
  210. return false;
  211. }
  212. var reader = new FileReader();
  213. reader.readAsDataURL(files[0]);
  214. reader.onload = function (e) {
  215. if( that.parents("div.image").children().find('img').next().length >= 1 ){
  216. that.parents("div.image").children().find('img').next().remove();
  217. }
  218. that.parents("div.image").children().find('img').attr("src", this.result).after('<div onclick="$(this).parents(\'.image\').find(\'input[type=hidden]\').val(0);$(this).prev().attr(\'src\', $(this).prev().attr(\'nonePicUrl\'));$(this).parents(\'.form-group\').find(\'input[type=file]\').val(\'\');$(this).remove();" style="position: absolute;width: 50px;padding: 5px 3px 3px 5px;top:5px;left:6px;background: black;opacity: 0.6;color: white;cursor: pointer"><i class="fa fa-trash" aria-hidden="true"> '+ common.deleteText +'</i></div>');
  219. }
  220. }
  221. });
  222. //在顶部导航栏打开tab
  223. $(".openContab").click(function(){
  224. parent.openConTab($(this));
  225. return false;
  226. });
  227. //提交表单后除form为none-loading的class显示loading效果
  228. $("form:not(.none-loading)").bind("beforeSubmit", function () {
  229. $(this).find("button[type=submit]").attr("disabled", true);
  230. layer.load(2,{
  231. shade: [0.1,'#fff'] //0.1透明度的白色背景
  232. });
  233. })
  234. //prettyFile美化文件选框
  235. $("input[type=file].pretty-file").each(function () {
  236. $(this).prettyFile({
  237. text:this.getAttribute('text')
  238. });
  239. })
  240. //美化日期laydate插件
  241. lay('.date-time').each(function(){
  242. var config = {
  243. elem: this,
  244. type: this.getAttribute('dateType'),
  245. range: this.getAttribute('range') === 'true' ? true : ( this.getAttribute('range') === 'false' ? false : this.getAttribute('range') ),
  246. format: this.getAttribute('format'),
  247. value: this.getAttribute('val') === 'new Date()' ? new Date() : this.getAttribute('val'),
  248. isInitValue: this.getAttribute('isInitValue') != 'false',
  249. min: this.getAttribute('min'),
  250. max: this.getAttribute('max'),
  251. trigger: this.getAttribute('trigger'),
  252. show: this.getAttribute('show') != 'false',
  253. position: this.getAttribute('position'),
  254. zIndex: parseInt(this.getAttribute('zIndex')),
  255. showBottom: this.getAttribute('showBottom') != 'false',
  256. btns: this.getAttribute('btns').replace(/\[/ig, '').replace(/\]/ig, '').replace(/'/ig,'').replace(/\s/ig, '').split(','),
  257. lang: this.getAttribute('lang'),
  258. theme: this.getAttribute('theme'),
  259. calendar: this.getAttribute('calendar') != 'false',
  260. mark: JSON.parse(this.getAttribute('mark'))
  261. };
  262. if( !this.getAttribute('search') ){//搜素
  263. config.done = function(value, date, endDate){
  264. setTimeout(function(){
  265. $(this).val(value);
  266. var e = $.Event("keydown");
  267. e.keyCode = 13;
  268. $(".date-time[search!='true']").trigger(e);
  269. },100)
  270. }
  271. }
  272. delete config['val'];
  273. laydate.render(config);
  274. });
  275. //美化select选框jquery chosen
  276. $(".chosen-select").each(function(){
  277. $(this).chosen({
  278. allow_single_deselect: this.getAttribute('allow_single_deselect') !== 'false',
  279. disable_search: this.getAttribute('disable_search') !== 'false',
  280. disable_search_threshold: this.getAttribute('disable_search_threshold'),
  281. enable_split_word_search: this.getAttribute('enable_split_word_search') !== 'false',
  282. inherit_select_classes: this.getAttribute('inherit_select_classes') !== 'false',
  283. max_selected_options: this.getAttribute('max_selected_options'),
  284. no_results_text: this.getAttribute('no_results_text'),
  285. placeholder_text_multiple: this.getAttribute('placeholder_text_multiple'),
  286. placeholder_text_single: this.getAttribute('placeholder_text_single'),
  287. search_contains: this.getAttribute('search_contains') !== 'false',
  288. group_search: this.getAttribute('group_search') !== 'false',
  289. single_backstroke_delete: this.getAttribute('single_backstroke_delete') !== 'false',
  290. width: this.getAttribute('width'),
  291. display_disabled_options: this.getAttribute('display_disabled_options') !== 'false',
  292. display_selected_options: this.getAttribute('display_selected_options') !== 'false',
  293. include_group_label_in_selected: this.getAttribute('include_group_label_in_selected') !== 'false',
  294. max_shown_results: this.getAttribute('max_shown_results'),
  295. case_sensitive_search: this.getAttribute('case_sensitive_search') !== 'false',
  296. hide_results_on_select: this.getAttribute('hide_results_on_select') !== 'false',
  297. rtl: this.getAttribute('rtl') !== 'false'
  298. });
  299. })
  300. })
  301. function indexSort(){
  302. layer.load(2,{
  303. shade: [0.1,'#fff'] //0.1透明度的白色背景
  304. });
  305. var data = {};
  306. var name = $(this).attr('name');
  307. data[name] = $(this).val();
  308. var sortHeader = $("th[sort-header=1]");
  309. $.ajax({
  310. url: sortHeader.attr('action'),
  311. method: sortHeader.attr('method'),
  312. data: data,
  313. error: function (jqXHR, textStatus, errorThrown) {
  314. if( jqXHR.hasOwnProperty("responseJSON") ) {
  315. layer.alert(jqXHR.responseJSON.message, {
  316. title: tips.error,
  317. btn: [tips.ok],
  318. icon: 2,
  319. skin: 'layer-ext-moon'
  320. })
  321. }else{
  322. layer.alert(jqXHR.responseText, {
  323. title:tips.error,
  324. btn: [tips.ok],
  325. icon: 2,
  326. skin: 'layer-ext-moon'
  327. })
  328. }
  329. },
  330. complete: function () {
  331. layer.closeAll('loading');
  332. }
  333. })
  334. return false;
  335. }