feat: init omix typescript version
This commit is contained in:
parent
d0aac946eb
commit
51720771aa
|
@ -0,0 +1,30 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
App({
|
||||
onLaunch: function () {
|
||||
var _this = this;
|
||||
var logs = wx.getStorageSync('logs') || [];
|
||||
logs.unshift(Date.now());
|
||||
wx.setStorageSync('logs', logs);
|
||||
wx.login({
|
||||
success: function (_res) {
|
||||
}
|
||||
});
|
||||
wx.getSetting({
|
||||
success: function (res) {
|
||||
if (res.authSetting['scope.userInfo']) {
|
||||
wx.getUserInfo({
|
||||
success: function (res) {
|
||||
_this.globalData.userInfo = res.userInfo;
|
||||
if (_this.userInfoReadyCallback) {
|
||||
_this.userInfoReadyCallback(res.userInfo);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
globalData: {}
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYXBwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBUUEsR0FBRyxDQUFTO0lBQ1YsUUFBUTtRQUFSLGlCQWdDQztRQTlCQyxJQUFJLElBQUksR0FBYSxFQUFFLENBQUMsY0FBYyxDQUFDLE1BQU0sQ0FBQyxJQUFJLEVBQUUsQ0FBQTtRQUNwRCxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxHQUFHLEVBQUUsQ0FBQyxDQUFBO1FBQ3hCLEVBQUUsQ0FBQyxjQUFjLENBQUMsTUFBTSxFQUFFLElBQUksQ0FBQyxDQUFBO1FBRy9CLEVBQUUsQ0FBQyxLQUFLLENBQUM7WUFDUCxPQUFPLFlBQUMsSUFBSTtZQUdaLENBQUM7U0FDRixDQUFDLENBQUE7UUFFRixFQUFFLENBQUMsVUFBVSxDQUFDO1lBQ1osT0FBTyxFQUFFLFVBQUMsR0FBRztnQkFDWCxJQUFJLEdBQUcsQ0FBQyxXQUFXLENBQUMsZ0JBQWdCLENBQUMsRUFBRTtvQkFFckMsRUFBRSxDQUFDLFdBQVcsQ0FBQzt3QkFDYixPQUFPLEVBQUUsVUFBQSxHQUFHOzRCQUVWLEtBQUksQ0FBQyxVQUFVLENBQUMsUUFBUSxHQUFHLEdBQUcsQ0FBQyxRQUFRLENBQUE7NEJBR3ZDLElBQUksS0FBSSxDQUFDLHFCQUFxQixFQUFFO2dDQUM5QixLQUFJLENBQUMscUJBQXFCLENBQUMsR0FBRyxDQUFDLFFBQVEsQ0FBQyxDQUFBOzZCQUN6Qzt3QkFDSCxDQUFDO3FCQUNGLENBQUMsQ0FBQTtpQkFDSDtZQUNILENBQUM7U0FDRixDQUFDLENBQUE7SUFDSixDQUFDO0lBQ0QsVUFBVSxFQUFFLEVBQ1g7Q0FDRixDQUFDLENBQUEiLCJzb3VyY2VzQ29udGVudCI6WyIvL2FwcC50c1xuZXhwb3J0IGludGVyZmFjZSBJTXlBcHAge1xuICB1c2VySW5mb1JlYWR5Q2FsbGJhY2s/KHJlczogd3guVXNlckluZm8pOiB2b2lkXG4gIGdsb2JhbERhdGE6IHtcbiAgICB1c2VySW5mbz86IHd4LlVzZXJJbmZvXG4gIH1cbn1cblxuQXBwPElNeUFwcD4oe1xuICBvbkxhdW5jaCgpIHtcbiAgICAvLyDlsZXnpLrmnKzlnLDlrZjlgqjog73liptcbiAgICB2YXIgbG9nczogbnVtYmVyW10gPSB3eC5nZXRTdG9yYWdlU3luYygnbG9ncycpIHx8IFtdXG4gICAgbG9ncy51bnNoaWZ0KERhdGUubm93KCkpXG4gICAgd3guc2V0U3RvcmFnZVN5bmMoJ2xvZ3MnLCBsb2dzKVxuXG4gICAgLy8g55m75b2VXG4gICAgd3gubG9naW4oe1xuICAgICAgc3VjY2VzcyhfcmVzKSB7XG4gICAgICAgIC8vIGNvbnNvbGUubG9nKF9yZXMuY29kZSlcbiAgICAgICAgLy8g5Y+R6YCBIF9yZXMuY29kZSDliLDlkI7lj7DmjaLlj5Ygb3BlbklkLCBzZXNzaW9uS2V5LCB1bmlvbklkXG4gICAgICB9XG4gICAgfSlcbiAgICAvLyDojrflj5bnlKjmiLfkv6Hmga9cbiAgICB3eC5nZXRTZXR0aW5nKHtcbiAgICAgIHN1Y2Nlc3M6IChyZXMpID0+IHtcbiAgICAgICAgaWYgKHJlcy5hdXRoU2V0dGluZ1snc2NvcGUudXNlckluZm8nXSkge1xuICAgICAgICAgIC8vIOW3sue7j+aOiOadg++8jOWPr+S7peebtOaOpeiwg+eUqCBnZXRVc2VySW5mbyDojrflj5blpLTlg4/mmLXnp7DvvIzkuI3kvJrlvLnmoYZcbiAgICAgICAgICB3eC5nZXRVc2VySW5mbyh7XG4gICAgICAgICAgICBzdWNjZXNzOiByZXMgPT4ge1xuICAgICAgICAgICAgICAvLyDlj6/ku6XlsIYgcmVzIOWPkemAgee7meWQjuWPsOino+eggeWHuiB1bmlvbklkXG4gICAgICAgICAgICAgIHRoaXMuZ2xvYmFsRGF0YS51c2VySW5mbyA9IHJlcy51c2VySW5mb1xuICAgICAgICAgICAgICAvLyDnlLHkuo4gZ2V0VXNlckluZm8g5piv572R57uc6K+35rGC77yM5Y+v6IO95Lya5ZyoIFBhZ2Uub25Mb2FkIOS5i+WQjuaJjei/lOWbnlxuICAgICAgICAgICAgICAvLyDmiYDku6XmraTlpITliqDlhaUgY2FsbGJhY2sg5Lul6Ziy5q2i6L+Z56eN5oOF5Ya1XG4gICAgICAgICAgICAgIGlmICh0aGlzLnVzZXJJbmZvUmVhZHlDYWxsYmFjaykge1xuICAgICAgICAgICAgICAgIHRoaXMudXNlckluZm9SZWFkeUNhbGxiYWNrKHJlcy51c2VySW5mbylcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pXG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9KVxuICB9LFxuICBnbG9iYWxEYXRhOiB7XG4gIH1cbn0pIl19
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/logs/logs"
|
||||
],
|
||||
"window": {
|
||||
"backgroundTextStyle": "light",
|
||||
"navigationBarBackgroundColor": "#fff",
|
||||
"navigationBarTitleText": "WeChat",
|
||||
"navigationBarTextStyle": "black"
|
||||
},
|
||||
"sitemapLocation": "sitemap.json"
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
//app.ts
|
||||
export interface IMyApp {
|
||||
userInfoReadyCallback?(res: wx.UserInfo): void
|
||||
globalData: {
|
||||
userInfo?: wx.UserInfo
|
||||
}
|
||||
}
|
||||
|
||||
App<IMyApp>({
|
||||
onLaunch() {
|
||||
// 展示本地存储能力
|
||||
var logs: number[] = wx.getStorageSync('logs') || []
|
||||
logs.unshift(Date.now())
|
||||
wx.setStorageSync('logs', logs)
|
||||
|
||||
// 登录
|
||||
wx.login({
|
||||
success(_res) {
|
||||
// console.log(_res.code)
|
||||
// 发送 _res.code 到后台换取 openId, sessionKey, unionId
|
||||
}
|
||||
})
|
||||
// 获取用户信息
|
||||
wx.getSetting({
|
||||
success: (res) => {
|
||||
if (res.authSetting['scope.userInfo']) {
|
||||
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
|
||||
wx.getUserInfo({
|
||||
success: res => {
|
||||
// 可以将 res 发送给后台解码出 unionId
|
||||
this.globalData.userInfo = res.userInfo
|
||||
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
||||
// 所以此处加入 callback 以防止这种情况
|
||||
if (this.userInfoReadyCallback) {
|
||||
this.userInfoReadyCallback(res.userInfo)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
globalData: {
|
||||
}
|
||||
})
|
|
@ -0,0 +1,10 @@
|
|||
/**app.wxss**/
|
||||
.container {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 200rpx 0;
|
||||
box-sizing: border-box;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var app = getApp();
|
||||
Page({
|
||||
data: {
|
||||
motto: '点击 “编译” 以构建',
|
||||
userInfo: {},
|
||||
hasUserInfo: false,
|
||||
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
||||
},
|
||||
bindViewTap: function () {
|
||||
wx.navigateTo({
|
||||
url: '../logs/logs'
|
||||
});
|
||||
},
|
||||
onLoad: function () {
|
||||
var _this = this;
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
hasUserInfo: true,
|
||||
});
|
||||
}
|
||||
else if (this.data.canIUse) {
|
||||
app.userInfoReadyCallback = function (res) {
|
||||
_this.setData({
|
||||
userInfo: res,
|
||||
hasUserInfo: true
|
||||
});
|
||||
};
|
||||
}
|
||||
else {
|
||||
wx.getUserInfo({
|
||||
success: function (res) {
|
||||
app.globalData.userInfo = res.userInfo;
|
||||
_this.setData({
|
||||
userInfo: res.userInfo,
|
||||
hasUserInfo: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
getUserInfo: function (e) {
|
||||
console.log(e);
|
||||
app.globalData.userInfo = e.detail.userInfo;
|
||||
this.setData({
|
||||
userInfo: e.detail.userInfo,
|
||||
hasUserInfo: true
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUlBLElBQU0sR0FBRyxHQUFHLE1BQU0sRUFBVSxDQUFBO0FBRTVCLElBQUksQ0FBQztJQUNILElBQUksRUFBRTtRQUNKLEtBQUssRUFBRSxhQUFhO1FBQ3BCLFFBQVEsRUFBRSxFQUFFO1FBQ1osV0FBVyxFQUFFLEtBQUs7UUFDbEIsT0FBTyxFQUFFLEVBQUUsQ0FBQyxPQUFPLENBQUMsOEJBQThCLENBQUM7S0FDcEQ7SUFFRCxXQUFXO1FBQ1QsRUFBRSxDQUFDLFVBQVUsQ0FBQztZQUNaLEdBQUcsRUFBRSxjQUFjO1NBQ3BCLENBQUMsQ0FBQTtJQUNKLENBQUM7SUFDRCxNQUFNO1FBQU4saUJBMkJDO1FBMUJDLElBQUksR0FBRyxDQUFDLFVBQVUsQ0FBQyxRQUFRLEVBQUU7WUFDM0IsSUFBSSxDQUFDLE9BQVEsQ0FBQztnQkFDWixRQUFRLEVBQUUsR0FBRyxDQUFDLFVBQVUsQ0FBQyxRQUFRO2dCQUNqQyxXQUFXLEVBQUUsSUFBSTthQUNsQixDQUFDLENBQUE7U0FDSDthQUFNLElBQUksSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLEVBQUM7WUFHM0IsR0FBRyxDQUFDLHFCQUFxQixHQUFHLFVBQUMsR0FBRztnQkFDOUIsS0FBSSxDQUFDLE9BQVEsQ0FBQztvQkFDWixRQUFRLEVBQUUsR0FBRztvQkFDYixXQUFXLEVBQUUsSUFBSTtpQkFDbEIsQ0FBQyxDQUFBO1lBQ0osQ0FBQyxDQUFBO1NBQ0Y7YUFBTTtZQUVMLEVBQUUsQ0FBQyxXQUFXLENBQUM7Z0JBQ2IsT0FBTyxFQUFFLFVBQUEsR0FBRztvQkFDVixHQUFHLENBQUMsVUFBVSxDQUFDLFFBQVEsR0FBRyxHQUFHLENBQUMsUUFBUSxDQUFBO29CQUN0QyxLQUFJLENBQUMsT0FBUSxDQUFDO3dCQUNaLFFBQVEsRUFBRSxHQUFHLENBQUMsUUFBUTt3QkFDdEIsV0FBVyxFQUFFLElBQUk7cUJBQ2xCLENBQUMsQ0FBQTtnQkFDSixDQUFDO2FBQ0YsQ0FBQyxDQUFBO1NBQ0g7SUFDSCxDQUFDO0lBRUQsV0FBVyxZQUFDLENBQU07UUFDaEIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUNkLEdBQUcsQ0FBQyxVQUFVLENBQUMsUUFBUSxHQUFHLENBQUMsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFBO1FBQzNDLElBQUksQ0FBQyxPQUFRLENBQUM7WUFDWixRQUFRLEVBQUUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxRQUFRO1lBQzNCLFdBQVcsRUFBRSxJQUFJO1NBQ2xCLENBQUMsQ0FBQTtJQUNKLENBQUM7Q0FDRixDQUFDLENBQUEiLCJzb3VyY2VzQ29udGVudCI6WyIvL2luZGV4LmpzXG4vL+iOt+WPluW6lOeUqOWunuS+i1xuaW1wb3J0IHsgSU15QXBwIH0gZnJvbSAnLi4vLi4vYXBwJ1xuXG5jb25zdCBhcHAgPSBnZXRBcHA8SU15QXBwPigpXG5cblBhZ2Uoe1xuICBkYXRhOiB7XG4gICAgbW90dG86ICfngrnlh7sg4oCc57yW6K+R4oCdIOS7peaehOW7uicsXG4gICAgdXNlckluZm86IHt9LFxuICAgIGhhc1VzZXJJbmZvOiBmYWxzZSxcbiAgICBjYW5JVXNlOiB3eC5jYW5JVXNlKCdidXR0b24ub3Blbi10eXBlLmdldFVzZXJJbmZvJyksXG4gIH0sXG4gIC8v5LqL5Lu25aSE55CG5Ye95pWwXG4gIGJpbmRWaWV3VGFwKCkge1xuICAgIHd4Lm5hdmlnYXRlVG8oe1xuICAgICAgdXJsOiAnLi4vbG9ncy9sb2dzJ1xuICAgIH0pXG4gIH0sXG4gIG9uTG9hZCgpIHtcbiAgICBpZiAoYXBwLmdsb2JhbERhdGEudXNlckluZm8pIHtcbiAgICAgIHRoaXMuc2V0RGF0YSEoe1xuICAgICAgICB1c2VySW5mbzogYXBwLmdsb2JhbERhdGEudXNlckluZm8sXG4gICAgICAgIGhhc1VzZXJJbmZvOiB0cnVlLFxuICAgICAgfSlcbiAgICB9IGVsc2UgaWYgKHRoaXMuZGF0YS5jYW5JVXNlKXtcbiAgICAgIC8vIOeUseS6jiBnZXRVc2VySW5mbyDmmK/nvZHnu5zor7fmsYLvvIzlj6/og73kvJrlnKggUGFnZS5vbkxvYWQg5LmL5ZCO5omN6L+U5ZueXG4gICAgICAvLyDmiYDku6XmraTlpITliqDlhaUgY2FsbGJhY2sg5Lul6Ziy5q2i6L+Z56eN5oOF5Ya1XG4gICAgICBhcHAudXNlckluZm9SZWFkeUNhbGxiYWNrID0gKHJlcykgPT4ge1xuICAgICAgICB0aGlzLnNldERhdGEhKHtcbiAgICAgICAgICB1c2VySW5mbzogcmVzLFxuICAgICAgICAgIGhhc1VzZXJJbmZvOiB0cnVlXG4gICAgICAgIH0pXG4gICAgICB9XG4gICAgfSBlbHNlIHtcbiAgICAgIC8vIOWcqOayoeaciSBvcGVuLXR5cGU9Z2V0VXNlckluZm8g54mI5pys55qE5YW85a655aSE55CGXG4gICAgICB3eC5nZXRVc2VySW5mbyh7XG4gICAgICAgIHN1Y2Nlc3M6IHJlcyA9PiB7XG4gICAgICAgICAgYXBwLmdsb2JhbERhdGEudXNlckluZm8gPSByZXMudXNlckluZm9cbiAgICAgICAgICB0aGlzLnNldERhdGEhKHtcbiAgICAgICAgICAgIHVzZXJJbmZvOiByZXMudXNlckluZm8sXG4gICAgICAgICAgICBoYXNVc2VySW5mbzogdHJ1ZVxuICAgICAgICAgIH0pXG4gICAgICAgIH1cbiAgICAgIH0pXG4gICAgfVxuICB9LFxuXG4gIGdldFVzZXJJbmZvKGU6IGFueSkge1xuICAgIGNvbnNvbGUubG9nKGUpXG4gICAgYXBwLmdsb2JhbERhdGEudXNlckluZm8gPSBlLmRldGFpbC51c2VySW5mb1xuICAgIHRoaXMuc2V0RGF0YSEoe1xuICAgICAgdXNlckluZm86IGUuZGV0YWlsLnVzZXJJbmZvLFxuICAgICAgaGFzVXNlckluZm86IHRydWVcbiAgICB9KVxuICB9XG59KVxuIl19
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
//index.js
|
||||
//获取应用实例
|
||||
import { IMyApp } from '../../app'
|
||||
|
||||
const app = getApp<IMyApp>()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
motto: '点击 “编译” 以构建',
|
||||
userInfo: {},
|
||||
hasUserInfo: false,
|
||||
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
||||
},
|
||||
//事件处理函数
|
||||
bindViewTap() {
|
||||
wx.navigateTo({
|
||||
url: '../logs/logs'
|
||||
})
|
||||
},
|
||||
onLoad() {
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData!({
|
||||
userInfo: app.globalData.userInfo,
|
||||
hasUserInfo: true,
|
||||
})
|
||||
} else if (this.data.canIUse){
|
||||
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
||||
// 所以此处加入 callback 以防止这种情况
|
||||
app.userInfoReadyCallback = (res) => {
|
||||
this.setData!({
|
||||
userInfo: res,
|
||||
hasUserInfo: true
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 在没有 open-type=getUserInfo 版本的兼容处理
|
||||
wx.getUserInfo({
|
||||
success: res => {
|
||||
app.globalData.userInfo = res.userInfo
|
||||
this.setData!({
|
||||
userInfo: res.userInfo,
|
||||
hasUserInfo: true
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
getUserInfo(e: any) {
|
||||
console.log(e)
|
||||
app.globalData.userInfo = e.detail.userInfo
|
||||
this.setData!({
|
||||
userInfo: e.detail.userInfo,
|
||||
hasUserInfo: true
|
||||
})
|
||||
}
|
||||
})
|
|
@ -0,0 +1,13 @@
|
|||
<!--index.wxml-->
|
||||
<view class="container">
|
||||
<view class="userinfo">
|
||||
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
|
||||
<block wx:else>
|
||||
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
|
||||
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
|
||||
</block>
|
||||
</view>
|
||||
<view class="usermotto">
|
||||
<text class="user-motto">{{motto}}</text>
|
||||
</view>
|
||||
</view>
|
|
@ -0,0 +1,21 @@
|
|||
/**index.wxss**/
|
||||
.userinfo {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.userinfo-avatar {
|
||||
width: 128rpx;
|
||||
height: 128rpx;
|
||||
margin: 20rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.userinfo-nickname {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.usermotto {
|
||||
margin-top: 200px;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var util_1 = require("../../utils/util");
|
||||
Page({
|
||||
data: {
|
||||
logs: []
|
||||
},
|
||||
onLoad: function () {
|
||||
this.setData({
|
||||
logs: (wx.getStorageSync('logs') || []).map(function (log) {
|
||||
return util_1.formatTime(new Date(log));
|
||||
})
|
||||
});
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9ncy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImxvZ3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSx5Q0FBNkM7QUFFN0MsSUFBSSxDQUFDO0lBQ0gsSUFBSSxFQUFFO1FBQ0osSUFBSSxFQUFFLEVBQWM7S0FDckI7SUFDRCxNQUFNO1FBQ0osSUFBSSxDQUFDLE9BQVEsQ0FBQztZQUNaLElBQUksRUFBRSxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsTUFBTSxDQUFDLElBQUksRUFBRSxDQUFDLENBQUMsR0FBRyxDQUFDLFVBQUMsR0FBVztnQkFDdEQsT0FBTyxpQkFBVSxDQUFDLElBQUksSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUE7WUFDbEMsQ0FBQyxDQUFDO1NBQ0gsQ0FBQyxDQUFBO0lBQ0osQ0FBQztDQUNGLENBQUMsQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbIi8vbG9ncy5qc1xuaW1wb3J0IHsgZm9ybWF0VGltZSB9IGZyb20gJy4uLy4uL3V0aWxzL3V0aWwnXG5cblBhZ2Uoe1xuICBkYXRhOiB7XG4gICAgbG9nczogW10gYXMgc3RyaW5nW11cbiAgfSxcbiAgb25Mb2FkKCkge1xuICAgIHRoaXMuc2V0RGF0YSEoe1xuICAgICAgbG9nczogKHd4LmdldFN0b3JhZ2VTeW5jKCdsb2dzJykgfHwgW10pLm1hcCgobG9nOiBudW1iZXIpID0+IHtcbiAgICAgICAgcmV0dXJuIGZvcm1hdFRpbWUobmV3IERhdGUobG9nKSlcbiAgICAgIH0pXG4gICAgfSlcbiAgfSxcbn0pXG4iXX0=
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"navigationBarTitleText": "查看启动日志",
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
//logs.js
|
||||
import { formatTime } from '../../utils/util'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
logs: [] as string[]
|
||||
},
|
||||
onLoad() {
|
||||
this.setData!({
|
||||
logs: (wx.getStorageSync('logs') || []).map((log: number) => {
|
||||
return formatTime(new Date(log))
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
|
@ -0,0 +1,6 @@
|
|||
<!--logs.wxml-->
|
||||
<view class="container log-list">
|
||||
<block wx:for="{{logs}}" wx:for-item="log">
|
||||
<text class="log-item">{{index + 1}}. {{log}}</text>
|
||||
</block>
|
||||
</view>
|
|
@ -0,0 +1,8 @@
|
|||
.log-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 40rpx;
|
||||
}
|
||||
.log-item {
|
||||
margin: 10rpx;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
|
||||
"rules": [{
|
||||
"action": "allow",
|
||||
"page": "*"
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function formatTime(date) {
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth() + 1;
|
||||
var day = date.getDate();
|
||||
var hour = date.getHours();
|
||||
var minute = date.getMinutes();
|
||||
var second = date.getSeconds();
|
||||
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':');
|
||||
}
|
||||
exports.formatTime = formatTime;
|
||||
var formatNumber = function (n) {
|
||||
var str = n.toString();
|
||||
return str[1] ? str : '0' + str;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInV0aWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxTQUFnQixVQUFVLENBQUMsSUFBVTtJQUNuQyxJQUFNLElBQUksR0FBRyxJQUFJLENBQUMsV0FBVyxFQUFFLENBQUE7SUFDL0IsSUFBTSxLQUFLLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxHQUFHLENBQUMsQ0FBQTtJQUNqQyxJQUFNLEdBQUcsR0FBRyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7SUFDMUIsSUFBTSxJQUFJLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxDQUFBO0lBQzVCLElBQU0sTUFBTSxHQUFHLElBQUksQ0FBQyxVQUFVLEVBQUUsQ0FBQTtJQUNoQyxJQUFNLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxFQUFFLENBQUE7SUFFaEMsT0FBTyxDQUFDLElBQUksRUFBRSxLQUFLLEVBQUUsR0FBRyxDQUFDLENBQUMsR0FBRyxDQUFDLFlBQVksQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsR0FBRyxHQUFHLEdBQUcsQ0FBQyxJQUFJLEVBQUUsTUFBTSxFQUFFLE1BQU0sQ0FBQyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUE7QUFDbEgsQ0FBQztBQVRELGdDQVNDO0FBRUQsSUFBTSxZQUFZLEdBQUcsVUFBQyxDQUFTO0lBQzdCLElBQU0sR0FBRyxHQUFHLENBQUMsQ0FBQyxRQUFRLEVBQUUsQ0FBQTtJQUN4QixPQUFPLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxHQUFHLEdBQUcsR0FBRyxDQUFBO0FBQ2pDLENBQUMsQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBmdW5jdGlvbiBmb3JtYXRUaW1lKGRhdGU6IERhdGUpOiBzdHJpbmcge1xuICBjb25zdCB5ZWFyID0gZGF0ZS5nZXRGdWxsWWVhcigpXG4gIGNvbnN0IG1vbnRoID0gZGF0ZS5nZXRNb250aCgpICsgMVxuICBjb25zdCBkYXkgPSBkYXRlLmdldERhdGUoKVxuICBjb25zdCBob3VyID0gZGF0ZS5nZXRIb3VycygpXG4gIGNvbnN0IG1pbnV0ZSA9IGRhdGUuZ2V0TWludXRlcygpXG4gIGNvbnN0IHNlY29uZCA9IGRhdGUuZ2V0U2Vjb25kcygpXG5cbiAgcmV0dXJuIFt5ZWFyLCBtb250aCwgZGF5XS5tYXAoZm9ybWF0TnVtYmVyKS5qb2luKCcvJykgKyAnICcgKyBbaG91ciwgbWludXRlLCBzZWNvbmRdLm1hcChmb3JtYXROdW1iZXIpLmpvaW4oJzonKVxufVxuXG5jb25zdCBmb3JtYXROdW1iZXIgPSAobjogbnVtYmVyKSA9PiB7XG4gIGNvbnN0IHN0ciA9IG4udG9TdHJpbmcoKVxuICByZXR1cm4gc3RyWzFdID8gc3RyIDogJzAnICsgc3RyXG59XG4iXX0=
|
|
@ -0,0 +1,15 @@
|
|||
export function formatTime(date: Date): string {
|
||||
const year = date.getFullYear()
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const hour = date.getHours()
|
||||
const minute = date.getMinutes()
|
||||
const second = date.getSeconds()
|
||||
|
||||
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
|
||||
}
|
||||
|
||||
const formatNumber = (n: number) => {
|
||||
const str = n.toString()
|
||||
return str[1] ? str : '0' + str
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "demo",
|
||||
"version": "1.0.1",
|
||||
"scripts": {
|
||||
"compile": "./node_modules/typescript/bin/tsc",
|
||||
"tsc": "node ./node_modules/typescript/lib/tsc.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^3.3.3333"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"description": "项目配置文件",
|
||||
"packOptions": {
|
||||
"ignore": []
|
||||
},
|
||||
"miniprogramRoot": "miniprogram/",
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "2.4.0",
|
||||
"projectname": "omix-ts",
|
||||
"scripts": {
|
||||
"beforeCompile": "npm run tsc",
|
||||
"beforePreview": "npm run tsc",
|
||||
"beforeUpload": "npm run tsc"
|
||||
},
|
||||
"setting": {},
|
||||
"appid": "wxfaf6dad43f57c6bd",
|
||||
"simulatorType": "wechat",
|
||||
"simulatorPluginLibVersion": {},
|
||||
"condition": {}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": true,
|
||||
"module": "CommonJS",
|
||||
"target": "ES5",
|
||||
"allowJs": false,
|
||||
"experimentalDecorators": true,
|
||||
"noImplicitThis": true,
|
||||
"noImplicitReturns": true,
|
||||
"alwaysStrict": true,
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"strict": true,
|
||||
"removeComments": true,
|
||||
"pretty": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"typeRoots": [
|
||||
"./typings"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"./miniprogram/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"miniprogram_dist",
|
||||
"**/*.spec.ts"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/// <reference path="./lib.wa.es6.d.ts" />
|
||||
/// <reference path="./wx/index.d.ts" />
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,29 @@
|
|||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/// <reference path="./lib.wx.app.d.ts" />
|
||||
/// <reference path="./lib.wx.page.d.ts" />
|
||||
/// <reference path="./lib.wx.api.d.ts" />
|
||||
/// <reference path="./lib.wx.cloud.d.ts" />
|
||||
/// <reference path="./lib.wx.component.d.ts" />
|
||||
|
||||
declare type IAnyObject = Record<string, any>
|
||||
|
||||
declare type KVInfer<T> = {
|
||||
[K in keyof T]: T[K]
|
||||
}
|
||||
|
||||
declare type Void<T> = T | undefined | null
|
||||
|
||||
type PartialOptional<T, K extends keyof T> = Partial<Pick<T, K>> & Pick<T, Exclude<keyof T, K>>
|
||||
|
||||
type Optional<T> = {
|
||||
[K in keyof T]+?: T[K]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,249 @@
|
|||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace App {
|
||||
interface ILaunchOptions {
|
||||
query: number
|
||||
}
|
||||
|
||||
interface IReferrerInfo {
|
||||
/** 来源小程序或公众号或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 ILaunchShowOption {
|
||||
/** 打开小程序的路径 */
|
||||
path: string
|
||||
/** 打开小程序的query */
|
||||
query: IAnyObject
|
||||
/** 打开小程序的场景值
|
||||
* - 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?: IReferrerInfo
|
||||
}
|
||||
|
||||
interface IPageNotFoundOption {
|
||||
/** 不存在页面的路径 */
|
||||
path: string
|
||||
/** 打开不存在页面的 query */
|
||||
query: IAnyObject
|
||||
/** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */
|
||||
isEntryPage: boolean
|
||||
}
|
||||
|
||||
interface AppInstance<T extends IAnyObject = {}> {
|
||||
/** 生命周期回调—监听小程序初始化
|
||||
*
|
||||
* 小程序初始化完成时触发,全局只触发一次。
|
||||
*/
|
||||
onLaunch?(options?: ILaunchShowOption): void
|
||||
/** 生命周期回调—监听小程序显示
|
||||
*
|
||||
* 小程序启动,或从后台进入前台显示时
|
||||
*/
|
||||
onShow?(options?: ILaunchShowOption): void
|
||||
/** 生命周期回调—监听小程序隐藏
|
||||
*
|
||||
* 小程序从前台进入后台时
|
||||
*/
|
||||
onHide?(): void
|
||||
/** 错误监听函数
|
||||
*
|
||||
* 小程序发生脚本错误,或者 api
|
||||
*/
|
||||
onError?(/** 错误信息,包含堆栈 */error?: string): void
|
||||
/** 页面不存在监听函数
|
||||
*
|
||||
* 小程序要打开的页面不存在时触发,会带上页面信息回调该函数
|
||||
*
|
||||
* **注意:**
|
||||
* 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。
|
||||
* 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。
|
||||
*
|
||||
* 最低基础库: 1.9.90
|
||||
*/
|
||||
onPageNotFound?(options?: IPageNotFoundOption): void
|
||||
}
|
||||
|
||||
interface AppConstructor {
|
||||
<T extends IAnyObject & AppInstance>(
|
||||
options: AppInstance<T> & T
|
||||
): void
|
||||
}
|
||||
|
||||
interface IGetAppOption {
|
||||
/** 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包
|
||||
*
|
||||
* 最低基础库: 2.2.4
|
||||
*/
|
||||
allowDefault: boolean
|
||||
}
|
||||
|
||||
interface GetApp {
|
||||
<T extends IAnyObject>(opts?: IGetAppOption): AppInstance<T> & T
|
||||
}
|
||||
}
|
||||
|
||||
declare const App: App.AppConstructor
|
||||
declare const getApp: App.GetApp
|
|
@ -0,0 +1,687 @@
|
|||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/////////////////////
|
||||
///// WX Cloud Apis
|
||||
/////////////////////
|
||||
|
||||
/**
|
||||
* Common interfaces and types
|
||||
*/
|
||||
|
||||
interface IAPIError {
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
interface IAPIParam<T = any> {
|
||||
config?: ICloudConfig,
|
||||
success?: (res: T) => void,
|
||||
fail?: (err: IAPIError) => void,
|
||||
complete?: (val: T | IAPIError) => void,
|
||||
}
|
||||
|
||||
interface IAPISuccessParam {
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
type IAPICompleteParam = IAPISuccessParam | IAPIError
|
||||
|
||||
type IAPIFunction<T, P extends IAPIParam<T>> = (param: P) => Promise<T> | any
|
||||
|
||||
interface IInitCloudConfig {
|
||||
env?: string | {
|
||||
database?: string,
|
||||
functions?: string,
|
||||
storage?: string,
|
||||
},
|
||||
traceUser?: boolean,
|
||||
}
|
||||
|
||||
interface ICloudConfig {
|
||||
env?: string,
|
||||
traceUser?: boolean,
|
||||
}
|
||||
|
||||
interface IICloudAPI {
|
||||
init: (config?: IInitCloudConfig) => void,
|
||||
[api: string]: AnyFunction | IAPIFunction<any, any>,
|
||||
}
|
||||
|
||||
interface ICloudService {
|
||||
name: string,
|
||||
|
||||
getAPIs: () => { [name: string]: IAPIFunction<any, any> },
|
||||
}
|
||||
|
||||
interface ICloudServices {
|
||||
[serviceName: string]: ICloudService
|
||||
}
|
||||
|
||||
interface ICloudMetaData {
|
||||
session_id: string,
|
||||
}
|
||||
|
||||
declare class InternalSymbol {
|
||||
|
||||
}
|
||||
|
||||
type AnyObject = {
|
||||
[x: string]: any
|
||||
}
|
||||
|
||||
type AnyArray = any[]
|
||||
|
||||
type AnyFunction = (...args: any[]) => any
|
||||
|
||||
/**
|
||||
* original wx
|
||||
*/
|
||||
|
||||
declare namespace WXNS {
|
||||
|
||||
interface AnyObject {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
interface IAPIParam<T> {
|
||||
success?: (res: T) => void,
|
||||
fail?: (err: IAPIError) => void,
|
||||
complete?: (val: T | IAPIError) => void,
|
||||
}
|
||||
|
||||
interface CommonAPIResult {
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
interface IAPIError {
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
interface IProgressUpdateEvent {
|
||||
progress: number,
|
||||
totalBytesWritten: number,
|
||||
totalBytesExpectedToWrite: number,
|
||||
}
|
||||
|
||||
interface operateWXData {
|
||||
(param: any): void
|
||||
}
|
||||
|
||||
interface uploadFile {
|
||||
/**
|
||||
* upload file
|
||||
* @param param
|
||||
*/
|
||||
(param: IUploadFileParam): IUploadFileTask
|
||||
}
|
||||
|
||||
interface IUploadFileParam extends IAPIParam<IUploadFileSuccessResult> {
|
||||
url: string,
|
||||
filePath: string,
|
||||
name: string,
|
||||
header?: AnyObject,
|
||||
}
|
||||
|
||||
interface IUploadFileSuccessResult extends CommonAPIResult {
|
||||
data: string,
|
||||
statusCode: number,
|
||||
}
|
||||
|
||||
interface IUploadFileTask {
|
||||
onProgressUpdate: (fn: (event: IProgressUpdateEvent) => void) => void,
|
||||
abort: AnyFunction,
|
||||
}
|
||||
|
||||
interface downloadFile {
|
||||
/**
|
||||
* download file
|
||||
* @param param
|
||||
*/
|
||||
(param: IDownloadFileParam): IDownloadFileTask
|
||||
}
|
||||
|
||||
interface IDownloadFileParam extends IAPIParam<IDownloadFileSuccessResult> {
|
||||
url: string,
|
||||
header?: AnyObject,
|
||||
}
|
||||
|
||||
interface IDownloadFileSuccessResult extends CommonAPIResult {
|
||||
tempFilePath: string,
|
||||
statusCode: number,
|
||||
}
|
||||
|
||||
interface IDownloadFileTask {
|
||||
onProgressUpdate: (fn: (event: IProgressUpdateEvent) => void) => void,
|
||||
abort: AnyFunction,
|
||||
}
|
||||
|
||||
interface request {
|
||||
(param: IRequestParam): IRequestTask
|
||||
}
|
||||
|
||||
interface IRequestParam extends IAPIParam<IRequestSuccessResult> {
|
||||
url: string,
|
||||
data?: AnyObject | string | ArrayBuffer,
|
||||
header?: AnyObject,
|
||||
method?: string,
|
||||
dataType?: string,
|
||||
responseType?: string,
|
||||
}
|
||||
|
||||
interface IRequestSuccessResult {
|
||||
data: AnyObject | string | ArrayBuffer,
|
||||
statusCode: number,
|
||||
header: AnyObject,
|
||||
}
|
||||
|
||||
interface IRequestTask {
|
||||
abort: () => void
|
||||
}
|
||||
|
||||
interface getFileInfo {
|
||||
(param: IGetFileInfoParam): void
|
||||
}
|
||||
|
||||
interface IGetFileInfoParam extends IAPIParam<IGetFileInfoSuccessResult> {
|
||||
filePath: string,
|
||||
digestAlgorithm?: string,
|
||||
}
|
||||
|
||||
interface IGetFileInfoSuccessResult {
|
||||
size: number,
|
||||
digest: string,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare namespace wx {
|
||||
interface WX {
|
||||
cloud: {
|
||||
init: (config?: ICloudConfig) => void,
|
||||
|
||||
// callFunction: (param: ICloud.CallFunctionParam) => Promise<ICloud.CallFunctionResult> | void,
|
||||
|
||||
// uploadFile: (param: ICloud.UploadFileParam) => Promise<ICloud.UploadFileResult> | WXNS.IUploadFileTask,
|
||||
// downloadFile: (param: ICloud.DownloadFileParam) => Promise<ICloud.DownloadFileResult> | WXNS.IDownloadFileTask,
|
||||
// getTempFileURL: (param: ICloud.GetTempFileURLParam) => Promise<ICloud.GetTempFileURLResult> | void,
|
||||
// deleteFile: (param: ICloud.DeleteFileParam) => Promise<ICloud.DeleteFileResult> | void,
|
||||
|
||||
callFunction(param: OQ<ICloud.CallFunctionParam>): void
|
||||
callFunction(param: RQ<ICloud.CallFunctionParam>): Promise<ICloud.CallFunctionResult>
|
||||
|
||||
uploadFile(param: OQ<ICloud.UploadFileParam>): WXNS.IUploadFileTask
|
||||
uploadFile(param: RQ<ICloud.UploadFileParam>): Promise<ICloud.UploadFileResult>
|
||||
|
||||
downloadFile(param: OQ<ICloud.DownloadFileParam>): WXNS.IDownloadFileTask
|
||||
downloadFile(param: RQ<ICloud.DownloadFileParam>): Promise<ICloud.DownloadFileResult>
|
||||
|
||||
getTempFileURL(param: OQ<ICloud.GetTempFileURLParam>): void,
|
||||
getTempFileURL(param: RQ<ICloud.GetTempFileURLParam>): Promise<ICloud.GetTempFileURLResult>
|
||||
|
||||
deleteFile(param: OQ<ICloud.DeleteFileParam>): void,
|
||||
deleteFile(param: RQ<ICloud.DeleteFileParam>): Promise<ICloud.DeleteFileResult>
|
||||
|
||||
database: (config?: ICloudConfig) => DB.Database,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace ICloud {
|
||||
|
||||
interface ICloudAPIParam<T = any> extends IAPIParam<T> {
|
||||
config?: ICloudConfig
|
||||
}
|
||||
|
||||
// === API: callFunction ===
|
||||
export type CallFunctionData = AnyObject
|
||||
|
||||
export interface CallFunctionResult extends IAPISuccessParam {
|
||||
result: AnyObject | string | undefined,
|
||||
}
|
||||
|
||||
export interface CallFunctionParam extends ICloudAPIParam<CallFunctionResult> {
|
||||
name: string,
|
||||
data?: CallFunctionData,
|
||||
slow?: boolean,
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: uploadFile ===
|
||||
export interface UploadFileResult extends IAPISuccessParam {
|
||||
fileID: string,
|
||||
statusCode: number,
|
||||
}
|
||||
|
||||
export interface UploadFileParam extends ICloudAPIParam<UploadFileResult> {
|
||||
cloudPath: string,
|
||||
filePath: string,
|
||||
header?: AnyObject,
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: downloadFile ===
|
||||
export interface DownloadFileResult extends IAPISuccessParam {
|
||||
tempFilePath: string,
|
||||
statusCode: number,
|
||||
}
|
||||
|
||||
export interface DownloadFileParam extends ICloudAPIParam<DownloadFileResult> {
|
||||
fileID: string,
|
||||
cloudPath?: string,
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: getTempFileURL ===
|
||||
export interface GetTempFileURLResult extends IAPISuccessParam {
|
||||
fileList: GetTempFileURLResultItem[],
|
||||
}
|
||||
|
||||
export interface GetTempFileURLResultItem {
|
||||
fileID: string,
|
||||
tempFileURL: string,
|
||||
maxAge: number,
|
||||
status: number,
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
export interface GetTempFileURLParam extends ICloudAPIParam<GetTempFileURLResult> {
|
||||
fileList: string[],
|
||||
}
|
||||
// === end ===
|
||||
|
||||
// === API: deleteFile ===
|
||||
interface DeleteFileResult extends IAPISuccessParam {
|
||||
fileList: DeleteFileResultItem[],
|
||||
}
|
||||
|
||||
interface DeleteFileResultItem {
|
||||
fileID: string,
|
||||
status: number,
|
||||
errMsg: string,
|
||||
}
|
||||
|
||||
interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> {
|
||||
fileList: string[],
|
||||
}
|
||||
// === end ===
|
||||
|
||||
}
|
||||
|
||||
// === Database ===
|
||||
declare namespace DB {
|
||||
/**
|
||||
* The class of all exposed cloud database instances
|
||||
*/
|
||||
export class Database {
|
||||
|
||||
public readonly config: ICloudConfig
|
||||
public readonly command: DatabaseCommand
|
||||
public readonly Geo: Geo
|
||||
public readonly serverDate: () => ServerDate
|
||||
|
||||
private constructor();
|
||||
|
||||
collection(collectionName: string): CollectionReference
|
||||
|
||||
}
|
||||
|
||||
export class CollectionReference extends Query {
|
||||
|
||||
public readonly collectionName: string
|
||||
public readonly database: Database
|
||||
|
||||
private constructor(name: string, database: Database)
|
||||
|
||||
doc(docId: string | number): DocumentReference
|
||||
|
||||
// add(options: IAddDocumentOptions): Promise<IAddResult> | void
|
||||
|
||||
add(options: OQ<IAddDocumentOptions>): void
|
||||
add(options: RQ<IAddDocumentOptions>): Promise<IAddResult>
|
||||
|
||||
}
|
||||
|
||||
export class DocumentReference {
|
||||
|
||||
private constructor(docId: string | number, database: Database)
|
||||
|
||||
field(object: object): this
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQuerySingleResult> | void
|
||||
|
||||
// set(options?: ISetSingleDocumentOptions): Promise<ISetResult> | void
|
||||
|
||||
// update(options?: IUpdateSingleDocumentOptions): Promise<IUpdateResult> | void
|
||||
|
||||
// remove(options?: IRemoveSingleDocumentOptions): Promise<IRemoveResult> | void
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQuerySingleResult> | void
|
||||
get(): Promise<IQuerySingleResult>
|
||||
get(options: OQ<IGetDocumentOptions>): void
|
||||
get(options: RQ<IGetDocumentOptions>): Promise<IQuerySingleResult>
|
||||
|
||||
// set(options?: ISetSingleDocumentOptions): Promise<ISetResult> | void
|
||||
set(): Promise<ISetResult>
|
||||
set(options: OQ<ISetSingleDocumentOptions>): void
|
||||
set(options: RQ<ISetSingleDocumentOptions>): Promise<ISetResult>
|
||||
|
||||
// update(options?: IUpdateSingleDocumentOptions): Promise<IUpdateResult> | void
|
||||
update(): Promise<IUpdateResult>
|
||||
update(options: OQ<IUpdateSingleDocumentOptions>): void
|
||||
update(options: RQ<IUpdateSingleDocumentOptions>): Promise<IUpdateResult>
|
||||
|
||||
// remove(options?: IRemoveSingleDocumentOptions): Promise<IRemoveResult> | void
|
||||
remove(): Promise<IRemoveResult>
|
||||
remove(options: OQ<IRemoveSingleDocumentOptions>): void
|
||||
remove(options: RQ<IRemoveSingleDocumentOptions>): Promise<IRemoveResult>
|
||||
|
||||
}
|
||||
|
||||
export class Query {
|
||||
|
||||
where(condition: IQueryCondition): Query
|
||||
|
||||
orderBy(fieldPath: string, order: string): Query
|
||||
|
||||
limit(max: number): Query
|
||||
|
||||
skip(offset: number): Query
|
||||
|
||||
field(object: object): Query
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQueryResult> | void
|
||||
|
||||
// // update(options?: IUpdateDocumentOptions): Promise<IUpdateResult> | void
|
||||
|
||||
// // remove(options?: IRemoveDocumentOptions): Promise<IRemoveResult> | void
|
||||
|
||||
// count(options?: ICountDocumentOptions): Promise<ICountResult> | void
|
||||
|
||||
// get(options?: IGetDocumentOptions): Promise<IQueryResult> | void
|
||||
get(): Promise<IQueryResult>
|
||||
get(options: OQ<IGetDocumentOptions>): void
|
||||
get(options: RQ<IGetDocumentOptions>): Promise<IQueryResult>
|
||||
|
||||
// update(options?: IUpdateDocumentOptions): Promise<IUpdateResult> | void
|
||||
|
||||
// remove(options?: IRemoveDocumentOptions): Promise<IRemoveResult> | void
|
||||
|
||||
// count(options?: ICountDocumentOptions): Promise<ICountResult> | void
|
||||
count(): Promise<ICountResult>
|
||||
count(options: OQ<ICountDocumentOptions>): void
|
||||
count(options: RQ<ICountDocumentOptions>): Promise<ICountResult>
|
||||
|
||||
}
|
||||
|
||||
export interface DatabaseCommand {
|
||||
|
||||
eq(val: any): DatabaseQueryCommand
|
||||
neq(val: any): DatabaseQueryCommand
|
||||
gt(val: any): DatabaseQueryCommand
|
||||
gte(val: any): DatabaseQueryCommand
|
||||
lt(val: any): DatabaseQueryCommand
|
||||
lte(val: any): DatabaseQueryCommand
|
||||
in(val: any[]): DatabaseQueryCommand
|
||||
nin(val: any[]): DatabaseQueryCommand
|
||||
|
||||
and(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
or(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
|
||||
set(val: any): DatabaseUpdateCommand
|
||||
remove(): DatabaseUpdateCommand
|
||||
inc(val: number): DatabaseUpdateCommand
|
||||
mul(val: number): DatabaseUpdateCommand
|
||||
|
||||
push(...values: any[]): DatabaseUpdateCommand
|
||||
pop(): DatabaseUpdateCommand
|
||||
shift(): DatabaseUpdateCommand
|
||||
unshift(...values: any[]): DatabaseUpdateCommand
|
||||
|
||||
}
|
||||
|
||||
export enum LOGIC_COMMANDS_LITERAL {
|
||||
AND = 'and',
|
||||
OR = 'or',
|
||||
NOT = 'not',
|
||||
NOR = 'nor',
|
||||
}
|
||||
|
||||
export class DatabaseLogicCommand {
|
||||
|
||||
public fieldName: string | InternalSymbol
|
||||
public operator: LOGIC_COMMANDS_LITERAL | string
|
||||
public operands: any[]
|
||||
|
||||
_setFieldName(fieldName: string): DatabaseLogicCommand
|
||||
|
||||
and(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
or(...expressions: (DatabaseLogicCommand | IQueryCondition)[]): DatabaseLogicCommand
|
||||
|
||||
}
|
||||
|
||||
export enum QUERY_COMMANDS_LITERAL {
|
||||
EQ = 'eq',
|
||||
NEQ = 'neq',
|
||||
GT = 'gt',
|
||||
GTE = 'gte',
|
||||
LT = 'lt',
|
||||
LTE = 'lte',
|
||||
IN = 'in',
|
||||
NIN = 'nin',
|
||||
}
|
||||
|
||||
export class DatabaseQueryCommand extends DatabaseLogicCommand {
|
||||
|
||||
public operator: QUERY_COMMANDS_LITERAL | string
|
||||
|
||||
_setFieldName(fieldName: string): DatabaseQueryCommand
|
||||
|
||||
eq(val: any): DatabaseLogicCommand
|
||||
neq(val: any): DatabaseLogicCommand
|
||||
gt(val: any): DatabaseLogicCommand
|
||||
gte(val: any): DatabaseLogicCommand
|
||||
lt(val: any): DatabaseLogicCommand
|
||||
lte(val: any): DatabaseLogicCommand
|
||||
in(val: any[]): DatabaseLogicCommand
|
||||
nin(val: any[]): DatabaseLogicCommand
|
||||
|
||||
}
|
||||
|
||||
export enum UPDATE_COMMANDS_LITERAL {
|
||||
SET = 'set',
|
||||
REMOVE = 'remove',
|
||||
INC = 'inc',
|
||||
MUL = 'mul',
|
||||
PUSH = 'push',
|
||||
POP = 'pop',
|
||||
SHIFT = 'shift',
|
||||
UNSHIFT = 'unshift',
|
||||
}
|
||||
|
||||
export class DatabaseUpdateCommand {
|
||||
|
||||
public fieldName: string | InternalSymbol
|
||||
public operator: UPDATE_COMMANDS_LITERAL
|
||||
public operands: any[]
|
||||
|
||||
constructor(operator: UPDATE_COMMANDS_LITERAL, operands: any[], fieldName?: string | InternalSymbol)
|
||||
|
||||
_setFieldName(fieldName: string): DatabaseUpdateCommand
|
||||
}
|
||||
|
||||
export class Batch {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A contract that all API provider must adhere to
|
||||
*/
|
||||
export class APIBaseContract<PROMISE_RETURN, CALLBACK_RETURN, PARAM extends IAPIParam, CONTEXT = any> {
|
||||
|
||||
getContext(param: PARAM): CONTEXT
|
||||
|
||||
/**
|
||||
* In case of callback-style invocation, this function will be called
|
||||
*/
|
||||
getCallbackReturn(param: PARAM, context: CONTEXT): CALLBACK_RETURN
|
||||
|
||||
getFinalParam<T extends PARAM>(param: PARAM, context: CONTEXT): T
|
||||
|
||||
run<T extends PARAM>(param: T): Promise<PROMISE_RETURN>
|
||||
|
||||
}
|
||||
|
||||
export interface GeoPointConstructor {
|
||||
new (longitude: number, latitide: number): GeoPoint
|
||||
}
|
||||
|
||||
export interface Geo {
|
||||
Point: {
|
||||
new (longitude: number, latitide: number): GeoPoint
|
||||
(longitude: number, latitide: number): GeoPoint
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class GeoPoint {
|
||||
public longitude: number
|
||||
public latitude: number
|
||||
|
||||
constructor(longitude: number, latitude: number)
|
||||
|
||||
toJSON(): object
|
||||
toString(): string
|
||||
}
|
||||
|
||||
export interface IServerDateOptions {
|
||||
offset: number,
|
||||
}
|
||||
|
||||
export abstract class ServerDate {
|
||||
public readonly options: IServerDateOptions
|
||||
constructor(options?: IServerDateOptions)
|
||||
}
|
||||
|
||||
export type DocumentId = string | number
|
||||
|
||||
export interface IDocumentData {
|
||||
_id?: DocumentId,
|
||||
[key: string]: any,
|
||||
}
|
||||
|
||||
export interface IDBAPIParam extends IAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface IAddDocumentOptions extends IDBAPIParam {
|
||||
data: IDocumentData,
|
||||
}
|
||||
|
||||
export interface IGetDocumentOptions extends IDBAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface ICountDocumentOptions extends IDBAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface IUpdateDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface IUpdateSingleDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface ISetDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface ISetSingleDocumentOptions extends IDBAPIParam {
|
||||
data: IUpdateCondition,
|
||||
}
|
||||
|
||||
export interface IRemoveDocumentOptions extends IDBAPIParam {
|
||||
query: IQueryCondition,
|
||||
}
|
||||
|
||||
export interface IRemoveSingleDocumentOptions extends IDBAPIParam {
|
||||
|
||||
}
|
||||
|
||||
export interface IQueryCondition {
|
||||
[key: string]: any,
|
||||
}
|
||||
|
||||
export type IStringQueryCondition = string
|
||||
|
||||
export interface IQueryResult extends IAPISuccessParam {
|
||||
data: IDocumentData[],
|
||||
}
|
||||
|
||||
export interface IQuerySingleResult extends IAPISuccessParam {
|
||||
data: IDocumentData,
|
||||
}
|
||||
|
||||
export interface IUpdateCondition {
|
||||
[key: string]: any,
|
||||
}
|
||||
|
||||
export type IStringUpdateCondition = string
|
||||
|
||||
export interface ISetCondition {
|
||||
|
||||
}
|
||||
|
||||
export interface IAddResult extends IAPISuccessParam {
|
||||
_id: DocumentId,
|
||||
}
|
||||
|
||||
export interface IUpdateResult extends IAPISuccessParam {
|
||||
stats: {
|
||||
updated: number,
|
||||
// created: number,
|
||||
}
|
||||
}
|
||||
|
||||
export interface ISetResult extends IAPISuccessParam {
|
||||
_id: DocumentId,
|
||||
stats: {
|
||||
updated: number,
|
||||
created: number,
|
||||
}
|
||||
}
|
||||
|
||||
export interface IRemoveResult extends IAPISuccessParam {
|
||||
stats: {
|
||||
removed: number,
|
||||
}
|
||||
}
|
||||
|
||||
export interface ICountResult extends IAPISuccessParam {
|
||||
total: number
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Utils
|
||||
*/
|
||||
|
||||
type OQ<T extends Optional<Record<'complete' | 'success' | 'fail', (...args: any[]) => any>>> =
|
||||
(RQ<T> & Required<Pick<T, 'success'>>) |
|
||||
(RQ<T> & Required<Pick<T, 'fail'>>) |
|
||||
(RQ<T> & Required<Pick<T, 'complete'>>) |
|
||||
(RQ<T> & Required<Pick<T, 'success' | 'fail'>>) |
|
||||
(RQ<T> & Required<Pick<T, 'success' | 'complete'>>) |
|
||||
(RQ<T> & Required<Pick<T, 'fail' | 'complete'>>) |
|
||||
(RQ<T> & Required<Pick<T, 'fail' | 'complete' | 'success'>>)
|
||||
|
||||
type RQ<T extends Optional<Record<'complete' | 'success' | 'fail', (...args: any[]) => any>>> = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>>
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
type PropertyType =
|
||||
| StringConstructor
|
||||
| NumberConstructor
|
||||
| BooleanConstructor
|
||||
| ObjectConstructor
|
||||
| ArrayConstructor
|
||||
| null;
|
||||
|
||||
declare interface PropertyOption {
|
||||
/** 属性类型 */
|
||||
type: PropertyType;
|
||||
/** 属性初始值 */
|
||||
value: any;
|
||||
/** 属性值被更改时的响应函数 */
|
||||
observer?(
|
||||
newVal?: any,
|
||||
oldVal?: any,
|
||||
changedPath?: Array<string | number>,
|
||||
): void;
|
||||
optionalTypes?: PropertyType[];
|
||||
}
|
||||
|
||||
declare interface TriggerEventOption {
|
||||
/** 事件是否冒泡
|
||||
*
|
||||
* 默认值: `false`
|
||||
*/
|
||||
bubbles?: boolean;
|
||||
/** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部
|
||||
*
|
||||
* 默认值: `false`
|
||||
*/
|
||||
composed?: boolean;
|
||||
/** 事件是否拥有捕获阶段
|
||||
*
|
||||
* 默认值: `false`
|
||||
*/
|
||||
capturePhase?: boolean;
|
||||
}
|
||||
|
||||
declare interface WxComponent extends BaseComponent {
|
||||
/** 组件的文件路径 */
|
||||
is: string;
|
||||
/** 节点id */
|
||||
id: string;
|
||||
/** 节点dataset */
|
||||
dataset: string;
|
||||
/** 组件数据,**包括内部数据和属性值** */
|
||||
data: IAnyObject;
|
||||
/** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
|
||||
properties: {
|
||||
[propertyName: string]: PropertyOption;
|
||||
};
|
||||
|
||||
/** 设置data并执行视图层渲染 */
|
||||
setData(
|
||||
/** 这次要改变的数据
|
||||
*
|
||||
* 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。
|
||||
*
|
||||
* 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。
|
||||
*/
|
||||
data: IAnyObject,
|
||||
/** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */
|
||||
callback?: (data: IAnyObject) => void,
|
||||
): void;
|
||||
/** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */
|
||||
hasBehavior(behavior: object): void;
|
||||
/** 触发事件,参见组件事件 */
|
||||
triggerEvent(name: string, detail: object, options: TriggerEventOption): void;
|
||||
/** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */
|
||||
createSelectorQuery(): wx.SelectorQuery;
|
||||
/** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */
|
||||
createIntersectionObserver(
|
||||
options: wx.CreateIntersectionObserverOption,
|
||||
): wx.IntersectionObserver;
|
||||
/** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */
|
||||
selectComponent(selector: string): WxComponent;
|
||||
/** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */
|
||||
selectAllComponents(selector: string): WxComponent[];
|
||||
/** 获取这个关系所对应的所有关联节点,参见 组件间关系 */
|
||||
getRelationNodes(relationKey: string): WxComponent[];
|
||||
/** 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)*/
|
||||
groupSetData(callback?: () => void): void;
|
||||
/** 返回当前页面的 custom-tab-bar 的组件实例 */
|
||||
getTabBar(): WxComponent;
|
||||
}
|
||||
|
||||
declare interface ComponentLifetimes {
|
||||
/** 组件生命周期函数,在组件实例进入页面节点树时执行,注意此时不能调用 `setData` */
|
||||
created?(this: WxComponent): void;
|
||||
/** 组件生命周期函数,在组件实例进入页面节点树时执行 */
|
||||
attached?(this: WxComponent): void;
|
||||
/** 组件生命周期函数,在组件布局完成后执行,此时可以获取节点信息(使用 [SelectorQuery]((SelectorQuery))) */
|
||||
ready?(this: WxComponent): void;
|
||||
/** 组件生命周期函数,在组件实例被移动到节点树另一个位置时执行 */
|
||||
moved?(this: WxComponent): void;
|
||||
/** 组件生命周期函数,在组件实例被从页面节点树移除时执行 */
|
||||
detached?(this: WxComponent): void;
|
||||
/** 组件生命周期函数,每当组件方法抛出错误时执行 */
|
||||
error?(error: Error): void;
|
||||
}
|
||||
|
||||
declare interface PageLifetimes {
|
||||
/** 页面生命周期回调—监听页面显示
|
||||
*
|
||||
* 页面显示/切入前台时触发。
|
||||
*/
|
||||
show?(this: Page.PageInstance): void;
|
||||
/** 页面生命周期回调—监听页面隐藏
|
||||
*
|
||||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
|
||||
*/
|
||||
hide?(this: Page.PageInstance): void;
|
||||
/** 页面生命周期回调—监听页面尺寸变化
|
||||
*
|
||||
* 所在页面尺寸变化时执行
|
||||
*/
|
||||
resize?(Size?: Page.IResizeOption): void;
|
||||
}
|
||||
|
||||
declare interface RelationOption {
|
||||
/** 目标组件的相对关系 */
|
||||
type: 'parent' | 'child' | 'ancestor' | 'descendant';
|
||||
/** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
|
||||
linked?(target: WxComponent): any;
|
||||
/** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
|
||||
linkChanged?(target: WxComponent): any;
|
||||
/** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
|
||||
unlinked?(target: WxComponent): any;
|
||||
/** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
|
||||
target?: string;
|
||||
}
|
||||
|
||||
type DefinitionFilter = (
|
||||
defFields: WxComponent,
|
||||
definitionFilterArr?: DefinitionFilter[],
|
||||
) => void;
|
||||
|
||||
declare interface ComponentOptions {
|
||||
multipleSlots?: boolean;
|
||||
addGlobalClass?: boolean;
|
||||
}
|
||||
|
||||
declare interface BaseComponent extends ComponentLifetimes {
|
||||
/** 组件的对外属性,是属性名到属性设置的映射表 */
|
||||
properties?: {
|
||||
[propertyName: string]: PropertyOption;
|
||||
};
|
||||
/** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
|
||||
data?: IAnyObject;
|
||||
/** 组件数据字段监听器,用于监听 properties 和 data 的变化 */
|
||||
observers?: IAnyObject;
|
||||
/** object组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件事件](events.md) */
|
||||
methods?: {
|
||||
[methodName: string]: (this: WxComponent) => any;
|
||||
};
|
||||
/** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](behaviors.md) */
|
||||
behaviors?: string[];
|
||||
/** 组件间关系定义,参见 [组件间关系](relations.md) */
|
||||
relations?: {
|
||||
[componentName: string]: RelationOption;
|
||||
};
|
||||
/** 组件接受的外部样式类,参见 [外部样式类](wxml-wxss.md) */
|
||||
externalClasses?: string[];
|
||||
/** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */
|
||||
options?: ComponentOptions;
|
||||
/** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高
|
||||
*
|
||||
* 最低基础库: `2.2.3` */
|
||||
lifetimes?: ComponentLifetimes;
|
||||
/** 组件所在页面的生命周期声明对象,目前仅支持页面的 `show` 和 `hide` 两个生命周期
|
||||
*
|
||||
* 最低基础库: `2.2.3` */
|
||||
pageLifetimes?: PageLifetimes;
|
||||
/** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](extend.md)
|
||||
*
|
||||
* 最低基础库: `2.2.3` */
|
||||
definitionFilter?: DefinitionFilter;
|
||||
}
|
||||
|
||||
/** Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性、数据、方法等。
|
||||
*
|
||||
* * 使用 `this.data` 可以获取内部数据和属性值,但不要直接修改它们,应使用 `setData` 修改。
|
||||
* * 生命周期函数无法在组件方法中通过 `this` 访问到。
|
||||
* * 属性名应避免以 data 开头,即不要命名成 `dataXyz` 这样的形式,因为在 WXML 中, `data-xyz=""` 会被作为节点 dataset 来处理,而不是组件属性。
|
||||
* * 在一个组件的定义和使用时,组件的属性名和 data 字段相互间都不能冲突(尽管它们位于不同的定义段中)。
|
||||
* * 从基础库 `2.0.9` 开始,对象类型的属性和 data 字段中可以包含函数类型的子字段,即可以通过对象类型的属性字段来传递函数。低于这一版本的基础库不支持这一特性。
|
||||
* * `bug` : 对于 type 为 Object 或 Array 的属性,如果通过该组件自身的 `this.setData` 来改变属性值的一个子字段,则依旧会触发属性 observer ,且 observer 接收到的 `newVal` 是变化的那个子字段的值, `oldVal` 为空, `changedPath` 包含子字段的字段名相关信息。
|
||||
*/
|
||||
declare function Component(
|
||||
/** 自定义组件注册参数 */ options: BaseComponent,
|
||||
): void;
|
|
@ -0,0 +1,212 @@
|
|||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) 2018 Tencent, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace Page {
|
||||
interface ICustomShareContent {
|
||||
/** 转发标题。默认值:当前小程序名称 */
|
||||
title?: string;
|
||||
/** 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path */
|
||||
path?: string;
|
||||
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,最低基础库: `1.5.0`。默认值:使用默认截图 */
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
interface IPageScrollOption {
|
||||
/** 页面在垂直方向已滚动的距离(单位px) */
|
||||
scrollTop: number;
|
||||
}
|
||||
|
||||
interface IShareAppMessageOption {
|
||||
/** 转发事件来源。
|
||||
*
|
||||
* 可选值:
|
||||
* - `button`:页面内转发按钮;
|
||||
* - `menu`:右上角转发菜单。
|
||||
*
|
||||
* 最低基础库: `1.2.4`
|
||||
*/
|
||||
from: 'button' | 'menu' | string;
|
||||
/** 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined`
|
||||
*
|
||||
* 最低基础库: `1.2.4` */
|
||||
target: any;
|
||||
/** 页面中包含`<web-view>`组件时,返回当前`<web-view>`的url
|
||||
*
|
||||
* 最低基础库: `1.6.4`
|
||||
*/
|
||||
webViewUrl?: string;
|
||||
}
|
||||
|
||||
interface ITabItemTapOption {
|
||||
/** 被点击tabItem的序号,从0开始,最低基础库: `1.9.0` */
|
||||
index: string;
|
||||
/** 被点击tabItem的页面路径,最低基础库: `1.9.0` */
|
||||
pagePath: string;
|
||||
/** 被点击tabItem的按钮文字,最低基础库: `1.9.0` */
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface IResizeOption {
|
||||
size: {
|
||||
/** 变化后的窗口宽度,单位 px */
|
||||
windowWidth: number;
|
||||
/** 变化后的窗口高度,单位 px */
|
||||
windowHeight: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface PageInstanceBaseProps<D extends IAnyObject = any> {
|
||||
/** 页面的初始数据
|
||||
*
|
||||
* `data` 是页面第一次渲染使用的**初始数据**。
|
||||
*
|
||||
* 页面加载时,`data` 将会以`JSON`字符串的形式由逻辑层传至渲染层,因此`data`中的数据必须是可以转成`JSON`的类型:字符串,数字,布尔值,对象,数组。
|
||||
*
|
||||
* 渲染层可以通过 `WXML` 对数据进行绑定。
|
||||
*/
|
||||
data?: D;
|
||||
|
||||
/** `setData` 函数用于将数据从逻辑层发送到视图层(异步),同时改变对应的 `this.data` 的值(同步)。
|
||||
*
|
||||
* **注意:**
|
||||
*
|
||||
* 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。
|
||||
* 1. 仅支持设置可 JSON 化的数据。
|
||||
* 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。
|
||||
* 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。
|
||||
*/
|
||||
|
||||
setData?<K extends keyof D>(
|
||||
/** 这次要改变的数据
|
||||
*
|
||||
* 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。
|
||||
*
|
||||
* 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。
|
||||
*/
|
||||
data: D | Pick<D, K> | IAnyObject,
|
||||
/** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */
|
||||
callback?: () => void,
|
||||
): void;
|
||||
|
||||
/** 到当前页面的路径,类型为`String`。最低基础库: `1.2.0` */
|
||||
route?: string;
|
||||
}
|
||||
|
||||
interface PageInstance<
|
||||
D extends IAnyObject = any,
|
||||
T extends IAnyObject = any
|
||||
> extends PageInstanceBaseProps<D> {
|
||||
/** 生命周期回调—监听页面加载
|
||||
*
|
||||
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。
|
||||
*/
|
||||
onLoad?(
|
||||
/** 打开当前页面路径中的参数 */
|
||||
query?: { [queryKey: string]: string },
|
||||
): void;
|
||||
/** 生命周期回调—监听页面显示
|
||||
*
|
||||
* 页面显示/切入前台时触发。
|
||||
*/
|
||||
onShow?(): void;
|
||||
/** 生命周期回调—监听页面初次渲染完成
|
||||
*
|
||||
* 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
|
||||
*
|
||||
|
||||
* 注意:对界面内容进行设置的 API 如`wx.setNavigationBarTitle`,请在`onReady`之后进行。
|
||||
*/
|
||||
onReady?(): void;
|
||||
/** 生命周期回调—监听页面隐藏
|
||||
*
|
||||
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
|
||||
*/
|
||||
onHide?(): void;
|
||||
/** 生命周期回调—监听页面卸载
|
||||
*
|
||||
* 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。
|
||||
*/
|
||||
onUnload?(): void;
|
||||
/** 监听用户下拉动作
|
||||
*
|
||||
* 监听用户下拉刷新事件。
|
||||
* - 需要在`app.json`的`window`选项中或页面配置中开启`enablePullDownRefresh`。
|
||||
* - 可以通过`wx.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
||||
* - 当处理完数据刷新后,`wx.stopPullDownRefresh`可以停止当前页面的下拉刷新。
|
||||
*/
|
||||
onPullDownRefresh?(): void;
|
||||
/** 页面上拉触底事件的处理函数
|
||||
*
|
||||
* 监听用户上拉触底事件。
|
||||
* - 可以在`app.json`的`window`选项中或页面配置中设置触发距离`onReachBottomDistance`。
|
||||
* - 在触发距离内滑动期间,本事件只会被触发一次。
|
||||
*/
|
||||
onReachBottom?(): void;
|
||||
/** 用户点击右上角转发
|
||||
*
|
||||
* 监听用户点击页面内转发按钮(`<button>` 组件 `open-type="share"`)或右上角菜单“转发”按钮的行为,并自定义转发内容。
|
||||
*
|
||||
* **注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮**
|
||||
*
|
||||
* 此事件需要 return 一个 Object,用于自定义转发内容
|
||||
*/
|
||||
onShareAppMessage?(
|
||||
/** 分享发起来源参数 */
|
||||
options?: IShareAppMessageOption,
|
||||
): ICustomShareContent;
|
||||
/** 页面滚动触发事件的处理函数
|
||||
*
|
||||
* 监听用户滑动页面事件。
|
||||
*/
|
||||
onPageScroll?(
|
||||
/** 页面滚动参数 */
|
||||
options?: IPageScrollOption,
|
||||
): void;
|
||||
|
||||
/** 当前是 tab 页时,点击 tab 时触发,最低基础库: `1.9.0` */
|
||||
onTabItemTap?(
|
||||
/** tab 点击参数 */
|
||||
options?: ITabItemTapOption,
|
||||
): void;
|
||||
|
||||
/** 窗口尺寸改变时触发,最低基础库:`2.4.0` */
|
||||
onResize?(
|
||||
/** 窗口尺寸参数 */
|
||||
options?: IResizeOption,
|
||||
): void;
|
||||
}
|
||||
|
||||
interface PageConstructor {
|
||||
<D extends IAnyObject, T extends IAnyObject & PageInstance>(
|
||||
options: PageInstance<D, T> & T,
|
||||
): void;
|
||||
}
|
||||
|
||||
interface GetCurrentPages {
|
||||
<D extends IAnyObject = {}, T extends IAnyObject = {}>(): (PageInstance<
|
||||
D,
|
||||
T
|
||||
> &
|
||||
T)[];
|
||||
}
|
||||
}
|
||||
|
||||
declare const Page: Page.PageConstructor;
|
||||
declare const getCurrentPages: Page.GetCurrentPages;
|
Loading…
Reference in New Issue