代码规范
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -1,21 +1,37 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-tree-select
|
<div>
|
||||||
allowClear
|
<a-tree-select
|
||||||
labelInValue
|
v-if="isAsync"
|
||||||
tree-node-filter-prop="title"
|
allowClear
|
||||||
:getPopupContainer="(node) => node.parentNode"
|
tree-node-filter-prop="title"
|
||||||
style="width: 100%"
|
:getPopupContainer="(node) => node.parentNode"
|
||||||
:disabled="disabled"
|
style="width: 100%"
|
||||||
:dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
|
:disabled="disabled"
|
||||||
:placeholder="placeholder"
|
:dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
|
||||||
:loadData="asyncLoadTreeData"
|
:placeholder="placeholder"
|
||||||
:value="treeValue"
|
:loadData="asyncLoadTreeData"
|
||||||
:treeData="treeData"
|
:value="treeValue"
|
||||||
:multiple="multiple"
|
:treeData="treeData"
|
||||||
:show-search="!multiple"
|
:multiple="multiple"
|
||||||
@change="onChange"
|
:show-search="!multiple"
|
||||||
@search="onSearch">
|
@change="onChange">
|
||||||
</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,19 +126,18 @@
|
|||||||
this.loadItemByCode()
|
this.loadItemByCode()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
mounted(){
|
||||||
|
window.that = this
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadItemByCode(){
|
loadItemByCode(){
|
||||||
if(!this.value || this.value=="0"){
|
if( !this.value || this.value == "0" ){
|
||||||
this.treeValue = null
|
this.treeValue = null
|
||||||
}else{
|
}else{
|
||||||
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,71 +205,63 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loadRoot(){ // 初始化树
|
/**
|
||||||
let param = {
|
* 初始化树
|
||||||
pid:this.pidValue,
|
* isAsync:true===异步获取 false===同步获取数据 默认异步*/
|
||||||
tableName:this.tableName,
|
loadRoot(){
|
||||||
text:this.text,
|
if (this.isAsync){
|
||||||
code:this.code,
|
let param = {
|
||||||
pidField:this.pidField,
|
pid:this.pidValue,
|
||||||
hasChildField:this.hasChildField,
|
tableName:this.tableName,
|
||||||
condition:this.condition
|
text:this.text,
|
||||||
}
|
code:this.code,
|
||||||
getAction(this.url,param).then(res=>{
|
pidField:this.pidField,
|
||||||
if(res.success && res.result){
|
hasChildField:this.hasChildField,
|
||||||
for(let i of res.result){
|
condition:this.condition
|
||||||
i.value = i.key
|
|
||||||
if(i.leaf==false){
|
|
||||||
i.isLeaf=false
|
|
||||||
}else if(i.leaf==true){
|
|
||||||
i.isLeaf=true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.treeData = [...res.result]
|
|
||||||
}else{
|
|
||||||
console.log("数根节点查询结果-else",res)
|
|
||||||
}
|
}
|
||||||
})
|
getAction(this.url,param).then(res=>{
|
||||||
|
if(res.success && res.result){
|
||||||
|
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 = [...res.result]
|
||||||
|
}else{
|
||||||
|
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>
|
||||||
|
|||||||
Reference in New Issue
Block a user