mirror of
https://github.com/jumpserver/lina.git
synced 2025-06-26 23:17:05 +00:00
perf: 封装SwitchFormatter组件
This commit is contained in:
parent
e6721a9905
commit
815247f5b5
64
src/components/Table/TableFormatters/SwitchFormatter.vue
Normal file
64
src/components/Table/TableFormatters/SwitchFormatter.vue
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="display">
|
||||||
|
<el-switch v-model="value" @change="onChange" />
|
||||||
|
</div>
|
||||||
|
<span v-else>-</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import BaseFormatter from './base.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'SwitchFormatter',
|
||||||
|
extends: BaseFormatter,
|
||||||
|
props: {
|
||||||
|
formatterArgsDefault: {
|
||||||
|
type: Object,
|
||||||
|
default() {
|
||||||
|
return {
|
||||||
|
getPatchUrl(row) {
|
||||||
|
return ''
|
||||||
|
},
|
||||||
|
getPatchData(row) {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
isDisplay(row) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs),
|
||||||
|
value: this.cellValue
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
patchUrl() {
|
||||||
|
return this.formatterArgs.getPatchUrl(this.row)
|
||||||
|
},
|
||||||
|
patchData() {
|
||||||
|
return this.formatterArgs.getPatchData(this.row)
|
||||||
|
},
|
||||||
|
display(row) {
|
||||||
|
return this.formatterArgs.isDisplay(this.row)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onChange(val) {
|
||||||
|
this.$axios.patch(this.patchUrl, this.patchData).then(res => {
|
||||||
|
this.$message.success(this.$t('common.updateSuccessMsg'))
|
||||||
|
}).catch(err => {
|
||||||
|
this.value = !val
|
||||||
|
this.$message.error(this.$t('common.updateErrorMsg' + ' ' + err))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -16,6 +16,7 @@ import ObjectRelatedFormatter from './ObjectRelatedFormatter.vue'
|
|||||||
import TwoTabFormatter from './TwoTabFormatter.vue'
|
import TwoTabFormatter from './TwoTabFormatter.vue'
|
||||||
import ProtocolsFormatter from './ProtocolsFormatter.vue'
|
import ProtocolsFormatter from './ProtocolsFormatter.vue'
|
||||||
import TagChoicesFormatter from './TagChoicesFormatter.vue'
|
import TagChoicesFormatter from './TagChoicesFormatter.vue'
|
||||||
|
import SwitchFormatter from './SwitchFormatter.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
DetailFormatter,
|
DetailFormatter,
|
||||||
@ -35,7 +36,8 @@ export default {
|
|||||||
TwoTabFormatter,
|
TwoTabFormatter,
|
||||||
ProtocolsFormatter,
|
ProtocolsFormatter,
|
||||||
TagChoicesFormatter,
|
TagChoicesFormatter,
|
||||||
LabelsFormatter
|
LabelsFormatter,
|
||||||
|
SwitchFormatter
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -56,5 +58,6 @@ export {
|
|||||||
TwoTabFormatter,
|
TwoTabFormatter,
|
||||||
ProtocolsFormatter,
|
ProtocolsFormatter,
|
||||||
TagChoicesFormatter,
|
TagChoicesFormatter,
|
||||||
LabelsFormatter
|
LabelsFormatter,
|
||||||
|
SwitchFormatter
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script type="text/jsx">
|
<script type="text/jsx">
|
||||||
import { ChoicesFormatter, DetailFormatter } from '@/components/Table/TableFormatters'
|
import { ChoicesFormatter, DetailFormatter, SwitchFormatter } from '@/components/Table/TableFormatters'
|
||||||
import { BASE_URL } from '@/utils/common'
|
import { BASE_URL } from '@/utils/common'
|
||||||
import ListTable from '@/components/Table/ListTable/index.vue'
|
import ListTable from '@/components/Table/ListTable/index.vue'
|
||||||
|
|
||||||
@ -112,25 +112,18 @@ export default {
|
|||||||
enabled: {
|
enabled: {
|
||||||
width: '80px',
|
width: '80px',
|
||||||
label: `${this.$t('common.Enable')}/${this.$t('common.Disable')}`,
|
label: `${this.$t('common.Enable')}/${this.$t('common.Disable')}`,
|
||||||
formatter: (row) => {
|
formatter: SwitchFormatter,
|
||||||
console.log(row.exec_cycle)
|
formatterArgs: {
|
||||||
if (row.exec_cycle === undefined) {
|
isDisplay(row) {
|
||||||
return '-'
|
return row.exec_cycle !== undefined
|
||||||
} else {
|
},
|
||||||
return <el-switch
|
getPatchUrl(row) {
|
||||||
v-model={row.enabled}
|
return `/api/v1/ops/celery/period-tasks/${row.name}/`
|
||||||
onChange={(v) => {
|
},
|
||||||
const url = `/api/v1/ops/celery/period-tasks/${row.name}/`
|
getPatchData(row) {
|
||||||
const data = { enabled: v }
|
return {
|
||||||
this.$axios.patch(url, data).catch(() => {
|
enabled: !row.enabled
|
||||||
row.enabled = !v
|
}
|
||||||
}).then(res => {
|
|
||||||
this.$message.success(this.$t('common.updateSuccessMsg'))
|
|
||||||
}).catch(err => {
|
|
||||||
this.$message.error(this.$t('common.updateErrorMsg' + ' ' + err))
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user