forked from wangjiadong/comp
parent
2fc9136657
commit
1614ce0094
8 changed files with 471 additions and 25 deletions
@ -0,0 +1,169 @@ |
||||
<!--部门选择组件--> |
||||
<template> |
||||
<div> |
||||
<JSelectBiz @handleOpen="handleOpen" :loading="loadingEcho" v-bind="attrs" @change="handleChange"/> |
||||
<DeptStuSelectModal @register="regModal" @getSelectResult="setValue" v-bind="getBindValue" /> |
||||
</div> |
||||
</template> |
||||
<script lang="ts"> |
||||
import DeptStuSelectModal from './modal/DeptStuSelectModal.vue'; |
||||
import JSelectBiz from './base/JSelectBiz.vue'; |
||||
import { defineComponent, ref, reactive, watchEffect, watch, provide, unref, toRaw } from 'vue'; |
||||
import { useModal } from '/@/components/Modal'; |
||||
import { propTypes } from '/@/utils/propTypes'; |
||||
import { useRuleFormItem } from '/@/hooks/component/useFormItem'; |
||||
import { useAttrs } from '/@/hooks/core/useAttrs'; |
||||
import { SelectValue } from 'ant-design-vue/es/select'; |
||||
|
||||
export default defineComponent({ |
||||
name: 'JStuSelectDept', |
||||
components: { |
||||
DeptStuSelectModal, |
||||
JSelectBiz, |
||||
}, |
||||
inheritAttrs: false, |
||||
props: { |
||||
value: propTypes.oneOfType([propTypes.string, propTypes.array]), |
||||
// 是否允许多选,默认 true |
||||
multiple: propTypes.bool.def(true), |
||||
}, |
||||
emits: ['options-change', 'change', 'select', 'update:value'], |
||||
setup(props, { emit, refs }) { |
||||
const emitData = ref<any[]>(); |
||||
//注册model |
||||
const [regModal, { openModal }] = useModal(); |
||||
//表单值 |
||||
const [state] = useRuleFormItem(props, 'value', 'change', emitData); |
||||
//下拉框选项值 |
||||
const selectOptions = ref<SelectValue>([]); |
||||
//下拉框选中值 |
||||
let selectValues = reactive<Recordable>({ |
||||
value: [], |
||||
}); |
||||
// 是否正在加载回显数据 |
||||
const loadingEcho = ref<boolean>(false); |
||||
//下发 selectOptions,xxxBiz组件接收 |
||||
provide('selectOptions', selectOptions); |
||||
//下发 selectValues,xxxBiz组件接收 |
||||
provide('selectValues', selectValues); |
||||
//下发 loadingEcho,xxxBiz组件接收 |
||||
provide('loadingEcho', loadingEcho); |
||||
|
||||
const tag = ref(false); |
||||
const attrs = useAttrs(); |
||||
|
||||
/** |
||||
* 监听组件值 |
||||
*/ |
||||
watchEffect(() => { |
||||
props.value && initValue(); |
||||
}); |
||||
|
||||
//update-begin-author:liusq---date:20220609--for: 为了解决弹窗form初始化赋值问题 --- |
||||
watch( |
||||
() => props.value, |
||||
() => { |
||||
initValue(); |
||||
} |
||||
); |
||||
//update-end-author:liusq---date:20220609--for: 为了解决弹窗form初始化赋值问题 --- |
||||
/** |
||||
* 监听selectValues变化 |
||||
*/ |
||||
watch(selectValues, () => { |
||||
if (selectValues) { |
||||
state.value = selectValues.value; |
||||
} |
||||
}); |
||||
/** |
||||
* 监听selectOptions变化 |
||||
*/ |
||||
watch(selectOptions, () => { |
||||
if (selectOptions) { |
||||
emit('select', toRaw(unref(selectOptions)), toRaw(unref(selectValues))); |
||||
} |
||||
}); |
||||
|
||||
/** |
||||
* 打卡弹出框 |
||||
*/ |
||||
function handleOpen() { |
||||
tag.value = true; |
||||
openModal(true, { |
||||
isUpdate: false, |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 将字符串值转化为数组 |
||||
*/ |
||||
function initValue() { |
||||
let value = props.value ? props.value : []; |
||||
if (value && typeof value === 'string') { |
||||
state.value = value.split(','); |
||||
selectValues.value = value.split(','); |
||||
} else { |
||||
// 【VUEN-857】兼容数组(行编辑的用法问题) |
||||
selectValues.value = value; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置下拉框的值 |
||||
*/ |
||||
function setValue(options, values) { |
||||
selectOptions.value = options; |
||||
//emitData.value = values.join(","); |
||||
state.value = values; |
||||
selectValues.value = values; |
||||
emit('update:value', values.join(',')); |
||||
} |
||||
const getBindValue = Object.assign({}, unref(props), unref(attrs)); |
||||
|
||||
//update-begin---author:wangshuai ---date:20230406 for:【issues/397】在表单中使用v-model:value绑定JSelectDept组件时无法清除已选择的数据------------ |
||||
/** |
||||
* 值改变事件更新value值 |
||||
* @param values |
||||
*/ |
||||
function handleChange(values) { |
||||
emit('update:value', values); |
||||
} |
||||
//update-end---author:wangshuai ---date:20230406 for:【issues/397】在表单中使用v-model:value绑定JSelectDept组件时无法清除已选择的数据------------ |
||||
|
||||
return { |
||||
state, |
||||
attrs, |
||||
selectOptions, |
||||
selectValues, |
||||
loadingEcho, |
||||
getBindValue, |
||||
tag, |
||||
regModal, |
||||
setValue, |
||||
handleOpen, |
||||
handleChange |
||||
}; |
||||
}, |
||||
}); |
||||
</script> |
||||
<style lang="less" scoped> |
||||
.j-select-row { |
||||
@width: 82px; |
||||
|
||||
.left { |
||||
width: calc(100% - @width - 8px); |
||||
} |
||||
|
||||
.right { |
||||
width: @width; |
||||
} |
||||
|
||||
.full { |
||||
width: 100%; |
||||
} |
||||
|
||||
:deep(.ant-select-search__field) { |
||||
display: none !important; |
||||
} |
||||
} |
||||
</style> |
@ -0,0 +1,122 @@ |
||||
<!--部门选择框--> |
||||
<template> |
||||
<div> |
||||
<BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="500px" @ok="handleOk" destroyOnClose @visible-change="visibleChange"> |
||||
<BasicTree |
||||
ref="treeRef" |
||||
:treeData="treeData" |
||||
:load-data="sync == false ? null : onLoadData" |
||||
v-bind="getBindValue" |
||||
@select="onSelect" |
||||
@check="onCheck" |
||||
:fieldNames="fieldNames" |
||||
:checkedKeys="checkedKeys" |
||||
:checkStrictly="getCheckStrictly" |
||||
/> |
||||
<!--树操作部分--> |
||||
<template #insertFooter> |
||||
<a-dropdown placement="top"> |
||||
<template #overlay> |
||||
<a-menu> |
||||
<!-- <a-menu-item v-if="multiple" key="1" @click="checkALL(true)">全部勾选</a-menu-item>--> |
||||
<!-- <a-menu-item v-if="multiple" key="2" @click="checkALL(false)">取消全选</a-menu-item>--> |
||||
<a-menu-item key="3" @click="expandAll(true)">展开全部</a-menu-item> |
||||
<a-menu-item key="4" @click="expandAll(false)">折叠全部</a-menu-item> |
||||
</a-menu> |
||||
</template> |
||||
<a-button style="float: left"> 树操作 <Icon icon="ant-design:up-outlined" /> </a-button> |
||||
</a-dropdown> |
||||
</template> |
||||
</BasicModal> |
||||
</div> |
||||
</template> |
||||
<script lang="ts"> |
||||
import { defineComponent, ref, unref } from 'vue'; |
||||
import { BasicModal, useModalInner } from '/@/components/Modal'; |
||||
import { queryStuDepartTreeSync, queryStuTreeList } from '/@/api/common/api'; |
||||
import { useAttrs } from '/@/hooks/core/useAttrs'; |
||||
import { treeProps } from '/@/components/Form/src/jeecg/props/props'; |
||||
import { BasicTree, TreeActionType } from '/@/components/Tree'; |
||||
import { useTreeBiz } from '/@/components/Form/src/jeecg/hooks/useTreeBiz'; |
||||
import {propTypes} from "/@/utils/propTypes"; |
||||
|
||||
export default defineComponent({ |
||||
name: 'DeptStuSelectModal', |
||||
components: { |
||||
BasicModal, |
||||
BasicTree, |
||||
}, |
||||
props: { |
||||
...treeProps, |
||||
//选择框标题 |
||||
modalTitle: { |
||||
type: String, |
||||
default: '院系选择', |
||||
}, |
||||
value: propTypes.oneOfType([propTypes.string, propTypes.array]) |
||||
}, |
||||
emits: ['register', 'getSelectResult'], |
||||
setup(props, { emit, refs }) { |
||||
//注册弹框 |
||||
const [register, { closeModal }] = useModalInner(); |
||||
const attrs = useAttrs(); |
||||
const treeRef = ref<Nullable<TreeActionType>>(null); |
||||
|
||||
//update-begin-author:taoyan date:2022-10-28 for: 部门选择警告类型不匹配 |
||||
let propValue = props.value === ''?[]:props.value; |
||||
//update-begin-author:liusq date:2023-05-26 for: [issues/538]JSelectDept组件受 dynamicDisabled 影响 |
||||
const getBindValue = Object.assign({}, unref(props), unref(attrs), {value: propValue},{disabled: false}); |
||||
//update-end-author:liusq date:2023-05-26 for: [issues/538]JSelectDept组件受 dynamicDisabled 影响 |
||||
//update-end-author:taoyan date:2022-10-28 for: 部门选择警告类型不匹配 |
||||
|
||||
const queryUrl = getQueryUrl(); |
||||
const [{ visibleChange, checkedKeys, getCheckStrictly, getSelectTreeData, onCheck, onLoadData, treeData, checkALL, expandAll, onSelect }] = |
||||
useTreeBiz(treeRef, queryUrl, getBindValue); |
||||
const searchInfo = ref(props.params); |
||||
const tree = ref([]); |
||||
//替换treeNode中key字段为treeData中对应的字段 |
||||
const fieldNames = { |
||||
key: props.rowKey, |
||||
}; |
||||
// {children:'children', title:'title', key:'key' } |
||||
/** |
||||
* 确定选择 |
||||
*/ |
||||
function handleOk() { |
||||
getSelectTreeData((options, values) => { |
||||
//回传选项和已选择的值 |
||||
emit('getSelectResult', options, values); |
||||
//关闭弹窗 |
||||
closeModal(); |
||||
}); |
||||
} |
||||
|
||||
/** 获取查询数据方法 */ |
||||
function getQueryUrl() { |
||||
let queryFn = props.sync ? queryStuDepartTreeSync : queryStuTreeList; |
||||
//update-begin-author:taoyan date:2022-7-4 for: issues/I5F3P4 online配置部门选择后编辑,查看数据应该显示部门名称,不是部门代码 |
||||
return (params) => queryFn(Object.assign({}, params, { primaryKey: props.rowKey })); |
||||
//update-end-author:taoyan date:2022-7-4 for: issues/I5F3P4 online配置部门选择后编辑,查看数据应该显示部门名称,不是部门代码 |
||||
} |
||||
|
||||
return { |
||||
tree, |
||||
handleOk, |
||||
searchInfo, |
||||
treeRef, |
||||
treeData, |
||||
onCheck, |
||||
onSelect, |
||||
checkALL, |
||||
expandAll, |
||||
fieldNames, |
||||
checkedKeys, |
||||
register, |
||||
getBindValue, |
||||
getCheckStrictly, |
||||
visibleChange, |
||||
onLoadData, |
||||
}; |
||||
}, |
||||
}); |
||||
</script> |
Loading…
Reference in new issue