Skip to content

Commit

Permalink
feat(mp,h5): uni://form-field
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Apr 22, 2019
1 parent 404139f commit 2462cfc
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 36 deletions.
1 change: 1 addition & 0 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
replace({
__GLOBAL__: platform.prefix,
__PLATFORM_TITLE__: platform.title,
__PLATFORM_PREFIX__: JSON.stringify(platform.prefix),
__PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM)
})
],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"__PLATFORM__": true,
"__VERSION__": true,
"__GLOBAL__": true,
"__PLATFORM_TITLE__": true
"__PLATFORM_TITLE__": true,
"__PLATFORM_PREFIX__":true
},
"rules": {
"no-tabs": 0,
Expand Down
38 changes: 32 additions & 6 deletions packages/uni-app-plus/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,32 @@ function createObserver (name) {
}
}

function getBehaviors (vueExtends, vueMixins) {
function getBehaviors (vueOptions) {
const vueBehaviors = vueOptions['behaviors'];
const vueExtends = vueOptions['extends'];
const vueMixins = vueOptions['mixins'];

let vueProps = vueOptions['props'];

if (!vueProps) {
vueOptions['props'] = vueProps = [];
}

const behaviors = [];
if (Array.isArray(vueBehaviors)) {
vueBehaviors.forEach(behavior => {
behaviors.push(behavior.replace('uni://', `${"wx"}://`));
if (behavior === 'uni://form-field') {
if (Array.isArray(vueProps)) {
vueProps.push('name');
vueProps.push('value');
} else {
vueProps['name'] = String;
vueProps['value'] = null;
}
}
});
}
if (isPlainObject(vueExtends) && vueExtends.props) {
behaviors.push(
Behavior({
Expand Down Expand Up @@ -486,6 +510,11 @@ function getProperties (props, isBehavior = false, file = '') {
}

function wrapper$1 (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event));
} catch (e) {}

event.stopPropagation = noop;
event.preventDefault = noop;

Expand All @@ -495,9 +524,6 @@ function wrapper$1 (event) {
event.detail = {};
}

// TODO 又得兼容 mpvue 的 mp 对象
event.mp = event;

if (isPlainObject(event.detail)) {
event.target = Object.assign({}, event.target, event.detail);
}
Expand Down Expand Up @@ -887,9 +913,9 @@ function initVm$2 (VueComponent) {
function createComponent (vueOptions) {
vueOptions = vueOptions.default || vueOptions;

const properties = getProperties(vueOptions.props, false, vueOptions.__file);
const behaviors = getBehaviors(vueOptions);

const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']);
const properties = getProperties(vueOptions.props, false, vueOptions.__file);

const VueComponent = Vue.extend(vueOptions);

Expand Down
2 changes: 1 addition & 1 deletion packages/uni-app-plus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-app-plus",
"version": "0.0.227",
"version": "0.0.228",
"description": "uni-app app-plus",
"main": "dist/index.js",
"scripts": {
Expand Down
38 changes: 32 additions & 6 deletions packages/uni-mp-baidu/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,32 @@ function createObserver (name) {
}
}

function getBehaviors (vueExtends, vueMixins) {
function getBehaviors (vueOptions) {
const vueBehaviors = vueOptions['behaviors'];
const vueExtends = vueOptions['extends'];
const vueMixins = vueOptions['mixins'];

let vueProps = vueOptions['props'];

if (!vueProps) {
vueOptions['props'] = vueProps = [];
}

const behaviors = [];
if (Array.isArray(vueBehaviors)) {
vueBehaviors.forEach(behavior => {
behaviors.push(behavior.replace('uni://', `${"swan"}://`));
if (behavior === 'uni://form-field') {
if (Array.isArray(vueProps)) {
vueProps.push('name');
vueProps.push('value');
} else {
vueProps['name'] = String;
vueProps['value'] = null;
}
}
});
}
if (isPlainObject(vueExtends) && vueExtends.props) {
behaviors.push(
Behavior({
Expand Down Expand Up @@ -635,6 +659,11 @@ function getProperties (props, isBehavior = false, file = '') {
}

function wrapper$1 (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event));
} catch (e) {}

event.stopPropagation = noop;
event.preventDefault = noop;

Expand All @@ -654,9 +683,6 @@ function wrapper$1 (event) {
}
}

// TODO 又得兼容 mpvue 的 mp 对象
event.mp = event;

if (isPlainObject(event.detail)) {
event.target = Object.assign({}, event.target, event.detail);
}
Expand Down Expand Up @@ -1070,9 +1096,9 @@ function initVm$2 (VueComponent) {
function createComponent (vueOptions) {
vueOptions = vueOptions.default || vueOptions;

const properties = getProperties(vueOptions.props, false, vueOptions.__file);
const behaviors = getBehaviors(vueOptions);

const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']);
const properties = getProperties(vueOptions.props, false, vueOptions.__file);

const VueComponent = Vue.extend(vueOptions);

Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-baidu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-baidu",
"version": "0.0.824",
"version": "0.0.825",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"scripts": {
Expand Down
38 changes: 32 additions & 6 deletions packages/uni-mp-toutiao/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,32 @@ function createObserver (name) {
}
}

function getBehaviors (vueExtends, vueMixins) {
function getBehaviors (vueOptions) {
const vueBehaviors = vueOptions['behaviors'];
const vueExtends = vueOptions['extends'];
const vueMixins = vueOptions['mixins'];

let vueProps = vueOptions['props'];

if (!vueProps) {
vueOptions['props'] = vueProps = [];
}

const behaviors = [];
if (Array.isArray(vueBehaviors)) {
vueBehaviors.forEach(behavior => {
behaviors.push(behavior.replace('uni://', `${"tt"}://`));
if (behavior === 'uni://form-field') {
if (Array.isArray(vueProps)) {
vueProps.push('name');
vueProps.push('value');
} else {
vueProps['name'] = String;
vueProps['value'] = null;
}
}
});
}
if (isPlainObject(vueExtends) && vueExtends.props) {
behaviors.push(
Behavior({
Expand Down Expand Up @@ -703,6 +727,11 @@ function getProperties (props, isBehavior = false, file = '') {
}

function wrapper$1 (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event));
} catch (e) {}

event.stopPropagation = noop;
event.preventDefault = noop;

Expand All @@ -712,9 +741,6 @@ function wrapper$1 (event) {
event.detail = {};
}

// TODO 又得兼容 mpvue 的 mp 对象
event.mp = event;

if (isPlainObject(event.detail)) {
event.target = Object.assign({}, event.target, event.detail);
}
Expand Down Expand Up @@ -1078,9 +1104,9 @@ function initVm$2 (VueComponent) {
function createComponent (vueOptions) {
vueOptions = vueOptions.default || vueOptions;

const properties = getProperties(vueOptions.props, false, vueOptions.__file);
const behaviors = getBehaviors(vueOptions);

const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']);
const properties = getProperties(vueOptions.props, false, vueOptions.__file);

const VueComponent = Vue.extend(vueOptions);

Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-toutiao/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "0.0.322",
"version": "0.0.323",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"scripts": {
Expand Down
38 changes: 32 additions & 6 deletions packages/uni-mp-weixin/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,32 @@ function createObserver (name) {
}
}

function getBehaviors (vueExtends, vueMixins) {
function getBehaviors (vueOptions) {
const vueBehaviors = vueOptions['behaviors'];
const vueExtends = vueOptions['extends'];
const vueMixins = vueOptions['mixins'];

let vueProps = vueOptions['props'];

if (!vueProps) {
vueOptions['props'] = vueProps = [];
}

const behaviors = [];
if (Array.isArray(vueBehaviors)) {
vueBehaviors.forEach(behavior => {
behaviors.push(behavior.replace('uni://', `${"wx"}://`));
if (behavior === 'uni://form-field') {
if (Array.isArray(vueProps)) {
vueProps.push('name');
vueProps.push('value');
} else {
vueProps['name'] = String;
vueProps['value'] = null;
}
}
});
}
if (isPlainObject(vueExtends) && vueExtends.props) {
behaviors.push(
Behavior({
Expand Down Expand Up @@ -503,6 +527,11 @@ function getProperties (props, isBehavior = false, file = '') {
}

function wrapper$1 (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event));
} catch (e) {}

event.stopPropagation = noop;
event.preventDefault = noop;

Expand All @@ -512,9 +541,6 @@ function wrapper$1 (event) {
event.detail = {};
}

// TODO 又得兼容 mpvue 的 mp 对象
event.mp = event;

if (isPlainObject(event.detail)) {
event.target = Object.assign({}, event.target, event.detail);
}
Expand Down Expand Up @@ -907,9 +933,9 @@ function initVm$2 (VueComponent) {
function createComponent (vueOptions) {
vueOptions = vueOptions.default || vueOptions;

const properties = getProperties(vueOptions.props, false, vueOptions.__file);
const behaviors = getBehaviors(vueOptions);

const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']);
const properties = getProperties(vueOptions.props, false, vueOptions.__file);

const VueComponent = Vue.extend(vueOptions);

Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-weixin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-weixin",
"version": "0.0.946",
"version": "0.0.947",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/core/runtime/wrapper/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function initVm (VueComponent) {
export function createComponent (vueOptions) {
vueOptions = vueOptions.default || vueOptions

const properties = getProperties(vueOptions.props, false, vueOptions.__file)
const behaviors = getBehaviors(vueOptions)

const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins'])
const properties = getProperties(vueOptions.props, false, vueOptions.__file)

const VueComponent = Vue.extend(vueOptions)

Expand Down
34 changes: 30 additions & 4 deletions src/core/runtime/wrapper/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,32 @@ function createObserver (name) {
}
}

export function getBehaviors (vueExtends, vueMixins) {
export function getBehaviors (vueOptions) {
const vueBehaviors = vueOptions['behaviors']
const vueExtends = vueOptions['extends']
const vueMixins = vueOptions['mixins']

let vueProps = vueOptions['props']

if (!vueProps) {
vueOptions['props'] = vueProps = []
}

const behaviors = []
if (Array.isArray(vueBehaviors)) {
vueBehaviors.forEach(behavior => {
behaviors.push(behavior.replace('uni://', `${__PLATFORM_PREFIX__}://`))
if (behavior === 'uni://form-field') {
if (Array.isArray(vueProps)) {
vueProps.push('name')
vueProps.push('value')
} else {
vueProps['name'] = String
vueProps['value'] = null
}
}
})
}
if (isPlainObject(vueExtends) && vueExtends.props) {
behaviors.push(
Behavior({
Expand Down Expand Up @@ -164,6 +188,11 @@ export function getProperties (props, isBehavior = false, file = '') {
}

function wrapper (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event))
} catch (e) {}

event.stopPropagation = noop
event.preventDefault = noop

Expand All @@ -183,9 +212,6 @@ function wrapper (event) {
}
}

// TODO 又得兼容 mpvue 的 mp 对象
event.mp = event

if (isPlainObject(event.detail)) {
event.target = Object.assign({}, event.target, event.detail)
}
Expand Down
Loading

0 comments on commit 2462cfc

Please sign in to comment.