add:pda新版本发布在线更新

This commit is contained in:
zhaoyf
2026-08-12 14:21:09 +08:00
parent b40e11daf2
commit b883f24cc1
7 changed files with 499 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
<template>
<div class="app-container">
<div class="head-container">
<div v-if="crud.props.searchToggle">
<el-input
v-model="query.app_name"
clearable
size="mini"
placeholder="应用名称"
style="width: 200px;"
@keyup.enter.native="crud.toQuery"
/>
<rrOperation />
</div>
<crudOperation :permission="permission">
<el-button
slot="left"
class="filter-item"
size="mini"
type="primary"
icon="el-icon-upload"
@click="dialogVisible = true"
>发布版本</el-button>
</crudOperation>
<el-table v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;">
<el-table-column type="index" label="序号" width="55" align="center" />
<el-table-column prop="app_name" label="应用名称" min-width="140" />
<el-table-column prop="version_name" label="版本号" width="120" />
<el-table-column prop="apk_name" label="APK 文件名" min-width="200" />
<el-table-column :formatter="formatSize" prop="apk_size" label="文件大小" width="110" align="right" />
<el-table-column prop="create_name" label="发布人" width="100" />
<el-table-column prop="create_time" label="发布时间" width="160" />
<el-table-column label="操作" width="100" fixed="right" align="center">
<template slot-scope="scope">
<el-link type="primary" :href="downloadUrl(scope.row.app_version_id)">下载</el-link>
</template>
</el-table-column>
</el-table>
<pagination />
</div>
<el-dialog
:close-on-click-modal="false"
title="发布 APP 版本"
:visible.sync="dialogVisible"
width="480px"
@close="resetForm"
>
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="90px">
<el-form-item label="应用名称" prop="app_name">
<el-input v-model="form.app_name" maxlength="100" placeholder="例如WMS PDA" />
</el-form-item>
<el-form-item label="版本号" prop="version_name">
<el-input v-model="form.version_name" maxlength="50" placeholder="例如1.2.0" />
</el-form-item>
<el-form-item label="APK 文件" prop="file">
<el-upload
ref="upload"
:action="publishUrl"
:auto-upload="false"
:data="form"
:headers="headers"
:limit="1"
accept=".apk,application/vnd.android.package-archive"
:before-upload="beforeUpload"
:on-success="uploadSuccess"
:on-error="uploadError"
:on-exceed="handleExceed"
>
<el-button size="small" type="primary">选择 APK</el-button>
<div slot="tip" class="el-upload__tip">仅支持 APK文件名将保存为应用名称-版本号.apk</div>
</el-upload>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button :loading="uploading" type="primary" @click="publish">发布</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
import CRUD, { crud, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
const defaultForm = { app_name: '', version_name: '' }
export default {
name: 'AppVersion',
components: { crudOperation, rrOperation, pagination },
cruds() {
return CRUD({
title: 'APP版本',
idField: 'app_version_id',
url: 'api/appVersion',
optShow: { add: false, edit: false, del: false, reset: true, download: false }
})
},
mixins: [presenter(), header(), crud()],
data() {
return {
dialogVisible: false,
uploading: false,
headers: { Authorization: getToken() },
form: { ...defaultForm },
permission: {},
rules: {
app_name: [{ required: true, message: '请输入应用名称', trigger: 'blur' }],
version_name: [{ required: true, message: '请输入版本号', trigger: 'blur' }]
}
}
},
computed: {
...mapGetters(['baseApi']),
publishUrl() {
return this.baseApi + '/api/appVersion/publish'
}
},
methods: {
publish() {
this.$refs.form.validate(valid => {
if (!valid) return
if (this.$refs.upload.uploadFiles.length === 0) {
this.$message.warning('请选择 APK 文件')
return
}
this.uploading = true
this.$refs.upload.submit()
})
},
beforeUpload(file) {
const isApk = file.name.toLowerCase().endsWith('.apk')
if (!isApk) {
this.$message.error('只能上传 APK 文件')
this.uploading = false
}
return isApk
},
uploadSuccess() {
this.$message.success('版本发布成功')
this.dialogVisible = false
this.crud.toQuery()
},
uploadError(error) {
let message = '版本发布失败'
try {
message = JSON.parse(error.message).message || message
} catch (e) {
// Element UI does not always expose a JSON response body.
}
this.$message.error(message)
this.uploading = false
},
handleExceed() {
this.$message.warning('一次只能上传一个 APK 文件')
},
resetForm() {
this.uploading = false
this.form = { ...defaultForm }
if (this.$refs.form) this.$refs.form.resetFields()
if (this.$refs.upload) this.$refs.upload.clearFiles()
},
formatSize(row) {
if (!row.apk_size) return '0 B'
const units = ['B', 'KB', 'MB', 'GB']
const index = Math.min(Math.floor(Math.log(row.apk_size) / Math.log(1024)), units.length - 1)
const value = row.apk_size / Math.pow(1024, index)
return value.toFixed(index === 0 ? 0 : 2) + ' ' + units[index]
},
downloadUrl(id) {
return this.baseApi + '/api/appVersion/download/' + id
}
}
}
</script>