Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
Chameleon
提交
be2a2e33
C
Chameleon
项目概览
DiDi
/
Chameleon
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Chameleon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
be2a2e33
编写于
1月 21, 2019
作者:
G
gaozhenze
提交者:
quyatong
1月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support alipay program
上级
8d33ec4c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
161 addition
and
107 deletion
+161
-107
packages/chameleon-mixins/alipay-mixins.js
packages/chameleon-mixins/alipay-mixins.js
+23
-0
packages/chameleon-mixins/wx-alipay-common-mixins.js
packages/chameleon-mixins/wx-alipay-common-mixins.js
+116
-0
packages/chameleon-mixins/wx-mixins.js
packages/chameleon-mixins/wx-mixins.js
+9
-107
packages/chameleon-template-parse/src/compile-template-cml.js
...ages/chameleon-template-parse/src/compile-template-cml.js
+1
-0
packages/chameleon-template-parse/src/parser/index.js
packages/chameleon-template-parse/src/parser/index.js
+12
-0
未找到文件。
packages/chameleon-mixins/alipay-mixins.js
0 → 100644
浏览文件 @
be2a2e33
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
packages/chameleon-mixins/wx-alipay-common-mixins.js
0 → 100644
浏览文件 @
be2a2e33
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
;
}
packages/chameleon-mixins/wx-mixins.js
浏览文件 @
be2a2e33
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
;
}
});
packages/chameleon-template-parse/src/compile-template-cml.js
浏览文件 @
be2a2e33
...
...
@@ -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"
...
...
packages/chameleon-template-parse/src/parser/index.js
浏览文件 @
be2a2e33
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录