<!--
@ 作者: 袁纪菲
@ 时间: 2024.4.16
@ 备注: 应用管理
-->
<script lang="ts" setup>
import editpage from './editpage.vue';
import { ref , onMounted } from 'vue';
import { useRouter } from 'vue-router';

//页面跳转
const router = useRouter();
const goToCreatePage = () => {
  try {
    router.push({ name: 'create' });
  } catch (error) {
    console.error("导航到创建页面时发生错误:", error);
  }
};
const dialogRefedit = ref(false);
interface cardDatas {
    id: number;
    name: string;
    icon: string;
}
//初始化应用卡片数据
const cardData = ref<cardDatas[]>([]);
const emits = defineEmits(["update:Visible", "data"]);

onMounted(() => {
    if (!cardData.value.length) {
    for (let i = 0; i < 9; i++) {
        cardData.value.push({
            id: i,
            name: '标题' + i,
            icon: 'https://img.zcool.cn/community/01f3fb5a66a75ea80120a123a9f582.jpg@2o.jpg'
        });
    }
    }
});
//编辑应用
const showEditPage = (index: number) => {
    dialogRefedit.value = true;
    editpage.value.cardData = cardData.value[index];
    editpage.value.onSubmit = handleEdit;
};
//编辑应用数据的接受与处理
const handleEdit = (newCard: cardDatas) => {
    cardData.value.splice(0, 1, newCard);
};
//删除卡片
const deleteCard = (index: number) => {
    cardData.value.splice(index, 1);
};
</script>
<template>
<<<<<<< HEAD
  <cardadd v-model:visible="drawerRefadd" :keyval="props.visible" @data="handleNewCard"/>
  <cardedit v-model:visible="drawerRefedit" :keyval="props.visible" @data="handleNewCard"/>
  <el-row :gutter="10">
    <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
        <div class="grid-content ep-bg-purple" >
          <el-card class="cardlarge">
            <template #header>
              <div class="cardhead-large">
                  <el-row class="block-col-2">
                    <el-col style="text-align: right;">
                      <el-dropdown>
                        <span class="el-dropdown-link">
                          <el-icon><MoreFilled /></el-icon>
                        </span>
                        <template #dropdown>
                          <el-dropdown-menu>
                            <el-dropdown-item @click="opencardadd" >添加</el-dropdown-item>
                            <el-dropdown-item >编辑</el-dropdown-item>
                            <el-dropdown-item >删除</el-dropdown-item>
                          </el-dropdown-menu>
                        </template>
                      </el-dropdown>
                    </el-col>
                    <el-col style="text-align: left;">
                      <span>标题一</span>
                    </el-col>
                  </el-row>
              </div>
            </template>
            <div class="grid-content ep-bg-purple" >
              <el-row :gutter="10" >
                <el-col v-for="(card, index) in cardData" :key="card.id" :xs="8" :sm="12" :md="8" :lg="8" :xl="8">
                      <el-card class="cardpattern">
                        <img
                       
                        
                          title="示例图片"
                          class="picture"
                        />
                          <div class="cardhead">
                          <span>{{ card.name }}</span>
                          </div>
                          <div class="bottom">
                            <el-button size="small" circle class="button" :icon="View"></el-button>
                            <el-button size="small" circle class="button" :icon="Edit" @click="() => opencardedit(index)"></el-button>
                            <el-button size="small" circle class="button" :icon="Delete" @click="() => deleteCard(index)"></el-button>
                          </div>
                      </el-card>
                </el-col>
              </el-row>
            </div>
          </el-card>
        </div>
    </el-col>
  </el-row>

<!-- 分页 -->
  <div class="example-pagination-block">
    <div class="example-demonstration"></div>
    <el-pagination layout="prev, pager, next" :total="50" />
