From d9bc3d075e224cf349975fcde45ba67a263bd652 Mon Sep 17 00:00:00 2001 From: guoenxuan Date: Fri, 8 Sep 2023 10:49:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=9E=E7=8E=B0=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E3=80=81=E8=8E=B7=E5=8F=96=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=8F=82=E6=95=B0=E3=80=81=E8=8F=9C=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E7=BD=AEAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/mini-program-example/src/app.ts | 4 +-- .../basics/miniProgram/lifeCycle/index.tsx | 15 +++++++-- .../src/pages/api/interface/menu/index.tsx | 9 +++-- .../api/interface/navigationBar/index.tsx | 2 +- .../src/pages/api/redirection/index.tsx | 22 ++++++++++++- .../src/api/base/weapp/life-cycle.ts | 33 +++++++++++++++---- .../taro-mpharmony/src/api/navigate/index.ts | 28 ++++++++++++++-- packages/taro-mpharmony/src/api/ui/menu.ts | 16 +++++++-- 8 files changed, 109 insertions(+), 20 deletions(-) diff --git a/examples/mini-program-example/src/app.ts b/examples/mini-program-example/src/app.ts index e1c947ba2658..2e4c660e02aa 100644 --- a/examples/mini-program-example/src/app.ts +++ b/examples/mini-program-example/src/app.ts @@ -4,8 +4,8 @@ import { TestConsole } from '@/util/util' import './app.scss' class App extends React.Component { - onLaunch() { - TestConsole.consoleNormal('onLaunch') + onLaunch(res) { + TestConsole.consoleNormal('onLaunch', res) } onError(error) { diff --git a/examples/mini-program-example/src/pages/api/basics/miniProgram/lifeCycle/index.tsx b/examples/mini-program-example/src/pages/api/basics/miniProgram/lifeCycle/index.tsx index 91e553770ea0..f0dee997e8f5 100644 --- a/examples/mini-program-example/src/pages/api/basics/miniProgram/lifeCycle/index.tsx +++ b/examples/mini-program-example/src/pages/api/basics/miniProgram/lifeCycle/index.tsx @@ -1,6 +1,7 @@ import React from 'react' import Taro from '@tarojs/taro' -import { View, Text } from '@tarojs/components' +import { View } from '@tarojs/components' +import { TestConsole } from '@/util/util' import ButtonList from '@/components/buttonList' /** @@ -13,11 +14,19 @@ export default class Index extends React.Component { list: [ { id: 'getLaunchOptionsSync', - func: null, + func: () => { + TestConsole.consoleTest('Taro.getLaunchOptionsSync') + const options = Taro.getLaunchOptionsSync() + TestConsole.consoleNormal('getLaunchOptionsSync', options) + }, }, { id: 'getEnterOptionsSync', - func: null, + func: () => { + TestConsole.consoleTest('Taro.getEnterOptionsSync') + const options = Taro.getEnterOptionsSync() + TestConsole.consoleNormal('getEnterOptionsSync', options) + }, }, ], } diff --git a/examples/mini-program-example/src/pages/api/interface/menu/index.tsx b/examples/mini-program-example/src/pages/api/interface/menu/index.tsx index f340e491627a..4261db8802d4 100644 --- a/examples/mini-program-example/src/pages/api/interface/menu/index.tsx +++ b/examples/mini-program-example/src/pages/api/interface/menu/index.tsx @@ -1,6 +1,7 @@ import React from 'react' import Taro from '@tarojs/taro' -import { View, Text } from '@tarojs/components' +import { View } from '@tarojs/components' +import { TestConsole } from '@/util/util' import ButtonList from '@/components/buttonList' import './index.scss' @@ -14,7 +15,11 @@ export default class Index extends React.Component { list: [ { id: 'getMenuButtonBoundingClientRect', - func: null, + func: () => { + TestConsole.consoleTest('Taro.getMenuButtonBoundingClientRect') + const rect = Taro.getMenuButtonBoundingClientRect() + TestConsole.consoleNormal('getMenuButtonBoundingClientRect', rect) + }, }, ], } diff --git a/examples/mini-program-example/src/pages/api/interface/navigationBar/index.tsx b/examples/mini-program-example/src/pages/api/interface/navigationBar/index.tsx index a80e4491a986..735c28d389b5 100644 --- a/examples/mini-program-example/src/pages/api/interface/navigationBar/index.tsx +++ b/examples/mini-program-example/src/pages/api/interface/navigationBar/index.tsx @@ -1,6 +1,6 @@ import React from 'react' import Taro from '@tarojs/taro' -import { View, Text } from '@tarojs/components' +import { View } from '@tarojs/components' import { TestConsole } from '@/util/util' import ButtonList from '@/components/buttonList' import './index.scss' diff --git a/examples/mini-program-example/src/pages/api/redirection/index.tsx b/examples/mini-program-example/src/pages/api/redirection/index.tsx index e4fb8379df94..e94a0724ac4e 100644 --- a/examples/mini-program-example/src/pages/api/redirection/index.tsx +++ b/examples/mini-program-example/src/pages/api/redirection/index.tsx @@ -1,6 +1,7 @@ import React from 'react' import Taro from '@tarojs/taro' import { View, Text } from '@tarojs/components' +import { TestConsole } from '@/util/util' import ButtonList from '@/components/buttonList' import './index.scss' @@ -22,7 +23,26 @@ export default class Index extends React.Component { }, { id: 'navigateToMiniProgram', - func: null, + inputData: { + appId: 'com.example.myapplication', + path: 'EntryAbility', + extraData: {}, + }, + func: (apiIndex, data) => { + TestConsole.consoleTest('Taro.navigateToMiniProgram') + Taro.navigateToMiniProgram({ + ...data, + success: (res) => { + TestConsole.consoleSuccess.call(this, res, apiIndex) + }, + fail: (res) => { + TestConsole.consoleFail.call(this, res, apiIndex) + }, + complete: (res) => { + TestConsole.consoleComplete.call(this, res, apiIndex) + }, + }) + }, }, { id: 'navigateBackMiniProgram', diff --git a/packages/taro-mpharmony/src/api/base/weapp/life-cycle.ts b/packages/taro-mpharmony/src/api/base/weapp/life-cycle.ts index b1b67f161092..a47850c0d581 100644 --- a/packages/taro-mpharmony/src/api/base/weapp/life-cycle.ts +++ b/packages/taro-mpharmony/src/api/base/weapp/life-cycle.ts @@ -1,15 +1,34 @@ import Taro from '@tarojs/api' -const launchOptions: Taro.getLaunchOptionsSync.LaunchOptions = { - path: '', - query: {}, - scene: 0, - shareTicket: '', - referrerInfo: {}, +function getReferrerInfo () { + let referrerInfo + try { + // @ts-ignore + const callerBundle = bundleMap.get('callerBundle') + // @ts-ignore + const callerParams = bundleMap.get('callerParams') + + referrerInfo = { + referrerInfo: { + appId: callerBundle || '', + extraData: JSON.parse(callerParams), + }, + } + } catch (err) { + referrerInfo = { + referrerInfo: { + appId: '', + extraData: {}, + }, + } + } + return referrerInfo } +let launchOptions function initLaunchOptions (options = {}) { - Object.assign(launchOptions, options) + Object.assign(options, getReferrerInfo()) + launchOptions = options } Taro.eventCenter.once('__taroRouterLaunch', initLaunchOptions) diff --git a/packages/taro-mpharmony/src/api/navigate/index.ts b/packages/taro-mpharmony/src/api/navigate/index.ts index d3db506899fd..e1703b4ca028 100644 --- a/packages/taro-mpharmony/src/api/navigate/index.ts +++ b/packages/taro-mpharmony/src/api/navigate/index.ts @@ -1,8 +1,32 @@ -import { temporarilyNotSupport } from '../../utils' +import Taro from '@tarojs/api' +import { MethodHandler } from 'src/utils/handler' + +import { shouldBeObject, temporarilyNotSupport } from '../../utils' // 跳转 export const openEmbeddedMiniProgram = /* @__PURE__ */ temporarilyNotSupport('openEmbeddedMiniProgram') -export const navigateToMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateToMiniProgram') export const navigateBackMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateBackMiniProgram') export const exitMiniProgram = /* @__PURE__ */ temporarilyNotSupport('exitMiniProgram') export const openBusinessView = /* @__PURE__ */ temporarilyNotSupport('openBusinessView') + +export const navigateToMiniProgram: typeof Taro.navigateToMiniProgram = (options) => { + const apiName = 'navigateToMiniProgram' + // options must be an Object + const isObject = shouldBeObject(options) + if (!isObject.flag) { + const res = { errMsg: `${apiName}:fail ${isObject.msg}` } + return Promise.reject(res) + } + const { success, fail, complete, ...otherOptions } = options as Exclude + const handle = new MethodHandler({ name: apiName, success, fail, complete }) + + // @ts-ignore + return native.navigateToMiniProgram(otherOptions).then( + (res: any) => { + handle.success(res) + }, + (res: any) => { + handle.fail(res) + } + ) +} diff --git a/packages/taro-mpharmony/src/api/ui/menu.ts b/packages/taro-mpharmony/src/api/ui/menu.ts index ae45717c06f8..78173c76c39f 100644 --- a/packages/taro-mpharmony/src/api/ui/menu.ts +++ b/packages/taro-mpharmony/src/api/ui/menu.ts @@ -1,4 +1,16 @@ -import { temporarilyNotSupport } from '../../utils' +import Taro from '@tarojs/api' // 菜单 -export const getMenuButtonBoundingClientRect = /* @__PURE__ */ temporarilyNotSupport('getMenuButtonBoundingClientRect') +export const getMenuButtonBoundingClientRect: typeof Taro.getMenuButtonBoundingClientRect = () => { + // @ts-ignore + const data = native.getMenuButtonBoundingClientRect() + const rect = JSON.parse(JSON.stringify(data)) + return { + left: rect.left, + top: rect.top, + right: rect.right, + bottom: rect.bottom, + height: rect.height, + width: rect.width, + } +}