├── .idea ├── .gitignore ├── dbnavigator.xml ├── django_vue_rbac.iml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── README.md ├── django_vue_admin ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── __init__.cpython-37.pyc │ ├── __init__.cpython-38.pyc │ ├── settings.cpython-36.pyc │ ├── settings.cpython-37.pyc │ ├── settings.cpython-38.pyc │ ├── urls.cpython-36.pyc │ ├── urls.cpython-37.pyc │ ├── urls.cpython-38.pyc │ ├── wsgi.cpython-36.pyc │ ├── wsgi.cpython-37.pyc │ └── wsgi.cpython-38.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── manage.py ├── rbac ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── __init__.cpython-37.pyc │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-36.pyc │ ├── admin.cpython-37.pyc │ ├── admin.cpython-38.pyc │ ├── auth.cpython-36.pyc │ ├── auth.cpython-37.pyc │ ├── auth.cpython-38.pyc │ ├── models.cpython-36.pyc │ ├── models.cpython-37.pyc │ ├── models.cpython-38.pyc │ ├── permissions.cpython-37.pyc │ ├── permissions.cpython-38.pyc │ ├── serializers.cpython-36.pyc │ ├── serializers.cpython-37.pyc │ ├── serializers.cpython-38.pyc │ ├── urls.cpython-36.pyc │ ├── urls.cpython-37.pyc │ ├── urls.cpython-38.pyc │ ├── utils.cpython-36.pyc │ ├── utils.cpython-37.pyc │ ├── utils.cpython-38.pyc │ ├── views.cpython-36.pyc │ ├── views.cpython-37.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── auth.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-37.pyc │ │ ├── __init__.cpython-36.pyc │ │ ├── __init__.cpython-37.pyc │ │ └── __init__.cpython-38.pyc ├── models.py ├── permissions.py ├── serializers.py ├── tests.py ├── urls.py ├── utils.py └── views.py ├── requirements.txt ├── test.sql └── vue_admin ├── .babelrc ├── .editorconfig ├── .gitignore ├── .postcssrc.js ├── README.md ├── build ├── build.js ├── check-versions.js ├── logo.png ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js └── webpack.prod.conf.js ├── config ├── dev.env.js ├── index.js └── prod.env.js ├── index.html ├── package-lock.json ├── package.json ├── src ├── App.vue ├── api │ ├── menu.js │ ├── permission.js │ ├── role.js │ └── user.js ├── assets │ ├── css │ │ └── base.css │ ├── fonts │ │ └── font_2361663_kv0jeqzw1y │ │ │ ├── demo.css │ │ │ ├── demo_index.html │ │ │ ├── iconfont.css │ │ │ ├── iconfont.eot │ │ │ ├── iconfont.js │ │ │ ├── iconfont.json │ │ │ ├── iconfont.svg │ │ │ ├── iconfont.ttf │ │ │ ├── iconfont.woff │ │ │ └── iconfont.woff2 │ └── img │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ └── 6.png ├── components │ ├── 404 │ │ └── 404.vue │ ├── custom │ │ └── Mybread.vue │ ├── index │ │ └── index.vue │ ├── login │ │ └── login.vue │ ├── permission │ │ ├── menu.vue │ │ ├── permissions.vue │ │ └── roles.vue │ └── users │ │ └── users.vue ├── main.js ├── plugins │ ├── http.js │ └── user.js ├── router │ └── index.js ├── session │ └── index.js ├── store │ └── index.js └── utils │ └── index.js └── static └── .gitkeep /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | /rbac/migrations/ 5 | -------------------------------------------------------------------------------- /.idea/dbnavigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 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 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 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 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | -------------------------------------------------------------------------------- /.idea/django_vue_rbac.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

RBAC权限管理系统

