从服务器接口请求数据并写入数据库

使用说明

客户端 Android iOS
支持说明 支持 支持
import { MDownloader } from "@yl/super-jssdk";

MDownloader.downloadData(optional)

参数说明

参数 类型 必填 作用
optional Object 必填参数

optional

参数 类型 必填 作用
url string 数据下载url
dbPath string 指定的数据库路径,支持file://前缀
start function 文件下载进度回调
options Object 插件选填参数

options

参数 类型 必填 作用
httpMethod int 设置http请求方式,1:GET 2:POST 默认GET
httpHeaderFields json http请求头设置 1.3.4版本开始生效
httpBodyFields json http实体设置 1.3.4版本开始生效
compatibleNotExist bool 为true时,insert、replace及update condition在操作字段多于表字段时,可忽略多出的字段;为false时无此特性。默认false 1.4.4版本开始生效

返回说明

参数 类型 作用
resolve Function 数据下载完成回调
reject(err) Function 数据下载错误回调,err为详细错误信息,是一个json对象,例如:{"errCode":-1,"errMsg":"出错啦"}

服务端返回接口数据格式示例

{
  "result": [{
      "operation": "delete",
      "table": "batch_room",
      "condition": "batch_building_id='1'"
    },
    {
      "operation": "insert",
      "table": "batch_room",
      "onconflict": "replace",
      "rows": [{
          "id": "39d06889-4df7-8431-546b-b3e8d41bc5be",
          "batch_id": "39d06889-4df7-8431-546b-b3e8d41bc5be",
          "batch_building_id": "39d06889-4df7-8431-546b-b3e8d41bc5be",
          "signature_url": "http://sss",
          "signature_local_path": "DDD"
        },
        {
          "id": "39d06889-4df7-8431-546b-b3e8d41bc5be",
          "batch_id": "39d06889-4df7-8431-546b-b3e8d41bc5be",
          "batch_building_id": "39d06889-4df7-8431-546b-b3e8d41bc5be"
        }
      ]
    },
    {
      "operation": "replace_insert",
      "table": "satisfaction_dimension",
      "rows": [{
        "id": "39d52d57-db0f-b865-1090-74889eab5e1d",
        "type": "开放",
        "dimension": "FUYL测试添加",
        "sort": "3"
      }]
    },
    {
      "operation": "update",
      "table": "batch_building",
      "onconflict": "replace",
      "set": {
        "is_download": 1,
        "has_update": 0,
        "timestamp": 23232
      },
      "condition": "batch_building_id='1'"
    }
  ]
}

代码示例

const params = {
  url: "rrr",
  dbPath: "5656"
};
MDownloader.downloadData(params)
  .then((res) => {
    console.log("success", res);
  })
  .catch((err) => {
    console.log("fail", err);
  });

results matching ""

    No results matching ""