From feac900bf5d10bfcbd916bacd84dab1b4e4fe13a Mon Sep 17 00:00:00 2001 From: bocai Date: Tue, 1 Jan 2019 23:26:42 +0800 Subject: [PATCH 01/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UpdateManager=E3=80=81o?= =?UTF-8?q?nLaunch=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/weapp-api-tests.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index 82a5b8d91d..e13f3766d5 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -347,6 +347,30 @@ wx.getSystemInfo({ } }) +const updateManager = wx.getUpdateManager() + +// updateManager.onCheckForUpdate(function (res) { +// //请求完新版本信息的回调 +// console.log(res.hasUpdate) +// }) + +updateManager.onUpdateReady(function () { + // wx.showModal({ + // title: '更新提示', + // content: '新版本已经准备好,是否重启应用?', + // success(res) { + // if (res.confirm) { + // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + // updateManager.applyUpdate() + // } + // } + // }) +}) + +updateManager.onUpdateFailed(function () { + // 新版本下载失败 +}) + wx.onAccelerometerChange(function(res) { console.log(res.x) console.log(res.y) @@ -673,3 +697,9 @@ wx.requestPayment({ 'fail':function(res){ } }) + +App({ + onLaunch(options){ + console.log(options.query) + } +}) From 184abf8051f2583ccf68e00abb96af82e3356ba0 Mon Sep 17 00:00:00 2001 From: bocai Date: Tue, 1 Jan 2019 23:28:51 +0800 Subject: [PATCH 02/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UpdateManager=E3=80=81o?= =?UTF-8?q?nLaunch=E7=9B=B8=E5=85=B3=E5=A3=B0=E6=98=8E=EF=BC=8C=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E4=BD=BF=E7=94=A8type=20aliases/interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index f22ed51765..c3b85a658a 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -37,12 +37,33 @@ declare namespace wx { [key: string]: any; } + interface referrerInfo { + /** 来源小程序、公众号或 App 的 appId */ + appId: string, + /** 来源小程序传过来的数据,scene=1037或1038时支持 */ + extraData: Object + } + + interface LaunchOptions { + /** 启动小程序的路径 */ + path: string, + /** 启动小程序的场景值 */ + scene: number, + /** 启动小程序的query参数 */ + query: Object, + shareTicket: string, + /** 来源信息。从另一个小程序、公众号或App进入小程序时返回。范泽返回{} */ + referrerInfo: referrerInfo + } + + type LaunchCallback = (options: LaunchOptions) => void; + interface AppOptions { /** * 生命周期函数--监听小程序初始化 * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次) */ - onLaunch?: NoneParamCallback; + onLaunch?: LaunchCallback; /** * 生命周期函数--监听小程序显示 * 当小程序启动,或从后台进入前台显示,会触发 onShow @@ -561,6 +582,34 @@ declare namespace wx { */ function getSystemInfo(options: GetSystemInfoOptions): void; + interface UpdateManager { + /** + * 强制小程序重启并使用新版本。在小程序新版本下载完成后(即收到 onUpdateReady 回调)调用。 + */ + applyUpdate(callback: DataResponseCallback): void; + /** + * 监听向微信后台请求检查更新结果事件。微信在小程序冷启动时自动检查更新,不需由开发者主动触发。 + */ + onCheckForUpdate(): void; + /** + * 监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调 + */ + onUpdateReady(callback: NoneParamCallback): void; + /** + * 监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)后回调 + */ + onUpdateFailed(callback: NoneParamCallback): void; + } + /** + * 获取全局唯一的版本更新管理器,用于管理小程序更新。关于小程序的更新机制,可以查看运行机制文档。 + */ + function getUpdateManager(): UpdateManager; + + /** + * 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。 + */ + function getLaunchOptionsSync(): LaunchCallback; + interface AccelerometerData { /** X 轴 */ x: number; From 0330b0179cf5676f90a3bf9c3be71998541cfc08 Mon Sep 17 00:00:00 2001 From: bocai Date: Wed, 2 Jan 2019 01:40:37 +0800 Subject: [PATCH 03/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BA=A7=E4=BA=8B=E4=BB=B6=E3=80=81=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E3=80=81=E8=B7=AF=E7=94=B1=E3=80=81=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 131 +++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index c3b85a658a..0e06bd8357 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,6 +3,8 @@ // Definitions by: vargeek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import functions from "../react-icons/md/functions"; + declare namespace wx { type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; @@ -44,7 +46,7 @@ declare namespace wx { extraData: Object } - interface LaunchOptions { + interface onLaunchOptions { /** 启动小程序的路径 */ path: string, /** 启动小程序的场景值 */ @@ -56,24 +58,34 @@ declare namespace wx { referrerInfo: referrerInfo } - type LaunchCallback = (options: LaunchOptions) => void; + type onLaunchCallback = (options: onLaunchOptions) => void; + type onShowOptions = onLaunchOptions; interface AppOptions { /** * 生命周期函数--监听小程序初始化 * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次) */ - onLaunch?: LaunchCallback; + onLaunch?: onLaunchCallback; /** * 生命周期函数--监听小程序显示 * 当小程序启动,或从后台进入前台显示,会触发 onShow */ - onShow?: NoneParamCallback; + onShow?: (options: onShowOptions) => void; /** * 生命周期函数--监听小程序隐藏 * 当小程序从前台进入后台,会触发 onHide */ onHide?: NoneParamCallback; + /** 小程序发生脚本错误或 API 调用报错时触发。也可以使用 wx.onError 绑定监听。*/ + onError?: ErrorCallback; + /** + * 小程序要打开的页面不存在时触发 + * 1. 开发者可以在回调中进行页面重定向,但必须在回调中同步处理,异步处理(例如 setTimeout 异步执行)无效。 + * 2. 若开发者没有调用 wx.onPageNotFound 绑定监听,也没有声明 App.onPageNotFound,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。 + * 3. 如果回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再第二次回调。 + */ + onPageNotFound?: NoneParamCallback; [key: string]: any } @@ -608,7 +620,87 @@ declare namespace wx { /** * 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。 */ - function getLaunchOptionsSync(): LaunchCallback; + function getLaunchOptionsSync(): onLaunchCallback; + + // 应用级事件 + /** + * 取消监听小程序要打开的页面不存在事件 + */ + function offPageNotFound(): NoneParamCallback; + /** + * 监听小程序要打开的页面不存在事件。该事件与 App.onPageNotFound 的回调时机一致。 + */ + function onPageNotFound(): NoneParamCallback; + /** + * 取消监听小程序错误事件。 + */ + function offError(): NoneParamCallback; + /** + * 监听小程序错误事件。如脚本错误或 API 调用报错等。该事件与 App.onError 的回调时机与参数一致。 + */ + function onError(): ErrorCallback; + /** + * 取消监听小程序切前台事件 + */ + function offAppShow(): NoneParamCallback; + /** + * 监听小程序切前台事件。该事件与 App.onShow 的回调参数一致。 + * @param callback + */ + function onAppShow(callback: onShowOptions): void; + /** + * 取消监听小程序切后台事件 + */ + function offAppHide(): NoneParamCallback; + /** + * 监听小程序切后台事件。该事件与 App.onHide 的回调时机一致。 + */ + function onAppHide(): NoneParamCallback; + + // 调试 TODO + + // 路由 + interface routerOptions { + + } + /** + * 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。 + */ + function navigateBack(): void; + function switchTab(): void; + function navigateTo(): void; + function reLaunch(): void; + function redirectTo(): void; + + // 界面 + // 交互 + // tapIndex为用户点击的按钮序号,从上到下的顺序,从0开始 + type ActionSheetSuccessCallback = (res: {tapIndex: number}) => void; + + interface ActionSheetOptions { + // 必填,按钮的文字数组,数组长度最大为 6 + itemList: Array; + // 按钮的文字颜色 + itemColor?: string; + success?: ActionSheetSuccessCallback; + fail?: ResponseCallback; + complete?: ResponseCallback; + } + /** + * 显示操作菜单 + */ + function showActionSheet(options: ActionSheetOptions): void; + function hideLoading(): void; + function showLoading(): void; + function hideToast(): void; + function showToast(): void; + function showModal(): void; + + // 导航栏 + function setNavigationBarColor(): void; + function hideNavigationBarLoading(): void; + function showNavigationBarLoading(): void; + function setNavigationBarTitle(): void; interface AccelerometerData { /** X 轴 */ @@ -1182,3 +1274,32 @@ declare var App: AppConstructor; * 我们提供了全局的 getApp() 函数,可以获取到小程序实例。 */ declare function getApp(): App; + +// 定时器 +/** + * 设定一个定时器。在定时到期以后执行注册的回调函数 + * @param callback + * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 + * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 + */ +declare function setTimeout(callback: functions, delay: number, rest: any): number; + +/** + * 取消由 setTimeout 设置的定时器。 + * @param timeoutID 要取消的定时器的ID + */ +declare function clearTimeout(timeoutID: number): number; + +/** + * 设定一个定时器。按照指定的周期(以毫秒计)来执行注册的回调函数 + * @param callback + * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 + * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 + */ +declare function setInterval(callback: functions, delay: number, rest: any): number; + +/** + * 取消由 setInterval 设置的定时器。 + * @param timeoutID 要取消的定时器的ID + */ +declare function clearInterval(timeoutID: number): number; From fda4a8bab76702763a01347d450ff566bebf44d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Wed, 2 Jan 2019 21:45:48 +0800 Subject: [PATCH 04/37] modify --- types/weapp-api/index.d.ts | 67 +++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0e06bd8357..fa328782ca 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -686,15 +686,72 @@ declare namespace wx { fail?: ResponseCallback; complete?: ResponseCallback; } + + interface CommonCallbackOptions { + success?: ResponseCallback; + fail?: ResponseCallback; + complete?: ResponseCallback; + } + + interface LoadingOptions extends CommonCallbackOptions{ + // must,提示的内容 + title: string; + // 默认false。是否显示透明蒙层,防止触摸穿透 + mask: boolean; + } + + type icon = 'success' | 'loading' | 'none'; + interface ToastOptions extends CommonCallbackOptions{ + // 提示的内容 + title: string; + // 图标,默认值'success' + icon?: icon; + // 自定义图标的本地路径,image 的优先级高于 icon + imgage?: string; + // 提示的延迟时间,默认值1500ms + duration?: number; + // 是否显示透明蒙层,防止触摸穿透,默认值false + mask: boolean; + } + + interface ModalOptions extends CommonCallbackOptions{ + // 提示的内容 + title: string; + // 提示的内容 + content: string; + // 是否显示取消按钮,默认值true + showCancel?: boolean; + // 取消按钮的文字,最多 4 个字符,默认值'取消' + cancelText?: string; + // 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值'#000000' + cancelColor?: string; + // 确认按钮的文字,最多 4 个字符 + confirmText?: string; + // 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值'#3cc51f' + confirmColor?: boolean; + } /** * 显示操作菜单 */ function showActionSheet(options: ActionSheetOptions): void; - function hideLoading(): void; - function showLoading(): void; - function hideToast(): void; - function showToast(): void; - function showModal(): void; + /** + * 隐藏 loading 提示框 + * @param options + */ + function hideLoading(options?: CommonCallbackOptions): void; + /** + * 显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框 + * @param options + */ + function showLoading(options: LoadingOptions): void; + function hideToast(options?: CommonCallbackOptions): void; + function showToast(options: ToastOptions): void; + + /** + * 显示模态对话框 + * @param options + */ + function showModal(options: ModalOptions): void; // 导航栏 function setNavigationBarColor(): void; From dcdb40585267e54523243e73a21bb88532006244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 21:12:02 +0800 Subject: [PATCH 05/37] =?UTF-8?q?weapp-api,=E5=A2=9E=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E9=83=A8=E5=88=86=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 51 ++++++++++++++++++++-- types/weapp-api/tsconfig.json | 5 ++- types/weapp-api/weapp-api-tests.ts | 69 +++++++++++++++--------------- 3 files changed, 84 insertions(+), 41 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index fa328782ca..fec6f90f14 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -687,6 +687,9 @@ declare namespace wx { complete?: ResponseCallback; } + /** + * 公共回调函数 + */ interface CommonCallbackOptions { success?: ResponseCallback; fail?: ResponseCallback; @@ -744,20 +747,60 @@ declare namespace wx { * @param options */ function showLoading(options: LoadingOptions): void; + /** + * 隐藏消息提示框 + * @param options + */ function hideToast(options?: CommonCallbackOptions): void; + /** + * 显示消息提示框 + * @param options + */ function showToast(options: ToastOptions): void; - /** * 显示模态对话框 * @param options */ function showModal(options: ModalOptions): void; + + interface NavigationBarColorAnimationOptions { + // 动画变化时间,单位 ms,默认0 + animation?: number; + // 动画变化方式.动画从头到尾的速度是相同的,动画以低速开始,动画以低速结束,动画以低速开始和结束 + timingFunc?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' + } + interface NavigationBarColorOptions extends CommonCallbackOptions{ + // 前景颜色值,包括按钮、标题、状态栏的颜色,仅支持 #ffffff 和 #000000 + frontColor: string; + // 背景颜色值,有效值为十六进制颜色 + backgroundColor: string; + // 动画效果 + animation: NavigationBarColorAnimationOptions; + } + interface NavigationBarTitleOptions extends CommonCallbackOptions{ + // 动态设置当前页面的标题 + title: string; + } // 导航栏 function setNavigationBarColor(): void; - function hideNavigationBarLoading(): void; - function showNavigationBarLoading(): void; - function setNavigationBarTitle(): void; + /** + * 在当前页面隐藏导航条加载动画 + */ + function hideNavigationBarLoading(options?: CommonCallbackOptions): void; + /** + * 在当前页面显示导航条加载动画 + */ + function showNavigationBarLoading(options: CommonCallbackOptions): void; + /** + * 动态设置当前页面的标题 + * @param options + */ + function setNavigationBarTitle(options: NavigationBarTitleOptions): void; + + // 背景 + function setBackgroundTextStyle(): void; + function setBackgroundColor(): void; interface AccelerometerData { /** X 轴 */ diff --git a/types/weapp-api/tsconfig.json b/types/weapp-api/tsconfig.json index ef43ffab75..74812f3d05 100644 --- a/types/weapp-api/tsconfig.json +++ b/types/weapp-api/tsconfig.json @@ -19,6 +19,7 @@ }, "files": [ "index.d.ts", - "weapp-api-tests.ts" + "weapp-api-tests.ts", + "../baidu-app/index.d.ts" ] -} \ No newline at end of file +} diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index e13f3766d5..4363179c80 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -14,7 +14,7 @@ App({ wx.login({ success: function () { wx.getUserInfo({ - success: function (res) { + success: function (res: any) { that.globalData.userInfo = res.userInfo; typeof cb == "function" && cb(that.globalData.userInfo) } @@ -37,7 +37,6 @@ Page({ foo: 'bar' }, onLoad: function (options) { - console.log(options.title); } }) @@ -51,13 +50,13 @@ wx.request({ header: { 'Content-Type': 'application/json' }, - success: function (res) { + success: function (res: any) { console.log(res.data) } }) wx.chooseImage({ - success: function (res) { + success: function (res: any) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'http://example.com/upload', @@ -73,7 +72,7 @@ wx.chooseImage({ wx.downloadFile({ url: 'http://example.com/audio/123', type: 'audio', - success: function (res) { + success: function (res: any) { wx.playVoice({ filePath: res.tempFilePath }) @@ -95,17 +94,17 @@ wx.connectSocket({ wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { console.log('WebSocket连接已打开!') }) wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { console.log('WebSocket连接已打开!') }) -wx.onSocketError(function (res) { +wx.onSocketError(function (res: any) { console.log('WebSocket连接打开失败,请检查!') }) @@ -115,7 +114,7 @@ wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { socketOpen = true for (var i = 0; i < socketMsgQueue.length; i++) { sendSocketMessage(socketMsgQueue[i]) @@ -137,7 +136,7 @@ wx.connectSocket({ url: 'test.php' }) -wx.onSocketMessage(function (res) { +wx.onSocketMessage(function (res: any) { console.log('收到服务器内容:' + res.data) }) @@ -152,7 +151,7 @@ wx.onSocketOpen(function () { wx.closeSocket() }) -wx.onSocketClose(function (res) { +wx.onSocketClose(function (res: any) { console.log('WebSocket 已关闭!') }) @@ -160,7 +159,7 @@ wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 - success: function (res) { + success: function (res: any) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths } @@ -172,10 +171,10 @@ wx.previewImage({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath }, - fail: function (res) { + fail: function (res: any) { //录音失败 } }) @@ -185,7 +184,7 @@ setTimeout(function () { }, 10000) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath, @@ -196,7 +195,7 @@ wx.startRecord({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath @@ -210,7 +209,7 @@ wx.startRecord({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath @@ -223,7 +222,7 @@ wx.startRecord({ }) wx.getBackgroundAudioPlayerState({ - success: function (res) { + success: function (res: any) { var status = res.status var dataUrl = res.dataUrl var currentPosition = res.currentPosition @@ -246,11 +245,11 @@ wx.seekBackgroundAudio({ wx.stopBackgroundAudio() wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.saveFile({ tempFilePath: tempFilePath, - success: function (res) { + success: function (res: any) { var savedFilePath = res.savedFilePath } }) @@ -265,7 +264,7 @@ Page({ sourceType: ['album', 'camera'], maxDuration: 60, camera: ['front', 'back'], - success: function (res) { + success: function (res: any) { that.setData({ src: res.tempFilePath }) @@ -286,7 +285,7 @@ try { wx.getStorage({ key: 'key', - success: function (res) { + success: function (res: any) { console.log(res.data) } }) @@ -309,7 +308,7 @@ try { wx.getLocation({ type: 'wgs84', - success: function (res) { + success: function (res: any) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed @@ -319,7 +318,7 @@ wx.getLocation({ wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 - success: function(res) { + success: function(res: any) { var latitude = res.latitude var longitude = res.longitude wx.openLocation({ @@ -331,13 +330,13 @@ wx.getLocation({ }) wx.getNetworkType({ - success: function(res) { + success: function(res: any) { var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi } }) wx.getSystemInfo({ - success: function(res) { + success: function(res: any) { console.log(res.model) console.log(res.pixelRatio) console.log(res.windowWidth) @@ -349,7 +348,7 @@ wx.getSystemInfo({ const updateManager = wx.getUpdateManager() -// updateManager.onCheckForUpdate(function (res) { +// updateManager.onCheckForUpdate(function (res: any) { // //请求完新版本信息的回调 // console.log(res.hasUpdate) // }) @@ -358,7 +357,7 @@ updateManager.onUpdateReady(function () { // wx.showModal({ // title: '更新提示', // content: '新版本已经准备好,是否重启应用?', - // success(res) { + // success(res: any) { // if (res.confirm) { // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 // updateManager.applyUpdate() @@ -371,13 +370,13 @@ updateManager.onUpdateFailed(function () { // 新版本下载失败 }) -wx.onAccelerometerChange(function(res) { +wx.onAccelerometerChange(function(res: any) { console.log(res.x) console.log(res.y) console.log(res.z) }) -wx.onCompassChange(function (res) { +wx.onCompassChange(function (res: any) { console.log(res.direction) }) @@ -543,7 +542,7 @@ Page({ onReady: function() { var context = wx.createContext() wx.chooseImage({ - success: function(res) { + success: function(res: any) { context.drawImage(res.tempFilePaths[0], 0, 0) wx.drawCanvas({ canvasId: 1, @@ -656,7 +655,7 @@ Page({ App({ onLaunch: function() { wx.login({ - success: function(res) { + success: function(res: any) { if (res.code) { //发起网络请求 wx.request({ @@ -675,7 +674,7 @@ App({ wx.getUserInfo({ - success: function(res) { + success: function(res: any) { var userInfo = res.userInfo var nickName = userInfo.nickName var avatarUrl = userInfo.avatarUrl @@ -692,9 +691,9 @@ wx.requestPayment({ 'package': '', 'signType': 'MD5', 'paySign': '', - 'success':function(res){ + 'success':function(res: any){ }, - 'fail':function(res){ + 'fail':function(res: any){ } }) From db851d18a7cfb5ba5f01852e2399111e372f70e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 22:02:56 +0800 Subject: [PATCH 06/37] weapp-api,export wx --- types/weapp-api/index.d.ts | 2 ++ types/weapp-api/weapp-api-tests.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index fec6f90f14..5eb9c36175 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1403,3 +1403,5 @@ declare function setInterval(callback: functions, delay: number, rest: any): num * @param timeoutID 要取消的定时器的ID */ declare function clearInterval(timeoutID: number): number; + +export default wx diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index 4363179c80..5b2b0616a2 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -1,12 +1,13 @@ +import wx from './index' App({ onLaunch: function () { //调用API从本地缓存中获取数据 - var logs = wx.getStorageSync('logs') as Array || [] + let logs = wx.getStorageSync('logs') as Array || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) }, getUserInfo: function (cb: Function) { - var that = this; + let that = this; if (this.globalData.userInfo) { typeof cb == "function" && cb(this.globalData.userInfo) } else { From 3544462263a63022527c3217398c0b1ffcf4d96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 22:08:31 +0800 Subject: [PATCH 07/37] modify functions type --- types/weapp-api/index.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 5eb9c36175..dcc3cd3e16 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,8 +3,6 @@ // Definitions by: vargeek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import functions from "../react-icons/md/functions"; - declare namespace wx { type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; @@ -1382,7 +1380,7 @@ declare function getApp(): App; * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */ -declare function setTimeout(callback: functions, delay: number, rest: any): number; +declare function setTimeout(callback: any, delay: number, rest: any): number; /** * 取消由 setTimeout 设置的定时器。 @@ -1396,7 +1394,7 @@ declare function clearTimeout(timeoutID: number): number; * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */ -declare function setInterval(callback: functions, delay: number, rest: any): number; +declare function setInterval(callback: any, delay: number, rest: any): number; /** * 取消由 setInterval 设置的定时器。 From e821f3072d516a04c66f6ad35dfa4b8f425c303c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Mon, 7 Jan 2019 15:49:11 +0800 Subject: [PATCH 08/37] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=EF=BC=8C=E8=B7=AF=E7=94=B1=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 327 +++++++++++++++++++++++++++++-------- 1 file changed, 258 insertions(+), 69 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index dcc3cd3e16..0882745c2f 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -4,6 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace wx { + // import startPullDownRefresh = swan.startPullDownRefresh; type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; type ResponseCallback = (res: any) => void; @@ -87,6 +88,8 @@ declare namespace wx { [key: string]: any } + // 网络 + // 发起请求 interface RequestHeader { [key: string]: string; } @@ -109,9 +112,79 @@ declare namespace wx { /** * wx.request发起的是https请求。一个微信小程序,同时只能有5个网络请求连接。 */ - function request(options: RequestOptions): void; + function request(options: RequestOptions): RequestTask; + /** + * 网络请求任务对象 + */ + interface RequestTask { + // 中断请求任务 + abort(): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } + // 下载 + interface OnProgressCallbackOptions { + // 下载进度百分比 + progress: number; + // 已经下载的数据长度,单位 Bytes + totalBytesWritten: number; + // 预期需要下载的数据总长度,单位 Bytes + totalBytesExpectedToWrite: number; + } + /** + * 一个可以监听下载进度变化事件,以及取消下载任务的对象 + */ + interface DownloadTask { + // 中断下载任务 + abort(): void; + // 下载进度变化事件的回调函数 + onProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 取消监听下载进度变化事件 + offProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } + interface DownloadFileOptions { + /** 下载资源的 url */ + url: string; + /** 下载资源的类型,用于客户端识别处理,有效值:image/audio/video */ + type?: string; + /** HTTP 请求 Header */ + header?: RequestHeader; + /** 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'} */ + success?: TempFileResponseCallback; + /** 接口调用失败的回调函数 */ + fail?: ResponseCallback; + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete?: ResponseCallback; + } + /** + * 下载文件资源到本地。客户端直接发起一个 HTTP GET 请求, + * 把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。 + */ + function downloadFile(options: DownloadFileOptions): DownloadTask; + // 上传 + /** + * 一个可以监听上传进度变化事件,以及取消上传任务的对象 + */ + interface UploadTask { + // 中断上传任务 + abort(): void; + // 上传进度变化事件的回调函数 + onProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 取消监听上传进度变化事件 + offProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } interface UploadFileOptions { /** 开发者服务器 url */ url: string; @@ -137,30 +210,9 @@ declare namespace wx { * 客户端发起一个 HTTPS POST 请求, * 其中 Content-Type 为 multipart/form-data 。 */ - function uploadFile(options: UploadFileOptions): void; - - - interface DownloadFileOptions { - /** 下载资源的 url */ - url: string; - /** 下载资源的类型,用于客户端识别处理,有效值:image/audio/video */ - type?: string; - /** HTTP 请求 Header */ - header?: RequestHeader; - /** 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'} */ - success?: TempFileResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 下载文件资源到本地。客户端直接发起一个 HTTP GET 请求, - * 把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。 - */ - function downloadFile(options: DownloadFileOptions): void; - + function uploadFile(options: UploadFileOptions): UploadTask; + // WebSocket interface ConnectSocketOptions { /** 开发者服务器接口地址,必须是 HTTPS 协议,且域名必须是后台配置的合法域名 */ url: string; @@ -440,6 +492,29 @@ declare namespace wx { */ function chooseVideo(options: ChooseVideoOptions): void; + // 数据缓存 + interface StorageInfo { + // 当前 storage 中所有的 key + keys: Array; + // 当前占用的空间大小, 单位 KB + currentSize: number; + // 限制的空间大小,单位 KB + limitSize: number; + } + type StorageInfoCallback = (res: StorageInfoOptions) => void; + interface StorageInfoOptions extends CommonCallbackOptions{ + success?: StorageInfoCallback; + } + /** + * getStorageInfo的同步版本 + */ + function getStorageInfoSync(): StorageInfo; + /** + * 异步获取当前storage的相关信息 + * @param options + */ + function getStorageInfo(options: StorageInfoOptions): void; + interface SetStorageOptions { /** 本地缓存中的指定的 key */ key: string; @@ -498,6 +573,9 @@ declare namespace wx { */ function clearStorageSync(): void; + // 媒体 + // 地图 TODO + interface LocationData { /** 纬度,浮点数,范围为-90~90,负数表示南纬 */ latitude: number; @@ -658,17 +736,36 @@ declare namespace wx { // 调试 TODO // 路由 - interface routerOptions { - + interface routerOptions extends CommonCallbackOptions{ + // 需要跳转的应用内非 tabBar 的页面的路径, 路径后可以带参数。参数与路径之间使用 ? 分隔,参数键与参数值用 = 相连,不同参数用 & 分隔;如 'path?key=value&key2=value2' + url: string; + } + interface NavigateBackOptions extends CommonCallbackOptions { + // 返回的页面数,如果 delta 大于现有页面数,则返回到首页。 + delta: number; } /** * 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。 */ - function navigateBack(): void; - function switchTab(): void; - function navigateTo(): void; - function reLaunch(): void; - function redirectTo(): void; + function navigateBack(options: NavigateBackOptions): void; + /** + * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 + * @param options + */ + function switchTab(options: routerOptions): void; + /** + * 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 wx.navigateBack 可以返回到原页面。 + * @param options + */ + function navigateTo(options: routerOptions): void; + /** + * 关闭所有页面,打开到应用内的某个页面 + */ + function reLaunch(options: routerOptions): void; + /** + * 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 + */ + function redirectTo(options: routerOptions): void; // 界面 // 交互 @@ -689,8 +786,11 @@ declare namespace wx { * 公共回调函数 */ interface CommonCallbackOptions { + // 接口调用成功回调函数 success?: ResponseCallback; + // 接口调用失败回调函数 fail?: ResponseCallback; + // 接口调用结束的回调函数 complete?: ResponseCallback; } @@ -798,7 +898,133 @@ declare namespace wx { // 背景 function setBackgroundTextStyle(): void; + interface BackgroundColorOptions extends CommonCallbackOptions{ + // 窗口的背景色,必须为十六进制颜色值 + backgroundColor?: string; + // 顶部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 + backgroundColorTop?: string; + // 底部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 + backgroundColorBottom?: string; + } function setBackgroundColor(): void; + // Tab Bar + interface TabBarItemOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + // tab 上的按钮文字 + text?: string; + // 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片 + iconPath?: string; + // 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效 + selectedIconPath?: string; + } + /** + * 动态设置 tabBar 某一项的内容 + * @param options + */ + function setTabBarItem(options: TabBarItemOptions): void; + + interface TabBarStyleOptions extends CommonCallbackOptions{ + // tab 上的文字默认颜色,HexColor + color: string; + // tab 上的文字选中时的颜色,HexColor + selectedColor: string; + // tab 的背景色,HexColor + backgroundColor: string; + // tabBar上边框的颜色, 仅支持 black/white + borderStyle: string; + } + /** + * 动态设置tabBar的整体样式 + */ + function setTabBarStyle(options: TabBarItemOptions): void; + + interface TabBarAnimationOptions extends CommonCallbackOptions{ + // 是否需要动画效果 + animation: boolean; + } + /** + * 隐藏tabBar + */ + function hideTabBar(options: TabBarAnimationOptions): void; + /** + * 显示tabBar + */ + function showTabBar(options: TabBarAnimationOptions): void; + + interface TabBarRedDotOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + } + /** + * 隐藏 tabBar 某一项的右上角的红点 + * @param options + */ + function hideTabBarRedDot(options: TabBarBadgeOptions): void; + /** + * 显示 tabBar 某一项的右上角的红点 + * @param options + */ + function showTabBarRedDot(options: TabBarRedDotOptions): void; + + interface TabBarBadgeOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + // 显示的文本,超过 4 个字符则显示成 ... + text: string; + } + /** + * 移除 tabBar 某一项右上角的文本 + * @param options + */ + function removeTabBarBadge(options: TabBarRedDotOptions): void; + /** + * 为 tabBar 某一项的右上角添加文本 + * @param options + */ + function setTabBarBadge(options: TabBarBadgeOptions): void; + + interface FontDescOptions { + // 字体样式,可选值为 normal / italic / oblique + style?: string; + // 字体粗细,可选值为 normal / bold / 100 / 200../ 900 + weight?: string; + // 设置小型大写字母的字体显示文本,可选值为 normal / small-caps / inherit + variant?: string; + } + // 字体 + interface FontFaceOptions extends CommonCallbackOptions{ + // 定义的字体名称 + family: string; + // 字体资源的地址。建议格式为 TTF 和 WOFF,WOFF2 在低版本的iOS上会不兼容。 + source: string; + // 可选的字体描述符 + desc?: FontDescOptions; + } + function loadFontFace(options: FontFaceOptions): void; + + // 下拉刷新 + /** + * 停止当前页面下拉刷新。 + */ + function stopPullDownRefresh(options?: CommonCallbackOptions): void; + + /** + * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。 + */ + function startPullDownRefresh(options?: CommonCallbackOptions): void; + + // 滚动 + interface PageScrollToOptions extends CommonCallbackOptions{ + // 滚动到页面的目标位置,单位 px + scrollTop: number; + // 滚动动画的时长,单位 ms。默认300 + duration: number; + } + /** + * 将页面滚动到 + */ + function pageScrollTo(): void; interface AccelerometerData { /** X 轴 */ @@ -845,46 +1071,9 @@ declare namespace wx { */ function hideNavigationBarLoading(): void; - interface NavigateToOptions { - /** 需要跳转的应用内页面的路径 */ - url: string; - /** 成功获取系统信息的回调 */ - success?: ResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。 - * - * 注意:为了不让用户在使用小程序时造成困扰, - * 我们规定页面路径只能是五层,请尽量避免多层级的交互方式。 - */ - function navigateTo(options: NavigateToOptions): void; - - interface RedirectToOptions { - /** 需要跳转的应用内页面的路径 */ - url: string; - /** 成功获取系统信息的回调 */ - success?: ResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 关闭当前页面,跳转到应用内的某个页面。 - */ - function redirectTo(options: RedirectToOptions): void; - - /** - * 关闭当前页面,回退前一页面。 - */ - function navigateBack(): void; - type TimingFunction = 'linear' | 'ease' | 'ease-in' | 'ease-in-out' | 'ease-out' | 'step-start' | 'step-end'; + // 动画 interface CreateAnimationOptions { /** 动画持续时间,单位ms,默认值 400 */ duration?: number; From bb53a7d08d2577f62b1b6b2097d04eaacd0dda08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:08:35 +0800 Subject: [PATCH 09/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=9C=B0=E5=9B=BE=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 160 ++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0882745c2f..6fdf7df480 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -574,7 +574,62 @@ declare namespace wx { function clearStorageSync(): void; // 媒体 - // 地图 TODO + // 地图 + interface LocationBaseOptions { + // 纬度,浮点数,范围为-90~90,负数表示南纬 + latitude: number; + // 经度,浮点数,范围为-180~180,负数表示西经 + longitude: number; + } + interface GetCenterLocationSuccCbOptions extends CommonCallbackOptions{ + success(res: LocationBaseOptions): void; + } + interface translateMarkerOptions extends CommonCallbackOptions{ + // 指定 marker + markerId: number; + // 指定 marker 移动到的目标点 + destination: LocationBaseOptions; + // 移动过程中是否自动旋转 marker + autoRotate: boolean; + // marker 的旋转角度 + rotate: number; + // 动画持续时长,平移与旋转分别计算 + duration?: number; + // 动画结束回调函数 + animationEnd?(): void; + } + interface zoomPointsOptions extends CommonCallbackOptions { + // 要显示在可视区域内的坐标点列表 + points: Array; + // 坐标点形成的矩形边缘到地图边缘的距离,单位像素。格式为[上,右,下,左],安卓上只能识别数组第一项,上下左右的padding一致。开发者工具暂不支持padding参数。 + padding?: Array; + } + interface GetReginSuccessCallbackOptions { + // 西南角经纬度 + southwest: number, + // 东北角经纬度 + northeast: number; + } + interface GetReginOptions extends CommonCallbackOptions{ + success?(callback: (res: GetReginSuccessCallbackOptions) => void): void; + } + interface GetScaleOptions extends CommonCallbackOptions{ + success?(callback: (res: {scale: number}) => void): void; + } + interface MapContext { + // 获取当前地图中心的经纬度。返回的是 gcj02 坐标系,可以用于 wx.openLocation() + getCenterLocation(options: GetCenterLocationSuccCbOptions): void; + // 将地图中心移动到当前定位点。需要配合map组件的show-location使用 + moveToLocation(): void; + // 平移marker,带动画 + translateMarker(options: translateMarkerOptions): void; + // 缩放视野展示所有经纬度 + includePoints(options: zoomPointsOptions): void; + // 获取当前地图的视野范围 + getRegion(options: GetReginOptions): void; + // 获取当前地图的缩放级别 + getScale(options: GetScaleOptions): void; + } interface LocationData { /** 纬度,浮点数,范围为-90~90,负数表示南纬 */ @@ -1440,6 +1495,8 @@ declare namespace wx { */ function hideKeyboard(): void; + // 开放接口 + // 登录 interface LoginResponse { /** 调用结果 */ errMsg: string; @@ -1458,6 +1515,10 @@ declare namespace wx { complete?: ResponseCallback; } + /** + * 检查登录态是否过期。 + */ + function checkSession(options: CommonCallbackOptions): void; /** * 调用接口获取登录凭证(code)进而换取用户登录态信息, * 包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key)。 @@ -1465,6 +1526,51 @@ declare namespace wx { */ function login(option: LoginOptions): void; + type envVersion = 'develop' | 'trial' | 'release'; + interface NavigateToMiniProgramOptions extends CommonCallbackOptions { + // 要打开的小程序 appId + appId: string; + // 打开的页面路径,如果为空则打开首页 + path?: string; + // 需要传递给目标小程序的数据,目标小程序可在 App.onLaunch,App.onShow 中获取到这份数据。 + extraData?: object; + // 要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版。 + envVersion?: envVersion; + } + /** + * 打开另一个小程序 + */ + function navigateToMiniProgram(options: NavigateToMiniProgramOptions): void; + interface NavigateBackMiniProgramOptions extends CommonCallbackOptions { + // 需要返回给上一个小程序的数据,上一个小程序可在 App.onShow 中获取到这份数据。 + extraData: object; + } + /** + * 返回到上一个小程序。只有在当前小程序是被其他小程序打开时可以调用成功 + */ + function navigateBackMiniProgram(options: NavigateBackMiniProgramOptions): void; + + // 帐号信息 + interface AccountInfo { + // 小程序帐号信息 + miniProgram: { + // 小程序appId + appId: string; + }; + // 插件帐号信息(仅在插件中调用时包含这一项) + Plugin: { + // 插件appId + appId: string; + // 插件版本号 + vetsion: string + }; + } + /** + * 获取当前账号信息 + */ + function getAccountInfoSync(): AccountInfo; + + // 帐号信息 interface UserInfo { nickName: string; avatarUrl: string; @@ -1515,11 +1621,63 @@ declare namespace wx { /** 接口调用结束的回调函数(调用成功、失败都会执行) */ complete?: ResponseCallback; } + // 支付 /** * 发起微信支付。 */ function requestPayment(options: RequestPaymentOptions): void; + + // 授权 + /** + * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html + * 用户信息 wx.getUserInfo、 + * 地理位置 wx.getLocation,wx.chooseLocation、 + * 通讯地址 wx.chooseAddress、 + * 发票抬头 wx.chooseInvoiceTitle、 + * 获取发票 wx.chooseInvoice、 + * 微信运动步数 wx.getWeRunData、 + * 录音功能 wx.startRecord、 + * 保存到相册 wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum、 + * 摄像头 组件 + */ + type Scope = 'userInfo' | 'userLocation' | 'address' | 'invoiceTitle' | 'invoice' | 'werun' | 'record' | 'writePhotosAlbum' | 'camera'; + interface AuthorizeOptions extends CommonCallbackOptions { + // 需要获取权限的 scope,详见 scope 列表 + scope: Scope; + } + /** + * 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。 + */ + function authorize(options: AuthorizeOptions): void; + + // 设置 + interface SettingOptions extends CommonCallbackOptions{ + success?(res: AuthSetting): void; + } + /** + * 调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。 + */ + function openSetting(options: SettingOptions): void; + /** + * 获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。 + */ + function getSetting(options: SettingOptions): void; + /** + * 用户授权结果,参考 type Scope + */ + interface AuthSetting { + 'scope.userInfo': boolean; + 'scope.userLocation': boolean; + 'scope.address': boolean; + 'scope.invoiceTitle': boolean; + 'scope.invoice': boolean; + 'scope.werun': boolean; + 'scope.record': boolean; + 'scope.writePhotosAlbum': boolean; + 'scope.camera': boolean; + } } +// end of wx namespace interface Page { From df704ca70e81f456349b25ebfa36e37284e50a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:16:37 +0800 Subject: [PATCH 10/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0author=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 6fdf7df480..0cbaf8b97b 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for weapp // Project: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html -// Definitions by: vargeek +// Definitions by: vargeek & pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace wx { From af503c0c11e282af711655dee39f315f4a857df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:59:03 +0800 Subject: [PATCH 11/37] add author and TypeScript version --- types/weapp-api/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0cbaf8b97b..4350eb1d25 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1,7 +1,9 @@ // Type definitions for weapp // Project: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html -// Definitions by: vargeek & pbestz +// Definitions by: vargeek +// pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2.1 declare namespace wx { // import startPullDownRefresh = swan.startPullDownRefresh; From 397470e63d5b6346fb22aeece72ee307ae017d1c Mon Sep 17 00:00:00 2001 From: bocai Date: Tue, 1 Jan 2019 23:26:42 +0800 Subject: [PATCH 12/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UpdateManager=E3=80=81o?= =?UTF-8?q?nLaunch=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/weapp-api-tests.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index 82a5b8d91d..e13f3766d5 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -347,6 +347,30 @@ wx.getSystemInfo({ } }) +const updateManager = wx.getUpdateManager() + +// updateManager.onCheckForUpdate(function (res) { +// //请求完新版本信息的回调 +// console.log(res.hasUpdate) +// }) + +updateManager.onUpdateReady(function () { + // wx.showModal({ + // title: '更新提示', + // content: '新版本已经准备好,是否重启应用?', + // success(res) { + // if (res.confirm) { + // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + // updateManager.applyUpdate() + // } + // } + // }) +}) + +updateManager.onUpdateFailed(function () { + // 新版本下载失败 +}) + wx.onAccelerometerChange(function(res) { console.log(res.x) console.log(res.y) @@ -673,3 +697,9 @@ wx.requestPayment({ 'fail':function(res){ } }) + +App({ + onLaunch(options){ + console.log(options.query) + } +}) From 71219ace4fdccd537643ad440e709ce2feeddbb1 Mon Sep 17 00:00:00 2001 From: bocai Date: Tue, 1 Jan 2019 23:28:51 +0800 Subject: [PATCH 13/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UpdateManager=E3=80=81o?= =?UTF-8?q?nLaunch=E7=9B=B8=E5=85=B3=E5=A3=B0=E6=98=8E=EF=BC=8C=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E4=BD=BF=E7=94=A8type=20aliases/interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index f22ed51765..c3b85a658a 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -37,12 +37,33 @@ declare namespace wx { [key: string]: any; } + interface referrerInfo { + /** 来源小程序、公众号或 App 的 appId */ + appId: string, + /** 来源小程序传过来的数据,scene=1037或1038时支持 */ + extraData: Object + } + + interface LaunchOptions { + /** 启动小程序的路径 */ + path: string, + /** 启动小程序的场景值 */ + scene: number, + /** 启动小程序的query参数 */ + query: Object, + shareTicket: string, + /** 来源信息。从另一个小程序、公众号或App进入小程序时返回。范泽返回{} */ + referrerInfo: referrerInfo + } + + type LaunchCallback = (options: LaunchOptions) => void; + interface AppOptions { /** * 生命周期函数--监听小程序初始化 * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次) */ - onLaunch?: NoneParamCallback; + onLaunch?: LaunchCallback; /** * 生命周期函数--监听小程序显示 * 当小程序启动,或从后台进入前台显示,会触发 onShow @@ -561,6 +582,34 @@ declare namespace wx { */ function getSystemInfo(options: GetSystemInfoOptions): void; + interface UpdateManager { + /** + * 强制小程序重启并使用新版本。在小程序新版本下载完成后(即收到 onUpdateReady 回调)调用。 + */ + applyUpdate(callback: DataResponseCallback): void; + /** + * 监听向微信后台请求检查更新结果事件。微信在小程序冷启动时自动检查更新,不需由开发者主动触发。 + */ + onCheckForUpdate(): void; + /** + * 监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调 + */ + onUpdateReady(callback: NoneParamCallback): void; + /** + * 监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)后回调 + */ + onUpdateFailed(callback: NoneParamCallback): void; + } + /** + * 获取全局唯一的版本更新管理器,用于管理小程序更新。关于小程序的更新机制,可以查看运行机制文档。 + */ + function getUpdateManager(): UpdateManager; + + /** + * 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。 + */ + function getLaunchOptionsSync(): LaunchCallback; + interface AccelerometerData { /** X 轴 */ x: number; From 4c2a32422d3cf0e01d4800c9dfd30749d88c7de3 Mon Sep 17 00:00:00 2001 From: bocai Date: Wed, 2 Jan 2019 01:40:37 +0800 Subject: [PATCH 14/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BA=A7=E4=BA=8B=E4=BB=B6=E3=80=81=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E3=80=81=E8=B7=AF=E7=94=B1=E3=80=81=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 131 +++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index c3b85a658a..0e06bd8357 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,6 +3,8 @@ // Definitions by: vargeek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import functions from "../react-icons/md/functions"; + declare namespace wx { type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; @@ -44,7 +46,7 @@ declare namespace wx { extraData: Object } - interface LaunchOptions { + interface onLaunchOptions { /** 启动小程序的路径 */ path: string, /** 启动小程序的场景值 */ @@ -56,24 +58,34 @@ declare namespace wx { referrerInfo: referrerInfo } - type LaunchCallback = (options: LaunchOptions) => void; + type onLaunchCallback = (options: onLaunchOptions) => void; + type onShowOptions = onLaunchOptions; interface AppOptions { /** * 生命周期函数--监听小程序初始化 * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次) */ - onLaunch?: LaunchCallback; + onLaunch?: onLaunchCallback; /** * 生命周期函数--监听小程序显示 * 当小程序启动,或从后台进入前台显示,会触发 onShow */ - onShow?: NoneParamCallback; + onShow?: (options: onShowOptions) => void; /** * 生命周期函数--监听小程序隐藏 * 当小程序从前台进入后台,会触发 onHide */ onHide?: NoneParamCallback; + /** 小程序发生脚本错误或 API 调用报错时触发。也可以使用 wx.onError 绑定监听。*/ + onError?: ErrorCallback; + /** + * 小程序要打开的页面不存在时触发 + * 1. 开发者可以在回调中进行页面重定向,但必须在回调中同步处理,异步处理(例如 setTimeout 异步执行)无效。 + * 2. 若开发者没有调用 wx.onPageNotFound 绑定监听,也没有声明 App.onPageNotFound,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。 + * 3. 如果回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再第二次回调。 + */ + onPageNotFound?: NoneParamCallback; [key: string]: any } @@ -608,7 +620,87 @@ declare namespace wx { /** * 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。 */ - function getLaunchOptionsSync(): LaunchCallback; + function getLaunchOptionsSync(): onLaunchCallback; + + // 应用级事件 + /** + * 取消监听小程序要打开的页面不存在事件 + */ + function offPageNotFound(): NoneParamCallback; + /** + * 监听小程序要打开的页面不存在事件。该事件与 App.onPageNotFound 的回调时机一致。 + */ + function onPageNotFound(): NoneParamCallback; + /** + * 取消监听小程序错误事件。 + */ + function offError(): NoneParamCallback; + /** + * 监听小程序错误事件。如脚本错误或 API 调用报错等。该事件与 App.onError 的回调时机与参数一致。 + */ + function onError(): ErrorCallback; + /** + * 取消监听小程序切前台事件 + */ + function offAppShow(): NoneParamCallback; + /** + * 监听小程序切前台事件。该事件与 App.onShow 的回调参数一致。 + * @param callback + */ + function onAppShow(callback: onShowOptions): void; + /** + * 取消监听小程序切后台事件 + */ + function offAppHide(): NoneParamCallback; + /** + * 监听小程序切后台事件。该事件与 App.onHide 的回调时机一致。 + */ + function onAppHide(): NoneParamCallback; + + // 调试 TODO + + // 路由 + interface routerOptions { + + } + /** + * 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。 + */ + function navigateBack(): void; + function switchTab(): void; + function navigateTo(): void; + function reLaunch(): void; + function redirectTo(): void; + + // 界面 + // 交互 + // tapIndex为用户点击的按钮序号,从上到下的顺序,从0开始 + type ActionSheetSuccessCallback = (res: {tapIndex: number}) => void; + + interface ActionSheetOptions { + // 必填,按钮的文字数组,数组长度最大为 6 + itemList: Array; + // 按钮的文字颜色 + itemColor?: string; + success?: ActionSheetSuccessCallback; + fail?: ResponseCallback; + complete?: ResponseCallback; + } + /** + * 显示操作菜单 + */ + function showActionSheet(options: ActionSheetOptions): void; + function hideLoading(): void; + function showLoading(): void; + function hideToast(): void; + function showToast(): void; + function showModal(): void; + + // 导航栏 + function setNavigationBarColor(): void; + function hideNavigationBarLoading(): void; + function showNavigationBarLoading(): void; + function setNavigationBarTitle(): void; interface AccelerometerData { /** X 轴 */ @@ -1182,3 +1274,32 @@ declare var App: AppConstructor; * 我们提供了全局的 getApp() 函数,可以获取到小程序实例。 */ declare function getApp(): App; + +// 定时器 +/** + * 设定一个定时器。在定时到期以后执行注册的回调函数 + * @param callback + * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 + * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 + */ +declare function setTimeout(callback: functions, delay: number, rest: any): number; + +/** + * 取消由 setTimeout 设置的定时器。 + * @param timeoutID 要取消的定时器的ID + */ +declare function clearTimeout(timeoutID: number): number; + +/** + * 设定一个定时器。按照指定的周期(以毫秒计)来执行注册的回调函数 + * @param callback + * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 + * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 + */ +declare function setInterval(callback: functions, delay: number, rest: any): number; + +/** + * 取消由 setInterval 设置的定时器。 + * @param timeoutID 要取消的定时器的ID + */ +declare function clearInterval(timeoutID: number): number; From 0aadfcc335eb66021214ce86619b574c78b9fc2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Wed, 2 Jan 2019 21:45:48 +0800 Subject: [PATCH 15/37] modify --- types/weapp-api/index.d.ts | 67 +++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0e06bd8357..fa328782ca 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -686,15 +686,72 @@ declare namespace wx { fail?: ResponseCallback; complete?: ResponseCallback; } + + interface CommonCallbackOptions { + success?: ResponseCallback; + fail?: ResponseCallback; + complete?: ResponseCallback; + } + + interface LoadingOptions extends CommonCallbackOptions{ + // must,提示的内容 + title: string; + // 默认false。是否显示透明蒙层,防止触摸穿透 + mask: boolean; + } + + type icon = 'success' | 'loading' | 'none'; + interface ToastOptions extends CommonCallbackOptions{ + // 提示的内容 + title: string; + // 图标,默认值'success' + icon?: icon; + // 自定义图标的本地路径,image 的优先级高于 icon + imgage?: string; + // 提示的延迟时间,默认值1500ms + duration?: number; + // 是否显示透明蒙层,防止触摸穿透,默认值false + mask: boolean; + } + + interface ModalOptions extends CommonCallbackOptions{ + // 提示的内容 + title: string; + // 提示的内容 + content: string; + // 是否显示取消按钮,默认值true + showCancel?: boolean; + // 取消按钮的文字,最多 4 个字符,默认值'取消' + cancelText?: string; + // 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值'#000000' + cancelColor?: string; + // 确认按钮的文字,最多 4 个字符 + confirmText?: string; + // 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值'#3cc51f' + confirmColor?: boolean; + } /** * 显示操作菜单 */ function showActionSheet(options: ActionSheetOptions): void; - function hideLoading(): void; - function showLoading(): void; - function hideToast(): void; - function showToast(): void; - function showModal(): void; + /** + * 隐藏 loading 提示框 + * @param options + */ + function hideLoading(options?: CommonCallbackOptions): void; + /** + * 显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框 + * @param options + */ + function showLoading(options: LoadingOptions): void; + function hideToast(options?: CommonCallbackOptions): void; + function showToast(options: ToastOptions): void; + + /** + * 显示模态对话框 + * @param options + */ + function showModal(options: ModalOptions): void; // 导航栏 function setNavigationBarColor(): void; From 9989c26e9226b18d4b8f94f1f16d559dba310dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 21:12:02 +0800 Subject: [PATCH 16/37] =?UTF-8?q?weapp-api,=E5=A2=9E=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E9=83=A8=E5=88=86=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 51 ++++++++++++++++++++-- types/weapp-api/tsconfig.json | 5 ++- types/weapp-api/weapp-api-tests.ts | 69 +++++++++++++++--------------- 3 files changed, 84 insertions(+), 41 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index fa328782ca..fec6f90f14 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -687,6 +687,9 @@ declare namespace wx { complete?: ResponseCallback; } + /** + * 公共回调函数 + */ interface CommonCallbackOptions { success?: ResponseCallback; fail?: ResponseCallback; @@ -744,20 +747,60 @@ declare namespace wx { * @param options */ function showLoading(options: LoadingOptions): void; + /** + * 隐藏消息提示框 + * @param options + */ function hideToast(options?: CommonCallbackOptions): void; + /** + * 显示消息提示框 + * @param options + */ function showToast(options: ToastOptions): void; - /** * 显示模态对话框 * @param options */ function showModal(options: ModalOptions): void; + + interface NavigationBarColorAnimationOptions { + // 动画变化时间,单位 ms,默认0 + animation?: number; + // 动画变化方式.动画从头到尾的速度是相同的,动画以低速开始,动画以低速结束,动画以低速开始和结束 + timingFunc?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' + } + interface NavigationBarColorOptions extends CommonCallbackOptions{ + // 前景颜色值,包括按钮、标题、状态栏的颜色,仅支持 #ffffff 和 #000000 + frontColor: string; + // 背景颜色值,有效值为十六进制颜色 + backgroundColor: string; + // 动画效果 + animation: NavigationBarColorAnimationOptions; + } + interface NavigationBarTitleOptions extends CommonCallbackOptions{ + // 动态设置当前页面的标题 + title: string; + } // 导航栏 function setNavigationBarColor(): void; - function hideNavigationBarLoading(): void; - function showNavigationBarLoading(): void; - function setNavigationBarTitle(): void; + /** + * 在当前页面隐藏导航条加载动画 + */ + function hideNavigationBarLoading(options?: CommonCallbackOptions): void; + /** + * 在当前页面显示导航条加载动画 + */ + function showNavigationBarLoading(options: CommonCallbackOptions): void; + /** + * 动态设置当前页面的标题 + * @param options + */ + function setNavigationBarTitle(options: NavigationBarTitleOptions): void; + + // 背景 + function setBackgroundTextStyle(): void; + function setBackgroundColor(): void; interface AccelerometerData { /** X 轴 */ diff --git a/types/weapp-api/tsconfig.json b/types/weapp-api/tsconfig.json index ef43ffab75..74812f3d05 100644 --- a/types/weapp-api/tsconfig.json +++ b/types/weapp-api/tsconfig.json @@ -19,6 +19,7 @@ }, "files": [ "index.d.ts", - "weapp-api-tests.ts" + "weapp-api-tests.ts", + "../baidu-app/index.d.ts" ] -} \ No newline at end of file +} diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index e13f3766d5..4363179c80 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -14,7 +14,7 @@ App({ wx.login({ success: function () { wx.getUserInfo({ - success: function (res) { + success: function (res: any) { that.globalData.userInfo = res.userInfo; typeof cb == "function" && cb(that.globalData.userInfo) } @@ -37,7 +37,6 @@ Page({ foo: 'bar' }, onLoad: function (options) { - console.log(options.title); } }) @@ -51,13 +50,13 @@ wx.request({ header: { 'Content-Type': 'application/json' }, - success: function (res) { + success: function (res: any) { console.log(res.data) } }) wx.chooseImage({ - success: function (res) { + success: function (res: any) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'http://example.com/upload', @@ -73,7 +72,7 @@ wx.chooseImage({ wx.downloadFile({ url: 'http://example.com/audio/123', type: 'audio', - success: function (res) { + success: function (res: any) { wx.playVoice({ filePath: res.tempFilePath }) @@ -95,17 +94,17 @@ wx.connectSocket({ wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { console.log('WebSocket连接已打开!') }) wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { console.log('WebSocket连接已打开!') }) -wx.onSocketError(function (res) { +wx.onSocketError(function (res: any) { console.log('WebSocket连接打开失败,请检查!') }) @@ -115,7 +114,7 @@ wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { socketOpen = true for (var i = 0; i < socketMsgQueue.length; i++) { sendSocketMessage(socketMsgQueue[i]) @@ -137,7 +136,7 @@ wx.connectSocket({ url: 'test.php' }) -wx.onSocketMessage(function (res) { +wx.onSocketMessage(function (res: any) { console.log('收到服务器内容:' + res.data) }) @@ -152,7 +151,7 @@ wx.onSocketOpen(function () { wx.closeSocket() }) -wx.onSocketClose(function (res) { +wx.onSocketClose(function (res: any) { console.log('WebSocket 已关闭!') }) @@ -160,7 +159,7 @@ wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 - success: function (res) { + success: function (res: any) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths } @@ -172,10 +171,10 @@ wx.previewImage({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath }, - fail: function (res) { + fail: function (res: any) { //录音失败 } }) @@ -185,7 +184,7 @@ setTimeout(function () { }, 10000) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath, @@ -196,7 +195,7 @@ wx.startRecord({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath @@ -210,7 +209,7 @@ wx.startRecord({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath @@ -223,7 +222,7 @@ wx.startRecord({ }) wx.getBackgroundAudioPlayerState({ - success: function (res) { + success: function (res: any) { var status = res.status var dataUrl = res.dataUrl var currentPosition = res.currentPosition @@ -246,11 +245,11 @@ wx.seekBackgroundAudio({ wx.stopBackgroundAudio() wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.saveFile({ tempFilePath: tempFilePath, - success: function (res) { + success: function (res: any) { var savedFilePath = res.savedFilePath } }) @@ -265,7 +264,7 @@ Page({ sourceType: ['album', 'camera'], maxDuration: 60, camera: ['front', 'back'], - success: function (res) { + success: function (res: any) { that.setData({ src: res.tempFilePath }) @@ -286,7 +285,7 @@ try { wx.getStorage({ key: 'key', - success: function (res) { + success: function (res: any) { console.log(res.data) } }) @@ -309,7 +308,7 @@ try { wx.getLocation({ type: 'wgs84', - success: function (res) { + success: function (res: any) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed @@ -319,7 +318,7 @@ wx.getLocation({ wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 - success: function(res) { + success: function(res: any) { var latitude = res.latitude var longitude = res.longitude wx.openLocation({ @@ -331,13 +330,13 @@ wx.getLocation({ }) wx.getNetworkType({ - success: function(res) { + success: function(res: any) { var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi } }) wx.getSystemInfo({ - success: function(res) { + success: function(res: any) { console.log(res.model) console.log(res.pixelRatio) console.log(res.windowWidth) @@ -349,7 +348,7 @@ wx.getSystemInfo({ const updateManager = wx.getUpdateManager() -// updateManager.onCheckForUpdate(function (res) { +// updateManager.onCheckForUpdate(function (res: any) { // //请求完新版本信息的回调 // console.log(res.hasUpdate) // }) @@ -358,7 +357,7 @@ updateManager.onUpdateReady(function () { // wx.showModal({ // title: '更新提示', // content: '新版本已经准备好,是否重启应用?', - // success(res) { + // success(res: any) { // if (res.confirm) { // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 // updateManager.applyUpdate() @@ -371,13 +370,13 @@ updateManager.onUpdateFailed(function () { // 新版本下载失败 }) -wx.onAccelerometerChange(function(res) { +wx.onAccelerometerChange(function(res: any) { console.log(res.x) console.log(res.y) console.log(res.z) }) -wx.onCompassChange(function (res) { +wx.onCompassChange(function (res: any) { console.log(res.direction) }) @@ -543,7 +542,7 @@ Page({ onReady: function() { var context = wx.createContext() wx.chooseImage({ - success: function(res) { + success: function(res: any) { context.drawImage(res.tempFilePaths[0], 0, 0) wx.drawCanvas({ canvasId: 1, @@ -656,7 +655,7 @@ Page({ App({ onLaunch: function() { wx.login({ - success: function(res) { + success: function(res: any) { if (res.code) { //发起网络请求 wx.request({ @@ -675,7 +674,7 @@ App({ wx.getUserInfo({ - success: function(res) { + success: function(res: any) { var userInfo = res.userInfo var nickName = userInfo.nickName var avatarUrl = userInfo.avatarUrl @@ -692,9 +691,9 @@ wx.requestPayment({ 'package': '', 'signType': 'MD5', 'paySign': '', - 'success':function(res){ + 'success':function(res: any){ }, - 'fail':function(res){ + 'fail':function(res: any){ } }) From 537fd9a06d5bf3fbc1c73722585e7707181bb20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 22:02:56 +0800 Subject: [PATCH 17/37] weapp-api,export wx --- types/weapp-api/index.d.ts | 2 ++ types/weapp-api/weapp-api-tests.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index fec6f90f14..5eb9c36175 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1403,3 +1403,5 @@ declare function setInterval(callback: functions, delay: number, rest: any): num * @param timeoutID 要取消的定时器的ID */ declare function clearInterval(timeoutID: number): number; + +export default wx diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index 4363179c80..5b2b0616a2 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -1,12 +1,13 @@ +import wx from './index' App({ onLaunch: function () { //调用API从本地缓存中获取数据 - var logs = wx.getStorageSync('logs') as Array || [] + let logs = wx.getStorageSync('logs') as Array || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) }, getUserInfo: function (cb: Function) { - var that = this; + let that = this; if (this.globalData.userInfo) { typeof cb == "function" && cb(this.globalData.userInfo) } else { From c2d2111a3a07444d3e6c0e2e4f9e20b5621ea41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 22:08:31 +0800 Subject: [PATCH 18/37] modify functions type --- types/weapp-api/index.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 5eb9c36175..dcc3cd3e16 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,8 +3,6 @@ // Definitions by: vargeek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import functions from "../react-icons/md/functions"; - declare namespace wx { type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; @@ -1382,7 +1380,7 @@ declare function getApp(): App; * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */ -declare function setTimeout(callback: functions, delay: number, rest: any): number; +declare function setTimeout(callback: any, delay: number, rest: any): number; /** * 取消由 setTimeout 设置的定时器。 @@ -1396,7 +1394,7 @@ declare function clearTimeout(timeoutID: number): number; * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */ -declare function setInterval(callback: functions, delay: number, rest: any): number; +declare function setInterval(callback: any, delay: number, rest: any): number; /** * 取消由 setInterval 设置的定时器。 From 53b61db0513a8570fd15794ef80d071de8d48c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Mon, 7 Jan 2019 15:49:11 +0800 Subject: [PATCH 19/37] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=EF=BC=8C=E8=B7=AF=E7=94=B1=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 327 +++++++++++++++++++++++++++++-------- 1 file changed, 258 insertions(+), 69 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index dcc3cd3e16..0882745c2f 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -4,6 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace wx { + // import startPullDownRefresh = swan.startPullDownRefresh; type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; type ResponseCallback = (res: any) => void; @@ -87,6 +88,8 @@ declare namespace wx { [key: string]: any } + // 网络 + // 发起请求 interface RequestHeader { [key: string]: string; } @@ -109,9 +112,79 @@ declare namespace wx { /** * wx.request发起的是https请求。一个微信小程序,同时只能有5个网络请求连接。 */ - function request(options: RequestOptions): void; + function request(options: RequestOptions): RequestTask; + /** + * 网络请求任务对象 + */ + interface RequestTask { + // 中断请求任务 + abort(): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } + // 下载 + interface OnProgressCallbackOptions { + // 下载进度百分比 + progress: number; + // 已经下载的数据长度,单位 Bytes + totalBytesWritten: number; + // 预期需要下载的数据总长度,单位 Bytes + totalBytesExpectedToWrite: number; + } + /** + * 一个可以监听下载进度变化事件,以及取消下载任务的对象 + */ + interface DownloadTask { + // 中断下载任务 + abort(): void; + // 下载进度变化事件的回调函数 + onProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 取消监听下载进度变化事件 + offProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } + interface DownloadFileOptions { + /** 下载资源的 url */ + url: string; + /** 下载资源的类型,用于客户端识别处理,有效值:image/audio/video */ + type?: string; + /** HTTP 请求 Header */ + header?: RequestHeader; + /** 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'} */ + success?: TempFileResponseCallback; + /** 接口调用失败的回调函数 */ + fail?: ResponseCallback; + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete?: ResponseCallback; + } + /** + * 下载文件资源到本地。客户端直接发起一个 HTTP GET 请求, + * 把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。 + */ + function downloadFile(options: DownloadFileOptions): DownloadTask; + // 上传 + /** + * 一个可以监听上传进度变化事件,以及取消上传任务的对象 + */ + interface UploadTask { + // 中断上传任务 + abort(): void; + // 上传进度变化事件的回调函数 + onProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 取消监听上传进度变化事件 + offProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } interface UploadFileOptions { /** 开发者服务器 url */ url: string; @@ -137,30 +210,9 @@ declare namespace wx { * 客户端发起一个 HTTPS POST 请求, * 其中 Content-Type 为 multipart/form-data 。 */ - function uploadFile(options: UploadFileOptions): void; - - - interface DownloadFileOptions { - /** 下载资源的 url */ - url: string; - /** 下载资源的类型,用于客户端识别处理,有效值:image/audio/video */ - type?: string; - /** HTTP 请求 Header */ - header?: RequestHeader; - /** 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'} */ - success?: TempFileResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 下载文件资源到本地。客户端直接发起一个 HTTP GET 请求, - * 把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。 - */ - function downloadFile(options: DownloadFileOptions): void; - + function uploadFile(options: UploadFileOptions): UploadTask; + // WebSocket interface ConnectSocketOptions { /** 开发者服务器接口地址,必须是 HTTPS 协议,且域名必须是后台配置的合法域名 */ url: string; @@ -440,6 +492,29 @@ declare namespace wx { */ function chooseVideo(options: ChooseVideoOptions): void; + // 数据缓存 + interface StorageInfo { + // 当前 storage 中所有的 key + keys: Array; + // 当前占用的空间大小, 单位 KB + currentSize: number; + // 限制的空间大小,单位 KB + limitSize: number; + } + type StorageInfoCallback = (res: StorageInfoOptions) => void; + interface StorageInfoOptions extends CommonCallbackOptions{ + success?: StorageInfoCallback; + } + /** + * getStorageInfo的同步版本 + */ + function getStorageInfoSync(): StorageInfo; + /** + * 异步获取当前storage的相关信息 + * @param options + */ + function getStorageInfo(options: StorageInfoOptions): void; + interface SetStorageOptions { /** 本地缓存中的指定的 key */ key: string; @@ -498,6 +573,9 @@ declare namespace wx { */ function clearStorageSync(): void; + // 媒体 + // 地图 TODO + interface LocationData { /** 纬度,浮点数,范围为-90~90,负数表示南纬 */ latitude: number; @@ -658,17 +736,36 @@ declare namespace wx { // 调试 TODO // 路由 - interface routerOptions { - + interface routerOptions extends CommonCallbackOptions{ + // 需要跳转的应用内非 tabBar 的页面的路径, 路径后可以带参数。参数与路径之间使用 ? 分隔,参数键与参数值用 = 相连,不同参数用 & 分隔;如 'path?key=value&key2=value2' + url: string; + } + interface NavigateBackOptions extends CommonCallbackOptions { + // 返回的页面数,如果 delta 大于现有页面数,则返回到首页。 + delta: number; } /** * 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。 */ - function navigateBack(): void; - function switchTab(): void; - function navigateTo(): void; - function reLaunch(): void; - function redirectTo(): void; + function navigateBack(options: NavigateBackOptions): void; + /** + * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 + * @param options + */ + function switchTab(options: routerOptions): void; + /** + * 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 wx.navigateBack 可以返回到原页面。 + * @param options + */ + function navigateTo(options: routerOptions): void; + /** + * 关闭所有页面,打开到应用内的某个页面 + */ + function reLaunch(options: routerOptions): void; + /** + * 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 + */ + function redirectTo(options: routerOptions): void; // 界面 // 交互 @@ -689,8 +786,11 @@ declare namespace wx { * 公共回调函数 */ interface CommonCallbackOptions { + // 接口调用成功回调函数 success?: ResponseCallback; + // 接口调用失败回调函数 fail?: ResponseCallback; + // 接口调用结束的回调函数 complete?: ResponseCallback; } @@ -798,7 +898,133 @@ declare namespace wx { // 背景 function setBackgroundTextStyle(): void; + interface BackgroundColorOptions extends CommonCallbackOptions{ + // 窗口的背景色,必须为十六进制颜色值 + backgroundColor?: string; + // 顶部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 + backgroundColorTop?: string; + // 底部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 + backgroundColorBottom?: string; + } function setBackgroundColor(): void; + // Tab Bar + interface TabBarItemOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + // tab 上的按钮文字 + text?: string; + // 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片 + iconPath?: string; + // 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效 + selectedIconPath?: string; + } + /** + * 动态设置 tabBar 某一项的内容 + * @param options + */ + function setTabBarItem(options: TabBarItemOptions): void; + + interface TabBarStyleOptions extends CommonCallbackOptions{ + // tab 上的文字默认颜色,HexColor + color: string; + // tab 上的文字选中时的颜色,HexColor + selectedColor: string; + // tab 的背景色,HexColor + backgroundColor: string; + // tabBar上边框的颜色, 仅支持 black/white + borderStyle: string; + } + /** + * 动态设置tabBar的整体样式 + */ + function setTabBarStyle(options: TabBarItemOptions): void; + + interface TabBarAnimationOptions extends CommonCallbackOptions{ + // 是否需要动画效果 + animation: boolean; + } + /** + * 隐藏tabBar + */ + function hideTabBar(options: TabBarAnimationOptions): void; + /** + * 显示tabBar + */ + function showTabBar(options: TabBarAnimationOptions): void; + + interface TabBarRedDotOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + } + /** + * 隐藏 tabBar 某一项的右上角的红点 + * @param options + */ + function hideTabBarRedDot(options: TabBarBadgeOptions): void; + /** + * 显示 tabBar 某一项的右上角的红点 + * @param options + */ + function showTabBarRedDot(options: TabBarRedDotOptions): void; + + interface TabBarBadgeOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + // 显示的文本,超过 4 个字符则显示成 ... + text: string; + } + /** + * 移除 tabBar 某一项右上角的文本 + * @param options + */ + function removeTabBarBadge(options: TabBarRedDotOptions): void; + /** + * 为 tabBar 某一项的右上角添加文本 + * @param options + */ + function setTabBarBadge(options: TabBarBadgeOptions): void; + + interface FontDescOptions { + // 字体样式,可选值为 normal / italic / oblique + style?: string; + // 字体粗细,可选值为 normal / bold / 100 / 200../ 900 + weight?: string; + // 设置小型大写字母的字体显示文本,可选值为 normal / small-caps / inherit + variant?: string; + } + // 字体 + interface FontFaceOptions extends CommonCallbackOptions{ + // 定义的字体名称 + family: string; + // 字体资源的地址。建议格式为 TTF 和 WOFF,WOFF2 在低版本的iOS上会不兼容。 + source: string; + // 可选的字体描述符 + desc?: FontDescOptions; + } + function loadFontFace(options: FontFaceOptions): void; + + // 下拉刷新 + /** + * 停止当前页面下拉刷新。 + */ + function stopPullDownRefresh(options?: CommonCallbackOptions): void; + + /** + * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。 + */ + function startPullDownRefresh(options?: CommonCallbackOptions): void; + + // 滚动 + interface PageScrollToOptions extends CommonCallbackOptions{ + // 滚动到页面的目标位置,单位 px + scrollTop: number; + // 滚动动画的时长,单位 ms。默认300 + duration: number; + } + /** + * 将页面滚动到 + */ + function pageScrollTo(): void; interface AccelerometerData { /** X 轴 */ @@ -845,46 +1071,9 @@ declare namespace wx { */ function hideNavigationBarLoading(): void; - interface NavigateToOptions { - /** 需要跳转的应用内页面的路径 */ - url: string; - /** 成功获取系统信息的回调 */ - success?: ResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。 - * - * 注意:为了不让用户在使用小程序时造成困扰, - * 我们规定页面路径只能是五层,请尽量避免多层级的交互方式。 - */ - function navigateTo(options: NavigateToOptions): void; - - interface RedirectToOptions { - /** 需要跳转的应用内页面的路径 */ - url: string; - /** 成功获取系统信息的回调 */ - success?: ResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 关闭当前页面,跳转到应用内的某个页面。 - */ - function redirectTo(options: RedirectToOptions): void; - - /** - * 关闭当前页面,回退前一页面。 - */ - function navigateBack(): void; - type TimingFunction = 'linear' | 'ease' | 'ease-in' | 'ease-in-out' | 'ease-out' | 'step-start' | 'step-end'; + // 动画 interface CreateAnimationOptions { /** 动画持续时间,单位ms,默认值 400 */ duration?: number; From 0ffb1d9d2b10010234e381510c7035c6749082b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:08:35 +0800 Subject: [PATCH 20/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=9C=B0=E5=9B=BE=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 160 ++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0882745c2f..6fdf7df480 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -574,7 +574,62 @@ declare namespace wx { function clearStorageSync(): void; // 媒体 - // 地图 TODO + // 地图 + interface LocationBaseOptions { + // 纬度,浮点数,范围为-90~90,负数表示南纬 + latitude: number; + // 经度,浮点数,范围为-180~180,负数表示西经 + longitude: number; + } + interface GetCenterLocationSuccCbOptions extends CommonCallbackOptions{ + success(res: LocationBaseOptions): void; + } + interface translateMarkerOptions extends CommonCallbackOptions{ + // 指定 marker + markerId: number; + // 指定 marker 移动到的目标点 + destination: LocationBaseOptions; + // 移动过程中是否自动旋转 marker + autoRotate: boolean; + // marker 的旋转角度 + rotate: number; + // 动画持续时长,平移与旋转分别计算 + duration?: number; + // 动画结束回调函数 + animationEnd?(): void; + } + interface zoomPointsOptions extends CommonCallbackOptions { + // 要显示在可视区域内的坐标点列表 + points: Array; + // 坐标点形成的矩形边缘到地图边缘的距离,单位像素。格式为[上,右,下,左],安卓上只能识别数组第一项,上下左右的padding一致。开发者工具暂不支持padding参数。 + padding?: Array; + } + interface GetReginSuccessCallbackOptions { + // 西南角经纬度 + southwest: number, + // 东北角经纬度 + northeast: number; + } + interface GetReginOptions extends CommonCallbackOptions{ + success?(callback: (res: GetReginSuccessCallbackOptions) => void): void; + } + interface GetScaleOptions extends CommonCallbackOptions{ + success?(callback: (res: {scale: number}) => void): void; + } + interface MapContext { + // 获取当前地图中心的经纬度。返回的是 gcj02 坐标系,可以用于 wx.openLocation() + getCenterLocation(options: GetCenterLocationSuccCbOptions): void; + // 将地图中心移动到当前定位点。需要配合map组件的show-location使用 + moveToLocation(): void; + // 平移marker,带动画 + translateMarker(options: translateMarkerOptions): void; + // 缩放视野展示所有经纬度 + includePoints(options: zoomPointsOptions): void; + // 获取当前地图的视野范围 + getRegion(options: GetReginOptions): void; + // 获取当前地图的缩放级别 + getScale(options: GetScaleOptions): void; + } interface LocationData { /** 纬度,浮点数,范围为-90~90,负数表示南纬 */ @@ -1440,6 +1495,8 @@ declare namespace wx { */ function hideKeyboard(): void; + // 开放接口 + // 登录 interface LoginResponse { /** 调用结果 */ errMsg: string; @@ -1458,6 +1515,10 @@ declare namespace wx { complete?: ResponseCallback; } + /** + * 检查登录态是否过期。 + */ + function checkSession(options: CommonCallbackOptions): void; /** * 调用接口获取登录凭证(code)进而换取用户登录态信息, * 包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key)。 @@ -1465,6 +1526,51 @@ declare namespace wx { */ function login(option: LoginOptions): void; + type envVersion = 'develop' | 'trial' | 'release'; + interface NavigateToMiniProgramOptions extends CommonCallbackOptions { + // 要打开的小程序 appId + appId: string; + // 打开的页面路径,如果为空则打开首页 + path?: string; + // 需要传递给目标小程序的数据,目标小程序可在 App.onLaunch,App.onShow 中获取到这份数据。 + extraData?: object; + // 要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版。 + envVersion?: envVersion; + } + /** + * 打开另一个小程序 + */ + function navigateToMiniProgram(options: NavigateToMiniProgramOptions): void; + interface NavigateBackMiniProgramOptions extends CommonCallbackOptions { + // 需要返回给上一个小程序的数据,上一个小程序可在 App.onShow 中获取到这份数据。 + extraData: object; + } + /** + * 返回到上一个小程序。只有在当前小程序是被其他小程序打开时可以调用成功 + */ + function navigateBackMiniProgram(options: NavigateBackMiniProgramOptions): void; + + // 帐号信息 + interface AccountInfo { + // 小程序帐号信息 + miniProgram: { + // 小程序appId + appId: string; + }; + // 插件帐号信息(仅在插件中调用时包含这一项) + Plugin: { + // 插件appId + appId: string; + // 插件版本号 + vetsion: string + }; + } + /** + * 获取当前账号信息 + */ + function getAccountInfoSync(): AccountInfo; + + // 帐号信息 interface UserInfo { nickName: string; avatarUrl: string; @@ -1515,11 +1621,63 @@ declare namespace wx { /** 接口调用结束的回调函数(调用成功、失败都会执行) */ complete?: ResponseCallback; } + // 支付 /** * 发起微信支付。 */ function requestPayment(options: RequestPaymentOptions): void; + + // 授权 + /** + * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html + * 用户信息 wx.getUserInfo、 + * 地理位置 wx.getLocation,wx.chooseLocation、 + * 通讯地址 wx.chooseAddress、 + * 发票抬头 wx.chooseInvoiceTitle、 + * 获取发票 wx.chooseInvoice、 + * 微信运动步数 wx.getWeRunData、 + * 录音功能 wx.startRecord、 + * 保存到相册 wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum、 + * 摄像头 组件 + */ + type Scope = 'userInfo' | 'userLocation' | 'address' | 'invoiceTitle' | 'invoice' | 'werun' | 'record' | 'writePhotosAlbum' | 'camera'; + interface AuthorizeOptions extends CommonCallbackOptions { + // 需要获取权限的 scope,详见 scope 列表 + scope: Scope; + } + /** + * 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。 + */ + function authorize(options: AuthorizeOptions): void; + + // 设置 + interface SettingOptions extends CommonCallbackOptions{ + success?(res: AuthSetting): void; + } + /** + * 调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。 + */ + function openSetting(options: SettingOptions): void; + /** + * 获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。 + */ + function getSetting(options: SettingOptions): void; + /** + * 用户授权结果,参考 type Scope + */ + interface AuthSetting { + 'scope.userInfo': boolean; + 'scope.userLocation': boolean; + 'scope.address': boolean; + 'scope.invoiceTitle': boolean; + 'scope.invoice': boolean; + 'scope.werun': boolean; + 'scope.record': boolean; + 'scope.writePhotosAlbum': boolean; + 'scope.camera': boolean; + } } +// end of wx namespace interface Page { From d57069b7d7f9ea3ccde347f878a5594e06906e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:16:37 +0800 Subject: [PATCH 21/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0author=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 6fdf7df480..0cbaf8b97b 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for weapp // Project: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html -// Definitions by: vargeek +// Definitions by: vargeek & pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace wx { From bddec1cc7ff388ea07b18261007c4fa20330d4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:59:03 +0800 Subject: [PATCH 22/37] add author and TypeScript version --- types/weapp-api/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0cbaf8b97b..4350eb1d25 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1,7 +1,9 @@ // Type definitions for weapp // Project: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html -// Definitions by: vargeek & pbestz +// Definitions by: vargeek +// pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2.1 declare namespace wx { // import startPullDownRefresh = swan.startPullDownRefresh; From 5743f0981f90e0f6afc45206e47188f9822c6bd7 Mon Sep 17 00:00:00 2001 From: bocai Date: Tue, 1 Jan 2019 23:26:42 +0800 Subject: [PATCH 23/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UpdateManager=E3=80=81o?= =?UTF-8?q?nLaunch=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/weapp-api-tests.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index 82a5b8d91d..e13f3766d5 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -347,6 +347,30 @@ wx.getSystemInfo({ } }) +const updateManager = wx.getUpdateManager() + +// updateManager.onCheckForUpdate(function (res) { +// //请求完新版本信息的回调 +// console.log(res.hasUpdate) +// }) + +updateManager.onUpdateReady(function () { + // wx.showModal({ + // title: '更新提示', + // content: '新版本已经准备好,是否重启应用?', + // success(res) { + // if (res.confirm) { + // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + // updateManager.applyUpdate() + // } + // } + // }) +}) + +updateManager.onUpdateFailed(function () { + // 新版本下载失败 +}) + wx.onAccelerometerChange(function(res) { console.log(res.x) console.log(res.y) @@ -673,3 +697,9 @@ wx.requestPayment({ 'fail':function(res){ } }) + +App({ + onLaunch(options){ + console.log(options.query) + } +}) From 9bc6e211c32b6b545b997d1b9329fc9c46eef33b Mon Sep 17 00:00:00 2001 From: bocai Date: Tue, 1 Jan 2019 23:28:51 +0800 Subject: [PATCH 24/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UpdateManager=E3=80=81o?= =?UTF-8?q?nLaunch=E7=9B=B8=E5=85=B3=E5=A3=B0=E6=98=8E=EF=BC=8C=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E4=BD=BF=E7=94=A8type=20aliases/interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index f22ed51765..c3b85a658a 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -37,12 +37,33 @@ declare namespace wx { [key: string]: any; } + interface referrerInfo { + /** 来源小程序、公众号或 App 的 appId */ + appId: string, + /** 来源小程序传过来的数据,scene=1037或1038时支持 */ + extraData: Object + } + + interface LaunchOptions { + /** 启动小程序的路径 */ + path: string, + /** 启动小程序的场景值 */ + scene: number, + /** 启动小程序的query参数 */ + query: Object, + shareTicket: string, + /** 来源信息。从另一个小程序、公众号或App进入小程序时返回。范泽返回{} */ + referrerInfo: referrerInfo + } + + type LaunchCallback = (options: LaunchOptions) => void; + interface AppOptions { /** * 生命周期函数--监听小程序初始化 * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次) */ - onLaunch?: NoneParamCallback; + onLaunch?: LaunchCallback; /** * 生命周期函数--监听小程序显示 * 当小程序启动,或从后台进入前台显示,会触发 onShow @@ -561,6 +582,34 @@ declare namespace wx { */ function getSystemInfo(options: GetSystemInfoOptions): void; + interface UpdateManager { + /** + * 强制小程序重启并使用新版本。在小程序新版本下载完成后(即收到 onUpdateReady 回调)调用。 + */ + applyUpdate(callback: DataResponseCallback): void; + /** + * 监听向微信后台请求检查更新结果事件。微信在小程序冷启动时自动检查更新,不需由开发者主动触发。 + */ + onCheckForUpdate(): void; + /** + * 监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调 + */ + onUpdateReady(callback: NoneParamCallback): void; + /** + * 监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)后回调 + */ + onUpdateFailed(callback: NoneParamCallback): void; + } + /** + * 获取全局唯一的版本更新管理器,用于管理小程序更新。关于小程序的更新机制,可以查看运行机制文档。 + */ + function getUpdateManager(): UpdateManager; + + /** + * 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。 + */ + function getLaunchOptionsSync(): LaunchCallback; + interface AccelerometerData { /** X 轴 */ x: number; From 61183f975936a28e45b46585a5784548f0240419 Mon Sep 17 00:00:00 2001 From: bocai Date: Wed, 2 Jan 2019 01:40:37 +0800 Subject: [PATCH 25/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BA=A7=E4=BA=8B=E4=BB=B6=E3=80=81=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E3=80=81=E8=B7=AF=E7=94=B1=E3=80=81=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 131 +++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index c3b85a658a..0e06bd8357 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,6 +3,8 @@ // Definitions by: vargeek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import functions from "../react-icons/md/functions"; + declare namespace wx { type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; @@ -44,7 +46,7 @@ declare namespace wx { extraData: Object } - interface LaunchOptions { + interface onLaunchOptions { /** 启动小程序的路径 */ path: string, /** 启动小程序的场景值 */ @@ -56,24 +58,34 @@ declare namespace wx { referrerInfo: referrerInfo } - type LaunchCallback = (options: LaunchOptions) => void; + type onLaunchCallback = (options: onLaunchOptions) => void; + type onShowOptions = onLaunchOptions; interface AppOptions { /** * 生命周期函数--监听小程序初始化 * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次) */ - onLaunch?: LaunchCallback; + onLaunch?: onLaunchCallback; /** * 生命周期函数--监听小程序显示 * 当小程序启动,或从后台进入前台显示,会触发 onShow */ - onShow?: NoneParamCallback; + onShow?: (options: onShowOptions) => void; /** * 生命周期函数--监听小程序隐藏 * 当小程序从前台进入后台,会触发 onHide */ onHide?: NoneParamCallback; + /** 小程序发生脚本错误或 API 调用报错时触发。也可以使用 wx.onError 绑定监听。*/ + onError?: ErrorCallback; + /** + * 小程序要打开的页面不存在时触发 + * 1. 开发者可以在回调中进行页面重定向,但必须在回调中同步处理,异步处理(例如 setTimeout 异步执行)无效。 + * 2. 若开发者没有调用 wx.onPageNotFound 绑定监听,也没有声明 App.onPageNotFound,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。 + * 3. 如果回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再第二次回调。 + */ + onPageNotFound?: NoneParamCallback; [key: string]: any } @@ -608,7 +620,87 @@ declare namespace wx { /** * 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。 */ - function getLaunchOptionsSync(): LaunchCallback; + function getLaunchOptionsSync(): onLaunchCallback; + + // 应用级事件 + /** + * 取消监听小程序要打开的页面不存在事件 + */ + function offPageNotFound(): NoneParamCallback; + /** + * 监听小程序要打开的页面不存在事件。该事件与 App.onPageNotFound 的回调时机一致。 + */ + function onPageNotFound(): NoneParamCallback; + /** + * 取消监听小程序错误事件。 + */ + function offError(): NoneParamCallback; + /** + * 监听小程序错误事件。如脚本错误或 API 调用报错等。该事件与 App.onError 的回调时机与参数一致。 + */ + function onError(): ErrorCallback; + /** + * 取消监听小程序切前台事件 + */ + function offAppShow(): NoneParamCallback; + /** + * 监听小程序切前台事件。该事件与 App.onShow 的回调参数一致。 + * @param callback + */ + function onAppShow(callback: onShowOptions): void; + /** + * 取消监听小程序切后台事件 + */ + function offAppHide(): NoneParamCallback; + /** + * 监听小程序切后台事件。该事件与 App.onHide 的回调时机一致。 + */ + function onAppHide(): NoneParamCallback; + + // 调试 TODO + + // 路由 + interface routerOptions { + + } + /** + * 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。 + */ + function navigateBack(): void; + function switchTab(): void; + function navigateTo(): void; + function reLaunch(): void; + function redirectTo(): void; + + // 界面 + // 交互 + // tapIndex为用户点击的按钮序号,从上到下的顺序,从0开始 + type ActionSheetSuccessCallback = (res: {tapIndex: number}) => void; + + interface ActionSheetOptions { + // 必填,按钮的文字数组,数组长度最大为 6 + itemList: Array; + // 按钮的文字颜色 + itemColor?: string; + success?: ActionSheetSuccessCallback; + fail?: ResponseCallback; + complete?: ResponseCallback; + } + /** + * 显示操作菜单 + */ + function showActionSheet(options: ActionSheetOptions): void; + function hideLoading(): void; + function showLoading(): void; + function hideToast(): void; + function showToast(): void; + function showModal(): void; + + // 导航栏 + function setNavigationBarColor(): void; + function hideNavigationBarLoading(): void; + function showNavigationBarLoading(): void; + function setNavigationBarTitle(): void; interface AccelerometerData { /** X 轴 */ @@ -1182,3 +1274,32 @@ declare var App: AppConstructor; * 我们提供了全局的 getApp() 函数,可以获取到小程序实例。 */ declare function getApp(): App; + +// 定时器 +/** + * 设定一个定时器。在定时到期以后执行注册的回调函数 + * @param callback + * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 + * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 + */ +declare function setTimeout(callback: functions, delay: number, rest: any): number; + +/** + * 取消由 setTimeout 设置的定时器。 + * @param timeoutID 要取消的定时器的ID + */ +declare function clearTimeout(timeoutID: number): number; + +/** + * 设定一个定时器。按照指定的周期(以毫秒计)来执行注册的回调函数 + * @param callback + * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 + * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 + */ +declare function setInterval(callback: functions, delay: number, rest: any): number; + +/** + * 取消由 setInterval 设置的定时器。 + * @param timeoutID 要取消的定时器的ID + */ +declare function clearInterval(timeoutID: number): number; From 85bcca8a6de4c92368ea1072a38f81414f758af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Wed, 2 Jan 2019 21:45:48 +0800 Subject: [PATCH 26/37] modify --- types/weapp-api/index.d.ts | 67 +++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0e06bd8357..fa328782ca 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -686,15 +686,72 @@ declare namespace wx { fail?: ResponseCallback; complete?: ResponseCallback; } + + interface CommonCallbackOptions { + success?: ResponseCallback; + fail?: ResponseCallback; + complete?: ResponseCallback; + } + + interface LoadingOptions extends CommonCallbackOptions{ + // must,提示的内容 + title: string; + // 默认false。是否显示透明蒙层,防止触摸穿透 + mask: boolean; + } + + type icon = 'success' | 'loading' | 'none'; + interface ToastOptions extends CommonCallbackOptions{ + // 提示的内容 + title: string; + // 图标,默认值'success' + icon?: icon; + // 自定义图标的本地路径,image 的优先级高于 icon + imgage?: string; + // 提示的延迟时间,默认值1500ms + duration?: number; + // 是否显示透明蒙层,防止触摸穿透,默认值false + mask: boolean; + } + + interface ModalOptions extends CommonCallbackOptions{ + // 提示的内容 + title: string; + // 提示的内容 + content: string; + // 是否显示取消按钮,默认值true + showCancel?: boolean; + // 取消按钮的文字,最多 4 个字符,默认值'取消' + cancelText?: string; + // 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值'#000000' + cancelColor?: string; + // 确认按钮的文字,最多 4 个字符 + confirmText?: string; + // 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值'#3cc51f' + confirmColor?: boolean; + } /** * 显示操作菜单 */ function showActionSheet(options: ActionSheetOptions): void; - function hideLoading(): void; - function showLoading(): void; - function hideToast(): void; - function showToast(): void; - function showModal(): void; + /** + * 隐藏 loading 提示框 + * @param options + */ + function hideLoading(options?: CommonCallbackOptions): void; + /** + * 显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框 + * @param options + */ + function showLoading(options: LoadingOptions): void; + function hideToast(options?: CommonCallbackOptions): void; + function showToast(options: ToastOptions): void; + + /** + * 显示模态对话框 + * @param options + */ + function showModal(options: ModalOptions): void; // 导航栏 function setNavigationBarColor(): void; From 6e980110df756f9a609aa9aac36fbe7359e0f998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 21:12:02 +0800 Subject: [PATCH 27/37] =?UTF-8?q?weapp-api,=E5=A2=9E=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E9=83=A8=E5=88=86=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 51 ++++++++++++++++++++-- types/weapp-api/tsconfig.json | 5 ++- types/weapp-api/weapp-api-tests.ts | 69 +++++++++++++++--------------- 3 files changed, 84 insertions(+), 41 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index fa328782ca..fec6f90f14 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -687,6 +687,9 @@ declare namespace wx { complete?: ResponseCallback; } + /** + * 公共回调函数 + */ interface CommonCallbackOptions { success?: ResponseCallback; fail?: ResponseCallback; @@ -744,20 +747,60 @@ declare namespace wx { * @param options */ function showLoading(options: LoadingOptions): void; + /** + * 隐藏消息提示框 + * @param options + */ function hideToast(options?: CommonCallbackOptions): void; + /** + * 显示消息提示框 + * @param options + */ function showToast(options: ToastOptions): void; - /** * 显示模态对话框 * @param options */ function showModal(options: ModalOptions): void; + + interface NavigationBarColorAnimationOptions { + // 动画变化时间,单位 ms,默认0 + animation?: number; + // 动画变化方式.动画从头到尾的速度是相同的,动画以低速开始,动画以低速结束,动画以低速开始和结束 + timingFunc?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' + } + interface NavigationBarColorOptions extends CommonCallbackOptions{ + // 前景颜色值,包括按钮、标题、状态栏的颜色,仅支持 #ffffff 和 #000000 + frontColor: string; + // 背景颜色值,有效值为十六进制颜色 + backgroundColor: string; + // 动画效果 + animation: NavigationBarColorAnimationOptions; + } + interface NavigationBarTitleOptions extends CommonCallbackOptions{ + // 动态设置当前页面的标题 + title: string; + } // 导航栏 function setNavigationBarColor(): void; - function hideNavigationBarLoading(): void; - function showNavigationBarLoading(): void; - function setNavigationBarTitle(): void; + /** + * 在当前页面隐藏导航条加载动画 + */ + function hideNavigationBarLoading(options?: CommonCallbackOptions): void; + /** + * 在当前页面显示导航条加载动画 + */ + function showNavigationBarLoading(options: CommonCallbackOptions): void; + /** + * 动态设置当前页面的标题 + * @param options + */ + function setNavigationBarTitle(options: NavigationBarTitleOptions): void; + + // 背景 + function setBackgroundTextStyle(): void; + function setBackgroundColor(): void; interface AccelerometerData { /** X 轴 */ diff --git a/types/weapp-api/tsconfig.json b/types/weapp-api/tsconfig.json index ef43ffab75..74812f3d05 100644 --- a/types/weapp-api/tsconfig.json +++ b/types/weapp-api/tsconfig.json @@ -19,6 +19,7 @@ }, "files": [ "index.d.ts", - "weapp-api-tests.ts" + "weapp-api-tests.ts", + "../baidu-app/index.d.ts" ] -} \ No newline at end of file +} diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index e13f3766d5..4363179c80 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -14,7 +14,7 @@ App({ wx.login({ success: function () { wx.getUserInfo({ - success: function (res) { + success: function (res: any) { that.globalData.userInfo = res.userInfo; typeof cb == "function" && cb(that.globalData.userInfo) } @@ -37,7 +37,6 @@ Page({ foo: 'bar' }, onLoad: function (options) { - console.log(options.title); } }) @@ -51,13 +50,13 @@ wx.request({ header: { 'Content-Type': 'application/json' }, - success: function (res) { + success: function (res: any) { console.log(res.data) } }) wx.chooseImage({ - success: function (res) { + success: function (res: any) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'http://example.com/upload', @@ -73,7 +72,7 @@ wx.chooseImage({ wx.downloadFile({ url: 'http://example.com/audio/123', type: 'audio', - success: function (res) { + success: function (res: any) { wx.playVoice({ filePath: res.tempFilePath }) @@ -95,17 +94,17 @@ wx.connectSocket({ wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { console.log('WebSocket连接已打开!') }) wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { console.log('WebSocket连接已打开!') }) -wx.onSocketError(function (res) { +wx.onSocketError(function (res: any) { console.log('WebSocket连接打开失败,请检查!') }) @@ -115,7 +114,7 @@ wx.connectSocket({ url: 'test.php' }) -wx.onSocketOpen(function (res) { +wx.onSocketOpen(function (res: any) { socketOpen = true for (var i = 0; i < socketMsgQueue.length; i++) { sendSocketMessage(socketMsgQueue[i]) @@ -137,7 +136,7 @@ wx.connectSocket({ url: 'test.php' }) -wx.onSocketMessage(function (res) { +wx.onSocketMessage(function (res: any) { console.log('收到服务器内容:' + res.data) }) @@ -152,7 +151,7 @@ wx.onSocketOpen(function () { wx.closeSocket() }) -wx.onSocketClose(function (res) { +wx.onSocketClose(function (res: any) { console.log('WebSocket 已关闭!') }) @@ -160,7 +159,7 @@ wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 - success: function (res) { + success: function (res: any) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths } @@ -172,10 +171,10 @@ wx.previewImage({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath }, - fail: function (res) { + fail: function (res: any) { //录音失败 } }) @@ -185,7 +184,7 @@ setTimeout(function () { }, 10000) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath, @@ -196,7 +195,7 @@ wx.startRecord({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath @@ -210,7 +209,7 @@ wx.startRecord({ }) wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.playVoice({ filePath: tempFilePath @@ -223,7 +222,7 @@ wx.startRecord({ }) wx.getBackgroundAudioPlayerState({ - success: function (res) { + success: function (res: any) { var status = res.status var dataUrl = res.dataUrl var currentPosition = res.currentPosition @@ -246,11 +245,11 @@ wx.seekBackgroundAudio({ wx.stopBackgroundAudio() wx.startRecord({ - success: function (res) { + success: function (res: any) { var tempFilePath = res.tempFilePath wx.saveFile({ tempFilePath: tempFilePath, - success: function (res) { + success: function (res: any) { var savedFilePath = res.savedFilePath } }) @@ -265,7 +264,7 @@ Page({ sourceType: ['album', 'camera'], maxDuration: 60, camera: ['front', 'back'], - success: function (res) { + success: function (res: any) { that.setData({ src: res.tempFilePath }) @@ -286,7 +285,7 @@ try { wx.getStorage({ key: 'key', - success: function (res) { + success: function (res: any) { console.log(res.data) } }) @@ -309,7 +308,7 @@ try { wx.getLocation({ type: 'wgs84', - success: function (res) { + success: function (res: any) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed @@ -319,7 +318,7 @@ wx.getLocation({ wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 - success: function(res) { + success: function(res: any) { var latitude = res.latitude var longitude = res.longitude wx.openLocation({ @@ -331,13 +330,13 @@ wx.getLocation({ }) wx.getNetworkType({ - success: function(res) { + success: function(res: any) { var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi } }) wx.getSystemInfo({ - success: function(res) { + success: function(res: any) { console.log(res.model) console.log(res.pixelRatio) console.log(res.windowWidth) @@ -349,7 +348,7 @@ wx.getSystemInfo({ const updateManager = wx.getUpdateManager() -// updateManager.onCheckForUpdate(function (res) { +// updateManager.onCheckForUpdate(function (res: any) { // //请求完新版本信息的回调 // console.log(res.hasUpdate) // }) @@ -358,7 +357,7 @@ updateManager.onUpdateReady(function () { // wx.showModal({ // title: '更新提示', // content: '新版本已经准备好,是否重启应用?', - // success(res) { + // success(res: any) { // if (res.confirm) { // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 // updateManager.applyUpdate() @@ -371,13 +370,13 @@ updateManager.onUpdateFailed(function () { // 新版本下载失败 }) -wx.onAccelerometerChange(function(res) { +wx.onAccelerometerChange(function(res: any) { console.log(res.x) console.log(res.y) console.log(res.z) }) -wx.onCompassChange(function (res) { +wx.onCompassChange(function (res: any) { console.log(res.direction) }) @@ -543,7 +542,7 @@ Page({ onReady: function() { var context = wx.createContext() wx.chooseImage({ - success: function(res) { + success: function(res: any) { context.drawImage(res.tempFilePaths[0], 0, 0) wx.drawCanvas({ canvasId: 1, @@ -656,7 +655,7 @@ Page({ App({ onLaunch: function() { wx.login({ - success: function(res) { + success: function(res: any) { if (res.code) { //发起网络请求 wx.request({ @@ -675,7 +674,7 @@ App({ wx.getUserInfo({ - success: function(res) { + success: function(res: any) { var userInfo = res.userInfo var nickName = userInfo.nickName var avatarUrl = userInfo.avatarUrl @@ -692,9 +691,9 @@ wx.requestPayment({ 'package': '', 'signType': 'MD5', 'paySign': '', - 'success':function(res){ + 'success':function(res: any){ }, - 'fail':function(res){ + 'fail':function(res: any){ } }) From 25ea4919f60209bd4fdf009dc3af95e98599c721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 22:02:56 +0800 Subject: [PATCH 28/37] weapp-api,export wx --- types/weapp-api/index.d.ts | 2 ++ types/weapp-api/weapp-api-tests.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index fec6f90f14..5eb9c36175 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1403,3 +1403,5 @@ declare function setInterval(callback: functions, delay: number, rest: any): num * @param timeoutID 要取消的定时器的ID */ declare function clearInterval(timeoutID: number): number; + +export default wx diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index 4363179c80..5b2b0616a2 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -1,12 +1,13 @@ +import wx from './index' App({ onLaunch: function () { //调用API从本地缓存中获取数据 - var logs = wx.getStorageSync('logs') as Array || [] + let logs = wx.getStorageSync('logs') as Array || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) }, getUserInfo: function (cb: Function) { - var that = this; + let that = this; if (this.globalData.userInfo) { typeof cb == "function" && cb(this.globalData.userInfo) } else { From 702916ca689af083ec92e984f98b48dff818ec26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 4 Jan 2019 22:08:31 +0800 Subject: [PATCH 29/37] modify functions type --- types/weapp-api/index.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 5eb9c36175..dcc3cd3e16 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,8 +3,6 @@ // Definitions by: vargeek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import functions from "../react-icons/md/functions"; - declare namespace wx { type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; @@ -1382,7 +1380,7 @@ declare function getApp(): App; * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */ -declare function setTimeout(callback: functions, delay: number, rest: any): number; +declare function setTimeout(callback: any, delay: number, rest: any): number; /** * 取消由 setTimeout 设置的定时器。 @@ -1396,7 +1394,7 @@ declare function clearTimeout(timeoutID: number): number; * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */ -declare function setInterval(callback: functions, delay: number, rest: any): number; +declare function setInterval(callback: any, delay: number, rest: any): number; /** * 取消由 setInterval 设置的定时器。 From 998964f58a5e714cf9cbbafe9ff757f724638902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Mon, 7 Jan 2019 15:49:11 +0800 Subject: [PATCH 30/37] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=EF=BC=8C=E8=B7=AF=E7=94=B1=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 327 +++++++++++++++++++++++++++++-------- 1 file changed, 258 insertions(+), 69 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index dcc3cd3e16..0882745c2f 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -4,6 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace wx { + // import startPullDownRefresh = swan.startPullDownRefresh; type NoneParamCallback = () => void; type OneParamCallback = (data: any) => void; type ResponseCallback = (res: any) => void; @@ -87,6 +88,8 @@ declare namespace wx { [key: string]: any } + // 网络 + // 发起请求 interface RequestHeader { [key: string]: string; } @@ -109,9 +112,79 @@ declare namespace wx { /** * wx.request发起的是https请求。一个微信小程序,同时只能有5个网络请求连接。 */ - function request(options: RequestOptions): void; + function request(options: RequestOptions): RequestTask; + /** + * 网络请求任务对象 + */ + interface RequestTask { + // 中断请求任务 + abort(): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } + // 下载 + interface OnProgressCallbackOptions { + // 下载进度百分比 + progress: number; + // 已经下载的数据长度,单位 Bytes + totalBytesWritten: number; + // 预期需要下载的数据总长度,单位 Bytes + totalBytesExpectedToWrite: number; + } + /** + * 一个可以监听下载进度变化事件,以及取消下载任务的对象 + */ + interface DownloadTask { + // 中断下载任务 + abort(): void; + // 下载进度变化事件的回调函数 + onProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 取消监听下载进度变化事件 + offProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } + interface DownloadFileOptions { + /** 下载资源的 url */ + url: string; + /** 下载资源的类型,用于客户端识别处理,有效值:image/audio/video */ + type?: string; + /** HTTP 请求 Header */ + header?: RequestHeader; + /** 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'} */ + success?: TempFileResponseCallback; + /** 接口调用失败的回调函数 */ + fail?: ResponseCallback; + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete?: ResponseCallback; + } + /** + * 下载文件资源到本地。客户端直接发起一个 HTTP GET 请求, + * 把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。 + */ + function downloadFile(options: DownloadFileOptions): DownloadTask; + // 上传 + /** + * 一个可以监听上传进度变化事件,以及取消上传任务的对象 + */ + interface UploadTask { + // 中断上传任务 + abort(): void; + // 上传进度变化事件的回调函数 + onProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 取消监听上传进度变化事件 + offProgressUpdate(callback: (res: OnProgressCallbackOptions) => {}): void; + // 监听 HTTP Response Header 事件。会比请求完成事件更早 + onHeadersReceived(callback: DataResponseCallback): void; + // 取消监听 HTTP Response Header 事件 + offHeadersReceived(callback: DataResponseCallback): void; + } interface UploadFileOptions { /** 开发者服务器 url */ url: string; @@ -137,30 +210,9 @@ declare namespace wx { * 客户端发起一个 HTTPS POST 请求, * 其中 Content-Type 为 multipart/form-data 。 */ - function uploadFile(options: UploadFileOptions): void; - - - interface DownloadFileOptions { - /** 下载资源的 url */ - url: string; - /** 下载资源的类型,用于客户端识别处理,有效值:image/audio/video */ - type?: string; - /** HTTP 请求 Header */ - header?: RequestHeader; - /** 下载成功后以 tempFilePath 的形式传给页面,res = {tempFilePath: '文件的临时路径'} */ - success?: TempFileResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 下载文件资源到本地。客户端直接发起一个 HTTP GET 请求, - * 把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。 - */ - function downloadFile(options: DownloadFileOptions): void; - + function uploadFile(options: UploadFileOptions): UploadTask; + // WebSocket interface ConnectSocketOptions { /** 开发者服务器接口地址,必须是 HTTPS 协议,且域名必须是后台配置的合法域名 */ url: string; @@ -440,6 +492,29 @@ declare namespace wx { */ function chooseVideo(options: ChooseVideoOptions): void; + // 数据缓存 + interface StorageInfo { + // 当前 storage 中所有的 key + keys: Array; + // 当前占用的空间大小, 单位 KB + currentSize: number; + // 限制的空间大小,单位 KB + limitSize: number; + } + type StorageInfoCallback = (res: StorageInfoOptions) => void; + interface StorageInfoOptions extends CommonCallbackOptions{ + success?: StorageInfoCallback; + } + /** + * getStorageInfo的同步版本 + */ + function getStorageInfoSync(): StorageInfo; + /** + * 异步获取当前storage的相关信息 + * @param options + */ + function getStorageInfo(options: StorageInfoOptions): void; + interface SetStorageOptions { /** 本地缓存中的指定的 key */ key: string; @@ -498,6 +573,9 @@ declare namespace wx { */ function clearStorageSync(): void; + // 媒体 + // 地图 TODO + interface LocationData { /** 纬度,浮点数,范围为-90~90,负数表示南纬 */ latitude: number; @@ -658,17 +736,36 @@ declare namespace wx { // 调试 TODO // 路由 - interface routerOptions { - + interface routerOptions extends CommonCallbackOptions{ + // 需要跳转的应用内非 tabBar 的页面的路径, 路径后可以带参数。参数与路径之间使用 ? 分隔,参数键与参数值用 = 相连,不同参数用 & 分隔;如 'path?key=value&key2=value2' + url: string; + } + interface NavigateBackOptions extends CommonCallbackOptions { + // 返回的页面数,如果 delta 大于现有页面数,则返回到首页。 + delta: number; } /** * 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。 */ - function navigateBack(): void; - function switchTab(): void; - function navigateTo(): void; - function reLaunch(): void; - function redirectTo(): void; + function navigateBack(options: NavigateBackOptions): void; + /** + * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 + * @param options + */ + function switchTab(options: routerOptions): void; + /** + * 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 wx.navigateBack 可以返回到原页面。 + * @param options + */ + function navigateTo(options: routerOptions): void; + /** + * 关闭所有页面,打开到应用内的某个页面 + */ + function reLaunch(options: routerOptions): void; + /** + * 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 + */ + function redirectTo(options: routerOptions): void; // 界面 // 交互 @@ -689,8 +786,11 @@ declare namespace wx { * 公共回调函数 */ interface CommonCallbackOptions { + // 接口调用成功回调函数 success?: ResponseCallback; + // 接口调用失败回调函数 fail?: ResponseCallback; + // 接口调用结束的回调函数 complete?: ResponseCallback; } @@ -798,7 +898,133 @@ declare namespace wx { // 背景 function setBackgroundTextStyle(): void; + interface BackgroundColorOptions extends CommonCallbackOptions{ + // 窗口的背景色,必须为十六进制颜色值 + backgroundColor?: string; + // 顶部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 + backgroundColorTop?: string; + // 底部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 + backgroundColorBottom?: string; + } function setBackgroundColor(): void; + // Tab Bar + interface TabBarItemOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + // tab 上的按钮文字 + text?: string; + // 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片 + iconPath?: string; + // 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效 + selectedIconPath?: string; + } + /** + * 动态设置 tabBar 某一项的内容 + * @param options + */ + function setTabBarItem(options: TabBarItemOptions): void; + + interface TabBarStyleOptions extends CommonCallbackOptions{ + // tab 上的文字默认颜色,HexColor + color: string; + // tab 上的文字选中时的颜色,HexColor + selectedColor: string; + // tab 的背景色,HexColor + backgroundColor: string; + // tabBar上边框的颜色, 仅支持 black/white + borderStyle: string; + } + /** + * 动态设置tabBar的整体样式 + */ + function setTabBarStyle(options: TabBarItemOptions): void; + + interface TabBarAnimationOptions extends CommonCallbackOptions{ + // 是否需要动画效果 + animation: boolean; + } + /** + * 隐藏tabBar + */ + function hideTabBar(options: TabBarAnimationOptions): void; + /** + * 显示tabBar + */ + function showTabBar(options: TabBarAnimationOptions): void; + + interface TabBarRedDotOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + } + /** + * 隐藏 tabBar 某一项的右上角的红点 + * @param options + */ + function hideTabBarRedDot(options: TabBarBadgeOptions): void; + /** + * 显示 tabBar 某一项的右上角的红点 + * @param options + */ + function showTabBarRedDot(options: TabBarRedDotOptions): void; + + interface TabBarBadgeOptions extends CommonCallbackOptions{ + // tabBar 的哪一项,从左边算起 + index: number; + // 显示的文本,超过 4 个字符则显示成 ... + text: string; + } + /** + * 移除 tabBar 某一项右上角的文本 + * @param options + */ + function removeTabBarBadge(options: TabBarRedDotOptions): void; + /** + * 为 tabBar 某一项的右上角添加文本 + * @param options + */ + function setTabBarBadge(options: TabBarBadgeOptions): void; + + interface FontDescOptions { + // 字体样式,可选值为 normal / italic / oblique + style?: string; + // 字体粗细,可选值为 normal / bold / 100 / 200../ 900 + weight?: string; + // 设置小型大写字母的字体显示文本,可选值为 normal / small-caps / inherit + variant?: string; + } + // 字体 + interface FontFaceOptions extends CommonCallbackOptions{ + // 定义的字体名称 + family: string; + // 字体资源的地址。建议格式为 TTF 和 WOFF,WOFF2 在低版本的iOS上会不兼容。 + source: string; + // 可选的字体描述符 + desc?: FontDescOptions; + } + function loadFontFace(options: FontFaceOptions): void; + + // 下拉刷新 + /** + * 停止当前页面下拉刷新。 + */ + function stopPullDownRefresh(options?: CommonCallbackOptions): void; + + /** + * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。 + */ + function startPullDownRefresh(options?: CommonCallbackOptions): void; + + // 滚动 + interface PageScrollToOptions extends CommonCallbackOptions{ + // 滚动到页面的目标位置,单位 px + scrollTop: number; + // 滚动动画的时长,单位 ms。默认300 + duration: number; + } + /** + * 将页面滚动到 + */ + function pageScrollTo(): void; interface AccelerometerData { /** X 轴 */ @@ -845,46 +1071,9 @@ declare namespace wx { */ function hideNavigationBarLoading(): void; - interface NavigateToOptions { - /** 需要跳转的应用内页面的路径 */ - url: string; - /** 成功获取系统信息的回调 */ - success?: ResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。 - * - * 注意:为了不让用户在使用小程序时造成困扰, - * 我们规定页面路径只能是五层,请尽量避免多层级的交互方式。 - */ - function navigateTo(options: NavigateToOptions): void; - - interface RedirectToOptions { - /** 需要跳转的应用内页面的路径 */ - url: string; - /** 成功获取系统信息的回调 */ - success?: ResponseCallback; - /** 接口调用失败的回调函数 */ - fail?: ResponseCallback; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: ResponseCallback; - } - /** - * 关闭当前页面,跳转到应用内的某个页面。 - */ - function redirectTo(options: RedirectToOptions): void; - - /** - * 关闭当前页面,回退前一页面。 - */ - function navigateBack(): void; - type TimingFunction = 'linear' | 'ease' | 'ease-in' | 'ease-in-out' | 'ease-out' | 'step-start' | 'step-end'; + // 动画 interface CreateAnimationOptions { /** 动画持续时间,单位ms,默认值 400 */ duration?: number; From df687b91cc8262fe9863b37779bad4b81518040e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:08:35 +0800 Subject: [PATCH 31/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=9C=B0=E5=9B=BE=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 160 ++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0882745c2f..6fdf7df480 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -574,7 +574,62 @@ declare namespace wx { function clearStorageSync(): void; // 媒体 - // 地图 TODO + // 地图 + interface LocationBaseOptions { + // 纬度,浮点数,范围为-90~90,负数表示南纬 + latitude: number; + // 经度,浮点数,范围为-180~180,负数表示西经 + longitude: number; + } + interface GetCenterLocationSuccCbOptions extends CommonCallbackOptions{ + success(res: LocationBaseOptions): void; + } + interface translateMarkerOptions extends CommonCallbackOptions{ + // 指定 marker + markerId: number; + // 指定 marker 移动到的目标点 + destination: LocationBaseOptions; + // 移动过程中是否自动旋转 marker + autoRotate: boolean; + // marker 的旋转角度 + rotate: number; + // 动画持续时长,平移与旋转分别计算 + duration?: number; + // 动画结束回调函数 + animationEnd?(): void; + } + interface zoomPointsOptions extends CommonCallbackOptions { + // 要显示在可视区域内的坐标点列表 + points: Array; + // 坐标点形成的矩形边缘到地图边缘的距离,单位像素。格式为[上,右,下,左],安卓上只能识别数组第一项,上下左右的padding一致。开发者工具暂不支持padding参数。 + padding?: Array; + } + interface GetReginSuccessCallbackOptions { + // 西南角经纬度 + southwest: number, + // 东北角经纬度 + northeast: number; + } + interface GetReginOptions extends CommonCallbackOptions{ + success?(callback: (res: GetReginSuccessCallbackOptions) => void): void; + } + interface GetScaleOptions extends CommonCallbackOptions{ + success?(callback: (res: {scale: number}) => void): void; + } + interface MapContext { + // 获取当前地图中心的经纬度。返回的是 gcj02 坐标系,可以用于 wx.openLocation() + getCenterLocation(options: GetCenterLocationSuccCbOptions): void; + // 将地图中心移动到当前定位点。需要配合map组件的show-location使用 + moveToLocation(): void; + // 平移marker,带动画 + translateMarker(options: translateMarkerOptions): void; + // 缩放视野展示所有经纬度 + includePoints(options: zoomPointsOptions): void; + // 获取当前地图的视野范围 + getRegion(options: GetReginOptions): void; + // 获取当前地图的缩放级别 + getScale(options: GetScaleOptions): void; + } interface LocationData { /** 纬度,浮点数,范围为-90~90,负数表示南纬 */ @@ -1440,6 +1495,8 @@ declare namespace wx { */ function hideKeyboard(): void; + // 开放接口 + // 登录 interface LoginResponse { /** 调用结果 */ errMsg: string; @@ -1458,6 +1515,10 @@ declare namespace wx { complete?: ResponseCallback; } + /** + * 检查登录态是否过期。 + */ + function checkSession(options: CommonCallbackOptions): void; /** * 调用接口获取登录凭证(code)进而换取用户登录态信息, * 包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key)。 @@ -1465,6 +1526,51 @@ declare namespace wx { */ function login(option: LoginOptions): void; + type envVersion = 'develop' | 'trial' | 'release'; + interface NavigateToMiniProgramOptions extends CommonCallbackOptions { + // 要打开的小程序 appId + appId: string; + // 打开的页面路径,如果为空则打开首页 + path?: string; + // 需要传递给目标小程序的数据,目标小程序可在 App.onLaunch,App.onShow 中获取到这份数据。 + extraData?: object; + // 要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版。 + envVersion?: envVersion; + } + /** + * 打开另一个小程序 + */ + function navigateToMiniProgram(options: NavigateToMiniProgramOptions): void; + interface NavigateBackMiniProgramOptions extends CommonCallbackOptions { + // 需要返回给上一个小程序的数据,上一个小程序可在 App.onShow 中获取到这份数据。 + extraData: object; + } + /** + * 返回到上一个小程序。只有在当前小程序是被其他小程序打开时可以调用成功 + */ + function navigateBackMiniProgram(options: NavigateBackMiniProgramOptions): void; + + // 帐号信息 + interface AccountInfo { + // 小程序帐号信息 + miniProgram: { + // 小程序appId + appId: string; + }; + // 插件帐号信息(仅在插件中调用时包含这一项) + Plugin: { + // 插件appId + appId: string; + // 插件版本号 + vetsion: string + }; + } + /** + * 获取当前账号信息 + */ + function getAccountInfoSync(): AccountInfo; + + // 帐号信息 interface UserInfo { nickName: string; avatarUrl: string; @@ -1515,11 +1621,63 @@ declare namespace wx { /** 接口调用结束的回调函数(调用成功、失败都会执行) */ complete?: ResponseCallback; } + // 支付 /** * 发起微信支付。 */ function requestPayment(options: RequestPaymentOptions): void; + + // 授权 + /** + * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html + * 用户信息 wx.getUserInfo、 + * 地理位置 wx.getLocation,wx.chooseLocation、 + * 通讯地址 wx.chooseAddress、 + * 发票抬头 wx.chooseInvoiceTitle、 + * 获取发票 wx.chooseInvoice、 + * 微信运动步数 wx.getWeRunData、 + * 录音功能 wx.startRecord、 + * 保存到相册 wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum、 + * 摄像头 组件 + */ + type Scope = 'userInfo' | 'userLocation' | 'address' | 'invoiceTitle' | 'invoice' | 'werun' | 'record' | 'writePhotosAlbum' | 'camera'; + interface AuthorizeOptions extends CommonCallbackOptions { + // 需要获取权限的 scope,详见 scope 列表 + scope: Scope; + } + /** + * 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。 + */ + function authorize(options: AuthorizeOptions): void; + + // 设置 + interface SettingOptions extends CommonCallbackOptions{ + success?(res: AuthSetting): void; + } + /** + * 调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。 + */ + function openSetting(options: SettingOptions): void; + /** + * 获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。 + */ + function getSetting(options: SettingOptions): void; + /** + * 用户授权结果,参考 type Scope + */ + interface AuthSetting { + 'scope.userInfo': boolean; + 'scope.userLocation': boolean; + 'scope.address': boolean; + 'scope.invoiceTitle': boolean; + 'scope.invoice': boolean; + 'scope.werun': boolean; + 'scope.record': boolean; + 'scope.writePhotosAlbum': boolean; + 'scope.camera': boolean; + } } +// end of wx namespace interface Page { From 9d8bc4fa109254f1d4d4216a8ba1b094fecc340d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:16:37 +0800 Subject: [PATCH 32/37] =?UTF-8?q?=E5=A2=9E=E5=8A=A0author=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/weapp-api/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 6fdf7df480..0cbaf8b97b 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for weapp // Project: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html -// Definitions by: vargeek +// Definitions by: vargeek & pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace wx { From c8eda895a2187bfc5a7c4b0ec1fe9830ffe57ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Tue, 8 Jan 2019 16:59:03 +0800 Subject: [PATCH 33/37] add author and TypeScript version --- types/weapp-api/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 0cbaf8b97b..4350eb1d25 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1,7 +1,9 @@ // Type definitions for weapp // Project: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html -// Definitions by: vargeek & pbestz +// Definitions by: vargeek +// pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2.1 declare namespace wx { // import startPullDownRefresh = swan.startPullDownRefresh; From b765e282d5adf88f96a9c4c5fcc1486dde434fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 11 Jan 2019 15:56:23 +0800 Subject: [PATCH 34/37] fix CI build failed --- types/weapp-api/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 4350eb1d25..1007429649 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,7 +3,6 @@ // Definitions by: vargeek // pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.2.1 declare namespace wx { // import startPullDownRefresh = swan.startPullDownRefresh; From e2a88a0709d020936a4e7b45e694133087e68831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 11 Jan 2019 16:04:36 +0800 Subject: [PATCH 35/37] fix CI build errors --- types/weapp-api/tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/weapp-api/tsconfig.json b/types/weapp-api/tsconfig.json index 74812f3d05..9df5bc5879 100644 --- a/types/weapp-api/tsconfig.json +++ b/types/weapp-api/tsconfig.json @@ -19,7 +19,6 @@ }, "files": [ "index.d.ts", - "weapp-api-tests.ts", - "../baidu-app/index.d.ts" + "weapp-api-tests.ts" ] } From 19867156a106c08343113fe899eeb80fff260dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 11 Jan 2019 16:16:03 +0800 Subject: [PATCH 36/37] fix CI build error. export App --- types/weapp-api/index.d.ts | 13 +++++++++++-- types/weapp-api/weapp-api-tests.ts | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 1007429649..3bc0200fa6 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -1728,7 +1728,7 @@ declare function getApp(): App; * @param delay 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 * @param rest param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */ -declare function setTimeout(callback: any, delay: number, rest: any): number; +declare function setTimeout(callback: any, delay: number, rest?: any): number; /** * 取消由 setTimeout 设置的定时器。 @@ -1750,4 +1750,13 @@ declare function setInterval(callback: any, delay: number, rest: any): number; */ declare function clearInterval(timeoutID: number): number; -export default wx +export { + wx, + App, + Page, + getApp, + setTimeout, + clearTimeout, + setInterval, + clearInterval +} diff --git a/types/weapp-api/weapp-api-tests.ts b/types/weapp-api/weapp-api-tests.ts index 5b2b0616a2..73f86e31f5 100644 --- a/types/weapp-api/weapp-api-tests.ts +++ b/types/weapp-api/weapp-api-tests.ts @@ -1,4 +1,4 @@ -import wx from './index' +import {wx, App, Page, getApp, setTimeout, clearTimeout, setInterval, clearInterval} from './index' App({ onLaunch: function () { //调用API从本地缓存中获取数据 From a7a94fc20dd7616abda1306b0cdcc637cf41dd69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=B9=8F=E6=B3=A2?= Date: Fri, 11 Jan 2019 16:35:53 +0800 Subject: [PATCH 37/37] add TS version in header --- types/weapp-api/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/weapp-api/index.d.ts b/types/weapp-api/index.d.ts index 3bc0200fa6..6c2b4d8ec0 100644 --- a/types/weapp-api/index.d.ts +++ b/types/weapp-api/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: vargeek // pbestz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 declare namespace wx { // import startPullDownRefresh = swan.startPullDownRefresh;