add_information.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/3/17 0017
  6. * Time: 下午 3:41
  7. */
  8. use yii\helpers\Url;
  9. use yii\widgets\ActiveForm;
  10. use common\models\UploadForm;
  11. use kucha\ueditor\UEditor;
  12. $position_arr = [
  13. '0'=>'轮播框',
  14. '1'=>'平台公告',
  15. '2'=>'轮播框下方',
  16. ];
  17. //$type_arr = [
  18. // '0'=>'图片',
  19. // '1'=>'文字公告',
  20. // '2'=>'轮播框下方',
  21. //]
  22. ?>
  23. <script src="/js/layer/laydate/laydate.js"></script>
  24. <style type="text/css">
  25. .modal-backdrop.in {display: none!important;}
  26. .modal-open .modal {background: rgba(0, 0, 0, 0.52);}
  27. .modal.in .modal-dialog{position: fixed;margin-left: -300px;top: 10%;left: 50%;}
  28. .red{color: red;}
  29. </style>
  30. <?php if(empty($model->id)):?>
  31. <form id="tijiao" action="<?=Url::toRoute(['webconfig/add_information']);?>" method="post">
  32. <?php else:?>
  33. <form id="tijiao" action="<?=Url::toRoute(['webconfig/edit_information']);?>" method="post">
  34. <?php endif;?>
  35. <div class="col-sm-12">
  36. <div class="ibox float-e-margins">
  37. <div class="ibox-content form-horizontal">
  38. <div class="form-group">
  39. <label class="col-sm-2 control-label">类型:</label>
  40. <div class="col-sm-10" style="padding-left:0;padding-top: 7px;">
  41. <label><input name="Information[type]" type="radio" value="10"<?php if(!empty($model->type)):?><?=($model->type=='10')?"checked='checked'":''?><?php else:?>checked='checked'<?php endif ?>/>公告 </label>
  42. <label><input name="Information[type]" type="radio" value="20"<?php if(!empty($model->type)):?><?=($model->type=='20')?"checked='checked'":''?><?php endif;?> />关于我们 </label>
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. <label class="col-sm-2 control-label">标题:</label>
  47. <div class="col-sm-10" style="padding-left:0">
  48. <input type="text" name="Information[title]" id="title" class="form-control " rows="2" maxlength="120" value="<?=empty($model->title)?"":"$model->title";?>">
  49. <label class="red notice"></label>
  50. </div>
  51. </div>
  52. <!--上传封面-->
  53. <div class="form-group">
  54. <label class="col-sm-2 control-label">封面:</label><br>
  55. <a>
  56. <img src="<?=empty($model->covers)?"../images/default.jpg":Yii::getAlias('@imgdomain').'/'."$model->covers"?>" class="img-thumbnail articlelibrary_imgurl" id="imgurl" style="width: 200px;height: 100px;" imgtype="img">
  57. <input id="imgurl_input" type="hidden" name="Information[covers]" value="<?=empty($model->covers)?"":"$model->covers"?>" >
  58. </a>
  59. <!-- <span>轮播图片大小为1000*480</span>-->
  60. </div>
  61. <div class="form-group">
  62. <label class="col-sm-2 control-label">内容:</label>
  63. <div class="col-sm-10" style="padding-left:0">
  64. <div class="summernote"><?=isset($model->content)?$model->content:''?></div>
  65. <textarea name="Information[content]" id="content" class="form-control desc" style="display:none;" maxlength="255"></textarea>
  66. </div>
  67. </div>
  68. <input type="hidden" name="_csrf-backend" value="<?=Yii::$app->request->csrfToken;?>" />
  69. <input type="hidden" name="id" value="<?=empty($model->id)?'': $model->id;?>" />
  70. <div class="form-group">
  71. <div class="col-sm-2"></div>
  72. <div class="col-sm-10">
  73. <button type="button" class="btn btn-primary" id="submit1">提交</button>
  74. <button type="button" class="btn btn-default" onclick="location.href='<?=Url::toRoute(['webconfig/information']);?>';return false;">取消</button>
  75. </label>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </form>
  81. <!--上传封面图片的div-->
  82. <iframe name="upload_target" style="display: none;"></iframe>
  83. <div id="upload_picture" style="display: none;">
  84. <?php $form = ActiveForm::begin(
  85. [
  86. 'options' => ['enctype' => 'multipart/form-data','target'=>'upload_target'],
  87. 'action'=>Url::toRoute(['webconfig/advertimgurl']),
  88. 'method'=>'post',
  89. ]
  90. )?>
  91. <?= $form->field($picture_form, 'imageFile')->fileInput() ?>
  92. <input type="hidden" id="upfield" name="type" value="covers">
  93. <?php ActiveForm::end() ?>
  94. </div>
  95. <script>
  96. $('#title').blur(function(){
  97. var title = $('#title').val();
  98. $.ajax({
  99. url: '<?=Url::toRoute(['webconfig/checktitle'])?>',
  100. type: 'POST',
  101. dataType:"json",
  102. data: {title:title, '_csrf-backend': '<?=Yii::$app->request->getCsrfToken();?>'},
  103. success: function (data) {
  104. console.log(data)
  105. if(data=='该内容标题已存在'){
  106. lock = false;
  107. $('.notice').text('该内容标题已存在');
  108. }else{
  109. lock = true;
  110. $('.notice').text('');
  111. }
  112. }
  113. })
  114. });
  115. // 富文本編輯器
  116. $('.summernote').summernote({
  117. lang:"zh-CN",
  118. height: "300px",
  119. onImageUpload: function (files,editor, welEditable) { //the onImageUpload API
  120. img = sendFile(files[0], editor, welEditable);
  121. $('.gray-bg .modal-backdrop').hide();
  122. }
  123. });
  124. //编辑框里图片上传
  125. function sendFile(file, editor, welEditable) {
  126. data = new FormData();
  127. data.append("file", file);
  128. data.append("type", 'information');
  129. data.append("_csrf-backend", '<?=Yii::$app->request->csrfToken;?>');
  130. $.ajax({
  131. data: data,
  132. type: "POST",
  133. url: "<?=Url::toRoute(['webconfig/uploadsummernote'])?>",
  134. cache: false,
  135. contentType: false,
  136. processData: false,
  137. success: function(url) {
  138. editor.insertImage(welEditable,'<?=Yii::getAlias('@imgdomain'); ?>'+url);
  139. }
  140. });
  141. }
  142. $(document).on('click','#submit1',function(){
  143. var content = $('.note-editable').html();
  144. $('#content').text(content);
  145. $('#tijiao').submit()
  146. })
  147. // 上传封面
  148. $(".articlelibrary_imgurl").click(function(){
  149. $("#upload_picture input").click();
  150. $('#upload_picture input').change(function(){
  151. if($("#uploadpictureform-picture").val() != ""){
  152. $('#upload_picture form').submit();
  153. }
  154. });
  155. // var id = $(this).attr('id');
  156. // $('#upfield').attr('data',id);
  157. // var type=$(this).attr('imgtype');
  158. // $('#type').attr('value',type);
  159. });
  160. // 添加图片的返回函数
  161. function callback(message,status,url){
  162. if(status==1){
  163. var id = $('#upfield').attr('data');
  164. $('#imgurl').attr("src","<?=Yii::getAlias('@imgdomain'); ?>"+url);
  165. $('#imgurl_input').val(url);
  166. // $('#'+id+"_input").val(url);
  167. $("#uploadpictureform-picture").val("");
  168. $('#upload_picture form')[0].reset();
  169. }else{
  170. alert(message);
  171. }
  172. }
  173. </script>