# Others

This section generally covers common methods.

# 1. Generate Token

/**
 * Generates a token using the original text.
 * @param text The original text.
 */
generateTokenWithOriginText(text: string): string;

Example Code:

const text = 'originText'
const token = client.generateTokenWithOriginText(text)

# 2. Decrypt Token

/**
 * Gets the original text using the generated token.
 * @param token The token.
 */
originTextWithToken(token: string): string

Example Code:

const text = client.originTextWithToken(token)

# 3. Update User Data

/**
 * Updates user information data.
 * @param type - The type of user information data to update. Can modify User ID, Phone Number, or Member Identifier.
 * @param value - The user data to set.
 * @returns Returns `true` on success when updating `userId` or `phone`; no return value when updating `memberUserId`.
 */
updateUserInfo(type: 'userId' | 'phone' | 'memberUserId', value: string): boolean | void

Example Code:

client.updateUserInfo('userId','newUserId') 
client.updateUserInfo('phone','130xxxxxxxx')
client.updateUserInfo('memberUserId', 'memberUserId')

# 4. Host-App Logs Input to Mini-Program's vConsole

/**
 * Host-App writes logs to vConsole.
 * @param appId - The ID of the Mini-Program.
 * @param msg - The data to be written.
 * @param consoleLevel  - The log level.
 * @param apiServer - The API server associated with the Mini-Program.
 * @param appRunId - The Mini-Program run ID.
 * @returns A result containing the log addition result or an error.
 */
public addConsoleLog(appId: string, msg: string, consoleLevel: 'log' | 'warn' | 'error' | 'info', apiServer?: string, appRunId?: string): IFinApplet.IFinAppResult<boolean>

Example Code:

client.addConsoleLog('appId','this is from arkTs', 'log') 

# 5. Handling Events in the More Panel

When customizing the More Mini-Program panel, although the UI is self-designed, some functionalities can still reuse those from the SDK, such as the About page, Settings page, Complaint Feedback, Forward/Share, etc. You can call the APIs under MoreMenuHelper within the button's click event to implement navigation and corresponding logic.

To use MoreMenuHelper, you need to obtain it first.

const moreMenuHelper = FinAppClient.getInstance()?.getMoreMenuHelper(appId, apiServer)

# 5.1 Navigate to the About Mini-Program Page

 /**
   * Opens the About page of the Mini-Program.
   */
  public goToAboutPage():void

Example Code:

moreMenuHelper?.goToAboutPage()

# 5.2 Trigger Forward/Share Event

  /**
   * Triggers the forward event to obtain Mini-Program information used for forwarding. After obtaining the Mini-Program info, it triggers FinAppProxyHandlerManager.buttonOpenTypeHandler.forwardAppletWithInfo.
   * @returns
   */
  public invokeForwardMenuAction():void

Example Code:

moreMenuHelper?.invokeForwardMenuAction()

# 5.3 Navigate to the Complaint Feedback Page

/**
   * Opens the Feedback page of the Mini-Program.
   */
  public goToFeedbackPage():void

Example Code:

moreMenuHelper?.goToFeedbackPage()

# 5.4 Navigate to the Settings Page

  /**
   * Opens the Settings page of the Mini-Program.
   * @param onPop Callback triggered when the Settings page is closed.
   */
  public goToSettingPage(onPop?: () => void):void

Example Code:

moreMenuHelper?.goToSettingPage()

# 5.5 Get the Mini-Program's Debug Mode

 get isEnableAppletDebug(): boolean

Example Code:

const isDebug = moreMenuHelper?.isEnableAppletDebug

# 5.6 Set the Mini-Program's Debug Mode

 /**
   * Enables/disables the debug mode of the Mini-Program.
   * @param enableDebug
   * @returns
   */
  public setEnableAppletDebug(enableDebug: boolean): boolean

Example Code:

moreMenuHelper?.setEnableAppletDebug(true)

# 5.7 Check if the Mini-Program Implements Custom Menu Functionality

Since some custom menus require data returned by the Mini-Program, similar to the implementation of onShareAppMessage, you can call the following method to check if the current page of the Mini-Program implements the on{menuId}ButtonHandler method.

interface ICustomMiniProgramMenuRes {
  eventName: string
  menuId: string
  value: boolean
}

 /**
   * Checks if the Mini-Program implements custom menu functionality.
   * @param menuIds Array of custom icon IDs.
   * @returns Detection result, type is {"eventName": ##Mini-Program Event Name##,"menuId": ##Icon ID##, "value": ##Whether the event is implemented##}
   */
  public checkMenus(menuIds: string[]): Promise<ICustomMiniProgramMenuRes[]>

