;
+
+export function requiredBy(
+ requiredByPropName: string,
+ propType: PropTypes.Validator
,
+ defaultValue?: any,
+): PropTypes.Requireable
;
+
+export function restrictedProp(
+ messageFunction?: (
+ props: object,
+ propName: string,
+ componentName: string,
+ location: string,
+ propFullName: string,
+ ) => string | Error | undefined,
+): PropTypes.Requireable;
+
+export function sequenceOf(...specifiers: Specifier[]): PropTypes.Requireable;
+
+export function shape(
+ propTypes: PropTypes.ValidationMap,
+): PropTypes.Requireable;
+
+export function stringStartsWith(string: string): PropTypes.Requireable;
+
+export function uniqueArray(): PropTypes.Requireable;
+
+export function uniqueArrayOf(
+ propType: PropTypes.Validator,
+ mapperOrName: ((value: any) => any) | string,
+ name?: string,
+): PropTypes.Requireable;
+
+export function valuesOf(
+ propType: PropTypes.Validator,
+): PropTypes.Requireable<{ [key: string]: T }>;
+
+export function withShape(
+ propType: PropTypes.Validator,
+ propTypes: PropTypes.ValidationMap,
+): PropTypes.Requireable;
diff --git a/types/airbnb-prop-types/tsconfig.json b/types/airbnb-prop-types/tsconfig.json
new file mode 100644
index 0000000000..ccefe4943c
--- /dev/null
+++ b/types/airbnb-prop-types/tsconfig.json
@@ -0,0 +1,16 @@
+{
+ "compilerOptions": {
+ "module": "commonjs",
+ "lib": ["es6"],
+ "noImplicitAny": true,
+ "noImplicitThis": true,
+ "strictNullChecks": true,
+ "strictFunctionTypes": true,
+ "baseUrl": "../",
+ "typeRoots": ["../"],
+ "types": [],
+ "noEmit": true,
+ "forceConsistentCasingInFileNames": true
+ },
+ "files": ["index.d.ts", "airbnb-prop-types-tests.ts"]
+}
diff --git a/types/airbnb-prop-types/tslint.json b/types/airbnb-prop-types/tslint.json
new file mode 100644
index 0000000000..71ee04c4e1
--- /dev/null
+++ b/types/airbnb-prop-types/tslint.json
@@ -0,0 +1,6 @@
+{
+ "extends": "dtslint/dt.json",
+ "rules": {
+ "no-unnecessary-generics": false
+ }
+}
diff --git a/types/ajv-errors/index.d.ts b/types/ajv-errors/index.d.ts
index fed9e4585f..3b5c2d2322 100644
--- a/types/ajv-errors/index.d.ts
+++ b/types/ajv-errors/index.d.ts
@@ -2,6 +2,7 @@
// Project: https://github.com/epoberezkin/ajv-errors
// Definitions by: Afshawn Lotfi
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+// TypeScript Version: 2.2
import { Ajv } from "ajv";
diff --git a/types/ale-url-parser/ale-url-parser-tests.ts b/types/ale-url-parser/ale-url-parser-tests.ts
new file mode 100644
index 0000000000..2a5d9fe632
--- /dev/null
+++ b/types/ale-url-parser/ale-url-parser-tests.ts
@@ -0,0 +1,22 @@
+import { parse, stringify } from 'ale-url-parser';
+
+let url;
+let urlObject;
+
+url = stringify({});
+console.log(url);
+
+url = stringify({
+ protocol: 'protocol',
+ host: 'host',
+ path: ['foo', 'bar', 'baz'],
+ hash: 'hash',
+ query: {
+ foo: 1,
+ bar: [2, '3']
+ }
+});
+console.log(url);
+
+urlObject = parse('//any.dom.ain.co.m/foo/bar?test=1&test=2#hash');
+console.log(urlObject);
diff --git a/types/ale-url-parser/index.d.ts b/types/ale-url-parser/index.d.ts
new file mode 100644
index 0000000000..31b2d2fd03
--- /dev/null
+++ b/types/ale-url-parser/index.d.ts
@@ -0,0 +1,29 @@
+// Type definitions for ale-url-parser 0.10
+// Project: https://github.com/msn0/ale-url-parser#readme
+// Definitions by: Michał Jezierski
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+// TypeScript Version: 2.1
+
+export interface QueryParams {
+ [key: string]: any;
+}
+
+export interface UrlObject {
+ protocol?: string;
+ host?: string;
+ path?: string[];
+ query?: QueryParams;
+ hash?: string;
+}
+
+/**
+ * Parse url string into url object.
+ * @return UrlObject
+ */
+export function parse(url: string): UrlObject;
+
+/**
+ * Stringify url object into url string.
+ * @return string
+ */
+export function stringify(urlObject: UrlObject): string;
diff --git a/types/ale-url-parser/tsconfig.json b/types/ale-url-parser/tsconfig.json
new file mode 100644
index 0000000000..2d18200901
--- /dev/null
+++ b/types/ale-url-parser/tsconfig.json
@@ -0,0 +1,24 @@
+{
+ "compilerOptions": {
+ "module": "commonjs",
+ "lib": [
+ "es6",
+ "dom"
+ ],
+ "noImplicitAny": true,
+ "noImplicitThis": true,
+ "strictNullChecks": true,
+ "strictFunctionTypes": true,
+ "baseUrl": "../",
+ "typeRoots": [
+ "../"
+ ],
+ "types": [],
+ "noEmit": true,
+ "forceConsistentCasingInFileNames": true
+ },
+ "files": [
+ "index.d.ts",
+ "ale-url-parser-tests.ts"
+ ]
+}
diff --git a/types/react-i18next/v4/tslint.json b/types/ale-url-parser/tslint.json
similarity index 100%
rename from types/react-i18next/v4/tslint.json
rename to types/ale-url-parser/tslint.json
diff --git a/types/algoliasearch/algoliasearch-tests.ts b/types/algoliasearch/algoliasearch-tests.ts
index b148e84599..cbd98d253a 100644
--- a/types/algoliasearch/algoliasearch-tests.ts
+++ b/types/algoliasearch/algoliasearch-tests.ts
@@ -21,6 +21,7 @@ let _algoliaResponse: Response = {
processingTimeMS: 32,
query: '',
params: '',
+ index: '',
};
let _clientOptions: ClientOptions = {
@@ -103,7 +104,7 @@ let _algoliaQueryParameters: QueryParameters = {
filters: '',
attributesToRetrieve: [''],
restrictSearchableAttributes: [''],
- facets: '',
+ facets: [''],
facetingAfterDistinct: true,
maxValuesPerFacet: 2,
attributesToHighlight: [''],
@@ -121,28 +122,29 @@ let _algoliaQueryParameters: QueryParameters = {
typoTolerance: false,
allowTyposOnNumericTokens: false,
ignorePlurals: false,
- disableTypoToleranceOnAttributes: '',
+ disableTypoToleranceOnAttributes: [''],
aroundLatLng: '',
aroundLatLngViaIP: '',
aroundRadius: 0,
aroundPrecision: 0,
minimumAroundRadius: 0,
insideBoundingBox: [[0]],
- queryType: '',
+ queryType: 'prefixAll',
insidePolygon: [[0]],
- removeWordsIfNoResults: '',
+ removeWordsIfNoResults: 'firstWords',
advancedSyntax: false,
optionalWords: [''],
removeStopWords: [''],
disableExactOnAttributes: [''],
- exactOnSingleWordQuery: '',
- alternativesAsExact: true,
+ exactOnSingleWordQuery: 'attribute',
+ alternativesAsExact: ["ignorePlurals"],
distinct: 0,
getRankingInfo: false,
numericAttributesToIndex: [''],
+ numericAttributesForFiltering: [''],
numericFilters: [''],
- tagFilters: '',
- facetFilters: '',
+ tagFilters: [''],
+ facetFilters: [''],
analytics: false,
analyticsTags: [''],
synonyms: true,
@@ -172,8 +174,38 @@ index.partialUpdateObjects([{}], false).then(() => {});
let indexName : string = index.indexName;
// complete copy
-client.copyIndex('from', 'to').then(()=>{})
-client.copyIndex('from', 'to', ()=> {})
+client.copyIndex('from', 'to').then(()=>{});
+client.copyIndex('from', 'to', ()=> {});
// with scope
-client.copyIndex('from', 'to', ['settings']).then(()=>{})
-client.copyIndex('from', 'to', ['synonyms', 'rules'], ()=> {})
+client.copyIndex('from', 'to', ['settings']).then(()=>{});
+client.copyIndex('from', 'to', ['synonyms', 'rules'], ()=> {});
+
+// Browsing
+const browser = index.browseAll();
+index.browseAll('query');
+index.browseAll('', {
+ filters: 'dog',
+});
+
+let hits: Object[] = [];
+
+browser.on('result', function onResult(content) {
+ hits = hits.concat(content.hits);
+});
+
+browser.on('end', function onEnd() {
+ const _message = `We got ${hits.length} hits`
+});
+
+browser.on('error', function onError(err) {
+ throw err;
+});
+
+browser.stop();
+
+index.browse("", {
+ advancedSyntax: false,
+ attributesToRetrieve: ['dogs']
+});
+client.copyIndex('from', 'to', ['settings']).then(()=>{});
+client.copyIndex('from', 'to', ['synonyms', 'rules'], ()=> {});
diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts
index a0bb0e0e45..04291996ba 100644
--- a/types/algoliasearch/index.d.ts
+++ b/types/algoliasearch/index.d.ts
@@ -1,11 +1,14 @@
-// Type definitions for algoliasearch-client-js 3.27.0
+// Type definitions for algoliasearch-client-js 3.30.0
// Project: https://github.com/algolia/algoliasearch-client-js
// Definitions by: Baptiste Coquelle
// Haroen Viaene
// Aurélien Hervé
// Samuel Vaillant
+// Kai Eichinger
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-// TypeScript Version: 2.2
+// TypeScript Version: 2.8
+
+type Omit = Pick>
declare namespace algoliasearch {
/**
@@ -611,6 +614,11 @@ declare namespace algoliasearch {
options: SearchForFacetValues.Parameters,
cb: (err: Error, res: SearchForFacetValues.Response) => void
): void;
+ /**
+ * Browse an index
+ * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
+ */
+ browse(query: string, parameters: BrowseParameters, cb: (err: Error, res: BrowseResponse) => void): void;
/**
* Browse an index
* https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
@@ -620,7 +628,7 @@ declare namespace algoliasearch {
* Browse an index
* https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
*/
- browse(query: string): Promise;
+ browse(query: string, parameters?: BrowseParameters): Promise;
/**
* Browse an index from a cursor
* https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
@@ -638,7 +646,7 @@ declare namespace algoliasearch {
* Browse an entire index
* https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
*/
- browseAll(): Promise;
+ browseAll(query?: string, parameters?: BrowseParameters): Browser;
/**
* Clear an index content
* https://github.com/algolia/algoliasearch-client-js#clear-index---clearindex
@@ -966,6 +974,22 @@ declare namespace algoliasearch {
query: string;
processingTimeMS: number;
}
+ type BrowseParameters = Omit<
+ QueryParameters,
+ | "typoTolerance"
+ | "distinct"
+ | "facets"
+ | "getRankingInfo"
+ | "attributesToHighlight"
+ | "attributesToSnippet"
+ >
+ interface Browser {
+ on(type: "error", cb: (err: Error) => void): void
+ on(type: "end", cb: () => void): void
+ on(type: "stop", cb: () => void): void
+ on(type: "result", cb: (content: BrowseResponse) => void): void
+ stop(): void
+ }
/**
* Describes a synonym object
*/
@@ -1099,120 +1123,121 @@ declare namespace algoliasearch {
userToken?: string;
}
interface QueryParameters {
+ /**
+ * Query string used to perform the search
+ * default: ''
+ * https://www.algolia.com/doc/api-reference/api-parameters/query/
+ */
+ query?: string;
+ /**
+ * Filter the query with numeric, facet or/and tag filters
+ * default: ""
+ * https://www.algolia.com/doc/api-reference/api-parameters/filters/
+ */
+ filters?: string;
+ /**
+ * A string that contains the list of attributes you want to retrieve in order to minimize the size of the JSON answer.
+ * default: *
+ * https://www.algolia.com/doc/api-reference/api-parameters/attributesToRetrieve/
+ */
+ attributesToRetrieve?: string[];
+ /**
+ * List of attributes you want to use for textual search
+ * default: attributeToIndex
+ * https://www.algolia.com/doc/api-reference/api-parameters/restrictSearchableAttributes/
+ */
+ restrictSearchableAttributes?: string[];
+ /**
+ * You can use facets to retrieve only a part of your attributes declared in attributesForFaceting attributes
+ * default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/facets/
+ */
+ facets?: string[];
/**
- * Query string used to perform the search
- * default: ''
- * https://github.com/algolia/algoliasearch-client-js#query
- */
- query?: string;
- /**
- * Filter the query with numeric, facet or/and tag filters
- * default: ""
- * https://github.com/algolia/algoliasearch-client-js#filters
- */
- filters?: string;
- /**
- * A string that contains the list of attributes you want to retrieve in order to minimize the size of the JSON answer.
- * default: *
- * https://github.com/algolia/algoliasearch-client-js#attributestoretrieve
- */
- attributesToRetrieve?: string[];
- /**
- * List of attributes you want to use for textual search
- * default: attributeToIndex
- * https://github.com/algolia/algoliasearch-client-js#restrictsearchableattributes
- */
- restrictSearchableAttributes?: string[];
- /**
- * You can use facets to retrieve only a part of your attributes declared in attributesForFaceting attributes
- * default: ""
- * https://github.com/algolia/algoliasearch-client-js#facets
- */
- facets?: string | string[];
- /**
* Force faceting to be applied after de-duplication (via the Distinct setting).
- * When using the distinct setting in combination with faceting, facet counts may be higher than expected.
- * This is because the engine, by default, computes faceting before applying de-duplication (distinct).
+ * When using the distinct setting in combination with faceting, facet counts may be higher than expected.
+ * This is because the engine, by default, computes faceting before applying de-duplication (distinct).
* When facetingAfterDistinct is set to true, the engine calculates faceting after the de-duplication has been applied.
* default ""
+ * https://www.algolia.com/doc/api-reference/api-parameters/facetingAfterDistinct/
*/
facetingAfterDistinct?: boolean;
/**
* Limit the number of facet values returned for each facet.
- * default: ""
- * https://github.com/algolia/algoliasearch-client-js#maxvaluesperfacet
+ * default: 100
+ * https://www.algolia.com/doc/api-reference/api-parameters/maxValuesPerFacet/
*/
maxValuesPerFacet?: number;
/**
* Default list of attributes to highlight. If set to null, all indexed attributes are highlighted.
* default: null
- * https://github.com/algolia/algoliasearch-client-js#attributestohighlight
+ * https://www.algolia.com/doc/api-reference/api-parameters/attributesToHighlight/
*/
attributesToHighlight?: string[];
/**
* Default list of attributes to snippet alongside the number of words to return
* default: null
- * https://github.com/algolia/algoliasearch-client-js#attributestosnippet
+ * https://www.algolia.com/doc/api-reference/api-parameters/attributesToSnippet/
*/
attributesToSnippet?: string[];
/**
* Specify the string that is inserted before the highlighted parts in the query result
* default:
- * https://github.com/algolia/algoliasearch-client-js#highlightpretag
+ * https://www.algolia.com/doc/api-reference/api-parameters/highlightPreTag/
*/
highlightPreTag?: string;
/**
* Specify the string that is inserted after the highlighted parts in the query result
* default:
- * https://github.com/algolia/algoliasearch-client-js#highlightposttag
+ * https://www.algolia.com/doc/api-reference/api-parameters/highlightPostTag/
*/
highlightPostTag?: string;
/**
* String used as an ellipsis indicator when a snippet is truncated.
* default: …
- * https://github.com/algolia/algoliasearch-client-js#snippetellipsistext
+ * https://www.algolia.com/doc/api-reference/api-parameters/snippetEllipsisText/
*/
snippetEllipsisText?: string;
/**
* If set to true, restrict arrays in highlights and snippets to items that matched the query at least partially else return all array items in highlights and snippets
* default: false
- * https://github.com/algolia/algoliasearch-client-js#restricthighlightandsnippetarrays
+ * https://www.algolia.com/doc/api-reference/api-parameters/restrictHighlightAndSnippetArrays/
*/
restrictHighlightAndSnippetArrays?: boolean;
/**
* Pagination parameter used to select the number of hits per page
* default: 20
- * https://github.com/algolia/algoliasearch-client-js#hitsperpage
+ * https://www.algolia.com/doc/api-reference/api-parameters/hitsPerPage/
*/
hitsPerPage?: number;
/**
* Pagination parameter used to select the page to retrieve.
* default: 0
- * https://github.com/algolia/algoliasearch-client-js#page
+ * https://www.algolia.com/doc/api-reference/api-parameters/page/
*/
page?: number;
/**
* Offset of the first hit to return
* default: null
- * https://github.com/algolia/algoliasearch-client-js#offset
+ * https://www.algolia.com/doc/api-reference/api-parameters/offset/
*/
offset?: number;
/**
* Number of hits to return.
* default: null
- * https://github.com/algolia/algoliasearch-client-js#length
+ * https://www.algolia.com/doc/api-reference/api-parameters/length/
*/
length?: number;
/**
* The minimum number of characters needed to accept one typo.
* default: 4
- * https://github.com/algolia/algoliasearch-client-js#minwordsizefor1typo
+ * https://www.algolia.com/doc/api-reference/api-parameters/minWordSizefor1Typo/
*/
minWordSizefor1Typo?: number;
/**
* The minimum number of characters needed to accept two typo.
* fault: 8
- * https://github.com/algolia/algoliasearch-client-js#minwordsizefor2typos
+ * https://www.algolia.com/doc/api-reference/api-parameters/minWordSizefor2Typos/
*/
minWordSizefor2Typos?: number;
/**
@@ -1222,62 +1247,62 @@ declare namespace algoliasearch {
* 'false' The typo tolerance is disabled. All results with typos will be hidden.
* 'min' Only keep results with the minimum number of typos
* 'strict' Hits matching with 2 typos are not retrieved if there are some matching without typos.
- * https://github.com/algolia/algoliasearch-client-js#minwordsizefor2typos
+ * https://www.algolia.com/doc/api-reference/api-parameters/typoTolerance/
*/
typoTolerance?: boolean;
/**
* If set to false, disables typo tolerance on numeric tokens (numbers).
* default:
- * https://github.com/algolia/algoliasearch-client-js#allowtyposonnumerictokens
+ * https://www.algolia.com/doc/api-reference/api-parameters/allowTyposOnNumericTokens/
*/
allowTyposOnNumericTokens?: boolean;
/**
* If set to true, plural won't be considered as a typo
* default: false
- * https://github.com/algolia/algoliasearch-client-js#ignoreplurals
+ * https://www.algolia.com/doc/api-reference/api-parameters/ignorePlurals/
*/
ignorePlurals?: boolean;
/**
* List of attributes on which you want to disable typo tolerance
- * default: ""
- * https://github.com/algolia/algoliasearch-client-js#disabletypotoleranceonattributes
+ * default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/disableTypoToleranceOnAttributes/
*/
- disableTypoToleranceOnAttributes?: string;
+ disableTypoToleranceOnAttributes?: string[];
/**
* Search for entries around a given location
* default: ""
- * https://github.com/algolia/algoliasearch-client-js#aroundlatlng
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLng/
*/
aroundLatLng?: string;
/**
* Search for entries around a given latitude/longitude automatically computed from user IP address.
* default: ""
- * https://github.com/algolia/algoliasearch-client-js#aroundlatlngviaip
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLngViaIP/
*/
aroundLatLngViaIP?: string;
/**
* Control the radius associated with a geo search. Defined in meters.
* default: null
* You can specify aroundRadius=all if you want to compute the geo distance without filtering in a geo area
- * https://github.com/algolia/algoliasearch-client-js#aroundradius
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundRadius/
*/
aroundRadius?: number | 'all';
/**
* Control the precision of a geo search
* default: null
- * https://github.com/algolia/algoliasearch-client-js#aroundprecision
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundPrecision/
*/
aroundPrecision?: number;
/**
* Define the minimum radius used for a geo search when aroundRadius is not set.
* default: null
- * https://github.com/algolia/algoliasearch-client-js#minimumaroundradius
+ * https://www.algolia.com/doc/api-reference/api-parameters/minimumAroundRadius/
*/
minimumAroundRadius?: number;
/**
* Search entries inside a given area defined by the two extreme points of a rectangle
* default: null
- * https://github.com/algolia/algoliasearch-client-js#insideboundingbox
+ * https://www.algolia.com/doc/api-reference/api-parameters/insideBoundingBox/
*/
insideBoundingBox?: number[][];
/**
@@ -1286,13 +1311,13 @@ declare namespace algoliasearch {
* 'prefixAll' All query words are interpreted as prefixes. This option is not recommended.
* 'prefixLast' Only the last word is interpreted as a prefix (default behavior).
* 'prefixNone' No query word is interpreted as a prefix. This option is not recommended.
- * https://github.com/algolia/algoliasearch-client-js#querytype
+ * https://www.algolia.com/doc/api-reference/api-parameters/queryType/
*/
- queryType?: any;
+ queryType?: "prefixAll"|"prefixLast"|"prefixNone";
/**
* Search entries inside a given area defined by a set of points
* defauly: ''
- * https://github.com/algolia/algoliasearch-client-js#insidepolygon
+ * https://www.algolia.com/doc/api-reference/api-parameters/insidePolygon/
*/
insidePolygon?: number[][];
/**
@@ -1302,19 +1327,19 @@ declare namespace algoliasearch {
* 'firstWords' When a query does not return any results, the first word will be added as optional
* 'allOptional' When a query does not return any results, a second trial will be made with all words as optional
* 'none' No specific processing is done when a query does not return any results
- * https://github.com/algolia/algoliasearch-client-js#removewordsifnoresults
+ * https://www.algolia.com/doc/api-reference/api-parameters/removeWordsIfNoResults/
*/
- removeWordsIfNoResults?: string;
+ removeWordsIfNoResults?: "none"|"lastWords"|"firstWords"|"allOptional";
/**
* Enables the advanced query syntax
* default: false
- * https://github.com/algolia/algoliasearch-client-js#advancedsyntax
+ * https://www.algolia.com/doc/api-reference/api-parameters/advancedSyntax/
*/
advancedSyntax?: boolean;
/**
* A string that contains the comma separated list of words that should be considered as optional when found in the query
* default: []
- * https://github.com/algolia/algoliasearch-client-js#optionalwords
+ * https://www.algolia.com/doc/api-reference/api-parameters/optionalWords/
*/
optionalWords?: string[];
/**
@@ -1322,13 +1347,13 @@ declare namespace algoliasearch {
* default: false
* true|false: enable or disable stop words for all 41 supported languages; or
* a list of language ISO codes (as a comma-separated string) for which stop words should be enable
- * https://github.com/algolia/algoliasearch-client-js#removestopwords
+ * https://www.algolia.com/doc/api-reference/api-parameters/removeStopWords/
*/
- removeStopWords?: string[];
+ removeStopWords?: boolean|string[];
/**
* List of attributes on which you want to disable the computation of exact criteria
* default: []
- * https://github.com/algolia/algoliasearch-client-js#disableexactonattributes
+ * https://www.algolia.com/doc/api-reference/api-parameters/disableExactOnAttributes/
*/
disableExactOnAttributes?: string[];
/**
@@ -1337,81 +1362,90 @@ declare namespace algoliasearch {
* 'none': no exact on single word query
* 'word': exact set to 1 if the query word is found in the record
* 'attribute': exact set to 1 if there is an attribute containing a string equals to the query
- * https://github.com/algolia/algoliasearch-client-js#exactonsinglewordquery
+ * https://www.algolia.com/doc/api-reference/api-parameters/exactOnSingleWordQuery/
*/
- exactOnSingleWordQuery?: string;
+ exactOnSingleWordQuery?: "attribute"|"none"|"word";
/**
* Specify the list of approximation that should be considered as an exact match in the ranking formula
* default: ['ignorePlurals', 'singleWordSynonym']
* 'ignorePlurals': alternative words added by the ignorePlurals feature
* 'singleWordSynonym': single-word synonym (For example "NY" = "NYC")
* 'multiWordsSynonym': multiple-words synonym
- * https://github.com/algolia/algoliasearch-client-js#alternativesasexact
+ * https://www.algolia.com/doc/api-reference/api-parameters/alternativesAsExact/
*/
- alternativesAsExact?: any;
+ alternativesAsExact?: Array<"ignorePlurals"|"singleWordSynonym"|"multiWordsSynonym">;
/**
* If set to 1, enables the distinct feature, disabled by default, if the attributeForDistinct index setting is set.
- * https://github.com/algolia/algoliasearch-client-js#distinct
+ * https://www.algolia.com/doc/api-reference/api-parameters/distinct/
*/
- distinct?: any;
+ distinct?: number|boolean;
/**
* If set to true, the result hits will contain ranking information in the _rankingInfo attribute.
* default: false
- * https://github.com/algolia/algoliasearch-client-js#getrankinginfo
+ * https://www.algolia.com/doc/api-reference/api-parameters/getRankingInfo/
*/
getRankingInfo?: boolean;
/**
+ * @deprecated Use `numericAttributesForFiltering` instead
* All numerical attributes are automatically indexed as numerical filters
* default: ''
- * https://github.com/algolia/algoliasearch-client-js#numericattributestoindex
+ * https://www.algolia.com/doc/api-reference/api-parameters/numericAttributesForFiltering/
*/
numericAttributesToIndex?: string[];
+ /**
+ * All numerical attributes are automatically indexed as numerical filters
+ * default: ''
+ * https://www.algolia.com/doc/api-reference/api-parameters/numericAttributesForFiltering/
+ */
+ numericAttributesForFiltering?: string[];
/**
* @deprecated please use filters instead
* A string that contains the comma separated list of numeric filters you want to apply.
- * https://github.com/algolia/algoliasearch-client-js#numericfilters-deprecated
+ * https://www.algolia.com/doc/api-reference/api-parameters/numericFilters/
*/
numericFilters?: string[];
/**
* @deprecated
+ *
* Filter the query by a set of tags.
- * https://github.com/algolia/algoliasearch-client-js#tagfilters-deprecated
+ * Default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/tagFilters/
*/
- tagFilters?: string;
+ tagFilters?: string[];
/**
- * @deprecated
* Filter the query by a set of facets.
- * https://github.com/algolia/algoliasearch-client-js#facetfilters-deprecated
+ * Default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/
*/
- facetFilters?: string | string[]
+ facetFilters?: string[]|string[][];
/**
* If set to false, this query will not be taken into account in the analytics feature.
* default true
- * https://github.com/algolia/algoliasearch-client-js#analytics
+ * https://www.algolia.com/doc/api-reference/api-parameters/analytics/
*/
analytics?: boolean;
/**
* If set, tag your query with the specified identifiers
- * default: null
- * https://github.com/algolia/algoliasearch-client-js#analyticstags
+ * default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/analyticsTags/
*/
analyticsTags?: string[];
/**
* If set to false, the search will not use the synonyms defined for the targeted index.
* default: true
- * https://github.com/algolia/algoliasearch-client-js#synonyms
+ * https://www.algolia.com/doc/api-reference/api-parameters/synonyms/
*/
synonyms?: boolean;
/**
* If set to false, words matched via synonym expansion will not be replaced by the matched synonym in the highlighted result.
* default: true
- * https://github.com/algolia/algoliasearch-client-js#replacesynonymsinhighlight
+ * https://www.algolia.com/doc/api-reference/api-parameters/replaceSynonymsInHighlight/
*/
replaceSynonymsInHighlight?: boolean;
/**
* Configure the precision of the proximity ranking criterion
* default: 1
- * https://github.com/algolia/algoliasearch-client-js#minproximity
+ * https://www.algolia.com/doc/api-reference/api-parameters/minProximity/
*/
minProximity?: number;
@@ -1464,7 +1498,7 @@ declare namespace algoliasearch {
interface Task {
taskID: number;
createdAt: string;
- objectID?: string;
+ objectID?: string;
}
interface TaskStatus {
@@ -1747,42 +1781,42 @@ declare namespace algoliasearch {
interface Response {
/**
* Contains all the hits matching the query
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
hits: any[];
/**
* Current page
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
page: number;
/**
* Number of total hits matching the query
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
nbHits: number;
/**
* Number of pages
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
nbPages: number;
/**
* Number of hits per pages
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
hitsPerPage: number;
/**
* Engine processing time (excluding network transfer)
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
processingTimeMS: number;
/**
* Query used to perform the search
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
query: string;
/**
* GET parameters used to perform the search
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
params: string;
facets?: {
@@ -1796,6 +1830,16 @@ declare namespace algoliasearch {
sum: number,
};
};
+ /**
+ * The index name is only set when searching multiple indices.
+ * https://www.algolia.com/doc/api-reference/api-methods/multiple-queries/?language=javascript#response
+ */
+ index?: string;
+ /**
+ * The cursor is only set when browsing the index.
+ * https://www.algolia.com/doc/api-reference/api-methods/browse/
+ */
+ cursor?: string;
}
interface MultiResponse {
diff --git a/types/algoliasearch/lite/index.d.ts b/types/algoliasearch/lite/index.d.ts
index 4f068d5647..ce58d6a428 100644
--- a/types/algoliasearch/lite/index.d.ts
+++ b/types/algoliasearch/lite/index.d.ts
@@ -1,12 +1,15 @@
-// Type definitions for algoliasearch-client-js 3.27.0
+// Type definitions for algoliasearch-client-js 3.30.0
// Project: https://github.com/algolia/algoliasearch-client-js
// Definitions by: Baptiste Coquelle
// Haroen Viaene
// Aurélien Hervé
// Samuel Vaillant
// Claas Brüggemann
+// Kai Eichinger
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-// TypeScript Version: 2.2
+// TypeScript Version: 2.8
+
+type Omit = Pick>
declare namespace algoliasearch {
/**
@@ -130,6 +133,11 @@ declare namespace algoliasearch {
options: SearchForFacetValues.Parameters,
cb: (err: Error, res: SearchForFacetValues.Response) => void
): void;
+ /**
+ * Browse an index
+ * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
+ */
+ browse(query: string, parameters: BrowseParameters, cb: (err: Error, res: BrowseResponse) => void): void;
/**
* Browse an index
* https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
@@ -139,7 +147,7 @@ declare namespace algoliasearch {
* Browse an index
* https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
*/
- browse(query: string): Promise;
+ browse(query: string, parameters?: BrowseParameters): Promise;
/**
* Browse an index from a cursor
* https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse
@@ -194,114 +202,122 @@ declare namespace algoliasearch {
query: string;
processingTimeMS: number;
}
-
+ type BrowseParameters = Omit<
+ QueryParameters,
+ | "typoTolerance"
+ | "distinct"
+ | "facets"
+ | "getRankingInfo"
+ | "attributesToHighlight"
+ | "attributesToSnippet"
+ >
interface QueryParameters {
/**
* Query string used to perform the search
* default: ''
- * https://github.com/algolia/algoliasearch-client-js#query
+ * https://www.algolia.com/doc/api-reference/api-parameters/query/
*/
query?: string;
/**
* Filter the query with numeric, facet or/and tag filters
* default: ""
- * https://github.com/algolia/algoliasearch-client-js#filters
+ * https://www.algolia.com/doc/api-reference/api-parameters/filters/
*/
filters?: string;
/**
* A string that contains the list of attributes you want to retrieve in order to minimize the size of the JSON answer.
* default: *
- * https://github.com/algolia/algoliasearch-client-js#attributestoretrieve
+ * https://www.algolia.com/doc/api-reference/api-parameters/attributesToRetrieve/
*/
attributesToRetrieve?: string[];
/**
* List of attributes you want to use for textual search
* default: attributeToIndex
- * https://github.com/algolia/algoliasearch-client-js#restrictsearchableattributes
+ * https://www.algolia.com/doc/api-reference/api-parameters/restrictSearchableAttributes/
*/
restrictSearchableAttributes?: string[];
/**
* You can use facets to retrieve only a part of your attributes declared in attributesForFaceting attributes
- * default: ""
- * https://github.com/algolia/algoliasearch-client-js#facets
+ * default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/facets/
*/
- facets?: string;
+ facets?: string[];
/**
* Limit the number of facet values returned for each facet.
- * default: ""
- * https://github.com/algolia/algoliasearch-client-js#maxvaluesperfacet
+ * default: 100
+ * https://www.algolia.com/doc/api-reference/api-parameters/maxValuesPerFacet/
*/
maxValuesPerFacet?: number;
/**
* Default list of attributes to highlight. If set to null, all indexed attributes are highlighted.
* default: null
- * https://github.com/algolia/algoliasearch-client-js#attributestohighlight
+ * https://www.algolia.com/doc/api-reference/api-parameters/attributesToHighlight/
*/
attributesToHighlight?: string[];
/**
* Default list of attributes to snippet alongside the number of words to return
* default: null
- * https://github.com/algolia/algoliasearch-client-js#attributestosnippet
+ * https://www.algolia.com/doc/api-reference/api-parameters/attributesToSnippet/
*/
attributesToSnippet?: string[];
/**
* Specify the string that is inserted before the highlighted parts in the query result
* default:
- * https://github.com/algolia/algoliasearch-client-js#highlightpretag
+ * https://www.algolia.com/doc/api-reference/api-parameters/highlightPreTag/
*/
highlightPreTag?: string;
/**
* Specify the string that is inserted after the highlighted parts in the query result
* default:
- * https://github.com/algolia/algoliasearch-client-js#highlightposttag
+ * https://www.algolia.com/doc/api-reference/api-parameters/highlightPostTag/
*/
highlightPostTag?: string;
/**
* String used as an ellipsis indicator when a snippet is truncated.
* default: …
- * https://github.com/algolia/algoliasearch-client-js#snippetellipsistext
+ * https://www.algolia.com/doc/api-reference/api-parameters/snippetEllipsisText/
*/
snippetEllipsisText?: string;
/**
* If set to true, restrict arrays in highlights and snippets to items that matched the query at least partially else return all array items in highlights and snippets
* default: false
- * https://github.com/algolia/algoliasearch-client-js#restricthighlightandsnippetarrays
+ * https://www.algolia.com/doc/api-reference/api-parameters/restrictHighlightAndSnippetArrays/
*/
restrictHighlightAndSnippetArrays?: boolean;
/**
* Pagination parameter used to select the number of hits per page
* default: 20
- * https://github.com/algolia/algoliasearch-client-js#hitsperpage
+ * https://www.algolia.com/doc/api-reference/api-parameters/hitsPerPage/
*/
hitsPerPage?: number;
/**
* Pagination parameter used to select the page to retrieve.
* default: 0
- * https://github.com/algolia/algoliasearch-client-js#page
+ * https://www.algolia.com/doc/api-reference/api-parameters/page/
*/
page?: number;
/**
* Offset of the first hit to return
* default: null
- * https://github.com/algolia/algoliasearch-client-js#offset
+ * https://www.algolia.com/doc/api-reference/api-parameters/offset/
*/
offset?: number;
/**
* Number of hits to return.
* default: null
- * https://github.com/algolia/algoliasearch-client-js#length
+ * https://www.algolia.com/doc/api-reference/api-parameters/length/
*/
length?: number;
/**
* The minimum number of characters needed to accept one typo.
* default: 4
- * https://github.com/algolia/algoliasearch-client-js#minwordsizefor1typo
+ * https://www.algolia.com/doc/api-reference/api-parameters/minWordSizefor1Typo/
*/
minWordSizefor1Typo?: number;
/**
* The minimum number of characters needed to accept two typo.
* fault: 8
- * https://github.com/algolia/algoliasearch-client-js#minwordsizefor2typos
+ * https://www.algolia.com/doc/api-reference/api-parameters/minWordSizefor2Typos/
*/
minWordSizefor2Typos?: number;
/**
@@ -311,62 +327,62 @@ declare namespace algoliasearch {
* 'false' The typo tolerance is disabled. All results with typos will be hidden.
* 'min' Only keep results with the minimum number of typos
* 'strict' Hits matching with 2 typos are not retrieved if there are some matching without typos.
- * https://github.com/algolia/algoliasearch-client-js#minwordsizefor2typos
+ * https://www.algolia.com/doc/api-reference/api-parameters/typoTolerance/
*/
typoTolerance?: boolean;
/**
* If set to false, disables typo tolerance on numeric tokens (numbers).
* default:
- * https://github.com/algolia/algoliasearch-client-js#allowtyposonnumerictokens
+ * https://www.algolia.com/doc/api-reference/api-parameters/allowTyposOnNumericTokens/
*/
allowTyposOnNumericTokens?: boolean;
/**
* If set to true, plural won't be considered as a typo
* default: false
- * https://github.com/algolia/algoliasearch-client-js#ignoreplurals
+ * https://www.algolia.com/doc/api-reference/api-parameters/ignorePlurals/
*/
ignorePlurals?: boolean;
/**
* List of attributes on which you want to disable typo tolerance
- * default: ""
- * https://github.com/algolia/algoliasearch-client-js#disabletypotoleranceonattributes
+ * default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/disableTypoToleranceOnAttributes/
*/
- disableTypoToleranceOnAttributes?: string;
+ disableTypoToleranceOnAttributes?: string[];
/**
* Search for entries around a given location
* default: ""
- * https://github.com/algolia/algoliasearch-client-js#aroundlatlng
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLng/
*/
aroundLatLng?: string;
/**
* Search for entries around a given latitude/longitude automatically computed from user IP address.
* default: ""
- * https://github.com/algolia/algoliasearch-client-js#aroundlatlngviaip
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLngViaIP/
*/
aroundLatLngViaIP?: string;
/**
* Control the radius associated with a geo search. Defined in meters.
* default: null
* You can specify aroundRadius=all if you want to compute the geo distance without filtering in a geo area
- * https://github.com/algolia/algoliasearch-client-js#aroundradius
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundRadius/
*/
aroundRadius?: number | 'all';
/**
* Control the precision of a geo search
* default: null
- * https://github.com/algolia/algoliasearch-client-js#aroundprecision
+ * https://www.algolia.com/doc/api-reference/api-parameters/aroundPrecision/
*/
aroundPrecision?: number;
/**
* Define the minimum radius used for a geo search when aroundRadius is not set.
* default: null
- * https://github.com/algolia/algoliasearch-client-js#minimumaroundradius
+ * https://www.algolia.com/doc/api-reference/api-parameters/minimumAroundRadius/
*/
minimumAroundRadius?: number;
/**
* Search entries inside a given area defined by the two extreme points of a rectangle
* default: null
- * https://github.com/algolia/algoliasearch-client-js#insideboundingbox
+ * https://www.algolia.com/doc/api-reference/api-parameters/insideBoundingBox/
*/
insideBoundingBox?: number[][];
/**
@@ -375,13 +391,13 @@ declare namespace algoliasearch {
* 'prefixAll' All query words are interpreted as prefixes. This option is not recommended.
* 'prefixLast' Only the last word is interpreted as a prefix (default behavior).
* 'prefixNone' No query word is interpreted as a prefix. This option is not recommended.
- * https://github.com/algolia/algoliasearch-client-js#querytype
+ * https://www.algolia.com/doc/api-reference/api-parameters/queryType/
*/
- queryType?: any;
+ queryType?: "prefixAll"|"prefixLast"|"prefixNone";
/**
* Search entries inside a given area defined by a set of points
* defauly: ''
- * https://github.com/algolia/algoliasearch-client-js#insidepolygon
+ * https://www.algolia.com/doc/api-reference/api-parameters/insidePolygon/
*/
insidePolygon?: number[][];
/**
@@ -391,19 +407,19 @@ declare namespace algoliasearch {
* 'firstWords' When a query does not return any results, the first word will be added as optional
* 'allOptional' When a query does not return any results, a second trial will be made with all words as optional
* 'none' No specific processing is done when a query does not return any results
- * https://github.com/algolia/algoliasearch-client-js#removewordsifnoresults
+ * https://www.algolia.com/doc/api-reference/api-parameters/removeWordsIfNoResults/
*/
- removeWordsIfNoResults?: string;
+ removeWordsIfNoResults?: "none"|"lastWords"|"firstWords"|"allOptional";
/**
* Enables the advanced query syntax
* default: false
- * https://github.com/algolia/algoliasearch-client-js#advancedsyntax
+ * https://www.algolia.com/doc/api-reference/api-parameters/advancedSyntax/
*/
advancedSyntax?: boolean;
/**
* A string that contains the comma separated list of words that should be considered as optional when found in the query
* default: []
- * https://github.com/algolia/algoliasearch-client-js#optionalwords
+ * https://www.algolia.com/doc/api-reference/api-parameters/optionalWords/
*/
optionalWords?: string[];
/**
@@ -411,13 +427,13 @@ declare namespace algoliasearch {
* default: false
* true|false: enable or disable stop words for all 41 supported languages; or
* a list of language ISO codes (as a comma-separated string) for which stop words should be enable
- * https://github.com/algolia/algoliasearch-client-js#removestopwords
+ * https://www.algolia.com/doc/api-reference/api-parameters/removeStopWords/
*/
- removeStopWords?: string[];
+ removeStopWords?: boolean|string[];
/**
* List of attributes on which you want to disable the computation of exact criteria
* default: []
- * https://github.com/algolia/algoliasearch-client-js#disableexactonattributes
+ * https://www.algolia.com/doc/api-reference/api-parameters/disableExactOnAttributes/
*/
disableExactOnAttributes?: string[];
/**
@@ -426,81 +442,90 @@ declare namespace algoliasearch {
* 'none': no exact on single word query
* 'word': exact set to 1 if the query word is found in the record
* 'attribute': exact set to 1 if there is an attribute containing a string equals to the query
- * https://github.com/algolia/algoliasearch-client-js#exactonsinglewordquery
+ * https://www.algolia.com/doc/api-reference/api-parameters/exactOnSingleWordQuery/
*/
- exactOnSingleWordQuery?: string;
+ exactOnSingleWordQuery?: "attribute"|"none"|"word";
/**
* Specify the list of approximation that should be considered as an exact match in the ranking formula
* default: ['ignorePlurals', 'singleWordSynonym']
* 'ignorePlurals': alternative words added by the ignorePlurals feature
* 'singleWordSynonym': single-word synonym (For example "NY" = "NYC")
* 'multiWordsSynonym': multiple-words synonym
- * https://github.com/algolia/algoliasearch-client-js#alternativesasexact
+ * https://www.algolia.com/doc/api-reference/api-parameters/alternativesAsExact/
*/
- alternativesAsExact?: any;
+ alternativesAsExact?: Array<"ignorePlurals"|"singleWordSynonym"|"multiWordsSynonym">;
/**
* If set to 1, enables the distinct feature, disabled by default, if the attributeForDistinct index setting is set.
- * https://github.com/algolia/algoliasearch-client-js#distinct
+ * https://www.algolia.com/doc/api-reference/api-parameters/distinct/
*/
- distinct?: any;
+ distinct?: number|boolean;
/**
* If set to true, the result hits will contain ranking information in the _rankingInfo attribute.
* default: false
- * https://github.com/algolia/algoliasearch-client-js#getrankinginfo
+ * https://www.algolia.com/doc/api-reference/api-parameters/getRankingInfo/
*/
getRankingInfo?: boolean;
/**
+ * @deprecated Use `numericAttributesForFiltering` instead
* All numerical attributes are automatically indexed as numerical filters
* default: ''
- * https://github.com/algolia/algoliasearch-client-js#numericattributestoindex
+ * https://www.algolia.com/doc/api-reference/api-parameters/numericAttributesForFiltering/
*/
numericAttributesToIndex?: string[];
+ /**
+ * All numerical attributes are automatically indexed as numerical filters
+ * default: ''
+ * https://www.algolia.com/doc/api-reference/api-parameters/numericAttributesForFiltering/
+ */
+ numericAttributesForFiltering?: string[];
/**
* @deprecated please use filters instead
* A string that contains the comma separated list of numeric filters you want to apply.
- * https://github.com/algolia/algoliasearch-client-js#numericfilters-deprecated
+ * https://www.algolia.com/doc/api-reference/api-parameters/numericFilters/
*/
numericFilters?: string[];
/**
* @deprecated
+ *
* Filter the query by a set of tags.
- * https://github.com/algolia/algoliasearch-client-js#tagfilters-deprecated
+ * Default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/tagFilters/
*/
- tagFilters?: string;
+ tagFilters?: string[];
/**
- * @deprecated
* Filter the query by a set of facets.
- * https://github.com/algolia/algoliasearch-client-js#facetfilters-deprecated
+ * Default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/
*/
- facetFilters?: string;
+ facetFilters?: string[]|string[][];
/**
* If set to false, this query will not be taken into account in the analytics feature.
* default true
- * https://github.com/algolia/algoliasearch-client-js#analytics
+ * https://www.algolia.com/doc/api-reference/api-parameters/analytics/
*/
analytics?: boolean;
/**
* If set, tag your query with the specified identifiers
- * default: null
- * https://github.com/algolia/algoliasearch-client-js#analyticstags
+ * default: []
+ * https://www.algolia.com/doc/api-reference/api-parameters/analyticsTags/
*/
analyticsTags?: string[];
/**
* If set to false, the search will not use the synonyms defined for the targeted index.
* default: true
- * https://github.com/algolia/algoliasearch-client-js#synonyms
+ * https://www.algolia.com/doc/api-reference/api-parameters/synonyms/
*/
synonyms?: boolean;
/**
* If set to false, words matched via synonym expansion will not be replaced by the matched synonym in the highlighted result.
* default: true
- * https://github.com/algolia/algoliasearch-client-js#replacesynonymsinhighlight
+ * https://www.algolia.com/doc/api-reference/api-parameters/replaceSynonymsInHighlight/
*/
replaceSynonymsInHighlight?: boolean;
/**
* Configure the precision of the proximity ranking criterion
* default: 1
- * https://github.com/algolia/algoliasearch-client-js#minproximity
+ * https://www.algolia.com/doc/api-reference/api-parameters/minProximity/
*/
minProximity?: number;
@@ -530,42 +555,42 @@ declare namespace algoliasearch {
interface Response {
/**
* Contains all the hits matching the query
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
hits: any[];
/**
* Current page
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
page: number;
/**
* Number of total hits matching the query
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
nbHits: number;
/**
* Number of pages
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
nbPages: number;
/**
* Number of hits per pages
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
hitsPerPage: number;
/**
* Engine processing time (excluding network transfer)
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
processingTimeMS: number;
/**
* Query used to perform the search
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
query: string;
/**
* GET parameters used to perform the search
- * https://github.com/algolia/algoliasearch-client-js#response-format
+ * https://www.algolia.com/doc/api-reference/api-methods/search/?language=javascript#response
*/
params: string;
facets?: {
@@ -579,6 +604,16 @@ declare namespace algoliasearch {
sum: number,
};
};
+ /**
+ * The index name is only set when searching multiple indices.
+ * https://www.algolia.com/doc/api-reference/api-methods/multiple-queries/?language=javascript#response
+ */
+ index?: string;
+ /**
+ * The cursor is only set when browsing the index.
+ * https://www.algolia.com/doc/api-reference/api-methods/browse/
+ */
+ cursor?: string;
}
interface MultiResponse {
diff --git a/types/ali-app/ali-app-tests.ts b/types/ali-app/ali-app-tests.ts
new file mode 100644
index 0000000000..a42301aed1
--- /dev/null
+++ b/types/ali-app/ali-app-tests.ts
@@ -0,0 +1,2153 @@
+(() => {
+ // https://docs.alipay.com/mini/api/ui-navigate
+ my.navigateTo({
+ url: 'new_page?count=100'
+ });
+ // test.js
+ Page({
+ onLoad(query: any) {
+ my.alert({
+ content: JSON.stringify(query),
+ });
+ }
+ });
+ my.redirectTo({
+ url: 'new_page?count=100'
+ });
+ // 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,
+ // 而 redirectTo 方法则不会。见下方示例代码
+
+ // 此处是one页面
+ my.navigateTo({
+ url: 'two?pageId=10000'
+ });
+
+ // 此处是two页面
+ my.navigateTo({
+ url: 'one?pageId=99999'
+ });
+
+ // 在three页面内 navigateBack,将返回one页面
+ my.navigateBack({
+ delta: 2
+ });
+ my.reLaunch({
+ url: '/page/index'
+ });
+ my.setNavigationBar({
+ title: '你好',
+ backgroundColor: '#108ee9',
+ success() {
+ my.alert({
+ content: '设置成功',
+ });
+ },
+ fail() {
+ my.alert({
+ content: '设置是失败',
+ });
+ },
+ });
+ my.showNavigationBarLoading();
+ my.hideNavigationBarLoading();
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-tabbar
+ my.switchTab({
+ url: '/home'
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-feedback
+ my.alert({
+ title: '亲',
+ content: '您本月的账单已出',
+ buttonText: '我知道了',
+ success: () => {
+ my.alert({
+ title: '用户点击了「我知道了」',
+ });
+ },
+ });
+ my.confirm({
+ title: '温馨提示',
+ content: '您是否想查询快递单号:1234567890',
+ confirmButtonText: '马上查询',
+ cancelButtonText: '暂不需要',
+ success: (result) => {
+ my.alert({
+ title: `${result.confirm}`,
+ });
+ },
+ });
+ my.prompt({
+ title: '标题单行',
+ message: '说明当前状态、提示用户解决方案,最好不要超过两行。',
+ placeholder: '给朋友留言',
+ okButtonText: '确定',
+ cancelButtonText: '取消',
+ success: (result) => {
+ my.alert({
+ title: JSON.stringify(result),
+ });
+ },
+ });
+ my.showToast({
+ type: 'success',
+ content: '操作成功',
+ duration: 3000,
+ success: () => {
+ my.alert({
+ title: 'toast 消失了',
+ });
+ },
+ });
+ my.hideToast();
+ my.showLoading({
+ content: '加载中...',
+ delay: 1000,
+ });
+
+ my.hideLoading();
+
+ Page({
+ onLoad() {
+ my.showLoading();
+ const that = this;
+ setTimeout(() => {
+ my.hideLoading({
+ page: that, // 防止执行时已经切换到其它页面,page指向不准确
+ });
+ }, 4000);
+ }
+ });
+ my.showNavigationBarLoading();
+ my.hideNavigationBarLoading();
+ my.showActionSheet({
+ title: '支付宝-ActionSheet',
+ items: ['菜单一', '菜单二', '菜单三', '菜单四', '菜单五'],
+ badges: [
+ { index: 0, type: 'none' },
+ { index: 1, type: 'point' },
+ { index: 2, type: 'num', text: '99' },
+ { index: 3, type: 'text', text: '推荐' },
+ { index: 4, type: 'more' }],
+ cancelButtonText: '取消好了',
+ success: (res) => {
+ const btn = res.index === -1 ? '取消' : `第${res.index}个`;
+ my.alert({
+ title: `你点了${btn}按钮`
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-pulldown
+ Page({
+ onPullDownRefresh() {
+ my.stopPullDownRefresh();
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-contact
+ my.choosePhoneContact({
+ success: (res) => {
+ my.alert({
+ content: `姓名:${res.name}\n号码:${res.mobile}`
+ });
+ }
+ });
+ my.chooseAlipayContact({
+ count: 2,
+ success: (res) => {
+ my.alert({
+ content: 'chooseAlipayContact response: ' + JSON.stringify(res)
+ });
+ },
+ fail: (res) => {
+ my.alert({
+ content: 'chooseAlipayContact response: ' + JSON.stringify(res)
+ });
+ }
+ });
+ my.chooseContact({
+ chooseType: 'multi', // 多选模式
+ includeMe: true, // 包含自己
+ includeMobileContactMode: 'known', // 仅包含双向手机通讯录联系人,也即双方手机通讯录都存有对方号码的联系人
+ multiChooseMax: 3, // 最多能选择三个联系人
+ multiChooseMaxTips: '超过选择的最大人数了',
+ success: (res) => {
+ my.alert({
+ content: 'chooseContact : ' + JSON.stringify(res)
+ });
+ },
+ fail: (res) => {
+ my.alert({
+ content: 'chooseContact : ' + JSON.stringify(res)
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-city
+ my.chooseCity({
+ cities: [
+ {
+ city: '朝阳区',
+ adCode: '110105',
+ spell: 'chaoyang'
+ },
+ {
+ city: '海淀区',
+ adCode: '110108',
+ spell: 'haidian'
+ },
+ {
+ city: '丰台区',
+ adCode: '110106',
+ spell: 'fengtai'
+ },
+ {
+ city: '东城区',
+ adCode: '110101',
+ spell: 'dongcheng'
+ },
+ {
+ city: '西城区',
+ adCode: '110102',
+ spell: 'xicheng'
+ },
+ {
+ city: '房山区',
+ adCode: '110111',
+ spell: 'fangshan'
+ }
+ ],
+ hotCities: [
+ {
+ city: '朝阳区',
+ adCode: '110105'
+ },
+ {
+ city: '海淀区',
+ adCode: '110108'
+ },
+ {
+ city: '丰台区',
+ adCode: '110106'
+ }
+ ],
+ success: (res) => {
+ my.alert({
+ content: `${res.city}:${res.adCode}`
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-date
+ my.datePicker({
+ format: 'yyyy-MM-dd',
+ currentDate: '2012-12-12',
+ startDate: '2012-12-10',
+ endDate: '2012-12-15',
+ success: (res) => {
+ my.alert({
+ content: res.date,
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-animation
+ const animation = my.createAnimation({
+ transformOrigin: "top right",
+ duration: 3000,
+ timeFunction: "ease-in-out",
+ delay: 100,
+ });
+ Page({
+ data: {
+ animationInfo: {}
+ },
+ onShow() {
+ const animation = my.createAnimation({
+ duration: 1000,
+ timeFunction: 'ease-in-out',
+ });
+
+ this.animation = animation;
+
+ animation.scale(3, 3).rotate(60).step();
+
+ this.setData({
+ animationInfo: animation.export()
+ });
+
+ setTimeout(() => {
+ animation.translate(35).step();
+ this.setData({
+ animationInfo: animation.export(),
+ });
+ }, 1500);
+ },
+ rotateAndScale(this: my.Page) {
+ // 旋转同时放大
+ this.animation.rotate(60).scale(3, 3).step();
+ this.setData({
+ animationInfo: this.animation.export(),
+ });
+ },
+ rotateThenScale(this: my.Page) {
+ // 先旋转后放大
+ this.animation.rotate(60).step();
+ this.animation.scale(3, 3).step();
+ this.setData({
+ animationInfo: this.animation.export(),
+ });
+ },
+ rotateAndScaleThenTranslate(this: my.Page) {
+ // 先旋转同时放大,然后平移
+ this.animation.rotate(60).scale(3, 3).step();
+ this.animation.translate(100, 100).step({ duration: 2000 });
+ this.setData({
+ animationInfo: this.animation.export()
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-canvas
+ const ctx = my.createCanvasContext('awesomeCanvas');
+ ctx.toTempFilePath({
+ success() { },
+ });
+
+ ctx.setTextAlign("left");
+ ctx.fillText("Hello world", 0, 100);
+
+ ctx.setTextBaseline("top");
+ ctx.fillText("Hello world", 0, 100);
+
+ ctx.setFillStyle('blue');
+ ctx.fillRect(50, 50, 100, 175);
+ ctx.draw();
+
+ ctx.setStrokeStyle('blue');
+ ctx.strokeRect(50, 50, 100, 175);
+ ctx.draw();
+
+ ctx.setFillStyle('red');
+ ctx.setShadow(15, 45, 45, 'yellow');
+ ctx.fillRect(20, 20, 100, 175);
+ ctx.draw();
+
+ const grd = ctx.createLinearGradient(10, 10, 150, 10);
+ grd.addColorStop(0, 'yellow');
+ grd.addColorStop(1, 'blue');
+
+ ctx.setFillStyle(grd);
+ ctx.fillRect(20, 20, 250, 180);
+ ctx.draw();
+
+ grd.addColorStop(0, 'blue');
+ grd.addColorStop(1, 'red');
+
+ ctx.setFillStyle(grd);
+ ctx.fillRect(20, 20, 250, 180);
+ ctx.draw();
+
+ grd.addColorStop(0.36, 'orange');
+ grd.addColorStop(0.56, 'cyan');
+ grd.addColorStop(0.63, 'yellow');
+ grd.addColorStop(0.76, 'blue');
+ grd.addColorStop(0.54, 'green');
+ grd.addColorStop(1, 'purple');
+ grd.addColorStop(0.4, 'red');
+
+ ctx.setFillStyle(grd);
+ ctx.fillRect(20, 20, 250, 180);
+ ctx.draw();
+
+ ctx.beginPath();
+ ctx.moveTo(20, 20);
+ ctx.lineTo(250, 10);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineWidth(10);
+ ctx.moveTo(20, 35);
+ ctx.lineTo(250, 30);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineWidth(20);
+ ctx.moveTo(20, 50);
+ ctx.lineTo(250, 55);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineWidth(25);
+ ctx.moveTo(20, 80);
+ ctx.lineTo(250, 85);
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.beginPath();
+ ctx.moveTo(10, 10);
+ ctx.lineTo(150, 10);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineCap('round');
+ ctx.setLineWidth(20);
+ ctx.moveTo(20, 70);
+ ctx.lineTo(250, 80);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineCap('butt');
+ ctx.setLineWidth(10);
+ ctx.moveTo(25, 80);
+ ctx.lineTo(250, 30);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineCap('square');
+ ctx.setLineWidth(10);
+ ctx.moveTo(35, 47);
+ ctx.lineTo(230, 120);
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.beginPath();
+ ctx.moveTo(20, 30);
+ ctx.lineTo(150, 70);
+ ctx.lineTo(20, 100);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineJoin('round');
+ ctx.setLineWidth(20);
+ ctx.moveTo(100, 20);
+ ctx.lineTo(280, 80);
+ ctx.lineTo(100, 100);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineJoin('bevel');
+ ctx.setLineWidth(20);
+ ctx.moveTo(60, 25);
+ ctx.lineTo(180, 80);
+ ctx.lineTo(90, 100);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineJoin('miter');
+ ctx.setLineWidth(15);
+ ctx.moveTo(130, 70);
+ ctx.lineTo(250, 50);
+ ctx.lineTo(230, 100);
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.beginPath();
+ ctx.setLineWidth(15);
+ ctx.setLineJoin('miter');
+ ctx.setMiterLimit(1);
+ ctx.moveTo(10, 10);
+ ctx.lineTo(100, 50);
+ ctx.lineTo(10, 90);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineWidth(15);
+ ctx.setLineJoin('miter');
+ ctx.setMiterLimit(2);
+ ctx.moveTo(50, 10);
+ ctx.lineTo(140, 50);
+ ctx.lineTo(50, 90);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.setLineWidth(15);
+ ctx.setLineJoin('miter');
+ ctx.setMiterLimit(3);
+ ctx.moveTo(90, 10);
+ ctx.lineTo(180, 50);
+ ctx.lineTo(90, 90);
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.rect(20, 20, 250, 80);
+ ctx.setFillStyle('blue');
+ ctx.fill();
+ ctx.draw();
+
+ ctx.fillRect(20, 20, 250, 80);
+ ctx.setFillStyle('blue');
+ ctx.draw();
+
+ ctx.setStrokeStyle('blue');
+ ctx.strokeRect(20, 20, 250, 80);
+ ctx.draw();
+
+ ctx.setFillStyle('blue');
+ ctx.fillRect(250, 10, 250, 200);
+ ctx.setFillStyle('yellow');
+ ctx.fillRect(0, 0, 150, 200);
+ ctx.clearRect(10, 10, 150, 75);
+ ctx.draw();
+
+ ctx.moveTo(20, 20);
+ ctx.lineTo(200, 20);
+ ctx.lineTo(200, 200);
+ ctx.fill();
+ ctx.draw();
+
+ ctx.rect(20, 20, 110, 40);
+ ctx.setFillStyle('blue');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.rect(20, 30, 150, 40);
+
+ ctx.setFillStyle('yellow');
+ ctx.fillRect(20, 80, 150, 40);
+
+ ctx.rect(20, 150, 150, 40);
+
+ ctx.setFillStyle('red');
+ ctx.fill();
+ ctx.draw();
+
+ ctx.moveTo(20, 20);
+ ctx.lineTo(150, 10);
+ ctx.lineTo(150, 150);
+ ctx.stroke();
+ ctx.draw();
+
+ ctx.rect(10, 10, 100, 30);
+ ctx.setStrokeStyle('blue');
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.rect(20, 50, 150, 50);
+
+ ctx.setStrokeStyle('yellow');
+ ctx.strokeRect(15, 75, 200, 35);
+
+ ctx.rect(20, 200, 150, 30);
+
+ ctx.setStrokeStyle('red');
+ ctx.stroke();
+ ctx.draw();
+
+ ctx.rect(20, 20, 150, 50);
+ ctx.setFillStyle('blue');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.rect(20, 50, 150, 40);
+
+ ctx.setFillStyle('yellow');
+ ctx.fillRect(20, 170, 150, 40);
+
+ ctx.rect(10, 100, 100, 30);
+
+ ctx.setFillStyle('red');
+ ctx.fill();
+ ctx.draw();
+
+ ctx.moveTo(20, 20);
+ ctx.lineTo(150, 20);
+ ctx.lineTo(150, 150);
+ ctx.closePath();
+ ctx.stroke();
+ ctx.draw();
+
+ ctx.rect(20, 20, 150, 50);
+ ctx.closePath();
+
+ ctx.beginPath();
+ ctx.rect(20, 50, 150, 40);
+
+ ctx.setFillStyle('red');
+ ctx.fillRect(20, 80, 120, 30);
+
+ ctx.rect(20, 150, 150, 40);
+
+ ctx.setFillStyle('blue');
+ ctx.fill();
+ ctx.draw();
+
+ ctx.moveTo(20, 20);
+ ctx.lineTo(150, 15);
+
+ ctx.moveTo(20, 55);
+ ctx.lineTo(120, 60);
+ ctx.stroke();
+ ctx.draw();
+
+ ctx.moveTo(20, 20);
+ ctx.rect(20, 20, 80, 30);
+ ctx.lineTo(120, 80);
+ ctx.stroke();
+ ctx.draw();
+
+ ctx.arc(200, 75, 50, 0, 2 * Math.PI);
+ ctx.setFillStyle('#CCCCCC');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.moveTo(50, 65);
+ ctx.lineTo(170, 80);
+ ctx.moveTo(200, 35);
+ ctx.lineTo(200, 235);
+ ctx.setStrokeStyle('#AAAAAA');
+ ctx.stroke();
+
+ ctx.setFontSize(12);
+ ctx.setFillStyle('yellow');
+ ctx.fillText('0', 165, 78);
+ ctx.fillText('0.6*PI', 96, 148);
+ ctx.fillText('1*PI', 15, 57);
+ ctx.fillText('1.7*PI', 94, 20);
+
+ ctx.beginPath();
+ ctx.arc(200, 85, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('blue');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.arc(200, 35, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('green');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.arc(450, 60, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('red');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.arc(150, 35, 50, 0, 1.8 * Math.PI);
+ ctx.setStrokeStyle('#666666');
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.beginPath();
+ ctx.arc(30, 30, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('red');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.arc(250, 25, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('blue');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.arc(20, 100, 2, 0, 2 * Math.PI);
+ ctx.arc(200, 100, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('green');
+ ctx.fill();
+
+ ctx.setFillStyle('yellow');
+ ctx.setFontSize(14);
+
+ ctx.beginPath();
+ ctx.moveTo(30, 30);
+ ctx.lineTo(30, 100);
+ ctx.lineTo(150, 75);
+
+ ctx.moveTo(250, 30);
+ ctx.lineTo(250, 80);
+ ctx.lineTo(70, 75);
+ ctx.setStrokeStyle('#EEEEEE');
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.moveTo(30, 30);
+ ctx.bezierCurveTo(30, 150, 250, 150, 180, 20);
+ ctx.setStrokeStyle('black');
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.beginPath();
+ ctx.arc(30, 30, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('red');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.arc(250, 20, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('blue');
+ ctx.fill();
+
+ ctx.beginPath();
+ ctx.arc(30, 200, 2, 0, 2 * Math.PI);
+ ctx.setFillStyle('green');
+ ctx.fill();
+
+ ctx.setFillStyle('black');
+ ctx.setFontSize(12);
+
+ ctx.beginPath();
+ ctx.moveTo(30, 30);
+ ctx.lineTo(30, 150);
+ ctx.lineTo(250, 30);
+ ctx.setStrokeStyle('#AAAAAA');
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.moveTo(30, 30);
+ ctx.quadraticCurveTo(30, 150, 250, 25);
+ ctx.setStrokeStyle('black');
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.strokeRect(15, 15, 30, 25);
+ ctx.scale(3, 3);
+ ctx.strokeRect(15, 15, 30, 25);
+ ctx.scale(3, 3);
+ ctx.strokeRect(15, 15, 30, 25);
+
+ ctx.draw();
+
+ ctx.strokeRect(200, 20, 180, 150);
+ ctx.rotate(30 * Math.PI / 180);
+ ctx.strokeRect(200, 20, 180, 150);
+ ctx.rotate(30 * Math.PI / 180);
+ ctx.strokeRect(200, 20, 180, 150);
+
+ ctx.draw();
+
+ ctx.strokeRect(20, 20, 250, 80);
+ ctx.translate(30, 30);
+ ctx.strokeRect(20, 20, 250, 80);
+ ctx.translate(30, 30);
+ ctx.strokeRect(20, 20, 250, 80);
+
+ ctx.draw();
+
+ ctx.setFontSize(14);
+ ctx.fillText('14', 20, 20);
+ ctx.setFontSize(22);
+ ctx.fillText('22', 40, 40);
+ ctx.setFontSize(30);
+ ctx.fillText('30', 60, 60);
+ ctx.setFontSize(38);
+ ctx.fillText('38', 90, 90);
+
+ ctx.draw();
+
+ ctx.setFontSize(42);
+ ctx.fillText('Hello', 30, 30);
+ ctx.fillText('alipay', 200, 200);
+
+ ctx.draw();
+
+ ctx.drawImage('https://img.alicdn.com/tfs/TB1GvVMj2BNTKJjy0FdXXcPpVXa-520-280.jpg', 2, 2, 250, 80);
+ ctx.draw();
+
+ ctx.setFillStyle('yellow');
+ ctx.fillRect(10, 10, 150, 100);
+ ctx.setGlobalAlpha(0.2);
+ ctx.setFillStyle('blue');
+ ctx.fillRect(50, 50, 150, 100);
+ ctx.setFillStyle('red');
+ ctx.fillRect(100, 100, 150, 100);
+
+ ctx.draw();
+
+ ctx.setLineDash([5, 15, 25]);
+ ctx.beginPath();
+ ctx.moveTo(0, 100);
+ ctx.lineTo(400, 100);
+ ctx.stroke();
+
+ ctx.draw();
+
+ ctx.rotate(45 * Math.PI / 180);
+ ctx.setFillStyle('red');
+ ctx.fillRect(70, 0, 100, 30);
+
+ ctx.transform(1, 1, 0, 1, 0, 0);
+ ctx.setFillStyle('#000');
+ ctx.fillRect(0, 0, 100, 100);
+
+ ctx.draw();
+
+ ctx.rotate(45 * Math.PI / 180);
+ ctx.setFillStyle('red');
+ ctx.fillRect(70, 0, 100, 30);
+
+ ctx.setTransform(1, 1, 0, 1, 0, 0);
+ ctx.setFillStyle('#000');
+ ctx.fillRect(0, 0, 100, 100);
+
+ ctx.draw();
+
+ ctx.save();
+ ctx.setFillStyle('red');
+ ctx.fillRect(20, 20, 250, 80);
+
+ ctx.restore();
+ ctx.fillRect(60, 60, 155, 130);
+
+ ctx.draw();
+
+ ctx.setFillStyle('blue');
+ ctx.fillRect(20, 20, 180, 80);
+ ctx.draw();
+ ctx.fillRect(60, 60, 250, 120);
+ ctx.draw(true);
+
+ ctx.font = 'italic bold 50px cursive';
+ const { width } = ctx.measureText('hello world');
+ console.log(width);
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-map
+ Page({
+ onReady() {
+ // 使用 my.createMapContext 获取 map 上下文
+ this.mapCtx = my.createMapContext('userMap');
+ },
+ getCenterLocation(this: my.Page) {
+ (this.mapCtx as my.MapContext).getCenterLocation({
+ success(res) {
+ console.log(res.longitude);
+ console.log(res.latitude);
+ }
+ });
+ },
+ moveToLocation() {
+ this.mapCtx.moveToLocation();
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ui-hidekeyboard
+ my.hideKeyboard();
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/scroll
+ my.pageScrollTo({
+ scrollTop: 100
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/selector-query
+ Page({
+ onReady() {
+ my.createSelectorQuery()
+ .select('#non-exists').boundingClientRect()
+ .select('#one').boundingClientRect()
+ .selectAll('.all').boundingClientRect()
+ .select('#scroll').scrollOffset()
+ .selectViewport().boundingClientRect()
+ .selectViewport().scrollOffset().exec((ret) => {
+ console.log(JSON.stringify(ret, null, 2));
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/ewdxl3
+ my.multiLevelSelect({
+ title: 'nihao', // 级联选择标题
+ list: [
+ {
+ name: "杭州市", // 条目名称
+ subList: [
+ {
+ name: "西湖区",
+ subList: [
+ {
+ name: "古翠街道"
+ },
+ {
+ name: "文新街道"
+ }
+ ]
+ },
+ {
+ name: "上城区",
+ subList: [
+ {
+ name: "延安街道"
+ },
+ {
+ name: "龙翔桥街道"
+ }
+ ]
+ }
+ ]// 级联子数据列表
+ }
+ ]// 级联数据列表
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/openapi-authorize
+ my.getAuthCode({
+ scopes: 'auth_user',
+ success: (res) => {
+ my.alert({
+ content: res.authCode,
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/userinfo
+ my.getAuthCode({
+ scopes: 'auth_user',
+ success: (res) => {
+ my.getAuthUserInfo({
+ success: (userInfo) => {
+ my.alert({
+ content: userInfo.nickName
+ });
+ my.alert({
+ content: userInfo.avatar
+ });
+ }
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/openapi-pay
+ my.tradePay({
+ tradeNO: '201711152100110410533667792', // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号trade_no
+ success: (res) => {
+ my.alert({
+ content: JSON.stringify(res),
+ });
+ },
+ fail: (res) => {
+ my.alert({
+ content: JSON.stringify(res),
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/pay-sign
+ my.paySignCenter({
+ // tslint:disable-next-line:max-line-length
+ signStr: 'biz_content%3D%257B%2522access_params%2522%253A%257B%2522channel%2522%253A%2522ALIPAYAPP%2522%257D%252C%2522external_agreement_no%2522%253A%2522xidong___2317%2522%252C%2522external_logon_id%2522%253A%252213852852877%2522%252C%2522personal_product_code%2522%253A%2522GENERAL_WITHHOLDING_P%2522%252C%2522product_code%2522%253A%2522GENERAL_WITHHOLDING%2522%252C%2522sign_scene%2522%253A%2522INDUSTRY%257CCARRENTAL%2522%252C%2522third_party_type%2522%253A%2522PARTNER%2522%257D%26sign%3Df3pjBDTRftOwXWnCqAMAnkBfGTFlcMmZI8hEgmV6uREZRXVDuLsSjD8WO%252FeZ1fjDG8GqVO9t1AN7q6yCUHKX%252Bw%252FE7efXwpVDWldr4iVuXDtNd3UJDJUiRJhIm6b73czWacVzm1XIery%252F2DyKI2y08tBf5NNWuQCC3d%252FITxziTl8%253D%26timestamp%3D2017-06-27%2B14%253A44%253A00%26sign_type%3DRSA%26notify_url%3Dhttp%253A%252F%252Fapi.test.alipay.net%252Fatinterface%252Freceive_notify.htm%26charset%3DUTF-8%26app_id%3D2017060101317939%26method%3Dalipay.user.agreement.page.sign%26return_url%3Dhttp%253A%252F%252Fapi.test.alipay.net%252Fatinterface%252Freceive_notify.htm%26version%3D1.0',
+ success: (res) => {
+ my.alert({
+ title: 'success', // alert框的标题
+ content: JSON.stringify(res)
+ });
+ },
+ fail: (res) => {
+ my.alert({
+ title: 'fail', // alert框的标题
+ content: JSON.stringify(res)
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/card-voucher-ticket
+ my.openCardList();
+ my.openMerchantCardList({ partnerId: '2088xxxxx' });
+ // 传入passId来打开
+ my.openCardDetail({ passId: "11xxxxx" });
+ my.openVoucherList();
+ my.openMerchantVoucherList({ partnerId: '2088xxxx' });
+ // 传入passId来打开
+ my.openVoucherDetail({ passId: "20170921" });
+
+ // 传入partnerId 和 serialNumber来打开
+ my.openVoucherDetail({
+ partnerId: "2018xxxx",
+ serialNumber: "20170921"
+ });
+ // 传入passId来打开
+ my.openKBVoucherDetail({ passId: "20170921" });
+
+ // 传入partnerId 和 serialNumber来打开
+ my.openKBVoucherDetail({
+ partnerId: "2088xxxx",
+ serialNumber: "20170921"
+ });
+ my.openTicketList();
+ my.openMerchantTicketList({ partnerId: '2088xxxx' });
+ // 传入passId来打开
+ my.openTicketDetail({ passId: "20170921" });
+
+ // 传入partnerId 和 serialNumber来打开
+ my.openTicketDetail({
+ partnerId: "2088xxxx",
+ serialNumber: "20170921"
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/add-card-auth
+ my.addCardAuth({
+ url: '从 openapi 接口获取到的 url',
+ success: (res) => {
+ my.alert({ content: '授权成功' });
+ },
+ fail: (res) => {
+ my.alert({ content: '授权失败' });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/zm-service
+ my.startZMVerify({
+ bizNo: 'your-biz-no',
+ success: (res) => {
+ my.alert({ title: 'success:' + JSON.stringify(res) });
+ },
+ fail: (res) => {
+ my.alert({ title: 'fail: ' + JSON.stringify(res) });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/zmcreditborrow
+ my.zmCreditBorrow({
+ credit_biz: "",
+ out_order_no: "",
+ borrow_shop_name: "",
+ goods_name: "",
+ product_code: "w1010100000000002858",
+ rent_unit: "HOUR_YUAN",
+ rent_amount: "0.10",
+ deposit_amount: "0.50",
+ deposit_state: "Y",
+ invoke_return_url: "",
+ invoke_type: "TINYAPP",
+ borrow_time: "2017-04-27 10:01:01",
+ expiry_time: "2017-05-27 10:01:01",
+ rent_info: "2hour-free",
+ success: (res) => {
+ try {
+ const { resultStatus, result } = res;
+ switch (resultStatus) {
+ case '9000':
+ const callbackData = result.callbackData;
+ const decodedCallbackData = decodeURIComponent(callbackData);
+ const json = JSON.parse(decodedCallbackData.match(/{.*}/)!.toString());
+ const jsonStr = JSON.stringify(json, null, 4);
+ if (json.success === true || json.success === 'true') {
+ // 创建订单成功, 此时可以跳转到订单详情页面
+ my.alert({ content: '下单成功: ' + jsonStr });
+ } else {
+ // 创建订单失败, 请提示用户创建失败
+ my.alert({ content: '下单失败: ' + jsonStr });
+ }
+ // (this as any as my.Page).setData({
+ // callbackData,
+ // decodedCallbackData,
+ // parsedJSON: jsonStr,
+ // });
+ break;
+ case '6001':
+ // 用户点击返回, 取消此次服务, 此时可以给提示
+ my.alert({ content: '取消' });
+ break;
+ default:
+ break;
+ }
+ } catch (error) {
+ // 异常, 请在这里提示用户稍后重试
+ my.alert({
+ content: '异常' + JSON.stringify(error, null, 4)
+ });
+ }
+ },
+ fail: (error) => {
+ // 调用接口失败, 请在这里提示用户稍后重试
+ my.alert({
+ content: '调用失败' + JSON.stringify(error, null, 4)
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/templatemessage
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/text-identification
+ my.textRiskIdentification({
+ content: '加我支付宝',
+ type: ['keyword', '0', '1', '2', '3'],
+ success: (res) => {
+ my.alert({
+ title: 'ok', // alert 框的标题
+ content: JSON.stringify(res),
+ });
+ },
+ fail: (res) => {
+ my.alert({
+ title: 'fail', // alert 框的标题
+ content: JSON.stringify(res),
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/open-miniprogram
+ my.navigateToMiniProgram({
+ appId: 'xxxx',
+ extraData: {
+ data1: "test"
+ },
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ },
+ fail: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+ my.navigateBackMiniProgram({
+ extraData: {
+ data1: "test"
+ },
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ },
+ fail: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/webview-context
+ Page({
+ onLoad() {
+ this.webViewContext = my.createWebViewContext('web-view-1');
+ },
+ // 接收来自H5的消息
+ onMessage(e: any) {
+ console.log(e); // {'sendToMiniProgram': '0'}
+ // 向H5发送消息
+ this.webViewContext.postMessage({ sendToWebView: '1' });
+ }
+ });
+ // H5的js代码中需要先定义my.onMessage 用于接收来自小程序的消息。
+ my.onMessage = (e) => {
+ console.log(e); // {'sendToWebView': '1'}
+ };
+ // H5想小程序发送消息
+ my.postMessage({ sendToMiniProgram: '0' });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/media-image
+ const img = null as any as HTMLImageElement;
+ my.chooseImage({
+ count: 2,
+ success: (res) => {
+ img.src = res.apFilePaths[0];
+ },
+ });
+ my.previewImage({
+ current: 2,
+ urls: [
+ 'https://img.alicdn.com/tps/TB1sXGYIFXXXXc5XpXXXXXXXXXX.jpg',
+ 'https://img.alicdn.com/tps/TB1pfG4IFXXXXc6XXXXXXXXXXXX.jpg',
+ 'https://img.alicdn.com/tps/TB1h9xxIFXXXXbKXXXXXXXXXXXX.jpg'
+ ],
+ });
+ my.saveImage({
+ url: 'https://img.alicdn.com/tps/TB1sXGYIFXXXXc5XpXXXXXXXXXX.jpg'
+ });
+ my.compressImage({
+ apFilePaths: ['https://resource/apmlcc0ed184daffc5a0d8da86b2f518cf7b.image'],
+ // level: 1,
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+ // 网络图片路径
+ my.getImageInfo({
+ src: 'https://img.alicdn.com/tps/TB1sXGYIFXXXXc5XpXXXXXXXXXX.jpg',
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+
+ // apFilePath
+ my.chooseImage({
+ success: (res) => {
+ my.getImageInfo({
+ src: res.apFilePaths[0],
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+ },
+ });
+
+ // 相对路径
+ my.getImageInfo({
+ src: 'image/api.png',
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/storage
+ my.setStorage({
+ key: 'currentCity',
+ data: {
+ cityName: '杭州',
+ adCode: '330100',
+ spell: ' hangzhou',
+ },
+ success() {
+ my.alert({ content: '写入成功' });
+ }
+ });
+ my.setStorageSync({
+ key: 'currentCity',
+ data: {
+ cityName: '杭州',
+ adCode: '330100',
+ spell: ' hangzhou',
+ }
+ });
+ my.getStorage({
+ key: 'currentCity',
+ success(res) {
+ my.alert({ content: '获取成功:' + res.data.cityName });
+ },
+ fail(res) {
+ my.alert({ content: res.errorMessage });
+ }
+ });
+ const res = my.getStorageSync({ key: 'currentCity' });
+ my.alert({
+ content: JSON.stringify(res.data),
+ });
+ my.removeStorage({
+ key: 'currentCity',
+ success() {
+ my.alert({ content: '删除成功' });
+ }
+ });
+ my.removeStorageSync({
+ key: 'currentCity',
+ });
+ my.clearStorage();
+ my.clearStorageSync();
+ my.getStorageInfo({
+ success(res) {
+ console.log(res.keys);
+ console.log(res.currentSize);
+ console.log(res.limitSize);
+ }
+ });
+ const res1 = my.getStorageInfoSync();
+ console.log(res1.keys);
+ console.log(res1.currentSize);
+ console.log(res1.limitSize);
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/file
+ my.chooseImage({
+ success: (res) => {
+ my.saveFile({
+ apFilePath: res.apFilePaths[0],
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ },
+ });
+ },
+ });
+ my.getFileInfo({
+ apFilePath: 'https://resource/apml953bb093ebd2834530196f50a4413a87.video',
+ digestAlgorithm: 'sha1',
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+ my.getSavedFileInfo({
+ apFilePath: 'https://resource/apml953bb093ebd2834530196f50a4413a87.video',
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+ my.getSavedFileList({
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ }
+ });
+ my.getSavedFileList({
+ success: (res) => {
+ my.removeSavedFile({
+ apFilePath: res.fileList[0].apFilePath,
+ success: (res) => {
+ console.log('remove success');
+ }
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/location
+ my.getLocation({
+ success(res) {
+ my.hideLoading();
+ console.log(res);
+ /* that对象为Page可以设置数据刷新界面
+ that.setData({
+ hasLocation: true,
+ location: formatLocation(res.longitude, res.latitude)
+ })
+ */
+ },
+ fail() {
+ my.hideLoading();
+ my.alert({ title: '定位失败' });
+ },
+ });
+ my.openLocation({
+ longitude: '121.549697',
+ latitude: '31.227250',
+ name: '支付宝',
+ address: '杨高路地铁站',
+ });
+ my.chooseLocation({
+ success: (res) => {
+ console.log(res);
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/network
+ my.httpRequest({
+ url: 'http://httpbin.org/post',
+ method: 'POST',
+ data: {
+ from: '支付宝',
+ production: 'AlipayJSAPI',
+ },
+ dataType: 'json',
+ success(res) {
+ my.alert({ content: 'success' });
+ },
+ fail(res) {
+ my.alert({ content: 'fail' });
+ },
+ complete(res) {
+ my.hideLoading();
+ my.alert({ content: 'complete' });
+ }
+ });
+ my.uploadFile({
+ url: '请使用自己服务器地址',
+ fileType: 'image',
+ fileName: 'file',
+ filePath: '...',
+ success: (res) => {
+ my.alert({
+ content: '上传成功'
+ });
+ },
+ });
+ my.downloadFile({
+ url: 'http://img.alicdn.com/tfs/TB1x669SXXXXXbdaFXXXXXXXXXX-520-280.jpg',
+ success({ apFilePath }) {
+ my.previewImage({
+ urls: [apFilePath],
+ });
+ },
+ fail(res) {
+ my.alert({
+ content: res.errorMessage || res.error,
+ });
+ },
+ });
+ my.connectSocket({
+ url: 'test.php',
+ data: {},
+ header: {
+ 'content-type': 'application/json'
+ },
+ method: 'GET'
+ });
+ my.connectSocket({
+ url: 'test.php',
+ });
+
+ my.onSocketOpen(() => {
+ console.log('WebSocket 连接已打开!');
+ });
+ Page({
+ onLoad() {
+ this.callback = this.callback.bind(this);
+ my.onSocketOpen(this.callback);
+ },
+ onUnload() {
+ my.offSocketOpen(this.callback);
+ },
+ callback() {
+ },
+ });
+ my.connectSocket({
+ url: '开发者的服务器地址'
+ });
+
+ my.onSocketOpen(() => {
+ console.log('WebSocket 连接已打开!');
+ });
+
+ my.onSocketError(() => {
+ console.log('WebSocket 连接打开失败,请检查!');
+ });
+ Page({
+ onLoad() {
+ this.callback = this.callback.bind(this);
+ my.onSocketError(this.callback);
+ },
+ onUnload() {
+ my.offSocketError(this.callback);
+ },
+ callback() {
+ my.sendSocketMessage({
+ data: this.data.toSendMessage, // 需要发送的内容
+ success: (res) => {
+ my.alert({ content: '数据发送!' + this.data.toSendMessage });
+ },
+ });
+ },
+ });
+ my.connectSocket({
+ url: '服务器地址'
+ });
+
+ my.onSocketMessage((res) => {
+ console.log('收到服务器内容:' + res.data);
+ });
+ my.onSocketOpen(() => {
+ my.closeSocket();
+ });
+
+ my.onSocketClose(() => {
+ console.log('WebSocket 已关闭!');
+ });
+ Page({
+ // onLoad() {
+ onLaunch() {
+ // 注意: 回调方法的注册在整个小程序启动阶段只要做一次,调多次会有多次回调
+ my.onSocketClose(() => {
+ my.alert({ content: '连接已关闭!' });
+ this.setData({
+ sendMessageAbility: false,
+ closeLinkAbility: false,
+ });
+ });
+ // 注意: 回调方法的注册在整个小程序启动阶段只要做一次,调多次会有多次回调
+ my.onSocketOpen(() => {
+ my.alert({ content: '连接已打开!' });
+ this.setData({
+ sendMessageAbility: true,
+ closeLinkAbility: true,
+ });
+ });
+
+ my.onSocketError((res) => {
+ my.alert({ content: 'WebSocket 连接打开失败,请检查!' + res });
+ });
+
+ // 注意: 回调方法的注册在整个小程序启动阶段只要做一次,调多次会有多次回调
+ my.onSocketMessage((res) => {
+ my.alert({ content: '收到数据!' + JSON.stringify(res) });
+ });
+ },
+ connect_start() {
+ my.connectSocket({
+ url: '服务器地址', // 开发者服务器接口地址,必须是 wss 协议,且域名必须是后台配置的合法域名
+ success: (res) => {
+ my.showToast({
+ content: 'success', // 文字内容
+ });
+ },
+ fail: () => {
+ my.showToast({
+ content: 'fail', // 文字内容
+ });
+ }
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/can-i-use
+ my.canIUse('getFileInfo');
+ my.canIUse('closeSocket.object.code');
+ my.canIUse('getLocation.object.type');
+ my.canIUse('getSystemInfo.return.brand');
+ my.canIUse('lifestyle');
+ my.canIUse('button.open-type.share');
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/sdk-version
+ console.log(my.SDKVersion);
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/system-info
+ Page({
+ data: {
+ systemInfo: {}
+ },
+ getSystemInfoPage(this: my.Page) {
+ my.getSystemInfo({
+ success: (res) => {
+ this.setData({
+ systemInfo: res
+ });
+ }
+ });
+ },
+ });
+ Page({
+ data: {
+ systemInfo: {}
+ },
+ getSystemInfoSyncPage(this: my.Page) {
+ this.setData({
+ systemInfo: my.getSystemInfoSync()
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/network-status
+ Page({
+ data: {
+ hasNetworkType: false
+ },
+ getNetworkType(this: my.Page) {
+ my.getNetworkType({
+ success: (res) => {
+ this.setData({
+ hasNetworkType: true,
+ networkType: res.networkType
+ });
+ }
+ });
+ },
+ clear(this: my.Page) {
+ this.setData({
+ hasNetworkType: false,
+ networkType: ''
+ });
+ },
+ });
+ my.onNetworkStatusChange((res) => {
+ console.log(JSON.stringify(res));
+ });
+ my.offNetworkStatusChange();
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/clipboard
+ Page({
+ data: {
+ text: '3.1415926',
+ copy: '',
+ },
+
+ handlePaste(this: my.Page) {
+ my.getClipboard({
+ success: ({ text }) => {
+ this.setData({ copy: text });
+ },
+ });
+ },
+ });
+ Page({
+ data: {
+ text: '3.1415926',
+ copy: '',
+ },
+
+ handleCopy() {
+ my.setClipboard({
+ text: this.data.text,
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/shake
+ Page({
+ watchShake() {
+ my.watchShake({
+ success() {
+ console.log('动起来了');
+ my.alert({ title: '动起来了 o.o' });
+ }
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/vibrate
+ Page({
+ vibrate() {
+ my.vibrate({
+ success: () => {
+ my.alert({ title: '震动起来了' });
+ }
+ });
+ },
+ });
+ Page({
+ vibrateLong() {
+ my.vibrateLong({
+ success: () => {
+ my.alert({ title: '震动起来了' });
+ }
+ });
+ },
+ });
+ Page({
+ vibrateShort() {
+ my.vibrateShort({
+ success: () => {
+ my.alert({ title: '震动起来了' });
+ }
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/macke-call
+ Page({
+ makePhoneCall() {
+ my.makePhoneCall({ number: '95888' });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/get-server-time
+ // getServerTime(){
+ // my.getServerTime({
+ // success: (res) => {
+ // my.alert({
+ // title: res.time,
+ // });
+ // },
+ // });
+ // };
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/user-capture-screen
+ my.onUserCaptureScreen(() => {
+ my.alert({
+ content: '收到用户截屏事件'
+ });
+ });
+ my.offUserCaptureScreen();
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/screen-brightness
+ my.setKeepScreenOn({
+ keepScreenOn: true,
+ success: (res) => {
+ },
+ fail: (res) => {
+ },
+ });
+ my.getScreenBrightness({
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ },
+ fail: (res) => {
+ },
+ });
+ my.setScreenBrightness({
+ brightness: 0.5,
+ success: (res) => {
+ console.log(JSON.stringify(res));
+ },
+ fail: (res) => {
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/show-auth-guide
+ my.showAuthGuide({
+ authType: 'LBSSERVICE'
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/scan
+ Page({
+ scan() {
+ my.scan({
+ type: 'qr',
+ success: (res) => {
+ my.alert({ title: res.code });
+ },
+ });
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/bluetooth-intro
+ // 初始化
+ my.openBluetoothAdapter({
+ success: (res) => {
+ console.log(res);
+ }
+ });
+ // 注册发现事件
+ my.onBluetoothDeviceFound({
+ success: (res) => {
+ const device = res.devices[0];
+ // 连接发现的设备
+ my.connectBLEDevice({
+ deviceId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ // 停止搜索
+ my.stopBluetoothDevicesDiscovery({
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ }
+ });
+ const deviceId = 'test';
+ const serviceId = 'test';
+ const characteristicId = 'test';
+ // 注册连接事件
+ my.onBLEConnectionStateChanged({
+ success: (res) => {
+ console.log(res);
+ if (res.connected) {
+ // 开始读写notify等操作
+ my.notifyBLECharacteristicValueChange({
+ deviceId,
+ serviceId,
+ characteristicId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ }
+ }
+ });
+ // 注册接收read或notify的数据
+ my.onBLECharacteristicValueChange({
+ success: (res) => {
+ console.log(res);
+ }
+ });
+ // 开始搜索
+ my.startBluetoothDevicesDiscovery({
+ services: ['fff0'],
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+
+ // 断开连接
+ my.disconnectBLEDevice({
+ deviceId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+
+ // 注销事件
+ my.offBluetoothDeviceFound();
+ my.offBLEConnectionStateChanged();
+ my.offBLECharacteristicValueChange();
+
+ // 退出蓝牙模块
+ my.closeBluetoothAdapter({
+ success: (res) => {
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/bluetooth-api
+ my.openBluetoothAdapter({
+ success: (res) => {
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.closeBluetoothAdapter({
+ success: (res) => {
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.getBluetoothAdapterState({
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.startBluetoothDevicesDiscovery({
+ services: ['fff0'],
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.stopBluetoothDevicesDiscovery({
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.getBluetoothDevices({
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.getConnectedBluetoothDevices({
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ const deviceId = 'test';
+ const serviceId = 'test';
+ const characteristicId = 'test';
+ my.connectBLEDevice({
+ // 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
+ deviceId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.disconnectBLEDevice({
+ deviceId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.writeBLECharacteristicValue({
+ deviceId,
+ serviceId,
+ characteristicId,
+ value: 'fffe',
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.readBLECharacteristicValue({
+ deviceId,
+ serviceId,
+ characteristicId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.notifyBLECharacteristicValueChange({
+ deviceId,
+ serviceId,
+ characteristicId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.getBLEDeviceServices({
+ deviceId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ my.getBLEDeviceCharacteristics({
+ deviceId,
+ serviceId,
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+ Page({
+ onLoad() {
+ this.callback = this.callback.bind(this);
+ my.onBluetoothDeviceFound(this.callback);
+ },
+ onUnload() {
+ my.offBluetoothDeviceFound(this.callback);
+ },
+ callback(res: any) {
+ console.log(res);
+ },
+ });
+ my.offBluetoothDeviceFound();
+ Page({
+ onLoad() {
+ this.callback = this.callback.bind(this);
+ my.onBLECharacteristicValueChange(this.callback);
+ },
+ onUnload() {
+ my.offBLECharacteristicValueChange(this.callback);
+ },
+ callback(res: any) {
+ console.log(res);
+ },
+ });
+ my.offBLECharacteristicValueChange();
+ my.offBLEConnectionStateChanged();
+ my.offBluetoothAdapterStateChange();
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/yqleyc
+ my.startBeaconDiscovery({
+ uuids: ['uuid1', 'uuid2'],
+ success: (res) => {
+ console.log(res);
+ },
+ fail: () => {
+ },
+ complete: () => {
+ }
+ });
+
+ my.stopBeaconDiscovery({
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+
+ my.getBeacons({
+ success: (res) => {
+ console.log(res);
+ },
+ fail: (res) => {
+ },
+ complete: (res) => {
+ }
+ });
+
+ my.onBeaconUpdate({
+ success: (res) => {
+ },
+ });
+
+ my.onBeaconServiceChange({
+ success: (res) => {
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/data-safe
+ Page({
+ data: {
+ inputValue: '',
+ outputValue: '',
+ },
+ onInput(this: my.Page, e: any) {
+ this.setData({ inputValue: e.detail.value });
+ },
+ onEncrypt(this: my.Page) {
+ my.rsa({
+ action: 'encrypt',
+ // 设置公钥
+ // tslint:disable-next-line:max-line-length
+ key: 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDKmi0dUSVQ04hL6GZGPMFK8+d6\nGzulagP27qSUBYxIJfE04KT+OHVeFFb6K+8nWDea5mkmZrIgp022zZVDgdWPNM62\n3ouBwHlsfm2ekey8PpQxfXaj8lhM9t8rJlC4FEc0s8Qp7Q5/uYrowQbT9m6t7BFK\n3egOO2xOKzLpYSqfbQIDAQAB',
+ text: this.data.inputValue,
+ success: (result) => {
+ this.setData({ outputValue: result.text });
+ },
+ fail(e) {
+ my.alert({
+ content: e.errorMessage || e.error,
+ });
+ },
+ });
+ },
+ onDecrypt(this: my.Page) {
+ my.rsa({
+ action: 'decrypt',
+ text: this.data.inputValue,
+ // 设置私钥
+ // tslint:disable-next-line:prefer-template
+ key: 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMqaLR1RJVDTiEvo\n' +
+ 'ZkY8wUrz53obO6VqA/bupJQFjEgl8TTgpP44dV4UVvor7ydYN5rmaSZmsiCnTbbN\n' +
+ 'lUOB1Y80zrbei4HAeWx+bZ6R7Lw+lDF9dqPyWEz23ysmULgURzSzxCntDn+5iujB\n' +
+ 'BtP2bq3sEUrd6A47bE4rMulhKp9tAgMBAAECgYBjsfRLPdfn6v9hou1Y2KKg+F5K\n' +
+ 'ZsY2AnIK+6l+sTAzfIAx7e0ir7OJZObb2eyn5rAOCB1r6RL0IH+MWaN+gZANNG9g\n' +
+ 'pXvRgcZzFY0oqdMZDuSJjpMTj7OEUlPyoGncBfvjAg0zdt9QGAG1at9Jr3i0Xr4X\n' +
+ '6WrFhtfVlmQUY1VsoQJBAPK2Qj/ClkZNtrSDfoD0j083LcNICqFIIGkNQ+XeuTwl\n' +
+ '+Gq4USTyaTOEe68MHluiciQ+QKvRAUd4E1zeZRZ02ikCQQDVscINBPTtTJt1JfAo\n' +
+ 'wRfTzA0Lvgig136xLLeQXREcgq1lzgkf+tGyUGYoy9BXsV0mOuYAT9ldja4jhJeq\n' +
+ 'cEulAkEAuSJ5KjV9dyb0RIFAz5C8d8o5KAodwaRIxJkPv5nCZbT45j6t9qbJxDg8\n' +
+ 'N+vghDlHI4owvl5wwVlAO8iQBy8e8QJBAJe9CVXFV0XJR/n/XnER66FxGzJjVi0f\n' +
+ '185nOlFARI5CHG5VxxT2PUCo5mHBl8ctIj+rQvalvGs515VQ6YEVDCECQE3S0AU2\n' +
+ 'BKyFVNtTpPiTyRUWqig4EbSXwjXdr8iBBJDLsMpdWsq7DCwv/ToBoLg+cQ4Crc5/\n5DChU8P30EjOiEo=',
+ success: (result) => {
+ this.setData({ outputValue: result.text });
+ },
+ fail(e) {
+ my.alert({
+ content: e.errorMessage || e.error,
+ });
+ },
+ });
+ },
+ });
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/share_app
+ Page({
+ onShareAppMessage() {
+ return {
+ title: '小程序示例',
+ desc: '小程序官方示例Demo,展示已支持的接口能力及组件。',
+ path: 'page/component/component-pages/view/view?param=123'
+ };
+ },
+ });
+
+ my.hideShareMenu();
+})();
+
+(() => {
+ // https://docs.alipay.com/mini/api/report
+ my.reportAnalytics('purchase', {
+ status: 200,
+ reason: 'ok'
+ });
+})();
diff --git a/types/ali-app/index.d.ts b/types/ali-app/index.d.ts
new file mode 100644
index 0000000000..82f7b2bf27
--- /dev/null
+++ b/types/ali-app/index.d.ts
@@ -0,0 +1,3265 @@
+// Type definitions for ali-app 1.0
+// Project: https://docs.alipay.com/mini/api/overview (Does not have to be to GitHub, but prefer linking to a source code repository rather than to a project website.)
+// Definitions by: taoqf
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+// TypeScript Version: 2.3
+
+// 公共部分
+declare namespace my {
+ // #region 基本参数
+ interface DataResponse {
+ /** 回调函数返回的内容 */
+ data: any;
+ /** 开发者服务器返回的 HTTP 状态码 */
+ status: number;
+ /** 开发者服务器返回的 HTTP Response Header */
+ headers: object;
+ }
+ interface ErrMsgResponse {
+ /** 成功:ok,错误:详细信息 */
+ errMsg: "ok" | string;
+ }
+ interface TempFileResponse {
+ /** 文件的临时路径 */
+ apFilePath: string;
+ }
+ interface BaseOptions {
+ /** 接口调用成功的回调函数 */
+ success?(res: R): void;
+ /** 接口调用失败的回调函数 */
+ fail?(res: E): void;
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
+ complete?(res: any): void;
+ }
+ interface ErrCodeResponse {
+ errCode: number;
+ }
+ // #endregion
+}
+
+// 界面
+declare namespace my {
+ //#region 导航栏 https://docs.alipay.com/mini/api/ui-navigate
+ interface NavigateToOptions extends BaseOptions {
+ /** 需要跳转的应用内页面的路径 */
+ url: string;
+ }
+ /**
+ * 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。
+ *
+ * 注意:为了不让用户在使用小程序时造成困扰,
+ * 我们规定页面路径只能是五层,请尽量避免多层级的交互方式。
+ */
+ function navigateTo(options: NavigateToOptions): void;
+
+ interface RedirectToOptions extends BaseOptions {
+ /** 需要跳转的应用内页面的路径 */
+ url: string;
+ }
+ /**
+ * 关闭当前页面,跳转到应用内的某个页面。
+ */
+ function redirectTo(options: RedirectToOptions): void;
+
+ interface NavigateBackOptions extends BaseOptions {
+ /** 返回的页面数,如果 delta 大于现有打开的页面数,则返回到首页 */
+ delta: number;
+ }
+ /**
+ * 关闭当前页面,返回上一级或多级页面。可通过 getCurrentPages 获取当前的页面栈信息,决定需要返回几层。
+ */
+ function navigateBack(options?: NavigateBackOptions): void;
+
+ interface ReLaunchOptions extends BaseOptions {
+ /**
+ * 需要跳转的应用内页面路径 , 路径后可以带参数。
+ * 参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔
+ * 如 'path?key=value&key2=value2',如果跳转的页面路径是 tabBar 页面则不能带参数
+ */
+ url: string;
+ }
+ /**
+ * 关闭所有页面,打开到应用内的某个页面。
+ */
+ function reLaunch(options?: ReLaunchOptions): void;
+
+ interface SetNavigationBarOptions extends BaseOptions {
+ /** 页面标题 */
+ title: string;
+ /** 图片连接地址,必须是https,请使用3x高清图片。若设置了image则title参数失效 */
+ image: string;
+ /** 导航栏背景色,支持十六进制颜色值 */
+ backgroundColor: string;
+ /** 导航栏底部边框颜色,支持十六进制颜色值。若设置了 backgroundColor,则borderBottomColor 不会生效,默认会和 backgroundColor 颜色一样 */
+ borderBottomColor: string;
+ /** 是否重置导航栏为支付宝默认配色,默认 false */
+ reset: boolean;
+ }
+ /**
+ * 动态设置当前页面的标题。
+ */
+ function setNavigationBar(options: Partial): void;
+
+ /**
+ * 显示导航栏 loading
+ */
+ function showNavigationBarLoading(): void;
+
+ /** 隐藏导航栏 loading。 */
+ function hideNavigationBarLoading(): void;
+ //#endregion
+
+ //#region TabBar https://docs.alipay.com/mini/api/ui-tabbar
+ interface SwitchTabOptions extends BaseOptions {
+ /**
+ * 需要跳转的 tabBar 页面的路径
+ * (需在 app.json 的 tabBar 字段定义的页面),路径后不能带参数
+ */
+ url: string;
+ }
+ /**
+ * 跳转到指定 tabBar 页面,并关闭其他所有非 tabBar 页面
+ */
+ function switchTab(options: SwitchTabOptions): void;
+ //#endregion
+
+ //#region 交互反馈 https://docs.alipay.com/mini/api/ui-feedback
+
+ interface AlertOptions extends BaseOptions {
+ /** alert框的标题 */
+ title: string;
+ /** alert框的内容 */
+ content: string;
+ /** 按钮文字,默认确定 */
+ buttonText: string;
+ }
+ function alert(options: Partial): void;
+
+ interface ConfirmOptions extends BaseOptions {
+ /** confirm框的标题 */
+ title: string;
+ /** confirm框的内容 */
+ content: string;
+ /** 确认按钮文字,默认‘确定’ */
+ confirmButtonText: string;
+ /** 确认按钮文字,默认‘取消’ */
+ cancelButtonText: string;
+ success(result: { confirm: boolean; }): void;
+ }
+ function confirm(options: Partial): void;
+
+ interface PromptOptions extends BaseOptions {
+ /** prompt框标题 */
+ title?: string;
+ /** prompt框文本,默认‘请输入内容’ */
+ message?: string;
+ /** 输入框内的提示文案 */
+ placeholder?: string;
+ /** message对齐方式,可用枚举left/center/right,iOS ‘center’, android ‘left’ */
+ align?: 'left' | 'center' | 'right' | string;
+ /** 确认按钮文字,默认‘确定’ */
+ okButtonText: string;
+ /** 确认按钮文字,默认‘取消’ */
+ cancelButtonText: string;
+ success(result: { ok: boolean; inputValue: string; }): void;
+ }
+ function prompt(options: PromptOptions): void;
+
+ interface ToastOptions extends BaseOptions {
+ /**
+ * 文字内容
+ */
+ content: string;
+ /** toast 类型,展示相应图标,默认 none,支持 success / fail / exception / none’。其中 exception 类型必须传文字信息 */
+ type?: 'none' | 'success' | 'fail' | 'exception' | string;
+ /**
+ * 显示时长,单位为 ms,默认 2000
+ */
+ duration?: number;
+ }
+ /**
+ * 显示消息提示框
+ */
+ function showToast(options: Partial): void;
+ function hideToast(): void;
+
+ interface LoadingOptions extends BaseOptions {
+ /**
+ * loading的文字内容
+ */
+ content?: string;
+ /**
+ * 延迟显示,单位 ms,默认 0。如果在此时间之前调用了 my.hideLoading 则不会显示
+ */
+ delay?: number;
+ }
+ /**
+ * 显示加载提示
+ */
+ function showLoading(options?: LoadingOptions): void;
+ interface HideLoadingOptions {
+ /**
+ * 体指当前page实例,某些场景下,需要指明在哪个page执行hideLoading。
+ */
+ page: any;
+ }
+ /**
+ * 隐藏消息提示框
+ */
+ function hideLoading(options?: HideLoadingOptions): void;
+
+ interface Badge {
+ /** 需要飘红的选项的索引,从0开始 */
+ index: number;
+ /**
+ * 飘红类型,支持 none(无红点)/ point(纯红点) / num(数字红点)/ text(文案红点)/ more(...)
+ *
+ */
+ type: 'none' | 'point' | 'num' | 'text' | 'more' | string;
+
+ /**
+ * 自定义飘红文案:
+ *
+ * 1、type为none/point/more时本文案可不填
+ * 2、type为num时本文案为小数或<=0均不显示, >100 显示"..."
+ */
+ text: string;
+ }
+ interface ActionSheetOptions extends BaseOptions {
+ /** 菜单标题 */
+ title?: string;
+ /**
+ * 菜单按钮文字数组
+ */
+ items: string[];
+ /**
+ * 取消按钮文案。默认为‘取消’。注:Android平台此字段无效,不会显示取消按钮。
+ */
+ cancelButtonText?: string;
+ /**
+ * (iOS特殊处理)指定按钮的索引号,从0开始,使用场景:需要删除或清除数据等类似场景,默认红色
+ */
+ destructiveBtnIndex?: number;
+ /**
+ * 需飘红选项的数组,数组内部对象字段见下表
+ */
+ badges?: Array>;
+ /**
+ * 接口调用成功的回调函数
+ */
+ success?(res: {
+ /**
+ * 用户点击的按钮,从上到下的顺序,从0开始
+ */
+ index: number;
+ }): void;
+ }
+ /**
+ * 显示操作菜单
+ */
+ function showActionSheet(options: ActionSheetOptions): void;
+ //#endregion
+
+ //#region 下拉刷新 https://docs.alipay.com/mini/api/ui-pulldown
+ /**
+ * Page 实现的接口对象
+ */
+ interface PageOptions {
+ /**
+ * 下拉刷新
+ * 在 Page 中定义 onPullDownRefresh 处理函数,监听该页面用户下拉刷新事件。
+ * 需要在页面对应的 .json 配置文件中配置 "pullRefresh": true 选项,才能开启下拉刷新事件。
+ * 当处理完数据刷新后,调用 my.stopPullDownRefresh 可以停止当前页面的下拉刷新。
+ */
+ onPullDownRefresh?(this: Page): void;
+ }
+ /**
+ * 停止当前页面的下拉刷新。
+ */
+ function stopPullDownRefresh(): void;
+ //#endregion
+
+ //#region 联系人 https://docs.alipay.com/mini/api/ui-contact
+ interface ChoosePhoneContactOptions extends BaseOptions {
+ success(result: {
+ name: string; // 选中的联系人姓名
+ mobile: string; // 选中的联系人手机号
+ }): void;
+ /**
+ * 10 没有权限
+ * 11 用户取消操作(或设备未授权使用通讯录)
+ */
+ fail?(error: 10 | 11): void;
+ }
+ /**
+ * 选择本地系统通信录中某个联系人的电话。
+ */
+ function choosePhoneContact(options: ChoosePhoneContactOptions): void;
+
+ interface ChooseAlipayContactOptions extends BaseOptions {
+ /** 单次最多选择联系人个数,默认 1,最大 10 */
+ count: number;
+ success(result: {
+ realName: string; // 账号的真实姓名
+ mobile: string; // 账号对应的手机号码
+ email: string; // 账号的邮箱
+ avatar: string; // 账号的头像链接
+ userId: string; // 支付宝账号唯一 userId
+ }): void;
+ /**
+ * 10 没有权限
+ * 11 用户取消操作(或设备未授权使用通讯录)
+ */
+ fail?(error: 10 | 11): void;
+ }
+ /**
+ * 唤起支付宝通讯录,选择一个或者多个支付宝联系人。
+ */
+ function chooseAlipayContact(options: ChooseAlipayContactOptions): void;
+
+ interface ContactsDic {
+ /**
+ * 支付宝账号唯一 userId
+ */
+ userId: string;
+ /**
+ * 账号的头像链接
+ */
+ avatar: string;
+ /**
+ * 账号对应的手机号码
+ */
+ mobile: string;
+ /**
+ * 账号的真实姓名
+ */
+ realName: string;
+ /**
+ * 账号的显示名称:也即支付宝设置的备注名称,默认为朋友圈里面的昵称
+ */
+ displayName: string; // 账号的显示名称:也即支付宝设置的备注名称,默认为朋友圈里面的昵称
+ }
+ interface ChooseContactOptions extends BaseOptions {
+ /** 选择类型,值为single(单选)或者 multi(多选) */
+ chooseType: 'single' | 'multi' | string;
+ /** 包含手机通讯录联系人的模式:默认为不包含(none)、或者仅仅包含双向通讯录联系人(known)、或者包含手机通讯录联系人(all) */
+ includeMobileContactMode?: 'none' | 'known' | 'all' | string;
+ /** 是否包含自己 */
+ includeMe?: boolean;
+ /** 最大选择人数,仅 chooseType 为 multi 时才有效 */
+ multiChooseMax?: number;
+ /** 多选达到上限的文案,仅 chooseType 为 multi 时才有效 */
+ multiChooseMaxTips?: string;
+
+ success(result: {
+ contactsDicArray: ContactsDic[];
+ }): void;
+ }
+ /**
+ * 唤起选人组件,默认只包含支付宝联系人,可以通过修改参数包含手机通讯录联系人或者双向通讯录联系人。
+ */
+ function chooseContact(options: ChooseContactOptions): void;
+ //#endregion
+
+ //#region 选择城市 https://docs.alipay.com/mini/api/ui-city
+ interface City {
+ city: string; // 城市名
+ adCode: string; // 行政区划代码
+ spell?: string; // 城市名对应拼音拼写,方便用户搜索
+ }
+ interface ChooseCityOptions extends BaseOptions {
+ showLocatedCity: boolean; // 是否显示当前定位城市,默认 false
+ showHotCities: boolean; // 是否显示热门城市,默认 true
+ cities: City[]; // 自定义城市列表,列表内对象字段见下表
+ hotCities: City[]; // 自定义热门城市列表,列表内对象字段见下表
+ success(result: { city: string; adCode: string; }): void;
+ }
+ /**
+ * 打开城市选择列表
+ *
+ * 如果用户没有选择任何城市直接点击了返回,将不会触发回调函数。
+ */
+ function chooseCity(options: Partial): void;
+ //#endregion
+
+ //#region 选择日期 https://docs.alipay.com/mini/api/ui-date
+ interface DatePickerOptions extends BaseOptions {
+ /**
+ * 返回的日期格式,
+ * 1. yyyy-MM-dd(默认)
+ * 2. HH:mm
+ * 3. yyyy-MM-dd HH:mm
+ * 4. yyyy-MM (最低基础库:1.1.1, 可用 canIUse('datePicker.object.format.yyyy-MM') 判断)
+ * 5. yyyy (最低基础库:1.1.1,可用 canIUse('datePicker.object.format.yyyy') 判断)
+ */
+ format: 'yyyy-MM-dd' | 'HH:mm' | 'yyyy-MM-dd HH:mm' | 'yyyy-MM' | 'yyyy';
+ /** 初始选择的日期时间,默认当前时间 */
+ currentDate: string;
+ /** 最小日期时间 */
+ startDate: string;
+ /** 最大日期时间 */
+ endDate: string;
+ success(result: { date: string; }): void;
+ /** 11 用户取消操作 */
+ fail(error: 11): void;
+ }
+ /**
+ * 打开日期选择列表
+ */
+ function datePicker(optiosn: Partial): void;
+ //#endregion
+
+ //#region 动画 https://docs.alipay.com/mini/api/ui-animation
+ type TimingFunction =
+ | "linear"
+ | "ease"
+ | "ease-in"
+ | "ease-in-out"
+ | "ease-out"
+ | "step-start"
+ | "step-end";
+ interface CreateAnimationOptions {
+ /** 动画持续时间,单位ms,默认值 400 */
+ duration: number;
+ /** 定义动画的效果,默认值"linear",有效值:"linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end" */
+ timeFunction: TimingFunction;
+ /** 动画持续时间,单位 ms,默认值 0 */
+ delay: number;
+ /** 设置transform-origin,默认为"50% 50% 0" */
+ transformOrigin: string;
+ }
+ interface Animator {
+ actions: AnimationAction[];
+ }
+ interface AnimationAction {
+ animates: Animate[];
+ option: AnimationActionOption;
+ }
+ interface AnimationActionOption {
+ transformOrigin: string;
+ transition: AnimationTransition;
+ }
+ interface AnimationTransition {
+ delay: number;
+ duration: number;
+ timingFunction: TimingFunction;
+ }
+ interface Animate {
+ type: string;
+ args: any[];
+ }
+ /**
+ * 创建动画实例 animation。调用实例的方法来描述动画,最后通过动画实例的export方法将动画数据导出并传递给组件的animation属性。
+ *
+ * 注意: export 方法每次调用后会清掉之前的动画操作
+ */
+ function createAnimation(options: Partial): Animation;
+ /** 动画实例可以调用以下方法来描述动画,调用结束后会返回自身,支持链式调用的写法。 */
+ interface Animation {
+ /**
+ * 调用动画操作方法后要调用 step() 来表示一组动画完成,
+ * 可以在一组动画中调用任意多个动画方法,
+ * 一组动画中的所有动画会同时开始,
+ * 一组动画完成后才会进行下一组动画。
+ * @param options 指定当前组动画的配置
+ */
+ step(options?: CreateAnimationOptions): void;
+ /**
+ * 导出动画操作
+ *
+ * 注意: export 方法每次调用后会清掉之前的动画操作
+ */
+ export(): Animator;
+ /** 透明度,参数范围 0~1 */
+ opacity(value: number): Animation;
+ /** 颜色值 */
+ backgroundColor(color: string): Animation;
+ /** 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值 */
+ width(length: number): Animation;
+ /** 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值 */
+ height(length: number): Animation;
+ /** 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值 */
+ top(length: number): Animation;
+ /** 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值 */
+ left(length: number): Animation;
+ /** 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值 */
+ bottom(length: number): Animation;
+ /** 长度值,如果传入 Number 则默认使用 px,可传入其他自定义单位的长度值 */
+ right(length: number): Animation;
+ /** deg的范围-180~180,从原点顺时针旋转一个deg角度 */
+ rotate(deg: number): Animation;
+ /** deg的范围-180~180,在X轴旋转一个deg角度 */
+ rotateX(deg: number): Animation;
+ /** deg的范围-180~180,在Y轴旋转一个deg角度 */
+ rotateY(deg: number): Animation;
+ /** deg的范围-180~180,在Z轴旋转一个deg角度 */
+ rotateZ(deg: number): Animation;
+ /** 同transform-function rotate3d */
+ rotate3d(x: number, y: number, z: number, deg: number): Animation;
+ /**
+ * 一个参数时,表示在X轴、Y轴同时缩放sx倍数;
+ * 两个参数时表示在X轴缩放sx倍数,在Y轴缩放sy倍数
+ */
+ scale(sx: number, sy?: number): Animation;
+ /** 在X轴缩放sx倍数 */
+ scaleX(sx: number): Animation;
+ /** 在Y轴缩放sy倍数 */
+ scaleY(sy: number): Animation;
+ /** 在Z轴缩放sy倍数 */
+ scaleZ(sz: number): Animation;
+ /** 在X轴缩放sx倍数,在Y轴缩放sy倍数,在Z轴缩放sz倍数 */
+ scale3d(sx: number, sy: number, sz: number): Animation;
+ /**
+ * 一个参数时,表示在X轴偏移tx,单位px;
+ * 两个参数时,表示在X轴偏移tx,在Y轴偏移ty,单位px。
+ */
+ translate(tx: number, ty?: number): Animation;
+ /**
+ * 在X轴偏移tx,单位px
+ */
+ translateX(tx: number): Animation;
+ /**
+ * 在Y轴偏移tx,单位px
+ */
+ translateY(ty: number): Animation;
+ /**
+ * 在Z轴偏移tx,单位px
+ */
+ translateZ(tz: number): Animation;
+ /**
+ * 在X轴偏移tx,在Y轴偏移ty,在Z轴偏移tz,单位px
+ */
+ translate3d(tx: number, ty: number, tz: number): Animation;
+ /**
+ * 参数范围-180~180;
+ * 一个参数时,Y轴坐标不变,X轴坐标延顺时针倾斜ax度;
+ * 两个参数时,分别在X轴倾斜ax度,在Y轴倾斜ay度
+ */
+ skew(ax: number, ay?: number): Animation;
+ /** 参数范围-180~180;Y轴坐标不变,X轴坐标延顺时针倾斜ax度 */
+ skewX(ax: number): Animation;
+ /** 参数范围-180~180;X轴坐标不变,Y轴坐标延顺时针倾斜ay度 */
+ skewY(ay: number): Animation;
+ /**
+ * 同transform-function matrix
+ */
+ matrix(
+ a: number,
+ b: number,
+ c: number,
+ d: number,
+ tx: number,
+ ty: number
+ ): Animation;
+ /** 同transform-function matrix3d */
+ matrix3d(
+ a1: number,
+ b1: number,
+ c1: number,
+ d1: number,
+ a2: number,
+ b2: number,
+ c2: number,
+ d2: number,
+ a3: number,
+ b3: number,
+ c3: number,
+ d3: number,
+ a4: number,
+ b4: number,
+ c4: number,
+ d4: number
+ ): Animation;
+ }
+ //#endregion
+
+ //#region 画布 https://docs.alipay.com/mini/api/ui-canvas
+ interface ToTempFilePathOptions extends BaseOptions {
+ x: number; // 画布 x 轴起点,默认为 0
+ y: number; // 画布 y 轴起点,默认为 0
+ width: number; // 画布宽度,默认为 canvas 宽度 - x
+ height: number; // 画布高度,默认为 canvas 高度 - y
+ destWidth: number; // 输出的图片宽度,默认为 width
+ destHeight: number; // 输出的图片高度,默认为 height
+ }
+ type Color = string | number[] | number | CanvasAction;
+
+ interface CanvasAction {
+ /**
+ * 创建一个颜色的渐变点。
+ * 小于最小 stop 的部分会按最小 stop 的 color 来渲染,大于最大 stop 的部分会按最大 stop 的 color 来渲染。
+ *
+ * @param stop 渐变点位置,值必须在 [0,1] 范围内
+ * @param color 颜色值
+ */
+ addColorStop(stop: number, color: Color): void;
+ }
+
+ interface TextMetrics {
+ width: number;
+ }
+
+ interface ConvasContext {
+ font: string;
+ /**
+ * 把当前画布的内容导出生成图片,并返回文件路径。
+ */
+ toTempFilePath(options?: Partial): void;
+ /**
+ * textAlign 是 Canvas 2D API 描述绘制文本时,文本的对齐方式的属性。注意,该对齐是基于
+ * CanvasRenderingContext2D.fillText 方法的x的值。所以如果 textAlign="center",那么该文本将画在 x-50%*width
+ */
+ setTextAlign(textAlign: 'left' | 'right' | 'center' | 'start' | 'end'): void;
+ /**
+ * textBaseline 是 Canvas 2D API 描述绘制文本时,当前文本基线的属性。
+ */
+ setTextBaseline(textBaseline: 'top' | 'hanging' | 'middle' | 'alphabetic' | 'ideographic' | 'bottom'): void;
+ /**
+ * 设置填充色。
+ *
+ * 如果没有设置 fillStyle,则默认颜色为 black。
+ */
+ setFillStyle(color: Color): void;
+ /**
+ * 设置边框颜色。
+ *
+ * 如果没有设置 strokeStyle,则默认颜色为 black。
+ */
+ setStrokeStyle(color: Color): void;
+ /**
+ * 设置阴影样式。
+ * 如果没有设置,offsetX 的默认值为 0, offsetY 的默认值为 0, blur 的默认值为 0,color 的默认值为 black。
+ * @param offsetX 阴影相对于形状水平方向的偏移
+ * @param offsetY 阴影相对于形状竖直方向的偏移
+ * @param blur 0~100 阴影的模糊级别,值越大越模糊
+ * @param color 阴影颜色
+ */
+ setShadow(offsetX: number, offsetY: number, blur: number, color: Color): void;
+
+ /**
+ * 创建一个线性的渐变色。
+ *
+ * @param x0 起点 x 坐标
+ * @param y0 起点 y 坐标
+ * @param x1 终点 x 坐标
+ * @param y1 终点 y 坐标
+ */
+ createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasAction;
+
+ /**
+ * 创建一个圆形的渐变色。
+ * 起点在圆心,终点在圆环。
+ * 需要使用 addColorStop() 来指定渐变点,至少需要两个。
+ * @param x 圆心 x 坐标
+ * @param y 圆心 y 坐标
+ * @param r 圆半径
+ * @returns
+ */
+ createCircularGradient(x: number, y: number, r: number): CanvasAction;
+
+ /**
+ * 设置线条的宽度。
+ * @param lineWidth 线条宽度,单位为 px
+ */
+ setLineWidth(lineWidth: number): void;
+
+ /**
+ * 设置线条的端点样式。
+ *
+ * @param lineCap 线条的结束端点样式
+ */
+ setLineCap(lineCap: 'round' | 'butt' | 'square'): void;
+
+ /**
+ * 设置线条的交点样式。
+ *
+ * @param lineJoin 线条的结束交点样式
+ */
+ setLineJoin(lineJoin: 'round' | 'bevel' | 'miter'): void;
+
+ /**
+ * 设置最大斜接长度,斜接长度指的是在两条线交汇处内角和外角之间的距离。 当 setLineJoin() 为 miter 时才有效。超过最大倾斜长度的,连接处将以 lineJoin 为 bevel 来显示
+ *
+ * @param miterLimit 最大斜接长度
+ */
+ setMiterLimit(miterLimit: number): void;
+
+ /**
+ * 创建一个矩形。
+ *
+ * @param x 矩形左上角的 x 坐标
+ * @param y 矩形左上角的 y 坐标
+ * @param width 矩形路径宽度
+ * @param height 矩形路径高度
+ */
+ rect(x: number, y: number, width: number, height: number): void;
+
+ /**
+ * 填充矩形。
+ * 用 setFillStyle() 设置矩形的填充色,如果没设置则默认是 black。
+ * @param x 矩形左上角的 x 坐标
+ * @param y 矩形左上角的 y 坐标
+ * @param width 矩形路径宽度
+ * @param height 矩形路径高度
+ */
+ fillRect(x: number, y: number, width: number, height: number): void;
+
+ /**
+ * 画一个矩形(非填充)。
+ * 用 setFillStroke() 设置矩形线条的颜色,如果没设置默认是 black。
+ * @param x 矩形左上角的 x 坐标
+ * @param y 矩形左上角的 y 坐标
+ * @param width 矩形路径宽度
+ * @param height 矩形路径高度
+ */
+ strokeRect(x: number, y: number, width: number, height: number): void;
+
+ /**
+ * 清除画布上在该矩形区域内的内容。
+ * clearRect 并非画一个白色的矩形在地址区域,而是清空,为了有直观感受,可以对 canvas 加了一层背景色。
+ * @param x 矩形左上角的 x 坐标
+ * @param y 矩形左上角的 y 坐标
+ * @param width 矩形路径宽度
+ * @param height 矩形路径高度
+ */
+ clearRect(x: number, y: number, width: number, height: number): void;
+
+ /**
+ * 对当前路径中的内容进行填充。默认的填充色为黑色。
+ *
+ */
+ fill(): void;
+
+ /**
+ * 画出当前路径的边框。默认 black。
+ * stroke() 描绘的的路径是从 beginPath() 开始计算,但是不会将 strokeRect() 包含进去
+ */
+ stroke(): void;
+
+ /**
+ * 关闭一个路径
+ * 关闭路径会连接起点和终点。
+ * 如果关闭路径后没有调用 fill() 或者 stroke() 并开启了新的路径,那之前的路径将不会被渲染。
+ */
+ beginPath(): void;
+
+ /**
+ * 关闭一个路径
+ * 关闭路径会连接起点和终点。
+ *
+ */
+ closePath(): void;
+
+ /**
+ * 把路径移动到画布中的指定点,不创建线条。
+ * 用 stroke() 方法来画线条
+ * @param x 目标位置 x 坐标
+ * @param y 目标位置 y 坐标
+ */
+ moveTo(x: number, y: number): void;
+
+ /**
+ * lineTo 方法增加一个新点,然后创建一条从上次指定点到目标点的线。
+ * 用 stroke() 方法来画线条
+ *
+ * @param x 目标位置 x 坐标
+ * @param y 目标位置 y 坐标
+ */
+ lineTo(x: number, y: number): void;
+
+ /**
+ * 画一条弧线。
+ * 创建一个圆可以用 arc() 方法指定其实弧度为0,终止弧度为 2 * Math.PI。
+ *
+ * @param x
+ * @param y
+ * @param r
+ * @param sAngle
+ * @param eAngle
+ */
+ arc(x: number, y: number, r: number, sAngle: number, eAngle: number): void;
+
+ /**
+ * 创建三次方贝塞尔曲线路径。
+ * 曲线的起始点为路径中前一个点。
+ * @param cp1x
+ * @param cp1y
+ * @param cp2x
+ * @param cp2y
+ * @param x
+ * @param y
+ */
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
+
+ /**
+ * 将当前创建的路径设置为当前剪切路径。
+ *
+ */
+ clip(): void;
+
+ /**
+ * 创建二次贝塞尔曲线路径。
+ * 曲线的起始点为路径中前一个点。
+ * @param cpx 贝塞尔控制点 x 坐标
+ * @param cpy 贝塞尔控制点 y 坐标
+ * @param x 结束点 x 坐标
+ * @param y 结束点 y 坐标
+ */
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
+
+ /**
+ * 在调用scale方法后,之后创建的路径其横纵坐标会被缩放。多次调用scale,倍数会相乘。
+ *
+ * @param scaleWidth 横坐标缩放倍数 (1 = 100%,0.5 = 50%,2 = 200%)
+ * @param scaleHeight 纵坐标轴缩放倍数 (1 = 100%,0.5 = 50%,2 = 200%)
+ */
+ scale(scaleWidth: number, scaleHeight: number): void;
+
+ /**
+ * 以原点为中心,原点可以用 translate方法修改。顺时针旋转当前坐标轴。多次调用rotate,旋转的角度会叠加。
+ *
+ * @param rotate 旋转角度,以弧度计(degrees * Math.PI/180;degrees 范围为0~360)
+ */
+ rotate(rotate: number): void;
+
+ /**
+ * 对当前坐标系的原点(0, 0)进行变换,默认的坐标系原点为页面左上角。
+ *
+ * @param x 水平坐标平移量
+ * @param y 竖直坐标平移量
+ */
+ translate(x: number, y: number): void;
+
+ /**
+ * 设置字体大小。
+ *
+ * @param fontSize 字号
+ */
+ setFontSize(fontSize: number): void;
+
+ /**
+ * 在画布上绘制被填充的文本。
+ *
+ * @param text 文本
+ * @param x 绘制文本的左上角 x 坐标
+ * @param y 绘制文本的左上角 y 坐标
+ */
+ fillText(text: string, x: number, y: number): void;
+
+ /**
+ * 绘制图像,图像保持原始尺寸。
+ *
+ * @param imageResource 图片资源, 只支持线上 cdn 地址或离线包地址,线上 cdn 需返回头 Access-Control-Allow-Origin: *
+ * @param x 图像左上角 x 坐标
+ * @param y 图像左上角 y 坐标
+ * @param width 图像宽度
+ * @param height 图像高度
+ */
+ drawImage(imageResource: string, x: number, y: number, width: number, height: number): void;
+
+ /**
+ * 设置全局画笔透明度。
+ *
+ * @param alpha 透明度,0 表示完全透明,1 表示不透明 范围 [0, 1]
+ */
+ setGlobalAlpha(alpha: number): void;
+
+ /**
+ * 设置虚线的样式
+ *
+ * @param segments 一组描述交替绘制线段和间距(坐标空间单位)长度的数字。 如果数组元素的数量是奇数, 数组的元素会被复制并重复。例如, [5, 15, 25] 会变成 [5, 15, 25, 5, 15, 25]。
+ */
+ setLineDash(segments: number[]): void;
+
+ /**
+ * 使用矩阵多次叠加当前变换的方法,矩阵由方法的参数进行描述。你可以缩放、旋转、移动和倾斜上下文。
+ *
+ * @param scaleX 水平缩放
+ * @param skewX 水平倾斜
+ * @param skewY 垂直倾斜
+ * @param scaleY 垂直缩放
+ * @param translateX 水平移动
+ * @param translateY 垂直移动
+ */
+ transform(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number): void;
+
+ /**
+ * 使用单位矩阵重新设置(覆盖)当前的变换并调用变换的方法,此变换由方法的变量进行描述。
+ *
+ * @param scaleX 水平缩放
+ * @param skewX 水平倾斜
+ * @param skewY 垂直倾斜
+ * @param scaleY 垂直缩放
+ * @param translateX 水平移动
+ * @param translateY 垂直移动
+ */
+ setTransform(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number): void;
+
+ /**
+ * 保存当前的绘图上下文。
+ *
+ */
+ save(): void;
+
+ /**
+ * 恢复之前保存的绘图上下文。
+ */
+ restore(): void;
+
+ /**
+ * 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中。
+ * 绘图上下文需要由 my.createCanvasContext(canvasId) 来创建。
+ * @param [reserve] 本次绘制是否接着上一次绘制,即 reserve 参数为 false 时则在本次调用 drawCanvas绘制之前 native 层应先清空画布再继续绘制;若 reserver 参数为true 时,则保留当前画布上的内容,本次调用drawCanvas绘制的内容覆盖在上面,默认 false
+ */
+ draw(reserve?: boolean): void;
+
+ measureText(text: string): TextMetrics;
+ }
+ /**
+ * 创建 canvas 绘图上下文
+ *
+ * 该绘图上下文只作用于对应 canvasId 的
+ */
+ function createCanvasContext(canvasId: string): ConvasContext;
+ //#endregion
+
+ //#region 地图 https://docs.alipay.com/mini/api/ui-map
+ interface GetCenterLocationOptions extends BaseOptions {
+ success?(res: { longitude: string; latitude: string; }): void;
+ }
+
+ interface MapContext extends BaseOptions {
+ /**
+ * 获取当前地图中心的经纬度,返回 gcj02 坐标系的值,可以用于 my.openLocation
+ *
+ * @param options
+ */
+ getCenterLocation(options: GetCenterLocationOptions): void;
+ /**
+ * 将地图中心移动到当前定位点,需要配合 map 组件的 show-location 使用
+ */
+ moveToLocation(): void;
+ }
+
+ /**
+ * 创建并返回一个 map 上下文对象 mapContext。
+ *
+ * @param mapId
+ * @returns
+ */
+ function createMapContext(mapId: string): MapContext;
+
+ //#endregion
+
+ //#region 键盘 https://docs.alipay.com/mini/api/ui-hidekeyboard
+ /**
+ * 隐藏键盘
+ *
+ */
+ function hideKeyboard(): void;
+ //#endregion
+
+ //#region 滚动 https://docs.alipay.com/mini/api/scroll
+ interface PageScrollToOptions {
+ scrollTop: number; // 滚动到页面的目标位置,单位 px
+ }
+
+ /**
+ * 滚动到页面的目标位置
+ *
+ * @param options
+ */
+ function pageScrollTo(options: PageScrollToOptions): void;
+ //#endregion
+
+ //#region 节点查询 https://docs.alipay.com/mini/api/selector-query
+ interface RectArea {
+ /** 节点的左边界坐标 */
+ left: number;
+ /** 节点的右边界坐标 */
+ right: number;
+ /** 节点的上边界坐标 */
+ top: number;
+ /** 节点的下边界坐标 */
+ bottom: number;
+ /** 节点的宽度 */
+ width: number;
+ /** 节点的高度 */
+ height: number;
+ }
+ interface NodesRefRect extends RectArea {
+ /** 节点的ID */
+ id: string;
+ /** 节点的dataset */
+ dataset: any;
+ }
+ interface NodeRefOffset {
+ /** 节点的ID */
+ id: string;
+ /** 节点的dataset */
+ dataset: any;
+ /** 节点的水平滚动位置 */
+ scrollLeft: number;
+ /** 节点的竖直滚动位置 */
+ scrollTop: number;
+ }
+ interface NodesRef {
+ /**
+ * 添加节点的布局位置的查询请求,相对于显示区域,以像素为单位。
+ * 其功能类似于DOM的getBoundingClientRect。
+ * 返回值是nodesRef对应的selectorQuery。
+ * 返回的节点信息中,每个节点的位置用
+ * left、right、top、bottom、width、height字段描述。
+ * 如果提供了callback回调函数,在执行selectQuery的exec方法后
+ * 节点信息会在callback中返回。
+ */
+ boundingClientRect(
+ callback?: (rect: T) => void
+ ): SelectorQuery;
+ /**
+ * 添加节点的滚动位置查询请求,以像素为单位。
+ * 节点必须是scroll-view或者viewport。
+ * 返回值是nodesRef对应的selectorQuery。
+ * 返回的节点信息中,每个节点的滚动位置用scrollLeft、scrollHeight字段描述。
+ * 如果提供了callback回调函数,在执行selectQuery的exec方法后,节点信息会在callback中返回。
+ */
+ scrollOffset(callback?: (rect: NodeRefOffset) => void): SelectorQuery;
+ // /**
+ // * 获取节点的相关信息,需要获取的字段在fields中指定。
+ // * 返回值是nodesRef对应的selectorQuery。
+ // */
+ // fields(
+ // fields: NodeRefFieldsOptions,
+ // callback?: (result: any) => void
+ // ): SelectorQuery;
+ }
+ /**
+ * SelectorQuery对象实例
+ */
+ interface SelectorQuery {
+ // /**
+ // * 将选择器的选取范围更改为自定义组件component内
+ // * (初始时,选择器仅选取页面范围的节点,不会选取任何自定义组件中的节点
+ // * @version 1.6.0
+ // */
+ // in(component: Component