大数据模型练习3

html 复制代码
<template>
  <div class="search-panel-container">
    <div class="panel-header">
      <el-popover placement="bottom-start" width="200" trigger="click">
        <template #reference>
          <el-button link>
            当前模板: {{ searchStore.currentTemplateName || '自定义' }}
            <el-icon class="el-icon--right"><ArrowDown /></el-icon>
          </el-button>
        </template>
        <ul class="template-dropdown-list">
          <li v-for="t in searchStore.templates" :key="t.id" @click="searchStore.applyTemplate(t)">
            {{ t.name }}
          </li>
          <li class="manage-btn" @click="showManager = true">
            <el-icon><Setting /></el-icon> 搜索模板管理
          </li>
        </ul>
      </el-popover>
    </div>

    <div class="search-form-wrapper">
      <el-form :inline="true" :model="searchStore.searchForm" class="demo-form-inline">
        <template v-for="field in searchStore.activeFieldsConfig" :key="field.key">
          <el-form-item :label="field.label">
            <el-input
              v-if="field.type === 'input'"
              v-model="searchStore.searchForm[field.key]"
              :placeholder="'Enter ' + field.label"
              clearable
            />

            <el-select
              v-else-if="field.type === 'select'"
              v-model="searchStore.searchForm[field.key]"
              :placeholder="'Select ' + field.label"
              clearable
              style="width: 180px"
            >
              <el-option
                v-for="opt in field.options"
                :key="opt.value"
                :label="opt.label"
                :value="opt.value"
              />
            </el-select>

            <el-date-picker
              v-else-if="field.type === 'date-picker'"
              v-model="searchStore.searchForm[field.key]"
              type="datetimerange"
              start-placeholder="Start"
              end-placeholder="End"
            />
          </el-form-item>
        </template>

        <el-form-item>
          <el-button type="primary" @click="handleSearch">查询</el-button>
          <el-button @click="handleReset">重置</el-button>
          <el-button
            v-if="canUpdateCurrentTemplate"
            type="warning"
            plain
            @click="handleUpdateTemplate"
          >
            更新模板
          </el-button>
          <el-button @click="showSaveDialog">存为模板</el-button>
          <el-button link type="primary" @click="showConfig = true"> 搜索项配置 </el-button>
        </el-form-item>
      </el-form>
    </div>

    <SearchConfigDialog v-model="showConfig" />
    <TemplateManagerDialog v-model="showManager" />
  </div>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue'
import { ArrowDown, Setting } from '@element-plus/icons-vue'
import { useSearchStore } from '../../stores/searchStore'
import { ElMessageBox, ElMessage } from 'element-plus'
// import SearchConfigDialog from './SearchConfigDialog.vue'
import SearchConfigDialog from './DiySearchConfigDialog.vue'
import TemplateManagerDialog from './TemplateManagerDialog.vue'

const searchStore = useSearchStore()
const showConfig = ref(false)
const showManager = ref(false)

onMounted(() => {
  searchStore.initData()
})

const handleSearch = () => {
  console.log('发起查询,参数:', JSON.parse(JSON.stringify(searchStore.searchForm)))
  ElMessage.info('查询请求已发出,请查看控制台')
}

const handleReset = () => {
  searchStore.searchForm = {}
}

const showSaveDialog = () => {
  ElMessageBox.prompt('请输入模板名称', '存为模板', {
    confirmButtonText: '保存',
    cancelButtonText: '取消',
  })
    .then(({ value }) => {
      if (value) {
        searchStore.saveAsTemplate(value)
      }
    })
    .catch(() => {})
}
const canUpdateCurrentTemplate = computed(() => {
  const tplId = searchStore.currentTemplateId
  if (!tplId) return false

  const tpl = searchStore.templates.find((t) => t.id === tplId)
  // 核心判断:存在且允许更新
  return tpl && tpl.permission && tpl.permission.canUpdate
})

const handleUpdateTemplate = async () => {
  try {
    await searchStore.updateCurrentTemplate()
    ElMessage.success('当前模板已更新')
  } catch (e) {
    ElMessage.error('更新失败')
  }
}
</script>

<style scoped>
.search-panel-container {
  background: #fff;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.panel-header {
  margin-bottom: 12px;
  border-bottom: 1px solid #eee;
  padding-bottom: 8px;
}
.template-dropdown-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.template-dropdown-list li {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f5f5f5;
}
.template-dropdown-list li:hover {
  background-color: #f0f9eb;
  color: #409eff;
}
.template-dropdown-list li.manage-btn {
  color: #409eff;
  border-top: 1px solid #eee;
  margin-top: 4px;
}
</style>
相关推荐
大雷神7 小时前
HarmonyOS智慧农业管理应用开发教程--高高种地-- 第24篇:学习中心 - 课程体系设计
大数据·学习·harmonyos
辰宇信息咨询13 小时前
3D自动光学检测(AOI)市场调研报告-发展趋势、机遇及竞争分析
大数据·数据分析
珠海西格15 小时前
“主动预防” vs “事后补救”:分布式光伏防逆流技术的代际革命,西格电力给出标准答案
大数据·运维·服务器·分布式·云计算·能源
创客匠人老蒋15 小时前
从数据库到智能体:教育企业如何构建自己的“数字大脑”?
大数据·人工智能·创客匠人
2501_9481201515 小时前
基于大数据的泄漏仪设备监控系统
大数据
Spey_Events16 小时前
星箭聚力启盛会,2026第二届商业航天产业发展大会暨商业航天展即将开幕!
大数据·人工智能
AC赳赳老秦17 小时前
专利附图说明:DeepSeek生成的专业技术描述与权利要求书细化
大数据·人工智能·kafka·区块链·数据库开发·数据库架构·deepseek
GeeLark17 小时前
#请输入你的标签内容
大数据·人工智能·自动化
智能相对论18 小时前
2万台?九识无人车车队规模靠谱吗?
大数据