index.vue 13.8 KB
Newer Older
wanli's avatar
wanli committed
1 2 3
<template>
  <div class="app-container">
    <el-form :inline="true" ref="form" :model="form" size="mini">
wanli's avatar
wanli committed
4 5
      <el-form-item><el-button type="warning" @click="onAdd">添加应用</el-button></el-form-item>
      <el-form-item><el-button type="success" @click="onAddFramework">添加系统页面</el-button></el-form-item>
wanli's avatar
wanli committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    </el-form>
    <el-table
      v-loading="isLoading"
      element-loading-text="Loading"
      :data="list"
      size="mini"
      border
      stripe
      fit
      highlight-current-row
    >
      <el-table-column
        prop="app_name"
        label="应用名称"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="app_version"
        label="应用版本号"
        width="150"
      ></el-table-column>
wanli's avatar
wanli committed
27 28 29 30 31 32 33 34 35 36
      <el-table-column
        prop="category"
        label="应用类别"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="app_url"
        label="应用路径"
        width="120"
      ></el-table-column>
wanli's avatar
wanli committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
      <el-table-column
        prop="app_desc"
        label="应用描述"
        width="200"
      ></el-table-column>
      <el-table-column
        prop="create_at"
        label="创建时间"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="create_by.username"
        label="创建者"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="update_at"
        label="更新时间"
        width="150"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="update_by.username"
        label="更新者"
        width="150"
      ></el-table-column>
      <el-table-column label="操作" align="center" min-width="180" fixed="right">
        <template slot-scope="scope">
            <el-button
            size="mini"
            type="primary"
            @click="handleBuild(scope.$index, scope.row)"
            >一键打包</el-button
          >
          <el-button
            size="mini"
            type="success"
            @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="page-wrapper">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="form.pagenum"
        background
        small
        :page-size="form.pagesize"
        :pager-count="5"
        layout="pager, prev, next, total"
        :total="total"
      ></el-pagination>
    </div>
wanli's avatar
wanli committed
98 99
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%">
      <el-form :model="post" status-icon ref="post" size="medium" label-width="100px">
wanli's avatar
wanli committed
100
        <el-form-item label="应用名称" prop="app_name">
wanli's avatar
wanli committed
101
          <el-input type="text" v-model="post.app_name" autocomplete="off"></el-input>
wanli's avatar
wanli committed
102 103
        </el-form-item>
        <el-form-item label="应用版本号" prop="app_version">
wanli's avatar
wanli committed
104 105 106 107 108 109 110
          <el-input type="text" v-model="post.app_version" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="应用路径" prop="app_url">
          <el-input type="text" v-model="post.app_url" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="应用类别" prop="category">
          <el-input type="text" v-model="post.category" autocomplete="off"></el-input>
wanli's avatar
wanli committed
111 112
        </el-form-item>
        <el-form-item label="应用描述" prop="app_desc">
wanli's avatar
wanli committed
113
          <el-input type="text" v-model="post.app_desc" autocomplete="off"></el-input>
wanli's avatar
wanli committed
114
        </el-form-item>
wanli's avatar
wanli committed
115
        <el-form-item label="应用Logo" prop="app_icon">
wanli's avatar
wanli committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
          <el-upload
            class="avatar-uploader"
            :action="`${window.location.protocol}//${window.location.host}/api/v1/evm_store/upload`"
            name="binfile"
            :on-remove="handleAvatarRemove"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl" :src="imageUrl" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="应用文件" prop="app_files">
          <el-upload
            drag
            :action="`${window.location.protocol}//${window.location.host}/api/v1/evm_store/upload`"
            :on-remove="handleRemove"
wanli's avatar
wanli committed
133
            :on-success="handleUploadSuccess"
wanli's avatar
wanli committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147
            multiple
            name="binfile"
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处,或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              .evue和资源文件
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
wanli's avatar
wanli committed
148 149 150
        <el-button type="primary" size="medium" plain @click="submitForm('post')">提交</el-button>
        <el-button type="success" size="medium" plain @click="onReset('form')">重置</el-button>
        <el-button size="medium" @click="dialogVisible = false">关闭</el-button>