2 | 3 | #### 项目简介 4 | 一个基于 Django、Django REST framework(DRF)、Vue的前后端分离的后台管理系统,前后台均做了权限校验,**可精确到按钮级权限**,可轻松添加业务页面及功能. 5 | 6 | #### 技术栈 7 | 8 | 前端:Vue + Vue-Router + Vuex + Element-Ui 9 | 后台:Django+Django-drf+JWT 10 | 数据库:Mysql 11 | 12 | #### 系统预览 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | #### 特别鸣谢 33 | - 感谢 [JetBrains](https://www.jetbrains.com/) 提供的非商业开源软件开发授权 34 | - 感谢 [Django](https://github.com/django/django) 提供后端Django框架 35 | - 感谢 [DRF](https://github.com/encode/django-rest-framework) 提供后端DRF框架 36 | - 感谢 [Elemnt UI](https://element.eleme.cn/#/zh-CN) 提供的页面布局及前端模板 37 | -------------------------------------------------------------------------------- /django_vue_admin/__init__.py: -------------------------------------------------------------------------------- 1 | import pymysql 2 | pymysql.version_info = (1, 4, 13, "final", 0) 3 | pymysql.install_as_MySQLdb() -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/settings.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/settings.cpython-36.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/wsgi.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/wsgi.cpython-36.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/wsgi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/wsgi.cpython-37.pyc -------------------------------------------------------------------------------- /django_vue_admin/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/django_vue_admin/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /django_vue_admin/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for django_vue_admin project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_vue_admin.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /django_vue_admin/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for django_vue_admin project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.6. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = ')+k1c9ah6jo*k7jjx1&pnpjak320-u(%ds+^)o_@0wgb1b(p@v' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = ['*'] 29 | 30 | #跨域增加忽略 31 | CORS_ALLOW_CREDENTIALS = True 32 | CORS_ORIGIN_ALLOW_ALL = True 33 | # CORS_ORIGIN_WHITELIST = [('*')] 34 | 35 | CORS_ALLOW_METHODS = ( 36 | 'DELETE', 37 | 'GET', 38 | 'OPTIONS', 39 | 'PATCH', 40 | 'POST', 41 | 'PUT', 42 | 'VIEW', 43 | ) 44 | 45 | CORS_ALLOW_HEADERS = ( 46 | 'XMLHttpRequest', 47 | 'X_FILENAME', 48 | 'accept-encoding', 49 | 'authorization', 50 | 'content-type', 51 | 'dnt', 52 | 'origin', 53 | 'user-agent', 54 | 'x-csrftoken', 55 | 'x-requested-with', 56 | 'Pragma', 57 | 'token' 58 | ) 59 | 60 | # Application definition 61 | 62 | INSTALLED_APPS = [ 63 | 'django.contrib.admin', 64 | 'django.contrib.auth', 65 | 'django.contrib.contenttypes', 66 | 'django.contrib.sessions', 67 | 'django.contrib.messages', 68 | 'django.contrib.staticfiles', 69 | 'corsheaders', 70 | 'rest_framework', 71 | 'rbac', 72 | ] 73 | 74 | MIDDLEWARE = [ 75 | 'django.middleware.security.SecurityMiddleware', 76 | 'corsheaders.middleware.CorsMiddleware', 77 | 'django.contrib.sessions.middleware.SessionMiddleware', 78 | 79 | 'django.middleware.common.CommonMiddleware', 80 | # 'django.middleware.csrf.CsrfViewMiddleware', 81 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 82 | 'django.contrib.messages.middleware.MessageMiddleware', 83 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 84 | ] 85 | 86 | ROOT_URLCONF = 'django_vue_admin.urls' 87 | 88 | TEMPLATES = [ 89 | { 90 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 91 | 'DIRS': [], 92 | 'APP_DIRS': True, 93 | 'OPTIONS': { 94 | 'context_processors': [ 95 | 'django.template.context_processors.debug', 96 | 'django.template.context_processors.request', 97 | 'django.contrib.auth.context_processors.auth', 98 | 'django.contrib.messages.context_processors.messages', 99 | ], 100 | }, 101 | }, 102 | ] 103 | 104 | WSGI_APPLICATION = 'django_vue_admin.wsgi.application' 105 | 106 | 107 | # Database 108 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 109 | 110 | DATABASES = { 111 | 'default': { 112 | 'ENGINE': 'django.db.backends.mysql', 113 | 'NAME': 'django_demo', 114 | 'HOST':'127.0.0.1', 115 | 'PORT':3306, 116 | 'USER':'root', 117 | 'PASSWORD':'123456' 118 | } 119 | } 120 | 121 | 122 | # Password validation 123 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 124 | 125 | AUTH_PASSWORD_VALIDATORS = [ 126 | { 127 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 128 | }, 129 | { 130 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 131 | }, 132 | { 133 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 134 | }, 135 | { 136 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 137 | }, 138 | ] 139 | 140 | 141 | # Internationalization 142 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 143 | 144 | LANGUAGE_CODE = 'zh-hans' 145 | 146 | TIME_ZONE = 'Asia/Shanghai' 147 | 148 | USE_I18N = True 149 | 150 | USE_L10N = True 151 | 152 | USE_TZ = True 153 | 154 | 155 | # Static files (CSS, JavaScript, Images) 156 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 157 | 158 | STATIC_URL = '/static/' 159 | AUTH_USER_MODEL = 'rbac.User' 160 | 161 | 162 | import datetime 163 | # drf框架的配置信息 164 | REST_FRAMEWORK = { 165 | # 配置默认的认证方式 base:账号密码验证 166 | #session:session_id认证 167 | 'DEFAULT_AUTHENTICATION_CLASSES': ( 168 | # drf的这一阶段主要是做验证,middleware的auth主要是设置session和user到request对象 169 | # 默认的验证是按照验证列表从上到下的验证 170 | 'rest_framework.authentication.BasicAuthentication', 171 | 'rest_framework.authentication.SessionAuthentication', 172 | "rest_framework_jwt.authentication.JSONWebTokenAuthentication", 173 | )} 174 | 175 | import datetime 176 | 177 | # 超时时间 178 | JWT_AUTH = { 179 | 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=2), 180 | # token前缀 181 | 'JWT_AUTH_HEADER_PREFIX': 'JWT', 182 | } 183 | 184 | SESSION_ENGINE = 'django.contrib.sessions.backends.db' 185 | SESSION_COOKIE_NAME = "sessionid" 186 | SESSION_COOKIE_PATH = "/" 187 | SESSION_COOKIE_DOMAIN = None 188 | SESSION_COOKIE_SECURE = False 189 | SESSION_COOKIE_HTTPONLY = True 190 | SESSION_COOKIE_AGE = 43200 191 | SESSION_EXPIRE_AT_BROWSER_CLOSE = True 192 | SESSION_SAVE_EVERY_REQUEST = False -------------------------------------------------------------------------------- /django_vue_admin/urls.py: -------------------------------------------------------------------------------- 1 | """django_vue_admin URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('rbac/',include("rbac.urls")) 22 | ] 23 | -------------------------------------------------------------------------------- /django_vue_admin/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_vue_admin project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_vue_admin.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_vue_admin.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /rbac/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__init__.py -------------------------------------------------------------------------------- /rbac/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/admin.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/admin.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/admin.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/admin.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/auth.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/auth.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/auth.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/auth.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/auth.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/auth.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/permissions.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/permissions.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/permissions.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/permissions.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/serializers.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/serializers.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/serializers.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/serializers.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/serializers.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/serializers.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/utils.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/utils.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/views.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/views.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/views.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/views.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | from rbac.models import User, Menu, Role, Permission 5 | 6 | admin.site.register(User) 7 | admin.site.register(Menu) 8 | admin.site.register(Role) 9 | admin.site.register(Permission) -------------------------------------------------------------------------------- /rbac/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class PermissionConfig(AppConfig): 5 | name = 'rbac' 6 | -------------------------------------------------------------------------------- /rbac/auth.py: -------------------------------------------------------------------------------- 1 | from rest_framework.exceptions import AuthenticationFailed 2 | from rest_framework_jwt.serializers import VerifyJSONWebTokenSerializer 3 | 4 | 5 | class TokenAuth(): 6 | def authenticate(self, request): 7 | token={"token":None} 8 | token["token"] = request.META.get('HTTP_TOKEN') 9 | valid_data = VerifyJSONWebTokenSerializer().validate(token) 10 | user = valid_data['user'] 11 | if user: 12 | return 13 | else: 14 | raise AuthenticationFailed('认证失败') -------------------------------------------------------------------------------- /rbac/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.4 on 2021-03-07 03:09 2 | 3 | from django.conf import settings 4 | import django.contrib.auth.models 5 | from django.db import migrations, models 6 | import django.db.models.deletion 7 | import django.utils.timezone 8 | 9 | 10 | class Migration(migrations.Migration): 11 | 12 | initial = True 13 | 14 | dependencies = [ 15 | ('auth', '0012_alter_user_first_name_max_length'), 16 | ] 17 | 18 | operations = [ 19 | migrations.CreateModel( 20 | name='User', 21 | fields=[ 22 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 23 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 24 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), 25 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 26 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 27 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 28 | ('username', models.CharField(max_length=30, unique=True)), 29 | ('password', models.TextField()), 30 | ('email', models.CharField(max_length=30)), 31 | ('gender', models.IntegerField(choices=[(1, '男'), (2, '女')], default=1)), 32 | ('is_active', models.IntegerField(default=1)), 33 | ('is_admin', models.IntegerField(default=0)), 34 | ('last_login', models.DateTimeField(auto_now=True)), 35 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), 36 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), 37 | ], 38 | options={ 39 | 'verbose_name_plural': '用户', 40 | 'db_table': 'tb_user', 41 | }, 42 | managers=[ 43 | ('objects', django.contrib.auth.models.UserManager()), 44 | ], 45 | ), 46 | migrations.CreateModel( 47 | name='Menu', 48 | fields=[ 49 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 50 | ('name', models.CharField(blank=True, max_length=50, null=True)), 51 | ('title', models.CharField(blank=True, max_length=50, null=True)), 52 | ('path', models.CharField(blank=True, max_length=50, null=True)), 53 | ('icon', models.CharField(max_length=50)), 54 | ('component', models.CharField(blank=True, max_length=50, null=True)), 55 | ('parent_id', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='rbac.menu')), 56 | ], 57 | options={ 58 | 'verbose_name_plural': '菜单', 59 | 'db_table': 'tb_menu', 60 | }, 61 | ), 62 | migrations.CreateModel( 63 | name='Permission', 64 | fields=[ 65 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 66 | ('name', models.CharField(max_length=20)), 67 | ('is_root', models.IntegerField(default=1)), 68 | ('code', models.CharField(default=1, max_length=30)), 69 | ('menu', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='permissions', to='rbac.menu')), 70 | ], 71 | options={ 72 | 'verbose_name_plural': '权限', 73 | 'db_table': 'tb_permission', 74 | }, 75 | ), 76 | migrations.CreateModel( 77 | name='Role', 78 | fields=[ 79 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 80 | ('name', models.CharField(max_length=20)), 81 | ('menus', models.ManyToManyField(blank=True, null=True, related_name='roles', to='rbac.Menu')), 82 | ('permissions', models.ManyToManyField(blank=True, null=True, related_name='roles', to='rbac.Permission')), 83 | ('users', models.ManyToManyField(blank=True, null=True, related_name='roles', to=settings.AUTH_USER_MODEL)), 84 | ], 85 | options={ 86 | 'verbose_name_plural': '角色', 87 | 'db_table': 'tb_role', 88 | }, 89 | ), 90 | ] 91 | -------------------------------------------------------------------------------- /rbac/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/migrations/__init__.py -------------------------------------------------------------------------------- /rbac/migrations/__pycache__/0001_initial.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/migrations/__pycache__/0001_initial.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/migrations/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/migrations/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /rbac/migrations/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/migrations/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /rbac/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/rbac/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /rbac/models.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | from django.contrib.auth.models import AbstractUser 4 | from django.db import models 5 | 6 | # Create your models here. 7 | 8 | 9 | 10 | class User(AbstractUser): 11 | GENDER_TYPE = ( 12 | (1, "男"), 13 | (2, "女") 14 | ) 15 | username = models.CharField(max_length=30,unique=True) 16 | password = models.TextField() 17 | email = models.CharField(max_length=30) 18 | gender = models.IntegerField(choices=GENDER_TYPE,default=1) 19 | is_active = models.IntegerField(default=1) 20 | is_admin = models.IntegerField(default=0) 21 | last_login = models.DateTimeField(auto_now=True) 22 | 23 | @property 24 | def roles(self): 25 | return self.roles.values("id").all() 26 | 27 | def __str__(self): 28 | return self.username 29 | 30 | class Meta: 31 | db_table = 'tb_user' 32 | verbose_name_plural = "用户" 33 | 34 | 35 | class Menu(models.Model): 36 | name = models.CharField(max_length=50,null=True,blank=True) 37 | title = models.CharField(max_length=50,null=True,blank=True) 38 | path = models.CharField(max_length=50,null=True,blank=True) 39 | icon = models.CharField(max_length=50) 40 | component = models.CharField(max_length=50,null=True,blank=True) 41 | parent_id = models.ForeignKey('self',null=True,blank=True,on_delete=models.CASCADE) 42 | 43 | 44 | 45 | def __str__(self): 46 | return self.title 47 | 48 | class Meta: 49 | db_table = 'tb_menu' 50 | verbose_name_plural = "菜单" 51 | 52 | 53 | class Permission(models.Model): 54 | name = models.CharField(max_length=20) 55 | is_root = models.IntegerField(default=1) 56 | code = models.CharField(max_length=30,default=1) 57 | menu = models.ForeignKey("Menu",on_delete=models.CASCADE,related_name="permissions") 58 | 59 | def __str__(self): 60 | return self.name 61 | 62 | class Meta: 63 | db_table = 'tb_permission' 64 | verbose_name_plural = "权限" 65 | 66 | 67 | class Role(models.Model): 68 | name = models.CharField(max_length=20) 69 | users = models.ManyToManyField("User",related_name="roles",blank=True,null=True) 70 | menus = models.ManyToManyField("Menu",related_name="roles",blank=True,null=True) 71 | permissions = models.ManyToManyField("permission",related_name="roles",blank=True,null=True) 72 | 73 | @property 74 | def menu(self): 75 | return self.menus.values("title","id").filter(parent_id__isnull = False).all() 76 | 77 | @property 78 | def permission(self): 79 | return self.permissions.values("name","id").all() 80 | 81 | 82 | 83 | def __str__(self): 84 | return self.name 85 | 86 | class Meta: 87 | db_table = 'tb_role' 88 | verbose_name_plural = "角色" -------------------------------------------------------------------------------- /rbac/permissions.py: -------------------------------------------------------------------------------- 1 | from functools import wraps 2 | 3 | from rest_framework.response import Response 4 | 5 | 6 | def permission_required(permissionName): 7 | def outer(func): 8 | @wraps(func) 9 | def inner(self, request, *args, **kwargs): 10 | if permissionName in request.session["permission"]: 11 | return func(self,request,*args, **kwargs) 12 | else: 13 | return Response({"code":"10005","msg":"没有权限"}) 14 | return inner 15 | return outer -------------------------------------------------------------------------------- /rbac/serializers.py: -------------------------------------------------------------------------------- 1 | 2 | from rest_framework import serializers 3 | from rest_framework.response import Response 4 | 5 | from rbac import models 6 | from rbac.utils import initMenu 7 | 8 | 9 | class MenuSerializer(serializers.ModelSerializer): 10 | 11 | class Meta: 12 | model = models.Menu 13 | fields = "__all__" 14 | 15 | 16 | class PermissionSerializer(serializers.ModelSerializer): 17 | class Meta: 18 | model = models.Permission 19 | fields = "__all__" 20 | 21 | 22 | 23 | class RoleListSerializer(serializers.ModelSerializer): 24 | menus = serializers.ListField(source="menu") 25 | permissions = serializers.ListField(source="permission") 26 | class Meta: 27 | model = models.Role 28 | fields = "__all__" 29 | 30 | class RoleSerializer(serializers.ModelSerializer): 31 | 32 | class Meta: 33 | model = models.Role 34 | fields = "__all__" 35 | 36 | 37 | 38 | class MenuPermissionSerializer(serializers.Serializer): 39 | id = serializers.IntegerField() 40 | title = serializers.CharField() 41 | permissions = serializers.SerializerMethodField() 42 | 43 | def get_permissions(self,obj): 44 | return PermissionSerializer(instance=obj.permissions.all(),many=True).data 45 | 46 | 47 | class UserRoleSerializer(serializers.Serializer): 48 | menu = serializers.SerializerMethodField() 49 | permissions = serializers.SerializerMethodField() 50 | router = serializers.SerializerMethodField() 51 | 52 | def get_menu(self,obj): 53 | rolesList = obj.roles.all() 54 | menuList = [] 55 | for role in rolesList: 56 | singleRoleMenuList = role.menus.all() 57 | menuList.extend(singleRoleMenuList) 58 | menuList = list(set(menuList)) 59 | se = MenuSerializer(instance=menuList, many=True) 60 | return initMenu(se.data) 61 | 62 | def get_permissions(self,obj): 63 | rolesList = obj.roles.all() 64 | permissionList = [] 65 | for role in rolesList: 66 | rolepermission = role.permissions.all() 67 | permissionList.extend(rolepermission) 68 | permissionList = list(set(permissionList)) 69 | return [ item['code'] for item in PermissionSerializer(instance=permissionList,many=True).data] 70 | 71 | def get_router(selfobj,obj): 72 | rolesList = obj.roles.all() 73 | routerList = [] 74 | for role in rolesList: 75 | rolerouter = role.menus.filter(parent_id__isnull=False).all() 76 | routerList.extend(rolerouter) 77 | routerList = list(set(routerList)) 78 | return MenuSerializer(instance=routerList,many=True).data 79 | 80 | 81 | 82 | 83 | 84 | class UserSerializer(serializers.ModelSerializer): 85 | 86 | class Meta: 87 | model = models.User 88 | fields = ["id","username","password","gender","date_joined","email","is_active","roles"] 89 | 90 | 91 | 92 | 93 | class PermissionListSerializer(serializers.ModelSerializer): 94 | # menu = serializers.CharField(source='menu.title') 95 | class Meta: 96 | model = models.Permission 97 | fields = ["id","name","code","is_root","menu"] 98 | 99 | -------------------------------------------------------------------------------- /rbac/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /rbac/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from rest_framework_jwt.views import obtain_jwt_token 3 | 4 | from rbac import views 5 | 6 | urlpatterns=[ 7 | url(r"^login/$", obtain_jwt_token), 8 | url(r"^userinfo/$", views.UserInfoView.as_view()), 9 | url(r"^user/$", views.UserListView.as_view()), 10 | url(r"^user/(?P\d+)/$", views.UserView.as_view()), 11 | url(r"^permission/$", views.PermissionListView.as_view()), 12 | url(r"^permission/(?P\d+)/$", views.PermissionView.as_view()), 13 | url(r"^role/$",views.RoleListView.as_view()), 14 | url(r"^role/(?P\d+)/$",views.RoleView.as_view()), 15 | url(r"^menu/$",views.MenuListView.as_view()), 16 | url(r"^menu/(?P\d+)/$",views.MenuView.as_view()), 17 | url(r"^rootmenu/$",views.RootMenuView.as_view()), 18 | url(r"^treemenu/$",views.TreemenuView.as_view()) 19 | ] -------------------------------------------------------------------------------- /rbac/utils.py: -------------------------------------------------------------------------------- 1 | #菜单结构化 2 | def initMenu(menuListData): 3 | menuList = [] 4 | for item in menuListData: 5 | if not item['parent_id']: 6 | item['children'] = [] 7 | menuList.append(item) 8 | for menuobj in menuList: 9 | if menuobj['id'] == item['parent_id']: 10 | menuobj['children'].append(item) 11 | return menuList 12 | 13 | -------------------------------------------------------------------------------- /rbac/views.py: -------------------------------------------------------------------------------- 1 | from functools import wraps 2 | 3 | from django.http import HttpResponse, JsonResponse 4 | from django.shortcuts import render 5 | 6 | # Create your views here. 7 | from django.utils.decorators import method_decorator 8 | from django.views import View 9 | from rest_framework.response import Response 10 | from rest_framework.views import APIView 11 | from rest_framework_jwt.serializers import VerifyJSONWebTokenSerializer 12 | 13 | from rbac import models, serializers 14 | from rbac.auth import TokenAuth 15 | from rbac.permissions import permission_required 16 | from rbac.utils import initMenu 17 | 18 | 19 | 20 | 21 | 22 | class UserInfoView(APIView): 23 | authentication_classes = [TokenAuth] 24 | 25 | # 获取用户信息 26 | def get(self,request): 27 | token = {"token": None} 28 | token["token"] = request.META.get('HTTP_TOKEN') 29 | valid_data = VerifyJSONWebTokenSerializer().validate(token) 30 | user = valid_data['user'] 31 | roleList = models.User.objects.filter(username = user).first() 32 | menuse = serializers.UserRoleSerializer(instance=roleList) 33 | request.session['permission'] = menuse.data['permissions'] 34 | result = { 35 | "code":200, 36 | "msg":"ok", 37 | "data":{"username":roleList.username, 38 | "menu":menuse.data['menu'], 39 | "permission":menuse.data['permissions'], 40 | "router":menuse.data['router']} 41 | } 42 | return Response(result) 43 | 44 | 45 | 46 | class UserListView(APIView): 47 | authentication_classes = [TokenAuth] 48 | #获取用户列表 49 | def get(self, request): 50 | 51 | obj = models.User.objects.all() 52 | se = serializers.UserSerializer(instance=obj, many=True) 53 | result = { 54 | "code": 10001, 55 | "data": se.data, 56 | "msg": "ok" 57 | } 58 | return Response(result) 59 | 60 | @permission_required("user_add") 61 | #新增用户 62 | def post(self,request): 63 | data = request.data 64 | se = serializers.UserSerializer(data=data) 65 | se.is_valid(raise_exception=True) 66 | se.save() 67 | result = { 68 | "code": 10001, 69 | "data": se.data, 70 | "msg": "ok" 71 | } 72 | return Response(result) 73 | 74 | 75 | 76 | 77 | 78 | class UserView(APIView): 79 | authentication_classes = [TokenAuth] 80 | 81 | #查看用户详情 82 | @permission_required("user_view") 83 | def get(self, request, uid): 84 | obj = models.User.objects.all() 85 | se = serializers.UserSerializer(instance=obj,many=True) 86 | result={ 87 | "code":10001, 88 | "data":se.data, 89 | "msg":"ok" 90 | } 91 | return Response(result) 92 | 93 | #修改用户信息 94 | @permission_required("user_reset") 95 | def put(self,request,uid): 96 | data = request.data 97 | userbj = models.User.objects.filter(id = uid).first() 98 | se = serializers.UserSerializer(instance=userbj,data = data) 99 | se.is_valid(raise_exception=True) 100 | se.save() 101 | result = { 102 | "code": 10001, 103 | "data": se.data, 104 | "msg": "ok" 105 | } 106 | return Response(result) 107 | 108 | 109 | 110 | class RoleListView(APIView): 111 | authentication_classes = [TokenAuth] 112 | #获取角色列表 113 | def get(self, request): 114 | roledata = models.Role.objects.all() 115 | se = serializers.RoleListSerializer(instance=roledata,many=True) 116 | result = { 117 | "code": 10001, 118 | "data": se.data, 119 | "msg": "ok" 120 | } 121 | return Response(result) 122 | 123 | #添加新角色 124 | def post(self,request): 125 | data = request.data 126 | se = serializers.RoleSerializer(data=data) 127 | se.is_valid(raise_exception = True) 128 | se.save() 129 | result = { 130 | "code": 10001, 131 | "data": se.data, 132 | "msg": "ok" 133 | } 134 | return Response(result) 135 | 136 | 137 | class RoleView(APIView): 138 | authentication_classes = [TokenAuth] 139 | 140 | #查看角色详情 141 | @permission_required("role_view") 142 | def get(self, request,uid): 143 | roledata = models.Role.objects.filter(id=uid).first() 144 | se = serializers.RoleSerializer(instance=roledata) 145 | result = { 146 | "code": 10001, 147 | "data": se.data, 148 | "msg": "ok" 149 | } 150 | return Response(result) 151 | 152 | #修改角色信息 153 | @permission_required("role_reset") 154 | def put(self,request,uid): 155 | per_obj = models.Role.objects.filter(id=uid).first() 156 | per_data = request.data 157 | se = serializers.RoleSerializer(instance=per_obj, data=per_data) 158 | se.is_valid(raise_exception=True) 159 | se.save() 160 | result = { 161 | "code": 10001, 162 | "data": se.data, 163 | "msg": "ok" 164 | } 165 | return Response(result) 166 | 167 | #删除角色 168 | @permission_required("role_delete") 169 | def delete(self,request,uid): 170 | obj = models.Role.objects.filter(id = uid).first() 171 | obj.delete() 172 | result = { 173 | "code": 10001, 174 | "msg": "ok" 175 | } 176 | return Response(result) 177 | 178 | 179 | 180 | class PermissionListView(APIView): 181 | authentication_classes = [TokenAuth] 182 | 183 | #查看权限列表 184 | def get(self, request): 185 | permissiondata = models.Permission.objects.all() 186 | se = serializers.PermissionListSerializer(instance=permissiondata, many=True) 187 | result = { 188 | "code": 10001, 189 | "data": se.data, 190 | "msg": "ok" 191 | } 192 | return Response(result) 193 | 194 | #新增权限 195 | @permission_required("permission_add") 196 | def post(self,request): 197 | data = request.data 198 | se = serializers.PermissionSerializer(data=data) 199 | se.is_valid(raise_exception=True) 200 | se.save() 201 | result = { 202 | "code": 10001, 203 | "data": se.data, 204 | "msg": "ok" 205 | } 206 | return Response(result) 207 | 208 | 209 | class PermissionView(APIView): 210 | authentication_classes = [TokenAuth] 211 | 212 | #修改权限 213 | @permission_required("permission_reset") 214 | def put(self,request,uid): 215 | per_obj = models.Permission.objects.filter(id = uid).first() 216 | per_data = request.data 217 | se = serializers.PermissionSerializer(instance=per_obj,data=per_data) 218 | se.is_valid(raise_exception=True) 219 | se.save() 220 | result = { 221 | "code": 10001, 222 | "data": se.data, 223 | "msg": "ok" 224 | } 225 | return Response(result) 226 | 227 | #删除权限 228 | @permission_required("permission_delete") 229 | def delete(self,request,uid): 230 | obj = models.Permission.objects.filter(id = uid).first() 231 | obj.delete() 232 | result = { 233 | "code": 10001, 234 | "msg": "ok" 235 | } 236 | return Response(result) 237 | 238 | 239 | 240 | class MenuListView(APIView): 241 | 242 | #获取菜单列表 243 | def get(self,request): 244 | queryset = models.Menu.objects.filter(parent_id__isnull = False) 245 | se = serializers.MenuSerializer(instance=queryset,many=True) 246 | result = { 247 | "code": 10001, 248 | "data": se.data, 249 | "msg": "ok" 250 | } 251 | return Response(result) 252 | 253 | #新增菜单 254 | def post(self,request): 255 | data = request.data 256 | se = serializers.MenuSerializer(data = data) 257 | se.is_valid(raise_exception=True) 258 | se.save() 259 | result = { 260 | "code": 10001, 261 | "data": se.data, 262 | "msg": "ok" 263 | } 264 | return Response(result) 265 | 266 | 267 | 268 | class MenuView(APIView): 269 | authentication_classes = [TokenAuth] 270 | #修改菜单 271 | def put(self,request,uid): 272 | obj = models.Menu.objects.filter(id = uid).first() 273 | data = request.data 274 | se = serializers.MenuSerializer(instance=obj,data = data) 275 | se.is_valid(raise_exception=True) 276 | se.save() 277 | result = { 278 | "code": 10001, 279 | "data": se.data, 280 | "msg": "ok" 281 | } 282 | return Response(result) 283 | 284 | #删除菜单 285 | def delete(self,request,uid): 286 | obj = models.Menu.objects.filter(id = uid).first() 287 | obj.delete() 288 | result = { 289 | "code": 10001, 290 | "msg": "ok" 291 | } 292 | return Response(result) 293 | 294 | 295 | 296 | class TreemenuView(APIView): 297 | 298 | #获取结构化菜单列表 299 | def get(self,request): 300 | queryset = models.Menu.objects.all() 301 | se = serializers.MenuSerializer(instance=queryset,many=True) 302 | result = { 303 | "code": 10001, 304 | "data": initMenu(se.data), 305 | "msg": "ok" 306 | } 307 | return Response(result) 308 | 309 | class RootMenuView(APIView): 310 | 311 | # 获取根菜单课表 312 | def get(self,request): 313 | queryset = models.Menu.objects.filter(parent_id__isnull=True) 314 | se = serializers.MenuSerializer(instance=queryset, many=True) 315 | result = { 316 | "code": 10001, 317 | "data": se.data, 318 | "msg": "ok" 319 | } 320 | return Response(result) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Django==3.1.4 2 | PyMySQL==0.10.0 3 | djangorestframework_jwt==1.11.0 4 | djangorestframework==3.12.2 5 | -------------------------------------------------------------------------------- /vue_admin/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-vue-jsx", "transform-runtime"] 12 | } 13 | -------------------------------------------------------------------------------- /vue_admin/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /vue_admin/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | /dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Editor directories and files 9 | .idea 10 | .vscode 11 | *.suo 12 | *.ntvs* 13 | *.njsproj 14 | *.sln 15 | -------------------------------------------------------------------------------- /vue_admin/.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | "postcss-import": {}, 6 | "postcss-url": {}, 7 | // to edit target browsers: use "browserslist" field in package.json 8 | "autoprefixer": {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /vue_admin/README.md: -------------------------------------------------------------------------------- 1 | # vue_admin 2 | 3 | > A Vue.js project 4 | 5 | ## Build Setup 6 | 7 | ``` bash 8 | # install dependencies 9 | npm install 10 | 11 | # serve with hot reload at localhost:8080 12 | npm run dev 13 | 14 | # build for production with minification 15 | npm run build 16 | 17 | # build for production and view the bundle analyzer report 18 | npm run build --report 19 | ``` 20 | 21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 22 | -------------------------------------------------------------------------------- /vue_admin/build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | process.env.NODE_ENV = 'production' 5 | 6 | const ora = require('ora') 7 | const rm = require('rimraf') 8 | const path = require('path') 9 | const chalk = require('chalk') 10 | const webpack = require('webpack') 11 | const config = require('../config') 12 | const webpackConfig = require('./webpack.prod.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, (err, stats) => { 20 | spinner.stop() 21 | if (err) throw err 22 | process.stdout.write(stats.toString({ 23 | colors: true, 24 | modules: false, 25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build. 26 | chunks: false, 27 | chunkModules: false 28 | }) + '\n\n') 29 | 30 | if (stats.hasErrors()) { 31 | console.log(chalk.red(' Build failed with errors.\n')) 32 | process.exit(1) 33 | } 34 | 35 | console.log(chalk.cyan(' Build complete.\n')) 36 | console.log(chalk.yellow( 37 | ' Tip: built files are meant to be served over an HTTP server.\n' + 38 | ' Opening index.html over file:// won\'t work.\n' 39 | )) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /vue_admin/build/check-versions.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const chalk = require('chalk') 3 | const semver = require('semver') 4 | const packageConfig = require('../package.json') 5 | const shell = require('shelljs') 6 | 7 | function exec (cmd) { 8 | return require('child_process').execSync(cmd).toString().trim() 9 | } 10 | 11 | const versionRequirements = [ 12 | { 13 | name: 'node', 14 | currentVersion: semver.clean(process.version), 15 | versionRequirement: packageConfig.engines.node 16 | } 17 | ] 18 | 19 | if (shell.which('npm')) { 20 | versionRequirements.push({ 21 | name: 'npm', 22 | currentVersion: exec('npm --version'), 23 | versionRequirement: packageConfig.engines.npm 24 | }) 25 | } 26 | 27 | module.exports = function () { 28 | const warnings = [] 29 | 30 | for (let i = 0; i < versionRequirements.length; i++) { 31 | const mod = versionRequirements[i] 32 | 33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 34 | warnings.push(mod.name + ': ' + 35 | chalk.red(mod.currentVersion) + ' should be ' + 36 | chalk.green(mod.versionRequirement) 37 | ) 38 | } 39 | } 40 | 41 | if (warnings.length) { 42 | console.log('') 43 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 44 | console.log() 45 | 46 | for (let i = 0; i < warnings.length; i++) { 47 | const warning = warnings[i] 48 | console.log(' ' + warning) 49 | } 50 | 51 | console.log() 52 | process.exit(1) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vue_admin/build/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/build/logo.png -------------------------------------------------------------------------------- /vue_admin/build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const config = require('../config') 4 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 5 | const packageConfig = require('../package.json') 6 | 7 | exports.assetsPath = function (_path) { 8 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 9 | ? config.build.assetsSubDirectory 10 | : config.dev.assetsSubDirectory 11 | 12 | return path.posix.join(assetsSubDirectory, _path) 13 | } 14 | 15 | exports.cssLoaders = function (options) { 16 | options = options || {} 17 | 18 | const cssLoader = { 19 | loader: 'css-loader', 20 | options: { 21 | sourceMap: options.sourceMap 22 | } 23 | } 24 | 25 | const postcssLoader = { 26 | loader: 'postcss-loader', 27 | options: { 28 | sourceMap: options.sourceMap 29 | } 30 | } 31 | 32 | // generate loader string to be used with extract text plugin 33 | function generateLoaders (loader, loaderOptions) { 34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] 35 | 36 | if (loader) { 37 | loaders.push({ 38 | loader: loader + '-loader', 39 | options: Object.assign({}, loaderOptions, { 40 | sourceMap: options.sourceMap 41 | }) 42 | }) 43 | } 44 | 45 | // Extract CSS when that option is specified 46 | // (which is the case during production build) 47 | if (options.extract) { 48 | return ExtractTextPlugin.extract({ 49 | use: loaders, 50 | fallback: 'vue-style-loader' 51 | }) 52 | } else { 53 | return ['vue-style-loader'].concat(loaders) 54 | } 55 | } 56 | 57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 58 | return { 59 | css: generateLoaders(), 60 | postcss: generateLoaders(), 61 | less: generateLoaders('less'), 62 | sass: generateLoaders('sass', { indentedSyntax: true }), 63 | scss: generateLoaders('sass'), 64 | stylus: generateLoaders('stylus'), 65 | styl: generateLoaders('stylus') 66 | } 67 | } 68 | 69 | // Generate loaders for standalone style files (outside of .vue) 70 | exports.styleLoaders = function (options) { 71 | const output = [] 72 | const loaders = exports.cssLoaders(options) 73 | 74 | for (const extension in loaders) { 75 | const loader = loaders[extension] 76 | output.push({ 77 | test: new RegExp('\\.' + extension + '$'), 78 | use: loader 79 | }) 80 | } 81 | 82 | return output 83 | } 84 | 85 | exports.createNotifierCallback = () => { 86 | const notifier = require('node-notifier') 87 | 88 | return (severity, errors) => { 89 | if (severity !== 'error') return 90 | 91 | const error = errors[0] 92 | const filename = error.file && error.file.split('!').pop() 93 | 94 | notifier.notify({ 95 | title: packageConfig.name, 96 | message: severity + ': ' + error.name, 97 | subtitle: filename || '', 98 | icon: path.join(__dirname, 'logo.png') 99 | }) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /vue_admin/build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | const sourceMapEnabled = isProduction 6 | ? config.build.productionSourceMap 7 | : config.dev.cssSourceMap 8 | 9 | module.exports = { 10 | loaders: utils.cssLoaders({ 11 | sourceMap: sourceMapEnabled, 12 | extract: isProduction 13 | }), 14 | cssSourceMap: sourceMapEnabled, 15 | cacheBusting: config.dev.cacheBusting, 16 | transformToRequire: { 17 | video: ['src', 'poster'], 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vue_admin/build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const config = require('../config') 5 | const vueLoaderConfig = require('./vue-loader.conf') 6 | 7 | function resolve (dir) { 8 | return path.join(__dirname, '..', dir) 9 | } 10 | 11 | 12 | 13 | module.exports = { 14 | context: path.resolve(__dirname, '../'), 15 | entry: { 16 | app: './src/main.js' 17 | }, 18 | output: { 19 | path: config.build.assetsRoot, 20 | filename: '[name].js', 21 | publicPath: process.env.NODE_ENV === 'production' 22 | ? config.build.assetsPublicPath 23 | : config.dev.assetsPublicPath 24 | }, 25 | resolve: { 26 | extensions: ['.js', '.vue', '.json'], 27 | alias: { 28 | 'vue$': 'vue/dist/vue.esm.js', 29 | '@': resolve('src'), 30 | } 31 | }, 32 | module: { 33 | rules: [ 34 | { 35 | test: /\.vue$/, 36 | loader: 'vue-loader', 37 | options: vueLoaderConfig 38 | }, 39 | { 40 | test: /\.js$/, 41 | loader: 'babel-loader', 42 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] 43 | }, 44 | { 45 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 46 | loader: 'url-loader', 47 | options: { 48 | limit: 10000, 49 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 50 | } 51 | }, 52 | { 53 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 54 | loader: 'url-loader', 55 | options: { 56 | limit: 10000, 57 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 58 | } 59 | }, 60 | { 61 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 62 | loader: 'url-loader', 63 | options: { 64 | limit: 10000, 65 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 66 | } 67 | } 68 | ] 69 | }, 70 | node: { 71 | // prevent webpack from injecting useless setImmediate polyfill because Vue 72 | // source contains it (although only uses it if it's native). 73 | setImmediate: false, 74 | // prevent webpack from injecting mocks to Node native modules 75 | // that does not make sense for the client 76 | dgram: 'empty', 77 | fs: 'empty', 78 | net: 'empty', 79 | tls: 'empty', 80 | child_process: 'empty' 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /vue_admin/build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const webpack = require('webpack') 4 | const config = require('../config') 5 | const merge = require('webpack-merge') 6 | const path = require('path') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 11 | const portfinder = require('portfinder') 12 | 13 | const HOST = process.env.HOST 14 | const PORT = process.env.PORT && Number(process.env.PORT) 15 | 16 | const devWebpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) 19 | }, 20 | // cheap-module-eval-source-map is faster for development 21 | devtool: config.dev.devtool, 22 | 23 | // these devServer options should be customized in /config/index.js 24 | devServer: { 25 | clientLogLevel: 'warning', 26 | historyApiFallback: { 27 | rewrites: [ 28 | { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }, 29 | ], 30 | }, 31 | hot: true, 32 | contentBase: false, // since we use CopyWebpackPlugin. 33 | compress: true, 34 | host: HOST || config.dev.host, 35 | port: PORT || config.dev.port, 36 | open: config.dev.autoOpenBrowser, 37 | overlay: config.dev.errorOverlay 38 | ? { warnings: false, errors: true } 39 | : false, 40 | publicPath: config.dev.assetsPublicPath, 41 | proxy: config.dev.proxyTable, 42 | quiet: true, // necessary for FriendlyErrorsPlugin 43 | watchOptions: { 44 | poll: config.dev.poll, 45 | } 46 | }, 47 | plugins: [ 48 | new webpack.DefinePlugin({ 49 | 'process.env': require('../config/dev.env') 50 | }), 51 | new webpack.HotModuleReplacementPlugin(), 52 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. 53 | new webpack.NoEmitOnErrorsPlugin(), 54 | // https://github.com/ampedandwired/html-webpack-plugin 55 | new HtmlWebpackPlugin({ 56 | filename: 'index.html', 57 | template: 'index.html', 58 | inject: true 59 | }), 60 | // copy custom static assets 61 | new CopyWebpackPlugin([ 62 | { 63 | from: path.resolve(__dirname, '../static'), 64 | to: config.dev.assetsSubDirectory, 65 | ignore: ['.*'] 66 | } 67 | ]) 68 | ] 69 | }) 70 | 71 | module.exports = new Promise((resolve, reject) => { 72 | portfinder.basePort = process.env.PORT || config.dev.port 73 | portfinder.getPort((err, port) => { 74 | if (err) { 75 | reject(err) 76 | } else { 77 | // publish the new Port, necessary for e2e tests 78 | process.env.PORT = port 79 | // add port to devServer config 80 | devWebpackConfig.devServer.port = port 81 | 82 | // Add FriendlyErrorsPlugin 83 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ 84 | compilationSuccessInfo: { 85 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], 86 | }, 87 | onErrors: config.dev.notifyOnErrors 88 | ? utils.createNotifierCallback() 89 | : undefined 90 | })) 91 | 92 | resolve(devWebpackConfig) 93 | } 94 | }) 95 | }) 96 | -------------------------------------------------------------------------------- /vue_admin/build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const webpack = require('webpack') 5 | const config = require('../config') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') 13 | 14 | const env = require('../config/prod.env') 15 | 16 | const webpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ 19 | sourceMap: config.build.productionSourceMap, 20 | extract: true, 21 | usePostCSS: true 22 | }) 23 | }, 24 | devtool: config.build.productionSourceMap ? config.build.devtool : false, 25 | output: { 26 | path: config.build.assetsRoot, 27 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 28 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 29 | }, 30 | plugins: [ 31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 32 | new webpack.DefinePlugin({ 33 | 'process.env': env 34 | }), 35 | new UglifyJsPlugin({ 36 | uglifyOptions: { 37 | compress: { 38 | warnings: false 39 | } 40 | }, 41 | sourceMap: config.build.productionSourceMap, 42 | parallel: true 43 | }), 44 | // extract css into its own file 45 | new ExtractTextPlugin({ 46 | filename: utils.assetsPath('css/[name].[contenthash].css'), 47 | // Setting the following option to `false` will not extract CSS from codesplit chunks. 48 | // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack. 49 | // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, 50 | // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110 51 | allChunks: true, 52 | }), 53 | // Compress extracted CSS. We are using this plugin so that possible 54 | // duplicated CSS from different components can be deduped. 55 | new OptimizeCSSPlugin({ 56 | cssProcessorOptions: config.build.productionSourceMap 57 | ? { safe: true, map: { inline: false } } 58 | : { safe: true } 59 | }), 60 | // generate dist index.html with correct asset hash for caching. 61 | // you can customize output by editing /index.html 62 | // see https://github.com/ampedandwired/html-webpack-plugin 63 | new HtmlWebpackPlugin({ 64 | filename: config.build.index, 65 | template: 'index.html', 66 | inject: true, 67 | minify: { 68 | removeComments: true, 69 | collapseWhitespace: true, 70 | removeAttributeQuotes: true 71 | // more options: 72 | // https://github.com/kangax/html-minifier#options-quick-reference 73 | }, 74 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 75 | chunksSortMode: 'dependency' 76 | }), 77 | // keep module.id stable when vendor modules does not change 78 | new webpack.HashedModuleIdsPlugin(), 79 | // enable scope hoisting 80 | new webpack.optimize.ModuleConcatenationPlugin(), 81 | // split vendor js into its own file 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'vendor', 84 | minChunks (module) { 85 | // any required modules inside node_modules are extracted to vendor 86 | return ( 87 | module.resource && 88 | /\.js$/.test(module.resource) && 89 | module.resource.indexOf( 90 | path.join(__dirname, '../node_modules') 91 | ) === 0 92 | ) 93 | } 94 | }), 95 | // extract webpack runtime and module manifest to its own file in order to 96 | // prevent vendor hash from being updated whenever app bundle is updated 97 | new webpack.optimize.CommonsChunkPlugin({ 98 | name: 'manifest', 99 | minChunks: Infinity 100 | }), 101 | // This instance extracts shared chunks from code splitted chunks and bundles them 102 | // in a separate chunk, similar to the vendor chunk 103 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk 104 | new webpack.optimize.CommonsChunkPlugin({ 105 | name: 'app', 106 | async: 'vendor-async', 107 | children: true, 108 | minChunks: 3 109 | }), 110 | 111 | // copy custom static assets 112 | new CopyWebpackPlugin([ 113 | { 114 | from: path.resolve(__dirname, '../static'), 115 | to: config.build.assetsSubDirectory, 116 | ignore: ['.*'] 117 | } 118 | ]) 119 | ] 120 | }) 121 | 122 | if (config.build.productionGzip) { 123 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 124 | 125 | webpackConfig.plugins.push( 126 | new CompressionWebpackPlugin({ 127 | asset: '[path].gz[query]', 128 | algorithm: 'gzip', 129 | test: new RegExp( 130 | '\\.(' + 131 | config.build.productionGzipExtensions.join('|') + 132 | ')$' 133 | ), 134 | threshold: 10240, 135 | minRatio: 0.8 136 | }) 137 | ) 138 | } 139 | 140 | if (config.build.bundleAnalyzerReport) { 141 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 142 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 143 | } 144 | 145 | module.exports = webpackConfig 146 | -------------------------------------------------------------------------------- /vue_admin/config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"' 7 | }) 8 | -------------------------------------------------------------------------------- /vue_admin/config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // Template version: 1.3.1 3 | // see http://vuejs-templates.github.io/webpack for documentation. 4 | 5 | const path = require('path') 6 | 7 | module.exports = { 8 | dev: { 9 | 10 | // Paths 11 | assetsSubDirectory: 'static', 12 | assetsPublicPath: '/', 13 | proxyTable: {}, 14 | 15 | // Various Dev Server settings 16 | host: '0.0.0.0', // can be overwritten by process.env.HOST 17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined 18 | autoOpenBrowser: false, 19 | errorOverlay: true, 20 | notifyOnErrors: true, 21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- 22 | 23 | 24 | /** 25 | * Source Maps 26 | */ 27 | 28 | // https://webpack.js.org/configuration/devtool/#development 29 | devtool: 'cheap-module-eval-source-map', 30 | 31 | // If you have problems debugging vue-files in devtools, 32 | // set this to false - it *may* help 33 | // https://vue-loader.vuejs.org/en/options.html#cachebusting 34 | cacheBusting: true, 35 | 36 | cssSourceMap: true 37 | }, 38 | 39 | build: { 40 | // Template for index.html 41 | index: path.resolve(__dirname, '../dist/index.html'), 42 | 43 | // Paths 44 | assetsRoot: path.resolve(__dirname, '../dist'), 45 | assetsSubDirectory: 'static', 46 | assetsPublicPath: '/', 47 | 48 | /** 49 | * Source Maps 50 | */ 51 | 52 | productionSourceMap: true, 53 | // https://webpack.js.org/configuration/devtool/#production 54 | devtool: '#source-map', 55 | 56 | // Gzip off by default as many popular static hosts such as 57 | // Surge or Netlify already gzip all static assets for you. 58 | // Before setting to `true`, make sure to: 59 | // npm install --save-dev compression-webpack-plugin 60 | productionGzip: false, 61 | productionGzipExtensions: ['js', 'css'], 62 | 63 | // Run the build command with an extra argument to 64 | // View the bundle analyzer report after build finishes: 65 | // `npm run build --report` 66 | // Set to `true` or `false` to always turn it on or off 67 | bundleAnalyzerReport: process.env.npm_config_report 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /vue_admin/config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /vue_admin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | vue_admin 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /vue_admin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue_admin", 3 | "version": "1.0.0", 4 | "description": "A Vue.js project", 5 | "author": "", 6 | "private": true, 7 | "scripts": { 8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", 9 | "start": "npm run dev", 10 | "build": "node build/build.js" 11 | }, 12 | "dependencies": { 13 | "axios": "^0.21.1", 14 | "element-ui": "^2.15.0", 15 | "vue": "^2.5.2", 16 | "vue-router": "^3.0.1", 17 | "vuex": "^3.6.2" 18 | }, 19 | "devDependencies": { 20 | "autoprefixer": "^7.1.2", 21 | "babel-core": "^6.22.1", 22 | "babel-helper-vue-jsx-merge-props": "^2.0.3", 23 | "babel-loader": "^7.1.1", 24 | "babel-plugin-syntax-jsx": "^6.18.0", 25 | "babel-plugin-transform-runtime": "^6.22.0", 26 | "babel-plugin-transform-vue-jsx": "^3.5.0", 27 | "babel-preset-env": "^1.3.2", 28 | "babel-preset-stage-2": "^6.22.0", 29 | "chalk": "^2.0.1", 30 | "copy-webpack-plugin": "^4.0.1", 31 | "css-loader": "^0.28.0", 32 | "extract-text-webpack-plugin": "^3.0.0", 33 | "file-loader": "^1.1.4", 34 | "friendly-errors-webpack-plugin": "^1.6.1", 35 | "html-webpack-plugin": "^2.30.1", 36 | "less": "^4.1.1", 37 | "less-loader": "^8.0.0", 38 | "node-notifier": "^5.1.2", 39 | "optimize-css-assets-webpack-plugin": "^3.2.0", 40 | "ora": "^1.2.0", 41 | "portfinder": "^1.0.13", 42 | "postcss-import": "^11.0.0", 43 | "postcss-loader": "^2.0.8", 44 | "postcss-url": "^7.2.1", 45 | "rimraf": "^2.6.0", 46 | "semver": "^5.3.0", 47 | "shelljs": "^0.7.6", 48 | "uglifyjs-webpack-plugin": "^1.1.1", 49 | "url-loader": "^0.5.8", 50 | "vue-loader": "^13.3.0", 51 | "vue-style-loader": "^3.0.1", 52 | "vue-template-compiler": "^2.5.2", 53 | "webpack": "^3.6.0", 54 | "webpack-bundle-analyzer": "^2.9.0", 55 | "webpack-dev-server": "^2.9.1", 56 | "webpack-merge": "^4.1.0" 57 | }, 58 | "engines": { 59 | "node": ">= 6.0.0", 60 | "npm": ">= 3.0.0" 61 | }, 62 | "browserslist": [ 63 | "> 1%", 64 | "last 2 versions", 65 | "not ie <= 8" 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /vue_admin/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 21 | -------------------------------------------------------------------------------- /vue_admin/src/api/menu.js: -------------------------------------------------------------------------------- 1 | import axios from "@/plugins/http.js" 2 | 3 | 4 | function getTreeMenu() { 5 | return axios.get('/rbac/treemenu/') 6 | } 7 | 8 | function getMenuList() { 9 | return axios.get('/rbac/rootmenu/') 10 | } 11 | 12 | function editMenu(id, data) { 13 | return axios.put('/rbac/menu/' + id + "/", data) 14 | } 15 | 16 | 17 | function addMenu(data) { 18 | return axios.post('/rbac/menu/', data) 19 | } 20 | 21 | 22 | function deleteMenu(id) { 23 | return axios.delete('/rbac/menu/' + id + "/") 24 | } 25 | 26 | 27 | 28 | 29 | 30 | export { getTreeMenu, getMenuList, editMenu, addMenu, deleteMenu } -------------------------------------------------------------------------------- /vue_admin/src/api/permission.js: -------------------------------------------------------------------------------- 1 | import axios from "@/plugins/http.js" 2 | 3 | 4 | function getPermissionList() { 5 | return axios.get('/rbac/permission/') 6 | } 7 | 8 | function editPermission(id, data) { 9 | return axios.put('/rbac/permission/' + id + "/", data) 10 | } 11 | 12 | 13 | function addPermission(data) { 14 | return axios.post('/rbac/permission/', data) 15 | } 16 | 17 | function deletePermission(id) { 18 | return axios.delete('/rbac/permission/' + id + "/") 19 | } 20 | 21 | 22 | export { getPermissionList, editPermission, addPermission, deletePermission } -------------------------------------------------------------------------------- /vue_admin/src/api/role.js: -------------------------------------------------------------------------------- 1 | import axios from "@/plugins/http.js" 2 | 3 | 4 | function getRoleList() { 5 | return axios.get('/rbac/role/') 6 | } 7 | 8 | function getRoleInfo(id) { 9 | return axios.get('/rbac/role/' + id + "/") 10 | } 11 | 12 | function editRole(id, data) { 13 | return axios.put('/rbac/role/' + id + "/", data) 14 | } 15 | 16 | 17 | function addRole(data) { 18 | return axios.post('/rbac/role/', data) 19 | } 20 | 21 | function deleteRole(id) { 22 | return axios.delete('/rbac/role/' + id + '/') 23 | } 24 | 25 | 26 | 27 | 28 | 29 | export { getRoleList, getRoleInfo, editRole, addRole, deleteRole } -------------------------------------------------------------------------------- /vue_admin/src/api/user.js: -------------------------------------------------------------------------------- 1 | import axios from "@/plugins/http.js" 2 | 3 | 4 | function getUserList() { 5 | return axios.get('/rbac/user/') 6 | } 7 | 8 | function editUser(id, data) { 9 | return axios.put('/rbac/user/' + id + "/", data) 10 | } 11 | 12 | 13 | function addUser(data) { 14 | return axios.post('/rbac/user/', data) 15 | } 16 | 17 | 18 | export { getUserList, editUser, addUser } -------------------------------------------------------------------------------- /vue_admin/src/assets/css/base.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/css/base.css -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/demo.css: -------------------------------------------------------------------------------- 1 | /* Logo 字体 */ 2 | @font-face { 3 | font-family: "iconfont logo"; 4 | src: url('https://at.alicdn.com/t/font_985780_km7mi63cihi.eot?t=1545807318834'); 5 | src: url('https://at.alicdn.com/t/font_985780_km7mi63cihi.eot?t=1545807318834#iefix') format('embedded-opentype'), 6 | url('https://at.alicdn.com/t/font_985780_km7mi63cihi.woff?t=1545807318834') format('woff'), 7 | url('https://at.alicdn.com/t/font_985780_km7mi63cihi.ttf?t=1545807318834') format('truetype'), 8 | url('https://at.alicdn.com/t/font_985780_km7mi63cihi.svg?t=1545807318834#iconfont') format('svg'); 9 | } 10 | 11 | .logo { 12 | font-family: "iconfont logo"; 13 | font-size: 160px; 14 | font-style: normal; 15 | -webkit-font-smoothing: antialiased; 16 | -moz-osx-font-smoothing: grayscale; 17 | } 18 | 19 | /* tabs */ 20 | .nav-tabs { 21 | position: relative; 22 | } 23 | 24 | .nav-tabs .nav-more { 25 | position: absolute; 26 | right: 0; 27 | bottom: 0; 28 | height: 42px; 29 | line-height: 42px; 30 | color: #666; 31 | } 32 | 33 | #tabs { 34 | border-bottom: 1px solid #eee; 35 | } 36 | 37 | #tabs li { 38 | cursor: pointer; 39 | width: 100px; 40 | height: 40px; 41 | line-height: 40px; 42 | text-align: center; 43 | font-size: 16px; 44 | border-bottom: 2px solid transparent; 45 | position: relative; 46 | z-index: 1; 47 | margin-bottom: -1px; 48 | color: #666; 49 | } 50 | 51 | 52 | #tabs .active { 53 | border-bottom-color: #f00; 54 | color: #222; 55 | } 56 | 57 | .tab-container .content { 58 | display: none; 59 | } 60 | 61 | /* 页面布局 */ 62 | .main { 63 | padding: 30px 100px; 64 | width: 960px; 65 | margin: 0 auto; 66 | } 67 | 68 | .main .logo { 69 | color: #333; 70 | text-align: left; 71 | margin-bottom: 30px; 72 | line-height: 1; 73 | height: 110px; 74 | margin-top: -50px; 75 | overflow: hidden; 76 | *zoom: 1; 77 | } 78 | 79 | .main .logo a { 80 | font-size: 160px; 81 | color: #333; 82 | } 83 | 84 | .helps { 85 | margin-top: 40px; 86 | } 87 | 88 | .helps pre { 89 | padding: 20px; 90 | margin: 10px 0; 91 | border: solid 1px #e7e1cd; 92 | background-color: #fffdef; 93 | overflow: auto; 94 | } 95 | 96 | .icon_lists { 97 | width: 100% !important; 98 | overflow: hidden; 99 | *zoom: 1; 100 | } 101 | 102 | .icon_lists li { 103 | width: 100px; 104 | margin-bottom: 10px; 105 | margin-right: 20px; 106 | text-align: center; 107 | list-style: none !important; 108 | cursor: default; 109 | } 110 | 111 | .icon_lists li .code-name { 112 | line-height: 1.2; 113 | } 114 | 115 | .icon_lists .icon { 116 | display: block; 117 | height: 100px; 118 | line-height: 100px; 119 | font-size: 42px; 120 | margin: 10px auto; 121 | color: #333; 122 | -webkit-transition: font-size 0.25s linear, width 0.25s linear; 123 | -moz-transition: font-size 0.25s linear, width 0.25s linear; 124 | transition: font-size 0.25s linear, width 0.25s linear; 125 | } 126 | 127 | .icon_lists .icon:hover { 128 | font-size: 100px; 129 | } 130 | 131 | .icon_lists .svg-icon { 132 | /* 通过设置 font-size 来改变图标大小 */ 133 | width: 1em; 134 | /* 图标和文字相邻时,垂直对齐 */ 135 | vertical-align: -0.15em; 136 | /* 通过设置 color 来改变 SVG 的颜色/fill */ 137 | fill: currentColor; 138 | /* path 和 stroke 溢出 viewBox 部分在 IE 下会显示 139 | normalize.css 中也包含这行 */ 140 | overflow: hidden; 141 | } 142 | 143 | .icon_lists li .name, 144 | .icon_lists li .code-name { 145 | color: #666; 146 | } 147 | 148 | /* markdown 样式 */ 149 | .markdown { 150 | color: #666; 151 | font-size: 14px; 152 | line-height: 1.8; 153 | } 154 | 155 | .highlight { 156 | line-height: 1.5; 157 | } 158 | 159 | .markdown img { 160 | vertical-align: middle; 161 | max-width: 100%; 162 | } 163 | 164 | .markdown h1 { 165 | color: #404040; 166 | font-weight: 500; 167 | line-height: 40px; 168 | margin-bottom: 24px; 169 | } 170 | 171 | .markdown h2, 172 | .markdown h3, 173 | .markdown h4, 174 | .markdown h5, 175 | .markdown h6 { 176 | color: #404040; 177 | margin: 1.6em 0 0.6em 0; 178 | font-weight: 500; 179 | clear: both; 180 | } 181 | 182 | .markdown h1 { 183 | font-size: 28px; 184 | } 185 | 186 | .markdown h2 { 187 | font-size: 22px; 188 | } 189 | 190 | .markdown h3 { 191 | font-size: 16px; 192 | } 193 | 194 | .markdown h4 { 195 | font-size: 14px; 196 | } 197 | 198 | .markdown h5 { 199 | font-size: 12px; 200 | } 201 | 202 | .markdown h6 { 203 | font-size: 12px; 204 | } 205 | 206 | .markdown hr { 207 | height: 1px; 208 | border: 0; 209 | background: #e9e9e9; 210 | margin: 16px 0; 211 | clear: both; 212 | } 213 | 214 | .markdown p { 215 | margin: 1em 0; 216 | } 217 | 218 | .markdown>p, 219 | .markdown>blockquote, 220 | .markdown>.highlight, 221 | .markdown>ol, 222 | .markdown>ul { 223 | width: 80%; 224 | } 225 | 226 | .markdown ul>li { 227 | list-style: circle; 228 | } 229 | 230 | .markdown>ul li, 231 | .markdown blockquote ul>li { 232 | margin-left: 20px; 233 | padding-left: 4px; 234 | } 235 | 236 | .markdown>ul li p, 237 | .markdown>ol li p { 238 | margin: 0.6em 0; 239 | } 240 | 241 | .markdown ol>li { 242 | list-style: decimal; 243 | } 244 | 245 | .markdown>ol li, 246 | .markdown blockquote ol>li { 247 | margin-left: 20px; 248 | padding-left: 4px; 249 | } 250 | 251 | .markdown code { 252 | margin: 0 3px; 253 | padding: 0 5px; 254 | background: #eee; 255 | border-radius: 3px; 256 | } 257 | 258 | .markdown strong, 259 | .markdown b { 260 | font-weight: 600; 261 | } 262 | 263 | .markdown>table { 264 | border-collapse: collapse; 265 | border-spacing: 0px; 266 | empty-cells: show; 267 | border: 1px solid #e9e9e9; 268 | width: 95%; 269 | margin-bottom: 24px; 270 | } 271 | 272 | .markdown>table th { 273 | white-space: nowrap; 274 | color: #333; 275 | font-weight: 600; 276 | } 277 | 278 | .markdown>table th, 279 | .markdown>table td { 280 | border: 1px solid #e9e9e9; 281 | padding: 8px 16px; 282 | text-align: left; 283 | } 284 | 285 | .markdown>table th { 286 | background: #F7F7F7; 287 | } 288 | 289 | .markdown blockquote { 290 | font-size: 90%; 291 | color: #999; 292 | border-left: 4px solid #e9e9e9; 293 | padding-left: 0.8em; 294 | margin: 1em 0; 295 | } 296 | 297 | .markdown blockquote p { 298 | margin: 0; 299 | } 300 | 301 | .markdown .anchor { 302 | opacity: 0; 303 | transition: opacity 0.3s ease; 304 | margin-left: 8px; 305 | } 306 | 307 | .markdown .waiting { 308 | color: #ccc; 309 | } 310 | 311 | .markdown h1:hover .anchor, 312 | .markdown h2:hover .anchor, 313 | .markdown h3:hover .anchor, 314 | .markdown h4:hover .anchor, 315 | .markdown h5:hover .anchor, 316 | .markdown h6:hover .anchor { 317 | opacity: 1; 318 | display: inline-block; 319 | } 320 | 321 | .markdown>br, 322 | .markdown>p>br { 323 | clear: both; 324 | } 325 | 326 | 327 | .hljs { 328 | display: block; 329 | background: white; 330 | padding: 0.5em; 331 | color: #333333; 332 | overflow-x: auto; 333 | } 334 | 335 | .hljs-comment, 336 | .hljs-meta { 337 | color: #969896; 338 | } 339 | 340 | .hljs-string, 341 | .hljs-variable, 342 | .hljs-template-variable, 343 | .hljs-strong, 344 | .hljs-emphasis, 345 | .hljs-quote { 346 | color: #df5000; 347 | } 348 | 349 | .hljs-keyword, 350 | .hljs-selector-tag, 351 | .hljs-type { 352 | color: #a71d5d; 353 | } 354 | 355 | .hljs-literal, 356 | .hljs-symbol, 357 | .hljs-bullet, 358 | .hljs-attribute { 359 | color: #0086b3; 360 | } 361 | 362 | .hljs-section, 363 | .hljs-name { 364 | color: #63a35c; 365 | } 366 | 367 | .hljs-tag { 368 | color: #333333; 369 | } 370 | 371 | .hljs-title, 372 | .hljs-attr, 373 | .hljs-selector-id, 374 | .hljs-selector-class, 375 | .hljs-selector-attr, 376 | .hljs-selector-pseudo { 377 | color: #795da3; 378 | } 379 | 380 | .hljs-addition { 381 | color: #55a532; 382 | background-color: #eaffea; 383 | } 384 | 385 | .hljs-deletion { 386 | color: #bd2c00; 387 | background-color: #ffecec; 388 | } 389 | 390 | .hljs-link { 391 | text-decoration: underline; 392 | } 393 | 394 | /* 代码高亮 */ 395 | /* PrismJS 1.15.0 396 | https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript */ 397 | /** 398 | * prism.js default theme for JavaScript, CSS and HTML 399 | * Based on dabblet (http://dabblet.com) 400 | * @author Lea Verou 401 | */ 402 | code[class*="language-"], 403 | pre[class*="language-"] { 404 | color: black; 405 | background: none; 406 | text-shadow: 0 1px white; 407 | font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; 408 | text-align: left; 409 | white-space: pre; 410 | word-spacing: normal; 411 | word-break: normal; 412 | word-wrap: normal; 413 | line-height: 1.5; 414 | 415 | -moz-tab-size: 4; 416 | -o-tab-size: 4; 417 | tab-size: 4; 418 | 419 | -webkit-hyphens: none; 420 | -moz-hyphens: none; 421 | -ms-hyphens: none; 422 | hyphens: none; 423 | } 424 | 425 | pre[class*="language-"]::-moz-selection, 426 | pre[class*="language-"] ::-moz-selection, 427 | code[class*="language-"]::-moz-selection, 428 | code[class*="language-"] ::-moz-selection { 429 | text-shadow: none; 430 | background: #b3d4fc; 431 | } 432 | 433 | pre[class*="language-"]::selection, 434 | pre[class*="language-"] ::selection, 435 | code[class*="language-"]::selection, 436 | code[class*="language-"] ::selection { 437 | text-shadow: none; 438 | background: #b3d4fc; 439 | } 440 | 441 | @media print { 442 | 443 | code[class*="language-"], 444 | pre[class*="language-"] { 445 | text-shadow: none; 446 | } 447 | } 448 | 449 | /* Code blocks */ 450 | pre[class*="language-"] { 451 | padding: 1em; 452 | margin: .5em 0; 453 | overflow: auto; 454 | } 455 | 456 | :not(pre)>code[class*="language-"], 457 | pre[class*="language-"] { 458 | background: #f5f2f0; 459 | } 460 | 461 | /* Inline code */ 462 | :not(pre)>code[class*="language-"] { 463 | padding: .1em; 464 | border-radius: .3em; 465 | white-space: normal; 466 | } 467 | 468 | .token.comment, 469 | .token.prolog, 470 | .token.doctype, 471 | .token.cdata { 472 | color: slategray; 473 | } 474 | 475 | .token.punctuation { 476 | color: #999; 477 | } 478 | 479 | .namespace { 480 | opacity: .7; 481 | } 482 | 483 | .token.property, 484 | .token.tag, 485 | .token.boolean, 486 | .token.number, 487 | .token.constant, 488 | .token.symbol, 489 | .token.deleted { 490 | color: #905; 491 | } 492 | 493 | .token.selector, 494 | .token.attr-name, 495 | .token.string, 496 | .token.char, 497 | .token.builtin, 498 | .token.inserted { 499 | color: #690; 500 | } 501 | 502 | .token.operator, 503 | .token.entity, 504 | .token.url, 505 | .language-css .token.string, 506 | .style .token.string { 507 | color: #9a6e3a; 508 | background: hsla(0, 0%, 100%, .5); 509 | } 510 | 511 | .token.atrule, 512 | .token.attr-value, 513 | .token.keyword { 514 | color: #07a; 515 | } 516 | 517 | .token.function, 518 | .token.class-name { 519 | color: #DD4A68; 520 | } 521 | 522 | .token.regex, 523 | .token.important, 524 | .token.variable { 525 | color: #e90; 526 | } 527 | 528 | .token.important, 529 | .token.bold { 530 | font-weight: bold; 531 | } 532 | 533 | .token.italic { 534 | font-style: italic; 535 | } 536 | 537 | .token.entity { 538 | cursor: help; 539 | } 540 | -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/demo_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IconFont Demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |

