#2 支持跳转半屏小程序

開啟中
huangzhichao 請求將 5 次代碼提交從 weapp/feature/support-miniapp 合併至 weapp/staging

+ 13 - 4
src/pages/index/index.tsx

@@ -1,13 +1,22 @@
+import Taro from '@tarojs/taro'
 import React from 'react'
 import { View } from '@tarojs/components'
 import './index.less'
-
-const adpId = 'ADY_17103126327291030'
+// dev ADY_17097254415021673
+// pro ADY_17103126327291030
+const adpId = 'ADY_17119548862451948'
 const Index: React.FC = () => {
+
+  function onEmitOpenMiniProgram(appId, path, extraData) {
+    Taro.openEmbeddedMiniProgram({
+      appId, path, extraData
+    })
+  }
+
   return (
     <View className='index'>
-      {/* <calendar /> */}
-      <custom props={{ adpId, width: 200 }}/>
+      <calendar />
+      {/* <custom props={{ adpId, width: 200, onEmitOpenMiniProgram, closeIcon: false }} /> */}
     </View>
   )
 }

+ 5 - 1
src/plugin/components/calendar/index.scss

@@ -1,2 +1,6 @@
 	
-@import "~taro-ui/dist/style/components/calendar.scss";
+@import "~taro-ui/dist/style/components/calendar.scss";
+
+.calendar-container {
+  width: 100vw;
+}

+ 1 - 1
src/plugin/components/calendar/index.tsx

@@ -4,7 +4,7 @@ import './index.scss'
 
 function Index() {
   return (
-    <View>
+    <View className='calendar-container'>
       <AtCalendar />
     </View>
   )

+ 22 - 7
src/plugin/components/custom/index.tsx

@@ -19,6 +19,7 @@ function YLQCustom(props: PropsWithChildren<CustomPropsType>) {
   let {
     adpId,
     width,
+    closeIcon,
     onEmitOpenMiniProgram,
     onError,
     onLoad,
@@ -93,12 +94,16 @@ function YLQCustom(props: PropsWithChildren<CustomPropsType>) {
   
   function videoClick() {
     adActionReport(reportBusinessType.adClick, 'adClick')
-    videoOpenMiniProgram()
+    const { landingPageAddress, landingPageType, landingPageAppid } = adData
+    if (landingPageType === 1) { // 半屏小程序
+      openOriginMiniProgram(landingPageAddress, landingPageAppid)
+    } else if (landingPageType === 2) { // h5
+      openSelfMiniProgram(landingPageAddress)
+    }
     closeCustom()
   }
 
-  function videoOpenMiniProgram() {
-    const { landingPageAddress } = adData
+  function openSelfMiniProgram(landingPageAddress) {
     const query = queryURLParams(createAdActionReportData())
 
     adActionReport(reportBusinessType.adPlay, 'adOpen')
@@ -107,7 +112,16 @@ function YLQCustom(props: PropsWithChildren<CustomPropsType>) {
 
     onEmitOpenMiniProgram(
       'wx5ef216d1caf4a0ea',
-      `/pages/ad-launch-page/index?q=${path}`
+      `/pages/ad-launch-page/index?q=${path}`,
+      {}
+    )
+  }
+
+  function openOriginMiniProgram(landingPageAddress, landingPageAppid) {
+    onEmitOpenMiniProgram(
+      landingPageAppid,
+      landingPageAddress,
+      { pqtId }
     )
   }
 
@@ -183,7 +197,8 @@ function YLQCustom(props: PropsWithChildren<CustomPropsType>) {
       bidCreativeParam: JSON.stringify(bidCreativeParam || {}), // {}
       adpId,
       pqtId,
-      ownAdSystemType
+      ownAdSystemType,
+      clientTimestamp: new Date().getTime()
     }
   }
 
@@ -206,8 +221,8 @@ function YLQCustom(props: PropsWithChildren<CustomPropsType>) {
             广告
           </View>
           {/* 关闭icon */}
-          <View className='close-icon' onClick={closeCustom}>
-          </View>
+          {closeIcon && <View className='close-icon' onClick={closeCustom}>
+          </View>}
           <Custom
             width={width}
             adData={adData}

+ 2 - 0
src/plugin/share/index.ts

@@ -7,6 +7,7 @@ export function wrapProps(props: PropsWithChildren<CustomPropsType>) {
   let {
     adpId,
     width,
+    closeIcon = true,
     onEmitOpenMiniProgram = noop,
     onError = noop,
     onLoad = noop,
@@ -23,6 +24,7 @@ export function wrapProps(props: PropsWithChildren<CustomPropsType>) {
   return {
     adpId,
     width,
+    closeIcon,
     onEmitOpenMiniProgram,
     onError,
     onLoad,

+ 2 - 1
types/global.d.ts

@@ -36,7 +36,8 @@ declare namespace Taro {
 type CustomPropsType = {
   adpId: number
   width?: number
-  onEmitOpenMiniProgram(appId: string, path: string): void
+  closeIcon?: boolean
+  onEmitOpenMiniProgram(appId: string, path: string, extraData: { pqtId?: string }): void
   onError?(code: number): void
   onLoad?(): void
   onClose?(): void