wanli's avatar
wanli committed
151 152
      </div>
    </el-dialog>
wanli's avatar
wanli committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    <el-dialog title="添加系统页面" :visible.sync="frameworkDialog">
        <el-form :model="form" label-width="100px">
            <el-form-item label="页面名称">
                <el-input v-model="framework.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="页面路径">
                <el-input v-model="framework.url" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="活动描述">
                <el-input v-model="framework.desc" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="活动类型">
                <el-input v-model="framework.type" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="资源文件" prop="app_icon">
                <el-upload
                    drag
                    multiple
                    name="binfile"
                    :action="`${window.location.protocol}//${window.location.host}/api/v1/evm_store/upload`"
                    :on-remove="handleFrameworkRemove"
                    :on-success="handleFrameworkSuccess"
                    :file-list="fileList"
                >
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
                    <div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过500kb</div>
                </el-upload>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="frameworkDialog = false">取 消</el-button>
            <el-button type="primary" @click="addFramework">确 定</el-button>
        </div>
    </el-dialog>
wanli's avatar
wanli committed
188 189 190
  </div>
</template>
<script>
wanli's avatar
wanli committed
191
import { getAppsList, deleteApp, addApp, updateApp, buildApp, addFramework } from "@/api/app-store";
wanli's avatar
wanli committed
192
import { mapTrim, checkURL } from "@/utils/index";
wanli's avatar
wanli committed
193 194 195 196 197 198 199 200

