Merge remote-tracking branch 'origin/master'

This commit is contained in:
zer0Black
2021-03-24 15:07:59 +08:00
2 changed files with 126 additions and 109 deletions
+14 -24
View File
@@ -10,7 +10,8 @@
:value="momVal" :value="momVal"
:showTime="true" :showTime="true"
:format="dateFormat" :format="dateFormat"
:getCalendarContainer="getCalendarContainer"></a-date-picker> :getCalendarContainer="getCalendarContainer">
</a-date-picker>
<!--YYYY-MM-DD--> <!--YYYY-MM-DD-->
<a-date-picker <a-date-picker
v-if="showType === 'day'" v-if="showType === 'day'"
@@ -21,7 +22,8 @@
:value="momVal" :value="momVal"
:showTime="false" :showTime="false"
:format="dateFormat" :format="dateFormat"
:getCalendarContainer="getCalendarContainer"></a-date-picker> :getCalendarContainer="getCalendarContainer">
</a-date-picker>
<!--YYYY-MM--> <!--YYYY-MM-->
<a-month-picker <a-month-picker
v-if="showType === 'month'" v-if="showType === 'month'"
@@ -29,7 +31,8 @@
:value="momVal" :value="momVal"
:disabled="disabled || readOnly" :disabled="disabled || readOnly"
:format="dateFormat" :format="dateFormat"
@change="handleMonthChange"></a-month-picker> @change="handleMonthChange">
</a-month-picker>
<!--YYYY--> <!--YYYY-->
<a-date-picker <a-date-picker
v-if="showType === 'year'" v-if="showType === 'year'"
@@ -37,12 +40,12 @@
mode="year" mode="year"
:format="dateFormat" :format="dateFormat"
:value="year" :value="year"
@disabledDate="disabledDate"
:disabled="disabled || readOnly" :disabled="disabled || readOnly"
:open="yearShowOne" :open="yearShowOne"
:getCalendarContainer="getCalendarContainer" :getCalendarContainer="getCalendarContainer"
@openChange="openChangeOne" @openChange="openChangeOne"
@panelChange="panelChangeOne"></a-date-picker> @panelChange="panelChangeOne">
</a-date-picker>
</div> </div>
</template> </template>
<script> <script>
@@ -64,12 +67,6 @@
default: 'YYYY-MM-DD', default: 'YYYY-MM-DD',
required: false required: false
}, },
//此属性可以被废弃了
triggerChange:{
type: Boolean,
required: false,
default: false
},
readOnly:{ readOnly:{
type: Boolean, type: Boolean,
required: false, required: false,
@@ -95,8 +92,7 @@
let dateStr = this.value; let dateStr = this.value;
return { return {
yearShowOne:false, //控制年份模态框的显示与否 yearShowOne:false, //控制年份模态框的显示与否
year:'', year:'', // mode==“year” 专用
decorator:"",
momVal:!dateStr?null:moment(dateStr,this.dateFormat), momVal:!dateStr?null:moment(dateStr,this.dateFormat),
} }
}, },
@@ -110,9 +106,6 @@
} }
}, },
methods: { methods: {
disabledDate(current){
return new Date(current._d).setFullYear((new Date(current._d).getFullYear())) < new Date(moment()._d).setFullYear((new Date(moment()._d).getFullYear() - 1))
},
moment, moment,
handleDateChange(mom,dateStr){ handleDateChange(mom,dateStr){
this.$emit('change', dateStr); this.$emit('change', dateStr);
@@ -120,9 +113,11 @@
handleMonthChange(mom,dateStr){ handleMonthChange(mom,dateStr){
this.$emit('change',dateStr) this.$emit('change',dateStr)
}, },
// 弹出日历和关闭日历的回调 /**
* 弹出日历和关闭日历的回调
* status:打开或关闭的状态
* */
openChangeOne(status){ openChangeOne(status){
//status是打开或关闭的状态
this.yearShowOne = status this.yearShowOne = status
}, },
// 得到年份选择器的值 // 得到年份选择器的值
@@ -133,15 +128,10 @@
this.$emit('change',year) this.$emit('change',year)
} }
}, },
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'change'
} }
} }
// let bodyO = document.querySelector()
// bodyO.onclick = function (){
// console.log(0)
// }
</script> </script>
+74 -47
View File
@@ -1,7 +1,8 @@
<template> <template>
<div>
<a-tree-select <a-tree-select
v-if="isAsync"
allowClear allowClear
labelInValue
tree-node-filter-prop="title" tree-node-filter-prop="title"
:getPopupContainer="(node) => node.parentNode" :getPopupContainer="(node) => node.parentNode"
style="width: 100%" style="width: 100%"
@@ -13,9 +14,24 @@
:treeData="treeData" :treeData="treeData"
:multiple="multiple" :multiple="multiple"
:show-search="!multiple" :show-search="!multiple"
@change="onChange" @change="onChange">
@search="onSearch">
</a-tree-select> </a-tree-select>
<a-tree-select
v-if="!isAsync"
allowClear
tree-node-filter-prop="title"
:getPopupContainer="(node) => node.parentNode"
style="width: 100%"
:disabled="disabled"
:dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
:placeholder="placeholder"
:value="treeValue"
:treeData="treeData"
:multiple="multiple"
:show-search="!multiple"
@change="onChange">
</a-tree-select>
</div>
</template> </template>
<script> <script>
@@ -28,6 +44,11 @@
export default { export default {
name: 'JTreeSelect', name: 'JTreeSelect',
props: { props: {
isAsync:{ // 是否采用异步方式初始化树
type:Boolean,
required:true,
default:true
},
value:{ value:{
type: String, type: String,
required: false required: false
@@ -80,8 +101,8 @@
}, },
data () { data () {
return { return {
treeValue: null, treeValue: null, // 选中的数据
treeData:[], treeData:[],// 渲染树的数组
url:"/sys/dict/loadTreeData", url:"/sys/dict/loadTreeData",
view:'/sys/dict/loadDictItem/', view:'/sys/dict/loadDictItem/',
tableName:"", tableName:"",
@@ -95,7 +116,7 @@
}, },
dict(){ dict(){
this.initDictInfo() this.initDictInfo()
this.loadRoot(); this.loadRoot()
} }
}, },
created(){ created(){
@@ -105,6 +126,9 @@
this.loadItemByCode() this.loadItemByCode()
}) })
}, },
mounted(){
window.that = this
},
methods: { methods: {
loadItemByCode(){ loadItemByCode(){
if( !this.value || this.value == "0" ){ if( !this.value || this.value == "0" ){
@@ -113,11 +137,7 @@
getAction(`${this.view}${this.dict}`,{key:this.value}).then(res=>{ getAction(`${this.view}${this.dict}`,{key:this.value}).then(res=>{
if(res.success){ if(res.success){
let values = this.value.split(',') let values = this.value.split(',')
this.treeValue = res.result.map((item, index) => ({ this.treeValue = values // v-model接收的是string || string[]
key: values[index],
value: values[index],
label: item
}))
this.onLoadTriggleChange(res.result[0]); this.onLoadTriggleChange(res.result[0]);
} }
}) })
@@ -135,6 +155,7 @@
this.text = arr[1] this.text = arr[1]
this.code = arr[2] this.code = arr[2]
}, },
//异步加载树节点
asyncLoadTreeData (treeNode) { asyncLoadTreeData (treeNode) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (treeNode.$vnode.children) { if (treeNode.$vnode.children) {
@@ -151,10 +172,8 @@
hasChildField:this.hasChildField, hasChildField:this.hasChildField,
condition:this.condition condition:this.condition
} }
console.log(param)
getAction(this.url,param).then(res=>{ getAction(this.url,param).then(res=>{
if(res.success){ if(res.success){
console.log(res)
for(let i of res.result){ for(let i of res.result){
i.value = i.key i.value = i.key
if(i.leaf==false){ if(i.leaf==false){
@@ -173,11 +192,11 @@
addChildren(pid,children,treeArray){ addChildren(pid,children,treeArray){
if(treeArray && treeArray.length>0){ if(treeArray && treeArray.length>0){
for(let item of treeArray){ for(let item of treeArray){
if(item.key == pid){ if(item.key == pid){ //找到当前元素所在的父节点
if(!children || children.length==0){ if(!children || children.length==0){
item.isLeaf=true item.isLeaf=true
}else{ }else{
item.children = children item.children = children // 搜索出来的children添加到原树子children
} }
break break
}else{ }else{
@@ -186,7 +205,11 @@
} }
} }
}, },
loadRoot(){ // 初始化树 /**
* 初始化树
* isAsynctrue===异步获取 false===同步获取数据 默认异步*/
loadRoot(){
if (this.isAsync){
let param = { let param = {
pid:this.pidValue, pid:this.pidValue,
tableName:this.tableName, tableName:this.tableName,
@@ -211,46 +234,34 @@
console.log("数根节点查询结果-else",res) console.log("数根节点查询结果-else",res)
} }
}) })
}else{
//同步
let param = {
code:this.code,
pidField:this.pidField,
tableName:this.tableName,
text:this.text
}
getAction('/sys/dict/queryAllTreeData',param).then((res)=>{
if (res.success){
this.treeData = deepFor(res.result)
}
})
}
}, },
onChange(value){ onChange(value){
if(!value){ if(!value){
this.$emit('change', ''); this.$emit('change', '');
this.treeValue = null this.treeValue = null
} else if (value instanceof Array) { } else if (value instanceof Array) {
this.$emit('change', value.map(item => item.value).join(',')) //多选
this.$emit('change', value.join(',').toString()) //修改第一次选中时,选中为空的情况
this.treeValue = value this.treeValue = value
} else { } else {
this.$emit('change', value.value,value.label) //单选
this.$emit('change', value)
this.treeValue = value this.treeValue = value
} }
},
onSearch(value){
let param = {
code:this.code,
keyword:value,
pidField:this.pidField,
tableName:this.tableName,
text:this.text
}
getAction('/sys/dict/queryTreeDataByKeyword',param).then((res)=>{
if (res.success){
//设置是否是叶子节点(是否能展开)
for(let i of res.result){
i.value = i.key
if(i.leaf==false){
i.isLeaf=false
}else if(i.leaf==true){
i.isLeaf=true
}
}
//赋值树的数据
this.treeData = []
this.treeData = [...res.result]
// this.treeData = fn(res.result)
// fn(res.result)
}
})
}, },
getCurrTreeData(){ getCurrTreeData(){
return this.treeData return this.treeData
@@ -277,10 +288,26 @@
}) })
} }
}, },
//2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼 //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型
model: { model: {
prop: 'value', prop: 'value',
event: 'change' event: 'change'
} }
} }
//递归整个树,判断是否是叶子节点----同步获取数据时用到
function deepFor(source){
for(let i of source){
i.value = i.key
if(i.leaf==false){
i.isLeaf=false
}else if(i.leaf==true){
i.isLeaf=true
}
if (i.children && i.children.length > 0){
deepFor(i.children)
}
}
return source
}
</script> </script>