Skip to content

Commit

Permalink
feat: 添加快手的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
三少 committed Mar 22, 2022
1 parent 06c65f6 commit 01355d2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 28 deletions.
78 changes: 50 additions & 28 deletions packages/mini-fix/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function smoothOutParams() {
const oriApp = App
const oriPage = Page
const oriComponent = Component
let firstLoad = false
let firstShow = true
let firstShowOpt: any = null

/**
* 处理页面生命周期
Expand All @@ -22,60 +23,76 @@ function smoothOutParams() {
) {
switch (methodName) {
case 'onLaunch': {
firstLoad = true
// 微信和抖音需要decode,支付宝自己decode过了
// 微信和抖音需要decode,支付宝、快手自己decode过了
if (process.env.TARO_ENV === 'weapp' || process.env.TARO_ENV === 'tt') {
const params = JSON.parse(JSON.stringify(args[0].query || {}))
args[0].query = decodeParams(params)
// 微信、支付宝、快手、抖音launch之后马上触发的appshow会使用当前的参数,所以这里decode过了,appshow就不需要decode了
args[0].query = decodeParams(args[0].query || {})
}
firstShow = true
console.log('inner launch', JSON.stringify(args[0]))
break
}

case 'onLoad': {
// 微信和抖音需要decode,支付宝自己decode过了
// 微信和抖音需要decode,支付宝、快手自己decode过了
// 实测抖音第一次进来的时候不需要decode
if (
process.env.TARO_ENV === 'weapp' ||
(process.env.TARO_ENV === 'tt' && !firstLoad)
) {
if (process.env.TARO_ENV === 'weapp') {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = JSON.parse(JSON.stringify(currentPage.options || {}))
currentPage.options = decodeParams(options)

const params = JSON.parse(JSON.stringify(args[0] || {}))
args[0] = decodeParams(params)
const currentPage = (pages && pages[pages.length - 1]) || {}
args[0] = decodeParams(args[0] || {})
currentPage.options = args[0]
}

if (firstLoad) {
firstLoad = false
if (process.env.TARO_ENV === 'tt') {
const strParams = JSON.stringify(args[0] || {})
const pages = getCurrentPages()
const currentPage = (pages && pages[pages.length - 1]) || {}
if (!firstShowOpt || (firstShowOpt && strParams !== firstShowOpt)) {
args[0] = decodeParams(args[0] || {})
}
currentPage.options = args[0]
currentPage.minifixWithTT = JSON.stringify(args[0])
}
firstShowOpt = null
console.log('inner load', JSON.stringify(args[0]))

break
}

case 'onShow': {
if (isApp) {
// 微信和抖音需要decode,支付宝自己decode过了
if (
process.env.TARO_ENV === 'weapp' ||
process.env.TARO_ENV === 'tt'
) {
const params = JSON.parse(JSON.stringify(args[0].query || {}))
args[0].query = decodeParams(params)
if (firstShow) {
firstShow = false
firstShowOpt = JSON.stringify(args[0].query || {})
console.log('inner first show', JSON.stringify(args[0]))
} else {
if (process.env.TARO_ENV === 'weapp') {
args[0].query = decodeParams(args[0].query || {})
}
if (process.env.TARO_ENV === 'tt') {
const strParams = JSON.stringify(args[0].query || {})
const pages = getCurrentPages()
const currentPage = (pages && pages[pages.length - 1]) || {}
if (strParams !== currentPage.minifixWithTT) {
args[0].query = decodeParams(args[0].query || {})
}
}
console.log('inner not first show', JSON.stringify(args[0]))
}
}
break
}
default:
break
}
return args
}

const wrapMethod = function (target: any, methodName: string, isApp = false) {
const methodFunc = target[methodName]
target[methodName] = function (...args: any) {
try {
handlePageCycle(methodName, args, isApp)
const factoryOptions = handlePageCycle(methodName, args, isApp)
return methodFunc.apply(this, factoryOptions)
} catch (e) {
console.info('ace-mini wrapMethod error', e)
}
Expand Down Expand Up @@ -112,6 +129,11 @@ function smoothOutParams() {
}
}

if (process.env.TARO_ENV === 'weapp' || process.env.TARO_ENV === 'tt') {
if (
process.env.TARO_ENV === 'weapp' ||
process.env.TARO_ENV === 'alipay' ||
process.env.TARO_ENV === 'kwai' ||
process.env.TARO_ENV === 'tt'
) {
smoothOutParams()
}
1 change: 1 addition & 0 deletions packages/mini-fix/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare global {
| 'qywx'
| 'jd'
| 'iot'
| 'kwai'
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/trace/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export enum EAppSubType {
qywx = '10',
// 支付宝IOT小程序
iot = '11',
// 快手小程序
kwai = '12',
}

export enum ELf {
Expand Down
1 change: 1 addition & 0 deletions packages/unite/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare global {
| 'qywx'
| 'jd'
| 'iot'
| 'kwai'
}
}
}
Expand Down

0 comments on commit 01355d2

Please # to comment.