main.js 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444
  1. //这里的代码是最早写的,很乱,以后整合优化
  2. var editors = [];
  3. var editors_index = [];
  4. var tables = [];
  5. var select = '';
  6. var submitButton = '';
  7. var editorWidth = 0;
  8. var admingroup = false;
  9. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  10. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  11. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  12. } else {
  13. return this.replace(reallyDo, replaceWith);
  14. }
  15. }
  16. Array.prototype.remove = function(val) {
  17. var index = -1;
  18. for(var i = 0; i < this.length; i++)
  19. {
  20. if(this[i] == val)
  21. {
  22. index = i;
  23. }
  24. }
  25. if (index > -1) {
  26. this.splice(index, 1);
  27. }
  28. };
  29. Array.prototype.replaceOne = function(old, val) {
  30. var index = -1;
  31. for(var i = 0; i < this.length; i++)
  32. {
  33. if(this[i] == old)
  34. {
  35. index = i;
  36. }
  37. }
  38. if (index > -1) {
  39. this.splice(index, 1, val);
  40. }
  41. };
  42. $(document).ready(function()
  43. {
  44. //init();
  45. });
  46. function init(ew)
  47. {
  48. if (ew) {
  49. editorWidth = ew;
  50. } else {
  51. editorWidth = 0;
  52. }
  53. editors = [];
  54. editors_index = [];
  55. initEditor();
  56. select = '';
  57. edit();
  58. del();
  59. checkbox();
  60. image();
  61. change();
  62. autocomplete();
  63. template();
  64. submit();
  65. loadShow();
  66. initPic();
  67. initDate();
  68. initLayui();
  69. initColor();
  70. initUpdate();
  71. initClipboard();
  72. initEmoji();
  73. initSearch();
  74. //更新页面一些功能,上边的一些功能等找时间再优化吧
  75. dever_update.init();
  76. hljs.initHighlightingOnLoad();
  77. table();
  78. }
  79. function initSearch()
  80. {
  81. $("#form1 input").bind('keypress', function (event) {
  82. if (event.keyCode == 13) {
  83. $("#search_button").click();
  84. }
  85. });
  86. }
  87. function initEmoji()
  88. {
  89. if ($('.dever-emoji').length) {
  90. $('.dever-emoji').each(function()
  91. {
  92. emoji($(this), $(this).html());
  93. })
  94. }
  95. }
  96. function emoji(e, content)
  97. {
  98. var handle = function()
  99. {
  100. e.html(twemoji.parse(content)).show(200);
  101. };
  102. if (typeof jEmoji != 'object') {
  103. $.getScript('//twemoji.maxcdn.com/2/twemoji.min.js?11.4', function() {
  104. /*
  105. $("head").append("<link>");
  106. var css = $("head").children(":last");
  107. css.attr({
  108. rel: "stylesheet",
  109. type: "text/css",
  110. href: config.script + '/lib/emoji/emoji.css'
  111. });
  112. */
  113. return handle();
  114. });
  115. } else {
  116. return handle();
  117. }
  118. }
  119. function checkClick(e)
  120. {
  121. var objEvt = $._data(e[0], "events");
  122. if (objEvt && !objEvt["click"]) {
  123. return false;
  124. }
  125. return true;
  126. }
  127. function initClipboard()
  128. {
  129. var clipboard = new ClipboardJS('.clipboard');
  130. clipboard.on('success', function(e) {
  131. notify('复制成功', e.trigger);
  132. e.clearSelection();
  133. });
  134. clipboard.on('error', function(e) {
  135. notify('复制失败', e.trigger);
  136. });
  137. }
  138. function initUpdate()
  139. {
  140. if ($('.update_show_editor').length) {
  141. $('.update_show_editor').each(function() {
  142. $(this).bind('click', function()
  143. {
  144. var url = $(this).attr('key');
  145. var value = $(this).attr('editor_id');
  146. var title = $(this).attr('value');
  147. var send = '';
  148. if ($(this).attr('data-value')) {
  149. send = $(this).attr('data-value');
  150. }
  151. $.post(url, {value:send}, function(t)
  152. {
  153. var func = function() {
  154. var url = $('#editor_applet_pic').val();
  155. var appid = $('#editor_applet_id').val();
  156. var path = $('#editor_applet_path').val();
  157. var link = $('#editor_applet_link').val();
  158. if (!appid) {
  159. //alert('请选择小程序');
  160. //return;
  161. }
  162. if (!path) {
  163. alert('请填写路径');
  164. return;
  165. }
  166. if (!url) {
  167. alert('请上传封面');
  168. return;
  169. }
  170. var w = 750/2;
  171. KindEditor.insertHtml('#' + value, '<img src="'+url+'" style="width:'+w+'px;" data-applet="'+url+'||'+appid+'||'+path+'||'+link+'"/>');
  172. layer.closeAll();
  173. };
  174. showAlert(t, func, title);
  175. image();
  176. })
  177. })
  178. });
  179. }
  180. }
  181. function initLayui()
  182. {
  183. layui.use('layer', function() {
  184. var layer = layui.layer;
  185. layer.ready(function() {
  186. $(".dever-img").each(function()
  187. {
  188. layer.photos({
  189. photos: '#' + $(this).attr('id'),
  190. shade : 0.5
  191. });
  192. });
  193. });
  194. });
  195. }
  196. function initColor()
  197. {
  198. if ($('.dever-color').length) {
  199. $('.dever-color').each(function()
  200. {
  201. var self = $(this);
  202. var val = self.val();
  203. if (!val) {
  204. val = '#000000';
  205. }
  206. self.css('border-right', '40px solid '+val);
  207. self.colpick({
  208. layout:'hex',
  209. submit:0,
  210. colorScheme:'dark',
  211. color: val,
  212. onChange : function (hsb,hex,rgb,el,bySetColor) {
  213. $(el).css('border-color','#'+hex);
  214. if(!bySetColor) $(el).val('#' + hex);
  215. }
  216. }).keyup(function(){
  217. $(this).colpickSetColor(this.value);
  218. });
  219. })
  220. }
  221. }
  222. function formData(form)
  223. {
  224. var d = {};
  225. var t = $(form).serializeArray();
  226. var u = '';
  227. $.each(t, function() {
  228. if (this.name.indexOf('search_') != -1) {
  229. d[this.name] = this.value;
  230. u += '&' + this.name + '=' + this.value;
  231. }
  232. });
  233. return [d,u];
  234. }
  235. function initMenu()
  236. {
  237. if(typeof(config.layout) != "undefined")
  238. {
  239. $('.list-unstyled li').each(function(j)
  240. {
  241. $(this).unbind('click').bind('click', function()
  242. {
  243. if ($(this).index() == i) {
  244. //return;
  245. }
  246. $('.list-unstyled .active').each(function()
  247. {
  248. $(this).attr('class', '');
  249. $(this).find('a').attr('class', '');
  250. })
  251. $(this).attr('class', 'active');
  252. var a = $(this).find('a');
  253. a.attr('class', 'subdrop');
  254. //alert($(this).attr('class'));
  255. })
  256. });
  257. /*
  258. $('.project-list').each(function(i)
  259. {
  260. $(this).unbind('click').bind('click', function()
  261. {
  262. if ($(this).index() == i) {
  263. return;
  264. }
  265. $('.project-list').each(function()
  266. {
  267. $(this).find('i').parent().attr('class', '');
  268. $(this).find('ul').attr('class', 'list-unstyled upload-menu');
  269. })
  270. $(this).find('i').parent().attr('class', 'active');
  271. $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
  272. })
  273. });
  274. */
  275. }
  276. }
  277. function setOption(e, id)
  278. {
  279. var s = $("select[name="+id+"]");
  280. var v = s.val();
  281. if (!select) {
  282. select = s.clone();
  283. }
  284. s.find('option[parent]').remove();
  285. //查找出需要显示的option并复制
  286. var options = select.find("option[parent="+e.val()+"]").clone();
  287. //将需要显示的option添加到select中
  288. s.append(options);
  289. //因为option.remove()不会刷新控件,需要将新的option切换上去
  290. //这里排除了options.size() == 0的情况
  291. var state = 2;
  292. s.find('option').each(function()
  293. {
  294. var val = $(this).val();
  295. if (v == val) {
  296. state = 1;
  297. }
  298. });
  299. if (state == 1) {
  300. s.val(v);
  301. } else {
  302. s.val(0);
  303. }
  304. }
  305. function table()
  306. {
  307. if ($('.table-responsive').length) {
  308. $('.table-responsive[data-pattern]').each(function()
  309. {
  310. $(this).responsiveTable('update');
  311. });
  312. }
  313. }
  314. function pjax(param)
  315. {
  316. param.timeout = 8000;
  317. $.pjax(param);
  318. }
  319. function initDate()
  320. {
  321. $.datetimepicker.setLocale('ch');
  322. if($(".manage_date").length)
  323. {
  324. $(".manage_date").each(function()
  325. {
  326. $(this).datetimepicker(
  327. {
  328. //datepicker:false,
  329. format:'Y-m-d H:i:s',
  330. lang:'ch'
  331. });
  332. });
  333. }
  334. if($(".manage_day").length)
  335. {
  336. $(".manage_day").each(function()
  337. {
  338. $(this).datetimepicker(
  339. {
  340. //inline:true,
  341. timepicker:false,
  342. format:'Y-m-d',
  343. lang:'ch'
  344. });
  345. });
  346. }
  347. if($(".manage_sday").length)
  348. {
  349. $(".manage_sday").each(function()
  350. {
  351. $(this).datetimepicker(
  352. {
  353. //inline:true,
  354. timepicker:false,
  355. format:'Y-m-d',
  356. lang:'ch'
  357. });
  358. });
  359. }
  360. if($(".manage_sdate").length)
  361. {
  362. $(".manage_sdate").each(function()
  363. {
  364. $(this).datetimepicker(
  365. {
  366. //datepicker:false,
  367. format:'Y-m-d H:i:s',
  368. lang:'ch'
  369. });
  370. });
  371. }
  372. layui.use('laydate', function() {
  373. var laydate = layui.laydate;
  374. if ($('.manage_year').length) {
  375. $('.manage_year').each(function(i) {
  376. $(this).attr('id', 'manage_year_' + i);
  377. laydate.render({
  378. elem: '#manage_year_' + i,
  379. type: 'year',
  380. });
  381. })
  382. }
  383. if ($('.manage_month').length) {
  384. $('.manage_month').each(function(i) {
  385. $(this).attr('id', 'manage_month_' + i);
  386. laydate.render({
  387. elem: '#manage_month_' + i,
  388. type: 'month',
  389. });
  390. })
  391. }
  392. });
  393. }
  394. function initPic()
  395. {
  396. $('a[rel]').fancybox();
  397. }
  398. function initEditor(e)
  399. {
  400. if (!e) {
  401. e = $('.editor');
  402. }
  403. if(e.length)
  404. {
  405. var param = false;
  406. var editor = [];
  407. e.each(function()
  408. {
  409. var parent = $(this).parent().parent();
  410. //alert(parent.attr('id'));
  411. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  412. {
  413. return;
  414. }
  415. if (!param) {
  416. param = loadEditorParam($(this));
  417. }
  418. editor.push($(this).attr('id'));
  419. });
  420. if (editor) {
  421. for (var i in editor) {
  422. var id = editor[i];
  423. if (typeof(id) == 'string' && !editors[id]) {
  424. param.index = editors_index.length;
  425. editors[id] = KindEditor.create('#' + id, param);
  426. editors_index.push(id);
  427. }
  428. }
  429. }
  430. }
  431. if ($('.editor_tool').length) {
  432. $('.editor_tool').each(function()
  433. {
  434. $(this).click(function()
  435. {
  436. var tool = $(this).attr('tool');
  437. var id = $(this).attr('editor_id');
  438. editors[id].clickToolbar(tool);
  439. })
  440. });
  441. }
  442. }
  443. function loadEditorParam(e)
  444. {
  445. if(!e.length)
  446. {
  447. return;
  448. }
  449. var key = e.attr('key');
  450. var media = e.attr('media');
  451. var token = e.attr('token');
  452. var host = e.attr('host');
  453. var domain = e.attr('domain');
  454. var path = e.attr('path');
  455. var upload_search = e.attr('upload_search');
  456. var upload_search_value = e.attr('upload_search_value');
  457. var yun = {};
  458. if (token && host) {
  459. yun.token = token;
  460. yun.host = host;
  461. yun.domain = domain;
  462. yun.path = path;
  463. }
  464. if (!media) {
  465. media = key;
  466. }
  467. var view = config.upload.replace('save', 'view');
  468. var param = {
  469. height : "400px",
  470. allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
  471. allowImageRemote : true, //上传图片框网络图片的功能,false为隐藏,默认为true
  472. allowFileManager : true, //浏览图片空间
  473. allowMediaUpload : true,
  474. filterMode : false, //HTML特殊代码过滤
  475. themeType : 'default',
  476. filePostName : 'file',
  477. dialogOffset : 0, //对话框距离页面顶部的位置,默认为0居中,
  478. uploadJson : config.upload + '.kindeditor?key=' + key + '&search=' + upload_search_value,
  479. uploadResJson : config.uploadRes + '.kindeditor?key=' + key + '&search=' + upload_search_value,
  480. uploadMediaJson : config.upload + '.kindeditor?key=' + media + '&search=' + upload_search_value,
  481. uploadYunJson : yun,
  482. fileManagerJson : view + '.files?key=' + media + '&upload_search=' + upload_search,
  483. htmlTags : {
  484. section : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  485. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  486. span : [
  487. 'id', 'class', '.color', '.background-color', '.font-size','.letter-spacing', '.background',
  488. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  489. ],
  490. div : [
  491. 'id', 'class', 'data-applet', 'data-file', 'data-id', 'data-key','.dever-video', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  492. '.background-color', '.font-size','.letter-spacing', '.font-weight', '.background',
  493. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  494. ],
  495. table: [
  496. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  497. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  498. '.font-size', '.font-weight', '.font-style', '.text-decoration', '.background',
  499. '.width', '.height', '.border-collapse'
  500. ],
  501. 'td,th': [
  502. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  503. '.text-align', '.color', '.background-color', '.font-size','.letter-spacing', '.font-weight',
  504. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  505. ],
  506. a : ['id', 'class', 'href', 'target', 'name'],
  507. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  508. img : ['id', 'class', 'data-applet', 'data-file', 'data-id', 'data-key', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  509. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  510. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size','.letter-spacing', '.background',
  511. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  512. ],
  513. pre : ['id', 'class'],
  514. hr : ['id', 'class', '.page-break-after'],
  515. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  516. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  517. },
  518. items : [
  519. 'preview', 'undo', 'redo', '|', 'cut', 'copy', 'paste',
  520. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  521. 'justifyfull', 'indent', 'outdent', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', 'source', '/',
  522. 'formatblock', 'fontsize', 'fontheight', '|', 'forecolor', 'hilitecolor', 'bold',
  523. 'italic', 'underline', 'lineheight', 'removeformat', 'insertorderedlist','|', 'image','table', 'hr', 'pagebreak','link', 'unlink'
  524. ]
  525. /*
  526. items : [
  527. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  528. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  529. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  530. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  531. 'formatblock', 'fontsize', 'fontheight', '|', 'forecolor', 'hilitecolor', 'bold',
  532. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage','table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  533. 'anchor', 'link', 'unlink'
  534. ]
  535. */
  536. //media
  537. /*
  538. items : [
  539. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  540. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  541. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  542. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  543. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  544. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  545. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  546. 'anchor', 'link', 'unlink', '|', 'about'
  547. ]
  548. */
  549. }
  550. if (editorWidth > 0) {
  551. param.width = editorWidth + 'px';
  552. param.minWidth = editorWidth + 'px';
  553. }
  554. return param;
  555. }
  556. //更新页面的提交按钮
  557. function submit()
  558. {
  559. if($(".save-data").length)
  560. {
  561. if (submitButton) {
  562. $(".save-data").each(function()
  563. {
  564. $(this).html(submitButton);
  565. })
  566. }
  567. $(".save-data").unbind('click').bind('click', function()
  568. {
  569. if (editors) {
  570. for (var i in editors) {
  571. if (i.indexOf('update_') != -1) {
  572. editors[i].sync();
  573. }
  574. }
  575. }
  576. //return;
  577. submitButton = $(this).html();
  578. $(this).html('loading...');
  579. $(this).unbind('click');
  580. submit_action();
  581. })
  582. }
  583. }
  584. //直接提交更新页的数据
  585. function submit_action()
  586. {
  587. $(".form1").submit();
  588. }
  589. //设置某一个input的值
  590. function set_update(id, value)
  591. {
  592. if($(id).length)
  593. {
  594. $(id).val(value);
  595. }
  596. }
  597. /**
  598. * 批量复制数据
  599. */
  600. function copy_data(e)
  601. {
  602. var html = '<div>';
  603. html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
  604. html += '</div>';
  605. $('#dever_modal_body').html(html);
  606. $('#dever_modal_title').html('复制数据');
  607. $("#dever_modal_yes").unbind('click').bind('click', function()
  608. {
  609. set_update('#copy_num', $("#temp_copy_num").val());
  610. set_update('#update_where_id', 0);
  611. submit_action();
  612. });
  613. }
  614. //头部菜单
  615. function topMenu(e)
  616. {
  617. var p = e.parent().parent().parent().find('span');
  618. p.html(e.html());
  619. //更新当前的精细权限
  620. var url = config.host + 'top.update_action?json=1';
  621. var id = e.attr('data-id');
  622. $.post(url, {id:id}, function(t)
  623. {
  624. var href = location.href;
  625. if(location.href.indexOf('where_id') != -1)
  626. {
  627. var temp = location.href.split('where_id');
  628. href = temp[0] + 'where_id=' + t;
  629. }
  630. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  631. {
  632. pjax({url: href, container: config.layout})
  633. }
  634. else
  635. {
  636. location.href = href;
  637. }
  638. })
  639. }
  640. //头部菜单
  641. function topCMenu(e)
  642. {
  643. var p = e.parent().parent().parent().find('span');
  644. p.html(e.html());
  645. //更新当前的精细权限
  646. var url = config.host + 'company.set?json=1';
  647. var id = e.attr('data-id');
  648. $.post(url, {company_id:id}, function(t)
  649. {
  650. location.reload();
  651. })
  652. }
  653. //链接跳转
  654. function go(key, value)
  655. {
  656. var href = location.href;
  657. if(location.href.indexOf(key) != -1)
  658. {
  659. var temp = location.href.split(key + '=');
  660. href = temp[0] + key + '=' + value + '&' + temp[1];
  661. } else {
  662. href = href + '&' + key + '=' + value;
  663. }
  664. location.href = href;
  665. }
  666. //更新页面的批量载入选择
  667. function loadShow()
  668. {
  669. if($(".show_input").length)
  670. {
  671. $(".show_input input:radio").each(function()
  672. {
  673. if ($(this).attr('checked'))
  674. {
  675. inputShow($(this), $(this).attr('show_id'), 'input');
  676. }
  677. var filter = $(this).attr('lay-filter');
  678. if (filter) {
  679. form.on('radio('+filter+')', function(data) {
  680. inputShow($(this), $(this).attr('show_id'), 'input');
  681. })
  682. }
  683. })
  684. $(".show_input input:checkbox").each(function()
  685. {
  686. if ($(this).attr('checked'))
  687. {
  688. inputShow($(this), $(this).attr('show_id'), 'input');
  689. }
  690. var filter = $(this).attr('lay-filter');
  691. if (filter) {
  692. form.on('checkbox('+filter+')', function(data) {
  693. inputShow($(this), $(this).attr('show_id'), 'input');
  694. })
  695. }
  696. })
  697. $(".show_input select").each(function()
  698. {
  699. if($(this).find('option:selected').text())
  700. {
  701. inputShow($(this), $(this).attr('show_id'));
  702. }
  703. })
  704. }
  705. }
  706. function menuGroup(id, e)
  707. {
  708. if (typeof(layer) != 'undefined' && admingroup) {
  709. layer.close(admingroup);
  710. }
  711. $('.menu_group').hide();
  712. $('.menu_group_' + id).show();
  713. $('.menu_group_' + id).eq(0).addClass('layui-nav-itemed');
  714. }
  715. function inputShow(e,n,t)
  716. {
  717. $(".show_" + n).hide();
  718. var v = e.val();
  719. if (t == 'input') {
  720. var item = e.parent().find('input');
  721. item.each(function()
  722. {
  723. if($(this).get(0).checked == true)
  724. {
  725. inputShowOne($(this),n);
  726. }
  727. });
  728. } else {
  729. var item = e.parent().find('select');
  730. item.each(function()
  731. {
  732. if($(this).find('option:selected').text())
  733. {
  734. inputShowOne($(this),n);
  735. }
  736. });
  737. }
  738. var array = ['input', 'textarea'];
  739. for(var a in array)
  740. {
  741. if ($(".show_" + n).find(array[a]).length) {
  742. var s = $(".show_" + n).find(array[a]);
  743. var p = s.parent().parent().parent().css('display');
  744. var c = s.attr('class');
  745. if (c.indexOf('validate[required]') > -1 && p == 'none') {
  746. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  747. }
  748. if (c.indexOf('validates') > -1) {
  749. $(".show_" + n).find(array[a]).removeClass('validates').addClass('validate[required]');
  750. }
  751. }
  752. }
  753. }
  754. function inputShowOne(e,n)
  755. {
  756. var value = e.val();
  757. var ele = '.show_' + n + '_ajax';
  758. if ($(ele).length) {
  759. $(ele).each(function()
  760. {
  761. var self = $(this);
  762. var url = self.attr('dever-ajax');
  763. $.getJSON(url + value + '&callback=?', function(t) {
  764. self.find('.margin-top').html(t.data);
  765. inputShowOneValiDate(self);
  766. checkbox();
  767. })
  768. })
  769. } else {
  770. ele = '.show_' + n + '_' + value;
  771. inputShowOneValiDate($(ele));
  772. }
  773. }
  774. function inputShowOneValiDate(e)
  775. {
  776. e.show();
  777. var array = ['input', 'textarea'];
  778. for(var a in array)
  779. {
  780. if(e.length && e.attr('class').indexOf('show_no') == -1)
  781. {
  782. e.find(array[a]).each(function()
  783. {
  784. var parent = $(this).parent();
  785. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  786. {
  787. $(this).addClass('validate[required]');
  788. }
  789. })
  790. }
  791. }
  792. }
  793. //批量更新
  794. function list_mul(e)
  795. {
  796. var type = parseInt($("#mul_type").val());
  797. if(type != 1 && type != 2)
  798. {
  799. alert('您还没有选择数据更新方式');
  800. return;
  801. }
  802. var index = layer.confirm('确定进行此项操作吗?', function()
  803. {
  804. $('#method').val('mul');
  805. $('#function').val('msg');
  806. layer.close(index);
  807. $('#form1').attr('target', 'f1').submit();
  808. })
  809. }
  810. //搜索
  811. function list_search(e)
  812. {
  813. $('#method').val('search');
  814. $('#function').val('');
  815. $('#form1').attr('target', '').submit();
  816. }
  817. //更新数据
  818. function update(e, id, project, table, notice, menu_id)
  819. {
  820. var call = function()
  821. {
  822. var col = e.attr('name').replace('up_col_', '');
  823. var value = e.val();
  824. var old = e.attr('data-old');
  825. var url = config.host + 'database.update_action?json=1';
  826. $.post(url, {where_id:id,col:col,value:value,project:project,table:table,menu_id:menu_id}, function(t)
  827. {
  828. var t = eval('('+t+')');
  829. if (t.status == 1) {
  830. e.attr('data-old', value);
  831. notify('操作已成功!您的操作已修改当前选项!', e);
  832. preview();
  833. } else {
  834. msg(t);
  835. e.val(old);
  836. }
  837. })
  838. }
  839. if(notice)
  840. {
  841. var index = layer.confirm(notice, function(i, l)
  842. {
  843. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  844. layer.close(index);
  845. call();
  846. });
  847. }
  848. else
  849. {
  850. call();
  851. }
  852. }
  853. function notify(msg, e)
  854. {
  855. if (!e) {
  856. layer.msg(msg);
  857. return;
  858. }
  859. layer.tips(msg, e, {
  860. tips: [1, '#3595CC']
  861. });
  862. /*
  863. var notice = new PNotify({
  864. title: '提示信息',
  865. text: msg,
  866. buttons: {
  867. closer: false,
  868. sticker: false
  869. }
  870. });
  871. notice.get().click(function() {
  872. notice.remove();
  873. });
  874. */
  875. }
  876. //模板选择
  877. function template()
  878. {
  879. if(config.template)
  880. {
  881. $('body').attr('class', 'theme-' + config.template);
  882. }
  883. if($(".selector").length)
  884. {
  885. $(".selector").each(function()
  886. {
  887. if($(this).data('check') == 'checked')
  888. {
  889. selector($(this));
  890. }
  891. })
  892. }
  893. }
  894. //选择器
  895. function selector(e)
  896. {
  897. var value = e.data('value');
  898. var name = e.data('name');
  899. $('#'+name+'_value').val(value);
  900. $('.'+name+'_selector').children().css({'border':'2px solid #ccc'});
  901. e.children().css({'border':'2px solid #1e9fff'});
  902. if(name == 'update_template')
  903. {
  904. $('body').attr('class', 'theme-' + value);
  905. }
  906. }
  907. //根据e的值,来载入其他数据
  908. function loading(e, data, type)
  909. {
  910. if (type == 1) {
  911. var value = e.attr('v');
  912. } else {
  913. var value = e.val();
  914. if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
  915. {
  916. var id = e.attr('id').replace('_temp', '');
  917. if($('#' + id).length)
  918. {
  919. var value = $('#' + id).val();
  920. }
  921. }
  922. }
  923. if(data.element)
  924. {
  925. if(data.url)
  926. {
  927. data.value = value;
  928. $.getJSON(data.url + '&json=1', data, function(t)
  929. {
  930. $('#update_'+data.element+'_value').val(t.data);
  931. });
  932. }
  933. else
  934. {
  935. $('#update_'+data.element+'_value').val(value);
  936. }
  937. }
  938. else if(data.url)
  939. {
  940. data.value = value;
  941. data.where_id = $('#update_where_id').val();
  942. data.table = $('#table').val();
  943. data.project = $('#project').val();
  944. $.getJSON(data.url + '&json=1', data, function(s)
  945. {
  946. t = s.data;
  947. if (typeof(t) == 'object') {
  948. var d = t.data;
  949. t = t.html;
  950. if (d) {
  951. for(var i in d) {
  952. //$('#update_'+i+'_value').val(d[i]);
  953. $('#update_'+i).val(d[i]);
  954. }
  955. }
  956. }
  957. if(t.indexOf('onblur') != -1)
  958. {
  959. eval(t);
  960. }
  961. else
  962. {
  963. var parent = e.parent().parent();
  964. var tagName = parent.prop("tagName");
  965. if(t.indexOf('status') == -1)
  966. {
  967. if(data.type == 1)
  968. {
  969. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  970. {
  971. $(this).remove();
  972. });
  973. }
  974. else
  975. {
  976. $('.checking_-1,.checking_3,.checking_4').each(function()
  977. {
  978. $(this).remove();
  979. });
  980. }
  981. if (!parent.parent().find('.bind_show').length) {
  982. if (tagName == 'TD') {
  983. parent.next().html('<div class="bind_show">' + t + '</div>');
  984. } else {
  985. parent.after('<div class="bind_show">' + t + '</div>');
  986. }
  987. } else if (parent.parent().find('.bind_show').html() != t) {
  988. parent.parent().find('.bind_show').html(t);
  989. }
  990. checkbox();
  991. }
  992. }
  993. });
  994. }
  995. }
  996. //根据e的值,来载入其他数据,先检测是否选中
  997. function checking(name, e, data)
  998. {
  999. var value = [];
  1000. $('.' + name).each(function()
  1001. {
  1002. if($(this).get(0).checked == true)
  1003. {
  1004. value.push($(this).val());
  1005. }
  1006. });
  1007. if(data.url)
  1008. {
  1009. data.value = value.join(',');
  1010. data.where_id = $('#update_where_id').val();
  1011. data.table = $('#table').val();
  1012. data.project = $('#project').val();
  1013. if(data.check)
  1014. {
  1015. data.check_value = false;
  1016. $(data.check).each(function()
  1017. {
  1018. if($(this).get(0).checked == true)
  1019. {
  1020. data.check_value = $(this).val();
  1021. }
  1022. });
  1023. }
  1024. $.getJSON(data.url, data, function(s)
  1025. {
  1026. t = s.data;
  1027. var parent = e.parent().parent().parent();
  1028. if(t.indexOf('status') == -1)
  1029. {
  1030. if(data.type == 1)
  1031. {
  1032. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  1033. {
  1034. $(this).remove();
  1035. });
  1036. }
  1037. else
  1038. {
  1039. $('.checking_-1,.checking_3,.checking_4').each(function()
  1040. {
  1041. $(this).remove();
  1042. });
  1043. }
  1044. parent.after(t);
  1045. checkbox();
  1046. }
  1047. });
  1048. }
  1049. }
  1050. function autocomplete()
  1051. {
  1052. if ($("input").length) {
  1053. $("input").each(function()
  1054. {
  1055. $(this).attr('autocomplete', 'off');
  1056. });
  1057. }
  1058. if($("input[complete]").length)
  1059. {
  1060. $("input[complete]").each(function()
  1061. {
  1062. var cache = {};
  1063. var self = $(this);
  1064. self.autocomplete(
  1065. {
  1066. minLength: 2,
  1067. source: function( request, response )
  1068. {
  1069. var term = request.term.split( /,\s*/ );
  1070. request.term = term.pop();
  1071. if ( request.term in cache ) {
  1072. response( cache[ request.term ] );
  1073. return;
  1074. }
  1075. var cate = self.attr('complete_cate');
  1076. if (cate) {
  1077. request[cate] = $('update_' + cate + '_value').val();
  1078. }
  1079. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  1080. data = data.data
  1081. cache[ term ] = data;
  1082. var state = true;
  1083. for(var i in data)
  1084. {
  1085. if(data[i].id <=0)
  1086. {
  1087. state = false;
  1088. }
  1089. }
  1090. if(state)
  1091. {
  1092. response( data );
  1093. }
  1094. });
  1095. },
  1096. focus: function() {
  1097. // prevent value inserted on focus
  1098. return false;
  1099. },
  1100. select: function( event, ui )
  1101. {
  1102. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  1103. var value = self.attr('complete_callback');
  1104. var id = self.attr('id').replace('_temp', '');
  1105. var name = self.attr('name').replace('_temp', '');
  1106. //var e = $("#" + id);
  1107. var e = self;
  1108. 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>';
  1109. if (!$("#" + id + '_show').length) {
  1110. e.parent().append(html);
  1111. }
  1112. if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
  1113. {
  1114. var link = '';
  1115. var attr = '';
  1116. var pic = '';
  1117. if (ui.item['pic']) {
  1118. pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
  1119. }
  1120. if (ui.item['link']) {
  1121. link = ui.item['link'];
  1122. attr = ' target="_blank"';
  1123. }
  1124. 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>';
  1125. $("#" + id + '_show').append(html);
  1126. if (!autocomplete_value[id]) {
  1127. autocomplete_value[id] = [];
  1128. }
  1129. autocomplete_value[id].push(ui.item[value]);
  1130. }
  1131. ui.item.value = '';
  1132. }
  1133. });
  1134. })
  1135. }
  1136. }
  1137. function autocomplete_del(e, id, value, name)
  1138. {
  1139. e.parent().parent().remove();
  1140. autocomplete_value[id].remove(value);
  1141. var len = autocomplete_value[id].length;
  1142. if (len < 1 && !($('#del_' + name).length)) {
  1143. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1144. }
  1145. }
  1146. function searchbox(id, e)
  1147. {
  1148. var self = e.parent().find("input");
  1149. var v = self.val();
  1150. var key = self.attr('id').replace('_temp', '');
  1151. var request = {};
  1152. request.term = v;
  1153. var cate = self.attr('searchbox_cate');
  1154. if (cate) {
  1155. var c = cate.split(',');
  1156. for (var i in c) {
  1157. if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
  1158. request[c[i]] = $('#'+c[i]).val();
  1159. }
  1160. }
  1161. }
  1162. var index = layer.msg('加载中...');
  1163. $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
  1164. layer.close(index);
  1165. var data = data.data;
  1166. if (!data) {
  1167. showAlert('没有搜索到数据');
  1168. return;
  1169. }
  1170. var html = '<div class="layui-tab layui-tab-brief"" 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>';
  1171. if (data) {
  1172. var j = 0;
  1173. var c = '';
  1174. var s = '';
  1175. var cateHtml = '';
  1176. var content = '';
  1177. for (var i in data) {
  1178. if (j == 0) {
  1179. c = 'class="layui-this"';
  1180. s = 'layui-show';
  1181. } else {
  1182. c = '';
  1183. s = '';
  1184. }
  1185. cateHtml += '<li '+c+'>'+data[i].name+'</li>';
  1186. j++;
  1187. 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}';
  1188. var p = false;
  1189. for (var k in data[i].child) {
  1190. if (data[i].child[k].name) {
  1191. var pic = '';
  1192. if (data[i].child[k].pic) {
  1193. pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
  1194. p = true;
  1195. }
  1196. var check = '';
  1197. if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
  1198. check = 'checked';
  1199. }
  1200. 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>';
  1201. }
  1202. }
  1203. item += '</table></div></div>';
  1204. 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>';
  1205. if (p) {
  1206. head = head.replace('</td><td>', '</td><td>图片</td><td>');
  1207. }
  1208. item = item.replace('{head}', head);
  1209. content += item;
  1210. }
  1211. if (cateHtml) {
  1212. html = html.replace('{cate}', cateHtml);
  1213. }
  1214. if (content) {
  1215. html = html.replace('{content}', content);
  1216. }
  1217. }
  1218. var config = {
  1219. type: 1,
  1220. shade: 0.3,
  1221. title : false,
  1222. shadeClose : true,
  1223. area : ['800px', '600px'],
  1224. content: html
  1225. };
  1226. layer.open(config);
  1227. layui.use('element', function(){
  1228. var element = layui.element;
  1229. });
  1230. });
  1231. }
  1232. function searchbox_checkall(e, id)
  1233. {
  1234. $('.' + id).each(function()
  1235. {
  1236. $(this).get(0).checked = e.get(0).checked;
  1237. //$(this).click();
  1238. })
  1239. }
  1240. function searchbox_checkone(e, id, key, value)
  1241. {
  1242. if (!e.get(0).checked) {
  1243. $('#searchbox_check_' + key + '_' + value).remove();
  1244. searchbox_value.remove(value);
  1245. var len = searchbox_value.length;
  1246. var name = key.replace('_value', '');
  1247. if (len < 1 && !($('#del_' + name).length)) {
  1248. $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1249. }
  1250. } else {
  1251. var c = '.' + e.attr('data-class');
  1252. searchbox_yes(id, c, false);
  1253. }
  1254. }
  1255. function searchbox_yes(e, c, state)
  1256. {
  1257. var self = $("#" +e);
  1258. $(c).each(function()
  1259. {
  1260. if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
  1261. var value = self.attr('searchbox_callback');
  1262. var id = self.attr('id').replace('_temp', '');
  1263. var name = self.attr('name').replace('_temp', '');
  1264. 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>';
  1265. if (!$("#" + id + '_show').length) {
  1266. self.parent().append(html);
  1267. }
  1268. if (!$("#" + id + '_show').find('#searchbox_check_'+id+'_'+$(this).attr('data-value')).length)
  1269. {
  1270. var link = '';
  1271. var attr = '';
  1272. var pic = '';
  1273. if ($(this).attr('data-pic') && $(this).attr('data-pic') != 'undefined') {
  1274. pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
  1275. }
  1276. if ($(this).attr('data-link')) {
  1277. link = $(this).attr('data-link');
  1278. attr = ' target="_blank"';
  1279. }
  1280. 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>';
  1281. $("#" + id + '_show').append(html);
  1282. if (!searchbox_value[id]) {
  1283. searchbox_value[id] = [];
  1284. }
  1285. searchbox_value[id].push($(this).attr('data-value'));
  1286. }
  1287. }
  1288. })
  1289. if (state == true) {
  1290. layer.closeAll();
  1291. }
  1292. }
  1293. function searchbox_del(e, id, value, name)
  1294. {
  1295. e.parent().parent().remove();
  1296. searchbox_value.remove(value);
  1297. var len = searchbox_value.length;
  1298. if (len < 1 && !($('#del_' + name).length)) {
  1299. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1300. }
  1301. }
  1302. //后台通用的提示
  1303. function msg(value)
  1304. {
  1305. $("#dever_modal_no").click();
  1306. if(!value.data)
  1307. {
  1308. value.data = value.msg;
  1309. }
  1310. if(value == 1)
  1311. {
  1312. location.reload();
  1313. return;
  1314. }
  1315. submit();
  1316. var url = '';
  1317. if(value.data != 'reload' && value.status == 2)
  1318. {
  1319. showAlert(value.msg, false, '错误提示');
  1320. //alert(value.data);
  1321. //location.reload();
  1322. return;
  1323. }
  1324. else if(value.data == 'reload')
  1325. {
  1326. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1327. {
  1328. pjax({url: location.href, container: config.layout})
  1329. }
  1330. else
  1331. {
  1332. location.reload();
  1333. }
  1334. return;
  1335. }
  1336. else if(value.data == 'refer')
  1337. {
  1338. history.back();
  1339. return;
  1340. }
  1341. else
  1342. {
  1343. if(value.data.indexOf('http') != -1)
  1344. {
  1345. url = value.data;
  1346. }
  1347. else if($("#url").length)
  1348. {
  1349. url = $("#url").val();
  1350. }
  1351. else
  1352. {
  1353. notify(value.data)
  1354. return;
  1355. }
  1356. if(url)
  1357. {
  1358. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1359. {
  1360. pjax({url: url, container: config.layout});
  1361. }
  1362. else
  1363. {
  1364. location.href = url;
  1365. }
  1366. }
  1367. else
  1368. {
  1369. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1370. {
  1371. pjax({url: location.href, container: config.layout});
  1372. }
  1373. else
  1374. {
  1375. location.reload();
  1376. }
  1377. }
  1378. }
  1379. return;
  1380. }
  1381. /**
  1382. * 处理多选问题,处理全选按钮
  1383. */
  1384. function checkbox()
  1385. {
  1386. if($(".autoload").length)
  1387. {
  1388. $(".autoload").each(function()
  1389. {
  1390. if($(this).get(0).checked == true)
  1391. {
  1392. $(this).removeClass('autoload');
  1393. $(this).load();
  1394. }
  1395. });
  1396. }
  1397. if($(".autoload_text").length)
  1398. {
  1399. $(".autoload_text").each(function()
  1400. {
  1401. if($(this).val())
  1402. {
  1403. $(this).removeClass('autoload_text');
  1404. $(this).load();
  1405. }
  1406. });
  1407. }
  1408. var name = 'checkbox-checkall';
  1409. var checkbox = $("." + name);
  1410. if(checkbox.length)
  1411. {
  1412. if (checkbox.attr('title')) {
  1413. checkbox.each(function()
  1414. {
  1415. var self = $(this);
  1416. var ele = "." + name + "-" + self.val();
  1417. var len = $(ele).length;
  1418. $(ele).each(function()
  1419. {
  1420. if(this.checked == true)
  1421. {
  1422. self.get(0).checked = true;
  1423. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1424. inputShow($(this), 'col');
  1425. }
  1426. }
  1427. var filter = $(this).attr('lay-filter');
  1428. if (filter) {
  1429. form.on('checkbox('+filter+')', function (data) {
  1430. var next = $(this).next();
  1431. var state = $(this).attr('data-state');
  1432. if(data.elem.checked == true)
  1433. {
  1434. if (state == 2) {
  1435. self.get(0).checked = true;
  1436. } else {
  1437. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1438. self.get(0).checked = true;
  1439. }
  1440. }
  1441. if(self.attr('type') == 'radio')
  1442. {
  1443. //如果父选项是radio类型,做下限制
  1444. //alert(1);
  1445. }
  1446. if($("#mul_type").length)
  1447. {
  1448. $("#mul_type").val(1);
  1449. }
  1450. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1451. {
  1452. next.attr('disabled', false);
  1453. }
  1454. }
  1455. else
  1456. {
  1457. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1458. {
  1459. next.attr('disabled', true);
  1460. }
  1461. }
  1462. var num = 0;
  1463. $(ele).each(function()
  1464. {
  1465. if($(this).get(0).checked == true)
  1466. {
  1467. num = 1;
  1468. }
  1469. });
  1470. var id = $(this).attr('name');
  1471. var hidden = id;
  1472. id = id.replace('[]', '');
  1473. if(num == 0)
  1474. {
  1475. self.get(0).checked = false;
  1476. if($("#mul_type").length)
  1477. {
  1478. $("#mul_type").val(0);
  1479. }
  1480. if (state == 2) {
  1481. } else if (!$('#' + id).length) {
  1482. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+id+'" />');
  1483. }
  1484. } else {
  1485. if ($('#' + id).length) {
  1486. $('#' + id).remove();
  1487. }
  1488. }
  1489. form.render('checkbox');
  1490. });
  1491. }
  1492. });
  1493. var filter = self.attr('lay-filter');
  1494. form.on('checkbox('+filter+')', function (data) {
  1495. $("." + name + "-" + $(this).val()).each(function()
  1496. {
  1497. this.checked = data.elem.checked;
  1498. var next = $(this).next();
  1499. if(this.checked == true)
  1500. {
  1501. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1502. {
  1503. next.attr('disabled', false);
  1504. }
  1505. if($("#mul_type").length)
  1506. {
  1507. $("#mul_type").val(1);
  1508. }
  1509. }
  1510. else
  1511. {
  1512. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1513. {
  1514. next.attr('disabled', true);
  1515. }
  1516. if($("#mul_type").length)
  1517. {
  1518. $("#mul_type").val(0);
  1519. }
  1520. }
  1521. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1522. inputShow($(this), 'col');
  1523. }
  1524. form.render('checkbox');
  1525. });
  1526. });
  1527. form.render('checkbox');
  1528. });
  1529. } else {
  1530. checkbox.unbind('click').bind('click', function()
  1531. {
  1532. var self = $(this);
  1533. $("." + name + "-" + self.val()).each(function()
  1534. {
  1535. $(this).get(0).checked = self.get(0).checked;
  1536. var next = $(this).next();
  1537. if($(this).get(0).checked == true)
  1538. {
  1539. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1540. {
  1541. next.attr('disabled', false);
  1542. }
  1543. if($("#mul_type").length)
  1544. {
  1545. $("#mul_type").val(1);
  1546. }
  1547. }
  1548. else
  1549. {
  1550. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1551. {
  1552. next.attr('disabled', true);
  1553. }
  1554. if($("#mul_type").length)
  1555. {
  1556. $("#mul_type").val(0);
  1557. }
  1558. }
  1559. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1560. inputShow($(this), 'col');
  1561. }
  1562. })
  1563. });
  1564. checkbox.each(function()
  1565. {
  1566. var self = $(this);
  1567. var len = $("." + name + "-" + self.val()).length;
  1568. $("." + name + "-" + self.val()).each(function()
  1569. {
  1570. $(this).unbind('click').bind('click', function()
  1571. {
  1572. var next = $(this).next();
  1573. var state = $(this).attr('data-state');
  1574. if($(this).get(0).checked == true)
  1575. {
  1576. if (state == 2) {
  1577. self.get(0).checked = true;
  1578. } else {
  1579. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1580. self.get(0).checked = true;
  1581. }
  1582. }
  1583. if(self.attr('type') == 'radio')
  1584. {
  1585. //如果父选项是radio类型,做下限制
  1586. //alert(1);
  1587. }
  1588. if($("#mul_type").length)
  1589. {
  1590. $("#mul_type").val(1);
  1591. }
  1592. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1593. {
  1594. next.attr('disabled', false);
  1595. }
  1596. }
  1597. else
  1598. {
  1599. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1600. {
  1601. next.attr('disabled', true);
  1602. }
  1603. }
  1604. var num = 0;
  1605. $("." + name + "-" + self.val()).each(function()
  1606. {
  1607. if($(this).get(0).checked == true)
  1608. {
  1609. num = 1;
  1610. }
  1611. });
  1612. var id = $(this).attr('name');
  1613. var hidden = id;
  1614. id = id.replace('[]', '');
  1615. if(num == 0)
  1616. {
  1617. self.get(0).checked = false;
  1618. if($("#mul_type").length)
  1619. {
  1620. $("#mul_type").val(0);
  1621. }
  1622. if (state == 2) {
  1623. } else if (!$('#' + id).length) {
  1624. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  1625. }
  1626. } else {
  1627. if ($('#' + id).length) {
  1628. $('#' + id).remove();
  1629. }
  1630. }
  1631. })
  1632. if($(this).get(0).checked == true)
  1633. {
  1634. self.get(0).checked = true;
  1635. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1636. inputShow($(this), 'col');
  1637. }
  1638. }
  1639. });
  1640. })
  1641. }
  1642. }
  1643. }
  1644. /**
  1645. * 处理双击编辑
  1646. */
  1647. function edit()
  1648. {
  1649. if($(".edit").length)
  1650. {
  1651. $(".edit").each(function()
  1652. {
  1653. $(this).bind('dblclick', function()
  1654. {
  1655. var col = $(this).attr('data-col');
  1656. var project = $(this).attr('data-project');
  1657. var table = $(this).attr('data-table');
  1658. var url = $(this).attr('data-url');
  1659. var id = $(this).attr('data-id');
  1660. var html = $(this).attr('data-content');
  1661. var type = $(this).attr('data-type');
  1662. if($(this).find(".edit-content").length)
  1663. {
  1664. html = $(this).find(".edit-content").html();
  1665. html = html.replace('<!--', '<');
  1666. html = html.replace('-->', '>');
  1667. }
  1668. if (html == '点此编辑') {
  1669. html = '';
  1670. }
  1671. if(html.indexOf('input') == -1)
  1672. {
  1673. if(type && type == 'textarea')
  1674. {
  1675. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1676. }
  1677. else
  1678. {
  1679. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1680. }
  1681. var self = $(this);
  1682. self.find("#edit").focus();
  1683. self.find("#edit").blur(function()
  1684. {
  1685. var value = self.find("#edit").val();
  1686. if(!value)
  1687. {
  1688. alert('不能为空');
  1689. return;
  1690. }
  1691. if($(this).find(".edit-content").length)
  1692. {
  1693. $(this).find(".edit-content").html(value);
  1694. }
  1695. else
  1696. {
  1697. self.attr('data-content', value);
  1698. }
  1699. self.html(value);
  1700. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1701. {
  1702. notify('修改成功', self);
  1703. preview();
  1704. /*
  1705. if(type && type == 'textarea')
  1706. {
  1707. self.html(t);
  1708. }
  1709. */
  1710. })
  1711. })
  1712. }
  1713. });
  1714. })
  1715. }
  1716. }
  1717. function preview()
  1718. {
  1719. if($("#preview").length)
  1720. {
  1721. var time = Date.parse(new Date());
  1722. var src = $('#preview').attr('src').split('#');
  1723. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1724. }
  1725. }
  1726. function del()
  1727. {
  1728. if($(".oper_delete").length)
  1729. {
  1730. $(".oper_delete").each(function()
  1731. {
  1732. var href = $(this).attr('href');
  1733. $(this).attr('href', '#');
  1734. $(this).unbind('click');
  1735. $(this).bind('click', function()
  1736. {
  1737. del_act(href);
  1738. });
  1739. })
  1740. }
  1741. }
  1742. /**
  1743. * 处理删除
  1744. */
  1745. function del_act(href)
  1746. {
  1747. var index = layer.confirm('确定进行此项操作吗?', function(i, l)
  1748. {
  1749. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  1750. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1751. {
  1752. msg(t);
  1753. layer.close(index);
  1754. })
  1755. });
  1756. }
  1757. /**
  1758. * 处理特殊加载的按钮
  1759. */
  1760. function load(href, content, title)
  1761. {
  1762. if (!content) {
  1763. content = '确定进行此项操作吗?';
  1764. }
  1765. if (!title) {
  1766. title = '温馨提示';
  1767. }
  1768. var i = 0;
  1769. var flag = false;
  1770. var send = {title:title}
  1771. var index = layer.confirm(content, send, function(i, l)
  1772. {
  1773. if (!flag) {
  1774. i++;
  1775. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  1776. if(href.indexOf('&') == -1)
  1777. {
  1778. href += '?json=1&callback=?';
  1779. }
  1780. else
  1781. {
  1782. href += '&json=1&callback=?';
  1783. }
  1784. $.getJSON(href, {}, function(t)
  1785. {
  1786. if (t.status == 2) {
  1787. flag = false;
  1788. showAlert(t.msg, false, '错误提示');
  1789. return;
  1790. } else {
  1791. // 修改标志位
  1792. flag = true;
  1793. msg(t);
  1794. layer.close(index);
  1795. //location.reload();
  1796. }
  1797. })
  1798. }
  1799. })
  1800. /*
  1801. showAlert('确定进行此项操作吗?', function()
  1802. {
  1803. $("#dever_modal_no").click();
  1804. $.getJSON(href + '&json=1', {}, function(t)
  1805. {
  1806. msg(t);
  1807. })
  1808. });
  1809. */
  1810. }
  1811. /**
  1812. * 处理特殊页面
  1813. */
  1814. function loadPage(href, title, submit)
  1815. {
  1816. if(href.indexOf('&') == -1)
  1817. {
  1818. href += '?json=1&callback=?';
  1819. }
  1820. else
  1821. {
  1822. href += '&json=1&callback=?';
  1823. }
  1824. $.getJSON(href, {}, function(t)
  1825. {
  1826. var func = false;
  1827. if (submit) {
  1828. }
  1829. showAlert(t.data, func, title);
  1830. })
  1831. }
  1832. /**
  1833. * 处理特殊加载的按钮
  1834. */
  1835. function jump(href, form)
  1836. {
  1837. if (form) {
  1838. var param = formData(form);
  1839. href += param[1];
  1840. }
  1841. if (href.indexOf('list_excel') != -1) {
  1842. layer.confirm('确认导出数据吗?', function()
  1843. {
  1844. Excel.export(href);
  1845. })
  1846. } else {
  1847. location.href = href;
  1848. }
  1849. }
  1850. /**
  1851. * 处理change
  1852. */
  1853. function change()
  1854. {
  1855. if($(".change").length)
  1856. {
  1857. $(".change").each(function()
  1858. {
  1859. var key = $(this).attr('data-child');
  1860. /*
  1861. $('.' + key).each(function()
  1862. {
  1863. if($(this).find('select option:selected').val())
  1864. {
  1865. $(this).show();
  1866. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1867. }
  1868. });
  1869. */
  1870. $(this).change(function()
  1871. {
  1872. $('.' + key).hide();
  1873. var v = $('.' + key + '_' + $(this).val());
  1874. var s = v.find('select');
  1875. s.change(function()
  1876. {
  1877. $('.' + key + '_value').val($(this).val());
  1878. })
  1879. if(v.length)
  1880. {
  1881. $('.' + key + '_value').val(s.val());
  1882. v.show();
  1883. }
  1884. else
  1885. {
  1886. $('.' + key + '_value').val(-1);
  1887. }
  1888. });
  1889. if($(this).val() > 0)
  1890. {
  1891. $(this).change();
  1892. }
  1893. });
  1894. }
  1895. }
  1896. /**
  1897. * 处理图库系统
  1898. */
  1899. function image()
  1900. {
  1901. if($(".dever-note").length)
  1902. {
  1903. $(".dever-note").each(function()
  1904. {
  1905. var key = $(this).attr('key');
  1906. $(this).inlineattachment(
  1907. {
  1908. uploadUrl: config.upload + '.drag?key='+ key
  1909. });
  1910. });
  1911. }
  1912. if($(".image_upload").length)
  1913. {
  1914. $(".image_upload").each(function(i)
  1915. {
  1916. //如果是大文件
  1917. if ($(this).attr('l')) {
  1918. loadUploadL(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');
  1919. } else {
  1920. var parent = $(this).parent().parent();
  1921. //alert(parent.attr('id'));
  1922. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1923. {
  1924. return;
  1925. }
  1926. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1927. }
  1928. })
  1929. }
  1930. if($(".upload_show").length)
  1931. {
  1932. $(".upload_show").each(function(i)
  1933. {
  1934. var parent = $(this).parent().parent();
  1935. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1936. {
  1937. return;
  1938. }
  1939. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1940. })
  1941. }
  1942. if($(".upload_cover").length)
  1943. {
  1944. $(".upload_cover").each(function(i)
  1945. {
  1946. var parent = $(this).parent().parent();
  1947. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1948. {
  1949. return;
  1950. }
  1951. showUploadCover(i,$(this),$(this).attr('key'),config.upload + '.videoCover', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1952. })
  1953. }
  1954. if($(".upload_show_editor").length)
  1955. {
  1956. $(".upload_show_editor").each(function(i)
  1957. {
  1958. var parent = $(this).parent().parent();
  1959. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1960. {
  1961. return;
  1962. }
  1963. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 3);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  1964. })
  1965. }
  1966. }
  1967. /**
  1968. * 修改密码
  1969. */
  1970. function pass(e)
  1971. {
  1972. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  1973. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  1974. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  1975. html += '</div>';
  1976. var edit = function()
  1977. {
  1978. var old_password = $("#edit_old_password").val();
  1979. var new_password = $("#edit_new_password").val();
  1980. if(!old_password || !new_password)
  1981. {
  1982. alert('请输入密码');
  1983. return;
  1984. }
  1985. if(old_password == new_password)
  1986. {
  1987. alert('旧密码和新密码相同');
  1988. return;
  1989. }
  1990. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  1991. {
  1992. alert(t);
  1993. })
  1994. };
  1995. showAlert(html, edit, '修改密码');
  1996. /*
  1997. $('#dever_modal_body').html(html);
  1998. $('#dever_modal_title').html('修改密码');
  1999. */
  2000. }
  2001. var MSG = [];
  2002. /**
  2003. * 打开弹窗
  2004. */
  2005. //function showMsg(title, e, id, func)
  2006. function showMsg(title, e, id, func, param)
  2007. {
  2008. if(id.indexOf('http://') == -1)
  2009. {
  2010. if($(id).length)
  2011. {
  2012. var html = $(id).html();
  2013. if($(id).html())
  2014. {
  2015. var html = $(id).html();
  2016. MSG[id] = html;
  2017. $(id).html('');
  2018. }
  2019. else
  2020. {
  2021. var html = MSG[id];
  2022. }
  2023. }
  2024. else
  2025. {
  2026. var html = id;
  2027. }
  2028. showAlert(html, func, title);
  2029. /*
  2030. $('#dever_modal_body').html(html);
  2031. $('#dever_modal_title').html(title);
  2032. if (func) {
  2033. $("#dever_modal_yes").unbind('click').bind('click', func);
  2034. } else {
  2035. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  2036. }
  2037. */
  2038. }
  2039. else
  2040. {
  2041. var url = id;
  2042. var send = {};
  2043. if (param) {
  2044. send = param;
  2045. }
  2046. if (e && e.attr('msg-send')) {
  2047. send.data = e.attr('msg-send');
  2048. }
  2049. if (url.indexOf('?') != -1) {
  2050. url = url + '&';
  2051. } else {
  2052. url = url + '?';
  2053. }
  2054. $.getJSON(url+'json=1&callback=?',send,function(t)
  2055. {
  2056. t = t.data;
  2057. showAlert(t, func, t);
  2058. /*
  2059. $('#dever_modal_body').html(t);
  2060. $('#dever_modal_title').html(title);
  2061. if(func)
  2062. {
  2063. $("#dever_modal_yes").unbind('click').bind('click', func);
  2064. }
  2065. */
  2066. });
  2067. }
  2068. }
  2069. function updateMsg(id)
  2070. {
  2071. $("#"+id).submit();
  2072. }
  2073. function showAlert(msg, func, title, index, t)
  2074. {
  2075. if (!title) {
  2076. title = '温馨提示';
  2077. }
  2078. var type = 0;
  2079. if (msg.indexOf('<') != -1) {
  2080. type = 1;
  2081. }
  2082. if (t) {
  2083. type = t;
  2084. }
  2085. var config = {
  2086. type: 0,
  2087. title: title,
  2088. shade: 0.1,
  2089. shadeClose : true,
  2090. content: msg
  2091. };
  2092. if (index) {
  2093. config.zIndex = index;
  2094. }
  2095. config.scrollbar = false;
  2096. if (type == 1) {
  2097. config.type = 1;
  2098. config.btn = ['保存', '关闭'];
  2099. if (func) {
  2100. config.area = ['800px', '550px'];
  2101. config.btn = ['保存', '关闭'];
  2102. } else {
  2103. config.area = ['800px', '550px'];
  2104. config.btn = ['关闭'];
  2105. }
  2106. } else if (type == 2) {
  2107. config.type = 1;
  2108. config.btn = [];
  2109. config.area = ['800px', '550px'];
  2110. }
  2111. config.cancel = config.btn2 = function(index)
  2112. {
  2113. layer.close(index);
  2114. };
  2115. var flag = false;
  2116. if (func) {
  2117. config.yes = function(index)
  2118. {
  2119. if (!flag) {
  2120. flag = true;
  2121. func(index);
  2122. }
  2123. };
  2124. } else {
  2125. config.yes = config.cancel;
  2126. }
  2127. config.success = function() {
  2128. //$('.layui-layer-content').css('padding', '10px');
  2129. }
  2130. config.end = function() {
  2131. $('.layui-layer-content').css('overflow-x', 'auto');
  2132. $('#update_button').show();
  2133. }
  2134. var index = layer.open(config);
  2135. }
  2136. function fastEdit(e, url, title, col, index, type)
  2137. {
  2138. var func = function()
  2139. {
  2140. $(".fast").submit();
  2141. };
  2142. var send = {};
  2143. if (col) {
  2144. send.col = col;
  2145. }
  2146. $.get(url + '&fast=1',send,function(t)
  2147. {
  2148. var html = '';
  2149. var valid = '';
  2150. var action = '';
  2151. //if ($(t).find('form').length && !$(t).find('#form1').length) {
  2152. if ($(t).find('form').length) {
  2153. if ($(t).find('form').length > 1) {
  2154. var form_1 = $(t).find('form').eq(1);
  2155. form_1.addClass('layui-card-body');
  2156. } else {
  2157. var form_1 = $(t).find('form').eq(0);
  2158. }
  2159. action = form_1.attr('action');
  2160. form_1.addClass('fast');
  2161. form_1.find('#function').eq(0).val('showYes');
  2162. var html = form_1.prop("outerHTML");
  2163. if ($(t).find('#valid').length) {
  2164. var valid = $(t).find('#valid').prop("outerHTML");
  2165. html = html + valid;
  2166. }
  2167. if (html.indexOf('left: 740px') != -1) {
  2168. html = html.replace('left: 740px', 'left:583px;')
  2169. }
  2170. } else {
  2171. html = t;
  2172. func = false;
  2173. }
  2174. /*
  2175. if ($(html).find('.layui-card-body').length > 0) {
  2176. html = html.replace('class="layui-card-body"', 'class="layui-card-body" style="display:none"');
  2177. html = html.replaceAll('class="layui-btn layuiadmin-btn-list"', 'class="layui-btn layuiadmin-btn-list" style="display:none"');
  2178. }
  2179. */
  2180. if (!action) {
  2181. type = 2;
  2182. func = false;
  2183. }
  2184. if (index == 1) {
  2185. showAlert(html, func, title, 19850422, type);
  2186. } else {
  2187. showAlert(html, func, title, false, type);
  2188. }
  2189. $('.layui-layer-content').css('overflow-x', 'hidden');
  2190. if ($('#update_button').length) {
  2191. $('#update_button').hide();
  2192. }
  2193. layui.use(['form'], function(){
  2194. layui.form.render();
  2195. $('select').each(function() {
  2196. if ($(this).attr('xm-select')) {
  2197. layui.formSelects.render($(this).attr('xm-select'));
  2198. }
  2199. });
  2200. });
  2201. init(560);
  2202. });
  2203. }
  2204. /*
  2205. var test =
  2206. {
  2207. refreshPage: false,
  2208. addAjaxFlag: true,
  2209. //添加收藏
  2210. add: function(cfg)
  2211. {
  2212. }
  2213. }
  2214. */
  2215. function showToggle(e)
  2216. {
  2217. var id = e.attr('toggle');
  2218. var child = e.attr('toggle_child');
  2219. var parent = e.parent();
  2220. parent.parent().find('li').removeClass('active');
  2221. parent.addClass('active');
  2222. $(child).fadeOut(100);
  2223. $(id).fadeIn(500);
  2224. initEditor($(id).find('.editor'));
  2225. }
  2226. function addChange(e)
  2227. {
  2228. var val = e.val();
  2229. if (val == 0) {
  2230. var o = e.find('option:selected');
  2231. var type = o.attr('data-type');
  2232. if (type && type == 'add') {
  2233. var url = o.attr('data-url');
  2234. var p = e.parent();
  2235. if (p.find('.addchange').length < 1) {
  2236. p.html(p.html() + '<div class="addchange" style="display: inline-block;margin-left: 10px;"></div>');
  2237. }
  2238. var id = e.attr('id');
  2239. p.find('.addchange').html('<input type="text" class="update_value form-control layui-input " id="add_'+id+'" value="" autocomplete="off" style="width:60%;display: inline;" autofocus="autofocus" /><button class="btn btn-default layui-btn layuiadmin-btn-list" type="button" style="vertical-align: middle;margin-bottom: 2px;margin-left: 10px;" onclick="addChangeAction(\''+url+'\',\''+id+'\', $(this))">创建</button>');
  2240. }
  2241. e.val('0');
  2242. }
  2243. }
  2244. function addChangeAction(url, id, self)
  2245. {
  2246. var send = {};
  2247. var e = $('#' + id);
  2248. send.value = $('#add_' + id).val();
  2249. if (!send.value) {
  2250. layer.alert('没有填写内容');
  2251. return;
  2252. }
  2253. send.json = 1;
  2254. $.getJSON(url, send, function(t)
  2255. {
  2256. if (t.status == 1) {
  2257. e.append('<option value="'+t.data.id+'">'+send.value+'</option>');
  2258. e.val(t.data.id);
  2259. self.parent().remove();
  2260. } else {
  2261. layer.alert(t.msg);
  2262. }
  2263. });
  2264. }
  2265. function loadChange(e, load)
  2266. {
  2267. var val = e.val();
  2268. showLoad(load, [val]);
  2269. }
  2270. function showLoad(id, value)
  2271. {
  2272. var e = $('#update_' + id);
  2273. if (!value) {
  2274. e.html('');
  2275. return;
  2276. }
  2277. e.html('加载中...');
  2278. var url = e.attr("data-load");
  2279. var cate = e.attr("data-cate");
  2280. var id = e.attr("data-id");
  2281. var send = {};
  2282. send['json'] = 1;
  2283. if (cate) {
  2284. send[cate] = value.join(',');
  2285. }
  2286. if (id) {
  2287. send['id'] = id;
  2288. }
  2289. $.getJSON(url, send, function(t)
  2290. {
  2291. if (t.status == 1) {
  2292. if (t.data == 'no') {
  2293. if (e.html() == '加载中...') {
  2294. e.html('');
  2295. }
  2296. } else {
  2297. e.html(t.data);
  2298. }
  2299. } else {
  2300. e.html('');
  2301. }
  2302. layui.use(['form'], function(){
  2303. layui.form.render();
  2304. });
  2305. checkbox();
  2306. });
  2307. }
  2308. var level_value = [];
  2309. var select_api = {};
  2310. var select_api_name = [];
  2311. var select_api_title = '';
  2312. var select_api_open = '';
  2313. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param, col, api, type, title, open, load)
  2314. {
  2315. var e = '#' + id;
  2316. var parent = value.split(',');
  2317. var cur = parent[0];
  2318. parent.remove(cur);
  2319. value = parent.join(',');
  2320. var html = '';
  2321. var old = level;
  2322. var level_name = '';
  2323. if (!total) {
  2324. level_id = 0;
  2325. } else {
  2326. level_id = $(e + '_' + level).val();
  2327. if (level_id.indexOf('|') != -1) {
  2328. var temp = level_id.split('|');
  2329. if (level == 1) {
  2330. select_api_name = [];
  2331. }
  2332. level_id = temp[0];
  2333. level_name = temp[1];
  2334. select_api_name[level-1] = level_name;
  2335. }
  2336. if (level >= total) {
  2337. //$(e).show();
  2338. if (load) {
  2339. var key = total-1;
  2340. if (level_value[key]) {
  2341. level_value[key] = level_id;
  2342. } else {
  2343. level_value.push(level_id);
  2344. }
  2345. showLoad(load, level_value);
  2346. }
  2347. return;
  2348. }
  2349. level = parseInt(level) + 1;
  2350. }
  2351. var api_name = '';
  2352. if (col && api) {
  2353. select_api_title = title;
  2354. select_api_open = open;
  2355. if (name.indexOf('_no') == -1) {
  2356. api_name = name;
  2357. } else {
  2358. var t = name.split('_no');
  2359. api_name = t[0];
  2360. }
  2361. name += '_no';
  2362. }
  2363. $.getJSON(url + '&json=1&callback=?', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  2364. var check = '';
  2365. if (t.status == 1) {
  2366. if (level == 2) {
  2367. level_value = [];
  2368. }
  2369. if (load && level_id > 0) {
  2370. level_value.push(level_id);
  2371. showLoad(load, level_value);
  2372. }
  2373. var total = t.data.level_total;
  2374. var data = t.data.list;
  2375. if(!$(e + '_' + level).length) {
  2376. html = '<select lay-ignore data-validation-placeholder="-1" style="display:inline;margin-top:10px;'+w+'" class="layui-input layui-select update_value form-control '+valid+' '+name+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\', \''+col+'\', \''+api+'\', \''+type+'\', \''+title+'\', \''+open+'\', \''+load+'\');">';
  2377. }
  2378. for (a in data) {
  2379. if (data[a].value) {
  2380. check = '';
  2381. if (cur == data[a].value) {
  2382. check = ' selected';
  2383. }
  2384. var v = data[a].value;
  2385. if (col && api) {
  2386. v = data[a].value + '|' + data[a].name;
  2387. }
  2388. html += '<option value="'+v+'" '+check+'>'+data[a].name+'</option>';
  2389. }
  2390. }
  2391. if(!$(e + '_' + level).length) {
  2392. html += '</select><span>&nbsp;&nbsp;</span>';
  2393. $(e).append(html);
  2394. $(e + '_' + level).change();
  2395. } else {
  2396. $(e + '_' + level).html(html);
  2397. $(e + '_' + level).change();
  2398. }
  2399. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  2400. } else {
  2401. if (level == 2) {
  2402. level_value = [];
  2403. if (load && level_id < 0) {
  2404. showLoad(load, false);
  2405. }
  2406. }
  2407. if (load && level_id > 0) {
  2408. level_value.push(level_id)
  2409. showLoad(load, level_value);
  2410. }
  2411. $(e + '_' + old).nextAll('select').remove();
  2412. $(e + '_' + old).next('span').nextAll('span').remove();
  2413. }
  2414. if (col && api && level_id > 0) {
  2415. var send = {};
  2416. send[col] = level_id;
  2417. $.getJSON(api + '&json=1&callback=?', send, function(r) {
  2418. var h = '<ul style="list-style:none;margin-top: 20px;display:;" class="">';
  2419. if (type == 'checkbox') {
  2420. h += '<li style="display:inline;margin-left:15px;"><input class="update_value" type="checkbox" onclick="select_linkage_check_all($(this), \'check_level_'+level_id+'\', \''+level_id+'\', \''+select_api_name.join('->')+'\', \''+e+'\', \''+api_name+'\')" value=""/>&nbsp;&nbsp;全选</li>';
  2421. }
  2422. for (var i in r.data) {
  2423. if (r.data[i]['name']) {
  2424. var checked = false;
  2425. if (select_api['level_' + level_id] && select_api['level_' + level_id]['value'] && select_api['level_' + level_id]['value']['id_' + r.data[i]['id']] && select_api['level_' + level_id]['value']['id_' + r.data[i]['id']]['state'] == 1) {
  2426. checked = true;
  2427. }
  2428. h += '<li style="display:inline;margin-left:15px;"><input onclick="select_linkage_check($(this), \''+level_id+'\', \''+select_api_name.join('->')+'\', \''+e+'\', \''+api_name+'\')" '+(checked ? 'checked' : '')+' class="update_value check_level_'+level_id+'" type="' + type + '" id="'+id+'_'+r.data[i]['id']+'" value="'+r.data[i]['id']+'|' + r.data[i]['name'] + '"/>&nbsp;&nbsp;' + r.data[i]['name'] + '</li>';
  2429. }
  2430. }
  2431. h += '</ul>';
  2432. $(e + '_content').html(h);
  2433. });
  2434. }
  2435. /*
  2436. if ($('#' + name + '_level_value').length) {
  2437. var total = $(id).find('select').length;
  2438. $('#' + name + '_level_value').val(total);
  2439. }
  2440. if ($('#' + name + '_up_value').length) {
  2441. $('#' + name + '_up_value').val($(id + '_-2').val());
  2442. }
  2443. */
  2444. });
  2445. if (col && api) {
  2446. select_linkage_check_show(e, api_name);
  2447. }
  2448. }
  2449. function select_linkage_check_all(e, cur, level_id, level_name, id, api_name)
  2450. {
  2451. var checked = e.prop('checked');
  2452. $('.' + cur).each(function() {
  2453. $(this).prop('checked', checked);
  2454. select_linkage_check($(this), level_id, level_name, id, api_name);
  2455. })
  2456. }
  2457. function select_linkage_check(e, level_id, level_name, id, api_name, cid)
  2458. {
  2459. var level_key = 'level_' + level_id;
  2460. if (!select_api[level_key]) {
  2461. select_api[level_key] = {};
  2462. select_api[level_key]['id'] = level_id;
  2463. select_api[level_key]['name'] = level_name;
  2464. select_api[level_key]['value'] = {};
  2465. }
  2466. var value = e.val();
  2467. var temp = value.split('|');
  2468. var key = 'id_' + temp[0];
  2469. if (e.prop('checked')) {
  2470. select_api[level_key]['value'][key] = {};
  2471. select_api[level_key]['value'][key]['id'] = temp[0];
  2472. select_api[level_key]['value'][key]['name'] = temp[1];
  2473. select_api[level_key]['value'][key]['state'] = 1;
  2474. } else {
  2475. if (select_api[level_key] && select_api[level_key]['value'] && select_api[level_key]['value'][key]) {
  2476. select_api[level_key]['value'][key]['state'] = 2;
  2477. }
  2478. if (cid) {
  2479. $(cid).prop('checked', false);
  2480. }
  2481. }
  2482. select_linkage_check_show(id, api_name);
  2483. }
  2484. function select_linkage_check_show(id, api_name)
  2485. {
  2486. if (select_api) {
  2487. var select_api_json = JSON.stringify(select_api);
  2488. var html = '<div style="margin-top: 20px;display:;border: 1px solid #5050b1;padding: 10px;">';
  2489. for (var i in select_api) {
  2490. if (select_api[i]['value']) {
  2491. html += '[' + select_api[i]['name'] + ']:<ul style="list-style:none;" class="">';
  2492. for (var j in select_api[i]['value']) {
  2493. var n = '&nbsp;&nbsp;' + select_api[i]['value'][j]['name'];
  2494. if (select_api_open) {
  2495. var o = select_api_open.replace('{id}', select_api[i]['value'][j]['id']);
  2496. n = '<a href="javascript:;" onclick="fastEdit($(this), \''+o+'\', \''+select_api_title+'\', \'\', 1,1)">'+n+'</a>';
  2497. }
  2498. if (select_api[i]['value'][j]['state'] == 2) {
  2499. n += '[已删除]';
  2500. var checked = false;
  2501. } else {
  2502. var checked = true;
  2503. }
  2504. html += '<li style="display:inline;margin-left:15px;"><input onclick="select_linkage_check($(this), \''+select_api[i]['id']+'\', \''+select_api[i]['name']+'\', \''+id+'\', \''+api_name+'\', \''+id+'_'+select_api[i]['value'][j]['id']+'\')" '+(checked ? 'checked' : '')+' class="update_value" type="checkbox" id="s_'+select_api[i]['value'][j]['id']+'_test" name="s_'+select_api[i]['value'][j]['id']+'_test" value="'+select_api[i]['value'][j]['id']+'|' + select_api[i]['value'][j]['name'] + '"/>'+n+'</li>';
  2505. }
  2506. html += '</ul>';
  2507. }
  2508. }
  2509. html += '</div>';
  2510. html += '<textarea name="'+api_name+'" style="display:none">'+select_api_json+'</textarea>';
  2511. $(id + '_data').html(html);
  2512. }
  2513. }
  2514. /*
  2515. function select_mul(level, id, url, name, value, valid, w, num)
  2516. {
  2517. if(level == 0)
  2518. {
  2519. $(id).find('select').remove();
  2520. $(id).find('span').remove();
  2521. return;
  2522. }
  2523. var parent = value.split(',');
  2524. var cur = parent[0];
  2525. parent.remove(cur);
  2526. value = parent.join(',');
  2527. var html = '';
  2528. var old = level;
  2529. if(level != -1)
  2530. {
  2531. if($(id + '_' + level).length)
  2532. {
  2533. level = $(id + '_' + level).val();
  2534. }
  2535. alert(level);
  2536. if(level == 0)
  2537. {
  2538. $(id + '_' + old).nextAll('select').remove();
  2539. $(id + '_' + old).next('span').nextAll('span').remove();
  2540. if($('#' + name + '_level_value').length)
  2541. {
  2542. var total = $(id).find('select').length;
  2543. $('#' + name + '_level_value').val(total);
  2544. }
  2545. if(old == -2 && $('#' + name + '_value_value').length)
  2546. {
  2547. $('#' + name + '_value_value').val(level);
  2548. }
  2549. return;
  2550. }
  2551. if(old == -2)
  2552. {
  2553. $(id + '_' + old).nextAll('select').remove();
  2554. $(id + '_' + old).next('span').nextAll('span').remove();
  2555. }
  2556. if($('#' + name + '_value_value').length)
  2557. {
  2558. $('#' + name + '_value_value').val(level);
  2559. }
  2560. }
  2561. var total = $(id).find('select').length;
  2562. if(num > 0 && total >= num)
  2563. {
  2564. return;
  2565. }
  2566. var get = url.replace('{level}', level);
  2567. if(level == -1)
  2568. {
  2569. level = -2;
  2570. }
  2571. if(!$(id + '_' + level).length)
  2572. {
  2573. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  2574. {
  2575. var check = '';
  2576. if(t.status == 1)
  2577. {
  2578. 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+');">';
  2579. console.log(t.data);
  2580. for(a in t.data)
  2581. {
  2582. if(t.data[a].value)
  2583. {
  2584. check = '';
  2585. if(cur == t.data[a].value)
  2586. {
  2587. check = ' selected';
  2588. }
  2589. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  2590. }
  2591. }
  2592. html += '</select><span>&nbsp;&nbsp;</span>';
  2593. $(id).append(html);
  2594. $(id + '_' + level).change();
  2595. }
  2596. else
  2597. {
  2598. $(id + '_' + old).nextAll('select').remove();
  2599. $(id + '_' + old).next('span').nextAll('span').remove();
  2600. }
  2601. if($('#' + name + '_level_value').length)
  2602. {
  2603. var total = $(id).find('select').length;
  2604. $('#' + name + '_level_value').val(total);
  2605. }
  2606. if($('#' + name + '_up_value').length)
  2607. {
  2608. $('#' + name + '_up_value').val($(id + '_-2').val());
  2609. }
  2610. });
  2611. }
  2612. }
  2613. */
  2614. //处理更新页面的一些功能,写到一起吧
  2615. var dever_update =
  2616. {
  2617. addIndex : 2,
  2618. index : [],
  2619. auto : false,
  2620. save_key : '',
  2621. init : function()
  2622. {
  2623. var self = this;
  2624. self.index = [];
  2625. // 增加整个更新的表单
  2626. if($(".dever_update_add").length)
  2627. {
  2628. $('.dever_update_add').unbind('click').bind('click', function()
  2629. {
  2630. self.add($(this));
  2631. })
  2632. }
  2633. /* 以后再增加 同时更新另外一个表
  2634. if($(".form-add-content").length)
  2635. {
  2636. var url = config.host + 'auth.password';
  2637. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  2638. $.get(url, function(t)
  2639. {
  2640. $(".form-add-content").html(t);
  2641. init();
  2642. })
  2643. }
  2644. */
  2645. //增加某一部分表单
  2646. if($(".dever_form_add").length)
  2647. {
  2648. $('.dever_form_add').each(function()
  2649. {
  2650. var key = $.attr('toggle_key');
  2651. if(typeof(self.index[key]) == "undefined")
  2652. {
  2653. self.index[key] = 0;
  2654. }
  2655. $(this).unbind('click').bind('click', function()
  2656. {
  2657. self.append($(this));
  2658. })
  2659. })
  2660. self.del();
  2661. }
  2662. // 开启自动保存
  2663. if($("#struct").length)
  2664. {
  2665. var save = $("#struct").attr('save');
  2666. if(save == 'yes')
  2667. {
  2668. //检测
  2669. self.save_key = location.href + 'test';
  2670. self.check();
  2671. }
  2672. }
  2673. if($('.dever-note').length)
  2674. {
  2675. $('.dever-note').each(function()
  2676. {
  2677. var mditor = new Mditor($(this),{
  2678. fixedHeight:true
  2679. });
  2680. mditor.openPreview();
  2681. })
  2682. }
  2683. },
  2684. save : function()
  2685. {
  2686. //var data = $("#data-1").html();
  2687. var data = [];
  2688. $(".update_value").each(function(i)
  2689. {
  2690. if($(this).attr("update_type") == 'checked')
  2691. {
  2692. data[i] = $(this).get(0).checked;
  2693. }
  2694. else if($(this).attr("update_type") == 'html')
  2695. {
  2696. data[i] = $(this).html();
  2697. }
  2698. else if($(this).attr("update_type") == 'src')
  2699. {
  2700. data[i] = $(this).attr('src');
  2701. }
  2702. else
  2703. {
  2704. data[i] = $(this).val();
  2705. }
  2706. });
  2707. store.set(this.save_key, data.join('|||'));
  2708. //console.info(data);
  2709. },
  2710. recover : function()
  2711. {
  2712. var index = layer.confirm('确定恢复上次保存的数据吗?', function(i, l)
  2713. {
  2714. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  2715. var data = store.get(this.save_key).split('|||');
  2716. if(data)
  2717. {
  2718. var value = $(".update_value");
  2719. for(var k in data)
  2720. {
  2721. var e = value.eq(k);
  2722. if(e.attr('update_type') == 'checked')
  2723. {
  2724. if(data[k] == 'true')
  2725. {
  2726. e.get(0).checked = true;
  2727. }
  2728. else
  2729. {
  2730. e.get(0).checked = false;
  2731. }
  2732. }
  2733. else if(e.attr('update_type') == 'html')
  2734. {
  2735. e.html(data[k]);
  2736. }
  2737. else if(e.attr('update_type') == 'src')
  2738. {
  2739. e.attr('src', data[k]);
  2740. }
  2741. else
  2742. {
  2743. if(e.attr('id'))
  2744. {
  2745. var id = e.attr('id');
  2746. if(typeof(editors[id]) != "undefined")
  2747. {
  2748. editors[id].html(data[k]);
  2749. }
  2750. }
  2751. e.val(data[k]);
  2752. }
  2753. }
  2754. store.set(this.save_key, '');
  2755. this.check();
  2756. }
  2757. })
  2758. },
  2759. check : function()
  2760. {
  2761. var data = store.get(this.save_key);
  2762. var self = this;
  2763. if(data)
  2764. {
  2765. $(".dever_save").unbind('click').bind('click', function()
  2766. {
  2767. self.recover();
  2768. }).show();
  2769. }
  2770. else
  2771. {
  2772. $(".dever_save").hide();
  2773. self.auto = setInterval(function(){self.save()}, 3000);
  2774. }
  2775. },
  2776. del : function()
  2777. {
  2778. var self = this;
  2779. if($(".dever_form_delete").length)
  2780. {
  2781. $('.dever_form_delete').each(function()
  2782. {
  2783. $(this).unbind('click').bind('click', function()
  2784. {
  2785. var parent = $(this).parent();
  2786. var id = parent.attr('id');
  2787. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  2788. var key = $('#tab-' + id).attr('toggle_key');
  2789. if(index <= 1 && self.index[key] <= index)
  2790. {
  2791. }
  2792. else if(index <= 1 && self.index[key] > index)
  2793. {
  2794. index = index+1;
  2795. $("#tab-"+key+"-child-" + index).click();
  2796. }
  2797. else
  2798. {
  2799. index = index-1;
  2800. $("#tab-"+key+"-child-" + index).click();
  2801. };
  2802. $('#tab-' + id).parent().remove();
  2803. parent.remove();
  2804. self.index[key]--;
  2805. })
  2806. })
  2807. }
  2808. },
  2809. append : function(e)
  2810. {
  2811. var self = this;
  2812. var key = e.attr('toggle_key');
  2813. var parent = e.parent().parent().parent();
  2814. var child = '.dever_'+key+'_child';
  2815. if(typeof(self.index[key]) == "undefined")
  2816. {
  2817. self.index[key] = 0;
  2818. }
  2819. if (isNaN(self.index[key])) {
  2820. self.index[key] = 0;
  2821. }
  2822. if(self.index[key] <= 0)
  2823. {
  2824. self.index[key] = parent.find(child).length;
  2825. }
  2826. if(self.index[key] > 100)
  2827. {
  2828. layer.showAlert('最多只能增加100条');
  2829. return;
  2830. }
  2831. var p = e.parent();
  2832. var id = key + '-child-' + self.index[key];
  2833. var name = '第' + (self.index[key]) + '条';
  2834. p.before('<li style="margin:0px;padding:0 15px;"><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>');
  2835. var e = e.parent().parent();
  2836. var n = e.next();
  2837. var p = e.parent();
  2838. var content = n.html();
  2839. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  2840. var cname = n.attr('class');
  2841. if (cname.indexOf('layui-tab') > -1) {
  2842. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+'">' + content + '</div>';
  2843. } else {
  2844. //content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  2845. content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+'">' + content + '</div>';
  2846. }
  2847. p.append(content);
  2848. if ($("#" + id).find('.ke-container').length >= 1) {
  2849. $("#" + id).find('.ke-container').eq(0).remove();
  2850. }
  2851. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
  2852. self.del();
  2853. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  2854. self.index[key]++;
  2855. image();
  2856. loadShow();
  2857. autocomplete();
  2858. change();
  2859. form.render();
  2860. initPic();
  2861. initDate();
  2862. layui.use(['formSelects'], function(){
  2863. $('#' + id + " select").each(function()
  2864. {
  2865. if ($(this).attr('xm-select')) {
  2866. layui.formSelects.render($(this).attr('xm-select'));
  2867. }
  2868. })
  2869. });
  2870. },
  2871. add : function(e)
  2872. {
  2873. var self = this;
  2874. var p = e.parent();
  2875. var id = 'data-' + this.addIndex;
  2876. var name = '新增数据-' + (this.addIndex-1);
  2877. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  2878. var content = $("#content").find('.tab-pane').eq(0).html();
  2879. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  2880. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  2881. $("#content").append(content);
  2882. $('#update_' + this.addIndex + '__where_id').val('-1');
  2883. this.addIndex++;
  2884. }
  2885. }
  2886. $.fn.pasteEvents = function( delay ) {
  2887. if (delay == undefined) delay = 20;
  2888. return $(this).each(function() {
  2889. var $el = $(this);
  2890. $el.on("paste", function() {
  2891. $el.trigger("prepaste");
  2892. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  2893. });
  2894. });
  2895. };
  2896. $("textarea").on("postpaste", function()
  2897. {
  2898. if($(this).val().indexOf('<') != -1)
  2899. {
  2900. $(this).val(toMarkdown($(this).val()));
  2901. }
  2902. }).pasteEvents();
  2903. function showYes(msg)
  2904. {
  2905. if (msg.msg == 'reload') {
  2906. location.reload();
  2907. return;
  2908. }
  2909. if (msg.status == 2) {
  2910. layer.alert(msg.msg);
  2911. } else {
  2912. showAlert('保存成功', function() {
  2913. if (select_api_open) {
  2914. $('.layui-layer-content').css('overflow-x', 'auto');
  2915. $('#update_button').show();
  2916. layer.closeAll();
  2917. } else {
  2918. if(msg.data.indexOf('http') != -1) {
  2919. location.href = msg.data;
  2920. } else if (msg.data && msg.data == 'refer') {
  2921. history.back();
  2922. } else {
  2923. location.reload();
  2924. }
  2925. }
  2926. });
  2927. }
  2928. }
  2929. function setDay(e, d)
  2930. {
  2931. $('#search_option_sday').val(d);
  2932. $('.sday_button').removeClass('sday_button_border');
  2933. e.addClass('sday_button_border');
  2934. var date = new Date();
  2935. var year = date.getFullYear();
  2936. var month = date.getMonth()+1;
  2937. var day = date.getDate();
  2938. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  2939. //获取30天前得日期
  2940. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  2941. var lastY = lastDate.getFullYear();
  2942. var lastM = lastDate.getMonth()+1;
  2943. var lastD = lastDate.getDate();
  2944. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  2945. $('.manage_sday').eq(0).val(LDate);
  2946. $('.manage_sday').eq(1).val(nowDate);
  2947. }
  2948. function setDate(e, d)
  2949. {
  2950. $('#search_option_sdate').val(d);
  2951. $('.sdate_button').removeClass('sdate_button_border');
  2952. e.addClass('sdate_button_border');
  2953. var date = new Date();
  2954. var year = date.getFullYear();
  2955. var month = date.getMonth()+1;
  2956. var day = date.getDate();
  2957. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  2958. //获取30天前得日期
  2959. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  2960. var lastY = lastDate.getFullYear();
  2961. var lastM = lastDate.getMonth()+1;
  2962. var lastD = lastDate.getDate();
  2963. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  2964. $('.manage_sdate').eq(0).val(LDate + ' 00:00:00');
  2965. $('.manage_sdate').eq(1).val(nowDate + ' 23:59:59');
  2966. }
  2967. function showVideo(video)
  2968. {
  2969. var html = '<meta name="referrer" content="no-referrer"><video width="400" height="300" controls autoplay="autoplay"><source src="'+video+'" type="video/mp4">您的浏览器不支持Video标签。</video>';
  2970. showAlert(html);
  2971. }
  2972. function sku(e)
  2973. {
  2974. var data = $('#sku_table_col').html();
  2975. data = JSON.parse(data);
  2976. var thead = [];
  2977. var tbody = [];
  2978. var mthead = [];
  2979. var mtbody = [];
  2980. for (var i in data) {
  2981. if (data[i]['verify'] == 'number') {
  2982. var type = 'required|number';
  2983. var value = '0';
  2984. } else {
  2985. var type = 'required';
  2986. var value = '';
  2987. }
  2988. if (data[i]['type'] == 'image') {
  2989. var icon = '';
  2990. } else {
  2991. var icon = 'layui-icon-cols';
  2992. }
  2993. mthead.push({title: data[i]['name'], icon: icon});
  2994. mtbody.push({type: data[i]['type'], field: i, value: value, verify: type, reqtext: data[i]['name'] + '不能为空'});
  2995. if (data[i]['type'] != 'image') {
  2996. thead.push({title: data[i]['name'], icon: 'layui-icon-cols'});
  2997. tbody.push({type: data[i]['type'], field: i, value: value, verify: type, reqtext: data[i]['name'] + '不能为空'});
  2998. }
  2999. }
  3000. var obj = skuTable.render({
  3001. //规格类型 1统一规格 2多规格
  3002. isAttributeValue: e.attr('data-type'),
  3003. //规格类型容器id
  3004. isAttributeElemId: 'sku_spec_type',
  3005. //规格表容器id
  3006. specTableElemId: 'sku_spec_table',
  3007. //sku表容器id
  3008. skuTableElemId: 'sku_table',
  3009. //规格拖拽排序
  3010. sortable: true,
  3011. //sku表相同属性值是否合并行
  3012. rowspan: true,
  3013. //请求成功返回状态码值
  3014. requestSuccessCode: 1,
  3015. //上传接口地址
  3016. //接口要求返回格式参考 upload.json
  3017. uploadUrl: e.attr('data-upload'),
  3018. //统一规格配置项
  3019. singleSkuTableConfig: {
  3020. thead: thead,
  3021. tbody: tbody
  3022. },
  3023. //多规格配置项
  3024. multipleSkuTableConfig: {
  3025. thead: mthead,
  3026. tbody: mtbody
  3027. },
  3028. //商品id 配合specDataUrl和skuDataUrl使用
  3029. productId: e.attr('data-id'),
  3030. //规格数据, 一般从后台获取,
  3031. specData: [],
  3032. specDataUrl: e.attr('data-spec'),
  3033. skuData : [],
  3034. skuDataUrl: e.attr('data-sku'),
  3035. });
  3036. }
  3037. var append_total = 10;
  3038. function append(self, id)
  3039. {
  3040. var e = self.parent().parent().parent().find('.table_copy');
  3041. var html = e.html();
  3042. var parent = e.parent();
  3043. var total = parent.find('tr').length-1;
  3044. append_total++;
  3045. total += append_total;
  3046. html = html.replaceAll('_-1_', '_' + total + '_');
  3047. html = html.replaceAll('up_', 'update_');
  3048. id = 'append_' + id + '_' + total;
  3049. parent.append('<tr id="'+id+'">' + html + '</tr>');
  3050. form.render();
  3051. $('#' + id + " select").each(function()
  3052. {
  3053. if ($(this).attr('xm-select')) {
  3054. layui.formSelects.render($(this).attr('xm-select'));
  3055. }
  3056. });
  3057. }