fix(components): 修复组件中的空值处理和命名规范问题
This commit is contained in:
@@ -74,8 +74,8 @@ export default {
|
|||||||
// 绑定node-click事件
|
// 绑定node-click事件
|
||||||
this.$emit('node-click', value)
|
this.$emit('node-click', value)
|
||||||
// 绑定form value
|
// 绑定form value
|
||||||
this.$emit('change', value.id)
|
this.$emit('change', value ? value.id : null)
|
||||||
this.$emit('input', value.id)
|
this.$emit('input', value ? value.id : null)
|
||||||
},
|
},
|
||||||
resetField() {
|
resetField() {
|
||||||
this.$refs.deptTree.setCurrentNode(null)
|
this.$refs.deptTree.setCurrentNode(null)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export default {
|
|||||||
let isLt2M = true
|
let isLt2M = true
|
||||||
isLt2M = file.size / 1024 ** 2 < 100
|
isLt2M = file.size / 1024 ** 2 < 100
|
||||||
if (!isLt2M) {
|
if (!isLt2M) {
|
||||||
this.$message.error('上传文件大小不能超过 100MB')
|
KitMessage.Error('上传文件大小不能超过 100MB')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return isLt2M
|
return isLt2M
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export default {
|
|||||||
let isLt2M = true
|
let isLt2M = true
|
||||||
isLt2M = file.size / 1024 ** 2 < 100
|
isLt2M = file.size / 1024 ** 2 < 100
|
||||||
if (!isLt2M) {
|
if (!isLt2M) {
|
||||||
this.$message.error('上传文件大小不能超过 100MB')
|
KitMessage.Error('上传文件大小不能超过 100MB')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return isLt2M
|
return isLt2M
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in deptOptions"
|
v-for="item in productLineOptions"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.label"
|
:label="item.label"
|
||||||
:value="item.value"
|
:value="item.value"
|
||||||
@@ -44,7 +44,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
deptOptions: [],
|
productLineOptions: [],
|
||||||
innerValue: this.value
|
innerValue: this.value
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -59,7 +59,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
fetchDeptData() {
|
fetchDeptData() {
|
||||||
listMetadata().then(data => {
|
listMetadata().then(data => {
|
||||||
this.deptOptions = data
|
this.productLineOptions = data
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('获取部门数据失败:', error)
|
console.error('获取部门数据失败:', error)
|
||||||
KitMessage.Error('获取部门数据失败')
|
KitMessage.Error('获取部门数据失败')
|
||||||
@@ -67,7 +67,7 @@ export default {
|
|||||||
},
|
},
|
||||||
handleChange(value) {
|
handleChange(value) {
|
||||||
this.innerValue = value
|
this.innerValue = value
|
||||||
for (const item of this.deptOptions) {
|
for (const item of this.productLineOptions) {
|
||||||
if (item.value === value) {
|
if (item.value === value) {
|
||||||
this.$emit('detail', item)
|
this.$emit('detail', item)
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<el-cascader
|
<el-cascader
|
||||||
v-model="innerValue"
|
v-model="innerValue"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:options="deptOptions"
|
:options="productLineOptions"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
placeholder="请选择产品线"
|
placeholder="请选择产品线"
|
||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
@@ -36,7 +36,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
deptOptions: [],
|
productLineOptions: [],
|
||||||
innerValue: this.value
|
innerValue: this.value
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -51,6 +51,9 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
// 递归清理空的children属性
|
// 递归清理空的children属性
|
||||||
cleanEmptyChildren(data) {
|
cleanEmptyChildren(data) {
|
||||||
|
if (!data || !Array.isArray(data)) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
return data.map(item => {
|
return data.map(item => {
|
||||||
const newItem = { ...item }
|
const newItem = { ...item }
|
||||||
if (newItem.children && newItem.children.length > 0) {
|
if (newItem.children && newItem.children.length > 0) {
|
||||||
@@ -65,8 +68,7 @@ export default {
|
|||||||
},
|
},
|
||||||
fetchDeptData() {
|
fetchDeptData() {
|
||||||
listMetadata().then(data => {
|
listMetadata().then(data => {
|
||||||
this.deptOptions = this.cleanEmptyChildren(data)
|
this.productLineOptions = this.cleanEmptyChildren(data)
|
||||||
// console.error('deptOptions', this.deptOptions)
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('获取部门数据失败:', error)
|
console.error('获取部门数据失败:', error)
|
||||||
KitMessage.Error('获取部门数据失败')
|
KitMessage.Error('获取部门数据失败')
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
innerValue: [],
|
innerValue: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
options: []
|
options: []
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user