Skip to content

Commit

Permalink
perf: 调整 virtual app 卡片展示
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Dec 1, 2023
1 parent 7a32685 commit 9163ae6
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 52 deletions.
127 changes: 127 additions & 0 deletions src/views/settings/Applet/VirtualApp/UploadDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<template>
<Dialog
:show-cancel="false"
:title="$tc('common.OfflineUpload')"
:before-close="handleClose"
:loading-status="!isFinished"
v-bind="$attrs"
@cancel="onCancel"
@confirm="onSubmit"
v-on="$listeners"
>
<el-form label-position="top">
<el-form-item
:label="$tc('common.Upload' )"
:label-width="'100px'"
class="file-uploader"
>
<el-upload
ref="upload"
:auto-upload="false"
:before-upload="beforeUpload"
:limit="1"
:on-change="onFileChange"
accept=".zip"
action="string"
drag
list-type="text/csv"
upload-files="uploadFiles"
>
<i class="el-icon-upload" />
<div class="el-upload__text">
{{ $t('common.imExport.dragUploadFileInfo') }}
</div>
<div slot="tip" class="el-upload__tip">
<span :class="{'hasError': hasFileFormatOrSizeError }">
{{ $t('terminal.uploadZipTips') }}
</span>
<div v-if="renderError" class="hasError">{{ renderError }}</div>
</div>
</el-upload>
</el-form-item>
</el-form>
</Dialog>
</template>

<script>
import { Dialog } from '@/components'
export default {
name: 'UploadDialog',
components: {
Dialog
},
data() {
return {
hasFileFormatOrSizeError: false,
renderError: '',
file: null,
isFinished: true
}
},
methods: {
onFileChange(file, fileList) {
if (file.status !== 'ready') {
return
}
this.file = file
},
beforeUpload(file) {
},
handleClose(done) {
if (this.isFinished) {
done()
} else {
this.$message.warning(this.$tc('terminal.Uploading'))
}
},
onCancel() {
this.$emit('update:visible', false)
},
onSubmit() {
if (!this.file) {
return
}
this.isFinished = false
const form = new FormData()
form.append('file', this.file.raw)
this.$axios.post(
'/api/v1/terminal/virtual-apps/upload/',
form,
{
headers: { 'Content-Type': 'multipart/form-data' },
disableFlashErrorMsg: true
}
).then(res => {
this.isFinished = true
this.$message.success(this.$tc('terminal.UploadSucceed'))
this.$emit('update:visible', false)
this.$emit('upload-event', res)
}).catch(err => {
this.isFinished = true
const error = err.response.data
const msg = error?.message || error?.detail || error?.error || JSON.stringify(error)
this.$message.error(msg)
})
setTimeout(() => {
this.$refs.upload.clearFiles()
}, 400)
}
}
}
</script>
<style lang="scss" scoped>
.file-uploader.el-form-item {
margin-bottom: 0;
>>> .el-upload {
width: 100%;
.el-upload-dragger {
width: 100%;
}
}
}
</style>
62 changes: 61 additions & 1 deletion src/views/settings/Applet/VirtualApp/VirtualAppDetail/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
<el-col :md="10" :sm="24">
<AutoDetailCard :fields="detailFields" :object="object" :url="url" />
</el-col>
<el-col :md="14" :sm="24">
<IBox title="README">
<vue-markdown v-if="object.readme" :source="object.readme" />
<span v-else>{{ $tc('common.NoData') }}</span>
</IBox>
</el-col>
</el-row>
</template>

