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. <input type="hidden" name="id" value={$id}>
  104. <input type="hidden" name="cjid" value={$cjid}>
  105. <div class="formControls col-sm-8">
  106. <div class="skin-minimal">
  107. <div class="check-box">
  108. <input type="checkbox" name="thumb" value="true" {$thumb ? 'checked' : "" }>
  109. <label for="thumb-1">缩略图</label>
  110. <input type="text" class="input-text" name="width" value={$width}
  111. style="width: 80px;">缩略图宽度
  112. <input type="text" class="input-text" name="height" value={$height}
  113. style="width: 80px;">缩略图高度
  114. </div>
  115. <div class="check-box">
  116. <input type="checkbox" name="original" value="true" {$original ? 'checked'
  117. : "" }>
  118. <label for="overwrite">保留原图</label>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <div class="row cl" style="margin-top:30px;margin-left:30px;">
  124. <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
  125. <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;"
  126. onCLick="uploadImg()">
  127. <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
  128. onClick="layer_close();">
  129. </div>
  130. </div>
  131. </form>
  132. </div>
  133. <!-- 本地上传end -->
  134. </div>
  135. <div class="tabCon">
  136. </div>
  137. <!-- 在线图片 -->
  138. <div class="tabCon">
  139. </div>
  140. </div>
  141. <!--请在下方写此页面业务相关的脚本-->
  142. <script type="text/javascript">
  143. jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
  144. var $tab_menu = $(tabBar);
  145. // 初始化操作
  146. $tab_menu.removeClass(class_name);
  147. $(tabBar).eq(i).addClass(class_name);
  148. $(tabCon).hide();
  149. $(tabCon).eq(i).show();
  150. $tab_menu.bind(tabEvent, function () {
  151. $tab_menu.removeClass(class_name);
  152. $(this).addClass(class_name);
  153. var index = $tab_menu.index(this);
  154. $(tabCon).hide();
  155. $(tabCon).eq(index).show()
  156. })
  157. }
  158. $(function () {
  159. $.Huitab("#tab-img .tabBar span", "#tab-img .tabCon", "current", "click", "0");
  160. $(document).on("click", "#online li", function(){
  161. $("#online li").removeClass('selected');
  162. $(this).addClass('selected');
  163. img = $(this).children('img').attr('_src');
  164. $("#online_file").val(img);
  165. })
  166. });
  167. //step1本地上传图片
  168. function uploadImg() {
  169. if ($("#upload_file").val() == '') {
  170. layer.msg("请选择要上传的文件", {
  171. icon: 6,
  172. time: 1000
  173. });
  174. return false;
  175. } else {
  176. var formData = new FormData($("#form-uploadimg")[0]);
  177. $.ajax({
  178. url: '{:url("file_manager/uploadLocalImg")}',
  179. type: 'POST',
  180. async: true,
  181. cache: false,
  182. data: formData,
  183. processData: false,
  184. contentType: false,
  185. dataType: "json",
  186. beforeSend: function () {
  187. // loadIndex = layer.load();
  188. },
  189. success: function (res) {
  190. if (res.code == 0) {
  191. // layer.close(loadIndex);
  192. console.log(res);
  193. var img = res.picture_url + res.picname;
  194. window.parent.$("#" + res.img_id).val(img);
  195. if (res.thumbname) {
  196. img = res.picture_url + res.thumbname;
  197. window.parent.$("#thumb").val(img);
  198. }
  199. window.parent.$("#view-" + res.img_id).attr('src', img);
  200. layer_close();
  201. } else {
  202. // layer.close(loadIndex);
  203. layer.msg(res.msg, {
  204. icon: 5,
  205. time: 1000
  206. });
  207. return false;
  208. }
  209. }
  210. });
  211. }
  212. }
  213. function onlinepicture(page) {
  214. var data = { "page": page };
  215. $.ajax({
  216. url: '{:url("file_manager/onlineimg")}',
  217. type: 'GET',
  218. async: true,
  219. cache: false,
  220. data: 'page=' + page,
  221. processData: false,
  222. contentType: false,
  223. dataType: "json",
  224. success: function (res) {
  225. if (res.code == 0) {
  226. html_str = "";
  227. res.list.forEach(element => {
  228. html_str += '<li><img width="170" height="113" src="' + element.url + '?noCache=' + element.mtime + '"';
  229. html_str += '_src="' + element.url + '">';
  230. html_str += '<span class="icon"></span></li>';
  231. });
  232. $('ul.list').prepend(html_str);
  233. }
  234. }
  235. });
  236. }
  237. // 网络图片
  238. function uploadUrlImg() {
  239. if ($("#url_file").val() == '') {
  240. layer.msg("文件地址不可以为空", {
  241. icon: 6,
  242. time: 1000
  243. });
  244. return false;
  245. } else {
  246. var formData = new FormData($("#form-uploadurlimg")[0]);
  247. $.ajax({
  248. url: '{:url("file_manager/uploadurlimg")}',
  249. type: 'POST',
  250. async: true,
  251. cache: false,
  252. data: formData,
  253. processData: false,
  254. contentType: false,
  255. dataType: "json",
  256. beforeSend: function () {
  257. // loadIndex = layer.load();
  258. },
  259. success: function (res) {
  260. if (res.code == 0) {
  261. console.log(res);
  262. // layer.close(loadIndex);
  263. var img = res.picture_url + res.picname;
  264. window.parent.$("#" + res.img_id).val(img);
  265. if (res.thumbname) {
  266. img = res.picture_url + res.thumbname;
  267. window.parent.$("#thumb").val(img);
  268. }
  269. window.parent.$("#view-" + res.img_id).attr('src', img);
  270. layer_close();
  271. } else {
  272. // layer.close(loadIndex);
  273. layer.msg(res.msg, {
  274. icon: 5,
  275. time: 1000
  276. });
  277. return false;
  278. }
  279. }
  280. });
  281. }
  282. }
  283. function uploadOnlineImg() {
  284. if ($("#online_file").val() == '') {
  285. layer.msg("文件地址不可以为空", {
  286. icon: 6,
  287. time: 1000
  288. });
  289. return false;
  290. } else {
  291. var formData = new FormData($("#form-uploadonlineimg")[0]);
  292. $.ajax({
  293. url: '{:url("file_manager/uploadonlineimg")}',
  294. type: 'POST',
  295. async: true,
  296. cache: false,
  297. data: formData,
  298. processData: false,
  299. contentType: false,
  300. dataType: "json",
  301. beforeSend: function () {
  302. // loadIndex = layer.load();
  303. },
  304. success: function (res) {
  305. if (res.code == 0) {
  306. // console.log(res);
  307. // layer.close(loadIndex);
  308. var img = res.picname;
  309. window.parent.$("#" + res.img_id).val(img);
  310. if (res.thumbname) {
  311. img = res.thumbname;
  312. window.parent.$("#thumb").val(img);
  313. }
  314. window.parent.$("#view-" + res.img_id).attr('src', img);
  315. layer_close();
  316. } else {
  317. // layer.close(loadIndex);
  318. layer.msg(res.msg, {
  319. icon: 5,
  320. time: 1000
  321. });
  322. return false;
  323. }
  324. }
  325. });
  326. }
  327. }
  328. </script>
  329. <!--请在上方写此页面业务相关的脚本-->