page_setting.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. {include file="public/header" /}
  2. <script src="{$Think.PLUGINS_SITE_ROOT}/jquery.SuperSlide.2.1.1.js"></script>
  3. <link rel="stylesheet" href="{$Think.HOME_SITE_ROOT}/css/editable_page.css">
  4. <link href="{$Think.PLUGINS_SITE_ROOT}/colorpicker/evol.colorpicker.css" rel="stylesheet" type="text/css">
  5. <script src="{$Think.PLUGINS_SITE_ROOT}/colorpicker/evol.colorpicker.min.js"></script>
  6. <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.lazyload.min.js"></script>
  7. <script type="text/javascript" charset="utf-8" src="{$Think.PLUGINS_SITE_ROOT}/ueditor/ueditor.config.js"></script>
  8. <script type="text/javascript" charset="utf-8" src="{$Think.PLUGINS_SITE_ROOT}/ueditor/ueditor.all.min.js"> </script>
  9. <script type="text/javascript" charset="utf-8" src="{$Think.PLUGINS_SITE_ROOT}/ueditor/lang/zh-cn/zh-cn.js"></script>
  10. <div class="model-wrapper active">
  11. <div class="model-title"><span class="title">{$Think.lang.model_list}</span><span class="desc">{$Think.lang.model_list_tips}</span></div>
  12. <div class="model-list">
  13. <div id="model_list">
  14. <div class="editable-page-model">
  15. <form>
  16. <div class="model-item-list">
  17. <label class="model-item-wrapper" data-show="1">
  18. <div class="model-item">
  19. <div class="model-image ui-draggable ui-draggable-handle" data-id="11"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-11.jpg"></div>
  20. <div class="model-name">分类切换商品列表</div>
  21. </div>
  22. </label>
  23. <label class="model-item-wrapper" data-show="1">
  24. <div class="model-item">
  25. <div class="model-image ui-draggable ui-draggable-handle" data-id="10"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-10.jpg"></div>
  26. <div class="model-name">两列分类商品列表</div>
  27. </div>
  28. </label>
  29. <label class="model-item-wrapper" data-show="1">
  30. <div class="model-item">
  31. <div class="model-image ui-draggable ui-draggable-handle" data-id="9"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-9.jpg"></div>
  32. <div class="model-name">分类商品列表</div>
  33. </div>
  34. </label>
  35. <label class="model-item-wrapper" data-show="1">
  36. <div class="model-item">
  37. <div class="model-image ui-draggable ui-draggable-handle" data-id="8"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-8.jpg"></div>
  38. <div class="model-name">商品分类和轮播图</div>
  39. </div>
  40. </label>
  41. <label class="model-item-wrapper" data-show="0">
  42. <div class="model-item">
  43. <div class="model-image ui-draggable ui-draggable-handle" data-id="2"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-2.jpg"></div>
  44. <div class="model-name">富文本</div>
  45. </div>
  46. </label>
  47. <label class="model-item-wrapper" data-show="0">
  48. <div class="model-item">
  49. <div class="model-image ui-draggable ui-draggable-handle" data-id="1"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-1.jpg"></div>
  50. <div class="model-name">轮播图</div>
  51. </div>
  52. </label>
  53. </div>
  54. <div class="clear"></div>
  55. </form>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="pc-page">
  61. <div class="pc-page-content" id="page_content">
  62. {if isset($config_list)}
  63. {foreach name='config_list' item='item' key='key'}
  64. <div onclick="setConfig({$key+1})" data-type="html" data-id="{$key+1}"><div class="model-del iconfont" onclick="delConfig({$key+1})">&#xe6e6;</div>{$item.html|raw}</div>
  65. {/foreach}
  66. {/if}
  67. <div class="pc-page-empty" {if !empty($config_list)}style="display:none"{/if}>请点击组件添加到此区域</div>
  68. </div>
  69. </div>
  70. <div class="page-wrapper" style="display: block;position: relative;">
  71. <div>
  72. <div data-type="load">
  73. {if isset($config_list)}
  74. {foreach name='config_list' item='item' key="key"}
  75. <div data-type="config" data-id="{$key+1}" style="display:none">{$item.config|raw}</div>
  76. {/foreach}
  77. {/if}
  78. </div>
  79. </div>
  80. <div class="footer-btn">
  81. <input class="btn" type="button" value="{$Think.lang.ds_save}" onclick="saveForm()" />
  82. <a href="{:url('home/special/index',['special_id'=>input('param.editable_page_id')])}" target="_blank"><input class="btn btn-red" type="button" value="预览"/></a>
  83. </div>
  84. </div>
  85. <script>
  86. var ue={}
  87. EDITABLE_PAGE_URL='{$Think.ADMIN_SITE_URL}/editable_page'
  88. window.UEDITOR_HOME_URL='{$Think.PLUGINS_SITE_ROOT}/ueditor/'
  89. var goods_class={}
  90. function loadGoodsClass(level,id,obj){
  91. id=parseInt(id)
  92. if(goods_class['i_'+id]){
  93. addGoodsClass(level,id,obj)
  94. }else if(level==4){
  95. $('#'+obj).find('*[data-input]').val(id)
  96. }else if(level==1 || id>0){
  97. $.getJSON(EDITABLE_PAGE_URL+'/goods_class?parent_id='+id,function(data){
  98. if(data.code!=10000){
  99. layer.msg(data.message)
  100. }else if(data.result.length){
  101. goods_class['i_'+id]=data.result
  102. addGoodsClass(level,id,obj)
  103. }
  104. })
  105. }
  106. }
  107. function getGoodsClass(id,obj){
  108. $.getJSON(EDITABLE_PAGE_URL+'/goods_class?id='+id,function(data){
  109. if(data.code!=10000){
  110. layer.msg(data.message)
  111. }else{
  112. if(data.result.id.length){
  113. var temp=''
  114. for(var i in data.result.id){
  115. if(i==0){
  116. goods_class['i_0']=data.result.list[i]
  117. }else{
  118. goods_class['i_'+data.result.id[i-1]]=data.result.list[i]
  119. }
  120. i=parseInt(i)
  121. temp+='<select data-level="'+(i+1)+'" onchange="loadGoodsClass('+(i+2)+',$(this).val(),\''+obj+'\')">'
  122. temp+='<option value="0">{$Think.lang.ds_please_choose}</option>'
  123. for(var j in data.result.list[i]){
  124. temp+='<option value="'+data.result.list[i][j]['gc_id']+'" '+(data.result.list[i][j]['gc_id']==data.result.id[i]?'selected=""':'')+'>'+data.result.list[i][j]['gc_name']+'</option>'
  125. }
  126. temp+='</select>'
  127. }
  128. $('#'+obj+' [data-select]').append(temp)
  129. if($('#'+obj+' tbody').length){
  130. var temp=''
  131. var json
  132. var v=$('#'+obj+' *[data-type="template"]').attr('data-value')
  133. if(v){
  134. json=JSON.parse(v)
  135. }
  136. for(var i in data.result.list[data.result.list.length-1]){
  137. temp+='<tr><td class="tl"><label class="checkbox-label"><i class="checkbox-common"><input type="checkbox" onchange="checkboxChange($(this))" /></i><span>'+data.result.list[data.result.list.length-1][i].gc_name+'</span></label></td><td><input type="text" size="1" name="'+$('#'+obj+' *[data-type="template"]').attr('data-name')+'['+data.result.list[data.result.list.length-1][i].gc_id+'][sort]" value="'+((json && json[data.result.list[data.result.list.length-1][i].gc_id])?json[data.result.list[data.result.list.length-1][i].gc_id].sort:"255")+'" '+((json && json[data.result.list[data.result.list.length-1][i].gc_id])?"disabled=''":"")+' /></td></tr>'
  138. }
  139. $('#'+obj+' tbody').html(temp)
  140. }
  141. }
  142. }
  143. })
  144. }
  145. function checkboxChange(obj){
  146. if(obj.is(':checked')){
  147. obj.parents('tr').find('input[type="text"]').removeAttr('disabled');
  148. obj.parent().addClass('selected');
  149. }else{
  150. obj.parents('tr').find('input[type="text"]').attr('disabled','');
  151. obj.parent().removeClass('selected');
  152. }
  153. }
  154. function addGoodsClass(level,id,obj){
  155. if(level==1 || id>0){
  156. $('#'+obj).find('*[data-input]').val(id)
  157. if(goods_class['i_'+id]){
  158. var temp='<option value="0">{$Think.lang.ds_please_choose}</option>'
  159. for(var i in goods_class['i_'+id]){
  160. temp+='<option value="'+goods_class['i_'+id][i]['gc_id']+'">'+goods_class['i_'+id][i]['gc_name']+'</option>'
  161. }
  162. if($('#'+obj).find('select[data-level='+level+']').length){
  163. $('#'+obj).find('select[data-level='+level+']').html(temp)
  164. $('#'+obj).find('select[data-level]:gt('+($('#'+obj).find('select[data-level='+level+']').index()-1)+')').remove()
  165. }else{
  166. $('#'+obj+' [data-select]').append('<select data-level="'+level+'" onchange="loadGoodsClass('+(level+1)+',$(this).val(),\''+obj+'\')">'+temp+'</select>')
  167. }
  168. }
  169. }else{
  170. if(level>2){
  171. $('#'+obj).find('*[data-input]').val($('#'+obj).find('select[data-level='+(level-2)+']').val())
  172. }else{
  173. $('#'+obj).find('*[data-input]').val(0)
  174. }
  175. $('#'+obj).find('select[data-level]:gt('+($('#'+obj).find('select[data-level='+(level-1)+']').index()-1)+')').remove()
  176. }
  177. if($('#'+obj+' tbody').length){
  178. var temp=''
  179. $('#'+obj+' select:last-child').find('option').each(function(){
  180. if($(this).val()>0){
  181. temp+='<tr><td class="tl"><label class="checkbox-label"><i class="checkbox-common"><input type="checkbox" onchange="checkboxChange($(this))" /></i><span>'+$(this).text()+'</span></label></td><td><input type="text" size="1" name="'+$('#'+obj+' *[data-type="template"]').attr('data-name')+'['+$(this).val()+'][sort]" value="255" disabled="" /></td></tr>'
  182. }
  183. })
  184. $('#'+obj+' tbody').html(temp)
  185. }
  186. }
  187. var id={if isset($config_list)}{:count($config_list)}{else}0{/if};
  188. $(function(){
  189. $('#page_content a').removeAttr('href')
  190. //懒加载
  191. $("img.lazyload").lazyload({
  192. effect: "fadeIn",
  193. skip_invisible : false,
  194. threshold : 200,
  195. });
  196. {if isset($config_list)}
  197. {foreach name='config_list' item='item' key='key'}
  198. if(typeof(window['loadHtml{$item.val.editable_page_model_id}'])!='undefined'){
  199. window['loadHtml{$item.val.editable_page_model_id}']($('*[data-type="html"][data-id={$key+1}]'))
  200. }
  201. if(typeof(window['loadConfig{$item.val.editable_page_model_id}'])!='undefined'){
  202. window['loadConfig{$item.val.editable_page_model_id}']($('*[data-type="config"][data-id={$key+1}]'))
  203. }
  204. {/foreach}
  205. {/if}
  206. $('#page_content').sortable();
  207. $('#page_content').disableSelection();
  208. $('.model-wrapper').draggable({ handle: ".model-title" })
  209. $('.model-item-wrapper').click(function(){
  210. var config=$(this).find('.model-image').attr('data-id')
  211. $.getJSON(EDITABLE_PAGE_URL+'/config_load?model_id='+config,function(data){
  212. if(data.code!=10000) {
  213. layer.msg(data.message);
  214. }else{
  215. id++
  216. $('.pc-page-empty').hide()
  217. var obj=$('.active[data-type="html"]')
  218. $('*[data-type="html"]').removeClass('active');
  219. var temp='<div onclick="setConfig('+id+')" class="active" data-type="html" data-id="'+id+'"><div class="model-del iconfont" onclick="delConfig('+id+')">&#xe6e6;</div>'+data.result.html+'</div>'
  220. if(obj.length){
  221. obj.after(temp)
  222. }else{
  223. $('#page_content').append(temp)
  224. }
  225. $('html,body').animate({scrollTop:$('*[data-type="html"][data-id='+id+']').offset().top}, 500);
  226. $('*[data-type="load"]').prepend('<div data-type="config" data-id="'+id+'">'+data.result.config+'</div>')
  227. if(typeof(window['loadHtml'+config])!='undefined'){
  228. window['loadHtml'+config]($('*[data-type="html"][data-id='+id+']'))
  229. }
  230. if(typeof(window['loadConfig'+config])!='undefined'){
  231. window['loadConfig'+config]($('*[data-type="config"][data-id='+id+']'))
  232. }
  233. $('#page_content a').removeAttr('href')
  234. //懒加载
  235. $("img.lazyload").lazyload({
  236. effect: "fadeIn",
  237. skip_invisible : false,
  238. threshold : 200,
  239. });
  240. setConfig(id)
  241. }
  242. })
  243. })
  244. })
  245. // 图片上传ajax
  246. function uploadFile(obj,callback) {
  247. if(!event.target.files[0]){
  248. return false;
  249. }
  250. var formData = new FormData();
  251. formData.append('config_id',0);
  252. formData.append('name','file');
  253. formData.append('file', event.target.files[0]);
  254. $.ajax({
  255. type: "POST",
  256. url : EDITABLE_PAGE_URL+'/image_upload',
  257. dataType : 'json',
  258. data : formData,
  259. contentType: false,
  260. processData: false,
  261. success : function (data, status) {
  262. if (data.code!=10000) {
  263. layer.msg(data.message);
  264. } else {
  265. obj.parents('.uploader-wrapper').find('input[type="hidden"]').val(data.result.file_path);
  266. obj.parents('.uploader-wrapper').find('.uploader-content').hide();
  267. obj.parents('.uploader-wrapper').find('.uploader-image').attr('src', data.result.file_path);
  268. obj.parents('.uploader-wrapper').find('.uploader-image-wrapper').show();
  269. if(callback){
  270. callback(data.result.file_path,obj)
  271. }
  272. }
  273. }
  274. });
  275. return false;
  276. }
  277. function delFile(obj){
  278. obj.parents('.uploader-wrapper').find('input[type="hidden"]').val('');
  279. obj.parents('.uploader-wrapper').find('.uploader-content').show();
  280. obj.parents('.uploader-wrapper').find('.uploader-image').attr('src', '');
  281. obj.parents('.uploader-wrapper').find('.uploader-image-wrapper').hide();
  282. }
  283. function setRadio(obj,callback){
  284. obj.parents('.ds-icon-radio').find('li').removeClass('ds-icon-active')
  285. obj.addClass('ds-icon-active')
  286. obj.parents('.ds-icon-radio').find('input[type="hidden"]').val(obj.attr('data-val'))
  287. if(callback){
  288. callback()
  289. }
  290. }
  291. function setConfig(id){
  292. $('*[data-type="html"].active').removeClass('active')
  293. $('*[data-type="html"][data-id='+id+']').addClass('active')
  294. $('*[data-type="load"]').parent().show()
  295. $('*[data-type="config"]').hide()
  296. $('*[data-type="config"][data-id='+id+']').show()
  297. layer.open({
  298. type: 1,
  299. area: '500px',
  300. maxHeight:600,
  301. title:$('*[data-type="config"][data-id='+id+'] .attr-title').text(),
  302. content: $('*[data-type="config"][data-id='+id+']'),
  303. btn:['保存'],
  304. btn1:function(index){
  305. changeForm($('*[data-type="config"][data-id='+id+']').find('form'),function(){
  306. layer.close(index)
  307. $('*[data-type="load"]').parent().hide()
  308. })
  309. },
  310. btnAlign: 'c',
  311. cancel:function(){
  312. $('*[data-type="load"]').parent().hide()
  313. }
  314. });
  315. }
  316. function delConfig(id){
  317. $('*[data-type="html"][data-id='+id+']').remove()
  318. $('*[data-type="config"][data-id='+id+']').remove()
  319. if(!$('*[data-type="html"]').length){
  320. $('.pc-page-empty').show()
  321. }
  322. event.stopPropagation()
  323. }
  324. var index={}
  325. var html={}
  326. function addModel(obj,id){
  327. index['i_'+id]++
  328. obj.before('<div class="model-item">'+html['i_'+id].replace(/\[i_\d+\]/g,'[i_'+index['i_'+id]+']')+'<div class="model-del iconfont" onclick="delModel($(this))">&#xe696;</div>'+'</div>')
  329. if(typeof(window['loadConfig'+id])!='undefined'){
  330. window['loadConfig'+id](obj.parents('*[data-type="config"]'))
  331. }
  332. }
  333. function delModel(obj){
  334. obj.parents('.model-item').remove()
  335. }
  336. function saveForm(){
  337. var data=[]
  338. $('*[data-type="html"]').each(function(){
  339. data.push(formartForm($('*[data-type="config"][data-id='+$(this).attr('data-id')+']').find('form').serializeArray()))
  340. })
  341. $.ajax({
  342. type: "POST",
  343. url : EDITABLE_PAGE_URL+'/config_edit?page_id={$Request.param.editable_page_id}',
  344. dataType : 'json',
  345. data : {config_list:data},
  346. success : function (data, status) {
  347. layer.msg(data.message)
  348. }
  349. })
  350. }
  351. function formartForm(temp){
  352. var formData={}
  353. var m_s=[]
  354. var m_i=[]
  355. var r={}
  356. for(var i in temp){
  357. var m=temp[i]['name'].match(/(\[([^\[\]]+)\])+?/g)
  358. if(m){
  359. var w={}
  360. for(var j=m.length-1;j>=0;j--){
  361. var o=m[j].match(/\[(.+)\]/)
  362. var t=(j==m.length-1)?temp[i]['value']:w
  363. w={}
  364. if(o[1].match(/^i_\d+$/)){
  365. if(m_s[j]!=o[1]){
  366. if(!m_s[j] || parseInt(o[1].substr(2))<parseInt(m_s[j].substr(2))){
  367. m_i[j]=0
  368. }else{
  369. m_i[j]++
  370. }
  371. m_s[j]=o[1]
  372. }
  373. w[m_i[j]]=t
  374. }else if(o[1].match(/^\d+$/)){
  375. w[o[1].toString()]=t
  376. }else{
  377. w[o[1]]=t
  378. }
  379. }
  380. var n=temp[i]['name'].match(/^([^\[\]]+)/)
  381. r={}
  382. r[n[1]]=w
  383. formData=setAttr(formData,r)
  384. }else{
  385. formData[temp[i]['name']]=temp[i]['value']
  386. }
  387. }
  388. function setAttr(obj,val){
  389. for(var j in val){
  390. if(obj[j]){
  391. obj[j]=setAttr(obj[j],val[j])
  392. return obj
  393. }else{
  394. return Object.assign(obj,val)
  395. }
  396. }
  397. }
  398. return formData
  399. }
  400. function changeForm(obj,callback){
  401. var id=obj.find('input[name="model_id"]').val()
  402. var temp=obj.serializeArray()
  403. var formData=formartForm(temp)
  404. $.ajax({
  405. type: "POST",
  406. url : EDITABLE_PAGE_URL+'/config_load?model_id='+id,
  407. dataType : 'json',
  408. data : {config_info:formData},
  409. success : function (data, status) {
  410. if (data.code!=10000) {
  411. layer.msg(data.message);
  412. } else {
  413. $('*[data-type="html"][data-id='+obj.parents('*[data-type="config"]').attr('data-id')+']').html('<div class="model-del iconfont" onclick="delConfig('+obj.parents('*[data-type="config"]').attr('data-id')+')">&#xe6e6;</div>'+data.result.html)
  414. if(typeof(window['loadHtml'+id])!='undefined'){
  415. window['loadHtml'+id]($('*[data-type="html"][data-id='+obj.parents('*[data-type="config"]').attr('data-id')+']'))
  416. }
  417. $('#page_content a').removeAttr('href')
  418. //懒加载
  419. $("img.lazyload").lazyload({
  420. effect: "fadeIn",
  421. skip_invisible : false,
  422. threshold : 200,
  423. });
  424. if(callback){
  425. callback()
  426. }
  427. }
  428. }
  429. })
  430. }
  431. </script>
  432. <style>
  433. .page-wrapper .footer-btn{position:fixed;z-index: 10;}
  434. *[data-type="config"]{padding:20px}
  435. *[data-type="config"] .attr-title{display: none;}
  436. *[data-type="html"].active{border:0}
  437. *[data-type="html"].active::after{content:'';position: absolute;width:1200px;top:0;bottom:0;border:1px dashed #FF6A00;left:50%;margin-left:-600px}
  438. *[data-type="html"] .model-del{right:50%;top:0;margin-right:-600px;width:30px;height: 30px;line-height: 30px;z-index: 10;}
  439. .model-wrapper{position: fixed;top:80px;left:-180px;z-index: 100000;width:227px;background: #fff}
  440. .model-wrapper.active{left:0;}
  441. .model-wrapper .model-title{cursor: move}
  442. .pc-page .pc-page-header,.pc-page .pc-page-footer{text-align: center;background-color: #fff;opacity: .5;}
  443. .pc-page .pc-page-header img,.pc-page .pc-page-footer img{width: 1200px;}
  444. .pc-page .pc-page-content .pc-page-empty{font-size: 24px;font-weight:bold;text-align: center;margin: 0 auto;top:300px;position: relative;color:#999}
  445. </style>