提交 1c6b4c86 编写于 作者: Mosher's avatar Mosher

新增下拉列表框对数值类型的处理逻辑

上级 7db66caf
...@@ -170,10 +170,20 @@ export default class DropDownList extends Vue { ...@@ -170,10 +170,20 @@ export default class DropDownList extends Vue {
/** /**
* 属性类型 * 属性类型
* @type {string} *
* @type {'string' | 'number'}
* @memberof DropDownList
*/
@Prop({ default: 'string' })
public valueType!: 'string' | 'number';
/**
* 选择实际值
*
* @type {*}
* @memberof DropDownList * @memberof DropDownList
*/ */
@Prop() public valueType?: string; public value: any = null;
/** /**
* 计算属性(当前值) * 计算属性(当前值)
...@@ -204,7 +214,7 @@ export default class DropDownList extends Vue { ...@@ -204,7 +214,7 @@ export default class DropDownList extends Vue {
}) })
return JSON.stringify([result]); return JSON.stringify([result]);
} }
return this.itemValue; return this.value;
} }
/** /**
...@@ -263,10 +273,12 @@ export default class DropDownList extends Vue { ...@@ -263,10 +273,12 @@ export default class DropDownList extends Vue {
this.formStateEvent = this.formState.subscribe(({ type, data }) => { this.formStateEvent = this.formState.subscribe(({ type, data }) => {
if (Object.is('load', type)) { if (Object.is('load', type)) {
this.loadData(); this.loadData();
this.readyValue();
} }
}); });
} }
this.loadData(); this.loadData();
this.readyValue();
} }
/** /**
...@@ -298,6 +310,29 @@ export default class DropDownList extends Vue { ...@@ -298,6 +310,29 @@ export default class DropDownList extends Vue {
}); });
} }
} }
/**
* 准备值
*
* @memberof DropDownList
*/
public readyValue() {
if (this.itemValue == null) {
this.value = null;
return;
}
if (this.$util.typeOf(this.itemValue) === this.valueType) {
this.value = this.itemValue;
} else if (this.valueType === 'number') {
if (this.itemValue.indexOf('.') === -1) {
this.value = parseInt(this.itemValue);
} else {
this.value = parseFloat(this.itemValue);
}
} else {
this.value = this.itemValue.toString();
}
}
/** /**
* 下拉点击事件 * 下拉点击事件
...@@ -331,32 +366,29 @@ export default class DropDownList extends Vue { ...@@ -331,32 +366,29 @@ export default class DropDownList extends Vue {
* @memberof DropDownList * @memberof DropDownList
*/ */
public formatCodeList(items: Array<any>){ public formatCodeList(items: Array<any>){
let matching: boolean = true; let matching: boolean = false;
this.items = []; this.items = [];
try{ try{
if(this.valueType){ items.forEach((item: any)=>{
items.forEach((item: any)=>{ const type = this.$util.typeOf(item.value);
const type = this.$util.typeOf(item.value); if(type != this.valueType){
if(type != this.valueType){ matching = true;
matching = false; if(type === 'number'){
if(type == 'number'){ item.value = item.value.toString();
item.value = item.value.toString(); }else{
if(item.value.indexOf('.') == -1){
item.value = parseInt(item.value);
}else{ }else{
if(item.value.indexOf('.') == -1){ item.value = parseFloat(item.value);
item.value = parseInt(item.value);
}else{
item.value = parseFloat(item.value);
}
} }
} }
this.items.push(item);
});
if(!matching){
console.warn(`代码表 ${ this.tag } 值类型和属性类型不匹配,已自动强制转换,请修正代码表值类型和属性类型匹配`);
} }
}else{ this.items.push(item);
this.items = items; });
if(matching){
console.warn(`代码表 ${ this.tag } 值类型和属性类型不匹配,已自动强制转换,请修正代码表值类型和属性类型匹配`);
} }
}catch(error){ }catch(error){
console.warn('代码表值类型和属性类型不匹配,自动强制转换异常,请修正代码表值类型和属性类型匹配'); console.warn('代码表值类型和属性类型不匹配,自动强制转换异常,请修正代码表值类型和属性类型匹配');
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册