19 | 29 |
30 |
31 |
    32 | 33 |
  • 34 | 35 |
    用户名
    36 |
    &#xe63e;
    37 |
  • 38 | 39 |
  • 40 | 41 |
    密码
    42 |
    &#xe635;
    43 |
  • 44 | 45 |
46 |
47 |

Unicode 引用

48 |
49 | 50 |

Unicode 是字体在网页端最原始的应用方式,特点是:

51 |
    52 |
  • 兼容性最好,支持 IE6+,及所有现代浏览器。
  • 53 |
  • 支持按字体的方式去动态调整图标大小,颜色等等。
  • 54 |
  • 但是因为是字体,所以不支持多色。只能使用平台里单色的图标,就算项目里有多色图标也会自动去色。
  • 55 |
56 |
57 |

注意:新版 iconfont 支持多色图标,这些多色图标在 Unicode 模式下将不能使用,如果有需求建议使用symbol 的引用方式

58 |
59 |

Unicode 使用步骤如下:

60 |

第一步:拷贝项目下面生成的 @font-face

61 |
@font-face {
 63 |   font-family: 'iconfont';
 64 |   src: url('iconfont.eot');
 65 |   src: url('iconfont.eot?#iefix') format('embedded-opentype'),
 66 |       url('iconfont.woff2') format('woff2'),
 67 |       url('iconfont.woff') format('woff'),
 68 |       url('iconfont.ttf') format('truetype'),
 69 |       url('iconfont.svg#iconfont') format('svg');
 70 | }
 71 | 
