update
This commit is contained in:
@@ -2,6 +2,8 @@ from asgiref.sync import async_to_sync
|
|||||||
from channels.generic.websocket import WebsocketConsumer
|
from channels.generic.websocket import WebsocketConsumer
|
||||||
from server.lib.coope_mind_lib import CooperationMindLogLib
|
from server.lib.coope_mind_lib import CooperationMindLogLib
|
||||||
import json
|
import json
|
||||||
|
from server.websocket.qrContext import QrContext
|
||||||
|
from server.websocket.qrContext import get_context
|
||||||
|
|
||||||
|
|
||||||
class ChatConsumer(WebsocketConsumer):
|
class ChatConsumer(WebsocketConsumer):
|
||||||
@@ -46,6 +48,10 @@ class ChatConsumer(WebsocketConsumer):
|
|||||||
self.send(text_data=message)
|
self.send(text_data=message)
|
||||||
|
|
||||||
|
|
||||||
|
# 获得一个环境变量
|
||||||
|
qrContext = get_context()
|
||||||
|
|
||||||
|
|
||||||
class QrConsumer(WebsocketConsumer):
|
class QrConsumer(WebsocketConsumer):
|
||||||
"""
|
"""
|
||||||
扫码进度websocket
|
扫码进度websocket
|
||||||
@@ -61,6 +67,7 @@ class QrConsumer(WebsocketConsumer):
|
|||||||
self.channel_name
|
self.channel_name
|
||||||
)
|
)
|
||||||
self.accept()
|
self.accept()
|
||||||
|
qrContext.add(self.channel_name, self)
|
||||||
|
|
||||||
def disconnect(self, close_code):
|
def disconnect(self, close_code):
|
||||||
# Leave room group
|
# Leave room group
|
||||||
@@ -68,6 +75,8 @@ class QrConsumer(WebsocketConsumer):
|
|||||||
self.room_group_name,
|
self.room_group_name,
|
||||||
self.channel_name
|
self.channel_name
|
||||||
)
|
)
|
||||||
|
qrContext.remove(self.channel_name)
|
||||||
|
print('close')
|
||||||
|
|
||||||
# Receive message from WebSocket
|
# Receive message from WebSocket
|
||||||
def receive(self, text_data):
|
def receive(self, text_data):
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
def get_context():
|
||||||
|
if QrContext.instance is None:
|
||||||
|
QrContext.instance = QrContext()
|
||||||
|
return QrContext.instance
|
||||||
|
|
||||||
|
|
||||||
|
class QrContext():
|
||||||
|
instance = None
|
||||||
|
all_obj = {}
|
||||||
|
|
||||||
|
def get(self, key):
|
||||||
|
return self.all_obj.get(key)
|
||||||
|
|
||||||
|
def add(self, key, v):
|
||||||
|
self.all_obj.update({key: v})
|
||||||
|
|
||||||
|
def remove(self, key):
|
||||||
|
del self.all_obj[key]
|
||||||
@@ -12,16 +12,6 @@ body {
|
|||||||
* Sidebar
|
* Sidebar
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.sidebar {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
z-index: 100; /* Behind the navbar */
|
|
||||||
padding: 48px 0 0; /* Height of navbar */
|
|
||||||
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 767.98px) {
|
@media (max-width: 767.98px) {
|
||||||
.sidebar {
|
.sidebar {
|
||||||
top: 5rem;
|
top: 5rem;
|
||||||
|
|||||||
@@ -24,10 +24,13 @@
|
|||||||
$('#exampleModal').on('show.bs.modal', function (event) {
|
$('#exampleModal').on('show.bs.modal', function (event) {
|
||||||
console.log(qr_websocket)
|
console.log(qr_websocket)
|
||||||
console.log('打开');
|
console.log('打开');
|
||||||
|
const ws = new WebSocket(`ws://${window.location.host}/ws/qr/?${qr_websocket.uuid}`)
|
||||||
|
qr_websocket.websocket = ws
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#exampleModal').on('hidden.bs.modal', function (event) {
|
$('#exampleModal').on('hidden.bs.modal', function (event) {
|
||||||
console.log('关闭');
|
console.log('关闭');
|
||||||
|
qr_websocket.websocket.close()
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -40,12 +43,12 @@
|
|||||||
<div class="modal-dialog modal-dialog-centered">
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
<div>微信扫码登录</div>
|
||||||
<img src="https://img0.baidu.com/it/u=3881180510,1470858589&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" height="300px">
|
<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>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|||||||
Reference in New Issue
Block a user