代码优化

This commit is contained in:
Elune
2019-12-18 13:24:39 +08:00
parent 47d83846ef
commit b3528e88d0
15 changed files with 91 additions and 113 deletions

View File

@@ -1,8 +1,9 @@
import request from '@/utils/request'
export function del(key) {
export function del(keys) {
return request({
url: 'auth/online/' + key,
method: 'delete'
url: 'auth/online',
method: 'delete',
data: keys
})
}

View File

@@ -8,10 +8,11 @@ export function add(data) {
})
}
export function del(id) {
export function del(ids) {
return request({
url: 'api/server/' + id,
method: 'delete'
url: 'api/server',
method: 'delete',
data: ids
})
}

View File

@@ -16,10 +16,11 @@ export function add(data) {
})
}
export function del(id) {
export function del(ids) {
return request({
url: 'api/dept/' + id,
method: 'delete'
url: 'api/dept',
method: 'delete',
data: ids
})
}
@@ -31,12 +32,4 @@ export function edit(data) {
})
}
export function delAll(ids) {
return request({
url: 'api/dept/',
method: 'delete',
data: ids
})
}
export default { add, edit, del, getDepts, delAll }
export default { add, edit, del, getDepts }

View File

@@ -21,10 +21,11 @@ export function add(data) {
})
}
export function del(id) {
export function del(ids) {
return request({
url: 'api/job/' + id,
method: 'delete'
url: 'api/job',
method: 'delete',
data: ids
})
}
@@ -36,12 +37,4 @@ export function edit(data) {
})
}
export function delAll(ids) {
return request({
url: 'api/job/',
method: 'delete',
data: ids
})
}
export default { add, edit, del, delAll }
export default { add, edit, del }

View File

@@ -22,10 +22,11 @@ export function add(data) {
})
}
export function del(id) {
export function del(ids) {
return request({
url: 'api/menus/' + id,
method: 'delete'
url: 'api/menus',
method: 'delete',
data: ids
})
}
@@ -37,12 +38,4 @@ export function edit(data) {
})
}
export function delAll(ids) {
return request({
url: 'api/menus/',
method: 'delete',
data: ids
})
}
export default { add, edit, del, getMenusTree, delAll }
export default { add, edit, del, getMenusTree }

View File

@@ -30,10 +30,11 @@ export function getLevel() {
})
}
export function del(id) {
export function del(ids) {
return request({
url: 'api/roles/' + id,
method: 'delete'
url: 'api/roles',
method: 'delete',
data: ids
})
}
@@ -53,12 +54,4 @@ export function editMenu(data) {
})
}
export function delAll(ids) {
return request({
url: 'api/roles/',
method: 'delete',
data: ids
})
}
export default { add, edit, del, get, editMenu, delAll }
export default { add, edit, del, get, editMenu }

View File

@@ -9,10 +9,11 @@ export function add(data) {
})
}
export function del(id) {
export function del(ids) {
return request({
url: 'api/users/' + id,
method: 'delete'
url: 'api/users',
method: 'delete',
data: ids
})
}
@@ -56,13 +57,5 @@ export function updateEmail(form) {
})
}
export function delAll(ids) {
return request({
url: 'api/users/',
method: 'delete',
data: ids
})
}
export default { add, edit, del, delAll }
export default { add, edit, del }

View File

@@ -126,11 +126,7 @@ export default {
type: 'warning'
}).then(() => {
this.crud.delAllLoading = true
if (datas.length === 1) {
this.crud.doDelete(datas[0])
} else {
this.crud.doDeletes(datas)
}
this.crud.doDelete(datas)
}).catch(() => {
})
},

View File