72 |

第二步:定义使用 iconfont 的样式

73 |
.iconfont {
 75 |   font-family: "iconfont" !important;
 76 |   font-size: 16px;
 77 |   font-style: normal;
 78 |   -webkit-font-smoothing: antialiased;
 79 |   -moz-osx-font-smoothing: grayscale;
 80 | }
 81 | 
82 |

第三步:挑选相应图标并获取字体编码,应用于页面

83 |
 84 | <span class="iconfont">&#x33;</span>
 86 | 
87 |
88 |

"iconfont" 是你项目下的 font-family。可以通过编辑项目查看,默认是 "iconfont"。

89 |
90 |
91 |
92 |
93 |
    94 | 95 |
  • 96 | 97 |
    98 | 用户名 99 |
    100 |
    .icon-icon 101 |
    102 |
  • 103 | 104 |
  • 105 | 106 |
    107 | 密码 108 |
    109 |
    .icon-mima 110 |
    111 |
  • 112 | 113 |
114 |
115 |

font-class 引用

116 |
117 | 118 |

font-class 是 Unicode 使用方式的一种变种,主要是解决 Unicode 书写不直观,语意不明确的问题。

119 |

与 Unicode 使用方式相比,具有如下特点:

120 |
    121 |
  • 兼容性良好,支持 IE8+,及所有现代浏览器。
  • 122 |
  • 相比于 Unicode 语意明确,书写更直观。可以很容易分辨这个 icon 是什么。
  • 123 |
  • 因为使用 class 来定义图标,所以当要替换图标时,只需要修改 class 里面的 Unicode 引用。
  • 124 |
  • 不过因为本质上还是使用的字体,所以多色图标还是不支持的。
  • 125 |