<script>
import AutoDetailCard from '@/components/Cards/DetailCard/auto'
import { IBox } from '@/components'
import VueMarkdown from 'vue-markdown'
export default {
name: 'Detail',
components: {
VueMarkdown,
IBox,
AutoDetailCard
},
props: {
Expand All @@ -22,9 +32,59 @@ export default {
}
},
data() {
const vm = this
return {
url: `/api/v1/terminal/virtual-apps/${this.object.id}`,
detailFields: ['name', 'image_name', 'version', 'protocols', 'is_active', 'comment']
detailFields: [
{
key: '',
formatter: () => {
return <img src={this.object.icon} alt='' height='40'/>
}
},
'name', 'display_name', 'author',
{
key: this.$t('assets.Protocols'),
formatter: () => {
const types = ['primary', 'success', 'warning', 'danger']
const data = this.object.protocols.map((p, i) => {
return <el-tag type={types[i % 4]} size='mini'>{p}</el-tag>
})
return <span> {data} </span>
}
},
{
key: this.$t('assets.Label'),
formatter: () => {
const types = ['primary', 'success', 'warning', 'danger']
const data = this.object.tags.map((p, i) => {
return <el-tag type={types[i % 4]} size='mini'>{p}</el-tag>
})
return <span> {data} </span>
}
},
{
key: this.$t('common.Activate'),
formatter: () => {
return <el-switch
v-model={this.object.is_active}
disabled={!vm.$hasPerm('terminal.change_virtualapp')}
onChange={(v) => {
const url = `/api/v1/terminal/virtual-apps/${vm.object.id}/`
const data = { is_active: v }
vm.$axios.patch(url, data).catch(() => {
this.object.is_active = !v
}).then(res => {
vm.$message.success(vm.$t('common.updateSuccessMsg'))
}).catch(err => {
vm.$message.error(vm.$t('common.updateErrorMsg' + ' ' + err))
})
}}
/>
}
},
'date_created', 'date_updated', 'comment'
]
}
},
mounted() {
Expand Down
83 changes: 32 additions & 51 deletions src/views/settings/Applet/VirtualApp/VirtualAppList.vue
Original file line number Diff line number Diff line change
@@ -1,78 +1,59 @@
<template>
<div>
<ListTable class="virtual-app" v-bind="$data" />
<CardTable ref="CardTable" v-bind="$data" />
<UploadDialog :visible.sync="uploadDialogVisible" @upload-event="handleUpload" />
</div>
</template>

<script>
import { ListTable } from '@/components'
import { ActionsFormatter, ProtocolsFormatter } from '@/components/Table/TableFormatters'
import CardTable from './components/CardTable'
import UploadDialog from './UploadDialog'
export default {
name: 'VirtualApp',
components: {
ListTable
CardTable,
UploadDialog
},
data() {
return {
uploadDialogVisible: false,
tableConfig: {
url: '/api/v1/terminal/virtual-apps/',
columnsShow: {
min: ['name'],
default: [
'name', 'image_name', 'comment', 'actions'
]
},
columnsMeta: {
name: {
formatterArgs: {
getRoute: ({ row }) => {
return {
name: 'VirtualAppDetail',
params: { id: row.id }
}
}
}
},
protocols: {
label: this.$t('assets.Protocols'),
formatter: ProtocolsFormatter
},
actions: {
formatter: ActionsFormatter,
formatterArgs: {
hasClone: false,
onUpdate: ({ row }) => {
const route = {
name: 'VirtualAppUpdate',
params: { id: row.id },
query: {}
}
this.$router.push(route)
},
performDelete: ({ row }) => {
const id = row.id
const url = `/api/v1/terminal/virtual-apps/${id}/`
return this.$axios.delete(url)
}
}
}
}
deletePerm: 'terminal.delete_virtualapp'
},
headerActions: {
createRoute: 'VirtualAppCreate',
hasRefresh: true,
onCreate: () => {
this.uploadDialogVisible = true
},
createTitle: this.$t('common.Upload'),
searchConfig: {
getUrlQuery: false,
exclude: ['version']
},
detailRoute: 'VirtualAppDetail',
hasExport: false,
hasImport: false
hasImport: false,
hasBulkDelete: false,
hasBulkUpdate: false,
hasColumnSetting: false
}
}
},
methods: {
handleUpload(res) {
this.$refs.CardTable.reloadTable()
}
}
}
</script>

<style lang="scss" scoped>
.virtual-app > > > .protocol {
margin-left: 3px;
}
.dom {
white-space: initial;
.el-tag {
margin-right: 3px;
}
}
</style>
Loading

0 comments on commit 9163ae6

Please sign in to comment.