This commit is contained in:
2025-11-14 11:39:33 +08:00
parent 6e5d892992
commit 1ba633ba45
7143 changed files with 922330 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
export {
getPushClientId,
onPushMessage,
offPushMessage,
invokePushCallback
}
from 'uni-core/service/api/plugin/push'
export {
__f__
}
from 'uni-core/service/api/plugin/__f__'

View File

@@ -0,0 +1,24 @@
// import navigateTo from 'uni-helpers/navigate-to'
// import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
// import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
// 需要做转换的 API 列表
export const protocols = {
// navigateTo,
// redirectTo,
// previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo
// getUserProfile
}
// 不支持的 API 列表
// TODO: 补充
export const todos = [
'getSelectedTextRange'
]
// 存在兼容性的 API 列表
export const canIUses = []

View File

@@ -0,0 +1,6 @@
export default {
oauth: ['xhs'],
share: ['xhs'],
payment: ['xhs'],
push: ['xhs']
}

View File

@@ -0,0 +1 @@
import '../../mp-weixin/runtime/index'

View File

@@ -0,0 +1,17 @@
const isXhs = window.xhs &&
window.xhs.miniProgram &&
/xhsminiapp/i.test(navigator.userAgent)
export function initWebviewApi (readyCallback) {
if (!isXhs) {
return
}
// todo 没有 XhsJSBridgeReady
// if (window.XhsJSBridgeReady && window.XhsJSBridgeReady.invoke) {
// setTimeout(readyCallback, 0)
// } else {
// document.addEventListener('XhsJSBridgeReady', readyCallback)
// }
return window.xhs.miniProgram
}

View File

@@ -0,0 +1,5 @@
import parseBaseApp from '../../../mp-weixin/runtime/wrapper/app-parser'
export default function parseApp (vm) {
return parseBaseApp(vm)
}

View File

@@ -0,0 +1,36 @@
// import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-parser'
// export default function parseComponent (vueComponentOptions) {
// const componentOptions = parseBaseComponent(vueComponentOptions)
// // 小红书小程序 lifetimes 存在兼容问题
// const lifetimes = componentOptions.lifetimes
// Object.keys(lifetimes).forEach(key => {
// componentOptions[key] = lifetimes[key]
// })
// return componentOptions
// }
import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-parser'
import { isPage } from '../../../mp-weixin/runtime/wrapper/util'
import {
fixSetDataStart,
fixSetDataEnd
} from '../../../mp-weixin/runtime/wrapper/fix-set-data'
export default function parseComponent (vueComponentOptions, needVueOptions) {
const [componentOptions, vueOptions] = parseBaseComponent(vueComponentOptions, true)
const oldAttached = componentOptions.lifetimes.attached
componentOptions.lifetimes.attached = function attached () {
// 暂不区分版本
if (isPage.call(this)) {
fixSetDataStart(this)
setTimeout(() => {
fixSetDataEnd(this)
}, 0)
}
oldAttached.call(this)
}
return needVueOptions ? [componentOptions, vueOptions] : componentOptions
}

View File

@@ -0,0 +1,98 @@
import Vue from 'vue'
import {
stringifyQuery
} from 'uni-shared/query'
import {
initData,
initHooks,
initUnknownHooks,
handleEvent,
initBehaviors,
initVueComponent,
PAGE_EVENT_HOOKS
} from 'uni-wrapper/util'
import { handleLink, initBehavior } from '../../../mp-weixin/runtime/wrapper/util'
import {
handleWrap,
initSpecialMethods
} from './util'
const hooks = [
'onShow',
'onHide',
'onUnload'
]
hooks.push(...PAGE_EVENT_HOOKS)
export default function parsePage (vuePageOptions) {
const [VueComponent, vueOptions] = initVueComponent(Vue, vuePageOptions)
const pageOptions = {
mixins: initBehaviors(vueOptions, initBehavior),
data: initData(vueOptions, Vue.prototype),
onLoad (query) {
const properties = this.props
this.__query = query
this.__options = {
mpType: 'page',
mpInstance: this,
propsData: properties
}
},
onReady () {
// initChildVues(this)
// 初始化 vue 实例
this.$vm = new VueComponent(this.__options)
// 触发首次 setData
this.$vm.$mount()
initSpecialMethods(this)
this.$vm._isMounted = true
this.$vm.__call_hook('mounted')
// mounted => onLoad
this.options = this.__query
this.$vm.$mp.query = this.__query // 兼容 mpvue
const copyQuery = Object.assign({}, this.__query)
delete copyQuery.__id__
this.$page = {
fullPath: '/' + this.route + stringifyQuery(copyQuery)
}
this.$vm.__call_hook('onLoad', this.__query)
this.$vm.__call_hook('onShow')
setTimeout(() => {
this.$vm.__call_hook('onReady')
})
},
onUnload () {
this.$vm.__call_hook('onUnload')
this.$vm.$destroy()
},
// __r: handleRef,
__e: handleEvent,
__l: handleLink,
__w: handleWrap,
triggerEvent: function noop () {}
}
initHooks(pageOptions, hooks, vueOptions)
initUnknownHooks(pageOptions, vueOptions, ['onReady'])
if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => {
pageOptions[callMethod] = function (args) {
return this.$vm[callMethod](args)
}
})
}
return pageOptions
}

View File

@@ -0,0 +1,52 @@
import {
isFn,
hasOwn
} from 'uni-shared'
export const isComponent2 = xhs.canIUse('component2')
export const mocks = ['$id']
export function initSpecialMethods (mpInstance) {
if (!mpInstance.$vm) {
return
}
let path = mpInstance.is || mpInstance.route
if (!path) {
return
}
if (path.indexOf('/') === 0) {
path = path.substr(1)
}
const specialMethods = xhs.specialMethods && xhs.specialMethods[path]
if (specialMethods) {
specialMethods.forEach(method => {
if (isFn(mpInstance.$vm[method])) {
mpInstance[method] = function (event) {
if (hasOwn(event, 'markerId')) {
event.detail = typeof event.detail === 'object' ? event.detail : {}
event.detail.markerId = event.markerId
}
// TODO normalizeEvent
mpInstance.$vm[method](event)
}
}
})
}
}
export const handleWrap = function (mp, destory) {
const vueId = mp.props.vueId
const list = (mp.props['data-event-list'] || '').split(',')
list.forEach(eventName => {
const key = `${eventName}${vueId}`
if (destory) {
delete this[key]
} else {
// TODO remove handleRef
this[key] = function () {
mp.props[eventName].apply(this, arguments)
}
}
})
}