diff --git a/dist/common/color.d.ts b/dist/common/color.d.ts index 5fa14477..3f462228 100644 --- a/dist/common/color.d.ts +++ b/dist/common/color.d.ts @@ -1,3 +1,4 @@ export declare const RED = "#f44"; export declare const BLUE = "#1989fa"; export declare const GREEN = "#07c160"; +export declare const ORANGE = "#ff976a"; diff --git a/dist/common/color.js b/dist/common/color.js index 5f5e9660..c850d2a1 100644 --- a/dist/common/color.js +++ b/dist/common/color.js @@ -1,3 +1,4 @@ export const RED = '#f44'; export const BLUE = '#1989fa'; export const GREEN = '#07c160'; +export const ORANGE = '#ff976a'; diff --git a/dist/common/component.d.ts b/dist/common/component.d.ts index 2c47a09a..9ba8a3bd 100644 --- a/dist/common/component.d.ts +++ b/dist/common/component.d.ts @@ -1,3 +1,3 @@ -import { VantComponentOptions, CombinedComponentInstance } from 'definitions/index'; +import { VantComponentOptions, CombinedComponentInstance } from '../definitions/index'; declare function VantComponent(vantOptions?: VantComponentOptions>): void; export { VantComponent }; diff --git a/dist/common/utils.d.ts b/dist/common/utils.d.ts index 32fc1bab..dc55bd7d 100644 --- a/dist/common/utils.d.ts +++ b/dist/common/utils.d.ts @@ -1,5 +1,7 @@ +/// export declare function isDef(value: any): boolean; export declare function isObj(x: any): boolean; export declare function isNumber(value: any): boolean; export declare function range(num: number, min: number, max: number): number; export declare function nextTick(fn: Function): void; +export declare function getSystemInfoSync(): WechatMiniprogram.GetSystemInfoSuccessCallbackResult; diff --git a/dist/common/utils.js b/dist/common/utils.js index f08d8d35..213c91ae 100644 --- a/dist/common/utils.js +++ b/dist/common/utils.js @@ -16,3 +16,10 @@ export function nextTick(fn) { fn(); }, 1000 / 30); } +let systemInfo = null; +export function getSystemInfoSync() { + if (systemInfo == null) { + systemInfo = wx.getSystemInfoSync(); + } + return systemInfo; +} diff --git a/dist/field/index.js b/dist/field/index.js index 188c4d37..7865c000 100644 --- a/dist/field/index.js +++ b/dist/field/index.js @@ -1,4 +1,5 @@ import { VantComponent } from '../common/component'; +import { getSystemInfoSync } from '../common/utils'; VantComponent({ field: true, classes: ['input-class', 'right-icon-class'], @@ -66,63 +67,29 @@ VantComponent({ } }, data: { - showClear: false - }, - beforeCreate() { - this.focused = false; + focused: false, + system: getSystemInfoSync().system.split(' ').shift().toLowerCase() }, methods: { onInput(event) { const { value = '' } = event.detail || {}; - this.set({ - value, - showClear: this.getShowClear(value) - }, () => { + this.set({ value }, () => { this.emitChange(value); }); }, onFocus(event) { - const { value = '', height = 0 } = event.detail || {}; - this.$emit('focus', { value, height }); - this.focused = true; - this.blurFromClear = false; - this.set({ - showClear: this.getShowClear() - }); + this.set({ focused: true }); + this.$emit('focus', event.detail); }, onBlur(event) { - const { value = '', cursor = 0 } = event.detail || {}; - this.$emit('blur', { value, cursor }); - this.focused = false; - const showClear = this.getShowClear(); - if (this.data.value === value) { - this.set({ - showClear - }); - } - else if (!this.blurFromClear) { - // fix: the handwritten keyboard does not trigger input change - this.set({ - value, - showClear - }, () => { - this.emitChange(value); - }); - } + this.set({ focused: false }); + this.$emit('blur', event.detail); }, onClickIcon() { this.$emit('click-icon'); }, - getShowClear(value) { - value = value === undefined ? this.data.value : value; - return (this.data.clearable && this.focused && value && !this.data.readonly); - }, onClear() { - this.blurFromClear = true; - this.set({ - value: '', - showClear: this.getShowClear('') - }, () => { + this.set({ value: '' }, () => { this.emitChange(''); this.$emit('clear', ''); }); diff --git a/dist/field/index.wxml b/dist/field/index.wxml index 1a3e9afd..d5e70cc1 100644 --- a/dist/field/index.wxml +++ b/dist/field/index.wxml @@ -14,15 +14,18 @@ > - + - - -// 判断子项是否被选中 -function isArray (array) { - return array instanceof Array; -} -function isActive (activeList, itemId) { - if (typeof activeList === 'undefined' || activeList == null) return false; - if (isArray(activeList)) { - return activeList.indexOf(itemId) > -1; - } - else { - return activeList === itemId; - } -} - -module.exports.isActive = isActive; - + {{ item.text }} -1; + } + + return activeList === itemId; +} + +module.exports.isActive = isActive; diff --git a/lib/common/color.js b/lib/common/color.js index be4c57b5..7e8d90ea 100644 --- a/lib/common/color.js +++ b/lib/common/color.js @@ -3,3 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.RED = '#f44'; exports.BLUE = '#1989fa'; exports.GREEN = '#07c160'; +exports.ORANGE = '#ff976a'; diff --git a/lib/common/utils.js b/lib/common/utils.js index 21d51d2d..2af36733 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -23,3 +23,11 @@ function nextTick(fn) { }, 1000 / 30); } exports.nextTick = nextTick; +var systemInfo = null; +function getSystemInfoSync() { + if (systemInfo == null) { + systemInfo = wx.getSystemInfoSync(); + } + return systemInfo; +} +exports.getSystemInfoSync = getSystemInfoSync; diff --git a/lib/field/index.js b/lib/field/index.js index 4db86c77..d27057a5 100644 --- a/lib/field/index.js +++ b/lib/field/index.js @@ -1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var component_1 = require("../common/component"); +var utils_1 = require("../common/utils"); component_1.VantComponent({ field: true, classes: ['input-class', 'right-icon-class'], @@ -68,66 +69,31 @@ component_1.VantComponent({ } }, data: { - showClear: false - }, - beforeCreate: function () { - this.focused = false; + focused: false, + system: utils_1.getSystemInfoSync().system.split(' ').shift().toLowerCase() }, methods: { onInput: function (event) { var _this = this; var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a; - this.set({ - value: value, - showClear: this.getShowClear(value) - }, function () { + this.set({ value: value }, function () { _this.emitChange(value); }); }, onFocus: function (event) { - var _a = event.detail || {}, _b = _a.value, value = _b === void 0 ? '' : _b, _c = _a.height, height = _c === void 0 ? 0 : _c; - this.$emit('focus', { value: value, height: height }); - this.focused = true; - this.blurFromClear = false; - this.set({ - showClear: this.getShowClear() - }); + this.set({ focused: true }); + this.$emit('focus', event.detail); }, onBlur: function (event) { - var _this = this; - var _a = event.detail || {}, _b = _a.value, value = _b === void 0 ? '' : _b, _c = _a.cursor, cursor = _c === void 0 ? 0 : _c; - this.$emit('blur', { value: value, cursor: cursor }); - this.focused = false; - var showClear = this.getShowClear(); - if (this.data.value === value) { - this.set({ - showClear: showClear - }); - } - else if (!this.blurFromClear) { - // fix: the handwritten keyboard does not trigger input change - this.set({ - value: value, - showClear: showClear - }, function () { - _this.emitChange(value); - }); - } + this.set({ focused: false }); + this.$emit('blur', event.detail); }, onClickIcon: function () { this.$emit('click-icon'); }, - getShowClear: function (value) { - value = value === undefined ? this.data.value : value; - return (this.data.clearable && this.focused && value && !this.data.readonly); - }, onClear: function () { var _this = this; - this.blurFromClear = true; - this.set({ - value: '', - showClear: this.getShowClear('') - }, function () { + this.set({ value: '' }, function () { _this.emitChange(''); _this.$emit('clear', ''); }); diff --git a/lib/field/index.wxml b/lib/field/index.wxml index 1a3e9afd..d5e70cc1 100644 --- a/lib/field/index.wxml +++ b/lib/field/index.wxml @@ -14,15 +14,18 @@ > - + - - -// 判断子项是否被选中 -function isArray (array) { - return array instanceof Array; -} -function isActive (activeList, itemId) { - if (typeof activeList === 'undefined' || activeList == null) return false; - if (isArray(activeList)) { - return activeList.indexOf(itemId) > -1; - } - else { - return activeList === itemId; - } -} - -module.exports.isActive = isActive; - + {{ item.text }} -1; + } + + return activeList === itemId; +} + +module.exports.isActive = isActive;