index.vue 9.92 KB
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="应用包名" prop="pkgName">
        <el-input
          v-model="queryParams.pkgName"
          placeholder="请输入应用包名"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应用版本号" prop="versionCode">
        <el-input
          v-model="queryParams.versionCode"
          placeholder="请输入应用版本号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应用版本名称" prop="versionName">
        <el-input
          v-model="queryParams.versionName"
          placeholder="请输入应用版本名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
        :col-data="colData"
        @selectData="selectData"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading=""
      :data="apkList"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="id"
        align="center"
        prop="id"
        width="55"
        v-if="colData[0].istrue"
      />
      <el-table-column
        label="应用包名"
        align="center"
        prop="pkgName"
        :show-overflow-tooltip="true"
        width="300"
        v-if="colData[1].istrue"
      />
      <el-table-column
        label="应用版本号"
        align="center"
        prop="versionCode"
        width="150"
        v-if="colData[2].istrue"
      />
      <el-table-column
        label="应用版本名称"
        align="center"
        prop="versionName"
        width="150"
        v-if="colData[3].istrue"
      />
      <el-table-column
        label="下载链接"
        align="center"
        prop="url"
        :show-overflow-tooltip="true"
        width="500"
        v-if="colData[4].istrue"
      />
      <el-table-column
        label="md5校验码"
        align="center"
        prop="md5"
        :show-overflow-tooltip="true"
        width="500"
        v-if="colData[5].istrue"
      />
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="140"
        v-if="colData[6].istrue"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改上传应用对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="应用包名" prop="pkgName">
          <el-input v-model="form.pkgName" placeholder="请输入应用包名" />
        </el-form-item>
        <el-form-item label="应用版本号" prop="versionCode">
          <el-input v-model="form.versionCode" placeholder="请输入应用版本号" />
        </el-form-item>
        <el-form-item label="应用版本名称" prop="versionName">
          <el-input
            v-model="form.versionName"
            placeholder="请输入应用版本名称"
          />
        </el-form-item>
        <el-form-item label="下载链接" prop="url">
          <el-input v-model="form.url" placeholder="请输入下载链接" />
        </el-form-item>
        <el-form-item label="MD5校验码" prop="md5">
          <el-input v-model="form.md5" placeholder="请输入MD5校验码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <import-dialog :show.sync="importShow" />
  </div>
</template>

<script>
import importDialog from "./dialog/importDialog";
import {
  listApkinfo,
  updateApkinfo,
  getApkInfoById,
} from "@/api/system/apkinfo";
export default {
  name: "Apkinfo",
  components: {
    importDialog,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // apk表格数据
      apkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //   导入对话框传值
      importShow: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pkgName: undefined,
        versionCode: undefined,
        versionName: undefined,
      },
      // 表单参数
      form: {},
      // 表格istrue属性存放列的状态
      colData: [
        { title: "id", istrue: false },
        { title: "应用包名", istrue: true },
        { title: "应用版本号", istrue: true },
        { title: "应用版本名称", istrue: true },
        { title: "下载链接", istrue: true },
        { title: "md5校验码", istrue: true },
        { title: "操作", istrue: true, disabled: true },
      ],
    };
  },
  created() {
    this.getList();
  },
  beforeUpdate() {
    this.$nextTick(() => {
      this.$refs["table"].doLayout();
    });
  },
  methods: {
    /** 查询apk信息列表 */
    getList() {
      this.loading = true;
      listApkinfo(this.queryParams).then((response) => {
        this.apkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        pkgName: undefined,
        versionCode: undefined,
        versionName: undefined,
        url: undefined,
        md5: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getApkInfoById(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改上传应用";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          updateConfig(this.form).then((response) => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const uploadIds = row.id || this.ids;
      this.$confirm(
        row.id
          ? "是否确认删除该条上传应用信息吗?"
          : "是否确认删除选中的" + this.ids.length + "条数据项?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delConfig(uploadIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    /** 导入按钮操作 */
    handleImport() {
      this.importShow = true;
    },
    /** 表格列显示隐藏切换操作 */
    selectData(val) {
      if (val) {
        this.colData.filter((i) => {
          if (val.indexOf(i.title) !== -1) {
            i.istrue = true;
          } else {
            i.istrue = false;
          }
        });
      }
    },
  },
};
</script>