uploadimg.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <!-- <div class="cl pd-5 bg-1 bk-gray">
  2. <a href="{:url('/file_manager/selectpicture')}" class="btn btn-default radius sethumb">
  3. <i class="Hui-iconfont">&#xe600;</i> 站内选择 </a>&nbsp;&nbsp;
  4. <a href="javascript:void(0);" class="btn btn-primary radius sethumb">
  5. <i class="Hui-iconfont">&#xe600;</i> 本地上传 </a>&nbsp;&nbsp;
  6. <a href="{:url('/file_manager/onlinepicture')}" class="btn btn-default radius sethumb">
  7. <i class="Hui-iconfont">&#xe600;</i> 网络图片 </a>&nbsp;&nbsp;
  8. </div> -->
  9. <!-- 本地上传 -->
  10. <style>
  11. #online {
  12. width: 100%;
  13. height: 224px;
  14. padding: 10px 0 0 0;
  15. }
  16. #online #imageList {
  17. width: 100%;
  18. height: 100%;
  19. overflow-x: hidden;
  20. overflow-y: auto;
  21. position: relative;
  22. margin-left: 20px;
  23. }
  24. #online ul {
  25. display: block;
  26. list-style: none;
  27. margin: 0;
  28. padding: 0;
  29. }
  30. #online li {
  31. float: left;
  32. display: block;
  33. list-style: none;
  34. padding: 0;
  35. width: 113px;
  36. height: 113px;
  37. margin: 0 0 9px 9px;
  38. background-color: #eee;
  39. overflow: hidden;
  40. cursor: pointer;
  41. position: relative;
  42. }
  43. #online li img {
  44. cursor: pointer;
  45. }
  46. #online li .icon {
  47. cursor: pointer;
  48. width: 113px;
  49. height: 113px;
  50. position: absolute;
  51. top: 0;
  52. left: 0;
  53. z-index: 2;
  54. border: 0;
  55. background-repeat: no-repeat;
  56. }
  57. #online li .icon:hover {
  58. width: 107px;
  59. height: 107px;
  60. border: 3px solid #1094fa;
  61. }
  62. #online li.selected .icon {
  63. background-image: url(/static/images/success.png);
  64. background-image: url(images/success.gif)\9;
  65. background-position: 75px 75px;
  66. }
  67. #online li.clearFloat {
  68. float: none;
  69. clear: both;
  70. display: block;
  71. width: 0;
  72. height: 0;
  73. margin: 0;
  74. padding: 0;
  75. }
  76. </style>
  77. <div id="tab-img" class="HuiTab">
  78. <div class="tabBar clearfix">
  79. <span>本地上传</span>
  80. <span>网络文件上传</span>
  81. <a onclick="onlinepicture(1)"><span>服务器图片选择</span></a>
  82. </div>
  83. <div class="tabCon">
  84. <div class="step1 active" style="margin-left:30px;">
  85. <form id="form-uploadimg" method="post" action="" enctype="multipart/form-data">
  86. <div class="row cl" style="margin-top:20px;">
  87. <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>图片要求: </label>
  88. <div class="formControls col-xs-8 col-sm-8">
  89. 格式 jpg,png,gif,jpeg,webp; 大小不超过4M.
  90. </div>
  91. <div class="col-3"> </div>
  92. </div>
  93. <div class="row cl" style="margin-top:20px;">
  94. <label class="form-label col-xs-2 col-sm-2">
  95. <span class="c-red">*</span>本地上传:</label>
  96. <div class="formControls col-xs-4 col-sm-4">
  97. <input type="file" class="input-text" name="upload_file" id="upload_file">
  98. </div>
  99. <div class="col-3"> </div>
  100. </div>
  101. <div class="row cl" style="margin-top:20px;">
  102. <input type="hidden" name="img_id" value={$img_id}>
  103. <div class="formControls col-xs-12 col-sm-8">
  104. <div class="skin-minimal">
  105. <div class="check-box">
  106. <input type="checkbox" name="overwrite" value="{$overwrite}" {$overwrite ? 'checked'
  107. : "" }>
  108. <label for="overwrite">覆盖原图</label>
  109. </div>
  110. <div class="check-box">
  111. <input type="checkbox" name="water" value="{$water}" {$water ? 'checked' : "" }>
  112. <label for="water">水印</label>
  113. </div>
  114. <div class="check-box">
  115. <input type="checkbox" name="thumb" value="{$thumb}" {$thumb ? 'checked' : "" }>
  116. <label for="thumb-1">缩略图</label>
  117. <input type="text" class="input-text" name="width" value={$width}
  118. style="width: 80px;">缩略图宽度
  119. <input type="text" class="input-text" name="height" value={$height}
  120. style="width: 80px;">缩略图高度
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="row cl" style="margin-top:30px;margin-left:30px;">
  126. <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
  127. <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;"
  128. onCLick="uploadImg()">
  129. <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
  130. onClick="layer_close();">
  131. </div>
  132. </div>
  133. </form>
  134. </div>
  135. <!-- 本地上传end -->
  136. </div>
  137. <div class="tabCon">
  138. </div>
  139. <!-- 在线图片 -->
  140. <div class="tabCon">
  141. </div>
  142. </div>
  143. <!--请在下方写此页面业务相关的脚本-->
  144. <script type="text/javascript">
  145. jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
  146. var $tab_menu = $(tabBar);
  147. // 初始化操作
  148. $tab_menu.removeClass(class_name);
  149. $(tabBar).eq(i).addClass(class_name);
  150. $(tabCon).hide();
  151. $(tabCon).eq(i).show();
  152. $tab_menu.bind(tabEvent, function () {
  153. $tab_menu.removeClass(class_name);
  154. $(this).addClass(class_name);
  155. var index = $tab_menu.index(this);
  156. $(tabCon).hide();
  157. $(tabCon).eq(index).show()
  158. })
  159. }
  160. $(function () {
  161. $.Huitab("#tab-img .tabBar span", "#tab-img .tabCon", "current", "click", "0");
  162. $(document).on("click", "#online li", function(){
  163. $("#online li").removeClass('selected');
  164. $(this).addClass('selected');
  165. img = $(this).children('img').attr('_src');
  166. $("#online_file").val(img);
  167. })
  168. });
  169. function onlinepicture(page) {
  170. var data = { "page": page };
  171. $.ajax({
  172. url: '{:url("file_manager/onlineimg")}',
  173. type: 'GET',
  174. async: true,
  175. cache: false,
  176. data: 'page=' + page,
  177. processData: false,
  178. contentType: false,
  179. dataType: "json",
  180. success: function (res) {
  181. if (res.code == 0) {
  182. html_str = "";
  183. res.list.forEach(element => {
  184. html_str += '<li><img width="170" height="113" src="' + element.url + '?noCache=' + element.mtime + '"';
  185. html_str += '_src="' + element.url + '">';
  186. html_str += '<span class="icon"></span></li>';
  187. });
  188. $('ul.list').prepend(html_str);
  189. }
  190. }
  191. });
  192. }
  193. //step1本地上传图片
  194. function uploadImg() {
  195. if ($("#upload_file").val() == '') {
  196. layer.msg("请选择要上传的文件", {
  197. icon: 6,
  198. time: 1000
  199. });
  200. return false;
  201. } else {
  202. var formData = new FormData($("#form-uploadimg")[0]);
  203. $.ajax({
  204. url: '{:url("file_manager/uploadimg")}',
  205. type: 'POST',
  206. async: true,
  207. cache: false,
  208. data: formData,
  209. processData: false,
  210. contentType: false,
  211. dataType: "json",
  212. beforeSend: function () {
  213. // loadIndex = layer.load();
  214. },
  215. success: function (res) {
  216. if (res.code == 0) {
  217. // layer.close(loadIndex);
  218. console.log(res);
  219. var img = res.picture_url + res.picname;
  220. window.parent.$("#" + res.img_id).val(img);
  221. if (res.thumbname) {
  222. img = res.picture_url + res.thumbname;
  223. window.parent.$("#thumb").val(img);
  224. }
  225. window.parent.$("#view-" + res.img_id).attr('src', img);
  226. layer_close();
  227. } else {
  228. // layer.close(loadIndex);
  229. layer.msg(res.msg, {
  230. icon: 5,
  231. time: 1000
  232. });
  233. return false;
  234. }
  235. }
  236. });
  237. }
  238. }
  239. // 网络图片
  240. function uploadUrlImg() {
  241. if ($("#url_file").val() == '') {
  242. layer.msg("文件地址不可以为空", {
  243. icon: 6,
  244. time: 1000
  245. });
  246. return false;
  247. } else {
  248. var formData = new FormData($("#form-uploadurlimg")[0]);
  249. $.ajax({
  250. url: '{:url("file_manager/uploadurlimg")}',
  251. type: 'POST',
  252. async: true,
  253. cache: false,
  254. data: formData,
  255. processData: false,
  256. contentType: false,
  257. dataType: "json",
  258. beforeSend: function () {
  259. // loadIndex = layer.load();
  260. },
  261. success: function (res) {
  262. if (res.code == 0) {
  263. console.log(res);
  264. // layer.close(loadIndex);
  265. var img = res.picture_url + res.picname;
  266. window.parent.$("#" + res.img_id).val(img);
  267. if (res.thumbname) {
  268. img = res.picture_url + res.thumbname;
  269. window.parent.$("#thumb").val(img);
  270. }
  271. window.parent.$("#view-" + res.img_id).attr('src', img);
  272. layer_close();
  273. } else {
  274. // layer.close(loadIndex);
  275. layer.msg(res.msg, {
  276. icon: 5,
  277. time: 1000
  278. });
  279. return false;
  280. }
  281. }
  282. });
  283. }
  284. }
  285. function uploadOnlineImg() {
  286. if ($("#online_file").val() == '') {
  287. layer.msg("文件地址不可以为空", {
  288. icon: 6,
  289. time: 1000
  290. });
  291. return false;
  292. } else {
  293. var formData = new FormData($("#form-uploadonlineimg")[0]);
  294. $.ajax({
  295. url: '{:url("file_manager/uploadonlineimg")}',
  296. type: 'POST',
  297. async: true,
  298. cache: false,
  299. data: formData,
  300. processData: false,
  301. contentType: false,
  302. dataType: "json",
  303. beforeSend: function () {
  304. // loadIndex = layer.load();
  305. },
  306. success: function (res) {
  307. if (res.code == 0) {
  308. // console.log(res);
  309. // layer.close(loadIndex);
  310. var img = res.picname;
  311. window.parent.$("#" + res.img_id).val(img);
  312. if (res.thumbname) {
  313. img = res.thumbname;
  314. window.parent.$("#thumb").val(img);
  315. }
  316. window.parent.$("#view-" + res.img_id).attr('src', img);
  317. layer_close();
  318. } else {
  319. // layer.close(loadIndex);
  320. layer.msg(res.msg, {
  321. icon: 5,
  322. time: 1000
  323. });
  324. return false;
  325. }
  326. }
  327. });
  328. }
  329. }
  330. </script>
  331. <!--请在上方写此页面业务相关的脚本-->