add_article.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. {include file="public/header" /}
  2. <body class="gray-bg">
  3. <div class="layui-fluid layui-col-md12">
  4. <div class="layui-card">
  5. <div class="layui-card-header">添加文章</div>
  6. <div class="layui-card-body layui-form">
  7. <div class="layui-row layui-col-space10 layui-form-item ">
  8. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  9. <label class="layui-form-label">TableSelect</label>
  10. <div class="layui-input-block">
  11. <input type="text" class="layui-input layui-hide" id="layTables" name="title" lay-verify="required" placeholder="文章标题" value="1,3,5,7,9,11,13,14" >
  12. </div>
  13. </div>
  14. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  15. <label class="layui-form-label">一键粘贴</label>
  16. <div class="layui-input-block">
  17. <input type="text" class="layui-input layui-disabled" name="title" lay-verify="required" placeholder="文章标题" value="123123e214" readonly>
  18. <div class="layui-copy" onclick="wk.lay_copy(this)" title="复制" alt="复制"><span><i class="fa fa-paste"></i></span></div>
  19. </div>
  20. </div>
  21. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  22. <label class="layui-form-label">所属分类</label>
  23. <div class="layui-input-block">
  24. <select name="cate_id" lay-verify="required" lay-search="">
  25. <option value="">请选择分类</option>
  26. {if !empty($cate)}
  27. {foreach name="cate" item="vo"}
  28. <option value="{$vo.id}">{$vo.name}</option>
  29. {/foreach}
  30. {/if}
  31. </select>
  32. </div>
  33. </div>
  34. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  35. <label class="layui-form-label">三级联动</label>
  36. <div class="layui-input-inline">
  37. <select name="province" lay-search="" id="province" lay-filter="province">
  38. <option value="">---- 请选择省 ----</option>
  39. {foreach name="province" item="vo"}
  40. <option value="{$vo.district_id}">{$vo.district}</option>
  41. {/foreach}
  42. </select>
  43. </div>
  44. <div class="layui-input-inline">
  45. <select name="city" lay-search="" id="city" lay-filter="city">
  46. <option value="">---- 请选择市 ----</option>
  47. </select>
  48. </div>
  49. <div class="layui-input-inline">
  50. <select name="district" lay-search="" id="district" lay-filter="district">
  51. <option value="">---- 请选择区 ----</option>
  52. </select>
  53. </div>
  54. </div>
  55. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  56. <label class="layui-form-label">关键字</label>
  57. <div class="layui-input-block">
  58. <input type="text" class="layui-input " name="keyword" lay-verify="required" placeholder="文章关键字">
  59. </div>
  60. </div>
  61. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  62. <label class="layui-form-label">描述</label>
  63. <div class="layui-input-block">
  64. <textarea name="remark" class="layui-textarea" lay-verify="required" placeholder="文章描述"></textarea>
  65. </div>
  66. </div>
  67. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  68. <label class="layui-form-label">单图片上传</label>
  69. <input type="hidden" name="lay-img" id="lay-img" lay-verify="image">
  70. <div class="layui-input-block">
  71. <div id="lay-upload">上传图片</div>
  72. <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
  73. 预览图:
  74. <div class="layui-upload-list" id="lay-img-list">
  75. </div>
  76. </blockquote>
  77. </div>
  78. </div>
  79. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  80. <label class="layui-form-label">单图片上传</label>
  81. <input type="hidden" name="lay-img1" id="lay-img1" lay-verify="image">
  82. <div class="layui-input-block">
  83. <div id="lay-upload1">上传图片</div>
  84. <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
  85. 预览图:
  86. <div class="layui-upload-list" id="lay-img-list1">
  87. </div>
  88. </blockquote>
  89. </div>
  90. </div>
  91. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  92. <label class="layui-form-label">音频上传</label>
  93. <input type="hidden" name="lay-music" id="lay-music" lay-verify="music">
  94. <div class="layui-input-block">
  95. <div id="lay-music-upload">上传音频</div>
  96. <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
  97. 预览音频:
  98. <div class="layui-upload-list" id="lay-music-list">
  99. </div>
  100. </blockquote>
  101. </div>
  102. </div>
  103. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  104. <label class="layui-form-label">音频上传</label>
  105. <input type="hidden" name="lay-music" id="lay-music1" lay-verify="music">
  106. <div class="layui-input-block">
  107. <div id="lay-music-upload1">上传音频</div>
  108. <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
  109. 预览音频:
  110. <div class="layui-upload-list" id="lay-music-list1">
  111. </div>
  112. </blockquote>
  113. </div>
  114. </div>
  115. <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8">-->
  116. <!--<label class="layui-form-label">上传视频:</label>-->
  117. <!--<div class="layui-input-block">-->
  118. <!--<button type="button" class="layui-btn" id="lay-upload2">上传视频</button>-->
  119. <!--<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">-->
  120. <!--预览视频:-->
  121. <!--<div class="layui-upload-list" id="lay-video-list">-->
  122. <!--<span id="lay-msg" style="display: none;">-->
  123. <!--<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="lay-video">-->
  124. <!--<div class="layui-progress-bar" lay-percent="0%"></div>-->
  125. <!--</div>-->
  126. <!--<p>正在上传... <i class="layui-icon layui-icon-loading-1 layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i></p>-->
  127. <!--</span>-->
  128. <!--</div>-->
  129. <!--</blockquote>-->
  130. <!--</div>-->
  131. <!--</div>-->
  132. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  133. <label class="layui-form-label">上传视频:</label>
  134. <input type="hidden" name="lay-video" >
  135. <div class="layui-input-block">
  136. <div id="lay-upload2">上传视频</div>
  137. <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
  138. 预览视频:
  139. <div class="layui-upload-list" id="lay-video-list">
  140. </div>
  141. </blockquote>
  142. </div>
  143. </div>
  144. <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
  145. <label class="layui-form-label">多图片上传</label>
  146. <div class="layui-input-block">
  147. <input type="hidden" name="photo" id="photo" lay-verify="image">
  148. <div id="uploader" class="container">
  149. <div class="queueList">
  150. <div class="placeholder">
  151. <div id="filePicker"></div>
  152. <p>或将照片拖到这里</p>
  153. </div>
  154. </div>
  155. <div class="statusBar" style="display:none;">
  156. <div class="layui-progress layui-progress-big active" lay-showpercent="true">
  157. <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
  158. </div>
  159. <span></span>
  160. </div>
  161. <div class="info"></div>
  162. <div class="btns">
  163. <div id="goPicker" class="filePicker2"></div>
  164. <div class="uploadBtn">开始上传</div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
  171. <label class="layui-form-label">多图片上传1</label>
  172. <div class="layui-input-block">
  173. <input type="hidden" name="photo" id="photo1" lay-verify="image">
  174. <div id="uploader1" class="container">
  175. <div class="queueList">
  176. <div class="placeholder">
  177. <div id="filePicker1"></div>
  178. <p>或将照片拖到这里</p>
  179. </div>
  180. </div>
  181. <div class="statusBar" style="display:none;">
  182. <div class="layui-progress layui-progress-big active" lay-showpercent="true">
  183. <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
  184. </div>
  185. <span></span>
  186. </div>
  187. <div class="info"></div>
  188. <div class="btns">
  189. <div id="goPicker1" class="filePicker2"></div>
  190. <div class="uploadBtn">开始上传</div>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
  197. <label class="layui-form-label">多图片上传2</label>
  198. <div class="layui-input-block">
  199. <input type="hidden" name="photo" id="photo2" lay-verify="image">
  200. <div id="uploader2" class="container">
  201. <div class="queueList">
  202. <div class="placeholder">
  203. <div id="filePicker2"></div>
  204. <p>或将照片拖到这里</p>
  205. </div>
  206. </div>
  207. <div class="statusBar" style="display:none;">
  208. <div class="layui-progress layui-progress-big active" lay-showpercent="true">
  209. <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
  210. </div>
  211. <span></span>
  212. </div>
  213. <div class="info"></div>
  214. <div class="btns">
  215. <div id="goPicker2" class="filePicker2"></div>
  216. <div class="uploadBtn">开始上传</div>
  217. </div>
  218. </div>
  219. </div>
  220. </div>
  221. </div>
  222. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  223. <label class="layui-form-label">所属分类</label>
  224. <div class="layui-input-block">
  225. <select name="cate_id" lay-verify="required" lay-search="">
  226. <option value="">请选择分类</option>
  227. {if !empty($cate)}
  228. {foreach name="cate" item="vo"}
  229. <option value="{$vo.id}">{$vo.name}</option>
  230. {/foreach}
  231. {/if}
  232. </select>
  233. </div>
  234. </div>
  235. <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
  236. <label class="layui-form-label">wangEditor编辑器</label>
  237. <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
  238. </div>
  239. </div>
  240. <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
  241. <label class="layui-form-label">layEdit</label>
  242. <div class="layui-input-block" >
  243. <textarea class="layui-textarea" name="lay_content" id="LAY_editor1" placeholder="文章描述"></textarea>
  244. </div>
  245. </div>
  246. <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
  247. <label class="layui-form-label">百度富文本:</label>
  248. <div class="layui-input-block" >
  249. <textarea name="lay_content" id="LAY_editor2" placeholder="文章描述"></textarea>
  250. </div>
  251. </div>
  252. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  253. <label class="layui-form-label">浏览量</label>
  254. <div class="layui-input-block">
  255. <input type="text" class="layui-input " name="views" lay-verify="required" placeholder="文章浏览量" onkeyup="value=value.replace(/[^\d]/g,'')">
  256. </div>
  257. </div>
  258. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  259. <label class="layui-form-label">作者</label>
  260. <div class="layui-input-block">
  261. <input type="text" class="layui-input " name="views" lay-verify="required" placeholder="文章作者">
  262. </div>
  263. </div>
  264. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  265. <label class="layui-form-label">是否推荐</label>
  266. <div class="layui-input-block">
  267. <input type="radio" name="is_tui" value="1" title="是" checked>
  268. <input type="radio" name="is_tui" value="2" title="否" >
  269. </div>
  270. </div>
  271. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  272. <div class="layui-input-block">
  273. <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
  274. </button>
  275. <button class="layui-btn layui-btn-primary" onclick="history.back()">关闭</button>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. {include file="public/footer" /}
  283. <script>
  284. //百度富文本编辑器
  285. var editor = UE.getEditor('LAY_editor2', {
  286. initialFrameHeight:450,
  287. autoHeight: false,
  288. autoHeightEnabled:false,
  289. autoFloatEnabled:false
  290. });
  291. //自定义上传接口
  292. UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
  293. UE.Editor.prototype.getActionUrl = function(action) {
  294. if (action == 'uploadimage' || action == 'uploadscrawl') {
  295. return '/admin/upload/ueditorUpload';//这就是自定义的上传地址
  296. } else {
  297. return this._bkGetActionUrl.call(this, action);
  298. }
  299. }
  300. var n = wk.uploads({num:3,type:'png',url:"{:url('admin/upload/uploadLocality')}"});
  301. var n1 = wk.uploads({num:4,type:'jpg',attr:1});
  302. var n2 = wk.uploads({num:6,type:'jpg,png',attr:2});
  303. function imgDel(e,obj){
  304. wk.uploads_del(e,obj,n,"{:url('admin/upload/deleteLocality')}");
  305. }
  306. function imgDel1(e,obj){
  307. wk.uploads_del(e,obj,n1);
  308. }
  309. function imgDel2(e,obj){
  310. wk.uploads_del(e,obj,n2);
  311. }
  312. var editor = wk.wang({elem:'#LAY_editor'});
  313. var index = wk.layeditor('LAY_editor1');
  314. wk.uploadImg({size:2,type:'png',url:"{:url('Upload/upload')}",domain:"{:config('qiniu.domain')}"});
  315. wk.uploadImg({size:5,num:1,type:'jpg',url:"{:url('Upload/upload')}",domain:"{:config('qiniu.domain')}"});
  316. wk.uploadMusic({size:100,type:'mp3',url:"{:url('Upload/upload')}",domain:"{:config('qiniu.domain')}"});
  317. wk.uploadMusic({size:100,num:1,type:'mp3',url:"{:url('Upload/upload')}",domain:"{:config('qiniu.domain')}"});
  318. wk.tableSelect({elem:'#layTables',field:'id',name:'name',key:'keyword',splaceholder:'昵称',iplaceholder:'请选择数据',url:"{:url('getUserData')}",cols:[{type: 'checkbox'}, {field: 'id', width: '', title: 'ID', align: 'center'}, {field: 'name', width: '', title: '用户名', align: 'center'}]});
  319. var uploader = WebUploader.create({
  320. auto: true,// 选完文件后,是否自动上传。
  321. server: '/admin/Upload/video',// 文件接收服务端。
  322. duplicate :true,// 重复上传文件,true为可重复false为不可重复
  323. chunked: true,// 分片上传大文件
  324. pick: {
  325. id: "#lay-upload2",// 选择文件的按钮
  326. multiple: false,//true多文件上传 false单文件上传
  327. label: "选择视频"
  328. },
  329. fileSingleSizeLimit: 200*1024*1024, //限制上传单个文件大小,单位是B,1M=1024000B
  330. accept: {
  331. title: 'Video',
  332. extensions: 'mp4',
  333. mimeTypes: '.mp4'
  334. },
  335. //上传成功
  336. 'onUploadSuccess': function(file, data, response) {
  337. layui.config({
  338. base: '/src/' //静态资源所在路径
  339. }).extend({
  340. ckplayer: 'modules/ckplayer'
  341. }).use(['ckplayer'], function() {
  342. var ckplayer = layui.ckplayer
  343. var videoObject = {
  344. container: '#' + file.id,
  345. loop: false,
  346. autoplay: false,
  347. video: [
  348. [data._raw, 'video/mp4']
  349. ]
  350. };
  351. var player = new ckplayer(videoObject);
  352. })
  353. $( '#'+file.id ).show();
  354. $( '#'+file.id ).next('div').hide();
  355. $( '#'+file.id ).next().next('p').html('<span style="color: #009688;">上传成功!</span>');
  356. },
  357. //上传失败
  358. 'uploadError':function(file){
  359. $( '#'+file.id ).next('div').hide();
  360. $( '#'+file.id ).next().next('p').html('<span style="color: #FF5722;">上传失败!</span>');
  361. }
  362. });
  363. //上传进度
  364. uploader.on( 'uploadProgress' ,function(file,percentage){
  365. layui.element.progress('lay-video', Math.round(100 * percentage)+'%');
  366. });
  367. //视频加入队列
  368. uploader.on( 'fileQueued', function( file ) {
  369. $('#lay-video-list').html('<div id="' + file.id + '" style="width: 80%;height: auto;display:none;"></div><div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="lay-video"><div class="layui-progress-bar" lay-percent="0%"></div></div><p id="lay-msg">正在上传... <i class="layui-icon layui-icon-loading-1 layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i></p>')
  370. });
  371. //错误信息提示
  372. uploader.on('error', function (code) {
  373. switch (code) {
  374. case 'F_EXCEED_SIZE':
  375. layer.msg('视频大小不得超过'+ uploader.options.fileSingleSizeLimit/1024/1024 + 'MB',{icon:2,time:1500,shade:0.1});
  376. break;
  377. case 'Q_TYPE_DENIED':
  378. layer.msg('请上传正确的视频格式',{icon:2,time:1500,shade:0.1});
  379. break;
  380. default:
  381. layer.msg('上传错误,请刷新',{icon:2,time:1500,shade:0.1});
  382. break;
  383. }
  384. });
  385. layui.use(['form','upload','layedit','element'], function() {
  386. var form = layui.form
  387. , layedit = layui.layedit
  388. , upload = layui.upload
  389. , element = layui.element
  390. //layedit富文本
  391. layedit.set({
  392. uploadImage: {
  393. url: '/admin/Upload/layUpload',
  394. type: 'post'
  395. }
  396. });
  397. var index = layedit.build('LAY_editor1', {height: 400});
  398. form.verify({
  399. image:[/\S/,'请上传图片'],
  400. music:[/\S/,'请上传音频'],
  401. editor:function(value,item){
  402. if(editor.txt.html() == '<p><br></p>'){
  403. return '请填写内容';
  404. }
  405. }
  406. });
  407. form.on('submit(component-form-element)', function (data) {
  408. $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
  409. data.field.html = editor.txt.html();
  410. layedit.sync(index);
  411. // data.field.lay_content = layedit.getContent(index);
  412. $.ajax({
  413. url:"{:url('add_article')}",
  414. type:'post',
  415. dataType:'json',
  416. data:data.field,
  417. success:function(res){
  418. if (res.code == 200) {
  419. layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
  420. wk.layer_close();
  421. })
  422. } else {
  423. $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
  424. wk.error(res.msg);
  425. return false;
  426. }
  427. }
  428. })
  429. });
  430. });
  431. </script>
  432. </body>
  433. </html>