瀏覽代碼

chore: 修改登录逻辑适应后端接口

lanjianrong 4 年之前
父節點
當前提交
dbfd9f0ff2

+ 3 - 19
src/api/sys/model/userModel.ts

@@ -2,7 +2,7 @@
  * @description: Login interface parameters
  */
 export interface LoginParams {
-  username: string
+  staffName: string
   password: string
 }
 
@@ -31,22 +31,6 @@ export interface LoginResultModel {
  * @description: Get user information return value
  */
 export interface GetUserInfoByUserIdModel {
-  // roles: RoleInfo[]
-  id: string
-  projectId: string
-  bidsectionId: string
-  account: string
-  password: string
-  name: string
-  company: string
-  position: string
-  role: string
-  mobile: string
-  telephone: string
-  isAdmin: number
-  accountGroup: number
-  enable: number
-  contractPermission: string
-  qualityPermission: string
-  safePermission: string
+  username: string
+  category: string
 }

+ 1 - 1
src/api/sys/user.ts

@@ -10,7 +10,7 @@ import { ErrorMessageMode } from '/@/utils/http/axios/types'
 
 enum Api {
   Login = '/backstage/login',
-  Logout = '/backstage/out',
+  Logout = '/backstage/login/out',
   GetUserInfoById = '/login/project/name',
   GetPermCodeByUserId = '/getPermCodeByUserId',
   GetToken = '/login/project/name'

+ 1 - 1
src/design/var/index.less

@@ -2,7 +2,7 @@
 @import 'easing';
 @import 'breakpoint';
 
-@namespace: vben;
+@namespace: zh;
 
 // tabs
 @multiple-height: 30px;

+ 2 - 2
src/enums/pageEnum.ts

@@ -2,9 +2,9 @@ export enum PageEnum {
   // basic login path
   BASE_LOGIN = '/login',
   // basic home path
-  BASE_HOME = '/dashboard',
+  BASE_HOME = '/dashboard/main',
   // error page path
   ERROR_PAGE = '/exception',
   // error log page path
-  ERROR_LOG_PAGE = '/error-log/list',
+  ERROR_LOG_PAGE = '/error-log/list'
 }

+ 0 - 11
src/router/menus/modules/about.ts

@@ -1,11 +0,0 @@
-import type { MenuModule } from '/@/router/types';
-import { t } from '/@/hooks/web/useI18n';
-
-const about: MenuModule = {
-  orderNo: 100000,
-  menu: {
-    path: '/about/index',
-    name: t('routes.dashboard.about'),
-  },
-};
-export default about;

+ 7 - 18
src/router/menus/modules/dashboard.ts

@@ -1,22 +1,11 @@
-import type { MenuModule } from '/@/router/types';
-import { t } from '/@/hooks/web/useI18n';
+import type { MenuModule } from '/@/router/types'
+import { t } from '/@/hooks/web/useI18n'
 
 const menu: MenuModule = {
   orderNo: 10,
   menu: {
-    name: t('routes.dashboard.dashboard'),
-    path: '/dashboard',
-
-    children: [
-      {
-        path: 'analysis',
-        name: t('routes.dashboard.analysis'),
-      },
-      {
-        path: 'workbench',
-        name: t('routes.dashboard.workbench'),
-      },
-    ],
-  },
-};
-export default menu;
+    name: t('routes.dashboard.workbench'),
+    path: '/dashboard/main'
+  }
+}
+export default menu

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

