addDialog.vue 4.7 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
          <el-input
乐宝呗666's avatar
乐宝呗666 committed
20
            maxlength="20" 
乐宝呗666's avatar
乐宝呗666 committed
21 22 23 24
            v-model="formItem.appVersion"
            clearable
            placeholder="请输入版本号"
          ></el-input>
25
        </el-form-item>
qzhxx's avatar
qzhxx committed
26
        <el-form-item label="版本信息:" prop="versionInfo">
乐宝呗666's avatar
乐宝呗666 committed
27
          <el-input
乐宝呗666's avatar
乐宝呗666 committed
28
            maxlength="100" 
乐宝呗666's avatar
乐宝呗666 committed
29 30 31
            type="textarea"
            v-model="formItem.versionInfo"
          ></el-input>
32
        </el-form-item>
乐宝呗666's avatar
乐宝呗666 committed
33
        <el-form-item label="更新内容:" prop="updateLog">
乐宝呗666's avatar
乐宝呗666 committed
34
          <el-input
乐宝呗666's avatar
乐宝呗666 committed
35
            maxlength="100" 
乐宝呗666's avatar
乐宝呗666 committed
36
            type="textarea"
乐宝呗666's avatar
乐宝呗666 committed
37
            v-model="formItem.updateLog"
乐宝呗666's avatar
乐宝呗666 committed
38
          ></el-input>
39 40 41 42
        </el-form-item>
        <el-upload
          class="text-center"
          drag
乐宝呗666's avatar
乐宝呗666 committed
43
          :action="uploadUrl"
乐宝呗666's avatar
乐宝呗666 committed
44
          :headers ="headers"
qzhxx's avatar
qzhxx committed
45
          :on-success="handleAvatarSuccess"
乐宝呗666's avatar
乐宝呗666 committed
46 47 48
          :before-upload="handleBeforeUpload"
          :file-list="fileList"
        >
49
          <i class="el-icon-upload"></i>
乐宝呗666's avatar
乐宝呗666 committed
50 51 52 53
          <div class="el-upload__text">
            将安装包拖到此处,或<em>点击上传安装包</em>
          </div>
          <div class="el-upload__tip" slot="tip">只能上传apk文件</div>
54 55
        </el-upload>
      </el-form>
qzhxx's avatar
qzhxx committed
56 57 58
    </div>
    <div slot="footer" class="dialog-footer btn-group">
      <el-button size="mini" @click="close">取 消</el-button>
乐宝呗666's avatar
乐宝呗666 committed
59
      <el-button size="mini" type="primary" @click="submitForm('formItem')">确定</el-button>
liqin's avatar
liqin committed
60

61 62 63 64 65 66 67 68
    </div>
  </el-dialog>
</template>

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

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

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

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

liqin's avatar
liqin committed
180
</style>