126 |

使用步骤如下:

127 |

第一步:引入项目下面生成的 fontclass 代码:

128 |
<link rel="stylesheet" href="./iconfont.css">
129 | 
130 |

第二步:挑选相应图标并获取类名,应用于页面:

131 |
<span class="iconfont icon-xxx"></span>
132 | 
133 |
134 |

" 135 | iconfont" 是你项目下的 font-family。可以通过编辑项目查看,默认是 "iconfont"。

136 |
137 |
138 |
139 |
140 |
    141 | 142 |
  • 143 | 146 |
    用户名
    147 |
    #icon-icon
    148 |
  • 149 | 150 |
  • 151 | 154 |
    密码
    155 |
    #icon-mima
    156 |
  • 157 | 158 |
159 |
160 |

Symbol 引用

161 |
162 | 163 |

这是一种全新的使用方式,应该说这才是未来的主流,也是平台目前推荐的用法。相关介绍可以参考这篇文章 164 | 这种用法其实是做了一个 SVG 的集合,与另外两种相比具有如下特点:

165 |
    166 |
  • 支持多色图标了,不再受单色限制。
  • 167 |
  • 通过一些技巧,支持像字体那样,通过 font-size, color 来调整样式。
  • 168 |
  • 兼容性较差,支持 IE9+,及现代浏览器。
  • 169 |
  • 浏览器渲染 SVG 的性能一般,还不如 png。
  • 170 |
