Name Last Update
..
utssdk Loading commit data...
README.md Loading commit data...
package.json Loading commit data...

plus.* API 迁移插件

将 gl_tape 项目中的 plus.* API 迁移到 uni-app x 的 UTS 插件实现。

功能说明

本插件提供了以下 plus.* API 的 uni-app x 替代实现:

1. plus.runtime

  • getAppVersion() - 获取应用版本号
  • getAppId() - 获取应用ID
  • openURL() - 打开外部URL

2. plus.screen

  • lockOrientation() - 锁定屏幕方向
  • unlockOrientation() - 解锁屏幕方向
  • setKeepScreenOn() - 保持屏幕常亮

3. plus.io

  • getFilePath() - 获取文件路径
  • readFile() / writeFile() - 文件读写
  • checkFileExists() - 检查文件是否存在
  • readDirectory() / createDirectory() / deleteDirectory() - 目录操作

4. plus.android

  • getRuntimeMainActivity() - 获取主 Activity
  • openSystemSettings() - 打开系统设置
  • openAppSettings() - 打开应用设置
  • getInstalledPackages() - 获取已安装应用列表
  • getExternalFilesDir() / getFilesDir() - 获取存储目录

5. plus.ios

  • openSystemSettings() - 打开系统设置
  • openAppSettings() - 打开应用设置

6. plus.navigator

  • getStatusbarHeight() - 获取状态栏高度
  • setUserAgent() - 设置用户代理

7. plus.os

  • isIOS() / isAndroid() - 判断操作系统
  • getOSName() - 获取操作系统名称

使用方法

在页面中导入使用

// 导入工具函数
import { getAppVersion, openURL } from "@/utils/plus-runtime"
import { lockOrientation, setKeepScreenOn } from "@/utils/plus-screen"
import { getFilePath, readFile, writeFile } from "@/utils/plus-io"
import { isIOS, isAndroid } from "@/utils/plus-os"

// 使用
const version = getAppVersion()
openURL("https://example.com")
lockOrientation("portrait-primary")
setKeepScreenOn(true)

使用 UTS 插件(原生实现)

// 导入插件
import androidImpl from "@/uni_modules/plus-migration/utssdk/app-android/index"
import iosImpl from "@/uni_modules/plus-migration/utssdk/app-ios/index"

// Android 使用
androidImpl.openSystemSettings()
androidImpl.openAppSettings()
const packages = androidImpl.getInstalledPackages()

// iOS 使用
iosImpl.openSystemSettings()
iosImpl.openAppSettings()

注意事项

  1. Context/Activity 获取:

    • Android 实现中需要获取 Context,请根据 uni-app x 的 API 文档实现 getContext() 方法
    • 可能需要使用 getUniActivity() 或类似的 uni-app x API
  2. 原生代码实现:

    • plus.android 和 plus.ios 的复杂功能需要使用 UTS 插件
    • 插件中的代码会编译为 Kotlin(Android)或 Swift(iOS)
    • 需要根据 uni-app x 的实际 API 调整实现
  3. 权限要求:

    • 某些功能(如获取已安装应用列表)需要相应权限
    • 请在 manifest.json 中配置所需权限
  4. 平台兼容性:

    • 所有函数都使用条件编译,确保多端兼容
    • 非目标平台会返回默认值或空值

迁移对照表

原代码(plus.*) 新代码(uni-app x) 说明
plus.runtime.version getAppVersion() 需要通过 UTS 插件获取
plus.runtime.appid getAppId() 需要通过 UTS 插件获取
plus.runtime.openURL() openURL() 使用 uni.openURL
plus.screen.lockOrientation() lockOrientation() 建议在 manifest.json 配置
plus.screen.unlockOrientation() unlockOrientation() 建议在 manifest.json 配置
plus.device.setWakelock() setKeepScreenOn() 使用 uni.setKeepScreenOn
plus.io.requestFileSystem() getFilePath() 使用 uni.getFileSystemManager
plus.android.runtimeMainActivity() androidImpl.getRuntimeMainActivity() 需要 UTS 插件
plus.android.importClass() 直接使用原生类 在 UTS 中直接导入
plus.ios.import() 直接使用原生类 在 UTS 中直接导入

示例

查看 pages/demo/gl-tape-demo/index.uvue 了解完整的使用示例。