123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <template>
- <div ref="container">
- <a-modal
- title="发布新版本"
- :visible="visible"
- :confirmLoading="confirmLoading"
- :getContainer="() => $refs.container"
- :maskStyle="{ top: '93px', left: '154px' }"
- :wrapClassName="wrapClassNameInfo()"
- :mask="isDesktop()"
- :maskClosable="false"
- @cancel="handleCancel"
- :footer="null"
- width="500px"
- style="top: 5%"
- >
- <a-spin :spinning="confirmLoading">
- <a-form :form="form" class="form-content" id="appVersionModal">
- <a-form-item label="版本号" :labelCol="labelCol" :wrapperCol="wrapperCol">
- <a-input placeholder="请输入" allowClear v-decorator="['version', validatorRules.version]" />
- </a-form-item>
-
- <a-form-item label="上传文件" :labelCol="labelCol" :wrapperCol="wrapperCol">
- <div class="upload-container">
- <a-upload
- name="file"
- :data="uploadOpts.data"
- :showUploadList="true"
- :multiple="false"
- :headers="uploadOpts.headers"
- :action="uploadOpts.action"
- :method="uploadOpts.method"
- :accept="uploadOpts.accept"
- :fileList="fileList"
- @change="handleChange"
- :beforeUpload="beforeUpload"
- @reject="handleReject"
- >
- <div class="upload-content">
- <div class="upload-icon">
- <a-icon type="folder-open" style="color: #4e73f8; font-size: 32px;" />
- </div>
- <a-button type="primary" class="upload-button">上传文件</a-button>
- </div>
- </a-upload>
- </div>
- </a-form-item>
-
- <div class="form-actions">
- <a-button @click="handleCancel" class="cancel-button">取消</a-button>
- <a-button type="primary" @click="handleOk" :loading="confirmLoading" class="confirm-button">确定发布新版本</a-button>
- </div>
- </a-form>
- </a-spin>
- </a-modal>
- </div>
- </template>
- <script>
- import Vue from 'vue'
- import { ACCESS_TOKEN } from '@/store/mutation-types'
- import pick from 'lodash.pick'
- import { autoJumpNextInput } from '@/utils/util'
- import { mixinDevice } from '@/utils/mixin'
- import { postAction } from '@/api/manage'
- export default {
- name: 'AppVersionModal',
- mixins: [mixinDevice],
- data() {
- return {
- visible: false,
- confirmLoading: false,
- labelCol: { span: 4 },
- wrapperCol: { span: 20 },
- fileList: [],
- validatorRules: {
- version: {
- rules: [
- { required: true, message: '请输入版本号!' },
- { pattern: /^\d+\.\d+\.\d+$/, message: '版本号格式不正确!' }
- ]
- },
- url: {
- rules: [
- { required: true, message: '请上传.apk文件!' }
- ]
- }
- },
- form: this.$form.createForm(this),
- model: {},
- uploadOpts:{
- headers: {
- 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)
- },
- method: 'POST',
- action: window._CONFIG['domianURL'] + '/apkVersion/upload',
- accept: '.apk',
- data:{
- biz: 'bill'
- }
- },
- }
- },
- methods: {
- add() {
- this.edit({})
- },
- edit(record) {
- this.form.resetFields()
- this.model = Object.assign({}, record)
- this.fileList = []
- this.visible = true
- this.$nextTick(() => {
- this.form.setFieldsValue(
- pick(
- this.model,
- 'url',
- 'version'
- )
- )
- autoJumpNextInput('appVersionModal')
- })
- },
- beforeUpload(file) {
- // 检查文件类型
- const isAPK = file.type === 'application/vnd.android.package-archive' || file.name.endsWith('.apk')
- if (!isAPK) {
- this.$message.error('只能上传APK文件!')
- return false
- }
-
- // 阻止自动上传
- return true
- },
- handleChange(info) {
- this.fileList = [info.file]
- console.log('文件列表:', this.fileList)
- if (info.file.status === 'uploading') {
- console.log(info.file, info.fileList)
- this.confirmLoading = true
- }else if(info.file.status === 'removed'){
- this.fileList = []
- this.model.url = ''
- }else if (info.file.status === 'done') {
- this.confirmLoading = false
- console.log('model=====', this.model)
- if (info.file.response) {
- if (info.file.response.code === 200) {
- info.file.name = info.file.response.data
- this.model.url = info.file.response.data
- } else {
- this.$message.warning(info.file.response.data, 8)
- }
- } else {
- this.$message.error(`${info.file.name} ${info.file.response.data}.`)
- }
- } else if (info.file.status === 'error') {
- this.confirmLoading = false
- this.$message.error(`文件上传失败: ${info.file.msg} `)
- }
- },
- handleReject(file) {
- console.log('文件类型不正确:', file)
- this.$message.error('文件类型不正确,请上传.apk文件!')
- },
- handleOk() {
- this.form.validateFields((err, values) => {
- if (err) return
- console.log('values======',values)
- if (this.fileList.length === 0) {
- this.$message.error('请上传.apk类型文件!')
- return
- }
-
- const formData = {
- version: values.version,
- url: this.fileList[0].name // 实际应用中这里应该是上传后的URL
- }
-
- this.confirmLoading = true
-
- postAction('/apkVersion/add', formData).then(res => {
- if (res.code === 200) {
- this.$message.success(res.msg)
- this.visible = false
- this.$emit('ok', formData)
- } else {
- this.$message.error(res.data||'操作失败')
- }
- }).catch(err => {
- console.error(err)
- }).finally(() => {
- this.confirmLoading = false
- })
- })
- },
- handleCancel() {
- this.visible = false
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .form-content {
- padding: 0 10px;
- }
- .upload-container {
- border: 1px dashed #d9d9d9;
- border-radius: 4px;
- padding: 24px;
- background-color: #fafafa;
- }
- .upload-content {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 10px 0;
- }
- .upload-icon {
- margin-bottom: 16px;
- }
- .upload-button {
- height: 32px;
- font-size: 14px;
- border-radius: 4px;
- background-color: #4e73f8;
- border-color: #4e73f8;
- }
- .reupload-button {
- background-color: #4e73f8;
- border-color: #4e73f8;
- }
- .form-actions {
- display: flex;
- justify-content: flex-end;
- margin-top: 24px;
-
- .cancel-button {
- margin-right: 12px;
- min-width: 80px;
- height: 32px;
- }
-
- .confirm-button {
- background-color: #4e73f8;
- border-color: #4e73f8;
- min-width: 120px;
- height: 32px;
- }
- }
- /deep/ .ant-upload.ant-upload-select {
- display: block;
- }
- /deep/ .ant-upload-list-item {
- margin-top: 8px;
- }
- /deep/ .ant-form-item-label {
- text-align: left;
- line-height: 32px;
- }
- /deep/ .ant-form-item {
- margin-bottom: 24px;
- }
- /deep/ .ant-modal-close-x {
- width: 46px;
- height: 46px;
- line-height: 46px;
- }
- /deep/ .ant-modal-body {
- padding: 16px 24px 24px;
- }
- /deep/ .ant-form-item-control {
- line-height: 32px;
- }
- /deep/ .ant-input {
- height: 32px;
- }
- </style>
|