[Update] 修改详情页

This commit is contained in:
ibuler
2020-04-21 13:29:27 +08:00
parent e02f7485b7
commit 668ac84e8a
5 changed files with 51 additions and 14 deletions

View File

@@ -10,7 +10,6 @@ import FormGroupHeader from '@/components/formGroupHeader'
import { optionUrlMeta } from '@/api/common'
import rules from '@/components/DataForm/rules'
import Select2 from '@/components/Select2'
import _ from 'lodash'
export default {
name: 'AutoDataForm',
components: {
@@ -79,6 +78,7 @@ export default {
type = 'input'
if (!fieldMeta.max_length) {
field.el.type = 'textarea'
field.el.rows = 3
}
break
default:

View File

@@ -26,6 +26,7 @@
<script>
import Page from '../Page/'
import { getApiPath } from '@/utils/common'
import ActionsGroup from '@/components/ActionsGroup'
export default {
name: 'GenericDetailPage',
@@ -60,9 +61,17 @@ export default {
return this.defaultDelete(item)
}
},
deleteRoute: {
deleteUrl: {
type: String,
default: null
default: function() {
return getApiPath(this)
}
},
deleteSuccessRoute: {
type: String,
default: function() {
return this.$route.name.replace('Detail', 'List')
}
},
canUpdate: {
type: [Boolean, Function],
@@ -76,7 +85,9 @@ export default {
},
updateRoute: {
type: String,
default: null
default: function() {
return this.$route.name.replace('Detail', 'Update')
}
}
},
data() {
@@ -100,13 +111,39 @@ export default {
},
methods: {
defaultDelete() {
const msg = this.$tc('Are you sure to delete') + ' ?'
const title = this.$tc('Info')
const performDelete = async function() {
this.$log.debug('Start perform delete: ', this.deleteUrl)
return this.$axios.delete(this.deleteUrl)
}
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.bind(this)()
done()
this.$message.success(this.$tc('Delete success'))
this.$router.push({ name: this.deleteSuccessRoute })
} catch (error) {
this.$message.error(this.$tc('Delete failed' + ' ' + error))
} finally {
instance.confirmButtonLoading = false
}
}
}).catch(() => {
/* 取消*/
})
},
defaultUpdate() {
const id = this.$route.params.id
const defaultUpdateRoute = this.$route.name.replace('Detail', 'Update')
const routeName = this.updateRoute || defaultUpdateRoute
this.$router.push({ name: routeName, params: { id: id }})
this.$router.push({ name: this.updateRoute, params: { id: id }})
},
getObject() {
}
}
}

View File

@@ -76,3 +76,8 @@ export function toSafeLocalDateStr(d) {
const date_s = date.toLocaleString(getUserLang(), { hourCycle: 'h23' })
return date_s.split('/').join('-')
}
export function getApiPath(that) {
const pagePath = that.$route.path
return `/api/v1${pagePath}/`
}

View File

@@ -12,11 +12,6 @@ export default {
return {
config: {
initial: {
password_strategy: 0,
mfa_level: 0,
source: 'local',
role: 'Admin',
date_expired: '2099-12-31 00:00:00 +0800'
},
url: '/api/v1/users/groups/',
fields: ['name', 'users', 'comment'],

View File

@@ -51,7 +51,7 @@ export default {
name: 'assetPermissions'
}
],
canDelete: this.canDelete,
canDelete: true,
canUpdate: true
},
groupMembers: [],