提交 e55d8d97 编写于 作者: Q qiang

Merge branch 'dev' into alpha

...@@ -10,15 +10,16 @@ ...@@ -10,15 +10,16 @@
**OBJECT参数说明:** **OBJECT参数说明:**
|属性|类型|默认值|必填|说明| |属性|类型|默认值|必填|说明|平台差异|
|:-|:-|:-|:-|:-| |:-|:-|:-|:-|:-|:-|
|index|number||是|tabBar 的哪一项,从左边算起| |index|number||是|tabBar 的哪一项,从左边算起||
|text|String||否|tab 上的按钮文字| |text|String||否|tab 上的按钮文字||
|iconPath|String||否|图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片| |iconPath|String||否|图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片||
|selectedIconPath|String||否|选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效| |selectedIconPath|String||否|选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效||
|success|Funtion||否|接口调用成功的回调函数| |pagePath|String||否|页面绝对路径,必须在 [pages](/collocation/pages?id=pages) 中先定义|App(2.8.4+)、H5(2.8.4+)|
|fail|Funtion||否|接口调用失败的回调函数| |success|Funtion||否|接口调用成功的回调函数||
|complete|Funtion||否|接口调用结束的回调函数(调用成功、失败都会执行)| |fail|Funtion||否|接口调用失败的回调函数||
|complete|Funtion||否|接口调用结束的回调函数(调用成功、失败都会执行)||
**示例代码** **示例代码**
......
const compiler = require('../lib') const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) { function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
const res = compiler.compile(template, { const res = compiler.compile(template, {
resourcePath: 'test.wxml', resourcePath: 'test.wxml',
mp: Object.assign({ mp: Object.assign({
minified: true, minified: true,
isTest: true, isTest: true,
platform: 'mp-toutiao' platform: 'mp-toutiao'
}, options) }, options)
...@@ -20,13 +20,13 @@ describe('mp:compiler-mp-toutiao', () => { ...@@ -20,13 +20,13 @@ describe('mp:compiler-mp-toutiao', () => {
'<view><view v-for="(item,index) in items" :key="index"></view></view>', '<view><view v-for="(item,index) in items" :key="index"></view></view>',
'<view><block tt:for="{{items}}" tt:for-item="item" tt:for-index="index" tt:key="index"><view></view></block></view>' '<view><block tt:for="{{items}}" tt:for-item="item" tt:for-index="index" tt:key="index"><view></view></block></view>'
) )
}) })
it('generate ref', () => { it('generate ref', () => {
assertCodegen( assertCodegen(
'<my-component ref="ref"></my-component>', '<my-component ref="ref"></my-component>',
'<my-component class="vue-ref" vue-id="551070e6-1" data-ref="ref" bind:__l="__l"></my-component>' '<my-component class="vue-ref" vue-id="551070e6-1" data-ref="ref" bind:__l="__l"></my-component>'
) )
}) })
it('generate class binding', () => { it('generate class binding', () => {
...@@ -49,10 +49,10 @@ describe('mp:compiler-mp-toutiao', () => { ...@@ -49,10 +49,10 @@ describe('mp:compiler-mp-toutiao', () => {
assertCodegen( assertCodegen(
'<p class="static" :class="[{ active: isActive }, errorClass]">5</p>', '<p class="static" :class="[{ active: isActive }, errorClass]">5</p>',
'<view class="{{(((\'static _p\')+\' \'+[(isActive)?\'active\':\'\'])+\' \'+errorClass)}}">5</view>' '<view class="{{(((\'static _p\')+\' \'+[(isActive)?\'active\':\'\'])+\' \'+errorClass)}}">5</view>'
) )
assertCodegen( assertCodegen(
'<div class="container" :class="computedClassObject">6</div>', '<div class="container" :class="computedClassObject">6</div>',
'<view class="{{((\'container _div\')+\' \'+computedClassObject)}}">6</view>' '<view class="{{((\'container _div\')+\' \'+computedClassObject)}}">6</view>'
) )
// assertCodegen( // assertCodegen(
// `<div class="container" :class="computedClassObject">6</div>`, // `<div class="container" :class="computedClassObject">6</div>`,
...@@ -72,4 +72,11 @@ describe('mp:compiler-mp-toutiao', () => { ...@@ -72,4 +72,11 @@ describe('mp:compiler-mp-toutiao', () => {
'<view class="{{((\'bg _p\')+\' \'+(classStr1||classStr2))}}">9</view>' '<view class="{{((\'bg _p\')+\' \'+(classStr1||classStr2))}}">9</view>'
) )
}) })
it('generate v-show directive', () => {
assertCodegen(
'<test v-show="shown">hello world</test>',
'<test bind:-data-custom-hidden="{{!(shown)}}" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}">hello world</test>'
)
})
}) })
...@@ -132,4 +132,11 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -132,4 +132,11 @@ describe('mp:compiler-mp-weixin', () => {
) )
assertCodegen('<test :obj="{x:0}"></test>', '<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>') assertCodegen('<test :obj="{x:0}"></test>', '<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>')
}) })
it('generate v-show directive', () => {
assertCodegen(
'<test v-show="shown">hello world</test>',
'<test data-custom-hidden="{{!(shown)}}" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}">hello world</test>'
)
})
}) })
...@@ -63,6 +63,7 @@ module.exports = { ...@@ -63,6 +63,7 @@ module.exports = {
ATTR_DATA_EVENT_OPTS: 'data-event-opts', ATTR_DATA_EVENT_OPTS: 'data-event-opts',
ATTR_DATA_COM_TYPE: 'data-com-type', ATTR_DATA_COM_TYPE: 'data-com-type',
ATTR_DATA_EVENT_PARAMS: 'data-event-params', ATTR_DATA_EVENT_PARAMS: 'data-event-params',
ATTE_DATA_CUSTOM_HIDDEN: 'data-custom-hidden',
INTERNAL_GET_ORIG, INTERNAL_GET_ORIG,
INTERNAL_GET_CLASS, INTERNAL_GET_CLASS,
INTERNAL_GET_STYLE, INTERNAL_GET_STYLE,
......
...@@ -9,9 +9,14 @@ const { ...@@ -9,9 +9,14 @@ const {
genCode, genCode,
getCode, getCode,
getForKey, getForKey,
traverseKey traverseKey,
isComponent
} = require('../util') } = require('../util')
const {
ATTE_DATA_CUSTOM_HIDDEN
} = require('../constants')
module.exports = function traverse (ast, state = {}) { module.exports = function traverse (ast, state = {}) {
babelTraverse(ast, { babelTraverse(ast, {
WithStatement (path) { WithStatement (path) {
...@@ -222,7 +227,17 @@ function traverseDataNode (dataNode, state, node) { ...@@ -222,7 +227,17 @@ function traverseDataNode (dataNode, state, node) {
objectExpression.properties.find(valueProperty => { objectExpression.properties.find(valueProperty => {
const isValue = valueProperty.key.name === 'value' const isValue = valueProperty.key.name === 'value'
if (isValue) { if (isValue) {
ret.hidden = genCode(valueProperty.value, false, true) let key
// 自定义组件不支持 hidden 属性
const platform = state.options.platform.name
const platforms = ['mp-weixin', 'mp-qq', 'mp-toutiao']
if (isComponent(node.type) && platforms.includes(platform)) {
// 字节跳动小程序自定义属性不会反应在DOM上,只能使用事件格式
key = `${platform === 'mp-toutiao' ? 'bind:-' : ''}${ATTE_DATA_CUSTOM_HIDDEN}`
} else {
key = 'hidden'
}
ret[key] = genCode(valueProperty.value, false, true)
} }
return isValue return isValue
}) })
......
...@@ -45,6 +45,11 @@ module.exports = function generateApp (compilation) { ...@@ -45,6 +45,11 @@ module.exports = function generateApp (compilation) {
} }
} }
// 框架预设样式 用于隐藏自定义组件
// TODO 分平台 import 不同 css
const platforms = ['mp-weixin', 'mp-qq', 'mp-toutiao']
const presetStyle = platforms.includes(process.env.UNI_PLATFORM) ? '[data-custom-hidden="true"],[bind-data-custom-hidden="true"]{display: none !important;}' : ''
if (compilation.assets[`common/main${ext}`]) { // 是否存在 main.css if (compilation.assets[`common/main${ext}`]) { // 是否存在 main.css
importMainCss = `@import './common/main${ext}';` importMainCss = `@import './common/main${ext}';`
} }
...@@ -54,23 +59,23 @@ module.exports = function generateApp (compilation) { ...@@ -54,23 +59,23 @@ module.exports = function generateApp (compilation) {
} }
const runtimeJsPath = 'common/runtime.js' const runtimeJsPath = 'common/runtime.js'
const asset = compilation.assets[runtimeJsPath] const asset = compilation.assets[runtimeJsPath]
if ( // app 和 baidu 不需要 if ( // app 和 baidu 不需要
process.env.UNI_PLATFORM !== 'app-plus' && process.env.UNI_PLATFORM !== 'app-plus' &&
process.env.UNI_PLATFORM !== 'mp-baidu' && process.env.UNI_PLATFORM !== 'mp-baidu' &&
asset && asset &&
!asset.source.__$wrappered !asset.source.__$wrappered
) { ) {
const source = const source =
` `
!function(){try{var a=Function("return this")();a&&!a.Math&&(Object.assign(a,{isFinite:isFinite,Array:Array,Date:Date,Error:Error,Function:Function,Math:Math,Object:Object,RegExp:RegExp,String:String,TypeError:TypeError,setTimeout:setTimeout,clearTimeout:clearTimeout,setInterval:setInterval,clearInterval:clearInterval}),"undefined"!=typeof Reflect&&(a.Reflect=Reflect))}catch(a){}}(); !function(){try{var a=Function("return this")();a&&!a.Math&&(Object.assign(a,{isFinite:isFinite,Array:Array,Date:Date,Error:Error,Function:Function,Math:Math,Object:Object,RegExp:RegExp,String:String,TypeError:TypeError,setTimeout:setTimeout,clearTimeout:clearTimeout,setInterval:setInterval,clearInterval:clearInterval}),"undefined"!=typeof Reflect&&(a.Reflect=Reflect))}catch(a){}}();
${asset.source()} ${asset.source()}
` `
const newSource = function () { const newSource = function () {
return source return source
} }
newSource.__$wrappered = true newSource.__$wrappered = true
compilation.assets[runtimeJsPath].source = newSource compilation.assets[runtimeJsPath].source = newSource
} }
...@@ -90,6 +95,7 @@ require('./common/main.js')` ...@@ -90,6 +95,7 @@ require('./common/main.js')`
}, { }, {
file: 'app' + ext, file: 'app' + ext,
source: `${importMainCss} source: `${importMainCss}
${importVendorCss}` ${importVendorCss}
${presetStyle}`
}] }]
} }
...@@ -18,6 +18,9 @@ export const setTabBarItem = { ...@@ -18,6 +18,9 @@ export const setTabBarItem = {
}, },
selectedIconPath: { selectedIconPath: {
type: String type: String
},
pagePath: {
type: String
} }
} }
......
...@@ -281,9 +281,8 @@ export default { ...@@ -281,9 +281,8 @@ export default {
if (this.skipMatcher) { if (this.skipMatcher) {
return delta return delta
} }
return { delta.ops = delta.ops.filter(({ insert }) => typeof insert === 'string').map(({ insert }) => ({ insert }))
ops: delta.ops.filter(({ insert }) => typeof insert === 'string').map(({ insert }) => ({ insert })) return delta
}
}) })
this.initKeyboard($el) this.initKeyboard($el)
this.quillReady = true this.quillReady = true
......
...@@ -19,14 +19,21 @@ export function setTabBarItem ({ ...@@ -19,14 +19,21 @@ export function setTabBarItem ({
index, index,
text, text,
iconPath, iconPath,
selectedIconPath selectedIconPath,
pagePath
}) { }) {
if (!isTabBarPage()) { tabBar.setTabBarItem(index, text, iconPath, selectedIconPath)
return { const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath)
errMsg: 'setTabBarItem:fail not TabBar page' if (route) {
const meta = route.meta
meta.isTabBar = true
meta.tabBarIndex = index
meta.isQuit = true
const tabBar = __uniConfig.tabBar
if (tabBar && tabBar.list && tabBar.list[index]) {
tabBar.list[index].pagePath = pagePath.startsWith('/') ? pagePath.substring(1) : pagePath
} }
} }
tabBar.setTabBarItem(index, text, iconPath, selectedIconPath)
return { return {
errMsg: 'setTabBarItem:ok' errMsg: 'setTabBarItem:ok'
} }
......
...@@ -43,9 +43,22 @@ function setTabBar (type, args = {}) { ...@@ -43,9 +43,22 @@ function setTabBar (type, args = {}) {
case 'hideTabBar': case 'hideTabBar':
app.$children[0].hideTabBar = true app.$children[0].hideTabBar = true
break break
case 'setTabBarItem': case 'setTabBarItem': {
setProperties(tabBar.list[index], setTabBarItemProps, args) setProperties(tabBar.list[index], setTabBarItemProps, args)
const pagePath = args.pagePath
const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath)
if (route) {
const meta = route.meta
meta.isTabBar = true
meta.tabBarIndex = index
meta.isQuit = true
const tabBar = __uniConfig.tabBar
if (tabBar && tabBar.list && tabBar.list[index]) {
tabBar.list[index].pagePath = pagePath.startsWith('/') ? pagePath.substring(1) : pagePath
}
}
break break
}
case 'setTabBarStyle': case 'setTabBarStyle':
setProperties(tabBar, setTabBarStyleProps, args) setProperties(tabBar, setTabBarStyleProps, args)
break break
......
...@@ -126,6 +126,14 @@ export default function parseComponent (vueComponentOptions) { ...@@ -126,6 +126,14 @@ export default function parseComponent (vueComponentOptions) {
componentOptions.deriveDataFromProps = createObserver() componentOptions.deriveDataFromProps = createObserver()
} else { } else {
componentOptions.didUpdate = createObserver(true) componentOptions.didUpdate = createObserver(true)
}
if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => {
componentOptions.methods[callMethod] = function (args) {
return this.$vm[callMethod](args)
}
})
} }
return componentOptions return componentOptions
......
...@@ -77,6 +77,14 @@ export default function parsePage (vuePageOptions) { ...@@ -77,6 +77,14 @@ export default function parsePage (vuePageOptions) {
} }
initHooks(pageOptions, hooks, vuePageOptions) initHooks(pageOptions, hooks, vuePageOptions)
if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => {
pageOptions[callMethod] = function (args) {
return this.$vm[callMethod](args)
}
})
}
return pageOptions return pageOptions
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册