teacherEdit.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php use common\widgets\UeditorWidget; ?>
  2. <!--百度图片上传-->
  3. <link rel="stylesheet" type="text/css" href="/js/webuploader-0.1.5/webuploader.css">
  4. <script type="text/javascript" src="/js/webuploader-0.1.5/webuploader.js"></script>
  5. <div class="row">
  6. <div class="col-sm-12">
  7. <div class="panel panel-default">
  8. <div class="panel-body">
  9. <form role="form" class="form-horizontal">
  10. <div class="form-group">
  11. <label class="col-sm-2 control-label">名称:</label>
  12. <input type="hidden" name="id" value="<?= $info['id'] ?>"/>
  13. <div class="col-sm-10">
  14. <input type="text" class="form-control" name="teacherName"
  15. value="<?= $info['teacherName'] ?>"
  16. placeholder="">
  17. <p></p>
  18. </div>
  19. </div>
  20. <div class="form-group">
  21. <label class="col-sm-2 control-label">头衔:</label>
  22. <div class="col-sm-10">
  23. <input type="text" class="form-control" name="title"
  24. value="<?= $info['title'] ?>"
  25. placeholder="">
  26. <p></p>
  27. </div>
  28. </div>
  29. <div class="form-group">
  30. <label class="col-sm-2 control-label">头像:</label>
  31. <div class="col-sm-10">
  32. <div>
  33. <img name="teacherAvatar" width="80" src="<?php if(!empty($info['avatar'])){ echo Yii::$app->params['imgUrl'].$info['avatar']; }else{ echo '/images/teacher_default_avatar.jpg'; }?>" />
  34. </div>
  35. <div id="uploader-demo" style="margin-top:2px;">
  36. <div id="fileList" class="uploader-list"></div>
  37. <div id="filePicker">选择图片</div>
  38. </div>
  39. <input type="hidden" class="form-control" name="avatar" value="<?= $info['avatar'] ?>" placeholder="">
  40. <p></p>
  41. </div>
  42. </div>
  43. <div class="form-group">
  44. <label class="col-sm-2 control-label" for="field-3">简介:</label>
  45. <div class="col-sm-10">
  46. <?= UeditorWidget::widget(['name' => 'intro','content' => $info['intro']]); ?>
  47. <p></p>
  48. </div>
  49. </div>
  50. <div class="form-group-separator"></div>
  51. <div class="form-group" style="text-align:center;">
  52. <button type="button" onclick="addSubmit('click',this)" class="btn btn-info btn-single">确认
  53. </button>
  54. <button type="button" onclick="history.go(-1);" class="btn btn-info btn-single">返回</button>
  55. </div>
  56. </form>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- footer -->
  62. <?php
  63. use backend\widgets\FooterWidget;
  64. ?>
  65. <?= FooterWidget::widget() ?>
  66. <!-- footer -->
  67. <script>
  68. //文章验证流程
  69. var id = $("input[name=id]");
  70. var teacherName = $("input[name=teacherName]");
  71. var title = $("input[name=title]");
  72. var avatar = $("input[name=avatar]");
  73. var intro = $("textarea[name=intro]");
  74. var needValidate = [teacherName, avatar, intro];
  75. //修改文章验证流程
  76. addSubmit();
  77. function addSubmit() {
  78. setStats(teacherName, '请填写名称', function (val, mess) {
  79. var info = [false, mess];
  80. if (val.length <= 0) {
  81. info[1] = '请填写名称';
  82. } else if (getLength(val) > 0) {
  83. info[0] = true;
  84. info[1] = '填写正确';
  85. } else {
  86. info[0] = false;
  87. }
  88. return info;
  89. });
  90. setStats(avatar, '请上传头像', function (val, mess) {
  91. var info = [false, mess];
  92. if (val.length <= 0) {
  93. info[1] = '请上传头像';
  94. } else if (getLength(val) > 0) {
  95. info[0] = true;
  96. info[1] = '填写正确';
  97. } else {
  98. info[0] = false;
  99. }
  100. return info;
  101. });
  102. setStats(intro, '请填写简介', function (val, mess) {
  103. var info = [false, mess];
  104. if (getLength(val) > 0) {
  105. info[0] = true;
  106. info[1] = '填写正确';
  107. } else {
  108. info[1] = '请填写简介';
  109. }
  110. return info;
  111. });
  112. if (arguments[0] == 'click') {//用户点击提交
  113. var verifyStatus = true;
  114. for (var m = 0; m < needValidate.length; m++) {
  115. var singleObj = needValidate[m];
  116. if (singleObj.attr('addStatus') == undefined) {
  117. singleObj.blur();
  118. }
  119. if (singleObj.attr('addStatus') == 'no') {
  120. verifyStatus = false;
  121. continue;
  122. }
  123. }
  124. if (verifyStatus) {
  125. var data = "teacherName=" + teacherName.val() + "&title=" + title.val() + "&avatar=" + avatar.val() + "&intro=" + intro.val()+"&id="+id.val();
  126. data += "&_csrf=<?= Yii::$app->request->csrfToken ?>";
  127. $.ajax({
  128. type: "POST",
  129. url: '/teach/teacher-save-edit',
  130. data: data,
  131. dataType: 'json',
  132. async: false,
  133. success: function (data) {
  134. if (data.code == 'A0001') {
  135. xhPopMsg(data.msg, 1300);
  136. setTimeout(function () {
  137. window.location.href = '/teach/teacher';
  138. }, 1400);
  139. }
  140. }
  141. });
  142. }
  143. }
  144. }
  145. function setStats(obj, mess, check) {
  146. obj.focus(function () {
  147. $(this).removeAttr('addStatus');
  148. $(this).siblings('p').removeClass('help-error-mention').html('');
  149. $(this).parent().parent().removeClass("has-success").removeClass('has-error');
  150. });
  151. obj.blur(function () {
  152. var objVal = obj.val();
  153. var info = check(objVal, mess);
  154. if (info[0]) {
  155. $(this).attr('addStatus', 'yes');
  156. $(this).siblings('p').removeClass('help-error-mention').html('');
  157. $(this).parent().parent().addClass("has-success").removeClass("has-error");
  158. } else {
  159. $(this).attr('addStatus', 'no');
  160. $(this).siblings('p').addClass('help-error-mention').html(info[1]);
  161. $(this).parent().parent().addClass("has-error").removeClass("has-success");
  162. }
  163. });
  164. }
  165. // 图片上传demo
  166. jQuery(function() {
  167. var $ = jQuery,
  168. $list = $('#fileList'),
  169. // 优化retina, 在retina下这个值是2
  170. ratio = window.devicePixelRatio || 1,
  171. // 缩略图大小
  172. thumbnailWidth = 100 * ratio,
  173. thumbnailHeight = 100 * ratio,
  174. // Web Uploader实例
  175. uploader;
  176. // 初始化Web Uploader
  177. uploader = WebUploader.create({
  178. // 自动上传。
  179. auto: true,
  180. // swf文件路径
  181. swf: '/js/webuploader-0.1.5/Uploader.swf',
  182. //swf: BASE_URL + '/js/Uploader.swf',
  183. // 文件接收服务端。
  184. server: '/teach/upload-teacher-avatar',
  185. // 选择文件的按钮。可选。
  186. // 内部根据当前运行是创建,可能是input元素,也可能是flash.
  187. pick: '#filePicker',
  188. //是否允许重复上传
  189. duplicate :true,
  190. fileSingleSizeLimit: 1*1024*1024,//上传限制1M
  191. fileNumLimit: 5,//每次只能传5张
  192. formData: { "_csrf": '<?= Yii::$app->request->csrfToken?>'},
  193. // 只允许选择文件,可选。
  194. accept: {
  195. title: 'Images',
  196. extensions: 'gif,jpg,jpeg,bmp,png',
  197. mimeTypes: 'image/*'
  198. }
  199. });
  200. // 当有文件添加进来的时候
  201. uploader.on( 'fileQueued', function( file ) {
  202. //这里可以取到图片的宽高
  203. //uploader.makeThumb(file, function (error, src) {
  204. //console.log(file._info.width + '*' + file._info.height)
  205. //uploader.removeFile( file );
  206. //}, 100, 100);
  207. });
  208. // 文件上传过程中创建进度条实时显示。
  209. uploader.on( 'uploadProgress', function( file, percentage ) {
  210. });
  211. // 文件上传成功,给item添加成功class, 用样式标记上传成功。
  212. uploader.on( 'uploadSuccess', function( file, response) {
  213. $("img[name=teacherAvatar]").attr('src','<?= Yii::$app->params['imgUrl']?>'+response.data.url);
  214. $("input[name=avatar]").val(response.data.url);
  215. });
  216. // 文件上传失败,现实上传出错。
  217. uploader.on( 'uploadError', function( file ) {
  218. });
  219. // 完成上传完了,成功或者失败,先删除进度条。
  220. uploader.on( 'uploadComplete', function( file ) {
  221. xhPopMsg('上传成功', 1000);
  222. });
  223. uploader.on("error", function (type) {
  224. if (type == "Q_TYPE_DENIED") {
  225. alert("请上传JPG、PNG、GIF、BMP格式文件");
  226. } else if (type == "F_EXCEED_SIZE") {
  227. alert("单张图片不能超过1M");
  228. }else {
  229. alert("上传出错!请检查后重新上传!错误代码"+type);
  230. }
  231. });
  232. });
  233. </script>