index.vue 14.6 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 6 7 8
      <el-form-item
        ><el-button type="warning" @click="onAdd"
          >添加应用</el-button
        ></el-form-item
      >
wanli's avatar
wanli committed
9 10
      <!-- <el-form-item><el-button type="success" @click="onAddFramework">添加系统页面</el-button></el-form-item> -->
      <!-- <el-form-item><el-button type="success" @click="onAddFramework">上传JSON配置文件</el-button></el-form-item> -->
wanli's avatar
wanli committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    </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
32 33 34 35 36 37 38 39 40 41
      <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
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
      <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>
wanli's avatar
wanli committed
68 69 70 71 72 73
      <el-table-column
        label="操作"
        align="center"
        min-width="180"
        fixed="right"
      >
wanli's avatar
wanli committed
74
        <template slot-scope="scope">
wanli's avatar
wanli committed
75
          <el-button
wanli's avatar
wanli committed
76 77 78
            size="mini"
            type="primary"
            @click="handleBuild(scope.$index, scope.row)"
wanli's avatar
wanli committed
79
            >下载应用</el-button
wanli's avatar
wanli committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
          >
          <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
108
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%">
wanli's avatar
wanli committed
109 110 111 112 113 114 115
      <el-form
        :model="post"
        status-icon
        ref="post"
        size="medium"
        label-width="100px"
      >
wanli's avatar
wanli committed
116
        <el-form-item label="应用排序" prop="sort">
wanli's avatar
wanli committed
117 118 119 120 121
          <el-input
            type="number"
            v-model.number="post.sort"
            autocomplete="off"
          ></el-input>
wanli's avatar
wanli committed
122
        </el-form-item>
wanli's avatar
wanli committed
123
        <el-form-item label="应用名称" prop="app_name">
wanli's avatar
wanli committed
124 125 126 127 128
          <el-input
            type="text"
            v-model="post.app_name"
            autocomplete="off"
          ></el-input>
wanli's avatar
wanli committed
129 130
        </el-form-item>
        <el-form-item label="应用版本号" prop="app_version">
wanli's avatar
wanli committed
131 132 133 134 135
          <el-input
            type="text"
            v-model="post.app_version"
            autocomplete="off"
          ></el-input>
wanli's avatar
wanli committed
136 137
        </el-form-item>
        <el-form-item label="应用路径" prop="app_url">
wanli's avatar
wanli committed
138 139 140 141 142
          <el-input
            type="text"
            v-model="post.app_url"
            autocomplete="off"
          ></el-input>
wanli's avatar
wanli committed
143 144
        </el-form-item>
        <el-form-item label="应用类别" prop="category">
wanli's avatar
wanli committed
145 146 147 148 149
          <el-input
            type="text"
            v-model="post.category"
            autocomplete="off"
          ></el-input>
wanli's avatar
wanli committed
150 151
        </el-form-item>
        <el-form-item label="应用描述" prop="app_desc">
wanli's avatar
wanli committed
152 153 154 155 156
          <el-input
            type="text"
            v-model="post.app_desc"
            autocomplete="off"
          ></el-input>
wanli's avatar
wanli committed
157
        </el-form-item>
wanli's avatar
wanli committed
158
        <el-form-item label="应用Logo" prop="app_icon">
wanli's avatar
wanli committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
          <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
wanli's avatar
wanli committed
174
            ref="upload"
wanli's avatar
wanli committed
175 176
            :action="`${window.location.protocol}//${window.location.host}/api/v1/evm_store/upload`"
            :on-remove="handleRemove"
wanli's avatar
wanli committed
177
            :on-success="handleUploadSuccess"
wanli's avatar
wanli committed
178 179 180 181 182 183 184 185
            multiple
            name="binfile"
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处,或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
wanli's avatar
wanli committed
186 187 188
              <el-button size="small" type="text" @click="clear"
                >清空上传</el-button
              >
wanli's avatar
wanli committed
189 190 191 192 193
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
wanli's avatar
wanli committed
194 195 196 197 198 199 200 201 202 203
        <el-button
          type="primary"
          size="medium"
          plain
          @click="submitForm('post')"
          >提交</el-button
        >
        <el-button type="success" size="medium" plain @click="onReset('form')"
          >重置</el-button
        >
wanli's avatar
wanli committed
204
        <el-button size="medium" @click="dialogVisible = false">关闭</el-button>
wanli's avatar
wanli committed
205 206
      </div>
    </el-dialog>
wanli's avatar
wanli committed
207
    <el-dialog title="添加系统页面" :visible.sync="frameworkDialog">
wanli's avatar
wanli committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
      <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"
          >
            <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>
wanli's avatar
wanli committed
244
    </el-dialog>
wanli's avatar
wanli committed
245 246 247
  </div>
</template>
<script>
wanli's avatar
wanli committed
248 249 250 251 252 253 254 255
import {
  getAppsList,
  deleteApp,
  addApp,
  updateApp,
  getBuildApp,
  addFramework,
} from "@/api/app-store";
wanli's avatar
wanli committed
256
import { mapTrim, checkURL, download } from "@/utils/index";
wanli's avatar
wanli committed
257 258 259 260 261 262 263 264

