addDialog.vue 4.61 KB
Newer Older
1 2 3 4 5
<template>
  <el-dialog
    class="custom-dialog"
    custom-class="party-dialog"
    title="上传新版安装包"
乐宝呗666's avatar
乐宝呗666 committed
6
    width="468px"
7 8 9 10 11 12
    :visible.sync="formVisible"
    :before-close="close"
  >
    <div class="dialog-content">
      <el-form
        :model="formItem"
乐宝呗666's avatar
乐宝呗666 committed
13
        class="party-form version-add"
14
        ref="formItem"
乐宝呗666's avatar
乐宝呗666 committed
15
        label-position="top"
16 17
        :rules="rules"
      >
qzhxx's avatar
qzhxx committed
18
        <el-form-item label="版本号:" prop="appVersion">
乐宝呗666's avatar
乐宝呗666 committed
19 20 21 22 23
          <el-input
            v-model="formItem.appVersion"
            clearable
            placeholder="请输入版本号"
          ></el-input>
24
        </el-form-item>
qzhxx's avatar
qzhxx committed
25
        <el-form-item label="版本信息:" prop="versionInfo">
乐宝呗666's avatar
乐宝呗666 committed
26 27 28 29
          <el-input
            type="textarea"
            v-model="formItem.versionInfo"
          ></el-input>
30
        </el-form-item>
乐宝呗666's avatar
乐宝呗666 committed
31
        <el-form-item label="更新内容:" prop="updateLog">
乐宝呗666's avatar
乐宝呗666 committed
32 33
          <el-input
            type="textarea"
乐宝呗666's avatar
乐宝呗666 committed
34
            v-model="formItem.updateLog"
乐宝呗666's avatar
乐宝呗666 committed
35
          ></el-input>
36 37 38 39
        </el-form-item>
        <el-upload
          class="text-center"
          drag
乐宝呗666's avatar
乐宝呗666 committed
40
          :action="uploadUrl"
乐宝呗666's avatar
乐宝呗666 committed
41
          :headers ="headers"
qzhxx's avatar
qzhxx committed
42
          :on-success="handleAvatarSuccess"
乐宝呗666's avatar
乐宝呗666 committed
43 44 45
          :before-upload="handleBeforeUpload"
          :file-list="fileList"
        >
46
          <i class="el-icon-upload"></i>
乐宝呗666's avatar
乐宝呗666 committed
47 48 49 50
          <div class="el-upload__text">
            将安装包拖到此处,或<em>点击上传安装包</em>
          </div>
          <div class="el-upload__tip" slot="tip">只能上传apk文件</div>
51 52
        </el-upload>
      </el-form>
qzhxx's avatar
qzhxx committed
53 54 55
    </div>
    <div slot="footer" class="dialog-footer btn-group">
      <el-button size="mini" @click="close">取 消</el-button>
乐宝呗666's avatar
乐宝呗666 committed
56
      <el-button size="mini" type="primary" @click="submitForm('formItem')">确定</el-button>
liqin's avatar
liqin committed
57

58 59 60 61 62 63 64 65
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
liqin's avatar
liqin committed
66
      uploadUrl:'http://111.203.232.175:8088/mall/file/upload/allType',
67
      formVisible: false,
乐宝呗666's avatar
乐宝呗666 committed
68
      headers:{Authorization: localStorage.getItem('backToken')},
69
      formItem: {},
乐宝呗666's avatar
乐宝呗666 committed
70
      fileList: [],
71
      rules: {
qzhxx's avatar
qzhxx committed
72
        appVersion: [
乐宝呗666's avatar
乐宝呗666 committed
73
          { required: true, message: "请输入版本号", trigger: "blur" },
74
        ],
乐宝呗666's avatar
乐宝呗666 committed
75 76 77
        versionInfo: [
          { required: true, message: "请输入版本信息", trigger: "blur" },
        ],
乐宝呗666's avatar
乐宝呗666 committed
78
        updateLog: [
乐宝呗666's avatar
乐宝呗666 committed
79 80 81
          { required: true, message: "请输入更新内容", trigger: "blur" },
        ],
      },