export default {
  name: "AppIndex",
  data() {
    return {
      imageUrl: "",
      total: 0,
      list: [],
wanli's avatar
wanli committed
201
      fileList: [],
wanli's avatar
wanli committed
202 203 204 205 206 207 208
      isLoading: false,
      form: {
        uuid: null,
        name: null,
        pagesize: 15,
        pagenum: 1,
      },
wanli's avatar
wanli committed
209 210 211 212 213 214 215 216 217
      framework: {
          name: null,
          url: null,
          desc: null,
          type: null,
          assets: {
              files: []
          }
      },
wanli's avatar
wanli committed
218 219
      currentIndex: 0,
      currentValue: null,
wanli's avatar
wanli committed
220
      frameworkDialog: false,
wanli's avatar
wanli committed
221 222 223 224 225
      dialogTitle: "",
      dialogVisible: false,
      post: {
        app_name: null,
        app_version: null,
wanli's avatar
wanli committed
226 227 228
        app_icon: null,
        app_url: null,
        category: null,
wanli's avatar
wanli committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
        app_desc: null,
        app_files: [],
      },
    };
  },
  computed: {
    window: () => window,
  },
  methods: {
    fetchData(params) {
      this.isLoading = true;
      getAppsList(params)
        .then((res) => {
          this.total = res.count;
          this.list = res.data;
        })
        .catch((err) => {
          // this.$message.error(err.message)
          console.log(err.message);
        })
        .finally(() => {
          this.isLoading = false;
        });
    },
    handleSizeChange(e) {
      this.form.pagesize = e;
      this.fetchData(mapTrim(this.form));
    },
    handleCurrentChange(e) {
      this.form.pagenum = e;
      this.fetchData(mapTrim(this.form));
    },
    handleBuild(index, row) {
wanli's avatar
wanli committed
262
        console.log(index)
wanli's avatar
wanli committed
263
        buildApp(row.uuid).then(res => {
wanli's avatar
wanli committed
264
            this.$message.success(res.message)
wanli's avatar
wanli committed
265 266
        }).catch(err => {
            console.log(err)
wanli's avatar
wanli committed
267
            this.$message.error(err.message)
wanli's avatar
wanli committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
        })
    },
    handleEdit(index, row) {
      this.post = Object.assign(row);
      this.currentIndex = index;
      this.currentValue = row;
      this.dialogTitle = "编辑";
      this.dialogVisible = true;
    },
    handleDelete(index, row) {
      this.$alert(
        "您确定要删除么?删除操作将不可恢复。如需取消操作,请点击右上角关闭按钮。",
        "删除提醒",
        {
          confirmButtonText: "确定",
          callback: (action) => {
            if (action == "confirm")
              deleteApp(row.uuid)
                .then((res) => {
                  console.log(res);
                  this.total -= 1;
                  this.$delete(this.list, index);
                  this.$message({
                    type: "success",
                    message: `成功删除第${index}行`,
                  });
                })
                .catch((err) => {
                  this.$message.error(err.message);
                });
          },
        }
      );
    },
wanli's avatar
wanli committed
302 303 304 305 306 307
    handleUploadSuccess(res) {
        if (res.code == 200) {
            if (!checkURL(res.data.filepath))
                res.data.filepath = `${window.location.origin}/${res.data.filepath}`
            this.post.app_files.push(res.data)
        }
wanli's avatar
wanli committed
308 309
    },
    handleAvatarSuccess(res, file) {
wanli's avatar
wanli committed
310 311 312
        if (res.code == 200) {
            if (!checkURL(res.data.filepath))
                res.data.filepath = `${window.location.origin}/${res.data.filepath}`
wanli's avatar
wanli committed
313
            this.post.app_icon = res.data
wanli's avatar
wanli committed
314
        }
wanli's avatar
wanli committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
        this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload() {
        // const isJPG = file.type === "image/jpeg";
        // const isLt2M = file.size / 1024 / 1024 < 2;

        // if (!isJPG) {
        //     this.$message.error("上传头像图片只能是 JPG 格式!");
        // }
        // if (!isLt2M) {
        //     this.$message.error("上传头像图片大小不能超过 2MB!");
        // }
        // return isJPG && isLt2M;
        return true;
    },
    handleAvatarRemove(file) {
        console.log(file);
        this.imageUrl = null;
    },
    handleRemove(file) {
        for(let i = 0; i < this.post.app_files.length; i++) {
            if (this.post.app_files[i].uuid == file.response.data.uuid) {
                this.post.app_files.splice(i, 1);
                break;
            }
        }
        console.log(file);
    },
wanli's avatar
wanli committed
343 344 345 346 347 348
    handleFrameworkRemove() {

    },
    handleFrameworkSuccess(res) {
        this.framework.assets.files.push(res.data)
    },
wanli's avatar
wanli committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        let result = true;
        if (valid) {
          if (this.dialogTitle === "添加")
            addApp(mapTrim(this.post))
              .then((res) => {
                console.log(res);
                this.$message({ type: "success", message: "添加成功" });
                this.fetchData(mapTrim(this.form));
              })
              .catch((err) => {
                this.$message.error(err.message);
              });
          else if (this.dialogTitle === "编辑")
            updateApp(this.currentValue.uuid, this.post)
              .then((res) => {
                console.log(res);
                // this.$set(this.list, this.currentIndex, Object.assign(this.currentValue, tmp))
                this.$message({ type: "success", message: "更新成功" });
                this.fetchData(mapTrim(this.form));
              })
              .catch((err) => {
                this.$message.error(err.message);
              });
        } else {
          result = false;
        }
        this.dialogVisible = false;
        return result;
      });
    },
wanli's avatar
wanli committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394
    submitFramework() {

    },
    addFramework() {
        addFramework(this.framework).then(res => {
            this.$message.success(res.message)
            this.frameworkDialog = false
        }).catch(err => {
            this.$message.error(err.message)
        })
    },
    onAddFramework() {
        this.frameworkDialog = true;
    },
wanli's avatar
wanli committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
    onAdd() {
      this.dialogTitle = "添加";
      this.dialogVisible = true;
    },
    onSubmit() {
      this.form.pagenum = 1;
      this.form.pagesize = 15;
      this.fetchData(mapTrim(this.form));
    },
    onReset(formName) {
      this.$refs[formName].resetFields();
      this.form.pagesize = 15;
      this.form.pagenum = 1;
      this.fetchData(mapTrim(this.form));
    },
  },
  mounted() {},
  created() {
    this.fetchData(mapTrim(this.form));
  },
};
</script>
<style lang="less" scoped>
.app-container {
  & > div.page-wrapper {
    margin: 10px 0px;
  }
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>