Baidu Mini Program runtime and compiler support for the uni-app cross-platform development framework
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Device and system information APIs providing access to device capabilities, account information, and system configuration with Baidu Smart Program specific enhancements.
Get comprehensive system and device information.
/**
* Get system information asynchronously
* @param options - Success, fail, and complete callbacks
* @returns Promise that resolves with system information
*/
function getSystemInfo(options?: SystemInfoOptions): Promise<SystemInfo>;
/**
* Get system information synchronously
* @returns System information object
*/
function getSystemInfoSync(): SystemInfo;
interface SystemInfoOptions {
success?(result: SystemInfo): void;
fail?(error: any): void;
complete?(): void;
}
interface SystemInfo {
brand: string; // Device brand
model: string; // Device model
pixelRatio: number; // Device pixel ratio
screenWidth: number; // Screen width in pixels
screenHeight: number; // Screen height in pixels
windowWidth: number; // Window width in pixels
windowHeight: number; // Window height in pixels
statusBarHeight: number; // Status bar height in pixels
language: string; // System language
version: string; // System version
system: string; // Operating system with version
platform: string; // Platform (ios/android)
fontSizeSetting: number; // Font size setting
SDKVersion: string; // SDK version
safeArea: SafeArea; // Safe area coordinates
safeAreaInsets: SafeAreaInsets; // Safe area insets
[key: string]: any; // Additional platform-specific properties
}
interface SafeArea {
left: number;
right: number;
top: number;
bottom: number;
width: number;
height: number;
}
interface SafeAreaInsets {
top: number;
left: number;
right: number;
bottom: number;
}Usage Examples:
import uni from "@dcloudio/uni-mp-baidu";
// Async version with promise
uni.getSystemInfo().then((systemInfo) => {
console.log('Device brand:', systemInfo.brand);
console.log('Screen size:', systemInfo.screenWidth, 'x', systemInfo.screenHeight);
console.log('Safe area:', systemInfo.safeArea);
});
// Async version with callback
uni.getSystemInfo({
success: (res) => {
console.log('System info:', res);
console.log('Platform:', res.platform);
console.log('System version:', res.system);
},
fail: (err) => {
console.error('Failed to get system info:', err);
}
});
// Synchronous version
try {
const systemInfo = uni.getSystemInfoSync();
console.log('Device model:', systemInfo.model);
console.log('Window size:', systemInfo.windowWidth, 'x', systemInfo.windowHeight);
console.log('Status bar height:', systemInfo.statusBarHeight);
} catch (error) {
console.error('Error getting system info:', error);
}Get current mini program account information.
/**
* Get account information synchronously
* @returns Account information including mini program and plugin details
*/
function getAccountInfoSync(): AccountInfo;
interface AccountInfo {
miniProgram: {
appId: string; // Mini program app ID
};
plugin?: {
appId: string; // Plugin app ID (if running as plugin)
version: string; // Plugin version
};
}Usage Examples:
// Get account information
const accountInfo = uni.getAccountInfoSync();
console.log('Mini program app ID:', accountInfo.miniProgram.appId);
if (accountInfo.plugin) {
console.log('Running as plugin:', accountInfo.plugin.appId);
console.log('Plugin version:', accountInfo.plugin.version);
}The system APIs in uni-mp-baidu include several enhancements specific to the Baidu Smart Program platform:
systemInfo.deviceIdgetAccountInfoSync() is mapped to Baidu's swan.getEnvInfoSync()The SystemInfo object includes standard cross-platform properties plus Baidu-specific enhancements:
brand, model: Device manufacturer and modelpixelRatio: Device pixel density ratioscreenWidth, screenHeight: Physical screen dimensionswindowWidth, windowHeight: Available window dimensionsstatusBarHeight: System status bar heightlanguage: System language settingversion, system: OS version informationplatform: Operating system (ios/android)deviceId: Generated unique device identifiersafeArea: Calculated safe area boundariessafeAreaInsets: Safe area margin values// Handle potential errors in system API calls
try {
const systemInfo = uni.getSystemInfoSync();
// Process system info
} catch (error) {
console.error('System API error:', error);
// Fallback handling
}
// Async error handling
uni.getSystemInfo({
success: (res) => {
// Success handling
},
fail: (err) => {
console.error('Failed to get system info:', err);
// Error handling
},
complete: () => {
// Always executed
}
});Install with Tessl CLI
npx tessl i tessl/npm-dcloudio--uni-mp-baidu