Kaynağa Gözat

feat: 用户名密码登录

Tim_Walker 2 yıl önce
ebeveyn
işleme
5552d74eec

+ 1 - 1
.env.dev

@@ -2,7 +2,7 @@
 NODE_ENV=production
 
 # 接口前缀
-VITE_API_BASEPATH=dev
+VITE_API_BASEPATH=/api
 
 # 打包路径
 VITE_BASE_PATH=/dist-dev/

+ 3 - 0
.vscode/settings.json

@@ -1,5 +1,8 @@
 {
   "i18n-ally.localesPaths": [
     "src/locales"
+  ],
+  "cSpell.words": [
+    "chelvc"
   ]
 }

+ 13 - 1
src/api/login/index.ts

@@ -6,7 +6,19 @@ interface RoleParams {
 }
 
 export const loginApi = (data: UserType): Promise<IResponse<UserType>> => {
-  return request.post({ url: '/user/login', data })
+  return request.post({
+    url: '/uc/oauth/token',
+    data: Object.assign({}, data, {
+      client_id: 'chelvc_client',
+      client_secret: 'qWBe6jD%GCuPPTkP',
+      grant_type: 'password'
+    }),
+    headersType: 'application/x-www-form-urlencoded',
+    headers: {
+      Platform: 'PC',
+      Terminal: 'ADMIN'
+    }
+  })
 }
 
 export const loginOutApi = (): Promise<IResponse> => {

+ 3 - 3
src/config/axios/config.ts

@@ -14,7 +14,7 @@ const config: {
    */
   base_url: {
     // 开发环境接口前缀
-    base: '',
+    base: 'http://test.chelvc.com/api',
 
     // 打包开发环境接口前缀
     dev: '',
@@ -29,12 +29,12 @@ const config: {
   /**
    * 接口成功返回状态码
    */
-  result_code: '0000',
+  result_code: '200',
 
   /**
    * 接口请求超时时间
    */
-  request_timeout: 60000,
+  request_timeout: 10000,
 
   /**
    * 默认接口请求类型

+ 2 - 1
src/config/axios/service.ts

@@ -59,10 +59,11 @@ service.interceptors.request.use(
 // response 拦截器
 service.interceptors.response.use(
   (response: AxiosResponse<any>) => {
+    console.log('response', response)
     if (response.config.responseType === 'blob') {
       // 如果是文件流,直接过
       return response
-    } else if (response.data.code === result_code) {
+    } else if (response.status == result_code) {
       return response.data
     } else {
       ElMessage.error(response.data.message)

+ 6 - 5
src/permission.ts

@@ -66,11 +66,12 @@ router.beforeEach(async (to, from, next) => {
       next(nextData)
     }
   } else {
-    if (whiteList.indexOf(to.path) !== -1) {
-      next()
-    } else {
-      next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
-    }
+    // if (whiteList.indexOf(to.path) !== -1) {
+    //   next()
+    // } else {
+    //   next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
+    // }
+    next()
   }
 })
 

+ 5 - 5
src/views/Login/components/LoginForm.vue

@@ -2,7 +2,7 @@
 import { reactive, ref, unref, watch } from 'vue'
 import { Form } from '@/components/Form'
 import { useI18n } from '@/hooks/web/useI18n'
-import { ElButton, ElCheckbox, ElLink } from 'element-plus'
+import { ElButton, ElCheckbox, ElLink, ElMessage } from 'element-plus'
 import { useForm } from '@/hooks/web/useForm'
 import { loginApi, getTestRoleApi, getAdminRoleApi } from '@/api/login'
 import { useCache } from '@/hooks/web/useCache'
@@ -43,7 +43,7 @@ const schema = reactive<FormSchema[]>([
   {
     field: 'username',
     label: t('login.username'),
-    value: 'admin',
+    value: '18380313545',
     component: 'Input',
     colProps: {
       span: 24
@@ -55,7 +55,7 @@ const schema = reactive<FormSchema[]>([
   {
     field: 'password',
     label: t('login.password'),
-    value: 'admin',
+    value: '313545',
     component: 'InputPassword',
     colProps: {
       span: 24
@@ -124,12 +124,12 @@ const signIn = async () => {
     if (isValid) {
       loading.value = true
       const { getFormData } = methods
-      const formData = await getFormData<UserType>()
+      let formData = await getFormData<UserType>()
 
       try {
         const res = await loginApi(formData)
-
         if (res) {
+          ElMessage.success('登录成功!')
           wsCache.set(appStore.getUserInfo, res.data)
           // 是否使用动态路由
           if (appStore.getDynamicRouter) {