quickapp_快应用_系统接口应用

系统接口

在项目中使用到的接口都需要在配置文件manifest.json中声明,不然会报如下警告

[WARN] 请在 manifest.json 文件里声明项目代码中用到的接口: system.storage, service.account, system.package, system.webview
[1]检查某app是否在手机上安装
  • 官方文档:官方文档
  • 接口: system.package的hasInstalled方法
  • 作用:检查某app是否在已经在手机上安装
  • 使用
    • [1] 接口声明- 在配置文件manifest.json中声明
      "features": [
        {
             
          "name": "system.package" 
        },
      ]
      
    • [2] 在需要的地方导入并使用
        import pkg from '@system.package'
      
      pkg.hasInstalled({
             
        package: 'app包名',
        success: function(data) {
             
          console.log(`handling success: ${
               data.result}`)
          // result为true表示app已安装
          // result为false表示app未安装
        },
       fail: function(data, code) {
             
         console.log(`handling fail, code = ${
               code}`)
        }
      })
      
[2]下载应用
  • 官方文档:官方文档
  • 接口: system.package的install方法
  • 作用:下载某app
  • 使用
    • [1] 接口声明- 在配置文件manifest.json中声明
      "features": [
        {
             
          "name": "system.package" 
        },
      ]
      
    • [2] 在需要的地方导入并使用
      import pkg from '@system.package'
      
      pkg.install({
             
       package: '应用包名',
       success: function(data) {
             
         console.log(`handling success: ${
               data.result}`)
         // result:true 下载成功
         // result: false 下载失败
       },
       fail: function(data, code) {
             
         console.log(`handling fail, code = ${
               code}`)
       }
      })
      
[3] 检查当前是否有桌面应用
  • 官方文档:官方文档
  • 接口: system.shortcut的hasInstalled方法
  • 作用:检查某app当前是否有桌面应用
  • 使用
    • [1] 接口声明- 在配置文件manifest.json中声明
      "features": [
        {
             
          "name": "system.shortcut" 
        },
      ]
      
    • [2] 在需要的地方导入并使用
      import shortcut from '@system.shortcut'
      
      shortcut.hasInstalled({
             
       success: function(res) {
             
         // res 为true表示已创建图标
         // res weifalse表示未创建图标
       }
      })
      
[4] 添加桌面应用
  • 官方文档:官方文档
  • 接口: system.shortcut的install方法
  • 作用:为某app添加桌面应用
  • 使用
    • [1] 接口声明- 在配置文件manifest.json中声明
      "features": [
        {
             
          "name": "system.shortcut" 
        },
      ]
      
    • [2] 在需要的地方导入并使用
      import shortcut from '@system.shortcut'
      
      shortcut.install({
             
        success: function() {
             
          console.log('handling success') // 创建成功
        },
        fail: function(data, code) {
             
         // 创建失败,请在设置中开启创建桌面应用权限
         console.log(`handling fail, code = ${
               code}, errorMsg=${
               data}`)
        }
      })
      
[5]数据存储

本地数据存储

[6]弹框
  • 官方文档:官方文档
  • 弹出框一共有三种
    • toast提示框-showToast
    • dialog对话框-showDialog
    • 列表框-showContextMenu
[7]接口
  • 官方文档:官方文档
  • 请求封装
    import {
          fetch } from "@system.fetch";
    import {
          getStorage, setStorage } from './storage'
    const api = 'xxx' 
    
    const hasToken = async () => {
         
       const token = await getStorage('token')
       return !!token
    }
    
    // 将与后端约定的数据统一添加在请求头中
    const getHeaders = async () => {
         
       const token = await getStorage('token')
       return {
         
           token,
           ....
       }
    }
    
    export const httpGet = async (url, data = {
          }, header = {
          }) => {
         
     await hasToken()
     const headers = await getHeaders()
     return new Promise((resolve, reject) => {
         
       fetch({
         
         url: api + url,
         data,
         method: 'GET',
         responseType: 'json',
         header: {
         
           ...headers,
           ...header
         },
         success(data) {
         
           resolve(data.data)
         },
         fail(err) {
         
           reject(err)
         }
       })
     })
    }
    
    export const httpPost = async (url, data = {
          }, header = {
          }) => {
         
     await hasToken()
     const headers = await getHeaders()
     return new Promise((resolve, reject) => {
         
       fetch({
         
         url: api + url,
         data,
         method: 'POST',
         responseType: 'json',
         header: {
         
           ...header,
           ...headers
         },
         success(data) {
         
           if (data.data.status === 1004) {
         
             router.replace({
         
               uri: '/pages/Login'
             })
           } else {
         
             resolve(data.data)
           }
             
         },
         fail(err) {
         
           reject(err)
         }
       })
     })
    }
    
    export default {
         
     httpGet,
     httpPost
    }
    
    
  • 请求头添加设备信息
[8]获取设备信息

获取设备信息

[9]获取上下文app

应用上下文app

  • 应用版本号

相关推荐

  1. quickapp_应用_系统接口应用

    2023-12-06 17:34:03       57 阅读
  2. quickapp_应用_DOM节点

    2023-12-06 17:34:03       54 阅读
  3. 应用组件通信

    2023-12-06 17:34:03       55 阅读
  4. 接口应用

    2023-12-06 17:34:03       35 阅读
  5. Gmsh应用程序编程接口

    2023-12-06 17:34:03       22 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-06 17:34:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-06 17:34:03       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-06 17:34:03       82 阅读
  4. Python语言-面向对象

    2023-12-06 17:34:03       91 阅读

热门阅读

  1. Socket通信

    2023-12-06 17:34:03       65 阅读
  2. MySQL之函数学习

    2023-12-06 17:34:03       50 阅读
  3. File 类

    2023-12-06 17:34:03       55 阅读
  4. 数据库备份与恢复

    2023-12-06 17:34:03       50 阅读
  5. QT——数据转换(int/QString/QByteArray/char/string)等

    2023-12-06 17:34:03       53 阅读
  6. openssl 生成CA及相关证书

    2023-12-06 17:34:03       58 阅读
  7. 索引器【C#】

    2023-12-06 17:34:03       57 阅读
  8. 特征与特征图的区别

    2023-12-06 17:34:03       52 阅读
  9. git 学习笔记

    2023-12-06 17:34:03       63 阅读
  10. 【开源视频联动物联网平台】Node-RED规则引擎

    2023-12-06 17:34:03       52 阅读
  11. 前端面试题:常见的响应状态码

    2023-12-06 17:34:03       51 阅读
  12. 【总结】ES 7.x 配置用户名和密码访问(亲测可用)

    2023-12-06 17:34:03       59 阅读
  13. C语言K&R圣经笔记 4.3 外部变量

    2023-12-06 17:34:03       44 阅读
  14. RabbitMQ常用命令(一)

    2023-12-06 17:34:03       45 阅读