From 8d9083ea58b4339ff585659e7f8b4b6e856a68db Mon Sep 17 00:00:00 2001 From: chenyang Date: Sat, 2 Jul 2022 18:17:12 +0800 Subject: [PATCH] update --- static/html/dashboard.html | 137 ++++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 57 deletions(-) diff --git a/static/html/dashboard.html b/static/html/dashboard.html index 5b5a221..a9eae80 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -22,7 +22,23 @@ uuid: (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16) } + /**界面初始化*/ + function view_init() { + const uid = $('#uid').html() + // 未登录 + if (!uid || isNaN(uid)) { + $('#login_register').show() + $('#logout_a').hide() + } else { + $('#login_register').hide() + $('#logout_a').show() + } + } + $(function () { + /**界面初始化*/ + view_init() + // 监听modal窗口事件 $('#exampleModal').on('show.bs.modal', function (event) { // console.log(qr_websocket) @@ -152,8 +168,11 @@ if (data.code === 0) { login_alert(data.msg, 'alert-primary') $('#exampleModal').modal('hide') - $('#login_register').remove() - fetch_mind() + // $('#login_register').hide() + // fetch_mind() + setTimeout(function () { + location.reload(); + }, 500) } else { // 登录失败 login_alert(data.msg) @@ -163,58 +182,6 @@ }); }) - /**获得导图*/ - 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 - } - // clear - $('main .container-fluid').empty() - - // 解析结果 - const results = resp.results - let idx = 0 - let row = $(`
`) - results.forEach(function (item) { - const content = ` -
-
-
${item.coop_mind_name}
- ... - 编辑 -
-
- ` - row.append(content) - idx++ - if (idx % 3 === 0) { - // 3个一行 - $('main .container-fluid').append(row) - // 重置row - row = $(`
`) - } - }) - - // 如果不是3的整数倍,将剩余的添加 - if (idx % 3 !== 0) { - $('main .container-fluid').append(row) - } - }, - async: false - }); - } /**新建导图*/ $('#new_mind_btn').click(function () { @@ -253,12 +220,68 @@ function logout_() { $.ajax({ type: "post", - url: "login", + url: "logout", headers: {"X-CSRFToken": $.cookie("csrftoken")}, - data: {'username': 'userName_login'}, + data: {'xx': 'xx'}, dataType: "json", success: function (data) { common_alert_(data.msg) + setTimeout(function () { + location.reload(); + }, 1000) + }, + 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 + } + // clear + $('main .container-fluid').empty() + + // 解析结果 + const results = resp.results + let idx = 0 + let row = $(`
`) + results.forEach(function (item) { + const content = ` +
+
+
${item.coop_mind_name}
+ ... + 编辑 +
+
+ ` + row.append(content) + idx++ + if (idx % 3 === 0) { + // 3个一行 + $('main .container-fluid').append(row) + // 重置row + row = $(`
`) + } + }) + + // 如果不是3的整数倍,将剩余的添加 + if (idx % 3 !== 0) { + $('main .container-fluid').append(row) + } }, async: false }); @@ -267,7 +290,7 @@ - +