[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 <div
:is="col.formatter" :is="col.formatter"
:key="row.id" :key="row.id"
:setting="data" :table-data="data"
:row="row" :row="row"
:reload="getList"
:col="col" :col="col"
:cell-value="row[col.prop]" :cell-value="row[col.prop]"
> >

View File

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

View File

@ -3,32 +3,70 @@
</template> </template>
<script> <script>
import ActionsGroup from '@/components/ActionsGroup' import ActionsGroup from '@/components/ActionsGroup/index'
import BaseFormatter from './base' 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 { export default {
name: 'ActionsFormatter', name: 'ActionsFormatter',
components: { ActionsGroup }, components: { ActionsGroup },
extends: BaseFormatter, extends: BaseFormatter,
data() { data() {
const colActions = this.col.actions || {}
const defaultActions = [ const defaultActions = [
{ {
name: 'update', name: 'update',
title: this.$tc('Update'), title: this.$tc('Update'),
type: 'primary', type: 'primary',
has: this.col.actions.hasUpdate || true, has: colActions.hasUpdate || true,
can: this.col.actions.canUpdate || true, can: colActions.canUpdate || true,
callback: this.col.actions.onUpdate callback: colActions.onUpdate || defaultUpdateCallback.bind(this)
}, },
{ {
name: 'delete', name: 'delete',
title: this.$tc('Delete'), title: this.$tc('Delete'),
type: 'danger', type: 'danger',
has: this.col.actions.hasDelete || true, has: colActions.hasDelete || true,
can: this.col.actions.canDelete || true, can: colActions.canDelete || true,
callback: this.col.actions.onDelete callback: colActions.onDelete || defaultDeleteCallback.bind(this)
} }
] ]
const extraActions = this.col.actions.extraActions || [] const extraActions = colActions.extraActions || []
return { return {
defaultActions: defaultActions, defaultActions: defaultActions,
extraActions: extraActions extraActions: extraActions
@ -70,8 +108,14 @@ export default {
handleActionClick(item) { handleActionClick(item) {
const action = this.namedValidActions[item] const action = this.namedValidActions[item]
if (action && action.callback) { if (action && action.callback) {
console.log(this.setting) const attrs = {
action.callback(this.row, this.col, this.cellValue) reload: this.reload,
row: this.row,
col: this.col,
cellValue: this.cellValue,
tableData: this.tableData
}
action.callback(attrs)
} }
}, },
checkItem(item, attr) { checkItem(item, attr) {

View File

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

View File

@ -2,7 +2,7 @@
<div> <div>
<TableAction v-bind="headerActions" @clickAction="handleActionClick"></TableAction> <TableAction v-bind="headerActions" @clickAction="handleActionClick"></TableAction>
<el-card class="table-content" shadow="never"> <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"> <template v-slot:actions="row">
{{ row.id }} {{ row.id }}
</template> </template>
@ -39,29 +39,13 @@ export default {
} }
}, },
computed: { 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: { methods: {
handleSelectionChange(val) { handleSelectionChange(val) {
this.selectRows = val this.selectRows = val
this.multipleSelection = val; this.multipleSelection = val;
(val.length > 0) ? (this.selectDisable = false) : (this.selectDisable = true) (val.length > 0) ? (this.selectDisable = false) : (this.selectDisable = true)
console.log(this.$refs.table)
}, },
handleActionClick(item) { handleActionClick(item) {
const handler = this.getActionHandler(item) const handler = this.getActionHandler(item)

View File

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

View File

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

View File

@ -4,21 +4,18 @@
<script> <script>
import { GenericListPage } from '@/layout/components' import { GenericListPage } from '@/layout/components'
import { DetailFormatter, ActionsFormatter } from '@/components/DataTable/formatters/index' import { DetailFormatter, ActionsFormatter } from '@/components/ListTable/formatters/index'
export default { export default {
components: { components: {
GenericListPage GenericListPage
}, },
data() { data() {
const data = []
return { return {
tableConfig: { tableConfig: {
url: '/api/v1/users/groups/', url: '/api/v1/users/groups/',
columns: [ columns: [
{
label: 'ID',
type: 'index'
},
{ {
prop: 'name', prop: 'name',
label: this.$tc('Name'), label: this.$tc('Name'),
@ -29,7 +26,7 @@ export default {
{ {
prop: 'users_amount', prop: 'users_amount',
label: this.$t('users.User'), label: this.$t('users.User'),
key: 'users_amount', key: 'users_amount'
}, },
{ {
prop: 'comment', prop: 'comment',
@ -38,52 +35,13 @@ export default {
}, },
{ {
prop: 'id', prop: 'id',
label: this.$tc('Action'), label: this.$tc('Actions'),
align: 'center', align: 'center',
formatter: ActionsFormatter, formatter: ActionsFormatter,
actions: { width: '200px'
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: []
}
} }
], ],
// table // table
tableActions: {
editRoute: '404'
}
}, },
headerActions: { headerActions: {
createRoute: 'UserGroupCreate' createRoute: 'UserGroupCreate'

View File

@ -4,7 +4,7 @@
<script> <script>
import { GenericListPage } from '@/layout/components' 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 { export default {
components: { components: {