From 30e176f0309c1e9c6b0f1d2388e3d4e1f78b4859 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Mon, 18 Dec 2023 19:09:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20uts-file-manager=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 7 - pages/advance/advance.vue | 3 - pages/resource/fileRead.uvue | 27 ---- pages/resource/fileRead.vue | 79 ----------- uni_modules/uts-file-manager/changelog.md | 0 uni_modules/uts-file-manager/package.json | 81 ------------ uni_modules/uts-file-manager/readme.md | 6 - .../utssdk/app-android/index.uts | 124 ------------------ .../uts-file-manager/utssdk/app-ios/index.uts | 0 .../uts-file-manager/utssdk/interface.uts | 106 --------------- .../uts-file-manager/utssdk/unierror.uts | 18 --- 11 files changed, 451 deletions(-) delete mode 100644 pages/resource/fileRead.uvue delete mode 100644 pages/resource/fileRead.vue delete mode 100644 uni_modules/uts-file-manager/changelog.md delete mode 100644 uni_modules/uts-file-manager/package.json delete mode 100644 uni_modules/uts-file-manager/readme.md delete mode 100644 uni_modules/uts-file-manager/utssdk/app-android/index.uts delete mode 100644 uni_modules/uts-file-manager/utssdk/app-ios/index.uts delete mode 100644 uni_modules/uts-file-manager/utssdk/interface.uts delete mode 100644 uni_modules/uts-file-manager/utssdk/unierror.uts diff --git a/pages.json b/pages.json index 0a211d1..2b4ec8d 100644 --- a/pages.json +++ b/pages.json @@ -91,13 +91,6 @@ "enablePullDownRefresh": false } }, - { - "path": "pages/resource/fileRead", - "style": { - "navigationBarTitleText": "", - "enablePullDownRefresh": false - } - }, { "path": "pages/advance/android/decorview", "style": { diff --git a/pages/advance/advance.vue b/pages/advance/advance.vue index 2246082..494e01a 100644 --- a/pages/advance/advance.vue +++ b/pages/advance/advance.vue @@ -61,9 +61,6 @@ pages: [{ name: "图片加载示例", url: "resource/resource" - },{ - name: "文件读取示例", - url: "resource/fileRead" }] }, { diff --git a/pages/resource/fileRead.uvue b/pages/resource/fileRead.uvue deleted file mode 100644 index 18c4fcf..0000000 --- a/pages/resource/fileRead.uvue +++ /dev/null @@ -1,27 +0,0 @@ - - - - diff --git a/pages/resource/fileRead.vue b/pages/resource/fileRead.vue deleted file mode 100644 index b5b8769..0000000 --- a/pages/resource/fileRead.vue +++ /dev/null @@ -1,79 +0,0 @@ - - - - diff --git a/uni_modules/uts-file-manager/changelog.md b/uni_modules/uts-file-manager/changelog.md deleted file mode 100644 index e69de29..0000000 diff --git a/uni_modules/uts-file-manager/package.json b/uni_modules/uts-file-manager/package.json deleted file mode 100644 index e69ed1a..0000000 --- a/uni_modules/uts-file-manager/package.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "id": "uts-file-manager", - "displayName": "uts-file-manager", - "version": "1.0.0", - "description": "uts-file-manager", - "keywords": [ - "uts-file-manager" -], - "repository": "", - "engines": { - "HBuilderX": "^3.6.8" - }, - "dcloudext": { - "type": "uts", - "sale": { - "regular": { - "price": "0.00" - }, - "sourcecode": { - "price": "0.00" - } - }, - "contact": { - "qq": "" - }, - "declaration": { - "ads": "", - "data": "", - "permissions": "" - }, - "npmurl": "" - }, - "uni_modules": { - "dependencies": [], - "encrypt": [], - "platforms": { - "cloud": { - "tcb": "u", - "aliyun": "u" - }, - "client": { - "Vue": { - "vue2": "u", - "vue3": "u" - }, - "App": { - "app-android": "u", - "app-ios": "u" - }, - "H5-mobile": { - "Safari": "u", - "Android Browser": "u", - "微信浏览器(Android)": "u", - "QQ浏览器(Android)": "u" - }, - "H5-pc": { - "Chrome": "u", - "IE": "u", - "Edge": "u", - "Firefox": "u", - "Safari": "u" - }, - "小程序": { - "微信": "u", - "阿里": "u", - "百度": "u", - "字节跳动": "u", - "QQ": "u", - "钉钉": "u", - "快手": "u", - "飞书": "u", - "京东": "u" - }, - "快应用": { - "华为": "u", - "联盟": "u" - } - } - } - } -} \ No newline at end of file diff --git a/uni_modules/uts-file-manager/readme.md b/uni_modules/uts-file-manager/readme.md deleted file mode 100644 index 71f9adf..0000000 --- a/uni_modules/uts-file-manager/readme.md +++ /dev/null @@ -1,6 +0,0 @@ -# uts-file-manager -### 开发文档 -[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) -[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) -[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html) -[Hello UTS](https://gitcode.net/dcloud/hello-uts) \ No newline at end of file diff --git a/uni_modules/uts-file-manager/utssdk/app-android/index.uts b/uni_modules/uts-file-manager/utssdk/app-android/index.uts deleted file mode 100644 index 9bbbc3e..0000000 --- a/uni_modules/uts-file-manager/utssdk/app-android/index.uts +++ /dev/null @@ -1,124 +0,0 @@ -import { ReadFileSuccessResult, ReadFileOptions } from "../interface.uts" -import { WriteFileSuccessResult, WriteFileOptions } from "../interface.uts" -import { GetFileSystemManager,FileSystemManager} from "../interface.uts" -import { UniErrorSubject, UniErrors } from "../unierror.uts" - -import File from "java.io.File" -import Base64 from "android.util.Base64" - -export { ReadFileOptions, WriteFileOptions } from "../interface.uts" - - -class AndroidFileSystemManager implements FileSystemManager{ - - public readFile(options : ReadFileOptions) { - - // 判断type 是否合法 - if(options.encoding != 'base64' && options.encoding != 'utf-8'){ - let err = new UniError(UniErrorSubject, 1200002, UniErrors.get(1200002)!); - options.fail?.(err) - options.complete?.(err) - return - } - - let filePath = UTSAndroid.convert2AbsFullPath(options.filePath) - let targetFile = new File(filePath) - if (!targetFile.exists()) { - let err = new UniError(UniErrorSubject, 1300002, UniErrors.get(1300002)! + filePath); - options.fail?.(err) - options.complete?.(err) - return - } - - if (targetFile.isDirectory()) { - let err = new UniError(UniErrorSubject,1301003,UniErrors.get(1301003)!); - options.fail?.(err) - options.complete?.(err) - return - } - - /** - * 文件超过16M,会超过应用内存 - */ - if (targetFile.length() > 16 * 1024 * 1024) { - let err = new UniError(UniErrorSubject,1300202,UniErrors.get(1300202)!); - options.fail?.(err) - options.complete?.(err) - return - } - - let currentDispatcher = UTSAndroid.getDispatcher() - /** - * 执行真正的加载行为,为了避免阻塞分发到 io任务序列 - */ - UTSAndroid.getDispatcher('io').async(function(_){ - - let ret : ReadFileSuccessResult = { - data : "" - } - - if(options.encoding == 'base64'){ - // base64 - let byteArray = targetFile.readBytes() - let base64Content = Base64.encodeToString(byteArray,Base64.NO_WRAP) - ret.data = base64Content - - }else{ - // text - let text = targetFile.readText() - ret.data = text - } - - currentDispatcher.async(function(_){ - options.success?.(ret) - options.complete?.(ret) - }) - - },null) - - } - - - public writeFile(options : WriteFileOptions) { - // 判断type 是否合法 - let nextFile = new File(UTSAndroid.getAppContext()?.getFilesDir(),options.filePath) - if(nextFile.exists() && nextFile.isDirectory()){ - // 出错了,目标文件已存在,并且是个目录 - let err = new UniError(UniErrorSubject,1301003,UniErrors.get(1301003)!); - options.fail?.(err) - options.complete?.(err) - return - } - - - let currentDispatcher = UTSAndroid.getDispatcher() - UTSAndroid.getDispatcher('io').async(function(_){ - - /** - * 如果上一级目录不存在,创建之 - */ - if(!nextFile.parentFile!.exists()){ - nextFile.parentFile!.mkdirs() - } - - if(!nextFile.exists()){ - nextFile.createNewFile() - } - // 写入文本,暂时只支持覆盖写入 - nextFile.writeText(options.data) - - let ret : WriteFileSuccessResult = { - filePath: nextFile.getPath() - } - - currentDispatcher.async(function(_){ - options.success?.(ret) - options.complete?.(ret) - }) - },null) - } -} - -export const getFileSystemManager:GetFileSystemManager = function ():FileSystemManager { - return new AndroidFileSystemManager() -}; diff --git a/uni_modules/uts-file-manager/utssdk/app-ios/index.uts b/uni_modules/uts-file-manager/utssdk/app-ios/index.uts deleted file mode 100644 index e69de29..0000000 diff --git a/uni_modules/uts-file-manager/utssdk/interface.uts b/uni_modules/uts-file-manager/utssdk/interface.uts deleted file mode 100644 index bb677a4..0000000 --- a/uni_modules/uts-file-manager/utssdk/interface.uts +++ /dev/null @@ -1,106 +0,0 @@ - -export type ReadFileSuccessResult = { - data: string -} - - -export type ReadFileSuccessCallback = (res: ReadFileSuccessResult) => void - -export type ReadFileFailCallback = (res: UniError) => void - -export type ReadFileCompleteCallback = (res: any) => void - - - -export type ReadFileOptions = { - /** - * base64 / utf-8 - */ - encoding: string, - /** - * 文件路径,支持相对地址和绝对地址 - */ - filePath: string, - /** - * 接口调用的回调函数 - */ - success?: ReadFileSuccessCallback | null, - /** - * 接口调用失败的回调函数 - */ - fail?: ReadFileFailCallback | null, - /** - * 接口调用结束的回调函数(调用成功、失败都会执行) - */ - complete?: ReadFileCompleteCallback | null -} - - -export type WriteFileSuccessResult = { - filePath: string, -} - - -export type WriteFileSuccessCallback = (res: WriteFileSuccessResult) => void - -export type WriteFileFailCallback = (res: UniError) => void - -export type WriteFileCompleteCallback = (res: any) => void - - -export type WriteFileOptions = { - /** - * 文件路径,只支持绝对地址 - */ - filePath: string, - /** - * 写入的文本内容 - */ - data: string, - /** - * 接口调用的回调函数 - */ - success?: WriteFileSuccessCallback | null, - /** - * 接口调用失败的回调函数 - */ - fail?: WriteFileFailCallback | null, - /** - * 接口调用结束的回调函数(调用成功、失败都会执行) - */ - complete?: WriteFileCompleteCallback | null -} - - -export interface FileSystemManager { - readFile(options: ReadFileOptions): void; - writeFile(options: WriteFileOptions): void; -} - - -export type GetFileSystemManager = () => FileSystemManager; - - -export interface Uni { - /** - * 获取文件管理器 - * @uniPlatform { - * "app": { - * "android": { - * "osVer": "4.4.4", - * "uniVer": "√", - * "unixVer": "3.9.0" - * }, - * "ios": { - * "osVer": "x", - * "uniVer": "x", - * "unixVer": "x" - * } - * } - * } - * @uniVueVersion 2,3 //支持的vue版本 - */ - getFileSystemManager: GetFileSystemManager -} - - diff --git a/uni_modules/uts-file-manager/utssdk/unierror.uts b/uni_modules/uts-file-manager/utssdk/unierror.uts deleted file mode 100644 index ca89a7a..0000000 --- a/uni_modules/uts-file-manager/utssdk/unierror.uts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * 错误主题 - */ -export const UniErrorSubject = 'uni-file-manager'; - - -/** - * 错误码 - * @UniError - */ -export const UniErrors:Map = new Map([ - - [1200002, 'type error. only support base64 / utf-8'], - [1300002, 'no such file or directory'], - [1301003, 'illegal operation on a directory'], - [1300202, 'the maximum size of the file storage limit is exceeded'], - -]); -- GitLab