menu.py 12.2 KB
Newer Older
1 2 3 4 5 6 7 8
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-28 17:16:06
LastEditors: your name
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\views\menu.py
'''
9 10 11
#!/usr/bin/env python
# -*- coding: utf_8 -*-

12
import traceback
wanli's avatar
wanli committed
13 14 15
from flask import current_app, jsonify, request
from flask_restful import Resource
from flask_restful.reqparse import RequestParser
16
from flask_jwt_extended import ( jwt_required, get_jwt_identity )
wanli's avatar
wanli committed
17 18 19 20
from application.signal_manager import signalManager
from webcreator.log import logger
from webcreator.response import ResponseCode, response_result

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
class MenuList(Resource):
    def __init__(self):
        pass
        # 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
        self.parser = RequestParser()

    def get(self):
        # 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
        # self.parser.add_argument("page", type=int, location="args", default=1)
        # self.parser.add_argument("pageSize", type=int, location="args", default=15)
        # args = self.parser.parse_args()
        result = [
            {
                "id": "1044886626813353984",
                "parentId": "0",
                "name": "dashboard",
                "path": "/dashboard",
                "icon": "dashboard",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "analysis",
                        "path": "/dashboard/analysis",
                        "leaf": True,
                        "children": []
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "workplace",
                        "path": "/dashboard/workplace",
                        "leaf": True,
                        "children": []
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "parentId": "0",
                "name": "system",
                "path": "/system",
                "icon": "setting",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "setting",
                        "path": "/system/setting",
                        "leaf": False,
                        "children": [
                            {
                                "id": "1044886630026190848",
                                "parentId": "1044886629921333248",
                                "name": "menu",
                                "path": "/system/setting/menu",
                                "leaf": True,
                                "children": []
                            },
                            {
                                "id": "1044886630122659840",
                                "parentId": "1044886629921333248",
                                "name": "module",
                                "path": "/system/setting/module",
                                "leaf": True,
                                "children": []
                            },
                            {
                                "id": "1044886630122659841",
                                "parentId": "1044886629921333248",
                                "name": "file-manager",
                                "path": "/system/setting/file-manager",
                                "leaf": True,
                                "children": []
                            }
                        ]
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "role",
                        "path": "/system/role",
                        "leaf": True
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "admin",
                        "path": "/system/admin",
                        "leaf": True
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "icon": "shop",
                "parentId": "0",
                "name": "application",
                "path": "/application",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "index",
                        "path": "/application/index",
                        "leaf": True,
                        "children": []
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "manager",
                        "path": "/application/manager",
                        "leaf": True,
                        "children": []
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "icon": "usb",
                "parentId": "0",
                "name": "device",
                "path": "/device",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "index",
                        "path": "/device/index",
                        "leaf": True,
                        "children": []
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "icon": "tool",
                "parentId": "0",
                "name": "tools",
                "path": "/tools",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "monitor",
                        "path": "/tools/monitor",
                        "leaf": True,
                        "children": []
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "index",
                        "path": "/tools/index",
                        "leaf": True,
                        "children": []
                    }
                ]
            }
        ]
wanli's avatar
wanli committed
187 188
        
        signalManager.actionTreelist.emit()
189

wanli's avatar
wanli committed
190
        return response_result(ResponseCode.HTTP_SUCCESS, data=result)
191

wanli's avatar
wanli committed
192
    @jwt_required(locations=["headers"])
193
    def post(self):
wanli's avatar
wanli committed
194 195 196 197 198
        self.parser.add_argument("icon", type=str, location="json", required=True)
        self.parser.add_argument("path", type=str, location="json", required=True)
        self.parser.add_argument("name", type=str, location="json", required=True)
        args = self.parser.parse_args()

199 200
        try:
            json_payload = request.json
wanli's avatar
wanli committed
201
            print("--------------------->>>>", args)
202
            logger.warn(json_payload)
wanli's avatar
wanli committed
203 204 205
            result = signalManager.actionMenuCreate.emit(json_payload, jwt=get_jwt_identity())
            print("=====================>>>>", result)
            return response_result(ResponseCode.HTTP_SUCCESS)
206 207 208 209 210
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)


211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
class Batch(Resource):
    def __init__(self):
        self.parser = RequestParser()
        
    def post(self):
        self.parser.add_argument("ids", type=str, location="args", required=True)
        args = self.parser.parse_args()

        try:
            print("========>", args)
            result, message = signalManager.actionMenuBatch.emit(args)
            return response_result(message, data=result)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)

class UpdateSort(Resource):
    def __init__(self):
        self.parser = RequestParser()
        
    def post(self):
        self.parser.add_argument("id", type=int, location="json", required=True)
        self.parser.add_argument("direction", type=str, choices=["top", "bottom"], location="json", required=True)
        args = self.parser.parse_args()

        try:
            print("========>", args)
            result, message = signalManager.actionUpdateSort.emit(args)
            return response_result(message, data=result)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)

class Create(Resource):
    def __init__(self):
        self.parser = RequestParser()
        
    def post(self):
        self.parser.add_argument("parentId", type=int, location="json", default=None, required=False)
        self.parser.add_argument("icon", type=str, location="json", required=True)
        self.parser.add_argument("path", type=str, location="json", required=True)
        self.parser.add_argument("name", type=str, location="json", required=True)
        self.parser.add_argument("remarks", type=str, location="json", required=True)
        args = self.parser.parse_args()

        try:
            print("========>", args)
258
            result, message = signalManager.actionMenuCreate.emit(args, jwt={ "uuid": "551EDA6E032F16FE000847ABA4048B56" })
259 260 261 262 263
            return response_result(message, data=result)
        except Exception as e:
            # traceback.print_exc()
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)
wanli's avatar
wanli committed
264

265
class Treelist(Resource):
wanli's avatar
wanli committed
266 267
    def __init__(self):
        self.parser = RequestParser()
268 269 270 271 272
        
    def post(self):
        self.parser.add_argument("page", type=int, location="args", default=1, required=False)
        self.parser.add_argument("pageSize", type=int, location="args", default=10, required=False)
        args = self.parser.parse_args()
wanli's avatar
wanli committed
273

274 275 276 277 278 279 280
        try:
            print("========>", args)
            result, message = signalManager.actionTreelist.emit(args)
            return response_result(message, data=result)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)
wanli's avatar
wanli committed
281

282 283 284 285 286 287 288 289
class Treenodes(Resource):
    def __init__(self):
        self.parser = RequestParser()
        
    def get(self):
        self.parser.add_argument("page", type=int, location="args", default=1, required=False)
        self.parser.add_argument("pageSize", type=int, location="args", default=10, required=False)
        args = self.parser.parse_args()
290 291

        try:
292 293 294
            print("========>", args)
            result, message = signalManager.actionTreenodes.emit(args)
            return response_result(message, data=result)
295 296 297 298
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)

299
class Updatebyid(Resource):
wanli's avatar
wanli committed
300
    def __init__(self):
301 302 303 304 305 306 307 308 309
        self.parser = RequestParser()
        
    def post(self):
        self.parser.add_argument("icon", type=str, location="json", default=None, required=False)
        self.parser.add_argument("name", type=str, location="json", default=None, required=False)
        self.parser.add_argument("parentId", type=int, location="json", default=None, required=False)
        self.parser.add_argument("path", type=str, location="json", default=None, required=False)
        self.parser.add_argument("remark", type=str, location="json", default=None, required=False)
        args = self.parser.parse_args()
wanli's avatar
wanli committed
310 311

        try:
312 313 314
            print("========>", args)
            result, message = signalManager.actionUpdatebyid.emit(args)
            return response_result(message, data=result)
wanli's avatar
wanli committed
315 316 317
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)
318