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

fix(mp-alipay): getPhoneNumber (#3116)

上级 dda18d05
......@@ -6,7 +6,14 @@ describe('mp-alipay: transform v-on', () => {
`<button open-type='getPhoneNumber' @getphonenumber="getPhoneNumber">获取手机号</button>`,
`<button open-type="getAuthorize" scope="phoneNumber" onGetAuthorize="{{a}}" onError="{{b}}">获取手机号</button>`,
`(_ctx, _cache) => {
return { a: _o($event => _ctx.$onAliGetAuthorize('getPhoneNumber', $event)), b: _o($event => _ctx.$onAliAuthError('getPhoneNumber', $event)) }
return { a: _o($event => _ctx.$onAliGetAuthorize(_ctx.getPhoneNumber, $event)), b: _o($event => _ctx.$onAliAuthError(_ctx.getPhoneNumber, $event)) }
}`
)
assert(
`<button open-type='getPhoneNumber' @getphonenumber="getPhoneNumber($event)">获取手机号</button>`,
`<button open-type="getAuthorize" scope="phoneNumber" onGetAuthorize="{{a}}" onError="{{b}}">获取手机号</button>`,
`(_ctx, _cache) => {
return { a: _o($event => _ctx.$onAliGetAuthorize($event => { _ctx.getPhoneNumber($event); }, $event)), b: _o($event => _ctx.$onAliAuthError($event => { _ctx.getPhoneNumber($event); }, $event)) }
}`
)
})
......
......@@ -120,8 +120,11 @@ function transformOpenType(node) {
return;
}
props.splice(getPhoneNumberPropIndex, 1);
props.push(uniCliShared.createOnDirectiveNode('getAuthorize', `$onAliGetAuthorize('${getPhoneNumberMethodName}',$event)`));
props.push(uniCliShared.createOnDirectiveNode('error', `$onAliAuthError('${getPhoneNumberMethodName}',$event)`));
const method = compilerCore.isSimpleIdentifier(getPhoneNumberMethodName)
? getPhoneNumberMethodName
: `$event => { ${getPhoneNumberMethodName} }`;
props.push(uniCliShared.createOnDirectiveNode('getAuthorize', `$onAliGetAuthorize(${method},$event)`));
props.push(uniCliShared.createOnDirectiveNode('error', `$onAliAuthError(${method},$event)`));
}
const projectConfigFilename = 'mini.project.json';
......
......@@ -628,8 +628,8 @@ function initCreatePluginApp(parseAppOptions) {
function onAliAuthError(method, $event) {
$event.type = 'getphonenumber';
$event.detail.errMsg =
'getPhoneNumber:fail Error: ' +
$event.detail.errorMessage(this)[method]($event);
'getPhoneNumber:fail Error: ' + $event.detail.errorMessage;
method($event);
}
function onAliGetAuthorize(method, $event) {
my.getPhoneNumber({
......@@ -639,12 +639,12 @@ function onAliGetAuthorize(method, $event) {
$event.detail.errMsg = 'getPhoneNumber:ok';
$event.detail.encryptedData = response.response;
$event.detail.sign = response.sign;
this[method]($event);
method($event);
},
fail: (res) => {
$event.type = 'getphonenumber';
$event.detail.errMsg = 'getPhoneNumber:fail Error: ' + JSON.stringify(res);
this[method]($event);
method($event);
},
});
}
......
import {
findProp,
isSimpleIdentifier,
NodeTypes,
RootNode,
TemplateChildNode,
......@@ -49,16 +50,16 @@ export function transformOpenType(node: RootNode | TemplateChildNode) {
return
}
props.splice(getPhoneNumberPropIndex, 1)
const method = isSimpleIdentifier(getPhoneNumberMethodName)
? getPhoneNumberMethodName
: `$event => { ${getPhoneNumberMethodName} }`
props.push(
createOnDirectiveNode(
'getAuthorize',
`$onAliGetAuthorize('${getPhoneNumberMethodName}',$event)`
`$onAliGetAuthorize(${method},$event)`
)
)
props.push(
createOnDirectiveNode(
'error',
`$onAliAuthError('${getPhoneNumberMethodName}',$event)`
)
createOnDirectiveNode('error', `$onAliAuthError(${method},$event)`)
)
}
......@@ -4,18 +4,18 @@ import { MiniProgramAppOptions } from '@dcloudio/uni-mp-core'
function onAliAuthError(
this: ComponentPublicInstance,
method: string,
method: ($event: unknown) => void,
$event: any
) {
$event.type = 'getphonenumber'
$event.detail.errMsg =
'getPhoneNumber:fail Error: ' +
$event.detail.errorMessage(this as any)[method]($event)
'getPhoneNumber:fail Error: ' + $event.detail.errorMessage
method($event)
}
function onAliGetAuthorize(
this: ComponentPublicInstance,
method: string,
method: ($event: unknown) => void,
$event: any
) {
my.getPhoneNumber({
......@@ -25,12 +25,12 @@ function onAliGetAuthorize(
$event.detail.errMsg = 'getPhoneNumber:ok'
$event.detail.encryptedData = response.response
$event.detail.sign = response.sign
;(this as any)[method]($event)
method($event)
},
fail: (res) => {
$event.type = 'getphonenumber'
$event.detail.errMsg = 'getPhoneNumber:fail Error: ' + JSON.stringify(res)
;(this as any)[method]($event)
method($event)
},
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册