@@ -264,8 +264,8 @@ function CRUD(options) {
crud.crudMethod.edit(crud.form).then(() => {
crud.status.edit = CRUD.STATUS.NORMAL
crud.getDataStatus(crud.form.id).edit = CRUD.STATUS.NORMAL
crud.resetForm()
crud.editSuccessNotify()
crud.resetForm()
callVmHook(crud, CRUD.HOOK.afterSubmit)
crud.refresh()
}).catch(() => {
@@ -277,44 +277,36 @@ function CRUD(options) {
* @param {*} data 数据项
*/
doDelete(data) {
const dataStatus = crud.getDataStatus(data.id)
if (!callVmHook(crud, CRUD.HOOK.beforeDelete, data)) {
return
}
dataStatus.delete = CRUD.STATUS.PROCESSING
return crud.crudMethod.del(data.id).then(() => {
dataStatus.delete = CRUD.STATUS.NORMAL
crud.dleChangePage(1)
crud.delSuccessNotify()
callVmHook(crud, CRUD.HOOK.afterDelete, data)
crud.refresh()
crud.delAllLoading = false
}).catch(() => {
crud.delAllLoading = false
dataStatus.delete = CRUD.STATUS.PREPARED
})
},
/**
* 删除多条记录
* @param datas
* @returns {Promise<T>}
*/
doDeletes(datas) {
let delAll = false
let dataStatus
const ids = []
datas.forEach(val => {
ids.push(val.id)
})
if (data instanceof Array) {
delAll = true
data.forEach(val => {
ids.push(val.id)
})
} else {
ids.push(data.id)
dataStatus = crud.getDataStatus(data.id)
}
if (!callVmHook(crud, CRUD.HOOK.beforeDelete, data)) {
return
}
return crud.crudMethod.delAll(ids).then(() => {
if (!delAll) {
dataStatus.delete = CRUD.STATUS.PROCESSING
}
return crud.crudMethod.del(ids).then(() => {
if (delAll) {
crud.delAllLoading = false
} else dataStatus.delete = CRUD.STATUS.PREPARED
crud.dleChangePage(1)
crud.delSuccessNotify()
callVmHook(crud, CRUD.HOOK.afterDelete, data)
crud.delAllLoading = false
crud.refresh()
}).catch(() => {
crud.delAllLoading = false
if (delAll) {
crud.delAllLoading = false
} else dataStatus.delete = CRUD.STATUS.PREPARED
})
},
/**

View File

@@ -19,7 +19,7 @@
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
</el-input>
<div class="login-code">
<img :src="codeUrl" alt="验证码" @click="getCode">
<img :src="codeUrl" alt="加载失败" @click="getCode">
</div>
</el-form-item>
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">

View File

@@ -12,9 +12,9 @@
type="danger"
icon="el-icon-delete"
size="mini"
:loading="crud.delAllLoading"
:loading="delLoading"
:disabled="crud.selections.length === 0"
@click="crud.toDelete(crud.selections)"
@click="doDelete(crud.selections)"
>
强退
</el-button>
@@ -91,18 +91,37 @@ export default {
this.url = 'auth/online'
return true
},
doDelete(datas) {
this.$confirm(`确认强退选中的${datas.length}个用户?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.delMethod(datas)
}).catch(() => {})
},
// 踢出用户
delMethod(key, index) {
const ids = []
if (key instanceof Array) {
key.forEach(val => {
ids.push(val.key)
})
} else ids.push(key)
this.delLoading = true
del(key).then(() => {
del(ids).then(() => {
this.delLoading = false
this.$refs[index].doClose()
if (this.$refs[index]) {
this.$refs[index].doClose()
}
this.crud.dleChangePage(1)
this.crud.delSuccessNotify()
this.crud.toQuery()
}).catch(() => {
this.delLoading = false
this.$refs[index].doClose()
if (this.$refs[index]) {
this.$refs[index].doClose()
}
})
}
}

View File

@@ -109,7 +109,7 @@ import pagination from '@crud/Pagination'
// crud交由presenter持有
const defaultCrud = CRUD({ title: '监控', url: 'api/server', sort: 'sort,asc', crudMethod: { ...crudServer }})
const defaultForm = { id: null, name: null, ip: null, port: 8777, state: null, cpuRate: null, cpuCore: null, memTotal: null, memUsed: null, diskTotal: null, diskUsed: null, swapTotal: null, swapUsed: null, sort: 999 }
const defaultForm = { id: null, address: 'localhost', name: null, ip: null, port: 8777, state: null, cpuRate: null, cpuCore: null, memTotal: null, memUsed: null, diskTotal: null, diskUsed: null, swapTotal: null, swapUsed: null, sort: 999 }
export default {
name: 'ServerMonitor',
components: { pagination, crudOperation, rrOperation, udOperation },
@@ -134,6 +134,9 @@ export default {
}
}
},
created() {
this.crud.optShow.download = false
},
methods: {
formatCpuRate(row, column) {
const value = row.cpuRate

View File

@@ -43,7 +43,7 @@
</el-dialog>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :tree-props="{children: 'children', hasChildren: 'hasChildren'}" default-expand-all :data="crud.data" row-key="id" @select="crud.selectChange" @select-all="crud.selectAllChange" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" />
<el-table-column :selectable="checkboxT" type="selection" width="55" />
<el-table-column v-if="columns.visible('name')" label="名称" prop="name" />
<el-table-column v-if="columns.visible('enabled')" label="状态" align="center" prop="enabled">
<template slot-scope="scope">
@@ -148,6 +148,9 @@ export default {
}).catch(() => {
data.enabled = !data.enabled
})
},
checkboxT(row, rowIndex) {
return row.id !== 1
}
}
}

View File

@@ -95,7 +95,7 @@ const defaultForm = {
sort: 999,
enabled: true,
dept: {
id: null
id: 1
}
}
export default {

View File

@@ -134,7 +134,7 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css'
// crud交由presenter持有
const defaultCrud = CRUD({ title: '角色', url: 'api/roles', sort: 'level,asc', crudMethod: { ...crudRoles }})
const defaultForm = { name: null, depts: [], remark: null, dataScope: null, level: 3, permission: null }
const defaultForm = { name: null, depts: [], remark: null, dataScope: '全部', level: 3, permission: null }
export default {
name: 'Role',
components: { Treeselect, pagination, crudOperation, rrOperation, udOperation },
@@ -172,7 +172,6 @@ export default {
},
// 编辑前
[CRUD.HOOK.beforeToEdit](crud, form) {
console.log(form.dataScope)
if (form.dataScope === '自定义') {
this.getDepts()
}
@@ -181,7 +180,6 @@ export default {
depts.push(dept.id)
})
form.depts = depts
console.log(form)
},
// 提交前做的操作
[CRUD.HOOK.afterValidateCU](crud) {