Skip to content

Commit

Permalink
perf: optimize await logic
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Jan 13, 2023
1 parent 54b246c commit 86a62c3
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/locales/lang/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ export default {
changeStatusFailed: 'Change status failed',
targetNotExist: 'Target does not exist',
notAllowDelete: 'Disallow deletion of this object',
notAllowDeleteAdminData: "Disallow deletion of administrator's data",
notAllowChangeStatus: 'Disallow modification of status',
};
1 change: 1 addition & 0 deletions src/locales/lang/zh-CN/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ export default {
changeStatusFailed: '状态修改失败',
targetNotExist: '目标不存在',
notAllowDelete: '禁止删除该数据',
notAllowDeleteAdminData: "禁止删除管理员数据",
notAllowChangeStatus: '禁止改变目标状态',
};
2 changes: 1 addition & 1 deletion src/views/dashboard/workbench/components/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ export const navItems: NavItem[] = [

export const systemInfoData = [
['sys.sys.Name', 'Simple Admin'],
['sys.sys.version', 'V 0.1.6'],
['sys.sys.version', 'V 0.2.1'],
];
6 changes: 3 additions & 3 deletions src/views/sys/api/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@
description: t(result.msg),
duration: 3,
});
reload();
await reload();
}
function handleSuccess() {
reload();
async function handleSuccess() {
await reload();
}
return {
Expand Down
6 changes: 3 additions & 3 deletions src/views/sys/dictionary/detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@
description: t(result.msg),
duration: 3,
});
reload();
await reload();
}
function handleSuccess() {
reload();
async function handleSuccess() {
await reload();
}
return {
Expand Down
2 changes: 1 addition & 1 deletion src/views/sys/dictionary/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
async function handleDelete(record: Recordable) {
const result = await deleteDictionary({ id: record.id }, 'modal');
message.success(t(result.msg), 2);
reload();
await reload();
}
function handleSuccess() {
Expand Down
32 changes: 16 additions & 16 deletions src/views/sys/menu/MenuDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
const modalVisible = ref<boolean>(false);
const paramFormTitle = ref<string>('');
// form model for menu parameters creating and updating
const formdata = reactive<paramFormData>({
const formData = reactive<paramFormData>({
id: 0,
menuId: 0,
dataType: 'string',
Expand All @@ -145,27 +145,27 @@
function handleOpenParamForm() {
modalVisible.value = false;
formdata.id = 0;
formdata.key = '';
formdata.value = '';
formdata.dataType = 'string';
formData.id = 0;
formData.key = '';
formData.value = '';
formData.dataType = 'string';
paramFormVisible.value = true;
}
async function handleOpenModal() {
const result = await getMenuParamListByMenuId({ id: menuId.value });
dataSource.value = result.data.data;
paramFormTitle.value = t('sys.menu.addMenuParam');
formdata.menuId = menuId.value;
formData.menuId = menuId.value;
modalVisible.value = true;
}
// menu parameters operations
function handleEdit(record: Recordable) {
formdata.id = record.id;
formdata.key = record.key;
formdata.value = record.value;
formdata.dataType = record.dataType;
formData.id = record.id;
formData.key = record.key;
formData.value = record.value;
formData.dataType = record.dataType;
paramFormTitle.value = t('sys.menu.editMenuParam');
paramFormVisible.value = true;
}
Expand All @@ -177,11 +177,11 @@
async function handleParamSubmit() {
const result = await createOrUpdateMenuParam({
id: formdata.id,
menuId: formdata.menuId,
dataType: formdata.dataType,
value: formdata.value,
key: formdata.key,
id: formData.id,
menuId: formData.menuId,
dataType: formData.dataType,
value: formData.value,
key: formData.key,
});
if (result.code === 0) {
paramFormVisible.value = false;
Expand Down Expand Up @@ -331,7 +331,7 @@
handleOpenModal,
modalVisible,
dataSource,
formdata,
formData,
paramFormVisible,
handleOpenParamForm,
paramFormTitle,
Expand Down
2 changes: 1 addition & 1 deletion src/views/sys/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
description: t(result.msg),
duration: 3,
});
reload();
await reload();
}
function handleSuccess() {
Expand Down
2 changes: 1 addition & 1 deletion src/views/sys/oauth/callback.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
const userStore = useUserStore();
// save token
userStore.setToken(token);
userStore.afterLoginAction(false);
await userStore.afterLoginAction(false);
go(PageEnum.BASE_HOME);
} catch (e) {
message.error(t('sys.oauth.createAccount'), 5);
Expand Down
60 changes: 29 additions & 31 deletions src/views/sys/role/RoleDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,36 @@
</BasicDrawer>
</template>
<script lang="ts">
import { defineComponent, ref, computed, unref, watch } from 'vue';
import { Tabs, Tree, message } from 'ant-design-vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import {
formSchema,
convertMenuTreeData,
convertApiTreeData,
convertApiCheckedKeysToReq,
convertApiToCheckedKeys,
} from './role.data';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { useI18n } from 'vue-i18n';
import {computed, defineComponent, ref, unref, watch} from 'vue';
import {message, Tabs, Tree} from 'ant-design-vue';
import {BasicForm, useForm} from '/@/components/Form/index';
import {
convertApiCheckedKeysToReq,
convertApiToCheckedKeys,
convertApiTreeData,
convertMenuTreeData,
formSchema,
} from './role.data';
import {BasicDrawer, useDrawerInner} from '/@/components/Drawer';
import {useI18n} from 'vue-i18n';
import { RoleInfo } from '/@/api/sys/model/roleModel';
import { ApiAuthorityInfo } from '/@/api/sys/model/authorityModel';
import { createOrUpdateRole } from '/@/api/sys/role';
import { getAllMenu } from '/@/api/sys/menu';
import {
createOrUpdateMenuAuthority,
getMenuAuthority,
getApiList,
createOrUpdateApiAuthority,
getApiAuthority,
} from '/@/api/sys/authority';
import { DataNode } from 'ant-design-vue/lib/tree';
import console from 'console';
import { BaseDataResp } from '/@/api/model/baseModel';
import { ApiListResp } from '/@/api/sys/model/apiModel';
import {RoleInfo} from '/@/api/sys/model/roleModel';
import {ApiAuthorityInfo} from '/@/api/sys/model/authorityModel';
import {createOrUpdateRole} from '/@/api/sys/role';
import {getAllMenu} from '/@/api/sys/menu';
import {
createOrUpdateApiAuthority,
createOrUpdateMenuAuthority,
getApiAuthority,
getApiList,
getMenuAuthority,
} from '/@/api/sys/authority';
import {DataNode} from 'ant-design-vue/lib/tree';
import console from 'console';
import {BaseDataResp} from '/@/api/model/baseModel';
import {ApiListResp} from '/@/api/sys/model/apiModel';
export default defineComponent({
export default defineComponent({
name: 'RoleDrawer',
components: { BasicDrawer, BasicForm, ATabs: Tabs, ATabPane: Tabs.TabPane, ATree: Tree },
emits: ['success', 'register'],
Expand Down Expand Up @@ -131,8 +131,7 @@
}
const roleId = await validate();
const checkedData = await getApiAuthority({ id: Number(roleId['id']) });
const checkKeyConv = convertApiToCheckedKeys(checkedData.data.data, apiData.data.data);
checkedApiKeys.value = checkKeyConv;
checkedApiKeys.value = convertApiToCheckedKeys(checkedData.data.data, apiData.data.data);
} catch (error) {
console.log(error);
}
Expand Down Expand Up @@ -195,7 +194,6 @@
status: values['status'],
remark: values['remark'],
orderNo: values['orderNo'],
createdAt: 0, // do not need to set
};
let result = await createOrUpdateRole(params);
if (result.code === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/views/sys/role/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
}
async function handleDelete(record: Recordable) {
if (record.id == 1) {
createMessage.warn(t('common.notAllowDelete'));
if (record.id === 1) {
createMessage.warn(t('common.notAllowDeleteAdminData'));
return;
}
const result = await deleteRole({ id: record.id }, 'modal');
Expand Down
6 changes: 1 addition & 5 deletions src/views/sys/token/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@
type: 'checkbox',
onChange: (selectedRowKeys, _selectedRows) => {
selectedIds.value = selectedRowKeys as string[];
if (selectedRowKeys.length > 0) {
showDeleteButton.value = true;
} else {
showDeleteButton.value = false;
}
showDeleteButton.value = selectedRowKeys.length > 0;
},
},
});
Expand Down
6 changes: 3 additions & 3 deletions src/views/sys/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
async function handleDelete(record: Recordable) {
if (record.nickname === 'admin') {
createMessage.warn(t('common.notAllowDelete'));
createMessage.warn(t('common.notAllowDeleteAdminData'));
return;
}
Expand All @@ -135,7 +135,7 @@
const ids = selectedIds.value as string[];
const rowData = getSelectRows()
if (rowData.filter(row => row.nickname === 'admin').length > 0) {
createMessage.warn(t('common.notAllowDelete'));
createMessage.warn(t('common.notAllowDeleteAdminData'));
return;
}
Expand All @@ -154,7 +154,7 @@
async function handleLogout(record: Recordable) {
const result = await logout(record.UUID);
if (result.code == 0) await reload();
if (result.code === 0) await reload();
}
function handleSuccess() {
Expand Down

0 comments on commit 86a62c3

Please sign in to comment.