大数据模型练习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>
相关推荐
德昂信息dataondemand16 小时前
BI项目中的主数据管理:如何确保跨部门数据一致性?
大数据
申通之声17 小时前
以体验和AI重构竞争力,申通要“构建生态共同体”
大数据·网络·人工智能·重构·交通物流
terry60017 小时前
2026图形验证码服务商横向测评|口碑、接入、安全选型全指南
java·大数据·人工智能·web安全·信息与通信·数据库架构
量化君也17 小时前
从回测到全自动实盘交易,全天候策略需要经历哪些改造?
大数据·人工智能·python·算法·金融
KaMeidebaby18 小时前
卡梅德生物技术快报|纳米抗体表达:分子生物学实操指南:噬菌体筛选与纳米抗体表达全流程技术拆解
大数据·人工智能·架构·spark·新浪微博
zhengzhouliuhaha18 小时前
智能医疗设备控费系统:以全院一体化管控,筑牢医疗资源“安全阀”
大数据·数据结构·人工智能·算法·安全·机器学习·软件需求
云边云科技_云网融合19 小时前
共建智能体互联网新生态|云边云科技亮相智能体互联网生态共建大会
大数据·人工智能
智能化咨询19 小时前
(105页PPT)智慧商圈解决方案(附下载方式)
大数据
2601_9549711319 小时前
大数据专业大类招生是什么模式,大一分流如何选方向
大数据
KKKlucifer19 小时前
数据分类分级产品排名解析:场景定制、规则联动、增量更新成核心能力
大数据·数据库·人工智能