main.js 89 KB

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