build(typings): use miniprogram-api-typings & update quickstart (#3746)

fix #3699
This commit is contained in:
rex 2020-11-11 11:20:31 +08:00 committed by GitHub
parent 3d3af763c1
commit 101e0f463b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 103 additions and 177 deletions

View File

@ -23,19 +23,20 @@ npm i vant-weapp -S --production
### 步骤二 修改 app.json ### 步骤二 修改 app.json
将 app.json 中的 `"style": "v2"` 去除,小程序的[新版基础组件](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#style)强行加上了许多样式,难以去除,不关闭将造成部分组件样式混乱。 将 app.json 中的 `"style": "v2"` 去除,小程序的[新版基础组件](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#style)强行加上了许多样式,难以覆盖,不关闭将造成部分组件样式混乱。
### 步骤三 修改 project.config.json ### 步骤三 修改 project.config.json
开发者工具创建的项目,`miniprogramRoot` 默认为 `miniprogram``package.json` 在其外部npm 构建无法正常工作。 开发者工具创建的项目,`miniprogramRoot` 默认为 `miniprogram``package.json` 在其外部npm 构建无法正常工作。
需要手动在 `project.config.json` 内添加如下配置,使开发者工具可以正确索引到 npm 依赖的位置 需要手动在 `project.config.json` 内添加如下配置,使开发者工具可以正确索引到 npm 依赖的位置
```json ```json
{ {
... ...
"setting": { "setting": {
... ...
"packNpmManually": true,
"packNpmRelationList": [ "packNpmRelationList": [
{ {
"packageJsonPath": "./package.json", "packageJsonPath": "./package.json",
@ -48,15 +49,27 @@ npm i vant-weapp -S --production
### 步骤四 构建 npm 包 ### 步骤四 构建 npm 包
打开微信开发者工具,点击 **工具 -> 构建 npm**,并勾选 **使用 npm 模块** 选项,构建完成后,即可引入组件 打开微信开发者工具,点击 **工具 -> 构建 npm**,并勾选 **使用 npm 模块** 选项,构建完成后,即可引入组件
<img style="width: 500px;" src="https://img.yzcdn.cn/public_files/2019/08/15/fa0549210055976cb63798503611ce3d.png" /> <img style="width: 500px;" src="https://img.yzcdn.cn/public_files/2019/08/15/fa0549210055976cb63798503611ce3d.png" />
### 步骤三 修改 tsconfig.json ### 步骤五 typescript 支持
如果你使用 typescript 开发小程序,需要在 `tsconfig.json` 中增加如下配置,防止 tsc 编译报错 如果你使用 typescript 开发小程序,还需要做如下操作,以获得顺畅的开发体验。
请将`path/to/node_modules/@vant/weapp`修改为项目的 `node_modules`@vant/weapp 所在的目录 #### 安装 miniprogram-api-typings
```bash
# 通过 npm 安装
npm i -D miniprogram-api-typings
# 通过 yarn 安装
yarn add -D miniprogram-api-typings
```
#### 在 tsconfig.json 中增加如下配置,以防止 tsc 编译报错。
请将`path/to/node_modules/@vant/weapp`修改为项目的 `node_modules`@vant/weapp 所在的目录。
```json ```json
{ {
@ -64,10 +77,11 @@ npm i vant-weapp -S --production
"compilerOptions": { "compilerOptions": {
... ...
"baseUrl": ".", "baseUrl": ".",
"types": ["miniprogram-api-typings"],
"paths": { "paths": {
"@vant/weapp/*": ["path/to/node_modules/@vant/weapp/dist/*"] "@vant/weapp/*": ["path/to/node_modules/@vant/weapp/dist/*"]
}, },
"lib": ["es6"] "lib": ["ES6"]
} }
} }
``` ```

View File

@ -33,7 +33,8 @@
"useCompilerModule": true, "useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false, "userConfirmedUseCompilerModuleSwitch": false,
"packNpmManually": false, "packNpmManually": false,
"packNpmRelationList": [] "packNpmRelationList": [],
"minifyWXSS": true
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"cloudfunctionRoot": "functions/", "cloudfunctionRoot": "functions/",
@ -48,26 +49,21 @@
"simulatorPluginLibVersion": {}, "simulatorPluginLibVersion": {},
"condition": { "condition": {
"search": { "search": {
"current": -1,
"list": [] "list": []
}, },
"conversation": { "conversation": {
"current": -1,
"list": [] "list": []
}, },
"plugin": { "plugin": {
"current": -1,
"list": [] "list": []
}, },
"game": { "game": {
"list": [] "list": []
}, },
"gamePlugin": { "gamePlugin": {
"current": -1,
"list": [] "list": []
}, },
"miniprogram": { "miniprogram": {
"current": 42,
"list": [ "list": [
{ {
"id": -1, "id": -1,

View File

@ -68,6 +68,7 @@
"less": "^3.9.0", "less": "^3.9.0",
"less-loader": "^7.0.0", "less-loader": "^7.0.0",
"lint-staged": "^10.0.0", "lint-staged": "^10.0.0",
"miniprogram-api-typings": "^3.1.6",
"miniprogram-ci": "^1.0.27", "miniprogram-ci": "^1.0.27",
"postcss": "^8.1.1", "postcss": "^8.1.1",
"postcss-loader": "^4.0.0", "postcss-loader": "^4.0.0",
@ -94,7 +95,5 @@
"ChromeAndroid >= 53", "ChromeAndroid >= 53",
"iOS >= 8" "iOS >= 8"
], ],
"dependencies": { "dependencies": {}
"@types/wechat-miniprogram": "^3.0.0"
}
} }

View File

@ -40,7 +40,7 @@ VantComponent({
}, },
methods: { methods: {
onSelect(event: WechatMiniprogram.TapEvent) { onSelect(event: WechatMiniprogram.TouchEvent) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
const item = this.data.actions[index]; const item = this.data.actions[index];
if (item && !item.disabled && !item.loading) { if (item && !item.disabled && !item.loading) {

View File

@ -1,6 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { pickerProps } from '../picker/shared'; import { pickerProps } from '../picker/shared';
import { Weapp } from 'definitions/weapp';
import { requestAnimationFrame } from '../common/utils'; import { requestAnimationFrame } from '../common/utils';
type AreaItem = { type AreaItem = {
@ -70,11 +69,11 @@ VantComponent({
return this.picker; return this.picker;
}, },
onCancel(event: Weapp.Event) { onCancel(event: WechatMiniprogram.CustomEvent) {
this.emit('cancel', event.detail); this.emit('cancel', event.detail);
}, },
onConfirm(event: Weapp.Event) { onConfirm(event: WechatMiniprogram.CustomEvent) {
const { index } = event.detail; const { index } = event.detail;
let { value } = event.detail; let { value } = event.detail;
value = this.parseOutputValues(value); value = this.parseOutputValues(value);
@ -103,7 +102,7 @@ VantComponent({
}); });
}, },
onChange(event: Weapp.Event) { onChange(event: WechatMiniprogram.CustomEvent) {
const { index, picker, value } = event.detail; const { index, picker, value } = event.detail;
this.code = value[index].code; this.code = value[index].code;
this.setValues().then(() => { this.setValues().then(() => {

View File

@ -34,7 +34,7 @@ VantComponent({
}, },
methods: { methods: {
onClick(event: WechatMiniprogram.TapEvent) { onClick(event: WechatMiniprogram.TouchEvent) {
this.$emit('click', event.detail); this.$emit('click', event.detail);
this.jumpLink(); this.jumpLink();
}, },

View File

@ -1,8 +1,8 @@
type CanvasContext = WechatMiniprogram.CanvasContext; type CanvasContext = WechatMiniprogram.CanvasContext;
export function adaptor( export function adaptor(
ctx: CanvasRenderingContext2D ctx: CanvasContext & Record<string, unknown>
): CanvasContext & CanvasRenderingContext2D { ): CanvasContext {
// @ts-ignore // @ts-ignore
return Object.assign(ctx, { return Object.assign(ctx, {
setStrokeStyle(val) { setStrokeStyle(val) {

View File

@ -1,7 +1,7 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isSameSecond, parseFormat, parseTimeData } from './utils'; import { isSameSecond, parseFormat, parseTimeData } from './utils';
function simpleTick(fn: Function) { function simpleTick(fn: WechatMiniprogram.SetTimeoutCompleteCallback) {
return setTimeout(fn, 30); return setTimeout(fn, 30);
} }

View File

@ -7,65 +7,6 @@ export namespace Weapp {
}; };
} }
interface Target {
id: string;
tagName: string;
dataset: {
[key: string]: any;
};
}
export interface Event {
/**
*
*/
type: string;
/**
*
*/
timeStamp: number;
/**
*
*/
target: Target;
/**
*
*/
currentTarget: Target;
/**
*
*/
detail: any;
}
interface Touch {
/**
*
*/
identifier: number;
/**
* X轴Y轴
*/
pageX: number;
/**
* X轴Y轴
*/
pageY: number;
/**
* X轴Y轴
*/
clientX: number;
/**
* X轴Y轴
*/
clientY: number;
}
export interface TouchEvent extends Event {
touches: Array<Touch>;
changedTouches: Array<Touch>;
}
/** /**
* relation定义miniprogram-api-typings缺少this定义 * relation定义miniprogram-api-typings缺少this定义
*/ */

View File

@ -86,7 +86,7 @@ VantComponent({
this.setData({ showWrapper: false }); this.setData({ showWrapper: false });
}, },
onOptionTap(event: WechatMiniprogram.TapEvent) { onOptionTap(event: WechatMiniprogram.TouchEvent) {
const { option } = event.currentTarget.dataset; const { option } = event.currentTarget.dataset;
const { value } = (option as unknown) as Option; const { value } = (option as unknown) as Option;

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
import { addUnit } from '../common/utils'; import { addUnit } from '../common/utils';
type TrivialInstance = WechatMiniprogram.Component.TrivialInstance; type TrivialInstance = WechatMiniprogram.Component.TrivialInstance;
@ -121,7 +120,7 @@ VantComponent({
); );
}, },
onTitleTap(event: Weapp.Event) { onTitleTap(event: WechatMiniprogram.TouchEvent) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
const child = this.children[index]; const child = this.children[index];

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
import { commonProps, inputProps, textareaProps } from './props'; import { commonProps, inputProps, textareaProps } from './props';
VantComponent({ VantComponent({
@ -59,7 +58,7 @@ VantComponent({
}, },
methods: { methods: {
onInput(event: Weapp.Event) { onInput(event: WechatMiniprogram.Input | WechatMiniprogram.TextareaInput) {
const { value = '' } = event.detail || {}; const { value = '' } = event.detail || {};
this.value = value; this.value = value;
@ -67,13 +66,17 @@ VantComponent({
this.emitChange(); this.emitChange();
}, },
onFocus(event: Weapp.Event) { onFocus(
event: WechatMiniprogram.InputFocus | WechatMiniprogram.TextareaFocus
) {
this.focused = true; this.focused = true;
this.setShowClear(); this.setShowClear();
this.$emit('focus', event.detail); this.$emit('focus', event.detail);
}, },
onBlur(event: Weapp.Event) { onBlur(
event: WechatMiniprogram.InputBlur | WechatMiniprogram.TextareaBlur
) {
this.focused = false; this.focused = false;
this.setShowClear(); this.setShowClear();
this.$emit('blur', event.detail); this.$emit('blur', event.detail);
@ -94,7 +97,9 @@ VantComponent({
}); });
}, },
onConfirm(event) { onConfirm(
event: WechatMiniprogram.InputConfirm | WechatMiniprogram.TextareaConfirm
) {
const { value = '' } = event.detail || {}; const { value = '' } = event.detail || {};
this.value = value; this.value = value;
this.setShowClear(); this.setShowClear();
@ -112,11 +117,15 @@ VantComponent({
this.emitChange(); this.emitChange();
}, },
onLineChange(event) { onLineChange(event: WechatMiniprogram.TextareaLineChange) {
this.$emit('linechange', event.detail); this.$emit('linechange', event.detail);
}, },
onKeyboardHeightChange(event) { onKeyboardHeightChange(
event:
| WechatMiniprogram.InputKeyboardHeightChange
| WechatMiniprogram.TextareaKeyboardHeightChange
) {
this.$emit('keyboardheightchange', event.detail); this.$emit('keyboardheightchange', event.detail);
}, },

View File

@ -2,7 +2,6 @@ import { VantComponent } from '../common/component';
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
mixins: [link, button, openType], mixins: [link, button, openType],
@ -24,7 +23,7 @@ VantComponent({
}, },
methods: { methods: {
onClick(event: Weapp.Event) { onClick(event: WechatMiniprogram.CustomEvent) {
this.$emit('click', event.detail); this.$emit('click', event.detail);
this.jumpLink(); this.jumpLink();
}, },

View File

@ -1,8 +1,7 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { link } from '../mixins/link';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { link } from '../mixins/link';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
classes: ['icon-class', 'text-class'], classes: ['icon-class', 'text-class'],
@ -19,7 +18,7 @@ VantComponent({
}, },
methods: { methods: {
onClick(event: Weapp.Event) { onClick(event: WechatMiniprogram.CustomEvent) {
this.$emit('click', event.detail); this.$emit('click', event.detail);
this.jumpLink(); this.jumpLink();
}, },

View File

@ -6,27 +6,27 @@ export const openType = Behavior({
}, },
methods: { methods: {
bindGetUserInfo(event: WechatMiniprogram.TapEvent) { bindGetUserInfo(event: WechatMiniprogram.ButtonGetUserInfo) {
this.$emit('getuserinfo', event.detail); this.$emit('getuserinfo', event.detail);
}, },
bindContact(event: WechatMiniprogram.TapEvent) { bindContact(event: WechatMiniprogram.ButtonContact) {
this.$emit('contact', event.detail); this.$emit('contact', event.detail);
}, },
bindGetPhoneNumber(event: WechatMiniprogram.TapEvent) { bindGetPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) {
this.$emit('getphonenumber', event.detail); this.$emit('getphonenumber', event.detail);
}, },
bindError(event: WechatMiniprogram.TapEvent) { bindError(event: WechatMiniprogram.ButtonError) {
this.$emit('error', event.detail); this.$emit('error', event.detail);
}, },
bindLaunchApp(event: WechatMiniprogram.TapEvent) { bindLaunchApp(event: WechatMiniprogram.ButtonLaunchApp) {
this.$emit('launchapp', event.detail); this.$emit('launchapp', event.detail);
}, },
bindOpenSetting(event: WechatMiniprogram.TapEvent) { bindOpenSetting(event: WechatMiniprogram.ButtonOpenSetting) {
this.$emit('opensetting', event.detail); this.$emit('opensetting', event.detail);
}, },
}, },

View File

@ -1,6 +1,4 @@
// @ts-nocheck // @ts-nocheck
import { Weapp } from 'definitions/weapp';
const MIN_DISTANCE = 10; const MIN_DISTANCE = 10;
function getDirection(x: number, y: number) { function getDirection(x: number, y: number) {
@ -25,14 +23,14 @@ export const touch = Behavior({
this.offsetY = 0; this.offsetY = 0;
}, },
touchStart(event: Weapp.TouchEvent) { touchStart(event: WechatMiniprogram.TouchEvent) {
this.resetTouchStatus(); this.resetTouchStatus();
const touch = event.touches[0]; const touch = event.touches[0];
this.startX = touch.clientX; this.startX = touch.clientX;
this.startY = touch.clientY; this.startY = touch.clientY;
}, },
touchMove(event: Weapp.TouchEvent) { touchMove(event: WechatMiniprogram.TouchEvent) {
const touch = event.touches[0]; const touch = event.touches[0];
this.deltaX = touch.clientX - this.startX; this.deltaX = touch.clientX - this.startX;
this.deltaY = touch.clientY - this.startY; this.deltaY = touch.clientY - this.startY;

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
import { getRect, requestAnimationFrame } from '../common/utils'; import { getRect, requestAnimationFrame } from '../common/utils';
VantComponent({ VantComponent({
@ -137,7 +136,7 @@ VantComponent({
} }
}, },
onClick(event: Weapp.Event) { onClick(event: WechatMiniprogram.TouchEvent) {
this.$emit('click', event); this.$emit('click', event);
}, },
}, },

View File

@ -1,4 +1,3 @@
import { Weapp } from 'definitions/weapp';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { WHITE } from '../common/color'; import { WHITE } from '../common/color';
@ -63,7 +62,7 @@ VantComponent({
wx.nextTick(onClose); wx.nextTick(onClose);
}, },
onTap(event: Weapp.Event) { onTap(event: WechatMiniprogram.TouchEvent) {
const { onClick } = this.data; const { onClick } = this.data;
if (onClick) { if (onClick) {
onClick(event.detail); onClick(event.detail);

View File

@ -1,6 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isObj, range } from '../common/utils'; import { isObj, range } from '../common/utils';
import { Weapp } from 'definitions/weapp';
const DEFAULT_DURATION = 200; const DEFAULT_DURATION = 200;
@ -50,7 +49,7 @@ VantComponent({
return this.data.options.length; return this.data.options.length;
}, },
onTouchStart(event: Weapp.TouchEvent) { onTouchStart(event: WechatMiniprogram.TouchEvent) {
this.setData({ this.setData({
startY: event.touches[0].clientY, startY: event.touches[0].clientY,
startOffset: this.data.offset, startOffset: this.data.offset,
@ -58,7 +57,7 @@ VantComponent({
}); });
}, },
onTouchMove(event: Weapp.TouchEvent) { onTouchMove(event: WechatMiniprogram.TouchEvent) {
const { data } = this; const { data } = this;
const deltaY = event.touches[0].clientY - data.startY; const deltaY = event.touches[0].clientY - data.startY;
this.setData({ this.setData({
@ -84,7 +83,7 @@ VantComponent({
} }
}, },
onClickItem(event: Weapp.Event) { onClickItem(event: WechatMiniprogram.TouchEvent) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
this.setIndex(index, true); this.setIndex(index, true);
}, },

View File

@ -1,6 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { pickerProps } from './shared'; import { pickerProps } from './shared';
import { Weapp } from 'definitions/weapp';
interface Column { interface Column {
values: object[]; values: object[];
@ -54,22 +53,7 @@ VantComponent({
return Promise.all(stack); return Promise.all(stack);
}, },
emit(event: Weapp.Event) { onChange(event: WechatMiniprogram.CustomEvent) {
const { type } = event.currentTarget.dataset;
if (this.simple) {
this.$emit(type, {
value: this.getColumnValue(0),
index: this.getColumnIndex(0),
});
} else {
this.$emit(type, {
value: this.getValues(),
index: this.getIndexes(),
});
}
},
onChange(event: Weapp.Event) {
if (this.simple) { if (this.simple) {
this.$emit('change', { this.$emit('change', {
picker: this, picker: this,

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
import { canIUseModel } from '../common/version'; import { canIUseModel } from '../common/version';
VantComponent({ VantComponent({
@ -60,7 +59,7 @@ VantComponent({
}, },
methods: { methods: {
onSelect(event: Weapp.Event) { onSelect(event: WechatMiniprogram.CustomEvent) {
const { data } = this; const { data } = this;
const { score } = event.currentTarget.dataset; const { score } = event.currentTarget.dataset;
if (!data.disabled && !data.readonly) { if (!data.disabled && !data.readonly) {
@ -77,7 +76,7 @@ VantComponent({
} }
}, },
onTouchMove(event: Weapp.TouchEvent) { onTouchMove(event: WechatMiniprogram.TouchEvent) {
const { touchable } = this.data; const { touchable } = this.data;
if (!touchable) return; if (!touchable) return;

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
import { canIUseModel } from '../common/version'; import { canIUseModel } from '../common/version';
VantComponent({ VantComponent({
@ -48,7 +47,7 @@ VantComponent({
}, },
methods: { methods: {
onChange(event: Weapp.Event) { onChange(event: WechatMiniprogram.CustomEvent) {
if (canIUseModel()) { if (canIUseModel()) {
this.setData({ value: event.detail }); this.setData({ value: event.detail });
} }
@ -69,19 +68,19 @@ VantComponent({
}, 200); }, 200);
}, },
onSearch(event) { onSearch(event: WechatMiniprogram.CustomEvent) {
this.$emit('search', event.detail); this.$emit('search', event.detail);
}, },
onFocus(event) { onFocus(event: WechatMiniprogram.CustomEvent) {
this.$emit('focus', event.detail); this.$emit('focus', event.detail);
}, },
onBlur(event) { onBlur(event: WechatMiniprogram.CustomEvent) {
this.$emit('blur', event.detail); this.$emit('blur', event.detail);
}, },
onClear(event) { onClear(event: WechatMiniprogram.CustomEvent) {
this.$emit('clear', event.detail); this.$emit('clear', event.detail);
}, },
}, },

View File

@ -1,4 +1,3 @@
import { Weapp } from 'definitions/weapp';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
@ -50,7 +49,7 @@ VantComponent({
this.$emit('cancel'); this.$emit('cancel');
}, },
onSelect(event: Weapp.Event) { onSelect(event: WechatMiniprogram.CustomEvent) {
this.$emit('select', event.detail); this.$emit('select', event.detail);
}, },

View File

@ -1,6 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch'; import { touch } from '../mixins/touch';
import { Weapp } from 'definitions/weapp';
import { canIUseModel } from '../common/version'; import { canIUseModel } from '../common/version';
VantComponent({ VantComponent({
@ -43,7 +42,7 @@ VantComponent({
}, },
methods: { methods: {
onTouchStart(event: Weapp.TouchEvent) { onTouchStart(event: WechatMiniprogram.TouchEvent) {
if (this.data.disabled) return; if (this.data.disabled) return;
this.touchStart(event); this.touchStart(event);
@ -51,7 +50,7 @@ VantComponent({
this.dragStatus = 'start'; this.dragStatus = 'start';
}, },
onTouchMove(event: Weapp.TouchEvent) { onTouchMove(event: WechatMiniprogram.TouchEvent) {
if (this.data.disabled) return; if (this.data.disabled) return;
if (this.dragStatus === 'start') { if (this.dragStatus === 'start') {
@ -79,7 +78,7 @@ VantComponent({
} }
}, },
onClick(event: Weapp.TouchEvent) { onClick(event: WechatMiniprogram.TouchEvent) {
if (this.data.disabled) return; if (this.data.disabled) return;
const { min } = this.data; const { min } = this.data;

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
import { isDef } from '../common/utils'; import { isDef } from '../common/utils';
const LONG_PRESS_START_TIME = 600; const LONG_PRESS_START_TIME = 600;
@ -107,11 +106,11 @@ VantComponent({
); );
}, },
onFocus(event: Weapp.Event) { onFocus(event: WechatMiniprogram.InputFocus) {
this.$emit('focus', event.detail); this.$emit('focus', event.detail);
}, },
onBlur(event: Weapp.Event) { onBlur(event: WechatMiniprogram.InputBlur) {
const value = this.format(event.detail.value); const value = this.format(event.detail.value);
this.emitChange(value); this.emitChange(value);
this.$emit('blur', { this.$emit('blur', {
@ -147,7 +146,7 @@ VantComponent({
return value; return value;
}, },
onInput(event: Weapp.Event) { onInput(event: WechatMiniprogram.Input) {
const { value = '' } = event.detail || {}; const { value = '' } = event.detail || {};
// allow input to be empty // allow input to be empty
@ -196,13 +195,13 @@ VantComponent({
}, LONG_PRESS_INTERVAL); }, LONG_PRESS_INTERVAL);
}, },
onTap(event: Weapp.Event) { onTap(event: WechatMiniprogram.TouchEvent) {
const { type } = event.currentTarget.dataset; const { type } = event.currentTarget.dataset;
this.type = type; this.type = type;
this.onChange(); this.onChange();
}, },
onTouchStart(event: Weapp.Event) { onTouchStart(event: WechatMiniprogram.TouchEvent) {
if (!this.data.longPress) { if (!this.data.longPress) {
return; return;
} }

View File

@ -1,4 +1,3 @@
import { Weapp } from 'definitions/weapp';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { GREEN, GRAY_DARK } from '../common/color'; import { GREEN, GRAY_DARK } from '../common/color';
@ -29,7 +28,7 @@ VantComponent({
}, },
methods: { methods: {
onClick(event: Weapp.Event) { onClick(event: WechatMiniprogram.TouchEvent) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
this.$emit('click-step', index); this.$emit('click-step', index);
}, },

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
classes: ['bar-class', 'price-class', 'button-class'], classes: ['bar-class', 'price-class', 'button-class'],
@ -56,7 +55,7 @@ VantComponent({
this.setData({ hasTip: typeof this.data.tip === 'string' }); this.setData({ hasTip: typeof this.data.tip === 'string' });
}, },
onSubmit(event: Weapp.Event) { onSubmit(event: WechatMiniprogram.CustomEvent) {
this.$emit('submit', event.detail); this.$emit('submit', event.detail);
}, },
}, },

View File

@ -1,6 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch'; import { touch } from '../mixins/touch';
import { Weapp } from 'definitions/weapp';
import { range } from '../common/utils'; import { range } from '../common/utils';
const THRESHOLD = 0.3; const THRESHOLD = 0.3;
@ -98,7 +97,7 @@ VantComponent({
this.setData({ catchMove: false }); this.setData({ catchMove: false });
}, },
startDrag(event: Weapp.TouchEvent) { startDrag(event: WechatMiniprogram.TouchEvent) {
if (this.data.disabled) { if (this.data.disabled) {
return; return;
} }
@ -109,7 +108,7 @@ VantComponent({
noop() {}, noop() {},
onDrag(event: Weapp.TouchEvent) { onDrag(event: WechatMiniprogram.TouchEvent) {
if (this.data.disabled) { if (this.data.disabled) {
return; return;
} }
@ -135,7 +134,7 @@ VantComponent({
this.swipeLeaveTransition(); this.swipeLeaveTransition();
}, },
onClick(event: Weapp.Event) { onClick(event: WechatMiniprogram.TouchEvent) {
const { key: position = 'outside' } = event.currentTarget.dataset; const { key: position = 'outside' } = event.currentTarget.dataset;
this.$emit('click', position); this.$emit('click', position);

View File

@ -1,6 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch'; import { touch } from '../mixins/touch';
import { Weapp } from 'definitions/weapp';
import { getAllRect, getRect, isDef } from '../common/utils'; import { getAllRect, getRect, isDef } from '../common/utils';
type TrivialInstance = WechatMiniprogram.Component.TrivialInstance; type TrivialInstance = WechatMiniprogram.Component.TrivialInstance;
@ -150,7 +149,7 @@ VantComponent({
}); });
}, },
onTap(event: Weapp.Event) { onTap(event: WechatMiniprogram.TouchEvent) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
const child = this.children[index]; const child = this.children[index];
@ -274,17 +273,17 @@ VantComponent({
}); });
}, },
onTouchScroll(event: Weapp.TouchEvent) { onTouchScroll(event: WechatMiniprogram.CustomEvent) {
this.$emit('scroll', event.detail); this.$emit('scroll', event.detail);
}, },
onTouchStart(event: Weapp.TouchEvent) { onTouchStart(event: WechatMiniprogram.TouchEvent) {
if (!this.data.swipeable) return; if (!this.data.swipeable) return;
this.touchStart(event); this.touchStart(event);
}, },
onTouchMove(event: Weapp.TouchEvent) { onTouchMove(event: WechatMiniprogram.TouchEvent) {
if (!this.data.swipeable) return; if (!this.data.swipeable) return;
this.touchMove(event); this.touchMove(event);

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
classes: [ classes: [
@ -42,7 +41,7 @@ VantComponent({
methods: { methods: {
// 当一个子项被选择时 // 当一个子项被选择时
onSelectItem(event: Weapp.Event) { onSelectItem(event: WechatMiniprogram.TouchEvent) {
const { item } = event.currentTarget.dataset; const { item } = event.currentTarget.dataset;
const isArray = Array.isArray(this.data.activeId); const isArray = Array.isArray(this.data.activeId);
// 判断有没有超出右侧选择的最大数 // 判断有没有超出右侧选择的最大数
@ -58,8 +57,8 @@ VantComponent({
}, },
// 当一个导航被点击时 // 当一个导航被点击时
onClickNav(event: Weapp.Event) { onClickNav(event: WechatMiniprogram.CustomEvent) {
const index = event.detail; const index = (event.detail as unknown) as number;
const item = this.data.items[index]; const item = this.data.items[index];
if (!item.disabled) { if (!item.disabled) {
this.$emit('click-nav', { index }); this.$emit('click-nav', { index });

View File

@ -8,6 +8,8 @@
"outDir": "dist", "outDir": "dist",
"baseUrl": ".", "baseUrl": ".",
"strict": true, "strict": true,
"lib": ["ES6"],
"types": ["miniprogram-api-typings"],
"paths": { "paths": {
"definitions/*": ["./packages/definitions/*"], "definitions/*": ["./packages/definitions/*"],
"packages/*": ["./packages/*"] "packages/*": ["./packages/*"]

View File

@ -1648,11 +1648,6 @@
"@types/webpack-sources" "*" "@types/webpack-sources" "*"
source-map "^0.6.0" source-map "^0.6.0"
"@types/wechat-miniprogram@^3.0.0":
version "3.0.0"
resolved "https://registry.npm.taobao.org/@types/wechat-miniprogram/download/@types/wechat-miniprogram-3.0.0.tgz#401d0bf4f437dd9463e8ca99209e4742302d1e54"
integrity sha1-QB0L9PQ33ZRj6MqZIJ5HQjAtHlQ=
"@typescript-eslint/eslint-plugin@^2.28.0": "@typescript-eslint/eslint-plugin@^2.28.0":
version "2.34.0" version "2.34.0"
resolved "https://registry.npm.taobao.org/@typescript-eslint/eslint-plugin/download/@typescript-eslint/eslint-plugin-2.34.0.tgz?cache=0&sync_timestamp=1602523203775&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40typescript-eslint%2Feslint-plugin%2Fdownload%2F%40typescript-eslint%2Feslint-plugin-2.34.0.tgz#6f8ce8a46c7dea4a6f1d171d2bb8fbae6dac2be9" resolved "https://registry.npm.taobao.org/@typescript-eslint/eslint-plugin/download/@typescript-eslint/eslint-plugin-2.34.0.tgz?cache=0&sync_timestamp=1602523203775&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40typescript-eslint%2Feslint-plugin%2Fdownload%2F%40typescript-eslint%2Feslint-plugin-2.34.0.tgz#6f8ce8a46c7dea4a6f1d171d2bb8fbae6dac2be9"
@ -8086,6 +8081,11 @@ minimist@^1.2.0, minimist@^1.2.5:
resolved "https://registry.npm.taobao.org/minimist/download/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" resolved "https://registry.npm.taobao.org/minimist/download/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI= integrity sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI=
miniprogram-api-typings@^3.1.6:
version "3.1.6"
resolved "https://registry.npm.taobao.org/miniprogram-api-typings/download/miniprogram-api-typings-3.1.6.tgz?cache=0&sync_timestamp=1604494894079&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fminiprogram-api-typings%2Fdownload%2Fminiprogram-api-typings-3.1.6.tgz#d4fcb47d6dddc041205adbab9161010f459b9f33"
integrity sha1-1Py0fW3dwEEgWturkWEBD0WbnzM=
miniprogram-ci@^1.0.27: miniprogram-ci@^1.0.27:
version "1.0.83" version "1.0.83"
resolved "https://registry.npm.taobao.org/miniprogram-ci/download/miniprogram-ci-1.0.83.tgz#90bce4439e8f3d7ec278b32a76e0246e9fca66f8" resolved "https://registry.npm.taobao.org/miniprogram-ci/download/miniprogram-ci-1.0.83.tgz#90bce4439e8f3d7ec278b32a76e0246e9fca66f8"