Browse Source

接口配置,

wangwei 4 years ago
parent
commit
b52bca9e6b

+ 2 - 1
.env.development

@@ -14,7 +14,8 @@ VITE_PROXY=[["/api","http://localhost:3000"],["/upload","http://localhost:3001/u
 VITE_DROP_CONSOLE = false
 
 # Basic interface address SPA
-VITE_GLOB_API_URL=/api
+VITE_GLOB_API_URL= http://localhost:8000/api
+# VITE_GLOB_API_URL=/api
 
 # File upload address, optional
 VITE_GLOB_UPLOAD_URL=/upload

BIN
server/api/__pycache__/models.cpython-38.pyc


BIN
server/api/__pycache__/views.cpython-38.pyc


+ 18 - 0
server/api/migrations/0012_auto_20210330_1125.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.1.7 on 2021-03-30 11:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0011_auto_20210329_1145'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='user',
+            old_name='realname',
+            new_name='realName',
+        ),
+    ]

BIN
server/api/migrations/__pycache__/0012_auto_20210330_1125.cpython-38.pyc


+ 1 - 1
server/api/models.py

@@ -3,7 +3,7 @@ from django.db import models
 
 class User(models.Model):
     username = models.CharField(max_length=20, unique=True, null=False)
-    realname = models.CharField(max_length=20, null=True)
+    realName = models.CharField(max_length=20, null=True)
     password = models.CharField(max_length=32, null=False)
     roleName = models.CharField(max_length=32, null=True)
     value = models.CharField(max_length=32, null=True)

+ 22 - 1
server/api/views.py

@@ -53,6 +53,23 @@ def format_useinfo(user):
         ]
         res.pop('roleName')
         res.pop('value')
+        res.pop('password')
+    return res
+
+
+def format_login_result(user):
+    format_user = json.loads(
+        serialize('json', user, ensure_ascii=False)
+    )
+    for item in format_user:
+        res = {}
+        res['userId'] = item.get('pk')
+        res['token'] = item.get('fields').get('token')
+        res['roles'] = [
+            {
+                'roleName': item.get('fields').get('roleName'), 'value': item.get('fields').get('value')
+            }
+        ]
     return res
 
 
@@ -116,7 +133,11 @@ class login(View):
         user = User.objects.all().filter(username=data.get(
             'username'), password=data.get('password'))
         if user:
-            res = format_useinfo(user)
+            print('-------user---------')
+            print(user)
+            res = format_login_result(user)
+            print('---------------res--------')
+            print(res)
             return JsonResponse({'code': 0, 'msg': 'success', 'result': res}, json_dumps_params={"ensure_ascii": False})
         else:
             return JsonResponse({'code': 1, 'error': '用户名或密码不正确'}, json_dumps_params={"ensure_ascii": False})

+ 2 - 0
src/api/sys/model/userModel.ts

@@ -38,6 +38,8 @@ export interface GetUserInfoByUserIdModel {
   username: string;
   // 真实名字
   realName: string;
+
+  status: boolean;
   // 介绍
   desc?: string;
 }

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

@@ -8,7 +8,7 @@ import {
 import { ErrorMessageMode } from '/@/utils/http/axios/types';
 
 enum Api {
-  Login = '/login',
+  Login = '/login/',
   GetUserInfoById = '/getUserInfoById',
   GetPermCodeByUserId = '/getPermCodeByUserId',
 }