171 |

使用步骤如下:

172 |

第一步:引入项目下面生成的 symbol 代码:

173 |
<script src="./iconfont.js"></script>
174 | 
175 |

第二步:加入通用 CSS 代码(引入一次就行):

176 |
<style>
177 | .icon {
178 |   width: 1em;
179 |   height: 1em;
180 |   vertical-align: -0.15em;
181 |   fill: currentColor;
182 |   overflow: hidden;
183 | }
184 | </style>
185 | 
186 |

第三步:挑选相应图标并获取类名,应用于页面:

187 |
<svg class="icon" aria-hidden="true">
188 |   <use xlink:href="#icon-xxx"></use>
189 | </svg>
190 | 
191 |
192 |
193 | 194 |
195 |
196 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.css: -------------------------------------------------------------------------------- 1 | @font-face {font-family: "iconfont"; 2 | src: url('iconfont.eot?t=1612245259969'); /* IE9 */ 3 | src: url('iconfont.eot?t=1612245259969#iefix') format('embedded-opentype'), /* IE6-IE8 */ 4 | url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAOQAAsAAAAAB3AAAANDAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCDBgqCWII8ATYCJAMMCwgABCAFhG0HNRuBBsgusG3Yk13HdWKMFoVi1t/uhYWXUTw8rdHen5ndEzUsuiWzRDPNdJVQCIkQaeQjefYSdtCuyt7sAc5J6+pgrjJz2XE2Z9T8ClSlUqj+i04o3w2OAgsksgT6ZZfBHrzZ+YZP+8LRs4A3Hc96xyjcCs8TrQGAK57/z+HSpiUwP1Aucw2MegHGAQW2xhK+AzlBv8fYELuf5QTaTcunOVjb3A18FEa7QNzEnA34pBRKTXpoFeqSoUW8Aq3pcVowXvq/H//p4UNSZUbXE5drnKD8l/WV8ssNsC4CczwduFFkbAAU4mKp4QImDGzAaFcE2vr4WhHSWO6/wWeovNr8h0cSRM1I7QRrMJj4ZdmMWGgT1lmnZlCTpKuAV8DADdopy11dsRAdzn3c5sPa70je0+p79O7JujvmhWZrau4febx5TscH0U2Sfo0PxJfezWm3VidJz+HXm2jf3bcz0PouskoA5+5cOBJfHMl0r3DzYdZ0//qxoU8ofHKgaWL4cuQZFUgEe/8tUfP2rUdu6nZ3RI+KjHi6XSlWh11rZnD2KX7r8ktwyQpSpWsCsOnzIT7xe/Cq/ZT3unimrs9VG1YVsmCefSHFlpQT237MB/D+6P0/5lcPj13LZO4FStXItJULqPK94Dmdtd/6feeVoSrqsn/ml+aj6urbrfW1URla30vACqApA8/1Q88Rs/23/I3uk1PRY8E7/7R2FPDT0fyJvakw7ZO0SnDMn8BsWVRUtqHMRWbYDN2UHb0hf0K7atYwLP0+95cM3WgotBqKIWkxBVmrRWTBboBKh41Qa7UH2q1XN7rDAIIRpQ3rbACEXlch6fYRsl7PkQX7CSrDvkCtNxhody4GpuywHNjvAEE2ipzQPgOxQ5ZYS039gvROxE0INpJk+/heRNzYDY06QzZchyRExujhnuRMlLKQJbIIa2E1JAgyVIjsQg6qG6dUKdTr2bIH6RyyCPwcQCA2FOIE2c2AMAeZhHXLU365n++EcCYIbEhNQYWyF0K44eohIx1DC2SdQGpVcC2nuE3imFAUC2IRMhFUCzpEMAMySClv5II4UDrjPXyKQnosxbYV6OYXic+3AtoZ+TlS5CjKqcdrb2HRBgAA') format('woff2'), 5 | url('iconfont.woff?t=1612245259969') format('woff'), 6 | url('iconfont.ttf?t=1612245259969') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */ 7 | url('iconfont.svg?t=1612245259969#iconfont') format('svg'); /* iOS 4.1- */ 8 | } 9 | 10 | [class^="iconfont"], [class*=" iconfont"]{ 11 | font-family: "iconfont" !important; 12 | font-size: 16px; 13 | font-style: normal; 14 | -webkit-font-smoothing: antialiased; 15 | -moz-osx-font-smoothing: grayscale; 16 | } 17 | 18 | .icon-icon:before { 19 | content: "\e63e"; 20 | } 21 | 22 | .icon-mima:before { 23 | content: "\e635"; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.eot -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.js: -------------------------------------------------------------------------------- 1 | !function(e){var t,n,o,i,c,d,a='',l=(l=document.getElementsByTagName("script"))[l.length-1].getAttribute("data-injectcss");if(l&&!e.__iconfont__svg__cssinject__){e.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(e){console&&console.log(e)}}function s(){c||(c=!0,o())}t=function(){var e,t,n,o;(o=document.createElement("div")).innerHTML=a,a=null,(n=o.getElementsByTagName("svg")[0])&&(n.setAttribute("aria-hidden","true"),n.style.position="absolute",n.style.width=0,n.style.height=0,n.style.overflow="hidden",e=n,(t=document.body).firstChild?(o=e,(n=t.firstChild).parentNode.insertBefore(o,n)):t.appendChild(e))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(t,0):(n=function(){document.removeEventListener("DOMContentLoaded",n,!1),t()},document.addEventListener("DOMContentLoaded",n,!1)):document.attachEvent&&(o=t,i=e.document,c=!1,(d=function(){try{i.documentElement.doScroll("left")}catch(e){return void setTimeout(d,50)}s()})(),i.onreadystatechange=function(){"complete"==i.readyState&&(i.onreadystatechange=null,s())})}(window); -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "2361663", 3 | "name": "test", 4 | "font_family": "iconfont", 5 | "css_prefix_text": "icon-", 6 | "description": "", 7 | "glyphs": [ 8 | { 9 | "icon_id": "344459", 10 | "name": "用户名", 11 | "font_class": "icon", 12 | "unicode": "e63e", 13 | "unicode_decimal": 58942 14 | }, 15 | { 16 | "icon_id": "8765228", 17 | "name": "密码", 18 | "font_class": "mima", 19 | "unicode": "e635", 20 | "unicode_decimal": 58933 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | Created by iconfont 9 | 10 | 11 | 12 | 13 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.ttf -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.woff -------------------------------------------------------------------------------- /vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/fonts/font_2361663_kv0jeqzw1y/iconfont.woff2 -------------------------------------------------------------------------------- /vue_admin/src/assets/img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/img/1.png -------------------------------------------------------------------------------- /vue_admin/src/assets/img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/img/2.png -------------------------------------------------------------------------------- /vue_admin/src/assets/img/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/img/3.png -------------------------------------------------------------------------------- /vue_admin/src/assets/img/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/img/4.png -------------------------------------------------------------------------------- /vue_admin/src/assets/img/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/img/5.png -------------------------------------------------------------------------------- /vue_admin/src/assets/img/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/src/assets/img/6.png -------------------------------------------------------------------------------- /vue_admin/src/components/404/404.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 23 | 24 | 25 | 73 | -------------------------------------------------------------------------------- /vue_admin/src/components/custom/Mybread.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 18 | 19 | -------------------------------------------------------------------------------- /vue_admin/src/components/index/index.vue: -------------------------------------------------------------------------------- 1 | 47 | 48 | 72 | 73 | -------------------------------------------------------------------------------- /vue_admin/src/components/login/login.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 88 | 89 | -------------------------------------------------------------------------------- /vue_admin/src/components/permission/menu.vue: -------------------------------------------------------------------------------- 1 | 154 | 155 | 269 | 270 | 275 | -------------------------------------------------------------------------------- /vue_admin/src/components/permission/permissions.vue: -------------------------------------------------------------------------------- 1 | 161 | 162 | 281 | 282 | 287 | -------------------------------------------------------------------------------- /vue_admin/src/components/permission/roles.vue: -------------------------------------------------------------------------------- 1 | 173 | 174 | 364 | 365 | 370 | -------------------------------------------------------------------------------- /vue_admin/src/components/users/users.vue: -------------------------------------------------------------------------------- 1 | 176 | 177 | 279 | 280 | 285 | -------------------------------------------------------------------------------- /vue_admin/src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import ElementUI from 'element-ui'; 5 | import 'element-ui/lib/theme-chalk/index.css'; 6 | import App from './App' 7 | import router from './router' 8 | import "./assets/fonts/font_2361663_kv0jeqzw1y/iconfont.css" 9 | 10 | import Mybread from "@/components/custom/Mybread.vue" 11 | import store from "./store" 12 | 13 | 14 | 15 | Vue.config.productionTip = false 16 | Vue.use(ElementUI); 17 | 18 | Vue.component(Mybread.name,Mybread) 19 | 20 | /* eslint-disable no-new */ 21 | new Vue({ 22 | el: '#app', 23 | store, 24 | router, 25 | components: { App }, 26 | template: '' 27 | }) 28 | -------------------------------------------------------------------------------- /vue_admin/src/plugins/http.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | axios.defaults.timeout = 1000 * 10 4 | 5 | axios.defaults.headers.post['Content-Type'] = "application/json;charset=UTF-8" 6 | 7 | axios.defaults.withCredentials = true 8 | 9 | axios.defaults.baseURL = "http://192.168.110.97:8000"; 10 | // axios.defaults.baseURL = "http://192.168.60.129:8000"; 11 | 12 | axios.interceptors.request.use(function(config) { 13 | const token = sessionStorage.getItem("token") 14 | 15 | if (token) { 16 | config.headers = { 17 | 'token': token 18 | } 19 | } 20 | // console.log(config); 21 | // 在发送请求之前做些什么 22 | return config; 23 | }, function(error) { 24 | // console.log(error); 25 | // 对请求错误做些什么 26 | return Promise.reject(error); 27 | }); 28 | 29 | // 添加响应拦截器 30 | axios.interceptors.response.use(function(response) { 31 | // console.log(response); 32 | // 对响应数据做点什么 33 | return response; 34 | }, function(error) { 35 | // console.log(error); 36 | // 对响应错误做点什么 37 | return Promise.reject(error); 38 | }); 39 | 40 | export default axios -------------------------------------------------------------------------------- /vue_admin/src/plugins/user.js: -------------------------------------------------------------------------------- 1 | import axios from "@/plugins/http.js" 2 | 3 | export function getUserInfo(){ 4 | return axios.get('/rbac/userinfo/') 5 | } -------------------------------------------------------------------------------- /vue_admin/src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import store from '@/store/index.js' 4 | import Login from "@/components/login/login.vue" 5 | import Index from "@/components/index/index.vue" 6 | import Users from "@/components/users/users.vue" 7 | import Roles from "@/components/permission/roles.vue" 8 | import Menu from "@/components/permission/menu.vue" 9 | import Permissions from "@/components/permission/permissions.vue" 10 | import Notfound from "@/components/404/404.vue" 11 | 12 | 13 | 14 | const originalPush = Router.prototype.push 15 | Router.prototype.push = function push(location) { 16 | return originalPush.call(this, location).catch(err => err) 17 | } 18 | Vue.use(Router) 19 | 20 | const router = new Router({ 21 | routes: [{ 22 | name: "login", 23 | path: '/login', 24 | component: Login 25 | }] 26 | }) 27 | 28 | export const asyncRoutes = [ 29 | 30 | { 31 | name: "uesrs", 32 | path: '/users', 33 | component: Users 34 | }, , { 35 | name: "menu", 36 | path: "/menus", 37 | component: Menu 38 | }, 39 | { 40 | name: "roles", 41 | path: "/roles", 42 | component: Roles 43 | }, { 44 | name: "permission", 45 | path: "/permissions", 46 | component: Permissions 47 | }, 48 | 49 | ] 50 | 51 | 52 | 53 | export function menusToRoutes(data) { 54 | const result = [] 55 | const children = [] 56 | 57 | result.push({ 58 | name: "index", 59 | path: '/', 60 | component: Index, 61 | children, 62 | }) 63 | 64 | data.forEach(item => { 65 | generateRoutes(children, item) 66 | }) 67 | 68 | children.push({ 69 | name: "404", 70 | path: "/404", 71 | component: Notfound 72 | }) 73 | 74 | // 最后添加404页面 否则会在登陆成功后跳到404页面 75 | result.push({ path: '*', redirect: '/404' }, ) 76 | return result 77 | } 78 | 79 | // 将菜单信息转成对应的路由信息 动态添加 80 | function generateRoutes(children, item) { 81 | asyncRoutes.forEach(function(routeitem) { 82 | if (item.name == routeitem.name) { 83 | children.push(routeitem) 84 | } 85 | }) 86 | } 87 | 88 | 89 | router.beforeEach((to, from, next) => { 90 | if (to.name == "login") { 91 | next() 92 | } else { 93 | const token = sessionStorage.getItem("token") 94 | if (!token) { 95 | router.push({ name: "login" }) 96 | } 97 | const menu = store.state.menu 98 | if (menu.length == 0) { 99 | store.commit("setUserInfo") 100 | router.push(window.location.hash.split("#/")[1]) 101 | } 102 | next() 103 | } 104 | 105 | }) 106 | 107 | 108 | export default router -------------------------------------------------------------------------------- /vue_admin/src/session/index.js: -------------------------------------------------------------------------------- 1 | function setUsername(ret){ 2 | sessionStorage.setItem("username",ret.data.data.username) 3 | } 4 | 5 | function setMenu(ret){ 6 | sessionStorage.setItem("menu",JSON.stringify(ret.data.data.menu) ) 7 | } 8 | 9 | function setPermission(ret){ 10 | sessionStorage.setItem("permission",JSON.stringify(ret.data.data.permission) ) 11 | } 12 | 13 | function setRouter(ret){ 14 | sessionStorage.setItem("router",JSON.stringify(ret.data.data.router) ) 15 | } 16 | 17 | function getUsername(){ 18 | return sessionStorage.getItem("username") 19 | } 20 | 21 | function getMenu(){ 22 | return JSON.parse(sessionStorage.getItem("menu")) 23 | } 24 | 25 | function getPermission(){ 26 | return JSON.parse(sessionStorage.getItem("permission")) 27 | } 28 | 29 | function getRouter(){ 30 | return JSON.parse(sessionStorage.getItem("router")) 31 | } 32 | 33 | 34 | export {setUsername,setMenu,setPermission,setRouter,getUsername,getMenu,getPermission,getRouter} -------------------------------------------------------------------------------- /vue_admin/src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | import {getUserInfo} from "@/plugins/user.js" 4 | import router from "@/router/index.js" 5 | import { menusToRoutes } from "@/router/index.js" 6 | 7 | Vue.use(Vuex) 8 | 9 | const store = new Vuex.Store({ 10 | state:{ 11 | username:'', 12 | menu:[], 13 | permission:[], 14 | }, 15 | mutations:{ 16 | setUserInfo(state){ 17 | const menu = sessionStorage.getItem("menu") 18 | if(!menu){ 19 | getUserInfo().then(ret=>{ 20 | sessionStorage.setItem("username",ret.data.data.username) 21 | sessionStorage.setItem("menu",JSON.stringify(ret.data.data.menu) ) 22 | sessionStorage.setItem("permission",JSON.stringify(ret.data.data.permission) ) 23 | sessionStorage.setItem("router",JSON.stringify(ret.data.data.router) ) 24 | state.username = ret.data.data.username 25 | state.menu = ret.data.data.menu 26 | state.permission = ret.data.data.permission 27 | state.router = ret.data.data.router 28 | 29 | const newRouter = menusToRoutes(state.router) 30 | newRouter.forEach(el =>{ 31 | router.addRoute(el) 32 | }) 33 | }) 34 | }else{ 35 | state.username = sessionStorage.getItem("username") 36 | state.menu = JSON.parse(sessionStorage.getItem("menu")) 37 | state.permission = JSON.parse(sessionStorage.getItem("permission")) 38 | state.router = JSON.parse(sessionStorage.getItem("router")) 39 | 40 | const newRouter = menusToRoutes(state.router) 41 | newRouter.forEach(el =>{ 42 | router.addRoute(el) 43 | }) 44 | } 45 | 46 | }, 47 | } 48 | }) 49 | 50 | 51 | export default store -------------------------------------------------------------------------------- /vue_admin/src/utils/index.js: -------------------------------------------------------------------------------- 1 | export function dateFormat(originVal) { 2 | const dt = new Date(originVal) 3 | 4 | const y = dt.getFullYear() 5 | const m = (dt.getMonth() + 1 + '').padStart(2, '0') 6 | const d = (dt.getDate() + '').padStart(2, '0') 7 | 8 | const hh = (dt.getHours() + '').padStart(2, '0') 9 | const mm = (dt.getMinutes() + '').padStart(2, '0') 10 | const ss = (dt.getSeconds() + '').padStart(2, '0') 11 | 12 | return `${y}-${m}-${d} ${hh}:${mm}:${ss}` 13 | } 14 | 15 | export function deepClone(obj) { 16 | var o; 17 | // 如果 他是对象object的话 , 因为null,object,array 也是'object'; 18 | if (typeof obj === 'object') { 19 | 20 | // 如果 他是空的话 21 | if (obj === null) { 22 | o = null; 23 | } else { 24 | 25 | // 如果 他是数组arr的话 26 | if (obj instanceof Array) { 27 | o = []; 28 | for (var i = 0, len = obj.length; i < len; i++) { 29 | o.push(deepClone(obj[i])); 30 | } 31 | } 32 | // 如果 他是对象object的话 33 | else { 34 | o = {}; 35 | for (var j in obj) { 36 | o[j] = deepClone(obj[j]); 37 | } 38 | } 39 | 40 | } 41 | } else { 42 | o = obj; 43 | } 44 | return o; 45 | }; -------------------------------------------------------------------------------- /vue_admin/static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiumozhou/django_vue_rbac/10d5b14faf377a1c02122f5db16fe8d91547c14d/vue_admin/static/.gitkeep --------------------------------------------------------------------------------