提交 da1dab32 编写于 作者: fxy060608's avatar fxy060608

wip(mp): mp-alipay

上级 302ed498
......@@ -683,7 +683,8 @@ function initBehavior({ properties }) {
};
}
function initRelation(mpInstance, detail) {
mpInstance.props.onVueInit(detail);
// onVueInit
mpInstance.props.onVI(detail);
}
function initSpecialMethods(mpInstance) {
if (!mpInstance.$vm) {
......@@ -742,8 +743,8 @@ function handleRef(ref) {
if (!ref) {
return;
}
const refName = ref.props['data-ref'];
const refInForName = ref.props['data-ref-in-for'];
const refName = ref.props['data-r']; // data-ref
const refInForName = ref.props['data-r-i-f']; // data-ref-in-for
if (!refName && !refInForName) {
return;
}
......@@ -828,46 +829,48 @@ function createVueComponent(mpType, mpInstance, vueOptions, parent) {
});
}
function createPage$1(vueOptions) {
vueOptions = vueOptions.default || vueOptions;
const pageOptions = {
onLoad(query) {
this.options = query;
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
};
// 初始化 vue 实例
this.$vm = createVueComponent('page', this, vueOptions);
initSpecialMethods(this);
this.$vm.$callHook(ON_LOAD, query);
},
onReady() {
initChildVues(this);
this.$vm.$callHook('mounted');
this.$vm.$callHook(ON_READY);
},
onUnload() {
if (this.$vm) {
this.$vm.$callHook(ON_UNLOAD);
$destroyComponent(this.$vm);
}
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack() {
this.$vm.$callHook(ON_BACK_PRESS);
function initCreatePage() {
return function createPage(vueOptions) {
vueOptions = vueOptions.default || vueOptions;
const pageOptions = {
onLoad(query) {
this.options = query;
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
};
// 初始化 vue 实例
this.$vm = createVueComponent('page', this, vueOptions);
initSpecialMethods(this);
this.$vm.$callHook(ON_LOAD, query);
},
},
__r: handleRef,
__l: handleLink,
onReady() {
initChildVues(this);
this.$vm.$callHook('mounted');
this.$vm.$callHook(ON_READY);
},
onUnload() {
if (this.$vm) {
this.$vm.$callHook(ON_UNLOAD);
$destroyComponent(this.$vm);
}
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack() {
this.$vm.$callHook(ON_BACK_PRESS);
},
},
__r: handleRef,
__l: handleLink,
};
if (__VUE_OPTIONS_API__) {
pageOptions.data = initData(vueOptions);
}
initHooks(pageOptions, PAGE_HOOKS);
initUnknownHooks(pageOptions, vueOptions);
initWxsCallMethods(pageOptions, vueOptions.wxsCallMethods);
return Page(pageOptions);
};
if (__VUE_OPTIONS_API__) {
pageOptions.data = initData(vueOptions);
}
initHooks(pageOptions, PAGE_HOOKS);
initUnknownHooks(pageOptions, vueOptions);
initWxsCallMethods(pageOptions, vueOptions.wxsCallMethods);
return Page(pageOptions);
}
function initComponentProps(rawProps) {
......@@ -877,7 +880,8 @@ function initComponentProps(rawProps) {
initProps(propertiesOptions, rawProps, false);
const properties = propertiesOptions.properties;
const props = {
onVueInit: function () { },
// onVueInit
onVI: function () { },
};
Object.keys(properties).forEach((key) => {
// vueSlots
......@@ -917,60 +921,64 @@ function initVm(mpInstance, createComponent) {
}
}
}
function createComponent$1(vueOptions) {
vueOptions = vueOptions.default || vueOptions;
const mpComponentOptions = {
props: initComponentProps(vueOptions.props),
didMount() {
const createComponent = (parent) => {
return createVueComponent('component', this, vueOptions, parent);
};
if (my.dd) {
// 钉钉小程序底层基础库有 bug,组件嵌套使用时,在 didMount 中无法及时调用 props 中的方法
setTimeout(() => {
function initCreateComponent() {
return function createComponent(vueOptions) {
vueOptions = vueOptions.default || vueOptions;
const mpComponentOptions = {
props: initComponentProps(vueOptions.props),
didMount() {
const createComponent = (parent) => {
return createVueComponent('component', this, vueOptions, parent);
};
if (my.dd) {
// 钉钉小程序底层基础库有 bug,组件嵌套使用时,在 didMount 中无法及时调用 props 中的方法
setTimeout(() => {
initVm(this, createComponent);
}, 4);
}
else {
initVm(this, createComponent);
}, 4);
}
else {
initVm(this, createComponent);
}
initSpecialMethods(this);
if (isComponent2) {
this.$vm.$callHook('mounted');
}
},
didUnmount() {
$destroyComponent(this.$vm);
},
methods: {
__r: handleRef,
__l: handleLink,
triggerEvent,
},
};
if (__VUE_OPTIONS_API__) {
mpComponentOptions.data = initData(vueOptions);
mpComponentOptions.mixins = initBehaviors(vueOptions, initBehavior);
}
if (isComponent2) {
mpComponentOptions.onInit = function onInit() {
initVm(this, (parent) => {
return createVueComponent('component', this, vueOptions, parent);
});
}
initSpecialMethods(this);
if (isComponent2) {
this.$vm.$callHook('mounted');
}
},
didUnmount() {
$destroyComponent(this.$vm);
},
methods: {
__r: handleRef,
__l: handleLink,
triggerEvent,
},
};
mpComponentOptions.deriveDataFromProps = createObserver();
}
else {
mpComponentOptions.didUpdate = createObserver(true);
}
initWxsCallMethods(mpComponentOptions.methods, vueOptions.wxsCallMethods);
return Component(mpComponentOptions);
if (__VUE_OPTIONS_API__) {
mpComponentOptions.data = initData(vueOptions);
mpComponentOptions.mixins = initBehaviors(vueOptions, initBehavior);
}
if (isComponent2) {
mpComponentOptions.onInit = function onInit() {
initVm(this, (parent) => {
return createVueComponent('component', this, vueOptions, parent);
});
};
mpComponentOptions.deriveDataFromProps = createObserver();
}
else {
mpComponentOptions.didUpdate = createObserver(true);
}
initWxsCallMethods(mpComponentOptions.methods, vueOptions.wxsCallMethods);
return Component(mpComponentOptions);
};
}
const createApp = initCreateApp(parseAppOptions);
const createPage = initCreatePage();
const createComponent = initCreateComponent();
my.EventChannel = EventChannel;
my.createApp = global.createApp = createApp;
my.createApp = createApp;
my.createPage = createPage;
my.createComponent = createComponent;
export { createApp, createComponent$1 as createComponent, createPage$1 as createPage };
export { createApp, createComponent, createPage };
......@@ -14,7 +14,9 @@
"license": "Apache-2.0",
"uni-app": {
"name": "mp-alipay",
"title": "支付宝小程序"
"title": "支付宝小程序",
"apply": "mp-alipay",
"main": "dist/uni.compiler.js"
},
"gitHead": "1efa8efd0a9eddeabdba75c020d015ebf31b8177"
}
......@@ -33,7 +33,8 @@ function initComponentProps(rawProps: Record<string, any>) {
initProps(propertiesOptions, rawProps, false)
const properties = propertiesOptions.properties as Record<string, any>
const props: Record<string, any> = {
onVueInit: function () {},
// onVueInit
onVI: function () {},
}
Object.keys(properties).forEach((key) => {
// vueSlots
......@@ -78,56 +79,58 @@ function initVm(
}
}
export function createComponent(vueOptions: ComponentOptions) {
vueOptions = vueOptions.default || vueOptions
const mpComponentOptions: tinyapp.ComponentOptions = {
props: initComponentProps(vueOptions.props),
didMount() {
const createComponent = (parent?: ComponentPublicInstance) => {
return createVueComponent('component', this, vueOptions, parent)
}
if ((my as any).dd) {
// 钉钉小程序底层基础库有 bug,组件嵌套使用时,在 didMount 中无法及时调用 props 中的方法
setTimeout(() => {
export function initCreateComponent() {
return function createComponent(vueOptions: ComponentOptions) {
vueOptions = vueOptions.default || vueOptions
const mpComponentOptions: tinyapp.ComponentOptions = {
props: initComponentProps(vueOptions.props),
didMount() {
const createComponent = (parent?: ComponentPublicInstance) => {
return createVueComponent('component', this, vueOptions, parent)
}
if ((my as any).dd) {
// 钉钉小程序底层基础库有 bug,组件嵌套使用时,在 didMount 中无法及时调用 props 中的方法
setTimeout(() => {
initVm(this, createComponent)
}, 4)
} else {
initVm(this, createComponent)
}, 4)
} else {
initVm(this, createComponent)
}
initSpecialMethods(this)
if (isComponent2) {
this.$vm.$callHook('mounted')
}
},
didUnmount() {
$destroyComponent(this.$vm)
},
methods: {
__r: handleRef,
__l: handleLink,
triggerEvent,
},
}
if (__VUE_OPTIONS_API__) {
mpComponentOptions.data = initData(vueOptions)
mpComponentOptions.mixins = initBehaviors(vueOptions, initBehavior)
}
}
initSpecialMethods(this)
if (isComponent2) {
this.$vm.$callHook('mounted')
}
},
didUnmount() {
$destroyComponent(this.$vm)
},
methods: {
__r: handleRef,
__l: handleLink,
triggerEvent,
},
}
if (__VUE_OPTIONS_API__) {
mpComponentOptions.data = initData(vueOptions)
mpComponentOptions.mixins = initBehaviors(vueOptions, initBehavior)
}
if (isComponent2) {
mpComponentOptions.onInit = function onInit(this: MPComponentInstance) {
initVm(this, (parent?: ComponentPublicInstance) => {
return createVueComponent('component', this, vueOptions, parent)
})
if (isComponent2) {
mpComponentOptions.onInit = function onInit(this: MPComponentInstance) {
initVm(this, (parent?: ComponentPublicInstance) => {
return createVueComponent('component', this, vueOptions, parent)
})
}
mpComponentOptions.deriveDataFromProps = createObserver()
} else {
mpComponentOptions.didUpdate = createObserver(true)
}
mpComponentOptions.deriveDataFromProps = createObserver()
} else {
mpComponentOptions.didUpdate = createObserver(true)
}
initWxsCallMethods(
mpComponentOptions.methods as WechatMiniprogram.Component.MethodOption,
vueOptions.wxsCallMethods
)
initWxsCallMethods(
mpComponentOptions.methods as WechatMiniprogram.Component.MethodOption,
vueOptions.wxsCallMethods
)
return Component(mpComponentOptions)
return Component(mpComponentOptions)
}
}
......@@ -27,49 +27,51 @@ import {
declare function Page<D>(options: tinyapp.PageOptions<D>): void
export function createPage(vueOptions: ComponentOptions) {
vueOptions = vueOptions.default || vueOptions
const pageOptions: tinyapp.PageOptions = {
onLoad(query) {
this.options = query
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
}
// 初始化 vue 实例
this.$vm = createVueComponent('page', this, vueOptions)
initSpecialMethods(this)
this.$vm.$callHook(ON_LOAD, query)
},
onReady() {
initChildVues(this)
this.$vm.$callHook('mounted')
this.$vm.$callHook(ON_READY)
},
onUnload() {
if (this.$vm) {
this.$vm.$callHook(ON_UNLOAD)
$destroyComponent(this.$vm)
}
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack() {
this.$vm.$callHook(ON_BACK_PRESS)
export function initCreatePage() {
return function createPage(vueOptions: ComponentOptions) {
vueOptions = vueOptions.default || vueOptions
const pageOptions: tinyapp.PageOptions = {
onLoad(query) {
this.options = query
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query),
}
// 初始化 vue 实例
this.$vm = createVueComponent('page', this, vueOptions)
initSpecialMethods(this)
this.$vm.$callHook(ON_LOAD, query)
},
},
__r: handleRef,
__l: handleLink,
}
if (__VUE_OPTIONS_API__) {
pageOptions.data = initData(vueOptions)
}
initHooks(pageOptions, PAGE_HOOKS)
initUnknownHooks(pageOptions, vueOptions)
onReady() {
initChildVues(this)
this.$vm.$callHook('mounted')
this.$vm.$callHook(ON_READY)
},
onUnload() {
if (this.$vm) {
this.$vm.$callHook(ON_UNLOAD)
$destroyComponent(this.$vm)
}
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack() {
this.$vm.$callHook(ON_BACK_PRESS)
},
},
__r: handleRef,
__l: handleLink,
}
if (__VUE_OPTIONS_API__) {
pageOptions.data = initData(vueOptions)
}
initHooks(pageOptions, PAGE_HOOKS)
initUnknownHooks(pageOptions, vueOptions)
initWxsCallMethods(
pageOptions as WechatMiniprogram.Component.MethodOption,
vueOptions.wxsCallMethods
)
initWxsCallMethods(
pageOptions as WechatMiniprogram.Component.MethodOption,
vueOptions.wxsCallMethods
)
return Page(pageOptions)
return Page(pageOptions)
}
}
......@@ -4,11 +4,12 @@ import { initCreateApp } from '@dcloudio/uni-mp-core'
import * as parseAppOptions from './parseAppOptions'
export { createPage } from './createPage'
export { createComponent } from './createComponent'
import { initCreatePage } from './createPage'
import { initCreateComponent } from './createComponent'
export const createApp = initCreateApp(parseAppOptions)
export const createPage = initCreatePage()
export const createComponent = initCreateComponent()
;(my as any).EventChannel = EventChannel
;(my as any).createApp = (global as any).createApp = createApp
;(my as any).createApp = createApp
;(my as any).createPage = createPage
;(my as any).createComponent = createComponent
......@@ -48,7 +48,8 @@ export function initRelation(
mpInstance: MPComponentInstance,
detail: RelationOptions
) {
mpInstance.props.onVueInit(detail)
// onVueInit
mpInstance.props.onVI(detail)
}
export function initSpecialMethods(
......@@ -128,8 +129,8 @@ export function handleRef(this: MPComponentInstance, ref: MPComponentInstance) {
if (!ref) {
return
}
const refName = ref.props['data-ref']
const refInForName = ref.props['data-ref-in-for']
const refName = ref.props['data-r'] // data-ref
const refInForName = ref.props['data-r-i-f'] // data-ref-in-for
if (!refName && !refInForName) {
return
}
......
......@@ -38,6 +38,7 @@ export interface UniMiniProgramPluginOptions {
template: {
extname: string
directive: string
event?: MiniProgramCompilerOptions['event']
class: MiniProgramCompilerOptions['class']
slot: MiniProgramCompilerOptions['slot']
filter?: {
......@@ -69,6 +70,7 @@ export function uniMiniProgramPlugin(
uni: uniOptions({
copyOptions,
miniProgram: {
event: template.event,
class: template.class,
filter: template.filter ? { lang: template.filter.lang } : undefined,
directive: template.directive,
......
......@@ -4882,8 +4882,9 @@ var plugin = {
const oldMount = app.mount;
app.mount = function mount(rootContainer) {
const instance = oldMount.call(app, rootContainer);
if (global.createApp) {
global.createApp(instance);
const createApp = getCreateApp();
if (createApp) {
createApp(instance);
}
else {
// @ts-ignore 旧编译器
......@@ -4895,7 +4896,16 @@ var plugin = {
return instance;
};
},
};
};
function getCreateApp() {
if (typeof global !== 'undefined') {
return global.createApp;
}
else if (typeof my !== 'undefined') {
// 支付宝小程序没有global
return my.createApp;
}
}
function vOn(value) {
const instance = getCurrentInstance();
......
......@@ -12,8 +12,9 @@ export default {
const oldMount = app.mount
app.mount = function mount(rootContainer: any) {
const instance = oldMount.call(app, rootContainer)
if ((global as any).createApp) {
;(global as any).createApp(instance)
const createApp = getCreateApp()
if (createApp) {
createApp(instance)
} else {
// @ts-ignore 旧编译器
if (typeof createMiniProgramApp !== 'undefined') {
......@@ -21,8 +22,16 @@ export default {
createMiniProgramApp(instance)
}
}
return instance
}
},
}
function getCreateApp() {
if (typeof global !== 'undefined') {
return (global as any).createApp
} else if (typeof my !== 'undefined') {
// 支付宝小程序没有global
return (my as any).createApp
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册