mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-11-14 04:33:41 +08:00
chore(projects): merge branch main into example
This commit is contained in:
@@ -160,6 +160,24 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
|
||||
Object.assign(pagination, update);
|
||||
}
|
||||
|
||||
/**
|
||||
* get data by page number
|
||||
*
|
||||
* @param pageNum the page number. default is 1
|
||||
*/
|
||||
async function getDataByPage(pageNum: number = 1) {
|
||||
updatePagination({
|
||||
page: pageNum
|
||||
});
|
||||
|
||||
updateSearchParams({
|
||||
current: pageNum,
|
||||
size: pagination.pageSize!
|
||||
});
|
||||
|
||||
await getData();
|
||||
}
|
||||
|
||||
scope.run(() => {
|
||||
watch(
|
||||
() => appStore.locale,
|
||||
@@ -184,6 +202,7 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
|
||||
mobilePagination,
|
||||
updatePagination,
|
||||
getData,
|
||||
getDataByPage,
|
||||
searchParams,
|
||||
updateSearchParams,
|
||||
resetSearchParams
|
||||
|
||||
@@ -23,6 +23,7 @@ const local: App.I18n.Schema = {
|
||||
deleteSuccess: 'Delete Success',
|
||||
confirmDelete: 'Are you sure you want to delete?',
|
||||
edit: 'Edit',
|
||||
error: 'Error',
|
||||
index: 'Index',
|
||||
keywordSearch: 'Please enter keyword',
|
||||
logout: 'Logout',
|
||||
|
||||
@@ -23,6 +23,7 @@ const local: App.I18n.Schema = {
|
||||
deleteSuccess: '删除成功',
|
||||
confirmDelete: '确认删除吗?',
|
||||
edit: '编辑',
|
||||
error: '错误',
|
||||
index: '序号',
|
||||
keywordSearch: '请输入关键词搜索',
|
||||
logout: '退出登录',
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
Router
|
||||
} from 'vue-router';
|
||||
import type { RouteKey, RoutePath } from '@elegant-router/types';
|
||||
import { getRouteName } from '@/router/elegant/transform';
|
||||
import { useAuthStore } from '@/store/modules/auth';
|
||||
import { useRouteStore } from '@/store/modules/route';
|
||||
import { localStg } from '@/utils/storage';
|
||||
@@ -149,9 +150,7 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
|
||||
// initialize the auth route requires the user to be logged in, if not, redirect to the login page
|
||||
if (!isLogin) {
|
||||
const loginRoute: RouteKey = 'login';
|
||||
const redirect = to.fullPath;
|
||||
|
||||
const query: LocationQueryRaw = to.name !== loginRoute ? { redirect } : {};
|
||||
const query = getRouteQueryOfLoginRoute(to, routeStore.routeHome);
|
||||
|
||||
const location: RouteLocationRaw = {
|
||||
name: loginRoute,
|
||||
@@ -197,3 +196,20 @@ function handleRouteSwitch(to: RouteLocationNormalized, from: RouteLocationNorma
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
function getRouteQueryOfLoginRoute(to: RouteLocationNormalized, routeHome: RouteKey) {
|
||||
const loginRoute: RouteKey = 'login';
|
||||
const redirect = to.fullPath;
|
||||
const [redirectPath, redirectQuery] = redirect.split('?');
|
||||
const redirectName = getRouteName(redirectPath as RoutePath);
|
||||
|
||||
const isRedirectHome = routeHome === redirectName;
|
||||
|
||||
const query: LocationQueryRaw = to.name !== loginRoute && !isRedirectHome ? { redirect } : {};
|
||||
|
||||
if (isRedirectHome && redirectQuery) {
|
||||
query.redirect = `/?${redirectQuery}`;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
||||
window.addEventListener('beforeunload', handleLogout);
|
||||
|
||||
window.$dialog?.error({
|
||||
title: 'Error',
|
||||
title: $t('common.error'),
|
||||
content: response.data.msg,
|
||||
positiveText: $t('common.confirm'),
|
||||
maskClosable: false,
|
||||
|
||||
1
src/typings/app.d.ts
vendored
1
src/typings/app.d.ts
vendored
@@ -273,6 +273,7 @@ declare namespace App {
|
||||
deleteSuccess: string;
|
||||
confirmDelete: string;
|
||||
edit: string;
|
||||
error: string;
|
||||
index: string;
|
||||
keywordSearch: string;
|
||||
logout: string;
|
||||
|
||||
@@ -18,7 +18,7 @@ const { bool: visible, setTrue: openModal } = useBoolean();
|
||||
|
||||
const wrapperRef = ref<HTMLElement | null>(null);
|
||||
|
||||
const { columns, columnChecks, data, loading, pagination, getData } = useTable({
|
||||
const { columns, columnChecks, data, loading, pagination, getData, getDataByPage } = useTable({
|
||||
apiFn: fetchGetMenuList,
|
||||
columns: () => [
|
||||
{
|
||||
@@ -257,7 +257,7 @@ init();
|
||||
:operate-type="operateType"
|
||||
:row-data="editingData"
|
||||
:all-pages="allPages"
|
||||
@submitted="getData"
|
||||
@submitted="getDataByPage"
|
||||
/>
|
||||
</NCard>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,17 @@ import RoleSearch from './modules/role-search.vue';
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
||||
const { columns, columnChecks, data, loading, getData, mobilePagination, searchParams, resetSearchParams } = useTable({
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
getDataByPage,
|
||||
mobilePagination,
|
||||
searchParams,
|
||||
resetSearchParams
|
||||
} = useTable({
|
||||
apiFn: fetchGetRoleList,
|
||||
apiParams: {
|
||||
current: 1,
|
||||
@@ -129,7 +139,7 @@ function edit(id: number) {
|
||||
|
||||
<template>
|
||||
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
||||
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
|
||||
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getDataByPage" />
|
||||
<NCard :title="$t('page.manage.role.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
|
||||
<template #header-extra>
|
||||
<TableHeaderOperation
|
||||
@@ -158,7 +168,7 @@ function edit(id: number) {
|
||||
v-model:visible="drawerVisible"
|
||||
:operate-type="operateType"
|
||||
:row-data="editingData"
|
||||
@submitted="getData"
|
||||
@submitted="getDataByPage"
|
||||
/>
|
||||
</NCard>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,17 @@ import UserSearch from './modules/user-search.vue';
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
||||
const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
getData,
|
||||
getDataByPage,
|
||||
loading,
|
||||
mobilePagination,
|
||||
searchParams,
|
||||
resetSearchParams
|
||||
} = useTable({
|
||||
apiFn: fetchGetUserList,
|
||||
showTotal: true,
|
||||
apiParams: {
|
||||
@@ -160,7 +170,7 @@ function edit(id: number) {
|
||||
|
||||
<template>
|
||||
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
||||
<UserSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
|
||||
<UserSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getDataByPage" />
|
||||
<NCard :title="$t('page.manage.user.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
|
||||
<template #header-extra>
|
||||
<TableHeaderOperation
|
||||
@@ -189,7 +199,7 @@ function edit(id: number) {
|
||||
v-model:visible="drawerVisible"
|
||||
:operate-type="operateType"
|
||||
:row-data="editingData"
|
||||
@submitted="getData"
|
||||
@submitted="getDataByPage"
|
||||
/>
|
||||
</NCard>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user