{"id":378,"date":"2025-05-20T15:21:41","date_gmt":"2025-05-20T07:21:41","guid":{"rendered":"https:\/\/www.hyw.life\/?p=378"},"modified":"2025-10-21T17:07:53","modified_gmt":"2025-10-21T09:07:53","slug":"uniapp%e5%a6%82%e4%bd%95%e4%b8%8b%e8%bd%bd%e6%96%87%e4%bb%b6%ef%bc%8c%e5%b9%b6%e5%b0%86%e6%96%87%e4%bb%b6%e9%87%8d%e5%91%bd%e5%90%8d","status":"publish","type":"post","link":"https:\/\/www.hyw.life\/?p=378","title":{"rendered":"uniapp\u5982\u4f55\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5e76\u5c06\u6587\u4ef6\u91cd\u547d\u540d"},"content":{"rendered":"\n<p>\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5e76\u5c06\u6587\u4ef6\u91cd\u547d\u540d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uni.showLoading({\n  title: '\u4e0b\u8f7d\u4e2d'\n})\n \nuni.downloadFile({\n  url: \"https:\/\/192.168.110.225\/1.xls\",\n  success: (downloadResult) => {\n    console.log(\"downloadResult\", downloadResult)\n    if (downloadResult.statusCode === 200) {\n      \/\/ \u4fdd\u5b58\u6587\u4ef6\n      uni.saveFile({\n        tempFilePath: downloadResult.tempFilePath,\n        success: (saveResult) => {\n          uni.hideLoading();\n          console.log('\u6587\u4ef6\u4fdd\u5b58\u6210\u529f\uff0c\u4fdd\u5b58\u8def\u5f84\uff1a', saveResult.savedFilePath);\n          const oldFilePath = saveResult.savedFilePath;\n          const fileExtension = oldFilePath.split('.').pop();\n \n          \/\/ \u521b\u5efa\u4e00\u4e2aDate\u5bf9\u8c61\n          const now = new Date();\n \n          \/\/ \u83b7\u53d6\u5f53\u524d\u7684\u5e74\u3001\u6708\u3001\u65e5\n          const year = now.getFullYear();\n          const month = now.getMonth() + 1; \/\/ \u6708\u4efd\u662f\u4ece0\u5f00\u59cb\u7684\uff0c\u9700\u8981\u52a01\n          const date = now.getDate();\n \n          const hours = now.getHours().toString().padStart(2, '0');\n          const minutes = now.getMinutes().toString().padStart(2, '0');\n          const seconds = now.getSeconds().toString().padStart(2, '0');\n \n          const newFileName = year + \"-\" + month + \"-\" + date + \" \" + hours + \":\" + minutes + \":\" + seconds + '_\u7ed3\u679c.xls'; \/\/\n          \u65b0\u7684\u6587\u4ef6\u540d\n          const newFilePath = oldFilePath.replace(\/&#91;^\\\/]*$\/, newFileName);\n \n          uni.showToast({\n            icon: 'none',\n            mask: true,\n            title: `\u6587\u4ef6\u5df2\u4fdd\u5b58`, \/\/\u4fdd\u5b58\u8def\u5f84\n            duration: 3000,\n          });\n          console.log(\"newFilePath\", oldFilePath, newFilePath)\n          \/\/ \u4fee\u6539\u6587\u4ef6\u540d\n          plus.io.resolveLocalFileSystemURL(oldFilePath, entry => {\n            entry.getParent(_oldFile => {\n              entry.moveTo(_oldFile, '\/' + newFileName, newFilePath => {\n                console.log('newFilePath', newFilePath.fullPath)\n              })\n            })\n          })\n        },\n        fail: (saveError) => {\n          console.error('\u6587\u4ef6\u4fdd\u5b58\u5931\u8d25\uff1a', saveError);\n        }\n      });\n    } else {\n      console.error('\u6587\u4ef6\u4e0b\u8f7d\u5931\u8d25\uff0c\u72b6\u6001\u7801\uff1a', downloadResult.statusCode);\n    }\n  },\n  fail: (downloadError) => {\n    console.error('\u6587\u4ef6\u4e0b\u8f7d\u5931\u8d25\uff1a', downloadError);\n  }\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5e76\u5c06\u6587\u4ef6\u91cd\u547d\u540d<\/p>\n","protected":false},"author":1,"featured_media":484,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,5],"tags":[15],"class_list":["post-378","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uniapp","category-qd","tag-uniapp"],"_links":{"self":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=378"}],"version-history":[{"count":2,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":380,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions\/380"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/media\/484"}],"wp:attachment":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}