@@ -7,17 +7,17 @@ const dashboard: AppRouteModule = {
   path: '/dashboard',
   name: 'Dashboard',
   component: LAYOUT,
-  redirect: '/dashboard/analysis',
+  redirect: '/dashboard/main',
   meta: {
-    icon: 'ion:grid-outline',
     title: t('routes.dashboard.dashboard')
   },
   children: [
     {
-      path: 'workbench',
+      path: 'main',
       name: 'Workbench',
       component: () => import('/@/views/dashboard/workbench/index.vue'),
       meta: {
+        icon: 'ion:grid-outline',
         title: t('routes.dashboard.workbench')
       }
     }

+ 16 - 11
src/store/modules/user.ts

@@ -76,27 +76,32 @@ export const useUserStore = defineStore({
     ): Promise<GetUserInfoByUserIdModel | null> {
       try {
         const { goHome = true, mode, ...loginParams } = params
-        await getXsrfToken('234')
-        const userInfo = await loginApi(loginParams, mode)
 
-        // save token
-        const token = getToken() as string
-        this.setToken(token)
+        const userInfo = await loginApi(loginParams, mode)
         // get user info
         // const userInfo = await this.getUserInfoAction({ userId })
+        this.setRoleList([RoleEnum.SUPER])
+        // if (isAdmin) {
+        // }
 
-        goHome && (await router.replace(PageEnum.BASE_HOME))
-        const { isAdmin } = userInfo
-        if (isAdmin) {
-          this.setRoleList([RoleEnum.SUPER])
-        }
         // const roleList = roles.map(item => item.value) as RoleEnum[]
-        this.setUserInfo(userInfo)
+        this.setUserInfo({ ...userInfo })
+        goHome && (await router.replace(PageEnum.BASE_HOME))
         return userInfo
       } catch (error) {
+        console.log(error)
+
         return null
       }
     },
+    async getToken() {
+      await getXsrfToken('234')
+
+      // save token
+      const token = getToken() as string
+
+      this.setToken(token)
+    },
     // async getUserInfoAction({ userId }: GetUserInfoByUserIdParams) {
     //   const userInfo = await getUserInfoById({ userId })
     //   const { roles } = userInfo

+ 4 - 1
src/utils/http/axios/index.ts

@@ -36,6 +36,7 @@ const transform: AxiosTransform = {
    */
   transformRequestHook: (res: AxiosResponse<Result>, options: RequestOptions) => {
     const { t } = useI18n()
+
     const { isTransformRequestResult } = options
     // 不进行任何处理,直接返回
     // 用于页面代码可能需要直接获取code,data,message这些信息时开启
@@ -98,6 +99,8 @@ const transform: AxiosTransform = {
       Promise.reject(new Error(timeoutMsg))
       return errorResult
     }
+    console.log(errorResult)
+
     return errorResult
   },
 
@@ -210,7 +213,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
           // 接口地址
           apiUrl: globSetting.apiUrl,
           //  是否加入时间戳
-          joinTime: true,
+          joinTime: false,
           // 忽略重复请求
           ignoreCancelToken: true
         }

+ 62 - 58
src/views/sys/login/LoginForm.vue

@@ -40,7 +40,7 @@
         {{ t('sys.login.registerButton') }}
       </Button> -->
     </FormItem>
-    <ARow class="enter-x">
+    <!-- <ARow class="enter-x">
       <ACol :xs="24" :md="8">
         <Button block @click="setLoginState(LoginStateEnum.MOBILE)">
           {{ t('sys.login.mobileSignInFormTitle') }}
@@ -56,39 +56,39 @@
           {{ t('sys.login.registerButton') }}
         </Button>
       </ACol>
-    </ARow>
+    </ARow> -->
 
     <Divider class="enter-x">{{ t('sys.login.otherSignIn') }}</Divider>
 
     <div class="flex justify-evenly enter-x" :class="`${prefixCls}-sign-in-way`">
-      <GithubFilled />
+      <!-- <GithubFilled />
       <WechatFilled />
       <AlipayCircleFilled />
       <GoogleCircleFilled />
-      <TwitterCircleFilled />
+      <TwitterCircleFilled /> -->
     </div>
   </Form>
 </template>
 <script lang="ts">
-  import { defineComponent, reactive, ref, toRaw, unref, computed } from 'vue';
-
-  import { Checkbox, Form, Input, Row, Col, Button, Divider } from 'ant-design-vue';
-  import {
-    GithubFilled,
-    WechatFilled,
-    AlipayCircleFilled,
-    GoogleCircleFilled,
-    TwitterCircleFilled,
-  } from '@ant-design/icons-vue';
-  import LoginFormTitle from './LoginFormTitle.vue';
-
-  import { useI18n } from '/@/hooks/web/useI18n';
-  import { useMessage } from '/@/hooks/web/useMessage';
-
-  import { useUserStore } from '/@/store/modules/user';
-  import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin';
-  import { useDesign } from '/@/hooks/web/useDesign';
-  import { onKeyStroke } from '@vueuse/core';
+  import { defineComponent, reactive, ref, toRaw, unref, computed, onMounted } from 'vue'
+
+  import { Checkbox, Form, Input, Row, Col, Button, Divider } from 'ant-design-vue'
+  // import {
+  //   GithubFilled,
+  //   WechatFilled,
+  //   AlipayCircleFilled,
+  //   GoogleCircleFilled,
+  //   TwitterCircleFilled,
+  // } from '@ant-design/icons-vue';
+  import LoginFormTitle from './LoginFormTitle.vue'
+
+  import { useI18n } from '/@/hooks/web/useI18n'
+  import { useMessage } from '/@/hooks/web/useMessage'
+
+  import { useUserStore } from '/@/store/modules/user'
+  import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin'
+  import { useDesign } from '/@/hooks/web/useDesign'
+  import { onKeyStroke } from '@vueuse/core'
 
   export default defineComponent({
     name: 'LoginForm',
@@ -102,57 +102,61 @@
       Input,
       Divider,
       LoginFormTitle,
-      InputPassword: Input.Password,
-      GithubFilled,
-      WechatFilled,
-      AlipayCircleFilled,
-      GoogleCircleFilled,
-      TwitterCircleFilled,
+      InputPassword: Input.Password
+      // GithubFilled,
+      // WechatFilled,
+      // AlipayCircleFilled,
+      // GoogleCircleFilled,
+      // TwitterCircleFilled,
     },
     setup() {
-      const { t } = useI18n();
-      const { notification } = useMessage();
-      const { prefixCls } = useDesign('login');
-      const userStore = useUserStore();
+      const { t } = useI18n()
+      const { notification } = useMessage()
+      const { prefixCls } = useDesign('login')
+      const userStore = useUserStore()
 
-      const { setLoginState, getLoginState } = useLoginState();
-      const { getFormRules } = useFormRules();
+      const { setLoginState, getLoginState } = useLoginState()
+      const { getFormRules } = useFormRules()
 
-      const formRef = ref();
-      const loading = ref(false);
-      const rememberMe = ref(false);
+      const formRef = ref()
+      const loading = ref(false)
+      const rememberMe = ref(false)
 
       const formData = reactive({
-        account: 'vben',
-        password: '123456',
-      });
+        account: '蔡频',
+        password: '123456'
+      })
 
-      const { validForm } = useFormValid(formRef);
+      onMounted(() => {
+        userStore.getToken()
+      })
+      const { validForm } = useFormValid(formRef)
 
-      onKeyStroke('Enter', handleLogin);
+      onKeyStroke('Enter', handleLogin)
 
-      const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN);
+      const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
 
       async function handleLogin() {
-        const data = await validForm();
-        if (!data) return;
+        const data = await validForm()
+        if (!data) return
         try {
-          loading.value = true;
+          loading.value = true
           const userInfo = await userStore.login(
             toRaw({
-              password: data.password,
-              username: data.account,
+              staffName: data.account,
+              password: data.password
             })
-          );
+          )
+
           if (userInfo) {
             notification.success({
               message: t('sys.login.loginSuccessTitle'),
-              description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realName}`,
-              duration: 3,
-            });
+              // description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realName}`,
+              duration: 3
+            })
           }
         } finally {
-          loading.value = false;
+          loading.value = false
         }
       }
 
@@ -167,8 +171,8 @@
         loading,
         setLoginState,
         LoginStateEnum,
-        getShow,
-      };
-    },
-  });
+        getShow
+      }
+    }
+  })
 </script>

+ 2 - 17
types/store.ts

@@ -30,23 +30,8 @@ export interface ErrorLogInfo {
 }
 
 export interface UserInfo {
-  id: string
-  projectId: string
-  bidsectionId: string
-  account: string
-  password: string
-  name: string
-  company: string
-  position: string
-  role: string
-  mobile: string
-  telephone: string
-  isAdmin: number
-  accountGroup: number
-  enable: number
-  contractPermission: string
-  qualityPermission: string
-  safePermission: string
+  username: string
+  category: string
 }
 
 export interface BeforeMiniState {