upload.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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 bucket = e.attr('bucket');
  231. var path = e.attr('path');
  232. var cover = e.attr('cover');
  233. var type = e.attr('m');
  234. var search = '';
  235. if (e.attr('upload_search_value')) {
  236. search = e.attr('upload_search_value');
  237. }
  238. if (!cover) {
  239. cover = 1;
  240. }
  241. var uploadUrl = url;
  242. url = domain;
  243. layui.use(['layer','element'], function() {
  244. var layer = layui.layer;
  245. var element = layui.element;
  246. $("#" + id).unbind("change").bind("change",function() {
  247. var file = this.files[0];
  248. if (file) {
  249. element.progress(id + '_progress', '0%');
  250. layer.load();
  251. var filename = file.name;
  252. var temp = filename.split('.');
  253. var name = temp[0];
  254. filename = path + hex_md5(file.name) + '.' + temp[temp.length-1];
  255. //不覆盖
  256. if (cover == 2) {
  257. var timestamp = Date.parse(new Date());
  258. filename = path + hex_md5(file.name + '_' + timestamp) + '.' + temp[temp.length-1];
  259. }
  260. // 设置next,error,complete对应的操作,分别处理相应的进度信息,错误信息,以及完成后的操作
  261. var error = function(err) {
  262. //请求异常回调
  263. layer.alert('文件上传错误');
  264. element.progress(id + '_progress', '0%')
  265. $('#' + id + '_progress').hide();
  266. layer.closeAll('loading');
  267. };
  268. var complete = function(res) {
  269. //&& res.key.match(/\.(jpg|jpeg|png|gif)$/)
  270. if (res.key) {
  271. element.progress(id + '_progress', '0%')
  272. $('#' + id + '_progress').hide();
  273. layer.closeAll('loading');
  274. var data = {};
  275. if (res.hash) {
  276. if (search.indexOf('#') != -1) {
  277. var temp = search.split('#');
  278. search = temp[0];
  279. if (temp[1]) {
  280. temp[1] = $('#update_'+temp[1]+'_value').val();
  281. if (temp[1] > 0) {
  282. search = search + '_' + temp[1];
  283. }
  284. }
  285. }
  286. $.getJSON(uploadUrl.replace('save.start', 'yun.addFile'), {source:file.name,file:res.key, key:key, search:search});
  287. data.status = 1;
  288. data.name = res.key;
  289. data.url = host + res.key;
  290. loadUploadSet(e,value,data,key);
  291. } else {
  292. layer.alert('文件上传错误');
  293. return false;
  294. }
  295. }
  296. };
  297. if (type == 'qiniu') {
  298. qiniuHandle(id, name, token, domain, bucket, file, filename, element, error, complete);
  299. } else if(type == 'oss') {
  300. ossHandle(id, name, token, domain, bucket, file, filename, element, error, complete);
  301. }
  302. }
  303. });
  304. });
  305. }
  306. function ossHandle(id, name, token, domain, bucket, file, filename, element, error, complete)
  307. {
  308. var temp = token.split('||');
  309. if (temp[0]) {
  310. token = temp[0];
  311. } else {
  312. token = '';
  313. }
  314. let ossConfig = {
  315. // region以杭州为例(oss-cn-hangzhou),其他region按实际情况填写。
  316. region: 'oss-' + domain,
  317. // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
  318. accessKeyId: temp[1],
  319. accessKeySecret: temp[2],
  320. bucket: bucket,
  321. }
  322. if (token) {
  323. ossConfig.stsToken = token;
  324. }
  325. let client = new OSS(ossConfig);
  326. let tempCheckpoint;
  327. // 定义上传方法。
  328. async function multipartUpload () {
  329. try {
  330. // object-key可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,实现将文件上传至当前Bucket或Bucket下的指定目录。
  331. let result = await client.multipartUpload(filename, file, {
  332. progress: function (p, checkpoint) {
  333. $('#' + id + '_progress').show();
  334. element.progress(id + '_progress', parseInt(p*100)+'%')
  335. // 断点记录点。浏览器重启后无法直接继续上传,您需要手动触发上传操作。
  336. tempCheckpoint = checkpoint;
  337. if (p >= 1) {
  338. complete({key:filename,hash:true});
  339. }
  340. },
  341. //meta: { year: 2020, people: 'test' },
  342. //mime: 'image/jpeg'
  343. })
  344. } catch(e){
  345. console.log(e);
  346. error();
  347. }
  348. }
  349. // 开始分片上传。
  350. multipartUpload();
  351. }
  352. function qiniuHandle(id, name, token, domain, bucket, file, filename, element, error, complete)
  353. {
  354. // eslint-disable-next-line
  355. var finishedAttr = [];
  356. // eslint-disable-next-line
  357. var compareChunks = [];
  358. var observable;
  359. var subscription;
  360. var next = function(response) {
  361. var chunks = response.chunks||[];
  362. var total = response.total;
  363. // 这里对每个chunk更新进度,并记录已经更新好的避免重复更新,同时对未开始更新的跳过
  364. for (var i = 0; i < chunks.length; i++) {
  365. if (chunks[i].percent === 0 || finishedAttr[i]){
  366. continue;
  367. }
  368. if (compareChunks[i].percent === chunks[i].percent){
  369. continue;
  370. }
  371. if (chunks[i].percent === 100){
  372. finishedAttr[i] = true;
  373. }
  374. }
  375. $('#' + id + '_progress').show();
  376. element.progress(id + '_progress', parseInt(total.percent)+'%')
  377. compareChunks = chunks;
  378. };
  379. var subObject = {
  380. next: next,
  381. error: error,
  382. complete: complete
  383. };
  384. // 调用sdk上传接口获得相应的observable,控制上传和暂停
  385. var layerConfig = {
  386. useCdnDomain: true,
  387. disableStatisticsReport: false,
  388. retryCount: 6
  389. };
  390. var putExtra = {
  391. fname: "",
  392. params: {"x:name":name},
  393. mimeType: null
  394. };
  395. observable = qiniu.upload(file, filename, token, putExtra, layerConfig);
  396. subscription = observable.subscribe(subObject);
  397. }
  398. function loadUpload(i,e,key,url,assets)
  399. {
  400. var value = e.attr('v');
  401. if (typeof(upload[value]) != "undefined") {
  402. //return;
  403. }
  404. upload[value] = true;
  405. upload_pic[value] = [];
  406. upload_pic_info[value] = [];
  407. upload_file[value] = [];
  408. var data = {};
  409. data.key = key;
  410. var token = e.attr('token');
  411. var host = e.attr('host');
  412. var domain = e.attr('domain');
  413. var path = e.attr('path');
  414. var cover = e.attr('cover');
  415. data.search = '';
  416. if (e.attr('upload_search_value')) {
  417. data.search = e.attr('upload_search_value');
  418. }
  419. if (!cover) {
  420. cover = 1;
  421. }
  422. if (token) {
  423. data.token = token;
  424. }
  425. var uploadUrl = url;
  426. if (domain) {
  427. url = domain;
  428. delete data.key;
  429. //data.key = 2;
  430. }
  431. var id = e.attr('id');
  432. layui.use(['upload','layer','element'], function() {
  433. var layer = layui.layer;
  434. var layuiUpload = layui.upload;
  435. var element = layui.element;
  436. var uploadInst = layuiUpload.render({
  437. elem: '#' + id
  438. ,data: data
  439. ,field: 'file'
  440. ,url: url
  441. ,multiple: true
  442. ,accept:'file'
  443. //,auto:false
  444. ,xhr:xhrOnProgress
  445. ,progress:function(value){//上传进度回调 value进度值
  446. $('#' + id + '_progress').show();
  447. element.progress(id + '_progress', value+'%')//设置页面进度条
  448. }
  449. ,before: function(obj){
  450. if (this.data.search.indexOf('#') != -1) {
  451. var temp = this.data.search.split('#');
  452. this.data.search = temp[0];
  453. if (temp[1]) {
  454. temp[1] = $('#update_'+temp[1]+'_value').val();
  455. if (temp[1] > 0) {
  456. this.data.search = this.data.search + '_' + temp[1];
  457. }
  458. }
  459. }
  460.             }
  461. ,choose: function(obj, self){
  462. if (domain) {
  463. obj.editFile(path, cover);
  464. }
  465. element.progress(id + '_progress', '0%')
  466. //layer.load();
  467. }
  468. ,done: function(data, file) {
  469. if (data.hash) {
  470. data.status = 1;
  471. data.name = data.key;
  472. data.url = host + data.key;
  473. $.getJSON(uploadUrl.replace('save.start', 'qiniu.addFile'), {source:file.name,file:data.key, key:key});
  474. }
  475. element.progress(id + '_progress', '0%')
  476. $('#' + id + '_progress').hide();
  477. layer.closeAll('loading');
  478. if (data.status == 1) {
  479. loadUploadSet(e,value,data,key);
  480. } else {
  481. element.progress(id + '_progress', '0%')
  482. layer.alert(data.message);
  483. return false;
  484. }
  485. }
  486. ,error: function(){
  487. //请求异常回调
  488. layer.alert('文件上传错误');
  489. element.progress(id + '_progress', '0%')
  490. $('#' + id + '_progress').hide();
  491. layer.closeAll('loading');
  492. }
  493. });
  494. });
  495. }
  496. function loadUploadSet(e,value,data,key)
  497. {
  498. if (showUploadFilesUploadE) {
  499. showUploadFilesSearch(showUploadFilesUploadE, showUploadFilesSearchState, showUploadFilesSearchAll);
  500. return;
  501. }
  502. var mul = e.attr('mul');
  503. var place = e.attr('place');
  504. if (mul == 'yes') {
  505. if (e.attr('t') == 'file') {
  506. if (upload_file[value].length <= 0 && $("#" + value).val()) {
  507. upload_file[value] = $("#" + value).val().split(',');
  508. }
  509. var m = $('.' +value+'_mul');
  510. var i = m.find('li').eq(upload_file[value].length);
  511. if (i.length) {
  512. i.find('a').eq(0).html(data.name);
  513. } else {
  514. 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>');
  515. }
  516. upload_file[value].push(data.url);
  517. $("#" + value).val(upload_file.join(','));
  518. } else {
  519. var i = e.attr('i');
  520. var info = '';
  521. if (data.width) {
  522. info = data.width + '_' + data.height + '_' +data.size + '_' + data.fid;
  523. }
  524. if (upload_pic[value].length <= 0 && $("#" + value).val()) {
  525. upload_pic[value] = $("#" + value).val().split(',');
  526. }
  527. if ($('#'+i).length) {
  528. upload_pic_info[value] = $("#" + i).val().split(',');
  529. }
  530. var m = $('.' +value+'_mul');
  531. var index = m.find('img').eq(upload_pic[value].length);
  532. var set = index.length;
  533. var place = m.find('.place');
  534. if (place.length) {
  535. set = false;
  536. }
  537. if (set) {
  538. index.attr('src', data.url);
  539. index.attr('data-src', data.url);
  540. index.attr('info', info);
  541. } else {
  542. 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>');
  543. }
  544. upload_pic[value].push(data.url);
  545. $("#" + value).val(upload_pic[value].join(','));
  546. if ($('#'+i).length && info) {
  547. upload_pic_info[value].push(info);
  548. $('#'+i).val(upload_pic_info[value].join(','));
  549. }
  550. }
  551. } else {
  552. if (e.attr('t') == 'file') {
  553. } else {
  554. var i = e.attr('i');
  555. if ($('#show_'+value).length) {
  556. $('#show_'+value).parent().show();
  557. $('#show_'+value).attr('src',data.url).show();
  558. $('#show_'+value).attr('data-src',data.url);
  559. if (!checkClick($('#show_'+value))) {
  560. $('#show_'+value).unbind('click').bind('click', function()
  561. {
  562. picManage($(this), value, key, 1, i, place);
  563. })
  564. }
  565. }
  566. }
  567. $('#'+value).val(data.url);
  568. if ($('#'+i).length && data.width) {
  569. var info = data.width + '_' + data.height + '_' +data.size + '_' + data.fid;
  570. $('#'+i).val(info);
  571. }
  572. }
  573. }
  574. function picSet(pic, s, info)
  575. {
  576. if (picManageE) {
  577. //$('#'+value).val(data.url);
  578. var img = picManageE.find('img');
  579. var old = img.attr('src');
  580. img.attr('src', pic);
  581. var value = $("#" + picManageV);
  582. value.val(value.val().replace(old, pic));
  583. if (s != 1) {
  584. upload_pic[picManageV].replaceOne(old,pic);
  585. }
  586. var i = picManageI;
  587. if ($('#'+i).length) {
  588. if (s == 1) {
  589. $('#'+i).val(info);
  590. } else {
  591. var old = img.attr('info');
  592. if (old) {
  593. upload_pic_info[picManageV].replaceOne(old,info);
  594. $("#" + i).val(upload_pic_info[picManageV].join(','));
  595. }
  596. }
  597. }
  598. }
  599. layer.close(picManageLayer);
  600. }
  601. function picDel(s)
  602. {
  603. if (!picManageE) {
  604. return;
  605. }
  606. if (confirm('确定要删除图片吗?')) {
  607. var v = picManageV;
  608. var e = picManageE;
  609. var i = picManageI;
  610. if (s == 1) {
  611. e.hide();
  612. $("#" + v).val('');
  613. if ($('#'+i).length) {
  614. $('#'+i).val('');
  615. }
  616. } else {
  617. if (upload_pic[v].length <= 0 && $("#" + v).val()) {
  618. upload_pic[v] = $("#" + v).val().split(',');
  619. }
  620. if (upload_pic_info[v].length <= 0 && $('#'+i).length && $("#" + i).val()) {
  621. upload_pic_info[v] = $("#" + i).val().split(',');
  622. }
  623. var p = e.find('img').attr('src');
  624. e.remove();
  625. upload_pic[v].remove(p);
  626. $("#" + v).val(upload_pic[v].join(','));
  627. if ($('#'+i).length) {
  628. var info = e.find('img').attr('info');
  629. upload_pic_info[v].remove(info);
  630. $("#" + i).val(upload_pic_info[v].join(','));
  631. }
  632. }
  633. }
  634. layer.close(picManageLayer);
  635. }
  636. function picManage(e,v,k,s,i,wh)
  637. {
  638. if (!s) {
  639. s = 2;
  640. }
  641. if (!wh) {
  642. wh = '160*90';
  643. }
  644. picManageE = e;
  645. picManageV = v;
  646. picManageI = i;
  647. var param = '';
  648. var img = e.find('img');
  649. if (img.attr('data-src')) {
  650. var pic = img.attr('data-src');
  651. param = img.attr('src');
  652. } else {
  653. var pic = img.attr('src');
  654. img.attr('data-src', pic);
  655. }
  656. if (pic.indexOf('temp.im') != -1) {
  657. return;
  658. }
  659. var url = config.upload.replace('save', 'view') + '.manage&state='+s+'&key='+k+'&pic=' + pic + '&param=' + param+'&wh='+wh;
  660. var layerConfig = {
  661. type: 2,
  662. title: '图片裁剪工具',
  663. content : [url, 'no'],
  664. shade: 0.1,
  665. shadeClose : true,
  666. area: ['1000px','550px']
  667. };
  668. picManageLayer = layer.open(layerConfig);
  669. }
  670. function fileDel(e,v)
  671. {
  672. if(confirm('确定要删除文件吗?'))
  673. {
  674. if(upload_file[v].length <= 0 && $("#" + v).val())
  675. {
  676. upload_file[v] = $("#" + v).val().split(',');
  677. }
  678. var parent = e.parent();
  679. var p = parent.find('a').eq(0).attr('href');
  680. parent.remove();
  681. upload_file[v].remove(p);
  682. //console.info(pic);
  683. $("#" + v).val(upload_file[v].join(','));
  684. }
  685. }