mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #33678 from dcloudio/master
Added new types for uni-app
This commit is contained in:
Vendored
+6232
File diff suppressed because it is too large
Load Diff
Vendored
+234
@@ -0,0 +1,234 @@
|
||||
declare namespace App {
|
||||
interface LaunchOptions {
|
||||
query: number;
|
||||
}
|
||||
|
||||
interface ReferrerInfo {
|
||||
/**
|
||||
* 来源小程序或公众号或App的 appId
|
||||
*
|
||||
* 以下场景支持返回 referrerInfo.appId:
|
||||
* - 1020(公众号 profile 页相关小程序列表): appId
|
||||
* - 1035(公众号自定义菜单):来源公众号 appId
|
||||
* - 1036(App 分享消息卡片):来源应用 appId
|
||||
* - 1037(小程序打开小程序):来源小程序 appId
|
||||
* - 1038(从另一个小程序返回):来源小程序 appId
|
||||
* - 1043(公众号模板消息):来源公众号 appId
|
||||
*/
|
||||
appId: string;
|
||||
/** 来源小程序传过来的数据,scene=1037或1038时支持 */
|
||||
extraData?: any;
|
||||
}
|
||||
|
||||
type SceneValues = 1001
|
||||
| 1005
|
||||
| 1006
|
||||
| 1007
|
||||
| 1008
|
||||
| 1011
|
||||
| 1012
|
||||
| 1013
|
||||
| 1014
|
||||
| 1017
|
||||
| 1019
|
||||
| 1020
|
||||
| 1022
|
||||
| 1023
|
||||
| 1024
|
||||
| 1025
|
||||
| 1026
|
||||
| 1027
|
||||
| 1028
|
||||
| 1029
|
||||
| 1030
|
||||
| 1031
|
||||
| 1032
|
||||
| 1034
|
||||
| 1035
|
||||
| 1036
|
||||
| 1037
|
||||
| 1038
|
||||
| 1039
|
||||
| 1042
|
||||
| 1043
|
||||
| 1044
|
||||
| 1045
|
||||
| 1046
|
||||
| 1047
|
||||
| 1048
|
||||
| 1049
|
||||
| 1052
|
||||
| 1053
|
||||
| 1054
|
||||
| 1056
|
||||
| 1057
|
||||
| 1058
|
||||
| 1059
|
||||
| 1064
|
||||
| 1067
|
||||
| 1068
|
||||
| 1069
|
||||
| 1071
|
||||
| 1072
|
||||
| 1073
|
||||
| 1074
|
||||
| 1077
|
||||
| 1078
|
||||
| 1079
|
||||
| 1081
|
||||
| 1082
|
||||
| 1084
|
||||
| 1089
|
||||
| 1090
|
||||
| 1091
|
||||
| 1092
|
||||
| 1095
|
||||
| 1096
|
||||
| 1097
|
||||
| 1099
|
||||
| 1102
|
||||
| 1103
|
||||
| 1104
|
||||
| number;
|
||||
|
||||
interface LaunchShowOption {
|
||||
/** 打开小程序的路径 */
|
||||
path: string;
|
||||
/** 打开小程序的query */
|
||||
query: AnyObject;
|
||||
/**
|
||||
* 打开小程序的场景值
|
||||
* - 1001: 发现栏小程序主入口,「最近使用」列表(基础库2.2.4版本起包含「我的小程序」列表)
|
||||
* - 1005: 顶部搜索框的搜索结果页
|
||||
* - 1006: 发现栏小程序主入口搜索框的搜索结果页
|
||||
* - 1007: 单人聊天会话中的小程序消息卡片
|
||||
* - 1008: 群聊会话中的小程序消息卡片
|
||||
* - 1011: 扫描二维码
|
||||
* - 1012: 长按图片识别二维码
|
||||
* - 1013: 手机相册选取二维码
|
||||
* - 1014: 小程序模板消息
|
||||
* - 1017: 前往体验版的入口页
|
||||
* - 1019: 微信钱包
|
||||
* - 1020: 公众号 profile 页相关小程序列表
|
||||
* - 1022: 聊天顶部置顶小程序入口
|
||||
* - 1023: 安卓系统桌面图标
|
||||
* - 1024: 小程序 profile 页
|
||||
* - 1025: 扫描一维码
|
||||
* - 1026: 附近小程序列表
|
||||
* - 1027: 顶部搜索框搜索结果页「使用过的小程序」列表
|
||||
* - 1028: 我的卡包
|
||||
* - 1029: 卡券详情页
|
||||
* - 1030: 自动化测试下打开小程序
|
||||
* - 1031: 长按图片识别一维码
|
||||
* - 1032: 手机相册选取一维码
|
||||
* - 1034: 微信支付完成页
|
||||
* - 1035: 公众号自定义菜单
|
||||
* - 1036: App 分享消息卡片
|
||||
* - 1037: 小程序打开小程序
|
||||
* - 1038: 从另一个小程序返回
|
||||
* - 1039: 摇电视
|
||||
* - 1042: 添加好友搜索框的搜索结果页
|
||||
* - 1043: 公众号模板消息
|
||||
* - 1044: 带 shareTicket 的小程序消息卡片 [详情]((转发#获取更多转发信息))
|
||||
* - 1045: 朋友圈广告
|
||||
* - 1046: 朋友圈广告详情页
|
||||
* - 1047: 扫描小程序码
|
||||
* - 1048: 长按图片识别小程序码
|
||||
* - 1049: 手机相册选取小程序码
|
||||
* - 1052: 卡券的适用门店列表
|
||||
* - 1053: 搜一搜的结果页
|
||||
* - 1054: 顶部搜索框小程序快捷入口
|
||||
* - 1056: 音乐播放器菜单
|
||||
* - 1057: 钱包中的银行卡详情页
|
||||
* - 1058: 公众号文章
|
||||
* - 1059: 体验版小程序绑定邀请页
|
||||
* - 1064: 微信连Wi-Fi状态栏
|
||||
* - 1067: 公众号文章广告
|
||||
* - 1068: 附近小程序列表广告
|
||||
* - 1069: 移动应用
|
||||
* - 1071: 钱包中的银行卡列表页
|
||||
* - 1072: 二维码收款页面
|
||||
* - 1073: 客服消息列表下发的小程序消息卡片
|
||||
* - 1074: 公众号会话下发的小程序消息卡片
|
||||
* - 1077: 摇周边
|
||||
* - 1078: 连Wi-Fi成功页
|
||||
* - 1079: 微信游戏中心
|
||||
* - 1081: 客服消息下发的文字链
|
||||
* - 1082: 公众号会话下发的文字链
|
||||
* - 1084: 朋友圈广告原生页
|
||||
* - 1089: 微信聊天主界面下拉,「最近使用」栏(基础库2.2.4版本起包含「我的小程序」栏)
|
||||
* - 1090: 长按小程序右上角菜单唤出最近使用历史
|
||||
* - 1091: 公众号文章商品卡片
|
||||
* - 1092: 城市服务入口
|
||||
* - 1095: 小程序广告组件
|
||||
* - 1096: 聊天记录
|
||||
* - 1097: 微信支付签约页
|
||||
* - 1099: 页面内嵌插件
|
||||
* - 1102: 公众号 profile 页服务预览
|
||||
* - 1103: 发现栏小程序主入口,「我的小程序」列表(基础库2.2.4版本起废弃)
|
||||
* - 1104: 微信聊天主界面下拉,「我的小程序」栏(基础库2.2.4版本起废弃)
|
||||
*/
|
||||
scene: SceneValues;
|
||||
/** shareTicket,详见 [获取更多转发信息]((转发#获取更多转发信息)) */
|
||||
shareTicket: string;
|
||||
/** 当场景为由从另一个小程序或公众号或App打开时,返回此字段 */
|
||||
referrerInfo?: ReferrerInfo;
|
||||
}
|
||||
|
||||
interface PageNotFoundOption {
|
||||
/** 不存在页面的路径 */
|
||||
path: string;
|
||||
/** 打开不存在页面的 query */
|
||||
query: AnyObject;
|
||||
/** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */
|
||||
isEntryPage: boolean;
|
||||
}
|
||||
|
||||
interface AppInstance<T extends AnyObject = {}> {
|
||||
/**
|
||||
* 生命周期回调—监听应用初始化
|
||||
* 应用初始化完成时触发,全局只触发一次。
|
||||
*/
|
||||
onLaunch?(options?: LaunchShowOption): void;
|
||||
/**
|
||||
* 生命周期回调—监听应用显示
|
||||
* 应用启动,或从后台进入前台显示时
|
||||
*/
|
||||
onShow?(options?: LaunchShowOption): void;
|
||||
/**
|
||||
* 生命周期回调—监听应用隐藏
|
||||
* 应用从前台进入后台时
|
||||
*/
|
||||
onHide?(): void;
|
||||
/**
|
||||
* 错误监听函数
|
||||
* 应用发生脚本错误,或者 api
|
||||
*/
|
||||
onError?(/** 错误信息,包含堆栈 */error?: string): void;
|
||||
/**
|
||||
* 页面不存在监听函数
|
||||
* 应用要打开的页面不存在时触发,会带上页面信息回调该函数
|
||||
*
|
||||
* **注意:**
|
||||
* 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。
|
||||
* 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。
|
||||
*
|
||||
*/
|
||||
onPageNotFound?(options?: PageNotFoundOption): void;
|
||||
}
|
||||
|
||||
type AppConstructor = <T extends AnyObject & AppInstance>(
|
||||
options: AppInstance<T> & T,
|
||||
) => void;
|
||||
|
||||
interface GetAppOption {
|
||||
/**
|
||||
* 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包
|
||||
*/
|
||||
allowDefault: boolean;
|
||||
}
|
||||
|
||||
type GetApp = <T extends AnyObject>(opts?: GetAppOption) => AppInstance<T> & T;
|
||||
}
|
||||
|
||||
declare const getApp: App.GetApp;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
type AnyObject = Record<string, any>;
|
||||
|
||||
type KVInfer<T> = { [K in keyof T]: T[K] };
|
||||
|
||||
type Void<T> = T | undefined | null;
|
||||
Vendored
+152
@@ -0,0 +1,152 @@
|
||||
declare namespace Page {
|
||||
interface CustomShareContent {
|
||||
/**
|
||||
* 转发标题。默认值:当前应用名称
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,默认值:使用默认截图
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
interface PageScrollOption {
|
||||
/**
|
||||
* 页面在垂直方向已滚动的距离(单位px)
|
||||
*/
|
||||
scrollTop: number;
|
||||
}
|
||||
|
||||
interface ShareAppMessageOption {
|
||||
/**
|
||||
* 转发事件来源。
|
||||
* 可选值:
|
||||
* - `button`:页面内转发按钮;
|
||||
* - `menu`:右上角转发菜单。
|
||||
*
|
||||
*/
|
||||
from: "button" | "menu" | string;
|
||||
/**
|
||||
* 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined`
|
||||
*/
|
||||
target: any;
|
||||
/**
|
||||
* 页面中包含`<web-view>`组件时,返回当前`<web-view>`的url
|
||||
*/
|
||||
webViewUrl?: string;
|
||||
}
|
||||
|
||||
interface TabItemTapOption {
|
||||
/**
|
||||
* 被点击tabItem的序号,从0开始
|
||||
*/
|
||||
index: string;
|
||||
/**
|
||||
* 被点击tabItem的页面路径
|
||||
*/
|
||||
pagePath: string;
|
||||
/**
|
||||
* 被点击tabItem的按钮文字
|
||||
*/
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface PageInstanceBaseProps<D extends AnyObject = any> {
|
||||
/**
|
||||
* 到当前页面的路径,类型为`String`
|
||||
*/
|
||||
route?: string;
|
||||
}
|
||||
|
||||
interface PageInstance<D extends AnyObject = any, T extends AnyObject = any> extends PageInstanceBaseProps<D> {
|
||||
/**
|
||||
* 生命周期回调—监听页面加载
|
||||
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。
|
||||
*/
|
||||
onLoad?(
|
||||
/**
|
||||
* 打开当前页面路径中的参数
|
||||
*/
|
||||
query?: { [queryKey: string]: string },
|
||||
): void;
|
||||
/**
|
||||
* 生命周期回调—监听页面显示
|
||||
* 页面显示/切入前台时触发。
|
||||
*/
|
||||
onShow?(): void;
|
||||
/**
|
||||
* 生命周期回调—监听页面初次渲染完成
|
||||
* 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
|
||||
*/
|
||||
onReady?(): void;
|
||||
/**
|
||||
* 生命周期回调—监听页面隐藏
|
||||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,应用切入后台等。
|
||||
*/
|
||||
onHide?(): void;
|
||||
/**
|
||||
* 生命周期回调—监听页面卸载
|
||||
* 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。
|
||||
*/
|
||||
onUnload?(): void;
|
||||
/**
|
||||
* 监听用户下拉动作
|
||||
* 监听用户下拉刷新事件。
|
||||
* - 需要在`pages.json`的页面配置中开启`enablePullDownRefresh`。
|
||||
* - 可以通过`uni.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
||||
* - 当处理完数据刷新后,`uni.stopPullDownRefresh`可以停止当前页面的下拉刷新。
|
||||
*/
|
||||
onPullDownRefresh?(): void;
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
* 监听用户上拉触底事件。
|
||||
* - 可以在`pages.json`的页面配置中设置触发距离`onReachBottomDistance`。
|
||||
* - 在触发距离内滑动期间,本事件只会被触发一次。
|
||||
*/
|
||||
onReachBottom?(): void;
|
||||
/**
|
||||
* 用户点击右上角转发
|
||||
* 监听用户点击页面内转发按钮(`<button>` 组件 `open-type="share"`)或右上角菜单“转发”按钮的行为,并自定义转发内容。
|
||||
* **注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮**
|
||||
* 此事件需要 return 一个 Object,用于自定义转发内容
|
||||
*/
|
||||
onShareAppMessage?(
|
||||
/**
|
||||
* 分享发起来源参数
|
||||
*/
|
||||
options?: ShareAppMessageOption,
|
||||
): CustomShareContent;
|
||||
/**
|
||||
* 页面滚动触发事件的处理函数
|
||||
* 监听用户滑动页面事件。
|
||||
*/
|
||||
onPageScroll?(
|
||||
/**
|
||||
* 页面滚动参数
|
||||
*/
|
||||
options?: PageScrollOption,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* 当前是 tab 页时,点击 tab 时触发
|
||||
*/
|
||||
onTabItemTap?(
|
||||
/**
|
||||
* tab 点击参数
|
||||
*/
|
||||
options?: TabItemTapOption,
|
||||
): void;
|
||||
}
|
||||
|
||||
type PageConstructor = <T extends AnyObject & PageInstance>(
|
||||
options: PageInstance<AnyObject, T> & T,
|
||||
) => void;
|
||||
|
||||
type GetCurrentPages = <T extends AnyObject = {}>() => Array<PageInstance<AnyObject, T> & T>;
|
||||
}
|
||||
|
||||
declare const getCurrentPages: Page.GetCurrentPages;
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import Vue from "vue";
|
||||
|
||||
declare module "*.vue" {
|
||||
export default Vue;
|
||||
}
|
||||
|
||||
declare module "vue/types/options" {
|
||||
type Hooks = App.AppInstance & Page.PageInstance;
|
||||
interface ComponentOptions<V extends Vue> extends Hooks {
|
||||
/**
|
||||
* 组件类型
|
||||
*/
|
||||
mpType?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"vue": "^2.6.8"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"lib/app.d.ts",
|
||||
"lib/page.d.ts",
|
||||
"lib/common.d.ts",
|
||||
"lib/vue.d.ts",
|
||||
"uni-app-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
uni.request({
|
||||
url: 'https://dcloud.io',
|
||||
success(res) {
|
||||
uni.showToast({
|
||||
title: res.data
|
||||
});
|
||||
},
|
||||
fail(error) {
|
||||
uni.showToast({
|
||||
title: error.errMsg
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
uni.navigateTo({
|
||||
url: 'index/index'
|
||||
});
|
||||
|
||||
uni.showLoading({
|
||||
title: 'test'
|
||||
});
|
||||
Reference in New Issue
Block a user