82 83 84
    };
  },
  methods: {
乐宝呗666's avatar
乐宝呗666 committed
85 86
    backFn() {
      this.formVisible = true
乐宝呗666's avatar
乐宝呗666 committed
87 88
      this.formItem = {}
      this.fileList = []
乐宝呗666's avatar
乐宝呗666 committed
89 90 91
      this.$nextTick(() => {
        this.$refs.formItem.clearValidate()
      });
liqin's avatar
liqin committed
92

93 94 95 96 97
    },
    // 关闭
    close() {
      this.formVisible = false;
      for (let key in this.formItem) {
乐宝呗666's avatar
乐宝呗666 committed
98 99 100 101 102 103 104 105 106
        this.formItem[key] = null
      }
      this.$refs["formItem"].resetFields()
    },
    // 格式控制
    handleBeforeUpload(file) {
      if (file.type !== "application/vnd.android.package-archive") {
        this.$message.error("只能上传apk文件")
        return false
107
      }
乐宝呗666's avatar
乐宝呗666 committed
108
      return true
109 110
    },
    // 上传数据操作
qzhxx's avatar
qzhxx committed
111
    handleAvatarSuccess(res, file) {
乐宝呗666's avatar
乐宝呗666 committed
112 113 114 115 116
      if(res.resultCode==='200'){
        this.formItem.apkUrl = res.data.url
      }else{
        this.$message.error(res.message)
      }
117 118 119 120
    },

    // 保存编辑信息
    submitForm() {
乐宝呗666's avatar
乐宝呗666 committed
121 122
      let _this = this
      _this.$refs.formItem.validate((valid) => {
123
        if (valid) {
qzhxx's avatar
qzhxx committed
124
          if (!this.formItem.apkUrl) {
乐宝呗666's avatar
乐宝呗666 committed
125
            this.$message.info("请先选取文件!")
126 127
            return false
          }
qzhxx's avatar
qzhxx committed
128 129 130
          let param = {
            appVersion: this.formItem.appVersion,
            versionInfo: this.formItem.versionInfo,
乐宝呗666's avatar
乐宝呗666 committed
131
            updateLog: this.formItem.updateLog,
乐宝呗666's avatar
乐宝呗666 committed
132 133 134 135
            apkUrl: this.formItem.apkUrl,
          }
          _this
            .$https(
qzhxx's avatar
qzhxx committed
136 137 138
              {
                url: "tAppVersion/save",
                method: "post",
乐宝呗666's avatar
乐宝呗666 committed
139
                authType: this.backToken,
qzhxx's avatar
qzhxx committed
140 141
              },
              _this.$qs.stringify(param)
乐宝呗666's avatar
乐宝呗666 committed
142 143 144 145 146 147 148
            )
            .then(
              (res) => {
                if (res.data.resultCode === "200") {
                  _this.$message.success(res.data.message)
                  _this.formVisible = false
                  _this.$emit("refreshFn")
qzhxx's avatar
qzhxx committed
149
                } else {
乐宝呗666's avatar
乐宝呗666 committed
150
                  _this.$message.error(res.data.message)
qzhxx's avatar
qzhxx committed
151 152
                }
              },
乐宝呗666's avatar
乐宝呗666 committed
153 154
              (error) => {
                console.log(error)
qzhxx's avatar
qzhxx committed
155
              }
乐宝呗666's avatar
乐宝呗666 committed
156
            )
157
        }
乐宝呗666's avatar
乐宝呗666 committed
158
      })
159
    },
乐宝呗666's avatar
乐宝呗666 committed
160
  },
161 162 163 164
};
</script>

<style lang="less">
乐宝呗666's avatar
乐宝呗666 committed
165 166 167 168 169 170 171 172 173
.version-add {
  .el-upload-dragger {
    height: 120px;
    .el-icon-upload {
      margin-top: 10px;
    }
  }
  .text-center {
    text-align: center;
174 175
  }
}
乐宝呗666's avatar
乐宝呗666 committed
176

liqin's avatar
liqin committed
177
</style>