3.21.0 • Published 3 months ago

@opentapd/tapd-open-js-sdk v3.21.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

Open TAPD JS SDK

使用

// 这里需要做设配
import SDK from "@tencent/tapd-open-js-sdk";

const sdk = SDK();

sdk.events.on('event from ', function(data){
  return 'world'; // return to tapd
})

sdk.handler('handle name', {
  hello: 'world', // You param to you service
})

sdk.navigator.openAppIndex('rul')

sdk.ui.openDialog({url: 'tencent.com'})

API

ui

.alert(message: string)

调用tapd的消息提示组件

sdk.ui.alert('Hello World')

.confirm(message: string) => Promise

调用TAPD侧的确认框。

sdk.ui.confirm('来个点赞3连?')
  .then(() => {
    alert('THX 😍')
  })

.closeDialog

关闭弹窗

sdk.ui.closeDialog()

.openDialog(params)

调用TAPD侧弹框

sdk.ui.openDialog(params)

参数:params

title: string

弹窗标题

url: string

弹窗URL

height: number

高度

width: number

宽度

showBtn: boolean

是否显示确认按钮

btnYesText: string

确认按钮文本

btnNoText: string

取消按钮文本

.resizeDialog(width: number, height: number)

调整弹框大小

sdk.ui.resizeDialog(300, 400)

handler

.handler(handlerName: string, params = {}) => Promise <res>

function调用。

参数

handlerName: 接口名

params: 传递给接口的参数。只支持普通对象

返回

res: 接口返回

sdk.handler('story', {id: 'tsets'});

navigator

.openAppIndex(url: string)

于TAPD侧打开调用sdk的嵌入应用新的页面。url 为嵌入应用的路由。

sdk.navigator.openAppIndex('/about')

.openObjectWindow(params: { entityType: string, entityId: string })

打开TAPD业务对象的详情页(目前只支持需求,任务,缺陷)

sdk.navigator.openObjectWindow({entityType: 'story', entityId: '123'})

.syncUrl(options: {url: string, refresh: bolean})

更新当前浏览器的路由,一般用于同步嵌入应用路由与浏览器路由

sdk.navigator.syncUrl({url: 'http://tapd.oa.com/', refresh: false})

参数

url: 目标路由

refresh: 跟新路由后是否刷新页面

context

.getEntranceData() => Promise <entranceConfigs >

获取当前页面嵌入TAPD的配置信息

const entranceConfigs = await sdk.context.getEntranceData() // return {appId, entranceId, code}

返回 entranceConfigs

appId: 应用ID

code: tapd Token,

entranceId: 挂载点ID

.refreshCode() => Promise <code>

跟新tapd授予码code,一般用于授权码过期

const newCode = await sdk.context.refreshCode()

iframe

.syncPageEvent(params: {entranceId: string, data: any}) => Promise

当在TADP的页面中有多个挂载点页面,可以通过这个方法在不同挂载点间通信

sdk.iframe.syncPageEvent({
  entranceId: 'app_for_obj_detail_bottom_card',
  data: {
    msg: '下次一定'
  }
})

.setPageHeight(height: number)

调用应用在TAPD侧的高度

sdk.iframe.setPageHeight(400)

command

.refreshAttachmentList()

当嵌入应用页面在tapd的业务对象(需求,任务,缺陷)详情页面,将更新页面里的附件列表

sdk.command.refreshAttachmentList()

.showObjDetailBottomCard()

当嵌入应用页面在tapd的业务对象(需求,任务,缺陷)详情页面, 可以唤起挂在类型为 app_for_obj_detail_bottom_card 的挂载页面

sdk.command.showObjDetailBottomCard()

request

.getUserListByKeyWords(params: {key_word: string, workspace_id: string, per_page: number}, configs: {timeout: number }) => Promise <response>

调用tapd侧的人名搜索接口

sdk.request
  .getUserListByKeyWords({
    key_word: 'tom',
    workspace_id: '1'
  })
  .then((response) => {
    console.log(response)
  })

返回 response

data: Array

用户列表

keyword: String

搜素的关键字

.getWorkspaceMemberList(params: {workspace_id: string,page_size: number, page: number }) => Promise<response>

调用TAPD侧获取项目下人员名单接口。

sdk.request
  .getWorkspaceMemberList({
    page_size: 100,
    workspace_id: '1',
    page: 1
  })
  .then((response) => {
    console.log(response)
  })

返回 response

data: Array

成员列表

count: String

总人数

.getAllRelateMember(params: object}) => Promise

获取对象相关成员名单

sdk.request.getAllRelateMember({
  workspace_id: '755',
  entity_type: 'bug',
  entity_id: '1000000755089798713',
  include_self: 1
  include_relate_story_member: 0
  include_sub_story_member: 0
})
.then((res) => {
  alert(res, ' 😍')
})

参数 params:

workspace_id: string

tapd 项目ID

entity_type: string

资源类型: story|bug|task

include_self: 0 | 1

是否包括用户

include_relate_story_member: 0 | 1

是否包含关联需求

include_sub_story_member: 0 | 1

是否包含子需求

event

.on(event: string, cb: data => res, config: {once: bolean})

监听来着TADP测的事件。

参数:

event: 事件名

cb: 回调函数,参数为接受的数据,当在函数中返回数据时,将会把返回的数据发回给TAPD

once: 是否只监听一次

sdk.event.on('ConfirmYes', function() {
  return {
    id: 'target Objct ID'
  }
}, {
  once: true
})
3.21.0

3 months ago

3.20.1-alpha.0

3 months ago

3.8.0-beta.11

3 months ago

3.8.1

5 months ago

3.8.0

5 months ago

3.8.0-beta.10

6 months ago

3.8.0-beta.9

6 months ago

3.8.0-beta.8

6 months ago

2.3.0-beta.0

6 months ago