index.vue 7.28 KB
<template>
  <div class="home-project">
    <h2>{{ $route.query.classify }} 分类项目</h2>
    <a-list item-layout="horizontal" :data-source="projectData">
      <a-list-item slot="renderItem" slot-scope="item">
        <a-list-item-meta>
          <!-- <a slot="title" href="https://www.antdv.com/">{{ item.title }}</a> -->
          <a-avatar slot="avatar" :src="projectImgUrl" />
        </a-list-item-meta>
        <div>
          <a-descriptions :title="item.project_title" :bordered="false">
            <a-descriptions-item label="开发人员">
              {{ item.developer_name }}
            </a-descriptions-item>
            <a-descriptions-item label="测试项目地址">
              <a
                :href="item.test_url"
                target="_blank"
                rel="noopener noreferrer"
                >{{ item.test_url }}</a
              >
            </a-descriptions-item>
            <a-descriptions-item label="生产项目地址">
              <a
                :href="item.test_url"
                target="_blank"
                rel="noopener noreferrer"
                >{{ item.product_url }}</a
              >
            </a-descriptions-item>
            <a-descriptions-item label="使用技术">
              {{ item.technology }}
            </a-descriptions-item>
            <a-descriptions-item label="配置名称">
              {{ item.config_name }}
            </a-descriptions-item>
            <a-descriptions-item label="git地址">
              <a
                :href="item.git_url"
                target="_blank"
                rel="noopener noreferrer"
                >{{ item.git_url }}</a
              >
            </a-descriptions-item>
            <a-descriptions-item label="git提交信息">
              <!-- <a
                :href="item.git_commit"
                target="_blank"
                rel="noopener noreferrer"
                >{{ item.git_commit }}</a
              > -->
              <a-button type="link" @click="checkGitLog(item)">
                查看git提交信息
              </a-button>
            </a-descriptions-item>
            <a-descriptions-item label="git项目ID">
              <a-popover title="什么是git ID">
                <template slot="content">
                  <p>1.进入git仓库项目设置</p>
                  <p>2.查看 Project ID</p>
                </template>
                {{ item.git_id }} <a-icon type="question" />
              </a-popover>
            </a-descriptions-item>
          </a-descriptions>
        </div>
        <a slot="actions" @click="editFn(item)">编辑</a>
        <a slot="actions" @click="commentsFn(item)">评论</a>
        <a slot="actions" @click="delFn(item)">删除</a>
        <template slot="actions">
          <a-select
            size="small"
            v-model="item.classify"
            @select="handleSelect(item)"
          >
            <!-- @change="handleChange(item)" -->
            <a-select-option
              v-for="classitem in classifyData"
              :key="classitem.id"
              :value="classitem.classify"
            >
              {{ classitem.classify }}
            </a-select-option>
          </a-select>
        </template>
      </a-list-item>
    </a-list>
    <div class="icon-anticons" @click="add">
      <a-icon type="plus-circle" theme="filled" />
    </div>
  </div>
</template>
<script>
const data = [
  // {
  //   id: 1,
  //   project_title: "广联运营平台",
  //   project_description: "广联运营平台",
  //   developer_name: "胡悦、陈婉清",
  //   config_name: "/admin_common",
  //   test_url: "http://sso.test.glsx.com.cn/#/login",
  //   product_url: "http://sso.glsx.com.cn/#/login",
  //   technology: "vue",
  //   git_url: "http://giturl.com/",
  //   git_id: 173,
  //   classify: "other",
  // },
  // {
  //   id: 2,
  //   project_title: "账户管理",
  //   project_description: "商户、角色、员工管理",
  //   developer_name: "胡悦、陈婉清",
  //   config_name: "/glsx-oss-account-config",
  //   test_url: "http://glsx-account-merchants.test.glsx.com.cn",
  //   product_url: "http://glsx-account.glsx.com.cn",
  //   technology: "vue",
  //   git_url: "http://giturl.com/",
  //   git_id: 173,
  //   classify: "other",
  // },
];
import projectImgUrl from "@/assets/project.jpg";
// import { getQueryVariable } from "@/utils/index";
export default {
  name: "Home",
  data() {
    return {
      projectData: data,
      projectImgUrl,
      classifyData: [],
      // selectClassify: "", //选中的分类
    };
  },
  mounted() {
    this.getList();
    this.getClassifyList();
  },
  methods: {
    getList() {
      const classify = this.$route.query.classify;
      this.api.project.getList(classify).then((res) => {
        // console.log(res);
        this.projectData = res;
      });
    },
    //设置 项目分类
    setClassifyFn() {
      const classify = this.$route.query.classify;

      sessionStorage.setItem("classify", classify);
    },
    add() {
      this.to("HomeAdd");
      this.setClassifyFn();
    },
    editFn(item) {
      this.to("HomeAdd", item);
      this.setClassifyFn();
    },
    commentsFn(item) {
      // this.to("Record", comments);
      this.$router.push({
        name: "Record",
        query: { id: item.id, title: item.project_title },
      });
    },
    delFn(item) {
      let that = this;
      this.$confirm({
        title: "您确认删除吗?",
        onOk() {
          that.delApiFn(item);
        },
        onCancel() {},
        okText: "确认",
        cancelText: "取消",
      });
    },
    delApiFn(item) {
      this.api.project.delete({ id: item.id }).then((res) => {
        if (res.id) {
          this.$message.success("删除成功");
          this.getList();
        } else {
          this.$message.error("删除失败");
        }
      });
    },
    checkGitLog(item) {
      if (!item.git_id) {
        return this.$message.error("请填写gitlab项目id");
      }
      // console.log('item: ', item);
      this.$router.push({ name: "GitLog", query: { projectId: item.git_id } });
    },
    //h获取全部的分类
    getClassifyList() {
      this.api.classify.getList().then((res) => {
        console.log(res);
        this.classifyData = res;
      });
    },
    //移动项目,选中某个分类
    handleSelect(item) {
      console.log("item: ", item);
      const that = this;
      this.$confirm({
        title: "您确定要移动项目?",
        content: `您确定要移动项目到 ${item.classify} 分类?`,
        onOk() {
          //编辑
          that.api.project.update(item).then((res) => {
            // console.log("res: ", res);
            if (res.id) {
              that.$message.success("移动成功");
              //重新获取列表
              that.getList();
            } else {
              that.$message.error("移动失败");
            }
          });
        },
        onCancel() {},
        okText: "确认",
        cancelText: "取消",
      });
    },
  },
};
</script>
<style lang="scss">
.home-project {
  padding: 20px;
  .ant-list-item {
    padding: 10px;
  }
  .ant-select {
    width: 90px !important;
  }
}
.ant-list-split .ant-list-item {
  transition: all 0.3s;
}
.ant-list-split .ant-list-item:hover {
  border-color: rgba(0, 0, 0, 0.09);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);
}
</style>