index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <style>
  2. .flower-img {
  3. margin-top: 10px;
  4. }
  5. .flower-img .flower-gallery-left .flower-gallery-sidebar ul li {
  6. border-bottom: 1px solid #DDDDDD;
  7. padding: 10px 0 10px 0;
  8. }
  9. .train_right {
  10. float: right;
  11. width: 78%;
  12. }
  13. .train_right .train_img_item {
  14. float: left;
  15. width: 18%;
  16. border: 1px solid #ccc;
  17. padding: 3px;
  18. margin-right: 1%;
  19. float: left;
  20. margin-bottom: 20px;
  21. }
  22. .train_right .train_img_item .img_bottom_text {
  23. font-size: 3px;
  24. }
  25. .train_right .train_img_item .img_bottom_text .img_order i {
  26. font-style: normal;
  27. }
  28. .train_right .train_img_item .img_bottom_text .img_trash {
  29. float: right;
  30. margin-right: 5px;
  31. }
  32. .train_right .train_img_category {
  33. height: 40px;
  34. border: 1px solid #F3F3F3;
  35. margin-bottom: 20px;
  36. }
  37. .train_right .train_img_category .train_name {
  38. margin-right: 5%;
  39. font-weight: bold;
  40. font-size: 18px;
  41. float: right;
  42. margin-top: 6px;
  43. }
  44. </style>
  45. <script type="text/javascript" src="/js/jquery-1.11.1.min.js"></script>
  46. <!--百度图片上传-->
  47. <link rel="stylesheet" type="text/css" href="/js/webuploader-0.1.5/webuploader.css">
  48. <script type="text/javascript" src="/js/webuploader-0.1.5/webuploader.js"></script>
  49. <?php
  50. use backend\widgets\TabWidget;
  51. echo TabWidget::widget(['list' => $this->context->menuList, 'currentMenu' => $this->context->id]);
  52. ?>
  53. <div class="panel panel-default">
  54. <?php
  55. use backend\widgets\SubTabWidget;
  56. echo SubTabWidget::widget(['list' => $this->context->subMenuList, 'currentMenu' => $this->context->action->id]);
  57. ?>
  58. <section class="gallery-env flower-img">
  59. <div class="row flower-row">
  60. <div>
  61. <div class="col-sm-9 gallery-right train_right">
  62. <div class="album-header train_img_category">
  63. <div id="uploader-demo" style="display:inline-block;float:left;">
  64. <!--用来存放item-->
  65. <div id="fileList" class="uploader-list"></div>
  66. <div id="filePicker">选择图片</div>
  67. </div>
  68. <div style="margin-top:12px;display:inline-block;width:50%;float:left;margin-left:5px;font-size:12px;font-size:100%;"><?= $categoryInfo['notice'] ?></div>
  69. <span class="train_name"><?php echo $categoryInfo['name']; ?></span>
  70. </div>
  71. <div>
  72. <div>
  73. <div id="train_img_list"></div>
  74. <?php if (!empty($models)) {
  75. foreach ($models as $model) { ?>
  76. <div class="train_img_item" id="train_image_item_<?= $model['id'] ?>">
  77. <a href="javascript:void(0)" class="thumb" data-action="edit">
  78. <img src="/images/grey/<?= $shapeInfo['name'] ?>.gif" style="width:100%;" data-original="<?= Yii::$app->params['imgUrl'] . $model['mobileUrl']; ?>" class="lazy"/>
  79. </a>
  80. <div class="image-options img_bottom_text">
  81. <span class="img_order"
  82. id="orderText<?= $model['id'] ?>"><i><?= $model['picSort'] ?></i></span>
  83. <span class="img_order" id="orderNum<?= $model['id'] ?>"
  84. style="display:none;">
  85. <input type="text" id="orderInput<?= $model['id'] ?>"
  86. onblur="saveOrder(<?= $model['id'] ?>,this)"
  87. style="width:35px;height:16px;font-size:5px;borde:1px solid #E5E5E5"
  88. value="<?= $model['picSort'] ?>"/>
  89. </span> <a href="javascript:void(0)" data-action="edit"><i
  90. onclick="changeOrder(this)" class="fa-pencil"></i></a>
  91. <a href="javascript:void(0)" onclick="delImg(<?= $model['id'] ?>)"
  92. class="img_trash"><i class="fa-trash"></i></a>
  93. </div>
  94. </div>
  95. <?php }
  96. } ?>
  97. </div>
  98. <div>
  99. <div class="dataTables_paginate paging_simple_numbers"
  100. style="float:right;padding-top:0px;margin-right:15px;">
  101. <?= $paging ?>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="col-sm-3 gallery-left flower-gallery-left" style="width:18%">
  107. <div class="gallery-sidebar flower-gallery-sidebar">
  108. <a href="javascript:"
  109. class="btn btn-block btn-secondary btn-icon btn-icon-standalone btn-icon-standalone-right">
  110. <i data-toggle="tooltip" data-placement="top" title="" data-original-title="建议上传图片比例:600 x 400" class="linecons-photo"></i>
  111. <span>分类</span> </a>
  112. <ul class="list-unstyled">
  113. <?php if (!empty($category)) {
  114. foreach ($category as $cat) { ?>
  115. <li class="active">
  116. <a href="/teach/index?categoryId=<?= $cat['id'] ?>"> <i class="fa-folder-o"></i>
  117. <span <?php if ($categoryId == $cat['id']) { ?>
  118. style="font-weight:bold"
  119. <?php }; ?> ><?php echo $cat['name']; ?></span> </a>
  120. </li>
  121. <?php }
  122. } ?>
  123. </ul>
  124. </div>
  125. </div>
  126. </div>
  127. </div>
  128. </section>
  129. </div>
  130. <!-- footer -->
  131. <?php
  132. use backend\widgets\FooterWidget;
  133. echo FooterWidget::widget();
  134. ?>
  135. <!-- footer -->
  136. <script type="text/javascript" src="/js/jquery.lazyload.min.js"></script>
  137. <script>
  138. $(".lazy").lazyload({effect: "fadeIn"});
  139. </script>
  140. <script>
  141. // 图片上传demo
  142. jQuery(function () {
  143. var $ = jQuery,
  144. $list = $('#fileList'),
  145. // 优化retina, 在retina下这个值是2
  146. ratio = window.devicePixelRatio || 1,
  147. // 缩略图大小
  148. thumbnailWidth = 100 * ratio,
  149. thumbnailHeight = 100 * ratio,
  150. // Web Uploader实例
  151. uploader;
  152. // 初始化Web Uploader
  153. uploader = WebUploader.create({
  154. // 自动上传。
  155. auto: true,
  156. // swf文件路径
  157. swf: '/js/webuploader-0.1.5/Uploader.swf',
  158. //swf: BASE_URL + '/js/Uploader.swf',
  159. // 文件接收服务端。
  160. server: '/teach/upload-img',
  161. // 选择文件的按钮。可选。
  162. // 内部根据当前运行是创建,可能是input元素,也可能是flash.
  163. pick: '#filePicker',
  164. //是否允许重复上传
  165. duplicate: true,
  166. fileSingleSizeLimit: 1 * 1024 * 1024,//上传限制1M
  167. fileNumLimit: 5,//每次只能传5张
  168. formData: {"_csrf": '<?= Yii::$app->request->csrfToken?>', "categoryId": <?= $categoryId ?>},
  169. // 只允许选择文件,可选。
  170. accept: {
  171. title: 'Images',
  172. extensions: 'gif,jpg,jpeg,bmp,png',
  173. mimeTypes: 'image/*'
  174. }
  175. });
  176. // 当有文件添加进来的时候
  177. uploader.on('fileQueued', function (file) {
  178. //这里可以取到图片的宽高
  179. //uploader.makeThumb(file, function (error, src) {
  180. //console.log(file._info.width + '*' + file._info.height)
  181. //uploader.removeFile( file );
  182. //}, 100, 100);
  183. });
  184. // 文件上传过程中创建进度条实时显示。
  185. uploader.on('uploadProgress', function (file, percentage) {
  186. });
  187. // 文件上传成功,给item添加成功class, 用样式标记上传成功。
  188. uploader.on('uploadSuccess', function (file, response) {
  189. var imgItem = '<div class="train_img_item" id="train_image_item_' + response.data.id + '">\
  190. <a href="javascript:void(0)" class="thumb" data-action="edit">\
  191. <img src="<?= Yii::$app->params['imgUrl']?>' + response.data.url + '" class="img-responsive"/>\
  192. </a>\
  193. <div class="image-options img_bottom_text">\
  194. <span class="img_order"><i>' + response.data.picSort + '</i></span>\
  195. <span class="img_order" style="display:none;">\
  196. <input type="text" value="' + response.data.picSort + '" onblur="saveOrder(' + response.data.id + ',this)" style="width:35px;height:16px;font-size:5px;borde:1px solid #E5E5E5" />\
  197. </span>\
  198. <a href="javascript:void(0)" data-action="edit"><i onclick="changeOrder(this)" class="fa-pencil"></i></a>\
  199. <a href="javascript:void(0)" onclick="delImg(' + response.data.id + ')" class="img_trash"><i class="fa-trash"></i></a>\
  200. </div>\
  201. </div>';
  202. $("#train_img_list").append(imgItem);
  203. });
  204. // 文件上传失败,现实上传出错。
  205. uploader.on('uploadError', function (file) {
  206. });
  207. // 完成上传完了,成功或者失败,先删除进度条。
  208. uploader.on('uploadComplete', function (file) {
  209. xhPopMsg('上传成功', 1000);
  210. });
  211. uploader.on("error", function (type) {
  212. if (type == "Q_TYPE_DENIED") {
  213. alert("请上传JPG、PNG、GIF、BMP格式文件");
  214. } else if (type == "F_EXCEED_SIZE") {
  215. alert("单张图片不能超过1M");
  216. } else {
  217. alert("上传出错!请检查后重新上传!错误代码" + type);
  218. }
  219. });
  220. });
  221. function delImg() {
  222. var respond = confirm('确认删除?');
  223. if (respond == false) {
  224. return false;
  225. }
  226. var id = arguments[0];
  227. $.ajax({
  228. type: "GET", url: '/teach/del-img?id=' + id, async: false, dataType: 'json', success: function (data) {
  229. if (data.code == 'A0001') {
  230. xhPopMsg(data.msg, 5000);//调用定时浮层 XXX毫秒后消失
  231. $("#train_image_item_" + id).remove();
  232. } else {
  233. xhPopMsg(data.msg, 5000);//调用定时浮层 XXX毫秒后消失
  234. }
  235. }
  236. });
  237. }
  238. function changeOrder() {
  239. var o = arguments[0];
  240. $(o).parent().siblings().eq(0).css('display', 'none');
  241. $(o).parent().siblings().eq(1).css('display', 'inline-block');
  242. }
  243. function saveOrder() {
  244. var id = arguments[0];
  245. var o = arguments[1];
  246. var num = $(o).val();
  247. $.ajax({
  248. type: "GET",
  249. url: '/teach/change-order?id=' + id + '&num=' + num,
  250. async: false,
  251. dataType: 'json',
  252. success: function (data) {
  253. if (data.code == 'A0001') {
  254. xhPopMsg(data.msg, 5000);//调用定时浮层 XXX毫秒后消失
  255. setTimeout(function () {
  256. window.location.reload(true);
  257. }, 900);
  258. } else {
  259. xhPopMsg(data.msg, 5000);//调用定时浮层 XXX毫秒后消失
  260. }
  261. }
  262. });
  263. }
  264. </script>