This commit is contained in:
chenyang
2022-07-02 08:52:08 +08:00
parent 0a244b34cc
commit 43e1402c74
6 changed files with 132 additions and 52 deletions
+7
View File
@@ -40,8 +40,15 @@ INSTALLED_APPS = [
'server', 'server',
'server_auth', 'server_auth',
'channels', 'channels',
'django_filters' # 注册过滤
] ]
REST_FRAMEWORK = {
# 全局过滤
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination'
}
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
+19
View File
@@ -0,0 +1,19 @@
from rest_framework.pagination import PageNumberPagination
from server.util.constant_util import *
from rest_framework.response import Response
class DefaultNumberPagination(PageNumberPagination):
page_size = 1 # default page size
page_size_query_param = 'page_size' # ?page=xx&page_size=??
max_page_size = 50 # max page size
def get_paginated_response(self, data):
"""
重写返回值格式
"""
return Response({
'code': CODE_SUCCESS,
'count': self.page.paginator.count,
'results': data
})
-6
View File
@@ -1,6 +0,0 @@
from rest_framework.pagination import PageNumberPagination
class NewPagination(PageNumberPagination):
page_size = 2
page_size_query_param = 'page_size'
+2 -2
View File
@@ -8,7 +8,7 @@ from rest_framework.views import APIView
from server.filters import CooperationMindFilter from server.filters import CooperationMindFilter
from server.serializers import * from server.serializers import *
from server.util.mix_util import build_response from server.util.mix_util import build_response
from server.util.pagination import NewPagination from server.pagination import DefaultNumberPagination
from server_auth.lib.auth import LoginRequiredJSONMixin from server_auth.lib.auth import LoginRequiredJSONMixin
@@ -20,7 +20,7 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView):
serializer_class = CooperationMindSerializer serializer_class = CooperationMindSerializer
filter_backends = [DjangoFilterBackend] filter_backends = [DjangoFilterBackend]
filter_class = CooperationMindFilter filter_class = CooperationMindFilter
pagination_class = NewPagination pagination_class = DefaultNumberPagination
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
""" """
+70 -18
View File
@@ -10,9 +10,9 @@
<link rel="stylesheet" type="text/css" href="/static/css/dashboard.css"> <link rel="stylesheet" type="text/css" href="/static/css/dashboard.css">
<link rel="stylesheet" type="text/css" href="/static/bootstrap-4.6.1-dist/css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="/static/bootstrap-4.6.1-dist/css/bootstrap.css">
<!--script start <!--script start-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>-->
<script src="/static/js/jquery-1.11.3.min.js"></script> <script src="/static/js/jquery-1.11.3.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="/static/bootstrap-4.6.1-dist/js/bootstrap.bundle.js"></script> <!-- bootstrap.bundle.min.js,还包含了 Popper,用于支持工具提示(tooltip)和弹出框(popover)功能,但是不包含 jQuery。--> <script src="/static/bootstrap-4.6.1-dist/js/bootstrap.bundle.js"></script> <!-- bootstrap.bundle.min.js,还包含了 Popper,用于支持工具提示(tooltip)和弹出框(popover)功能,但是不包含 jQuery。-->
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"></script> <!-- 图标相关--> <script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"></script> <!-- 图标相关-->
<script> <script>
@@ -37,8 +37,7 @@
qr_websocket.websocket.close() qr_websocket.websocket.close()
}); });
/**点击 扫码登录 */
// 扫码登录
$('#s_login_a').click(function () { $('#s_login_a').click(function () {
$('.modal-body').hide(); $('.modal-body').hide();
$('.qr_login_group').show(); $('.qr_login_group').show();
@@ -162,12 +161,15 @@
$.ajax({ $.ajax({
type: "post", type: "post",
url: "login", url: "login",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {username: userName_login, password: inputPassword_login}, data: {username: userName_login, password: inputPassword_login},
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
// 注册成功 // 注册成功
if (data.code === 0) { if (data.code === 0) {
login_alert(data.msg, 'alert-primary') login_alert(data.msg, 'alert-primary')
$('#exampleModal').modal('hide')
fetch_mind()
} else { } else {
// 注册失败 // 注册失败
login_alert(data.msg) login_alert(data.msg)
@@ -177,6 +179,58 @@
}); });
}) })
/**获得导图*/
function fetch_mind(page, page_size) {
if (!page) {
page = 1
}
if (!page_size) {
page_size = 10
}
$.ajax({
type: `get`,
url: `list?page=${page}&page_size=${page_size}`,
headers: {"X-CSRFToken": $.cookie("csrftoken")},
dataType: "json",
success: function (resp) {
if (resp.code !== 0) {
return
}
// 解析结果
const results = resp.results
let idx = 0
let row = $(`<div class="row"></row>`)
results.forEach(function (item) {
const content = `
<div class="card col-3" style="width: 18rem;margin: 8px;">
<div class="card-body">
<h5 class="card-title">${item.coop_mind_name}</h5>
<img src="https://img0.baidu.com/it/u=218959243,558802769&fm=253&fmt=auto&app=138&f=JPEG?w=1377&h=500" class="card-img-top" alt="...">
<a href="#" class="btn btn-info">编辑</a>
</div>
</div>
`
row.append(content)
idx++
if (idx % 3 === 0) {
// 3个一行
$('main .container-fluid').append(row)
// 重置row
row = $(`<div class="row"></row>`)
}
})
// 如果不是3的整数倍,将剩余的添加
if (idx % 3 !== 0) {
$('main .container-fluid').append(row)
}
},
async: false
});
}
/**如果已经登录则查询列表*/
fetch_mind()
// js end // js end
}) })
</script> </script>
@@ -202,36 +256,40 @@
<!--qr_login end--> <!--qr_login end-->
<!--register start--> <!--register start-->
<form>
<div class="modal-body register_group" style="display: none;height: 360px;"> <div class="modal-body register_group" style="display: none;height: 360px;">
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1> <h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
<label for="userName" class="sr-only"></label> <label for="userName" class="sr-only"></label>
<input type="text" id="userName" class="form-control" placeholder="用户名" autocomplete="off" required autofocus> <input type="text" id="userName" class="form-control" placeholder="用户名" autocomplete="off" required autofocus>
<label for="inputPassword" class="sr-only"></label> <label for="inputPassword" class="sr-only"></label>
<input type="password" id="inputPassword" class="form-control" placeholder="密码" required> <input type="password" id="inputPassword" class="form-control" placeholder="密码" autocomplete="new-password" required>
<label for="inputPassword_" class="sr-only"></label> <label for="inputPassword_" class="sr-only"></label>
<input type="password" id="inputPassword_" class="form-control" placeholder="密码" required> <input type="password" id="inputPassword_" class="form-control" placeholder="密码" autocomplete="new-password" required>
<div style="margin-bottom: 10px; text-align:right;"> <div style="margin-bottom: 10px; text-align:right;">
<button class="btn btn-sm btn-primary" type="submit" id="register_button">注册</button> <button class="btn btn-sm btn-primary" type="submit" id="register_button">注册</button>
</div> </div>
</div> </div>
</form>
<!--register end--> <!--register end-->
<!--pw_login start--> <!--pw_login start-->
<form>
<div class="modal-body pw_login_group" style="display: none;height: 360px;"> <div class="modal-body pw_login_group" style="display: none;height: 360px;">
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1> <h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
<label for="userName_login" class="sr-only">用户名</label> <label for="userName_login" class="sr-only">用户名</label>
<input type="text" id="userName_login" name="userName_login" class="form-control" placeholder="用户名" required autofocus> <input type="text" id="userName_login" name="userName_login" class="form-control" placeholder="用户名" autocomplete="username" required autofocus>
<label for="inputPassword_login" class="sr-only">密码</label> <label for="inputPassword_login" class="sr-only">密码</label>
<input type="password" id="inputPassword_login" name="inputPassword_login" class="form-control" placeholder="密码" required> <input type="password" id="inputPassword_login" name="inputPassword_login" class="form-control" placeholder="密码" autocomplete="current-password" required>
<div style="margin-bottom: 10px; text-align:right;"> <div style="margin-bottom: 10px; text-align:right;">
<button class="btn btn-sm btn-primary" id="login_button">登录</button> <button class="btn btn-sm btn-primary" id="login_button" type="button">登录</button>
</div> </div>
</div> </div>
</form>
<!--pw_login end--> <!--pw_login end-->
<div class="modal-footer"> <div class="modal-footer">
@@ -302,13 +360,14 @@
<!-- 左侧菜单 end--> <!-- 左侧菜单 end-->
<!-- 右侧内容 start--> <!-- 右侧内容 start-->
<main role="main" class="col-md-10 ml-sm-auto col-lg-10 px-md-4"> <main role="main" class="col-md-10 ml-sm-auto col-lg-10 px-md-4" id="main">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">全部文件</h1> <h1 class="h2">全部文件</h1>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">
<!--
<div class="row"> <div class="row">
<div class="card col-3" style="width: 18rem;margin: 8px;"> <div class="card col-3" style="width: 18rem;margin: 8px;">
<div class="card-body"> <div class="card-body">
@@ -317,15 +376,8 @@
<a href="#" class="btn btn-info">编辑</a> <a href="#" class="btn btn-info">编辑</a>
</div> </div>
</div> </div>
<div class="card col-3" style="width: 18rem;margin: 8px;">
<div class="card-body">
<h5 class="card-title">开发计划</h5>
<img src="https://img0.baidu.com/it/u=218959243,558802769&fm=253&fmt=auto&app=138&f=JPEG?w=1377&h=500" class="card-img-top" alt="...">
<a href="#" class="btn btn-info">编辑</a>
</div>
</div>
</div> </div>
-->
</div> </div>
</main> </main>
<!-- 右侧内容 end--> <!-- 右侧内容 end-->
+11 -3
View File
@@ -8,6 +8,7 @@
<link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" media="all"> <link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" media="all">
<script src="/static/layui-v2.6.8/layui/layui.js"></script> <script src="/static/layui-v2.6.8/layui/layui.js"></script>
<script src="/static/js/jquery-1.11.3.min.js"></script> <script src="/static/js/jquery-1.11.3.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script> <script>
let layer //弹层 let layer //弹层
, laypage //分页 , laypage //分页
@@ -241,17 +242,24 @@
} }
// post start // post start
const post_data = {'mind_name': mind_name, 'data_format': 'node_tree', 'snapshot_data': view.json2string(snapshot_data)} const post_data = {'mind_name': mind_name, 'data_format': 'node_tree', 'snapshot_data': view.json2string(snapshot_data)}
$.post('create', post_data, function (resp) { $.ajax({
type: "post",
url: "create",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: post_data,
dataType: "json",
success: function (resp) {
layer.closeAll() layer.closeAll()
view.fetch_data() view.fetch_data()
layer.msg('创建成功') layer.msg('创建成功')
// 新页面打开 // 新页面打开
setTimeout(function () { setTimeout(function () {
const id = resp.data const id = resp.data
window.open('detail?id=' + id) window.open('detail?id=' + id)
}, 500) }, 500)
}) },
async: false
});
// post end // post end
} else { } else {
layer.msg('请输入导图名称') layer.msg('请输入导图名称')