From 6da857016e93de89ee6aadd7f1a866c1be27d874 Mon Sep 17 00:00:00 2001 From: aqu415 Date: Sun, 13 Feb 2022 19:20:25 +0800 Subject: [PATCH] update --- server/views.py | 21 +++---- static/html/detail.html | 122 ++++++--------------------------------- static/html/list.html | 2 +- static/js/jsmind.coop.js | 6 +- 4 files changed, 30 insertions(+), 121 deletions(-) diff --git a/server/views.py b/server/views.py index fe43101..eefe501 100644 --- a/server/views.py +++ b/server/views.py @@ -4,7 +4,7 @@ from django.shortcuts import render from rest_framework.generics import * from rest_framework.response import Response from rest_framework.views import APIView - +import json from server.filters import CooperationMindFilter from server.models import * from server.serializers import CooperationMindSerializer @@ -24,7 +24,8 @@ def to_detail(request): """ 详情页面 """ - return render(request, "html/detail.html") + param = {'id': request.GET.get('id')} + return render(request, "html/detail.html", param) class JsMindLogView(ListAPIView): @@ -38,18 +39,14 @@ class JsMindLogView(ListAPIView): pagination_class = NewPagination def get(self, request, *args, **kwargs): + pk = request.GET.get('id') + if pk is not None: + mind = CooperationMind.objects.filter(id=pk).first() + # 序列化 + serializer = CooperationMindSerializer(mind) + return build_response(data=serializer.data) return self.list(request, *args, **kwargs) - # def get(self, request): - # qs = self.filter_queryset(self.get_queryset()) - # page = self.paginate_queryset(qs) - # if page: - # serializer_obj = self.get_serializer(instance=page, many=True) - # return self.get_paginated_response({'code': 0, 'res': "success", 'msg': serializer_obj.data}) - # - # serializer_obj = self.get_serializer(instance=qs, many=True) - # return Response({'code': 0, 'res': "success", 'msg': serializer_obj.data}, ) - def post(self, request): """ 查询思维导图 diff --git a/static/html/detail.html b/static/html/detail.html index 45cfcae..dea5832 100644 --- a/static/html/detail.html +++ b/static/html/detail.html @@ -33,29 +33,13 @@ }, loadMind: function () { // 打开已有脑图1、查询数据,组装option 2、实例化jm、show - const mind_name = $('#mind_name').val() + let id = $('#mind_id').val() + id = {{ id }}; const me = this - if (mind_name) { - - $.get('jsmind_op', {'mind_name': mind_name, 'type': 'get_mind_by_name'}, function (resp) { - me.destory_coop_if_necessary() - - // todo 设置返回的 data_log_id - me.init_new_mind(mind_name, resp.msg.data) - - }) - } - }, - newMind: function () { - $('#jsmind_container').empty() - const name = this.randomNum(1, 2222) - $('#mind_name').val(name) - if (!name) { - alert('请输入名字') - } else { - this.destory_coop_if_necessary() - this.init_new_mind(name) - } + $.get('list?id=' + id, function (resp) { + let data = resp.data.snapshot_data + me.init_new_mind(resp.data.coop_mind_name, JSON.parse(data)) + }) }, // 清除定时任务等 destory_coop_if_necessary() { @@ -66,61 +50,11 @@ init_new_mind: function (name, data) { const mind = { /* 元数据,定义思维导图的名称、作者、版本等信息 */ - meta: { - name: name, - author: 'hizzgdev@163.com', - version: '0.2' - }, + meta: {name: name, author: 'hizzgdev@163.com', version: '0.2'}, /* 数据格式声明 */ format: 'node_tree', /* 数据内容 */ - data: { - id: 'root', - topic: 'jsMind', - children: [ - { - id: 'easy', - topic: 'Easy', - direction: 'left', - expanded: false, - children: [ - {id: 'easy1', topic: 'Easy to show'}, - {id: 'easy2', topic: 'Easy to edit'}, - {id: 'easy3', topic: 'Easy to store'}, - {id: 'easy4', topic: 'Easy to embed'} - ] - }, - { - id: 'open', - topic: 'Open Source', - direction: 'right', - expanded: true, - children: [ - {id: 'open1', topic: 'on GitHub'}, - {id: 'open2', topic: 'BSD License'} - ] - }, - { - id: 'powerful', - topic: 'Powerful', - direction: 'right', - children: [ - {id: 'powerful1', topic: 'Base on Javascript'}, - {id: 'powerful2', topic: 'Base on HTML5'}, - {id: 'powerful3', topic: 'Depends on you'} - ] - }, - { - id: 'other', - topic: 'test node', - direction: 'left', - children: [ - {id: 'other1', topic: "I'm from local variable"}, - {id: 'other2', topic: 'I can do everything'} - ] - } - ] - } + data: {id: 'root', topic: 'jsMind'} } const options = { @@ -131,34 +65,13 @@ menuOpts: { showMenu: true, injectionList: [ - { - target: 'edit', - text: '编辑节点' - }, - { - target: 'addChild', - text: '添加子节点' - }, - { - target: 'addBrother', - text: '添加兄弟节点' - }, - { - target: 'delete', - text: '删除节点' - }, - { - target: 'screenshot', - text: '下载导图' - }, - { - target: 'showAll', - text: '展开全部节点' - }, - { - target: 'hideAll', - text: '收起全部节点' - } + {target: 'edit', text: '编辑节点'}, + {target: 'addChild', text: '添加子节点'}, + {target: 'addBrother', text: '添加兄弟节点'}, + {target: 'delete', text: '删除节点'}, + {target: 'screenshot', text: '下载导图'}, + {target: 'showAll', text: '展开全部节点'}, + {target: 'hideAll', text: '收起全部节点'} ] } } @@ -172,14 +85,13 @@ } } const xxObj = new xx() + xxObj.loadMind()
+
- 导图名称: - -
diff --git a/static/html/list.html b/static/html/list.html index a0a15bb..5dd5402 100644 --- a/static/html/list.html +++ b/static/html/list.html @@ -70,7 +70,7 @@ ${item.create_time} ${item.update_time} - 编辑 + 编辑 复制分享 ` diff --git a/static/js/jsmind.coop.js b/static/js/jsmind.coop.js index eec4956..25c9f87 100644 --- a/static/js/jsmind.coop.js +++ b/static/js/jsmind.coop.js @@ -27,7 +27,7 @@ this.coop_mind_id = coop_mind_id // this.timerFetch() } - this.timerPush() + // this.timerPush() } } Jm.coop.prototype = { @@ -101,7 +101,7 @@ } // ajax const me = this - Jm.util.ajax.post(this.coop_api_url, param, function (resp) { + /*Jm.util.ajax.post(this.coop_api_url, param, function (resp) { if (type === 1) { // 新建 me.coop_mind_id = resp.coop_mind_id @@ -111,7 +111,7 @@ // 操作 me.coop_mind_log_id = resp.coop_mind_log_id } - }) + })*/ } }, /**