main.js 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676
  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. if (e.attr('v')) {
  719. var v = e.attr('v');
  720. } else {
  721. var v = e.val();
  722. }
  723. if (t == 'input') {
  724. var item = e.parent().find('input');
  725. item.each(function()
  726. {
  727. if($(this).get(0).checked == true)
  728. {
  729. inputShowOne($(this),n);
  730. }
  731. });
  732. } else {
  733. var item = e.parent().find('select');
  734. item.each(function()
  735. {
  736. if($(this).find('option:selected').text())
  737. {
  738. inputShowOne($(this),n);
  739. }
  740. });
  741. }
  742. var array = ['input', 'textarea'];
  743. for(var a in array)
  744. {
  745. if ($(".show_" + n).find(array[a]).length) {
  746. var s = $(".show_" + n).find(array[a]);
  747. var p = s.parent().parent().parent().css('display');
  748. var c = s.attr('class');
  749. if (c.indexOf('validate[required]') > -1 && p == 'none') {
  750. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  751. }
  752. if (c.indexOf('validates') > -1) {
  753. $(".show_" + n).find(array[a]).removeClass('validates').addClass('validate[required]');
  754. }
  755. }
  756. }
  757. }
  758. function inputShowOne(e,n)
  759. {
  760. var value = e.val();
  761. var ele = '.show_' + n + '_ajax';
  762. if ($(ele).length) {
  763. $(ele).each(function()
  764. {
  765. var self = $(this);
  766. var url = self.attr('dever-ajax');
  767. $.getJSON(url + value + '&callback=?', function(t) {
  768. self.find('.margin-top').html(t.data);
  769. inputShowOneValiDate(self);
  770. checkbox();
  771. })
  772. })
  773. } else {
  774. ele = '.show_' + n + '_' + value;
  775. inputShowOneValiDate($(ele));
  776. }
  777. }
  778. function inputShowOneValiDate(e)
  779. {
  780. e.show();
  781. var array = ['input', 'textarea'];
  782. for(var a in array)
  783. {
  784. if(e.length && e.attr('class').indexOf('show_no') == -1)
  785. {
  786. e.find(array[a]).each(function()
  787. {
  788. var parent = $(this).parent();
  789. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  790. {
  791. $(this).addClass('validate[required]');
  792. }
  793. })
  794. }
  795. }
  796. }
  797. //批量更新
  798. var list_mul_state = 1;
  799. function list_mul(e, t, url)
  800. {
  801. if (t == 1) {
  802. var type = parseInt($("#mul_type").val());
  803. if(type != 1 && type != 2)
  804. {
  805. showAlert('您还没有选择数据');
  806. return;
  807. }
  808. }
  809. if (list_mul_state == 2) {
  810. showAlert('请不要重复点击');
  811. return;
  812. }
  813. var index = layer.confirm('确定进行此项操作吗?', function()
  814. {
  815. list_mul_state = 2;
  816. $('#method').val('mul');
  817. $('#function').val('msg');
  818. layer.close(index);
  819. if (url) {
  820. $('#method').val('mul.' + url);
  821. }
  822. $('#form1').attr('target', 'f1').submit();
  823. })
  824. }
  825. //搜索
  826. function list_search(e)
  827. {
  828. $('#method').val('search');
  829. $('#function').val('');
  830. $('#form1').attr('target', '').submit();
  831. }
  832. //更新数据
  833. function update(e, id, project, table, notice, menu_id)
  834. {
  835. var call = function()
  836. {
  837. var col = e.attr('name').replace('up_col_', '');
  838. var value = e.val();
  839. var old = e.attr('data-old');
  840. var url = config.host + 'database.update_action?json=1';
  841. $.post(url, {where_id:id,col:col,value:value,project:project,table:table,menu_id:menu_id}, function(t)
  842. {
  843. var t = eval('('+t+')');
  844. if (t.status == 1) {
  845. e.attr('data-old', value);
  846. notify('操作已成功!您的操作已修改当前选项!', e);
  847. preview();
  848. } else {
  849. msg(t);
  850. e.val(old);
  851. }
  852. })
  853. }
  854. if(notice)
  855. {
  856. var index = layer.confirm(notice, function(i, l)
  857. {
  858. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  859. layer.close(index);
  860. call();
  861. });
  862. }
  863. else
  864. {
  865. call();
  866. }
  867. }
  868. function notify(msg, e)
  869. {
  870. if (!e) {
  871. layer.msg(msg);
  872. return;
  873. }
  874. layer.tips(msg, e, {
  875. tips: [1, '#3595CC']
  876. });
  877. /*
  878. var notice = new PNotify({
  879. title: '提示信息',
  880. text: msg,
  881. buttons: {
  882. closer: false,
  883. sticker: false
  884. }
  885. });
  886. notice.get().click(function() {
  887. notice.remove();
  888. });
  889. */
  890. }
  891. //模板选择
  892. function template()
  893. {
  894. if(config.template)
  895. {
  896. $('body').attr('class', 'theme-' + config.template);
  897. }
  898. if($(".selector").length)
  899. {
  900. $(".selector").each(function()
  901. {
  902. if($(this).data('check') == 'checked')
  903. {
  904. selector($(this));
  905. }
  906. })
  907. }
  908. }
  909. //选择器
  910. function selector(e)
  911. {
  912. var value = e.data('value');
  913. var name = e.data('name');
  914. $('#'+name+'_value').val(value);
  915. $('.'+name+'_selector').children().css({'border':'2px solid #ccc'});
  916. e.children().css({'border':'2px solid #1e9fff'});
  917. if(name == 'update_template')
  918. {
  919. $('body').attr('class', 'theme-' + value);
  920. }
  921. }
  922. //根据e的值,来载入其他数据
  923. function loading(e, data, type)
  924. {
  925. if (type == 1) {
  926. var value = e.attr('v');
  927. } else {
  928. var value = e.val();
  929. if (e.attr('id') && e.attr('id').indexOf('_temp') != -1) {
  930. var id = e.attr('id').replace('_temp', '');
  931. if ($('#' + id).length) {
  932. var value = $('#' + id).val();
  933. }
  934. }
  935. }
  936. if (data.element) {
  937. if (data.url) {
  938. data.value = value;
  939. $.getJSON(data.url + '&json=1', data, function(t) {
  940. $('#update_'+data.element+'').val(t.data);
  941. });
  942. } else {
  943. $('#update_'+data.element+'').val(value);
  944. }
  945. } else if(data.url) {
  946. var parent = e.parent().parent();
  947. var tagName = parent.prop("tagName");
  948. var pid = '';
  949. if (tagName == 'TD') {
  950. pid = parent.parent().attr('id');
  951. }
  952. data.value = value;
  953. data.where_id = $('#update_where_id').val();
  954. data.table = $('#table').val();
  955. data.project = $('#project').val();
  956. if (data.col) {
  957. if (data.col.indexOf(',') != -1) {
  958. var s = data.col.split(',');
  959. for (var i in s) {
  960. if (i >= 0) {
  961. var a = s[i];
  962. if (pid) {
  963. var b = $('#update_'+ (pid + '_i_' + a));
  964. if (b.length) {
  965. var ue = b;
  966. } else {
  967. var ue = $('#update_'+a);
  968. }
  969. } else {
  970. var ue = $('#update_'+a);
  971. }
  972. data[s[i]] = ue.val();
  973. if (!data[s[i]]) {
  974. data[s[i]] = ue.attr('v');
  975. }
  976. }
  977. }
  978. } else {
  979. var a = data.col;
  980. if (pid) {
  981. var b = $('#update_'+ (pid + '_i_' + a));
  982. if (b.length) {
  983. var ue = b;
  984. } else {
  985. var ue = $('#update_'+a);
  986. }
  987. } else {
  988. var ue = $('#update_'+a);
  989. }
  990. data[a] = ue.val();
  991. if (!data[a]) {
  992. data[a] = ue.attr('v');
  993. }
  994. }
  995. }
  996. $.getJSON(data.url + '&json=1', data, function(s) {
  997. t = s.data;
  998. if (typeof(t) == 'object') {
  999. var o = t.option;
  1000. if (o) {
  1001. for (var i in o) {
  1002. if (pid) {
  1003. var ti = pid + '_i_' + i;
  1004. var ue = $('#update_'+ti);
  1005. } else {
  1006. var ue = $('#update_'+i);
  1007. }
  1008. ue.html(o[i]);
  1009. }
  1010. }
  1011. var d = t.data;
  1012. t = t.html;
  1013. if (d) {
  1014. for(var i in d) {
  1015. if (pid) {
  1016. var ti = pid + '_i_' + i;
  1017. var ue = $('#update_'+ti);
  1018. } else {
  1019. var ue = $('#update_'+i);
  1020. }
  1021. var div = ue.prop("tagName");
  1022. if (div == 'DIV') {
  1023. ue.html(d[i]);
  1024. } else {
  1025. ue.val(d[i]);
  1026. }
  1027. }
  1028. }
  1029. }
  1030. if (t) {
  1031. if (t.indexOf('onblur') != -1) {
  1032. eval(t);
  1033. } else {
  1034. if (t.indexOf('status') == -1) {
  1035. if (data.type == 1) {
  1036. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  1037. {
  1038. $(this).remove();
  1039. });
  1040. } else {
  1041. $('.checking_-1,.checking_3,.checking_4').each(function()
  1042. {
  1043. $(this).remove();
  1044. });
  1045. }
  1046. if (!parent.parent().find('.bind_show').length) {
  1047. if (tagName == 'TD') {
  1048. parent.next().html('<div class="bind_show">' + t + '</div>');
  1049. } else {
  1050. parent.after('<div class="bind_show">' + t + '</div>');
  1051. }
  1052. } else if (parent.parent().find('.bind_show').html() != t) {
  1053. parent.parent().find('.bind_show').html(t);
  1054. }
  1055. checkbox();
  1056. }
  1057. }
  1058. }
  1059. });
  1060. }
  1061. }
  1062. //根据e的值,来载入其他数据,先检测是否选中
  1063. function checking(name, e, data)
  1064. {
  1065. var value = [];
  1066. $('.' + name).each(function()
  1067. {
  1068. if($(this).get(0).checked == true)
  1069. {
  1070. value.push($(this).val());
  1071. }
  1072. });
  1073. if(data.url)
  1074. {
  1075. data.value = value.join(',');
  1076. data.where_id = $('#update_where_id').val();
  1077. data.table = $('#table').val();
  1078. data.project = $('#project').val();
  1079. if(data.check)
  1080. {
  1081. data.check_value = false;
  1082. $(data.check).each(function()
  1083. {
  1084. if($(this).get(0).checked == true)
  1085. {
  1086. data.check_value = $(this).val();
  1087. }
  1088. });
  1089. }
  1090. $.getJSON(data.url, data, function(s)
  1091. {
  1092. t = s.data;
  1093. var parent = e.parent().parent().parent();
  1094. if(t.indexOf('status') == -1)
  1095. {
  1096. if(data.type == 1)
  1097. {
  1098. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  1099. {
  1100. $(this).remove();
  1101. });
  1102. }
  1103. else
  1104. {
  1105. $('.checking_-1,.checking_3,.checking_4').each(function()
  1106. {
  1107. $(this).remove();
  1108. });
  1109. }
  1110. parent.after(t);
  1111. checkbox();
  1112. }
  1113. });
  1114. }
  1115. }
  1116. function autocomplete()
  1117. {
  1118. if ($("input").length) {
  1119. $("input").each(function()
  1120. {
  1121. $(this).attr('autocomplete', 'off');
  1122. });
  1123. }
  1124. if($("input[complete]").length)
  1125. {
  1126. $("input[complete]").each(function()
  1127. {
  1128. var cache = {};
  1129. var self = $(this);
  1130. self.autocomplete(
  1131. {
  1132. minLength: 2,
  1133. source: function( request, response )
  1134. {
  1135. var term = request.term.split( /,\s*/ );
  1136. request.term = term.pop();
  1137. if ( request.term in cache ) {
  1138. response( cache[ request.term ] );
  1139. return;
  1140. }
  1141. var cate = self.attr('complete_cate');
  1142. if (cate) {
  1143. request[cate] = $('#update_' + cate).val();
  1144. }
  1145. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  1146. data = data.data
  1147. cache[ term ] = data;
  1148. var state = true;
  1149. for(var i in data)
  1150. {
  1151. if(data[i].id <=0)
  1152. {
  1153. state = false;
  1154. }
  1155. }
  1156. if(state)
  1157. {
  1158. response( data );
  1159. }
  1160. });
  1161. },
  1162. focus: function() {
  1163. // prevent value inserted on focus
  1164. return false;
  1165. },
  1166. select: function( event, ui )
  1167. {
  1168. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  1169. var value = self.attr('complete_callback');
  1170. var id = self.attr('id').replace('_temp', '');
  1171. var name = self.attr('name').replace('_temp', '');
  1172. //var e = $("#" + id);
  1173. var e = self;
  1174. 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>';
  1175. if (!$("#" + id + '_show').length) {
  1176. e.parent().append(html);
  1177. }
  1178. if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
  1179. {
  1180. var link = '';
  1181. var attr = '';
  1182. var pic = '';
  1183. if (ui.item['pic']) {
  1184. pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
  1185. }
  1186. if (ui.item['link']) {
  1187. link = ui.item['link'];
  1188. attr = ' target="_blank"';
  1189. }
  1190. 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>';
  1191. $("#" + id + '_show').append(html);
  1192. if (!autocomplete_value[id]) {
  1193. autocomplete_value[id] = [];
  1194. }
  1195. autocomplete_value[id].push(ui.item[value]);
  1196. }
  1197. ui.item.value = '';
  1198. }
  1199. });
  1200. })
  1201. }
  1202. }
  1203. function autocomplete_del(e, id, value, name)
  1204. {
  1205. e.parent().parent().remove();
  1206. autocomplete_value[id].remove(value);
  1207. var len = autocomplete_value[id].length;
  1208. if (len < 1 && !($('#del_' + name).length)) {
  1209. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1210. }
  1211. }
  1212. function searchbox(id, e)
  1213. {
  1214. var self = e.parent().find("input");
  1215. var v = self.val();
  1216. var key = self.attr('id').replace('_temp', '');
  1217. var request = {};
  1218. request.term = v;
  1219. var cate = self.attr('searchbox_cate');
  1220. if (cate) {
  1221. var c = cate.split(',');
  1222. for (var i in c) {
  1223. if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
  1224. request[c[i]] = $('#'+c[i]).val();
  1225. }
  1226. }
  1227. }
  1228. var index = layer.msg('加载中...');
  1229. $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
  1230. layer.close(index);
  1231. var data = data.data;
  1232. if (!data) {
  1233. showAlert('没有搜索到数据');
  1234. return;
  1235. }
  1236. 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>';
  1237. if (data) {
  1238. var j = 0;
  1239. var c = '';
  1240. var s = '';
  1241. var cateHtml = '';
  1242. var content = '';
  1243. for (var i in data) {
  1244. if (j == 0) {
  1245. c = 'class="layui-this"';
  1246. s = 'layui-show';
  1247. } else {
  1248. c = '';
  1249. s = '';
  1250. }
  1251. cateHtml += '<li '+c+'>'+data[i].name+'</li>';
  1252. j++;
  1253. 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}';
  1254. var p = false;
  1255. for (var k in data[i].child) {
  1256. if (data[i].child[k].name) {
  1257. var pic = '';
  1258. if (data[i].child[k].pic) {
  1259. pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
  1260. p = true;
  1261. }
  1262. var check = '';
  1263. if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
  1264. check = 'checked';
  1265. }
  1266. 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>';
  1267. }
  1268. }
  1269. item += '</table></div></div>';
  1270. 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>';
  1271. if (p) {
  1272. head = head.replace('</td><td>', '</td><td>图片</td><td>');
  1273. }
  1274. item = item.replace('{head}', head);
  1275. content += item;
  1276. }
  1277. if (cateHtml) {
  1278. html = html.replace('{cate}', cateHtml);
  1279. }
  1280. if (content) {
  1281. html = html.replace('{content}', content);
  1282. }
  1283. }
  1284. var config = {
  1285. type: 1,
  1286. shade: 0.3,
  1287. title : false,
  1288. shadeClose : true,
  1289. area : ['800px', '600px'],
  1290. content: html
  1291. };
  1292. layer.open(config);
  1293. layui.use('element', function(){
  1294. var element = layui.element;
  1295. });
  1296. });
  1297. }
  1298. function searchbox_checkall(e, id)
  1299. {
  1300. $('.' + id).each(function()
  1301. {
  1302. $(this).get(0).checked = e.get(0).checked;
  1303. //$(this).click();
  1304. })
  1305. }
  1306. function searchbox_checkone(e, id, key, value)
  1307. {
  1308. if (!e.get(0).checked) {
  1309. $('#searchbox_check_' + key + '_' + value).remove();
  1310. searchbox_value.remove(value);
  1311. var len = searchbox_value.length;
  1312. var name = key.replace('_value', '');
  1313. if (len < 1 && !($('#del_' + name).length)) {
  1314. $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1315. }
  1316. } else {
  1317. var c = '.' + e.attr('data-class');
  1318. searchbox_yes(id, c, false);
  1319. }
  1320. }
  1321. function searchbox_yes(e, c, state)
  1322. {
  1323. var self = $("#" +e);
  1324. $(c).each(function()
  1325. {
  1326. if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
  1327. var value = self.attr('searchbox_callback');
  1328. var id = self.attr('id').replace('_temp', '');
  1329. var name = self.attr('name').replace('_temp', '');
  1330. 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>';
  1331. if (!$("#" + id + '_show').length) {
  1332. self.parent().append(html);
  1333. }
  1334. if (!$("#" + id + '_show').find('#searchbox_check_'+id+'_'+$(this).attr('data-value')).length)
  1335. {
  1336. var link = '';
  1337. var attr = '';
  1338. var pic = '';
  1339. if ($(this).attr('data-pic') && $(this).attr('data-pic') != 'undefined') {
  1340. pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
  1341. }
  1342. if ($(this).attr('data-link')) {
  1343. link = $(this).attr('data-link');
  1344. attr = ' target="_blank"';
  1345. }
  1346. 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>';
  1347. $("#" + id + '_show').append(html);
  1348. if (!searchbox_value[id]) {
  1349. searchbox_value[id] = [];
  1350. }
  1351. searchbox_value[id].push($(this).attr('data-value'));
  1352. }
  1353. }
  1354. })
  1355. if (state == true) {
  1356. layer.closeAll();
  1357. }
  1358. }
  1359. function searchbox_del(e, id, value, name)
  1360. {
  1361. e.parent().parent().remove();
  1362. searchbox_value.remove(value);
  1363. var len = searchbox_value.length;
  1364. if (len < 1 && !($('#del_' + name).length)) {
  1365. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1366. }
  1367. }
  1368. //后台通用的提示
  1369. function msg(value)
  1370. {
  1371. $("#dever_modal_no").click();
  1372. if(!value.data)
  1373. {
  1374. value.data = value.msg;
  1375. }
  1376. if(value == 1)
  1377. {
  1378. location.reload();
  1379. return;
  1380. }
  1381. submit();
  1382. var url = '';
  1383. if(value.data != 'reload' && value.status == 2 && value.code == 1)
  1384. {
  1385. if ($('#dever_submit').length && value.uuid) {
  1386. $('#dever_submit').val(value.uuid);
  1387. }
  1388. showAlertFlag = false;
  1389. list_mul_state = 1;
  1390. showAlert(value.msg, false, '错误提示');
  1391. //alert(value.data);
  1392. //location.reload();
  1393. return;
  1394. }
  1395. else if(value.data == 'reload')
  1396. {
  1397. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1398. {
  1399. pjax({url: location.href, container: config.layout})
  1400. }
  1401. else
  1402. {
  1403. location.reload();
  1404. }
  1405. return;
  1406. }
  1407. else if(value.data == 'refer')
  1408. {
  1409. history.back();
  1410. return;
  1411. }
  1412. else
  1413. {
  1414. if(value.data.indexOf('http') != -1)
  1415. {
  1416. url = value.data;
  1417. }
  1418. else if($("#url").length)
  1419. {
  1420. url = $("#url").val();
  1421. }
  1422. else
  1423. {
  1424. notify(value.data)
  1425. return;
  1426. }
  1427. if(url)
  1428. {
  1429. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1430. {
  1431. pjax({url: url, container: config.layout});
  1432. }
  1433. else
  1434. {
  1435. location.href = url;
  1436. }
  1437. }
  1438. else
  1439. {
  1440. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1441. {
  1442. pjax({url: location.href, container: config.layout});
  1443. }
  1444. else
  1445. {
  1446. location.reload();
  1447. }
  1448. }
  1449. }
  1450. return;
  1451. }
  1452. /**
  1453. * 处理多选问题,处理全选按钮
  1454. */
  1455. function checkbox()
  1456. {
  1457. if($(".autoload").length)
  1458. {
  1459. $(".autoload").each(function()
  1460. {
  1461. if($(this).get(0).checked == true)
  1462. {
  1463. $(this).removeClass('autoload');
  1464. $(this).load();
  1465. }
  1466. });
  1467. }
  1468. if($(".autoload_text").length)
  1469. {
  1470. $(".autoload_text").each(function()
  1471. {
  1472. if($(this).val())
  1473. {
  1474. $(this).removeClass('autoload_text');
  1475. $(this).load();
  1476. }
  1477. });
  1478. }
  1479. var name = 'checkbox-checkall';
  1480. var checkbox = $("." + name);
  1481. if(checkbox.length)
  1482. {
  1483. if (checkbox.attr('title')) {
  1484. checkbox.each(function()
  1485. {
  1486. var self = $(this);
  1487. var ele = "." + name + "-" + self.val();
  1488. var len = $(ele).length;
  1489. $(ele).each(function()
  1490. {
  1491. if(this.checked == true)
  1492. {
  1493. self.get(0).checked = true;
  1494. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1495. inputShow($(this), 'col');
  1496. }
  1497. }
  1498. var filter = $(this).attr('lay-filter');
  1499. if (filter) {
  1500. form.on('checkbox('+filter+')', function (data) {
  1501. var next = $(this).next();
  1502. var state = $(this).attr('data-state');
  1503. if(data.elem.checked == true)
  1504. {
  1505. if (state == 2) {
  1506. self.get(0).checked = true;
  1507. } else {
  1508. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1509. self.get(0).checked = true;
  1510. }
  1511. }
  1512. if(self.attr('type') == 'radio')
  1513. {
  1514. //如果父选项是radio类型,做下限制
  1515. //alert(1);
  1516. }
  1517. if($("#mul_type").length)
  1518. {
  1519. $("#mul_type").val(1);
  1520. }
  1521. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1522. {
  1523. next.attr('disabled', false);
  1524. }
  1525. }
  1526. else
  1527. {
  1528. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1529. {
  1530. next.attr('disabled', true);
  1531. }
  1532. }
  1533. var num = 0;
  1534. $(ele).each(function()
  1535. {
  1536. if($(this).get(0).checked == true)
  1537. {
  1538. num = 1;
  1539. }
  1540. });
  1541. var id = $(this).attr('name');
  1542. var hidden = id;
  1543. id = id.replace('[]', '');
  1544. if(num == 0)
  1545. {
  1546. self.get(0).checked = false;
  1547. if($("#mul_type").length)
  1548. {
  1549. $("#mul_type").val(0);
  1550. }
  1551. if (state == 2) {
  1552. } else if (!$('#' + id).length) {
  1553. //self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+id+'" />');
  1554. }
  1555. } else {
  1556. /*
  1557. if ($('#' + id).length) {
  1558. $('#' + id).remove();
  1559. }*/
  1560. }
  1561. form.render('checkbox');
  1562. });
  1563. }
  1564. });
  1565. var filter = self.attr('lay-filter');
  1566. form.on('checkbox('+filter+')', function (data) {
  1567. $("." + name + "-" + $(this).val()).each(function()
  1568. {
  1569. this.checked = data.elem.checked;
  1570. var next = $(this).next();
  1571. if(this.checked == true)
  1572. {
  1573. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1574. {
  1575. next.attr('disabled', false);
  1576. }
  1577. if($("#mul_type").length)
  1578. {
  1579. $("#mul_type").val(1);
  1580. }
  1581. }
  1582. else
  1583. {
  1584. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1585. {
  1586. next.attr('disabled', true);
  1587. }
  1588. if($("#mul_type").length)
  1589. {
  1590. $("#mul_type").val(0);
  1591. }
  1592. }
  1593. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1594. inputShow($(this), 'col');
  1595. }
  1596. form.render('checkbox');
  1597. });
  1598. });
  1599. form.render('checkbox');
  1600. });
  1601. } else {
  1602. checkbox.unbind('click').bind('click', function()
  1603. {
  1604. var self = $(this);
  1605. $("." + name + "-" + self.val()).each(function()
  1606. {
  1607. $(this).get(0).checked = self.get(0).checked;
  1608. var next = $(this).next();
  1609. if($(this).get(0).checked == true)
  1610. {
  1611. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1612. {
  1613. next.attr('disabled', false);
  1614. }
  1615. if($("#mul_type").length)
  1616. {
  1617. $("#mul_type").val(1);
  1618. }
  1619. }
  1620. else
  1621. {
  1622. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1623. {
  1624. next.attr('disabled', true);
  1625. }
  1626. if($("#mul_type").length)
  1627. {
  1628. $("#mul_type").val(0);
  1629. }
  1630. }
  1631. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1632. inputShow($(this), 'col');
  1633. }
  1634. })
  1635. });
  1636. checkbox.each(function()
  1637. {
  1638. var self = $(this);
  1639. var len = $("." + name + "-" + self.val()).length;
  1640. $("." + name + "-" + self.val()).each(function()
  1641. {
  1642. $(this).unbind('click').bind('click', function()
  1643. {
  1644. var next = $(this).next();
  1645. var state = $(this).attr('data-state');
  1646. if($(this).get(0).checked == true)
  1647. {
  1648. if (state == 2) {
  1649. self.get(0).checked = true;
  1650. } else {
  1651. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1652. self.get(0).checked = true;
  1653. }
  1654. }
  1655. if(self.attr('type') == 'radio')
  1656. {
  1657. //如果父选项是radio类型,做下限制
  1658. //alert(1);
  1659. }
  1660. if($("#mul_type").length)
  1661. {
  1662. $("#mul_type").val(1);
  1663. }
  1664. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1665. {
  1666. next.attr('disabled', false);
  1667. }
  1668. }
  1669. else
  1670. {
  1671. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1672. {
  1673. next.attr('disabled', true);
  1674. }
  1675. }
  1676. var num = 0;
  1677. $("." + name + "-" + self.val()).each(function()
  1678. {
  1679. if($(this).get(0).checked == true)
  1680. {
  1681. num = 1;
  1682. }
  1683. });
  1684. var id = $(this).attr('name');
  1685. var hidden = id;
  1686. id = id.replace('[]', '');
  1687. if(num == 0)
  1688. {
  1689. self.get(0).checked = false;
  1690. if($("#mul_type").length)
  1691. {
  1692. $("#mul_type").val(0);
  1693. }
  1694. if (state == 2) {
  1695. } else if (!$('#' + id).length) {
  1696. //self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  1697. }
  1698. } else {
  1699. /*
  1700. if ($('#' + id).length) {
  1701. $('#' + id).remove();
  1702. }*/
  1703. }
  1704. })
  1705. if($(this).get(0).checked == true)
  1706. {
  1707. self.get(0).checked = true;
  1708. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1709. inputShow($(this), 'col');
  1710. }
  1711. }
  1712. });
  1713. })
  1714. }
  1715. }
  1716. }
  1717. /**
  1718. * 处理双击编辑
  1719. */
  1720. function edit()
  1721. {
  1722. if($(".edit").length)
  1723. {
  1724. $(".edit").each(function()
  1725. {
  1726. $(this).bind('dblclick', function()
  1727. {
  1728. var col = $(this).attr('data-col');
  1729. var project = $(this).attr('data-project');
  1730. var table = $(this).attr('data-table');
  1731. var url = $(this).attr('data-url');
  1732. var id = $(this).attr('data-id');
  1733. var html = $(this).attr('data-content');
  1734. var type = $(this).attr('data-type');
  1735. if($(this).find(".edit-content").length)
  1736. {
  1737. html = $(this).find(".edit-content").html();
  1738. html = html.replace('<!--', '<');
  1739. html = html.replace('-->', '>');
  1740. }
  1741. if (html == '点此编辑') {
  1742. html = '';
  1743. }
  1744. if(html.indexOf('input') == -1)
  1745. {
  1746. if(type && type == 'textarea')
  1747. {
  1748. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1749. }
  1750. else
  1751. {
  1752. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1753. }
  1754. var self = $(this);
  1755. self.find("#edit").focus();
  1756. self.find("#edit").blur(function()
  1757. {
  1758. var value = self.find("#edit").val();
  1759. if(!value)
  1760. {
  1761. alert('不能为空');
  1762. return;
  1763. }
  1764. if($(this).find(".edit-content").length)
  1765. {
  1766. $(this).find(".edit-content").html(value);
  1767. }
  1768. else
  1769. {
  1770. self.attr('data-content', value);
  1771. }
  1772. self.html(value);
  1773. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1774. {
  1775. notify('修改成功', self);
  1776. preview();
  1777. /*
  1778. if(type && type == 'textarea')
  1779. {
  1780. self.html(t);
  1781. }
  1782. */
  1783. })
  1784. })
  1785. }
  1786. });
  1787. })
  1788. }
  1789. }
  1790. function preview()
  1791. {
  1792. if($("#preview").length)
  1793. {
  1794. var time = Date.parse(new Date());
  1795. var src = $('#preview').attr('src').split('#');
  1796. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1797. }
  1798. }
  1799. function del()
  1800. {
  1801. if($(".oper_delete").length)
  1802. {
  1803. $(".oper_delete").each(function()
  1804. {
  1805. var href = $(this).attr('href');
  1806. $(this).attr('href', '#');
  1807. $(this).unbind('click');
  1808. $(this).bind('click', function()
  1809. {
  1810. del_act(href);
  1811. });
  1812. })
  1813. }
  1814. }
  1815. /**
  1816. * 处理删除
  1817. */
  1818. function del_act(href)
  1819. {
  1820. var index = layer.confirm('确定进行此项操作吗?', function(i, l)
  1821. {
  1822. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  1823. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1824. {
  1825. msg(t);
  1826. layer.close(index);
  1827. })
  1828. });
  1829. }
  1830. /**
  1831. * 处理特殊加载的按钮
  1832. */
  1833. function load(href, content, title)
  1834. {
  1835. if (!content) {
  1836. content = '确定进行此项操作吗?';
  1837. }
  1838. if (!title) {
  1839. title = '温馨提示';
  1840. }
  1841. var i = 0;
  1842. var flag = false;
  1843. var send = {title:title}
  1844. var index = layer.confirm(content, send, function(i, l)
  1845. {
  1846. if (!flag) {
  1847. i++;
  1848. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  1849. if(href.indexOf('&') == -1)
  1850. {
  1851. href += '?json=1&callback=?';
  1852. }
  1853. else
  1854. {
  1855. href += '&json=1&callback=?';
  1856. }
  1857. $.getJSON(href, {}, function(t)
  1858. {
  1859. if (t.status == 2) {
  1860. flag = false;
  1861. showAlert(t.msg, false, '错误提示');
  1862. return;
  1863. } else {
  1864. // 修改标志位
  1865. flag = true;
  1866. msg(t);
  1867. layer.close(index);
  1868. //location.reload();
  1869. }
  1870. })
  1871. }
  1872. })
  1873. /*
  1874. showAlert('确定进行此项操作吗?', function()
  1875. {
  1876. $("#dever_modal_no").click();
  1877. $.getJSON(href + '&json=1', {}, function(t)
  1878. {
  1879. msg(t);
  1880. })
  1881. });
  1882. */
  1883. }
  1884. /**
  1885. * 处理特殊页面
  1886. */
  1887. function loadPage(href, title, submit)
  1888. {
  1889. if(href.indexOf('&') == -1)
  1890. {
  1891. href += '?json=1&callback=?';
  1892. }
  1893. else
  1894. {
  1895. href += '&json=1&callback=?';
  1896. }
  1897. $.getJSON(href, {}, function(t)
  1898. {
  1899. var func = false;
  1900. if (submit) {
  1901. }
  1902. showAlert(t.data, func, title);
  1903. })
  1904. }
  1905. /**
  1906. * 处理特殊加载的按钮
  1907. */
  1908. function jump(href, form)
  1909. {
  1910. if (form) {
  1911. var param = formData(form);
  1912. href += param[1];
  1913. }
  1914. if (href.indexOf('list_excel') != -1) {
  1915. layer.confirm('确认导出数据吗?', function()
  1916. {
  1917. Excel.export(href);
  1918. })
  1919. } else {
  1920. location.href = href;
  1921. }
  1922. }
  1923. /**
  1924. * 处理change
  1925. */
  1926. function change()
  1927. {
  1928. if($(".change").length)
  1929. {
  1930. $(".change").each(function()
  1931. {
  1932. var key = $(this).attr('data-child');
  1933. /*
  1934. $('.' + key).each(function()
  1935. {
  1936. if($(this).find('select option:selected').val())
  1937. {
  1938. $(this).show();
  1939. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1940. }
  1941. });
  1942. */
  1943. $(this).change(function()
  1944. {
  1945. $('.' + key).hide();
  1946. var v = $('.' + key + '_' + $(this).val());
  1947. var s = v.find('select');
  1948. s.change(function()
  1949. {
  1950. $('.' + key + '_value').val($(this).val());
  1951. })
  1952. if(v.length)
  1953. {
  1954. $('.' + key + '_value').val(s.val());
  1955. v.show();
  1956. }
  1957. else
  1958. {
  1959. $('.' + key + '_value').val(-1);
  1960. }
  1961. });
  1962. if($(this).val() > 0)
  1963. {
  1964. $(this).change();
  1965. }
  1966. });
  1967. }
  1968. }
  1969. /**
  1970. * 处理图库系统
  1971. */
  1972. function image()
  1973. {
  1974. if($(".dever-note").length)
  1975. {
  1976. $(".dever-note").each(function()
  1977. {
  1978. var key = $(this).attr('key');
  1979. $(this).inlineattachment(
  1980. {
  1981. uploadUrl: config.upload + '.drag?key='+ key
  1982. });
  1983. });
  1984. }
  1985. if($(".image_upload").length)
  1986. {
  1987. $(".image_upload").each(function(i)
  1988. {
  1989. //如果是大文件
  1990. if ($(this).attr('l')) {
  1991. loadUploadL(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');
  1992. } else {
  1993. var parent = $(this).parent().parent();
  1994. //alert(parent.attr('id'));
  1995. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  1996. {
  1997. return;
  1998. }
  1999. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2000. }
  2001. })
  2002. }
  2003. if($(".upload_show").length)
  2004. {
  2005. $(".upload_show").each(function(i)
  2006. {
  2007. var parent = $(this).parent().parent();
  2008. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  2009. {
  2010. return;
  2011. }
  2012. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2013. })
  2014. }
  2015. if($(".upload_cover").length)
  2016. {
  2017. $(".upload_cover").each(function(i)
  2018. {
  2019. var parent = $(this).parent().parent();
  2020. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  2021. {
  2022. return;
  2023. }
  2024. showUploadCover(i,$(this),$(this).attr('key'),config.upload + '.videoCover', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2025. })
  2026. }
  2027. if($(".upload_show_editor").length)
  2028. {
  2029. $(".upload_show_editor").each(function(i)
  2030. {
  2031. var parent = $(this).parent().parent();
  2032. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  2033. {
  2034. return;
  2035. }
  2036. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 3);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2037. })
  2038. }
  2039. }
  2040. /**
  2041. * 修改密码
  2042. */
  2043. function pass(e)
  2044. {
  2045. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  2046. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  2047. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  2048. html += '</div>';
  2049. var edit = function()
  2050. {
  2051. var old_password = $("#edit_old_password").val();
  2052. var new_password = $("#edit_new_password").val();
  2053. if(!old_password || !new_password)
  2054. {
  2055. alert('请输入密码');
  2056. return;
  2057. }
  2058. if(old_password == new_password)
  2059. {
  2060. alert('旧密码和新密码相同');
  2061. return;
  2062. }
  2063. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  2064. {
  2065. alert(t);
  2066. })
  2067. };
  2068. showAlert(html, edit, '修改密码');
  2069. /*
  2070. $('#dever_modal_body').html(html);
  2071. $('#dever_modal_title').html('修改密码');
  2072. */
  2073. }
  2074. var MSG = [];
  2075. /**
  2076. * 打开弹窗
  2077. */
  2078. //function showMsg(title, e, id, func)
  2079. function showMsg(title, e, id, func, param)
  2080. {
  2081. if(id.indexOf('http://') == -1)
  2082. {
  2083. if($(id).length)
  2084. {
  2085. var html = $(id).html();
  2086. if($(id).html())
  2087. {
  2088. var html = $(id).html();
  2089. MSG[id] = html;
  2090. $(id).html('');
  2091. }
  2092. else
  2093. {
  2094. var html = MSG[id];
  2095. }
  2096. }
  2097. else
  2098. {
  2099. var html = id;
  2100. }
  2101. showAlert(html, func, title);
  2102. /*
  2103. $('#dever_modal_body').html(html);
  2104. $('#dever_modal_title').html(title);
  2105. if (func) {
  2106. $("#dever_modal_yes").unbind('click').bind('click', func);
  2107. } else {
  2108. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  2109. }
  2110. */
  2111. }
  2112. else
  2113. {
  2114. var url = id;
  2115. var send = {};
  2116. if (param) {
  2117. send = param;
  2118. }
  2119. if (e && e.attr('msg-send')) {
  2120. send.data = e.attr('msg-send');
  2121. }
  2122. if (url.indexOf('?') != -1) {
  2123. url = url + '&';
  2124. } else {
  2125. url = url + '?';
  2126. }
  2127. $.getJSON(url+'json=1&callback=?',send,function(t)
  2128. {
  2129. t = t.data;
  2130. showAlert(t, func, t);
  2131. /*
  2132. $('#dever_modal_body').html(t);
  2133. $('#dever_modal_title').html(title);
  2134. if(func)
  2135. {
  2136. $("#dever_modal_yes").unbind('click').bind('click', func);
  2137. }
  2138. */
  2139. });
  2140. }
  2141. }
  2142. function updateMsg(id)
  2143. {
  2144. $("#"+id).submit();
  2145. }
  2146. var showAlertFlag = false;
  2147. function showAlert(msg, func, title, index, t)
  2148. {
  2149. if (!title) {
  2150. title = '温馨提示';
  2151. }
  2152. var type = 0;
  2153. if (msg.indexOf('<') != -1) {
  2154. type = 1;
  2155. }
  2156. if (t) {
  2157. type = t;
  2158. }
  2159. var config = {
  2160. type: 0,
  2161. title: title,
  2162. shade: 0.1,
  2163. shadeClose : true,
  2164. content: msg
  2165. };
  2166. if (index) {
  2167. config.zIndex = index;
  2168. }
  2169. config.scrollbar = false;
  2170. if (type == 1) {
  2171. config.type = 1;
  2172. config.btn = ['保存', '关闭'];
  2173. if (func) {
  2174. config.area = ['800px', '550px'];
  2175. config.btn = ['保存', '关闭'];
  2176. } else {
  2177. config.area = ['800px', '550px'];
  2178. config.btn = ['关闭'];
  2179. }
  2180. } else if (type == 2) {
  2181. config.type = 1;
  2182. config.btn = [];
  2183. config.area = ['800px', '550px'];
  2184. }
  2185. config.cancel = config.btn2 = function(index)
  2186. {
  2187. layer.close(index);
  2188. };
  2189. if (func) {
  2190. config.yes = function(index)
  2191. {
  2192. if (!showAlertFlag) {
  2193. showAlertFlag = true;
  2194. func(index);
  2195. }
  2196. };
  2197. } else {
  2198. config.yes = config.cancel;
  2199. }
  2200. config.success = function() {
  2201. //$('.layui-layer-content').css('padding', '10px');
  2202. }
  2203. config.end = function() {
  2204. $('.layui-layer-content').css('overflow-x', 'auto');
  2205. $('#update_button').show();
  2206. }
  2207. var index = layer.open(config);
  2208. }
  2209. function fastEdit(e, url, title, col, index, type)
  2210. {
  2211. var func = function()
  2212. {
  2213. $(".fast").submit();
  2214. };
  2215. var send = {};
  2216. if (col) {
  2217. send.col = col;
  2218. }
  2219. $.get(url + '&fast=1',send,function(t)
  2220. {
  2221. var html = '';
  2222. var valid = '';
  2223. var action = '';
  2224. //if ($(t).find('form').length && !$(t).find('#form1').length) {
  2225. if ($(t).find('form').length) {
  2226. if ($(t).find('form').length > 1 && $(t).find('form').eq(1).html()) {
  2227. var form_1 = $(t).find('form').eq(1);
  2228. form_1.addClass('layui-card-body');
  2229. } else {
  2230. var form_1 = $(t).find('form').eq(0);
  2231. }
  2232. action = form_1.attr('action');
  2233. form_1.addClass('fast');
  2234. form_1.find('#function').eq(0).val('showYes');
  2235. var html = form_1.prop("outerHTML");
  2236. if ($(t).find('#valid').length) {
  2237. var valid = $(t).find('#valid').prop("outerHTML");
  2238. html = html + valid;
  2239. }
  2240. if (html.indexOf('left: 740px') != -1) {
  2241. html = html.replace('left: 740px', 'left:583px;')
  2242. }
  2243. if ($(t).find('.dever_no_save').length) {
  2244. func = false;
  2245. }
  2246. } else {
  2247. html = t;
  2248. func = false;
  2249. }
  2250. /*
  2251. if ($(html).find('.layui-card-body').length > 0) {
  2252. html = html.replace('class="layui-card-body"', 'class="layui-card-body" style="display:none"');
  2253. html = html.replaceAll('class="layui-btn layuiadmin-btn-list"', 'class="layui-btn layuiadmin-btn-list" style="display:none"');
  2254. }
  2255. */
  2256. if (!action) {
  2257. type = 2;
  2258. func = false;
  2259. }
  2260. showAlertFlag = false;
  2261. if (index == 1) {
  2262. showAlert(html, func, title, 19850422, type);
  2263. } else {
  2264. showAlert(html, func, title, false, type);
  2265. }
  2266. $('.layui-layer-content').css('overflow-x', 'hidden');
  2267. if ($('#update_button').length) {
  2268. $('#update_button').hide();
  2269. }
  2270. layui.use(['form'], function(){
  2271. layui.form.render();
  2272. /*
  2273. $('select').each(function() {
  2274. if ($(this).attr('xm-select')) {
  2275. layui.formSelects.render($(this).attr('xm-select'));
  2276. }
  2277. });*/
  2278. });
  2279. init(560);
  2280. });
  2281. }
  2282. /*
  2283. var test =
  2284. {
  2285. refreshPage: false,
  2286. addAjaxFlag: true,
  2287. //添加收藏
  2288. add: function(cfg)
  2289. {
  2290. }
  2291. }
  2292. */
  2293. function showToggle(e)
  2294. {
  2295. var id = e.attr('toggle');
  2296. var child = e.attr('toggle_child');
  2297. var parent = e.parent();
  2298. parent.parent().find('li').removeClass('active');
  2299. parent.addClass('active');
  2300. $(child).fadeOut(100);
  2301. $(id).fadeIn(500);
  2302. initEditor($(id).find('.editor'));
  2303. }
  2304. function addChange(e)
  2305. {
  2306. var val = e.val();
  2307. if (val == 0) {
  2308. var o = e.find('option:selected');
  2309. var type = o.attr('data-type');
  2310. if (type && type == 'add') {
  2311. var url = o.attr('data-url');
  2312. var p = e.parent();
  2313. if (p.find('.addchange').length < 1) {
  2314. p.html(p.html() + '<div class="addchange" style="display: inline-block;margin-left: 10px;"></div>');
  2315. }
  2316. var id = e.attr('id');
  2317. 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>');
  2318. }
  2319. e.val('0');
  2320. }
  2321. }
  2322. function addChangeAction(url, id, self)
  2323. {
  2324. var send = {};
  2325. var e = $('#' + id);
  2326. send.value = $('#add_' + id).val();
  2327. if (!send.value) {
  2328. layer.alert('没有填写内容');
  2329. return;
  2330. }
  2331. send.json = 1;
  2332. $.getJSON(url, send, function(t)
  2333. {
  2334. if (t.status == 1) {
  2335. e.append('<option value="'+t.data.id+'">'+send.value+'</option>');
  2336. e.val(t.data.id);
  2337. self.parent().remove();
  2338. } else {
  2339. layer.alert(t.msg);
  2340. }
  2341. });
  2342. }
  2343. function loadChange(e, load)
  2344. {
  2345. if (e.attr('v')) {
  2346. var val = e.attr('v');
  2347. } else {
  2348. var val = e.val();
  2349. }
  2350. showLoad(load, [val]);
  2351. }
  2352. function showLoad(id, value)
  2353. {
  2354. var e = $('#update_' + id);
  2355. if (!value) {
  2356. e.html('');
  2357. return;
  2358. }
  2359. e.html('加载中...');
  2360. var url = e.attr("data-load");
  2361. var cate = e.attr("data-cate");
  2362. var id = e.attr("data-id");
  2363. var send = {};
  2364. send['json'] = 1;
  2365. if (cate) {
  2366. send[cate] = value.join(',');
  2367. }
  2368. if (id) {
  2369. send['id'] = id;
  2370. }
  2371. $.getJSON(url, send, function(t)
  2372. {
  2373. if (t.status == 1) {
  2374. if (t.data == 'no') {
  2375. if (e.html() == '加载中...') {
  2376. e.html('');
  2377. }
  2378. } else {
  2379. e.html(t.data);
  2380. }
  2381. } else {
  2382. e.html('');
  2383. }
  2384. layui.use(['form'], function(){
  2385. layui.form.render();
  2386. });
  2387. checkbox();
  2388. });
  2389. }
  2390. var level_value = [];
  2391. var select_api = {};
  2392. var select_api_name = [];
  2393. var select_api_title = '';
  2394. var select_api_open = '';
  2395. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param, col, api, type, title, open, load)
  2396. {
  2397. var e = '#' + id;
  2398. var parent = value.split(',');
  2399. var cur = parent[0];
  2400. parent.remove(cur);
  2401. value = parent.join(',');
  2402. var html = '';
  2403. var old = level;
  2404. var level_name = '';
  2405. if (!total) {
  2406. level_id = 0;
  2407. } else {
  2408. level_id = $(e + '_' + level).val();
  2409. if (level_id.indexOf('|') != -1) {
  2410. var temp = level_id.split('|');
  2411. if (level == 1) {
  2412. select_api_name = [];
  2413. }
  2414. level_id = temp[0];
  2415. level_name = temp[1];
  2416. select_api_name[level-1] = level_name;
  2417. }
  2418. if (level >= total) {
  2419. //$(e).show();
  2420. if (load) {
  2421. var key = total-1;
  2422. if (level_value[key]) {
  2423. level_value[key] = level_id;
  2424. } else {
  2425. level_value.push(level_id);
  2426. }
  2427. showLoad(load, level_value);
  2428. }
  2429. return;
  2430. }
  2431. level = parseInt(level) + 1;
  2432. }
  2433. var api_name = '';
  2434. if (col && api) {
  2435. select_api_title = title;
  2436. select_api_open = open;
  2437. if (name.indexOf('_no') == -1) {
  2438. api_name = name;
  2439. } else {
  2440. var t = name.split('_no');
  2441. api_name = t[0];
  2442. }
  2443. name += '_no';
  2444. }
  2445. $.getJSON(url + '&json=1&callback=?', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  2446. var check = '';
  2447. if (t.status == 1) {
  2448. if (level == 2) {
  2449. level_value = [];
  2450. }
  2451. if (load && level_id > 0) {
  2452. level_value.push(level_id);
  2453. showLoad(load, level_value);
  2454. }
  2455. var total = t.data.level_total;
  2456. var data = t.data.list;
  2457. if(!$(e + '_' + level).length) {
  2458. 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+'\');">';
  2459. }
  2460. for (a in data) {
  2461. if (data[a].value) {
  2462. check = '';
  2463. if (cur == data[a].value) {
  2464. check = ' selected';
  2465. }
  2466. var v = data[a].value;
  2467. if (col && api) {
  2468. v = data[a].value + '|' + data[a].name;
  2469. }
  2470. html += '<option value="'+v+'" '+check+'>'+data[a].name+'</option>';
  2471. }
  2472. }
  2473. if(!$(e + '_' + level).length) {
  2474. html += '</select><span>&nbsp;&nbsp;</span>';
  2475. $(e).append(html);
  2476. $(e + '_' + level).change();
  2477. } else {
  2478. $(e + '_' + level).html(html);
  2479. $(e + '_' + level).change();
  2480. }
  2481. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  2482. } else {
  2483. if (level == 2) {
  2484. level_value = [];
  2485. if (load && level_id < 0) {
  2486. showLoad(load, false);
  2487. }
  2488. }
  2489. if (load && level_id > 0) {
  2490. level_value.push(level_id)
  2491. showLoad(load, level_value);
  2492. }
  2493. $(e + '_' + old).nextAll('select').remove();
  2494. $(e + '_' + old).next('span').nextAll('span').remove();
  2495. }
  2496. if (col && api && level_id > 0) {
  2497. var send = {};
  2498. send[col] = level_id;
  2499. $.getJSON(api + '&json=1&callback=?', send, function(r) {
  2500. var h = '<ul style="list-style:none;margin-top: 20px;display:;" class="">';
  2501. if (type == 'checkbox') {
  2502. 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>';
  2503. }
  2504. for (var i in r.data) {
  2505. if (r.data[i]['name']) {
  2506. var checked = false;
  2507. 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) {
  2508. checked = true;
  2509. }
  2510. 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>';
  2511. }
  2512. }
  2513. h += '</ul>';
  2514. $(e + '_content').html(h);
  2515. });
  2516. }
  2517. /*
  2518. if ($('#' + name + '_level_value').length) {
  2519. var total = $(id).find('select').length;
  2520. $('#' + name + '_level_value').val(total);
  2521. }
  2522. if ($('#' + name + '_up_value').length) {
  2523. $('#' + name + '_up_value').val($(id + '_-2').val());
  2524. }
  2525. */
  2526. });
  2527. if (col && api) {
  2528. select_linkage_check_show(e, api_name);
  2529. }
  2530. }
  2531. function select_linkage_check_all(e, cur, level_id, level_name, id, api_name)
  2532. {
  2533. var checked = e.prop('checked');
  2534. $('.' + cur).each(function() {
  2535. $(this).prop('checked', checked);
  2536. select_linkage_check($(this), level_id, level_name, id, api_name);
  2537. })
  2538. }
  2539. function select_linkage_check(e, level_id, level_name, id, api_name, cid)
  2540. {
  2541. var level_key = 'level_' + level_id;
  2542. if (!select_api[level_key]) {
  2543. select_api[level_key] = {};
  2544. select_api[level_key]['id'] = level_id;
  2545. select_api[level_key]['name'] = level_name;
  2546. select_api[level_key]['value'] = {};
  2547. }
  2548. var value = e.val();
  2549. var temp = value.split('|');
  2550. var key = 'id_' + temp[0];
  2551. if (e.prop('checked')) {
  2552. select_api[level_key]['value'][key] = {};
  2553. select_api[level_key]['value'][key]['id'] = temp[0];
  2554. select_api[level_key]['value'][key]['name'] = temp[1];
  2555. select_api[level_key]['value'][key]['state'] = 1;
  2556. } else {
  2557. if (select_api[level_key] && select_api[level_key]['value'] && select_api[level_key]['value'][key]) {
  2558. select_api[level_key]['value'][key]['state'] = 2;
  2559. }
  2560. if (cid) {
  2561. $(cid).prop('checked', false);
  2562. }
  2563. }
  2564. select_linkage_check_show(id, api_name);
  2565. }
  2566. function select_linkage_check_show(id, api_name)
  2567. {
  2568. if (select_api) {
  2569. var select_api_json = JSON.stringify(select_api);
  2570. var html = '<div style="margin-top: 20px;display:;border: 1px solid #5050b1;padding: 10px;">';
  2571. for (var i in select_api) {
  2572. if (select_api[i]['value']) {
  2573. html += '[' + select_api[i]['name'] + ']:<ul style="list-style:none;" class="">';
  2574. for (var j in select_api[i]['value']) {
  2575. var n = '&nbsp;&nbsp;' + select_api[i]['value'][j]['name'];
  2576. if (select_api_open) {
  2577. var o = select_api_open.replace('{id}', select_api[i]['value'][j]['id']);
  2578. n = '<a href="javascript:;" onclick="fastEdit($(this), \''+o+'\', \''+select_api_title+'\', \'\', 1,1)">'+n+'</a>';
  2579. }
  2580. if (select_api[i]['value'][j]['state'] == 2) {
  2581. n += '[已删除]';
  2582. var checked = false;
  2583. } else {
  2584. var checked = true;
  2585. }
  2586. 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>';
  2587. }
  2588. html += '</ul>';
  2589. }
  2590. }
  2591. html += '</div>';
  2592. html += '<textarea name="'+api_name+'" style="display:none">'+select_api_json+'</textarea>';
  2593. $(id + '_data').html(html);
  2594. }
  2595. }
  2596. /*
  2597. function select_mul(level, id, url, name, value, valid, w, num)
  2598. {
  2599. if(level == 0)
  2600. {
  2601. $(id).find('select').remove();
  2602. $(id).find('span').remove();
  2603. return;
  2604. }
  2605. var parent = value.split(',');
  2606. var cur = parent[0];
  2607. parent.remove(cur);
  2608. value = parent.join(',');
  2609. var html = '';
  2610. var old = level;
  2611. if(level != -1)
  2612. {
  2613. if($(id + '_' + level).length)
  2614. {
  2615. level = $(id + '_' + level).val();
  2616. }
  2617. alert(level);
  2618. if(level == 0)
  2619. {
  2620. $(id + '_' + old).nextAll('select').remove();
  2621. $(id + '_' + old).next('span').nextAll('span').remove();
  2622. if($('#' + name + '_level_value').length)
  2623. {
  2624. var total = $(id).find('select').length;
  2625. $('#' + name + '_level_value').val(total);
  2626. }
  2627. if(old == -2 && $('#' + name + '_value_value').length)
  2628. {
  2629. $('#' + name + '_value_value').val(level);
  2630. }
  2631. return;
  2632. }
  2633. if(old == -2)
  2634. {
  2635. $(id + '_' + old).nextAll('select').remove();
  2636. $(id + '_' + old).next('span').nextAll('span').remove();
  2637. }
  2638. if($('#' + name + '_value_value').length)
  2639. {
  2640. $('#' + name + '_value_value').val(level);
  2641. }
  2642. }
  2643. var total = $(id).find('select').length;
  2644. if(num > 0 && total >= num)
  2645. {
  2646. return;
  2647. }
  2648. var get = url.replace('{level}', level);
  2649. if(level == -1)
  2650. {
  2651. level = -2;
  2652. }
  2653. if(!$(id + '_' + level).length)
  2654. {
  2655. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  2656. {
  2657. var check = '';
  2658. if(t.status == 1)
  2659. {
  2660. 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+');">';
  2661. console.log(t.data);
  2662. for(a in t.data)
  2663. {
  2664. if(t.data[a].value)
  2665. {
  2666. check = '';
  2667. if(cur == t.data[a].value)
  2668. {
  2669. check = ' selected';
  2670. }
  2671. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  2672. }
  2673. }
  2674. html += '</select><span>&nbsp;&nbsp;</span>';
  2675. $(id).append(html);
  2676. $(id + '_' + level).change();
  2677. }
  2678. else
  2679. {
  2680. $(id + '_' + old).nextAll('select').remove();
  2681. $(id + '_' + old).next('span').nextAll('span').remove();
  2682. }
  2683. if($('#' + name + '_level_value').length)
  2684. {
  2685. var total = $(id).find('select').length;
  2686. $('#' + name + '_level_value').val(total);
  2687. }
  2688. if($('#' + name + '_up_value').length)
  2689. {
  2690. $('#' + name + '_up_value').val($(id + '_-2').val());
  2691. }
  2692. });
  2693. }
  2694. }
  2695. */
  2696. //处理更新页面的一些功能,写到一起吧
  2697. var dever_update =
  2698. {
  2699. addIndex : 2,
  2700. index : [],
  2701. auto : false,
  2702. save_key : '',
  2703. init : function()
  2704. {
  2705. var self = this;
  2706. self.index = [];
  2707. // 增加整个更新的表单
  2708. if($(".dever_update_add").length)
  2709. {
  2710. $('.dever_update_add').unbind('click').bind('click', function()
  2711. {
  2712. self.add($(this));
  2713. })
  2714. }
  2715. /* 以后再增加 同时更新另外一个表
  2716. if($(".form-add-content").length)
  2717. {
  2718. var url = config.host + 'auth.password';
  2719. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  2720. $.get(url, function(t)
  2721. {
  2722. $(".form-add-content").html(t);
  2723. init();
  2724. })
  2725. }
  2726. */
  2727. //增加某一部分表单
  2728. if($(".dever_form_add").length)
  2729. {
  2730. $('.dever_form_add').each(function()
  2731. {
  2732. var key = $.attr('toggle_key');
  2733. if(typeof(self.index[key]) == "undefined")
  2734. {
  2735. self.index[key] = 0;
  2736. }
  2737. $(this).unbind('click').bind('click', function()
  2738. {
  2739. self.append($(this));
  2740. })
  2741. })
  2742. self.del();
  2743. }
  2744. // 开启自动保存
  2745. if($("#struct").length)
  2746. {
  2747. var save = $("#struct").attr('save');
  2748. if(save == 'yes')
  2749. {
  2750. //检测
  2751. self.save_key = location.href + 'test';
  2752. self.check();
  2753. }
  2754. }
  2755. if($('.dever-note').length)
  2756. {
  2757. $('.dever-note').each(function()
  2758. {
  2759. var mditor = new Mditor($(this),{
  2760. fixedHeight:true
  2761. });
  2762. mditor.openPreview();
  2763. })
  2764. }
  2765. },
  2766. save : function()
  2767. {
  2768. //var data = $("#data-1").html();
  2769. var data = [];
  2770. $(".update_value").each(function(i)
  2771. {
  2772. if($(this).attr("update_type") == 'checked')
  2773. {
  2774. data[i] = $(this).get(0).checked;
  2775. }
  2776. else if($(this).attr("update_type") == 'html')
  2777. {
  2778. data[i] = $(this).html();
  2779. }
  2780. else if($(this).attr("update_type") == 'src')
  2781. {
  2782. data[i] = $(this).attr('src');
  2783. }
  2784. else
  2785. {
  2786. data[i] = $(this).val();
  2787. }
  2788. });
  2789. store.set(this.save_key, data.join('|||'));
  2790. //console.info(data);
  2791. },
  2792. recover : function()
  2793. {
  2794. var index = layer.confirm('确定恢复上次保存的数据吗?', function(i, l)
  2795. {
  2796. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  2797. var data = store.get(this.save_key).split('|||');
  2798. if(data)
  2799. {
  2800. var value = $(".update_value");
  2801. for(var k in data)
  2802. {
  2803. var e = value.eq(k);
  2804. if(e.attr('update_type') == 'checked')
  2805. {
  2806. if(data[k] == 'true')
  2807. {
  2808. e.get(0).checked = true;
  2809. }
  2810. else
  2811. {
  2812. e.get(0).checked = false;
  2813. }
  2814. }
  2815. else if(e.attr('update_type') == 'html')
  2816. {
  2817. e.html(data[k]);
  2818. }
  2819. else if(e.attr('update_type') == 'src')
  2820. {
  2821. e.attr('src', data[k]);
  2822. }
  2823. else
  2824. {
  2825. if(e.attr('id'))
  2826. {
  2827. var id = e.attr('id');
  2828. if(typeof(editors[id]) != "undefined")
  2829. {
  2830. editors[id].html(data[k]);
  2831. }
  2832. }
  2833. e.val(data[k]);
  2834. }
  2835. }
  2836. store.set(this.save_key, '');
  2837. this.check();
  2838. }
  2839. })
  2840. },
  2841. check : function()
  2842. {
  2843. var data = store.get(this.save_key);
  2844. var self = this;
  2845. if(data)
  2846. {
  2847. $(".dever_save").unbind('click').bind('click', function()
  2848. {
  2849. self.recover();
  2850. }).show();
  2851. }
  2852. else
  2853. {
  2854. $(".dever_save").hide();
  2855. self.auto = setInterval(function(){self.save()}, 3000);
  2856. }
  2857. },
  2858. del : function()
  2859. {
  2860. var self = this;
  2861. if($(".dever_form_delete").length)
  2862. {
  2863. $('.dever_form_delete').each(function()
  2864. {
  2865. $(this).unbind('click').bind('click', function()
  2866. {
  2867. var parent = $(this).parent();
  2868. var id = parent.attr('id');
  2869. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  2870. var key = $('#tab-' + id).attr('toggle_key');
  2871. if(index <= 1 && self.index[key] <= index)
  2872. {
  2873. }
  2874. else if(index <= 1 && self.index[key] > index)
  2875. {
  2876. index = index+1;
  2877. $("#tab-"+key+"-child-" + index).click();
  2878. }
  2879. else
  2880. {
  2881. index = index-1;
  2882. $("#tab-"+key+"-child-" + index).click();
  2883. };
  2884. $('#tab-' + id).parent().remove();
  2885. parent.remove();
  2886. self.index[key]--;
  2887. })
  2888. })
  2889. }
  2890. },
  2891. append : function(e)
  2892. {
  2893. var self = this;
  2894. var key = e.attr('toggle_key');
  2895. var parent = e.parent().parent().parent();
  2896. var child = '.dever_'+key+'_child';
  2897. if(typeof(self.index[key]) == "undefined")
  2898. {
  2899. self.index[key] = 0;
  2900. }
  2901. if (isNaN(self.index[key])) {
  2902. self.index[key] = 0;
  2903. }
  2904. if(self.index[key] <= 0)
  2905. {
  2906. self.index[key] = parent.find(child).length;
  2907. }
  2908. if(self.index[key] > 100)
  2909. {
  2910. layer.showAlert('最多只能增加100条');
  2911. return;
  2912. }
  2913. var p = e.parent();
  2914. var id = key + '-child-' + self.index[key];
  2915. var name = '第' + (self.index[key]) + '条';
  2916. 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>');
  2917. var e = e.parent().parent();
  2918. var n = e.next();
  2919. var p = e.parent();
  2920. var content = n.html();
  2921. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  2922. var cname = n.attr('class');
  2923. if (cname.indexOf('layui-tab') > -1) {
  2924. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+'">' + content + '</div>';
  2925. } else {
  2926. //content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  2927. content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+'">' + content + '</div>';
  2928. }
  2929. p.append(content);
  2930. if ($("#" + id).find('.ke-container').length >= 1) {
  2931. $("#" + id).find('.ke-container').eq(0).remove();
  2932. }
  2933. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order').val())+1);
  2934. self.del();
  2935. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  2936. self.index[key]++;
  2937. image();
  2938. loadShow();
  2939. autocomplete();
  2940. change();
  2941. form.render();
  2942. initPic();
  2943. initDate();
  2944. /*
  2945. layui.use(['formSelects'], function(){
  2946. $('#' + id + " select").each(function()
  2947. {
  2948. if ($(this).attr('xm-select')) {
  2949. layui.formSelects.render($(this).attr('xm-select'));
  2950. }
  2951. })
  2952. });
  2953. */
  2954. },
  2955. add : function(e)
  2956. {
  2957. var self = this;
  2958. var p = e.parent();
  2959. var id = 'data-' + this.addIndex;
  2960. var name = '新增数据-' + (this.addIndex-1);
  2961. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  2962. var content = $("#content").find('.tab-pane').eq(0).html();
  2963. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  2964. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  2965. $("#content").append(content);
  2966. $('#update_' + this.addIndex + '__where_id').val('-1');
  2967. this.addIndex++;
  2968. }
  2969. }
  2970. $.fn.pasteEvents = function( delay ) {
  2971. if (delay == undefined) delay = 20;
  2972. return $(this).each(function() {
  2973. var $el = $(this);
  2974. $el.on("paste", function() {
  2975. $el.trigger("prepaste");
  2976. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  2977. });
  2978. });
  2979. };
  2980. $("textarea").on("postpaste", function()
  2981. {
  2982. if($(this).val().indexOf('<') != -1)
  2983. {
  2984. $(this).val(toMarkdown($(this).val()));
  2985. }
  2986. }).pasteEvents();
  2987. function showYes(msg)
  2988. {
  2989. if (msg.msg == 'reload') {
  2990. location.reload();
  2991. return;
  2992. }
  2993. showAlertFlag = false;
  2994. if (msg.status == 2) {
  2995. list_mul_state = 1;
  2996. layer.alert(msg.msg);
  2997. } else {
  2998. showAlert('保存成功', function() {
  2999. if (select_api_open) {
  3000. $('.layui-layer-content').css('overflow-x', 'auto');
  3001. $('#update_button').show();
  3002. layer.closeAll();
  3003. } else {
  3004. if(msg.data.indexOf('http') != -1) {
  3005. location.href = msg.data;
  3006. } else if (msg.data && msg.data == 'refer') {
  3007. history.back();
  3008. } else {
  3009. location.reload();
  3010. }
  3011. }
  3012. });
  3013. }
  3014. }
  3015. function setDay(e, d)
  3016. {
  3017. $('#search_option_sday').val(d);
  3018. $('.sday_button').removeClass('sday_button_border');
  3019. e.addClass('sday_button_border');
  3020. var date = new Date();
  3021. var year = date.getFullYear();
  3022. var month = date.getMonth()+1;
  3023. var day = date.getDate();
  3024. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  3025. //获取30天前得日期
  3026. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  3027. var lastY = lastDate.getFullYear();
  3028. var lastM = lastDate.getMonth()+1;
  3029. var lastD = lastDate.getDate();
  3030. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  3031. $('.manage_sday').eq(0).val(LDate);
  3032. $('.manage_sday').eq(1).val(nowDate);
  3033. }
  3034. function setDate(e, d)
  3035. {
  3036. $('#search_option_sdate').val(d);
  3037. $('.sdate_button').removeClass('sdate_button_border');
  3038. e.addClass('sdate_button_border');
  3039. var date = new Date();
  3040. var year = date.getFullYear();
  3041. var month = date.getMonth()+1;
  3042. var day = date.getDate();
  3043. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  3044. //获取30天前得日期
  3045. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  3046. var lastY = lastDate.getFullYear();
  3047. var lastM = lastDate.getMonth()+1;
  3048. var lastD = lastDate.getDate();
  3049. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  3050. $('.manage_sdate').eq(0).val(LDate + ' 00:00:00');
  3051. $('.manage_sdate').eq(1).val(nowDate + ' 23:59:59');
  3052. }
  3053. function showVideo(video)
  3054. {
  3055. var html = '<meta name="referrer" content="no-referrer"><video width="400" height="300" controls autoplay="autoplay"><source src="'+video+'" type="video/mp4">您的浏览器不支持Video标签。</video>';
  3056. showAlert(html);
  3057. }
  3058. function sku(e)
  3059. {
  3060. var data = $('#sku_table_col').html();
  3061. data = JSON.parse(data);
  3062. var thead = [];
  3063. var tbody = [];
  3064. var mthead = [];
  3065. var mtbody = [];
  3066. for (var i in data) {
  3067. if (data[i]['verify'] == 'number') {
  3068. var type = 'required|number';
  3069. var value = '0';
  3070. } else {
  3071. var type = 'required';
  3072. var value = '';
  3073. }
  3074. if (data[i]['type'] == 'input') {
  3075. var icon = 'layui-icon-cols';
  3076. } else {
  3077. var icon = '';
  3078. }
  3079. mthead.push({title: data[i]['name'], icon: icon});
  3080. var option = {type: data[i]['type'], field: i, value: value, verify: type, reqtext: data[i]['name'] + '不能为空'};
  3081. if (option.type == 'select') {
  3082. option.option = eval("(" + data[i]['option'] + ")");
  3083. }
  3084. mtbody.push(option);
  3085. if (option.type != 'image') {
  3086. thead.push({title: data[i]['name'], icon: 'layui-icon-cols'});
  3087. tbody.push(option);
  3088. }
  3089. }
  3090. var obj = skuTable.render({
  3091. //规格类型 1统一规格 2多规格
  3092. isAttributeValue: e.attr('data-type'),
  3093. //规格类型容器id
  3094. isAttributeElemId: 'sku_spec_type',
  3095. //规格表容器id
  3096. specTableElemId: 'sku_spec_table',
  3097. //sku表容器id
  3098. skuTableElemId: 'sku_table',
  3099. //规格拖拽排序
  3100. sortable: true,
  3101. //sku表相同属性值是否合并行
  3102. rowspan: true,
  3103. //请求成功返回状态码值
  3104. requestSuccessCode: 1,
  3105. //上传接口地址
  3106. //接口要求返回格式参考 upload.json
  3107. uploadUrl: e.attr('data-upload'),
  3108. //统一规格配置项
  3109. singleSkuTableConfig: {
  3110. thead: thead,
  3111. tbody: tbody
  3112. },
  3113. //多规格配置项
  3114. multipleSkuTableConfig: {
  3115. thead: mthead,
  3116. tbody: mtbody
  3117. },
  3118. //商品id 配合specDataUrl和skuDataUrl使用
  3119. productId: e.attr('data-id'),
  3120. //规格数据, 一般从后台获取,
  3121. specData: [],
  3122. specDataUrl: e.attr('data-spec'),
  3123. skuData : [],
  3124. skuDataUrl: e.attr('data-sku'),
  3125. });
  3126. }
  3127. var append_total = 10;
  3128. function append(self, id)
  3129. {
  3130. var e = self.parent().parent().parent().find('.table_copy');
  3131. var html = e.html();
  3132. var parent = e.parent();
  3133. var total = parent.find('tr').length-1;
  3134. append_total++;
  3135. total += append_total;
  3136. html = html.replaceAll('_-1_', '_' + total + '_');
  3137. html = html.replaceAll('up_', 'update_');
  3138. id = 'update_' + id + '_c_' + total;
  3139. parent.append('<tr id="'+id+'">' + html + '</tr>');
  3140. form.render();
  3141. /*
  3142. $('#' + id + " select").each(function()
  3143. {
  3144. if ($(this).attr('xm-select')) {
  3145. layui.formSelects.render($(this).attr('xm-select'));
  3146. }
  3147. });
  3148. */
  3149. initDate();
  3150. }
  3151. function init_xm(xm_id, xm_radio, xm_tips, xm_url, xm_data, xm_value, xm_on)
  3152. {
  3153. if (!xm_on) {
  3154. xm_on = function(){};
  3155. }
  3156. var xm_table = xm_id + '_table';
  3157. var xm = xmSelect.render({
  3158. el: "#" + xm_id,
  3159. data: xm_data,
  3160. tips:xm_tips,
  3161. name:xm_id,
  3162. initValue: xm_value,
  3163. radio:xm_radio,
  3164. clickClose: xm_radio,
  3165. layVerify: "required",
  3166. layVerType: "msg",
  3167. autoRow: true,
  3168. toolbar: { show: false },
  3169. model: xm_radio ? { label: { type: 'text' } } : {},
  3170. filterable: true,
  3171. autoRow: true,
  3172. height: 'auto',
  3173. paging: xm_url ? true : false,
  3174. pageRemote: xm_url ? true : false,
  3175. remoteSearch: xm_url ? true : false,
  3176. on: xm_on,
  3177. //direction: 'down',
  3178. remoteMethod: function(val, cb, show, pageIndex) {
  3179. if (!pageIndex) {
  3180. pageIndex = 1;
  3181. }
  3182. if(!val){
  3183. //return cb([]);
  3184. }
  3185. if (!xm_url) {
  3186. return cb(xm_data);
  3187. }
  3188. var data = {
  3189. id: xm_table,
  3190. keyword: val,
  3191. pg: pageIndex
  3192. };
  3193. if (xm_url.indexOf('{') != -1) {
  3194. var start = xm_url.split('{');
  3195. var end = start[1].split('}');
  3196. xm_url = start[0] + end[1];
  3197. if (end[0].indexOf(',')) {
  3198. var param = end[0].split(',');
  3199. } else {
  3200. var param = [];
  3201. param[0] = end[0];
  3202. }
  3203. for (var i in param) {
  3204. if (typeof(param[i]) == 'string') {
  3205. var e = $('#update_'+param[i]);
  3206. if (e.length > 1) {
  3207. e.each(function() {
  3208. if ($(this).get(0).checked) {
  3209. data[param[i]] = $(this).val();
  3210. }
  3211. })
  3212. } else {
  3213. data[param[i]] = e.val();
  3214. }
  3215. }
  3216. }
  3217. }
  3218. var success = function(response) {
  3219. if (typeof response == "string") {
  3220. response = JSON.parse(response);
  3221. }
  3222. if (response.status == 2) {
  3223. cb([]);
  3224. return;
  3225. }
  3226. if (!response.data.list) {
  3227. if (response.page && response.page.total_page) {
  3228. cb(response.data, response.page.total_page)
  3229. } else {
  3230. cb(response.data)
  3231. }
  3232. } else {
  3233. if (response.page && response.page.total_page) {
  3234. cb(response.data.list, response.page.total_page)
  3235. } else {
  3236. cb(response.data.list)
  3237. }
  3238. }
  3239. /*
  3240. if (response.data.table) {
  3241. xm.update({
  3242. content: response.data.table,
  3243. });
  3244. layui.table.init(xm_table, response.data.table_config).on('row('+xm_table+')', function(obj) {
  3245. var values = xm.getValue();
  3246. var item = obj.data;
  3247. var has = values.find(function(i){
  3248. return i.value === item.value
  3249. });
  3250. var send = {};
  3251. send.arr = [ item ];
  3252. if (has) {
  3253. xm.delete(send.arr);
  3254. } else if (xm_radio) {
  3255. xm.setValue(send.arr);
  3256. xm.closed();
  3257. } else {
  3258. xm.append(send.arr);
  3259. }
  3260. xm_on && xm_on(send)
  3261. })
  3262. }*/
  3263. };
  3264. $.ajax({
  3265. dataType: "json",
  3266. url: xm_url,
  3267. data: data,
  3268. timeout:0,
  3269. success: success
  3270. });
  3271. },
  3272. });
  3273. }