|
|
@@ -4,11 +4,11 @@
|
|
|
<div v-show="showSearch" class="mb-[20px]">
|
|
|
<el-card shadow="hover">
|
|
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
|
|
- <el-form-item label="盲注结构名称" prop="name">
|
|
|
- <el-input v-model="queryParams.name" placeholder="请输入盲注结构名称,如:Standard, Turbo" clearable @keyup.enter="handleQuery" />
|
|
|
+ <el-form-item label="名称" prop="name">
|
|
|
+ <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter="handleQuery" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="描述信息" prop="description">
|
|
|
- <el-input v-model="queryParams.description" placeholder="请输入描述信息" clearable @keyup.enter="handleQuery" />
|
|
|
+ <el-form-item label="备注" prop="description">
|
|
|
+ <el-input v-model="queryParams.description" placeholder="请输入备注" clearable @keyup.enter="handleQuery" />
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
|
|
@@ -23,7 +23,7 @@
|
|
|
<template #header>
|
|
|
<el-row :gutter="10" class="mb8">
|
|
|
<el-col :span="1.5">
|
|
|
- <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['business:structures:add']">新增</el-button>
|
|
|
+ <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['business:structures:add']">新增盲注表</el-button>
|
|
|
</el-col>
|
|
|
<el-col :span="1.5">
|
|
|
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['business:structures:edit']"
|
|
|
@@ -45,18 +45,28 @@
|
|
|
<el-table v-loading="loading" border :data="structuresList" @selection-change="handleSelectionChange">
|
|
|
<el-table-column type="selection" width="55" align="center" />
|
|
|
<el-table-column label="id" align="center" prop="id" v-if="false" />
|
|
|
- <el-table-column label="盲注结构名称" align="center" prop="name" />
|
|
|
- <el-table-column label="描述信息" align="center" prop="description" />
|
|
|
+ <el-table-column label="名称" align="center" prop="name" />
|
|
|
+ <!-- 新增列:盲注等级 -->
|
|
|
+ <el-table-column label="预览" align="center" width="150">
|
|
|
+ <template #default="scope">
|
|
|
+ <span class="level-link" @click="handleViewLevels(scope.row)" style="color: blue; cursor: pointer; text-decoration: underline">
|
|
|
+ {{ formatBlindLevel(scope.row.blindLevels) }}
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="备注" align="center" prop="description" />
|
|
|
<el-table-column label="创建时间" align="center" prop="createdAt" width="180">
|
|
|
<template #default="scope">
|
|
|
<span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="更新时间" align="center" prop="updatedAt" width="180">
|
|
|
+ <el-table-column label="创建人" align="center" prop="createName" />
|
|
|
+
|
|
|
+ <!-- <el-table-column label="更新时间" align="center" prop="updatedAt" width="180">
|
|
|
<template #default="scope">
|
|
|
<span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
|
|
</template>
|
|
|
- </el-table-column>
|
|
|
+ </el-table-column>-->
|
|
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
|
<template #default="scope">
|
|
|
<el-tooltip content="修改" placement="top">
|
|
|
@@ -65,7 +75,7 @@
|
|
|
<el-tooltip content="删除" placement="top">
|
|
|
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:structures:remove']"></el-button>
|
|
|
</el-tooltip>
|
|
|
- <el-tooltip content="查看等级" placement="top">
|
|
|
+ <el-tooltip content="查看" placement="top">
|
|
|
<el-button link type="primary" icon="View" @click="handleViewLevels(scope.row)" v-hasPermi="['business:levels:view']"></el-button>
|
|
|
</el-tooltip>
|
|
|
</template>
|
|
|
@@ -77,11 +87,38 @@
|
|
|
<!-- 添加或修改【请填写功能名称】对话框 -->
|
|
|
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
|
|
<el-form ref="structuresFormRef" :model="form" :rules="rules" label-width="120px">
|
|
|
- <el-form-item label="盲注结构名称" prop="name">
|
|
|
- <el-input v-model="form.name" placeholder="请输入盲注结构名称,如:Standard, Turbo" />
|
|
|
+ <el-form-item label="盲注表名称" prop="name">
|
|
|
+ <el-input v-model="form.name" placeholder="请输入盲注表名称" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="描述信息" prop="description">
|
|
|
- <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
|
|
|
+
|
|
|
+ <el-form-item label="上传盲注表" prop="file">
|
|
|
+ <div class="upload-container">
|
|
|
+ <el-upload
|
|
|
+ class="upload-demo"
|
|
|
+ action="#"
|
|
|
+ :on-change="handleFileChange"
|
|
|
+ :file-list="fileList"
|
|
|
+ :auto-upload="false"
|
|
|
+ :limit="1"
|
|
|
+ accept=".xlsx,.xls"
|
|
|
+ >
|
|
|
+ <template #trigger>
|
|
|
+ <el-button type="primary">点击上传盲注表</el-button>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template #tip>
|
|
|
+ <div class="el-upload__tip">
|
|
|
+ <el-link type="primary" @click="downloadTemplate"> <el-icon name="download" /> 模板下载 </el-link>
|
|
|
+ |
|
|
|
+ <el-button link @click="openPreview"> <el-icon name="document" /> 预 览 </el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-upload>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="盲注表备注" prop="description">
|
|
|
+ <el-input v-model="form.description" type="textarea" placeholder="请输入盲注表备注" />
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
<template #footer>
|
|
|
@@ -96,15 +133,42 @@
|
|
|
<!-- 使用 component 动态加载目标组件 -->
|
|
|
<levels-index :blind-structure-id="dialogParams.blindStructureId" :name="dialogParams.name" />
|
|
|
</el-dialog>
|
|
|
+
|
|
|
+ <!-- 预览弹窗 -->
|
|
|
+ <el-dialog title="预览" v-model="previewVisible" width="70%" append-to-body>
|
|
|
+ <div style="max-height: 500px; overflow-y: auto">
|
|
|
+ <el-table :data="previewData" border v-if="previewData.length > 0">
|
|
|
+ <!-- 使用动态表头 -->
|
|
|
+ <el-table-column v-for="(header, index) in previewHeaders" :key="index" :label="header">
|
|
|
+ <template #default="scope">
|
|
|
+ {{ scope.row[index] }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <p v-else>暂无数据可预览</p>
|
|
|
+ </div>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button @click="closePreview">关 闭</el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup name="Structures" lang="ts">
|
|
|
-import { listStructures, getStructures, delStructures, addStructures, updateStructures } from '@/api/system/business/structures';
|
|
|
+import {
|
|
|
+ listStructures,
|
|
|
+ getStructures,
|
|
|
+ delStructures,
|
|
|
+ addStructures,
|
|
|
+ updateStructures,
|
|
|
+ downloadImportTemplate
|
|
|
+} from '@/api/system/business/structures';
|
|
|
import { StructuresVO, StructuresQuery, StructuresForm } from '@/api/system/business/structures/types';
|
|
|
-import LevelsIndex from '@/views/system/business/levels/index.vue';
|
|
|
import { ref } from 'vue';
|
|
|
-
|
|
|
+import LevelsIndex from '@/views/system/business/levels/index.vue';
|
|
|
+import * as XLSX from 'xlsx';
|
|
|
// 控制 Dialog 是否显示
|
|
|
const levelsDialogVisible = ref(false);
|
|
|
|
|
|
@@ -136,7 +200,7 @@ const initFormData: StructuresForm = {
|
|
|
id: undefined,
|
|
|
name: undefined,
|
|
|
description: undefined,
|
|
|
- createdAt: undefined,
|
|
|
+ taskId: undefined,
|
|
|
updatedAt: undefined
|
|
|
};
|
|
|
const data = reactive<PageData<StructuresForm, StructuresQuery>>({
|
|
|
@@ -202,7 +266,7 @@ const handleSelectionChange = (selection: StructuresVO[]) => {
|
|
|
const handleAdd = () => {
|
|
|
reset();
|
|
|
dialog.visible = true;
|
|
|
- dialog.title = '添加【盲注结构】';
|
|
|
+ dialog.title = '新增盲注表';
|
|
|
};
|
|
|
|
|
|
/** 修改按钮操作 */
|
|
|
@@ -212,7 +276,8 @@ const handleUpdate = async (row?: StructuresVO) => {
|
|
|
const res = await getStructures(_id);
|
|
|
Object.assign(form.value, res.data);
|
|
|
dialog.visible = true;
|
|
|
- dialog.title = '修改【盲注结构】';
|
|
|
+ dialog.title = '修改盲注表';
|
|
|
+ initFormData.id = row?.id || ids.value[0];
|
|
|
};
|
|
|
|
|
|
/** 提交按钮 */
|
|
|
@@ -220,14 +285,36 @@ const submitForm = () => {
|
|
|
structuresFormRef.value?.validate(async (valid: boolean) => {
|
|
|
if (valid) {
|
|
|
buttonLoading.value = true;
|
|
|
- if (form.value.id) {
|
|
|
- await updateStructures(form.value).finally(() => (buttonLoading.value = false));
|
|
|
- } else {
|
|
|
- await addStructures(form.value).finally(() => (buttonLoading.value = false));
|
|
|
+
|
|
|
+ try {
|
|
|
+ const formData = new FormData();
|
|
|
+
|
|
|
+ // 如果有文件,添加文件字段
|
|
|
+ if (fileList.value.length > 0 && fileList.value[0].raw) {
|
|
|
+ formData.append('file', fileList.value[0].raw); // 假设后端接收字段名为 'file'
|
|
|
+ } else {
|
|
|
+ buttonLoading.value = false;
|
|
|
+ return proxy?.$modal.msgError('文件内容为空');
|
|
|
+ }
|
|
|
+ // 添加常规字段
|
|
|
+ formData.append('name', form.value.name || '');
|
|
|
+ formData.append('description', form.value.description || '');
|
|
|
+ // 发送请求
|
|
|
+ const uds = form.value.id;
|
|
|
+ if (uds) {
|
|
|
+ const json = JSON.stringify({ 'name': form.value.name || '', 'description': form.value.description || '', 'id': uds || '' });
|
|
|
+ const blob = new Blob([json], { type: 'application/json' });
|
|
|
+ formData.append('BlindStructuresBo', blob);
|
|
|
+ await updateStructures(formData).finally(() => (buttonLoading.value = false));
|
|
|
+ } else {
|
|
|
+ await addStructures(formData).finally(() => (buttonLoading.value = false));
|
|
|
+ }
|
|
|
+ proxy?.$modal.msgSuccess('操作成功');
|
|
|
+ dialog.visible = false;
|
|
|
+ await getList();
|
|
|
+ } catch (error) {
|
|
|
+ proxy?.$modal.msgError('提交失败');
|
|
|
}
|
|
|
- proxy?.$modal.msgSuccess('操作成功');
|
|
|
- dialog.visible = false;
|
|
|
- await getList();
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
@@ -255,9 +342,136 @@ onMounted(() => {
|
|
|
getList();
|
|
|
});
|
|
|
|
|
|
+const formatBlindLevel = (blindLevels) => {
|
|
|
+ if (!blindLevels || !Array.isArray(blindLevels) || blindLevels.length === 0) {
|
|
|
+ return '—';
|
|
|
+ }
|
|
|
+ const firstLevel = blindLevels[0];
|
|
|
+ return `${firstLevel.smallBlind}/${firstLevel.bigBlind} ${firstLevel.ante}`;
|
|
|
+};
|
|
|
+
|
|
|
const handleViewLevels = (row) => {
|
|
|
dialogParams.value.blindStructureId = row.id;
|
|
|
dialogParams.value.name = row.name;
|
|
|
levelsDialogVisible.value = true;
|
|
|
};
|
|
|
+
|
|
|
+const downloadTemplate = async () => {
|
|
|
+ try {
|
|
|
+ const response = await downloadImportTemplate();
|
|
|
+ // 创建 Blob 对象(直接使用 response)
|
|
|
+ // 确保正确获取 blob 数据
|
|
|
+ const blobData = new Blob([response.data || response], {
|
|
|
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
+ });
|
|
|
+ // 创建对象 URL
|
|
|
+ const urlBlob = window.URL.createObjectURL(blobData);
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = urlBlob;
|
|
|
+ link.setAttribute('download', '盲注结构模板.xlsx');
|
|
|
+ document.body.appendChild(link);
|
|
|
+
|
|
|
+ // 触发点击事件并稍作延迟,确保链接生效
|
|
|
+ link.click();
|
|
|
+ setTimeout(() => {
|
|
|
+ link.remove();
|
|
|
+ window.URL.revokeObjectURL(urlBlob);
|
|
|
+ }, 0);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Download error:', error); // 输出具体的错误信息
|
|
|
+ ElMessage.error('下载失败,请重试');
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const fileList = ref([]);
|
|
|
+const handleFileChange = (file) => {
|
|
|
+ const index = fileList.value.findIndex((f) => f.uid === file.uid);
|
|
|
+
|
|
|
+ // 如果文件不存在于列表中,则添加进去
|
|
|
+ if (index === -1) {
|
|
|
+ fileList.value.push(file);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+// 预览数据
|
|
|
+const previewData = ref<any[]>([]);
|
|
|
+const previewHeaders = ref<string[]>([]); // 新增表头数组
|
|
|
+const previewVisible = ref(false); // 控制预览弹窗
|
|
|
+// 打开预览弹窗并解析文件
|
|
|
+const openPreview = () => {
|
|
|
+ if (fileList.value.length === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const file = fileList.value[0].raw;
|
|
|
+ const isValidType = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'].includes(file.type);
|
|
|
+ if (!isValidType) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onload = (e) => {
|
|
|
+ const data = new Uint8Array(e.target?.result as ArrayBuffer);
|
|
|
+ const workbook = XLSX.read(data, { type: 'array' });
|
|
|
+
|
|
|
+ const sheetName = workbook.SheetNames[0];
|
|
|
+ const worksheet = workbook.Sheets[sheetName];
|
|
|
+
|
|
|
+ // 获取表头(第二行)
|
|
|
+ const headerRow = XLSX.utils.decode_range(worksheet['!ref']).e.r + 1;
|
|
|
+ const headerRange = `A2:E2`; // 假设最多5列
|
|
|
+ const headerCells = XLSX.utils.decode_range(headerRange);
|
|
|
+ previewHeaders.value = [];
|
|
|
+ for (let C = headerCells.s.c; C <= headerCells.e.c; ++C) {
|
|
|
+ const cellAddress = XLSX.utils.encode_cell({ c: C, r: 0 });
|
|
|
+ const cell = worksheet[cellAddress];
|
|
|
+ if (cell && cell.v) {
|
|
|
+ previewHeaders.value.push(cell.v.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取数据(第三行开始)
|
|
|
+ const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, range: 1 }); // 从第3行开始读取
|
|
|
+ previewData.value = jsonData;
|
|
|
+ previewVisible.value = true;
|
|
|
+ };
|
|
|
+ reader.readAsArrayBuffer(file);
|
|
|
+};
|
|
|
+
|
|
|
+// 关闭预览弹窗
|
|
|
+const closePreview = () => {
|
|
|
+ previewVisible.value = false;
|
|
|
+};
|
|
|
+/*const handleFileChange = async (file) => {
|
|
|
+ const index = fileList.value.findIndex((f) => f.uid === file.uid);
|
|
|
+
|
|
|
+ if (index === -1) {
|
|
|
+ // 如果文件不在列表中,则添加进去
|
|
|
+ fileList.value.push(file);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const rawFile = file.raw;
|
|
|
+ const res = await importData(rawFile);
|
|
|
+ if (res.code === 200) {
|
|
|
+ // 更新文件状态为成功
|
|
|
+ fileList.value[index] = {
|
|
|
+ ...file,
|
|
|
+ status: 'success',
|
|
|
+ response: res
|
|
|
+ };
|
|
|
+ ElMessage.success('上传成功');
|
|
|
+ } else {
|
|
|
+ throw new Error(res.msg);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ // 更新文件状态为失败
|
|
|
+ fileList.value[index] = {
|
|
|
+ ...file,
|
|
|
+ status: 'fail',
|
|
|
+ error: '上传失败'
|
|
|
+ };
|
|
|
+ ElMessage.error('上传失败,请重试');
|
|
|
+ }
|
|
|
+};*/
|
|
|
</script>
|