Example Code:

const menuIds = ['WXShareAPPFriends', 'WXShareAPPMoments', 'customMenu']
const result = await moreMenuHelper?.checkMenus(menuIds)

# 5.8 Trigger Custom Menu Functionality

For custom menu items that require data returned by the Mini-Program, you can call this method to obtain the Mini-Program information returned by the corresponding page's on{menuId}ButtonHandler method.

/**
   * Triggers a custom menu item (menu items that require cooperation from the Mini-Program, needing additional call parameters from the Mini-Program). After obtaining the information returned by the Mini-Program, it triggers FinAppProxyHandlerManager.moreMenuHandler.onCustomMenuItemClickWithInfo.
   * @param menuId Custom icon ID.
   */
  public invokeMiniProgramTypeMenuAction(menuId: string)

Example Code:

moreMenuHelper?.invokeMiniProgramTypeMenuAction('customMenu')

# 6. Opening a Native Page from the Mini-Program Page Stack

In certain scenarios, you may need to open a native page within the Mini-Program page stack. You can use the following method. After calling it, the Mini-Program page stack state will be: [Mini-Program Page A, Native Page A]

/**
   * Pushes a native page onto the current Mini-Program page stack.
   * @param appId - The ID of the Mini-Program.
   * @param pageName - The route name of the page.
   * @param extParam - Additional parameters to pass to the native page.
   * @param animate - Whether to enable animation for the navigation.
   * @param apiServer - The API server associated with the Mini-Program.
   * @param appRunId - The Mini-Program run ID.
   * @returns A result containing the API call result or an error, does not include the navigation result.
   */
  async pushNativePage(pageName: string, appId: string, extParam?: object, animate?: boolean, apiServer?: string, appRunId: string = ''): Promise<IFinApplet.IFinAppResult<boolean>>

Example Code:

FinAppClient.getInstance()?.pushNativePage('nativePageName', appId)

TIP

Here, nativePageName is the route name of the native page, which needs to be configured in route_map.json. Internal navigation within the Mini-Program uses Navigation instead of Router, please pay special attention.

Due to system specifications, passing an incorrect nativePageName will directly cause the Mini-Program to navigate to a blank page. Please pay special attention.

If you want to navigate to a Mini-Program page from the page opened by pushNativePage, you can use the following method. After calling it, the Mini-Program page stack state will be: [Mini-Program Page A, Native Page A, Mini-Program Page B]

/**
   * Opens a specific page of the specified Mini-Program.
   * @param appId - The ID of the Mini-Program.
   * @param pagePath - The page path of the Mini-Program.
   * @param query  - The query parameters for the Mini-Program page.
   * @param apiServer - The API server associated with the Mini-Program.
   * @param appRunId - The Mini-Program run ID.
   * @returns A result containing the navigation result or an error.
   */
  async pushAppletPage(pagePath: string, appId: string, query?: string, apiServer?: string,    appRunId: string = ''): Promise<IFinApplet.IFinAppResult<boolean>>

Example Code:

// The Mini-Program page path here must be a registered page path in the Mini-Program, otherwise a corresponding error message will be returned.
const res = FinAppClient.getInstance()?.pushAppletPage('/pages/logs/logs', appId,'foo=bar')
if (res?.errMsg) {
  promptMsg(`pushAppletPage fail:${res.errMsg}`)
}

# 7. Get the Current Active Mini-Program Page

/**
 * Gets the current active Mini-Program page.
 * @returns The Mini-Program page or an empty string if not found.
 */
getCurrentAppletPath(): string;

Example Code:

const currentPath = client.getCurrentAppletPath()

# 8. Temporarily Control the Display/Hide of the Capsule Button on the Current Page (This Setting is Invalidated Upon Exiting the Current Page)

 /**
 * Modifies the visibility of the capsule button.
 * @param type - The type of capsule button to modify, currently supports 'more' | 'close'.
 * @param hidden - Whether to hide.
 * @param appId - The ID of the Mini-Program.
 * @param apiServer - The API server associated with the Mini-Program.
 * @param appRunId - The Mini-Program run ID.
 * @returns A result containing the API call result or an error, does not include the modification result.
 */
public async handlerCapsuleBtn(type: ICapsule.CapsuleType, hidden: boolean, appId: string, apiServer?: string, appRunId: string = ''): Promise<IFinApplet.IFinAppResult<boolean>> 

Example Code:

client.handlerCapsuleBtn('more', true, 'appId')
client.handlerCapsuleBtn('close', true, 'appId')
© FinClip with ❤ , Since 2017