目录

联系人

接口声明

在manifest.json文件的 features属性中增加如下配置。

{"name": "system.contact"}

导入模块

在调用接口页面的<script>部分增加如下配置。

import contact from '@system.contact'

或

var contact = require("@system.contact")

使用限制

限制条件

说明

适用终端

手机、平板

适用区域

全球

接口定义

接口

描述

contact.pick(OBJECT)

选择联系人。

[h2]contact.pick(OBJECT)

描述

选择联系人。

OBJECT参数

参数

类型

是否必填

说明

success

function

否

成功回调。

fail

function

否

失败回调。

complete

function

否

执行结束后的回调。

success返回值:

参数名

类型

说明

displayName

string

联系人名称。

number

string

电话号码。

示例代码

contact.pick({
    success: function(data) {
        console.log('data : '+data.displayName+', number = '+data.number);
    },
    fail: function(errmsg, errcode) {
        console.log('pick failed ' + errmsg+' errcode = '+errcode);
    }
})

Demo

<template>
  <!-- Only one root node is allowed in template. -->
  <div class="container">
    <div class="info-container mt-item">
      <div class="info-item border-bottom-1">
        <text class="title">contact name:</text>
        <text class="result">{{namePicked ? name : 'please select name'}}</text>
      </div>
      <div class="info-item">
        <text class="title">contact phone:</text>
        <text class="result">{{namePicked ? phone : 'please select phone'}}</text>
      </div>
    </div>
    <div class="mlr-container row-center mt-item">
      <input onclick="pickName" type="button" class="btn-blue" value="Select a Contact"/>
    </div>
  </div>
</template>

<style lang="sass">
 .container {
  flex-direction: column;
  padding-bottom: 50px;
}
.mt-item {
  margin-top: 40px;
}
.case-title .title {
  color: rgba(0, 0, 0, 0.6);
  font-size: 28px;
  font-weight: 500;
}
.mlr-container {
  margin-right: 32px;
  margin-left: 32px;
}
.row-center {
  justify-content: center;
}
.column-center {
  align-items: center;
}
.border-bottom-1{
  border-bottom-width: 1px;
}
.info-container {
  margin-left: 32px;
  margin-right: 32px;
  margin-top: 40px;
  padding-right: 20px;
  padding-left: 20px;
  background-color: #fff;
  border-radius: 32px;

  flex-direction: column;
}
.info-container .info-item {
  height: 120px;
  border-bottom-color: rgba(0, 0, 0, 0.05);;
}
.info-container .info-item .title {
  flex-shrink: 0;
  font-size: 32px;
  color: rgba(0, 0, 0, 0.9);
}
.info-container .info-item .result {
  width: 100%;
  justify-content: flex-end;
  text-align: right;
  color: #999;
}
  .btn-blue {
     background-color: #0faeff;
    width: 100%;
    height: 80px;
    border-radius: 40px;
    color: #fff;
    font-size: 32px;
    font-weight: 500;
  }
</style>

<script>
  import contact from '@system.contact';
  module.exports = {
    public: {
        name:"",
        phone:"",
        namePicked:false,
    },
    onInit: function () {
      this.$page.setTitleBar({ text: 'contact' });
    },
    pickName(){
      let that = this;
      contact.pick({
        success: function (data) {
          that.namePicked = true;
          that.name = data.displayName;
          that.phone = data.number;
        }
      })
    }
  }
</script>

效果图如下:

版本更新说明

版本

发布日期

描述

1010

2018-04-20

第一次正式发布。