material_form.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. {include file="public/header" /}
  2. <div class="page">
  3. <div class="fixed-bar">
  4. <div class="item-title">
  5. <div class="subject">
  6. <h3>{$Think.lang.wechat_material}</h3>
  7. </div>
  8. {include file="public/admin_items" /}
  9. </div>
  10. </div>
  11. <div class='material-wrapper'>
  12. <div class='material-left'>
  13. <div class="material-mobile">
  14. <img class="material-mobile-head" src='{$Think.ADMIN_SITE_ROOT}/images/mobile_head.png' />
  15. <div class='material-mobile-content'>
  16. <div class='material-message'>
  17. <div class='material-message-big material-message-active' onclick='getMaterial($(this))'>
  18. <img class='material-message-big-image' {if !isset($material_info[0])}style="display:none"{/if} src='{if isset($material_info[0])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[0]["thumb_media_id"]}{/if}' />
  19. <div class='material-message-big-wrapper' {if isset($material_info[0])}style="display:none"{/if}>
  20. <div class='material-message-big-text'>封面图</div>
  21. </div>
  22. <div class='material-message-big-title'>{$material_info[0]["title"]|default="标题"}</div>
  23. </div>
  24. <div>
  25. <div class='material-message-small' {if !isset($material_info[1])}style='display:none'{/if} onclick='getMaterial($(this))'>
  26. <div class='material-message-small-title'>{$material_info[1]["title"]|default="标题"}</div>
  27. <img class='material-message-small-image' {if !isset($material_info[1])}style="display:none"{/if} src='{if isset($material_info[1])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[1]["thumb_media_id"]}{/if}' />
  28. <div class='material-message-small-wrapper' {if isset($material_info[1])}style="display:none"{/if}>
  29. <div class='material-message-small-text'>缩略图</div>
  30. </div>
  31. </div>
  32. <div class='material-message-small' {if !isset($material_info[2])}style='display:none'{/if} onclick='getMaterial($(this))'>
  33. <div class='material-message-small-title'>{$material_info[2]["title"]|default="标题"}</div>
  34. <img class='material-message-small-image' {if !isset($material_info[2])}style="display:none"{/if} src='{if isset($material_info[2])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[2]["thumb_media_id"]}{/if}' />
  35. <div class='material-message-small-wrapper' {if isset($material_info[2])}style="display:none"{/if}>
  36. <div class='material-message-small-text'>缩略图</div>
  37. </div>
  38. </div>
  39. <div class='material-message-small' {if !isset($material_info[3])}style='display:none'{/if} onclick='getMaterial($(this))'>
  40. <div class='material-message-small-title'>{$material_info[3]["title"]|default="标题"}</div>
  41. <img class='material-message-small-image' {if !isset($material_info[3])}style="display:none"{/if} src='{if isset($material_info[3])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[3]["thumb_media_id"]}{/if}' />
  42. <div class='material-message-small-wrapper' {if isset($material_info[3])}style="display:none"{/if}>
  43. <div class='material-message-small-text'>缩略图</div>
  44. </div>
  45. </div>
  46. <div class='material-message-small' {if !isset($material_info[4])}style='display:none'{/if} onclick='getMaterial($(this))'>
  47. <div class='material-message-small-title'>{$material_info[4]["title"]|default="标题"}</div>
  48. <img class='material-message-small-image' {if !isset($material_info[4])}style="display:none"{/if} src='{if isset($material_info[4])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[4]["thumb_media_id"]}{/if}' />
  49. <div class='material-message-small-wrapper' {if isset($material_info[4])}style="display:none"{/if}>
  50. <div class='material-message-small-text'>缩略图</div>
  51. </div>
  52. </div>
  53. <div class='material-message-small' {if !isset($material_info[5])}style='display:none'{/if} onclick='getMaterial($(this))'>
  54. <div class='material-message-small-title'>{$material_info[5]["title"]|default="标题"}</div>
  55. <img class='material-message-small-image' {if !isset($material_info[5])}style="display:none"{/if} src='{if isset($material_info[5])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[5]["thumb_media_id"]}{/if}' />
  56. <div class='material-message-small-wrapper' {if isset($material_info[5])}style="display:none"{/if}>
  57. <div class='material-message-small-text'>缩略图</div>
  58. </div>
  59. </div>
  60. <div class='material-message-small' {if !isset($material_info[6])}style='display:none'{/if} onclick='getMaterial($(this))'>
  61. <div class='material-message-small-title'>{$material_info[6]["title"]|default="标题"}</div>
  62. <img class='material-message-small-image' {if !isset($material_info[6])}style="display:none"{/if} src='{if isset($material_info[6])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[6]["thumb_media_id"]}{/if}' />
  63. <div class='material-message-small-wrapper' {if isset($material_info[6])}style="display:none"{/if}>
  64. <div class='material-message-small-text'>缩略图</div>
  65. </div>
  66. </div>
  67. <div class='material-message-small' {if !isset($material_info[7])}style='display:none'{/if} onclick='getMaterial($(this))'>
  68. <div class='material-message-small-title'>{$material_info[7]["title"]|default="标题"}</div>
  69. <img class='material-message-small-image' {if !isset($material_info[7])}style="display:none"{/if} src='{if isset($material_info[7])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[7]["thumb_media_id"]}{/if}' />
  70. <div class='material-message-small-wrapper' {if isset($material_info[7])}style="display:none"{/if}>
  71. <div class='material-message-small-text'>缩略图</div>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. {notpresent name='material_info'}
  78. <div class='material-mobile-foot'>
  79. <i class='material-arrow'></i>
  80. <div class='material-label' onclick='addMaterial()'>新增</div>
  81. </div>
  82. {/notpresent}
  83. </div>
  84. </div>
  85. <div class='material-right'>
  86. <i class='material-arrow'></i>
  87. <div class="material-right-content">
  88. <div class="material-editor-head">
  89. <div class="material-editor-head-title">图文消息(<span class='material-editor-head-number'>1</span>)</div>
  90. {notpresent name='material_info'}<div class="material-editor-head-btn" onclick='delMaterial()' style='display: none'>删除</div>{/notpresent}
  91. </div>
  92. <div class="material-editor-content">
  93. <form method="post" enctype="multipart/form-data" id="form1" action="">
  94. <div class="ncap-form-default">
  95. <dl>
  96. <dt><label class="validation">封面</label></dt>
  97. <dd>
  98. <div class="uploader-wrapper">
  99. <img class='uploader-image' {if !isset($material_info[0])}style="display:none"{/if} src='{if isset($material_info[0])}{:url("admin/Wechat/get_material_image")}?media_id={$material_info[0]["thumb_media_id"]}{/if}' />
  100. <div class='uploader-content' {if isset($material_info[0])}style="display:none"{/if}>
  101. <div class="uploader-icon iconfont">&#xe6bf;</div>
  102. <div class="uploader-text">点击上传</div>
  103. </div>
  104. <input type='file' id='uploader1' class='uploader-file'>
  105. <input type='hidden' name='thumb_media_id' value='{$material_info[0]["thumb_media_id"]|default=""}'>
  106. </div>
  107. <p class="notic">图片建议尺寸:封面图900 x 500像素,缩略图200 x 200像素,图片仅支持jpg/png格式,大小必须在1MB以下</p>
  108. </dd>
  109. </dl>
  110. <dl>
  111. <dt><label class="validation">标题</label></dt>
  112. <dd>
  113. <input name="title" value="{$material_info[0]["title"]|default=""}" class="input-txt" type="text" onchange='setTitle($(this))'>
  114. </dd>
  115. </dl>
  116. <dl>
  117. <dt><label>作者</label></dt>
  118. <dd>
  119. <input name="author" value="{$material_info[0]["author"]|default=""}" class="input-txt" type="text">
  120. </dd>
  121. </dl>
  122. <dl>
  123. <dt><label class="validation">内容</label></dt>
  124. <dd>
  125. {:build_editor(['name'=>'content','content'=>htmlspecialchars_decode('')])}
  126. <textarea name="content" id="content" style="width:100%;">{if isset($material_info[0])}{$material_info[0]["content"]|raw}{/if}</textarea>
  127. <div class="type-file-button" style='float:none;display: block'>
  128. <input type='file' id='uploader2' class='uploader-file'>
  129. <span>上传</span>
  130. </div>
  131. </dd>
  132. </dl>
  133. <dl>
  134. <dt><label class="validation">原文地址</label></dt>
  135. <dd>
  136. <input name="content_source_url" value="{$material_info[0]["content_source_url"]|default=""}" class="input-txt" type="text">
  137. </dd>
  138. </dl>
  139. <dl>
  140. <dt><label>是否打开评论</label></dt>
  141. <dd>
  142. <div class="onoff">
  143. <label for="need_open_comment_1" class="cb-enable {if isset($material_info[0]) && $material_info[0]["need_open_comment"]==1}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
  144. <label for="need_open_comment_0" class="cb-disable {if !isset($material_info[0]) || $material_info[0]["need_open_comment"]==0}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
  145. <input type="radio" id="need_open_comment_1" name="need_open_comment" value="1" {if isset($material_info[0]) && $material_info[0]["need_open_comment"]==1}checked=checked{/if}>
  146. <input type="radio" id="need_open_comment_0" name="need_open_comment" value="0" {if !isset($material_info[0]) || $material_info[0]["need_open_comment"]==0}checked=checked{/if}>
  147. </div>
  148. </dd>
  149. </dl>
  150. <dl>
  151. <dt><label>是否粉丝可评</label></dt>
  152. <dd>
  153. <div class="onoff">
  154. <label for="only_fans_can_comment_1" class="cb-enable {if isset($material_info[0]) && $material_info[0]["only_fans_can_comment"]==1}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
  155. <label for="only_fans_can_comment_0" class="cb-disable {if !isset($material_info[0]) || $material_info[0]["only_fans_can_comment"]==0}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
  156. <input type="radio" id="only_fans_can_comment_1" name="only_fans_can_comment" value="1" {if isset($material_info[0]) && $material_info[0]["only_fans_can_comment"]==1}checked=checked{/if}>
  157. <input type="radio" id="only_fans_can_comment_0" name="only_fans_can_comment" value="0" {if !isset($material_info[0]) || $material_info[0]["only_fans_can_comment"]==0}checked=checked{/if}>
  158. </div>
  159. </dd>
  160. </dl>
  161. </div>
  162. </form>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. <div class="btn-wrapper">
  168. <a href="JavaScript:void(0);" class="btn" onclick="submit()">{$Think.lang.ds_confirm_submit}</a>
  169. </div>
  170. </div>
  171. <style>
  172. .material-wrapper{display: flex;margin-top:20px}
  173. .material-wrapper .material-left{margin-right:20px;}
  174. .material-wrapper .material-left .material-mobile{width:320px;border:1px solid #e1e1e1;font-size: 0;}
  175. .material-wrapper .material-left .material-mobile .material-mobile-head{width:100%;}
  176. .material-wrapper .material-left .material-mobile .material-mobile-content{padding:20px;width:100%;box-sizing: border-box;}
  177. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message{border:1px solid #e1e1e1;}
  178. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-big{padding:10px;position:relative;}
  179. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-big .material-message-big-image{width:258px;height: 150px;object-fit: cover;}
  180. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-big .material-message-big-title{font-size:12px;position:absolute;bottom:10px;width:238px;height: 30px;line-height: 30px;padding:0 10px;color:#fff;background:rgba(0,0,0,.5);white-space: nowrap;overflow: hidden;text-overflow:ellipsis;}
  181. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-big .material-message-big-wrapper{width:258px;height: 150px;background:#eee;display: flex;justify-content: center;align-items: center;}
  182. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-big .material-message-big-wrapper .material-message-big-text{font-size:16px;color:#999}
  183. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-small{display: flex;border-top:1px solid #e1e1e1;padding:10px;}
  184. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-small .material-message-small-title{font-size:12px;flex:1;height:50px;}
  185. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-small .material-message-small-image{width:50px;height:50px;object-fit: cover;}
  186. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-small .material-message-small-wrapper{width:50px;height:50px;background:#eee;display: flex;justify-content: center;align-items: center;}
  187. .material-wrapper .material-left .material-mobile .material-mobile-content .material-message .material-message-small .material-message-small-wrapper .material-message-small-text{font-size:12px;color:#999}
  188. .material-wrapper .material-left .material-mobile .material-mobile-foot{height: 50px;border-top:1px solid #e1e1e1;text-align: center;position: relative;cursor: pointer}
  189. .material-wrapper .material-left .material-mobile .material-mobile-foot .material-label{line-height: 50px;font-size:16px;font-weight: bold}
  190. .material-wrapper .material-left .material-mobile .material-mobile-foot .material-arrow{position:absolute;left: 150px;top:-19px;}
  191. .material-wrapper .material-left .material-mobile .material-mobile-foot .material-arrow::before{content: ' ';border: 8px solid transparent;border-bottom-width: 10px;border-bottom-color: #e1e1e1;height: 0;width:0;display: block;}
  192. .material-wrapper .material-left .material-mobile .material-mobile-foot .material-arrow::after{position: absolute;content: ' ';border: 8px solid transparent;border-bottom-width: 10px;border-bottom-color: #fff;top: 1px;left:0;height: 0;width:0;display: block;}
  193. .material-wrapper .material-right{flex:1;position:relative;border:1px solid #e1e1e1;background: #f4f5f9}
  194. .material-wrapper .material-right .material-arrow{position:absolute;left: -18px;top:167px;}
  195. .material-wrapper .material-right .material-arrow::before{content: ' ';border: 8px solid transparent;border-right-width: 10px;border-right-color: #e1e1e1;height: 0;width:0;display: block;}
  196. .material-wrapper .material-right .material-arrow::after{position: absolute;content: ' ';border: 8px solid transparent;border-right-width: 10px;border-right-color: #f4f5f9;top: 0;left:1px;height: 0;width:0;display: block;}
  197. .material-wrapper .material-right .material-right-content .material-editor-head{display: flex;align-items:center;border-bottom: 1px solid #e1e1e1;padding:10px 20px;}
  198. .material-wrapper .material-right .material-right-content .material-editor-head .material-editor-head-title{font-size:16px;flex:1;}
  199. .material-wrapper .material-right .material-right-content .material-editor-head .material-editor-head-btn{background: #fff;border:1px solid #e1e1e1;text-align: center;line-height: 40px;width:100px;font-size:14px;cursor: pointer}
  200. .material-wrapper .material-right .material-right-content .material-editor-content{margin:20px;}
  201. .material-message-active{border: 1px solid #8b8b8b !important;}
  202. .btn-wrapper{text-align: center}
  203. .btn-wrapper .btn{margin:20px auto;}
  204. .uploader-wrapper{border:1px solid #e1e1e1;border-radius:5px;text-align: center;width: 258px;height: 150px;cursor: pointer;position:relative;}
  205. .uploader-wrapper .uploader-icon{font-size:50px;padding-top:50px;}
  206. .uploader-wrapper .uploader-text{font-size:16px;font-weight: bold;}
  207. .uploader-file{opacity: 0;position:absolute;top:0;bottom:0;left:0;right:0;}
  208. .uploader-image{object-fit: cover;width: 258px;height: 150px;cursor: pointer;}
  209. .type-file-button{cursor: pointer;text-align: center;position:relative}
  210. </style>
  211. <script type="text/javascript">
  212. var materialList=[null]
  213. $(function() {
  214. {present name='material_info'}
  215. materialList=[];
  216. {foreach name='material_info' item='item'}
  217. var temp=[];
  218. {foreach name='item' key='k' item='v'}
  219. {if in_array($k,['thumb_media_id','title','author','content','content_source_url','need_open_comment','only_fans_can_comment'])}
  220. var value={name:'{$k}'};
  221. {if $k=='content'}
  222. value["value"]='{:htmlspecialchars_decode($v)}';
  223. {else}
  224. value["value"]='{$v}';
  225. {/if}
  226. temp.push(value);
  227. {/if}
  228. {/foreach}
  229. materialList.push(temp);
  230. {/foreach}
  231. {/present}
  232. $('#uploader1').change(function(){
  233. var formData = new FormData();
  234. formData.append('file', event.target.files[0]);
  235. formData.append('type', 1);
  236. $.ajax({
  237. type: "POST",
  238. url: '{:url("admin/Wechat/upload_material_image")}',
  239. dataType: 'json',
  240. data: formData,
  241. contentType: false,
  242. processData: false,
  243. success: function (res) {
  244. if (res.code == 10000) {
  245. $('[name="thumb_media_id"]').val(res.result.media_id)
  246. if(!materialIndex){
  247. $('.material-message-big-image').attr('src','{:url("admin/Wechat/get_material_image")}?media_id='+res.result.media_id).show()
  248. $('.material-message-big-wrapper').hide()
  249. }else{
  250. $('.material-message-small-image').eq(materialIndex-1).attr('src','{:url("admin/Wechat/get_material_image")}?media_id='+res.result.media_id).show()
  251. $('.material-message-small-wrapper').eq(materialIndex-1).hide()
  252. }
  253. $('.uploader-image').attr('src','{:url("admin/Wechat/get_material_image")}?media_id='+res.result.media_id).show()
  254. $('.uploader-content').hide()
  255. } else {
  256. layer.msg(res.message)
  257. }
  258. }
  259. })
  260. })
  261. $('#uploader2').change(function(){
  262. var formData = new FormData();
  263. formData.append('file', event.target.files[0]);
  264. formData.append('type', 2);
  265. $.ajax({
  266. type: "POST",
  267. url: '{:url("admin/Wechat/upload_material_image")}',
  268. dataType: 'json',
  269. data: formData,
  270. contentType: false,
  271. processData: false,
  272. success: function (res) {
  273. if (res.code == 10000) {
  274. ue.execCommand('insertimage', {src:res.result.url});
  275. } else {
  276. layer.msg(res.message)
  277. }
  278. }
  279. })
  280. })
  281. });
  282. var materialArrow=[167,290,360,430,500,570,640,710]
  283. var materialIndex=0
  284. function addMaterial(){
  285. materialList[materialIndex]=$("#form1").serializeArray()
  286. materialList.push([])
  287. materialIndex=materialList.length-1
  288. $('.material-message-active').removeClass('material-message-active')
  289. $('.material-message-small').eq(materialIndex-1).addClass('material-message-active').show()
  290. $('.material-right .material-arrow').css('top',materialArrow[materialIndex]+'px')
  291. $('.material-editor-head-number').text(materialIndex+1)
  292. $('.material-editor-head-btn').show()
  293. $('#form1 input').val('')
  294. $('.uploader-image').hide()
  295. $('.uploader-content').show()
  296. ue.setContent('')
  297. if(materialList.length>=8){
  298. $('.material-mobile-foot').hide()
  299. }
  300. }
  301. function delMaterial(){
  302. materialList.splice(materialIndex,1)
  303. var obj=$('.material-message-small').eq(materialIndex-1)
  304. obj.hide()
  305. obj.parent().append(obj)
  306. if((materialList.length-1)<materialIndex){
  307. materialIndex=materialList.length-1
  308. }
  309. if(materialIndex!=0){
  310. getMaterial($('.material-message-small').eq(materialIndex-1),false)
  311. }else{
  312. getMaterial($('.material-message-big'),false)
  313. }
  314. if(materialList.length<8){
  315. $('.material-mobile-foot').show()
  316. }
  317. }
  318. function getMaterial(obj,if_save=true){
  319. var index
  320. if(obj.attr('class').indexOf("material-message-small") != -1 ){
  321. index=obj.index()+1
  322. }else{
  323. index=0
  324. }
  325. if(if_save){
  326. materialList[materialIndex]=$("#form1").serializeArray()
  327. }
  328. materialIndex=index
  329. $('.material-message-active').removeClass('material-message-active')
  330. if(materialIndex){
  331. $('.material-message-small').eq(materialIndex-1).addClass('material-message-active').show()
  332. $('.material-editor-head-btn').show()
  333. }else{
  334. $('.material-message-big').addClass('material-message-active').show()
  335. $('.material-editor-head-btn').hide()
  336. }
  337. $('.material-right .material-arrow').css('top',materialArrow[materialIndex]+'px')
  338. $('.material-editor-head-number').text(materialIndex+1)
  339. if(materialList[materialIndex]){
  340. for(var i in materialList[materialIndex]){
  341. $('[name="'+materialList[materialIndex][i]['name']+'"]').val(materialList[materialIndex][i]['value'])
  342. if(materialList[materialIndex][i]['name']=='content'){
  343. ue.setContent(materialList[materialIndex][i]['value'])
  344. }else if(materialList[materialIndex][i]['name']=='thumb_media_id'){
  345. if(materialList[materialIndex][i]['value']){
  346. $('.uploader-image').attr('src','{:url("admin/Wechat/get_material_image")}?media_id='+materialList[materialIndex][i]['value']).show()
  347. $('.uploader-content').hide()
  348. }else{
  349. $('.uploader-image').hide()
  350. $('.uploader-content').show()
  351. }
  352. }
  353. }
  354. }
  355. }
  356. function setTitle(obj){
  357. var title='标题'
  358. if(obj.val()){
  359. title=obj.val()
  360. }
  361. if(materialIndex){
  362. $('.material-message-small').eq(materialIndex-1).find('.material-message-small-title').text(title)
  363. }else{
  364. $('.material-message-big-title').text(title)
  365. }
  366. }
  367. function submit(){
  368. $('label.error').remove()
  369. materialList[materialIndex]=$("#form1").serializeArray()
  370. $.ajax({
  371. type: "POST",
  372. url: '{$Request.url}',
  373. dataType: 'json',
  374. data: {articles:materialList},
  375. success: function (res) {
  376. if (res.code == 10000) {
  377. window.history.back(-1)
  378. } else {
  379. if(res.result){
  380. $('[name="'+res.result.name+'"]').parents('dd').append('<label class="error">不能为空</label>')
  381. if(res.result.index!=0){
  382. getMaterial($('.material-message-small').eq(res.result.index-1),false)
  383. }else{
  384. getMaterial($('.material-message-big'),false)
  385. }
  386. }else{
  387. layer.msg(res.message)
  388. }
  389. }
  390. }
  391. })
  392. }
  393. </script>