Browse Source

perf: 不跳到login页

曾坤森 3 months ago
parent
commit
fb9bcd7cea

+ 1 - 1
.vscode/settings.json

@@ -3,7 +3,7 @@
     "src/locale",
     "src/components/message-box/locale",
     "src/views/login/locale",
-    "src/views/dashboard/history/locale",
+    "src/views/dashboard/record/locale",
     "src/views/dashboard/face/locale",
     "src/views/exception/403/locale",
     "src/views/exception/404/locale",

+ 0 - 22
src/api/dashboard.ts

@@ -1,22 +0,0 @@
-import axios from 'axios';
-import type { TableData } from '@arco-design/web-vue/es/table/interface';
-
-export interface ContentDataRecord {
-  x: string;
-  y: number;
-}
-
-export function queryContentData() {
-  return axios.get<ContentDataRecord[]>('/api/content-data');
-}
-
-export interface PopularRecord {
-  key: number;
-  clickNumber: string;
-  title: string;
-  increases: number;
-}
-
-export function queryPopularList(params: { type: string }) {
-  return axios.get<TableData[]>('/api/popular/list', { params });
-}

+ 0 - 21
src/api/form.ts

@@ -1,21 +0,0 @@
-import axios from 'axios';
-
-export interface BaseInfoModel {
-  activityName: string;
-  channelType: string;
-  promotionTime: string[];
-  promoteLink: string;
-}
-export interface ChannelInfoModel {
-  advertisingSource: string;
-  advertisingMedia: string;
-  keyword: string[];
-  pushNotify: boolean;
-  advertisingContent: string;
-}
-
-export type UnitChannelModel = BaseInfoModel & ChannelInfoModel;
-
-export function submitChannelForm(data: UnitChannelModel) {
-  return axios.post('/api/channel-form/submit', { data });
-}

+ 0 - 49
src/api/profile.ts

@@ -1,49 +0,0 @@
-import axios from 'axios';
-
-export interface ProfileBasicRes {
-  status: number;
-  video: {
-    mode: string;
-    acquisition: {
-      resolution: string;
-      frameRate: number;
-    };
-    encoding: {
-      resolution: string;
-      rate: {
-        min: number;
-        max: number;
-        default: number;
-      };
-      frameRate: number;
-      profile: string;
-    };
-  };
-  audio: {
-    mode: string;
-    acquisition: {
-      channels: number;
-    };
-    encoding: {
-      channels: number;
-      rate: number;
-      profile: string;
-    };
-  };
-}
-
-export function queryProfileBasic() {
-  return axios.get<ProfileBasicRes>('/api/profile/basic');
-}
-
-export type operationLogRes = Array<{
-  key: string;
-  contentNumber: string;
-  updateContent: string;
-  status: number;
-  updateTime: string;
-}>;
-
-export function queryOperationLog() {
-  return axios.get<operationLogRes>('/api/operation/log');
-}

+ 0 - 88
src/api/user-center.ts

@@ -1,88 +0,0 @@
-import axios from 'axios';
-
-export interface MyProjectRecord {
-  id: number;
-  name: string;
-  description: string;
-  peopleNumber: number;
-  contributors: {
-    name: string;
-    email: string;
-    avatar: string;
-  }[];
-}
-export function queryMyProjectList() {
-  return axios.post('/api/user/my-project/list');
-}
-
-export interface MyTeamRecord {
-  id: number;
-  avatar: string;
-  name: string;
-  peopleNumber: number;
-}
-export function queryMyTeamList() {
-  return axios.post('/api/user/my-team/list');
-}
-
-export interface LatestActivity {
-  id: number;
-  title: string;
-  description: string;
-  avatar: string;
-}
-export function queryLatestActivity() {
-  return axios.post<LatestActivity[]>('/api/user/latest-activity');
-}
-
-export function saveUserInfo() {
-  return axios.post('/api/user/save-info');
-}
-
-export interface BasicInfoModel {
-  email: string;
-  nickname: string;
-  countryRegion: string;
-  area: string;
-  address: string;
-  profile: string;
-}
-
-export interface EnterpriseCertificationModel {
-  accountType: number;
-  status: number;
-  time: string;
-  legalPerson: string;
-  certificateType: string;
-  authenticationNumber: string;
-  enterpriseName: string;
-  enterpriseCertificateType: string;
-  organizationCode: string;
-}
-
-export type CertificationRecord = Array<{
-  certificationType: number;
-  certificationContent: string;
-  status: number;
-  time: string;
-}>;
-
-export interface UnitCertification {
-  enterpriseInfo: EnterpriseCertificationModel;
-  record: CertificationRecord;
-}
-
-export function queryCertification() {
-  return axios.post<UnitCertification>('/api/user/certification');
-}
-
-export function userUploadApi(
-  data: FormData,
-  config: {
-    controller: AbortController;
-    onUploadProgress?: (progressEvent: any) => void;
-  }
-) {
-  // const controller = new AbortController();
-  return axios.post('/api/user/upload', data, config);
-}

