Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
194a2254a6 | ||
|
26abad14d0 | ||
|
1521a71f9c | ||
|
d425b455f1 | ||
|
230307474b | ||
|
69d6b40e39 | ||
|
5dc2f89e7f | ||
|
9eaca4d6a0 | ||
|
3680a462f5 | ||
|
3ac50e7cd8 | ||
|
21b2cc1d5d | ||
|
cd5448cc7d | ||
|
10610bdb4b | ||
|
b5c2156387 | ||
|
b05ae0d1a7 | ||
|
bbf6138d43 | ||
|
1ba3e6a680 | ||
|
64045c1f93 | ||
|
5a3e55813c | ||
|
bc72e58886 | ||
|
9e78955ba1 | ||
|
136853d9a4 | ||
|
036e3ad00d | ||
|
5ce6c93237 | ||
|
43dba7f7ed | ||
|
f4879d20d6 | ||
|
740e4c6034 | ||
|
0f2baa1d94 | ||
|
405b0af72c | ||
|
a4e5178979 | ||
|
c14fe23283 | ||
|
b3a058f908 | ||
|
bd82a0e27c | ||
|
f22a5c3543 | ||
|
ed81c3f091 | ||
|
07814b85f9 | ||
|
db52b28d6b | ||
|
fc85ba21c8 | ||
|
6c5ee3fcd9 | ||
|
40f1ef88a9 | ||
|
bce422ffc8 | ||
|
7c79066532 | ||
|
1129ac93fb | ||
|
5ab0e7e737 | ||
|
23319c7417 | ||
|
c74f85cabb | ||
|
fce2b689fb | ||
|
105327bb0c | ||
|
745c43d0a4 | ||
|
3130d94568 | ||
|
04a66eb239 | ||
|
68390ec6f1 | ||
|
17392be138 | ||
|
f2fdb29221 | ||
|
4a18698423 | ||
|
95ccee04f9 | ||
|
b60628247b | ||
|
a6d7699ab4 | ||
|
4b21bcc438 | ||
|
33dce2f0f3 | ||
|
d43b827fe5 | ||
|
aec8bade41 | ||
|
89ae89a449 | ||
|
945f90e386 | ||
|
2ba6a16613 |
1
.gitignore
vendored
@@ -38,6 +38,7 @@ pip-log.txt
|
||||
.tox
|
||||
nosetests.xml
|
||||
.pytest_cache
|
||||
cmdb-api/test-output
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
181
README.md
@@ -1,6 +1,7 @@
|
||||
<h1 align="center">CMDB</h1>
|
||||
<div align="center">
|
||||
尽可能实现比较通用的运维资产数据的配置和管理
|
||||
|
||||
As far as possible to achieve more universal configuration and management of IT resources
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
@@ -12,101 +13,113 @@
|
||||
</div>
|
||||
|
||||
|
||||
[English](README.md) / [中文](README_cn.md)
|
||||
|
||||
- 在线预览: [CMDB](http://121.42.12.46:8000)
|
||||
## DEMO ONLINE
|
||||
- preview online: [CMDB](http://121.42.12.46:8000)
|
||||
- username: demo
|
||||
- password: 123456
|
||||
|
||||
> **重要提示**: `master` 分支在开发过程中可能处于 *不稳定的状态* 。
|
||||
请通过[releases](https://github.com/pycook/cmdb/releases)获取
|
||||
> **ATTENTION**: branch `master` may be unstable as the result of continued development, please pull code from [releases](https://github.com/pycook/cmdb/releases)
|
||||
|
||||
----
|
||||
## Overview
|
||||
|
||||
CMDB is a universal project that can define and manage almost all IT resource, even every resource as long as you want to, which treat all IT resources as resource objects. objects has both attributes and relationship.
|
||||
|
||||
CMDB's main distinguishing features as compared to other resource systems are:
|
||||
- define attributes of resource objects dynamically,you don't need to define all the attributes at the beginning.
|
||||
- define relationship of resource objects dynamically and simply, even you can draw the relationship through the web.
|
||||
- three view:
|
||||
- resource view: model instance data that users can subscribe
|
||||
- tree view: the model is hierarchical by field, shown in a tree diagram, and users can subscribe
|
||||
- relational view: relationships between models, shown in a tree diagram, **are configurable by the administrator**
|
||||
|
||||
- authority management
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
There are various ways of installing CMDB.
|
||||
|
||||
### Install by Docker
|
||||
- prepare: install docker and docker-compose
|
||||
- in directory cmdb
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
- view: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||
|
||||
### Environment and dependency
|
||||
- database: mysql
|
||||
- cache: redis
|
||||
- python: python2.7, >=python3.6
|
||||
|
||||
### install
|
||||
- start mysql, redis
|
||||
- create mysql database: cmdb
|
||||
- pull code
|
||||
```bash
|
||||
git clone https://github.com/pycook/cmdb.git
|
||||
cd cmdb
|
||||
cp cmdb-api/settings.py.example cmdb-api/settings.py
|
||||
```
|
||||
**set database in config file cmdb-api/settings.py**
|
||||
|
||||
- install library
|
||||
- backend: ```cd cmdb-api && pipenv run pipenv install && cd ..```
|
||||
- frontend: ```cd cmdb-ui && yarn install && cd ..```
|
||||
|
||||
- create tables of cmdb database:
|
||||
|
||||
Overview
|
||||
----
|
||||
### 3种类型视图
|
||||
1. 资源视图 - 模型的实例数据, 用户可订阅
|
||||
2. 树形视图 - 模型按字段分级, 用树形图方式展示, 用户可订阅
|
||||
3. 关系视图 - 模型之间的关系, 用树形图方式展示, **管理员可配置**
|
||||
in **cmdb-api** directory: ```pipenv run flask db-setup && pipenv run flask init-cache```
|
||||
- suggest step: (default: user:demo,password:123456)
|
||||
|
||||
##### 资源视图
|
||||

|
||||
``` source docs/cmdb.sql```
|
||||
|
||||
##### 树形视图
|
||||

|
||||
|
||||
##### 关系视图
|
||||

|
||||
|
||||
##### 用户订阅
|
||||

|
||||
|
||||
##### 关系视图配置
|
||||

|
||||
|
||||
Docker一键快速构建
|
||||
----
|
||||
- 进入主目录(先安装docker环境)
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
- 浏览器打开: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||
|
||||
|
||||
本地搭建: 环境和依赖
|
||||
----
|
||||
- 存储: mysql, redis
|
||||
- python版本: python2.7, >=python3.6
|
||||
|
||||
Install
|
||||
----
|
||||
- 启动mysql服务, redis服务
|
||||
|
||||
- 创建数据库cmdb
|
||||
- 拉取代码
|
||||
```bash
|
||||
git clone https://github.com/pycook/cmdb.git
|
||||
cd cmdb
|
||||
cp cmdb-api/settings.py.example cmdb-api/settings.py
|
||||
```
|
||||
**设置cmdb-api/settings.py里的database**
|
||||
|
||||
- 安装库
|
||||
- 后端: ```cd cmdb-api && pipenv run pipenv install && cd ..```
|
||||
- 前端: ```cd cmdb-ui && yarn install && cd ..```
|
||||
- start service
|
||||
- backend: in **cmdb-api** directory: ```pipenv run flask run -h 0.0.0.0```
|
||||
- frontend: in **cmdb-ui** directory: ```yarn run serve```
|
||||
- worker: in **cmdb-api** directory: ```pipenv run celery worker -A celery_worker.celery -E -Q cmdb_async --concurrency=1```
|
||||
|
||||
- 创建数据库表 ```pipenv run flask db-setup && pipenv run flask init-cache```
|
||||
- 可以将docs/cmdb.sql导入到数据库里,登录用户和密码分别是:demo/123456
|
||||
|
||||
- 启动服务
|
||||
- 后端: 进入**cmdb-api**目录执行 ```pipenv run flask run -h 0.0.0.0```
|
||||
- 前端: 进入**cmdb-ui**目录执行```yarn run serve```
|
||||
- worker: 进入**cmdb-api**目录执行 ```pipenv run celery worker -A celery_worker.celery -E -Q cmdb_async --concurrency=1```
|
||||
|
||||
- 浏览器打开: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||
- 如果是非本机访问, 要修改**cmdb-ui/.env**里**VUE_APP_API_BASE_URL**里的IP地址为后端服务的ip地址
|
||||
- homepage: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||
- if not run localhost: please change ip address(**VUE_APP_API_BASE_URL**) in config file **cmdb-ui/.env** into your backend ip address
|
||||
|
||||
### Install by Makefile
|
||||
- start mysql,redis
|
||||
- create mysql database: cmdb
|
||||
- pull code
|
||||
```bash
|
||||
git clone https://github.com/pycook/cmdb.git
|
||||
cd cmdb
|
||||
cp cmdb-api/settings.py.example cmdb-api/settings.py
|
||||
```
|
||||
**set database in config file cmdb-api/settings.py**
|
||||
|
||||
- in cmdb directory,start in order as follows:
|
||||
- enviroment: ```make env```
|
||||
- start API: ```make api```
|
||||
- start UI: ```make ui```
|
||||
- start worker: ```make worker```
|
||||
|
||||
|
||||
Install by Makefile
|
||||
----
|
||||
- 启动mysql服务, redis服务
|
||||
## DEMO
|
||||
##### resource view
|
||||

|
||||
|
||||
- 创建数据库cmdb
|
||||
- 拉取代码
|
||||
```bash
|
||||
git clone https://github.com/pycook/cmdb.git
|
||||
cd cmdb
|
||||
cp cmdb-api/settings.py.example cmdb-api/settings.py
|
||||
```
|
||||
**cmdb-api/settings.py里的database**
|
||||
##### tree view
|
||||

|
||||
|
||||
- 顺序在cmdb目录下执行
|
||||
- 环境: ```make env```
|
||||
- 启动API: ```make api```
|
||||
- 启动UI: ```make ui```
|
||||
- 启动worker: ```make worker```
|
||||
##### relationship view
|
||||

|
||||
|
||||
##### user subscription
|
||||

|
||||
|
||||
----
|
||||
_**欢迎加入CMDB运维开发QQ群(336164978)**_
|
||||
##### define relationship view
|
||||

|
||||
|
||||

|
||||
-----
|
||||
_**welcome to join us through QQ group(336164978)**_
|
||||
|
||||

|
||||
|
112
README_cn.md
Normal file
@@ -0,0 +1,112 @@
|
||||
<h1 align="center">CMDB</h1>
|
||||
<div align="center">
|
||||
尽可能实现比较通用的运维资源的配置和管理
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||
[](https://github.com/pycook/cmdb/blob/master/LICENSE)
|
||||
[](https://github.com/sendya/ant-design-pro-vue)
|
||||
[](https://github.com/pallets/flask)
|
||||
|
||||
</div>
|
||||
|
||||
[English](README.md) / [中文](README_cn.md)
|
||||
|
||||
- 在线预览: [CMDB](http://121.42.12.46:8000)
|
||||
- username: demo
|
||||
- password: 123456
|
||||
|
||||
> **重要提示**: `master` 分支在开发过程中可能处于 *不稳定的状态* 。
|
||||
请通过[releases](https://github.com/pycook/cmdb/releases)获取
|
||||
|
||||
Overview
|
||||
----
|
||||
### 3种类型视图
|
||||
1. 资源视图 - 模型的实例数据, 用户可订阅
|
||||
2. 树形视图 - 模型按字段分级, 用树形图方式展示, 用户可订阅
|
||||
3. 关系视图 - 模型之间的关系, 用树形图方式展示, **管理员可配置**
|
||||
|
||||
##### 资源视图
|
||||

|
||||
|
||||
##### 树形视图
|
||||

|
||||
|
||||
##### 关系视图
|
||||

|
||||
|
||||
##### 用户订阅
|
||||

|
||||
|
||||
##### 关系视图配置
|
||||

|
||||
|
||||
Docker一键快速构建
|
||||
----
|
||||
- 进入主目录(先安装docker环境)
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
- 浏览器打开: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||
|
||||
|
||||
本地搭建: 环境和依赖
|
||||
----
|
||||
- 存储: mysql, redis
|
||||
- python版本: python2.7, >=python3.6
|
||||
|
||||
Install
|
||||
----
|
||||
- 启动mysql服务, redis服务
|
||||
|
||||
- 创建数据库cmdb
|
||||
- 拉取代码
|
||||
```bash
|
||||
git clone https://github.com/pycook/cmdb.git
|
||||
cd cmdb
|
||||
cp cmdb-api/settings.py.example cmdb-api/settings.py
|
||||
```
|
||||
**设置cmdb-api/settings.py里的database**
|
||||
|
||||
- 安装库
|
||||
- 后端: ```cd cmdb-api && pipenv run pipenv install && cd ..```
|
||||
- 前端: ```cd cmdb-ui && yarn install && cd ..```
|
||||
|
||||
- 创建数据库表: 进入**cmdb-api**目录执行 ```pipenv run flask db-setup && pipenv run flask init-cache```
|
||||
- 可以将docs/cmdb.sql导入到数据库里,登录用户和密码分别是:demo/123456
|
||||
|
||||
- 启动服务
|
||||
- 后端: 进入**cmdb-api**目录执行 ```pipenv run flask run -h 0.0.0.0```
|
||||
- 前端: 进入**cmdb-ui**目录执行```yarn run serve```
|
||||
- worker: 进入**cmdb-api**目录执行 ```pipenv run celery worker -A celery_worker.celery -E -Q cmdb_async --concurrency=1```
|
||||
|
||||
- 浏览器打开: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||
- 如果是非本机访问, 要修改**cmdb-ui/.env**里**VUE_APP_API_BASE_URL**里的IP地址为后端服务的ip地址
|
||||
|
||||
|
||||
Install by Makefile
|
||||
----
|
||||
- 启动mysql服务, redis服务
|
||||
|
||||
- 创建数据库cmdb
|
||||
- 拉取代码
|
||||
```bash
|
||||
git clone https://github.com/pycook/cmdb.git
|
||||
cd cmdb
|
||||
cp cmdb-api/settings.py.example cmdb-api/settings.py
|
||||
```
|
||||
**设置cmdb-api/settings.py里的database**
|
||||
|
||||
- 顺序在cmdb目录下执行
|
||||
- 环境: ```make env```
|
||||
- 启动API: ```make api```
|
||||
- 启动UI: ```make ui```
|
||||
- 启动worker: ```make worker```
|
||||
|
||||
|
||||
----
|
||||
_**欢迎加入CMDB运维开发QQ群(336164978)**_
|
||||
|
||||

|
16
cmdb-api/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
default: help
|
||||
|
||||
test: ## test in local environment
|
||||
pytest -s --html=test-output/test/index.html --cov-report html:test-output/coverage --cov=api tests
|
||||
|
||||
clean_test: ## clean test output
|
||||
rm -f .coverage
|
||||
rm -rf .pytest_cache
|
||||
rm -rf test-output
|
||||
|
||||
|
||||
docker_test: ## test all case in docker container
|
||||
@echo "TODO"
|
||||
|
||||
help:
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' ./Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
@@ -41,6 +41,7 @@ toposort = ">=1.5"
|
||||
requests = ">=2.22.0"
|
||||
PyJWT = ">=1.7.1"
|
||||
elasticsearch = "==7.0.4"
|
||||
future = "==0.18.2"
|
||||
|
||||
[dev-packages]
|
||||
# Testing
|
||||
|
@@ -107,13 +107,13 @@ class RelationTypeCache(object):
|
||||
cache.delete(cls.PREFIX_ID.format(ct.id))
|
||||
|
||||
|
||||
class CITypeAttributeCache(object):
|
||||
class CITypeAttributesCache(object):
|
||||
"""
|
||||
key is type_id or type_name
|
||||
"""
|
||||
|
||||
PREFIX_ID = "CITypeAttribute::ID::{0}"
|
||||
PREFIX_NAME = "CITypeAttribute::Name::{0}"
|
||||
PREFIX_ID = "CITypeAttributes::TypeID::{0}"
|
||||
PREFIX_NAME = "CITypeAttributes::TypeName::{0}"
|
||||
|
||||
@classmethod
|
||||
def get(cls, key):
|
||||
@@ -146,3 +146,30 @@ class CITypeAttributeCache(object):
|
||||
if attrs is not None and ci_type:
|
||||
cache.delete(cls.PREFIX_ID.format(ci_type.id))
|
||||
cache.delete(cls.PREFIX_NAME.format(ci_type.name))
|
||||
|
||||
|
||||
class CITypeAttributeCache(object):
|
||||
"""
|
||||
key is type_id & attr_id
|
||||
"""
|
||||
|
||||
PREFIX_ID = "CITypeAttribute::TypeID::{0}::AttrID::{1}"
|
||||
|
||||
@classmethod
|
||||
def get(cls, type_id, attr_id):
|
||||
|
||||
attr = cache.get(cls.PREFIX_ID.format(type_id, attr_id))
|
||||
attr = attr or cache.get(cls.PREFIX_ID.format(type_id, attr_id))
|
||||
if not attr:
|
||||
attr = CITypeAttribute.get_by(type_id=type_id, attr_id=attr_id, first=True, to_dict=False)
|
||||
if attr is not None:
|
||||
cls.set(type_id, attr_id, attr)
|
||||
return attr
|
||||
|
||||
@classmethod
|
||||
def set(cls, type_id, attr_id, attr):
|
||||
cache.set(cls.PREFIX_ID.format(type_id, attr_id), attr)
|
||||
|
||||
@classmethod
|
||||
def clean(cls, type_id, attr_id):
|
||||
cache.delete(cls.PREFIX_ID.format(type_id, attr_id))
|
||||
|
@@ -190,7 +190,7 @@ class CIManager(object):
|
||||
value_manager = AttributeValueManager()
|
||||
for p, v in ci_dict.items():
|
||||
try:
|
||||
value_manager.create_or_update_attr_value(p, v, ci.id, _no_attribute_policy)
|
||||
value_manager.create_or_update_attr_value(p, v, ci, _no_attribute_policy)
|
||||
except BadRequest as e:
|
||||
if existed is None:
|
||||
cls.delete(ci.id)
|
||||
@@ -201,11 +201,12 @@ class CIManager(object):
|
||||
return ci.id
|
||||
|
||||
def update(self, ci_id, **ci_dict):
|
||||
self.confirm_ci_existed(ci_id)
|
||||
ci = self.confirm_ci_existed(ci_id)
|
||||
|
||||
value_manager = AttributeValueManager()
|
||||
for p, v in ci_dict.items():
|
||||
try:
|
||||
value_manager.create_or_update_attr_value(p, v, ci_id)
|
||||
value_manager.create_or_update_attr_value(p, v, ci)
|
||||
except BadRequest as e:
|
||||
raise e
|
||||
|
||||
@@ -213,9 +214,9 @@ class CIManager(object):
|
||||
|
||||
@staticmethod
|
||||
def update_unique_value(ci_id, unique_name, unique_value):
|
||||
CI.get_by_id(ci_id) or abort(404, "CI <{0}> is not found".format(ci_id))
|
||||
ci = CI.get_by_id(ci_id) or abort(404, "CI <{0}> is not found".format(ci_id))
|
||||
|
||||
AttributeValueManager().create_or_update_attr_value(unique_name, unique_value, ci_id)
|
||||
AttributeValueManager().create_or_update_attr_value(unique_name, unique_value, ci)
|
||||
|
||||
ci_cache.apply_async([ci_id], queue=CMDB_QUEUE)
|
||||
|
||||
|
@@ -8,7 +8,10 @@ from api.extensions import db
|
||||
from api.lib.cmdb.attribute import AttributeManager
|
||||
from api.lib.cmdb.cache import AttributeCache
|
||||
from api.lib.cmdb.cache import CITypeAttributeCache
|
||||
from api.lib.cmdb.cache import CITypeAttributesCache
|
||||
from api.lib.cmdb.cache import CITypeCache
|
||||
from api.lib.cmdb.const import CMDB_QUEUE
|
||||
from api.lib.cmdb.value import AttributeValueManager
|
||||
from api.lib.decorator import kwargs_required
|
||||
from api.models.cmdb import CI
|
||||
from api.models.cmdb import CIType
|
||||
@@ -18,8 +21,8 @@ from api.models.cmdb import CITypeAttributeGroupItem
|
||||
from api.models.cmdb import CITypeGroup
|
||||
from api.models.cmdb import CITypeGroupItem
|
||||
from api.models.cmdb import CITypeRelation
|
||||
from api.models.cmdb import PreferenceTreeView
|
||||
from api.models.cmdb import PreferenceShowAttributes
|
||||
from api.models.cmdb import PreferenceTreeView
|
||||
|
||||
|
||||
class CITypeManager(object):
|
||||
@@ -36,7 +39,9 @@ class CITypeManager(object):
|
||||
|
||||
@staticmethod
|
||||
def check_is_existed(key):
|
||||
return CITypeCache.get(key) or abort(404, "CIType <{0}> is not existed".format(key))
|
||||
ci_type = CITypeCache.get(key) or abort(404, "CIType <{0}> is not existed".format(key))
|
||||
|
||||
return CIType.get_by_id(ci_type.id)
|
||||
|
||||
@staticmethod
|
||||
def get_ci_types(type_name=None):
|
||||
@@ -52,16 +57,35 @@ class CITypeManager(object):
|
||||
ci_type = CITypeCache.get(_type) or abort(404, "CIType <{0}> is not found".format(_type))
|
||||
return ci_type.to_dict()
|
||||
|
||||
@staticmethod
|
||||
def _validate_unique(type_id=None, name=None, alias=None):
|
||||
if name is not None:
|
||||
ci_type = CIType.get_by(name=name, first=True, to_dict=False)
|
||||
elif alias is not None:
|
||||
ci_type = CIType.get_by(alias=alias, first=True, to_dict=False)
|
||||
else:
|
||||
return
|
||||
|
||||
if not ci_type:
|
||||
return
|
||||
|
||||
if type_id is not None and ci_type.id != type_id:
|
||||
return abort(400, "CIType <{0}> is already existed".format(name or alias))
|
||||
|
||||
if type_id is None and ci_type is not None:
|
||||
return abort(400, "CIType <{0}> is already existed".format(name or alias))
|
||||
|
||||
@classmethod
|
||||
@kwargs_required("name")
|
||||
def add(cls, **kwargs):
|
||||
unique_key = kwargs.pop("unique_key", None)
|
||||
unique_key = AttributeCache.get(unique_key) or abort(404, "Unique key is not defined")
|
||||
|
||||
CIType.get_by(name=kwargs['name']) and abort(404, "CIType <{0}> is already existed".format(kwargs.get("name")))
|
||||
|
||||
kwargs["alias"] = kwargs["name"] if not kwargs.get("alias") else kwargs["alias"]
|
||||
|
||||
cls._validate_unique(name=kwargs['name'])
|
||||
cls._validate_unique(alias=kwargs['alias'])
|
||||
|
||||
kwargs["unique_id"] = unique_key.id
|
||||
ci_type = CIType.create(**kwargs)
|
||||
|
||||
@@ -85,6 +109,9 @@ class CITypeManager(object):
|
||||
|
||||
ci_type = cls.check_is_existed(type_id)
|
||||
|
||||
cls._validate_unique(type_id=type_id, name=kwargs.get('name'))
|
||||
cls._validate_unique(type_id=type_id, alias=kwargs.get('alias'))
|
||||
|
||||
unique_key = kwargs.pop("unique_key", None)
|
||||
unique_key = AttributeCache.get(unique_key)
|
||||
if unique_key is not None:
|
||||
@@ -201,11 +228,11 @@ class CITypeAttributeManager(object):
|
||||
|
||||
@staticmethod
|
||||
def get_attr_names_by_type_id(type_id):
|
||||
return [AttributeCache.get(attr.attr_id).name for attr in CITypeAttributeCache.get(type_id)]
|
||||
return [AttributeCache.get(attr.attr_id).name for attr in CITypeAttributesCache.get(type_id)]
|
||||
|
||||
@staticmethod
|
||||
def get_attributes_by_type_id(type_id):
|
||||
attrs = CITypeAttributeCache.get(type_id)
|
||||
attrs = CITypeAttributesCache.get(type_id)
|
||||
result = list()
|
||||
for attr in sorted(attrs, key=lambda x: (x.order, x.id)):
|
||||
attr_dict = AttributeManager().get_attribute(attr.attr_id)
|
||||
@@ -247,7 +274,7 @@ class CITypeAttributeManager(object):
|
||||
current_app.logger.debug(attr_id)
|
||||
CITypeAttribute.create(type_id=type_id, attr_id=attr_id, **kwargs)
|
||||
|
||||
CITypeAttributeCache.clean(type_id)
|
||||
CITypeAttributesCache.clean(type_id)
|
||||
|
||||
@classmethod
|
||||
def update(cls, type_id, attributes):
|
||||
@@ -269,7 +296,9 @@ class CITypeAttributeManager(object):
|
||||
|
||||
existed.update(**attr)
|
||||
|
||||
CITypeAttributeCache.clean(type_id)
|
||||
CITypeAttributeCache.clean(type_id, existed.attr_id)
|
||||
|
||||
CITypeAttributesCache.clean(type_id)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, type_id, attr_ids=None):
|
||||
@@ -279,6 +308,8 @@ class CITypeAttributeManager(object):
|
||||
:param attr_ids: list
|
||||
:return:
|
||||
"""
|
||||
from api.tasks.cmdb import ci_cache
|
||||
|
||||
cls._check(type_id, attr_ids)
|
||||
|
||||
for attr_id in attr_ids:
|
||||
@@ -289,7 +320,40 @@ class CITypeAttributeManager(object):
|
||||
if existed is not None:
|
||||
existed.soft_delete()
|
||||
|
||||
CITypeAttributeCache.clean(type_id)
|
||||
for ci in CI.get_by(type_id=type_id, to_dict=False):
|
||||
AttributeValueManager.delete_attr_value(attr_id, ci.id)
|
||||
|
||||
ci_cache.apply_async([ci.id], queue=CMDB_QUEUE)
|
||||
|
||||
CITypeAttributeCache.clean(type_id, attr_id)
|
||||
|
||||
CITypeAttributesCache.clean(type_id)
|
||||
|
||||
@classmethod
|
||||
def transfer(cls, type_id, _from, _to):
|
||||
current_app.logger.info("[{0}] {1} -> {2}".format(type_id, _from, _to))
|
||||
attr_id = _from.get('attr_id')
|
||||
from_group_id = _from.get('group_id')
|
||||
to_group_id = _to.get('group_id')
|
||||
order = _to.get('order')
|
||||
|
||||
if from_group_id != to_group_id:
|
||||
if from_group_id is not None:
|
||||
CITypeAttributeGroupManager.delete_item(from_group_id, attr_id)
|
||||
|
||||
if to_group_id is not None:
|
||||
CITypeAttributeGroupManager.add_item(to_group_id, attr_id, order)
|
||||
|
||||
elif from_group_id:
|
||||
CITypeAttributeGroupManager.update_item(from_group_id, attr_id, order)
|
||||
|
||||
else: # other attribute transfer
|
||||
return abort(400, "invalid operation!!!")
|
||||
|
||||
CITypeAttributesCache.clean(type_id)
|
||||
|
||||
from api.tasks.cmdb import ci_type_attribute_order_rebuild
|
||||
ci_type_attribute_order_rebuild.apply_async(args=(type_id,), queue=CMDB_QUEUE)
|
||||
|
||||
|
||||
class CITypeRelationManager(object):
|
||||
@@ -427,6 +491,8 @@ class CITypeAttributeGroupManager(object):
|
||||
return abort(400, "Group <{0}> duplicate".format(name))
|
||||
if name is not None:
|
||||
group.update(name=name)
|
||||
else:
|
||||
name = group.name
|
||||
|
||||
cls.create_or_update(group.type_id, name, attr_order, group_order)
|
||||
|
||||
@@ -441,3 +507,87 @@ class CITypeAttributeGroupManager(object):
|
||||
item.soft_delete()
|
||||
|
||||
return group_id
|
||||
|
||||
@classmethod
|
||||
def add_item(cls, group_id, attr_id, order):
|
||||
db.session.remove()
|
||||
|
||||
existed = CITypeAttributeGroupItem.get_by(group_id=group_id,
|
||||
attr_id=attr_id,
|
||||
first=True,
|
||||
to_dict=False)
|
||||
if existed is not None:
|
||||
existed.update(order=order)
|
||||
else:
|
||||
CITypeAttributeGroupItem.create(group_id=group_id, attr_id=attr_id, order=order)
|
||||
|
||||
gt_items = db.session.query(CITypeAttributeGroupItem).filter(
|
||||
CITypeAttributeGroupItem.deleted.is_(False)).filter(CITypeAttributeGroupItem.order > order)
|
||||
for _item in gt_items:
|
||||
_order = _item.order
|
||||
_item.update(order=_order + 1)
|
||||
|
||||
@classmethod
|
||||
def update_item(cls, group_id, attr_id, order):
|
||||
db.session.remove()
|
||||
|
||||
existed = CITypeAttributeGroupItem.get_by(group_id=group_id,
|
||||
attr_id=attr_id,
|
||||
first=True,
|
||||
to_dict=False)
|
||||
existed or abort(404, "Group<{0}> - Attribute<{1}> is not found".format(group_id, attr_id))
|
||||
|
||||
if existed.order > order: # forward, +1
|
||||
items = db.session.query(CITypeAttributeGroupItem).filter(
|
||||
CITypeAttributeGroupItem.deleted.is_(False)).filter(
|
||||
CITypeAttributeGroupItem.order >= order).filter(
|
||||
CITypeAttributeGroupItem.order < existed.order)
|
||||
for item in items:
|
||||
item.update(order=item.order + 1)
|
||||
|
||||
elif existed.order < order: # backward, -1
|
||||
items = db.session.query(CITypeAttributeGroupItem).filter(
|
||||
CITypeAttributeGroupItem.deleted.is_(False)).filter(
|
||||
CITypeAttributeGroupItem.order > existed.order).filter(
|
||||
CITypeAttributeGroupItem.order <= order)
|
||||
for item in items:
|
||||
item.update(order=item.order - 1)
|
||||
|
||||
existed.update(order=order)
|
||||
|
||||
@classmethod
|
||||
def delete_item(cls, group_id, attr_id):
|
||||
db.session.remove()
|
||||
|
||||
item = CITypeAttributeGroupItem.get_by(group_id=group_id,
|
||||
attr_id=attr_id,
|
||||
first=True,
|
||||
to_dict=False)
|
||||
|
||||
if item is not None:
|
||||
item.soft_delete()
|
||||
order = item.order
|
||||
gt_items = db.session.query(CITypeAttributeGroupItem).filter(
|
||||
CITypeAttributeGroupItem.deleted.is_(False)).filter(CITypeAttributeGroupItem.order > order)
|
||||
for _item in gt_items:
|
||||
_order = _item.order
|
||||
_item.update(order=_order - 1)
|
||||
|
||||
@classmethod
|
||||
def transfer(cls, type_id, _from, _to):
|
||||
current_app.logger.info("CIType[{0}] {1} -> {2}".format(type_id, _from, _to))
|
||||
from_group = CITypeAttributeGroup.get_by_id(_from)
|
||||
from_group or abort(404, "Group <{0}> is not found".format(_from))
|
||||
|
||||
to_group = CITypeAttributeGroup.get_by_id(_to)
|
||||
to_group or abort(404, "Group <{0}> is not found".format(_to))
|
||||
|
||||
from_order, to_order = from_group.order, to_group.order
|
||||
|
||||
from_group.update(order=to_order)
|
||||
to_group.update(order=from_order)
|
||||
|
||||
CITypeAttributesCache.clean(type_id)
|
||||
|
||||
from api.tasks.cmdb import ci_type_attribute_order_rebuild
|
||||
ci_type_attribute_order_rebuild.apply_async(args=(type_id,), queue=CMDB_QUEUE)
|
||||
|
@@ -11,6 +11,7 @@ class ValueTypeEnum(BaseEnum):
|
||||
DATETIME = "3"
|
||||
DATE = "4"
|
||||
TIME = "5"
|
||||
JSON = "6"
|
||||
|
||||
|
||||
class CIStatusEnum(BaseEnum):
|
||||
|
@@ -1,6 +1,8 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
|
||||
import json
|
||||
|
||||
from flask import abort
|
||||
from flask import g
|
||||
|
||||
@@ -105,8 +107,8 @@ class AttributeHistoryManger(object):
|
||||
for attr_id, operate_type, old, new in history_list or []:
|
||||
AttributeHistory.create(attr_id=attr_id,
|
||||
operate_type=operate_type,
|
||||
old=old,
|
||||
new=new,
|
||||
old=json.dumps(old) if isinstance(old, (dict, list)) else old,
|
||||
new=json.dumps(new) if isinstance(new, (dict, list)) else new,
|
||||
ci_id=ci_id,
|
||||
record_id=record.id)
|
||||
|
||||
|
@@ -13,7 +13,7 @@ from flask import g
|
||||
from api.extensions import db
|
||||
from api.lib.cmdb.attribute import AttributeManager
|
||||
from api.lib.cmdb.cache import AttributeCache
|
||||
from api.lib.cmdb.cache import CITypeAttributeCache
|
||||
from api.lib.cmdb.cache import CITypeAttributesCache
|
||||
from api.lib.cmdb.cache import CITypeCache
|
||||
from api.lib.cmdb.const import ResourceTypeEnum, RoleEnum, PermEnum
|
||||
from api.lib.exception import AbortException
|
||||
@@ -100,7 +100,7 @@ class PreferenceManager(object):
|
||||
|
||||
@staticmethod
|
||||
def create_or_update_tree_view(type_id, levels):
|
||||
attrs = CITypeAttributeCache.get(type_id)
|
||||
attrs = CITypeAttributesCache.get(type_id)
|
||||
for idx, i in enumerate(levels):
|
||||
for attr in attrs:
|
||||
attr = AttributeCache.get(attr.attr_id)
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import six
|
||||
from flask import current_app
|
||||
|
||||
from api.extensions import es
|
||||
@@ -129,7 +130,7 @@ class Search(object):
|
||||
if "*" in v:
|
||||
self._operator2query(operator).append({
|
||||
"wildcard": {
|
||||
attr: v
|
||||
attr: v.lower() if isinstance(v, six.string_types) else v
|
||||
}
|
||||
})
|
||||
else:
|
||||
@@ -137,7 +138,7 @@ class Search(object):
|
||||
attr = "type_id"
|
||||
self._operator2query(operator).append({
|
||||
"term": {
|
||||
attr: v
|
||||
attr: v.lower() if isinstance(v, six.string_types) else v
|
||||
}
|
||||
})
|
||||
|
||||
|
@@ -16,7 +16,7 @@ from api.models.cmdb import CI
|
||||
|
||||
class Search(object):
|
||||
def __init__(self, root_id,
|
||||
level=1,
|
||||
level=None,
|
||||
query=None,
|
||||
fl=None,
|
||||
facet_field=None,
|
||||
@@ -82,9 +82,10 @@ class Search(object):
|
||||
ci_ids=merge_ids).search()
|
||||
|
||||
def statistics(self, type_ids):
|
||||
_tmp = []
|
||||
ids = [self.root_id] if not isinstance(self.root_id, list) else self.root_id
|
||||
for l in range(0, int(self.level)):
|
||||
if l == 0:
|
||||
if not l:
|
||||
_tmp = list(map(lambda x: list(json.loads(x).keys()),
|
||||
[i or '{}' for i in rd.get(ids, REDIS_PREFIX_CI_RELATION) or []]))
|
||||
else:
|
||||
|
@@ -3,6 +3,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
import six
|
||||
from markupsafe import escape
|
||||
@@ -33,15 +34,17 @@ class ValueTypeMap(object):
|
||||
ValueTypeEnum.TIME: lambda x: escape(x).encode('utf-8').decode('utf-8'),
|
||||
ValueTypeEnum.DATETIME: str2datetime,
|
||||
ValueTypeEnum.DATE: str2datetime,
|
||||
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) and x else x,
|
||||
}
|
||||
|
||||
serialize = {
|
||||
ValueTypeEnum.INT: int,
|
||||
ValueTypeEnum.FLOAT: float,
|
||||
ValueTypeEnum.TEXT: lambda x: x if isinstance(x, six.text_type) else str(x),
|
||||
ValueTypeEnum.TIME: lambda x: x if isinstance(x, six.text_type) else str(x),
|
||||
ValueTypeEnum.TEXT: lambda x: x if isinstance(x, six.string_types) else str(x),
|
||||
ValueTypeEnum.TIME: lambda x: x if isinstance(x, six.string_types) else str(x),
|
||||
ValueTypeEnum.DATE: lambda x: x.strftime("%Y-%m-%d"),
|
||||
ValueTypeEnum.DATETIME: lambda x: x.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) and x else x,
|
||||
}
|
||||
|
||||
serialize2 = {
|
||||
@@ -51,6 +54,7 @@ class ValueTypeMap(object):
|
||||
ValueTypeEnum.TIME: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
||||
ValueTypeEnum.DATE: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
||||
ValueTypeEnum.DATETIME: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
||||
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) and x else x,
|
||||
}
|
||||
|
||||
choice = {
|
||||
@@ -66,12 +70,14 @@ class ValueTypeMap(object):
|
||||
ValueTypeEnum.DATE: model.CIValueDateTime,
|
||||
ValueTypeEnum.TIME: model.CIValueText,
|
||||
ValueTypeEnum.FLOAT: model.CIValueFloat,
|
||||
ValueTypeEnum.JSON: model.CIValueJson,
|
||||
'index_{0}'.format(ValueTypeEnum.INT): model.CIIndexValueInteger,
|
||||
'index_{0}'.format(ValueTypeEnum.TEXT): model.CIIndexValueText,
|
||||
'index_{0}'.format(ValueTypeEnum.DATETIME): model.CIIndexValueDateTime,
|
||||
'index_{0}'.format(ValueTypeEnum.DATE): model.CIIndexValueDateTime,
|
||||
'index_{0}'.format(ValueTypeEnum.TIME): model.CIIndexValueText,
|
||||
'index_{0}'.format(ValueTypeEnum.FLOAT): model.CIIndexValueFloat,
|
||||
'index_{0}'.format(ValueTypeEnum.JSON): model.CIValueJson,
|
||||
}
|
||||
|
||||
table_name = {
|
||||
@@ -81,12 +87,14 @@ class ValueTypeMap(object):
|
||||
ValueTypeEnum.DATE: 'c_value_datetime',
|
||||
ValueTypeEnum.TIME: 'c_value_texts',
|
||||
ValueTypeEnum.FLOAT: 'c_value_floats',
|
||||
ValueTypeEnum.JSON: 'c_value_json',
|
||||
'index_{0}'.format(ValueTypeEnum.INT): 'c_value_index_integers',
|
||||
'index_{0}'.format(ValueTypeEnum.TEXT): 'c_value_index_texts',
|
||||
'index_{0}'.format(ValueTypeEnum.DATETIME): 'c_value_index_datetime',
|
||||
'index_{0}'.format(ValueTypeEnum.DATE): 'c_value_index_datetime',
|
||||
'index_{0}'.format(ValueTypeEnum.TIME): 'c_value_index_texts',
|
||||
'index_{0}'.format(ValueTypeEnum.FLOAT): 'c_value_index_floats',
|
||||
'index_{0}'.format(ValueTypeEnum.JSON): 'c_value_json',
|
||||
}
|
||||
|
||||
es_type = {
|
||||
@@ -95,7 +103,8 @@ class ValueTypeMap(object):
|
||||
ValueTypeEnum.DATETIME: 'text',
|
||||
ValueTypeEnum.DATE: 'text',
|
||||
ValueTypeEnum.TIME: 'text',
|
||||
ValueTypeEnum.FLOAT: 'float'
|
||||
ValueTypeEnum.FLOAT: 'float',
|
||||
ValueTypeEnum.JSON: 'object'
|
||||
}
|
||||
|
||||
|
||||
|
@@ -8,8 +8,10 @@ from flask import abort
|
||||
from api.extensions import db
|
||||
from api.lib.cmdb.attribute import AttributeManager
|
||||
from api.lib.cmdb.cache import AttributeCache
|
||||
from api.lib.cmdb.cache import CITypeAttributeCache
|
||||
from api.lib.cmdb.const import ExistPolicy
|
||||
from api.lib.cmdb.const import OperateType
|
||||
from api.lib.cmdb.const import ValueTypeEnum
|
||||
from api.lib.cmdb.history import AttributeHistoryManger
|
||||
from api.lib.cmdb.utils import TableMap
|
||||
from api.lib.cmdb.utils import ValueTypeMap
|
||||
@@ -77,23 +79,31 @@ class AttributeValueManager(object):
|
||||
return abort(400, "attribute value <{0}> is invalid".format(value))
|
||||
|
||||
@staticmethod
|
||||
def __check_is_choice(attr_id, value_type, value):
|
||||
choice_values = AttributeManager.get_choice_values(attr_id, value_type)
|
||||
def __check_is_choice(attr, value_type, value):
|
||||
choice_values = AttributeManager.get_choice_values(attr.id, value_type)
|
||||
if value not in choice_values:
|
||||
return abort(400, "{0} does not existed in choice values".format(value))
|
||||
|
||||
@staticmethod
|
||||
def __check_is_unique(value_table, attr_id, ci_id, value):
|
||||
def __check_is_unique(value_table, attr, ci_id, value):
|
||||
existed = db.session.query(value_table.attr_id).filter(
|
||||
value_table.attr_id == attr_id).filter(value_table.deleted.is_(False)).filter(
|
||||
value_table.attr_id == attr.id).filter(value_table.deleted.is_(False)).filter(
|
||||
value_table.value == value).filter(value_table.ci_id != ci_id).first()
|
||||
existed and abort(400, "attribute <{0}> value {1} must be unique".format(attr_id, value))
|
||||
existed and abort(400, "attribute <{0}> value {1} must be unique".format(attr.alias, value))
|
||||
|
||||
def _validate(self, attr, value, value_table, ci_id):
|
||||
@staticmethod
|
||||
def __check_is_required(type_id, attr, value):
|
||||
type_attr = CITypeAttributeCache.get(type_id, attr.id)
|
||||
if type_attr and type_attr.is_required and not value and value != 0:
|
||||
return abort(400, "attribute <{0}> value is required".format(attr.alias))
|
||||
|
||||
def _validate(self, attr, value, value_table, ci):
|
||||
v = self.__deserialize_value(attr.value_type, value)
|
||||
|
||||
attr.is_choice and value and self.__check_is_choice(attr.id, attr.value_type, v)
|
||||
attr.is_unique and self.__check_is_unique(value_table, attr.id, ci_id, v)
|
||||
attr.is_choice and value and self.__check_is_choice(attr, attr.value_type, v)
|
||||
attr.is_unique and self.__check_is_unique(value_table, attr, ci.id, v)
|
||||
|
||||
self.__check_is_required(ci.type_id, attr, v)
|
||||
|
||||
return v
|
||||
|
||||
@@ -101,12 +111,12 @@ class AttributeValueManager(object):
|
||||
def _write_change(ci_id, attr_id, operate_type, old, new):
|
||||
AttributeHistoryManger.add(ci_id, [(attr_id, operate_type, old, new)])
|
||||
|
||||
def create_or_update_attr_value(self, key, value, ci_id, _no_attribute_policy=ExistPolicy.IGNORE):
|
||||
def create_or_update_attr_value(self, key, value, ci, _no_attribute_policy=ExistPolicy.IGNORE):
|
||||
"""
|
||||
add or update attribute value, then write history
|
||||
:param key: id, name or alias
|
||||
:param value:
|
||||
:param ci_id:
|
||||
:param ci: instance object
|
||||
:param _no_attribute_policy: ignore or reject
|
||||
:return:
|
||||
"""
|
||||
@@ -120,31 +130,47 @@ class AttributeValueManager(object):
|
||||
value_table = TableMap(attr_name=attr.name).table
|
||||
|
||||
if attr.is_list:
|
||||
value_list = [self._validate(attr, i, value_table, ci_id) for i in handle_arg_list(value)]
|
||||
value_list = [self._validate(attr, i, value_table, ci) for i in handle_arg_list(value)]
|
||||
if not value_list:
|
||||
self.__check_is_required(ci.type_id, attr, '')
|
||||
|
||||
existed_attrs = value_table.get_by(attr_id=attr.id,
|
||||
ci_id=ci_id,
|
||||
ci_id=ci.id,
|
||||
to_dict=False)
|
||||
existed_values = [i.value for i in existed_attrs]
|
||||
added = set(value_list) - set(existed_values)
|
||||
deleted = set(existed_values) - set(value_list)
|
||||
for v in added:
|
||||
value_table.create(ci_id=ci_id, attr_id=attr.id, value=v)
|
||||
self._write_change(ci_id, attr.id, OperateType.ADD, None, v)
|
||||
value_table.create(ci_id=ci.id, attr_id=attr.id, value=v)
|
||||
self._write_change(ci.id, attr.id, OperateType.ADD, None, v)
|
||||
|
||||
for v in deleted:
|
||||
existed_attr = existed_attrs[existed_values.index(v)]
|
||||
existed_attr.delete()
|
||||
self._write_change(ci_id, attr.id, OperateType.DELETE, v, None)
|
||||
self._write_change(ci.id, attr.id, OperateType.DELETE, v, None)
|
||||
else:
|
||||
value = self._validate(attr, value, value_table, ci_id)
|
||||
value = self._validate(attr, value, value_table, ci)
|
||||
existed_attr = value_table.get_by(attr_id=attr.id,
|
||||
ci_id=ci_id,
|
||||
ci_id=ci.id,
|
||||
first=True,
|
||||
to_dict=False)
|
||||
existed_value = existed_attr and existed_attr.value
|
||||
if existed_value is None:
|
||||
value_table.create(ci_id=ci_id, attr_id=attr.id, value=value)
|
||||
self._write_change(ci_id, attr.id, OperateType.ADD, None, value)
|
||||
value_table.create(ci_id=ci.id, attr_id=attr.id, value=value)
|
||||
|
||||
self._write_change(ci.id, attr.id, OperateType.ADD, None, value)
|
||||
else:
|
||||
existed_attr.update(value=value)
|
||||
self._write_change(ci_id, attr.id, OperateType.UPDATE, existed_value, value)
|
||||
if not value and attr.value_type != ValueTypeEnum.TEXT:
|
||||
existed_attr.delete()
|
||||
else:
|
||||
existed_attr.update(value=value)
|
||||
|
||||
self._write_change(ci.id, attr.id, OperateType.UPDATE, existed_value, value)
|
||||
|
||||
@staticmethod
|
||||
def delete_attr_value(attr_id, ci_id):
|
||||
attr = AttributeCache.get(attr_id)
|
||||
if attr is not None:
|
||||
value_table = TableMap(attr_name=attr.name).table
|
||||
for item in value_table.get_by(attr_id=attr.id, ci_id=ci_id, to_dict=False):
|
||||
item.delete()
|
||||
|
@@ -25,6 +25,9 @@ class FormatMixin(object):
|
||||
|
||||
|
||||
class CRUDMixin(FormatMixin):
|
||||
def __init__(self, **kwargs):
|
||||
super(CRUDMixin, self).__init__(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def create(cls, flush=False, **kwargs):
|
||||
return cls(**kwargs).save(flush=flush)
|
||||
|
@@ -12,7 +12,7 @@ from future.moves.urllib.parse import urlparse
|
||||
|
||||
|
||||
def build_api_key(path, params):
|
||||
g.user is not None or abort(403, "您得登陆才能进行该操作")
|
||||
g.user is not None or abort(403, "You have to login to do this")
|
||||
key = g.user.key
|
||||
secret = g.user.secret
|
||||
values = "".join([str(params[k]) for k in sorted(params.keys())
|
||||
|
@@ -47,12 +47,13 @@ def _auth_with_token():
|
||||
|
||||
try:
|
||||
token = auth_headers
|
||||
data = jwt.decode(token, current_app.config['SECRET_KEY'])
|
||||
data = jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=['HS256'])
|
||||
user = User.query.filter_by(email=data['sub']).first()
|
||||
if not user:
|
||||
return False
|
||||
|
||||
login_user(user)
|
||||
g.user = user
|
||||
return True
|
||||
except jwt.ExpiredSignatureError:
|
||||
return False
|
||||
|
@@ -1,5 +1,7 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import json
|
||||
|
||||
import redis
|
||||
import six
|
||||
from elasticsearch import Elasticsearch
|
||||
@@ -26,6 +28,9 @@ def get_page_size(page_size):
|
||||
|
||||
|
||||
def handle_arg_list(arg):
|
||||
if isinstance(arg, six.string_types) and arg.startswith('['):
|
||||
return json.loads(arg)
|
||||
|
||||
return list(filter(lambda x: x != "", arg.strip().split(","))) if isinstance(arg, six.string_types) else arg
|
||||
|
||||
|
||||
|
@@ -15,13 +15,13 @@ from api.lib.database import Model
|
||||
class RelationType(Model):
|
||||
__tablename__ = "c_relation_types"
|
||||
|
||||
name = db.Column(db.String(16), index=True)
|
||||
name = db.Column(db.String(16), index=True, nullable=False)
|
||||
|
||||
|
||||
class CITypeGroup(Model):
|
||||
__tablename__ = "c_ci_type_groups"
|
||||
|
||||
name = db.Column(db.String(32))
|
||||
name = db.Column(db.String(32), nullable=False)
|
||||
|
||||
|
||||
class CITypeGroupItem(Model):
|
||||
@@ -35,12 +35,12 @@ class CITypeGroupItem(Model):
|
||||
class CIType(Model):
|
||||
__tablename__ = "c_ci_types"
|
||||
|
||||
name = db.Column(db.String(32))
|
||||
alias = db.Column(db.String(32))
|
||||
name = db.Column(db.String(32), nullable=False)
|
||||
alias = db.Column(db.String(32), nullable=False)
|
||||
unique_id = db.Column(db.Integer, db.ForeignKey("c_attributes.id"), nullable=False)
|
||||
enabled = db.Column(db.Boolean, default=True, nullable=False)
|
||||
is_attached = db.Column(db.Boolean, default=False, nullable=False)
|
||||
icon_url = db.Column(db.String(256))
|
||||
icon_url = db.Column(db.String(256), default='', nullable=False)
|
||||
order = db.Column(db.SmallInteger, default=0, nullable=False)
|
||||
|
||||
unique_key = db.relationship("Attribute", backref="c_ci_types.unique_id")
|
||||
@@ -89,7 +89,7 @@ class CITypeAttribute(Model):
|
||||
class CITypeAttributeGroup(Model):
|
||||
__tablename__ = "c_ci_type_attribute_groups"
|
||||
|
||||
name = db.Column(db.String(64))
|
||||
name = db.Column(db.String(64), nullable=False)
|
||||
type_id = db.Column(db.Integer, db.ForeignKey("c_ci_types.id"), nullable=False)
|
||||
order = db.Column(db.SmallInteger, default=0)
|
||||
|
||||
@@ -250,13 +250,24 @@ class CIValueDateTime(Model):
|
||||
attr = db.relationship("Attribute", backref="c_value_datetime.attr_id")
|
||||
|
||||
|
||||
class CIValueJson(Model):
|
||||
__tablename__ = "c_value_json"
|
||||
|
||||
ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
||||
attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
||||
value = db.Column(db.JSON, nullable=False)
|
||||
|
||||
ci = db.relationship("CI", backref="c_value_json.ci_id")
|
||||
attr = db.relationship("Attribute", backref="c_value_json.attr_id")
|
||||
|
||||
|
||||
# history
|
||||
class OperationRecord(Model):
|
||||
__tablename__ = "c_records"
|
||||
|
||||
uid = db.Column(db.Integer, index=True, nullable=False)
|
||||
origin = db.Column(db.String(32))
|
||||
ticket_id = db.Column(db.String(32))
|
||||
origin = db.Column(db.String(32), nullable=True)
|
||||
ticket_id = db.Column(db.String(32), nullable=True)
|
||||
reason = db.Column(db.Text)
|
||||
|
||||
|
||||
@@ -306,5 +317,5 @@ class PreferenceTreeView(Model):
|
||||
class PreferenceRelationView(Model):
|
||||
__tablename__ = "c_preference_relation_views"
|
||||
|
||||
name = db.Column(db.String(8), index=True, nullable=False)
|
||||
name = db.Column(db.String(64), index=True, nullable=False)
|
||||
cr_ids = db.Column(db.TEXT) # [{parent_id: x, child_id: y}] TODO: JSON
|
||||
|
@@ -11,6 +11,7 @@ from api.extensions import celery
|
||||
from api.extensions import db
|
||||
from api.extensions import es
|
||||
from api.extensions import rd
|
||||
from api.lib.cmdb.cache import CITypeAttributeCache
|
||||
from api.lib.cmdb.const import CMDB_QUEUE
|
||||
from api.lib.cmdb.const import REDIS_PREFIX_CI
|
||||
from api.lib.cmdb.const import REDIS_PREFIX_CI_RELATION
|
||||
@@ -71,3 +72,23 @@ def ci_relation_delete(parent_id, child_id):
|
||||
rd.create_or_update({parent_id: json.dumps(children)}, REDIS_PREFIX_CI_RELATION)
|
||||
|
||||
current_app.logger.info("DELETE ci relation cache: {0} -> {1}".format(parent_id, child_id))
|
||||
|
||||
|
||||
@celery.task(name="cmdb.ci_type_attribute_order_rebuild", queue=CMDB_QUEUE)
|
||||
def ci_type_attribute_order_rebuild(type_id):
|
||||
current_app.logger.info('rebuild attribute order')
|
||||
db.session.remove()
|
||||
|
||||
from api.lib.cmdb.ci_type import CITypeAttributeGroupManager
|
||||
|
||||
attrs = CITypeAttributeCache.get(type_id)
|
||||
id2attr = {attr.attr_id: attr for attr in attrs}
|
||||
|
||||
res = CITypeAttributeGroupManager.get_by_type_id(type_id, True)
|
||||
order = 0
|
||||
for group in res:
|
||||
for _attr in group.get('attributes'):
|
||||
if order != id2attr.get(_attr['id']) and id2attr.get(_attr['id']):
|
||||
id2attr.get(_attr['id']).update(order=order)
|
||||
|
||||
order += 1
|
||||
|
@@ -73,7 +73,7 @@ class CIView(APIView):
|
||||
ci_dict[k] = v.strip() if isinstance(v, six.string_types) else v
|
||||
return ci_dict
|
||||
|
||||
@has_perm_from_args("ci_type", ResourceTypeEnum.CI, PermEnum.ADD)
|
||||
@has_perm_from_args("ci_type", ResourceTypeEnum.CI, PermEnum.ADD, lambda x: CITypeCache.get(x).name)
|
||||
def post(self):
|
||||
ci_type = request.values.get("ci_type")
|
||||
_no_attribute_policy = request.values.get("_no_attribute_policy", ExistPolicy.IGNORE)
|
||||
|
@@ -164,6 +164,34 @@ class CITypeAttributeView(APIView):
|
||||
return self.jsonify(attributes=attr_id_list)
|
||||
|
||||
|
||||
class CITypeAttributeTransferView(APIView):
|
||||
url_prefix = "/ci_types/<int:type_id>/attributes/transfer"
|
||||
|
||||
@args_required('from')
|
||||
@args_required('to')
|
||||
def post(self, type_id):
|
||||
_from = request.values.get('from') # {'attr_id': xx, 'group_id': xx}
|
||||
_to = request.values.get('to') # {'group_id': xx, 'order': xxx}
|
||||
|
||||
CITypeAttributeManager.transfer(type_id, _from, _to)
|
||||
|
||||
return self.jsonify(code=200)
|
||||
|
||||
|
||||
class CITypeAttributeGroupTransferView(APIView):
|
||||
url_prefix = "/ci_types/<int:type_id>/attribute_groups/transfer"
|
||||
|
||||
@args_required('from')
|
||||
@args_required('to')
|
||||
def post(self, type_id):
|
||||
_from = request.values.get('from') # group_id
|
||||
_to = request.values.get('to') # group_id
|
||||
|
||||
CITypeAttributeGroupManager.transfer(type_id, _from, _to)
|
||||
|
||||
return self.jsonify(code=200)
|
||||
|
||||
|
||||
class CITypeAttributeGroupView(APIView):
|
||||
url_prefix = ("/ci_types/<int:type_id>/attribute_groups",
|
||||
"/ci_types/attribute_groups/<int:group_id>")
|
||||
|
17
cmdb-api/local_test.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""For debugging in ide"""
|
||||
|
||||
from tests.conftest import *
|
||||
from pytest_mock import mocker
|
||||
from _pytest.config import _prepareconfig
|
||||
|
||||
from tests.test_cmdb_attribute import test_create_attribute
|
||||
|
||||
|
||||
for a in app():
|
||||
for d in database(a):
|
||||
for s in session(d, a):
|
||||
for c in client(a):
|
||||
for m in mocker(_prepareconfig()):
|
||||
clean_db()
|
||||
test_create_attribute(s, c)
|
7
cmdb-api/requirements-test.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
-i https://mirrors.aliyun.com/pypi/simple
|
||||
pytest==4.0.2
|
||||
attrs==19.1.0
|
||||
coverage==4.4.2
|
||||
pytest-cov==2.5.1
|
||||
pytest-html==1.16.1
|
||||
pytest-mock==1.10.0
|
@@ -1,38 +1,39 @@
|
||||
-i https://mirrors.aliyun.com/pypi/simple
|
||||
# Flask
|
||||
Flask==1.0.3
|
||||
Werkzeug==0.15.4
|
||||
click>=5.0
|
||||
Flask == 1.0.3
|
||||
Werkzeug == 0.15.4
|
||||
click >= 5.0
|
||||
# Api
|
||||
Flask-RESTful ==0.3.7
|
||||
Flask-RESTful == 0.3.7
|
||||
# Database
|
||||
Flask-SQLAlchemy ==2.4.0
|
||||
SQLAlchemy ==1.3.5
|
||||
PyMySQL ==0.9.3
|
||||
redis ==3.2.1
|
||||
Flask-SQLAlchemy == 2.4.0
|
||||
SQLAlchemy == 1.3.5
|
||||
PyMySQL == 0.9.3
|
||||
redis == 3.2.1
|
||||
# Migrations
|
||||
Flask-Migrate == 2.5.2
|
||||
# Deployment
|
||||
gevent ==1.4.0
|
||||
gevent == 1.4.0
|
||||
gunicorn == 19.5.0
|
||||
supervisor ==4.0.3
|
||||
supervisor == 4.0.3
|
||||
# Auth
|
||||
Flask-Login ==0.4.1
|
||||
Flask-Bcrypt ==0.7.1
|
||||
Flask-Cors>=3.0.8
|
||||
Flask-Login == 0.4.1
|
||||
Flask-Bcrypt == 0.7.1
|
||||
Flask-Cors >= 3.0.8
|
||||
# Caching
|
||||
Flask-Caching>=1.0.0
|
||||
Flask-Caching >= 1.0.0
|
||||
# Environment variable parsing
|
||||
environs ==4.2.0
|
||||
marshmallow ==2.20.2
|
||||
environs == 4.2.0
|
||||
marshmallow == 2.20.2
|
||||
# async tasks
|
||||
celery ==4.3.0
|
||||
more-itertools ==5.0.0
|
||||
kombu ==4.4.0
|
||||
celery == 4.3.0
|
||||
more-itertools == 5.0.0
|
||||
kombu == 4.4.0
|
||||
# other
|
||||
six ==1.12.0
|
||||
bs4>=0.0.1
|
||||
toposort>=1.5
|
||||
requests>=2.22.0
|
||||
PyJWT>=1.7.1
|
||||
elasticsearch ==7.0.4
|
||||
six == 1.12.0
|
||||
bs4 >= 0.0.1
|
||||
toposort >= 1.5
|
||||
requests >= 2.22.0
|
||||
PyJWT >= 1.7.1
|
||||
elasticsearch == 7.0.4
|
||||
future == 0.18.2
|
||||
|
@@ -1,16 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Defines fixtures available to all tests."""
|
||||
|
||||
import jwt
|
||||
import pytest
|
||||
from webtest import TestApp
|
||||
from flask import Response, json
|
||||
from flask.testing import FlaskClient
|
||||
from werkzeug.datastructures import Headers
|
||||
|
||||
from api.app import create_app
|
||||
from api.extensions import db, cache
|
||||
from api.models.acl import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
class CMDBTestClient(FlaskClient):
|
||||
TEST_APP_SECRET = "test"
|
||||
|
||||
def open(self, *args, **kwargs):
|
||||
headers = kwargs.pop("headers", Headers())
|
||||
headers.setdefault("User-Agent", "py.test")
|
||||
kwargs["headers"] = headers
|
||||
|
||||
json_data = kwargs.pop("json", None)
|
||||
if json_data is not None:
|
||||
kwargs["data"] = json.dumps(json_data)
|
||||
if not kwargs.get("content_type"):
|
||||
kwargs["content_type"] = "application/json"
|
||||
|
||||
auth = kwargs.pop("auth", (
|
||||
"Access-Token",
|
||||
jwt.encode({"sub": "test@xx.com"}, key=self.TEST_APP_SECRET)
|
||||
))
|
||||
kwargs["headers"][auth[0]] = auth[1]
|
||||
|
||||
return super(CMDBTestClient, self).open(*args, **kwargs)
|
||||
|
||||
|
||||
class CMDBTestResponse(Response):
|
||||
@property
|
||||
def json(self):
|
||||
return json.loads(self.data)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def app():
|
||||
"""Create application for the tests."""
|
||||
_app = create_app("tests.settings")
|
||||
_app.config['SECRET_KEY'] = CMDBTestClient.TEST_APP_SECRET
|
||||
_app.test_client_class = CMDBTestClient
|
||||
_app.response_class = CMDBTestResponse
|
||||
|
||||
ctx = _app.test_request_context()
|
||||
ctx.push()
|
||||
yield _app
|
||||
@@ -18,6 +57,66 @@ def app():
|
||||
ctx.pop()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def client(app):
|
||||
with app.test_client(use_cookies=False) as c:
|
||||
yield c
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def database(app):
|
||||
"""Clean database after each case finished"""
|
||||
setup_db()
|
||||
yield db
|
||||
teardown_db()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def session(database, app):
|
||||
with app.app_context():
|
||||
clean_db()
|
||||
clean_cache()
|
||||
yield database.session
|
||||
database.session.rollback()
|
||||
|
||||
|
||||
def setup_db():
|
||||
teardown_db()
|
||||
db.create_all()
|
||||
# create test user
|
||||
|
||||
|
||||
def teardown_db():
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
db.session.bind.dispose()
|
||||
|
||||
|
||||
def clean_cache():
|
||||
cache.clear()
|
||||
|
||||
|
||||
def clean_db():
|
||||
"""clean all data but not drop table"""
|
||||
for table in reversed(db.metadata.sorted_tables):
|
||||
if table.fullname in ["users"]:
|
||||
continue
|
||||
db.session.execute(table.delete())
|
||||
db.session.commit()
|
||||
|
||||
if not User.get_by(email="test@xx.com"):
|
||||
u = User.create(
|
||||
flush=True,
|
||||
username="test",
|
||||
nickname="测试",
|
||||
email="test@xx.com",
|
||||
key="",
|
||||
secret=""
|
||||
)
|
||||
u._set_password("123456")
|
||||
u.save()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def testapp(app):
|
||||
"""Create Webtest app."""
|
||||
|
135
cmdb-api/tests/sample.py
Normal file
@@ -0,0 +1,135 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""provide some sample data in database"""
|
||||
import uuid
|
||||
import random
|
||||
|
||||
from api.models.cmdb import (
|
||||
Attribute,
|
||||
CIType,
|
||||
CITypeAttributeGroup,
|
||||
CITypeAttribute,
|
||||
CITypeRelation,
|
||||
RelationType
|
||||
)
|
||||
from api.models.acl import User
|
||||
|
||||
from api.lib.cmdb.ci_type import CITypeAttributeManager
|
||||
from api.lib.cmdb.ci import CIManager, CIRelationManager
|
||||
|
||||
|
||||
def force_add_user():
|
||||
from flask import g
|
||||
if not getattr(g, "user", None):
|
||||
g.user = User.query.first()
|
||||
|
||||
|
||||
def init_attributes(num=1):
|
||||
attrs = []
|
||||
for i in range(num):
|
||||
attrs.append(Attribute.create(
|
||||
name=uuid.uuid4().hex[:8],
|
||||
alias=uuid.uuid4().hex[:8],
|
||||
value_type=str(random.randint(0, 100) % 3)
|
||||
))
|
||||
return attrs
|
||||
|
||||
|
||||
def init_ci_types(num=1):
|
||||
attrs = init_attributes(num)
|
||||
|
||||
ci_types = []
|
||||
for i in range(num):
|
||||
ci_type = CIType.create(
|
||||
name=uuid.uuid4().hex[:8],
|
||||
alias=uuid.uuid4().hex[:8],
|
||||
unique_id=attrs[i].id
|
||||
)
|
||||
CITypeAttribute.create(
|
||||
type_id=ci_type.id,
|
||||
attr_id=attrs[i].id,
|
||||
)
|
||||
ci_types.append(ci_type)
|
||||
|
||||
return ci_types
|
||||
|
||||
|
||||
def init_attribute_groups(num=1):
|
||||
ci_types = init_ci_types(num)
|
||||
|
||||
ags = []
|
||||
for i in range(num):
|
||||
ags.append(CITypeAttributeGroup.create(
|
||||
name=uuid.uuid4().hex[:8],
|
||||
type_id=ci_types[i].id,
|
||||
order=i
|
||||
))
|
||||
return ags
|
||||
|
||||
|
||||
def init_relation_type(num=1):
|
||||
result = []
|
||||
for i in range(num):
|
||||
result.append(RelationType.create(
|
||||
name=uuid.uuid4().hex[:8],
|
||||
))
|
||||
return result
|
||||
|
||||
|
||||
def init_ci_type_relation(num=1):
|
||||
result = []
|
||||
ci_types = init_ci_types(num+1)
|
||||
relation_types = init_relation_type(num)
|
||||
for i in range(num):
|
||||
result.append(CITypeRelation.create(
|
||||
parent_id=ci_types[i].id,
|
||||
child_id=ci_types[i+1].id,
|
||||
relation_type_id=relation_types[i].id
|
||||
))
|
||||
return result
|
||||
|
||||
|
||||
def fake_attr_value(attr_dict):
|
||||
attr_type = attr_dict["value_type"]
|
||||
attr_name = attr_dict["name"]
|
||||
|
||||
if attr_type == "0":
|
||||
return {attr_name: random.randint(0, 1000)}
|
||||
elif attr_type == "1":
|
||||
return {attr_name: random.randint(0, 1000) / 3.0}
|
||||
elif attr_type == "2":
|
||||
return {attr_name: uuid.uuid4().hex[:8]}
|
||||
|
||||
|
||||
def init_ci(num=1):
|
||||
# store ci need has user
|
||||
force_add_user()
|
||||
ci_type = init_ci_types(1)[0]
|
||||
attrs = CITypeAttributeManager.get_attributes_by_type_id(ci_type.id)
|
||||
manager = CIManager()
|
||||
result = []
|
||||
|
||||
for i in range(num):
|
||||
ci_id = manager.add(ci_type.name, **fake_attr_value(attrs[0]))
|
||||
result.append(manager.get_ci_by_id_from_db(ci_id))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def init_ci_with_type(ci_types):
|
||||
force_add_user()
|
||||
cis = []
|
||||
manager = CIManager()
|
||||
for ci_type in ci_types:
|
||||
attrs = CITypeAttributeManager.get_attributes_by_type_id(ci_type.id)
|
||||
ci_id = manager.add(ci_type.name, **fake_attr_value(attrs[0]))
|
||||
cis.append(manager.get_ci_by_id_from_db(ci_id))
|
||||
return cis
|
||||
|
||||
|
||||
def init_ci_relation():
|
||||
init_ci_type_relation(1)
|
||||
ci_types = CIType.query.all()
|
||||
cis = init_ci_with_type(ci_types)
|
||||
manager = CIRelationManager()
|
||||
cir_id = manager.add(cis[0]['ci_id'], cis[1]['ci_id'])
|
||||
return cir_id
|
@@ -1 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from api.models.cmdb import Attribute
|
||||
|
||||
from tests.sample import init_attributes
|
||||
|
||||
|
||||
def test_create_attribute(session, client):
|
||||
url = "/api/v0.1/attributes"
|
||||
payload = {
|
||||
"name": "region",
|
||||
"alias": "区域",
|
||||
"value_type": "2"
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
|
||||
# check resp status code and content
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["attr_id"]
|
||||
|
||||
# check there is a attribute in database
|
||||
attr_id = resp.json["attr_id"]
|
||||
attr_ins = Attribute.get_by_id(attr_id)
|
||||
assert attr_ins.id == attr_id
|
||||
assert attr_ins.name == "region"
|
||||
assert attr_ins.alias == "区域"
|
||||
|
||||
|
||||
def test_update_attribute(session, client):
|
||||
attr_ins = init_attributes(1)[0]
|
||||
|
||||
url = "/api/v0.1/attributes/" + str(attr_ins.id)
|
||||
payload = {
|
||||
"name": "update",
|
||||
}
|
||||
|
||||
resp = client.put(url, json=payload)
|
||||
|
||||
# check resp status code and content
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["attr_id"] == attr_ins.id
|
||||
|
||||
# check attribute updated in database
|
||||
attr_ins = Attribute.get_by_id(attr_ins.id)
|
||||
assert attr_ins.name == "update"
|
||||
|
||||
|
||||
def test_delete_attribute(session, client):
|
||||
attr_ins = init_attributes(1)[0]
|
||||
url = "/api/v0.1/attributes/" + str(attr_ins.id)
|
||||
|
||||
resp = client.delete(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
# attr should be soft delete
|
||||
attr_ins = Attribute.get_by_id(attr_ins.id)
|
||||
assert attr_ins.deleted is True
|
||||
assert attr_ins.deleted_at
|
||||
|
||||
|
@@ -1,10 +1,89 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .sample import init_ci_types, fake_attr_value, init_ci
|
||||
from api.lib.cmdb.ci_type import CITypeAttributeManager, CITypeManager
|
||||
from api.lib.cmdb.ci import CIManager
|
||||
from api.models.cmdb import CI
|
||||
|
||||
|
||||
class TestCI:
|
||||
def test_create_ci(session, client):
|
||||
ci_type = init_ci_types(1)[0]
|
||||
attrs = CITypeAttributeManager.get_attributes_by_type_id(ci_type.id)
|
||||
url = "/api/v0.1/ci"
|
||||
|
||||
fake_value = fake_attr_value(attrs[0])
|
||||
|
||||
payload = {
|
||||
"ci_type": ci_type.id,
|
||||
**fake_value
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["ci_id"]
|
||||
|
||||
ci_id = resp.json["ci_id"]
|
||||
ci = CIManager().get_ci_by_id_from_db(ci_id)
|
||||
assert ci[attrs[0]["name"]] == fake_value[attrs[0]['name']]
|
||||
|
||||
|
||||
def test_update_ci(session, client):
|
||||
ci = init_ci(1)[0]
|
||||
ci_id = ci.get("ci_id")
|
||||
ci_type = CITypeManager.get_ci_types(ci.get("ci_type"))[0]
|
||||
attrs = CITypeAttributeManager.get_attributes_by_type_id(ci_type["id"])
|
||||
url = "/api/v0.1/ci/{}".format(ci_id)
|
||||
|
||||
fake_value = fake_attr_value(attrs[0])
|
||||
|
||||
payload = {**fake_value}
|
||||
|
||||
resp = client.put(url, json=payload)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["ci_id"] == ci_id
|
||||
ci = CIManager().get_ci_by_id_from_db(ci_id)
|
||||
assert ci[attrs[0]['name']] == fake_value[attrs[0]['name']]
|
||||
|
||||
|
||||
def test_delete_ci(session, client):
|
||||
ci = init_ci(1)[0]
|
||||
ci_id = ci.get("ci_id")
|
||||
url = "/api/v0.1/ci/{}".format(ci_id)
|
||||
|
||||
resp = client.delete(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
||||
ci_from_db = CI.query.filter_by(id=ci_id).first()
|
||||
assert ci_from_db is None
|
||||
|
||||
|
||||
def test_get_ci_by_types(session, client):
|
||||
ci = init_ci(1)[0]
|
||||
ci_type = CITypeManager.get_ci_types(ci.get("ci_type"))[0]
|
||||
url = "/api/v0.1/ci/type/{}".format(ci_type["id"])
|
||||
|
||||
resp = client.get(url)
|
||||
assert resp.status_code == 200
|
||||
|
||||
assert resp.json['cis'][0]['ci_id'] == ci['ci_id']
|
||||
|
||||
|
||||
def test_get_ci_by_id(session, client):
|
||||
ci = init_ci(1)[0]
|
||||
url = "/api/v0.1/ci/{}".format(ci["ci_id"])
|
||||
|
||||
resp = client.get(url)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json['ci_id'] == ci['ci_id']
|
||||
|
||||
|
||||
def test_get_ci_detail_by_id(session, client):
|
||||
ci = init_ci(1)[0]
|
||||
url = "/api/v0.1/ci/{}/detail".format(ci["ci_id"])
|
||||
|
||||
resp = client.get(url)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json['id'] == ci['ci_id']
|
||||
|
||||
|
||||
def test_ci_search_only_type_query(self, app):
|
||||
with app.test_client() as c:
|
||||
rv = c.get('/api/v0.1/ci/s?q=_type:server', json={})
|
||||
json_data = rv.get_json()
|
||||
assert type(json_data.get("result")) is list
|
||||
|
@@ -1 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .sample import init_ci_with_type, init_ci_type_relation, init_ci_relation
|
||||
from api.lib.cmdb.ci import CIRelationManager
|
||||
from api.models.cmdb import CIRelation, CIType, CI
|
||||
|
||||
|
||||
def test_create_ci_relation(session, client):
|
||||
init_ci_type_relation(1)
|
||||
ci_types = CIType.query.all()
|
||||
cis = init_ci_with_type(ci_types)
|
||||
|
||||
url = "/api/v0.1/ci_relations/{}/{}".format(cis[0]['ci_id'], cis[1]['ci_id'])
|
||||
|
||||
resp = client.post(url)
|
||||
assert resp.status_code == 200
|
||||
cr_id = resp.json['cr_id']
|
||||
cr = CIRelation.get_by_id(cr_id)
|
||||
assert cr is not None
|
||||
|
||||
|
||||
def test_delte_ci_relation_by_ci_id(session, client):
|
||||
cr_id = init_ci_relation()
|
||||
cis = CI.query.all()
|
||||
|
||||
url = "/api/v0.1/ci_relations/{}/{}".format(cis[0].id, cis[1].id)
|
||||
resp = client.delete(url)
|
||||
assert resp.status_code == 200
|
||||
cr = CIRelation.get_by_id(cr_id)
|
||||
assert cr is None
|
||||
|
||||
|
||||
def test_delete_ci_relation_by_id(session, client):
|
||||
cr_id = init_ci_relation()
|
||||
url = "/api/v0.1/ci_relations/{cr_id}".format(cr_id=cr_id)
|
||||
resp = client.delete(url)
|
||||
assert resp.status_code == 200
|
||||
cr = CIRelation.get_by_id(cr_id)
|
||||
assert cr is None
|
||||
|
||||
|
@@ -1 +1,167 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from api.models.cmdb import (
|
||||
CIType, CITypeAttribute,
|
||||
Attribute, CITypeAttributeGroup,
|
||||
CITypeAttributeGroupItem)
|
||||
|
||||
from tests.sample import (
|
||||
init_attributes, init_ci_types,
|
||||
init_attribute_groups)
|
||||
|
||||
|
||||
def test_create_ci_type(session, client):
|
||||
attr = init_attributes(1)[0]
|
||||
|
||||
url = "/api/v0.1/ci_types"
|
||||
payload = {
|
||||
"name": "test",
|
||||
"alias": "测试",
|
||||
"unique_key": attr.id
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
|
||||
# check resp status code and content
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["type_id"]
|
||||
|
||||
# check there is a attribute in database
|
||||
type_id = resp.json["type_id"]
|
||||
ci_type_ins = CIType.get_by_id(type_id)
|
||||
assert ci_type_ins.id == type_id
|
||||
assert ci_type_ins.name == "test"
|
||||
assert ci_type_ins.alias == "测试"
|
||||
assert ci_type_ins.unique_id == attr.id
|
||||
|
||||
|
||||
def test_update_ci_type(session, client):
|
||||
ci_type_ins = init_ci_types(1)[0]
|
||||
|
||||
url = "/api/v0.1/ci_types/" + str(ci_type_ins.id)
|
||||
payload = {
|
||||
"name": "update",
|
||||
}
|
||||
|
||||
resp = client.put(url, json=payload)
|
||||
|
||||
# check resp status code and content
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["type_id"] == ci_type_ins.id
|
||||
|
||||
# check ci_type updated in database
|
||||
ci_type_ins = CIType.get_by_id(ci_type_ins.id)
|
||||
assert ci_type_ins.name == "update"
|
||||
|
||||
|
||||
def test_delete_ci_type(session, client):
|
||||
ci_type_ins = init_ci_types(1)[0]
|
||||
url = "/api/v0.1/ci_types/" + str(ci_type_ins.id)
|
||||
|
||||
resp = client.delete(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
# attr should be soft delete
|
||||
ci_type_ins = CIType.get_by_id(ci_type_ins.id)
|
||||
assert ci_type_ins.deleted is True
|
||||
assert ci_type_ins.deleted_at
|
||||
|
||||
|
||||
def test_bind_attributes_ci_type(session, client):
|
||||
attrs = init_attributes(3)
|
||||
ci_type = init_ci_types(1)[0]
|
||||
|
||||
url = "/api/v0.1/ci_types/{}/attributes".format(ci_type.id)
|
||||
payload = {
|
||||
"attr_id": [str(x.id) for x in attrs]
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
|
||||
# check resp status code and content
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json["attributes"]) == len(attrs)
|
||||
|
||||
# check ci_type has 4 attributes
|
||||
ci_type_attribute_ids = [x.attr_id for x in CITypeAttribute.query.filter_by(type_id=ci_type.id).all()]
|
||||
for attr in attrs:
|
||||
assert attr.id in ci_type_attribute_ids
|
||||
|
||||
|
||||
def test_get_attributes_ci_type(session, client):
|
||||
ci_type = init_ci_types(1)[0]
|
||||
url = "/api/v0.1/ci_types/{}/attributes".format(ci_type.name)
|
||||
|
||||
resp = client.get(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json["attributes"]) == 1
|
||||
|
||||
|
||||
def test_update_attributes_ci_type(session, client):
|
||||
ci_type = init_ci_types(1)[0]
|
||||
attr = Attribute.query.first()
|
||||
url = "/api/v0.1/ci_types/{}/attributes".format(ci_type.id)
|
||||
|
||||
payload = {
|
||||
"attributes": [
|
||||
{"attr_id": attr.id, "default_show": False, "is_required": True}
|
||||
]
|
||||
}
|
||||
resp = client.put(url, json=payload)
|
||||
assert resp.status_code == 200
|
||||
|
||||
ci_type_attr_ins = CITypeAttribute.query.filter_by(type_id=ci_type.id).first()
|
||||
assert ci_type_attr_ins
|
||||
assert ci_type_attr_ins.is_required is True
|
||||
assert ci_type_attr_ins.default_show is False
|
||||
|
||||
|
||||
def test_create_attribute_group_ci_type(session, client):
|
||||
ci_type = init_ci_types(1)[0]
|
||||
|
||||
url = "/api/v0.1/ci_types/{}/attribute_groups".format(ci_type.id)
|
||||
payload = {
|
||||
"name": "A",
|
||||
"order": 100,
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
|
||||
# check resp status code and content
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["group_id"]
|
||||
|
||||
ins = CITypeAttributeGroup.query.filter_by(type_id=ci_type.id).first()
|
||||
assert ins
|
||||
assert ins.id == resp.json["group_id"]
|
||||
assert ins.name == "A"
|
||||
assert ins.order == 100
|
||||
|
||||
|
||||
def test_update_attribute_group_ci_type(session, client):
|
||||
attribute_groups = init_attribute_groups(1)[0]
|
||||
|
||||
url = "/api/v0.1/ci_types/attribute_groups/{}".format(attribute_groups.id)
|
||||
payload = {
|
||||
"attributes": [x.id for x in Attribute.query.all()]
|
||||
}
|
||||
|
||||
resp = client.put(url, json=payload)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["group_id"]
|
||||
|
||||
ag_items = CITypeAttributeGroupItem.query.filter_by(group_id=attribute_groups.id).all()
|
||||
for a in Attribute.query.all():
|
||||
assert a.id in [x.attr_id for x in ag_items]
|
||||
|
||||
|
||||
def test_delete_attribute_group_ci_type(session, client):
|
||||
attribute_groups = init_attribute_groups(1)[0]
|
||||
|
||||
url = "/api/v0.1/ci_types/attribute_groups/{}".format(attribute_groups.id)
|
||||
resp = client.delete(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
attribute_group_ins = CITypeAttributeGroup.query.filter_by(id=attribute_groups.id).first()
|
||||
assert attribute_group_ins.deleted is True
|
||||
assert attribute_group_ins.deleted_at
|
||||
|
@@ -1 +1,86 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from api.models.cmdb import (
|
||||
CITypeRelation
|
||||
)
|
||||
|
||||
from .sample import init_relation_type, init_ci_types, init_ci_type_relation
|
||||
|
||||
|
||||
def test_create_ci_type_relation(session, client):
|
||||
ci_types = init_ci_types(2)
|
||||
relation_type = init_relation_type(1)[0]
|
||||
|
||||
url = "/api/v0.1/ci_type_relations/{}/{}".format(*[x.id for x in ci_types])
|
||||
payload = {
|
||||
"relation_type_id": relation_type.id,
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["ctr_id"]
|
||||
|
||||
ci_type_relations_id = resp.json["ctr_id"]
|
||||
ci_type_relation = CITypeRelation.get_by_id(ci_type_relations_id)
|
||||
assert ci_type_relation.parent_id == ci_types[0].id
|
||||
assert ci_type_relation.child_id == ci_types[1].id
|
||||
assert ci_type_relation.relation_type_id == relation_type.id
|
||||
|
||||
|
||||
def test_delete_ci_type_relation_by_ci_type_id(session, client):
|
||||
ci_type_relation_ins = init_ci_type_relation(1)[0]
|
||||
url = "/api/v0.1/ci_type_relations/{}/{}".format(
|
||||
ci_type_relation_ins.parent_id, ci_type_relation_ins.child_id)
|
||||
resp = client.delete(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
# fake deleted
|
||||
ci_type_relation_ins = CITypeRelation.query.filter_by(id=ci_type_relation_ins.id).first()
|
||||
assert ci_type_relation_ins is not None
|
||||
|
||||
|
||||
def test_delete_ci_type_relation_by_id(session, client):
|
||||
ci_type_relation_ins = init_ci_type_relation(1)[0]
|
||||
url = "/api/v0.1/ci_type_relations/" + str(ci_type_relation_ins.id)
|
||||
resp = client.delete(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
# fake deleted
|
||||
ci_type_relation_ins = CITypeRelation.query.filter_by(id=ci_type_relation_ins.id).first()
|
||||
assert ci_type_relation_ins is not None
|
||||
|
||||
|
||||
def test_get_ci_type_relations(session, client):
|
||||
ci_type_relations = init_ci_type_relation(2)
|
||||
url = "/api/v0.1/ci_type_relations"
|
||||
resp = client.get(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json) == 2
|
||||
assert resp.json[0]["id"] == ci_type_relations[0].id
|
||||
assert resp.json[1]["id"] == ci_type_relations[1].id
|
||||
|
||||
|
||||
def test_get_children(session, client):
|
||||
ci_type_relation_ins = init_ci_type_relation(1)[0]
|
||||
url = "/api/v0.1/ci_type_relations/{parent_id}/children".format(
|
||||
parent_id=ci_type_relation_ins.parent_id)
|
||||
resp = client.get(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json["children"]) == 1
|
||||
assert resp.json["children"][0]["id"] == ci_type_relation_ins.child_id
|
||||
|
||||
|
||||
def test_get_parents(session, client):
|
||||
ci_type_relation_ins = init_ci_type_relation(1)[0]
|
||||
url = "/api/v0.1/ci_type_relations/{child_id}/parents".format(
|
||||
child_id=ci_type_relation_ins.child_id)
|
||||
resp = client.get(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json["parents"]) == 1
|
||||
assert resp.json["parents"][0]["id"] == ci_type_relation_ins.parent_id
|
||||
|
||||
|
||||
|
||||
|
@@ -1 +1,80 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from api.models.cmdb import (
|
||||
RelationType
|
||||
)
|
||||
|
||||
from .sample import init_relation_type
|
||||
|
||||
|
||||
def test_get_relation_type(session, client):
|
||||
relation_type_instances = init_relation_type(2)
|
||||
url = "/api/v0.1/relation_types"
|
||||
resp = client.get(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json) == 2
|
||||
assert resp.json[0]["id"] == relation_type_instances[0].id
|
||||
assert resp.json[1]["id"] == relation_type_instances[1].id
|
||||
|
||||
|
||||
def test_create_relation_type(session, client):
|
||||
|
||||
url = "/api/v0.1/relation_types"
|
||||
payload = {
|
||||
"name": "test",
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["id"]
|
||||
|
||||
relation_types_id = resp.json["id"]
|
||||
relation_type = RelationType.get_by_id(relation_types_id)
|
||||
assert relation_type.id == relation_types_id
|
||||
assert relation_type.name == "test"
|
||||
|
||||
|
||||
def test_create_relation_type_name_strip(session, client):
|
||||
url = "/api/v0.1/relation_types"
|
||||
payload = {
|
||||
"name": "test\t ",
|
||||
}
|
||||
|
||||
resp = client.post(url, json=payload)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["id"]
|
||||
|
||||
relation_types_id = resp.json["id"]
|
||||
relation_type = RelationType.get_by_id(relation_types_id)
|
||||
assert relation_type.name == "test"
|
||||
|
||||
|
||||
def test_update_relation_type(session, client):
|
||||
relation_type_ins = init_relation_type(1)[0]
|
||||
|
||||
url = "/api/v0.1/relation_types/" + str(relation_type_ins.id)
|
||||
payload = {
|
||||
"name": "update",
|
||||
}
|
||||
|
||||
resp = client.put(url, json=payload)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp.json["id"] == relation_type_ins.id
|
||||
|
||||
relation_type_ins = RelationType.get_by_id(relation_type_ins.id)
|
||||
assert relation_type_ins.name == "update"
|
||||
|
||||
|
||||
def test_delete_relation_type(session, client):
|
||||
relation_type_ins = init_relation_type(1)[0]
|
||||
url = "/api/v0.1/relation_types/" + str(relation_type_ins.id)
|
||||
resp = client.delete(url)
|
||||
|
||||
assert resp.status_code == 200
|
||||
relation_type_ins = RelationType.query.filter_by(id=relation_type_ins.id).first()
|
||||
assert relation_type_ins.deleted is True
|
||||
assert relation_type_ins.deleted_at
|
||||
|
||||
|
@@ -33,6 +33,7 @@
|
||||
"vue": "^2.6.10",
|
||||
"vue-clipboard2": "^0.2.1",
|
||||
"vue-cropper": "0.4.4",
|
||||
"vue-i18n": "^8.15.3",
|
||||
"vue-json-excel": "^0.2.98",
|
||||
"vue-ls": "^3.2.0",
|
||||
"vue-quill-editor": "^3.0.6",
|
||||
@@ -62,11 +63,11 @@
|
||||
"eslint-plugin-vue": "^5.2.3",
|
||||
"less": "^3.0.4",
|
||||
"less-loader": "^5.0.0",
|
||||
"vue-template-compiler": "^2.6.10",
|
||||
"vue-svg-icon-loader": "^2.1.1",
|
||||
"webpack-theme-color-replacer": "^1.2.17",
|
||||
"opencollective": "^1.0.3",
|
||||
"opencollective-postinstall": "^2.0.2"
|
||||
"opencollective-postinstall": "^2.0.2",
|
||||
"vue-svg-icon-loader": "^2.1.1",
|
||||
"vue-template-compiler": "^2.6.10",
|
||||
"webpack-theme-color-replacer": "^1.2.17"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 496 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 165 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 318 KiB |
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 522 KiB |
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 469 KiB |
Before Width: | Height: | Size: 115 KiB |
Before Width: | Height: | Size: 70 KiB |
@@ -7,11 +7,12 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
|
||||
import i18n from '@/locales'
|
||||
import { AppDeviceEnquire } from '@/utils/mixin'
|
||||
import { mixin } from '@/store/i18n-mixin'
|
||||
|
||||
export default {
|
||||
mixins: [AppDeviceEnquire],
|
||||
mixins: [AppDeviceEnquire, mixin],
|
||||
provide () {
|
||||
return {
|
||||
reload: this.reload
|
||||
@@ -19,11 +20,16 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
locale: zhCN,
|
||||
locale: {},
|
||||
alive: true
|
||||
}
|
||||
},
|
||||
mounted () {},
|
||||
created () {
|
||||
this.$watch('currentLang', () => {
|
||||
this.locale = i18n.getLocaleMessage(this.currentLang).antLocale
|
||||
})
|
||||
},
|
||||
|
||||
methods: {
|
||||
reload () {
|
||||
this.alive = false
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { axios } from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 获取 所有的 ci_types
|
||||
* get all CI Type
|
||||
* @param parameter
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
@@ -14,7 +14,7 @@ export function getCITypes (parameter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 某个 ci_types
|
||||
* get a CI Type
|
||||
* @param CITypeName
|
||||
* @param parameter
|
||||
* @returns {AxiosPromise}
|
||||
@@ -28,7 +28,7 @@ export function getCIType (CITypeName, parameter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 ci_type
|
||||
* Create CI Type
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ export function createCIType (data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 ci_type
|
||||
* Update CI Type
|
||||
* @param CITypeId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -55,7 +55,7 @@ export function updateCIType (CITypeId, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 ci_type
|
||||
* Delete CI Type
|
||||
* @param CITypeId
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
@@ -67,7 +67,7 @@ export function deleteCIType (CITypeId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 某个 ci_type 的分组
|
||||
* Gets a grouping of a CI Type
|
||||
* @param CITypeId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -81,7 +81,7 @@ export function getCITypeGroupById (CITypeId, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存 某个 ci_type 的分组
|
||||
* Save a group of CI Type
|
||||
* @param CITypeId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -95,7 +95,7 @@ export function createCITypeGroupById (CITypeId, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 某个 ci_type 的分组
|
||||
* Changes the grouping of a CI Type
|
||||
* @param groupId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -109,7 +109,7 @@ export function updateCITypeGroupById (groupId, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 某个 ci_type 的分组
|
||||
* Removes a group for a CI Type
|
||||
* @param groupId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { axios } from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 获取 ci_type 的属性
|
||||
* Get CI Type attributes
|
||||
* @param CITypeName
|
||||
* @param parameter
|
||||
* @returns {AxiosPromise}
|
||||
@@ -16,7 +16,7 @@ export function getCITypeAttributesByName (CITypeName, parameter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 ci_type 的属性
|
||||
* Get CI Type attributes
|
||||
* @param CITypeId
|
||||
* @param parameter
|
||||
* @returns {AxiosPromise}
|
||||
@@ -30,7 +30,7 @@ export function getCITypeAttributesById (CITypeId, parameter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新属性
|
||||
* Update attribute
|
||||
* @param attrId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -44,7 +44,7 @@ export function updateAttributeById (attrId, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加属性
|
||||
* Add attribute
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ export function createAttribute (data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索属性/ 获取所有的属性
|
||||
* Search attributes or get all attributes
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
@@ -70,7 +70,7 @@ export function searchAttributes (params) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除属性
|
||||
* Delete attribute
|
||||
* @param attrId
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
@@ -82,7 +82,7 @@ export function deleteAttributesById (attrId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定ci_type 属性
|
||||
* Bind attribute
|
||||
* @param CITypeId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -96,7 +96,7 @@ export function createCITypeAttributes (CITypeId, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新ci_type 属性
|
||||
* Update CI Type attribute
|
||||
* @param CITypeId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -110,7 +110,7 @@ export function updateCITypeAttributesById (CITypeId, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除ci_type 属性
|
||||
* Delete CI Type attribute
|
||||
* @param CITypeId
|
||||
* @param data
|
||||
* @returns {AxiosPromise}
|
||||
@@ -122,3 +122,19 @@ export function deleteCITypeAttributesById (CITypeId, data) {
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
export function transferCITypeAttrIndex (CITypeId, data) {
|
||||
return axios({
|
||||
url: `/v0.1/ci_types/${CITypeId}/attributes/transfer`,
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
export function transferCITypeGroupIndex (CITypeId, data) {
|
||||
return axios({
|
||||
url: `/v0.1/ci_types/${CITypeId}/attribute_groups/transfer`,
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
@@ -42,26 +42,23 @@ export function writeExcel (columns, name) {
|
||||
return s
|
||||
}
|
||||
|
||||
// 判断一个数组元素是否都为空的
|
||||
// Determines whether an array element is empty
|
||||
export function any (ArrayList) {
|
||||
let flag = false
|
||||
for (let i = 0; i < ArrayList.length; i++) {
|
||||
if (ArrayList[i]) {
|
||||
flag = true
|
||||
return flag
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 去除一个二维数组 底下为空的部分
|
||||
export function filterNull (twoDimArray) {
|
||||
console.log(twoDimArray)
|
||||
const newArray = []
|
||||
for (let i = 0; i < twoDimArray.length; i++) {
|
||||
if (any(twoDimArray[i])) {
|
||||
newArray.push(twoDimArray[i])
|
||||
twoDimArray.forEach(item => {
|
||||
if (any(item)) {
|
||||
newArray.push(item)
|
||||
}
|
||||
}
|
||||
})
|
||||
return newArray
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ export function deleteCI (ciId) {
|
||||
})
|
||||
}
|
||||
|
||||
// 获取单个ci实例
|
||||
// Get a single CI instance
|
||||
export function getCIById (ciId) {
|
||||
return axios({
|
||||
url: urlPrefix + `/ci/${ciId}`,
|
||||
|
BIN
cmdb-ui/src/assets/cmdb.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
@@ -15,7 +15,7 @@
|
||||
<div class="header-index-wide">
|
||||
<div class="header-index-left">
|
||||
<logo class="top-nav-header" :show-title="device !== 'mobile'"/>
|
||||
<s-menu v-if="device !== 'mobile'" mode="horizontal" :menu="menus" :theme="theme" />
|
||||
<s-menu v-if="device !== 'mobile'" mode="horizontal" :menu="menus" :theme="theme" :i18n-render="i18nRender" />
|
||||
<a-icon v-else class="trigger" :type="collapsed ? 'menu-fold' : 'menu-unfold'" @click="toggle" />
|
||||
</div>
|
||||
<top-menu></top-menu>
|
||||
@@ -33,6 +33,7 @@ import TopMenu from '../tools/TopMenu'
|
||||
import SMenu from '../Menu/'
|
||||
import Logo from '../tools/Logo'
|
||||
import { mixin } from '@/utils/mixin'
|
||||
import { i18nRender } from '@/locales'
|
||||
|
||||
export default {
|
||||
name: 'GlobalHeader',
|
||||
@@ -79,6 +80,7 @@ export default {
|
||||
document.addEventListener('scroll', this.handleScroll, { passive: true })
|
||||
},
|
||||
methods: {
|
||||
i18nRender,
|
||||
handleScroll () {
|
||||
if (!this.autoHideHeader) {
|
||||
return
|
||||
|
@@ -11,6 +11,7 @@
|
||||
:menu="menus"
|
||||
:theme="theme"
|
||||
:mode="mode"
|
||||
:i18n-render="i18nRender"
|
||||
@select="onSelect"
|
||||
style="padding: 16px 0px;"></s-menu>
|
||||
</a-layout-sider>
|
||||
@@ -20,6 +21,7 @@
|
||||
<script>
|
||||
import Logo from '@/components/tools/Logo'
|
||||
import SMenu from './index'
|
||||
import { i18nRender } from '@/locales'
|
||||
import { mixin, mixinDevice } from '@/utils/mixin'
|
||||
|
||||
export default {
|
||||
@@ -53,6 +55,7 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
i18nRender,
|
||||
onSelect (obj) {
|
||||
this.$emit('menuSelect', obj)
|
||||
}
|
||||
|
@@ -1,31 +1,99 @@
|
||||
import Menu from 'ant-design-vue/es/menu'
|
||||
import Icon from 'ant-design-vue/es/icon'
|
||||
import { Menu, Icon } from 'ant-design-vue'
|
||||
|
||||
const { Item, SubMenu } = Menu
|
||||
|
||||
export default {
|
||||
name: 'SMenu',
|
||||
props: {
|
||||
menu: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
theme: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: 'dark'
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: 'inline'
|
||||
},
|
||||
collapsed: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false
|
||||
}
|
||||
const menuProps = {
|
||||
menu: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
theme: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: 'dark'
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: 'inline'
|
||||
},
|
||||
collapsed: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false
|
||||
},
|
||||
i18nRender: {
|
||||
type: Function,
|
||||
required: false
|
||||
}
|
||||
}
|
||||
|
||||
const defaultI18nRender = (key) => `${key}`
|
||||
|
||||
// render
|
||||
const renderItem = (h, menu, i18nRender) => {
|
||||
if (!menu.hidden) {
|
||||
// const localeKey = `menu.${menu.name}`
|
||||
// const localeKey = menu.meta && menu.meta.title
|
||||
// i18nRender(localeKey)
|
||||
return menu.children && !menu.hideChildrenInMenu ? renderSubMenu(h, menu, i18nRender) : renderMenuItem(h, menu, i18nRender)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const renderMenuItem = (h, menu, i18nRender) => {
|
||||
const target = menu.meta.target || null
|
||||
const CustomTag = target && 'a' || 'router-link'
|
||||
const props = { to: { name: menu.name } }
|
||||
const attrs = { href: menu.path, target: menu.meta.target }
|
||||
|
||||
if (menu.children && menu.hideChildrenInMenu) {
|
||||
// 把有子菜单的 并且 父菜单是要隐藏子菜单的
|
||||
// 都给子菜单增加一个 hidden 属性
|
||||
// 用来给刷新页面时, selectedKeys 做控制用
|
||||
menu.children.forEach(item => {
|
||||
item.meta = Object.assign(item.meta, { hidden: true })
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<Menu.Item {...{ key: menu.path }}>
|
||||
<CustomTag {...{ props, attrs }}>
|
||||
{renderIcon(h, menu.meta.icon)}
|
||||
<span>{i18nRender(menu.meta.title)}</span>
|
||||
</CustomTag>
|
||||
</Menu.Item>
|
||||
)
|
||||
}
|
||||
|
||||
const renderSubMenu = (h, menu, i18nRender) => {
|
||||
const itemArr = []
|
||||
if (!menu.hideChildrenInMenu) {
|
||||
menu.children.forEach(item => itemArr.push(renderItem(h, item, i18nRender)))
|
||||
}
|
||||
return (
|
||||
<Menu.SubMenu {...{ key: menu.path }}>
|
||||
<span slot="title">
|
||||
{renderIcon(h, menu.meta.icon)}
|
||||
<span>{i18nRender(menu.meta.title)}</span>
|
||||
</span>
|
||||
{itemArr}
|
||||
</Menu.SubMenu>
|
||||
)
|
||||
}
|
||||
|
||||
const renderIcon = (h, icon) => {
|
||||
if (icon === 'none' || icon === undefined) {
|
||||
return null
|
||||
}
|
||||
const props = {}
|
||||
typeof (icon) === 'object' ? props.component = icon : props.type = icon
|
||||
return (
|
||||
<Icon {...{ props }}/>
|
||||
)
|
||||
}
|
||||
|
||||
const SMenu = {
|
||||
name: 'SMenu',
|
||||
props: menuProps,
|
||||
data () {
|
||||
return {
|
||||
openKeys: [],
|
||||
@@ -41,24 +109,20 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
|
||||
},
|
||||
mounted () {
|
||||
this.updateMenu()
|
||||
},
|
||||
watch: {
|
||||
collapsed (val) {
|
||||
if (val) {
|
||||
this.$watch('collapsed', collapsed => {
|
||||
if (collapsed) {
|
||||
this.cachedOpenKeys = this.openKeys.concat()
|
||||
this.openKeys = []
|
||||
} else {
|
||||
this.openKeys = this.cachedOpenKeys
|
||||
}
|
||||
},
|
||||
$route: function () {
|
||||
})
|
||||
this.$watch('$route', () => {
|
||||
this.updateMenu()
|
||||
}
|
||||
|
||||
})
|
||||
},
|
||||
mounted () {
|
||||
this.updateMenu()
|
||||
},
|
||||
methods: {
|
||||
// select menu item
|
||||
@@ -78,7 +142,6 @@ export default {
|
||||
},
|
||||
updateMenu () {
|
||||
const routes = this.$route.matched.concat()
|
||||
|
||||
const { hidden } = this.$route.meta
|
||||
if (routes.length >= 3 && hidden) {
|
||||
routes.pop()
|
||||
@@ -94,67 +157,10 @@ export default {
|
||||
}
|
||||
|
||||
this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.openKeys = openKeys)
|
||||
},
|
||||
// render
|
||||
renderItem (menu) {
|
||||
if (!menu.hidden) {
|
||||
return menu.children && !menu.hideChildrenInMenu ? this.renderSubMenu(menu) : this.renderMenuItem(menu)
|
||||
}
|
||||
return null
|
||||
},
|
||||
renderMenuItem (menu) {
|
||||
const target = menu.meta.target || null
|
||||
const tag = target && 'a' || 'router-link'
|
||||
const props = { to: { name: menu.name } }
|
||||
const attrs = { href: menu.path, target: menu.meta.target }
|
||||
|
||||
if (menu.children && menu.hideChildrenInMenu) {
|
||||
// 把有子菜单的 并且 父菜单是要隐藏子菜单的
|
||||
// 都给子菜单增加一个 hidden 属性
|
||||
// 用来给刷新页面时, selectedKeys 做控制用
|
||||
menu.children.forEach(item => {
|
||||
item.meta = Object.assign(item.meta, { hidden: true })
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<Item {...{ key: menu.path }}>
|
||||
<tag {...{ props, attrs }}>
|
||||
{this.renderIcon(menu.meta.icon)}
|
||||
<span>{menu.meta.title}</span>
|
||||
</tag>
|
||||
</Item>
|
||||
)
|
||||
},
|
||||
renderSubMenu (menu) {
|
||||
const itemArr = []
|
||||
if (!menu.hideChildrenInMenu) {
|
||||
menu.children.forEach(item => itemArr.push(this.renderItem(item)))
|
||||
}
|
||||
return (
|
||||
<SubMenu {...{ key: menu.path }}>
|
||||
<span slot="title">
|
||||
{this.renderIcon(menu.meta.icon)}
|
||||
<span>{menu.meta.title}</span>
|
||||
</span>
|
||||
{itemArr}
|
||||
</SubMenu>
|
||||
)
|
||||
},
|
||||
renderIcon (icon) {
|
||||
if (icon === 'none' || icon === undefined) {
|
||||
return null
|
||||
}
|
||||
const props = {}
|
||||
typeof (icon) === 'object' ? props.component = icon : props.type = icon
|
||||
return (
|
||||
<Icon {... { props }} />
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
render () {
|
||||
const { mode, theme, menu } = this
|
||||
render (h) {
|
||||
const { mode, theme, menu, i18nRender = defaultI18nRender } = this
|
||||
const props = {
|
||||
mode: mode,
|
||||
theme: theme,
|
||||
@@ -172,7 +178,7 @@ export default {
|
||||
if (item.hidden) {
|
||||
return null
|
||||
}
|
||||
return this.renderItem(item)
|
||||
return renderItem(h, item, i18nRender)
|
||||
})
|
||||
// {...{ props, on: on }}
|
||||
return (
|
||||
@@ -182,3 +188,5 @@ export default {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default SMenu
|
||||
|
156
cmdb-ui/src/components/Menu/menu.render.js
Normal file
@@ -0,0 +1,156 @@
|
||||
import Menu from 'ant-design-vue/es/menu'
|
||||
import Icon from 'ant-design-vue/es/icon'
|
||||
|
||||
const { Item, SubMenu } = Menu
|
||||
|
||||
export default {
|
||||
name: 'SMenu',
|
||||
props: {
|
||||
menu: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
theme: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: 'dark'
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: 'inline'
|
||||
},
|
||||
collapsed: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
openKeys: [],
|
||||
selectedKeys: [],
|
||||
cachedOpenKeys: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
rootSubmenuKeys: vm => {
|
||||
const keys = []
|
||||
vm.menu.forEach(item => keys.push(item.path))
|
||||
return keys
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.updateMenu()
|
||||
},
|
||||
watch: {
|
||||
collapsed (val) {
|
||||
if (val) {
|
||||
this.cachedOpenKeys = this.openKeys.concat()
|
||||
this.openKeys = []
|
||||
} else {
|
||||
this.openKeys = this.cachedOpenKeys
|
||||
}
|
||||
},
|
||||
$route: function () {
|
||||
this.updateMenu()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
renderIcon: function (h, icon) {
|
||||
if (icon === 'none' || icon === undefined) {
|
||||
return null
|
||||
}
|
||||
const props = {}
|
||||
typeof (icon) === 'object' ? props.component = icon : props.type = icon
|
||||
return h(Icon, { props: { ...props } })
|
||||
},
|
||||
renderMenuItem: function (h, menu, pIndex, index) {
|
||||
const target = menu.meta.target || null
|
||||
return h(Item, { key: menu.path ? menu.path : 'item_' + pIndex + '_' + index }, [
|
||||
h('router-link', { attrs: { to: { name: menu.name }, target: target } }, [
|
||||
this.renderIcon(h, menu.meta.icon),
|
||||
h('span', [menu.meta.title])
|
||||
])
|
||||
])
|
||||
},
|
||||
renderSubMenu: function (h, menu, pIndex, index) {
|
||||
const this2_ = this
|
||||
const subItem = [h('span', { slot: 'title' }, [this.renderIcon(h, menu.meta.icon), h('span', [menu.meta.title])])]
|
||||
const itemArr = []
|
||||
const pIndex_ = pIndex + '_' + index
|
||||
console.log('menu', menu)
|
||||
if (!menu.hideChildrenInMenu) {
|
||||
menu.children.forEach(function (item, i) {
|
||||
itemArr.push(this2_.renderItem(h, item, pIndex_, i))
|
||||
})
|
||||
}
|
||||
return h(SubMenu, { key: menu.path ? menu.path : 'submenu_' + pIndex + '_' + index }, subItem.concat(itemArr))
|
||||
},
|
||||
renderItem: function (h, menu, pIndex, index) {
|
||||
if (!menu.hidden) {
|
||||
return menu.children && !menu.hideChildrenInMenu
|
||||
? this.renderSubMenu(h, menu, pIndex, index)
|
||||
: this.renderMenuItem(h, menu, pIndex, index)
|
||||
}
|
||||
},
|
||||
renderMenu: function (h, menuTree) {
|
||||
const this2_ = this
|
||||
const menuArr = []
|
||||
menuTree.forEach(function (menu, i) {
|
||||
if (!menu.hidden) {
|
||||
menuArr.push(this2_.renderItem(h, menu, '0', i))
|
||||
}
|
||||
})
|
||||
return menuArr
|
||||
},
|
||||
onOpenChange (openKeys) {
|
||||
const latestOpenKey = openKeys.find(key => !this.openKeys.includes(key))
|
||||
if (!this.rootSubmenuKeys.includes(latestOpenKey)) {
|
||||
this.openKeys = openKeys
|
||||
} else {
|
||||
this.openKeys = latestOpenKey ? [latestOpenKey] : []
|
||||
}
|
||||
},
|
||||
updateMenu () {
|
||||
const routes = this.$route.matched.concat()
|
||||
|
||||
if (routes.length >= 4 && this.$route.meta.hidden) {
|
||||
routes.pop()
|
||||
this.selectedKeys = [routes[2].path]
|
||||
} else {
|
||||
this.selectedKeys = [routes.pop().path]
|
||||
}
|
||||
|
||||
const openKeys = []
|
||||
if (this.mode === 'inline') {
|
||||
routes.forEach(item => {
|
||||
openKeys.push(item.path)
|
||||
})
|
||||
}
|
||||
|
||||
this.collapsed ? (this.cachedOpenKeys = openKeys) : (this.openKeys = openKeys)
|
||||
}
|
||||
},
|
||||
render (h) {
|
||||
return h(
|
||||
Menu,
|
||||
{
|
||||
props: {
|
||||
theme: this.$props.theme,
|
||||
mode: this.$props.mode,
|
||||
openKeys: this.openKeys,
|
||||
selectedKeys: this.selectedKeys
|
||||
},
|
||||
on: {
|
||||
openChange: this.onOpenChange,
|
||||
select: obj => {
|
||||
this.selectedKeys = obj.selectedKeys
|
||||
this.$emit('select', obj)
|
||||
}
|
||||
}
|
||||
},
|
||||
this.renderMenu(h, this.menu)
|
||||
)
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="page-header">
|
||||
<div class="page-header-index-wide">
|
||||
<s-breadcrumb />
|
||||
<s-breadcrumb :i18n-render="i18nRender" />
|
||||
<div class="detail">
|
||||
<div class="main" v-if="!$route.meta.hiddenHeaderContent">
|
||||
<div class="row">
|
||||
@@ -32,7 +32,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* eslint-disable */
|
||||
import Breadcrumb from '@/components/tools/Breadcrumb'
|
||||
import { i18nRender } from '@/locales'
|
||||
|
||||
export default {
|
||||
name: 'PageHeader',
|
||||
@@ -58,6 +60,9 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {}
|
||||
},
|
||||
methods () {
|
||||
i18nRender
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import T from 'ant-design-vue/es/table/Table'
|
||||
import get from 'lodash.get'
|
||||
import i18n from '@/locales'
|
||||
|
||||
export default {
|
||||
data () {
|
||||
@@ -232,7 +233,7 @@ export default {
|
||||
<a style="margin-left: 24px" onClick={() => {
|
||||
callback()
|
||||
this.clearSelected()
|
||||
}}>清空</a>
|
||||
}}>{ i18n.t('table.clear') }</a>
|
||||
)
|
||||
},
|
||||
renderAlert () {
|
||||
@@ -254,7 +255,7 @@ export default {
|
||||
return (
|
||||
<a-alert showIcon={true} style="margin-bottom: 16px">
|
||||
<template slot="message">
|
||||
<span style="margin-right: 12px">已选择: <a style="font-weight: 600">{this.selectedRows.length}</a></span>
|
||||
<span style="margin-right: 12px">{ i18n.t('table.selected') }: <a style="font-weight: 600">{this.selectedRows.length}</a></span>
|
||||
{needTotalItems}
|
||||
{clearItem}
|
||||
</template>
|
||||
|
@@ -4,14 +4,20 @@
|
||||
<router-link
|
||||
v-if="item.name != name && index != 1"
|
||||
:to="{ path: item.path === '' ? '/' : item.path }"
|
||||
>{{ item.meta.title }}</router-link>
|
||||
<span v-else>{{ item.meta.title }}</span>
|
||||
>{{ i18nRender(item.meta.title) }}</router-link>
|
||||
<span v-else>{{ i18nRender(item.meta.title) }}</span>
|
||||
</a-breadcrumb-item>
|
||||
</a-breadcrumb>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
i18nRender: {
|
||||
type: Function,
|
||||
default: (r) => `${r}`
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
name: '',
|
||||
|
38
cmdb-ui/src/components/tools/LangSelect.vue
Normal file
@@ -0,0 +1,38 @@
|
||||
<template>
|
||||
<a-dropdown>
|
||||
<span class="action global-lang">
|
||||
<a-icon type="global" style="font-size: 16px"/>
|
||||
</span>
|
||||
<a-menu slot="overlay" style="width: 150px;" @click="SwitchLang">
|
||||
<a-menu-item key="zh-CN">
|
||||
<a rel="noopener noreferrer">
|
||||
<span role="img" aria-label="简体中文">🇨🇳</span> 简体中文
|
||||
</a>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="en-US">
|
||||
<a rel="noopener noreferrer">
|
||||
<span role="img" aria-label="English">🇬🇧</span> English
|
||||
</a>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</a-dropdown>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mixin as langMixin } from '@/store/i18n-mixin'
|
||||
|
||||
export default {
|
||||
name: 'LangSelect',
|
||||
mixins: [langMixin],
|
||||
data () {
|
||||
return {}
|
||||
},
|
||||
inject: ['reload'],
|
||||
methods: {
|
||||
SwitchLang (row) {
|
||||
this.setLang(row.key)
|
||||
this.reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
@@ -1,7 +1,12 @@
|
||||
<template>
|
||||
<div class="logo">
|
||||
<router-link :to="{name:'cmdb'}">
|
||||
<h1 v-if="showTitle">{{ title }}</h1>
|
||||
<div style="margin-right: 24px">
|
||||
<div style="display: inline-block;">
|
||||
<img src="@/assets/cmdb.png" width="50px" height="50px" style="margin:0; padding:0" />
|
||||
</div>
|
||||
<h1 v-if="showTitle">{{ title }}</h1>
|
||||
</div>
|
||||
</router-link>
|
||||
</div>
|
||||
</template>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<div class="content-box">
|
||||
<a href="https://github.com/pycook/cmdb" target="_blank">
|
||||
<span class="action">
|
||||
源代码 -> <a-icon type="github" style="font-size: 20px; color: #002140"></a-icon>
|
||||
{{ $t('tip.sourceCode') }} -> <a-icon type="github" style="font-size: 20px; color: #002140"></a-icon>
|
||||
</span>
|
||||
</a>
|
||||
<!-- <a href="https://pro.loacg.com/docs/getting-started" target="_blank">
|
||||
@@ -34,11 +34,12 @@
|
||||
<a-menu-item key="3">
|
||||
<a href="javascript:;" @click="handleLogout">
|
||||
<a-icon type="logout"/>
|
||||
<span>退出登录</span>
|
||||
<span>{{ $t('login.logout') }}</span>
|
||||
</a>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</a-dropdown>
|
||||
<lang-select v-if="showLocale" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -46,11 +47,18 @@
|
||||
<script>
|
||||
import NoticeIcon from '@/components/NoticeIcon'
|
||||
import { mapActions, mapGetters } from 'vuex'
|
||||
import LangSelect from '@/components/tools/LangSelect'
|
||||
import config from '@/config/defaultSettings'
|
||||
|
||||
export default {
|
||||
name: 'UserMenu',
|
||||
components: {
|
||||
NoticeIcon
|
||||
NoticeIcon, LangSelect
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
showLocale: config.showLocale
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['Logout']),
|
||||
@@ -59,8 +67,8 @@ export default {
|
||||
const that = this
|
||||
|
||||
this.$confirm({
|
||||
title: '提示',
|
||||
content: '真的要注销登录吗 ?',
|
||||
title: this.$t('tip.warning'),
|
||||
content: this.$t('login.confirmLogout'),
|
||||
onOk () {
|
||||
return that.Logout()
|
||||
},
|
||||
|
@@ -1,19 +1,24 @@
|
||||
/**
|
||||
* 项目默认配置项
|
||||
* primaryColor - 默认主题色, 如果修改颜色不生效,请清理 localStorage
|
||||
* navTheme - sidebar theme ['dark', 'light'] 两种主题
|
||||
* colorWeak - 色盲模式
|
||||
* layout - 整体布局方式 ['sidemenu', 'topmenu'] 两种布局
|
||||
* fixedHeader - 固定 Header : boolean
|
||||
* fixSiderbar - 固定左侧菜单栏 : boolean
|
||||
* autoHideHeader - 向下滚动时,隐藏 Header : boolean
|
||||
* contentWidth - 内容区布局: 流式 | 固定
|
||||
* Project default configuration items
|
||||
* showLocale - Whether to display the Chinese and English switch buttons: boolean
|
||||
* defaultLang - Default display language: zh-CN | en-US
|
||||
* useSSO - Whether to use single sign-on: boolean
|
||||
* primaryColor - Default theme color, clean up localStorage if changing color does not take effect
|
||||
* navTheme - sidebar theme ['dark', 'light']
|
||||
* colorWeak - Color blindness mode
|
||||
* layout - Overall layout ['sidemenu', 'topmenu']
|
||||
* fixedHeader - Fix Header: boolean
|
||||
* fixSiderbar - Fix the left menu bar: boolean
|
||||
* autoHideHeader - Hide header as you scroll down: boolean
|
||||
* contentWidth - Content area layout: streaming | fixed
|
||||
*
|
||||
* storageOptions: {} - Vue-ls 插件配置项 (localStorage/sessionStorage)
|
||||
* storageOptions: {} - Vue-ls Plug-in configuration item (localStorage/sessionStorage)
|
||||
*
|
||||
*/
|
||||
|
||||
export default {
|
||||
showLocale: true,
|
||||
defaultLang: 'en-US', // zh-CN | en-US
|
||||
useSSO: false,
|
||||
primaryColor: '#1890ff', // primary color of ant design
|
||||
navTheme: 'dark', // theme for nav menu
|
||||
|
@@ -5,26 +5,28 @@ import { UserLayout, BasicLayout, RouteView } from '@/layouts'
|
||||
import { getPreference } from '@/api/cmdb/preference'
|
||||
|
||||
const cmdbRouter = [
|
||||
// preference
|
||||
// resource views
|
||||
{
|
||||
path: '/preference',
|
||||
component: () => import('@/views/cmdb/preference'),
|
||||
name: 'cmdb_preference',
|
||||
meta: { title: '我的订阅', icon: 'book', keepAlive: true }
|
||||
path: '/resource_views',
|
||||
redirect: '/relation_views',
|
||||
component: RouteView,
|
||||
name: 'cmdb_resource_views',
|
||||
meta: { title: 'menu.resourceViews', icon: 'hdd', keepAlive: true },
|
||||
children: []
|
||||
},
|
||||
// relation views
|
||||
{
|
||||
path: '/relation_views',
|
||||
component: () => import('@/views/cmdb/relation_views'),
|
||||
name: 'cmdb_relation_views',
|
||||
meta: { title: '关系视图', icon: 'link', keepAlive: true },
|
||||
meta: { title: 'menu.relationViews', icon: 'link', keepAlive: true },
|
||||
hideChildrenInMenu: true,
|
||||
children: [
|
||||
{
|
||||
path: '/relation_views/:viewId',
|
||||
name: 'cmdb_relation_views_item',
|
||||
component: () => import('@/views/cmdb/relation_views'),
|
||||
meta: { title: '关系视图', keepAlive: true },
|
||||
meta: { title: 'menu.relationViews', keepAlive: true },
|
||||
hidden: true
|
||||
}]
|
||||
},
|
||||
@@ -33,44 +35,51 @@ const cmdbRouter = [
|
||||
path: '/tree_views',
|
||||
component: () => import('@/views/cmdb/tree_views'),
|
||||
name: 'cmdb_tree_views',
|
||||
meta: { title: '树形视图', icon: 'share-alt', keepAlive: true },
|
||||
meta: { title: 'menu.treeViews', icon: 'share-alt', keepAlive: true },
|
||||
hideChildrenInMenu: true,
|
||||
children: [
|
||||
{
|
||||
path: '/tree_views/:typeId',
|
||||
name: 'cmdb_tree_views_item',
|
||||
component: () => import('@/views/cmdb/tree_views'),
|
||||
meta: { title: '树形视图', keepAlive: true },
|
||||
meta: { title: 'menu.treeViews', keepAlive: true },
|
||||
hidden: true
|
||||
}]
|
||||
},
|
||||
// preference
|
||||
{
|
||||
path: '/preference',
|
||||
component: () => import('@/views/cmdb/preference'),
|
||||
name: 'cmdb_preference',
|
||||
meta: { title: 'menu.preference', icon: 'star', keepAlive: true }
|
||||
},
|
||||
// batch
|
||||
{
|
||||
path: '/batch',
|
||||
component: () => import('@/views/cmdb/batch'),
|
||||
name: 'cmdb_batch',
|
||||
meta: { 'title': '批量导入', icon: 'upload', keepAlive: true }
|
||||
meta: { 'title': 'menu.batch', icon: 'upload', keepAlive: true }
|
||||
},
|
||||
{
|
||||
path: '/config//ci_types',
|
||||
path: '/config/ci_types',
|
||||
name: 'cmdb_ci_type',
|
||||
component: RouteView,
|
||||
redirect: '/ci_types',
|
||||
meta: { title: '模型配置', icon: 'setting', permission: ['admin'] },
|
||||
meta: { title: 'menu.ciType', icon: 'setting', permission: ['admin'] },
|
||||
children: [
|
||||
{
|
||||
path: '/config/ci_types',
|
||||
name: 'ci_type',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/cmdb/modeling/ci_type/list'),
|
||||
meta: { title: '模型管理', keepAlive: true }
|
||||
meta: { title: 'menu.ciModelManager', keepAlive: true }
|
||||
},
|
||||
{
|
||||
path: '/config/ci_types/:CITypeName/detail/:CITypeId',
|
||||
name: 'ci_type_detail',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/cmdb/modeling/ci_type/detail'),
|
||||
meta: { title: '模型管理', keepAlive: true, hidden: true },
|
||||
meta: { title: 'menu.ciModelManager', keepAlive: true, hidden: true },
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
@@ -78,21 +87,21 @@ const cmdbRouter = [
|
||||
name: 'attributes',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/cmdb/modeling/attributes/index'),
|
||||
meta: { title: '属性库', keepAlive: true }
|
||||
meta: { title: 'menu.ciPropertyRep', keepAlive: true }
|
||||
},
|
||||
{
|
||||
path: '/config/relation_type',
|
||||
name: 'relation_type',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/cmdb/modeling/relation_type/index'),
|
||||
meta: { title: '关系类型', keepAlive: true }
|
||||
meta: { title: 'menu.ciRelationType', keepAlive: true }
|
||||
},
|
||||
{
|
||||
path: '/config/preference_relation',
|
||||
name: 'preference_relation',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/cmdb/modeling/preference_relation/index'),
|
||||
meta: { title: '关系视图定义', keepAlive: true }
|
||||
meta: { title: 'menu.ciRelationViewDefine', keepAlive: true }
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -101,35 +110,35 @@ const cmdbRouter = [
|
||||
name: 'cmdb_acl',
|
||||
component: RouteView,
|
||||
redirect: '/acl/users',
|
||||
meta: { title: '权限管理', icon: 'safety-certificate', permission: ['admin'] },
|
||||
meta: { title: 'menu.acl', icon: 'safety-certificate', permission: ['admin'] },
|
||||
children: [
|
||||
{
|
||||
path: '/acl/users',
|
||||
name: 'cmdb_acl_users',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/acl/users'),
|
||||
meta: { title: '用户管理', keepAlive: true }
|
||||
meta: { title: 'menu.aclUsersManager', keepAlive: true }
|
||||
},
|
||||
{
|
||||
path: '/acl/roles',
|
||||
name: 'cmdb_acl_roles',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/acl/roles'),
|
||||
meta: { title: '角色管理', keepAlive: true }
|
||||
meta: { title: 'menu.aclRolesManager', keepAlive: true }
|
||||
},
|
||||
{
|
||||
path: '/acl/resources',
|
||||
name: 'cmdb_acl_resources',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/acl/resources'),
|
||||
meta: { title: '资源管理', keepAlive: true }
|
||||
meta: { title: 'menu.aclResourceManager', keepAlive: true }
|
||||
},
|
||||
{
|
||||
path: '/acl/resource_types',
|
||||
name: 'cmdb_acl_resource_types',
|
||||
hideChildrenInMenu: true,
|
||||
component: () => import('@/views/acl/resource_types'),
|
||||
meta: { title: '资源类型', keepAlive: true }
|
||||
meta: { title: 'menu.aclResourceType', keepAlive: true }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -147,20 +156,21 @@ function copyArray (arr) {
|
||||
|
||||
export const generatorDynamicRouter = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// cmdb 订阅的模型
|
||||
// sub menu of the resource view
|
||||
getPreference().then(res => {
|
||||
const routers = copyArray(asyncRouterMap)
|
||||
routers[0].children = copyArray(cmdbRouter)
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const item = res[i]
|
||||
routers[0].children.unshift({
|
||||
const resourceMenus = []
|
||||
res.forEach(item => {
|
||||
resourceMenus.push({
|
||||
path: `/instances/types/${item.id}`,
|
||||
component: () => import(`@/views/cmdb/ci/index`),
|
||||
name: `cmdb_${item.id}`,
|
||||
meta: { title: item.alias, icon: 'table', keepAlive: true, typeId: item.id },
|
||||
hideChildrenInMenu: true
|
||||
})
|
||||
}
|
||||
})
|
||||
routers[0].children[0].children = resourceMenus
|
||||
|
||||
resolve(routers)
|
||||
})
|
||||
@@ -183,7 +193,7 @@ const asyncRouterMap = [
|
||||
]
|
||||
|
||||
/**
|
||||
* 基础路由
|
||||
* basic route
|
||||
* @type { *[] }
|
||||
*/
|
||||
export const constantRouterMap = [
|
||||
|
@@ -8,7 +8,7 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="desc">
|
||||
运维资产数据管理
|
||||
{{ $t('login.subTitle') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
62
cmdb-ui/src/locales/index.js
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
import Vue from 'vue'
|
||||
import VueI18n from 'vue-i18n'
|
||||
// default language
|
||||
import enUS from './lang/en-US'
|
||||
import zhCN from './lang/zh-CN'
|
||||
// change default accept-language
|
||||
import { axios } from '@/utils/request'
|
||||
import config from '@/config/defaultSettings'
|
||||
|
||||
Vue.use(VueI18n)
|
||||
|
||||
const messages = {
|
||||
'en-US': {
|
||||
...enUS
|
||||
},
|
||||
'zh-CN': {
|
||||
...zhCN
|
||||
}
|
||||
}
|
||||
|
||||
const i18n = new VueI18n({
|
||||
locale: config.defaultLang,
|
||||
fallbackLocale: config.defaultLang,
|
||||
messages
|
||||
})
|
||||
|
||||
export default i18n
|
||||
|
||||
const loadedLanguages = [config.defaultLang]
|
||||
|
||||
function setI18nLanguage (lang) {
|
||||
i18n.locale = lang
|
||||
axios.defaults.headers.common['Accept-Language'] = lang
|
||||
document.querySelector('html').setAttribute('lang', lang)
|
||||
return lang
|
||||
}
|
||||
|
||||
export function i18nRender (key) {
|
||||
return i18n.t(key)
|
||||
}
|
||||
|
||||
export function loadLanguageAsync (lang = config.defaultLang) {
|
||||
return new Promise(resolve => {
|
||||
localStorage.setItem('lang', lang)
|
||||
if (i18n.locale !== lang) {
|
||||
if (!loadedLanguages.includes(lang)) {
|
||||
return import(/* webpackChunkName: "lang-[request]" */ `./lang/${lang}`).then(msg => {
|
||||
i18n.setLocaleMessage(lang, msg.default)
|
||||
loadedLanguages.push(lang)
|
||||
return setI18nLanguage(lang)
|
||||
})
|
||||
}
|
||||
return resolve(setI18nLanguage(lang))
|
||||
}
|
||||
return resolve(lang)
|
||||
})
|
||||
}
|
||||
|
||||
if (localStorage.getItem('lang') !== null && config.defaultLang !== localStorage.getItem('lang')) {
|
||||
loadLanguageAsync(localStorage.lang)
|
||||
}
|
229
cmdb-ui/src/locales/lang/en-US.js
Normal file
@@ -0,0 +1,229 @@
|
||||
/* eslint-disable */
|
||||
import enUS from 'ant-design-vue/es/locale-provider/en_US'
|
||||
export default {
|
||||
antLocale: enUS,
|
||||
menu: {
|
||||
preference: 'Preference',
|
||||
resourceViews: 'Resource views',
|
||||
relationViews: 'Relation views',
|
||||
treeViews: 'Tree views',
|
||||
batch: 'Batch import',
|
||||
ciType: 'Modeling',
|
||||
acl: 'Authorization',
|
||||
ciModelManager: 'CI Type',
|
||||
ciPropertyRep: 'Attributes',
|
||||
ciRelationType: 'Relation Type',
|
||||
ciRelationViewDefine: 'Relation view define',
|
||||
aclUsersManager: 'Users',
|
||||
aclRolesManager: 'Roles',
|
||||
aclResourceManager: 'Resources',
|
||||
aclResourceType: 'Resource Type'
|
||||
},
|
||||
button: {
|
||||
cancel: 'Cancel',
|
||||
submit: 'Submit',
|
||||
query: 'Query',
|
||||
add: 'Add',
|
||||
new: 'New',
|
||||
update: 'Edit',
|
||||
save: 'Save',
|
||||
delete: 'Delete',
|
||||
yes: 'Yes',
|
||||
no: 'No',
|
||||
reset: 'Reset',
|
||||
subscribe: 'Subscribe',
|
||||
downloadTemplate: 'Download',
|
||||
upload: 'Upload',
|
||||
download: 'Download',
|
||||
batchUpdate: 'Batch update',
|
||||
displayFields: 'Display fields'
|
||||
},
|
||||
tip: {
|
||||
sourceCode: 'view on',
|
||||
subscribed: 'Subscribed',
|
||||
unsubscribed: 'Unsubscribed',
|
||||
unfold: 'Unfold',
|
||||
fold: 'Fold',
|
||||
detail: 'Detail',
|
||||
delete: 'Delete',
|
||||
edit: 'Edit',
|
||||
operate: 'Operation',
|
||||
close: 'Close',
|
||||
create: 'Create',
|
||||
clear: 'Clear',
|
||||
modify: 'Modify',
|
||||
unselectedAttribute: 'Unselect attributes',
|
||||
selectedAttribute: 'Selected attributes',
|
||||
noData: 'No data',
|
||||
addSuccess: 'Add successfully',
|
||||
updateSuccess: 'Update successfully',
|
||||
saveSuccess: 'Save successfully',
|
||||
deleteSuccess: 'Delete successfully',
|
||||
cancelSuccess: 'Cancel successfully',
|
||||
downloading: 'Downloading ...',
|
||||
deleting: 'Deleting ...',
|
||||
confirmDelete: 'Confirm deleting ?',
|
||||
warning: 'Warning',
|
||||
error: 'Error',
|
||||
other: 'Other',
|
||||
requestFailed: 'Request error, please try again later',
|
||||
pleaseSelect: 'Please select',
|
||||
selectAll: 'Select all'
|
||||
},
|
||||
ci: {
|
||||
batchOperate: 'Batch operation',
|
||||
confirmBatchUpdate: 'Confirm batch modification?',
|
||||
batchUpdate: 'Batch update',
|
||||
batchUpdateSuccess: 'Batch update successfully',
|
||||
confirmDelete: 'Confirm deleting ?',
|
||||
attribute: 'Attributes',
|
||||
relation: 'Relation',
|
||||
history: 'History',
|
||||
time: 'Time',
|
||||
user: 'User',
|
||||
batchUpdateTip: 'Just fill in the fields that need to be modified!',
|
||||
selectLevel: '- - Directory level selection - -',
|
||||
displayFieldDefine: 'Display Fields Define'
|
||||
},
|
||||
table: {
|
||||
selected: 'Selected',
|
||||
clear: 'Clear'
|
||||
},
|
||||
preference: {
|
||||
cancelSubscribeConfirm: 'Really want to unsubscribe ?',
|
||||
subscribeSuccess: 'Subscribe successfully',
|
||||
subscribeModel: 'Subscribe model',
|
||||
resourceView: 'Resource view',
|
||||
subFormTip: 'You can either define a tree view or subscribe to a resource view, which will be presented separately in sidebar'
|
||||
},
|
||||
batch: {
|
||||
modelType: 'Model Type',
|
||||
pleaseSelectModelType: 'please select model type',
|
||||
uploadResult: 'upload result',
|
||||
dragFileHere: 'click or drag file to here!',
|
||||
suportFileType: 'suport file type'
|
||||
},
|
||||
relationView: {
|
||||
tip: 'The administrator has not configured the relational view, or you do not have permission to access it!'
|
||||
},
|
||||
treeView: {
|
||||
tip: 'Please go to my subscription page to complete the subscription!'
|
||||
},
|
||||
ciType: {
|
||||
add: 'Add',
|
||||
addAttribute: 'Add attribute',
|
||||
addAttribute1: 'Add attribute',
|
||||
moreAttribute: 'More attributes',
|
||||
bindAttribute: 'Bind attribute',
|
||||
editModel: 'Edit model',
|
||||
modelName: 'Model name',
|
||||
name: 'Name',
|
||||
alias: 'Alias',
|
||||
type: 'Type',
|
||||
unique: 'Unique',
|
||||
index: 'Index',
|
||||
sort: 'Sort',
|
||||
link: 'Link',
|
||||
password: 'Password',
|
||||
list: 'List',
|
||||
required: 'Required',
|
||||
integer: 'Integer',
|
||||
float: 'Float',
|
||||
text: 'Text',
|
||||
nameValidate: "You can't start with a number, you can start with an English number and an underscore (_)",
|
||||
nameRequired: 'Please enter a attribute name',
|
||||
isIt: 'Is it ',
|
||||
predefinedValue: 'Predefined values',
|
||||
predefinedValueTip: 'Multiple values are separated by line breaks',
|
||||
defaultShow: 'Default show',
|
||||
typeAttribute: 'Attribute',
|
||||
typeRelation: 'Relation',
|
||||
requiredCheck: 'Required check',
|
||||
defaultShowAttribute: 'Default display attributes',
|
||||
attributeGroup: 'Attribute grouping & sorting',
|
||||
addGroup: 'Add group',
|
||||
deleteGroup: 'Delete group',
|
||||
up: 'Up',
|
||||
down: 'Down',
|
||||
moveSuccess: 'Move successfully',
|
||||
moveFailed: 'Move failed',
|
||||
groupNameExisted: 'The group name already exists',
|
||||
moreAttributeCannotSort: 'More attributes cannot be sorted. If you need to sort, add them to other groups!',
|
||||
newCIType: 'New CI Type',
|
||||
editCIType: 'Edit CI Type',
|
||||
newRelation: 'New Relation',
|
||||
sourceCIType: 'Source CI Type',
|
||||
targetCIType: 'Target CI Type',
|
||||
relationType: 'Relation Type',
|
||||
relationViewDefinePanel: 'Relationship view definition panel',
|
||||
relationViewDefinePanelTip1: 'Method 1. Right-click tree node (recommended)',
|
||||
relationViewDefinePanelTip2: 'Method 2. Open the switch in the upper right corner and select the node of the tree',
|
||||
newRealtionView: 'New relational view',
|
||||
RealtionViewName: 'Relational view name',
|
||||
RealtionViewNameRequired: 'Please enter a relational view name',
|
||||
newRelationType: 'New Relation Type',
|
||||
relationTypeNameRequired: 'Please enter a type name',
|
||||
uniqueFlag: 'unique flag'
|
||||
},
|
||||
acl: {
|
||||
roleList: 'Roles',
|
||||
permList: 'Permissions',
|
||||
selectOtherRole: 'Please select another role',
|
||||
associatedParentRole: 'Associated parent role',
|
||||
associatedChildRole: 'Associated child role',
|
||||
associatedSuccess: 'Associated with success',
|
||||
name: 'Name',
|
||||
roleName: 'Role name',
|
||||
description: 'Desciption',
|
||||
resourceNameRequired: 'Please enter the resource name',
|
||||
descriptionTip: 'Please enter description...',
|
||||
permission: 'Permission',
|
||||
resourceType: 'Resource Type',
|
||||
newResource: 'New Resource',
|
||||
newRole: 'New Role',
|
||||
newResourceType: 'New Resource Type',
|
||||
addPermTip: 'Add authorization: ',
|
||||
add: 'Add',
|
||||
selectRoleTip: 'Please select the role name. Multiple choices are available!',
|
||||
selectPermTip: 'Please select permissions. Multiple options are available!',
|
||||
resourceTypeNameRequired: 'Please enter a type name',
|
||||
permissionNameRequired: 'Please enter a permission name',
|
||||
roleNameRequired: 'Please enter a role name',
|
||||
usernameRequired: 'Please enter a user name',
|
||||
inheritedFrom: 'Inherited from ',
|
||||
selectInheritedRoles: 'Select inherited roles',
|
||||
isAppAdmin: 'Is Application Admin',
|
||||
username: 'Username',
|
||||
nickname: 'NickName',
|
||||
password: 'Password',
|
||||
department: 'Department',
|
||||
catalog: 'Team',
|
||||
email: 'Email',
|
||||
emailValidate: 'Please enter the correct email address!',
|
||||
emailRequired: 'Please enter email address',
|
||||
mobile: 'Mobile phone number',
|
||||
mobileValidate: 'Please enter the correct mobile phone number',
|
||||
block: 'Is lock',
|
||||
newUser: 'New User',
|
||||
typeName: 'Type name',
|
||||
viewAuthorization: 'View Authorization',
|
||||
authorization: 'Authorization',
|
||||
resourceName: 'Resource Name',
|
||||
createdAt: 'Creation time',
|
||||
updatedAt: 'Last modified time',
|
||||
joinedAt: 'Join time'
|
||||
},
|
||||
login: {
|
||||
subTitle: 'Operation and maintenance resource data management',
|
||||
loginHeader: 'Account password login',
|
||||
loginName: 'User name or email address',
|
||||
loginNameRequired: 'Please enter your account name or email address',
|
||||
password: 'Password',
|
||||
passwordRequired: 'Please enter your password',
|
||||
autoLogin: 'Automatic login',
|
||||
welcome: 'Welocom',
|
||||
welcomeBack: 'Welcome back',
|
||||
confirmLogout: 'Do you really want to logout?',
|
||||
logout: 'Logout',
|
||||
}
|
||||
}
|
229
cmdb-ui/src/locales/lang/zh-CN.js
Normal file
@@ -0,0 +1,229 @@
|
||||
/* eslint-disable */
|
||||
import zhCN from 'ant-design-vue/es/locale-provider/zh_CN'
|
||||
export default {
|
||||
antLocale: zhCN,
|
||||
menu: {
|
||||
preference: '我的订阅',
|
||||
resourceViews: '资源视图',
|
||||
relationViews: '关系视图',
|
||||
treeViews: '树状视图',
|
||||
batch: '批量导入',
|
||||
ciType: '模型配置',
|
||||
acl: '权限管理',
|
||||
ciModelManager: '模型管理',
|
||||
ciPropertyRep: '属性库',
|
||||
ciRelationType: '关系类型',
|
||||
ciRelationViewDefine: '关系视图定义',
|
||||
aclUsersManager: '用户管理',
|
||||
aclRolesManager: '角色管理',
|
||||
aclResourceManager: '资源管理',
|
||||
aclResourceType: '资源类型'
|
||||
},
|
||||
button: {
|
||||
cancel: '取消',
|
||||
submit: '提交',
|
||||
query: '查询',
|
||||
add: '新增',
|
||||
new: '新建',
|
||||
update: '修改',
|
||||
save: '保存',
|
||||
delete: '删除',
|
||||
yes: '是',
|
||||
no: '否',
|
||||
reset: '重置',
|
||||
subscribe: '订阅',
|
||||
downloadTemplate: '下载模板',
|
||||
upload: '上传',
|
||||
download: '下载',
|
||||
batchUpdate: '批量修改',
|
||||
displayFields: '显示字段'
|
||||
},
|
||||
tip: {
|
||||
sourceCode: '源代码',
|
||||
subscribed: '已订阅',
|
||||
unsubscribed: '未订阅',
|
||||
unfold: '展开',
|
||||
fold: '收起',
|
||||
detail: '详情',
|
||||
delete: '删除',
|
||||
edit: '编辑',
|
||||
operate: '操作',
|
||||
close: '关闭',
|
||||
create: '创建',
|
||||
clear: '清空',
|
||||
modify: '修改',
|
||||
unselectedAttribute: '当前项',
|
||||
selectedAttribute: '已选项',
|
||||
noData: '没数据',
|
||||
addSuccess: '新增成功',
|
||||
updateSuccess: '修改成功',
|
||||
saveSuccess: '保存成功',
|
||||
deleteSuccess: '删除成功',
|
||||
cancelSuccess: '取消成功',
|
||||
downloading: '正在下载 ...',
|
||||
deleting: '正在删除 ...',
|
||||
confirmDelete: '真的要删除吗 ?',
|
||||
warning: '警告',
|
||||
error: '错误',
|
||||
other: '其他',
|
||||
requestFailed: '请求出现错误,请稍后再试',
|
||||
pleaseSelect: '请选择',
|
||||
selectAll: '全选'
|
||||
},
|
||||
ci: {
|
||||
batchOperate: '批量操作',
|
||||
confirmBatchUpdate: '确认要批量修改吗 ?',
|
||||
batchUpdate: '批量修改',
|
||||
batchUpdateSuccess: '批量修改成功',
|
||||
confirmDelete: '真的要删除吗 ?',
|
||||
attribute: '属性',
|
||||
relation: '关系',
|
||||
history: '操作历史',
|
||||
time: '时间',
|
||||
user: '用户',
|
||||
batchUpdateTip: '只需要填写需要修改的字段即可!',
|
||||
selectLevel: '- - 目录层级的选择 - -',
|
||||
displayFieldDefine: '显示字段定义'
|
||||
},
|
||||
table: {
|
||||
selected: '已选择',
|
||||
clear: '清空'
|
||||
},
|
||||
preference: {
|
||||
cancelSubscribeConfirm: '真的要取消订阅吗 ?',
|
||||
subscribeSuccess: '订阅成功',
|
||||
subscribeModel: '订阅模型',
|
||||
resourceView: '资源视图',
|
||||
subFormTip: '既可以定义树形视图, 也可以订阅资源视图, 资源视图会在SideBar单独呈现'
|
||||
},
|
||||
batch: {
|
||||
modelType: '模板类型',
|
||||
pleaseSelectModelType: '请选择模板类型',
|
||||
uploadResult: '上传结果',
|
||||
dragFileHere: '点击或拖拽文件至此上传!',
|
||||
suportFileType: '支持文件类型'
|
||||
},
|
||||
relationView: {
|
||||
tip: '管理员 还未配置关系视图, 或者你无权限访问!'
|
||||
},
|
||||
treeView: {
|
||||
tip: '请先到 我的订阅 页面完成订阅!'
|
||||
},
|
||||
ciType: {
|
||||
add: '新增',
|
||||
addAttribute: '新增属性',
|
||||
bindAttribute: '绑定属性',
|
||||
addAttribute1: '添加属性',
|
||||
moreAttribute: '更多属性',
|
||||
editModel: '编辑模型',
|
||||
modelName: '模型名(英文)',
|
||||
name: '名称',
|
||||
alias: '别名',
|
||||
type: '类型',
|
||||
unique: '唯一',
|
||||
index: '索引',
|
||||
sort: '排序',
|
||||
link: '链接',
|
||||
password: '密码',
|
||||
list: '列表',
|
||||
required: '必须',
|
||||
integer: '整数',
|
||||
float: '浮点数',
|
||||
text: '文本',
|
||||
nameValidate: '不能以数字开头,可以是英文 数字以及下划线 (_)',
|
||||
nameRequired: '请输入属性名',
|
||||
isIt: '是否',
|
||||
predefinedValue: '预定义值',
|
||||
predefinedValueTip: '多个值使用换行分隔',
|
||||
defaultShow: '默认显示',
|
||||
typeAttribute: '模型属性',
|
||||
typeRelation: '模型关联',
|
||||
requiredCheck: '必须校验',
|
||||
defaultShowAttribute: '默认显示属性',
|
||||
attributeGroup: '属性分组 & 排序',
|
||||
addGroup: '添加分组',
|
||||
deleteGroup: '删除分组',
|
||||
up: '上移',
|
||||
down: '下移',
|
||||
moveSuccess: '移动成功',
|
||||
moveFailed: '移动出错',
|
||||
groupNameExisted: '分组名称已存在',
|
||||
moreAttributeCannotSort: '更多属性不能进行排序, 如需排序需添加入其他分组中!',
|
||||
newCIType: '新增模型',
|
||||
editCIType: '编辑模型',
|
||||
newRelation: '新增关系',
|
||||
sourceCIType: '源模型',
|
||||
targetCIType: '目标模型',
|
||||
relationType: '关联关系',
|
||||
relationViewDefinePanel: '关系视图定义面板',
|
||||
relationViewDefinePanelTip1: '方法1. 右键选择树节点(推荐)',
|
||||
relationViewDefinePanelTip2: '方法2. 先打开右上角的开关,再选择树的节点',
|
||||
newRealtionView: '新增关系视图',
|
||||
RealtionViewName: '关系视图名',
|
||||
RealtionViewNameRequired: '请输入 关系视图名',
|
||||
newRelationType: '新增关系类型',
|
||||
relationTypeNameRequired: '请输入类型名',
|
||||
uniqueFlag: '唯一标识'
|
||||
},
|
||||
acl: {
|
||||
roleList: '角色列表',
|
||||
permList: '权限列表',
|
||||
selectOtherRole: '请选择另一个角色',
|
||||
associatedParentRole: '关联父角色',
|
||||
associatedChildRole: '关联子角色',
|
||||
associatedSuccess: '关联成功',
|
||||
name: '名称',
|
||||
roleName: '角色名称',
|
||||
description: '描述',
|
||||
resourceNameRequired: '请输入资源名',
|
||||
descriptionTip: '请输入描述信息...',
|
||||
permission: '权限',
|
||||
resourceType: '资源类型',
|
||||
newResource: '新增资源',
|
||||
newRole: '新增角色',
|
||||
newResourceType: '新增资源类型',
|
||||
addPermTip: '添加授权:',
|
||||
add: '添加',
|
||||
selectRoleTip: '请选择角色名称,可多选!',
|
||||
selectPermTip: '请选择权限,可多选!',
|
||||
resourceTypeNameRequired: '请输入类型名',
|
||||
permissionNameRequired: '请输入权限名',
|
||||
roleNameRequired: '请输入角色名',
|
||||
usernameRequired: '请输入用户名',
|
||||
inheritedFrom: '继承自',
|
||||
selectInheritedRoles: '选择继承角色',
|
||||
isAppAdmin: '是否应用管理员',
|
||||
username: '用户名',
|
||||
nickname: '昵称',
|
||||
password: '密码',
|
||||
department: '部门',
|
||||
catalog: '小组',
|
||||
email: '邮箱',
|
||||
emailValidate: '请输入正确的邮箱!',
|
||||
emailRequired: '请输入邮箱',
|
||||
mobile: '手机号码',
|
||||
mobileValidate: '请输入正确的手机号码',
|
||||
block: '是否锁定',
|
||||
newUser: '新增用户',
|
||||
typeName: '类型名',
|
||||
viewAuthorization: '查看授权',
|
||||
authorization: '授权',
|
||||
resourceName: '资源名',
|
||||
createdAt: '创建时间',
|
||||
updatedAt: '最后修改时间',
|
||||
joinedAt: '加入时间'
|
||||
},
|
||||
login: {
|
||||
subTitle: '运维资源数据管理',
|
||||
loginHeader: '账号密码登录',
|
||||
loginName: '用户名或者邮箱',
|
||||
loginNameRequired: '请输入帐户名或邮箱地址',
|
||||
password: '密码',
|
||||
passwordRequired: '请输入密码',
|
||||
autoLogin: '自动登录',
|
||||
welcome: '欢迎',
|
||||
welcomeBack: '欢迎回来',
|
||||
confirmLogout: '真的要注销登录吗 ?',
|
||||
logout: '退出登录',
|
||||
}
|
||||
}
|
@@ -5,7 +5,8 @@ import Vue from 'vue'
|
||||
import EventBus from './EventBus'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import store from './store/'
|
||||
import store from './store'
|
||||
import i18n from './locales'
|
||||
import { VueAxios } from './utils/request'
|
||||
|
||||
import bootstrap from './core/bootstrap'
|
||||
@@ -22,6 +23,7 @@ Vue.use(VueAxios)
|
||||
new Vue({
|
||||
router,
|
||||
store,
|
||||
i18n,
|
||||
created: bootstrap,
|
||||
render: h => h(App)
|
||||
}).$mount('#app')
|
||||
|
@@ -8,28 +8,35 @@ import notification from 'ant-design-vue/es/notification'
|
||||
import { setDocumentTitle, domTitle } from '@/utils/domUtil'
|
||||
import config from '@/config/defaultSettings'
|
||||
import { ACCESS_TOKEN } from './store/mutation-types'
|
||||
import i18n from '@/locales'
|
||||
|
||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start() // start progress bar
|
||||
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))
|
||||
var displayTitle
|
||||
|
||||
if (to.meta && to.meta.title && to.meta.title.split('.')[0] === 'menu') {
|
||||
displayTitle = i18n.messages[i18n.locale].menu[to.meta.title.split('.')[1]]
|
||||
} else if (to.meta && to.meta.title) {
|
||||
displayTitle = to.meta.title
|
||||
}
|
||||
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${displayTitle} - ${domTitle}`))
|
||||
if ((config.useSSO || (!config.useSSO && Vue.ls.get(ACCESS_TOKEN))) && store.getters.roles.length === 0) {
|
||||
store
|
||||
.dispatch('GetInfo')
|
||||
.then(res => {
|
||||
const roles = res.result && res.result.role
|
||||
store.dispatch('GenerateRoutes', { roles }).then(() => {
|
||||
// 根据roles权限生成可访问的路由表
|
||||
// 动态添加可访问路由表
|
||||
// Generate an accessible routing table based on the roles permissions
|
||||
// Dynamically add accessible routing tables
|
||||
router.addRoutes(store.getters.addRouters)
|
||||
|
||||
const redirect = decodeURIComponent(from.query.redirect || to.path)
|
||||
if (to.path === redirect) {
|
||||
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
|
||||
// set the replace: true so the navigation will not leave a history record
|
||||
next({ ...to, replace: true })
|
||||
} else {
|
||||
// 跳转到目的路由
|
||||
// Jump to destination route
|
||||
next({ path: redirect })
|
||||
}
|
||||
})
|
||||
@@ -37,8 +44,8 @@ router.beforeEach((to, from, next) => {
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
notification.error({
|
||||
message: '错误',
|
||||
description: '请求用户信息失败,请重试'
|
||||
message: this.$t('tip.error'),
|
||||
description: 'Failed to request user information. Please try again!'
|
||||
})
|
||||
setTimeout(() => {
|
||||
store.dispatch('Logout')
|
||||
|
@@ -1,145 +0,0 @@
|
||||
路由/菜单说明
|
||||
====
|
||||
|
||||
|
||||
|
||||
配置文件路径
|
||||
----
|
||||
|
||||
`@/config/router.config.js`
|
||||
|
||||
|
||||
|
||||
格式和说明
|
||||
----
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* 路由配置说明:
|
||||
* 建议:sider menu 请不要超过三级菜单,若超过三级菜单,则应该设计为顶部主菜单 配合左侧次级菜单
|
||||
*
|
||||
**/
|
||||
{
|
||||
redirect: noredirect,
|
||||
name: 'router-name',
|
||||
hidden: true,
|
||||
meta: {
|
||||
title: 'title',
|
||||
icon: 'a-icon',
|
||||
keepAlive: true,
|
||||
hiddenHeaderContent: true,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
`{ Route }` 对象
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| -------- | ----------------------------------------- | ------- | ------ |
|
||||
| hidden | 控制路由是否显示在 sidebar | boolean | false |
|
||||
| redirect | 重定向地址, 访问这个路由时,自定进行重定向 | string | - |
|
||||
| name | 路由名称, 必须设置,且不能重名 | string | - |
|
||||
| meta | 路由元信息(路由附带扩展信息) | object | {} |
|
||||
| hideChildrenInMenu | 强制菜单显示为Item而不是SubItem(配合 meta.hidden) | boolean | - |
|
||||
|
||||
|
||||
`{ Meta }` 路由元信息对象
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------------------- | ------------------------------------------------------------ | ------- | ------ |
|
||||
| title | 路由标题, 用于显示面包屑, 页面标题 *推荐设置 | string | - |
|
||||
| icon | 路由在 menu 上显示的图标 | [string,svg] | - |
|
||||
| keepAlive | 缓存该路由 | boolean | false |
|
||||
| hidden | 配合`hideChildrenInMenu`使用,用于隐藏菜单时,提供递归到父菜单显示 选中菜单项_(可参考 个人页 配置方式)_ | boolean | false |
|
||||
| hiddenHeaderContent | *特殊 隐藏 [PageHeader](https://github.com/sendya/ant-design-pro-vue/blob/master/src/components/layout/PageHeader.vue#L14) 组件中的页面带的 面包屑和页面标题栏 | boolean | false |
|
||||
| permission | 与项目提供的权限拦截匹配的权限,如果不匹配,则会被禁止访问该路由页面 | array | [] |
|
||||
|
||||
> 路由自定义 `Icon` 请引入自定义 `svg` Icon 文件,然后传递给路由的 `meta.icon` 参数即可
|
||||
|
||||
路由例子
|
||||
----
|
||||
|
||||
```ecmascript 6
|
||||
const asyncRouterMap = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'index',
|
||||
component: BasicLayout,
|
||||
meta: { title: '首页' },
|
||||
redirect: '/dashboard/analysis',
|
||||
children: [
|
||||
{
|
||||
path: '/dashboard',
|
||||
component: RouteView,
|
||||
name: 'dashboard',
|
||||
redirect: '/dashboard/workplace',
|
||||
meta: {title: '仪表盘', icon: 'dashboard', permission: ['dashboard']},
|
||||
children: [
|
||||
{
|
||||
path: '/dashboard/analysis',
|
||||
name: 'Analysis',
|
||||
component: () => import('@/views/dashboard/Analysis'),
|
||||
meta: {title: '分析页', permission: ['dashboard']}
|
||||
},
|
||||
{
|
||||
path: '/dashboard/monitor',
|
||||
name: 'Monitor',
|
||||
hidden: true,
|
||||
component: () => import('@/views/dashboard/Monitor'),
|
||||
meta: {title: '监控页', permission: ['dashboard']}
|
||||
},
|
||||
{
|
||||
path: '/dashboard/workplace',
|
||||
name: 'Workplace',
|
||||
component: () => import('@/views/dashboard/Workplace'),
|
||||
meta: {title: '工作台', permission: ['dashboard']}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// result
|
||||
{
|
||||
path: '/result',
|
||||
name: 'result',
|
||||
component: PageView,
|
||||
redirect: '/result/success',
|
||||
meta: { title: '结果页', icon: 'check-circle-o', permission: [ 'result' ] },
|
||||
children: [
|
||||
{
|
||||
path: '/result/success',
|
||||
name: 'ResultSuccess',
|
||||
component: () => import(/* webpackChunkName: "result" */ '@/views/result/Success'),
|
||||
// 该页面隐藏面包屑和页面标题栏
|
||||
meta: { title: '成功', hiddenHeaderContent: true, permission: [ 'result' ] }
|
||||
},
|
||||
{
|
||||
path: '/result/fail',
|
||||
name: 'ResultFail',
|
||||
component: () => import(/* webpackChunkName: "result" */ '@/views/result/Error'),
|
||||
// 该页面隐藏面包屑和页面标题栏
|
||||
meta: { title: '失败', hiddenHeaderContent: true, permission: [ 'result' ] }
|
||||
}
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
},
|
||||
]
|
||||
```
|
||||
|
||||
> 1. 请注意 `component: () => import('..') ` 方式引入路由的页面组件为 懒加载模式。具体可以看 [Vue 官方文档](https://router.vuejs.org/zh/guide/advanced/lazy-loading.html)
|
||||
> 2. 增加新的路由应该增加在 '/' (index) 路由的 `children` 内
|
||||
> 3. 子路由的父级路由必须有 `router-view` 才能让子路由渲染出来,请仔细查阅 vue-router 文档
|
||||
> 4. `permission` 可以进行自定义修改,只需要对这个模块进行自定义修改即可 [src/store/modules/permission.js#L10](https://github.com/sendya/ant-design-pro-vue/blob/master/src/store/modules/permission.js#L10)
|
||||
|
||||
|
||||
|
||||
附权限路由结构:
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
第二种前端路由由后端动态生成的设计,可以前往官网文档 https://pro.loacg.com/docs/authority-management 参考
|
16
cmdb-ui/src/store/i18n-mixin.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { mapState } from 'vuex'
|
||||
|
||||
const mixin = {
|
||||
computed: {
|
||||
...mapState({
|
||||
currentLang: state => state.i18n.lang
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
setLang (lang) {
|
||||
this.$store.dispatch('SetLang', lang)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { mixin }
|
@@ -3,6 +3,7 @@ import Vuex from 'vuex'
|
||||
|
||||
import app from './modules/app'
|
||||
import user from './modules/user'
|
||||
import i18n from './modules/i18n'
|
||||
import permission from './modules/permission'
|
||||
import getters from './getters'
|
||||
|
||||
@@ -12,7 +13,8 @@ export default new Vuex.Store({
|
||||
modules: {
|
||||
app,
|
||||
user,
|
||||
permission
|
||||
permission,
|
||||
i18n
|
||||
},
|
||||
state: {
|
||||
|
||||
|
24
cmdb-ui/src/store/modules/i18n.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { loadLanguageAsync } from '@/locales'
|
||||
|
||||
const i18n = {
|
||||
state: {
|
||||
lang: 'en-US'
|
||||
},
|
||||
mutations: {
|
||||
SET_LANG: (state, lang) => {
|
||||
state.lang = lang
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// Setting language
|
||||
SetLang ({ commit }, lang) {
|
||||
return new Promise(resolve => {
|
||||
commit('SET_LANG', lang)
|
||||
loadLanguageAsync(lang)
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default i18n
|
@@ -1,7 +1,7 @@
|
||||
import { generatorDynamicRouter, constantRouterMap } from '@/config/router.config'
|
||||
|
||||
/**
|
||||
* 过滤账户是否拥有某一个权限,并将菜单从加载列表移除
|
||||
* Filters if the account has a permission and removes the menu from the load list
|
||||
*
|
||||
* @param permission
|
||||
* @param route
|
||||
|
@@ -33,7 +33,7 @@ const user = {
|
||||
},
|
||||
|
||||
actions: {
|
||||
// 登录
|
||||
// login
|
||||
Login ({ commit }, userInfo) {
|
||||
return new Promise((resolve, reject) => {
|
||||
login(userInfo).then(response => {
|
||||
@@ -46,7 +46,7 @@ const user = {
|
||||
})
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
// get user info
|
||||
GetInfo ({ commit }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getInfo().then(response => {
|
||||
@@ -73,7 +73,7 @@ const user = {
|
||||
})
|
||||
},
|
||||
|
||||
// 登出
|
||||
// logout
|
||||
Logout ({ commit, state }) {
|
||||
return new Promise((resolve) => {
|
||||
commit('SET_TOKEN', '')
|
||||
|
@@ -1,288 +0,0 @@
|
||||
<template>
|
||||
<div class="page-header-index-wide page-header-wrapper-grid-content-main">
|
||||
<a-row :gutter="24">
|
||||
<a-col :md="24" :lg="7">
|
||||
<a-card :bordered="false">
|
||||
<div class="account-center-avatarHolder">
|
||||
<div class="avatar">
|
||||
<img :src="avatar()">
|
||||
</div>
|
||||
<div class="username">{{ nickname() }}</div>
|
||||
<div class="bio">海纳百川,有容乃大</div>
|
||||
</div>
|
||||
<div class="account-center-detail">
|
||||
<p>
|
||||
<i class="title"></i>交互专家
|
||||
</p>
|
||||
<p>
|
||||
<i class="group"></i>蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED
|
||||
</p>
|
||||
<p>
|
||||
<i class="address"></i>
|
||||
<span>浙江省</span>
|
||||
<span>杭州市</span>
|
||||
</p>
|
||||
</div>
|
||||
<a-divider/>
|
||||
|
||||
<div class="account-center-tags">
|
||||
<div class="tagsTitle">标签</div>
|
||||
<div>
|
||||
<template v-for="(tag, index) in tags">
|
||||
<a-tooltip v-if="tag.length > 20" :key="tag" :title="tag">
|
||||
<a-tag
|
||||
:key="tag"
|
||||
:closable="index !== 0"
|
||||
:afterClose="() => handleTagClose(tag)"
|
||||
>{{ `${tag.slice(0, 20)}...` }}</a-tag>
|
||||
</a-tooltip>
|
||||
<a-tag
|
||||
v-else
|
||||
:key="tag"
|
||||
:closable="index !== 0"
|
||||
:afterClose="() => handleTagClose(tag)"
|
||||
>{{ tag }}</a-tag>
|
||||
</template>
|
||||
<a-input
|
||||
v-if="tagInputVisible"
|
||||
ref="tagInput"
|
||||
type="text"
|
||||
size="small"
|
||||
:style="{ width: '78px' }"
|
||||
:value="tagInputValue"
|
||||
@change="handleInputChange"
|
||||
@blur="handleTagInputConfirm"
|
||||
@keyup.enter="handleTagInputConfirm"
|
||||
/>
|
||||
<a-tag v-else @click="showTagInput" style="background: #fff; borderStyle: dashed;">
|
||||
<a-icon type="plus"/>New Tag
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
<a-divider :dashed="true"/>
|
||||
|
||||
<div class="account-center-team">
|
||||
<div class="teamTitle">团队</div>
|
||||
<a-spin :spinning="teamSpinning">
|
||||
<div class="members">
|
||||
<a-row>
|
||||
<a-col :span="12" v-for="(item, index) in teams" :key="index">
|
||||
<a>
|
||||
<a-avatar size="small" :src="item.avatar"/>
|
||||
<span class="member">{{ item.name }}</span>
|
||||
</a>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</a-spin>
|
||||
</div>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :md="24" :lg="17">
|
||||
<a-card
|
||||
style="width:100%"
|
||||
:bordered="false"
|
||||
:tabList="tabListNoTitle"
|
||||
:activeTabKey="noTitleKey"
|
||||
@tabChange="key => handleTabChange(key, 'noTitleKey')"
|
||||
>
|
||||
<article-page v-if="noTitleKey === 'article'"></article-page>
|
||||
<app-page v-else-if="noTitleKey === 'app'"></app-page>
|
||||
<project-page v-else-if="noTitleKey === 'project'"></project-page>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { PageView, RouteView } from '@/layouts'
|
||||
import { AppPage, ArticlePage, ProjectPage } from './page'
|
||||
|
||||
import { mapGetters } from 'vuex'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
RouteView,
|
||||
PageView,
|
||||
AppPage,
|
||||
ArticlePage,
|
||||
ProjectPage
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
tags: ['很有想法的', '专注设计', '辣~', '大长腿', '川妹子', '海纳百川'],
|
||||
|
||||
tagInputVisible: false,
|
||||
tagInputValue: '',
|
||||
|
||||
teams: [],
|
||||
teamSpinning: true,
|
||||
|
||||
tabListNoTitle: [
|
||||
{
|
||||
key: 'article',
|
||||
tab: '文章(8)'
|
||||
},
|
||||
{
|
||||
key: 'app',
|
||||
tab: '应用(8)'
|
||||
},
|
||||
{
|
||||
key: 'project',
|
||||
tab: '项目(8)'
|
||||
}
|
||||
],
|
||||
noTitleKey: 'app'
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.getTeams()
|
||||
},
|
||||
methods: {
|
||||
...mapGetters(['nickname', 'avatar']),
|
||||
|
||||
getTeams () {
|
||||
this.$http.get('/workplace/teams').then(res => {
|
||||
this.teams = res.result
|
||||
this.teamSpinning = false
|
||||
})
|
||||
},
|
||||
|
||||
handleTabChange (key, type) {
|
||||
this[type] = key
|
||||
},
|
||||
|
||||
handleTagClose (removeTag) {
|
||||
const tags = this.tags.filter(tag => tag !== removeTag)
|
||||
this.tags = tags
|
||||
},
|
||||
|
||||
showTagInput () {
|
||||
this.tagInputVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.tagInput.focus()
|
||||
})
|
||||
},
|
||||
|
||||
handleInputChange (e) {
|
||||
this.tagInputValue = e.target.value
|
||||
},
|
||||
|
||||
handleTagInputConfirm () {
|
||||
const inputValue = this.tagInputValue
|
||||
let tags = this.tags
|
||||
if (inputValue && !tags.includes(inputValue)) {
|
||||
tags = [...tags, inputValue]
|
||||
}
|
||||
|
||||
Object.assign(this, {
|
||||
tags,
|
||||
tagInputVisible: false,
|
||||
tagInputValue: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.page-header-wrapper-grid-content-main {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 100%;
|
||||
transition: 0.3s;
|
||||
|
||||
.account-center-avatarHolder {
|
||||
text-align: center;
|
||||
margin-bottom: 24px;
|
||||
|
||||
& > .avatar {
|
||||
margin: 0 auto;
|
||||
width: 104px;
|
||||
height: 104px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
img {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.username {
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
font-size: 20px;
|
||||
line-height: 28px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.account-center-detail {
|
||||
p {
|
||||
margin-bottom: 8px;
|
||||
padding-left: 26px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
i {
|
||||
position: absolute;
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
left: 0;
|
||||
top: 4px;
|
||||
background: url(https://gw.alipayobjects.com/zos/rmsportal/pBjWzVAHnOOtAUvZmZfy.svg);
|
||||
}
|
||||
|
||||
.title {
|
||||
background-position: 0 0;
|
||||
}
|
||||
.group {
|
||||
background-position: 0 -22px;
|
||||
}
|
||||
.address {
|
||||
background-position: 0 -44px;
|
||||
}
|
||||
}
|
||||
|
||||
.account-center-tags {
|
||||
.ant-tag {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.account-center-team {
|
||||
.members {
|
||||
a {
|
||||
display: block;
|
||||
margin: 12px 0;
|
||||
line-height: 24px;
|
||||
height: 24px;
|
||||
.member {
|
||||
font-size: 14px;
|
||||
color: rgba(0, 0, 0, 0.65);
|
||||
line-height: 24px;
|
||||
max-width: 100px;
|
||||
vertical-align: top;
|
||||
margin-left: 12px;
|
||||
transition: all 0.3s;
|
||||
display: inline-block;
|
||||
}
|
||||
&:hover {
|
||||
span {
|
||||
color: #1890ff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tagsTitle,
|
||||
.teamTitle {
|
||||
font-weight: 500;
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
@@ -1,113 +0,0 @@
|
||||
<template>
|
||||
<div class="app-list">
|
||||
<a-list
|
||||
:grid="{ gutter: 24, lg: 3, md: 2, sm: 1, xs: 1 }"
|
||||
:dataSource="dataSource">
|
||||
<a-list-item slot="renderItem" slot-scope="item">
|
||||
<a-card :hoverable="true">
|
||||
<a-card-meta>
|
||||
<div style="margin-bottom: 3px" slot="title">{{ item.title }}</div>
|
||||
<a-avatar class="card-avatar" slot="avatar" :src="item.avatar" size="small"/>
|
||||
<div class="meta-cardInfo" slot="description">
|
||||
<div>
|
||||
<p>活跃用户</p>
|
||||
<p>
|
||||
<span>{{ item.activeUser }}<span>万</span></span>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>新增用户</p>
|
||||
<p>{{ item.newUser | NumberFormat }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a-card-meta>
|
||||
<template class="ant-card-actions" slot="actions">
|
||||
<a>
|
||||
<a-icon type="download"/>
|
||||
</a>
|
||||
<a>
|
||||
<a-icon type="edit"/>
|
||||
</a>
|
||||
<a>
|
||||
<a-icon type="share-alt"/>
|
||||
</a>
|
||||
<a>
|
||||
<a-dropdown>
|
||||
<a class="ant-dropdown-link" href="javascript:;">
|
||||
<a-icon type="ellipsis"/>
|
||||
</a>
|
||||
<a-menu slot="overlay">
|
||||
<a-menu-item>
|
||||
<a href="javascript:;">1st menu item</a>
|
||||
</a-menu-item>
|
||||
<a-menu-item>
|
||||
<a href="javascript:;">2nd menu item</a>
|
||||
</a-menu-item>
|
||||
<a-menu-item>
|
||||
<a href="javascript:;">3rd menu item</a>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</a-dropdown>
|
||||
</a>
|
||||
</template>
|
||||
</a-card>
|
||||
</a-list-item>
|
||||
</a-list>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const dataSource = []
|
||||
for (let i = 0; i < 11; i++) {
|
||||
dataSource.push({
|
||||
title: 'Alipay',
|
||||
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png',
|
||||
activeUser: 17,
|
||||
newUser: 1700
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'Article',
|
||||
components: {},
|
||||
data () {
|
||||
return {
|
||||
dataSource
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
.app-list {
|
||||
|
||||
.meta-cardInfo {
|
||||
zoom: 1;
|
||||
margin-top: 16px;
|
||||
|
||||
> div {
|
||||
position: relative;
|
||||
text-align: left;
|
||||
float: left;
|
||||
width: 50%;
|
||||
|
||||
p {
|
||||
line-height: 32px;
|
||||
font-size: 24px;
|
||||
margin: 0;
|
||||
|
||||
&:first-child {
|
||||
color: rgba(0, 0, 0, .45);
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
@@ -1,75 +0,0 @@
|
||||
<template>
|
||||
<a-list
|
||||
size="large"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
itemLayout="vertical"
|
||||
:dataSource="data"
|
||||
>
|
||||
<a-list-item :key="item.id" slot="renderItem" slot-scope="item">
|
||||
<template slot="actions">
|
||||
<icon-text type="star-o" :text="item.star" />
|
||||
<icon-text type="like-o" :text="item.like" />
|
||||
<icon-text type="message" :text="item.message" />
|
||||
</template>
|
||||
<a-list-item-meta>
|
||||
<a slot="title" href="https://vue.ant.design/">{{ item.title }}</a>
|
||||
<template slot="description">
|
||||
<span>
|
||||
<a-tag>Ant Design</a-tag>
|
||||
<a-tag>设计语言</a-tag>
|
||||
<a-tag>蚂蚁金服</a-tag>
|
||||
</span>
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
<article-list-content :description="item.description" :owner="item.owner" :avatar="item.avatar" :href="item.href" :updateAt="item.updatedAt" />
|
||||
</a-list-item>
|
||||
<div slot="footer" v-if="data.length > 0" style="text-align: center; margin-top: 16px;">
|
||||
<a-button @click="loadMore" :loading="loadingMore">加载更多</a-button>
|
||||
</div>
|
||||
</a-list>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ArticleListContent } from '@/components'
|
||||
import IconText from '@/views/list/search/components/IconText'
|
||||
|
||||
export default {
|
||||
name: 'Article',
|
||||
components: {
|
||||
IconText,
|
||||
ArticleListContent
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
loading: true,
|
||||
loadingMore: false,
|
||||
data: []
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.getList()
|
||||
},
|
||||
methods: {
|
||||
getList () {
|
||||
this.$http.get('/list/article').then(res => {
|
||||
console.log('res', res)
|
||||
this.data = res.result
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
loadMore () {
|
||||
this.loadingMore = true
|
||||
this.$http.get('/list/article').then(res => {
|
||||
this.data = this.data.concat(res.result)
|
||||
}).finally(() => {
|
||||
this.loadingMore = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@@ -1,109 +0,0 @@
|
||||
<template>
|
||||
<div class="ant-pro-pages-account-projects-cardList">
|
||||
<a-list :loading="loading" :data-source="data" :grid="{ gutter: 24, xxl: 3, xl: 2, lg: 2, md: 2, sm: 2, xs: 1 }">
|
||||
<a-list-item slot="renderItem" slot-scope="item">
|
||||
<a-card class="ant-pro-pages-account-projects-card" hoverable>
|
||||
<img slot="cover" :src="item.cover" :alt="item.title" />
|
||||
<a-card-meta :title="item.title">
|
||||
<template slot="description">
|
||||
<ellipsis :length="50">{{ item.description }}</ellipsis>
|
||||
</template>
|
||||
</a-card-meta>
|
||||
<div class="cardItemContent">
|
||||
<span>{{ item.updatedAt | fromNow }}</span>
|
||||
<div class="avatarList">
|
||||
<avatar-list size="mini">
|
||||
<avatar-list-item
|
||||
v-for="(member, i) in item.members"
|
||||
:key="`${item.id}-avatar-${i}`"
|
||||
:src="member.avatar"
|
||||
:tips="member.name"
|
||||
/>
|
||||
</avatar-list>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</a-list-item>
|
||||
</a-list>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import moment from 'moment'
|
||||
import { TagSelect, StandardFormRow, Ellipsis, AvatarList } from '@/components'
|
||||
const TagSelectOption = TagSelect.Option
|
||||
const AvatarListItem = AvatarList.AvatarItem
|
||||
|
||||
export default {
|
||||
name: 'Project',
|
||||
components: {
|
||||
AvatarList,
|
||||
AvatarListItem,
|
||||
Ellipsis,
|
||||
TagSelect,
|
||||
TagSelectOption,
|
||||
StandardFormRow
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
data: [],
|
||||
form: this.$form.createForm(this),
|
||||
loading: true
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
fromNow (date) {
|
||||
return moment(date).fromNow()
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.getList()
|
||||
},
|
||||
methods: {
|
||||
handleChange (value) {
|
||||
console.log(`selected ${value}`)
|
||||
},
|
||||
getList () {
|
||||
this.$http.get('/list/article', { params: { count: 8 } }).then(res => {
|
||||
console.log('res', res)
|
||||
this.data = res.result
|
||||
this.loading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.ant-pro-pages-account-projects-cardList {
|
||||
margin-top: 24px;
|
||||
|
||||
/deep/ .ant-card-meta-title {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
/deep/ .ant-card-meta-description {
|
||||
height: 44px;
|
||||
overflow: hidden;
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.cardItemContent {
|
||||
display: flex;
|
||||
height: 20px;
|
||||
margin-top: 16px;
|
||||
margin-bottom: -4px;
|
||||
line-height: 20px;
|
||||
|
||||
> span {
|
||||
flex: 1 1;
|
||||
color: rgba(0,0,0,.45);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/deep/ .ant-pro-avatar-list {
|
||||
flex: 0 1 auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
@@ -1,5 +0,0 @@
|
||||
import AppPage from './App'
|
||||
import ArticlePage from './Article'
|
||||
import ProjectPage from './Project'
|
||||
|
||||
export { AppPage, ArticlePage, ProjectPage }
|
@@ -1,109 +0,0 @@
|
||||
<template>
|
||||
<a-modal
|
||||
title="修改头像"
|
||||
:visible="visible"
|
||||
:maskClosable="false"
|
||||
:confirmLoading="confirmLoading"
|
||||
:width="800"
|
||||
@cancel="cancelHandel">
|
||||
<a-row>
|
||||
<a-col :xs="24" :md="12" :style="{height: '350px'}">
|
||||
<vue-cropper
|
||||
ref="cropper"
|
||||
:img="options.img"
|
||||
:info="true"
|
||||
:autoCrop="options.autoCrop"
|
||||
:autoCropWidth="options.autoCropWidth"
|
||||
:autoCropHeight="options.autoCropHeight"
|
||||
:fixedBox="options.fixedBox"
|
||||
@realTime="realTime"
|
||||
>
|
||||
</vue-cropper>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12" :style="{height: '350px'}">
|
||||
<div class="avatar-upload-preview">
|
||||
<img :src="previews.url" :style="previews.img"/>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<template slot="footer">
|
||||
<a-button key="back" @click="cancelHandel">取消</a-button>
|
||||
<a-button key="submit" type="primary" :loading="confirmLoading" @click="okHandel">保存</a-button>
|
||||
</template>
|
||||
</a-modal>
|
||||
</template>
|
||||
<script>
|
||||
// import { VueCropper } from 'vue-cropper'
|
||||
|
||||
export default {
|
||||
/*
|
||||
components: {
|
||||
VueCropper
|
||||
},
|
||||
*/
|
||||
data () {
|
||||
return {
|
||||
visible: false,
|
||||
id: null,
|
||||
confirmLoading: false,
|
||||
|
||||
options: {
|
||||
img: '/avatar2.jpg',
|
||||
autoCrop: true,
|
||||
autoCropWidth: 200,
|
||||
autoCropHeight: 200,
|
||||
fixedBox: true
|
||||
},
|
||||
previews: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
edit (id) {
|
||||
this.visible = true
|
||||
this.id = id
|
||||
/* 获取原始头像 */
|
||||
},
|
||||
close () {
|
||||
this.id = null
|
||||
this.visible = false
|
||||
},
|
||||
cancelHandel () {
|
||||
this.close()
|
||||
},
|
||||
okHandel () {
|
||||
const vm = this
|
||||
|
||||
vm.confirmLoading = true
|
||||
setTimeout(() => {
|
||||
vm.confirmLoading = false
|
||||
vm.close()
|
||||
vm.$message.success('上传头像成功')
|
||||
}, 2000)
|
||||
},
|
||||
|
||||
realTime (data) {
|
||||
this.previews = data
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
.avatar-upload-preview {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
width: 180px;
|
||||
height: 180px;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 4px #ccc;
|
||||
overflow: hidden;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
@@ -1,161 +0,0 @@
|
||||
<template>
|
||||
<div class="account-settings-info-view">
|
||||
<a-row :gutter="16">
|
||||
<a-col :md="24" :lg="16">
|
||||
|
||||
<a-form layout="vertical">
|
||||
<a-form-item
|
||||
label="昵称"
|
||||
>
|
||||
<a-input placeholder="给自己起个名字" />
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="Bio"
|
||||
>
|
||||
<a-textarea rows="4" placeholder="You are not alone."/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="电子邮件"
|
||||
:required="false"
|
||||
>
|
||||
<a-input placeholder="exp@admin.com"/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="加密方式"
|
||||
:required="false"
|
||||
>
|
||||
<a-select defaultValue="aes-256-cfb">
|
||||
<a-select-option value="aes-256-cfb">aes-256-cfb</a-select-option>
|
||||
<a-select-option value="aes-128-cfb">aes-128-cfb</a-select-option>
|
||||
<a-select-option value="chacha20">chacha20</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="连接密码"
|
||||
:required="false"
|
||||
>
|
||||
<a-input placeholder="h3gSbecd"/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="登录密码"
|
||||
:required="false"
|
||||
>
|
||||
<a-input placeholder="密码"/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button type="primary">提交</a-button>
|
||||
<a-button style="margin-left: 8px">保存</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
|
||||
</a-col>
|
||||
<a-col :md="24" :lg="8" :style="{ minHeight: '180px' }">
|
||||
<div class="ant-upload-preview" @click="$refs.modal.edit(1)" >
|
||||
<a-icon type="cloud-upload-o" class="upload-icon"/>
|
||||
<div class="mask">
|
||||
<a-icon type="plus" />
|
||||
</div>
|
||||
<img :src="option.img"/>
|
||||
</div>
|
||||
</a-col>
|
||||
|
||||
</a-row>
|
||||
|
||||
<avatar-modal ref="modal">
|
||||
|
||||
</avatar-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AvatarModal from './AvatarModal'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
AvatarModal
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
// cropper
|
||||
preview: {},
|
||||
option: {
|
||||
img: '/avatar2.jpg',
|
||||
info: true,
|
||||
size: 1,
|
||||
outputType: 'jpeg',
|
||||
canScale: false,
|
||||
autoCrop: true,
|
||||
// 只有自动截图开启 宽度高度才生效
|
||||
autoCropWidth: 180,
|
||||
autoCropHeight: 180,
|
||||
fixedBox: true,
|
||||
// 开启宽度和高度比例
|
||||
fixed: true,
|
||||
fixedNumber: [1, 1]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
.avatar-upload-wrapper {
|
||||
height: 200px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ant-upload-preview {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
max-width: 180px;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 4px #ccc;
|
||||
|
||||
.upload-icon {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 10px;
|
||||
font-size: 1.4rem;
|
||||
padding: 0.5rem;
|
||||
background: rgba(222, 221, 221, 0.7);
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.mask {
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
background: rgba(0,0,0,0.4);
|
||||
cursor: pointer;
|
||||
transition: opacity 0.4s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-left: -1rem;
|
||||
margin-top: -1rem;
|
||||
color: #d6d6d6;
|
||||
}
|
||||
}
|
||||
|
||||
img, .mask {
|
||||
width: 100%;
|
||||
max-width: 180px;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
</style>
|
@@ -1,25 +0,0 @@
|
||||
<template>
|
||||
<a-list
|
||||
itemLayout="horizontal"
|
||||
:dataSource="data"
|
||||
>
|
||||
|
||||
</a-list>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
data: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@@ -1,75 +0,0 @@
|
||||
<script>
|
||||
import { colorList } from '@/components/SettingDrawer/settingConfig'
|
||||
import ASwitch from 'ant-design-vue/es/switch'
|
||||
import AList from 'ant-design-vue/es/list'
|
||||
import AListItem from 'ant-design-vue/es/list/Item'
|
||||
import { mixin } from '@/utils/mixin'
|
||||
|
||||
const Meta = AListItem.Meta
|
||||
|
||||
export default {
|
||||
components: {
|
||||
AListItem,
|
||||
AList,
|
||||
ASwitch,
|
||||
Meta
|
||||
},
|
||||
mixins: [mixin],
|
||||
data () {
|
||||
return {
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
themeFilter (theme) {
|
||||
const themeMap = {
|
||||
'dark': '暗色',
|
||||
'light': '白色'
|
||||
}
|
||||
return themeMap[theme]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
colorFilter (color) {
|
||||
const c = colorList.filter(o => o.color === color)[0]
|
||||
return c && c.key
|
||||
},
|
||||
|
||||
onChange (checked) {
|
||||
if (checked) {
|
||||
this.$store.dispatch('ToggleTheme', 'dark')
|
||||
} else {
|
||||
this.$store.dispatch('ToggleTheme', 'light')
|
||||
}
|
||||
}
|
||||
},
|
||||
render () {
|
||||
return (
|
||||
<AList itemLayout="horizontal">
|
||||
<AListItem>
|
||||
<Meta>
|
||||
<a slot="title">风格配色</a>
|
||||
<span slot="description">
|
||||
整体风格配色设置
|
||||
</span>
|
||||
</Meta>
|
||||
<div slot="actions">
|
||||
<ASwitch checkedChildren="暗色" unCheckedChildren="白色" defaultChecked={this.navTheme === 'dark' && true || false} onChange={this.onChange} />
|
||||
</div>
|
||||
</AListItem>
|
||||
<AListItem>
|
||||
<Meta>
|
||||
<a slot="title">主题色</a>
|
||||
<span slot="description">
|
||||
页面风格配色: <a domPropsInnerHTML={ this.colorFilter(this.primaryColor) }/>
|
||||
</span>
|
||||
</Meta>
|
||||
</AListItem>
|
||||
</AList>
|
||||
)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@@ -1,155 +0,0 @@
|
||||
<template>
|
||||
<div class="page-header-index-wide">
|
||||
<a-card :bordered="false" :bodyStyle="{ padding: '16px 0', height: '100%' }" :style="{ height: '100%' }">
|
||||
<div class="account-settings-info-main" :class="device">
|
||||
<div class="account-settings-info-left">
|
||||
<a-menu
|
||||
:mode="device == 'mobile' ? 'horizontal' : 'inline'"
|
||||
:style="{ border: '0', width: device == 'mobile' ? '560px' : 'auto'}"
|
||||
:selectedKeys="selectedKeys"
|
||||
type="inner"
|
||||
@openChange="onOpenChange"
|
||||
>
|
||||
<a-menu-item key="/account/settings/base">
|
||||
<router-link :to="{ name: 'BaseSettings' }">
|
||||
基本设置
|
||||
</router-link>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/account/settings/security">
|
||||
<router-link :to="{ name: 'SecuritySettings' }">
|
||||
安全设置
|
||||
</router-link>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/account/settings/custom">
|
||||
<router-link :to="{ name: 'CustomSettings' }">
|
||||
个性化
|
||||
</router-link>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/account/settings/binding">
|
||||
<router-link :to="{ name: 'BindingSettings' }">
|
||||
账户绑定
|
||||
</router-link>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/account/settings/notification">
|
||||
<router-link :to="{ name: 'NotificationSettings' }">
|
||||
新消息通知
|
||||
</router-link>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</div>
|
||||
<div class="account-settings-info-right">
|
||||
<div class="account-settings-info-title">
|
||||
<span>{{ $route.meta.title }}</span>
|
||||
</div>
|
||||
<route-view></route-view>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { PageView, RouteView } from '@/layouts'
|
||||
import { mixinDevice } from '@/utils/mixin.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
RouteView,
|
||||
PageView
|
||||
},
|
||||
mixins: [mixinDevice],
|
||||
data () {
|
||||
return {
|
||||
// horizontal inline
|
||||
mode: 'inline',
|
||||
|
||||
openKeys: [],
|
||||
selectedKeys: [],
|
||||
|
||||
// cropper
|
||||
preview: {},
|
||||
option: {
|
||||
img: '/avatar2.jpg',
|
||||
info: true,
|
||||
size: 1,
|
||||
outputType: 'jpeg',
|
||||
canScale: false,
|
||||
autoCrop: true,
|
||||
// 只有自动截图开启 宽度高度才生效
|
||||
autoCropWidth: 180,
|
||||
autoCropHeight: 180,
|
||||
fixedBox: true,
|
||||
// 开启宽度和高度比例
|
||||
fixed: true,
|
||||
fixedNumber: [1, 1]
|
||||
},
|
||||
|
||||
pageTitle: ''
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.updateMenu()
|
||||
},
|
||||
methods: {
|
||||
onOpenChange (openKeys) {
|
||||
this.openKeys = openKeys
|
||||
},
|
||||
updateMenu () {
|
||||
const routes = this.$route.matched.concat()
|
||||
this.selectedKeys = [ routes.pop().path ]
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'$route' (val) {
|
||||
this.updateMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.account-settings-info-main {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
|
||||
&.mobile {
|
||||
display: block;
|
||||
|
||||
.account-settings-info-left {
|
||||
border-right: unset;
|
||||
border-bottom: 1px solid #e8e8e8;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
overflow-x: auto;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
.account-settings-info-right {
|
||||
padding: 20px 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.account-settings-info-left {
|
||||
border-right: 1px solid #e8e8e8;
|
||||
width: 224px;
|
||||
}
|
||||
|
||||
.account-settings-info-right {
|
||||
flex: 1 1;
|
||||
padding: 8px 40px;
|
||||
|
||||
.account-settings-info-title {
|
||||
color: rgba(0,0,0,.85);
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
line-height: 28px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.account-settings-info-view {
|
||||
padding-top: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
@@ -1,25 +0,0 @@
|
||||
<template>
|
||||
<a-list
|
||||
itemLayout="horizontal"
|
||||
:dataSource="data"
|
||||
>
|
||||
|
||||
</a-list>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
data: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@@ -1,41 +0,0 @@
|
||||
<template>
|
||||
<a-list
|
||||
itemLayout="horizontal"
|
||||
:dataSource="data"
|
||||
>
|
||||
<a-list-item slot="renderItem" slot-scope="item, index" :key="index">
|
||||
<a-list-item-meta>
|
||||
<a slot="title">{{ item.title }}</a>
|
||||
<span slot="description">
|
||||
<span class="security-list-description">{{ item.description }}</span>
|
||||
<span v-if="item.value"> : </span>
|
||||
<span class="security-list-value">{{ item.value }}</span>
|
||||
</span>
|
||||
</a-list-item-meta>
|
||||
<template v-if="item.actions">
|
||||
<a slot="actions" @click="item.actions.callback">{{ item.actions.title }}</a>
|
||||
</template>
|
||||
|
||||
</a-list-item>
|
||||
</a-list>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
data: [
|
||||
{ title: '账户密码', description: '当前密码强度', value: '强', actions: { title: '修改', callback: () => { this.$message.info('This is a normal message') } } },
|
||||
{ title: '密保手机', description: '已绑定手机', value: '138****8293', actions: { title: '修改', callback: () => { this.$message.success('This is a message of success') } } },
|
||||
{ title: '密保问题', description: '未设置密保问题,密保问题可有效保护账户安全', value: '', actions: { title: '设置', callback: () => { this.$message.error('This is a message of error') } } },
|
||||
{ title: '备用邮箱', description: '已绑定邮箱', value: 'ant***sign.com', actions: { title: '修改', callback: () => { this.$message.warning('This is message of warning') } } },
|
||||
{ title: 'MFA 设备', description: '未绑定 MFA 设备,绑定后,可以进行二次确认', value: '', actions: { title: '绑定', callback: () => { this.$message.info('This is a normal message') } } }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@@ -13,9 +13,9 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="角色列表"
|
||||
:label="$t('acl.roleList')"
|
||||
>
|
||||
<a-select name="otherID" :filterOption="filterOption" v-decorator="['otherID', {rules: [{ required: true, message: '请选择另一个角色'}]} ]">
|
||||
<a-select name="otherID" :filterOption="filterOption" v-decorator="['otherID', {rules: [{ required: true, message: $t('acl.selectOtherRole')}]} ]">
|
||||
<template v-for="role in allRoles">
|
||||
<a-select-option v-if="role.id != current_record.id" :key="role.id">{{ role.name }}</a-select-option>
|
||||
</template>
|
||||
@@ -42,9 +42,9 @@
|
||||
|
||||
}"
|
||||
>
|
||||
<a-button @click="handleAddParent" type="primary" style="margin-right: 1rem">关联父角色</a-button>
|
||||
<a-button @click="handleAddChild" type="primary" style="margin-right: 1rem">关联子角色</a-button>
|
||||
<a-button @click="onClose">取消</a-button>
|
||||
<a-button @click="handleAddParent" type="primary" style="margin-right: 1rem">{{ $t('acl.associatedParentRole') }}</a-button>
|
||||
<a-button @click="handleAddChild" type="primary" style="margin-right: 1rem">{{ $t('acl.associatedChildRole') }}</a-button>
|
||||
<a-button @click="onClose">{{ $t('button.cancel') }}</a-button>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -64,7 +64,7 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
drawerTitle: '角色关联',
|
||||
drawerTitle: this.$t('acl.associatedRole'),
|
||||
drawerVisible: false,
|
||||
formLayout: 'vertical',
|
||||
allRoles: [],
|
||||
@@ -144,7 +144,7 @@ export default {
|
||||
addParent (id, otherID) {
|
||||
addParentRole(id, otherID)
|
||||
.then(res => {
|
||||
this.$message.success(`关联父角色成功`)
|
||||
this.$message.success(this.$t('acl.associatedSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
}).catch(err => this.requestFailed(err))
|
||||
@@ -153,7 +153,7 @@ export default {
|
||||
addChild (id, otherID) {
|
||||
addChildRole(id, otherID)
|
||||
.then(res => {
|
||||
this.$message.success(`关联子角色成功`)
|
||||
this.$message.success(this.$t('acl.associatedSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
})
|
||||
@@ -161,7 +161,7 @@ export default {
|
||||
},
|
||||
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -13,31 +13,31 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="类型名"
|
||||
:label="$t('acl.name')"
|
||||
>
|
||||
<a-input
|
||||
name="name"
|
||||
placeholder=""
|
||||
v-decorator="['name', {rules: [{ required: true, message: '请输入资源名'}]} ]"
|
||||
v-decorator="['name', {rules: [{ required: true, message: $t('acl.resourceNameRequired') }]} ]"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="描述"
|
||||
:label="$t('acl.description')"
|
||||
>
|
||||
<a-textarea placeholder="请输入描述信息..." name="description" :rows="4" />
|
||||
<a-textarea :placeholder="$t('acl.descriptionTip')" name="description" :rows="4" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="权限"
|
||||
:label="$t('acl.permission')"
|
||||
>
|
||||
<div :style="{ borderBottom: '1px solid #E9E9E9' }">
|
||||
<a-checkbox :indeterminate="indeterminate" @change="onCheckAllChange" :checked="checkAll">
|
||||
全选
|
||||
{{ $t('tip.selectAll') }}
|
||||
</a-checkbox>
|
||||
</div>
|
||||
<br />
|
||||
@@ -65,8 +65,8 @@
|
||||
|
||||
}"
|
||||
>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">确定</a-button>
|
||||
<a-button @click="onClose">取消</a-button>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">{{ $t('button.submit') }}</a-button>
|
||||
<a-button @click="onClose">{{ $t('button.cancel') }}</a-button>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -86,7 +86,7 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
drawerTitle: '新增资源类型',
|
||||
drawerTitle: this.$t('acl.newResourceType'),
|
||||
drawerVisible: false,
|
||||
formLayout: 'vertical',
|
||||
perms: ['1'],
|
||||
@@ -177,7 +177,7 @@ export default {
|
||||
updateResourceType (id, data) {
|
||||
updateResourceTypeById(id, data)
|
||||
.then(res => {
|
||||
this.$message.success(`更新成功`)
|
||||
this.$message.success(this.$t('tip.updateSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
}).catch(err => this.requestFailed(err))
|
||||
@@ -186,7 +186,7 @@ export default {
|
||||
createResourceType (data) {
|
||||
addResourceType(data)
|
||||
.then(res => {
|
||||
this.$message.success(`添加成功`)
|
||||
this.$message.success(this.$t('tip.addSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
})
|
||||
@@ -194,7 +194,7 @@ export default {
|
||||
},
|
||||
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -13,19 +13,19 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="资源名"
|
||||
:label="$t('acl.name')"
|
||||
>
|
||||
<a-input
|
||||
name="name"
|
||||
placeholder=""
|
||||
v-decorator="['name', {rules: [{ required: true, message: '请输入资源名'}]} ]"
|
||||
v-decorator="['name', {rules: [{ required: true, message: $t('acl.resourceNameRequired')}]} ]"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="资源类型"
|
||||
:label="$t('acl.resourceType')"
|
||||
>
|
||||
<a-select name="type_id" v-decorator="['type_id', {rules: []} ]">
|
||||
<a-select-option v-for="type in allTypes" :key="type.id">{{ type.name }}</a-select-option>
|
||||
@@ -52,8 +52,8 @@
|
||||
|
||||
}"
|
||||
>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">确定</a-button>
|
||||
<a-button @click="onClose">取消</a-button>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">{{ $t('button.submit') }}</a-button>
|
||||
<a-button @click="onClose">{{ $t('button.cancel') }}</a-button>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -73,7 +73,7 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
drawerTitle: '新增资源',
|
||||
drawerTitle: this.$t('acl.newResource'),
|
||||
drawerVisible: false,
|
||||
formLayout: 'vertical',
|
||||
allTypes: []
|
||||
@@ -150,14 +150,14 @@ export default {
|
||||
createResource (data) {
|
||||
addResource(data)
|
||||
.then(res => {
|
||||
this.$message.success(`添加成功`)
|
||||
this.$message.success(this.$t('tip.addSuccess'))
|
||||
this.onClose()
|
||||
})
|
||||
.catch(err => this.requestFailed(err))
|
||||
},
|
||||
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
width="50%"
|
||||
>
|
||||
<template slot="footer">
|
||||
<a-button key="back" @click="handleCancel">关闭</a-button>
|
||||
<a-button key="back" @click="handleCancel">{{ $t('tip.close') }}</a-button>
|
||||
</template>
|
||||
|
||||
<template>
|
||||
@@ -40,7 +40,7 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
drawerTitle: '权限列表',
|
||||
drawerTitle: this.$t('acl.permList'),
|
||||
drawerVisible: false,
|
||||
record: null,
|
||||
allPerms: [],
|
||||
@@ -80,7 +80,7 @@ export default {
|
||||
},
|
||||
deletePerm (roleID, permName) {
|
||||
deleteRoleResourcePerm(roleID, this.record.id, { perms: [permName] }).then(res => {
|
||||
this.$message.success(`删除成功`)
|
||||
this.$message.success(this.$t('tip.deleteSuccess'))
|
||||
}).catch(err => this.requestFailed(err))
|
||||
},
|
||||
handleCancel (e) {
|
||||
@@ -88,7 +88,7 @@ export default {
|
||||
},
|
||||
requestFailed (err) {
|
||||
console.log(err)
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<a-drawer
|
||||
:title="'添加授权:'+instance.name"
|
||||
:title="$t('acl.addPermTip')+instance.name"
|
||||
width="30%"
|
||||
:closable="true"
|
||||
:visible="visible"
|
||||
@@ -8,29 +8,29 @@
|
||||
>
|
||||
<a-form :form="form">
|
||||
<a-form-item
|
||||
label="角色列表"
|
||||
:label="$t('acl.roleList')"
|
||||
>
|
||||
<a-select
|
||||
showSearch
|
||||
name="roleIdList"
|
||||
v-decorator="['roleIdList', {rules: []} ]"
|
||||
mode="multiple"
|
||||
placeholder="请选择角色名称,可多选!"
|
||||
:placeholder="$t('acl.selectRoleTip')"
|
||||
:filterOption="filterOption">
|
||||
<a-select-option v-for="role in allRoles" :key="role.id">{{ role.name }}</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="权限列表"
|
||||
:label="$t('acl.permList')"
|
||||
>
|
||||
<a-select name="permName" v-decorator="['permName', {rules: []} ]" mode="multiple" placeholder="请选择权限,可多选!">
|
||||
<a-select name="permName" v-decorator="['permName', {rules: []} ]" mode="multiple" :placeholder="$t('acl.selectPermTip')">
|
||||
<a-select-option v-for="perm in allPerms" :key="perm.name">{{ perm.name }}</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<div class="btn-group">
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">添加</a-button>
|
||||
<a-button @click="closeForm">取消</a-button>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">{{ $t('acl.add') }}</a-button>
|
||||
<a-button @click="closeForm">{{ $t('button.cancel') }}</a-button>
|
||||
</div>
|
||||
|
||||
</a-form>
|
||||
@@ -47,7 +47,7 @@ export default {
|
||||
allRoles: [],
|
||||
allPerms: [],
|
||||
visible: false,
|
||||
instance: {} // 当前对象
|
||||
instance: {}
|
||||
}
|
||||
},
|
||||
props: {
|
||||
@@ -84,7 +84,7 @@ export default {
|
||||
this.loadPerm(record['resource_type_id'])
|
||||
},
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
},
|
||||
filterOption (input, option) {
|
||||
@@ -98,7 +98,7 @@ export default {
|
||||
if (!err) {
|
||||
values.roleIdList.forEach(roleId => {
|
||||
setRoleResourcePerm(roleId, this.instance.id, { perms: values.permName }).then(
|
||||
res => { this.$message.info('添加授权成功') }).catch(
|
||||
res => { this.$message.info(this.$t('tip.addSuccess')) }).catch(
|
||||
err => this.requestFailed(err))
|
||||
})
|
||||
}
|
||||
|
@@ -13,29 +13,29 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="类型名"
|
||||
:label="$t('acl.name')"
|
||||
>
|
||||
<a-input
|
||||
name="name"
|
||||
placeholder="类型名称"
|
||||
v-decorator="['name', {rules: [{ required: true, message: '请输入类型名'}]} ]"
|
||||
:placeholder="$t('acl.name')"
|
||||
v-decorator="['name', {rules: [{ required: true, message: $t('acl.resourceTypeNameRequired')}]} ]"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="描述"
|
||||
:label="$t('acl.description')"
|
||||
>
|
||||
<a-textarea placeholder="请输入描述信息..." name="description" :rows="4" v-decorator="['description', {rules: []} ]"/>
|
||||
<a-textarea :placeholder="$t('acl.descriptionTip')" name="description" :rows="4" v-decorator="['description', {rules: []} ]"/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="权限"
|
||||
:label="$t('acl.permission')"
|
||||
>
|
||||
<a-select mode="tags" v-model="perms" style="width: 100%" placeholder="请输入权限名...">
|
||||
<a-select mode="tags" v-model="perms" style="width: 100%" :placeholder="$t('acl.permissionNameRequired')">
|
||||
</a-select>
|
||||
|
||||
</a-form-item>
|
||||
@@ -60,8 +60,8 @@
|
||||
|
||||
}"
|
||||
>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">确定</a-button>
|
||||
<a-button @click="onClose">取消</a-button>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">{{ $t('button.submit') }}</a-button>
|
||||
<a-button @click="onClose">{{ $t('button.cancel') }}</a-button>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
drawerTitle: '新增资源类型',
|
||||
drawerTitle: this.$t('acl.newResourceType'),
|
||||
drawerVisible: false,
|
||||
formLayout: 'vertical',
|
||||
perms: []
|
||||
@@ -159,7 +159,7 @@ export default {
|
||||
updateResourceType (id, data) {
|
||||
updateResourceTypeById(id, data)
|
||||
.then(res => {
|
||||
this.$message.success(`更新成功`)
|
||||
this.$message.success(this.$t('tip.updateSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
}).catch(err => this.requestFailed(err))
|
||||
@@ -168,7 +168,7 @@ export default {
|
||||
createResourceType (data) {
|
||||
addResourceType(data)
|
||||
.then(res => {
|
||||
this.$message.success(`添加成功`)
|
||||
this.$message.success(this.$t('tip.addSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
})
|
||||
@@ -176,7 +176,7 @@ export default {
|
||||
},
|
||||
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -13,22 +13,22 @@
|
||||
<a-form-item
|
||||
:label-col="{span:6}"
|
||||
:wrapper-col="{span:12}"
|
||||
label="角色名"
|
||||
:label="$t('acl.roleName')"
|
||||
>
|
||||
<a-input
|
||||
name="name"
|
||||
placeholder=""
|
||||
v-decorator="['name', {rules: [{ required: true, message: '请输入角色名'}]} ]"
|
||||
v-decorator="['name', {rules: [{ required: true, message: $t('acl.roleNameRequired')}]} ]"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
:label-col="{span:6}"
|
||||
:wrapper-col="{span:12}"
|
||||
label="继承自"
|
||||
:label="$t('acl.inheritedFrom')"
|
||||
>
|
||||
<a-select
|
||||
v-model="selectedParents"
|
||||
placeholder="可选择继承角色"
|
||||
:placeholder="$t('acl.selectInheritedRoles')"
|
||||
mode="multiple"
|
||||
:filterOption="filterOption">
|
||||
<template v-for="role in allRoles">
|
||||
@@ -39,7 +39,7 @@
|
||||
<a-form-item
|
||||
:label-col="{span:8}"
|
||||
:wrapper-col="{span:10}"
|
||||
label="是否应用管理员"
|
||||
:label="$t('acl.isAppAdmin')"
|
||||
>
|
||||
<a-switch
|
||||
@change="onChange"
|
||||
@@ -66,8 +66,8 @@
|
||||
background: '#fff',
|
||||
}"
|
||||
>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">确定</a-button>
|
||||
<a-button @click="onClose">取消</a-button>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">{{ $t('button.submit') }}</a-button>
|
||||
<a-button @click="onClose">{{ $t('button.cancel') }}</a-button>
|
||||
</div>
|
||||
|
||||
</a-form>
|
||||
@@ -86,7 +86,7 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
drawerTitle: '新增角色',
|
||||
drawerTitle: this.$t('acl.newRole'),
|
||||
current_id: 0,
|
||||
drawerVisible: false,
|
||||
formLayout: 'vertical',
|
||||
@@ -130,7 +130,7 @@ export default {
|
||||
)
|
||||
},
|
||||
handleCreate () {
|
||||
this.drawerTitle = '新增'
|
||||
this.drawerTitle = this.$t('button.add')
|
||||
this.drawerVisible = true
|
||||
},
|
||||
onClose () {
|
||||
@@ -144,7 +144,7 @@ export default {
|
||||
},
|
||||
|
||||
handleEdit (record) {
|
||||
this.drawerTitle = '编辑'
|
||||
this.drawerTitle = this.$t('button.update')
|
||||
this.drawerVisible = true
|
||||
this.current_id = record.id
|
||||
const _parents = this.id2parents[record.id]
|
||||
@@ -180,7 +180,7 @@ export default {
|
||||
this.updateParents(id)
|
||||
updateRoleById(id, data)
|
||||
.then(res => {
|
||||
this.$message.success(`更新成功`)
|
||||
this.$message.success(this.$t('tip.updateSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
}).catch(err => this.requestFailed(err))
|
||||
@@ -189,7 +189,7 @@ export default {
|
||||
createRole (data) {
|
||||
addRole(data)
|
||||
.then(res => {
|
||||
this.$message.success(`添加成功`)
|
||||
this.$message.success(this.$t('tip.addSuccess'))
|
||||
this.updateParents(res.id)
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
@@ -209,7 +209,7 @@ export default {
|
||||
})
|
||||
},
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -13,18 +13,18 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="用户名(英文)"
|
||||
:label="$t('acl.username')"
|
||||
>
|
||||
<a-input
|
||||
name="username"
|
||||
placeholder="英文名"
|
||||
v-decorator="['username', {rules: [{ required: true, message: '请输入用户名'}]} ]"
|
||||
:placeholder="$t('acl.username')"
|
||||
v-decorator="['username', {rules: [{ required: true, message: $t('acl.usernameRequired')}]} ]"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="中文名"
|
||||
:label="$t('acl.nickname')"
|
||||
>
|
||||
<a-input
|
||||
name="nickname"
|
||||
@@ -34,7 +34,7 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="密码"
|
||||
:label="$t('acl.password')"
|
||||
>
|
||||
<a-input
|
||||
type="password"
|
||||
@@ -46,7 +46,7 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="部门"
|
||||
:label="$t('acl.department')"
|
||||
>
|
||||
<a-input
|
||||
name="department"
|
||||
@@ -57,7 +57,7 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="小组"
|
||||
:label="$t('acl.catalog')"
|
||||
>
|
||||
<a-input
|
||||
name="catalog"
|
||||
@@ -68,7 +68,7 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="邮箱"
|
||||
:label="$t('acl.email')"
|
||||
>
|
||||
<a-input
|
||||
name="email"
|
||||
@@ -78,11 +78,11 @@
|
||||
rules: [
|
||||
{
|
||||
type: 'email',
|
||||
message: '请输入正确的邮箱!',
|
||||
message: $t('acl.emailValidate'),
|
||||
},
|
||||
{
|
||||
required: true,
|
||||
message: '请输入邮箱',
|
||||
message: $t('acl.emailRequired'),
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -93,18 +93,18 @@
|
||||
<a-form-item
|
||||
:label-col="formItemLayout.labelCol"
|
||||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="手机号码"
|
||||
:label="$t('acl.mobile')"
|
||||
>
|
||||
<a-input
|
||||
name="mobile"
|
||||
v-decorator="['mobile', {rules: [{message: '请输入正确的手机号码', pattern: /^1\d{10}$/ }]} ]"
|
||||
v-decorator="['mobile', {rules: [{message: $t('acl.mobileValidate'), pattern: /^1\d{10}$/ }]} ]"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
:label-col="horizontalFormItemLayout.labelCol"
|
||||
:wrapper-col="horizontalFormItemLayout.wrapperCol"
|
||||
label="是否锁定"
|
||||
:label="$t('acl.block')"
|
||||
>
|
||||
<a-switch
|
||||
@change="onChange"
|
||||
@@ -133,8 +133,8 @@
|
||||
|
||||
}"
|
||||
>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">确定</a-button>
|
||||
<a-button @click="onClose">取消</a-button>
|
||||
<a-button @click="handleSubmit" type="primary" style="margin-right: 1rem">{{ $t('button.submit') }}</a-button>
|
||||
<a-button @click="onClose">{{ $t('button.cancel') }}</a-button>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -154,7 +154,7 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
drawerTitle: '新增用户',
|
||||
drawerTitle: this.$t('acl.newUser'),
|
||||
drawerVisible: false,
|
||||
formLayout: 'vertical'
|
||||
}
|
||||
@@ -235,7 +235,7 @@ export default {
|
||||
updateUser (attrId, data) {
|
||||
updateUserById(attrId, data)
|
||||
.then(res => {
|
||||
this.$message.success(`更新成功`)
|
||||
this.$message.success(this.$t('tip.updateSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
}).catch(err => this.requestFailed(err))
|
||||
@@ -244,7 +244,7 @@ export default {
|
||||
createUser (data) {
|
||||
addUser(data)
|
||||
.then(res => {
|
||||
this.$message.success(`添加成功`)
|
||||
this.$message.success(this.$t('tip.addSuccess'))
|
||||
this.handleOk()
|
||||
this.onClose()
|
||||
})
|
||||
@@ -252,7 +252,7 @@ export default {
|
||||
},
|
||||
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<a-card :bordered="false">
|
||||
|
||||
<div class="action-btn">
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ btnName }}</a-button>
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ $t('acl.newResourceType') }}</a-button>
|
||||
</div>
|
||||
|
||||
<s-table
|
||||
@@ -12,7 +12,7 @@
|
||||
:rowKey="record=>record.id"
|
||||
:rowSelection="options.rowSelection"
|
||||
:scroll="scroll"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条记录`, pageSizeOptions: pageSizeOptions}"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} ${total} records in total`, pageSizeOptions: pageSizeOptions}"
|
||||
showPagination="auto"
|
||||
:pageSize="25"
|
||||
ref="table"
|
||||
@@ -34,12 +34,12 @@
|
||||
icon="search"
|
||||
size="small"
|
||||
style="width: 90px; margin-right: 8px"
|
||||
>搜索</a-button>
|
||||
>{{ $t('button.query') }}</a-button>
|
||||
<a-button
|
||||
@click="() => handleReset(clearFilters, column)"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
>重置</a-button>
|
||||
>{{ $t('button.reset') }}</a-button>
|
||||
</div>
|
||||
<a-icon slot="filterIcon" slot-scope="filtered" type="search" :style="{ color: filtered ? '#108ee9' : undefined }" />
|
||||
|
||||
@@ -61,17 +61,17 @@
|
||||
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<template>
|
||||
<a @click="handleEdit(record)">编辑</a>
|
||||
<a @click="handleEdit(record)">{{ $t('tip.edit') }}</a>
|
||||
<a-divider type="vertical"/>
|
||||
|
||||
<a-popconfirm
|
||||
title="确认删除?"
|
||||
:title="$t('tip.confirmDelete')"
|
||||
@confirm="handleDelete(record)"
|
||||
@cancel="cancel"
|
||||
okText="是"
|
||||
cancelText="否"
|
||||
:okText="$t('button.yes')"
|
||||
:cancelText="$t('button.no')"
|
||||
>
|
||||
<a>删除</a>
|
||||
<a>{{ $t('tip.delete') }}</a>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</span>
|
||||
@@ -97,7 +97,6 @@ export default {
|
||||
return {
|
||||
id2perms: {},
|
||||
scroll: { x: 1000, y: 500 },
|
||||
btnName: '新增资源类型',
|
||||
|
||||
formLayout: 'vertical',
|
||||
|
||||
@@ -109,7 +108,7 @@ export default {
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
title: '类型名',
|
||||
title: this.$t('acl.typeName'),
|
||||
dataIndex: 'name',
|
||||
sorter: false,
|
||||
width: 50,
|
||||
@@ -128,20 +127,20 @@ export default {
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
title: this.$t('acl.description'),
|
||||
dataIndex: 'description',
|
||||
width: 250,
|
||||
sorter: false,
|
||||
scopedSlots: { customRender: 'description' }
|
||||
},
|
||||
{
|
||||
title: '权限',
|
||||
title: this.$t('acl.permission'),
|
||||
dataIndex: 'id',
|
||||
sorter: false,
|
||||
scopedSlots: { customRender: 'id' }
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
title: this.$t('tip.operate'),
|
||||
dataIndex: 'action',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
@@ -169,11 +168,8 @@ export default {
|
||||
},
|
||||
|
||||
mdl: {},
|
||||
// 高级搜索 展开/关闭
|
||||
advanced: false,
|
||||
// 查询参数
|
||||
queryParam: {},
|
||||
// 表头
|
||||
|
||||
selectedRowKeys: [],
|
||||
selectedRows: [],
|
||||
@@ -255,13 +251,13 @@ export default {
|
||||
deleteResourceType (id) {
|
||||
deleteResourceTypeById(id)
|
||||
.then(res => {
|
||||
this.$message.success(`删除成功`)
|
||||
this.$message.success(this.$t('tip.deleteSuccess'))
|
||||
this.handleOk()
|
||||
})
|
||||
.catch(err => this.requestFailed(err))
|
||||
},
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
},
|
||||
cancel () {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<a-card :bordered="false">
|
||||
|
||||
<div class="action-btn">
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ btnName }}</a-button>
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ $t('acl.newResourceType') }}</a-button>
|
||||
</div>
|
||||
|
||||
<s-table
|
||||
@@ -12,7 +12,7 @@
|
||||
:rowKey="record=>record.id"
|
||||
:rowSelection="options.rowSelection"
|
||||
:scroll="scroll"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条记录`, pageSizeOptions: pageSizeOptions}"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} ${total} records in total`, pageSizeOptions: pageSizeOptions}"
|
||||
showPagination="auto"
|
||||
:pageSize="25"
|
||||
ref="table"
|
||||
@@ -34,12 +34,12 @@
|
||||
icon="search"
|
||||
size="small"
|
||||
style="width: 90px; margin-right: 8px"
|
||||
>搜索</a-button>
|
||||
>{{ $t('button.query') }}</a-button>
|
||||
<a-button
|
||||
@click="() => handleReset(clearFilters, column)"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
>重置</a-button>
|
||||
>{{ $t('button.reset') }}</a-button>
|
||||
</div>
|
||||
<a-icon slot="filterIcon" slot-scope="filtered" type="search" :style="{ color: filtered ? '#108ee9' : undefined }" />
|
||||
|
||||
@@ -61,17 +61,17 @@
|
||||
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<template>
|
||||
<a @click="handleEdit(record)">编辑</a>
|
||||
<a @click="handleEdit(record)">{{ $t('tip.edit') }}</a>
|
||||
<a-divider type="vertical"/>
|
||||
|
||||
<a-popconfirm
|
||||
title="确认删除?"
|
||||
:title="$t('tip.confirmDelete')"
|
||||
@confirm="handleDelete(record)"
|
||||
@cancel="cancel"
|
||||
okText="是"
|
||||
cancelText="否"
|
||||
:okText="$t('button.yes')"
|
||||
:cancelText="$t('button.no')"
|
||||
>
|
||||
<a>删除</a>
|
||||
<a>{{ $t('tip.delete') }}</a>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</span>
|
||||
@@ -97,7 +97,6 @@ export default {
|
||||
return {
|
||||
id2perms: {},
|
||||
scroll: { x: 1000, y: 500 },
|
||||
btnName: '新增资源类型',
|
||||
|
||||
formLayout: 'vertical',
|
||||
|
||||
@@ -109,7 +108,7 @@ export default {
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
title: '类型名',
|
||||
title: this.$t('acl.typeName'),
|
||||
dataIndex: 'name',
|
||||
sorter: false,
|
||||
width: 150,
|
||||
@@ -128,21 +127,21 @@ export default {
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
title: this.$t('acl.description'),
|
||||
dataIndex: 'description',
|
||||
width: 200,
|
||||
sorter: false,
|
||||
scopedSlots: { customRender: 'description' }
|
||||
},
|
||||
{
|
||||
title: '权限',
|
||||
title: this.$t('acl.permission'),
|
||||
dataIndex: 'id',
|
||||
width: 300,
|
||||
sorter: false,
|
||||
scopedSlots: { customRender: 'id' }
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
title: this.$t('tip.operate'),
|
||||
dataIndex: 'action',
|
||||
width: 150,
|
||||
scopedSlots: { customRender: 'action' }
|
||||
@@ -169,11 +168,8 @@ export default {
|
||||
},
|
||||
|
||||
mdl: {},
|
||||
// 高级搜索 展开/关闭
|
||||
advanced: false,
|
||||
// 查询参数
|
||||
queryParam: {},
|
||||
// 表头
|
||||
|
||||
selectedRowKeys: [],
|
||||
selectedRows: [],
|
||||
@@ -263,13 +259,13 @@ export default {
|
||||
deleteResourceType (id) {
|
||||
deleteResourceTypeById(id)
|
||||
.then(res => {
|
||||
this.$message.success(`删除成功`)
|
||||
this.$message.success(this.$t('tip.deleteSuccess'))
|
||||
this.handleOk()
|
||||
})
|
||||
.catch(err => this.requestFailed(err))
|
||||
},
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
},
|
||||
cancel () {
|
||||
|
@@ -18,7 +18,7 @@
|
||||
</div>
|
||||
<a-divider style="margin-top: -16px" />
|
||||
<div class="action-btn">
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ btnName }}</a-button>
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ $t('acl.newResource') }}</a-button>
|
||||
</div>
|
||||
|
||||
<s-table
|
||||
@@ -28,7 +28,7 @@
|
||||
:rowKey="record=>record.id"
|
||||
:rowSelection="options.rowSelection"
|
||||
:scroll="scroll"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条记录`, pageSizeOptions: pageSizeOptions}"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} ${total} records in total`, pageSizeOptions: pageSizeOptions}"
|
||||
showPagination="auto"
|
||||
:pageSize="25"
|
||||
ref="table"
|
||||
@@ -50,12 +50,12 @@
|
||||
icon="search"
|
||||
size="small"
|
||||
style="width: 90px; margin-right: 8px"
|
||||
>搜索</a-button>
|
||||
>{{ $t('button.query') }}</a-button>
|
||||
<a-button
|
||||
@click="() => handleReset(clearFilters, column)"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
>重置</a-button>
|
||||
>{{ $t('button.reset') }}</a-button>
|
||||
</div>
|
||||
<a-icon slot="filterIcon" slot-scope="filtered" type="search" :style="{ color: filtered ? '#108ee9' : undefined }" />
|
||||
|
||||
@@ -70,18 +70,18 @@
|
||||
</template>
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<template>
|
||||
<a @click="handlePerm(record)">查看授权</a>
|
||||
<a @click="handlePerm(record)">{{ $t('acl.viewAuthorization') }}</a>
|
||||
<a-divider type="vertical"/>
|
||||
<a @click="handlePermManage(record)">授权</a>
|
||||
<a @click="handlePermManage(record)">{{ $t('acl.authorization') }}</a>
|
||||
<a-divider type="vertical"/>
|
||||
<a-popconfirm
|
||||
title="确认删除?"
|
||||
:title="$t('tip.confirmDelete')"
|
||||
@confirm="handleDelete(record)"
|
||||
@cancel="cancel"
|
||||
okText="是"
|
||||
cancelText="否"
|
||||
:okText="$t('button.yes')"
|
||||
:cancelText="$t('button.no')"
|
||||
>
|
||||
<a>删除</a>
|
||||
<a>{{ $t('tip.delete') }}</a>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</span>
|
||||
@@ -111,7 +111,6 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
scroll: { x: 1000, y: 500 },
|
||||
btnName: '新增资源',
|
||||
allResourceTypes: [],
|
||||
currentType: { id: 0 },
|
||||
formLayout: 'vertical',
|
||||
@@ -125,7 +124,7 @@ export default {
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
title: '资源名',
|
||||
title: this.$t('acl.resourceName'),
|
||||
dataIndex: 'name',
|
||||
sorter: false,
|
||||
width: 250,
|
||||
@@ -144,17 +143,17 @@ export default {
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
title: this.$t('acl.createdAt'),
|
||||
width: 200,
|
||||
dataIndex: 'created_at'
|
||||
},
|
||||
{
|
||||
title: '最后修改时间',
|
||||
title: this.$t('acl.updatedAt'),
|
||||
width: 200,
|
||||
dataIndex: 'updated_at'
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
title: this.$t('tip.operate'),
|
||||
dataIndex: 'action',
|
||||
width: 150,
|
||||
scopedSlots: { customRender: 'action' }
|
||||
@@ -181,11 +180,8 @@ export default {
|
||||
},
|
||||
|
||||
mdl: {},
|
||||
// 高级搜索 展开/关闭
|
||||
advanced: false,
|
||||
// 查询参数
|
||||
queryParam: {},
|
||||
// 表头
|
||||
|
||||
selectedRowKeys: [],
|
||||
selectedRows: [],
|
||||
@@ -281,13 +277,13 @@ export default {
|
||||
deleteResource (id) {
|
||||
deleteResourceById(id)
|
||||
.then(res => {
|
||||
this.$message.success(`删除成功`)
|
||||
this.$message.success(this.$t('tip.deleteSuccess'))
|
||||
this.handleOk()
|
||||
})
|
||||
.catch(err => this.requestFailed(err))
|
||||
},
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
},
|
||||
cancel () {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<a-card :bordered="false">
|
||||
|
||||
<div class="action-btn">
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ btnName }}</a-button>
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ $t('acl.newRole') }}</a-button>
|
||||
</div>
|
||||
|
||||
<s-table
|
||||
@@ -11,7 +11,7 @@
|
||||
:data="loadData"
|
||||
:rowKey="record=>record.id"
|
||||
:rowSelection="options.rowSelection"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条记录`, pageSizeOptions: pageSizeOptions}"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} ${total} records in total`, pageSizeOptions: pageSizeOptions}"
|
||||
showPagination="auto"
|
||||
:pageSize="25"
|
||||
ref="table"
|
||||
@@ -32,12 +32,12 @@
|
||||
icon="search"
|
||||
size="small"
|
||||
style="width: 90px; margin-right: 8px"
|
||||
>搜索</a-button>
|
||||
>{{ $t('button.query') }}</a-button>
|
||||
<a-button
|
||||
@click="() => handleReset(clearFilters, column)"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
>重置</a-button>
|
||||
>{{ $t('button.reset') }}</a-button>
|
||||
</div>
|
||||
<a-icon slot="filterIcon" slot-scope="filtered" type="search" :style="{ color: filtered ? '#108ee9' : undefined }" />
|
||||
|
||||
@@ -61,16 +61,16 @@
|
||||
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<template>
|
||||
<a @click="handleEdit(record)">修改</a>
|
||||
<a @click="handleEdit(record)">{{ $t('button.update') }}</a>
|
||||
<a-divider type="vertical"/>
|
||||
<a-popconfirm
|
||||
title="确认删除?"
|
||||
:title="$t('tip.confirmDelete')"
|
||||
@confirm="handleDelete(record)"
|
||||
@cancel="cancel"
|
||||
okText="是"
|
||||
cancelText="否"
|
||||
:okText="$t('button.yes')"
|
||||
:cancelText="$t('button.no')"
|
||||
>
|
||||
<a>删除</a>
|
||||
<a>{{ $t('tip.delete') }}</a>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</span>
|
||||
@@ -93,7 +93,6 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
scroll: { x: 1000, y: 500 },
|
||||
btnName: '新增角色',
|
||||
|
||||
formLayout: 'vertical',
|
||||
|
||||
@@ -107,7 +106,7 @@ export default {
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
title: '角色名',
|
||||
title: this.$t('acl.roleName'),
|
||||
dataIndex: 'name',
|
||||
sorter: false,
|
||||
width: 150,
|
||||
@@ -126,7 +125,7 @@ export default {
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '是否管理员',
|
||||
title: this.$t('acl.isAppAdmin'),
|
||||
dataIndex: 'is_app_admin',
|
||||
width: 100,
|
||||
sorter: false,
|
||||
@@ -134,7 +133,7 @@ export default {
|
||||
|
||||
},
|
||||
{
|
||||
title: '继承自',
|
||||
title: this.$t('acl.inheritedFrom'),
|
||||
dataIndex: 'id',
|
||||
sorter: false,
|
||||
width: 250,
|
||||
@@ -142,7 +141,7 @@ export default {
|
||||
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
title: this.$t('tip.operate'),
|
||||
dataIndex: 'action',
|
||||
width: 150,
|
||||
scopedSlots: { customRender: 'action' }
|
||||
@@ -171,11 +170,8 @@ export default {
|
||||
},
|
||||
|
||||
mdl: {},
|
||||
// 高级搜索 展开/关闭
|
||||
advanced: false,
|
||||
// 查询参数
|
||||
queryParam: {},
|
||||
// 表头
|
||||
|
||||
selectedRowKeys: [],
|
||||
selectedRows: [],
|
||||
@@ -256,13 +252,13 @@ export default {
|
||||
deleteRole (id) {
|
||||
deleteRoleById(id)
|
||||
.then(res => {
|
||||
this.$message.success(`删除成功`)
|
||||
this.$message.success(this.$t('tip.deleteSuccess'))
|
||||
this.handleOk()
|
||||
})
|
||||
.catch(err => this.requestFailed(err))
|
||||
},
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
},
|
||||
cancel (e) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<a-card :bordered="false">
|
||||
|
||||
<div class="action-btn">
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ btnName }}</a-button>
|
||||
<a-button @click="handleCreate" type="primary" style="margin-right: 0.3rem;">{{ $t('acl.newUser') }}</a-button>
|
||||
</div>
|
||||
|
||||
<s-table
|
||||
@@ -12,7 +12,7 @@
|
||||
:rowKey="record=>record.uid"
|
||||
:rowSelection="options.rowSelection"
|
||||
:scroll="scroll"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条记录`, pageSizeOptions: pageSizeOptions}"
|
||||
:pagination="{ showTotal: (total, range) => `${range[0]}-${range[1]} ${total} records in total`, pageSizeOptions: pageSizeOptions}"
|
||||
showPagination="auto"
|
||||
:pageSize="25"
|
||||
ref="table"
|
||||
@@ -33,12 +33,12 @@
|
||||
icon="search"
|
||||
size="small"
|
||||
style="width: 90px; margin-right: 8px"
|
||||
>搜索</a-button>
|
||||
>{{ $t('button.query') }}</a-button>
|
||||
<a-button
|
||||
@click="() => handleReset(clearFilters, column)"
|
||||
size="small"
|
||||
style="width: 90px"
|
||||
>重置</a-button>
|
||||
>{{ $t('button.reset') }}</a-button>
|
||||
</div>
|
||||
<a-icon slot="filterIcon" slot-scope="filtered" type="search" :style="{ color: filtered ? '#108ee9' : undefined }" />
|
||||
|
||||
@@ -71,17 +71,17 @@
|
||||
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<template>
|
||||
<a @click="handleEdit(record)">编辑</a>
|
||||
<a @click="handleEdit(record)">{{ $t('tip.edit') }}</a>
|
||||
<a-divider type="vertical"/>
|
||||
|
||||
<a-popconfirm
|
||||
title="确认删除?"
|
||||
:title="$t('tip.confirmDelete')"
|
||||
@confirm="handleDelete(record)"
|
||||
@cancel="cancel"
|
||||
okText="是"
|
||||
cancelText="否"
|
||||
:okText="$t('button.yes')"
|
||||
:cancelText="$t('button.no')"
|
||||
>
|
||||
<a>删除</a>
|
||||
<a>{{ $t('tip.delete') }}</a>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</span>
|
||||
@@ -106,7 +106,6 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
scroll: { x: 1300, y: 500 },
|
||||
btnName: '新增用户',
|
||||
|
||||
CITypeName: this.$route.params.CITypeName,
|
||||
CITypeId: this.$route.params.CITypeId,
|
||||
@@ -122,7 +121,7 @@ export default {
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
title: '用户名',
|
||||
title: this.$t('acl.username'),
|
||||
dataIndex: 'username',
|
||||
sorter: false,
|
||||
width: 150,
|
||||
@@ -141,7 +140,7 @@ export default {
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '中文名',
|
||||
title: this.$t('acl.nickname'),
|
||||
dataIndex: 'nickname',
|
||||
sorter: false,
|
||||
width: 150,
|
||||
@@ -160,7 +159,7 @@ export default {
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '部门',
|
||||
title: this.$t('acl.department'),
|
||||
dataIndex: 'department',
|
||||
width: 100,
|
||||
sorter: false,
|
||||
@@ -168,7 +167,7 @@ export default {
|
||||
|
||||
},
|
||||
{
|
||||
title: '小组',
|
||||
title: this.$t('acl.catalog'),
|
||||
dataIndex: 'catalog',
|
||||
sorter: false,
|
||||
width: 100,
|
||||
@@ -176,7 +175,7 @@ export default {
|
||||
|
||||
},
|
||||
{
|
||||
title: '邮箱',
|
||||
title: this.$t('acl.email'),
|
||||
dataIndex: 'email',
|
||||
sorter: false,
|
||||
width: 200,
|
||||
@@ -184,7 +183,7 @@ export default {
|
||||
|
||||
},
|
||||
{
|
||||
title: '手机',
|
||||
title: this.$t('acl.mobile'),
|
||||
dataIndex: 'mobile',
|
||||
sorter: false,
|
||||
width: 150,
|
||||
@@ -192,7 +191,7 @@ export default {
|
||||
|
||||
},
|
||||
{
|
||||
title: '加入时间',
|
||||
title: this.$t('acl.joinedAt'),
|
||||
dataIndex: 'date_joined',
|
||||
sorter: false,
|
||||
width: 200,
|
||||
@@ -200,13 +199,13 @@ export default {
|
||||
|
||||
},
|
||||
{
|
||||
title: '锁定',
|
||||
title: this.$t('acl.block'),
|
||||
dataIndex: 'block',
|
||||
width: 100,
|
||||
scopedSlots: { customRender: 'block' }
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
title: this.$t('tip.operate'),
|
||||
dataIndex: 'action',
|
||||
width: 150,
|
||||
scopedSlots: { customRender: 'action' }
|
||||
@@ -232,11 +231,8 @@ export default {
|
||||
})
|
||||
},
|
||||
mdl: {},
|
||||
// 高级搜索 展开/关闭
|
||||
advanced: false,
|
||||
// 查询参数
|
||||
queryParam: {},
|
||||
// 表头
|
||||
selectedRowKeys: [],
|
||||
selectedRows: [],
|
||||
// custom table alert & rowSelection
|
||||
@@ -316,13 +312,13 @@ export default {
|
||||
deleteUser (attrId) {
|
||||
deleteUserById(attrId)
|
||||
.then(res => {
|
||||
this.$message.success(`删除成功`)
|
||||
this.$message.success(this.$t('tip.deleteSuccess'))
|
||||
this.handleOk()
|
||||
})
|
||||
.catch(err => this.requestFailed(err))
|
||||
},
|
||||
requestFailed (err) {
|
||||
const msg = ((err.response || {}).data || {}).message || '请求出现错误,请稍后再试'
|
||||
const msg = ((err.response || {}).data || {}).message || this.$t('tip.requestFailed')
|
||||
this.$message.error(`${msg}`)
|
||||
}
|
||||
|
||||
|
@@ -7,14 +7,14 @@
|
||||
<a-row>
|
||||
<a-col :span="18">
|
||||
<a-card style="height: 605px">
|
||||
<a-button class="ant-btn-primary" style="margin-left: 10px;" :disabled="uploadFlag" id="upload-button" @click="uploadData">上传</a-button>
|
||||
<a-button class="ant-btn-primary" style="margin-left: 10px;" :disabled="uploadFlag" id="upload-button" @click="uploadData">{{ $t('button.upload') }}</a-button>
|
||||
<upload-file-form v-if="displayUpload" ref="fileEditor"></upload-file-form>
|
||||
<ci-table v-if="editorOnline" :ciTypeAttrs="ciTypeAttrs" ref="onlineEditor"></ci-table>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6">
|
||||
<div style="min-height: 604px; background: white">
|
||||
<a-card title="上传结果">
|
||||
<a-card :title="$t('batch.uploadResult')">
|
||||
<upload-result v-if="beginLoad" :upLoadData="needDataList" :ciType="ciType" :unique-field="uniqueField"></upload-result>
|
||||
</a-card>
|
||||
</div>
|
||||
@@ -64,7 +64,7 @@ export default {
|
||||
},
|
||||
uploadData () {
|
||||
if (this.ciType < 0) {
|
||||
alert('尚未选择模板类型!')
|
||||
alert('CI Type not yet selected!')
|
||||
return
|
||||
}
|
||||
this.beginLoad = false
|
||||
|
@@ -36,42 +36,35 @@ export default {
|
||||
maxRows: 90,
|
||||
maxCols: 90,
|
||||
rowHeaders: true,
|
||||
// minSpareCols: 2, //列留白
|
||||
// minSpareCols: 2,
|
||||
colHeaders: aliasList,
|
||||
minSpareRows: 2, // 行留白
|
||||
// autoWrapRow: true, // 自动换行
|
||||
// 自定义右键菜单,可汉化,默认布尔值
|
||||
minSpareRows: 2,
|
||||
// autoWrapRow: true,
|
||||
contextMenu: {
|
||||
items: {
|
||||
row_above: {
|
||||
name: '上方插入一行'
|
||||
name: 'insert a line at the top'
|
||||
},
|
||||
row_below: {
|
||||
name: '下方插入一行'
|
||||
name: 'insert a line at the bottom'
|
||||
},
|
||||
moverow: {
|
||||
name: '删除行'
|
||||
name: 'Delete rows'
|
||||
},
|
||||
unfreeze_column: {
|
||||
name: '取消列固定'
|
||||
name: 'Uncolumn fixation'
|
||||
},
|
||||
hsep1: '---------', // 提供分隔线
|
||||
hsep1: '---------',
|
||||
hsep2: '---------'
|
||||
}
|
||||
},
|
||||
// width: '100%',
|
||||
// fillHandle: true, // 选中拖拽复制 possible values: true, false, "horizontal", "vertical"
|
||||
fixedColumnsLeft: 0, // 固定左边列数
|
||||
fixedRowsTop: 0, // 固定上边列数
|
||||
manualColumnFreeze: true, // 手动固定列
|
||||
// manualColumnMove: true, // 手动移动列
|
||||
// manualRowMove: true, // 手动移动行
|
||||
// manualColumnResize: true, // 手工更改列距
|
||||
// manualRowResize: true, // 手动更改行距
|
||||
comments: true, // 添加注释
|
||||
customBorders: [], // 添加边框
|
||||
columnSorting: true, // 排序
|
||||
stretchH: 'all', // 根据宽度横向扩展,last:只扩展最后一列,none:默认不扩展
|
||||
fixedColumnsLeft: 0,
|
||||
fixedRowsTop: 0,
|
||||
manualColumnFreeze: true,
|
||||
comments: true,
|
||||
customBorders: [],
|
||||
columnSorting: true,
|
||||
stretchH: 'all',
|
||||
afterChange: function (changes, source) {
|
||||
if (changes !== null) {
|
||||
document.getElementById('upload-button').disabled = false
|
||||
|
@@ -3,10 +3,10 @@
|
||||
<a-form :form="form" style="max-width: 500px; margin: 30px auto 0;">
|
||||
<a-row>
|
||||
<a-col :span="18">
|
||||
<a-form-item label="模板类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
||||
<a-form-item :label="$t('batch.modelType')" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
||||
<a-select
|
||||
placeholder="--请选择模板类型--"
|
||||
v-decorator="['ciTypes', { rules: [{required: true, message: '模板类型必须选择'}] }]"
|
||||
:placeholder="$t('batch.pleaseSelectModelType')"
|
||||
v-decorator="['ciTypes', { rules: [{required: true, message: 'CI Type must be selected'}] }]"
|
||||
@change="selectCiType"
|
||||
>
|
||||
<a-select-option v-for="ciType in ciTypeList" :key="ciType.name" :value="ciType.id">{{ ciType.alias }}</a-select-option>
|
||||
@@ -19,7 +19,7 @@
|
||||
style="margin-left: 20px"
|
||||
:disabled="downLoadButtonDis"
|
||||
@click="downLoadExcel"
|
||||
>下载模板</a-button>
|
||||
>{{ $t('button.downloadTemplate') }}</a-button>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
@@ -54,7 +54,6 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
selectCiType (el) {
|
||||
// 当选择好模板类型时的回调函数
|
||||
this.downLoadButtonDis = false
|
||||
this.selectNum = el
|
||||
getCITypeAttributesById(el).then(res => {
|
||||
|