=======
  <editpage v-model:Visible="dialogRefedit" @data="handleEdit" />
  <div class="common-layout">
    <el-container>
      <el-container>
        <el-main class="layout-content">
          <el-header class="content-header">
              <el-button class="create-btn" @click="goToCreatePage">
                  <el-icon><Plus /></el-icon>
                  新建应用
              </el-button>
          </el-header>
          <el-main>
              <el-scrollbar class="scrollbar">
                  <div class="xiangying">
                      <el-col v-for="(card) in cardData" :key="card.id">
                          <el-card class="cardpattern" shadow="hover" >
                              <div class="button">
                                <img :src="card.icon" class="picture" />
                                <span>自定义卡片</span>
                                <el-icon class="star">
                                    <Star />
                                </el-icon>
                                <el-dropdown class="xiala" trigger="click">
                                    <el-icon>
                                        <MoreFilled />
                                    </el-icon>
                                    <template #dropdown>
                                        <el-dropdown-menu>
                                            <el-dropdown-item @click = "() => showEditPage">编辑应用</el-dropdown-item>
                                            <el-dropdown-item @click = "() => deleteCard">删除</el-dropdown-item>
                                        </el-dropdown-menu>
                                    </template>
                                </el-dropdown>
                              </div>
                              <div class="cardhead">
                                  <span>{{ card.name }}</span>
                              </div>
                          </el-card>
                      </el-col>
                  </div>
              </el-scrollbar>
          </el-main>
        </el-main>
      </el-container>
    </el-container>
>>>>>>> yjf_v3
  </div>
</template>
<style scoped>
.common-layout {
    width: 100%;
    height: 100%;
    .el-container {
      height: 100%;
    /* 不折叠的时候宽度是200px，折叠的时候宽度自适应 */
    }
  }
  svg {
    width: 1.5em;
    margin-right: 5px;
  }
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-aside {
  width: auto;
}
.el-menu-vertical-demo {
  border-right: none;
  margin-top: 0;
  height: 100%;
  background-color: #586177;
  color: #fff;
}
.el-menu-item {
  color: #ffffff;
}
/* 侧边栏标题 */
.side-header {
  height: 64px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* 右侧上方标题 */
.up-header {
  display: flex;
  align-items : center;
  justify-content:left;
  background-color: #fff;
  padding: 0;
}
/* 缩放侧边栏按钮 */
.trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
}
.el-main {
  overflow-y: auto;
  padding-right: 0; /* 取消内外边距以免影响滚动区域 */
}
/* 内容框 */
.layout-content{
    padding: 15px;
    background: #f5f5f5;
    min-height: 280px;
}
/* 新建按钮框 */
.content-header {
  display: flex;
  justify-content: space-between;
  text-align: right; 
  font-size: 12px;
  height: 40px;
}
/* 新建按钮 */
.create-btn {
    margin-right: 10px;
    background-color: #1090ff;
    color: #ffffff;
}
/* 卡片整体所在区域 */
.scrollbar{
    height: 700px;
    overflow-y: auto; /* 自动显示垂直滚动条 */
    margin-right: 10px;
    box-sizing: border-box; /* 保证高度计算包含内边距和边框 */
    
    /* 当内容不够一屏时，禁用滚动条 */
    &::-webkit-scrollbar {
        width: 0;
        height: 0;
    }
}
/* 内容部分卡片响应式 */
.xiangying {
    display: grid;
    grid-auto-rows: minmax(160px, auto); /* 或者指定最大高度 */
    grid-gap: 1px;
    grid-template-columns: repeat(auto-fit, 230px);
    overflow-y: auto; /* 添加此行以允许卡片区域内部内容滚动 */
}
/* 卡片 */
.cardpattern {
    padding: 0px;
    margin-bottom: 10px;
    width: 220px;
    height: 150px;
    transition: all 0.3s ease;
}

/* 卡片标题 */
.cardhead {
    margin-top: 50px;
    font-size: 18px;
    color: #000000;
    font-weight: 500;
    text-align: left;
    font-family: PingFangSC-Regular;
    line-height: 20px;
}
/* 收藏按钮与下拉框区域 */
.button {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 3px; 
}
/* 收藏按钮 */
.star {
    font-size: 20px;
    margin-right: -5px;
}

/* 占位元素 */
.placeholder {
    height:14px;
    /* 设置为图标按钮组的高度 */
    width:100%;
    /* 设置为图标按钮组的宽度 */
    visibility: hidden;
    /* 或者 opacity: 0; 保证不会影响布局但不可见 */
    pointer-events: none;
    /* 防止此元素捕获鼠标事件 */
}
/* 图片 */
.picture {
    width: 3cap;
    margin: 1px;
}

</style>
