Skip to content

Commit

Permalink
refactor(projects): perf page manage_role
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jan 28, 2024
1 parent 39aa7aa commit a19f895
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 47 deletions.
2 changes: 2 additions & 0 deletions src/typings/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ declare module 'vue' {
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
NPopover: typeof import('naive-ui')['NPopover']
NRadio: typeof import('naive-ui')['NRadio']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NSelect: typeof import('naive-ui')['NSelect']
NSpace: typeof import('naive-ui')['NSpace']
NStatistic: typeof import('naive-ui')['NStatistic']
Expand Down
3 changes: 3 additions & 0 deletions src/typings/naive-ui.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare namespace NaiveUI {
type ThemeColor = 'default' | 'error' | 'primary' | 'info' | 'success' | 'warning';
}
12 changes: 0 additions & 12 deletions src/views/manage/role/context.ts

This file was deleted.

31 changes: 21 additions & 10 deletions src/views/manage/role/index.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script setup lang="tsx">
import { ref } from 'vue';
import { NButton, NPopconfirm } from 'naive-ui';
import { NButton, NPopconfirm, NTag } from 'naive-ui';
import { useBoolean } from '@sa/hooks';
import { fetchGetRoleList } from '@/service/api';
import { useAppStore } from '@/store/modules/app';
import { useTable } from '@/hooks/common/table';
import { $t } from '@/locales';
import OperateRoleDrawer, { type OperateType } from './operate-role-drawer.vue';
import RoleSearch from './role-search.vue';
import { setupRoleSearchContext } from './context';
import { roleStatusRecord } from '@/constants/business';
import RoleOperateDrawer, { type OperateType } from './modules/role-operate-drawer.vue';
import RoleSearch from './modules/role-search.vue';
const appStore = useAppStore();
const { bool: drawerVisible, setTrue: openDrawer } = useBoolean();
Expand Down Expand Up @@ -67,7 +67,21 @@ const { columns, filteredColumns, data, loading, pagination, getData, searchPara
{
key: 'roleStatus',
title: $t('page.manage.role.roleStatus'),
align: 'center'
align: 'center',
render: row => {
if (row.roleStatus === null) {
return null;
}
const tagMap: Record<Api.SystemManage.RoleStatus, NaiveUI.ThemeColor> = {
1: 'success',
2: 'warning'
};
const label = $t(roleStatusRecord[row.roleStatus]);
return <NTag type={tagMap[row.roleStatus]}>{label}</NTag>;
}
},
{
key: 'operate',
Expand Down Expand Up @@ -95,9 +109,6 @@ const { columns, filteredColumns, data, loading, pagination, getData, searchPara
]
});
// provide searchParams
setupRoleSearchContext(searchParams);
const operateType = ref<OperateType>('add');
function handleAdd() {
Expand Down Expand Up @@ -143,7 +154,7 @@ function getIndex(index: number) {

<template>
<div class="flex-vertical-stretch gap-16px overflow-hidden <sm:overflow-auto">
<RoleSearch @reset="resetSearchParams" @search="getData" />
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
<NCard :title="$t('page.manage.role.title')" :bordered="false" size="small" class="card-wrapper sm:flex-1-hidden">
<template #header-extra>
<TableHeaderOperation
Expand All @@ -167,7 +178,7 @@ function getIndex(index: number) {
:row-key="item => item.id"
class="sm:h-full"
/>
<OperateRoleDrawer
<RoleOperateDrawer
v-model:visible="drawerVisible"
:operate-type="operateType"
:row-data="editingData"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { computed, reactive, watch } from 'vue';
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';
import { roleStatusOptions } from '@/constants/business';
import { translateOptions } from '@/utils/common';
defineOptions({
name: 'OperateRoleDrawer'
name: 'RoleOperateDrawer'
});
/**
Expand Down Expand Up @@ -110,11 +109,9 @@ watch(visible, () => {
<NInput v-model:value="model.roleCode" :placeholder="$t('page.manage.role.form.roleCode')" />
</NFormItem>
<NFormItem :label="$t('page.manage.role.roleStatus')" path="roleStatus">
<NSelect
v-model:value="model.roleStatus"
:placeholder="$t('page.manage.role.form.roleStatus')"
:options="translateOptions(roleStatusOptions)"
/>
<NRadioGroup v-model:value="model.roleStatus">
<NRadio v-for="item in roleStatusOptions" :key="item.value" :value="item.value" :label="$t(item.label)" />
</NRadioGroup>
</NFormItem>
<NFormItem :label="$t('page.manage.role.roleDesc')" path="roleDesc">
<NInput v-model:value="model.roleDesc" :placeholder="$t('page.manage.role.form.roleDesc')" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script setup lang="ts">
import { watch } from 'vue';
import { $t } from '@/locales';
import { roleStatusOptions } from '@/constants/business';
import { translateOptions } from '@/utils/common';
import { useRoleSearchContext } from './context';
defineOptions({
name: 'RoleSearch'
Expand All @@ -16,8 +14,7 @@ interface Emits {
const emit = defineEmits<Emits>();
// inject searchParams
const { searchParams } = useRoleSearchContext();
const model = defineModel<Api.SystemManage.RoleSearchParams>('model', { required: true });
function reset() {
emit('reset');
Expand All @@ -26,31 +23,21 @@ function reset() {
function search() {
emit('search');
}
watch(
() => searchParams,
val => {
console.log('val: ', val);
},
{
deep: true
}
);
</script>

<template>
<NCard :title="$t('common.search')" :bordered="false" size="small" class="card-wrapper">
<NForm :model="searchParams" label-placement="left">
<NForm :model="model" label-placement="left">
<NGrid responsive="screen" item-responsive>
<NFormItemGi span="24 s:12 m:6" :label="$t('page.manage.role.roleName')" path="roleName" class="pr-24px">
<NInput v-model:value="searchParams.roleName" :placeholder="$t('page.manage.role.form.roleName')" />
<NInput v-model:value="model.roleName" :placeholder="$t('page.manage.role.form.roleName')" />
</NFormItemGi>
<NFormItemGi span="24 s:12 m:6" :label="$t('page.manage.role.roleCode')" path="roleCode" class="pr-24px">
<NInput v-model:value="searchParams.roleCode" :placeholder="$t('page.manage.role.form.roleCode')" />
<NInput v-model:value="model.roleCode" :placeholder="$t('page.manage.role.form.roleCode')" />
</NFormItemGi>
<NFormItemGi span="24 s:12 m:6" :label="$t('page.manage.role.roleStatus')" path="roleStatus" class="pr-24px">
<NSelect
v-model:value="searchParams.roleStatus"
v-model:value="model.roleStatus"
:placeholder="$t('page.manage.role.form.roleStatus')"
:options="translateOptions(roleStatusOptions)"
clearable
Expand Down

1 comment on commit a19f895

@vercel
Copy link

@vercel vercel bot commented on a19f895 Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

soybean-admin – ./

soybean-admin-eta.vercel.app
soybean-admin-soybeanjs.vercel.app
soybean-admin-git-main-soybeanjs.vercel.app

Please sign in to comment.