提交 f20a6cad 编写于 作者: M mehaotian

Merge branch 'v3' of https://github.com/dcloudio/uni-app into v3

...@@ -12,5 +12,5 @@ ...@@ -12,5 +12,5 @@
"message": "chore(release): publish %s" "message": "chore(release): publish %s"
} }
}, },
"version": "3.0.0-alpha-24020191018012" "version": "3.0.0-alpha-24020191018019"
} }
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"release": "npm run lint:cli && lerna publish --force-publish=*", "release": "npm run lint:cli && lerna publish --force-publish=*",
"release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha", "release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next", "release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:v3": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=v3" "release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3"
}, },
"dependencies": { "dependencies": {
"base64-arraybuffer": "^0.2.0", "base64-arraybuffer": "^0.2.0",
......
{ {
"name": "@dcloudio/uni-app-plus-nvue", "name": "@dcloudio/uni-app-plus-nvue",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app app-plus-nvue", "description": "uni-app app-plus-nvue",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
...@@ -3173,7 +3173,7 @@ var serviceContext = (function () { ...@@ -3173,7 +3173,7 @@ var serviceContext = (function () {
return invokeVmMethodWithoutArgs(ctx, 'pause') return invokeVmMethodWithoutArgs(ctx, 'pause')
}, },
seek (ctx, args) { seek (ctx, args) {
return invokeVmMethod(ctx, 'seek', args) return invokeVmMethod(ctx, 'seek', args.position)
}, },
stop (ctx) { stop (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'stop') return invokeVmMethodWithoutArgs(ctx, 'stop')
...@@ -3182,7 +3182,7 @@ var serviceContext = (function () { ...@@ -3182,7 +3182,7 @@ var serviceContext = (function () {
return invokeVmMethod(ctx, 'sendDanmu', args) return invokeVmMethod(ctx, 'sendDanmu', args)
}, },
playbackRate (ctx, args) { playbackRate (ctx, args) {
return invokeVmMethod(ctx, 'playbackRate', args) return invokeVmMethod(ctx, 'playbackRate', args.rate)
}, },
requestFullScreen (ctx, args) { requestFullScreen (ctx, args) {
return invokeVmMethod(ctx, 'requestFullScreen', args) return invokeVmMethod(ctx, 'requestFullScreen', args)
...@@ -7999,7 +7999,7 @@ var serviceContext = (function () { ...@@ -7999,7 +7999,7 @@ var serviceContext = (function () {
createMapContext: createMapContext$1 createMapContext: createMapContext$1
}); });
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5]; const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0];
function operateVideoPlayer$3 (videoId, pageVm, type, data) { function operateVideoPlayer$3 (videoId, pageVm, type, data) {
invokeMethod('operateVideoPlayer', videoId, pageVm, type, data); invokeMethod('operateVideoPlayer', videoId, pageVm, type, data);
...@@ -8021,8 +8021,8 @@ var serviceContext = (function () { ...@@ -8021,8 +8021,8 @@ var serviceContext = (function () {
operateVideoPlayer$3(this.id, this.pageVm, 'stop'); operateVideoPlayer$3(this.id, this.pageVm, 'stop');
} }
seek (position) { seek (position) {
operateVideoPlayer$3(this.id, this.pageVm, 'seek', { operateVideoPlayer$3(this.id, this.pageVm, 'seek', {
position position
}); });
} }
sendDanmu (args) { sendDanmu (args) {
...@@ -8032,12 +8032,12 @@ var serviceContext = (function () { ...@@ -8032,12 +8032,12 @@ var serviceContext = (function () {
if (!~RATES.indexOf(rate)) { if (!~RATES.indexOf(rate)) {
rate = 1.0; rate = 1.0;
} }
operateVideoPlayer$3(this.id, this.pageVm, 'playbackRate', { operateVideoPlayer$3(this.id, this.pageVm, 'playbackRate', {
rate rate
}); });
} }
requestFullScreen () { requestFullScreen (args = {}) {
operateVideoPlayer$3(this.id, this.pageVm, 'requestFullScreen'); operateVideoPlayer$3(this.id, this.pageVm, 'requestFullScreen', args);
} }
exitFullScreen () { exitFullScreen () {
operateVideoPlayer$3(this.id, this.pageVm, 'exitFullScreen'); operateVideoPlayer$3(this.id, this.pageVm, 'exitFullScreen');
......
...@@ -695,7 +695,13 @@ var uid = 0; ...@@ -695,7 +695,13 @@ var uid = 0;
* directives subscribing to it. * directives subscribing to it.
*/ */
var Dep = function Dep () { var Dep = function Dep () {
this.id = uid++; // fixed by xxxxxx (nvue vuex)
/* eslint-disable no-undef */
if(typeof SharedObject !== 'undefined'){
this.id = SharedObject.uid++;
} else {
this.id = uid++;
}
this.subs = []; this.subs = [];
}; };
...@@ -708,8 +714,8 @@ Dep.prototype.removeSub = function removeSub (sub) { ...@@ -708,8 +714,8 @@ Dep.prototype.removeSub = function removeSub (sub) {
}; };
Dep.prototype.depend = function depend () { Dep.prototype.depend = function depend () {
if (Dep.target) { if (Dep.SharedObject.target) { // fixed by xxxxxx
Dep.target.addDep(this); Dep.SharedObject.target.addDep(this);
} }
}; };
...@@ -730,17 +736,20 @@ Dep.prototype.notify = function notify () { ...@@ -730,17 +736,20 @@ Dep.prototype.notify = function notify () {
// The current target watcher being evaluated. // The current target watcher being evaluated.
// This is globally unique because only one watcher // This is globally unique because only one watcher
// can be evaluated at a time. // can be evaluated at a time.
Dep.target = null; // fixed by xxxxxx (nvue shared vuex)
var targetStack = []; /* eslint-disable no-undef */
Dep.SharedObject = typeof SharedObject !== 'undefined' ? SharedObject : {};
Dep.SharedObject.target = null;
Dep.SharedObject.targetStack = [];
function pushTarget (target) { function pushTarget (target) {
targetStack.push(target); Dep.SharedObject.targetStack.push(target);
Dep.target = target; Dep.SharedObject.target = target;
} }
function popTarget () { function popTarget () {
targetStack.pop(); Dep.SharedObject.targetStack.pop();
Dep.target = targetStack[targetStack.length - 1]; Dep.SharedObject.target = Dep.SharedObject.targetStack[Dep.SharedObject.targetStack.length - 1];
} }
/* */ /* */
...@@ -1019,7 +1028,7 @@ function defineReactive$$1 ( ...@@ -1019,7 +1028,7 @@ function defineReactive$$1 (
configurable: true, configurable: true,
get: function reactiveGetter () { get: function reactiveGetter () {
var value = getter ? getter.call(obj) : val; var value = getter ? getter.call(obj) : val;
if (Dep.target) { if (Dep.SharedObject.target) { // fixed by xxxxxx
dep.depend(); dep.depend();
if (childOb) { if (childOb) {
childOb.dep.depend(); childOb.dep.depend();
...@@ -4843,7 +4852,7 @@ function createComputedGetter (key) { ...@@ -4843,7 +4852,7 @@ function createComputedGetter (key) {
if (watcher.dirty) { if (watcher.dirty) {
watcher.evaluate(); watcher.evaluate();
} }
if (Dep.target) { if (Dep.SharedObject.target) { // fixed by xxxxxx
watcher.depend(); watcher.depend();
} }
return watcher.value return watcher.value
...@@ -6792,10 +6801,6 @@ var plugin = { ...@@ -6792,10 +6801,6 @@ var plugin = {
Vue.prototype._$queue = queue; Vue.prototype._$queue = queue;
Vue.prototype._m = function renderStatic() {
return this._e()
};
Vue.prototype.__call_hook = callHook$2; Vue.prototype.__call_hook = callHook$2;
// 运行时需要格式化 class,style // 运行时需要格式化 class,style
Vue.prototype._$stringifyClass = stringifyClass; Vue.prototype._$stringifyClass = stringifyClass;
......
此差异已折叠。
{ {
"name": "@dcloudio/uni-app-plus", "name": "@dcloudio/uni-app-plus",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app app-plus", "description": "uni-app app-plus",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-cli-shared", "name": "@dcloudio/uni-cli-shared",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-cli-shared", "description": "uni-cli-shared",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
...@@ -21,5 +21,5 @@ ...@@ -21,5 +21,5 @@
"hash-sum": "^1.0.2", "hash-sum": "^1.0.2",
"strip-json-comments": "^2.0.1" "strip-json-comments": "^2.0.1"
}, },
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-h5-ui", "name": "@dcloudio/uni-h5-ui",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app h5 ui", "description": "uni-app h5 ui",
"main": "dist/index.umd.min.js", "main": "dist/index.umd.min.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-h5", "name": "@dcloudio/uni-h5",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app h5", "description": "uni-app h5",
"main": "dist/index.umd.min.js", "main": "dist/index.umd.min.js",
"repository": { "repository": {
...@@ -18,5 +18,5 @@ ...@@ -18,5 +18,5 @@
"intersection-observer": "^0.7.0", "intersection-observer": "^0.7.0",
"safe-area-insets": "^1.4.1" "safe-area-insets": "^1.4.1"
}, },
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-mp-alipay", "name": "@dcloudio/uni-mp-alipay",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-alipay", "description": "uni-app mp-alipay",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-mp-baidu", "name": "@dcloudio/uni-mp-baidu",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-baidu", "description": "uni-app mp-baidu",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-mp-qq", "name": "@dcloudio/uni-mp-qq",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-qq", "description": "uni-app mp-qq",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-mp-toutiao", "name": "@dcloudio/uni-mp-toutiao",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-toutiao", "description": "uni-app mp-toutiao",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-mp-weixin", "name": "@dcloudio/uni-mp-weixin",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app mp-weixin", "description": "uni-app mp-weixin",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/uni-stat", "name": "@dcloudio/uni-stat",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -34,5 +34,5 @@ ...@@ -34,5 +34,5 @@
"rollup-plugin-replace": "^2.2.0", "rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.2" "rollup-plugin-uglify": "^6.0.2"
}, },
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
...@@ -70,6 +70,17 @@ describe('codegen', () => { ...@@ -70,6 +70,17 @@ describe('codegen', () => {
'<current-user v-slot="{ user }">{{ user.firstName }}</current-user>', '<current-user v-slot="{ user }">{{ user.firstName }}</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$s(0,'t0',_s(user.firstName))))]}}])})}` `with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$s(0,'t0',_s(user.firstName))))]}}])})}`
) )
})
it('generate keep-alive', () => {
assertCodegen(
`<keep-alive exclude="componentWithStatus1"><component is="componentWithStatus"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":"componentWithStatus1","_i":0}},[_c("componentWithStatus",{tag:"component",attrs:{"_i":1}})],1)}`
)
assertCodegen(
`<keep-alive :exclude="componentWithStatus1"><component :is="'componentWithStatus'+index"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":_$s(0,'a-exclude',componentWithStatus1),"_i":0}},[_c(_$s(1,'is','componentWithStatus'+index),{tag:"component",attrs:{"_i":1}})],1)}`
)
}) })
}) })
/* eslint-enable quotes */ /* eslint-enable quotes */
...@@ -15,7 +15,7 @@ describe('codegen', () => { ...@@ -15,7 +15,7 @@ describe('codegen', () => {
it('generate directive', () => { it('generate directive', () => {
assertCodegen( assertCodegen(
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>', '<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
) )
}) })
it('generate v-for directive', () => { it('generate v-for directive', () => {
...@@ -45,6 +45,16 @@ describe('codegen', () => { ...@@ -45,6 +45,16 @@ describe('codegen', () => {
'<current-user v-slot="{ user }">{{ user.firstName }}</current-user>', '<current-user v-slot="{ user }">{{ user.firstName }}</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$g(0,'t0')))]}}])})}` `with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$g(0,'t0')))]}}])})}`
) )
})
it('generate keep-alive', () => {
assertCodegen(
`<keep-alive exclude="componentWithStatus1"><component is="componentWithStatus"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":"componentWithStatus1","_i":0}},[_c("componentWithStatus",{tag:"component",attrs:{"_i":1}})],1)}`
)
assertCodegen(
`<keep-alive :exclude="componentWithStatus1"><component :is="'componentWithStatus'+index"/></keep-alive>`,
`with(this){return _c('keep-alive',{attrs:{"exclude":_$g(0,'a-exclude'),"_i":0}},[_c(_$g(1,'is'),{tag:"component",attrs:{"_i":1}})],1)}`
)
}) })
}) })
/* eslint-enable quotes */ /* eslint-enable quotes */
...@@ -576,7 +576,7 @@ describe('codegen', () => { ...@@ -576,7 +576,7 @@ describe('codegen', () => {
) )
assertCodegen( assertCodegen(
'<div :is="component1"></div>', '<div :is="component1"></div>',
`with(this){return _c(component1,{tag:"div"})}` `with(this){return _c(_$s(0,'is',component1),{tag:"div"})}`
) )
// maybe a component and normalize type should be 1 // maybe a component and normalize type should be 1
assertCodegen( assertCodegen(
...@@ -589,7 +589,7 @@ describe('codegen', () => { ...@@ -589,7 +589,7 @@ describe('codegen', () => {
// have "inline-template'" // have "inline-template'"
assertCodegen( assertCodegen(
'<my-component inline-template><p><span>hello world</span></p></my-component>', '<my-component inline-template><p><span>hello world</span></p></my-component>',
`with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _c('p',[_c('span')])}}]}})}` `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('p',[_c('span')])}},staticRenderFns:[]}})}`
) )
// "have inline-template attrs, but not having exactly one child element // "have inline-template attrs, but not having exactly one child element
assertCodegen( assertCodegen(
...@@ -616,7 +616,7 @@ describe('codegen', () => { ...@@ -616,7 +616,7 @@ describe('codegen', () => {
it('generate static trees inside v-for', () => { it('generate static trees inside v-for', () => {
assertCodegen( assertCodegen(
`<div><div v-for="i in 10"><p><span></span></p></div></div>`, `<div><div v-for="i in 10"><p><span></span></p></div></div>`,
`with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_m(0,true)])}),0)}` `with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_c('p',[_c('span')])])}),0)}`
// [`with(this){return _c('p',[_c('span')])}`] // [`with(this){return _c('p',[_c('span')])}`]
) )
}) })
...@@ -660,7 +660,7 @@ describe('codegen', () => { ...@@ -660,7 +660,7 @@ describe('codegen', () => {
it('does not squash templates inside v-pre', () => { it('does not squash templates inside v-pre', () => {
assertCodegen( assertCodegen(
'<div v-pre><template><p>{{msg}}</p></template></div>', '<div v-pre><template><p>{{msg}}</p></template></div>',
`with(this){return _m(0)}` `with(this){return _c('div',[[_c('p')]],2)}`
) )
// const template = '<div v-pre><template><p>{{msg}}</p></template></div>' // const template = '<div v-pre><template><p>{{msg}}</p></template></div>'
// const generatedCode = `with(this){return _m(0)}` // const generatedCode = `with(this){return _m(0)}`
......
...@@ -15,12 +15,12 @@ describe('codegen', () => { ...@@ -15,12 +15,12 @@ describe('codegen', () => {
it('generate directive', () => { it('generate directive', () => {
assertCodegen( assertCodegen(
'<p v-custom1:arg1.modifier="value1" v-custom2></p>', '<p v-custom1:arg1.modifier="value1" v-custom2></p>',
`with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
) )
// extra // extra
assertCodegen( assertCodegen(
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>', '<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
) )
}) })
...@@ -576,7 +576,7 @@ describe('codegen', () => { ...@@ -576,7 +576,7 @@ describe('codegen', () => {
) )
assertCodegen( assertCodegen(
'<div :is="component1"></div>', '<div :is="component1"></div>',
`with(this){return _c(component1,{tag:"v-uni-view",attrs:{"_i":0}})}` `with(this){return _c(_$g(0,'is'),{tag:"v-uni-view",attrs:{"_i":0}})}`
) )
// maybe a component and normalize type should be 1 // maybe a component and normalize type should be 1
assertCodegen( assertCodegen(
......
const compiler = require('../lib') const compiler = require('../lib')
const res = compiler.compile( const res = compiler.compile(
` `
<div :id="'a'+b">A{{ d | e | f }}B{{text}}C</div> <p v-text="test"></p>
`, { `, {
resourcePath: '/User/fxy/Documents/test.wxml', resourcePath: '/User/fxy/Documents/test.wxml',
isReservedTag: function (tag) { isReservedTag: function (tag) {
...@@ -13,7 +13,7 @@ const res = compiler.compile( ...@@ -13,7 +13,7 @@ const res = compiler.compile(
mp: { mp: {
platform: 'app-plus' platform: 'app-plus'
}, },
service: true, // service: true,
view: true view: true
}) })
console.log(require('util').inspect(res, { console.log(require('util').inspect(res, {
......
...@@ -14,7 +14,11 @@ function no (a, b, c) { ...@@ -14,7 +14,11 @@ function no (a, b, c) {
} }
function isBuiltInTag (tag) { function isBuiltInTag (tag) {
if (tag === 'slot' || tag === 'component') { if (
tag === 'slot' ||
tag === 'component' ||
tag === 'keep-alive'
) {
return true return true
} }
} }
...@@ -48,11 +52,11 @@ function markStatic (node) { ...@@ -48,11 +52,11 @@ function markStatic (node) {
} }
delete node.attrs delete node.attrs
} }
if (node.type === 1) { if (node.type === 1) {
delete node.staticClass delete node.staticClass
delete node.staticStyle delete node.staticStyle
if (node.attrs && !isComponent(node.tag)) { // 移除静态属性 if (node.attrs && !isComponent(node.tag) && node.tag !== 'keep-alive') { // 移除静态属性
node.attrs = node.attrs.filter(attr => attr.name === ID || isVar(attr.value)) node.attrs = node.attrs.filter(attr => attr.name === ID || isVar(attr.value))
} }
......
const { const {
ID, ID,
C_IS,
V_IF, V_IF,
V_FOR, V_FOR,
V_ELSE_IF, V_ELSE_IF,
...@@ -8,6 +9,15 @@ const { ...@@ -8,6 +9,15 @@ const {
const parseTextExpr = require('./text-parser') const parseTextExpr = require('./text-parser')
function parseIs (el, genVar) {
if (!el.component) {
return
}
if (isVar(el.component)) {
el.component = genVar(C_IS, el.component)
}
}
function parseIf (el, createGenVar) { function parseIf (el, createGenVar) {
if (!el.if) { if (!el.if) {
return return
...@@ -60,6 +70,7 @@ function parseText (el, parent, state) { ...@@ -60,6 +70,7 @@ function parseText (el, parent, state) {
} }
module.exports = { module.exports = {
parseIs,
parseIf, parseIf,
parseFor, parseFor,
parseText, parseText,
......
const { const {
ID, ID
hasOwn
} = require('../util') } = require('../util')
const tags = require('../../../../uni-cli-shared/lib/tags') const {
isComponent
} = require('../../util')
// 仅限 view 层 // 仅限 view 层
module.exports = function parseComponent (el) { module.exports = function parseComponent (el) {
// 需要把自定义组件的 attrs, props 全干掉 // 需要把自定义组件的 attrs, props 全干掉
if (el.tag && !hasOwn(tags, el.tag.replace('v-uni-', ''))) { if (el.tag && isComponent(el.tag)) {
// 仅保留 ID // 仅保留 ID
el.attrs && (el.attrs = el.attrs.filter(attr => attr.name === ID)) el.attrs && (el.attrs = el.attrs.filter(attr => attr.name === ID))
} }
......
...@@ -14,6 +14,7 @@ const { ...@@ -14,6 +14,7 @@ const {
} = require('../util') } = require('../util')
const { const {
parseIs,
parseIf, parseIf,
parseFor, parseFor,
parseText, parseText,
...@@ -82,6 +83,7 @@ function transformNode (el, parent, state) { ...@@ -82,6 +83,7 @@ function transformNode (el, parent, state) {
const genVar = createGenVar(el.attrsMap[ID]) const genVar = createGenVar(el.attrsMap[ID])
parseIs(el, genVar)
parseFor(el, createGenVar) parseFor(el, createGenVar)
parseKey(el) parseKey(el)
......
...@@ -9,6 +9,8 @@ const ITERATOR2 = '$2' ...@@ -9,6 +9,8 @@ const ITERATOR2 = '$2'
const ITERATOR3 = '$3' const ITERATOR3 = '$3'
const SET_DATA = '_$s' const SET_DATA = '_$s'
const GET_DATA = '_$g' const GET_DATA = '_$g'
const C_IS = 'is'
const V_FOR = 'f' const V_FOR = 'f'
const V_IF = 'i' const V_IF = 'i'
...@@ -190,7 +192,8 @@ function addHandler (el, name, value, important) { ...@@ -190,7 +192,8 @@ function addHandler (el, name, value, important) {
el.plain = false el.plain = false
} }
module.exports = { module.exports = {
C_IS,
V_FOR, V_FOR,
V_IF, V_IF,
V_ELSE_IF, V_ELSE_IF,
......
...@@ -9,10 +9,10 @@ const { ...@@ -9,10 +9,10 @@ const {
} = require('./util') } = require('./util')
const { const {
parseIs,
parseIf, parseIf,
parseFor, parseFor,
parseText, parseText,
parseDirs,
parseAttrs, parseAttrs,
parseProps, parseProps,
parseBinding parseBinding
...@@ -53,6 +53,41 @@ function parseKey (el) { ...@@ -53,6 +53,41 @@ function parseKey (el) {
} }
} }
function parseDirs (el, genVar, ignoreDirs, includeDirs = []) {
if (!el.directives) {
return
}
el.directives = el.directives.filter(dir => {
if (includeDirs.indexOf(dir.name) !== -1) {
if (ignoreDirs.indexOf(dir.name) === -1) {
dir.value && (dir.value = genVar('v-' + dir.name, dir.value))
dir.isDynamicArg && (dir.arg = genVar('v-' + dir.name + '-arg', dir.arg))
}
return true
}
})
}
const includeDirs = [
'text',
'html',
'bind',
'model',
'show',
'if',
'else',
'else-if',
'for',
'on',
'bind',
'slot',
'pre',
'cloak',
'once'
]
const ignoreDirs = ['model']
function transformNode (el, parent, state) { function transformNode (el, parent, state) {
if (el.type === 3) { if (el.type === 3) {
return return
...@@ -74,6 +109,8 @@ function transformNode (el, parent, state) { ...@@ -74,6 +109,8 @@ function transformNode (el, parent, state) {
const genVar = createGenVar(el.attrsMap[ID]) const genVar = createGenVar(el.attrsMap[ID])
parseIs(el, genVar)
if (parseFor(el, createGenVar)) { if (parseFor(el, createGenVar)) {
if (el.alias[0] === '{') { // <div><li v-for=" { a, b } in items"></li></div> if (el.alias[0] === '{') { // <div><li v-for=" { a, b } in items"></li></div>
el.alias = '$item' el.alias = '$item'
...@@ -83,7 +120,7 @@ function transformNode (el, parent, state) { ...@@ -83,7 +120,7 @@ function transformNode (el, parent, state) {
parseIf(el, createGenVar) parseIf(el, createGenVar)
parseBinding(el, genVar) parseBinding(el, genVar)
parseDirs(el, genVar, ['model']) parseDirs(el, genVar, ignoreDirs, includeDirs)
parseAttrs(el, genVar) parseAttrs(el, genVar)
parseProps(el, genVar) parseProps(el, genVar)
} }
......
...@@ -30,7 +30,7 @@ module.exports = { ...@@ -30,7 +30,7 @@ module.exports = {
compile (source, options = {}) { compile (source, options = {}) {
if (options.service) { if (options.service) {
(options.modules || (options.modules = [])).push(require('./app/service')) (options.modules || (options.modules = [])).push(require('./app/service'))
options.optimize = true // 启用 staticRenderFns options.optimize = false // 启用 staticRenderFns
// domProps => attrs // domProps => attrs
options.mustUseProp = () => false options.mustUseProp = () => false
options.isReservedTag = (tagName) => !isComponent(tagName) // 非组件均为内置 options.isReservedTag = (tagName) => !isComponent(tagName) // 非组件均为内置
...@@ -38,12 +38,11 @@ module.exports = { ...@@ -38,12 +38,11 @@ module.exports = {
// clear staticRenderFns // clear staticRenderFns
const compiled = compile(source, options) const compiled = compile(source, options)
compiled.staticRenderFns.length = 0
return compiled return compiled
} else if (options.view) { } else if (options.view) {
(options.modules || (options.modules = [])).push(require('./app/view')) (options.modules || (options.modules = [])).push(require('./app/view'))
options.optimize = false // 暂不启用 staticRenderFns options.optimize = false // 暂不启用 staticRenderFns
options.isReservedTag = (tagName) => false // 均为组件 options.isReservedTag = (tagName) => false // 均为组件
return compile(source, options) return compile(source, options)
} }
......
...@@ -183,9 +183,13 @@ const { ...@@ -183,9 +183,13 @@ const {
} = require('./h5') } = require('./h5')
function isComponent (tagName) { function isComponent (tagName) {
if (tagName === 'block' || tagName === 'template') { if (
tagName === 'block' ||
tagName === 'template' ||
tagName === 'keep-alive'
) {
return false return false
} }
return !hasOwn(tags, getTagName(tagName.replace('v-uni-', ''))) return !hasOwn(tags, getTagName(tagName.replace('v-uni-', '')))
} }
......
{ {
"name": "@dcloudio/uni-template-compiler", "name": "@dcloudio/uni-template-compiler",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-template-compiler", "description": "uni-template-compiler",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
...@@ -22,5 +22,5 @@ ...@@ -22,5 +22,5 @@
"@babel/types": "^7.3.3", "@babel/types": "^7.3.3",
"vue-template-compiler": "^2.6.10" "vue-template-compiler": "^2.6.10"
}, },
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/vue-cli-plugin-hbuilderx", "name": "@dcloudio/vue-cli-plugin-hbuilderx",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "HBuilderX plugin for vue-cli 3", "description": "HBuilderX plugin for vue-cli 3",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -18,5 +18,5 @@ ...@@ -18,5 +18,5 @@
"css": "~2.2.1", "css": "~2.2.1",
"escodegen": "^1.8.1" "escodegen": "^1.8.1"
}, },
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/vue-cli-plugin-uni-optimize", "name": "@dcloudio/vue-cli-plugin-uni-optimize",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app optimize plugin for vue-cli 3", "description": "uni-app optimize plugin for vue-cli 3",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/vue-cli-plugin-uni", "name": "@dcloudio/vue-cli-plugin-uni",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app plugin for vue-cli 3", "description": "uni-app plugin for vue-cli 3",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@dcloudio/uni-stat": "^3.0.0-alpha-24020191018012", "@dcloudio/uni-stat": "^3.0.0-alpha-24020191018019",
"copy-webpack-plugin": "^4.6.0", "copy-webpack-plugin": "^4.6.0",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
"envinfo": "^6.0.1", "envinfo": "^6.0.1",
...@@ -34,5 +34,5 @@ ...@@ -34,5 +34,5 @@
"wrap-loader": "^0.2.0", "wrap-loader": "^0.2.0",
"xregexp": "4.0.0" "xregexp": "4.0.0"
}, },
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
...@@ -17,7 +17,9 @@ const { ...@@ -17,7 +17,9 @@ const {
parseComponents parseComponents
} = require('./util') } = require('./util')
function getDefineComponents(components) { function getDefineComponents({
components
}) {
return components.map(({ return components.map(({
name, name,
source source
...@@ -93,7 +95,7 @@ module.exports = function(source, map) { ...@@ -93,7 +95,7 @@ module.exports = function(source, map) {
return ` return `
import 'uni-pages' import 'uni-pages'
function initView(){ function initView(){
${getStylesCode(this)} ${getStylesCode(this)}
injectStyles() injectStyles()
${getDefineComponents(parseComponents(source, traverse)).join('\n')} ${getDefineComponents(parseComponents(source, traverse)).join('\n')}
UniViewJSBridge.publishHandler('webviewReady') UniViewJSBridge.publishHandler('webviewReady')
......
...@@ -10,7 +10,7 @@ const { ...@@ -10,7 +10,7 @@ const {
parseComponents parseComponents
} = require('./util') } = require('./util')
function genComponentCode (components) { function genComponentCode(components) {
const importCode = [] const importCode = []
const componentsCode = [] const componentsCode = []
components.forEach(({ components.forEach(({
...@@ -24,12 +24,20 @@ function genComponentCode (components) { ...@@ -24,12 +24,20 @@ function genComponentCode (components) {
return [importCode.join('\n'), componentsCode.join(',\n')] return [importCode.join('\n'), componentsCode.join(',\n')]
} }
function genCode (components, css = []) { function genCode({
components,
options
}, css = []) {
const optionsCode = []
Object.keys(options).forEach(name => {
options[name] !== null && optionsCode.push(`${name}:${options[name]}`)
})
const [importComponentCode, componentsCode] = genComponentCode(components) const [importComponentCode, componentsCode] = genComponentCode(components)
// TODO js 内引用 css // TODO js 内引用 css
return ` return `
${importComponentCode} ${importComponentCode}
export default { export default {
${optionsCode.length?(optionsCode.join(',')+','):''}
data(){ data(){
return {} return {}
}, },
...@@ -40,7 +48,7 @@ export default { ...@@ -40,7 +48,7 @@ export default {
` `
} }
module.exports = function (content, map) { module.exports = function(content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
content = preprocessor.preprocess(content, jsPreprocessOptions.context, { content = preprocessor.preprocess(content, jsPreprocessOptions.context, {
......
const parser = require('@babel/parser') const parser = require('@babel/parser')
function parseComponents (content, traverse) { function parseComponents(content, traverse) {
const { const {
state: { state: {
options,
components components
} }
} = traverse(parser.parse(content, { } = traverse(parser.parse(content, {
...@@ -15,9 +16,16 @@ function parseComponents (content, traverse) { ...@@ -15,9 +16,16 @@ function parseComponents (content, traverse) {
'classProperties' 'classProperties'
] ]
}), { }), {
components: [] components: [],
options: {
name: null,
inheritAttrs: null
}
}) })
return components return {
components,
options
}
} }
module.exports = { module.exports = {
......
...@@ -6,10 +6,27 @@ const { ...@@ -6,10 +6,27 @@ const {
} = require('./util') } = require('./util')
function handleObjectExpression (declaration, path, state) { function handleObjectExpression (declaration, path, state) {
if (state.options) { // name,inheritAttrs
Object.keys(state.options).forEach(name => {
const optionProperty = declaration.properties.filter(prop => {
return t.isObjectProperty(prop) &&
t.isIdentifier(prop.key) &&
prop.key.name === name
})[0]
if (optionProperty) {
if (t.isStringLiteral(optionProperty.value)) {
state.options[name] = JSON.stringify(optionProperty.value.value)
} else {
state.options[name] = optionProperty.value.value
}
}
})
}
const componentsProperty = declaration.properties.filter(prop => { const componentsProperty = declaration.properties.filter(prop => {
return t.isObjectProperty(prop) && return t.isObjectProperty(prop) &&
t.isIdentifier(prop.key) && t.isIdentifier(prop.key) &&
prop.key.name === 'components' prop.key.name === 'components'
})[0] })[0]
if (componentsProperty && t.isObjectExpression(componentsProperty.value)) { if (componentsProperty && t.isObjectExpression(componentsProperty.value)) {
...@@ -27,7 +44,8 @@ function handleObjectExpression (declaration, path, state) { ...@@ -27,7 +44,8 @@ function handleObjectExpression (declaration, path, state) {
module.exports = function (ast, state = { module.exports = function (ast, state = {
type: 'Component', type: 'Component',
components: [] components: [],
options: {}
}) { }) {
babelTraverse(ast, { babelTraverse(ast, {
ExportDefaultDeclaration (path) { ExportDefaultDeclaration (path) {
...@@ -35,15 +53,15 @@ module.exports = function (ast, state = { ...@@ -35,15 +53,15 @@ module.exports = function (ast, state = {
if (t.isObjectExpression(declaration)) { // export default {components:{}} if (t.isObjectExpression(declaration)) { // export default {components:{}}
handleObjectExpression(declaration, path, state) handleObjectExpression(declaration, path, state)
} else if (t.isCallExpression(declaration) && } else if (t.isCallExpression(declaration) &&
t.isMemberExpression(declaration.callee) && t.isMemberExpression(declaration.callee) &&
declaration.arguments.length === 1) { // export default Vue.extend({components:{}}) declaration.arguments.length === 1) { // export default Vue.extend({components:{}})
if (declaration.callee.object.name === 'Vue' && declaration.callee.property.name === if (declaration.callee.object.name === 'Vue' && declaration.callee.property.name ===
'extend') { 'extend') {
handleObjectExpression(declaration.arguments[0], path, state) handleObjectExpression(declaration.arguments[0], path, state)
} }
} else if (t.isClassDeclaration(declaration) && } else if (t.isClassDeclaration(declaration) &&
declaration.decorators && declaration.decorators &&
declaration.decorators.length) { // export default @Component({components:{}}) class MyComponent extend Vue declaration.decorators.length) { // export default @Component({components:{}}) class MyComponent extend Vue
const componentDecorator = declaration.decorators[0] const componentDecorator = declaration.decorators[0]
if (t.isCallExpression(componentDecorator.expression)) { if (t.isCallExpression(componentDecorator.expression)) {
const args = componentDecorator.expression.arguments const args = componentDecorator.expression.arguments
......
{ {
"name": "@dcloudio/webpack-uni-mp-loader", "name": "@dcloudio/webpack-uni-mp-loader",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "webpack-uni-mp-loader", "description": "webpack-uni-mp-loader",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -16,5 +16,5 @@ ...@@ -16,5 +16,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
{ {
"name": "@dcloudio/webpack-uni-pages-loader", "name": "@dcloudio/webpack-uni-pages-loader",
"version": "3.0.0-alpha-24020191018012", "version": "3.0.0-alpha-24020191018019",
"description": "uni-app pages.json loader", "description": "uni-app pages.json loader",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
"uni-app": { "uni-app": {
"compilerVersion": "2.3.4" "compilerVersion": "2.3.4"
}, },
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" "gitHead": "ca81890923be0d953c6d9389d719cc44eaf2f118"
} }
...@@ -15,3 +15,4 @@ export const WEBVIEW_READY = 'webviewReady' ...@@ -15,3 +15,4 @@ export const WEBVIEW_READY = 'webviewReady'
export const WEBVIEW_UI_EVENT = 'webviewUIEvent' export const WEBVIEW_UI_EVENT = 'webviewUIEvent'
export const VD_SYNC_CALLBACK = 'vdSyncCallback' export const VD_SYNC_CALLBACK = 'vdSyncCallback'
export const INVOKE_API = 'invokeApi' export const INVOKE_API = 'invokeApi'
export const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
...@@ -4,7 +4,8 @@ import { ...@@ -4,7 +4,8 @@ import {
VD_SYNC, VD_SYNC,
VD_SYNC_CALLBACK, VD_SYNC_CALLBACK,
INVOKE_API, INVOKE_API,
WEBVIEW_READY WEBVIEW_READY,
WEB_INVOKE_APPSERVICE
} from '../../../constants' } from '../../../constants'
import { import {
...@@ -16,7 +17,8 @@ import onWebviewReady from './on-webview-ready' ...@@ -16,7 +17,8 @@ import onWebviewReady from './on-webview-ready'
import onVdSync from './on-vd-sync' import onVdSync from './on-vd-sync'
import onVdSyncCallback from './on-vd-sync-callback' import onVdSyncCallback from './on-vd-sync-callback'
import onInvokeApi from './on-invoke-api' import onInvokeApi from './on-invoke-api'
import onWebInvokeApi from './on-web-invoke-api'
export function initSubscribeHandlers () { export function initSubscribeHandlers () {
const { const {
...@@ -34,6 +36,8 @@ export function initSubscribeHandlers () { ...@@ -34,6 +36,8 @@ export function initSubscribeHandlers () {
subscribeHandler(data.type, data.data, data.pageId) subscribeHandler(data.type, data.data, data.pageId)
}) })
registerPlusMessage(WEB_INVOKE_APPSERVICE, onWebInvokeApi)
subscribe(WEBVIEW_READY, onWebviewReady) subscribe(WEBVIEW_READY, onWebviewReady)
const entryPagePath = '/' + __uniConfig.entryPagePath const entryPagePath = '/' + __uniConfig.entryPagePath
......
export default function onInvokeApi (data) {
// TODO
console.log('onInvokeApi', data)
}
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
</template> </template>
<script> <script>
import { import {
subscriber, subscriber
listeners
} from 'uni-mixins' } from 'uni-mixins'
import native from '../../mixins/native'
const methods = [ const methods = [
'play', 'play',
...@@ -60,7 +60,7 @@ const attrs = [ ...@@ -60,7 +60,7 @@ const attrs = [
export default { export default {
name: 'Video', name: 'Video',
mixins: [subscriber, listeners], mixins: [subscriber, native],
props: { props: {
id: { id: {
type: String, type: String,
...@@ -145,18 +145,6 @@ export default { ...@@ -145,18 +145,6 @@ export default {
default: true default: true
} }
}, },
data () {
return {
style: {
top: '0px',
left: '0px',
width: '0px',
height: '0px',
position: 'static'
},
hidden: false
}
},
computed: { computed: {
attrs () { attrs () {
const obj = {} const obj = {}
...@@ -173,11 +161,7 @@ export default { ...@@ -173,11 +161,7 @@ export default {
this.video && this.video[val ? 'hide' : 'show']() this.video && this.video[val ? 'hide' : 'show']()
} }
}, },
listeners: {
'@view-update': '_requestUpdate'
},
mounted () { mounted () {
this._updateStyle()
const video = this.video = plus.video.createVideoPlayer('video' + Date.now(), Object.assign({}, this.attrs, this.style)) const video = this.video = plus.video.createVideoPlayer('video' + Date.now(), Object.assign({}, this.attrs, this.style))
plus.webview.currentWebview().append(video) plus.webview.currentWebview().append(video)
if (this.hidden) { if (this.hidden) {
...@@ -217,29 +201,6 @@ export default { ...@@ -217,29 +201,6 @@ export default {
} }
this.video && this.video[type](data) this.video && this.video[type](data)
} }
},
_updateStyle () {
const rect = this.$refs.container.getBoundingClientRect()
this.hidden = false;
['top', 'left', 'width', 'height'].forEach(key => {
let val = rect[key]
val = key === 'top' ? val + (document.documentElement.scrollTop || document.body.scrollTop || 0) : val
if (!val && (key === 'width' || key === 'height')) {
this.hidden = true
}
this.style[key] = val + 'px'
})
},
_requestUpdate () {
if (this._animationFrame) {
cancelAnimationFrame(this._animationFrame)
}
if (this.video) {
this._animationFrame = requestAnimationFrame(() => {
delete this._animationFrame
this._updateStyle()
})
}
} }
} }
} }
......
import {
listeners
} from 'uni-mixins'
export default {
name: 'Native',
mixins: [listeners],
data () {
return {
style: {
top: '0px',
left: '0px',
width: '0px',
height: '0px',
position: 'static'
},
hidden: false,
tags: []
}
},
mounted () {
this._updateStyle()
this.$nextTick(() => {
if (this.tags.length) {
const view = this.view = plus.nativeObj.View('view' + Date.now(), this.style, this.tags)
plus.webview.currentWebview().append(view)
if (this.hidden) {
view.hide()
}
}
})
},
beforeDestroy () {
this.view && this.view.close()
delete this.view
},
listeners: {
'@view-update': '_requestUpdate'
},
methods: {
insertTextView () {
},
updateTextView () {
},
removeTextView () {
},
insertImageView () {
},
updateImageView () {
},
removeImageView () {
},
_updateStyle () {
const rect = this.$refs.container.getBoundingClientRect()
this.hidden = false;
['top', 'left', 'width', 'height'].forEach(key => {
let val = rect[key]
val = key === 'top' ? val + (document.documentElement.scrollTop || document.body.scrollTop || 0) : val
if (!val && (key === 'width' || key === 'height')) {
this.hidden = true
}
this.style[key] = val + 'px'
})
},
_requestUpdate () {
if (this._animationFrame) {
cancelAnimationFrame(this._animationFrame)
}
if (this._isMounted) {
this._animationFrame = requestAnimationFrame(() => {
delete this._animationFrame
this._updateStyle()
})
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册