Direct integration with Toutiao platform services and ByteDance-specific functionality, providing access to native Toutiao APIs and platform-specific features.
Direct access to Toutiao's native platform APIs through the global tt object.
/**
* Toutiao platform global object providing native API access
*/
declare const tt: ToutiaoGlobal;
interface ToutiaoGlobal {
/** Create Toutiao mini-program app */
createApp: (options: any) => any;
/** Create Toutiao mini-program page */
createPage: (options: any) => any;
/** Create Toutiao mini-program component */
createComponent: (options: any) => any;
/** Create subpackage app */
createSubpackageApp: (options: any) => any;
/** Event communication channel */
EventChannel: typeof EventChannel;
/** System information (synchronous) */
getSystemInfoSync: () => SystemInfo;
/** Payment functionality */
pay?: (options: PaymentOptions) => void;
/** Alternative payment method */
requestPayment?: (options: PaymentOptions) => void;
/** User login */
login: (options: LoginOptions) => void;
/** Get user information */
getUserInfo: (options: UserInfoOptions) => void;
/** Show toast notification */
showToast: (options: ToastOptions) => void;
/** Show loading indicator */
showLoading: (options: LoadingOptions) => void;
/** Hide loading indicator */
hideLoading: () => void;
/** Navigate to page */
navigateTo: (options: NavigateOptions) => void;
/** Redirect to page */
redirectTo: (options: NavigateOptions) => void;
/** Additional Toutiao-specific APIs */
[key: string]: any;
}Platform-specific utility functions for accessing system information and platform services.
/**
* Get base system information directly via tt.getSystemInfoSync()
* @returns Base system information from Toutiao platform
*/
function getBaseSystemInfo(): any;Usage Example:
import { getBaseSystemInfo } from "@dcloudio/uni-mp-toutiao/platform";
// Get base system information
const systemInfo = getBaseSystemInfo();
console.log('Platform:', systemInfo.platform);
console.log('System:', systemInfo.system);
console.log('Version:', systemInfo.version);Global event communication system for inter-component messaging.
/**
* Event communication channel for cross-component messaging
*/
class EventChannel {
/**
* Emit an event to all registered listeners
* @param eventName - Name of the event to emit
* @param args - Arguments to pass to event listeners
*/
emit(eventName: string, ...args: any[]): void;
/**
* Register an event listener
* @param eventName - Name of the event to listen for
* @param callback - Function to call when event is emitted
*/
on(eventName: string, callback: (...args: any[]) => void): void;
/**
* Remove an event listener
* @param eventName - Name of the event
* @param callback - Specific callback to remove (optional)
*/
off(eventName: string, callback?: (...args: any[]) => void): void;
/**
* Register a one-time event listener
* @param eventName - Name of the event to listen for
* @param callback - Function to call once when event is emitted
*/
once(eventName: string, callback: (...args: any[]) => void): void;
}Usage Example:
// Access global EventChannel
const eventChannel = tt.EventChannel;
// Set up communication between components
eventChannel.on('dataUpdate', (data) => {
console.log('Data updated:', data);
});
// Emit events from other components
eventChannel.emit('dataUpdate', { user: 'Alice', status: 'online' });
// One-time listeners
eventChannel.once('appReady', () => {
console.log('App is ready!');
});Access to Toutiao's native UI components and interactions.
interface NativeUIServices {
/** Show toast notification */
showToast: (options: ToastOptions) => void;
/** Show modal dialog */
showModal: (options: ModalOptions) => void;
/** Show loading indicator */
showLoading: (options: LoadingOptions) => void;
/** Hide loading indicator */
hideLoading: () => void;
/** Show action sheet */
showActionSheet: (options: ActionSheetOptions) => void;
}
interface ToastOptions {
title: string;
icon?: 'success' | 'loading' | 'none';
duration?: number;
mask?: boolean;
success?: () => void;
fail?: (error: any) => void;
}
interface ModalOptions {
title?: string;
content: string;
showCancel?: boolean;
cancelText?: string;
confirmText?: string;
success?: (result: ModalResult) => void;
fail?: (error: any) => void;
}
interface ModalResult {
confirm: boolean;
cancel: boolean;
}
interface LoadingOptions {
title: string;
mask?: boolean;
success?: () => void;
fail?: (error: any) => void;
}
interface ActionSheetOptions {
itemList: string[];
success?: (result: ActionSheetResult) => void;
fail?: (error: any) => void;
}
interface ActionSheetResult {
tapIndex: number;
}Usage Example:
// Show success toast
tt.showToast({
title: 'Operation successful',
icon: 'success',
duration: 2000
});
// Show modal dialog
tt.showModal({
title: 'Confirmation',
content: 'Are you sure you want to delete this item?',
success(result) {
if (result.confirm) {
console.log('User confirmed');
}
}
});
// Show loading indicator
tt.showLoading({
title: 'Loading...',
mask: true
});
// Hide loading after operation
setTimeout(() => {
tt.hideLoading();
}, 2000);Access to ByteDance ecosystem-specific functionality.
interface ByteDanceServices {
/** Aweme (TikTok) data integration */
awemeData: {
getUserCard: (options: UserCardOptions) => void;
getLivePreview: (options: LivePreviewOptions) => void;
getVideoData: (options: VideoDataOptions) => void;
};
/** E-commerce integration */
ecommerce: {
createPayButton: (options: PayButtonOptions) => void;
createRateButton: (options: RateButtonOptions) => void;
showProductCard: (options: ProductCardOptions) => void;
};
}
interface UserCardOptions {
userId: string;
success?: (data: UserCardData) => void;
fail?: (error: any) => void;
}
interface UserCardData {
nickname: string;
avatar: string;
followStatus: boolean;
}
interface LivePreviewOptions {
streamId: string;
autoPlay?: boolean;
success?: () => void;
fail?: (error: any) => void;
}
interface PayButtonOptions {
productId: string;
amount: number;
title: string;
success?: (result: PaymentResult) => void;
fail?: (error: any) => void;
}
interface PaymentResult {
orderId: string;
status: 'success' | 'fail' | 'cancel';
}Utilities for detecting and adapting to the Toutiao platform environment.
interface PlatformDetection {
/** Platform identifier */
readonly platform: 'mp-toutiao';
/** Global object name */
readonly globalName: 'tt';
/** Platform title */
readonly platformTitle: '字节跳动小程序';
/** Base library version checking */
checkBaseLibVersion: (requiredVersion: string) => boolean;
/** Feature availability checking */
checkFeature: (featureName: string) => boolean;
}
declare const __PLATFORM__: 'mp-toutiao';
declare const __GLOBAL__: 'tt';Usage Example:
// Platform-specific code
if (__PLATFORM__ === 'mp-toutiao') {
// Use Toutiao-specific features
tt.showToast({ title: 'Running on Toutiao!' });
}
// Feature detection
if (tt.pay) {
// Use native payment API
tt.pay(paymentOptions);
} else {
// Fall back to alternative payment method
tt.requestPayment(paymentOptions);
}Local storage APIs adapted for Toutiao platform.
interface StorageServices {
/** Set storage data */
setStorage: (options: SetStorageOptions) => void;
/** Set storage data synchronously */
setStorageSync: (key: string, data: any) => void;
/** Get storage data */
getStorage: (options: GetStorageOptions) => void;
/** Get storage data synchronously */
getStorageSync: (key: string) => any;
/** Remove storage data */
removeStorage: (options: RemoveStorageOptions) => void;
/** Remove storage data synchronously */
removeStorageSync: (key: string) => void;
/** Clear all storage data */
clearStorage: () => void;
/** Get storage info */
getStorageInfo: (options: StorageInfoOptions) => void;
}
interface SetStorageOptions {
key: string;
data: any;
success?: () => void;
fail?: (error: any) => void;
}
interface GetStorageOptions {
key: string;
success?: (result: { data: any }) => void;
fail?: (error: any) => void;
}
interface RemoveStorageOptions {
key: string;
success?: () => void;
fail?: (error: any) => void;
}
interface StorageInfoOptions {
success?: (result: StorageInfo) => void;
fail?: (error: any) => void;
}
interface StorageInfo {
keys: string[];
currentSize: number;
limitSize: number;
}Network request APIs with Toutiao platform optimizations.
interface NetworkServices {
/** Make HTTP request */
request: (options: RequestOptions) => RequestTask;
/** Upload file */
uploadFile: (options: UploadOptions) => UploadTask;
/** Download file */
downloadFile: (options: DownloadOptions) => DownloadTask;
}
interface RequestOptions {
url: string;
data?: any;
header?: Record<string, string>;
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
timeout?: number;
success?: (result: RequestResult) => void;
fail?: (error: any) => void;
}
interface RequestResult {
data: any;
statusCode: number;
header: Record<string, string>;
}
interface RequestTask {
abort: () => void;
}Usage Example:
// Make API request
const task = tt.request({
url: 'https://api.example.com/data',
method: 'GET',
success(result) {
console.log('Data received:', result.data);
},
fail(error) {
console.error('Request failed:', error);
}
});
// Abort request if needed
// task.abort();// Direct access to Toutiao APIs
tt.showToast({ title: 'Hello Toutiao!' });
tt.getSystemInfoSync();
// Event communication
const eventChannel = new tt.EventChannel();
eventChannel.emit('customEvent', data);// Conditional platform code
if (__PLATFORM__ === 'mp-toutiao') {
// Toutiao-specific implementation
tt.specificToutiaoFeature();
} else {
// Other platform implementations
}// Feature availability checking
if (typeof tt.newFeature === 'function') {
tt.newFeature();
} else {
// Fallback implementation
alternativeImplementation();
}