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 | 50 | 'check', |
| 51 | 51 | 'unSelectAll', |
| 52 | 52 | 'update:searchValue', |
| 53 | + 'strictlyStatus', | |
| 53 | 54 | ], |
| 54 | 55 | setup(props, { attrs, slots, emit, expose }) { |
| 55 | 56 | const state = reactive<State>({ |
| ... | ... | @@ -199,6 +200,7 @@ |
| 199 | 200 | |
| 200 | 201 | function onStrictlyChange(strictly: boolean) { |
| 201 | 202 | state.checkStrictly = strictly; |
| 203 | + emit('strictlyStatus', strictly); //父组件接收层级关联或独立的状态 false为层级关联 true为层级独立 | |
| 202 | 204 | } |
| 203 | 205 | |
| 204 | 206 | const searchText = ref(''); | ... | ... |
| ... | ... | @@ -16,6 +16,9 @@ |
| 16 | 16 | :checked-keys="checkGroup" |
| 17 | 17 | :expandedKeys="treeExpandData" |
| 18 | 18 | ref="basicTreeRef" |
| 19 | + @check="handleCheckClick" | |
| 20 | + @unSelectAll="handleUnSelectAll" | |
| 21 | + @strictlyStatus="handleStrictlyStatus" | |
| 19 | 22 | checkable |
| 20 | 23 | toolbar |
| 21 | 24 | @change="handleTreeSelect" |
| ... | ... | @@ -55,7 +58,7 @@ |
| 55 | 58 | SaveOrUpdateUserInfo, |
| 56 | 59 | filterRoleList, |
| 57 | 60 | } from '/@/api/system/system'; |
| 58 | - import { BasicTree, TreeItem } from '/@/components/Tree'; | |
| 61 | + import { BasicTree, TreeItem, CheckKeys, CheckEvent } from '/@/components/Tree'; | |
| 59 | 62 | import { findCurrentUserGroups } from '/@/api/system/group'; |
| 60 | 63 | import { RoleOrOrganizationParam } from '/@/api/system/model/systemModel'; |
| 61 | 64 | import { useMessage } from '/@/hooks/web/useMessage'; |
| ... | ... | @@ -91,6 +94,7 @@ |
| 91 | 94 | const singleEditPostPhoneNumber = reactive({ |
| 92 | 95 | phoneNumber: '', |
| 93 | 96 | }); |
| 97 | + const checkedKeysWithHalfChecked = ref<(string | number)[]>([]); | |
| 94 | 98 | const getRoleList = async () => { |
| 95 | 99 | const res = await filterRoleList(); |
| 96 | 100 | roleOptions.value = res.map((m) => { |
| ... | ... | @@ -208,10 +212,20 @@ |
| 208 | 212 | 'organizationIds', |
| 209 | 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 | 224 | values.accountExpireTime = |
| 212 | 225 | typeof values.accountExpireTime != 'undefined' && values.accountExpireTime != null |
| 213 | 226 | ? values.accountExpireTime.format('YYYY-MM-DD HH:mm:ss') |
| 214 | 227 | : null; |
| 228 | + values.organizationIds = organizationIds; | |
| 215 | 229 | Object.assign(postData, values); |
| 216 | 230 | if (unref(isUpdate)) { |
| 217 | 231 | if (values.email == '') { |
| ... | ... | @@ -232,6 +246,33 @@ |
| 232 | 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 | 276 | return { |
| 236 | 277 | registerModal, |
| 237 | 278 | registerForm, |
| ... | ... | @@ -247,6 +288,9 @@ |
| 247 | 288 | handleSuccess, |
| 248 | 289 | handleRoleSelect, |
| 249 | 290 | handleTreeSelect, |
| 291 | + handleCheckClick, | |
| 292 | + handleUnSelectAll, | |
| 293 | + handleStrictlyStatus, | |
| 250 | 294 | }; |
| 251 | 295 | }, |
| 252 | 296 | }); | ... | ... |