upload.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. var upload_pic = [];
  2. var upload_pic_info = [];
  3. var upload_file = [];
  4. var upload = [];
  5. var showUploadE = false;
  6. var showUploadFilesUploadE = false;
  7. var showUploadFilesSearchE = false;
  8. var showUploadFilesSearchState = 1;
  9. var showUploadFilesSearchAll = false;
  10. var upload_search_default = '';
  11. var showUploadUrl;
  12. var showUploadType = 1;
  13. var showUploadCall = false;
  14. var showUploadThis = false;
  15. var showUploadIndex = false;
  16. var picManageE = false;
  17. var picManageI = false;
  18. var picManageV = false;
  19. var picManageLayer = false;
  20. var showUploadFilesValue = [];
  21. //创建监听函数
  22. var xhrOnProgress=function(fun) {
  23. xhrOnProgress.onprogress = fun; //绑定监听
  24. //使用闭包实现监听绑
  25. return function() {
  26. //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
  27. var xhr = $.ajaxSettings.xhr();
  28. //判断监听函数是否为函数
  29. if (typeof xhrOnProgress.onprogress !== 'function')
  30. return xhr;
  31. //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
  32. if (xhrOnProgress.onprogress && xhr.upload) {
  33. xhr.upload.onprogress = xhrOnProgress.onprogress;
  34. }
  35. return xhr;
  36. }
  37. }
  38. function showUpload(i,e,key,url,assets,type)
  39. {
  40. layui.use(['upload','layer','element'], function() {
  41. var html = '';
  42. var layer = layui.layer;
  43. var layerConfig = {
  44. type: 1,
  45. title: e.attr('value'),
  46. shade: 0.1,
  47. shadeClose : true,
  48. content: html,
  49. area: ['800px', '600px']
  50. };
  51. e.unbind('click').bind('click', function()
  52. {
  53. url = url.replace('save', 'view');
  54. showUploadE = e;
  55. if (!type) {
  56. type = 1;
  57. }
  58. showUploadType = type;
  59. showUploadUrl = url;
  60. var cur = $('#' + showUploadE.attr('v')).val();
  61. var value = '';
  62. if (e.attr('data-value')) {
  63. value = e.attr('data-value');
  64. }
  65. var upload_search = '';
  66. if (e.attr('upload_search')) {
  67. upload_search = e.attr('upload_search');
  68. }
  69. $.getJSON(url, {json:1,key:key,cur:cur,value:value,upload_search:upload_search}, function(t)
  70. {
  71. if (showUploadIndex) {
  72. layer.close(showUploadIndex);
  73. }
  74. //layer.closeAll();
  75. layerConfig.content = t.data;
  76. layerConfig.end = function() {
  77. if (showUploadFilesUploadE) {
  78. showUploadFilesUploadE = false;
  79. }
  80. }
  81. showUploadIndex = layer.open(layerConfig);
  82. })
  83. })
  84. });
  85. }
  86. function editorShowUpload(cur, url, title, func, self)
  87. {
  88. showUploadType = 2;
  89. showUploadCall = func;
  90. showUploadThis = self;
  91. layui.use(['upload','layer','element'], function() {
  92. var html = '';
  93. var layer = layui.layer;
  94. var layerConfig = {
  95. type: 1,
  96. title: title,
  97. shade: 0.1,
  98. shadeClose : true,
  99. content: html,
  100. area: '800px'
  101. };
  102. url = url.replace('save', 'view');
  103. showUploadUrl = url;
  104. $.getJSON(url, {json:1,cur:cur}, function(t)
  105. {
  106. layerConfig.content = t.data;
  107. showUploadIndex = layer.open(layerConfig);
  108. })
  109. });
  110. }
  111. //删除
  112. function showUploadFilesSetState(e, url)
  113. {
  114. if (confirm('确定进行此项操作吗?')) {
  115. $.getJSON(url, {json:1}, function(t)
  116. {
  117. if (!showUploadFilesSearchE) {
  118. showUploadFilesSearchE = $('#showUploadFilesSearch');
  119. }
  120. showUploadFilesSearch(showUploadFilesSearchE, showUploadFilesSearchState,showUploadFilesSearchAll);
  121. })
  122. }
  123. }
  124. function showUploadFilesShowValue(e)
  125. {
  126. var html = e.html();
  127. layer.alert(html);
  128. }
  129. function showUploadFilesSetValue(e, url, id, value)
  130. {
  131. if (showUploadFilesValue[id]) {
  132. value = showUploadFilesValue[id];
  133. }
  134. layer.prompt({
  135. formType: 2,
  136. value: value,
  137. title: '请输入附加值,例子:key1=value1&key2=value2',
  138. area: ['300px', '150px'] //自定义文本域宽高
  139. }, function(value, index, elem){
  140. showUploadFilesValue[id] = value;
  141. $.getJSON(url, {value:value}, function(t){});
  142. layer.close(index);
  143. });
  144. }
  145. function showUploadFilesSet(e, name, url, id)
  146. {
  147. $('.layui-anim-yes').addClass('layui-anim-no');
  148. $('.layui-anim-yes').removeClass('layui-anim-yes');
  149. e.parent().removeClass('layui-anim-no');
  150. e.parent().addClass('layui-anim-yes');
  151. $('.file_cur').val(url);
  152. if (showUploadType == 1) {
  153. var value = showUploadE.attr('v');
  154. var key = showUploadE.attr('key');
  155. loadUploadSet(showUploadE, value, {name:name,url:url}, key);
  156. } else if (showUploadType == 2) {
  157. showUploadCall.call(showUploadThis, url, name, id);
  158. } else if (showUploadType == 3) {
  159. var value = showUploadE.attr('editor_id');
  160. var key = showUploadE.attr('key');
  161. //KindEditor.insertHtml('#' + value, '<div class="dever-video"><embed src="'+url+'" type="video/x-ms-asf-plugin" width="450" height="300" autostart="false" loop="true" data-id="'+id+'" data-key="'+key+'"/><div style="width:450px;height:20px;">'+name+':'+id+'(请勿修改)</div></div>');
  162. KindEditor.insertHtml('#' + value, '<img src="'+url+'" style="width:450px;height:300px;" data-id="'+id+'" data-key="'+key+'"/>');
  163. }
  164. if (showUploadIndex) {
  165. layer.close(showUploadIndex);
  166. showUploadIndex = false;
  167. } else {
  168. layer.closeAll();
  169. }
  170. }
  171. function showUploadFilesUpload(e)
  172. {
  173. showUploadFilesUploadE = e;
  174. showUploadE.parent().find('.image_upload').click();
  175. }
  176. function showUploadFilesSearch(e, state, all, pg)
  177. {
  178. showUploadFilesSearchE = e;
  179. showUploadFilesSearchState = state;
  180. var p = e.parent();
  181. if (!pg) {
  182. var pg = p.find('.file_pg').val();
  183. }
  184. var key = p.find('.file_key').val();
  185. var name = p.find('.file_filename').val();
  186. var tag = p.find('.file_tag').val();
  187. var cate = p.find('.file_cate').val();
  188. var cur = p.find('.file_cur').val();
  189. var upload_search = p.find('.upload_search').val();
  190. var state = state;
  191. var url = showUploadUrl;
  192. if (upload_search) {
  193. upload_search_default = upload_search;
  194. }
  195. upload_search = upload_search_default;
  196. if (all) {
  197. upload_search = '';
  198. showUploadFilesSearchAll = true;
  199. } else {
  200. showUploadFilesSearchAll = false;
  201. }
  202. showUploadFiles(url, name, key, cate, tag, cur, pg, upload_search, state);
  203. }
  204. function showUploadFiles(url, name, key, cate, tag, cur, pg, upload_search, state)
  205. {
  206. if (!pg) {
  207. pg = 1;
  208. }
  209. $.getJSON(url, {json:1,key:key, name:name,cate:cate, tag:tag, pg:pg, cur:cur, upload_search:upload_search,state:state}, function(t)
  210. {
  211. var t = '<div>' + t.data + '</div>';
  212. html = $(t).find('#component-anim').html();
  213. $("#component-anim").html(html);
  214. })
  215. }
  216. function loadUploadL(i,e,key,url,assets)
  217. {
  218. var value = e.attr('v');
  219. if (typeof(upload[value]) != "undefined") {
  220. //return;
  221. }
  222. upload[value] = true;
  223. upload_pic[value] = [];
  224. upload_pic_info[value] = [];
  225. upload_file[value] = [];
  226. var id = e.attr('id');
  227. var token = e.attr('token');
  228. var host = e.attr('host');
  229. var domain = e.attr('domain');
  230. var path = e.attr('path');
  231. var cover = e.attr('cover');
  232. var type = e.attr('m');
  233. var search = '';
  234. if (e.attr('upload_search_value')) {
  235. search = e.attr('upload_search_value');
  236. }
  237. if (!cover) {
  238. cover = 1;
  239. }
  240. var uploadUrl = url;
  241. url = domain;
  242. layui.use(['layer','element'], function() {
  243. var layer = layui.layer;
  244. var element = layui.element;
  245. $("#" + id).unbind("change").bind("change",function() {
  246. var file = this.files[0];
  247. if (file) {
  248. element.progress(id + '_progress', '0%');
  249. layer.load();
  250. var filename = file.name;
  251. var temp = filename.split('.');
  252. var name = temp[0];
  253. filename = path + hex_md5(file.name) + '.' + temp[temp.length-1];
  254. //不覆盖
  255. if (cover == 2) {
  256. var timestamp = Date.parse(new Date());
  257. filename = path + hex_md5(file.name + '_' + timestamp) + '.' + temp[temp.length-1];
  258. }
  259. // 设置next,error,complete对应的操作,分别处理相应的进度信息,错误信息,以及完成后的操作
  260. var error = function(err) {
  261. //请求异常回调
  262. layer.alert('文件上传错误');
  263. element.progress(id + '_progress', '0%')
  264. $('#' + id + '_progress').hide();
  265. layer.closeAll('loading');
  266. };
  267. var complete = function(res) {
  268. //&& res.key.match(/\.(jpg|jpeg|png|gif)$/)
  269. if (res.key) {
  270. element.progress(id + '_progress', '0%')
  271. $('#' + id + '_progress').hide();
  272. layer.closeAll('loading');
  273. var data = {};
  274. if (res.hash) {
  275. if (search.indexOf('#') != -1) {
  276. var temp = search.split('#');
  277. search = temp[0];
  278. if (temp[1]) {
  279. temp[1] = $('#update_'+temp[1]+'_value').val();
  280. if (temp[1] > 0) {
  281. search = search + '_' + temp[1];
  282. }
  283. }
  284. }
  285. $.getJSON(uploadUrl.replace('save.start', 'yun.addFile'), {source:file.name,file:res.key, key:key, search:search});
  286. data.status = 1;
  287. data.name = res.key;
  288. data.url = host + res.key;
  289. loadUploadSet(e,value,data,key);
  290. } else {
  291. layer.alert('文件上传错误');
  292. return false;
  293. }
  294. }
  295. };
  296. if (type == 'qiniu') {
  297. qiniuHandle(id, name, token, domain, file, filename, element, error, complete);
  298. } else if(type == 'oss') {
  299. ossHandle(id, name, token, domain, file, filename, element, error, complete);
  300. }
  301. }
  302. });
  303. });
  304. }
  305. function ossHandle(id, name, token, domain, file, filename, element, error, complete)
  306. {
  307. console.info(id);
  308. let OSS = require('ali-oss')
  309. let ossConfig = {
  310. // region以杭州为例(oss-cn-hangzhou),其他region按实际情况填写。
  311. region: 'oss-cn-' + domain,
  312. // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
  313. accessKeyId: '<Your AccessKeyId>',
  314. accessKeySecret: '<Your AccessKeySecret>',
  315. bucket: 'Your bucket name'
  316. }
  317. let client = new OSS(ossConfig);
  318. let tempCheckpoint;
  319. // 定义上传方法。
  320. async function multipartUpload () {
  321. try {
  322. // object-key可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,实现将文件上传至当前Bucket或Bucket下的指定目录。
  323. let result = await client.multipartUpload('object-key', 'file-object', {
  324. progress: function (p, checkpoint) {
  325. // 断点记录点。浏览器重启后无法直接继续上传,您需要手动触发上传操作。
  326. tempCheckpoint = checkpoint;
  327. },
  328. meta: { year: 2020, people: 'test' },
  329. mime: 'image/jpeg'
  330. })
  331. } catch(e){
  332. console.log(e);
  333. }
  334. }
  335. // 开始分片上传。
  336. multipartUpload();
  337. // 暂停分片上传。
  338. client.cancel();
  339. // 恢复上传。
  340. let resumeclient = new OSS(ossConfig);
  341. async function resumeUpload () {
  342. try {
  343. let result = await resumeclient.multipartUpload('object-key', 'file-object', {
  344. progress: function (p, checkpoint) {
  345. tempCheckpoint = checkpoint;
  346. },
  347. checkpoint: tempCheckpoint,
  348. meta: { year: 2020, people: 'test' },
  349. mime: 'image/jpeg'
  350. })
  351. } catch (e) {
  352. console.log(e);
  353. }
  354. }
  355. resumeUpload();
  356. }
  357. function qiniuHandle(id, name, token, domain, file, filename, element, error, complete)
  358. {
  359. // eslint-disable-next-line
  360. var finishedAttr = [];
  361. // eslint-disable-next-line
  362. var compareChunks = [];
  363. var observable;
  364. var subscription;
  365. var next = function(response) {
  366. var chunks = response.chunks||[];
  367. var total = response.total;
  368. // 这里对每个chunk更新进度,并记录已经更新好的避免重复更新,同时对未开始更新的跳过
  369. for (var i = 0; i < chunks.length; i++) {
  370. if (chunks[i].percent === 0 || finishedAttr[i]){
  371. continue;
  372. }
  373. if (compareChunks[i].percent === chunks[i].percent){
  374. continue;
  375. }
  376. if (chunks[i].percent === 100){
  377. finishedAttr[i] = true;
  378. }
  379. }
  380. $('#' + id + '_progress').show();
  381. element.progress(id + '_progress', parseInt(total.percent)+'%')
  382. compareChunks = chunks;
  383. };
  384. var subObject = {
  385. next: next,
  386. error: error,
  387. complete: complete
  388. };
  389. // 调用sdk上传接口获得相应的observable,控制上传和暂停
  390. var layerConfig = {
  391. useCdnDomain: true,
  392. disableStatisticsReport: false,
  393. retryCount: 6
  394. };
  395. var putExtra = {
  396. fname: "",
  397. params: {"x:name":name},
  398. mimeType: null
  399. };
  400. observable = qiniu.upload(file, filename, token, putExtra, layerConfig);
  401. subscription = observable.subscribe(subObject);
  402. }
  403. function loadUpload(i,e,key,url,assets)
  404. {
  405. var value = e.attr('v');
  406. if (typeof(upload[value]) != "undefined") {
  407. //return;
  408. }
  409. upload[value] = true;
  410. upload_pic[value] = [];
  411. upload_pic_info[value] = [];
  412. upload_file[value] = [];
  413. var data = {};
  414. data.key = key;
  415. var token = e.attr('token');
  416. var host = e.attr('host');
  417. var domain = e.attr('domain');
  418. var path = e.attr('path');
  419. var cover = e.attr('cover');
  420. data.search = '';
  421. if (e.attr('upload_search_value')) {
  422. data.search = e.attr('upload_search_value');
  423. }
  424. if (!cover) {
  425. cover = 1;
  426. }
  427. if (token) {
  428. data.token = token;
  429. }
  430. var uploadUrl = url;
  431. if (domain) {
  432. url = domain;
  433. delete data.key;
  434. //data.key = 2;
  435. }
  436. var id = e.attr('id');
  437. layui.use(['upload','layer','element'], function() {
  438. var layer = layui.layer;
  439. var layuiUpload = layui.upload;
  440. var element = layui.element;
  441. var uploadInst = layuiUpload.render({
  442. elem: '#' + id
  443. ,data: data
  444. ,field: 'file'
  445. ,url: url
  446. ,multiple: true
  447. ,accept:'file'
  448. //,auto:false
  449. ,xhr:xhrOnProgress
  450. ,progress:function(value){//上传进度回调 value进度值
  451. $('#' + id + '_progress').show();
  452. element.progress(id + '_progress', value+'%')//设置页面进度条
  453. }
  454. ,before: function(obj){
  455. if (this.data.search.indexOf('#') != -1) {
  456. var temp = this.data.search.split('#');
  457. this.data.search = temp[0];
  458. if (temp[1]) {
  459. temp[1] = $('#update_'+temp[1]+'_value').val();
  460. if (temp[1] > 0) {
  461. this.data.search = this.data.search + '_' + temp[1];
  462. }
  463. }
  464. }
  465.             }
  466. ,choose: function(obj, self){
  467. if (domain) {
  468. obj.editFile(path, cover);
  469. }
  470. element.progress(id + '_progress', '0%')
  471. //layer.load();
  472. }
  473. ,done: function(data, file) {
  474. if (data.hash) {
  475. data.status = 1;
  476. data.name = data.key;
  477. data.url = host + data.key;
  478. $.getJSON(uploadUrl.replace('save.start', 'qiniu.addFile'), {source:file.name,file:data.key, key:key});
  479. }
  480. element.progress(id + '_progress', '0%')
  481. $('#' + id + '_progress').hide();
  482. layer.closeAll('loading');
  483. if (data.status == 1) {
  484. loadUploadSet(e,value,data,key);
  485. } else {
  486. element.progress(id + '_progress', '0%')
  487. layer.alert(data.message);
  488. return false;
  489. }
  490. }
  491. ,error: function(){
  492. //请求异常回调
  493. layer.alert('文件上传错误');
  494. element.progress(id + '_progress', '0%')
  495. $('#' + id + '_progress').hide();
  496. layer.closeAll('loading');
  497. }
  498. });
  499. });
  500. }
  501. function loadUploadSet(e,value,data,key)
  502. {
  503. if (showUploadFilesUploadE) {
  504. showUploadFilesSearch(showUploadFilesUploadE, showUploadFilesSearchState, showUploadFilesSearchAll);
  505. return;
  506. }
  507. var mul = e.attr('mul');
  508. var place = e.attr('place');
  509. if (mul == 'yes') {
  510. if (e.attr('t') == 'file') {
  511. if (upload_file[value].length <= 0 && $("#" + value).val()) {
  512. upload_file[value] = $("#" + value).val().split(',');
  513. }
  514. var m = $('.' +value+'_mul');
  515. var i = m.find('li').eq(upload_file[value].length);
  516. if (i.length) {
  517. i.find('a').eq(0).html(data.name);
  518. } else {
  519. m.append('<li><a href="'+data.url+'" target="_blank" title="点此下载" >'+data.name+'</a>&nbsp;&nbsp;<a href="javascript:;" title="点此删除" style="color:red;" onclick="fileDel($(this), \''+value+'\')">[删除]</a></li>');
  520. }
  521. upload_file[value].push(data.url);
  522. $("#" + value).val(upload_file.join(','));
  523. } else {
  524. var i = e.attr('i');
  525. var info = '';
  526. if (data.width) {
  527. info = data.width + '_' + data.height + '_' +data.size + '_' + data.fid;
  528. }
  529. if (upload_pic[value].length <= 0 && $("#" + value).val()) {
  530. upload_pic[value] = $("#" + value).val().split(',');
  531. }
  532. if ($('#'+i).length) {
  533. upload_pic_info[value] = $("#" + i).val().split(',');
  534. }
  535. var m = $('.' +value+'_mul');
  536. var index = m.find('img').eq(upload_pic[value].length);
  537. var set = index.length;
  538. var place = m.find('.place');
  539. if (place.length) {
  540. set = false;
  541. }
  542. if (set) {
  543. index.attr('src', data.url);
  544. index.attr('data-src', data.url);
  545. index.attr('info', info);
  546. } else {
  547. m.append('<a href="javascript:;" title="打开图片管理工具" onclick="picManage($(this), \''+value+'\', \''+key+'\', 2, \''+i+'\', \''+place+'\')"><img src="'+data.url+'" data-src="'+data.url+'" info="'+info+'" width="150" class="cropper_img" style="margin-left:5px;" alt="打开图片管理工具"/></a>');
  548. }
  549. upload_pic[value].push(data.url);
  550. $("#" + value).val(upload_pic[value].join(','));
  551. if ($('#'+i).length && info) {
  552. upload_pic_info[value].push(info);
  553. $('#'+i).val(upload_pic_info[value].join(','));
  554. }
  555. }
  556. } else {
  557. if (e.attr('t') == 'file') {
  558. } else {
  559. var i = e.attr('i');
  560. if ($('#show_'+value).length) {
  561. $('#show_'+value).parent().show();
  562. $('#show_'+value).attr('src',data.url).show();
  563. $('#show_'+value).attr('data-src',data.url);
  564. if (!checkClick($('#show_'+value))) {
  565. $('#show_'+value).unbind('click').bind('click', function()
  566. {
  567. picManage($(this), value, key, 1, i, place);
  568. })
  569. }
  570. }
  571. }
  572. $('#'+value).val(data.url);
  573. if ($('#'+i).length && data.width) {
  574. var info = data.width + '_' + data.height + '_' +data.size + '_' + data.fid;
  575. $('#'+i).val(info);
  576. }
  577. }
  578. }
  579. function picSet(pic, s, info)
  580. {
  581. if (picManageE) {
  582. //$('#'+value).val(data.url);
  583. var img = picManageE.find('img');
  584. var old = img.attr('src');
  585. img.attr('src', pic);
  586. var value = $("#" + picManageV);
  587. value.val(value.val().replace(old, pic));
  588. if (s != 1) {
  589. upload_pic[picManageV].replaceOne(old,pic);
  590. }
  591. var i = picManageI;
  592. if ($('#'+i).length) {
  593. if (s == 1) {
  594. $('#'+i).val(info);
  595. } else {
  596. var old = img.attr('info');
  597. if (old) {
  598. upload_pic_info[picManageV].replaceOne(old,info);
  599. $("#" + i).val(upload_pic_info[picManageV].join(','));
  600. }
  601. }
  602. }
  603. }
  604. layer.close(picManageLayer);
  605. }
  606. function picDel(s)
  607. {
  608. if (!picManageE) {
  609. return;
  610. }
  611. if (confirm('确定要删除图片吗?')) {
  612. var v = picManageV;
  613. var e = picManageE;
  614. var i = picManageI;
  615. if (s == 1) {
  616. e.hide();
  617. $("#" + v).val('');
  618. if ($('#'+i).length) {
  619. $('#'+i).val('');
  620. }
  621. } else {
  622. if (upload_pic[v].length <= 0 && $("#" + v).val()) {
  623. upload_pic[v] = $("#" + v).val().split(',');
  624. }
  625. if (upload_pic_info[v].length <= 0 && $('#'+i).length && $("#" + i).val()) {
  626. upload_pic_info[v] = $("#" + i).val().split(',');
  627. }
  628. var p = e.find('img').attr('src');
  629. e.remove();
  630. upload_pic[v].remove(p);
  631. $("#" + v).val(upload_pic[v].join(','));
  632. if ($('#'+i).length) {
  633. var info = e.find('img').attr('info');
  634. upload_pic_info[v].remove(info);
  635. $("#" + i).val(upload_pic_info[v].join(','));
  636. }
  637. }
  638. }
  639. layer.close(picManageLayer);
  640. }
  641. function picManage(e,v,k,s,i,wh)
  642. {
  643. if (!s) {
  644. s = 2;
  645. }
  646. if (!wh) {
  647. wh = '160*90';
  648. }
  649. picManageE = e;
  650. picManageV = v;
  651. picManageI = i;
  652. var param = '';
  653. var img = e.find('img');
  654. if (img.attr('data-src')) {
  655. var pic = img.attr('data-src');
  656. param = img.attr('src');
  657. } else {
  658. var pic = img.attr('src');
  659. img.attr('data-src', pic);
  660. }
  661. if (pic.indexOf('temp.im') != -1) {
  662. return;
  663. }
  664. var url = config.upload.replace('save', 'view') + '.manage&state='+s+'&key='+k+'&pic=' + pic + '&param=' + param+'&wh='+wh;
  665. var layerConfig = {
  666. type: 2,
  667. title: '图片裁剪工具',
  668. content : [url, 'no'],
  669. shade: 0.1,
  670. shadeClose : true,
  671. area: ['1000px','550px']
  672. };
  673. picManageLayer = layer.open(layerConfig);
  674. }
  675. function fileDel(e,v)
  676. {
  677. if(confirm('确定要删除文件吗?'))
  678. {
  679. if(upload_file[v].length <= 0 && $("#" + v).val())
  680. {
  681. upload_file[v] = $("#" + v).val().split(',');
  682. }
  683. var parent = e.parent();
  684. var p = parent.find('a').eq(0).attr('href');
  685. parent.remove();
  686. upload_file[v].remove(p);
  687. //console.info(pic);
  688. $("#" + v).val(upload_file[v].join(','));
  689. }
  690. }