提交 be2a2e33 编写于 作者: G gaozhenze 提交者: quyatong

support alipay program

上级 8d33ec4c
const commonMixins = require('./wx-alipay-common-mixins.js');
var _ = module.exports = commonMixins.deepClone(commonMixins);
commonMixins.merge(_, {
cmlPropsEventProxy: {
key: "onCmlPropsEventProxy",
value: "_cmlPropsEventProxy"
}
})
commonMixins.merge(_.mixins.methods, {
[_.eventEmitName]: function(eventKey, detail) {
let eventKeyProps = this.props["data-event" + eventKey];
eventKeyProps && this.props[_.cmlPropsEventProxy.key](eventKeyProps, detail);
if (this.$__checkCmlEmit__) {
this.$__checkCmlEmit__(eventKey, detail);
}
},
[_.cmlPropsEventProxy.value](eventName, value){
this[eventName] && this[eventName]({
detail: value
});
}
});
\ No newline at end of file
const common = require('./common.js');
const wxStyleHandle = require('chameleon-css-loader/proxy/proxyMiniapp.js')
const deepClone = function(obj){
if(obj.toString().slice(8, -1) !== "Object"){
return obj;
}
let res = {};
Object.keys(obj).forEach(key=>{
res[key] = deepClone(obj[key]);
})
return res;
}
var _ = module.exports = { deepClone };
common.merge(_, common);
_.mixins = {
methods: {
// 支持事件传参
[_.inlineStatementEventProxy](e) {
let { dataset } = e.currentTarget;
let originFuncName = dataset && dataset[`event${e.type}`];
let argsStr = dataset && dataset.args;
let argsArr = argsStr.split(',').reduce((result, item, index) => {
let arg = dataset[`arg${index}`];
if (arg === "$event") {
let newEvent = getNewEvent(e);
result.push(newEvent);
} else {
// 这里的值微信已经计算好了;到dateset的时候已经是计算的结果 比如msg = 'sss' data-arg1="{{msg + 1}}"
// dataset[arg1] = 'sss1'
result.push(dataset[`arg${index}`])
}
return result;
}, []);
if (originFuncName && this[originFuncName] && _.isType(this[originFuncName], 'Function')) {
this[originFuncName](...argsArr)
} else {
console.log(`can not find method ${originFuncName}`)
}
},
[_.modelEventProxyName](e) {
let { dataset } = e.currentTarget;
let modelKey = dataset && dataset.modelkey
this[modelKey] = e.detail.value;
},
[_.eventProxyName](e) {
let { dataset } = e.currentTarget;
let originFuncName = dataset && dataset[`event${e.type}`]
if (originFuncName && this[originFuncName] && _.isType(this[originFuncName], 'Function')) {
let newEvent = getNewEvent(e);
this[originFuncName](newEvent)
} else {
console.log(`can not find method ${originFuncName}`)
}
},
[_.styleParseName](content) {
let res = ''
if (_.isType(content, 'Object')) {
Object.keys(content).forEach(key => {
res += `${key}:${content[key]};`
})
} else if (_.isType(content, 'String')) {
res = content;
}
return wxStyleHandle(res);
},
[_.mergeStyleName](...args) {
return _.mergeStyle(...args);
},
[_.animationProxy](...args) {
let animationValue = args[0];
// animationValue:{cbs:{0:cb0,1:cb1,length:2},index}
let animation = this[animationValue];// 引用值
if (!animation) {
return ;
}
const { cbs, index } = animation;
let cb = cbs[index];
if (cb && typeof cb === 'function') {
cb();
}
delete animation.index;
animation.index = index + 1;
}
}
}
function getNewEvent(e) {
let newEvent = {};
['type', 'timeStamp', 'target', 'currentTarget', 'detail', 'touches', 'changedTouches'].forEach((key) => {
if (e[key]) {
if (~['target', 'currentTarget'].indexOf(key)) {
let newTarget = {}
newTarget = {
id: e[key].id,
dataset: e[key].dataset
}
newEvent[key] = newTarget
} else {
newEvent[key] = e[key]
}
}
})
newEvent._originEvent = e;
return newEvent;
}
const common = require('./common.js');
const wxStyleHandle = require('chameleon-css-loader/proxy/proxyMiniapp.js')
const _ = module.exports = {};
common.merge(_, common);
_.mixins = {
methods: {
// 支持事件传参
[_.inlineStatementEventProxy](e) {
let { dataset } = e.currentTarget;
let originFuncName = dataset && dataset[`event${e.type}`];
let argsStr = dataset && dataset.args;
let argsArr = argsStr.split(',').reduce((result, item, index) => {
let arg = dataset[`arg${index}`];
if (arg === "$event") {
let newEvent = getNewEvent(e);
result.push(newEvent);
} else {
// 这里的值微信已经计算好了;到dateset的时候已经是计算的结果 比如msg = 'sss' data-arg1="{{msg + 1}}"
// dataset[arg1] = 'sss1'
result.push(dataset[`arg${index}`])
}
return result;
}, []);
if (originFuncName && this[originFuncName] && _.isType(this[originFuncName], 'Function')) {
this[originFuncName](...argsArr)
} else {
console.log(`can not find method ${originFuncName}`)
}
},
[_.modelEventProxyName](e) {
let { dataset } = e.currentTarget;
let modelKey = dataset && dataset.modelkey
this[modelKey] = e.detail.value;
},
[_.eventProxyName](e) {
let { dataset } = e.currentTarget;
let originFuncName = dataset && dataset[`event${e.type}`]
if (originFuncName && this[originFuncName] && _.isType(this[originFuncName], 'Function')) {
let newEvent = getNewEvent(e);
this[originFuncName](newEvent)
} else {
console.log(`can not find method ${originFuncName}`)
}
},
[_.eventEmitName](eventKey, detail) {
this.triggerEvent(eventKey, detail);
if (this.$__checkCmlEmit__) {
this.$__checkCmlEmit__(eventKey, detail);
}
},
[_.styleParseName](content) {
let res = ''
if (_.isType(content, 'Object')) {
Object.keys(content).forEach(key => {
res += `${key}:${content[key]};`
})
} else if (_.isType(content, 'String')) {
res = content;
}
return wxStyleHandle(res);
},
[_.mergeStyleName](...args) {
return _.mergeStyle(...args);
},
[_.animationProxy](...args) {
let animationValue = args[0];
// animationValue:{cbs:{0:cb0,1:cb1,length:2},index}
let animation = this[animationValue];// 引用值
if (!animation) {
return ;
}
const { cbs, index } = animation;
let cb = cbs[index];
if (cb && typeof cb === 'function') {
cb();
}
delete animation.index;
animation.index = index + 1;
const commonMixins = require('./wx-alipay-common-mixins.js');
var _ = module.exports = commonMixins.deepClone(commonMixins);
commonMixins.merge(_.mixins.methods, {
[_.eventEmitName]: function(eventKey, detail) {
this.triggerEvent(eventKey, detail);
if (this.$__checkCmlEmit__) {
this.$__checkCmlEmit__(eventKey, detail);
}
}
}
function getNewEvent(e) {
let newEvent = {};
['type', 'timeStamp', 'target', 'currentTarget', 'detail', 'touches', 'changedTouches'].forEach((key) => {
if (e[key]) {
if (~['target', 'currentTarget'].indexOf(key)) {
let newTarget = {}
newTarget = {
id: e[key].id,
dataset: e[key].dataset
}
newEvent[key] = newTarget
} else {
newEvent[key] = e[key]
}
}
})
newEvent._originEvent = e;
return newEvent;
}
});
......@@ -167,6 +167,7 @@ function compileAliPayTemplate(source, type, options) {
parseTemplate.afterParseTag(path, type, options);
parseTemplate.parseConditionalStatement(path, type, options);// 替换c-if c-else
parseTemplate.parseAddAliEventProps(path, type, options);
parseTemplate.parseEventListener(path, type, options);
// 解析c-model ==> value="{{modelValue}}" bindinput="_cmlModelEventProxy($event) data-modelkey="modelKey"
......
......@@ -11,6 +11,8 @@ const {parseDirective} = require('./parse-directive.js');
const {parseClass} = require('./parse-class.js');
const {parseRef} = require('./parse-ref.js');
const {parseTextContent} = require('./parse-text-content.js');
const alipayMixins = require('chameleon-mixins/alipay-mixins.js');
const {
tagMap
} = require('../common/cml-map.js')
......@@ -129,6 +131,16 @@ exports.parseEventListener = function parseEventListener(path, type, options) {
parseEvent.call({path, type, node, options})
}
}
exports.parseAddAliEventProps = function parseAddAliEventProps(path, type, options) {
let node = path.node;
if (t.isJSXElement(node)) {
let attributes = node.openingElement.attributes || [];
let hasEventBind = attributes.find((attr) => (t.isJSXNamespacedName(attr.name) && attr.name.namespace.name === 'c-bind'));
if (hasEventBind) {
attributes.push(t.jsxAttribute(t.jsxIdentifier(alipayMixins.cmlPropsEventProxy.key), t.stringLiteral(alipayMixins.cmlPropsEventProxy.value)));
}
}
}
// 只支持数组,小程序不支持对象的for循环;
// web weex wx 只处理cml语法 c-for
exports.parseIterationStatement = function parseIterationStatement(path, type, options) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册