mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
build(tsconfig): use strict mode (#3712)
This commit is contained in:
parent
31aacedd5b
commit
225484aeae
@ -12,6 +12,8 @@ Page({
|
|||||||
color: '#ad0000',
|
color: '#ad0000',
|
||||||
background: '#ffe1e1'
|
background: '#ffe1e1'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Notify.clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
showCustomDuration() {
|
showCustomDuration() {
|
||||||
|
@ -5,31 +5,35 @@
|
|||||||
},
|
},
|
||||||
"setting": {
|
"setting": {
|
||||||
"urlCheck": false,
|
"urlCheck": false,
|
||||||
"scopeDataCheck": false,
|
|
||||||
"coverView": true,
|
|
||||||
"es6": true,
|
"es6": true,
|
||||||
|
"enhance": false,
|
||||||
"postcss": true,
|
"postcss": true,
|
||||||
"compileHotReLoad": false,
|
|
||||||
"preloadBackgroundData": false,
|
"preloadBackgroundData": false,
|
||||||
"minified": true,
|
"minified": true,
|
||||||
"autoAudits": false,
|
|
||||||
"newFeature": true,
|
"newFeature": true,
|
||||||
"uglifyFileName": false,
|
"coverView": true,
|
||||||
"uploadWithSourceMap": true,
|
|
||||||
"useIsolateContext": true,
|
|
||||||
"nodeModules": true,
|
"nodeModules": true,
|
||||||
"enhance": false,
|
"autoAudits": false,
|
||||||
"useCompilerModule": false,
|
|
||||||
"userConfirmedUseCompilerModuleSwitch": false,
|
|
||||||
"showShadowRootInWxmlPanel": true,
|
"showShadowRootInWxmlPanel": true,
|
||||||
|
"scopeDataCheck": false,
|
||||||
|
"uglifyFileName": false,
|
||||||
"checkInvalidKey": true,
|
"checkInvalidKey": true,
|
||||||
"checkSiteMap": true,
|
"checkSiteMap": true,
|
||||||
|
"uploadWithSourceMap": true,
|
||||||
|
"compileHotReLoad": false,
|
||||||
|
"useMultiFrameRuntime": false,
|
||||||
|
"useApiHook": true,
|
||||||
"babelSetting": {
|
"babelSetting": {
|
||||||
"ignore": [],
|
"ignore": [],
|
||||||
"disablePlugins": [],
|
"disablePlugins": [],
|
||||||
"outputPath": ""
|
"outputPath": ""
|
||||||
},
|
},
|
||||||
"bundle": false
|
"bundle": false,
|
||||||
|
"useIsolateContext": true,
|
||||||
|
"useCompilerModule": true,
|
||||||
|
"userConfirmedUseCompilerModuleSwitch": false,
|
||||||
|
"packNpmManually": false,
|
||||||
|
"packNpmRelationList": []
|
||||||
},
|
},
|
||||||
"compileType": "miniprogram",
|
"compileType": "miniprogram",
|
||||||
"cloudfunctionRoot": "functions/",
|
"cloudfunctionRoot": "functions/",
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { Weapp } from 'definitions/weapp';
|
|
||||||
import { button } from '../mixins/button';
|
import { button } from '../mixins/button';
|
||||||
import { openType } from '../mixins/open-type';
|
import { openType } from '../mixins/open-type';
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onSelect(event: Weapp.Event) {
|
onSelect(event: WechatMiniprogram.TapEvent) {
|
||||||
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) {
|
||||||
|
@ -122,7 +122,7 @@ VantComponent({
|
|||||||
|
|
||||||
getList(type: string, code?: string): AreaItem[] {
|
getList(type: string, code?: string): AreaItem[] {
|
||||||
const { typeToColumnsPlaceholder } = this.data;
|
const { typeToColumnsPlaceholder } = this.data;
|
||||||
let result = [];
|
let result: { code: string; name: string }[] = [];
|
||||||
if (type !== 'province' && !code) {
|
if (type !== 'province' && !code) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -133,13 +133,15 @@ VantComponent({
|
|||||||
name: list[code],
|
name: list[code],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (code) {
|
if (code != null) {
|
||||||
// oversea code
|
// oversea code
|
||||||
if (code[0] === '9' && type === 'city') {
|
if (code[0] === '9' && type === 'city') {
|
||||||
code = '9';
|
code = '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
result = result.filter((item) => item.code.indexOf(code) === 0);
|
result = result.filter(
|
||||||
|
(item) => item.code.indexOf(code as string) === 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeToColumnsPlaceholder[type] && result.length) {
|
if (typeToColumnsPlaceholder[type] && result.length) {
|
||||||
@ -159,7 +161,7 @@ VantComponent({
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
getIndex(type: string, code: string): number {
|
getIndex(type: string, code: string) {
|
||||||
let compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
|
let compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
|
||||||
const list = this.getList(type, code.slice(0, compareNum - 2));
|
const list = this.getList(type, code.slice(0, compareNum - 2));
|
||||||
|
|
||||||
@ -201,8 +203,8 @@ VantComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stack = [];
|
const stack: Promise<void>[] = [];
|
||||||
const indexes = [];
|
const indexes: number[] = [];
|
||||||
const { columnsNum } = this.data;
|
const { columnsNum } = this.data;
|
||||||
|
|
||||||
if (columnsNum >= 1) {
|
if (columnsNum >= 1) {
|
||||||
|
@ -6,6 +6,13 @@ import {
|
|||||||
getNextDay,
|
getNextDay,
|
||||||
} from '../../utils';
|
} from '../../utils';
|
||||||
|
|
||||||
|
interface Day {
|
||||||
|
date: Date;
|
||||||
|
type: string;
|
||||||
|
text: number;
|
||||||
|
bottomInfo: string;
|
||||||
|
}
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
props: {
|
props: {
|
||||||
date: {
|
date: {
|
||||||
@ -48,14 +55,14 @@ VantComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
onClick(event) {
|
onClick(event) {
|
||||||
const { index } = event.currentTarget.dataset;
|
const { index } = event.currentTarget.dataset;
|
||||||
const item = this.data.days[index];
|
const item: Day = this.data.days[index];
|
||||||
if (item.type !== 'disabled') {
|
if (item.type !== 'disabled') {
|
||||||
this.$emit('click', item);
|
this.$emit('click', item);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setDays() {
|
setDays() {
|
||||||
const days = [];
|
const days: Day[] = [];
|
||||||
const startDate = new Date(this.data.date);
|
const startDate = new Date(this.data.date);
|
||||||
const year = startDate.getFullYear();
|
const year = startDate.getFullYear();
|
||||||
const month = startDate.getMonth();
|
const month = startDate.getMonth();
|
||||||
@ -69,7 +76,7 @@ VantComponent({
|
|||||||
const date = new Date(year, month, day);
|
const date = new Date(year, month, day);
|
||||||
const type = this.getDayType(date);
|
const type = this.getDayType(date);
|
||||||
|
|
||||||
let config = {
|
let config: Day = {
|
||||||
date,
|
date,
|
||||||
type,
|
type,
|
||||||
text: day,
|
text: day,
|
||||||
|
@ -182,6 +182,7 @@ VantComponent({
|
|||||||
minDate,
|
minDate,
|
||||||
maxDate,
|
maxDate,
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
// @ts-ignore
|
||||||
const targetDate = type === 'single' ? currentDate : currentDate[0];
|
const targetDate = type === 'single' ? currentDate : currentDate[0];
|
||||||
const displayed = show || !poppable;
|
const displayed = show || !poppable;
|
||||||
if (!targetDate || !displayed) {
|
if (!targetDate || !displayed) {
|
||||||
@ -222,6 +223,7 @@ VantComponent({
|
|||||||
const { type, currentDate, allowSameDay } = this.data;
|
const { type, currentDate, allowSameDay } = this.data;
|
||||||
|
|
||||||
if (type === 'range') {
|
if (type === 'range') {
|
||||||
|
// @ts-ignore
|
||||||
const [startDay, endDay] = currentDate;
|
const [startDay, endDay] = currentDate;
|
||||||
|
|
||||||
if (startDay && !endDay) {
|
if (startDay && !endDay) {
|
||||||
@ -240,6 +242,7 @@ VantComponent({
|
|||||||
} else if (type === 'multiple') {
|
} else if (type === 'multiple') {
|
||||||
let selectedIndex: number;
|
let selectedIndex: number;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
const selected = currentDate.some((dateItem: number, index: number) => {
|
const selected = currentDate.some((dateItem: number, index: number) => {
|
||||||
const equal = compareDay(dateItem, date) === 0;
|
const equal = compareDay(dateItem, date) === 0;
|
||||||
if (equal) {
|
if (equal) {
|
||||||
@ -249,10 +252,12 @@ VantComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
|
// @ts-ignore
|
||||||
const cancelDate = currentDate.splice(selectedIndex, 1);
|
const cancelDate = currentDate.splice(selectedIndex, 1);
|
||||||
this.setData({ currentDate });
|
this.setData({ currentDate });
|
||||||
this.unselect(cancelDate);
|
this.unselect(cancelDate);
|
||||||
} else {
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
this.select([...currentDate, date]);
|
this.select([...currentDate, date]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -324,6 +329,7 @@ VantComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wx.nextTick(() => {
|
wx.nextTick(() => {
|
||||||
|
// @ts-ignore
|
||||||
this.$emit('confirm', copyDates(this.data.currentDate));
|
this.$emit('confirm', copyDates(this.data.currentDate));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -89,7 +89,7 @@ export function getMonthEndDay(year: number, month: number): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getMonths(minDate: number, maxDate: number) {
|
export function getMonths(minDate: number, maxDate: number) {
|
||||||
const months = [];
|
const months: number[] = [];
|
||||||
const cursor = new Date(minDate);
|
const cursor = new Date(minDate);
|
||||||
|
|
||||||
cursor.setDate(1);
|
cursor.setDate(1);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { link } from '../mixins/link';
|
import { link } from '../mixins/link';
|
||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { Weapp } from 'definitions/weapp';
|
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
classes: [
|
classes: [
|
||||||
@ -35,7 +34,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onClick(event: Weapp.Event) {
|
onClick(event: WechatMiniprogram.TapEvent) {
|
||||||
this.$emit('click', event.detail);
|
this.$emit('click', event.detail);
|
||||||
this.jumpLink();
|
this.jumpLink();
|
||||||
},
|
},
|
||||||
|
@ -7,18 +7,23 @@ import {
|
|||||||
const relationFunctions = {
|
const relationFunctions = {
|
||||||
ancestor: {
|
ancestor: {
|
||||||
linked(parent) {
|
linked(parent) {
|
||||||
|
// @ts-ignore
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
},
|
},
|
||||||
unlinked() {
|
unlinked() {
|
||||||
|
// @ts-ignore
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
descendant: {
|
descendant: {
|
||||||
linked(child) {
|
linked(child) {
|
||||||
|
// @ts-ignore
|
||||||
this.children = this.children || [];
|
this.children = this.children || [];
|
||||||
|
// @ts-ignore
|
||||||
this.children.push(child);
|
this.children.push(child);
|
||||||
},
|
},
|
||||||
unlinked(child) {
|
unlinked(child) {
|
||||||
|
// @ts-ignore
|
||||||
this.children = (this.children || []).filter((it) => it !== child);
|
this.children = (this.children || []).filter((it) => it !== child);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -70,25 +70,29 @@ export function pickExclude(obj: unknown, keys: string[]) {
|
|||||||
export function getRect(
|
export function getRect(
|
||||||
this: WechatMiniprogram.Component.TrivialInstance,
|
this: WechatMiniprogram.Component.TrivialInstance,
|
||||||
selector: string
|
selector: string
|
||||||
): Promise<WechatMiniprogram.BoundingClientRectCallbackResult> {
|
) {
|
||||||
return new Promise((resolve) => {
|
return new Promise<WechatMiniprogram.BoundingClientRectCallbackResult>(
|
||||||
|
(resolve) => {
|
||||||
wx.createSelectorQuery()
|
wx.createSelectorQuery()
|
||||||
.in(this)
|
.in(this)
|
||||||
.select(selector)
|
.select(selector)
|
||||||
.boundingClientRect()
|
.boundingClientRect()
|
||||||
.exec((rect = []) => resolve(rect[0]));
|
.exec((rect = []) => resolve(rect[0]));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAllRect(
|
export function getAllRect(
|
||||||
this: WechatMiniprogram.Component.TrivialInstance,
|
this: WechatMiniprogram.Component.TrivialInstance,
|
||||||
selector: string
|
selector: string
|
||||||
): Promise<WechatMiniprogram.BoundingClientRectCallbackResult[]> {
|
) {
|
||||||
return new Promise((resolve) => {
|
return new Promise<WechatMiniprogram.BoundingClientRectCallbackResult[]>(
|
||||||
|
(resolve) => {
|
||||||
wx.createSelectorQuery()
|
wx.createSelectorQuery()
|
||||||
.in(this)
|
.in(this)
|
||||||
.selectAll(selector)
|
.selectAll(selector)
|
||||||
.boundingClientRect()
|
.boundingClientRect()
|
||||||
.exec((rect = []) => resolve(rect[0]));
|
.exec((rect = []) => resolve(rect[0]));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ function range(num: number, min: number, max: number) {
|
|||||||
return Math.min(Math.max(num, min), max);
|
return Math.min(Math.max(num, min), max);
|
||||||
}
|
}
|
||||||
|
|
||||||
function padZero(val: string | number): string {
|
function padZero(val: string | number) {
|
||||||
return `00${val}`.slice(-2);
|
return `00${val}`.slice(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,8 +26,7 @@ function times(n: number, iteratee: (index: number) => string): string[] {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTrueValue(formattedValue: string): number {
|
function getTrueValue(formattedValue: string) {
|
||||||
if (!formattedValue) return;
|
|
||||||
while (isNaN(parseInt(formattedValue, 10))) {
|
while (isNaN(parseInt(formattedValue, 10))) {
|
||||||
formattedValue = formattedValue.slice(1);
|
formattedValue = formattedValue.slice(1);
|
||||||
}
|
}
|
||||||
@ -38,7 +37,10 @@ function getMonthEndDay(year: number, month: number): number {
|
|||||||
return 32 - new Date(year, month - 1, 32).getDate();
|
return 32 - new Date(year, month - 1, 32).getDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultFormatter = (_, value) => value;
|
const defaultFormatter = (
|
||||||
|
type: 'year' | 'month' | 'day' | 'hour' | 'minute',
|
||||||
|
value: string
|
||||||
|
) => value;
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
classes: ['active-class', 'toolbar-class', 'column-class'],
|
classes: ['active-class', 'toolbar-class', 'column-class'],
|
||||||
@ -327,7 +329,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateColumnValue(value) {
|
updateColumnValue(value) {
|
||||||
let values = [];
|
let values: string[] = [];
|
||||||
const { type } = this.data;
|
const { type } = this.data;
|
||||||
const formatter = this.data.formatter || defaultFormatter;
|
const formatter = this.data.formatter || defaultFormatter;
|
||||||
const picker = this.getPicker();
|
const picker = this.getPicker();
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
let queue = [];
|
let queue: WechatMiniprogram.Component.TrivialInstance[] = [];
|
||||||
|
|
||||||
type DialogOptions = {
|
interface DialogOptions {
|
||||||
lang?: string;
|
lang?: string;
|
||||||
show?: boolean;
|
show?: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
width?: string | number;
|
width?: string | number | null;
|
||||||
zIndex?: number;
|
zIndex?: number;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
context?:
|
context?:
|
||||||
@ -33,7 +33,7 @@ type DialogOptions = {
|
|||||||
showCancelButton?: boolean;
|
showCancelButton?: boolean;
|
||||||
closeOnClickOverlay?: boolean;
|
closeOnClickOverlay?: boolean;
|
||||||
confirmButtonOpenType?: string;
|
confirmButtonOpenType?: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
const defaultOptions: DialogOptions = {
|
const defaultOptions: DialogOptions = {
|
||||||
show: false,
|
show: false,
|
||||||
@ -65,17 +65,16 @@ function getContext() {
|
|||||||
return pages[pages.length - 1];
|
return pages[pages.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Dialog = (
|
const Dialog = (options: DialogOptions) => {
|
||||||
options: DialogOptions
|
|
||||||
): Promise<WechatMiniprogram.Component.TrivialInstance> => {
|
|
||||||
options = {
|
options = {
|
||||||
...currentOptions,
|
...currentOptions,
|
||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise<WechatMiniprogram.Component.TrivialInstance>(
|
||||||
|
(resolve, reject) => {
|
||||||
const context = options.context || getContext();
|
const context = options.context || getContext();
|
||||||
const dialog = context.selectComponent(options.selector);
|
const dialog = context.selectComponent(options.selector as string);
|
||||||
|
|
||||||
delete options.context;
|
delete options.context;
|
||||||
delete options.selector;
|
delete options.selector;
|
||||||
@ -97,7 +96,8 @@ const Dialog = (
|
|||||||
'未找到 van-dialog 节点,请确认 selector 及 context 是否正确'
|
'未找到 van-dialog 节点,请确认 selector 及 context 是否正确'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Dialog.alert = (options: DialogOptions) => Dialog(options);
|
Dialog.alert = (options: DialogOptions) => Dialog(options);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { Weapp } from 'definitions/weapp';
|
import { Option } from './shared';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
field: true,
|
field: true,
|
||||||
@ -58,6 +58,7 @@ VantComponent({
|
|||||||
closeOnClickOverlay,
|
closeOnClickOverlay,
|
||||||
direction,
|
direction,
|
||||||
} = this.parent.data;
|
} = this.parent.data;
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
overlay,
|
overlay,
|
||||||
duration,
|
duration,
|
||||||
@ -85,9 +86,9 @@ VantComponent({
|
|||||||
this.setData({ showWrapper: false });
|
this.setData({ showWrapper: false });
|
||||||
},
|
},
|
||||||
|
|
||||||
onOptionTap(event: Weapp.Event) {
|
onOptionTap(event: WechatMiniprogram.TapEvent) {
|
||||||
const { option } = event.currentTarget.dataset;
|
const { option } = event.currentTarget.dataset;
|
||||||
const { value } = option;
|
const { value } = (option as unknown) as Option;
|
||||||
|
|
||||||
const shouldEmitChange = this.data.value !== value;
|
const shouldEmitChange = this.data.value !== value;
|
||||||
this.setData({ showPopup: false, value });
|
this.setData({ showPopup: false, value });
|
||||||
@ -100,7 +101,7 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggle(show, options = {}) {
|
toggle(show?: boolean, options: { immediate?: boolean } = {}) {
|
||||||
const { showPopup } = this.data;
|
const { showPopup } = this.data;
|
||||||
|
|
||||||
if (typeof show !== 'boolean') {
|
if (typeof show !== 'boolean') {
|
||||||
|
5
packages/dropdown-item/shared.ts
Normal file
5
packages/dropdown-item/shared.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface Option {
|
||||||
|
text: string;
|
||||||
|
value: string | number;
|
||||||
|
icon: string;
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
export const commonProps = {
|
export const commonProps = {
|
||||||
value: {
|
value: {
|
||||||
type: String,
|
type: String,
|
||||||
observer(value: string) {
|
observer(this: WechatMiniprogram.Component.TrivialInstance, value: string) {
|
||||||
if (value !== this.value) {
|
if (value !== this.value) {
|
||||||
this.setData({ innerValue: value });
|
this.setData({ innerValue: value });
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -50,7 +50,7 @@ VantComponent({
|
|||||||
} = data;
|
} = data;
|
||||||
const width = `${100 / columnNum}%`;
|
const width = `${100 / columnNum}%`;
|
||||||
|
|
||||||
const styleWrapper = [];
|
const styleWrapper: string[] = [];
|
||||||
styleWrapper.push(`width: ${width}`);
|
styleWrapper.push(`width: ${width}`);
|
||||||
|
|
||||||
if (square) {
|
if (square) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { VantComponent } from '../common/component';
|
|
||||||
import { GREEN } from '../common/color';
|
import { GREEN } from '../common/color';
|
||||||
|
import { VantComponent } from '../common/component';
|
||||||
|
import { getRect } from '../common/utils';
|
||||||
import { pageScrollMixin } from '../mixins/page-scroll';
|
import { pageScrollMixin } from '../mixins/page-scroll';
|
||||||
|
|
||||||
const indexList = () => {
|
const indexList = () => {
|
||||||
const indexList = [];
|
const indexList: string[] = [];
|
||||||
const charCodeOfA = 'A'.charCodeAt(0);
|
const charCodeOfA = 'A'.charCodeAt(0);
|
||||||
|
|
||||||
for (let i = 0; i < 26; i++) {
|
for (let i = 0; i < 26; i++) {
|
||||||
@ -51,7 +52,7 @@ VantComponent({
|
|||||||
|
|
||||||
mixins: [
|
mixins: [
|
||||||
pageScrollMixin(function (event) {
|
pageScrollMixin(function (event) {
|
||||||
this.scrollTop = event.scrollTop || 0;
|
this.scrollTop = event?.scrollTop || 0;
|
||||||
this.onScroll();
|
this.onScroll();
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -94,34 +95,29 @@ VantComponent({
|
|||||||
|
|
||||||
setAnchorsRect() {
|
setAnchorsRect() {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
this.children.map((anchor) =>
|
this.children.map(
|
||||||
anchor
|
(anchor: WechatMiniprogram.Component.TrivialInstance) =>
|
||||||
.getRect('.van-index-anchor-wrapper')
|
getRect.call(anchor, '.van-index-anchor-wrapper').then((rect) => {
|
||||||
.then(
|
|
||||||
(rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
|
|
||||||
Object.assign(anchor, {
|
Object.assign(anchor, {
|
||||||
height: rect.height,
|
height: rect.height,
|
||||||
top: rect.top + this.scrollTop,
|
top: rect.top + this.scrollTop,
|
||||||
});
|
});
|
||||||
}
|
})
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
setListRect() {
|
setListRect() {
|
||||||
return this.getRect('.van-index-bar').then(
|
return getRect.call(this, '.van-index-bar').then((rect) => {
|
||||||
(rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
|
|
||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
height: rect.height,
|
height: rect.height,
|
||||||
top: rect.top + this.scrollTop,
|
top: rect.top + this.scrollTop,
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setSiderbarRect() {
|
setSiderbarRect() {
|
||||||
return this.getRect('.van-index-bar__sidebar').then((res) => {
|
return getRect.call(this, '.van-index-bar__sidebar').then((res) => {
|
||||||
this.sidebar = {
|
this.sidebar = {
|
||||||
height: res.height,
|
height: res.height,
|
||||||
top: res.top,
|
top: res.top,
|
||||||
@ -144,9 +140,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getAnchorRect(anchor) {
|
getAnchorRect(anchor) {
|
||||||
return anchor
|
return getRect.call(anchor, '.van-index-anchor-wrapper').then((rect) => ({
|
||||||
.getRect('.van-index-anchor-wrapper')
|
|
||||||
.then((rect: WechatMiniprogram.BoundingClientRectCallbackResult) => ({
|
|
||||||
height: rect.height,
|
height: rect.height,
|
||||||
top: rect.top,
|
top: rect.top,
|
||||||
}));
|
}));
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
export const basic = Behavior({
|
export const basic = Behavior({
|
||||||
methods: {
|
methods: {
|
||||||
$emit(...args) {
|
$emit(
|
||||||
this.triggerEvent(...args);
|
name: string,
|
||||||
|
detail?: Record<string, unknown>,
|
||||||
|
options?: Record<string, unknown>
|
||||||
|
) {
|
||||||
|
this.triggerEvent(name, detail, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
set(data: object, callback: Function) {
|
set(data: object, callback: () => void) {
|
||||||
this.setData(data, callback);
|
this.setData(data, callback);
|
||||||
|
|
||||||
return new Promise((resolve) => wx.nextTick(resolve));
|
return new Promise((resolve) => wx.nextTick(resolve));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Weapp } from 'definitions/weapp';
|
// @ts-nocheck
|
||||||
|
|
||||||
export const openType = Behavior({
|
export const openType = Behavior({
|
||||||
properties: {
|
properties: {
|
||||||
@ -6,27 +6,27 @@ export const openType = Behavior({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
bindGetUserInfo(event: Partial<Weapp.Event>) {
|
bindGetUserInfo(event: WechatMiniprogram.TapEvent) {
|
||||||
this.$emit('getuserinfo', event.detail);
|
this.$emit('getuserinfo', event.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
bindContact(event: Partial<Weapp.Event>) {
|
bindContact(event: WechatMiniprogram.TapEvent) {
|
||||||
this.$emit('contact', event.detail);
|
this.$emit('contact', event.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
bindGetPhoneNumber(event: Partial<Weapp.Event>) {
|
bindGetPhoneNumber(event: WechatMiniprogram.TapEvent) {
|
||||||
this.$emit('getphonenumber', event.detail);
|
this.$emit('getphonenumber', event.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
bindError(event: Partial<Weapp.Event>) {
|
bindError(event: WechatMiniprogram.TapEvent) {
|
||||||
this.$emit('error', event.detail);
|
this.$emit('error', event.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
bindLaunchApp(event: Partial<Weapp.Event>) {
|
bindLaunchApp(event: WechatMiniprogram.TapEvent) {
|
||||||
this.$emit('launchapp', event.detail);
|
this.$emit('launchapp', event.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
bindOpenSetting(event: Partial<Weapp.Event>) {
|
bindOpenSetting(event: WechatMiniprogram.TapEvent) {
|
||||||
this.$emit('opensetting', event.detail);
|
this.$emit('opensetting', event.detail);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
type IPageScrollOption = WechatMiniprogram.Page.IPageScrollOption;
|
type IPageScrollOption = WechatMiniprogram.Page.IPageScrollOption;
|
||||||
type Scroller = (event: IPageScrollOption) => void;
|
type Scroller = (
|
||||||
|
this: WechatMiniprogram.Component.TrivialInstance,
|
||||||
|
event?: IPageScrollOption
|
||||||
|
) => void;
|
||||||
type TrivialInstance = WechatMiniprogram.Page.TrivialInstance & {
|
type TrivialInstance = WechatMiniprogram.Page.TrivialInstance & {
|
||||||
vanPageScroller?: Scroller[];
|
vanPageScroller?: Scroller[];
|
||||||
};
|
};
|
||||||
@ -9,11 +12,12 @@ function getCurrentPage(): TrivialInstance {
|
|||||||
return pages[pages.length - 1] || ({} as TrivialInstance);
|
return pages[pages.length - 1] || ({} as TrivialInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPageScroll(event: IPageScrollOption) {
|
function onPageScroll(event?: IPageScrollOption) {
|
||||||
const { vanPageScroller = [] } = getCurrentPage();
|
const { vanPageScroller = [] } = getCurrentPage();
|
||||||
|
|
||||||
vanPageScroller.forEach((scroller: Scroller) => {
|
vanPageScroller.forEach((scroller: Scroller) => {
|
||||||
if (typeof scroller === 'function') {
|
if (typeof scroller === 'function') {
|
||||||
|
// @ts-ignore
|
||||||
scroller(event);
|
scroller(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// @ts-nocheck
|
||||||
import { Weapp } from 'definitions/weapp';
|
import { Weapp } from 'definitions/weapp';
|
||||||
|
|
||||||
const MIN_DISTANCE = 10;
|
const MIN_DISTANCE = 10;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// @ts-nocheck
|
||||||
import { isObj, requestAnimationFrame } from '../common/utils';
|
import { isObj, requestAnimationFrame } from '../common/utils';
|
||||||
|
|
||||||
const getClassNames = (name: string) => ({
|
const getClassNames = (name: string) => ({
|
||||||
@ -7,7 +8,7 @@ const getClassNames = (name: string) => ({
|
|||||||
'leave-to': `van-${name}-leave-to van-${name}-leave-active leave-to-class leave-active-class`,
|
'leave-to': `van-${name}-leave-to van-${name}-leave-active leave-to-class leave-active-class`,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const transition = function (showDefaultValue: boolean) {
|
export function transition(showDefaultValue: boolean) {
|
||||||
return Behavior({
|
return Behavior({
|
||||||
properties: {
|
properties: {
|
||||||
customStyle: String,
|
customStyle: String,
|
||||||
@ -123,4 +124,4 @@ export const transition = function (showDefaultValue: boolean) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { Weapp } from 'definitions/weapp';
|
import { Weapp } from 'definitions/weapp';
|
||||||
import { requestAnimationFrame } from '../common/utils';
|
import { getRect, requestAnimationFrame } from '../common/utils';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
props: {
|
props: {
|
||||||
@ -70,9 +70,9 @@ VantComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
this.getRect('.van-notice-bar__content'),
|
getRect.call(this, '.van-notice-bar__content'),
|
||||||
this.getRect('.van-notice-bar__wrap'),
|
getRect.call(this, '.van-notice-bar__wrap'),
|
||||||
]).then((rects: WechatMiniprogram.BoundingClientRectCallbackResult[]) => {
|
]).then((rects) => {
|
||||||
const [contentRect, wrapRect] = rects;
|
const [contentRect, wrapRect] = rects;
|
||||||
if (
|
if (
|
||||||
contentRect == null ||
|
contentRect == null ||
|
||||||
|
@ -16,7 +16,7 @@ interface NotifyOptions {
|
|||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions: NotifyOptions = {
|
||||||
selector: '#van-notify',
|
selector: '#van-notify',
|
||||||
type: 'danger',
|
type: 'danger',
|
||||||
message: '',
|
message: '',
|
||||||
@ -31,7 +31,13 @@ const defaultOptions = {
|
|||||||
onClose: () => {},
|
onClose: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
function parseOptions(message: NotifyOptions | string): NotifyOptions {
|
function parseOptions(
|
||||||
|
message?: NotifyOptions | string
|
||||||
|
): Partial<NotifyOptions> {
|
||||||
|
if (message == null) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
return typeof message === 'string' ? { message } : message;
|
return typeof message === 'string' ? { message } : message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +47,7 @@ function getContext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Notify(options: NotifyOptions | string) {
|
export default function Notify(options: NotifyOptions | string) {
|
||||||
options = { ...defaultOptions, ...parseOptions(options) } as NotifyOptions;
|
options = { ...defaultOptions, ...parseOptions(options) };
|
||||||
|
|
||||||
const context = options.context || getContext();
|
const context = options.context || getContext();
|
||||||
const notify = context.selectComponent(options.selector);
|
const notify = context.selectComponent(options.selector);
|
||||||
@ -59,7 +65,7 @@ export default function Notify(options: NotifyOptions | string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Notify.clear = function (options?: NotifyOptions) {
|
Notify.clear = function (options?: NotifyOptions) {
|
||||||
options = { ...defaultOptions, ...parseOptions(options) } as NotifyOptions;
|
options = { ...defaultOptions, ...parseOptions(options) };
|
||||||
|
|
||||||
const context = options.context || getContext();
|
const context = options.context || getContext();
|
||||||
const notify = context.selectComponent(options.selector);
|
const notify = context.selectComponent(options.selector);
|
||||||
|
@ -32,7 +32,7 @@ const defaultOptions = {
|
|||||||
selector: '#van-toast',
|
selector: '#van-toast',
|
||||||
};
|
};
|
||||||
|
|
||||||
let queue = [];
|
let queue: WechatMiniprogram.Component.TrivialInstance[] = [];
|
||||||
let currentOptions: ToastOptions = { ...defaultOptions };
|
let currentOptions: ToastOptions = { ...defaultOptions };
|
||||||
|
|
||||||
function parseOptions(message): ToastOptions {
|
function parseOptions(message): ToastOptions {
|
||||||
@ -44,16 +44,14 @@ function getContext() {
|
|||||||
return pages[pages.length - 1];
|
return pages[pages.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function Toast(
|
function Toast(toastOptions: ToastOptions | ToastMessage) {
|
||||||
toastOptions: ToastOptions | ToastMessage
|
|
||||||
): WechatMiniprogram.Component.TrivialInstance {
|
|
||||||
const options = {
|
const options = {
|
||||||
...currentOptions,
|
...currentOptions,
|
||||||
...parseOptions(toastOptions),
|
...parseOptions(toastOptions),
|
||||||
} as ToastOptions;
|
} as ToastOptions;
|
||||||
|
|
||||||
const context = options.context || getContext();
|
const context = options.context || getContext();
|
||||||
const toast = context.selectComponent(options.selector);
|
const toast = context.selectComponent(options.selector as string);
|
||||||
|
|
||||||
if (!toast) {
|
if (!toast) {
|
||||||
console.warn('未找到 van-toast 节点,请确认 selector 及 context 是否正确');
|
console.warn('未找到 van-toast 节点,请确认 selector 及 context 是否正确');
|
||||||
@ -75,7 +73,7 @@ function Toast(
|
|||||||
toast.setData(options);
|
toast.setData(options);
|
||||||
clearTimeout(toast.timer);
|
clearTimeout(toast.timer);
|
||||||
|
|
||||||
if (options.duration > 0) {
|
if (options.duration != null && options.duration > 0) {
|
||||||
toast.timer = setTimeout(() => {
|
toast.timer = setTimeout(() => {
|
||||||
toast.clear();
|
toast.clear();
|
||||||
queue = queue.filter((item) => item !== toast);
|
queue = queue.filter((item) => item !== toast);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { isImageFile, chooseFile, isVideoFile } from './utils';
|
import { isImageFile, chooseFile, isVideoFile, File } from './utils';
|
||||||
import { chooseImageProps, chooseVideoProps } from './shared';
|
import { chooseImageProps, chooseVideoProps } from './shared';
|
||||||
import { isBoolean, isPromise } from '../common/validator';
|
import { isBoolean, isPromise } from '../common/validator';
|
||||||
|
|
||||||
@ -79,8 +79,6 @@ VantComponent({
|
|||||||
deletable: isBoolean(item.deletable) ? item.deletable : true,
|
deletable: isBoolean(item.deletable) ? item.deletable : true,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log(lists);
|
|
||||||
|
|
||||||
this.setData({ lists, isInCount: lists.length < maxCount });
|
this.setData({ lists, isInCount: lists.length < maxCount });
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -92,7 +90,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
startUpload() {
|
startUpload() {
|
||||||
const { maxCount, multiple, accept, lists, disabled } = this.data;
|
const { maxCount, multiple, lists, disabled } = this.data;
|
||||||
|
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
|
|
||||||
@ -101,8 +99,6 @@ VantComponent({
|
|||||||
maxCount: maxCount - lists.length,
|
maxCount: maxCount - lists.length,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
|
||||||
|
|
||||||
this.onBeforeRead(multiple ? res : res[0]);
|
this.onBeforeRead(multiple ? res : res[0]);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -110,7 +106,7 @@ VantComponent({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onBeforeRead(file) {
|
onBeforeRead(file: File) {
|
||||||
const { beforeRead, useBeforeRead } = this.data;
|
const { beforeRead, useBeforeRead } = this.data;
|
||||||
let res: boolean | Promise<void> = true;
|
let res: boolean | Promise<void> = true;
|
||||||
|
|
||||||
@ -172,7 +168,7 @@ VantComponent({
|
|||||||
if (!this.data.previewFullImage) return;
|
if (!this.data.previewFullImage) return;
|
||||||
|
|
||||||
const { index } = event.currentTarget.dataset;
|
const { index } = event.currentTarget.dataset;
|
||||||
const { lists } = this.data;
|
const { lists } = this.data as { lists: File[] };
|
||||||
const item = lists[index];
|
const item = lists[index];
|
||||||
|
|
||||||
wx.previewImage({
|
wx.previewImage({
|
||||||
@ -187,7 +183,7 @@ VantComponent({
|
|||||||
onPreviewVideo(event) {
|
onPreviewVideo(event) {
|
||||||
if (!this.data.previewFullImage) return;
|
if (!this.data.previewFullImage) return;
|
||||||
const { index } = event.currentTarget.dataset;
|
const { index } = event.currentTarget.dataset;
|
||||||
const { lists } = this.data;
|
const { lists } = this.data as { lists: File[] };
|
||||||
|
|
||||||
wx.previewMedia({
|
wx.previewMedia({
|
||||||
sources: lists
|
sources: lists
|
||||||
@ -205,7 +201,7 @@ VantComponent({
|
|||||||
|
|
||||||
onClickPreview(event) {
|
onClickPreview(event) {
|
||||||
const { index } = event.currentTarget.dataset;
|
const { index } = event.currentTarget.dataset;
|
||||||
const item = this.data.lists[index];
|
const item: File = this.data.lists[index];
|
||||||
|
|
||||||
this.$emit('click-preview', {
|
this.$emit('click-preview', {
|
||||||
...item,
|
...item,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { pickExclude } from '../common/utils';
|
import { pickExclude } from '../common/utils';
|
||||||
import { isImageUrl, isVideoUrl } from '../common/validator';
|
import { isImageUrl, isVideoUrl } from '../common/validator';
|
||||||
|
|
||||||
interface File {
|
export interface File {
|
||||||
url: string; // 上传临时地址
|
url: string; // 上传临时地址
|
||||||
size?: number; // 上传大小
|
size?: number; // 上传大小
|
||||||
name?: string;
|
name?: string;
|
||||||
@ -83,7 +83,7 @@ function formatFile(
|
|||||||
return res.tempFiles.map((item) => ({
|
return res.tempFiles.map((item) => ({
|
||||||
...pickExclude(item, ['path']),
|
...pickExclude(item, ['path']),
|
||||||
url: item.path,
|
url: item.path,
|
||||||
}));
|
})) as File[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function chooseFile({
|
export function chooseFile({
|
||||||
@ -96,7 +96,7 @@ export function chooseFile({
|
|||||||
camera,
|
camera,
|
||||||
maxCount,
|
maxCount,
|
||||||
}) {
|
}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise<File | File[]>((resolve, reject) => {
|
||||||
switch (accept) {
|
switch (accept) {
|
||||||
case 'image':
|
case 'image':
|
||||||
wx.chooseImage({
|
wx.chooseImage({
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"strict": false,
|
"strict": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"definitions/*": ["./packages/definitions/*"],
|
"definitions/*": ["./packages/definitions/*"],
|
||||||
"packages/*": ["./packages/*"]
|
"packages/*": ["./packages/*"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user