Files
Nsfocus_test_ai_project/static/html/dashboard.html
T
2022-07-02 10:14:23 +08:00

424 lines
17 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Dashboard Template</title>
<link rel="shortcut icon" href="/static/abl1b-qks1b-001.ico"/>
<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">
<!--script start-->
<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="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"></script> <!-- 图标相关-->
<script>
const qr_websocket = {
websocket: null,
uuid: (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16)
}
$(function () {
// 监听modal窗口事件
$('#exampleModal').on('show.bs.modal', function (event) {
// console.log(qr_websocket)
// console.log('打开');
const ws = new WebSocket(`ws://${window.location.host}/ws/qr/?${qr_websocket.uuid}`)
ws.onmessage = function (e) {
console.log('接收到websocket消息:' + e.data)
}
qr_websocket.websocket = ws
});
$('#exampleModal').on('hidden.bs.modal', function (event) {
// console.log('关闭');
qr_websocket.websocket.close()
});
/**点击 扫码登录 */
$('#s_login_a').click(function () {
$('.modal-body').hide();
$('.qr_login_group').show();
set_modal_title('登录');
})
// 点击注册控件
$('#register_a').click(function () {
$('.modal-body').hide();
$('.register_group').show();
set_modal_title('注册');
})
// 用户名密码登录
$('#p_login_a').click(function () {
$('.modal-body').hide();
$('.pw_login_group').show();
set_modal_title('登录');
})
/** 设置窗口名称 */
function set_modal_title(title) {
$('#exampleModal .modal-title').html(title);
}
/** 注册按钮 */
$('#register_button').click(function () {
const userName = $('#userName').val();
const inputPassword = $('#inputPassword').val();
const inputPassword_ = $('#inputPassword_').val();
if (!userName) {
reg_alert('请输入用户名')
return
}
if (!inputPassword) {
reg_alert('请输入密码')
return
}
// 校验输入是否一致
const validate = validate_pw_eq(this, inputPassword, inputPassword_)
if (validate) {
$.ajax({
type: "post",
url: "register",
data: {userName: userName, inputPassword: inputPassword},
dataType: "json",
success: function (data) {
// 注册成功
if (data.code === 0) {
clear_reg_info()
reg_alert(data.msg, 'alert-primary')
setTimeout(function () {
$('#p_login_a').click()
}, 1500)
} else {
// 注册失败
reg_alert(data.msg)
}
},
async: false
});
}
// validate end
});
/** 清除注册时输入内容 */
function clear_reg_info() {
$('#userName').val('');
$('#inputPassword').val('');
$('#inputPassword_').val('');
}
/**校验密码是否输入一致*/
function validate_pw_eq(obj, inputPassword, inputPassword_) {
if (inputPassword !== inputPassword_) {
reg_alert('两次密码输入不一样,请确认!')
return false
}
return true
}
/** 注册提示 */
function reg_alert(text, class_str) {
common_alert('register_button', text, class_str)
}
/** 登录提示 */
function login_alert(text, class_str) {
common_alert('login_button', text, class_str)
}
function common_alert(button_id, text, class_str) {
// 清除之前的弹窗
$('.alert').alert('close')
//
const uuid = '' + (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16)
const class_name = class_str ? class_str : 'alert-danger'
const alert_component = `
<div class="alert ${class_name} .alert-dismissible fade show" role="alert" id="${uuid}" style="clear: both;margin-top: 3px;margin-bottom: 3px;height: 30px;padding-top: 2px;padding-bottom: 2px;">
${text}
</div>
`
$('#' + button_id).parent().after(alert_component)
setTimeout(function () {
$('#' + uuid).fadeOut(1200)
}, 1000)
}
/**登录按钮*/
$('#login_button').click(function () {
const userName_login = $('#userName_login').val();
const inputPassword_login = $('#inputPassword_login').val();
if (!userName_login || !inputPassword_login) {
login_alert('请输入用户名和密码')
return
}
$.ajax({
type: "post",
url: "login",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {username: userName_login, password: inputPassword_login},
dataType: "json",
success: function (data) {
// 注册成功
if (data.code === 0) {
login_alert(data.msg, 'alert-primary')
$('#exampleModal').modal('hide')
fetch_mind()
} else {
// 注册失败
login_alert(data.msg)
}
},
async: false
});
})
/**获得导图*/
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
})
</script>
<!--script end-->
</head>
<body>
<!-- Modal start-->
<div class="modal fade" id="exampleModal" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">扫码登录</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<!--qr_login start-->
<div class="modal-body qr_login_group" style="height: 360px;">
<img src="https://img0.baidu.com/it/u=3881180510,1470858589&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" height="300px">
</div>
<!--qr_login end-->
<!--register start-->
<form>
<div class="modal-body register_group" style="display: none;height: 360px;">
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
<label for="userName" class="sr-only"></label>
<input type="text" id="userName" class="form-control" placeholder="用户名" autocomplete="off" required autofocus>
<label for="inputPassword" class="sr-only"></label>
<input type="password" id="inputPassword" class="form-control" placeholder="密码" autocomplete="new-password" required>
<label for="inputPassword_" class="sr-only"></label>
<input type="password" id="inputPassword_" class="form-control" placeholder="密码" autocomplete="new-password" required>
<div style="margin-bottom: 10px; text-align:right;">
<button class="btn btn-sm btn-primary" type="submit" id="register_button">注册</button>
</div>
</div>
</form>
<!--register end-->
<!--pw_login start-->
<form>
<div class="modal-body pw_login_group" style="display: none;height: 360px;">
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
<label for="userName_login" class="sr-only">用户名</label>
<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>
<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;">
<button class="btn btn-sm btn-primary" id="login_button" type="button">登录</button>
</div>
</div>
</form>
<!--pw_login end-->
<div class="modal-footer">
<a class="nav-link active" href="#" id="s_login_a">
<span data-feather="grid"></span>
扫码登录
</a>
<a class="nav-link active" id="register_a" href="#">
<span data-feather="check-circle"></span>
用户注册
</a>
<a class="nav-link active" href="#" id="p_login_a">
<span data-feather="smartphone"></span>
用户名登录
</a>
</div>
</div>
</div>
</div>
<div class="modal fade" id="newMindModal" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">新建</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<!--start-->
<form>
<div class="modal-body register_group">
<label for="userName" class="sr-only"></label>
<input type="text" id="userName" class="form-control" placeholder="思维导图名称" autocomplete="off" required autofocus>
<div style="text-align:right;">
<button type="button" class="btn btn-info">确认创建</button>
</div>
</div>
</form>
<!--end-->
</div>
</div>
</div>
<!-- Modal end-->
<!-- 页眉 start-->
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-md-2 col-lg-2 mr-0 px-3" href="#">协作思维导图</a>
<ul class="navbar-nav px-3">
<li class="nav-item text-nowrap">
<a class="nav-link" href="#" data-toggle="modal" data-target="#exampleModal">登录/注册</a>
</li>
</ul>
</nav>
<!-- 页眉 end-->
<!--菜单 和 内容 start-->
<div class="container-fluid">
<div class="row">
<!-- 左侧菜单 start-->
<nav id="sidebarMenu" class="col-md-2 col-lg-2 d-md-block bg-light">
<div class="sidebar-sticky pt-3">
<hr/>
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
<span data-feather="file-text"></span>
我的脑图
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="share-2"></span>
我的分享
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="star"></span>
我的收藏
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="trash-2"></span>
回收站
</a>
</li>
</ul>
</div>
</nav>
<!-- 左侧菜单 end-->
<!-- 右侧内容 start-->
<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">
<h1 class="h2">全部文件</h1>
</div>
<div>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#newMindModal">新建导图</button>
</div>
<div class="container-fluid">
<!--
<div class="row">
<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>
</main>
<!-- 右侧内容 end-->
</div>
</div>
<!--导航 和 内容 end-->
<script>
if (window.feather) {
window.feather.replace();
}
</script>
</body>
</html>