+ 0 - 73
src/api/visualization.ts

@@ -1,73 +0,0 @@
-import axios from 'axios';
-import { GeneralChart } from '@/types/global';
-
-export interface ChartDataRecord {
-  x: string;
-  y: number;
-  name: string;
-}
-export interface DataChainGrowth {
-  quota: string;
-}
-
-export interface DataChainGrowthRes {
-  count: number;
-  growth: number;
-  chartData: {
-    xAxis: string[];
-    data: { name: string; value: number[] };
-  };
-}
-export function queryDataChainGrowth(data: DataChainGrowth) {
-  return axios.post<DataChainGrowthRes>('/api/data-chain-growth', data);
-}
-
-export interface PopularAuthorRes {
-  list: {
-    ranking: number;
-    author: string;
-    contentCount: number;
-    clickCount: number;
-  }[];
-}
-
-export function queryPopularAuthor() {
-  return axios.get<PopularAuthorRes>('/api/popular-author/list');
-}
-
-export interface ContentPublishRecord {
-  x: string[];
-  y: number[];
-  name: string;
-}
-
-export function queryContentPublish() {
-  return axios.get<ContentPublishRecord[]>('/api/content-publish');
-}
-
-export function queryContentPeriodAnalysis() {
-  return axios.post<GeneralChart>('/api/content-period-analysis');
-}
-
-export interface PublicOpinionAnalysis {
-  quota: string;
-}
-export interface PublicOpinionAnalysisRes {
-  count: number;
-  growth: number;
-  chartData: ChartDataRecord[];
-}
-export function queryPublicOpinionAnalysis(data: DataChainGrowth) {
-  return axios.post<PublicOpinionAnalysisRes>(
-    '/api/public-opinion-analysis',
-    data
-  );
-}
-export interface DataOverviewRes {
-  xAxis: string[];
-  data: Array<{ name: string; value: number[]; count: number }>;
-}
-
-export function queryDataOverview() {
-  return axios.post<DataOverviewRes>('/api/data-overview');
-}

+ 3 - 3
src/locale/en-US.ts

@@ -1,7 +1,7 @@
 import localeMessageBox from '@/components/message-box/locale/en-US';
 import localeLogin from '@/views/login/locale/en-US';
 
-import localeHistory from '@/views/dashboard/history-list/locale/en-US';
+import localeRecord from '@/views/dashboard/record-list/locale/en-US';
 import localeFace from '@/views/dashboard/face-list/locale/en-US';
 
 import localeSearchTable from '@/views/list/search-table/locale/en-US';
