main.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250
  1. //这里的代码是最早写的,很乱,以后整合优化
  2. var editors = [];
  3. var editors_index = [];
  4. var tables = [];
  5. var select = '';
  6. var submitButton = '';
  7. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  8. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  9. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  10. } else {
  11. return this.replace(reallyDo, replaceWith);
  12. }
  13. }
  14. Array.prototype.remove = function(val) {
  15. var index = -1;
  16. for(var i = 0; i < this.length; i++)
  17. {
  18. if(this[i] == val)
  19. {
  20. index = i;
  21. }
  22. }
  23. if (index > -1) {
  24. this.splice(index, 1);
  25. }
  26. };
  27. $(document).ready(function()
  28. {
  29. //init();
  30. });
  31. function init()
  32. {
  33. editors = [];
  34. editors_index = [];
  35. select = '';
  36. edit();
  37. del();
  38. checkbox();
  39. image();
  40. change();
  41. autocomplete();
  42. template();
  43. submit();
  44. loadShow();
  45. initEditor();
  46. initPic();
  47. initDate();
  48. initLayui();
  49. initColor();
  50. //更新页面一些功能,上边的一些功能等找时间再优化吧
  51. dever_update.init();
  52. hljs.initHighlightingOnLoad();
  53. table();
  54. }
  55. function initLayui()
  56. {
  57. layui.use('layer', function() {
  58. var layer = layui.layer;
  59. layer.ready(function() {
  60. $(".dever-img").each(function()
  61. {
  62. layer.photos({
  63. photos: '#' + $(this).attr('id')
  64. });
  65. });
  66. });
  67. });
  68. }
  69. function initColor()
  70. {
  71. if ($('.dever-color').length) {
  72. $('.dever-color').each(function()
  73. {
  74. var self = $(this);
  75. var val = self.val();
  76. if (!val) {
  77. val = '#000000';
  78. }
  79. self.css('border-right', '40px solid '+val);
  80. self.colpick({
  81. layout:'hex',
  82. submit:0,
  83. colorScheme:'dark',
  84. color: val,
  85. onChange : function (hsb,hex,rgb,el,bySetColor) {
  86. $(el).css('border-color','#'+hex);
  87. if(!bySetColor) $(el).val('#' + hex);
  88. }
  89. }).keyup(function(){
  90. $(this).colpickSetColor(this.value);
  91. });
  92. })
  93. }
  94. }
  95. function formData(form)
  96. {
  97. var d = {};
  98. var t = $(form).serializeArray();
  99. var u = '';
  100. $.each(t, function() {
  101. if (this.name.indexOf('search_') != -1) {
  102. d[this.name] = this.value;
  103. u += '&' + this.name + '=' + this.value;
  104. }
  105. });
  106. return [d,u];
  107. }
  108. function initMenu()
  109. {
  110. if(typeof(config.layout) != "undefined")
  111. {
  112. $('.list-unstyled li').each(function(j)
  113. {
  114. $(this).unbind('click').bind('click', function()
  115. {
  116. if ($(this).index() == i) {
  117. //return;
  118. }
  119. $('.list-unstyled .active').each(function()
  120. {
  121. $(this).attr('class', '');
  122. $(this).find('a').attr('class', '');
  123. })
  124. $(this).attr('class', 'active');
  125. var a = $(this).find('a');
  126. a.attr('class', 'subdrop');
  127. //alert($(this).attr('class'));
  128. })
  129. });
  130. /*
  131. $('.project-list').each(function(i)
  132. {
  133. $(this).unbind('click').bind('click', function()
  134. {
  135. if ($(this).index() == i) {
  136. return;
  137. }
  138. $('.project-list').each(function()
  139. {
  140. $(this).find('i').parent().attr('class', '');
  141. $(this).find('ul').attr('class', 'list-unstyled upload-menu');
  142. })
  143. $(this).find('i').parent().attr('class', 'active');
  144. $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
  145. })
  146. });
  147. */
  148. }
  149. }
  150. function setOption(e, id)
  151. {
  152. var s = $("select[name="+id+"]");
  153. var v = s.val();
  154. if (!select) {
  155. select = s.clone();
  156. }
  157. s.find('option[parent]').remove();
  158. //查找出需要显示的option并复制
  159. var options = select.find("option[parent="+e.val()+"]").clone();
  160. //将需要显示的option添加到select中
  161. s.append(options);
  162. //因为option.remove()不会刷新控件,需要将新的option切换上去
  163. //这里排除了options.size() == 0的情况
  164. var state = 2;
  165. s.find('option').each(function()
  166. {
  167. var val = $(this).val();
  168. if (v == val) {
  169. state = 1;
  170. }
  171. });
  172. if (state == 1) {
  173. s.val(v);
  174. } else {
  175. s.val(0);
  176. }
  177. }
  178. function table()
  179. {
  180. if ($('.table-responsive').length) {
  181. $('.table-responsive[data-pattern]').each(function()
  182. {
  183. $(this).responsiveTable('update');
  184. });
  185. }
  186. }
  187. function pjax(param)
  188. {
  189. param.timeout = 8000;
  190. $.pjax(param);
  191. }
  192. function initDate()
  193. {
  194. $.datetimepicker.setLocale('ch');
  195. if($(".manage_time").length)
  196. {
  197. $(".manage_time").each(function()
  198. {
  199. $(this).datetimepicker(
  200. {
  201. //inline:true,
  202. timepicker:false,
  203. format:'Y-m-d',
  204. lang:'ch'
  205. });
  206. });
  207. }
  208. if($(".manage_date").length)
  209. {
  210. $(".manage_date").each(function()
  211. {
  212. $(this).datetimepicker(
  213. {
  214. //datepicker:false,
  215. format:'Y-m-d H:i:s',
  216. lang:'ch'
  217. });
  218. });
  219. }
  220. }
  221. function initPic()
  222. {
  223. $('a[rel]').fancybox();
  224. }
  225. function initEditor(e)
  226. {
  227. if (!e) {
  228. e = $('.editor');
  229. }
  230. if(e.length)
  231. {
  232. var param = false;
  233. var editor = [];
  234. e.each(function()
  235. {
  236. var parent = $(this).parent().parent();
  237. //alert(parent.attr('id'));
  238. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  239. {
  240. return;
  241. }
  242. if (!param) {
  243. param = loadEditorParam($(this));
  244. }
  245. editor.push($(this).attr('id'));
  246. });
  247. if (editor) {
  248. for (var i in editor) {
  249. var id = editor[i];
  250. if (typeof(id) == 'string' && !editors[id]) {
  251. param.index = editors_index.length;
  252. editors[id] = KindEditor.create('#' + id, param);
  253. editors_index.push(id);
  254. }
  255. }
  256. }
  257. }
  258. }
  259. function loadEditorParam(e)
  260. {
  261. if(!e.length)
  262. {
  263. return;
  264. }
  265. var key = e.attr('key');
  266. var param = {
  267. height : "500px",
  268. allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
  269. allowImageRemote : false, //上传图片框网络图片的功能,false为隐藏,默认为true
  270. allowFileManager : false, //浏览图片空间
  271. filterMode : true, //HTML特殊代码过滤
  272. themeType : 'default',
  273. filePostName : 'file',
  274. uploadJson : config.upload + '.kindeditor?key=' + key,
  275. //fileManagerJson : config.upload + '.kindeditorFile?key=' + key
  276. items : [
  277. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  278. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  279. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  280. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  281. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  282. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  283. 'anchor', 'link', 'unlink'
  284. ]
  285. /*
  286. items : [
  287. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  288. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  289. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  290. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  291. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  292. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  293. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  294. 'anchor', 'link', 'unlink', '|', 'about'
  295. ]
  296. */
  297. }
  298. return param;
  299. }
  300. //更新页面的提交按钮
  301. function submit()
  302. {
  303. if($(".save-data").length)
  304. {
  305. if (submitButton) {
  306. $(".save-data").each(function()
  307. {
  308. $(this).html(submitButton);
  309. })
  310. }
  311. $(".save-data").unbind('click').bind('click', function()
  312. {
  313. if (editors) {
  314. for (var i in editors) {
  315. if (i.indexOf('update_') != -1) {
  316. editors[i].sync();
  317. }
  318. }
  319. }
  320. //return;
  321. submitButton = $(this).html();
  322. $(this).html('loading...');
  323. $(this).unbind('click');
  324. submit_action();
  325. })
  326. }
  327. }
  328. //直接提交更新页的数据
  329. function submit_action()
  330. {
  331. $(".form1").submit();
  332. }
  333. //设置某一个input的值
  334. function set_update(id, value)
  335. {
  336. if($(id).length)
  337. {
  338. $(id).val(value);
  339. }
  340. }
  341. /**
  342. * 批量复制数据
  343. */
  344. function copy_data(e)
  345. {
  346. var html = '<div>';
  347. html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
  348. html += '</div>';
  349. $('#dever_modal_body').html(html);
  350. $('#dever_modal_title').html('复制数据');
  351. $("#dever_modal_yes").unbind('click').bind('click', function()
  352. {
  353. set_update('#copy_num', $("#temp_copy_num").val());
  354. set_update('#update_where_id', 0);
  355. submit_action();
  356. });
  357. }
  358. //头部菜单
  359. function topMenu(e)
  360. {
  361. var p = e.parent().parent().parent().find('span');
  362. p.html(e.html());
  363. //更新当前的精细权限
  364. var url = config.host + 'top.update_action?json=1';
  365. var id = e.attr('data-id');
  366. $.post(url, {id:id}, function(t)
  367. {
  368. var href = location.href;
  369. if(location.href.indexOf('where_id') != -1)
  370. {
  371. var temp = location.href.split('where_id');
  372. href = temp[0] + 'where_id=' + t;
  373. }
  374. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  375. {
  376. pjax({url: href, container: config.layout})
  377. }
  378. else
  379. {
  380. location.href = href;
  381. }
  382. })
  383. }
  384. //更新页面的批量载入选择
  385. function loadShow()
  386. {
  387. if($(".show_input").length)
  388. {
  389. $(".show_input input").each(function()
  390. {
  391. if($(this).attr('checked'))
  392. {
  393. inputShow($(this), $(this).attr('show_id'), 'input');
  394. }
  395. })
  396. $(".show_input select").each(function()
  397. {
  398. if($(this).find('option:selected').text())
  399. {
  400. inputShow($(this), $(this).attr('show_id'));
  401. }
  402. })
  403. }
  404. }
  405. function inputShow(e,n,t)
  406. {
  407. $(".show_" + n).hide();
  408. var array = ['input', 'textarea'];
  409. for(var a in array)
  410. {
  411. if ($(".show_" + n).find(array[a]).length) {
  412. var c = $(".show_" + n).find(array[a]).attr('class');
  413. if (c.indexOf('validate[required]') > -1) {
  414. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  415. }
  416. }
  417. }
  418. if (t == 'input') {
  419. var item = e.parent().find('input');
  420. item.each(function()
  421. {
  422. if($(this).get(0).checked == true)
  423. {
  424. inputShowOne($(this),n);
  425. }
  426. });
  427. } else {
  428. var item = e.parent().find('select');
  429. item.each(function()
  430. {
  431. if($(this).find('option:selected').text())
  432. {
  433. inputShowOne($(this),n);
  434. }
  435. });
  436. }
  437. }
  438. function inputShowOne(e,n)
  439. {
  440. var value = e.val();
  441. var ele = '.show_' + n + '_ajax';
  442. if ($(ele).length) {
  443. $(ele).each(function()
  444. {
  445. var self = $(this);
  446. var url = self.attr('dever-ajax');
  447. $.getJSON(url + value + '&callback=?', function(t) {
  448. self.find('.margin-top').html(t.data);
  449. inputShowOneValiDate(self);
  450. checkbox();
  451. })
  452. })
  453. } else {
  454. ele = '.show_' + n + '_' + value;
  455. inputShowOneValiDate($(ele));
  456. }
  457. }
  458. function inputShowOneValiDate(e)
  459. {
  460. e.show();
  461. var array = ['input', 'textarea'];
  462. for(var a in array)
  463. {
  464. if(e.length && e.attr('class').indexOf('show_no') == -1)
  465. {
  466. e.find(array[a]).each(function()
  467. {
  468. var parent = $(this).parent();
  469. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  470. {
  471. $(this).addClass('validate[required]');
  472. }
  473. })
  474. }
  475. }
  476. }
  477. //批量更新
  478. function list_mul(e)
  479. {
  480. var type = parseInt($("#mul_type").val());
  481. if(type != 1 && type != 2)
  482. {
  483. alert('您还没有选择数据更新方式');
  484. return;
  485. }
  486. layer.confirm('确定进行此项操作吗?', function()
  487. {
  488. $('#method').val('mul');
  489. $('#function').val('msg');
  490. $('#form1').attr('target', 'f1').submit();
  491. })
  492. }
  493. //搜索
  494. function list_search(e)
  495. {
  496. $('#method').val('search');
  497. $('#function').val('');
  498. $('#form1').attr('target', '').submit();
  499. }
  500. //更新数据
  501. function update(e, id, project, table, notice)
  502. {
  503. var call = function()
  504. {
  505. var col = e.attr('name').replace('up_col_', '');
  506. var value = e.val();
  507. var old = e.attr('data-old');
  508. var url = config.host + 'database.update_action?json=1';
  509. $.post(url, {where_id:id,col:col,value:value,project:project,table:table}, function(t)
  510. {
  511. var t = eval('('+t+')');
  512. if (t.status == 1) {
  513. e.attr('data-old', value);
  514. notify('操作已成功!您的操作已修改当前选项!');
  515. preview();
  516. } else {
  517. msg(t);
  518. e.val(old);
  519. }
  520. })
  521. }
  522. if(notice)
  523. {
  524. layer.confirm(notice, function()
  525. {
  526. call();
  527. });
  528. }
  529. else
  530. {
  531. call();
  532. }
  533. }
  534. function notify(msg)
  535. {
  536. var notice = new PNotify({
  537. title: '提示信息',
  538. text: msg,
  539. buttons: {
  540. closer: false,
  541. sticker: false
  542. }
  543. });
  544. notice.get().click(function() {
  545. notice.remove();
  546. });
  547. }
  548. //模板选择
  549. function template()
  550. {
  551. if(config.template)
  552. {
  553. $('body').attr('class', 'theme-' + config.template);
  554. }
  555. if($(".selector").length)
  556. {
  557. $(".selector").each(function()
  558. {
  559. if($(this).data('check') == 'checked')
  560. {
  561. selector($(this));
  562. }
  563. })
  564. }
  565. }
  566. //选择器
  567. function selector(e)
  568. {
  569. var value = e.data('value');
  570. var name = e.data('name');
  571. $('#'+name+'_value').val(value);
  572. $('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
  573. e.children().css({'border':'1px solid black'});
  574. if(name == 'update_template')
  575. {
  576. $('body').attr('class', 'theme-' + value);
  577. }
  578. }
  579. //根据e的值,来载入其他数据
  580. function loading(e, data)
  581. {
  582. var value = e.val();
  583. if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
  584. {
  585. var id = e.attr('id').replace('_temp', '');
  586. if($('#' + id).length)
  587. {
  588. var value = $('#' + id).val();
  589. }
  590. }
  591. if(data.element)
  592. {
  593. if(data.url)
  594. {
  595. data.value = value;
  596. $.getJSON(data.url, data, function(t)
  597. {
  598. $('#update_'+data.element+'_value').val(t.data);
  599. });
  600. }
  601. else
  602. {
  603. $('#update_'+data.element+'_value').val(value);
  604. }
  605. }
  606. else if(data.url)
  607. {
  608. data.value = value;
  609. data.where_id = $('#update_where_id').val();
  610. data.table = $('#table').val();
  611. data.project = $('#project').val();
  612. $.getJSON(data.url, data, function(s)
  613. {
  614. t = s.data;
  615. if(t.indexOf('onblur') != -1)
  616. {
  617. eval(t);
  618. }
  619. else
  620. {
  621. var parent = e.parent().parent();
  622. if(t.indexOf('status') == -1)
  623. {
  624. if(data.type == 1)
  625. {
  626. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  627. {
  628. $(this).remove();
  629. });
  630. }
  631. else
  632. {
  633. $('.checking_-1,.checking_3,.checking_4').each(function()
  634. {
  635. $(this).remove();
  636. });
  637. }
  638. parent.after(t);
  639. checkbox();
  640. }
  641. }
  642. });
  643. }
  644. }
  645. //根据e的值,来载入其他数据,先检测是否选中
  646. function checking(name, e, data)
  647. {
  648. var value = [];
  649. $('.' + name).each(function()
  650. {
  651. if($(this).get(0).checked == true)
  652. {
  653. value.push($(this).val());
  654. }
  655. });
  656. if(data.url)
  657. {
  658. data.value = value.join(',');
  659. data.where_id = $('#update_where_id').val();
  660. data.table = $('#table').val();
  661. data.project = $('#project').val();
  662. if(data.check)
  663. {
  664. data.check_value = false;
  665. $(data.check).each(function()
  666. {
  667. if($(this).get(0).checked == true)
  668. {
  669. data.check_value = $(this).val();
  670. }
  671. });
  672. }
  673. $.getJSON(data.url, data, function(s)
  674. {
  675. t = s.data;
  676. var parent = e.parent().parent().parent();
  677. if(t.indexOf('status') == -1)
  678. {
  679. if(data.type == 1)
  680. {
  681. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  682. {
  683. $(this).remove();
  684. });
  685. }
  686. else
  687. {
  688. $('.checking_-1,.checking_3,.checking_4').each(function()
  689. {
  690. $(this).remove();
  691. });
  692. }
  693. parent.after(t);
  694. checkbox();
  695. }
  696. });
  697. }
  698. }
  699. function autocomplete()
  700. {
  701. if ($("input").length) {
  702. $("input").each(function()
  703. {
  704. $(this).attr('autocomplete', 'new-password');
  705. });
  706. }
  707. if($("input[complete]").length)
  708. {
  709. $("input[complete]").each(function()
  710. {
  711. var cache = {};
  712. var self = $(this);
  713. self.autocomplete(
  714. {
  715. minLength: 2,
  716. source: function( request, response )
  717. {
  718. var term = request.term.split( /,\s*/ );
  719. request.term = term.pop();
  720. if ( request.term in cache ) {
  721. response( cache[ request.term ] );
  722. return;
  723. }
  724. var cate = self.attr('complete_cate');
  725. if (cate) {
  726. request[cate] = $('update_' + cate + '_value').val();
  727. }
  728. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  729. data = data.data
  730. cache[ term ] = data;
  731. var state = true;
  732. for(var i in data)
  733. {
  734. if(data[i].id <=0)
  735. {
  736. state = false;
  737. }
  738. }
  739. if(state)
  740. {
  741. response( data );
  742. }
  743. });
  744. },
  745. focus: function() {
  746. // prevent value inserted on focus
  747. return false;
  748. },
  749. select: function( event, ui )
  750. {
  751. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  752. var value = self.attr('complete_callback');
  753. var id = self.attr('id').replace('_temp', '');
  754. var name = self.attr('name').replace('_temp', '');
  755. //var e = $("#" + id);
  756. var e = self;
  757. var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
  758. if (!$("#" + id + '_show').length) {
  759. e.parent().append(html);
  760. }
  761. if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
  762. {
  763. var link = '';
  764. var attr = '';
  765. var pic = '';
  766. if (ui.item['pic']) {
  767. pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
  768. }
  769. if (ui.item['link']) {
  770. link = ui.item['link'];
  771. attr = ' target="_blank"';
  772. }
  773. var html = '<tr><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+ui.item[value]+'"/>&nbsp;&nbsp;'+pic+'<a href="'+link+'" '+attr+' title="'+ui.item.value+'">'+ui.item.value+'</td><td width="10%"><a href="javascript:;" onclick="autocomplete_del($(this), \''+id+'\', \''+ui.item[value]+'\', \''+name+'\')">[删除]</a></td></tr>';
  774. $("#" + id + '_show').append(html);
  775. if (!autocomplete_value[id]) {
  776. autocomplete_value[id] = [];
  777. }
  778. autocomplete_value[id].push(ui.item[value]);
  779. }
  780. ui.item.value = '';
  781. }
  782. });
  783. })
  784. }
  785. }
  786. function autocomplete_del(e, id, value)
  787. {
  788. e.parent().parent().remove();
  789. autocomplete_value[id].remove(value);
  790. var len = autocomplete_value.length;
  791. if (len < 1 && !($('#del_' + name).length)) {
  792. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  793. }
  794. }
  795. function searchbox(id, e)
  796. {
  797. var self = e.parent().find("input");
  798. var v = self.val();
  799. var key = self.attr('id').replace('_temp', '');
  800. var request = {};
  801. request.term = v;
  802. var cate = self.attr('searchbox_cate');
  803. if (cate) {
  804. var c = cate.split(',');
  805. for (var i in c) {
  806. if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
  807. request[c[i]] = $('#'+c[i]).val();
  808. }
  809. }
  810. }
  811. var index = layer.msg('加载中...');
  812. $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
  813. layer.close(index);
  814. var data = data.data;
  815. if (!data) {
  816. showAlert('没有搜索到数据');
  817. return;
  818. }
  819. var html = '<div class="layui-tab layui-tab-brief" style="width: 500px;" overflow><ul class="layui-tab-title" style="height: 60px; overflow: auto;">{cate}</ul><div class="layui-tab-content" style="padding-top: 0px;">{content}</div><div style="margin-left:10px"><input type="checkbox" onclick="searchbox_checkall($(this), \'searchbox_'+id+'\')"/>&nbsp;全选<button type="button" onclick="searchbox_yes(\''+self.attr('id')+'\', \'.searchbox_'+id+'\', true)" class="btn btn-primary layui-btn layuiadmin-btn-list" style="margin-left:10px;margin-top: -2px;"><i class="fa fa-save"></i> 确定</button></div></div>';
  820. if (data) {
  821. var j = 0;
  822. var c = '';
  823. var s = '';
  824. var cateHtml = '';
  825. var content = '';
  826. for (var i in data) {
  827. if (j == 0) {
  828. c = 'class="layui-this"';
  829. s = 'layui-show';
  830. } else {
  831. c = '';
  832. s = '';
  833. }
  834. cateHtml += '<li '+c+'>'+data[i].name+'</li>';
  835. j++;
  836. var item = '<div class="layui-tab-item '+s+'"><div style="margin-top: 10px;overflow: auto;max-height: 500px;"><table class="table table-small-font table-bordered">{head}';
  837. var p = false;
  838. for (var k in data[i].child) {
  839. if (data[i].child[k].name) {
  840. var pic = '';
  841. if (data[i].child[k].pic) {
  842. pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
  843. p = true;
  844. }
  845. var check = '';
  846. if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
  847. check = 'checked';
  848. }
  849. item += '<tr><td width="10%"><input '+check+' type="checkbox" onclick="searchbox_checkone($(this), \''+self.attr('id')+'\', \''+key+'\', '+data[i].child[k].id+', \''+key+'\')" class="searchbox_'+id+' searchbox_'+id+'_'+data[i].id+'" data-class="searchbox_'+id+'_'+data[i].id+'" data-pic="'+data[i].child[k].pic+'" data-name="'+data[i].child[k].name+'" data-value="'+data[i].child[k].id+'" data-link="'+data[i].child[k].link+'" value="'+data[i].child[k].id+'"/></td>'+pic+'<td><a href="" >'+data[i].child[k].name+'</td></tr>';
  850. }
  851. }
  852. item += '</table></div></div>';
  853. var head = '<tr><td width="10%"><input type="checkbox" class="searchbox_'+id+'" onclick="searchbox_checkall($(this), \'searchbox_'+id+'_'+data[i].id+'\')"/></td><td>标题</td></tr>';
  854. if (p) {
  855. head = head.replace('</td><td>', '</td><td>图片</td><td>');
  856. }
  857. item = item.replace('{head}', head);
  858. content += item;
  859. }
  860. if (cateHtml) {
  861. html = html.replace('{cate}', cateHtml);
  862. }
  863. if (content) {
  864. html = html.replace('{content}', content);
  865. }
  866. }
  867. var config = {
  868. type: 1,
  869. shade: 0.3,
  870. title : false,
  871. shadeClose : true,
  872. area : ['500px', 'auto'],
  873. content: html
  874. };
  875. layer.open(config);
  876. });
  877. }
  878. function searchbox_checkall(e, id)
  879. {
  880. $('.' + id).each(function()
  881. {
  882. $(this).get(0).checked = e.get(0).checked;
  883. //$(this).click();
  884. })
  885. }
  886. function searchbox_checkone(e, id, key, value)
  887. {
  888. if (!e.get(0).checked) {
  889. $('#searchbox_check_' + key + '_' + value).remove();
  890. searchbox_value.remove(value);
  891. var len = searchbox_value.length;
  892. var name = key.replace('_value', '');
  893. if (len < 1 && !($('#del_' + name).length)) {
  894. $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  895. }
  896. } else {
  897. var c = '.' + e.attr('data-class');
  898. searchbox_yes(id, c, false);
  899. }
  900. }
  901. function searchbox_yes(e, c, state)
  902. {
  903. var self = $("#" +e);
  904. $(c).each(function()
  905. {
  906. if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
  907. var value = self.attr('searchbox_callback');
  908. var id = self.attr('id').replace('_temp', '');
  909. var name = self.attr('name').replace('_temp', '');
  910. var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
  911. if (!$("#" + id + '_show').length) {
  912. e.parent().append(html);
  913. }
  914. if ($("#" + id + '_show').html().indexOf($(this).attr('data-name')) == -1)
  915. {
  916. var link = '';
  917. var attr = '';
  918. var pic = '';
  919. if ($(this).attr('data-pic')) {
  920. pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
  921. }
  922. if ($(this).attr('data-link')) {
  923. link = $(this).attr('data-link');
  924. attr = ' target="_blank"';
  925. }
  926. var html = '<tr id="searchbox_check_'+id+'_'+$(this).attr('data-value')+'"><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+$(this).attr('data-value')+'"/>&nbsp;&nbsp;'+pic+'<a href="'+link+'" '+attr+' title="'+$(this).attr('data-name')+'">'+$(this).attr('data-name')+'</td><td width="10%"><a href="javascript:;" onclick="searchbox_del($(this), \''+id+'\', \''+$(this).attr('data-value')+'\', \''+name+'\')">[删除]</a></td></tr>';
  927. $("#" + id + '_show').append(html);
  928. if (!searchbox_value[id]) {
  929. searchbox_value[id] = [];
  930. }
  931. searchbox_value[id].push($(this).attr('data-value'));
  932. }
  933. }
  934. })
  935. if (state == true) {
  936. layer.closeAll();
  937. }
  938. }
  939. function searchbox_del(e, id, value, name)
  940. {
  941. e.parent().parent().remove();
  942. searchbox_value.remove(value);
  943. var len = searchbox_value.length;
  944. if (len < 1 && !($('#del_' + name).length)) {
  945. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  946. }
  947. }
  948. //后台通用的提示
  949. function msg(value)
  950. {
  951. $("#dever_modal_no").click();
  952. if(!value.data)
  953. {
  954. value.data = value.msg;
  955. }
  956. if(value == 1)
  957. {
  958. location.reload();
  959. return;
  960. }
  961. submit();
  962. var url = '';
  963. if(value.data != 'reload' && value.status == 2)
  964. {
  965. showAlert(value.msg, false, '错误提示');
  966. //alert(value.data);
  967. //location.reload();
  968. return;
  969. }
  970. else if(value.data == 'reload')
  971. {
  972. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  973. {
  974. pjax({url: location.href, container: config.layout})
  975. }
  976. else
  977. {
  978. location.reload();
  979. }
  980. return;
  981. }
  982. else
  983. {
  984. if(value.data.indexOf('http://') != -1)
  985. {
  986. url = value.data;
  987. }
  988. else if($("#url").length)
  989. {
  990. url = $("#url").val();
  991. }
  992. else
  993. {
  994. notify(value.data)
  995. return;
  996. }
  997. if(url)
  998. {
  999. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1000. {
  1001. pjax({url: url, container: config.layout});
  1002. }
  1003. else
  1004. {
  1005. location.href = url;
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1011. {
  1012. pjax({url: location.href, container: config.layout});
  1013. }
  1014. else
  1015. {
  1016. location.reload();
  1017. }
  1018. }
  1019. }
  1020. return;
  1021. }
  1022. /**
  1023. * 处理多选问题,处理全选按钮
  1024. */
  1025. function checkbox()
  1026. {
  1027. if($(".autoload").length)
  1028. {
  1029. $(".autoload").each(function()
  1030. {
  1031. if($(this).get(0).checked == true)
  1032. {
  1033. $(this).removeClass('autoload');
  1034. $(this).load();
  1035. }
  1036. });
  1037. }
  1038. if($(".autoload_text").length)
  1039. {
  1040. $(".autoload_text").each(function()
  1041. {
  1042. if($(this).val())
  1043. {
  1044. $(this).removeClass('autoload_text');
  1045. $(this).load();
  1046. }
  1047. });
  1048. }
  1049. var name = 'checkbox-checkall';
  1050. var checkbox = $("." + name);
  1051. if(checkbox.length)
  1052. {
  1053. checkbox.unbind('click').bind('click', function()
  1054. {
  1055. var self = $(this);
  1056. $("." + name + "-" + self.val()).each(function()
  1057. {
  1058. $(this).get(0).checked = self.get(0).checked;
  1059. var next = $(this).next();
  1060. if($(this).get(0).checked == true)
  1061. {
  1062. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1063. {
  1064. next.attr('disabled', false);
  1065. }
  1066. if($("#mul_type").length)
  1067. {
  1068. $("#mul_type").val(1);
  1069. }
  1070. }
  1071. else
  1072. {
  1073. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1074. {
  1075. next.attr('disabled', true);
  1076. }
  1077. if($("#mul_type").length)
  1078. {
  1079. $("#mul_type").val(0);
  1080. }
  1081. }
  1082. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1083. inputShow($(this), 'col');
  1084. }
  1085. })
  1086. });
  1087. checkbox.each(function()
  1088. {
  1089. var self = $(this);
  1090. var len = $("." + name + "-" + self.val()).length;
  1091. $("." + name + "-" + self.val()).each(function()
  1092. {
  1093. $(this).unbind('click').bind('click', function()
  1094. {
  1095. var next = $(this).next();
  1096. if($(this).get(0).checked == true)
  1097. {
  1098. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1099. self.get(0).checked = true;
  1100. }
  1101. if(self.attr('type') == 'radio')
  1102. {
  1103. //如果父选项是radio类型,做下限制
  1104. //alert(1);
  1105. }
  1106. if($("#mul_type").length)
  1107. {
  1108. $("#mul_type").val(1);
  1109. }
  1110. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1111. {
  1112. next.attr('disabled', false);
  1113. }
  1114. }
  1115. else
  1116. {
  1117. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1118. {
  1119. next.attr('disabled', true);
  1120. }
  1121. }
  1122. var num = 0;
  1123. $("." + name + "-" + self.val()).each(function()
  1124. {
  1125. if($(this).get(0).checked == true)
  1126. {
  1127. num = 1;
  1128. }
  1129. });
  1130. var id = $(this).attr('name');
  1131. var hidden = id;
  1132. id = id.replace('[]', '');
  1133. if(num == 0)
  1134. {
  1135. self.get(0).checked = false;
  1136. if($("#mul_type").length)
  1137. {
  1138. $("#mul_type").val(0);
  1139. }
  1140. if (!$('#' + id).length) {
  1141. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  1142. }
  1143. } else {
  1144. if ($('#' + id).length) {
  1145. $('#' + id).remove();
  1146. }
  1147. }
  1148. })
  1149. if($(this).get(0).checked == true)
  1150. {
  1151. self.get(0).checked = true;
  1152. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1153. inputShow($(this), 'col');
  1154. }
  1155. }
  1156. });
  1157. })
  1158. }
  1159. }
  1160. /**
  1161. * 处理双击编辑
  1162. */
  1163. function edit()
  1164. {
  1165. if($(".edit").length)
  1166. {
  1167. $(".edit").each(function()
  1168. {
  1169. $(this).bind('dblclick', function()
  1170. {
  1171. var col = $(this).attr('data-col');
  1172. var project = $(this).attr('data-project');
  1173. var table = $(this).attr('data-table');
  1174. var url = $(this).attr('data-url');
  1175. var id = $(this).attr('data-id');
  1176. var html = $(this).attr('data-content');
  1177. var type = $(this).attr('data-type');
  1178. if($(this).find(".edit-content").length)
  1179. {
  1180. html = $(this).find(".edit-content").html();
  1181. html = html.replace('<!--', '<');
  1182. html = html.replace('-->', '>');
  1183. }
  1184. if(html.indexOf('input') == -1)
  1185. {
  1186. if(type && type == 'textarea')
  1187. {
  1188. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1189. }
  1190. else
  1191. {
  1192. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1193. }
  1194. var self = $(this);
  1195. self.find("#edit").blur(function()
  1196. {
  1197. var value = self.find("#edit").val();
  1198. if(!value)
  1199. {
  1200. alert('不能为空');
  1201. return;
  1202. }
  1203. if($(this).find(".edit-content").length)
  1204. {
  1205. $(this).find(".edit-content").html(value);
  1206. }
  1207. else
  1208. {
  1209. self.attr('data-content', value);
  1210. }
  1211. self.html(value);
  1212. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1213. {
  1214. notify('修改成功');
  1215. preview();
  1216. /*
  1217. if(type && type == 'textarea')
  1218. {
  1219. self.html(t);
  1220. }
  1221. */
  1222. })
  1223. })
  1224. }
  1225. });
  1226. })
  1227. }
  1228. }
  1229. function preview()
  1230. {
  1231. if($("#preview").length)
  1232. {
  1233. var time = Date.parse(new Date());
  1234. var src = $('#preview').attr('src').split('#');
  1235. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1236. }
  1237. }
  1238. function del()
  1239. {
  1240. if($(".oper_delete").length)
  1241. {
  1242. $(".oper_delete").each(function()
  1243. {
  1244. var href = $(this).attr('href');
  1245. $(this).attr('href', '#');
  1246. $(this).unbind('click');
  1247. $(this).bind('click', function()
  1248. {
  1249. del_act(href);
  1250. });
  1251. })
  1252. }
  1253. }
  1254. /**
  1255. * 处理删除
  1256. */
  1257. function del_act(href)
  1258. {
  1259. layer.confirm('确定进行此项操作吗?', function()
  1260. {
  1261. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1262. {
  1263. msg(t);
  1264. })
  1265. });
  1266. }
  1267. /**
  1268. * 处理特殊加载的按钮
  1269. */
  1270. function load(href)
  1271. {
  1272. layer.confirm('确定进行此项操作吗?', function()
  1273. {
  1274. if(href.indexOf('&') == -1)
  1275. {
  1276. href += '?json=1&callback=?';
  1277. }
  1278. else
  1279. {
  1280. href += '&json=1&callback=?';
  1281. }
  1282. $.getJSON(href, {}, function(t)
  1283. {
  1284. msg(t);
  1285. //location.reload();
  1286. })
  1287. })
  1288. /*
  1289. showAlert('确定进行此项操作吗?', function()
  1290. {
  1291. $("#dever_modal_no").click();
  1292. $.getJSON(href + '&json=1', {}, function(t)
  1293. {
  1294. msg(t);
  1295. })
  1296. });
  1297. */
  1298. }
  1299. /**
  1300. * 处理特殊加载的按钮
  1301. */
  1302. function jump(href, form)
  1303. {
  1304. if (form) {
  1305. var param = formData(form);
  1306. href += param[1];
  1307. }
  1308. location.href = href;
  1309. }
  1310. /**
  1311. * 处理change
  1312. */
  1313. function change()
  1314. {
  1315. if($(".change").length)
  1316. {
  1317. $(".change").each(function()
  1318. {
  1319. var key = $(this).attr('data-child');
  1320. /*
  1321. $('.' + key).each(function()
  1322. {
  1323. if($(this).find('select option:selected').val())
  1324. {
  1325. $(this).show();
  1326. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1327. }
  1328. });
  1329. */
  1330. $(this).change(function()
  1331. {
  1332. $('.' + key).hide();
  1333. var v = $('.' + key + '_' + $(this).val());
  1334. var s = v.find('select');
  1335. s.change(function()
  1336. {
  1337. $('.' + key + '_value').val($(this).val());
  1338. })
  1339. if(v.length)
  1340. {
  1341. $('.' + key + '_value').val(s.val());
  1342. v.show();
  1343. }
  1344. else
  1345. {
  1346. $('.' + key + '_value').val(-1);
  1347. }
  1348. });
  1349. if($(this).val() > 0)
  1350. {
  1351. $(this).change();
  1352. }
  1353. });
  1354. }
  1355. }
  1356. /**
  1357. * 处理图库系统
  1358. */
  1359. function image()
  1360. {
  1361. if($(".dever-note").length)
  1362. {
  1363. $(".dever-note").each(function()
  1364. {
  1365. var key = $(this).attr('key');
  1366. $(this).inlineattachment(
  1367. {
  1368. uploadUrl: config.upload + '.drag?key='+ key
  1369. });
  1370. });
  1371. }
  1372. if($(".image_upload").length)
  1373. {
  1374. $(".image_upload").each(function(i)
  1375. {
  1376. var parent = $(this).parent().parent();
  1377. //alert(parent.attr('id'));
  1378. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1379. {
  1380. return;
  1381. }
  1382. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1383. })
  1384. }
  1385. }
  1386. /**
  1387. * 修改密码
  1388. */
  1389. function pass(e)
  1390. {
  1391. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1392. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  1393. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  1394. html += '</div>';
  1395. var edit = function()
  1396. {
  1397. var old_password = $("#edit_old_password").val();
  1398. var new_password = $("#edit_new_password").val();
  1399. if(!old_password || !new_password)
  1400. {
  1401. alert('请输入密码');
  1402. return;
  1403. }
  1404. if(old_password == new_password)
  1405. {
  1406. alert('旧密码和新密码相同');
  1407. return;
  1408. }
  1409. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1410. {
  1411. alert(t);
  1412. })
  1413. };
  1414. showAlert(html, edit, '修改密码');
  1415. /*
  1416. $('#dever_modal_body').html(html);
  1417. $('#dever_modal_title').html('修改密码');
  1418. */
  1419. }
  1420. var MSG = [];
  1421. /**
  1422. * 打开弹窗
  1423. */
  1424. //function showMsg(title, e, id, func)
  1425. function showMsg(title, e, id, func, param)
  1426. {
  1427. if(id.indexOf('http://') == -1)
  1428. {
  1429. if($(id).length)
  1430. {
  1431. var html = $(id).html();
  1432. if($(id).html())
  1433. {
  1434. var html = $(id).html();
  1435. MSG[id] = html;
  1436. $(id).html('');
  1437. }
  1438. else
  1439. {
  1440. var html = MSG[id];
  1441. }
  1442. }
  1443. else
  1444. {
  1445. var html = id;
  1446. }
  1447. showAlert(html, func, title);
  1448. /*
  1449. $('#dever_modal_body').html(html);
  1450. $('#dever_modal_title').html(title);
  1451. if (func) {
  1452. $("#dever_modal_yes").unbind('click').bind('click', func);
  1453. } else {
  1454. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  1455. }
  1456. */
  1457. }
  1458. else
  1459. {
  1460. var url = id;
  1461. var send = {};
  1462. if (param) {
  1463. send = param;
  1464. }
  1465. if (e && e.attr('msg-send')) {
  1466. send.data = e.attr('msg-send');
  1467. }
  1468. if (url.indexOf('?') != -1) {
  1469. url = url + '&';
  1470. } else {
  1471. url = url + '?';
  1472. }
  1473. $.getJSON(url+'json=1',send,function(t)
  1474. {
  1475. t = t.data;
  1476. showAlert(t, func, t);
  1477. /*
  1478. $('#dever_modal_body').html(t);
  1479. $('#dever_modal_title').html(title);
  1480. if(func)
  1481. {
  1482. $("#dever_modal_yes").unbind('click').bind('click', func);
  1483. }
  1484. */
  1485. });
  1486. }
  1487. }
  1488. function updateMsg(id)
  1489. {
  1490. $("#"+id).submit();
  1491. }
  1492. function showAlert(msg, func, title)
  1493. {
  1494. if (!title) {
  1495. title = $("#dever-name").html() + '提醒您';
  1496. }
  1497. var type = 0;
  1498. if (msg.indexOf('<') != -1) {
  1499. type = 1;
  1500. }
  1501. var config = {
  1502. type: 0,
  1503. title: title,
  1504. shade: 0,
  1505. shadeClose : true,
  1506. content: msg
  1507. };
  1508. if (type == 1) {
  1509. config.area = '500px';
  1510. }
  1511. if (func) {
  1512. config.yes = function()
  1513. {
  1514. func();
  1515. };
  1516. }
  1517. layer.open(config);
  1518. }
  1519. function fastEdit(e, url, title, col)
  1520. {
  1521. var func = function()
  1522. {
  1523. submit_action();
  1524. };
  1525. var send = {};
  1526. send.col = col;
  1527. $.get(url,send,function(t)
  1528. {
  1529. var html = $(t).find('form').prop("outerHTML");
  1530. var valid = $(t).find('#valid').prop("outerHTML");
  1531. html = html + valid;
  1532. showAlert(html, func, title);
  1533. $('#update_button').hide();
  1534. init();
  1535. });
  1536. }
  1537. /*
  1538. var test =
  1539. {
  1540. refreshPage: false,
  1541. addAjaxFlag: true,
  1542. //添加收藏
  1543. add: function(cfg)
  1544. {
  1545. }
  1546. }
  1547. */
  1548. function showToggle(e)
  1549. {
  1550. var id = e.attr('toggle');
  1551. var child = e.attr('toggle_child');
  1552. var parent = e.parent();
  1553. parent.parent().find('li').removeClass('active');
  1554. parent.addClass('active');
  1555. $(child).fadeOut(100);
  1556. $(id).fadeIn(500);
  1557. initEditor($(id).find('.editor'));
  1558. }
  1559. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param)
  1560. {
  1561. var e = '#' + id;
  1562. var parent = value.split(',');
  1563. var cur = parent[0];
  1564. parent.remove(cur);
  1565. value = parent.join(',');
  1566. var html = '';
  1567. var old = level;
  1568. if (!total) {
  1569. level_id = 0;
  1570. } else {
  1571. if (level >= total) {
  1572. //$(e).show();
  1573. return;
  1574. }
  1575. level_id = $(e + '_' + level).val();
  1576. level = parseInt(level) + 1;
  1577. }
  1578. $.getJSON(url + '?json=1', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  1579. var check = '';
  1580. if (t.status == 1) {
  1581. var total = t.data.level_total;
  1582. var data = t.data.list;
  1583. if(!$(e + '_' + level).length) {
  1584. html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\');">';
  1585. }
  1586. for (a in data) {
  1587. if (data[a].value) {
  1588. check = '';
  1589. if (cur == data[a].value) {
  1590. check = ' selected';
  1591. }
  1592. html += '<option value="'+data[a].value+'" '+check+'>'+data[a].name+'</option>';
  1593. }
  1594. }
  1595. if(!$(e + '_' + level).length) {
  1596. html += '</select><span>&nbsp;&nbsp;</span>';
  1597. $(e).append(html);
  1598. $(e + '_' + level).change();
  1599. } else {
  1600. $(e + '_' + level).html(html);
  1601. $(e + '_' + level).change();
  1602. }
  1603. } else {
  1604. $(e + '_' + old).nextAll('select').remove();
  1605. $(e + '_' + old).next('span').nextAll('span').remove();
  1606. }
  1607. /*
  1608. if ($('#' + name + '_level_value').length) {
  1609. var total = $(id).find('select').length;
  1610. $('#' + name + '_level_value').val(total);
  1611. }
  1612. if ($('#' + name + '_up_value').length) {
  1613. $('#' + name + '_up_value').val($(id + '_-2').val());
  1614. }
  1615. */
  1616. });
  1617. }
  1618. /*
  1619. function select_mul(level, id, url, name, value, valid, w, num)
  1620. {
  1621. if(level == 0)
  1622. {
  1623. $(id).find('select').remove();
  1624. $(id).find('span').remove();
  1625. return;
  1626. }
  1627. var parent = value.split(',');
  1628. var cur = parent[0];
  1629. parent.remove(cur);
  1630. value = parent.join(',');
  1631. var html = '';
  1632. var old = level;
  1633. if(level != -1)
  1634. {
  1635. if($(id + '_' + level).length)
  1636. {
  1637. level = $(id + '_' + level).val();
  1638. }
  1639. alert(level);
  1640. if(level == 0)
  1641. {
  1642. $(id + '_' + old).nextAll('select').remove();
  1643. $(id + '_' + old).next('span').nextAll('span').remove();
  1644. if($('#' + name + '_level_value').length)
  1645. {
  1646. var total = $(id).find('select').length;
  1647. $('#' + name + '_level_value').val(total);
  1648. }
  1649. if(old == -2 && $('#' + name + '_value_value').length)
  1650. {
  1651. $('#' + name + '_value_value').val(level);
  1652. }
  1653. return;
  1654. }
  1655. if(old == -2)
  1656. {
  1657. $(id + '_' + old).nextAll('select').remove();
  1658. $(id + '_' + old).next('span').nextAll('span').remove();
  1659. }
  1660. if($('#' + name + '_value_value').length)
  1661. {
  1662. $('#' + name + '_value_value').val(level);
  1663. }
  1664. }
  1665. var total = $(id).find('select').length;
  1666. if(num > 0 && total >= num)
  1667. {
  1668. return;
  1669. }
  1670. var get = url.replace('{level}', level);
  1671. if(level == -1)
  1672. {
  1673. level = -2;
  1674. }
  1675. if(!$(id + '_' + level).length)
  1676. {
  1677. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  1678. {
  1679. var check = '';
  1680. if(t.status == 1)
  1681. {
  1682. html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+' dever-mul-'+name+'_'+level+'" name="'+name+'[]" onchange="select_mul(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+num+');">';
  1683. console.log(t.data);
  1684. for(a in t.data)
  1685. {
  1686. if(t.data[a].value)
  1687. {
  1688. check = '';
  1689. if(cur == t.data[a].value)
  1690. {
  1691. check = ' selected';
  1692. }
  1693. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  1694. }
  1695. }
  1696. html += '</select><span>&nbsp;&nbsp;</span>';
  1697. $(id).append(html);
  1698. $(id + '_' + level).change();
  1699. }
  1700. else
  1701. {
  1702. $(id + '_' + old).nextAll('select').remove();
  1703. $(id + '_' + old).next('span').nextAll('span').remove();
  1704. }
  1705. if($('#' + name + '_level_value').length)
  1706. {
  1707. var total = $(id).find('select').length;
  1708. $('#' + name + '_level_value').val(total);
  1709. }
  1710. if($('#' + name + '_up_value').length)
  1711. {
  1712. $('#' + name + '_up_value').val($(id + '_-2').val());
  1713. }
  1714. });
  1715. }
  1716. }
  1717. */
  1718. //处理更新页面的一些功能,写到一起吧
  1719. var dever_update =
  1720. {
  1721. addIndex : 2,
  1722. index : [],
  1723. auto : false,
  1724. save_key : '',
  1725. init : function()
  1726. {
  1727. var self = this;
  1728. self.index = [];
  1729. // 增加整个更新的表单
  1730. if($(".dever_update_add").length)
  1731. {
  1732. $('.dever_update_add').unbind('click').bind('click', function()
  1733. {
  1734. self.add($(this));
  1735. })
  1736. }
  1737. /* 以后再增加 同时更新另外一个表
  1738. if($(".form-add-content").length)
  1739. {
  1740. var url = config.host + 'auth.password';
  1741. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  1742. $.get(url, function(t)
  1743. {
  1744. $(".form-add-content").html(t);
  1745. init();
  1746. })
  1747. }
  1748. */
  1749. //增加某一部分表单
  1750. if($(".dever_form_add").length)
  1751. {
  1752. $('.dever_form_add').each(function()
  1753. {
  1754. var key = $.attr('toggle_key');
  1755. if(typeof(self.index[key]) == "undefined")
  1756. {
  1757. self.index[key] = 0;
  1758. }
  1759. $(this).unbind('click').bind('click', function()
  1760. {
  1761. self.append($(this));
  1762. })
  1763. })
  1764. self.del();
  1765. }
  1766. // 开启自动保存
  1767. if($("#struct").length)
  1768. {
  1769. var save = $("#struct").attr('save');
  1770. if(save == 'yes')
  1771. {
  1772. //检测
  1773. self.save_key = location.href + 'test';
  1774. self.check();
  1775. }
  1776. }
  1777. if($('.dever-note').length)
  1778. {
  1779. $('.dever-note').each(function()
  1780. {
  1781. var mditor = new Mditor($(this),{
  1782. fixedHeight:true
  1783. });
  1784. mditor.openPreview();
  1785. })
  1786. }
  1787. },
  1788. save : function()
  1789. {
  1790. //var data = $("#data-1").html();
  1791. var data = [];
  1792. $(".update_value").each(function(i)
  1793. {
  1794. if($(this).attr("update_type") == 'checked')
  1795. {
  1796. data[i] = $(this).get(0).checked;
  1797. }
  1798. else if($(this).attr("update_type") == 'html')
  1799. {
  1800. data[i] = $(this).html();
  1801. }
  1802. else if($(this).attr("update_type") == 'src')
  1803. {
  1804. data[i] = $(this).attr('src');
  1805. }
  1806. else
  1807. {
  1808. data[i] = $(this).val();
  1809. }
  1810. });
  1811. store.set(this.save_key, data.join('|||'));
  1812. //console.info(data);
  1813. },
  1814. recover : function()
  1815. {
  1816. layer.confirm('确定恢复上次保存的数据吗?', function()
  1817. {
  1818. var data = store.get(this.save_key).split('|||');
  1819. if(data)
  1820. {
  1821. var value = $(".update_value");
  1822. for(var k in data)
  1823. {
  1824. var e = value.eq(k);
  1825. if(e.attr('update_type') == 'checked')
  1826. {
  1827. if(data[k] == 'true')
  1828. {
  1829. e.get(0).checked = true;
  1830. }
  1831. else
  1832. {
  1833. e.get(0).checked = false;
  1834. }
  1835. }
  1836. else if(e.attr('update_type') == 'html')
  1837. {
  1838. e.html(data[k]);
  1839. }
  1840. else if(e.attr('update_type') == 'src')
  1841. {
  1842. e.attr('src', data[k]);
  1843. }
  1844. else
  1845. {
  1846. if(e.attr('id'))
  1847. {
  1848. var id = e.attr('id');
  1849. if(typeof(editors[id]) != "undefined")
  1850. {
  1851. editors[id].html(data[k]);
  1852. }
  1853. }
  1854. e.val(data[k]);
  1855. }
  1856. }
  1857. store.set(this.save_key, '');
  1858. this.check();
  1859. }
  1860. })
  1861. },
  1862. check : function()
  1863. {
  1864. var data = store.get(this.save_key);
  1865. var self = this;
  1866. if(data)
  1867. {
  1868. $(".dever_save").unbind('click').bind('click', function()
  1869. {
  1870. self.recover();
  1871. }).show();
  1872. }
  1873. else
  1874. {
  1875. $(".dever_save").hide();
  1876. self.auto = setInterval(function(){self.save()}, 3000);
  1877. }
  1878. },
  1879. del : function()
  1880. {
  1881. var self = this;
  1882. if($(".dever_form_delete").length)
  1883. {
  1884. $('.dever_form_delete').each(function()
  1885. {
  1886. $(this).unbind('click').bind('click', function()
  1887. {
  1888. var parent = $(this).parent();
  1889. var id = parent.attr('id');
  1890. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  1891. var key = $('#tab-' + id).attr('toggle_key');
  1892. if(index <= 1 && self.index[key] <= index)
  1893. {
  1894. }
  1895. else if(index <= 1 && self.index[key] > index)
  1896. {
  1897. index = index+1;
  1898. $("#tab-"+key+"-child-" + index).click();
  1899. }
  1900. else
  1901. {
  1902. index = index-1;
  1903. $("#tab-"+key+"-child-" + index).click();
  1904. };
  1905. $('#tab-' + id).parent().remove();
  1906. parent.remove();
  1907. self.index[key]--;
  1908. })
  1909. })
  1910. }
  1911. },
  1912. append : function(e)
  1913. {
  1914. var self = this;
  1915. var key = e.attr('toggle_key');
  1916. var child = '.dever_'+key+'_child';
  1917. if(typeof(self.index[key]) == "undefined")
  1918. {
  1919. self.index[key] = 0;
  1920. }
  1921. if(self.index[key] <= 0)
  1922. {
  1923. self.index[key] = $(child).length;
  1924. }
  1925. if(self.index[key] > 30)
  1926. {
  1927. layer.showAlert('最多只能增加30条');
  1928. return;
  1929. }
  1930. var p = e.parent();
  1931. var id = key + '-child-' + self.index[key];
  1932. var name = '第' + (self.index[key]) + '条';
  1933. p.before('<li><a href="javascript:;" id="tab-'+id+'" toggle_key="'+key+'" toggle_id="'+self.index[key]+'" toggle_child="'+child+'" toggle="#'+id+'" onclick="showToggle($(this))">'+name+'</a></li>');
  1934. var e = e.parent().parent();
  1935. var n = e.next();
  1936. var p = e.parent();
  1937. var content = n.html();
  1938. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  1939. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  1940. p.append(content);
  1941. if ($("#" + id).find('.ke-container').length >= 1) {
  1942. $("#" + id).find('.ke-container').eq(0).remove();
  1943. }
  1944. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  1945. self.del();
  1946. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  1947. self.index[key]++;
  1948. image();
  1949. loadShow();
  1950. autocomplete();
  1951. change();
  1952. },
  1953. add : function(e)
  1954. {
  1955. var self = this;
  1956. var p = e.parent();
  1957. var id = 'data-' + this.addIndex;
  1958. var name = '新增数据-' + (this.addIndex-1);
  1959. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  1960. var content = $("#content").find('.tab-pane').eq(0).html();
  1961. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  1962. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  1963. $("#content").append(content);
  1964. $('#update_' + this.addIndex + '__where_id').val('-1');
  1965. this.addIndex++;
  1966. }
  1967. }
  1968. $.fn.pasteEvents = function( delay ) {
  1969. if (delay == undefined) delay = 20;
  1970. return $(this).each(function() {
  1971. var $el = $(this);
  1972. $el.on("paste", function() {
  1973. $el.trigger("prepaste");
  1974. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  1975. });
  1976. });
  1977. };
  1978. $("textarea").on("postpaste", function()
  1979. {
  1980. if($(this).val().indexOf('<') != -1)
  1981. {
  1982. $(this).val(toMarkdown($(this).val()));
  1983. }
  1984. }).pasteEvents();