快应用sample与各家厂商的差异对比

129 阅读1分钟

鸿蒙的示例官网:developer.huawei.com/consumer/cn…

鸿蒙的示例官网代码仓库:gitee.com/harmonyos_s…

安卓的示例官网:developer.android.com/samples?hl=…

安卓的示例官网代码仓库:github.com/android

安卓的之前的api demo 仓库:github.com/THEONE10211…

苹果的示例官网:developer.apple.com/library/arc…

苹果的示例仓库:github.com/bqlin/Apple…

快应用sample侧重把接口api上面的属性,方法写成各个具体用到的写法展示出来给开发者学习,让开发者在真实的应用场景去组合出自己所需要的完整案例,没有给出一个完整工程的真实应用示例

快应用具体的代码展示和图片如下:

<template>
  <div class="doc-page">
    <div class="page-title-wrap">
      <text class="page-title">{{ componentName }}</text>
    </div>

    <div class="item-container">
      <input type="text" class="input-text" placeholder="自定义UserAgent(1040+)" onchange="handleUA" />
      <div class="item-content">
        <text class="txt">下载文件:</text><text class="txt">{{ fileDownloadData }}</text>
      </div>
      <input type="button" class="btn" onclick="downloadFile" value="下载文件" />
      <input type="button" class="btn" onclick="downloadFile1010" value="下载文件(文件重命名)1010+" />

      <div class="item-content">
        <text class="txt">上传文件:</text><text class="txt">{{ fileUploadData }}</text>
      </div>
      <input type="button" class="btn" onclick="uploadFile" value="上传文件" />
    </div>
  </div>
</template>

<style>
@import '../Common/css/common.css';

.item-container {
  margin-bottom: 50px;
  margin-right: 60px;
  margin-left: 60px;
  flex-direction: column;
}

.item-content {
  flex-direction: column;
  background-color: #ffffff;
  padding-left: 30px;
  padding-right: 30px;
  padding-top: 20px;
  padding-bottom: 20px;
  margin-bottom: 30px;
  align-items: flex-start;
}

.txt {
  lines: 5;
  padding-top: 15px;
  padding-bottom: 15px;
}

.input-text {
  height: 80px;
  line-height: 80px;
  padding-left: 30px;
  padding-right: 30px;
  margin-left: 30px;
  margin-right: 30px;
  margin-bottom: 30px;
  border-top-width: 1px;
  border-bottom-width: 1px;
  border-color: #999999;
  font-size: 30px;
  background-color: #ffffff;
}
</style>

<script>
import fetch from '@system.fetch'
import request from '@system.request'
import prompt from '@system.prompt'

export default {
  data: {
    componentName: 'request',
    fileDownloadData: '',
    fileUploadData: '',
    userAgent: '',
  },
  onInit: function() {
    this.$page.setTitleBar({ text: 'Requst' })
  },
  handleUA: function(e) {
    this.userAgent = e.value
  },
  downloadFile: function() {
    var that = this
    // 下载文件,存储在本地
    fetch.fetch({
      url: 'https://shopstatic.vivo.com.cn/vivoshop/commodity/20171228/20171228141136942321_original.jpg',
      header: {
        'User-Agent': this.userAgent,
      },
      success: function(ret) {
        that.fileDownloadData = ret.data
        console.log('file_downlaod_data--------' + JSON.stringify(ret))
      },
    })
  },
  downloadFile1010: function() {
    var that = this
    // 下载文件,存储在本地
    request.download({
      url: 'https://shopstatic.vivo.com.cn/vivoshop/commodity/20171228/20171228141136942321_original.jpg',
      header: {
        'User-Agent': this.userAgent,
      },
      description: '这是下载描述',
      filename: 'rename.jpg',
      success: function(ret) {
        that.fileDownloadData = 'internal://mass/download/rename.jpg'
        console.log('file_downlaod_data--------' + JSON.stringify(ret))
      },
    })
  },
  uploadFile() {
    var that = this
    // 上传下载好的本地文件.其中,data为请求的参数,files为需要上传的文件列表
    request.upload({
      url: 'http://172.25.70.224:8037/test',
      header: {
        'User-Agent': this.userAgent,
      },
      data: {
        name: 'component',
      },
      files: [
        {
          filename: 'testfile.jpg',
          uri: that.fileDownloadData,
          name: 'file',
        },
      ],
      success: function(ret) {
        that.fileUploadData = '上传文件成功'
      },
      fail: function(errmsg, errcode) {
        that.fileUploadData = errcode + ': ' + errmsg
      },
    })
  },
}
</script>