cloudDiskDe.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  6. <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  7. <title>云盘</title>
  8. <link rel="stylesheet" type="text/css" href="../../css/api.css" />
  9. <link rel="stylesheet" href="../../css/projeck.css">
  10. <style>
  11. /*搜索*/
  12. .api_search{
  13. padding: 13px;
  14. display: flex;
  15. justify-content: space-between;
  16. align-items: center;
  17. flex-wrap: nowrap;
  18. }
  19. .search_box{
  20. flex: 6;
  21. height: 34px;
  22. line-height: 34px;
  23. background:rgba(255,255,255,1);
  24. box-shadow:0 0 5px 0 rgba(0,0,0,0.25);
  25. border-radius:5px;
  26. font-size: 14px;
  27. color: #929292;
  28. padding-left: 30px;
  29. position: relative;
  30. }
  31. .search_icon{
  32. display: block;
  33. position: absolute;
  34. top: 7px;
  35. left: 7px;
  36. width: 20px;
  37. height: 20px;
  38. background: url("../../icon/searc1.png") center no-repeat;
  39. background-size: cover;
  40. }
  41. .sort_box{
  42. width: 25px;
  43. height: 25px;
  44. margin-left: 13px;
  45. background: url("../../icon/sort.png") center no-repeat;
  46. background-size: cover;
  47. }
  48. /*文件列表*/
  49. .cloud_lists{
  50. padding-top: 10px;
  51. overflow: hidden;
  52. }
  53. .cloud_list li{
  54. padding: 10px 14px;
  55. display: flex;
  56. justify-content: flex-start;
  57. align-items: center;
  58. flex-wrap: nowrap;
  59. color: #2C3E50;
  60. position: relative;
  61. }
  62. .img_text{
  63. display: flex;
  64. justify-content: flex-start;
  65. align-items: center;
  66. flex-wrap: nowrap;
  67. width: 86%;
  68. }
  69. .file_name_sizes{
  70. width: 82%;
  71. }
  72. .cloud_list li img{
  73. width: 40px;
  74. height: 40px;
  75. margin-right: 13px;
  76. }
  77. .file_name{
  78. font-size: 14px;
  79. margin-bottom: 3px;
  80. overflow: hidden;
  81. text-overflow: ellipsis;
  82. white-space: nowrap;
  83. }
  84. .file_size_time{
  85. color: #9C9FA5;
  86. font-size: 13px;
  87. }
  88. .file_tool{
  89. width: 25px;
  90. height: 25px;
  91. background: url("../../icon/tool.png") center no-repeat;
  92. background-size: cover;
  93. position: absolute;
  94. top: 17.5px;
  95. right: 14px;
  96. }
  97. /*悬浮菜单*/
  98. .menu{
  99. position: fixed;
  100. bottom: 13px;
  101. right: 13px;
  102. z-index: 9999;
  103. }
  104. .tool_boxs{
  105. background:rgba(255,255,255,1);
  106. box-shadow:0 0 10px 5px rgba(0,0,0,0.15);
  107. border-radius:27px;
  108. color: #2C3E50;
  109. font-size: 12px;
  110. text-align: center;
  111. padding: 3px;
  112. height: 51px;
  113. box-sizing: border-box;
  114. transition: .5s;
  115. overflow: hidden;
  116. }
  117. .tool_box_first{
  118. opacity: 0;
  119. height: 0;
  120. position: relative;
  121. bottom: -140px;
  122. margin-bottom: 0;
  123. transition: .5s;
  124. }
  125. .tool_box_two{
  126. opacity: 0;
  127. height: 0;
  128. position: relative;
  129. bottom: -70px;
  130. margin-bottom: 0;
  131. transition: .5s;
  132. }
  133. .tool_box p{
  134. width: 45px;
  135. height: 45px;
  136. }
  137. .plus{
  138. background: url("../../icon/tool1.png") center no-repeat;
  139. background-size: cover;
  140. position: relative;
  141. z-index:2000;
  142. cursor: pointer;
  143. }
  144. .file_x{
  145. background: url("../../icon/file_x.png") center no-repeat;
  146. background-size: cover;
  147. margin-bottom: 3px;
  148. }
  149. .file_j{
  150. background: url("../../icon/file_s.png") center no-repeat;
  151. background-size: cover;
  152. margin-bottom: 3px;
  153. }
  154. /*上传按钮原生H5样式修改*/
  155. .rt_rt_1ec4mqe238o31nmpp8e12r91n1{
  156. width: 45px;
  157. height: 45px;
  158. }
  159. .webuploader-element-invisible{
  160. opacity: 0;
  161. width: 45px;
  162. height: 45px;
  163. }
  164. </style>
  165. </head>
  166. <body>
  167. <div class="api_layout">
  168. <!-- 搜索-->
  169. <div class="api_search">
  170. <!-- 搜索框-->
  171. <div class="search_box" onclick="searchFile()">
  172. 搜索
  173. <i class="search_icon"></i>
  174. </div>
  175. <!-- 排序-->
  176. <div class="sort_box" onclick="openSortTool()"></div>
  177. </div>
  178. <!-- 文件列表-->
  179. <div class="cloud_lists" id="cloud_lists"></div>
  180. </div>
  181. <!--悬浮菜单-->
  182. <div class="menu">
  183. <div class="tool_boxs">
  184. <div class="tool_box tool_box_first tool_box_c" onclick="addFolder()">
  185. <p class="file_x"></p>
  186. 文件夹
  187. </div>
  188. <div class="tool_box tool_box_two tool_box_c" id="picker">
  189. <p class="file_j"></p>
  190. 文件
  191. </div>
  192. <div class="tool_box">
  193. <p class="plus"></p>
  194. </div>
  195. </div>
  196. </div>
  197. <!-- 无内容提示 -->
  198. <div class="noText hide">
  199. <img src="../../image/noText.png" alt="">
  200. </div>
  201. <!-- 下载 -->
  202. <a href="javascript:;" id="upload_file"></a>
  203. </body>
  204. </html>
  205. <script type="text/template" id="templateMyCloud">
  206. {{~it:value:index}}
  207. <ul class="cloud_list">
  208. {{? value.filetype === 0}}
  209. <li>
  210. <div class="img_text" tapmode onclick="openFolderContent('{{=value.filename}}','{{=value.id}}')">
  211. <img src="../../icon/file.png" alt="">
  212. <div class="file_name_sizes">
  213. <p class="file_name">{{=value.filename}}</p>
  214. <p class="file_size_time">{{=value.createtime}}</p>
  215. </div>
  216. </div>
  217. <i class="file_tool" onclick="openTool('{{=value.id}}','{{=value.filename}}','{{=value.filetype}}')"></i>
  218. </li>
  219. {{??}}
  220. <li>
  221. <div class="img_text">
  222. <img src="{{=value.fileicon}}" alt="">
  223. <div class="file_name_sizes">
  224. <p class="file_name">{{=value.filename}}</p>
  225. <p class="file_size_time">{{=value.createtime}} {{=value.filesizename}}</p>
  226. </div>
  227. </div>
  228. <i class="file_tool" onclick="openTool('{{=value.id}}','{{=value.filename}}')"></i>
  229. </li>
  230. {{?}}
  231. </ul>
  232. {{~}}
  233. </script>
  234. <script type="text/javascript" src="../../script/api.js"></script>
  235. <script type="text/javascript" src="../../script/doT.min.js"></script>
  236. <script type="text/javascript" src="../../script/cloudUpload/jquery-3.4.1.min.js"></script>
  237. <script type="text/javascript" src="../../script/cloudUpload/webuploader.min.js"></script>
  238. <script src="../../script/config.js" charset="utf-8"></script>
  239. <script type="text/javascript" src="../../script/cloudUpload/cloudUpload.js"></script>
  240. <script type="text/javascript">
  241. var skip = 1,isLoadding = false,userToken='',
  242. orderfield = '', ordertype='',isHtml = false
  243. pid = null;
  244. apiready = function() {
  245. userToken = api.pageParam.token
  246. pid = api.pageParam.id
  247. register(pid,userToken);
  248. init();
  249. findList()
  250. api.addEventListener({
  251. name : 'scrolltobottom',
  252. extra : {
  253. threshold : 0 //设置距离底部多少距离时触发,默认值为0,数字类型
  254. }
  255. }, function(ret, err) {
  256. if (!isLoadding) {
  257. isLoadding = true;
  258. isHtml = false;
  259. findList();
  260. }
  261. })
  262. }
  263. // list
  264. function findList() {
  265. var params = {
  266. pid,
  267. orderfield,
  268. ordertype,
  269. page: skip,
  270. limit: 20,
  271. token: userToken
  272. }
  273. $http.requestData(UrlRouter.findList,'post',params)
  274. .then(ret=>{
  275. if (ret.rows.length == 0 && skip == 1) {
  276. $api.removeCls($api.dom('.noText'), 'hide');
  277. return false;
  278. }else {
  279. $api.addCls($api.dom('.noText'), 'hide');
  280. }
  281. if (ret.rows.length > 0) {
  282. if (isHtml) {
  283. skip += 1;
  284. $apis.html(cloud_lists,'#templateMyCloud',ret.rows);
  285. }else {
  286. skip += 1;
  287. $apis.append(cloud_lists,'#templateMyCloud',ret.rows);
  288. }
  289. } else {
  290. isLoadding = true;
  291. api.toast({
  292. msg: '没有更多数据',
  293. duration: 2000,
  294. location: 'bottom'
  295. });
  296. }
  297. })
  298. .catch(err=>{
  299. api.toast({
  300. msg: '网络错误,请检查网络!',
  301. duration: 2000,
  302. location: 'top'
  303. })
  304. })
  305. }
  306. // 搜索
  307. function searchFile() {
  308. $event.openWin('searchFile_win','searchFile_win',{token:userToken},'')
  309. }
  310. // 排序工具栏
  311. function openSortTool() {
  312. api.actionSheet({
  313. title: '排序',
  314. cancelTitle: '取消',
  315. buttons: ['按时间顺序', '按名称排序']
  316. }, function(ret, err) {
  317. if (ret.buttonIndex === 1) {
  318. orderfield = 'createtime',
  319. ordertype = ''
  320. }else {
  321. ordertype = 'descending'
  322. orderfield = ''
  323. }
  324. skip = 1
  325. isHtml = true
  326. findList()
  327. });
  328. }
  329. // 下载删除工具函数
  330. function openTool(id,name,type) {
  331. var Toolname = type == 0 ? ['重命名']:['下载','重命名']
  332. api.actionSheet({
  333. title: '操作',
  334. cancelTitle: '取消',
  335. destructiveTitle: '删除',
  336. buttons: Toolname
  337. }, function(ret, err) {
  338. var index = ret.buttonIndex;
  339. if (index === 1) {
  340. api.confirm({
  341. title: '确定删除文件?',
  342. msg: '',
  343. buttons: ['确定', '取消']
  344. }, function(ret, err) {
  345. if (ret.buttonIndex === 1) {
  346. deleteFolder(id,name)
  347. }
  348. })
  349. }else if (index === 2) {
  350. if (type != 0) {
  351. mergeFilesNew(id,name)
  352. }else {
  353. renameFolder(id,name,type)
  354. }
  355. }
  356. else if (index === 3) {
  357. if (type != 0) {
  358. renameFolder(id,name,type)
  359. }
  360. }
  361. });
  362. }
  363. // 添加文件夹
  364. function addFolder() {
  365. api.prompt({
  366. title: '新建文件夹',
  367. buttons: ['确定', '取消'],
  368. text: '请输入文件夹名称!'
  369. }, function(ret, err) {
  370. if (ret.buttonIndex === 1) {
  371. newFolder(ret.text)
  372. }
  373. });
  374. }
  375. // 添加文件以及文件夹的js动画
  376. $('body').on('click','.plus',function () {
  377. if ($('.tool_boxs').height() === 45){
  378. $('.tool_box_c').css({
  379. bottom:0,
  380. height: 65,
  381. marginBottom:5,
  382. opacity:1
  383. })
  384. $('.tool_boxs').css({
  385. height:191
  386. })
  387. }else {
  388. $('.tool_box_c').css({
  389. bottom:-70,
  390. height: 0,
  391. marginBottom:0,
  392. opacity:0
  393. })
  394. $('.tool_boxs').css({
  395. height:51
  396. })
  397. }
  398. })
  399. // open文件夹
  400. function openFolderContent(name,id) {
  401. $event.openTabLayout('cloudDiskDe'+Math.random(),'cloudDiskDe',name,{id,token:userToken});
  402. }
  403. // 删除文件或文件夹
  404. function deleteFolder(id,name) {
  405. var params = {
  406. ids: [{id,name}],
  407. token:userToken
  408. }
  409. $http.requestShowProgress(UrlRouter.delete,'post',params)
  410. .then(ret=>{
  411. if (ret.code === 0) {
  412. api.toast({
  413. msg: '删除成功',
  414. duration: 2000,
  415. location: 'top'
  416. })
  417. skip = 1
  418. isHtml = true
  419. findList()
  420. }else {
  421. api.toast({
  422. msg: '删除失败',
  423. duration: 2000,
  424. location: 'top'
  425. })
  426. }
  427. })
  428. .catch(err=>{
  429. api.toast({
  430. msg: '网络错误,请检查网络!',
  431. duration: 2000,
  432. location: 'top'
  433. })
  434. })
  435. }
  436. // 新建文件夹
  437. function newFolder(name) {
  438. var params = {
  439. pid,
  440. name,
  441. token:userToken
  442. }
  443. $http.requestShowProgress(UrlRouter.addFolder,'post',params)
  444. .then(ret=>{
  445. if (ret.code === 0) {
  446. api.toast({
  447. msg: '添加成功',
  448. duration: 2000,
  449. location: 'top'
  450. })
  451. skip = 1
  452. isHtml = true
  453. findList()
  454. }else {
  455. api.toast({
  456. msg: '添加失败',
  457. duration: 2000,
  458. location: 'top'
  459. })
  460. }
  461. })
  462. .catch(err=>{
  463. api.toast({
  464. msg: '网络错误,请检查网络!',
  465. duration: 2000,
  466. location: 'top'
  467. })
  468. })
  469. }
  470. // 合并切块,上传文件
  471. function register(ids,token){
  472. //document->hook下面有介绍
  473. WebUploader.Uploader.register({
  474. 'name': 'webUploaderHookCommand',
  475. "before-send-file":"beforeSendFile",
  476. "before-send":"beforeSend",
  477. "after-send-file":"afterSendFile"
  478. },{
  479. beforeSendFile:function(file) {
  480. // 创建一个deffered,用于通知是否完成操作
  481. var deferred = WebUploader.Deferred();
  482. //js-spark-md5计算md5
  483. //内置计算md5【慢,而且jpg计算不对】
  484. getFileMd5(file,deferred,token);
  485. uploader.options.formData.uuid = uuid;
  486. uploader.options.formData.pid = ids;
  487. uploader.options.formData.token = userToken;
  488. //问题一:同时选择两个文件,大在前,小在后,则md5和filename会窜
  489. //问题二:主要如果<chunkSize,则不分块,不会有chunk和chunks两参数
  490. //问题三:内置参数chunk/chunks
  491. if(file.size<=chunkSize){
  492. uploader.options.formData.chunk=0;
  493. uploader.options.formData.chunks=1;
  494. }
  495. return deferred.promise();// 通知完成操作
  496. },
  497. beforeSend:function(block) {
  498. },
  499. afterSendFile:function(file) {//合并切块
  500. var url=baseurl+"disk/fileupload/mergeChunk";
  501. var args={
  502. "albumid":'',
  503. "pid":ids,
  504. "relativepath":"",
  505. "uuid":uuid,
  506. "fileid":file.id,
  507. "filename":file.name,
  508. "filemd5":md5,
  509. "totalSize":file.size,
  510. "token": token
  511. };
  512. $.post(url,args,function(data){
  513. if(data.code==0){
  514. api.toast({
  515. msg: '上传成功',
  516. duration: 2000,
  517. location: 'top'
  518. });
  519. skip = 1
  520. isHtml = true
  521. findList()
  522. api.hideProgress();
  523. }else{
  524. api.toast({
  525. msg: '上传失败',
  526. duration: 2000,
  527. location: 'top'
  528. });
  529. api.hideProgress();
  530. }
  531. });
  532. }
  533. });
  534. }
  535. // 下载文件 图片
  536. function mergeFilesNew(id) {
  537. var uploadFileElm= $('#upload_file')
  538. api.confirm({
  539. title: '提示',
  540. msg: '是否下载文件',
  541. buttons: ['确定', '取消']
  542. }, function(ret, err) {
  543. var index = ret.buttonIndex;
  544. if (index === 1) {
  545. uploadFileElm.attr('href',`${UrlRouter.download}fileid=${id}&token=${userToken}`)
  546. uploadFileElm.attr('download',`${UrlRouter.download}fileid=${id}&token=${userToken}`)
  547. document.getElementById("upload_file").click();
  548. }
  549. });
  550. }
  551. // 重命名
  552. function renameFolder(id,name,type) {
  553. var filename = name
  554. fileType = name.substring(name.lastIndexOf('.'))
  555. if (type != 0) {
  556. filename = name.substring(0,name.lastIndexOf('.'))
  557. }
  558. api.prompt({
  559. title: '修改文件名称',
  560. buttons: ['确定', '取消'],
  561. text: filename
  562. }, function(ret, err) {
  563. var text = ret.text;
  564. if (ret.buttonIndex === 1) {
  565. rename(id,ret.text,fileType)
  566. }
  567. });
  568. }
  569. function rename(id,filename,fileType) {
  570. var type = fileType
  571. if (fileType.indexOf('.') != 0 ) {
  572. type = ''
  573. }
  574. var params = {
  575. id,
  576. filename:filename+type,
  577. token:userToken
  578. }
  579. $http.requestShowProgress(UrlRouter.rename,'post',params)
  580. .then(ret=>{
  581. if (ret.code === 0) {
  582. api.toast({
  583. msg: '修改成功',
  584. duration: 2000,
  585. location: 'top'
  586. })
  587. skip = 1
  588. isHtml = true
  589. findList()
  590. }else {
  591. api.toast({
  592. msg: '修改失败',
  593. duration: 2000,
  594. location: 'top'
  595. })
  596. }
  597. })
  598. .catch(err=>{
  599. api.toast({
  600. msg: '网络错误,请检查网络!',
  601. duration: 2000,
  602. location: 'top'
  603. })
  604. })
  605. }
  606. </script>