You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.7 KiB

6 months ago
<template>
3 months ago
<div style="position: relative">
6 months ago
<Upload :action="uploadFileUrl" :headers="accessToken" :data="uploadData" :on-success="handleSuccess"
3 months ago
:on-error="handleError" :max-size="204800" :before-upload="beforeUpload"
:format="['wgt']" :on-format-error="handleFormatError" type="drag" ref="up">
6 months ago
<div style="padding: 20px 0">
<Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
3 months ago
<p>点击这里或将wgt包拖拽到这里上传</p>
6 months ago
</div>
</Upload>
3 months ago
<Form ref="form" :model="form" :label-width="100" :rules="formValidate" style="margin-top: 24px">
<FormItem label="版本号" prop="version">
<Input v-model="form.version" placeholder="请输入版本号,如1.0.1" style="width: 380px" />
</FormItem>
<FormItem label="wgt包地址" prop="url">
<Input v-model="form.url" readonly placeholder="请先上传wgt包" style="width: 520px" />
</FormItem>
<FormItem label="文件名">
<Input v-model="form.fileName" readonly style="width: 380px" />
6 months ago
</FormItem>
</Form>
3 months ago
<div>
6 months ago
<Button type="primary" :loading="submitLoading" @click="handelSubmit">提交</Button>
</div>
3 months ago
<Spin fix v-if="loading"></Spin>
6 months ago
</div>
</template>
<script>
import {
3 months ago
uploadAppUpdateFile,
6 months ago
checkOssSet,
3 months ago
getAppUpdateSet,
editAppUpdateSet,
6 months ago
} from "@/api/index";
export default {
3 months ago
name: "upApp",
6 months ago
data() {
return {
3 months ago
uploadFileUrl: uploadAppUpdateFile,
loading: false,
6 months ago
submitLoading: false,
accessToken: {},
uploadData: {},
form:{
3 months ago
url: "",
version: "",
fileName: "",
},
formValidate: {
version: [{ required: true, message: "请输入版本号", trigger: "blur" }],
url: [{ required: true, message: "请上传wgt包", trigger: "change" }],
},
6 months ago
};
},
methods: {
init() {
this.accessToken = {
accessToken: this.getStore("accessToken"),
};
3 months ago
this.initAppUpdateSet();
6 months ago
checkOssSet().then((res) => {
if (!res.success) {
this.$Modal.confirm({
title: "系统还未配置OSS",
content: "管理员还未配置第三方OSS服务,是否现在立即去配置?",
onOk: () => {
this.$router.push({
name: "setting",
query: {
name: "oss"
},
});
},
});
}
});
},
3 months ago
initAppUpdateSet() {
this.loading = true;
getAppUpdateSet().then((res) => {
this.loading = false;
if (res.result) {
for (let attr in res.result) {
if (res.result[attr] == null) {
res.result[attr] = "";
}
}
this.form = res.result;
}
});
},
beforeUpload(file) {
if (!file.name || file.name.toLowerCase().lastIndexOf(".wgt") !== file.name.length - 4) {
this.$Message.error("只能上传wgt格式的热更新包");
return false;
}
6 months ago
return true;
},
handleSuccess(res, file, fileList) {
if (res.success) {
this.$Message.success("上传文件 " + file.name + " 成功");
3 months ago
this.form.url = res.result;
this.form.fileName = file.name;
6 months ago
} else {
file.percentage = 0;
file.status = "fail";
file.name += "(上传失败)";
this.$Message.error(res.message);
}
},
handleError(error, file, fileList) {
this.$Message.error(error.toString());
},
3 months ago
handleFormatError(file) {
this.$Message.error(file.name + " 不是wgt格式文件");
},
6 months ago
handelSubmit() {
3 months ago
this.$refs.form.validate((valid) => {
if (!valid) {
return;
}
this.submitLoading = true;
editAppUpdateSet(this.form).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("保存成功");
}
});
});
},
6 months ago
},
mounted() {
this.init();
},
};
</script>
<style lang="less">
</style>