@@ -17,7 +17,7 @@ export default {
   'menu.manage': 'manage',
   'menu.server.manage': 'Manage-Server',
   'menu.server.face': 'Face-Server',
-  'menu.server.history': 'History-Server',
+  'menu.server.record': 'Record-Server',
   'menu.list': 'List',
   'menu.exception': 'Exception',
   'menu.user': 'User Center',
@@ -26,7 +26,7 @@ export default {
   ...localeSettings,
   ...localeMessageBox,
   ...localeLogin,
-  ...localeHistory,
+  ...localeRecord,
   ...localeFace,
   ...localeSearchTable,
   ...localeCardList,

+ 3 - 3
src/locale/zh-CN.ts

@@ -3,7 +3,7 @@ import localeLogin from '@/views/login/locale/zh-CN';
 
 import localeFace from '@/views/dashboard/face-list/locale/zh-CN';
 
-import localeHistory from '@/views/dashboard/history-list/locale/zh-CN';
+import localeRecord from '@/views/dashboard/record-list/locale/zh-CN';
 
 import localeSearchTable from '@/views/list/search-table/locale/zh-CN';
 import localeCardList from '@/views/list/card/locale/zh-CN';
@@ -17,7 +17,7 @@ import localeSettings from './zh-CN/settings';
 export default {
   'menu.manage': '管理中心',
   'menu.server.manage': '管理中心-服务端',
-  'menu.server.history': '通行记录-服务端',
+  'menu.server.record': '通行记录-服务端',
   'menu.server.face': '人脸库',
   'menu.list': '列表页',
   'menu.exception': '异常页',
@@ -28,7 +28,7 @@ export default {
   ...localeMessageBox,
   ...localeLogin,
   ...localeFace,
-  ...localeHistory,
+  ...localeRecord,
   ...localeSearchTable,
   ...localeCardList,
   ...locale403,

+ 1 - 0
src/mock/message-box.ts

@@ -71,6 +71,7 @@ const getMessageList = () => {
 };
 
 setupMock({
+  mock: false,
   setup: () => {
     Mock.mock(new RegExp('/api/message/list'), () => {
       return successResponseWrap(getMessageList());

+ 4 - 3
src/mock/user.ts

@@ -8,6 +8,7 @@ import { MockParams } from '@/types/mock';
 import { isLogin } from '@/utils/auth';
 
 setupMock({
+  mock: false,
   setup() {
     // Mock.XHR.prototype.withCredentials = true;
 
@@ -81,10 +82,10 @@ setupMock({
           },
           children: [
             {
-              path: 'history',
-              name: 'History',
+              path: 'record',
+              name: 'Record',
               meta: {
-                locale: 'menu.server.history',
+                locale: 'menu.server.record',
                 requiresAuth: true,
               },
             },

+ 3 - 3
src/router/constants.ts

@@ -9,10 +9,10 @@ export const NOT_FOUND = {
 
 export const REDIRECT_ROUTE_NAME = 'Redirect';
 
-export const DEFAULT_ROUTE_NAME = 'History';
+export const DEFAULT_ROUTE_NAME = 'Record';
 
 export const DEFAULT_ROUTE = {
-  title: 'menu.manage.history',
+  title: 'menu.manage.record',
   name: DEFAULT_ROUTE_NAME,
-  fullPath: '/manage/history',
+  fullPath: '/manage/record',
 };

+ 35 - 32
src/router/guard/userLoginInfo.ts

@@ -7,37 +7,40 @@ import { isLogin } from '@/utils/auth';
 export default function setupUserLoginInfoGuard(router: Router) {
   router.beforeEach(async (to, from, next) => {
     NProgress.start();
-    const userStore = useUserStore();
-    if (isLogin()) {
-      if (userStore.role) {
-        next();
-      } else {
-        try {
-          await userStore.info();
-          next();
-        } catch (error) {
-          await userStore.logout();
-          next({
-            name: 'login',
-            query: {
-              redirect: to.name,
-              ...to.query,
-            } as LocationQueryRaw,
-          });
-        }
-      }
-    } else {
-      if (to.name === 'login') {
-        next();
-        return;
-      }
-      next({
-        name: 'login',
-        query: {
-          redirect: to.name,
-          ...to.query,
-        } as LocationQueryRaw,
-      });
-    }
+    next();
+
+    // const userStore = useUserStore();
+    // if (isLogin()) {
+    //   if (userStore.role) {
+    //     next();
+    //   } else {
+    //     try {
+    //       await userStore.info();
+    //       next();
+    //     } catch (error) {
+    //       // next();
+    //       await userStore.logout();
+    //       next({
+    //         name: 'login',
+    //         query: {
+    //           redirect: to.name,
+    //           ...to.query,
+    //         } as LocationQueryRaw,
+    //       });
+    //     }
+    //   }
+    // } else {
+    //   if (to.name === 'login') {
+    //     next();
+    //     return;
+    //   }
+    //   next({
+    //     name: 'login',
+    //     query: {
+    //       redirect: to.name,
+    //       ...to.query,
+    //     } as LocationQueryRaw,
+    //   });
+    // }
   });
 }

+ 13 - 9
src/router/index.ts

@@ -13,16 +13,20 @@ const router = createRouter({
   routes: [
     {
       path: '/',
-      redirect: 'login',
-    },
-    {
-      path: '/login',
-      name: 'login',
-      component: () => import('@/views/login/index.vue'),
-      meta: {
-        requiresAuth: false,
-      },
+      redirect: '/manage/record',
     },
+    // {
+    //   path: '/',
+    //   redirect: 'login',
+    // },
+    // {
+    //   path: '/login',
+    //   name: 'login',
+    //   component: () => import('@/views/login/index.vue'),
+    //   meta: {
+    //     requiresAuth: false,
+    //   },
+    // },
     ...appRoutes,
     REDIRECT_MAIN,
     NOT_FOUND_ROUTE,

+ 5 - 5
src/router/routes/modules/dashboard.ts

@@ -13,11 +13,11 @@ const DASHBOARD: AppRouteRecordRaw = {
   },
   children: [
     {
-      path: 'history',
-      name: 'History',
-      component: () => import('@/views/dashboard/history-list/index.vue'),
+      path: 'record',
+      name: 'Record',
+      component: () => import('@/views/dashboard/record-list/index.vue'),
       meta: {
-        locale: 'menu.manage.history',
+        locale: 'menu.manage.record',
         requiresAuth: true,
         roles: ['*'],
       },
@@ -30,7 +30,7 @@ const DASHBOARD: AppRouteRecordRaw = {
       meta: {
         locale: 'menu.manage.face',
         requiresAuth: true,
-        roles: ['admin'],
+        roles: ['*'],
       },
     },
   ],

+ 2 - 4
src/store/modules/user/index.ts

@@ -56,16 +56,14 @@ const useUserStore = defineStore('user', {
     // Get user's information
     async info() {
       const res = await getUserInfo();
-
       this.setInfo(res.data);
     },
 
     // Login
     async login(loginForm: LoginData) {
       try {
-        // const res = await userLogin(loginForm);
-        // setToken(res.data.token);
-        setToken('demo-token');
+        const res = await userLogin(loginForm);
+        setToken(res.data.token);
       } catch (err) {
         clearToken();
         throw err;

+ 0 - 19
src/views/dashboard/history-list/index.vue

@@ -1,19 +0,0 @@
-<template>
-  <div class="container"> </div>
-</template>
-
-<script lang="ts" name="HistoryListPage" setup></script>
-
-<style scoped lang="less">
-  .container {
-    padding: 0 10px 20px;
-
-    :deep(.arco-list-content) {
-      overflow-x: hidden;
-    }
-
-    :deep(.arco-card-meta-title) {
-      font-size: 14px;
-    }
-  }
-</style>

+ 0 - 4
src/views/dashboard/history-list/locale/en-US.ts

@@ -1,4 +0,0 @@
-export default {
-  'menu.manage.history': '历史记录',
-  'historyList.table.title': '历史记录',
-};

+ 0 - 4
src/views/dashboard/history-list/locale/zh-CN.ts

@@ -1,4 +0,0 @@
-export default {
-  'menu.manage.history': '历史记录',
-  'historyList.table.title': '历史记录',
-};

+ 126 - 0
src/views/dashboard/record-list/index.vue

@@ -0,0 +1,126 @@
+<template>
+  <div class="container">
+    <a-card class="general-card" title="">
+      <a-table
+        row-key="id"
+        :loading="loading"
+        :pagination="pagination"
+        :columns="(cloneColumns as TableColumnData[])"
+        :data="renderData"
+        :bordered="false"
+        :size="size"
+        @page-change="onPageChange"
+      >
+        <template #index="{ rowIndex }">
+          {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
+        </template>
+      </a-table>
+    </a-card>
+  </div>
+</template>
+
+<script lang="ts" name="RecordListPage" setup>
+  import { computed, ref, reactive, watch, nextTick } from 'vue';
+  import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
+  import { useI18n } from 'vue-i18n';
+  import useLoading from '@/hooks/loading';
+  import { Pagination } from '@/types/global';
+  import { queryPolicyList, PolicyRecord, PolicyParams } from '@/api/list';
+
+  type SizeProps = 'mini' | 'small' | 'medium' | 'large';
+  type Column = TableColumnData & { checked?: true };
+
+  const generateFormModel = () => {
+    return {
+      number: '',
+      name: '',
+      contentType: '',
+      filterType: '',
+      createdTime: [],
+      status: '',
+    };
+  };
+  const { loading, setLoading } = useLoading(true);
+  const { t } = useI18n();
+  const renderData = ref<PolicyRecord[]>([]);
+  const formModel = ref(generateFormModel());
+  const cloneColumns = ref<Column[]>([
+    {
+      title: 'Name',
+      dataIndex: 'name',
+      ellipsis: true,
+      tooltip: true,
+      width: 100,
+    },
+    {
+      title: 'Salary',
+      dataIndex: 'salary',
+    },
+    {
+      title: 'Address',
+      dataIndex: 'address',
+      ellipsis: true,
+      width: 150,
+    },
+    {
+      title: 'Email',
+      dataIndex: 'email',
+      ellipsis: true,
+      tooltip: { position: 'left' },
+      width: 200,
+    },
+  ]);
+
+  const size = ref<SizeProps>('medium');
+
+  const basePagination: Pagination = {
+    current: 1,
+    pageSize: 20,
+  };
+  const pagination = reactive({
+    ...basePagination,
+  });
+  const fetchData = async (
+    params: PolicyParams = { current: 1, pageSize: 20 }
+  ) => {
+    setLoading(true);
+    try {
+      // const { data } = await queryPolicyList(params);
+      // renderData.value = data.list;
+      // pagination.current = params.current;
+      // pagination.total = data.total;
+    } catch (err) {
+      // you can report use errorHandler or other
+    } finally {
+      setLoading(false);
+    }
+  };
+  fetchData();
+  const search = () => {
+    fetchData({
+      ...basePagination,
+      ...formModel.value,
+    } as unknown as PolicyParams);
+  };
+  const onPageChange = (current: number) => {
+    fetchData({ ...basePagination, current });
+  };
+</script>
+
+<style scoped lang="less">
+  .container {
+    padding: 10px;
+
+    :deep(.arco-list-content) {
+      overflow-x: hidden;
+    }
+
+    :deep(.arco-card-meta-title) {
+      font-size: 14px;
+    }
+
+    .general-card {
+      padding-top: 10px;
+    }
+  }
+</style>

+ 4 - 0
src/views/dashboard/record-list/locale/en-US.ts

@@ -0,0 +1,4 @@
+export default {
+  'menu.manage.record': '历史记录',
+  'recordList.table.title': '历史记录',
+};

+ 4 - 0
src/views/dashboard/record-list/locale/zh-CN.ts

@@ -0,0 +1,4 @@
+export default {
+  'menu.manage.record': '历史记录',
+  'recordList.table.title': '历史记录',
+};

+ 1 - 0
src/views/list/search-table/mock.ts

@@ -21,6 +21,7 @@ const data = Mock.mock({
 });
 
 setupMock({
+  mock: false,
   setup() {
     Mock.mock(new RegExp('/api/list/policy'), (params: GetParams) => {
       const { current = 1, pageSize = 10 } = qs.parseUrl(params.url).query;

+ 1 - 1
src/views/login/components/login-form.vue

@@ -104,7 +104,7 @@
         await userStore.login(values as LoginData);
         const { redirect, ...othersQuery } = router.currentRoute.value.query;
         router.push({
-          name: (redirect as string) || 'History',
+          name: (redirect as string) || 'Record',
           query: {
             ...othersQuery,
           },

+ 1 - 1
src/views/not-found/index.vue

@@ -13,7 +13,7 @@
   const router = useRouter();
   const back = () => {
     // warning: Go to the node that has the permission
-    router.push({ name: 'History' });
+    router.push({ name: 'Record' });
   };
 </script>
 

+ 1 - 0
src/views/user/info/mock.ts

@@ -2,6 +2,7 @@ import Mock from 'mockjs';
 import setupMock, { successResponseWrap } from '@/utils/setup-mock';
 
 setupMock({
+  mock: false,
   setup() {
     // 最新项目
     Mock.mock(new RegExp('/api/user/my-project/list'), () => {