|
@@ -24,12 +24,9 @@
|
|
|
<script>
|
|
<script>
|
|
|
import { DownOutlined } from '@ant-design/icons-vue';
|
|
import { DownOutlined } from '@ant-design/icons-vue';
|
|
|
import Common from '../common/Common.js';
|
|
import Common from '../common/Common.js';
|
|
|
-import ClientResourceV2 from '../api/base/ClientResourceV2.js';
|
|
|
|
|
-import TokenClientResource from '../api/base/TokenClientResource.js';
|
|
|
|
|
-import { Notify, Uuid } from 'pc-component-v3';
|
|
|
|
|
|
|
+import { Notify } from 'pc-component-v3';
|
|
|
import { useRoleStateSingleton } from './RoleState.js';
|
|
import { useRoleStateSingleton } from './RoleState.js';
|
|
|
import { UserStorageResource } from 'pc-component-v3';
|
|
import { UserStorageResource } from 'pc-component-v3';
|
|
|
-import { message } from 'ant-design-vue';
|
|
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
components: {
|
|
components: {
|
|
@@ -39,7 +36,6 @@ export default {
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
userRoleOrTemplateList: [],
|
|
userRoleOrTemplateList: [],
|
|
|
- loginClientName: '',
|
|
|
|
|
roleStateInstance: useRoleStateSingleton,
|
|
roleStateInstance: useRoleStateSingleton,
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
@@ -51,16 +47,38 @@ export default {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
mounted() {
|
|
|
- this.listUserRoleOrTemplate();
|
|
|
|
|
|
|
+ this.init();
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
|
- handleRoleSelect(userRoleOrTemplate) {
|
|
|
|
|
- this.roleStateInstance.setUserRoleOrTemplate(userRoleOrTemplate);
|
|
|
|
|
- this.uploadSelectedRole(userRoleOrTemplate);
|
|
|
|
|
|
|
+ // 入口:先获取已保存的选中项,再加载角色列表,最后通知消费者就绪
|
|
|
|
|
+ async init() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const savedRole = await this.fetchSavedRole();
|
|
|
|
|
+ await this.loadRoleList(savedRole);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 无论角色列表加载成功或失败,都必须通知消费者初始化已完成
|
|
|
|
|
+ this.roleStateInstance.markRoleReady();
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- async listUserRoleOrTemplate() {
|
|
|
|
|
|
|
+ // 仅从远端获取已保存的选中角色,不做任何副作用
|
|
|
|
|
+ async fetchSavedRole() {
|
|
|
|
|
+ const key = 'UserSelectedRole';
|
|
|
|
|
+ try {
|
|
|
|
|
+ const { errorCode, data } = await UserStorageResource.uniqueByKey(key);
|
|
|
|
|
+ if (errorCode === 0) {
|
|
|
|
|
+ return data ? JSON.parse(data) : null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ Common.processException(error);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 加载角色列表后,将已保存的选中项匹配到列表并设置选中状态
|
|
|
|
|
+ async loadRoleList(savedRole) {
|
|
|
try {
|
|
try {
|
|
|
const response = await $.ajax({
|
|
const response = await $.ajax({
|
|
|
url: Common.getApiURL('RoleResourceV3/listUserRoleOrTemplate'),
|
|
url: Common.getApiURL('RoleResourceV3/listUserRoleOrTemplate'),
|
|
@@ -71,7 +89,7 @@ export default {
|
|
|
|
|
|
|
|
if (response.errorCode === 0) {
|
|
if (response.errorCode === 0) {
|
|
|
this.userRoleOrTemplateList = response.datas;
|
|
this.userRoleOrTemplateList = response.datas;
|
|
|
- this.downloadSelectedRole();
|
|
|
|
|
|
|
+ this.applySavedRole(savedRole);
|
|
|
} else {
|
|
} else {
|
|
|
Notify.error('错误', response.errorMessage, false);
|
|
Notify.error('错误', response.errorMessage, false);
|
|
|
}
|
|
}
|
|
@@ -80,6 +98,24 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ // 在已加载的角色列表中匹配 savedRole,匹配不到或 savedRole 为 null 时显式选择「全部」
|
|
|
|
|
+ applySavedRole(savedRole) {
|
|
|
|
|
+ if (!savedRole) {
|
|
|
|
|
+ this.roleStateInstance.setUserRoleOrTemplate(null);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const matched = this.userRoleOrTemplateList.find(item =>
|
|
|
|
|
+ `${item.userRoleTemplateId}-${item.userRoleId}` ===
|
|
|
|
|
+ `${savedRole.userRoleTemplateId}-${savedRole.userRoleId}`,
|
|
|
|
|
+ );
|
|
|
|
|
+ this.roleStateInstance.setUserRoleOrTemplate(matched || null);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ handleRoleSelect(userRoleOrTemplate) {
|
|
|
|
|
+ this.roleStateInstance.setUserRoleOrTemplate(userRoleOrTemplate);
|
|
|
|
|
+ this.uploadSelectedRole(userRoleOrTemplate);
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
async uploadSelectedRole(userRoleOrTemplate) {
|
|
async uploadSelectedRole(userRoleOrTemplate) {
|
|
|
const key = 'UserSelectedRole';
|
|
const key = 'UserSelectedRole';
|
|
|
const userStorageDtos = [{
|
|
const userStorageDtos = [{
|
|
@@ -93,26 +129,6 @@ export default {
|
|
|
Common.processException(error);
|
|
Common.processException(error);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
- async downloadSelectedRole() {
|
|
|
|
|
- const key = 'UserSelectedRole';
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- const { errorCode, data } = await UserStorageResource.uniqueByKey(key);
|
|
|
|
|
- if (errorCode === 0) {
|
|
|
|
|
- const selectedRole = data ? JSON.parse(data) : null;
|
|
|
|
|
- if (selectedRole) {
|
|
|
|
|
- const matched = this.userRoleOrTemplateList.find(item =>
|
|
|
|
|
- `${item.userRoleTemplateId}-${item.userRoleId}` ===
|
|
|
|
|
- `${selectedRole.userRoleTemplateId}-${selectedRole.userRoleId}`,
|
|
|
|
|
- );
|
|
|
|
|
- this.roleStateInstance.setUserRoleOrTemplate(matched || null);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- Common.processException(error);
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
</script>
|
|
</script>
|