diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js
index cb4c00c72f72ed08e6d1021b72fc3fce8433a3b7..4422cf0ac790cd28f06ab52d8ebec0646a901f47 100644
--- a/packages/uni-app-plus/dist/index.v3.js
+++ b/packages/uni-app-plus/dist/index.v3.js
@@ -250,6 +250,10 @@ var serviceContext = (function () {
return typeof fn === 'function'
}
+ function isObject (obj) {
+ return obj !== null && typeof obj === 'object'
+ }
+
function isPlainObject (obj) {
return _toString.call(obj) === '[object Object]'
}
@@ -258,7 +262,7 @@ var serviceContext = (function () {
return hasOwnProperty.call(obj, key)
}
- function noop () { }
+ function noop () {}
function toRawType (val) {
return _toString.call(val).slice(8, -1)
@@ -2718,7 +2722,7 @@ var serviceContext = (function () {
}
return page.$page.meta.isTabBar
}
- const route = __uniRoutes.find(route => route.path.slice(1) === path);
+ const route = __uniRoutes.find(route => route.path.replace(/^\//, '') === path.replace(/^\//, ''));
return route && route.meta.isTabBar
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
@@ -12760,11 +12764,29 @@ var serviceContext = (function () {
return ((this._$newData[id] || (this._$newData[id] = {}))[name] = value)
}
+ function fillVForData (forItems, vForData) {
+ let i, l;
+ if (Array.isArray(forItems) || typeof forItems === 'string') {
+ for (i = 0, l = forItems.length; i < l; i++) {
+ vForData[i] = i;
+ }
+ } else if (typeof forItems === 'number') {
+ for (i = 0; i < forItems; i++) {
+ vForData[i] = i;
+ }
+ } else if (isObject(forItems)) {
+ for (i = 0, l = Object.keys(forItems).length; i < l; i++) {
+ vForData[i] = i;
+ }
+ }
+ }
+
function setForData (id, value) {
const diffData = this._$newData[id] || (this._$newData[id] = {});
const vForData = diffData[V_FOR] || (diffData[V_FOR] = []);
if (value.forItems) {
+ value.fill && fillVForData(value.forItems, vForData);
return value.forItems
}
diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
index 628cfa296a7d817c60089b80892295c7f65c78b3..9e7a6a4b37409ab306d2f8023dd64d787902e49a 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
@@ -44,11 +44,11 @@ describe('codegen', () => {
)
assertCodegen(
'
text
',
- `with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return void 0})],2)}`
+ `with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return void 0})],2)}`
)
assertCodegen(
'{{text}}
',
- `with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(text))))]})],2)}`
+ `with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(text))))]})],2)}`
)
assertCodegen(
'{{text}}
',
@@ -56,12 +56,20 @@ describe('codegen', () => {
)
assertCodegen(
'a {{text1}} b {{text2}}
',
- `with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(text1)))+(_$s(("1-"+$30),'t1',_s(text2))))]})],2)}`
+ `with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(text1)))+(_$s(("1-"+$30),'t1',_s(text2))))]})],2)}`
)
assertCodegen(
'
',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [(_$s(("2-"+$30),'i',item.sub))?_c('span',{key:_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}):_e()]})],2)}`
- )
+ )
+ assertCodegen(
+ '{{item}}',
+ `with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
+ )
+ assertCodegen(
+ '{{item}}',
+ `with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
+ )
})
it('generate text with multiple statements', () => {
assertCodegen(
diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
index 9d10884d487576f558145b9398d34026a6d7fab6..5db90d294529afdc6d571771762b55764713200a 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
@@ -625,7 +625,7 @@ describe('codegen', () => {
// normalize type: 2
assertCodegen(
'{{ item }}
',
- `with(this){return _c('div',[_c('child',{attrs:{"_i":1}}),_l((_$s(2,'f',{forItems:list})),function(item,$10,$20,$30){return [_v((_$s(("2-"+$30),'t0',_s(item))))]})],2)}`
+ `with(this){return _c('div',[_c('child',{attrs:{"_i":1}}),_l((_$s(2,'f',{forItems:list,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("2-"+$30),'t0',_s(item))))]})],2)}`
)
})
diff --git a/packages/uni-template-compiler/__tests__/demo.js b/packages/uni-template-compiler/__tests__/demo.js
index fafffcea99b028028869ea173d2c36e7e9423961..22f6166f53e3268e1733c13beddedd8483506afb 100644
--- a/packages/uni-template-compiler/__tests__/demo.js
+++ b/packages/uni-template-compiler/__tests__/demo.js
@@ -1,7 +1,7 @@
const compiler = require('../lib')
const res = compiler.compile(
`
-
+text
`, {
miniprogram: true,
resourcePath: '/User/fxy/Documents/test.wxml',
@@ -14,9 +14,9 @@ const res = compiler.compile(
mp: {
platform: 'mp-weixin'
},
- filterModules: ['swipe']
- // service: true,
- // view: true
+ filterModules: ['swipe'],
+ service: true,
+ view: true
})
console.log(require('util').inspect(res, {
diff --git a/packages/uni-template-compiler/lib/app/parser/base-parser.js b/packages/uni-template-compiler/lib/app/parser/base-parser.js
index 6896d0efa70a2cd6ce0c3823d5b1d3f298f82f40..30fe8da69b31c38529317bd2804d04c593cff67d 100644
--- a/packages/uni-template-compiler/lib/app/parser/base-parser.js
+++ b/packages/uni-template-compiler/lib/app/parser/base-parser.js
@@ -33,9 +33,14 @@ function parseIf (el, createGenVar, isScopedSlot) {
el.if = createGenVar(el.attrsMap[ID], isScopedSlot)(V_IF, el.if)
}
-function parseFor (el, createGenVar, isScopedSlot) {
+function parseFor (el, createGenVar, isScopedSlot, fill = false) {
if (el.for && isVar(el.for)) {
- el.for = createGenVar(el.forId, isScopedSlot)(V_FOR, `{forItems:${el.for}}`)
+ el.for = createGenVar(el.forId, isScopedSlot)(
+ V_FOR,
+ fill
+ ? `{forItems:${el.for},fill:true}`
+ : `{forItems:${el.for}}`
+ )
return true
}
}
diff --git a/packages/uni-template-compiler/lib/app/service.js b/packages/uni-template-compiler/lib/app/service.js
index 5a2cb13bf8c88a4853471bd413a680eec0df3d7d..4f07200c55d0ad5158f35e237fb2af68429b6dc3 100644
--- a/packages/uni-template-compiler/lib/app/service.js
+++ b/packages/uni-template-compiler/lib/app/service.js
@@ -85,6 +85,20 @@ function parseComponentAttrs (el, genVar) {
})
}
+function checkAutoFill (el) {
+ if (
+ el.for &&
+ (
+ el.tag === 'template' ||
+ el.tag === 'block'
+ ) &&
+ !el.children.find(child => child.type === 1)
+ ) {
+ return true
+ }
+ return false
+}
+
function transformNode (el, parent, state, isScopedSlot) {
if (el.type === 3) {
return
@@ -111,7 +125,7 @@ function transformNode (el, parent, state, isScopedSlot) {
const genVar = createGenVar(el.attrsMap[ID], isScopedSlot)
parseIs(el, genVar)
- parseFor(el, createGenVar, isScopedSlot)
+ parseFor(el, createGenVar, isScopedSlot, checkAutoFill(el))
parseKey(el, isScopedSlot)
parseIf(el, createGenVar, isScopedSlot)
diff --git a/packages/uni-template-compiler/lib/app/util.js b/packages/uni-template-compiler/lib/app/util.js
index 025483c627d617ce5d72bdb97b02497bac70580c..259a46b5d97e5cd7e58a53d3e2c42873b3278862 100644
--- a/packages/uni-template-compiler/lib/app/util.js
+++ b/packages/uni-template-compiler/lib/app/util.js
@@ -170,9 +170,15 @@ function processForKey (el) {
const keyIndex = forEl.children.indexOf(el)
el.key = `${forEl.forId}+'-${keyIndex}'+${it}`
} else { // 当 template 下只有文本节点
- if (el.children && el.children.length && !el.children.find(child => child.key)) {
+ if (
+ el.children &&
+ el.children.length &&
+ !el.children.find(child => child.type === 1)
+ ) {
el.children[0].parent = el
- el.children[0].key = `${forEl.forId}+'-0'+${it}`
+ if (!el.children.find(child => child.key)) {
+ el.children[0].key = `${forEl.forId}+'-0'+${it}`
+ }
return true
}
}
@@ -219,8 +225,6 @@ function removeRawAttr (el, name) {
function removeRawBindingAttr (el, name) {
removeRawAttr(el, ':' + name)
removeRawAttr(el, 'v-bind:' + name)
- console.log(el)
- throw new Error('123')
}
function addHandler (el, name, value, important) {
diff --git a/src/platforms/app-plus/service/bridge.js b/src/platforms/app-plus/service/bridge.js
index 79f6ab6e117b26e29a4437a23b6f7c307d3e287f..5da78e31d329b67d26144630ab466714c795671e 100644
--- a/src/platforms/app-plus/service/bridge.js
+++ b/src/platforms/app-plus/service/bridge.js
@@ -71,7 +71,7 @@ export function isTabBarPage (path = '') {
}
return page.$page.meta.isTabBar
}
- const route = __uniRoutes.find(route => route.path.slice(1) === path)
+ const route = __uniRoutes.find(route => route.path.replace(/^\//, '') === path.replace(/^\//, ''))
return route && route.meta.isTabBar
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
diff --git a/src/platforms/app-plus/service/framework/plugins/data.js b/src/platforms/app-plus/service/framework/plugins/data.js
index bebdde124a4645e7fda9c065e4ee6f6995f84db2..d6535f0e67b245ffc4527de6753ec8e430bb5b47 100644
--- a/src/platforms/app-plus/service/framework/plugins/data.js
+++ b/src/platforms/app-plus/service/framework/plugins/data.js
@@ -1,6 +1,7 @@
import {
guid,
hasOwn,
+ isObject,
camelize
} from 'uni-shared'
@@ -164,11 +165,29 @@ function setData (id, name, value) {
return ((this._$newData[id] || (this._$newData[id] = {}))[name] = value)
}
+function fillVForData (forItems, vForData) {
+ let i, l
+ if (Array.isArray(forItems) || typeof forItems === 'string') {
+ for (i = 0, l = forItems.length; i < l; i++) {
+ vForData[i] = i
+ }
+ } else if (typeof forItems === 'number') {
+ for (i = 0; i < forItems; i++) {
+ vForData[i] = i
+ }
+ } else if (isObject(forItems)) {
+ for (i = 0, l = Object.keys(forItems).length; i < l; i++) {
+ vForData[i] = i
+ }
+ }
+}
+
function setForData (id, value) {
const diffData = this._$newData[id] || (this._$newData[id] = {})
const vForData = diffData[V_FOR] || (diffData[V_FOR] = [])
if (value.forItems) {
+ value.fill && fillVForData(value.forItems, vForData)
return value.forItems
}
diff --git a/src/platforms/h5/components/system-routes/open-location/index.vue b/src/platforms/h5/components/system-routes/open-location/index.vue
index 2c8113e7fa45833fc37c9218a8e54da50ed98c49..9a4a8b28dd7a8f5c838ede01dd7f3804e93d062d 100644
--- a/src/platforms/h5/components/system-routes/open-location/index.vue
+++ b/src/platforms/h5/components/system-routes/open-location/index.vue
@@ -70,7 +70,7 @@ export default {
},
_nav () {
var url =
- `https://apis.map.qq.com/uri/v1/routeplan?type=drive&to=${encodeURIComponent(this.name)}&tocoord=${this.latitude},${this.longitude}&referer=${referer}`
+ `https://apis.map.qq.com/uri/v1/routeplan?type=drive&to=${encodeURIComponent(this.name || '目的地')}&tocoord=${this.latitude},${this.longitude}&referer=${referer}`
this.$refs.map.src = url
}
}
diff --git a/src/shared/util.js b/src/shared/util.js
index e820cda160a8d2271baf58bf34f2e318e73e5a1d..8467221552981532e80d04dd2121068f25a414b3 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -13,6 +13,10 @@ export function isStr (str) {
return typeof str === 'string'
}
+export function isObject (obj) {
+ return obj !== null && typeof obj === 'object'
+}
+
export function isPlainObject (obj) {
return _toString.call(obj) === '[object Object]'
}
@@ -21,7 +25,7 @@ export function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}
-export function noop () { }
+export function noop () {}
export function toRawType (val) {
return _toString.call(val).slice(8, -1)
@@ -91,4 +95,4 @@ export function debounce (fn, delay) {
export function kebabCase (string) {
return string.replace(/[A-Z]/g, str => '-' + str.toLowerCase())
-}
+}