cloudDiskList.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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}}','{{=value.filetype}}')"></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/zepto.js"></script> -->
  237. <script type="text/javascript" src="../../script/cloudUpload/jquery-3.4.1.min.js"></script>
  238. <script type="text/javascript" src="../../script/cloudUpload/webuploader.min.js"></script>
  239. <script src="../../script/config.js" charset="utf-8"></script>
  240. <script type="text/javascript" src="../../script/cloudUpload/cloudUpload.js"></script>
  241. <script type="text/javascript">
  242. var skip = 1,isLoadding = false,userToken='',
  243. orderfield = '', ordertype='',isHtml = false
  244. id = 0, UIActionProgress = null;
  245. apiready = function() {
  246. userToken = api.pageParam.cloudtoken
  247. // 注册上传
  248. register(id,userToken);
  249. // 初始化上传
  250. init();
  251. // 进度条
  252. UIActionProgress = api.require('UIActionProgress');
  253. // 文件列表
  254. findList(api.pageParam.cloudtoken)
  255. api.addEventListener({
  256. name : 'scrolltobottom',
  257. extra : {
  258. threshold : 0 //设置距离底部多少距离时触发,默认值为0,数字类型
  259. }
  260. }, function(ret, err) {
  261. if (!isLoadding) {
  262. isLoadding = true;
  263. isHtml = false;
  264. findList(api.pageParam.cloudtoken);
  265. }
  266. })
  267. }
  268. // list
  269. function findList() {
  270. var params = {
  271. pid: 0,
  272. orderfield,
  273. ordertype,
  274. page: skip,
  275. limit: 20,
  276. token: userToken
  277. }
  278. $http.requestData(UrlRouter.findList,'post',params)
  279. .then(ret=>{
  280. if (ret.rows.length == 0 && skip == 1) {
  281. $api.removeCls($api.dom('.noText'), 'hide');
  282. return false;
  283. }else {
  284. $api.addCls($api.dom('.noText'), 'hide');
  285. }
  286. if (ret.rows.length > 0) {
  287. if (isHtml) {
  288. skip += 1;
  289. $apis.html(cloud_lists,'#templateMyCloud',ret.rows);
  290. }else {
  291. skip += 1;
  292. $apis.append(cloud_lists,'#templateMyCloud',ret.rows);
  293. }
  294. } else {
  295. isLoadding = true;
  296. api.toast({
  297. msg: '没有更多数据',
  298. duration: 2000,
  299. location: 'bottom'
  300. });
  301. }
  302. })
  303. .catch(err=>{
  304. api.toast({
  305. msg: '网络错误,请检查网络!',
  306. duration: 2000,
  307. location: 'top'
  308. })
  309. })
  310. }
  311. // 搜索
  312. function searchFile() {
  313. $event.openWin('searchFile_win','searchFile_win',{token:userToken},'')
  314. }
  315. // 排序工具栏
  316. function openSortTool() {
  317. api.actionSheet({
  318. title: '排序',
  319. cancelTitle: '取消',
  320. buttons: ['按时间顺序', '按名称排序']
  321. }, function(ret, err) {
  322. if (ret.buttonIndex === 1) {
  323. orderfield = 'createtime',
  324. ordertype = ''
  325. }else {
  326. ordertype = 'descending'
  327. orderfield = ''
  328. }
  329. skip = 1
  330. isHtml = true
  331. findList()
  332. });
  333. }
  334. // 下载删除分享工具函数
  335. function openTool(id,name,type) {
  336. var Toolname = type == 0 ? ['重命名']:['下载','重命名']
  337. api.actionSheet({
  338. title: '操作',
  339. cancelTitle: '取消',
  340. destructiveTitle: '删除',
  341. buttons: Toolname
  342. }, function(ret, err) {
  343. var index = ret.buttonIndex;
  344. if (index === 1) {
  345. api.confirm({
  346. title: '确定删除文件?',
  347. msg: '',
  348. buttons: ['确定', '取消']
  349. }, function(ret, err) {
  350. if (ret.buttonIndex === 1) {
  351. deleteFolder(id,name)
  352. }
  353. })
  354. }else if (index === 2) {
  355. if (type != 0) {
  356. mergeFilesNew(id,name)
  357. }else {
  358. renameFolder(id,name,type)
  359. }
  360. }
  361. else if (index === 3) {
  362. if (type != 0) {
  363. renameFolder(id,name,type)
  364. }
  365. }
  366. });
  367. }
  368. // 添加文件夹
  369. function addFolder() {
  370. api.prompt({
  371. title: '新建文件夹',
  372. buttons: ['确定', '取消'],
  373. text: '请输入文件夹名称!'
  374. }, function(ret, err) {
  375. var text = ret.text;
  376. if (ret.buttonIndex === 1) {
  377. newFolder(ret.text)
  378. }
  379. });
  380. }
  381. // 添加文件以及文件夹的js动画
  382. $('body').on('click','.plus',function () {
  383. if ($('.tool_boxs').height() === 45){
  384. $('.tool_box_c').css({
  385. bottom:0,
  386. height: 65,
  387. marginBottom:5,
  388. opacity:1
  389. })
  390. $('.tool_boxs').css({
  391. height:191
  392. })
  393. }else {
  394. $('.tool_box_c').css({
  395. bottom:-70,
  396. height: 0,
  397. marginBottom:0,
  398. opacity:0
  399. })
  400. $('.tool_boxs').css({
  401. height:51
  402. })
  403. }
  404. })
  405. // open文件夹
  406. function openFolderContent(name,id) {
  407. $event.openTabLayout('cloudDiskDe'+Math.random(),'cloudDiskDe',name,{id,token:userToken});
  408. }
  409. // 删除文件或文件夹
  410. function deleteFolder(id,name) {
  411. var params = {
  412. ids: [{id,name}],
  413. token:userToken
  414. }
  415. $http.requestShowProgress(UrlRouter.delete,'post',params)
  416. .then(ret=>{
  417. if (ret.code === 0) {
  418. api.toast({
  419. msg: '删除成功',
  420. duration: 2000,
  421. location: 'top'
  422. })
  423. skip = 1
  424. isHtml = true
  425. findList()
  426. }else {
  427. api.toast({
  428. msg: '删除失败',
  429. duration: 2000,
  430. location: 'top'
  431. })
  432. }
  433. })
  434. .catch(err=>{
  435. api.toast({
  436. msg: '网络错误,请检查网络!',
  437. duration: 2000,
  438. location: 'top'
  439. })
  440. })
  441. }
  442. // 新建文件夹
  443. function newFolder(name) {
  444. var params = {
  445. pid: 0,
  446. name,
  447. token:userToken
  448. }
  449. $http.requestShowProgress(UrlRouter.addFolder,'post',params)
  450. .then(ret=>{
  451. if (ret.code === 0) {
  452. api.toast({
  453. msg: '添加成功',
  454. duration: 2000,
  455. location: 'top'
  456. })
  457. skip = 1
  458. isHtml = true
  459. findList()
  460. }else {
  461. api.toast({
  462. msg: '添加失败',
  463. duration: 2000,
  464. location: 'top'
  465. })
  466. }
  467. })
  468. .catch(err=>{
  469. api.toast({
  470. msg: '网络错误,请检查网络!',
  471. duration: 2000,
  472. location: 'top'
  473. })
  474. })
  475. }
  476. // 合并切块,上传文件
  477. function register(ids,token){
  478. //document->hook下面有介绍
  479. WebUploader.Uploader.register({
  480. 'name': 'webUploaderHookCommand',
  481. "before-send-file":"beforeSendFile",
  482. "before-send":"beforeSend",
  483. "after-send-file":"afterSendFile"
  484. },{
  485. beforeSendFile:function(file) {
  486. // 创建一个deffered,用于通知是否完成操作
  487. var deferred = WebUploader.Deferred();
  488. //js-spark-md5计算md5
  489. //内置计算md5【慢,而且jpg计算不对】
  490. getFileMd5(file,deferred,token);
  491. uploader.options.formData.uuid = uuid;
  492. uploader.options.formData.pid = ids;
  493. uploader.options.formData.token = userToken;
  494. //问题一:同时选择两个文件,大在前,小在后,则md5和filename会窜
  495. //问题二:主要如果<chunkSize,则不分块,不会有chunk和chunks两参数
  496. //问题三:内置参数chunk/chunks
  497. if(file.size<=chunkSize){
  498. uploader.options.formData.chunk=0;
  499. uploader.options.formData.chunks=1;
  500. }
  501. return deferred.promise();// 通知完成操作
  502. },
  503. beforeSend:function(block) {
  504. },
  505. afterSendFile:function(file) {//合并切块
  506. var url=baseurl+"disk/fileupload/mergeChunk";
  507. var args={
  508. "albumid":'',
  509. "pid":ids,
  510. "relativepath":"",
  511. "uuid":uuid,
  512. "fileid":file.id,
  513. "filename":file.name,
  514. "filemd5":md5,
  515. "totalSize":file.size,
  516. "token": token
  517. };
  518. $.post(url,args,function(data){
  519. if(data.code === 0){
  520. api.toast({
  521. msg: '上传成功',
  522. duration: 2000,
  523. location: 'top'
  524. });
  525. skip = 1
  526. isHtml = true
  527. findList()
  528. UIActionProgress.close();
  529. }else{
  530. api.toast({
  531. msg: '上传失败',
  532. duration: 2000,
  533. location: 'top'
  534. });
  535. UIActionProgress.close();
  536. }
  537. });
  538. }
  539. });
  540. }
  541. // 下载文件 图片
  542. function mergeFilesNew(id) {
  543. var uploadFileElm= $('#upload_file')
  544. api.confirm({
  545. title: '提示',
  546. msg: '是否下载文件',
  547. buttons: ['确定', '取消']
  548. }, function(ret, err) {
  549. var index = ret.buttonIndex;
  550. if (index === 1) {
  551. uploadFileElm.attr('href',`${UrlRouter.download}fileid=${id}&token=${userToken}`)
  552. uploadFileElm.attr('download',`${UrlRouter.download}fileid=${id}&token=${userToken}`)
  553. document.getElementById("upload_file").click();
  554. }
  555. });
  556. }
  557. // 重命名
  558. // 文件夹
  559. function renameFolder(id,name,type) {
  560. var filename = name
  561. fileType = name.substring(name.lastIndexOf('.'))
  562. if (type != 0) {
  563. filename = name.substring(0,name.lastIndexOf('.'))
  564. }
  565. api.prompt({
  566. title: '修改文件名称',
  567. buttons: ['确定', '取消'],
  568. text: filename
  569. }, function(ret, err) {
  570. var text = ret.text;
  571. if (ret.buttonIndex === 1) {
  572. rename(id,ret.text,fileType)
  573. }
  574. });
  575. }
  576. function rename(id,filename,fileType) {
  577. var type = fileType
  578. if (fileType.indexOf('.') != 0 ) {
  579. type = ''
  580. }
  581. var params = {
  582. id,
  583. filename:filename+type,
  584. token:userToken
  585. }
  586. $http.requestShowProgress(UrlRouter.rename,'post',params)
  587. .then(ret=>{
  588. if (ret.code === 0) {
  589. api.toast({
  590. msg: '修改成功',
  591. duration: 2000,
  592. location: 'top'
  593. })
  594. skip = 1
  595. isHtml = true
  596. findList()
  597. }else {
  598. api.toast({
  599. msg: '修改失败',
  600. duration: 2000,
  601. location: 'top'
  602. })
  603. }
  604. })
  605. .catch(err=>{
  606. api.toast({
  607. msg: '网络错误,请检查网络!',
  608. duration: 2000,
  609. location: 'top'
  610. })
  611. })
  612. }
  613. // function shareFile(){
  614. // var sharedModule = api.require('shareAction');
  615. // sharedModule.share({
  616. // text: '纯文本信息',
  617. // type: 'text'
  618. // });
  619. // }
  620. </script>