Mazey's Taro utils.
Use mazey-taro-utils via npm.
npm install mazey-taro-utils --save
Of course, you can also download this file and serve it yourself. The file locates at the lib/mazey-taro-utils.min.js
.
import { getLoginCodeAsync } from "mazey-taro-utils";
getLoginCodeAsync()
.then((code) => {
console.log(`Login code: ${code}`);
})
.catch((error) => {
console.error(error);
});
Displays a toast message.
Parameters:
msg
(string): The message to display in the toast.
Example Usage:
quickToast('Hello, world!');
Navigates to a specified page.
Parameters:
page
(string): The page to navigate to. This should be the name of the directory under/pages
without the/index
part.params
(object, optional): Query parameters to include in the URL.
Example Usage:
quickNavigateTo('home', { params: { userId: 123 } });
Redirects to a specified page, without keeping the current page in the navigation history.
Parameters:
page
(string): The page to redirect to. This should be the name of the directory under/pages
without the/index
part.params
(object, optional): Query parameters to include in the URL.
Example Usage:
quickRedirectTo('home', { params: { userId: 123 } });
Quickly scrolls to a specified element on the page.
Parameters:
selector
(string): The selector of the element to scroll to.duration
(number, optional): The duration of the scroll animation in milliseconds. Default is 300ms.
Example Usage:
quickScrollTo('#elementId', 500);
Gets the current environment the application is running in.
Returns: string
- The name of the current environment (e.g.,
'h5'
,'weapp'
, etc.).
Example Usage:
console.log(`Current environment: ${getEnv()}`);
Gets the path of the current page.
Returns: string
Example Usage:
console.log(`Current page path: ${getCurrentPage()}`);
Gets all parameters of the current page.
Returns: object
Example Usage:
console.log(`Current page params: ${JSON.stringify(getAllParams())}`);
Gets the value of a query parameter from the current path.
Parameters:
name
(string): The name of the query parameter.
Returns: string
Example Usage:
const userId = getQueryParam('userId');
console.log(`User ID: ${userId}`);
Gets the size of the current window.
Returns: object
width
(number): The width of the window.height
(number): The height of the window.ratio
(number): The width-to-height ratio.hwRatio
(number): The height-to-width ratio.
Example Usage:
const { width, height, ratio, hwRatio } = getWindowSize();
console.log(`Window size - Width: ${width}, Height: ${height}, Ratio: ${ratio}, HW Ratio: ${hwRatio}`);
Gets the current system information, such as "iOS 14.4".
Returns: string
Example Usage:
const systemInfo = getSystem();
console.log(`System Info: ${systemInfo}`);
Calls the interface to get the login credential (code).
Returns: Promise<string>
Example Usage:
getLoginCodeAsync().then(code => {
console.log(`Login code: ${code}`);
}).catch(err => {
console.error(`Failed to get login code: ${err}`);
});
Checks if the current environment is a WeChat Mini Program.
Returns: boolean
Example Usage:
if (isMiniProgram()) {
console.log('Running in a WeChat Mini Program');
}
Determines if the current environment is a web environment (H5).
Returns: boolean
true
if the current environment is H5.false
otherwise.
Example Usage:
if (isH5()) {
console.log('Running in a web environment');
}
Checks if the device has a wide screen.
Returns: boolean
Example Usage:
if (isWideScreen()) {
console.log('Device has a wide screen');
}
Checks if the system is iOS.
Returns: boolean
Example Usage:
if (isIOS()) {
console.log('Running on iOS');
}
Checks if the system is Android.
Returns: boolean
Example Usage:
if (isAndroid()) {
console.log('Running on Android');
}
Node.js Version: 16.x
Install Dependencies:
npm i
Development:
npm run dev
Build:
npm run build
Document:
npm run docs
Test:
npm run test
This software is released under the terms of the MIT license.