mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-18 12:34:25 +08:00
fix code smells & bug
This commit is contained in:
parent
4f90dd3b05
commit
5f1c73fe8a
@ -351,9 +351,9 @@ export default {
|
||||
this.$nextTick().then(() => {
|
||||
this.typeIsSelect = typeisSelect
|
||||
if (typeisSelect) {
|
||||
const el = this.$refs.selectMenu.$el
|
||||
const $el = this.$refs.selectMenu.$el
|
||||
this.$parent.updatePosition(
|
||||
el,
|
||||
$el,
|
||||
(el, activatorRect) => {
|
||||
el.style.minWidth = activatorRect.width + 'px'
|
||||
},
|
||||
@ -396,14 +396,14 @@ export default {
|
||||
this.$refs.mask.showOnce(`Not all child nodes of "${option.label}" have been loaded`)
|
||||
return
|
||||
}
|
||||
const traverseMultiple = option => {
|
||||
if (!option || option.disabled) return
|
||||
if (Array.isArray(option.children)) {
|
||||
for (const child of option.children) {
|
||||
const traverseMultiple = item => {
|
||||
if (!item || item.disabled) return
|
||||
if (Array.isArray(item.children)) {
|
||||
for (const child of item.children) {
|
||||
traverseMultiple(child)
|
||||
}
|
||||
}
|
||||
if (!option.children) {
|
||||
if (!item.children) {
|
||||
newValues.push(option.value)
|
||||
}
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ export default {
|
||||
},
|
||||
addValidationEventListeners () {
|
||||
const rules = this.synthesizedRules
|
||||
if (rules.length >= 0) {
|
||||
if (rules.length > 0) {
|
||||
this.$on('blur', this.handleContentBlur)
|
||||
this.$on('input', this.handleContentInput)
|
||||
this.$on('focus', this.handleContentFocus)
|
||||
|
@ -4,9 +4,9 @@ import NPopoverContent from './PopoverContent'
|
||||
import activatorMixin from './activatorMixin'
|
||||
import genId from '../../../utils/genId'
|
||||
|
||||
function mixin (component, mixin) {
|
||||
function mixin (component, mixins) {
|
||||
component.mixins = component.mixins || []
|
||||
component.mixins.push(mixin)
|
||||
component.mixins.push(mixins)
|
||||
return component
|
||||
}
|
||||
|
||||
|
@ -376,7 +376,7 @@ export default {
|
||||
}
|
||||
let newValue = []
|
||||
if (Array.isArray(this.value)) {
|
||||
const optionValues = new Set(this.synthesizedOptions.map(option => option.value))
|
||||
const optionValues = new Set(this.synthesizedOptions.map(item => item.value))
|
||||
newValue = this.value.filter(value => optionValues.has(value) || this.memorizedValueOptionMap.has(value))
|
||||
}
|
||||
const index = newValue.findIndex(value => value === option.value)
|
||||
|
@ -312,7 +312,6 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
console.log('enter timePicker')
|
||||
this.checkValue()
|
||||
},
|
||||
methods: {
|
||||
@ -430,9 +429,7 @@ export default {
|
||||
},
|
||||
closeTimeSelector (returnFocus = false) {
|
||||
this.active = false
|
||||
if (returnFocus) {
|
||||
|
||||
} else {
|
||||
if (!returnFocus) {
|
||||
this.$emit('blur', this.value)
|
||||
}
|
||||
},
|
||||
@ -454,7 +451,6 @@ export default {
|
||||
this.isErrorVal = this.isHourDisabled(this.computedHour) || this.isMinuteDisabled(this.computedMinute) ||
|
||||
this.isSecondDisabled(this.computedSecond)
|
||||
this.$emit('checkValue', this.isErrorVal)
|
||||
console.log('this.checkTime', this.isErrorVal)
|
||||
}
|
||||
// checkHour () {
|
||||
// if (this.isHourDisabled(this.computedHour)) {
|
||||
|
@ -101,9 +101,9 @@ export default {
|
||||
body.appendChild(footerPatch)
|
||||
if (timeout) {
|
||||
window.setTimeout(() => {
|
||||
const body = this.$refs.body
|
||||
if (body) {
|
||||
body.removeChild(footerPatch)
|
||||
const bodyDom = this.$refs.body
|
||||
if (bodyDom) {
|
||||
bodyDom.removeChild(footerPatch)
|
||||
}
|
||||
}, timeout)
|
||||
}
|
||||
@ -122,9 +122,9 @@ export default {
|
||||
body.appendChild(headerPatch)
|
||||
if (timeout) {
|
||||
window.setTimeout(() => {
|
||||
const body = this.$refs.body
|
||||
if (body) {
|
||||
body.removeChild(headerPatch)
|
||||
const bodyDom = this.$refs.body
|
||||
if (bodyDom) {
|
||||
bodyDom.removeChild(headerPatch)
|
||||
}
|
||||
}, timeout)
|
||||
}
|
||||
|
@ -268,12 +268,12 @@ export default {
|
||||
|
||||
// console.log(this.$refs.contentInner)
|
||||
if (this.$refs.contentInner) {
|
||||
let el = this.$refs.contentInner
|
||||
let element = this.$refs.contentInner
|
||||
if (this.$refs.contentInner.$el) {
|
||||
el = this.$refs.contentInner.$el
|
||||
element = this.$refs.contentInner.$el
|
||||
}
|
||||
if (this.widthMode === 'activator') {
|
||||
el.style.minWidth = activatorBoundingClientRect.width + 'px'
|
||||
element.style.minWidth = activatorBoundingClientRect.width + 'px'
|
||||
}
|
||||
}
|
||||
if (el && cb) {
|
||||
|
@ -146,10 +146,10 @@ function rootedOptions (options) {
|
||||
*/
|
||||
function patchedOptions (options, patches) {
|
||||
// console.log('patchedOptions input', options, patches)
|
||||
function traverse (options, depth = 0, parentId = 0) {
|
||||
if (!Array.isArray(options)) return
|
||||
for (let i = 0; i < options.length; ++i) {
|
||||
const option = options[i]
|
||||
function traverse (items, depth = 0, parentId = 0) {
|
||||
if (!Array.isArray(items)) return
|
||||
for (let i = 0; i < items.length; ++i) {
|
||||
const option = items[i]
|
||||
const id = `${parentId}_${i + 1}`
|
||||
// console.log('iterate on option', id)
|
||||
if (!hasChildren(option)) {
|
||||
@ -254,13 +254,13 @@ function applyDrop ([sourceNode, targetNode, type]) {
|
||||
}
|
||||
|
||||
function linkedCascaderOptions (options, type) {
|
||||
const linkedCascaderOptions = options
|
||||
const cascaderOptions = options
|
||||
const path = []
|
||||
function traverse (options, parent = null, depth = 0, parentId = 0) {
|
||||
if (!Array.isArray(options)) return
|
||||
const length = options.length
|
||||
function traverse (items, parent = null, depth = 0, parentId = 0) {
|
||||
if (!Array.isArray(items)) return
|
||||
const length = items.length
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const option = options[i]
|
||||
const option = items[i]
|
||||
if (depth > 0) path.push(option.label)
|
||||
/**
|
||||
* option.type determine option ui status
|
||||
@ -319,14 +319,14 @@ function linkedCascaderOptions (options, type) {
|
||||
}
|
||||
if (depth > 0) path.pop()
|
||||
}
|
||||
markAvailableSiblingIds(options)
|
||||
markFirstAvailableChildId(options)
|
||||
markAvailableSiblingIds(items)
|
||||
markFirstAvailableChildId(items)
|
||||
}
|
||||
traverse(linkedCascaderOptions)
|
||||
return linkedCascaderOptions
|
||||
traverse(cascaderOptions)
|
||||
return cascaderOptions
|
||||
}
|
||||
|
||||
function menuOptions (linkedCascaderOptions, value, type) {
|
||||
function menuOptions (cascaderOptions, value, type) {
|
||||
const valueSet = new Set(value)
|
||||
const checkedOptions = []
|
||||
function traverse (options) {
|
||||
@ -379,18 +379,18 @@ function menuOptions (linkedCascaderOptions, value, type) {
|
||||
}
|
||||
}
|
||||
}
|
||||
traverse(linkedCascaderOptions)
|
||||
traverse(cascaderOptions)
|
||||
// console.log('menuOptions', linkedCascaderOptions)
|
||||
return linkedCascaderOptions
|
||||
return cascaderOptions
|
||||
}
|
||||
|
||||
function optionPath (options, optionId) {
|
||||
const path = []
|
||||
if (optionId === null) return path
|
||||
let done = false
|
||||
function traverseOptions (options) {
|
||||
if (!Array.isArray(options) || !options.length) return
|
||||
for (const option of options) {
|
||||
function traverseOptions (items) {
|
||||
if (!Array.isArray(items) || !items.length) return
|
||||
for (const option of items) {
|
||||
if (done) return
|
||||
path.push(option)
|
||||
if (option.id === optionId) {
|
||||
@ -429,8 +429,8 @@ function menuModel (options, activeId, trackId, loadingId) {
|
||||
*/
|
||||
if (option.depth === 0) continue
|
||||
if (hasChildren(option)) {
|
||||
model.push(option.children.map(option => {
|
||||
return processedOption(option, activeIds, trackId, loadingId)
|
||||
model.push(option.children.map(item => {
|
||||
return processedOption(item, activeIds, trackId, loadingId)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -59,11 +59,11 @@ export default function calcPlacementTransform (placement, activatorRect, conten
|
||||
const toWindowRight = window.innerWidth - activatorRect.left - contentRect.width
|
||||
if (contentRect.height > toWindowBottom && activatorRect.top > toWindowBottom) {
|
||||
contentBottom = toWindowBottom + activatorRect.height
|
||||
contentTop = null
|
||||
// contentTop = null
|
||||
suggesetedTransfromOrigin = 'bottom'
|
||||
} else {
|
||||
contentTop = activatorRect.top + activatorRect.height
|
||||
contentBottom = null
|
||||
// contentBottom = null
|
||||
suggesetedTransfromOrigin = 'top'
|
||||
}
|
||||
if (toWindowRight < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user