Skip to content

Commit

Permalink
vue-cli-service lint 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed May 15, 2020
1 parent fdd4627 commit 3dc410c
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 77 deletions.
35 changes: 17 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'@vue/standard'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
"space-before-function-paren": 0,
"prefer-const": 0,
"indent": [2, 4]
},
parserOptions: {
parser: 'babel-eslint'
}
root: true,
env: {
node: true
},
extends: [
'plugin:vue/essential',
'@vue/standard'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'space-before-function-paren': 0,
indent: [2, 4]
},
parserOptions: {
parser: 'babel-eslint'
}
}
4 changes: 2 additions & 2 deletions src/store/modules/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default {
},
actions: {
GEN_MENU({ commit, rootState }) {
let MainContainer = MainRoutes.find(v => v.path === '')
let children = MainContainer.children
const MainContainer = MainRoutes.find(v => v.path === '')
const children = MainContainer.children
let dr = dynamicRouter
if (!rootState.isAdmin) {
dr = dr.filter(v => v.meta.admin === false)
Expand Down
6 changes: 3 additions & 3 deletions src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export function readablizeBytes(bytes) {
if (bytes === 0) {
return '0'
}
let s = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB']
let e = Math.floor(Math.log(bytes) / Math.log(1024))
let r = bytes / Math.pow(1024, Math.floor(e))
const s = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB']
const e = Math.floor(Math.log(bytes) / Math.log(1024))
const r = bytes / Math.pow(1024, Math.floor(e))
return ((r + '').indexOf('.') !== -1 ? r.toFixed(2) : r) + ' ' + s[e]
}

Expand Down
22 changes: 11 additions & 11 deletions src/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ export default {
},
methods: {
randomIcon() {
let size = this.foodIcon.length
const size = this.foodIcon.length
this.downloadIcon = 'el-icon-' + this.foodIcon[Math.floor(Math.random() * size)]
this.uploadIcon = 'el-icon-' + this.foodIcon[Math.floor(Math.random() * size)]
this.totalIcon = 'el-icon-' + this.foodIcon[Math.floor(Math.random() * size)]
},
setOffset() {
let clientWith = document.body.clientWidth
const clientWith = document.body.clientWidth
if (clientWith < 1000) {
this.keyOffset = 1
this.valueOffset = 2
Expand All @@ -222,7 +222,7 @@ export default {
},
getServerInfo() {
serverInfo().then((res) => {
let data = res.Data
const data = res.Data
this.cpu.percentage = parseFloat(data.cpu[0].toFixed(2))
this.cpu.color = this.computeColor(this.cpu.percentage)
this.memory = this.computePercent(data.memory)
Expand All @@ -232,7 +232,7 @@ export default {
})
},
computePercent(data) {
let percent = parseFloat(data.usedPercent.toFixed(2))
const percent = parseFloat(data.usedPercent.toFixed(2))
return {
percentage: percent,
used: readablizeBytes(data.used),
Expand All @@ -250,9 +250,9 @@ export default {
}
},
async getUserList() {
let result = await userList()
const result = await userList()
if (result.Msg === 'success') {
let data = result.Data
const data = result.Data
this.userList = data.userList
let download = 0; let upload = 0
for (let i = 0; i < this.userList.length; i++) {
Expand All @@ -267,22 +267,22 @@ export default {
}
},
async getVersion() {
let result = await version()
let data = result.Data
const result = await version()
const data = result.Data
this.trojanVersion = data.trojanVersion
this.trojanRuntime = this.parseRuntime(data.trojanRuntime)
},
parseRuntime(runtime) {
let result = ''
if (runtime.indexOf('-') !== -1) {
let splitInfo = runtime.split('-')
const splitInfo = runtime.split('-')
result += splitInfo[0] + ''
let timeInfo = splitInfo[1].split(':')
const timeInfo = splitInfo[1].split(':')
result += timeInfo[0] + ''
result += timeInfo[1] + ''
result += timeInfo[2] + ''
} else {
let splitInfo = runtime.split(':')
const splitInfo = runtime.split(':')
if (splitInfo.length === 3) {
result += splitInfo[0] + ''
result += splitInfo[1] + ''
Expand Down
12 changes: 6 additions & 6 deletions src/views/layout/component/main-content/top-aside.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default {
},
methods: {
setDialogWidth() {
let clientWith = document.body.clientWidth
const clientWith = document.body.clientWidth
if (clientWith < 600) {
this.dialogWidth = '80%'
} else if (clientWith >= 600 && clientWith < 1000) {
Expand All @@ -124,13 +124,13 @@ export default {
this.$store.commit('SET_WIDTH', this.dialogWidth)
},
async getTitle() {
let result = await check()
const result = await check()
this.title = result.data.title
},
async handleLoginInfo() {
let formData = new FormData()
const formData = new FormData()
formData.set('title', this.title)
let result = await setLoginInfo(formData)
const result = await setLoginInfo(formData)
if (result.Msg === 'success') {
this.$message({
message: '修复登录页标题成功!',
Expand All @@ -145,11 +145,11 @@ export default {
this.loginVisible = false
},
async systemVersion() {
let result = await version()
const result = await version()
this.versionList = result.Data
},
async changePass() {
let formData = new FormData()
const formData = new FormData()
if (this.form.password1 !== this.form.password2) {
this.$message.error('两次输入不一致!')
return
Expand Down
4 changes: 2 additions & 2 deletions src/views/login/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export default {
return
}
this.loginForm.password = CryptoJS.SHA224(this.loginForm.password).toString()
let data = await login(this.loginForm)
let token = data.token
const data = await login(this.loginForm)
const token = data.token
let isAdmin = false
if (this.loginForm.username === 'admin') {
isAdmin = true
Expand Down
2 changes: 1 addition & 1 deletion src/views/login/register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default {
},
methods: {
async register() {
let formData = new FormData()
const formData = new FormData()
if (this.form.password1 !== this.form.password2) {
this.$message.error('两次输入不一致!')
return
Expand Down
20 changes: 10 additions & 10 deletions src/views/trojan/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export default {
methods: {
async setLoglevel() {
try {
let formData = new FormData()
const formData = new FormData()
formData.set('level', this.loglevel)
let result = await setLoglevel(formData)
const result = await setLoglevel(formData)
if (result.Msg === 'success') {
this.$message({
message: '设置日志等级成功!',
Expand All @@ -159,7 +159,7 @@ export default {
}
},
async getLoglevel() {
let result = await getLoglevel()
const result = await getLoglevel()
if (result.Msg === 'success') {
this.loglevel = result.Data.loglevel
} else {
Expand All @@ -168,7 +168,7 @@ export default {
},
async start() {
try {
let result = await start()
const result = await start()
if (result.Msg === 'success') {
this.$message({
message: '启动trojan成功!',
Expand All @@ -180,7 +180,7 @@ export default {
}
},
async stop() {
let result = await stop()
const result = await stop()
if (result.Msg === 'success') {
this.$message({
message: '停止trojan成功!',
Expand All @@ -190,7 +190,7 @@ export default {
},
async restart() {
try {
let result = await restart()
const result = await restart()
if (result.Msg === 'success') {
this.$message({
message: '重启trojan成功!',
Expand All @@ -203,7 +203,7 @@ export default {
},
async update() {
try {
let result = await update()
const result = await update()
if (result.Msg === 'success') {
this.$message({
message: '更新trojan成功!',
Expand All @@ -216,7 +216,7 @@ export default {
},
getLog() {
this.isFollow = true
let self = this
const self = this
if (this.ws != null) {
this.ws.close()
clearInterval(this.timer)
Expand All @@ -225,8 +225,8 @@ export default {
}
const textarea = document.getElementById('logshow')
textarea.innerText = ''
let prefix = process.env.NODE_ENV === 'production' ? '/' : '/ws'
let protocol = document.location.protocol === 'http:' ? 'ws' : 'wss'
const prefix = process.env.NODE_ENV === 'production' ? '/' : '/ws'
const protocol = document.location.protocol === 'http:' ? 'ws' : 'wss'
this.ws = new WebSocket(`${protocol}://${location.host}${prefix}/trojan/log?line=${this.line}&token=${store.state.UserToken}`)
this.ws.onopen = function () {
console.log('ws connected!')
Expand Down
14 changes: 7 additions & 7 deletions src/views/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ export default {
} else if (this.quotaUnit === 'GB') {
this.quota = this.quota * 1024 * 1024 * 1024
}
let formData = new FormData()
const formData = new FormData()
formData.set('id', this.userItem.ID)
formData.set('quota', this.quota)
let result = await setQuota(formData)
const result = await setQuota(formData)
if (result.Msg === 'success') {
this.$message({
message: `设置用户${this.userItem.Username}流量限制成功!`,
Expand Down Expand Up @@ -326,11 +326,11 @@ export default {
this.$message.error('不能创建用户名为admin的用户!')
return
}
let formData = new FormData()
const formData = new FormData()
formData.set('id', this.userItem.ID)
formData.set('username', this.userInfo.username)
formData.set('password', btoa(this.userInfo.password))
let result = await updateUser(formData)
const result = await updateUser(formData)
if (result.Msg === 'success') {
this.$message({
message: `修改用户${this.userInfo.username}成功!`,
Expand All @@ -353,10 +353,10 @@ export default {
this.$message.error('不能创建用户名为admin的用户!')
return
}
let formData = new FormData()
const formData = new FormData()
formData.set('username', this.userInfo.username)
formData.set('password', btoa(this.userInfo.password))
let result = await addUser(formData)
const result = await addUser(formData)
if (result.Msg === 'success') {
this.$message({
message: `新增用户${this.userInfo.username}成功!`,
Expand All @@ -376,7 +376,7 @@ export default {
this.getUserList()
},
async getUserList() {
let result = await userList()
const result = await userList()
if (result.Msg === 'success') {
this.dataList = result.Data.userList
if (result.Data.domain !== '') {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
env: {
jest: true
}
env: {
jest: true
}
}
12 changes: 6 additions & 6 deletions tests/unit/example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'

describe('HelloWorld.vue', () => {
it('renders props.msg when passed', () => {
const msg = 'new message'
const wrapper = shallowMount(HelloWorld, {
propsData: { msg }
it('renders props.msg when passed', () => {
const msg = 'new message'
const wrapper = shallowMount(HelloWorld, {
propsData: { msg }
})
expect(wrapper.text()).toMatch(msg)
})
expect(wrapper.text()).toMatch(msg)
})
})
16 changes: 8 additions & 8 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const proxyTargetMap = {
prod: 'https://xxx.xxx.com/',
dev: 'http://67.218.149.57'
}
let proxyTarget = proxyTargetMap[process.env.API_TYPE] || proxyTargetMap.prod
let wsTarget = proxyTarget.replace('http', 'ws')
let publicPath = process.env.NODE_ENV === 'production' ? '/' : '/'
let dllPublishPath = publicPath === '/' ? '/vendor' : publicPath + '/vendor'
const proxyTarget = proxyTargetMap[process.env.API_TYPE] || proxyTargetMap.prod
const wsTarget = proxyTarget.replace('http', 'ws')
const publicPath = process.env.NODE_ENV === 'production' ? '/' : '/'
const dllPublishPath = publicPath === '/' ? '/vendor' : publicPath + '/vendor'
module.exports = {
publicPath: publicPath,
outputDir: 'dist',
Expand Down Expand Up @@ -51,10 +51,10 @@ module.exports = {
config.plugins.delete('prefetch')
// 用cdn方式引入
config.externals({
'vue': 'Vue',
'vuex': 'Vuex',
vue: 'Vue',
vuex: 'Vuex',
'vue-router': 'VueRouter',
'axios': 'axios',
axios: 'axios',
'element-ui': 'ELEMENT'
})
// 添加新的svg-sprite-loader处理svgIcon
Expand Down Expand Up @@ -158,7 +158,7 @@ module.exports = {
publicPath: dllPublishPath,
// dll最终输出的目录
outputPath: './vendor'
}),
})
// 开启压缩
// new CompressionWebpackPlugin({
// filename: '[path].gz[query]',
Expand Down

0 comments on commit 3dc410c

Please sign in to comment.