From 58ad9d3f05461d750af8cadd15bb5c878a48e4a4 Mon Sep 17 00:00:00 2001 From: pycook Date: Mon, 11 Nov 2019 00:25:22 +0800 Subject: [PATCH] vue lint --- api/lib/cmdb/const.py | 7 +++- api/lib/cmdb/value.py | 2 + docker-compose.yml | 1 - ui/Dockerfile | 4 +- ui/src/api/index.js | 2 +- ui/src/api/login.js | 11 +++--- ui/src/config/defaultSettings.js | 2 +- ui/src/config/router.config.js | 4 +- ui/src/permission.js | 8 ++-- ui/src/views/cmdb/ci/index.vue | 38 +++++++++---------- .../cmdb/ci/modules/CreateInstanceForm.vue | 2 +- ui/src/views/user/Login.vue | 2 +- 12 files changed, 42 insertions(+), 41 deletions(-) diff --git a/api/lib/cmdb/const.py b/api/lib/cmdb/const.py index ffeabae..d7e0b39 100644 --- a/api/lib/cmdb/const.py +++ b/api/lib/cmdb/const.py @@ -1,5 +1,8 @@ # -*- coding:utf-8 -*- + +from __future__ import unicode_literals + import datetime import six @@ -37,8 +40,8 @@ type_map = { 'deserialize': { Attribute.INT: string2int, Attribute.FLOAT: float, - Attribute.TEXT: escape, - Attribute.TIME: escape, + Attribute.TEXT: lambda x: escape(x).encode('utf-8').decode('utf-8'), + Attribute.TIME: lambda x: escape(x).encode('utf-8').decode('utf-8'), Attribute.DATETIME: str2datetime, Attribute.DATE: str2datetime, }, diff --git a/api/lib/cmdb/value.py b/api/lib/cmdb/value.py index c320644..a9eb4fe 100644 --- a/api/lib/cmdb/value.py +++ b/api/lib/cmdb/value.py @@ -1,6 +1,8 @@ # -*- coding:utf-8 -*- +from __future__ import unicode_literals + import markupsafe from flask import abort diff --git a/docker-compose.yml b/docker-compose.yml index 2ac8c46..dadc603 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,7 +61,6 @@ services: CMDB_API_HOST: cmdb-api:5000 NGINX_PORT: 80 volumes: - - "$PWD/conf.d:/etc/nginx/conf.d" - ./docs/nginx.cmdb.conf.example:/etc/nginx/conf.d/nginx.cmdb.conf.example command: - /bin/bash diff --git a/ui/Dockerfile b/ui/Dockerfile index 4701c4e..86900f3 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.9 as builder +FROM node:alpine as builder LABEL description="cmdb-ui" @@ -6,7 +6,7 @@ COPY . /data/apps/cmdb-ui WORKDIR /data/apps/cmdb-ui -RUN apk add yarn && yarn install && sed -i 's#http://127.0.0.1:5000##g' .env && yarn build +RUN sed -i 's#http://127.0.0.1:5000##g' .env && yarn install && yarn build FROM nginx:latest diff --git a/ui/src/api/index.js b/ui/src/api/index.js index e422d8f..8ea0a5b 100644 --- a/ui/src/api/index.js +++ b/ui/src/api/index.js @@ -1,7 +1,7 @@ import config from '@/config/defaultSettings' const api = { - Login: config.useSSO ? '/api/sso/login' : '/login', + Login: config.useSSO ? '/api/sso/login' : '/login', Logout: config.useSSO ? '/api/sso/logout' : '/logout', ForgePassword: '/auth/forge-password', Register: '/auth/register', diff --git a/ui/src/api/login.js b/ui/src/api/login.js index 0bb542a..215950b 100644 --- a/ui/src/api/login.js +++ b/ui/src/api/login.js @@ -12,7 +12,7 @@ import config from '@/config/defaultSettings' * @param parameter * @returns {*} */ -export function login(parameter) { +export function login (parameter) { return axios({ url: api.Login, method: 'post', @@ -20,7 +20,7 @@ export function login(parameter) { }) } -export function getSmsCaptcha(parameter) { +export function getSmsCaptcha (parameter) { return axios({ url: api.SendSms, method: 'post', @@ -28,7 +28,7 @@ export function getSmsCaptcha(parameter) { }) } -export function getInfo() { +export function getInfo () { return axios({ url: api.UserInfo, method: 'get', @@ -38,7 +38,7 @@ export function getInfo() { }) } -export function logout() { +export function logout () { console.log('logout........') if (config.useSSO) { window.location.replace(api.Logout) @@ -51,14 +51,13 @@ export function logout() { } }) } - } /** * get user 2step code open? * @param parameter {*} */ -export function get2step(parameter) { +export function get2step (parameter) { return axios({ url: api.twoStepCode, method: 'post', diff --git a/ui/src/config/defaultSettings.js b/ui/src/config/defaultSettings.js index e617518..a7136e2 100644 --- a/ui/src/config/defaultSettings.js +++ b/ui/src/config/defaultSettings.js @@ -14,7 +14,7 @@ */ export default { - useSSO: false, + useSSO: false, primaryColor: '#1890ff', // primary color of ant design navTheme: 'dark', // theme for nav menu layout: 'sidemenu', // nav menu position: sidemenu or topmenu diff --git a/ui/src/config/router.config.js b/ui/src/config/router.config.js index a9f1ddd..28c94dd 100644 --- a/ui/src/config/router.config.js +++ b/ui/src/config/router.config.js @@ -1,7 +1,7 @@ // eslint-disable-next-line import store from '@/store' -import { UserLayout, BasicLayout, RouteView, PageView } from '@/layouts' +import { UserLayout, BasicLayout, RouteView } from '@/layouts' import { getPreference } from '@/api/cmdb/preference' const cmdbRouter = [ @@ -68,7 +68,7 @@ const cmdbRouter = [ } ] -function copyArray(arr) { +function copyArray (arr) { return arr.map((e) => { if (typeof e === 'object') { return Object.assign({}, e) diff --git a/ui/src/permission.js b/ui/src/permission.js index 8f11232..5dea6e6 100644 --- a/ui/src/permission.js +++ b/ui/src/permission.js @@ -7,7 +7,7 @@ import 'nprogress/nprogress.css' // progress bar style 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 { ACCESS_TOKEN } from './store/mutation-types' NProgress.configure({ showSpinner: false }) // NProgress Configuration @@ -44,15 +44,13 @@ router.beforeEach((to, from, next) => { store.dispatch('Logout') }, 3000) }) - } else if (to.path === '/user/login' && !config.useSSO && store.getters.roles.length !== 0) { next({ path: '/' }) NProgress.done() - } else if (!config.useSSO && !Vue.ls.get(ACCESS_TOKEN) && to.path !== "/user/login") { + } else if (!config.useSSO && !Vue.ls.get(ACCESS_TOKEN) && to.path !== '/user/login') { next({ path: '/user/login', query: { redirect: to.fullPath } }) NProgress.done() - } - else { + } else { next() } }) diff --git a/ui/src/views/cmdb/ci/index.vue b/ui/src/views/cmdb/ci/index.vue index 5200568..678f033 100644 --- a/ui/src/views/cmdb/ci/index.vue +++ b/ui/src/views/cmdb/ci/index.vue @@ -107,7 +107,7 @@ export default { CreateInstanceForm, CiDetail }, - data() { + data () { return { loading: false, loadTip: '', @@ -185,25 +185,25 @@ export default { }, optionAlertShow: false, watch: { - '$route.path': function(newPath, oldPath) { + '$route.path': function (newPath, oldPath) { this.reload() } } } }, - created() { + created () { this.tableOption() this.loadColumns() }, watch: { - '$route.path': function(newPath, oldPath) { + '$route.path': function (newPath, oldPath) { this.reload() } }, inject: ['reload'], methods: { - setColumnWidth() { + setColumnWidth () { let rows = [] try { rows = document.querySelector('.ant-table-body').childNodes[0].childNodes[2].childNodes[0].childNodes @@ -225,7 +225,7 @@ export default { document.querySelector('.ant-table-fixed-right').offsetWidth this.scrollY = window.innerHeight - this.$refs.table.$el.offsetTop - 300 }, - tableOption() { + tableOption () { if (!this.optionAlertShow) { this.options = { alert: { @@ -258,7 +258,7 @@ export default { } }, - loadColumns() { + loadColumns () { getSubscribeAttributes(this.$router.currentRoute.meta.typeId).then(res => { const prefAttrList = res.attributes this.preferenceAttrList = prefAttrList @@ -294,16 +294,16 @@ export default { }) }, - onSelectChange(selectedRowKeys, selectedRows) { + onSelectChange (selectedRowKeys, selectedRows) { this.selectedRowKeys = selectedRowKeys this.selectedRows = selectedRows }, - refreshTable(bool = false) { + refreshTable (bool = false) { this.$refs.table.refresh(bool) }, - onCellChange(key, dataIndex, event, oldValue) { + onCellChange (key, dataIndex, event, oldValue) { const value = event[0] const payload = {} payload[dataIndex] = value @@ -317,14 +317,14 @@ export default { }) }) }, - async batchDownload() { + async batchDownload () { this.loading = true this.loadTip = '正在下载 ...' const promises = this.selectedRowKeys.map(ciId => { return searchCI(`q=_id:${ciId}`).then(res => { - let ciMap = {} + const ciMap = {} Object.keys(res.result[0]).forEach(k => { - if (!["ci_type", "_id", "ci_type_alias", "_type"].includes(k)) { + if (!['ci_type', '_id', 'ci_type_alias', '_type'].includes(k)) { ciMap[k] = res.result[0][k] } }) @@ -337,12 +337,12 @@ export default { return results }, - batchUpdate(values) { + batchUpdate (values) { const that = this this.$confirm({ title: '警告', content: '确认要批量修改吗 ?', - onOk() { + onOk () { that.loading = true that.loadTip = '正在批量修改 ...' const payload = {} @@ -379,12 +379,12 @@ export default { } }) }, - batchDelete() { + batchDelete () { const that = this this.$confirm({ title: '警告', content: '真的要删除吗 ?', - onOk() { + onOk () { that.loading = true that.loadTip = '正在删除 ...' const promises = that.selectedRowKeys.map(ciId => { @@ -412,12 +412,12 @@ export default { } }) }, - deleteCI(record) { + deleteCI (record) { const that = this this.$confirm({ title: '警告', content: '真的要删除吗 ?', - onOk() { + onOk () { deleteCI(record.key) .then(res => { that.$refs.table.refresh(true) diff --git a/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue b/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue index 9976526..5d148c2 100644 --- a/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue +++ b/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue @@ -130,7 +130,7 @@ export default { this.form.validateFields((err, values) => { Object.keys(values).forEach(k => { if (typeof values[k] === 'object') { - values[k] = values[k].format("YYYY-MM-DD HH:mm:ss") + values[k] = values[k].format('YYYY-MM-DD HH:mm:ss') } }) if (!err) { diff --git a/ui/src/views/user/Login.vue b/ui/src/views/user/Login.vue index 501b679..c9545c2 100644 --- a/ui/src/views/user/Login.vue +++ b/ui/src/views/user/Login.vue @@ -139,7 +139,7 @@ export default { } }) }, - + loginSuccess (res) { this.$router.push({ path: this.$route.query.redirect }) // 延迟 1 秒显示欢迎信息