From f56b832a9eeafee926badb381bf6006013b4f548 Mon Sep 17 00:00:00 2001 From: Zakary Date: Mon, 17 Oct 2022 20:08:11 +0800 Subject: [PATCH] fix(events): add method & component not support events --- .../src/components/ad-custom/ad-custom.tsx | 9 +- .../taro-components/src/components/ad/ad.tsx | 9 +- .../src/components/camera/camera.tsx | 9 +- .../src/components/editor/editor.tsx | 9 +- .../functional-page-navigator.tsx | 9 +- .../keyboard-accessory/keyboard-accessory.tsx | 9 +- .../components/live-player/live-player.tsx | 9 +- .../components/live-pusher/live-pusher.tsx | 9 +- .../src/components/map/map.tsx | 9 +- .../components/match-media/match-media.tsx | 9 +- .../navigation-bar/navigation-bar.tsx | 9 +- .../official-account/official-account.tsx | 9 +- .../src/components/open-data/open-data.tsx | 9 +- .../page-container/page-container.tsx | 9 +- .../src/components/page-meta/page-meta.tsx | 9 +- .../components/root-portal/root-portal.tsx | 9 +- .../share-element/share-element.tsx | 9 +- .../src/components/slot/slot.tsx | 9 +- .../src/components/voip-room/voip-room.tsx | 9 +- packages/taro-components/src/utils/helper.ts | 12 +++ packages/taro-components/src/utils/index.ts | 1 + packages/taro-h5/src/utils/index.ts | 86 +++++++++++-------- 22 files changed, 158 insertions(+), 112 deletions(-) create mode 100644 packages/taro-components/src/utils/helper.ts diff --git a/packages/taro-components/src/components/ad-custom/ad-custom.tsx b/packages/taro-components/src/components/ad-custom/ad-custom.tsx index a2e7dbae563a..000d4a90fdc7 100644 --- a/packages/taro-components/src/components/ad-custom/ad-custom.tsx +++ b/packages/taro-components/src/components/ad-custom/ad-custom.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-ad-custom-core' }) -export class AdCustom { +export class AdCustom implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 AdCustom 组件!') + notSupport('AdCustom', this) } render () { diff --git a/packages/taro-components/src/components/ad/ad.tsx b/packages/taro-components/src/components/ad/ad.tsx index 26ab00cfcd7c..3676afce9c92 100644 --- a/packages/taro-components/src/components/ad/ad.tsx +++ b/packages/taro-components/src/components/ad/ad.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-ad-core' }) -export class Ad { +export class Ad implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 Ad 组件!') + notSupport('Ad', this) } render () { diff --git a/packages/taro-components/src/components/camera/camera.tsx b/packages/taro-components/src/components/camera/camera.tsx index e55579c33d99..e5ad0fc437db 100644 --- a/packages/taro-components/src/components/camera/camera.tsx +++ b/packages/taro-components/src/components/camera/camera.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-camera-core' }) -export class Camera { +export class Camera implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 Camera 组件!') + notSupport('Camera', this) } render () { diff --git a/packages/taro-components/src/components/editor/editor.tsx b/packages/taro-components/src/components/editor/editor.tsx index b031f3f0f4b4..daf84b38606d 100644 --- a/packages/taro-components/src/components/editor/editor.tsx +++ b/packages/taro-components/src/components/editor/editor.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-editor-core' }) -export class Editor { +export class Editor implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 Editor 组件!') + notSupport('Editor', this) } render () { diff --git a/packages/taro-components/src/components/functional-page-navigator/functional-page-navigator.tsx b/packages/taro-components/src/components/functional-page-navigator/functional-page-navigator.tsx index de6364824cee..b91cb12af060 100644 --- a/packages/taro-components/src/components/functional-page-navigator/functional-page-navigator.tsx +++ b/packages/taro-components/src/components/functional-page-navigator/functional-page-navigator.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-functional-page-navigator-core' }) -export class FunctionalPageNavigator { +export class FunctionalPageNavigator implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 FunctionalPageNavigator 组件!') + notSupport('FunctionalPageNavigator', this) } render () { diff --git a/packages/taro-components/src/components/keyboard-accessory/keyboard-accessory.tsx b/packages/taro-components/src/components/keyboard-accessory/keyboard-accessory.tsx index f7cfb93c0819..e8a351e79af8 100644 --- a/packages/taro-components/src/components/keyboard-accessory/keyboard-accessory.tsx +++ b/packages/taro-components/src/components/keyboard-accessory/keyboard-accessory.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-keyboard-accessory-core' }) -export class KeyboardAccessory { +export class KeyboardAccessory implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 KeyboardAccessory 组件!') + notSupport('KeyboardAccessory', this) } render () { diff --git a/packages/taro-components/src/components/live-player/live-player.tsx b/packages/taro-components/src/components/live-player/live-player.tsx index 30ee55726194..8be4bafcb613 100644 --- a/packages/taro-components/src/components/live-player/live-player.tsx +++ b/packages/taro-components/src/components/live-player/live-player.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-live-player-core' }) -export class LivePlayer { +export class LivePlayer implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 LivePlayer 组件!') + notSupport('LivePlayer', this) } render () { diff --git a/packages/taro-components/src/components/live-pusher/live-pusher.tsx b/packages/taro-components/src/components/live-pusher/live-pusher.tsx index 3f3bd1840812..d8c64df51f13 100644 --- a/packages/taro-components/src/components/live-pusher/live-pusher.tsx +++ b/packages/taro-components/src/components/live-pusher/live-pusher.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-live-pusher-core' }) -export class LivePusher { +export class LivePusher implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 LivePusher 组件!') + notSupport('LivePusher', this) } render () { diff --git a/packages/taro-components/src/components/map/map.tsx b/packages/taro-components/src/components/map/map.tsx index 92fed693055a..cbeac06ca6a1 100644 --- a/packages/taro-components/src/components/map/map.tsx +++ b/packages/taro-components/src/components/map/map.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-map-core' }) -export class Map { +export class Map implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 Map 组件!') + notSupport('Map', this) } render () { diff --git a/packages/taro-components/src/components/match-media/match-media.tsx b/packages/taro-components/src/components/match-media/match-media.tsx index 1154f67a8b4a..0462c52ce2f1 100644 --- a/packages/taro-components/src/components/match-media/match-media.tsx +++ b/packages/taro-components/src/components/match-media/match-media.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-match-media-core' }) -export class MatchMedia { +export class MatchMedia implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 MatchMedia 组件!') + notSupport('MatchMedia', this) } render () { diff --git a/packages/taro-components/src/components/navigation-bar/navigation-bar.tsx b/packages/taro-components/src/components/navigation-bar/navigation-bar.tsx index 057eba888b20..9e2209ca2520 100644 --- a/packages/taro-components/src/components/navigation-bar/navigation-bar.tsx +++ b/packages/taro-components/src/components/navigation-bar/navigation-bar.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-navigation-bar-core' }) -export class NavigationBar { +export class NavigationBar implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 NavigationBar 组件!') + notSupport('NavigationBar', this) } render () { diff --git a/packages/taro-components/src/components/official-account/official-account.tsx b/packages/taro-components/src/components/official-account/official-account.tsx index 284a51101ffc..429738f1fa00 100644 --- a/packages/taro-components/src/components/official-account/official-account.tsx +++ b/packages/taro-components/src/components/official-account/official-account.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-official-account-core' }) -export class OfficialAccount { +export class OfficialAccount implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 OfficialAccount 组件!') + notSupport('OfficialAccount', this) } render () { diff --git a/packages/taro-components/src/components/open-data/open-data.tsx b/packages/taro-components/src/components/open-data/open-data.tsx index 1c02183815fd..79d0a964b623 100644 --- a/packages/taro-components/src/components/open-data/open-data.tsx +++ b/packages/taro-components/src/components/open-data/open-data.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-open-data-core' }) -export class OpenData { +export class OpenData implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 OpenData 组件!') + notSupport('OpenData', this) } render () { diff --git a/packages/taro-components/src/components/page-container/page-container.tsx b/packages/taro-components/src/components/page-container/page-container.tsx index ceede42a0f97..42049cdb00a6 100644 --- a/packages/taro-components/src/components/page-container/page-container.tsx +++ b/packages/taro-components/src/components/page-container/page-container.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-page-container-core' }) -export class PageContainer { +export class PageContainer implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 PageContainer 组件!') + notSupport('PageContainer', this) } render () { diff --git a/packages/taro-components/src/components/page-meta/page-meta.tsx b/packages/taro-components/src/components/page-meta/page-meta.tsx index d5081051d0ec..e4650d55aaa1 100644 --- a/packages/taro-components/src/components/page-meta/page-meta.tsx +++ b/packages/taro-components/src/components/page-meta/page-meta.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-page-meta-core' }) -export class PageMeta { +export class PageMeta implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 PageMeta 组件!') + notSupport('PageMeta', this) } render () { diff --git a/packages/taro-components/src/components/root-portal/root-portal.tsx b/packages/taro-components/src/components/root-portal/root-portal.tsx index 7d0867263909..36fc9ee2df80 100644 --- a/packages/taro-components/src/components/root-portal/root-portal.tsx +++ b/packages/taro-components/src/components/root-portal/root-portal.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-root-portal-core' }) -export class RootPortal { +export class RootPortal implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 RootPortal 组件!') + notSupport('RootPortal', this) } render () { diff --git a/packages/taro-components/src/components/share-element/share-element.tsx b/packages/taro-components/src/components/share-element/share-element.tsx index 4eaa90c6c177..edf6c94c15c4 100644 --- a/packages/taro-components/src/components/share-element/share-element.tsx +++ b/packages/taro-components/src/components/share-element/share-element.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-share-element-core' }) -export class ShareElement { +export class ShareElement implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 ShareElement 组件!') + notSupport('ShareElement', this) } render () { diff --git a/packages/taro-components/src/components/slot/slot.tsx b/packages/taro-components/src/components/slot/slot.tsx index f8e7397b0fc3..7cacbe318ae2 100644 --- a/packages/taro-components/src/components/slot/slot.tsx +++ b/packages/taro-components/src/components/slot/slot.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-slot-core' }) -export class Slot { +export class Slot implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 Slot 组件!') + notSupport('Slot', this) } render () { diff --git a/packages/taro-components/src/components/voip-room/voip-room.tsx b/packages/taro-components/src/components/voip-room/voip-room.tsx index 9f271a19b30d..7ec3cdf829f8 100644 --- a/packages/taro-components/src/components/voip-room/voip-room.tsx +++ b/packages/taro-components/src/components/voip-room/voip-room.tsx @@ -1,12 +1,13 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, h, Host } from '@stencil/core' +import { Component, ComponentInterface, h, Host } from '@stencil/core' + +import { notSupport } from '../../utils' @Component({ tag: 'taro-voip-room-core' }) -export class VoipRoom { +export class VoipRoom implements ComponentInterface { componentDidLoad () { - console.error('H5 暂不支持 VoipRoom 组件!') + notSupport('VoipRoom', this) } render () { diff --git a/packages/taro-components/src/utils/helper.ts b/packages/taro-components/src/utils/helper.ts new file mode 100644 index 000000000000..a8354994305d --- /dev/null +++ b/packages/taro-components/src/utils/helper.ts @@ -0,0 +1,12 @@ +import Taro from '@tarojs/taro' + +export function notSupport (name = '', instance = {}) { + console.error(`H5 暂不支持 ${name} 组件!`) + + Taro.eventCenter.trigger('__taroNotSupport', { + name, + instance, + type: 'component', + category: 'temporarily', + }) +} diff --git a/packages/taro-components/src/utils/index.ts b/packages/taro-components/src/utils/index.ts index c4a8d6e6860b..6115d6dde96e 100755 --- a/packages/taro-components/src/utils/index.ts +++ b/packages/taro-components/src/utils/index.ts @@ -29,5 +29,6 @@ export function debounce (fn, ms = 250, scope?) { } } +export * from './helper' export * from './style' export * from './url' diff --git a/packages/taro-h5/src/utils/index.ts b/packages/taro-h5/src/utils/index.ts index caaf4b998758..d4f4fe99c5cb 100644 --- a/packages/taro-h5/src/utils/index.ts +++ b/packages/taro-h5/src/utils/index.ts @@ -1,6 +1,11 @@ /* eslint-disable prefer-promise-reject-errors */ +import Taro from '@tarojs/api' import { Current, hooks, TaroElement } from '@tarojs/runtime' +import { MethodHandler } from './handler' + +export const isProd = process.env.NODE_ENV === 'production' + export function shouldBeObject (target: unknown) { if (target && typeof target === 'object') return { flag: true } return { @@ -80,53 +85,62 @@ export function serializeParams (params) { .join('&') } -export function temporarilyNotSupport (apiName) { - return () => { - const errMsg = `暂时不支持 API ${apiName}` - if (process.env.NODE_ENV !== 'production') { - console.error(errMsg) - return Promise.reject({ - errMsg - }) - } else { +export function temporarilyNotSupport (name = '') { + return (option = {}, ...args) => { + const { success, fail, complete } = option as any + const handle = new MethodHandler({ name, success, fail, complete }) + const errMsg = '暂时不支持 API' + Taro.eventCenter.trigger('__taroNotSupport', { + name, + args: [option, ...args], + type: 'method', + category: 'temporarily', + }) + if (isProd) { console.warn(errMsg) - return Promise.resolve({ - errMsg - }) + return handle.success({ errMsg }) + } else { + return handle.fail({ errMsg }) } } } -export function weixinCorpSupport (apiName) { - return () => { - const errMsg = `h5端当前仅在微信公众号JS-SDK环境下支持此 API ${apiName}` - if (process.env.NODE_ENV !== 'production') { - console.error(errMsg) - return Promise.reject({ - errMsg - }) - } else { +export function weixinCorpSupport (name) { + return (option = {}, ...args) => { + const { success, fail, complete } = option as any + const handle = new MethodHandler({ name, success, fail, complete }) + const errMsg = 'h5 端当前仅在微信公众号 JS-SDK 环境下支持此 API' + Taro.eventCenter.trigger('__taroNotSupport', { + name, + args: [option, ...args], + type: 'method', + category: 'weixin_corp', + }) + if (isProd) { console.warn(errMsg) - return Promise.resolve({ - errMsg - }) + return handle.success({ errMsg }) + } else { + return handle.fail({ errMsg }) } } } -export function permanentlyNotSupport (apiName) { - return () => { - const errMsg = `不支持 API ${apiName}` - if (process.env.NODE_ENV !== 'production') { - console.error(errMsg) - return Promise.reject({ - errMsg - }) - } else { +export function permanentlyNotSupport (name = '') { + return (option = {}, ...args) => { + const { success, fail, complete } = option as any + const handle = new MethodHandler({ name, success, fail, complete }) + const errMsg = '不支持 API' + Taro.eventCenter.trigger('__taroNotSupport', { + name, + args: [option, ...args], + type: 'method', + category: 'permanently', + }) + if (isProd) { console.warn(errMsg) - return Promise.resolve({ - errMsg - }) + return handle.success({ errMsg }) + } else { + return handle.fail({ errMsg }) } } }