From 44f5d94e592a3b4e1b14c56f642dcc05e3414062 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=AF=BA?= <1253070437@qq.com>
Date: Thu, 6 Jul 2023 01:30:45 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8D=87=E7=BA=A7=E3=80=91=E6=96=B0?=
=?UTF-8?q?=E5=A2=9ExnPageSelect=E5=88=86=E9=A1=B5=E7=BB=84=E4=BB=B6?=
=?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E5=9D=87=E5=B7=B2?=
=?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=AF=A5=E6=96=B0=E7=BB=84=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/components/XnPageSelect/index.vue | 144 +++++++++++++++
snowy-admin-web/src/views/biz/user/form.vue | 170 +++++++++---------
snowy-admin-web/src/views/sys/user/form.vue | 158 ++++++++--------
3 files changed, 319 insertions(+), 153 deletions(-)
create mode 100644 snowy-admin-web/src/components/XnPageSelect/index.vue
diff --git a/snowy-admin-web/src/components/XnPageSelect/index.vue b/snowy-admin-web/src/components/XnPageSelect/index.vue
new file mode 100644
index 00000000..f1f67b8d
--- /dev/null
+++ b/snowy-admin-web/src/components/XnPageSelect/index.vue
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
diff --git a/snowy-admin-web/src/views/biz/user/form.vue b/snowy-admin-web/src/views/biz/user/form.vue
index f2a829e2..16519683 100644
--- a/snowy-admin-web/src/views/biz/user/form.vue
+++ b/snowy-admin-web/src/views/biz/user/form.vue
@@ -76,28 +76,26 @@
-
-
+ :page-function="selectApiFunction.positionSelector"
+ :echo-function="selectApiFunction.echoPosition"
+ />
-
-
+ :page-function="selectApiFunction.userSelector"
+ :echo-function="selectApiFunction.echoUser"
+ />
@@ -139,7 +137,6 @@
>
@@ -157,28 +154,26 @@
:name="['positionJson', index, 'positionId']"
:rules="{ required: true, message: '请选择岗位' }"
>
-
-
+ :page-function="selectApiFunction.childPositionSelector"
+ :echo-function="selectApiFunction.echoPosition"
+ />
-
-
+ :page-function="selectApiFunction.childUserSelector"
+ :echo-function="selectApiFunction.echoUser"
+ />
@@ -331,27 +326,26 @@
import bizUserApi from '@/api/biz/bizUserApi'
import { required } from '@/utils/formRules'
import tool from '@/utils/tool'
+ import userCenterApi from '@/api/sys/userCenterApi'
// 默认是关闭状态
- let visible = $ref(false)
+ const visible = ref(false)
const formRef = ref()
const activeTabsKey = ref('1')
const emit = defineEmits({ successful: null })
const formLoading = ref(false)
const treeData = ref([])
const treeDefaultExpandedKeys = ref([])
- // 主职职位数据
- let positionData = ref([])
- // 主职主管人员数据
- let directorData = ref([])
-
- // 定义一个装机构跟职位的壳
- let childrenOrgPosArray = ref([])
+ // 分页select组件dom定义
+ const xnPositionPageSelectRef = ref()
+ const xnUserPageSelectRef = ref()
+ const xnChildPositionPageSelectRef = ref()
+ const xnChildUserPageSelectRef = ref()
// 表单数据
- let formData = ref({})
+ const formData = ref({})
// 打开抽屉
const onOpen = (record, orgId) => {
- visible = true
+ visible.value = true
formData.value = {
gender: '男',
positionJson: []
@@ -392,9 +386,7 @@
const onClose = () => {
treeData.value = []
treeDefaultExpandedKeys.value = []
- positionData.value = []
- directorData.value = []
- visible = false
+ visible.value = false
}
// 回显数据
const convertFormData = (record) => {
@@ -404,14 +396,18 @@
// 查询详情
bizUserApi.userDetail(param).then((data) => {
if (data.positionJson) {
- const positionJsonLocal = JSON.parse(data.positionJson).map((item) => {
- childOrgSelect(item)
- return item
- })
// 替换表单中的格式与后端查到的
- data.positionJson = positionJsonLocal
+ data.positionJson = JSON.parse(data.positionJson)
}
formData.value = Object.assign(formData.value, data)
+ // 这里再写一次是因为上面需要先加载增行,下面再进行循环赋值
+ if (data.positionJson) {
+ // 遍历进行补充
+ data.positionJson.map((item, index) => {
+ childOrgSelect(item, 1, index)
+ return item
+ })
+ }
selePositionData(formData.value.orgId)
})
}
@@ -426,16 +422,14 @@
// 机构选择后查询对应的职位
const selePositionData = (orgId, type) => {
if (orgId) {
- const param = {
- orgId: orgId,
- size: -1
+ const xnPositionPageSelectParam = {
+ orgId: orgId
}
- bizUserApi.userPositionSelector(param).then((data) => {
- positionData.value = data.records
- })
- bizUserApi.userSelector().then((data) => {
- directorData.value = data.records
- })
+ xnPositionPageSelectRef.value.onPage(xnPositionPageSelectParam)
+ const xnUserPageSelectParam = {
+ orgId: orgId
+ }
+ xnUserPageSelectRef.value.onPage(xnUserPageSelectParam)
// 此类型代表选择的时候重置后面的职位
if (type === 0) {
formData.value.positionId = undefined
@@ -446,6 +440,40 @@
formData.value.directorId = undefined
}
}
+ // 传递选择组件需要的API
+ const selectApiFunction = {
+ positionSelector: (param) => {
+ return bizUserApi.userPositionSelector(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
+ userSelector: (param) => {
+ return bizUserApi.userSelector(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
+ childPositionSelector: (param) => {
+ return bizUserApi.userPositionSelector(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
+ childUserSelector: (param) => {
+ return bizUserApi.userSelector(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
+ // 通过id回显数据接口
+ echoPosition: (param) => {
+ return userCenterApi.userCenterGetPositionListByIdList(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
+ echoUser: (param) => {
+ return userCenterApi.userCenterGetUserListByIdList(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ }
+ }
// 附属职位信息增行
const addDomains = () => {
if (formData.value.positionJson === null) {
@@ -462,11 +490,11 @@
formData.value.positionJson.splice(index, 1)
}
// 子表行内选择机构
- const childOrgSelect = async (data, type) => {
+ const childOrgSelect = async (data, type, index) => {
// 说明正在切换机构,我们就将他的后面的设置空
if (type === 0) {
- formData.value.positionJson.filter((item) => {
- if (item.orgId === data.orgId) {
+ formData.value.positionJson.filter((item, serial) => {
+ if (item.orgId === data.orgId && serial === index) {
item.positionId = undefined
item.directorId = undefined
}
@@ -475,30 +503,10 @@
const param = {
orgId: data.orgId
}
- // 查询职位
- const posList = await bizUserApi.userPositionSelector(param)
- // 查询人员
- const userList = await bizUserApi.userSelector(param)
- const obj = {
- orgId: data.orgId,
- posList: posList.records,
- userList: userList.records
- }
- childrenOrgPosArray.value.push(obj)
- }
- // 获取行内职位数据
- const childPosData = (value) => {
- const resultData = childrenOrgPosArray.value.filter((item) => item.orgId === value)
- if (resultData.length > 0) {
- return resultData[0].posList
- }
- }
- // 获取行内人员数据
- const childUserData = (value) => {
- const resultData = childrenOrgPosArray.value.filter((item) => item.orgId === value)
- if (resultData.length > 0) {
- return resultData[0].userList
- }
+ nextTick(() => {
+ xnChildPositionPageSelectRef.value[index].onPage(param)
+ xnChildUserPageSelectRef.value[index].onPage(param)
+ })
}
// 验证并提交数据
const onSubmit = () => {
diff --git a/snowy-admin-web/src/views/sys/user/form.vue b/snowy-admin-web/src/views/sys/user/form.vue
index 837a55b7..1f835a7f 100644
--- a/snowy-admin-web/src/views/sys/user/form.vue
+++ b/snowy-admin-web/src/views/sys/user/form.vue
@@ -76,25 +76,25 @@
-
-
@@ -137,7 +137,6 @@
>
@@ -155,25 +154,25 @@
:name="['positionJson', index, 'positionId']"
:rules="{ required: true, message: '请选择职位' }"
>
-
-
@@ -327,29 +326,28 @@