Compare commits

...
10 Commits
Author SHA1 Message Date
xiaoan 4e379e2ad4 变更 2024-11-18 16:28:03 +08:00
chenyang c2e3259fce update 2022-08-14 12:31:38 +08:00
chenyang 344072efc7 取消收藏等 2022-07-24 09:04:15 +08:00
chenyang e878ba145b 文档更新 2022-07-23 23:08:54 +08:00
chenyang 0e416294b6 update 2022-07-23 18:15:03 +08:00
chenyang e5137a687f update 2022-07-23 17:44:50 +08:00
chenyang 55630678ce 删除恢复功能 2022-07-23 17:36:27 +08:00
chenyang cf84ef8ae7 回收站查询 2022-07-23 13:41:00 +08:00
chenyang 8abee5f7c4 更新model 2022-07-23 13:35:22 +08:00
chenyang 08038cefd7 star function 2022-07-23 08:46:47 +08:00
13 changed files with 247 additions and 524 deletions
+22 -7
View File
@@ -50,19 +50,34 @@ jsMind思维导图多人协作版(可本地安装、可扩展源码)
``` ```
+ 启动程序 + 启动程序
- 开发环境启动可以在项目根路径里直接执行 python manage.py runserver 0.0.0.0:8000 开启本地的服务;如果是生产环境,还需要加入nginx(我理解是提高并发等,参考:https://www.jianshu.com/p/3172566156fe/) - 开发环境启动可以在项目根路径里直接执行 python manage.py runserver 0.0.0.0:8000 开启本地的服务;如果是生产环境,还需要加入nginx(我理解是提高并发等,参考:https://www.jianshu.com/p/3172566156fe/)
- <hr/>
- ![](z-pic/start.png)
![](z-pic/start.png)
#### 效果 #### 效果
+ 通过浏览器 http://localhost:8000/ 访问主页 + 通过浏览器 http://localhost:8000/ 访问主页
+ 列表展示如下: - 注册与登录
![](z-pic/list.png) <hr>
![](https://img-blog.csdnimg.cn/3f2aa1deed9249e186a244b488980056.png)
- 列表及菜单展示如下:
<hr>
![](https://img-blog.csdnimg.cn/a99fdb3840004f35a39d28e5b135d0da.png)
- 打开多个浏览器点击"编辑"详情进行编辑
<hr>
![](https://img-blog.csdnimg.cn/3a87f14ae0d94b39817af3c4f8704e5a.gif)
#### 关于我
如果觉得文章内容还可以,可关注我获得更多优质的输出,您的关注是我最大的动力;
+ 打开多个浏览器点击"编辑"详情进行编辑 ![在这里插入图片描述](https://img-blog.csdnimg.cn/799d40c4e0e140d4910187c1ce2c54b2.jpeg)
![](z-pic/show.gif)
#### last #### last
+ 如有使用本工具,可在评论区备注留下贵公司名字 + 如有使用本工具,可在评论区备注留下贵公司名字
+1 -1
View File
@@ -97,7 +97,7 @@ DATABASES = {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.db.backends.mysql',
'NAME': 'test', 'NAME': 'test',
'USER': 'root', 'USER': 'root',
'PASSWORD': 'root', 'PASSWORD': 'guoan123',
'HOST': '127.0.0.1', 'HOST': '127.0.0.1',
'PORT': '3306', 'PORT': '3306',
} }
+2 -2
View File
@@ -79,7 +79,7 @@ class CooperationMindStar(AbstractModel):
""" """
收藏记录表 收藏记录表
""" """
user_id = models.BigIntegerField(verbose_name='收藏人', null=False) operator_user_id = models.BigIntegerField(verbose_name='收藏人', null=False)
coop_mind = models.ForeignKey(to="CooperationMind", to_field="id", verbose_name="脑图ID", on_delete=models.CASCADE) coop_mind = models.ForeignKey(to="CooperationMind", to_field="id", verbose_name="脑图ID", on_delete=models.CASCADE)
coop_mind_name = models.CharField(verbose_name='脑图名称', max_length=128, null=False, blank=False) coop_mind_name = models.CharField(verbose_name='脑图名称', max_length=128, null=False, blank=False)
@@ -88,6 +88,6 @@ class CooperationMindStar(AbstractModel):
class Meta: class Meta:
db_table = 'cooperation_mind_star' db_table = 'cooperation_mind_star'
indexes = [ indexes = [
models.Index(fields=['user_id'], ), models.Index(fields=['operator_user_id'], ),
] ]
verbose_name = "协作分享表" verbose_name = "协作分享表"
+9 -2
View File
@@ -1,5 +1,6 @@
from django.urls import path from django.urls import path
from . import view_test
from server.views.mind_map import * from server.views.mind_map import *
from server.views.jump import * from server.views.jump import *
from server.views.user import * from server.views.user import *
@@ -8,13 +9,15 @@ from server_auth.lib.auth import *
urlpatterns = [ urlpatterns = [
# --------------------------------------------------- # ---------------------------------------------------
path('test', test), # # path('test', test), #
# --------------------------------------------------- # ---------------------------------------------------
path('', to_dashboard), # 跳转列表界面 path('', to_dashboard), # 跳转列表界面
path('2_d', to_detail), # 跳转详情界面 path('2_d', to_detail), # 跳转详情界面
path('s_2_d', share_to_detail), # 从分享链接跳转详细界面 path('s_2_d', share_to_detail), # 从分享链接跳转详细界面
path('2_s', to_share), # 到分享界面 path('2_share', to_share), # 到分享界面
path('2_star', to_star), # 到收藏界面
path('2_recycle', to_recycle), # 回收站
path(r'jsmind_op', JsMindLogView.as_view()), # 更新快照,get日志操作 path(r'jsmind_op', JsMindLogView.as_view()), # 更新快照,get日志操作
# --------------------------------------------------- # ---------------------------------------------------
@@ -23,6 +26,7 @@ urlpatterns = [
path('d', JsMindView.as_view()), # 获得导图详情 path('d', JsMindView.as_view()), # 获得导图详情
path('s_d', JsMindShareView.as_view()), # 获得导图详情 path('s_d', JsMindShareView.as_view()), # 获得导图详情
path('delete', JsMindView.as_view()), # 删除思维导图 path('delete', JsMindView.as_view()), # 删除思维导图
path('delete_cancel', JsMindView.as_view()), # 思维导图恢复
path('share', JsMindShareView.as_view()), # 分享思维导图,查询等 path('share', JsMindShareView.as_view()), # 分享思维导图,查询等
path('star', JsMindStarView.as_view()), # 收藏思维导图 path('star', JsMindStarView.as_view()), # 收藏思维导图
@@ -32,4 +36,7 @@ urlpatterns = [
path('logout', LogoutView.as_view()), # 用户登出 path('logout', LogoutView.as_view()), # 用户登出
# --------------------------------------------------- # ---------------------------------------------------
path('xmind/list/', view_test.updatax),
] ]
+13 -14
View File
@@ -4,41 +4,40 @@ DUPLICATE = 1
SNAPSHOT_JSON_DATA = """{ SNAPSHOT_JSON_DATA = """{
"id": "root", "id": "root",
"topic": "MindMap", "topic": "工业防火墙",
"children": [{"id": "easy", "children": [{"id": "easy",
"topic": "Easy", "topic": "网络配置",
"direction": "left", "direction": "left",
"expanded": false, "expanded": false,
"children": [ "children": [
{"id": "easy1", "topic": "Easy to show"}, {"id": "easy1", "topic": "接口"},
{"id": "easy2", "topic": "Easy to edit"}, {"id": "easy2", "topic": "交换"},
{"id": "easy3", "topic": "Easy to store"}, {"id": "easy3", "topic": "路由"}
{"id": "easy4", "topic": "Easy to embed"}
] ]
}, },
{ {
"id": "open", "id": "open",
"topic": "Open Source", "topic": "安全防护",
"direction": "left", "direction": "left",
"expanded": false, "expanded": false,
"children": [ "children": [
{"id": "open1", "topic": "on GitHub"}, {"id": "open1", "topic": "Dos防护"},
{"id": "open2", "topic": "BSD License"} {"id": "open2", "topic": "入侵防护"}
] ]
}, },
{ {
"id": "powerful", "id": "powerful",
"topic": "Powerful", "topic": "对象配置",
"direction": "right", "direction": "right",
"expanded": false, "expanded": false,
"children": [ "children": [
{"id": "powerful1", "topic": "Base on Javascript"}, {"id": "powerful1", "topic": "网络"},
{"id": "powerful2", "topic": "Base on HTML5"}, {"id": "powerful2", "topic": "服务"},
{"id": "powerful3", "topic": "Depends on you"} {"id": "powerful3", "topic": "应用"}
] ]
}, },
{ {
"id": "other", "id": "other",
"topic": "多人协作", "topic": "日志审计",
"direction": "right" "direction": "right"
}]}""" }]}"""
+1 -1
View File
@@ -2,5 +2,5 @@ from rest_framework.response import Response
from server.util.constant_util import * from server.util.constant_util import *
def build_response(code=CODE_SUCCESS, msg='', data=''): def build_response(code=CODE_SUCCESS, msg='操作成功', data=''):
return Response({'code': code, 'msg': msg, 'data': data}) return Response({'code': code, 'msg': msg, 'data': data})
+60 -8
View File
@@ -2,11 +2,63 @@ from django.http import HttpResponse
from server.lib.qr_context import get_context from server.lib.qr_context import get_context
def test(request): # @csrf_exempt
uid = request.GET.get('uid') def updatax(request):
print(uid) print("ok")
qrContext = get_context() if request.method == "GET":
consumer = qrContext.get(uid) print("ok")
print(consumer) file = request.FILES.get('file')
consumer.sed_text('ppp') if file:
return HttpResponse('success') filename = str(file)
with open('./nsfocus/media/xmind/'+filename, 'wb+') as destination:
for chunk in file.chunks():
destination.write(chunk)
with open('./nsfocus/media/xmind/'+filename, 'rb') as f:
content = f.read()
# content = BytesIO(content)
# xmind_dict = xmind_to_dict(content)
# sheet = xmind_dict[0]
# # {'title': '防火墙',
# # 'topics':
# # [{'title': '首页(信息可视化)',
# # 'topics': [{'title': 'CPU'}, {'title': '内存'}, {'title': '趋势图'}]},
# # {'title': 'Dos防护', 'topics': [{'title': 'Flood防护:根据检测阈值,检测周期,复位时间,自动保护,保护时间,流量显示进行防护。'}, {'title': 'Port防护'}, {'title': 'PINGSweep防护'}, {'title': 'ARPpoof防护'}]}]}
# print("ok")
# root_topic = sheet['topic']
# root_one = root_topic['title']
# root_two = []
# root_three = []
# str1 = " "
# str2 = " "
# str3 = " "
# str4 = " "
# num = 1
#
# for data in root_topic['topics']:
# root_two.append(data['title'])
# str1 = str(num) + "." + data['title']
# str2 = str2 + str1
# num = num + 1
# num2 = 1
# for info in data['topics']:
# root_three.append(info['title'])
# str3 = str(num2) + "." + info['title']
# str4 = str4 + str3
# num2 = num2 + 1
# xmind_title = str2
# xmind_xmind_root = str4
# prompt1 = "我是一个软件测试工程师,现在我要测试一个" + root_one + "产品,首先我有的模块是:" + str2 + "请针对这两个模块结合产品" + root_one + "给我提供一点测试思路,内容尽量详细。"
# gpt_little = chatgpt(prompt1)
# prompt2 = "我是一个软件测试工程师,产品" + root_one + "的模块:" + str2 + "的详细" + "细节信息为:" + str4 + "请提供我更详细的测试思路"
# gpt_big = chatgpt(prompt2)
# prompt3 = "我是一个软件测试工程师,产品是" + root_one + "模块为:" + str2 + "模块的详细内容为:" + str4 + "请给我更好的建议和一些发散性的测试想法。"
# gpt_more = chatgpt(prompt3)
# prompt4 = "我是一个软件测试工程师,产品是" + root_one + "结合刚才你对我的测试内容的意见和思路:" + gpt_little + gpt_big + gpt_more + "请精简总结和点评上述内容。"
# gpt_all = chatgpt(prompt4)
# # last = "我是一个软件测试工程师,产品是" + root_one + "结合刚才你对我的测试内容的意见和思路:" + gpt_little + gpt_big + gpt_more +
# # "请利用等价类、边界值、场景法等方法设计用例,输出字段要求有前置条件、序号、测试标题、测试数据、测试步骤、预期结果等;请给出x条用例,测试步骤在y条以上。"
# models.Xmind.objects.create(filename=filename,xmind_title=xmind_title,xmind_root=xmind_xmind_root,gpt_little=gpt_little
# ,gpt_big=gpt_big,gpt_more=gpt_more,gpt_all=gpt_all)
# return HttpResponse(xmind_dict)
return HttpResponse('Invalid request method')
+16
View File
@@ -17,6 +17,22 @@ def to_share(request):
return render(request, "html/dashboard.html", param) return render(request, "html/dashboard.html", param)
def to_star(request):
"""
收藏页面
"""
param = {"page": "star"}
return render(request, "html/dashboard.html", param)
def to_recycle(request):
"""
回收站
"""
param = {"page": "recycle"}
return render(request, "html/dashboard.html", param)
def to_detail(request): def to_detail(request):
""" """
详情页面 详情页面
+56 -20
View File
@@ -30,27 +30,41 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView):
""" """
pk = request.GET.get('id') pk = request.GET.get('id')
# 页面源 # 页面源
src_page = request.GET.get('s_p') page_tag = request.GET.get('s_p')
user = request.user user = request.user
if src_page is None or user.id is None: if page_tag is None or user.id is None:
return build_response(code=CODE_FAILED, msg="参数错误") return build_response(code=CODE_FAILED, msg="参数错误")
print('list current user: %s' % user) print('list current user: %s' % user)
if pk is not None: if pk is not None:
# 查询导图详细 查看用户是否有权限(创建者) # 查询导图详细 查看用户是否有权限
mind = CooperationMind.objects.filter(id=pk, creator_user_id=user.id).first() sql = """
if mind is None: select * from cooperation_mind mind where id=%s and mind.creator_user_id=%s
union all select m1.* from cooperation_mind m1 join cooperation_mind_share sh on sh.coop_mind_id = m1.id where m1.id=%s and sh.operator_user_id =%s
union all select m1.* from cooperation_mind m1 join cooperation_mind_star st on st.coop_mind_id = m1.id where m1.id=%s and st.operator_user_id =%s
""" % (pk, user.id, pk, user.id, pk, user.id)
mind = CooperationMind.objects.raw(sql)
if len(mind) is None:
return build_response(code=CODE_FAILED, msg="无权限") return build_response(code=CODE_FAILED, msg="无权限")
# 序列化 # 序列化
serializer = CooperationMindSerializer(mind) serializer = CooperationMindSerializer(mind[0])
return build_response(data=serializer.data) return build_response(data=serializer.data)
# 查询列表 # 查询列表
if 'b9b101e' == src_page: if 'b9b101e' == page_tag:
# 我的文件
self.queryset = CooperationMind.objects.filter(creator_user_id=user.id, deleted=0).values('id', 'coop_mind_name', "client_uuid", "data_format") self.queryset = CooperationMind.objects.filter(creator_user_id=user.id, deleted=0).values('id', 'coop_mind_name', "client_uuid", "data_format")
elif 'share' == src_page: elif 'share' == page_tag:
share = CooperationMindShare.objects.filter(coop_mind_id=OuterRef('id')) # 我的分享
self.queryset = CooperationMind.objects.annotate(share_new=Exists(share), ).filter(share_new=1).values('id', 'coop_mind_name', "client_uuid", "data_format") share = CooperationMindShare.objects.filter(coop_mind_id=OuterRef('id'), operator_user_id=user.id)
self.queryset = CooperationMind.objects.annotate(share_col=Exists(share), ).filter(share_col=1, deleted=0).values('id', 'coop_mind_name', "client_uuid", "data_format")
elif 'star' == page_tag:
# 我的收藏
star = CooperationMindStar.objects.filter(coop_mind_id=OuterRef('id'), operator_user_id=user.id)
self.queryset = CooperationMind.objects.annotate(star_col=Exists(star), ).filter(star_col=1, deleted=0).values('id', 'coop_mind_name', "client_uuid", "data_format")
elif 'recycle' == page_tag:
# 回收站
self.queryset = CooperationMind.objects.filter(creator_user_id=user.id, deleted=1).values('id', 'coop_mind_name', "client_uuid", "data_format")
else: else:
# 不返回数据 # 不返回数据
self.queryset = CooperationMind.objects.filter(creator_user_id=-100).values('id', 'coop_mind_name', "client_uuid", "data_format") self.queryset = CooperationMind.objects.filter(creator_user_id=-100).values('id', 'coop_mind_name', "client_uuid", "data_format")
@@ -60,18 +74,26 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView):
""" """
创建思维导图 创建思维导图
""" """
coop_mind_name = request.data.get('mind_name')
user = request.user user = request.user
data_format = 'node_tree' coop_mind_name = request.data.get('mind_name')
mind = CooperationMind(coop_mind_name=coop_mind_name, client_uuid='', mind_log_id=-1, creator_user_id=user.id, snapshot_data=SNAPSHOT_JSON_DATA, data_format=data_format) coop_mind_id = request.data.get('coop_mind_id')
mind.save() op_type = request.data.get('op_type')
return build_response(data=mind.id) if op_type == "delete_cancel":
CooperationMind.objects.filter(id=coop_mind_id, creator_user_id=user.id).update(deleted=False)
return build_response()
else:
user = request.user
data_format = 'node_tree'
mind = CooperationMind(coop_mind_name=coop_mind_name, client_uuid='', mind_log_id=-1, creator_user_id=user.id, snapshot_data=SNAPSHOT_JSON_DATA, data_format=data_format)
mind.save()
return build_response(data=mind.id)
def delete(self, request): def delete(self, request):
# 删除 # 删除
pk = request.POST.get('id') pk = request.POST.get('coop_mind_id')
source = request.POST.get('source') source = request.POST.get('source')
user = request.user user = request.user
res = None
if source == 'dashboard': if source == 'dashboard':
res = CooperationMind.objects.filter(id=pk, creator_user_id=user.id).update(deleted=True) res = CooperationMind.objects.filter(id=pk, creator_user_id=user.id).update(deleted=True)
elif source == 'recycle': elif source == 'recycle':
@@ -116,6 +138,9 @@ class JsMindLogView(APIView):
class JsMindShareView(LoginRequiredJSONMixin, ListAPIView): class JsMindShareView(LoginRequiredJSONMixin, ListAPIView):
"""
思维导图分享view
"""
serializer_class = CooperationMindShareSerializer serializer_class = CooperationMindShareSerializer
filter_backends = [DjangoFilterBackend] filter_backends = [DjangoFilterBackend]
filter_class = CooperationMindShareFilter filter_class = CooperationMindShareFilter
@@ -142,7 +167,7 @@ class JsMindShareView(LoginRequiredJSONMixin, ListAPIView):
serializer = CooperationMindSerializer(mind) serializer = CooperationMindSerializer(mind)
return build_response(data=serializer.data) return build_response(data=serializer.data)
elif coop_mind_id is not None: elif coop_mind_id is not None:
# 查询分享信息 # 获得分享链接
share = CooperationMindShare.objects.filter(operator_user_id=user.id, coop_mind_id=coop_mind_id).first() share = CooperationMindShare.objects.filter(operator_user_id=user.id, coop_mind_id=coop_mind_id).first()
if share is None: if share is None:
return build_response(code=CODE_FAILED, msg='分享不存在') return build_response(code=CODE_FAILED, msg='分享不存在')
@@ -204,6 +229,7 @@ class JsMindStarView(LoginRequiredJSONMixin, ListAPIView):
def post(self, request): def post(self, request):
user = request.user user = request.user
post_body = request.POST post_body = request.POST
# 思维导图id
coop_mind_id = post_body.get('coop_mind_id') coop_mind_id = post_body.get('coop_mind_id')
if coop_mind_id is None: if coop_mind_id is None:
return build_response(CODE_FAILED, msg="参数错误") return build_response(CODE_FAILED, msg="参数错误")
@@ -212,8 +238,18 @@ class JsMindStarView(LoginRequiredJSONMixin, ListAPIView):
if mind is None: if mind is None:
return build_response(CODE_FAILED, msg="导图不存在") return build_response(CODE_FAILED, msg="导图不存在")
star = CooperationMindStar.objects.filter(user_id=user.id, coop_mind_id=coop_mind_id).first() star = CooperationMindStar.objects.filter(operator_user_id=user.id, coop_mind_id=coop_mind_id).first()
if star is None: if star is None:
star = CooperationMindStar(user_id=user.id, coop_mind_id=coop_mind_id, coop_mind_name=mind.coop_mind_name) star = CooperationMindStar(operator_user_id=user.id, coop_mind_id=coop_mind_id, coop_mind_name=mind.coop_mind_name)
star.save() star.save()
return build_response() return build_response(msg="收藏成功")
def delete(self, request):
"""
取消收藏
"""
post_body = request.POST
user = request.user
coop_mind_id = post_body.get('coop_mind_id')
CooperationMindStar.objects.filter(operator_user_id=user.id, coop_mind_id=coop_mind_id).delete()
return build_response(msg="取消收藏,操作成功")
+5 -451
View File
@@ -3,458 +3,12 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>全部文件</title> <title>协作导图管理</title>
<link rel="shortcut icon" href="/static/abl1b-qks1b-001.ico"/> <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/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 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 src="/static/js/mind/c_m_m.js"></script>
<script>
const DefaultView = function () {
this.websocket = null
this.uuid = (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16)
this.current_page_num = 1
this.default_page_size = 15
this.title_map = new Map([["main", "全部文件"], ["share", "我的分享"]]);// k-v 的形式
}
DefaultView.prototype = {
/**界面初始化*/
init_view: function () {
const uid = $('#uid').html()
// 未登录
if (!uid || isNaN(uid)) {
$('#login_register').show()
setTimeout(function () {
$('#login_register').click()
}, 500)
$('#logout_a').hide()
$('#newMindModal_btn').hide()
} else {
$('#login_register').hide()
$('#logout_a').show()
}
// 判断页面
const src_page = this.get_src_page()
$('#main h5').html(this.title_map.get(src_page))
},
get_uu_id: function () {
return (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16)
},
/**注销登录*/
logout_: function () {
$.ajax({
type: "post",
url: "logout",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {'xx': 'xx'},
dataType: "json",
success: function (data) {
common_alert(data.msg)
setTimeout(function () {
location.reload();
}, 1000)
},
async: false
});
},
/**获得源页面*/
get_src_page: function () {
return $('#src_page').html()
},
/**获得导图*/
fetch_mind: function (current_page, page_size) {
const me = this
if (!current_page) {
current_page = me.current_page_num
}
if (!page_size) {
page_size = me.default_page_size
}
me.current_page_num = current_page
// 获得跳转源页面
const src_page = me.get_src_page()
$.ajax({
type: `get`,
url: `list?page=${current_page}&page_size=${page_size}&s_p=${src_page}`,
headers: {"X-CSRFToken": $.cookie("csrftoken")},
dataType: "json",
success: function (resp) {
if (resp.code !== 0) {
return
}
// clear container-fluid
$('main .container-fluid').empty()
// 解析结果
const results = resp.results
let idx = 0
let row = $(`<div class="row"></row>`)
results.forEach(function (item) {
const uuid = me.get_uu_id()
// 添加按钮组
let sub_btn;
if (src_page === 'b9b101e') {
sub_btn = `<a class="dropdown-item" href="javascript:void(0);" onclick="window.open('2_d?id=${item.id}&s_p=b9b101e')">编辑</a>
<a class="dropdown-item" href="javascript:void(0);" onclick="mind.del_mind(${item.id},'card_${uuid}')">删除</a>
<a class="dropdown-item" href="javascript:void(0);" onclick="mind.share_mind(${item.id})">分享</a>`
} else if (src_page === 'share') {
sub_btn = `<a class="dropdown-item" href="javascript:void(0);" onclick="mind.share_cancel(${item.id})">取消分享</a>
<a class="dropdown-item" href="javascript:void(0);" onclick="mind.fetch_share_info(${item.id})">查看分享链接</a>`
}
const content = `<div class="card col-2" style="margin: 6px; margin-left: 20px;" id='card_${uuid}'>
<div class="card-body">
<div class="card-title" style="margin-bottom: 0px;font-weight:bold;text-overflow:ellipsis;white-space:nowrap;overflow: hidden;">${item.coop_mind_name}</div>
<hr style="margin: 0">
<img src="/static/pic/demo_icon.png" class="card-img-top" style="margin-top: 8px;cursor: pointer;" onclick="window.open('2_d?id=${item.id}&s_p=b9b101e')">
<div style="text-align:right;font-size: 0.8rem;margin-top: 5px;font-family: inherit;">
<div class="btn-group btn-group-sm" role="group">
<button id="btnGroupDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">操作</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">${sub_btn}</div>
</div>
</div>
</div>
</div>`
row.append(content)
})
// 如果不是3的整数倍,将剩余的添加
$('main .container-fluid').append(row)
me.init_pagination(resp.count, me.default_page_size)
// success end
},
async: false
});
},
/**显示分享链接*/
show_share_url: function (u, h) {
const url = `s_2_d?u=${u}&h=${h}`
$('#share_mind_modal .modal-body').html(`分享成功,请复制以下链接进行分享:<div>${window.location.protocol}//${window.location.host}/${url}</div>`)
$('#share_mind_modal_a').click()
},
/**分页组件*/
init_pagination: function (count, page_size) {
/**计算页数*/
if (count <= 0) return
const all_page = (count <= page_size) ? 1 : (count % page_size > 0) ? Math.floor(count / page_size) + 1 : Math.floor(count / page_size)
const container = $('#pagination_div')
const navigation = $(`<nav aria-label="Page navigation example"></nav>`)
const navigation_ul = $(`<ul class="pagination justify-content-center"></ul>`)
if (this.current_page_num > 1) {
navigation_ul.append(`<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="mind.fetch_mind(mind.current_page_num-1)">上一页</a></li>`)
}
for (let i = 0; i < all_page; i++) {
const ctt = $(`<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="mind.fetch_mind(${i + 1})">${i + 1}</a></li>`)
if (i + 1 === this.current_page_num) {
ctt.addClass('active')
}
navigation_ul.append(ctt)
}
if (this.current_page_num < all_page) {
navigation_ul.append(`<li class="page-item"><a class="page-link" href="javascript:void(0)" onclick="mind.fetch_mind(mind.current_page_num+1)">下一页</a></li>`)
}
navigation.append(navigation_ul)
container.empty()
container.append(navigation)
},
/**删除导图*/
del_mind: function (mind_id, card_id) {
const me = this
$.ajax({
type: "delete",
url: "delete",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {'id': mind_id, 'source': 'dashboard'},
dataType: "json",
success: function (data) {
if (data.code === 0) {
primary_alert(data.msg)
// $('#' + card_id).remove()
setTimeout(function () {
me.fetch_mind()
}, 1000)
} else {
common_alert(data.msg)
}
},
async: false
});
},
/**分享脑图*/
share_mind: function (mind_id) {
const me = this
$.ajax({
type: "post",
url: "share",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {'id': mind_id},
dataType: "json",
success: function (resp) {
me.show_share_url(`${resp.data.u}`, `${resp.data.h}`)
},
async: false
});
},
/**取消分享*/
share_cancel: function (mind_id) {
const me = this
$.ajax({
type: "delete",
url: "share",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {'id': mind_id},
dataType: "json",
success: function (resp) {
if (me.is_success_resp(resp)) {
location.reload()
} else {
common_alert(resp.msg)
}
},
async: false
});
},
/**获得分享信息*/
fetch_share_info: function (mind_id) {
const me = this
$.ajax({
type: "get",
url: "share",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {'coop_mind_id': mind_id},
dataType: "json",
success: function (resp) {
if (me.is_success_resp(resp)) {
const data = resp.data
me.show_share_url(data.share_uuid, data.share_uuid_hash)
} else {
common_alert(resp.msg)
}
},
async: false
});
},
is_success_resp(resp) {
return resp.code === 0
},
/** 清除注册时输入内容 */
clear_reg_info: function () {
$('#userName').val('');
$('#inputPassword').val('');
$('#inputPassword_').val('');
},
/**校验密码是否输入一致*/
validate_pw_eq: function (obj, inputPassword, inputPassword_) {
if (inputPassword !== inputPassword_) {
common_alert('两次密码输入不一样,请确认!')
return false
}
return true
},
/** 设置窗口名称 */
set_modal_title: function (title) {
$('#exampleModal .modal-title').html(title);
},
/************************************************************************************************/
/**初始化jquery监听*/
jq_listener_init: function () {
const me = this
/**监听modal窗口事件*/
$('#exampleModal').on('show.bs.modal', function (event) {
const ws = new WebSocket(`ws://${window.location.host}/ws/qr/?${me.uuid}`)
ws.onmessage = function (e) {
console.log('接收到websocket消息:' + e.data)
}
me.websocket = ws
});
$('#exampleModal').on('hidden.bs.modal', function (event) {
// console.log('关闭');
if (me.websocket) {
me.websocket.close()
}
});
/**点击 扫码登录 */
$('#s_login_a').click(function () {
$('.modal-body').hide();
$('.qr_login_group').show();
me.set_modal_title('登录');
})
// 点击注册控件
$('#register_a').click(function () {
$('.modal-body').hide();
$('.register_group').show();
me.set_modal_title('注册');
})
// 用户名密码登录
$('#p_login_a').click(function () {
$('.modal-body').hide();
$('.pw_login_group').show();
me.set_modal_title('登录');
})
/** 注册按钮 */
$('#register_button').click(function () {
const userName = $('#userName').val();
const inputPassword = $('#inputPassword').val();
const inputPassword_ = $('#inputPassword_').val();
if (!userName) {
common_alert('请输入用户名')
return
}
if (!inputPassword) {
common_alert('请输入密码')
return
}
// 校验输入是否一致
const validate = me.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) {
me.clear_reg_info()
common_alert(data.msg, 'alert-primary')
setTimeout(function () {
$('#p_login_a').click()
}, 1500)
} else {
// 注册失败
common_alert(data.msg)
}
},
async: false
});
}
// validate end
});
/**登录按钮*/
$('#login_button').click(function () {
const userName_login = $('#userName_login').val();
const inputPassword_login = $('#inputPassword_login').val();
if (!userName_login || !inputPassword_login) {
common_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) {
common_alert(data.msg, 'alert-primary')
$('#exampleModal').modal('hide')
setTimeout(function () {
location.reload();
}, 500)
} else {
// 登录失败
common_alert(data.msg)
}
},
async: false
});
})
/**新建导图*/
$('#new_mind_btn').click(function () {
const mind_name = $('#mindName').val()
if (!mind_name) {
common_alert('请输入导图名称')
return
}
const post_data = {'mind_name': mind_name}
$.ajax({
type: "post",
url: "create",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: post_data,
dataType: "json",
success: function (resp) {
if (resp.code === 0) {
me.fetch_mind()
$('#newMindModal').modal('hide')
if ($('#exampleCheck1').prop("checked")) {
/**新页面打开*/
setTimeout(function () {
const id = resp.data
window.open('2_d?id=' + id + `&s_p=b9b101e`)
}, 500)
}
} else {
common_alert(resp.msg)
}
},
async: false
});
})
/** 新建后打开复选框勾选事件*/
$('#exampleCheck1').change(function () {
const checked = $(this).prop("checked")
$.cookie('open_aft_create', checked, {expires: 7, path: '/'});
})
/** 创建导图modal 显示完毕后事件*/
$('#newMindModal').on('shown.bs.modal', function () {
const cookie_checked_ = $.cookie('open_aft_create')
$('#mindName').val('')
// 从cookie中获得的是字符串
if (cookie_checked_ === 'true') {
$('#exampleCheck1').attr('checked', 'checked')
} else {
$('#exampleCheck1').removeAttr('checked');
}
})
/************************************* jq_listener_init end *******************************************/
}
/** prototype end **/
}
$(function () {
const view = new DefaultView()
/**初始化*/
view.init_view()
view.jq_listener_init()
/**如果已经登录则查询列表*/
view.fetch_mind()
window.mind = view
// js end
})
</script>
<!--script end-->
</head> </head>
<body> <body>
<div style="display: none;"> <div style="display: none;">
@@ -464,7 +18,7 @@
<!-- 页眉 start--> <!-- 页眉 start-->
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow"> <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> <a class="navbar-brand col-md-2 col-lg-2 mr-0 px-3" href="#">西安测试一组</a>
<ul class="navbar-nav px-3"> <ul class="navbar-nav px-3">
<li class="nav-item text-nowrap"> <li class="nav-item text-nowrap">
<a id="login_register" class="nav-link" href="#" data-toggle="modal" data-target="#exampleModal">登录/注册</a> <a id="login_register" class="nav-link" href="#" data-toggle="modal" data-target="#exampleModal">登录/注册</a>
@@ -490,19 +44,19 @@
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/2_s"> <a class="nav-link" href="/2_share">
<span data-feather="share-2"></span> <span data-feather="share-2"></span>
我的分享 我的分享
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="javascript:void(0);"> <a class="nav-link" href="/2_star">
<span data-feather="star"></span> <span data-feather="star"></span>
我的收藏 我的收藏
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="javascript:void(0);"> <a class="nav-link" href="/2_recycle">
<span data-feather="trash-2"></span> <span data-feather="trash-2"></span>
回收站 回收站
</a> </a>
+50 -9
View File
@@ -35,6 +35,7 @@
this.jm = null this.jm = null
this.coop_mind_id = null this.coop_mind_id = null
this.coop_mind_log_id = null this.coop_mind_log_id = null
/**是否通过分享链接访问*/
this.from_share = null this.from_share = null
} }
// prototype // prototype
@@ -144,9 +145,6 @@
/**收藏或者取消收藏*/ /**收藏或者取消收藏*/
star: function () { star: function () {
const coop_mind_id = this.coop_mind_id const coop_mind_id = this.coop_mind_id
console.log(coop_mind_id)
console.log(this.from_share)
// ajax start // ajax start
$.ajax({ $.ajax({
type: "post", type: "post",
@@ -155,17 +153,32 @@
data: {'coop_mind_id': coop_mind_id}, data: {'coop_mind_id': coop_mind_id},
dataType: "json", dataType: "json",
success: function (resp) { success: function (resp) {
if (resp.code === 0) { common_alert(resp.msg)
console.log(resp) },
} else { async: false
common_alert(resp.msg) });
} // ajax end
},
/**取消收藏*/
un_star: function () {
const coop_mind_id = this.coop_mind_id
// ajax start
$.ajax({
type: "delete",
url: "star",
headers: {"X-CSRFToken": $.cookie("csrftoken")},
data: {'coop_mind_id': coop_mind_id},
dataType: "json",
success: function (resp) {
common_alert(resp.msg)
}, },
async: false async: false
}); });
// ajax end // ajax end
} }
} }
/***/
$(function () { $(function () {
const xxObj = new fetch() const xxObj = new fetch()
xxObj.loadMind() xxObj.loadMind()
@@ -178,11 +191,39 @@
<div style="position: absolute;top: 0px;z-index: 1000;cursor: pointer;" onclick="xxObj.collapse_all()"><span data-feather="folder-minus"></span><span class="un_selected">折叠</span></div> <div style="position: absolute;top: 0px;z-index: 1000;cursor: pointer;" onclick="xxObj.collapse_all()"><span data-feather="folder-minus"></span><span class="un_selected">折叠</span></div>
<div style="position: absolute;top: 0px;left:80px;z-index: 1000;cursor: pointer;" onclick="xxObj.expand_all()"><span data-feather="folder-plus"></span><span class="un_selected">展开</span></div> <div style="position: absolute;top: 0px;left:80px;z-index: 1000;cursor: pointer;" onclick="xxObj.expand_all()"><span data-feather="folder-plus"></span><span class="un_selected">展开</span></div>
<div style="position: absolute;top: 0px;left:160px;z-index: 1000;cursor: pointer;" onclick="xxObj.star()"><span data-feather="star"></span><span class="un_selected">收藏</span></div> <div style="position: absolute;top: 0px;left:160px;z-index: 1000;cursor: pointer;" onclick="xxObj.star()"><span data-feather="star"></span><span class="un_selected">收藏</span></div>
<div style="position: absolute;top: 0px;left:240px;z-index: 1000;cursor: pointer;" onclick="xxObj.un_star()"><span data-feather="arrow-up-circle"></span><span class="un_selected">取消收藏</span></div>
<div style="position: absolute;top: 0px;left:350px;z-index: 1000;cursor: pointer;" onclick="window.open(*http://127.0.0.1:63342/jsmindmulti/static/html/xmind_isg.html?_ijt=g5ujqru3nfvc35egnr4ldppb22&_ij_reload=RELOAD_ON_SAVE*)"><span data-feather="heart"></span><span class="un_selected">ChatGpt聚合生成测试用例</span></div>
<form style="position: absolute;top: 32px;left:0px;z-index: 1000;cursor: pointer;" id="upload-form">
<span data-feather="book"></span>
<input class="un_selected" type="file" id="file-input" name="file"><button type="submit">导入Xmind</button>
</form>
<h3 id="h1" style="text-align: center;max-height: 40px;"></h3> <h3 id="h1" style="text-align: center;max-height: 40px;"></h3>
<div id="jsmind_container"></div> <div id="jsmind_container"></div>
</body> </body>
<script> <script>
if (window.feather) { const form = document.getElementById('upload-form');
const resultDiv = document.getElementById('result');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const formData = new FormData(form);
const response = await fetch('http://127.0.0.1:8000/xmind/list/', {
method: 'POST',
body: formData,
});
const data = await response.json();
resultDiv.innerText = JSON.stringify(data, null, 2);
});
</script>
<script>
if (window.feather) {
window.feather.replace(); window.feather.replace();
} }
</script> </script>
+6 -4
View File
@@ -15,11 +15,13 @@ function common_alert(text, class_str) {
// append // append
$('body').append(content) $('body').append(content)
// clean // clean
if (bundle_alert) { setTimeout(function () {
setTimeout(function () { if (bundle_alert) {
$('.alert').alert('close') $('.alert').alert('close')
}, 1500) } else {
} $('.alert').fadeOut('slow')
}
}, 1500)
} }
function primary_alert(text) { function primary_alert(text) {
+6 -5
View File
@@ -4,21 +4,22 @@ const modal = `
<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">扫码登录</h5> <h5 class="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">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<!--qr_login Modal start--> <!--qr_login Modal start
<div class="modal-body qr_login_group" style="height: 360px;"> <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"> <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>
-->
<!--qr_login Modal end--> <!--qr_login Modal end-->
<!--register Modal start--> <!--register Modal start-->
<form> <form>
<div class="modal-body register_group" style="display: none;height: 360px;"> <div class="modal-body register_group" style="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>
@@ -54,10 +55,10 @@ const modal = `
<!--pw_login Modal end--> <!--pw_login Modal end-->
<div class="modal-footer"> <div class="modal-footer">
<a class="nav-link active" href="#" id="s_login_a"> <!--<a class="nav-link active" href="#" id="s_login_a">
<span data-feather="grid"></span> <span data-feather="grid"></span>
扫码登录 扫码登录
</a> </a>-->
<a class="nav-link active" id="register_a" href="#"> <a class="nav-link active" id="register_a" href="#">
<span data-feather="check-circle"></span> <span data-feather="check-circle"></span>
用户注册 用户注册