export default {
  name: "AppIndex",
  data() {
    return {
      imageUrl: "",
      total: 0,
      list: [],
wanli's avatar
wanli committed
265
      fileList: [],
wanli's avatar
wanli committed
266 267 268 269 270 271 272
      isLoading: false,
      form: {
        uuid: null,
        name: null,
        pagesize: 15,
        pagenum: 1,
      },
wanli's avatar
wanli committed
273
      framework: {
wanli's avatar
wanli committed
274 275 276 277 278 279 280
        name: null,
        url: null,
        desc: null,
        type: null,
        assets: {
          files: [],
        },
wanli's avatar
wanli committed
281
      },
wanli's avatar
wanli committed
282 283
      currentIndex: 0,
      currentValue: null,
wanli's avatar
wanli committed
284
      frameworkDialog: false,
wanli's avatar
wanli committed
285 286 287
      dialogTitle: "",
      dialogVisible: false,
      post: {
wanli's avatar
wanli committed
288 289 290 291 292 293 294 295
        sort: 0,
        app_name: null,
        app_version: null,
        app_icon: null,
        app_url: null,
        category: null,
        app_desc: null,
        app_files: [],
wanli's avatar
wanli committed
296 297 298 299 300 301 302
      },
    };
  },
  computed: {
    window: () => window,
  },
  methods: {
wanli's avatar
wanli committed
303 304 305
    clear() {
      this.$refs.upload.clearFiles();
    },
wanli's avatar
wanli committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
    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) {
wanli's avatar
wanli committed
322 323
      this.form.pagesize = e;
      this.fetchData(mapTrim(this.form));
wanli's avatar
wanli committed
324 325
    },
    handleCurrentChange(e) {
wanli's avatar
wanli committed
326 327
      this.form.pagenum = e;
      this.fetchData(mapTrim(this.form));
wanli's avatar
wanli committed
328 329
    },
    handleBuild(index, row) {
wanli's avatar
wanli committed
330 331 332 333 334
      console.log(index);
      getBuildApp(row.uuid)
        .then((res) => {
          download(res.data.app_name, res.data.app_path);
          this.$message.success(res.message);
wanli's avatar
wanli committed
335
        })
wanli's avatar
wanli committed
336 337 338 339
        .catch((err) => {
          console.log(err);
          this.$message.error(err.message);
        });
wanli's avatar
wanli committed
340 341
    },
    handleEdit(index, row) {
wanli's avatar
wanli committed
342 343 344 345 346 347
      this.post = Object.assign(row);
      this.imageUrl = null;
      this.currentIndex = index;
      this.currentValue = row;
      this.dialogTitle = "编辑";
      this.dialogVisible = true;
wanli's avatar
wanli committed
348 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
    },
    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
374
    handleUploadSuccess(res) {
wanli's avatar
wanli committed
375 376 377 378 379
      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
380 381
    },
    handleAvatarSuccess(res, file) {
wanli's avatar
wanli committed
382 383 384 385 386 387
      if (res.code == 200) {
        if (!checkURL(res.data.filepath))
          res.data.filepath = `${window.location.origin}/${res.data.filepath}`;
        this.post.app_icon = res.data;
      }
      this.imageUrl = URL.createObjectURL(file.raw);
wanli's avatar
wanli committed
388 389
    },
    beforeAvatarUpload() {
wanli's avatar
wanli committed
390 391
      // const isJPG = file.type === "image/jpeg";
      // const isLt2M = file.size / 1024 / 1024 < 2;
wanli's avatar
wanli committed
392

wanli's avatar
wanli committed
393 394 395 396 397 398 399 400
      // if (!isJPG) {
      //     this.$message.error("上传头像图片只能是 JPG 格式!");
      // }
      // if (!isLt2M) {
      //     this.$message.error("上传头像图片大小不能超过 2MB!");
      // }
      // return isJPG && isLt2M;
      return true;
wanli's avatar
wanli committed
401 402
    },
    handleAvatarRemove(file) {
wanli's avatar
wanli committed
403 404
      console.log(file);
      this.imageUrl = null;
wanli's avatar
wanli committed
405 406
    },
    handleRemove(file) {
wanli's avatar
wanli committed
407 408 409 410
      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;
wanli's avatar
wanli committed
411
        }
wanli's avatar
wanli committed
412 413
      }
      console.log(file);
wanli's avatar
wanli committed
414
    },
wanli's avatar
wanli committed
415
    handleFrameworkRemove() {},
wanli's avatar
wanli committed
416
    handleFrameworkSuccess(res) {
wanli's avatar
wanli committed
417
      this.framework.assets.files.push(res.data);
wanli's avatar
wanli committed
418
    },
wanli's avatar
wanli committed
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 447 448 449
    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
450 451
    },
    addFramework() {
wanli's avatar
wanli committed
452 453 454 455
      addFramework(this.framework)
        .then((res) => {
          this.$message.success(res.message);
          this.frameworkDialog = false;
wanli's avatar
wanli committed
456
        })
wanli's avatar
wanli committed
457 458 459
        .catch((err) => {
          this.$message.error(err.message);
        });
wanli's avatar
wanli committed
460 461
    },
    onAddFramework() {
wanli's avatar
wanli committed
462
      this.frameworkDialog = true;
wanli's avatar
wanli committed
463
    },
wanli's avatar
wanli committed
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
    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>