has.openDocument(Object object)
在新页面中打开文档。
起始版本: 1.0.8
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| filePath | string | 是 | 文件路径(本地路径),可通过has.downloadFile获取。 |
| fileType | string | 否 | 文件类型,指定文件类型打开文件。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
fileType的合法值:
| 值 | 描述 |
|---|---|
| pdf格式。 | |
| doc | doc格式。 |
| docx | docx格式。 |
| xls | xls格式。 |
| xlsx | xlsx格式。 |
| ppt | ppt格式。 |
| pptx | pptx格式。 |
错误码:
| 错误码 | 错误信息 |
|---|---|
| 102 | openDocument: fail fileType is not supported. |
| 104 | openDocument: fail no such file or directory. |
| 126 | Preview is not supported on this device. |
| 90002401 | openDocument: Failed to preview. |
| 90002402 | openDocument error. |
示例:
has.downloadFile({
url: 'https://www.example.com/xxx.pdf', // 此处仅为样例,请开发者更换为可用接口地址
success: (res) => {
const filePath = res.tempFilePath;
has.openDocument({
filePath: filePath,
success: (res) => {
console.info('openDocument success', res);
},
fail: (err) => {
console.error('openDocument fail', err);
},
complete: (res) => {
console.info('openDocument complete', res);
}
});
}
}); has.getFileSystemManager(): FileSystemManager
返回一个全局唯一的文件管理器。
起始版本: 1.0.4
返回值:
返回FileSystemManager对象。
示例:
const fileSystemManager = has.getFileSystemManager();
FileSystemManager.open和FileSystemManager.openSync方法flag参数的合法值。
起始版本: 1.0.16
| 值 | 描述 |
|---|---|
| a | 打开文件用于追加。如果文件不存在,则创建该文件。 |
| ax | 类似于 'a',但如果路径存在,则失败。 |
| a+ | 打开文件用于读取和追加。如果文件不存在,则创建该文件。 |
| ax+ | 类似于 'a+',但如果路径存在,则失败。 |
| as | 打开文件用于追加(在同步模式中)。如果文件不存在,则创建该文件。 |
| as+ | 打开文件用于读取和追加(在同步模式中)。如果文件不存在,则创建该文件。 |
| r | 打开文件用于读取。如果文件不存在,则会发生异常。 |
| r+ | 打开文件用于读取和写入。如果文件不存在,则会发生异常。 |
| w | 打开文件用于写入。如果文件不存在则创建文件,如果文件存在则截断文件。 |
| wx | 类似于 'w',但如果路径存在,则失败。 |
| w+ | 打开文件用于读取和写入。如果文件不存在则创建文件,如果文件存在则截断文件。 |
| wx+ | 类似于 'w+',但如果路径存在,则失败。 |
每个FileStats对象包含path和Stats。
起始版本: 1.0.4
| 属性 | 类型 | 描述 |
|---|---|---|
| path | string | 文件/目录路径。 |
| stats | Stats | Stats对象,即描述文件状态的对象。 |