[Update] 修改默认动作等

This commit is contained in:
ibuler 2020-04-03 15:36:52 +08:00
parent 8bc3bd6ebb
commit 8a40a5c0ff
13 changed files with 77 additions and 86 deletions

View File

@ -102,8 +102,9 @@
<div
:is="col.formatter"
:key="row.id"
:setting="data"
:table-data="data"
:row="row"
:reload="getList"
:col="col"
:cell-value="row[col.prop]"
>

View File

@ -36,16 +36,12 @@ export default {
hasDelete: userTableActions.hasDelete !== false,
hasNew: false,
// editText: this.$t('action.update'), //
operationAttrs: {
align: 'center',
width: '150px'
},
operationButtonType: 'button',
buttonSize: 'mini',
tableAttrs: {
stripe: true, //
border: true, //
fit: true //
fit: true, // ,
tooltipEffect: 'dark'
},
extraButtons: userTableActions.extraButtons,
onEdit: (row) => {

View File

@ -3,32 +3,70 @@
</template>
<script>
import ActionsGroup from '@/components/ActionsGroup'
import ActionsGroup from '@/components/ActionsGroup/index'
import BaseFormatter from './base'
const defaultPerformDelete = function({row, col}) {
const id = row.id
const url = `/api/v1/users/groups/${id}/`
return this.$axios.delete(url)
}
const defaultUpdateCallback = ({row, col, cellValue, reload}) => {
}
const defaultDeleteCallback = function({row, col, cellValue, reload}) {
const msg = this.$tc('Are you sure to delete') + ' "' + row.name + '"'
const title = this.$tc('Info')
const performDelete = col.actions.performDelete || defaultPerformDelete.bind(this)
this.$alert(msg, title, {
type: 'warning',
confirmButtonClass: 'el-button--danger',
showCancelButton: true,
beforeClose: async(action, instance, done) => {
if (action !== 'confirm') return done()
instance.confirmButtonLoading = true
try {
await performDelete({row: row, col: col})
done()
reload()
this.$message.success(this.$tc('Delete success'))
} catch (error) {
this.$message.error(this.$tc('Delete failed'))
console.warn(error)
} finally {
instance.confirmButtonLoading = false
}
}
}).catch(() => {
/* 取消*/
})
}
export default {
name: 'ActionsFormatter',
components: { ActionsGroup },
extends: BaseFormatter,
data() {
const colActions = this.col.actions || {}
const defaultActions = [
{
name: 'update',
title: this.$tc('Update'),
type: 'primary',
has: this.col.actions.hasUpdate || true,
can: this.col.actions.canUpdate || true,
callback: this.col.actions.onUpdate
has: colActions.hasUpdate || true,
can: colActions.canUpdate || true,
callback: colActions.onUpdate || defaultUpdateCallback.bind(this)
},
{
name: 'delete',
title: this.$tc('Delete'),
type: 'danger',
has: this.col.actions.hasDelete || true,
can: this.col.actions.canDelete || true,
callback: this.col.actions.onDelete
has: colActions.hasDelete || true,
can: colActions.canDelete || true,
callback: colActions.onDelete || defaultDeleteCallback.bind(this)
}
]
const extraActions = this.col.actions.extraActions || []
const extraActions = colActions.extraActions || []
return {
defaultActions: defaultActions,
extraActions: extraActions
@ -70,8 +108,14 @@ export default {
handleActionClick(item) {
const action = this.namedValidActions[item]
if (action && action.callback) {
console.log(this.setting)
action.callback(this.row, this.col, this.cellValue)
const attrs = {
reload: this.reload,
row: this.row,
col: this.col,
cellValue: this.cellValue,
tableData: this.tableData
}
action.callback(attrs)
}
},
checkItem(item, attr) {

View File

@ -5,6 +5,10 @@
export default {
name: 'BaseFormatter',
props: {
reload: {
type: Function,
default: ({reloading}) => ({})
},
row: {
type: Object,
default: () => ({})
@ -17,7 +21,7 @@ export default {
type: [String, Boolean, Number, Object],
default: null
},
setting: {
tableData: {
type: Array,
default: () => ({})
}

View File

@ -2,7 +2,7 @@
<div>
<TableAction v-bind="headerActions" @clickAction="handleActionClick"></TableAction>
<el-card class="table-content" shadow="never">
<DataTable :config="tableConfig" @selection-change="handleSelectionChange">
<DataTable ref="table" :config="tableConfig" @selection-change="handleSelectionChange">
<template v-slot:actions="row">
{{ row.id }}
</template>
@ -39,29 +39,13 @@ export default {
}
},
computed: {
actionColumn() {
const actions = []
let tc = this.tableConfig
if (tc.hasEdit !== false) {
actions.push({
name: 'update',
title: this.$tc('Update')
})
}
if (tc.hasDelete !== false) {
actions.push({
name: 'delete',
title: this.$tc('Delete')
})
}
}
},
methods: {
handleSelectionChange(val) {
this.selectRows = val
this.multipleSelection = val;
(val.length > 0) ? (this.selectDisable = false) : (this.selectDisable = true)
console.log(this.$refs.table)
},
handleActionClick(item) {
const handler = this.getActionHandler(item)

View File

@ -144,7 +144,6 @@ export default {
}
data.results.forEach((v) => {
this.options.push(v)
console.log(v)
})
}).catch(err => {
console.log(err)

View File

@ -39,7 +39,12 @@ const cn = {
'Update selected': '更新所选',
'Search': '搜索',
'Source': '来源',
'Status': '状态'
'Status': '状态',
'Actions': '动作',
'Monitor': '监控',
'Run': '执行',
'Are you sure to delete': '你确定要删除',
'Info': '提示'
},
route: {
'dashboard': '仪表盘',

View File

@ -4,21 +4,18 @@
<script>
import { GenericListPage } from '@/layout/components'
import { DetailFormatter, ActionsFormatter } from '@/components/DataTable/formatters/index'
import { DetailFormatter, ActionsFormatter } from '@/components/ListTable/formatters/index'
export default {
components: {
GenericListPage
},
data() {
const data = []
return {
tableConfig: {
url: '/api/v1/users/groups/',
columns: [
{
label: 'ID',
type: 'index'
},
{
prop: 'name',
label: this.$tc('Name'),
@ -29,7 +26,7 @@ export default {
{
prop: 'users_amount',
label: this.$t('users.User'),
key: 'users_amount',
key: 'users_amount'
},
{
prop: 'comment',
@ -38,52 +35,13 @@ export default {
},
{
prop: 'id',
label: this.$tc('Action'),
label: this.$tc('Actions'),
align: 'center',
formatter: ActionsFormatter,
actions: {
hasUpdate: (row, cellValue) => {
return true
},
canUpdate: (row, cellValue) => {
console.log('On table update')
return true
},
hasDelete: true,
canDelete: (row, cellValue) => {
return true
},
onDelete: (row, cellValue) => {
this.$confirm('你好啊', '提示', {
type: 'warning',
confirmButtonClass: 'el-button--danger',
beforeClose: async(action, instance, done) => {
}
}).catch(() => {
/* 取消*/
})
},
extraActions: [
{
name: 'run',
title: this.$tc('Run'),
callback: (row, cellValue) => {
console.log('On run')
}
},
{
name: 'monitor',
title: this.$tc('Monitor')
}
],
order: []
}
width: '200px'
}
],
// table
tableActions: {
editRoute: '404'
}
},
headerActions: {
createRoute: 'UserGroupCreate'

View File

@ -4,7 +4,7 @@
<script>
import { GenericListPage } from '@/layout/components'
import { DetailFormatter, DisplayFormatter, ChoicesFormatter } from '@/components/DataTable/formatters/index'
import { DetailFormatter, DisplayFormatter, ChoicesFormatter } from '@/components/ListTable/formatters/index'
export default {
components: {