Commit 7ce875284e16c8b70c8680d2d56c8ea73f4fd193
Merge branch 'fengtao' into 'main_dev'
fix: DEFECT-1902 客户账号中编辑组织时,选择层级独立,再选择一个组织,报500,前端参数传入问题 See merge request yunteng/thingskit-front!1193
Showing
2 changed files
with
47 additions
and
1 deletions
| @@ -50,6 +50,7 @@ | @@ -50,6 +50,7 @@ | ||
| 50 | 'check', | 50 | 'check', |
| 51 | 'unSelectAll', | 51 | 'unSelectAll', |
| 52 | 'update:searchValue', | 52 | 'update:searchValue', |
| 53 | + 'strictlyStatus', | ||
| 53 | ], | 54 | ], |
| 54 | setup(props, { attrs, slots, emit, expose }) { | 55 | setup(props, { attrs, slots, emit, expose }) { |
| 55 | const state = reactive<State>({ | 56 | const state = reactive<State>({ |
| @@ -199,6 +200,7 @@ | @@ -199,6 +200,7 @@ | ||
| 199 | 200 | ||
| 200 | function onStrictlyChange(strictly: boolean) { | 201 | function onStrictlyChange(strictly: boolean) { |
| 201 | state.checkStrictly = strictly; | 202 | state.checkStrictly = strictly; |
| 203 | + emit('strictlyStatus', strictly); //父组件接收层级关联或独立的状态 false为层级关联 true为层级独立 | ||
| 202 | } | 204 | } |
| 203 | 205 | ||
| 204 | const searchText = ref(''); | 206 | const searchText = ref(''); |
| @@ -16,6 +16,9 @@ | @@ -16,6 +16,9 @@ | ||
| 16 | :checked-keys="checkGroup" | 16 | :checked-keys="checkGroup" |
| 17 | :expandedKeys="treeExpandData" | 17 | :expandedKeys="treeExpandData" |
| 18 | ref="basicTreeRef" | 18 | ref="basicTreeRef" |
| 19 | + @check="handleCheckClick" | ||
| 20 | + @unSelectAll="handleUnSelectAll" | ||
| 21 | + @strictlyStatus="handleStrictlyStatus" | ||
| 19 | checkable | 22 | checkable |
| 20 | toolbar | 23 | toolbar |
| 21 | @change="handleTreeSelect" | 24 | @change="handleTreeSelect" |
| @@ -55,7 +58,7 @@ | @@ -55,7 +58,7 @@ | ||
| 55 | SaveOrUpdateUserInfo, | 58 | SaveOrUpdateUserInfo, |
| 56 | filterRoleList, | 59 | filterRoleList, |
| 57 | } from '/@/api/system/system'; | 60 | } from '/@/api/system/system'; |
| 58 | - import { BasicTree, TreeItem } from '/@/components/Tree'; | 61 | + import { BasicTree, TreeItem, CheckKeys, CheckEvent } from '/@/components/Tree'; |
| 59 | import { findCurrentUserGroups } from '/@/api/system/group'; | 62 | import { findCurrentUserGroups } from '/@/api/system/group'; |
| 60 | import { RoleOrOrganizationParam } from '/@/api/system/model/systemModel'; | 63 | import { RoleOrOrganizationParam } from '/@/api/system/model/systemModel'; |
| 61 | import { useMessage } from '/@/hooks/web/useMessage'; | 64 | import { useMessage } from '/@/hooks/web/useMessage'; |
| @@ -91,6 +94,7 @@ | @@ -91,6 +94,7 @@ | ||
| 91 | const singleEditPostPhoneNumber = reactive({ | 94 | const singleEditPostPhoneNumber = reactive({ |
| 92 | phoneNumber: '', | 95 | phoneNumber: '', |
| 93 | }); | 96 | }); |
| 97 | + const checkedKeysWithHalfChecked = ref<(string | number)[]>([]); | ||
| 94 | const getRoleList = async () => { | 98 | const getRoleList = async () => { |
| 95 | const res = await filterRoleList(); | 99 | const res = await filterRoleList(); |
| 96 | roleOptions.value = res.map((m) => { | 100 | roleOptions.value = res.map((m) => { |
| @@ -208,10 +212,20 @@ | @@ -208,10 +212,20 @@ | ||
| 208 | 'organizationIds', | 212 | 'organizationIds', |
| 209 | olderPhoneNumber.value === getFieldsValue().phoneNumber ? '' : 'phoneNumber', | 213 | olderPhoneNumber.value === getFieldsValue().phoneNumber ? '' : 'phoneNumber', |
| 210 | ]); | 214 | ]); |
| 215 | + let treeCheckedKeys: string[] | CheckKeys = | ||
| 216 | + (unref(basicTreeRef)?.getCheckedKeys() as string[] | CheckKeys) || []; | ||
| 217 | + //fix 取消层级独立后(unref(treeRef)?.getCheckedKeys() as string[])的数据不是数组,是{checked:[],halfChecked:[]}对象,迭代报错 | ||
| 218 | + if (!Array.isArray(treeCheckedKeys)) { | ||
| 219 | + treeCheckedKeys = treeCheckedKeys?.checked; | ||
| 220 | + } | ||
| 221 | + const organizationIds = [ | ||
| 222 | + ...new Set([...unref(checkedKeysWithHalfChecked), ...treeCheckedKeys]), | ||
| 223 | + ]; | ||
| 211 | values.accountExpireTime = | 224 | values.accountExpireTime = |
| 212 | typeof values.accountExpireTime != 'undefined' && values.accountExpireTime != null | 225 | typeof values.accountExpireTime != 'undefined' && values.accountExpireTime != null |
| 213 | ? values.accountExpireTime.format('YYYY-MM-DD HH:mm:ss') | 226 | ? values.accountExpireTime.format('YYYY-MM-DD HH:mm:ss') |
| 214 | : null; | 227 | : null; |
| 228 | + values.organizationIds = organizationIds; | ||
| 215 | Object.assign(postData, values); | 229 | Object.assign(postData, values); |
| 216 | if (unref(isUpdate)) { | 230 | if (unref(isUpdate)) { |
| 217 | if (values.email == '') { | 231 | if (values.email == '') { |
| @@ -232,6 +246,33 @@ | @@ -232,6 +246,33 @@ | ||
| 232 | }, 300); | 246 | }, 300); |
| 233 | } | 247 | } |
| 234 | } | 248 | } |
| 249 | + // 取消全部的时候清除回显时获取的 | ||
| 250 | + const handleUnSelectAll = () => { | ||
| 251 | + checkedKeysWithHalfChecked.value = []; | ||
| 252 | + }; | ||
| 253 | + | ||
| 254 | + const strictlyStatus = ref(false); //层级关联或独立的状态 false为层级关联 true为层级独立 | ||
| 255 | + | ||
| 256 | + const handleStrictlyStatus = (status) => (strictlyStatus.value = status); | ||
| 257 | + | ||
| 258 | + const handleCheckClick = (selectedKeys: CheckKeys, event: CheckEvent) => { | ||
| 259 | + //fix 取消层级独立后selectedKeys不是数组,是{checked:[],halfChecked:[]}对象 迭代报错 | ||
| 260 | + // 层级独立 | ||
| 261 | + if (strictlyStatus.value) { | ||
| 262 | + if (!Array.isArray(selectedKeys)) { | ||
| 263 | + selectedKeys = selectedKeys?.checked; | ||
| 264 | + event.halfCheckedKeys = []; | ||
| 265 | + } | ||
| 266 | + } else { | ||
| 267 | + // 层级关联 | ||
| 268 | + event.halfCheckedKeys = []; | ||
| 269 | + } | ||
| 270 | + checkedKeysWithHalfChecked.value = [ | ||
| 271 | + ...selectedKeys, | ||
| 272 | + ...(event.halfCheckedKeys as string[]), | ||
| 273 | + ]; | ||
| 274 | + }; | ||
| 275 | + | ||
| 235 | return { | 276 | return { |
| 236 | registerModal, | 277 | registerModal, |
| 237 | registerForm, | 278 | registerForm, |
| @@ -247,6 +288,9 @@ | @@ -247,6 +288,9 @@ | ||
| 247 | handleSuccess, | 288 | handleSuccess, |
| 248 | handleRoleSelect, | 289 | handleRoleSelect, |
| 249 | handleTreeSelect, | 290 | handleTreeSelect, |
| 291 | + handleCheckClick, | ||
| 292 | + handleUnSelectAll, | ||
| 293 | + handleStrictlyStatus, | ||
| 250 | }; | 294 | }; |
| 251 | }, | 295 | }, |
| 252 | }); | 296 | }); |