fei
7 天以前 c50a874feed1ceceb18e0d42f95e4094eef98128
src/views/archiveManager/archiveMaterial/index.vue
@@ -14,7 +14,29 @@
    <el-row>
    <el-col :span="16">
          <el-form-item label="责任者" prop="creator">
            <el-input v-model="form.creator" placeholder="请输入责任者" />
            <div class="title-search-wrapper">
              <el-input
                v-model="form.creator"
                placeholder="请输入责任者"
                @input="handleCreatorInput"
                @focus="showCreatorSuggestions = true"
                @blur="handleCreatorBlur"
              />
              <!-- 下拉建议框 -->
              <div
                v-if="showCreatorSuggestions && creatorSuggestions.length > 0"
                class="title-suggestions"
              >
                <div
                  v-for="(item, index) in creatorSuggestions"
                  :key="index"
                  class="suggestion-item"
                  @mousedown="selectCreatorSuggestion(item)"
                >
                  {{ item }}
                </div>
              </div>
            </div>
          </el-form-item>
          </el-col>
  </el-row>
@@ -22,7 +44,29 @@
  <el-col :span="16">
          <el-form-item label="文件题名" prop="title">
            <el-input v-model="form.title" placeholder="请输入文件题名" />
            <div class="title-search-wrapper">
              <el-input
                v-model="form.title"
                placeholder="请输入文件题名"
                @input="handleTitleInput"
                @focus="showTitleSuggestions = true"
                @blur="handleTitleBlur"
              />
              <!-- 下拉建议框 -->
              <div
                v-if="showTitleSuggestions && titleSuggestions.length > 0"
                class="title-suggestions"
              >
                <div
                  v-for="(item, index) in titleSuggestions"
                  :key="index"
                  class="suggestion-item"
                  @mousedown="selectTitleSuggestion(item)"
                >
                  {{ item }}
                </div>
              </div>
            </div>
          </el-form-item>
    </el-col>
    </el-row>
@@ -43,6 +87,7 @@
          <el-select
            v-model="form.fileStyle"
            placeholder="请选择材料类型"
            @change="handleFileStyleChange"
          >
            <el-option
              v-for="item in fileStyleOptions"
@@ -197,7 +242,7 @@
      <el-row :gutter="12" class="mb8">
      <el-row :gutter="12" class="mb8 fixed-row">
        <el-col :span="1.5">
          <el-button
            type="primary"
@@ -226,6 +271,7 @@
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:materials:list']"
          >导出</el-button>
        </el-col>
@@ -571,9 +617,11 @@
      <el-form-item label="文件题名" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入文件题目"
          placeholder="请输入文件题名"
          clearable
          @keyup.enter.native="handleQuery"
          :validate-event="false"
          @blur="validateQueryTitle"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
@@ -586,7 +634,15 @@
          placeholder="请选择日期">
        </el-date-picker> -->
      </el-form-item>
      <el-form-item label="页号" prop="pageNumber">
      <el-form-item label="档案号" prop="fileNumber">
        <el-input
          v-model="queryParams.fileNumber"
          placeholder="请输入档案号(支持范围搜索,如:B1.3-05-2024-0001~0003)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    <!--  <el-form-item label="页号" prop="pageNumber">
        <el-col :span="8">
          <el-input
            v-model.number="queryParams.pageNumber"
@@ -606,7 +662,7 @@
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      </el-form-item> -->
     <el-form-item label="文字材料" prop="fileStyle">
          <el-select
            v-model="queryParams.fileStyle"
@@ -740,7 +796,7 @@
  </template>
  <script>
  import { listMaterials, enload, getMaterials, delMaterials, addMaterials, updateMaterials } from "@/api/system/materials"
  import { getFileCount,islegal, listMaterials, enload, getMaterials, delMaterials, addMaterials, updateMaterials } from "@/api/system/materials"
import { getToken } from '@/utils/auth'
import store from '@/store'
import { updateStatusById } from "@/api/system/records"
@@ -750,6 +806,11 @@
    name: "Materials",
    data() {
      return {
        // 记录元素初始位置和状态
  originalOffsetLeft: 0,
        originalWidth: 0,
            placeholderEl: null,
       importDialogVisible: false,
      fileList: [],
      uploadUrl:  process.env.VUE_APP_BASE_API +'/system/materials/upload/'+this.recordId, // 替换为实际的上传接口
@@ -819,6 +880,13 @@
        materialsList: [],
        // 弹出层标题
        title: "",
        // 文件题名搜索相关
        titleSuggestions: [], // 匹配的文件题名建议列表
        showTitleSuggestions: false, // 是否显示建议框
        titleSearchTimer: null, // 防抖定时器
        creatorSuggestions: [], // 匹配的责任人建议列表
        showCreatorSuggestions: false, // 是否显示责任人建议框
        creatorSearchTimer: null, // 责任人查询防抖定时器
        // 是否显示弹出层
        open: false,
        titles: "",
@@ -863,32 +931,71 @@
        // 表单校验
        rules: {
          creator: [
           // { required: true, message: "创建者不能为空", trigger: "blur" }
           // { required: true, message: "创建者不能为空", trigger: "blur" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          title: [
            { required: true, message: "案卷题名不能为空", trigger: "blur" }
            { required: true, message: "案卷题名不能为空", trigger: "blur" },
             { pattern: /^[^\\/:*?"<>丨]+$/, message: "文件名不能包含 \\\:*?<>丨 等特殊字符", trigger: "blur" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          date: [
          //  { required: true, message: "日期不能为空", trigger: "blur" },
            { pattern: /^\d{4}-\d{2}-\d{2}$/, message: "日期格式必须为yyyy-mm-dd", trigger: "blur" }
            { pattern: /^\d{4}-\d{2}-\d{2}$/, message: "日期格式必须为yyyy-mm-dd", trigger: "blur" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          pageNumber: [
            { required: true, message: "页号不能为空", trigger: "blur" },
            { type: 'number', message: '页号必须为数字类型', trigger: ['blur', 'change'] },
            { pattern: /^\d+$/, message: '请输入正整数', trigger: 'blur' }
            { pattern: /^[1-9]\d*$/, message: '请输入大于0的正整数', trigger: 'blur' },
            // { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          stage: [
            { required: true, message: "所处阶段不能为空", trigger: "change" }
            { required: true, message: "所处阶段不能为空", trigger: "change" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          fileStyle: [
            { required: true, message: "材料类型不能为空", trigger: "change" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          isAttachment: [
            { required: true, message: "是否为附件不能为空", trigger: "change" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          retentionPeriod: [
            { required: true, message: "保管期限不能为空", trigger: "change" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          isSensitive: [
            { required: true, message: "是否敏感不能为空", trigger: "change" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ],
          isCanceled: [
            { required: true, message: "是否注销不能为空", trigger: "change" },
            { max: 85, message: "最大长度为85个字符", trigger: "blur" }
          ]
        }
      }
    },
   mounted() {
     // 添加滚动事件监听
     window.addEventListener('scroll', this.handleScroll);
    // 改为监听keydown事件
    document.addEventListener('keydown', this.handleKeyDown)
  },
  beforeDestroy() {
    // 移除滚动事件监听
    document.removeEventListener('keydown', this.handleKeyDown)
    // 移除滚动事件监听
    window.removeEventListener('scroll', this.handleScroll);
    // 清理占位符
    if (this.placeholderEl && this.placeholderEl.parentNode) {
      this.placeholderEl.parentNode.removeChild(this.placeholderEl);
    }
  },
    created() {
      //const roleId = this.$route.params && this.$route.params.roleId
@@ -959,14 +1066,31 @@
        this.$modal.msgWarning('请先选择文件再上传')
        return
      }
      if(fileCount!==this.total)
      {
        this.$modal.msgWarning('请选择与记录数一致的文件或者修改对应的页码使其对应')
        return
      }
     // alert(this.recordId)
      //判断页号与上传上传的文件的页号是不是一一对应的
      // 执行上传
      this.$refs.upload.submit()
     islegal(this.recordId).then(response => {
       console.log(response.data)
       var res = response.data.res
       //alert(response.data.total)
       if(fileCount!==response.data.total)
       {
         this.$modal.msgWarning('请选择与记录数一致的文件')
         return
       }
       if(res)
       {
         // 执行上传
           this.$refs.upload.submit()
           this.getList()
       }
       else
       {
         this.$modal.msgError("页号不连续,请修改为连续正确的页号!")
       }
     })
    },
    clearFileList() {
      this.fileList = [];
@@ -997,7 +1121,22 @@
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true
        listMaterials(this.queryParams).then(response => {
        // 处理档案号搜索逻辑,包括范围搜索
        const queryParams = { ...this.queryParams }
        // 检查是否包含范围搜索符号
        if (queryParams.fileNumber && queryParams.fileNumber.includes('~')) {
          const rangeParts = queryParams.fileNumber.split('~')
          if (rangeParts.length === 2) {
            // 解析范围搜索参数
            // 保留原始fileNumber用于其他处理
            queryParams.fileNumberStart = rangeParts[0].trim()
            queryParams.fileNumberEnd = rangeParts[1].trim()
          }
        }
        listMaterials(queryParams).then(response => {
          console.log(response)
          this.materialsList = response.data.data
          this.total = response.data.total
@@ -1040,6 +1179,122 @@
        }
        this.resetForm("forms")
      },
      // 处理文件题名输入事件
      handleTitleInput() {
        // 清除之前的定时器(防抖)
        if (this.titleSearchTimer) {
          clearTimeout(this.titleSearchTimer);
        }
        // 当输入框为空时,清空建议列表
        if (!this.form.title.trim()) {
          this.titleSuggestions = [];
          return;
        }
        // 设置新的定时器,延迟执行查询
        this.titleSearchTimer = setTimeout(() => {
          this.searchTitleSuggestions();
        }, 300);
      },
      // 搜索文件题名建议
      searchTitleSuggestions() {
        // 使用现有的listMaterials API,传入title作为查询参数
        listMaterials(
       {
          title: this.form.title,
          pageSize: 10 // 限制返回数量
        }).then(response => {
          console.log(response.data.data)
        //  alert(23)
          // 提取并去重title字段
          const titles = response.data.data.map(item => item.title);
          // 去重处理
          this.titleSuggestions = [...new Set(titles)];
          // 显示建议框
          this.showTitleSuggestions = true;
        }).catch(() => {
          // 错误处理
          this.titleSuggestions = [];
        });
      },
      // 处理失焦事件
      handleTitleBlur() {
        // 延迟隐藏,以便可以点击选择建议项
        setTimeout(() => {
          this.showTitleSuggestions = false;
        }, 200);
      },
      // 选择建议项
      selectTitleSuggestion(title) {
        this.form.title = title;
        this.showTitleSuggestions = false;
      },
      // 处理责任人输入事件
      handleCreatorInput() {
        // 清除之前的定时器(防抖)
        if (this.creatorSearchTimer) {
          clearTimeout(this.creatorSearchTimer);
        }
        // 当输入框为空时,清空建议列表
        if (!this.form.creator.trim()) {
          this.creatorSuggestions = [];
          return;
        }
        // 设置新的定时器,延迟执行查询
        this.creatorSearchTimer = setTimeout(() => {
          this.searchCreatorSuggestions();
        }, 300);
      },
      // 搜索责任人建议
      searchCreatorSuggestions() {
        // 使用现有的listMaterials API,传入creator作为查询参数
        listMaterials(
        {
          creator: this.form.creator,
          pageSize: 10 // 限制返回数量
        }).then(response => {
          // 提取并去重creator字段
          const creators = response.data.data.map(item => item.creator).filter(Boolean);
          // 去重处理
          this.creatorSuggestions = [...new Set(creators)];
          // 显示建议框
          this.showCreatorSuggestions = true;
        }).catch(() => {
          // 错误处理
          this.creatorSuggestions = [];
        });
      },
      // 处理责任人输入框失焦事件
      handleCreatorBlur() {
        // 延迟隐藏,以便可以点击选择建议项
        setTimeout(() => {
          this.showCreatorSuggestions = false;
        }, 200);
      },
      // 选择责任人建议项
      selectCreatorSuggestion(creator) {
        this.form.creator = creator;
        this.showCreatorSuggestions = false;
      },
      // 处理材料类型变化
      handleFileStyleChange(value) {
        // 当选择'其他材料'时,清空页码字段
        if (value === '其他材料') {
          this.form.pageNumber = null;
        }
      },
      // 表单重置
      reset() {
        this.form = {
@@ -1072,8 +1327,24 @@
        }
        this.resetForm("form")
      },
      // 验证查询表单中的文件题名
      validateQueryTitle() {
        const illegalCharsPattern = /[\\/:*?<>丨]/;
        if (this.queryParams.title && illegalCharsPattern.test(this.queryParams.title)) {
          this.$message.error("文件名不能包含 \\:/:*?<>丨 等特殊字符");
          this.queryParams.title = this.queryParams.title.replace(illegalCharsPattern, '');
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        // 搜索前校验文件题名
        const illegalCharsPattern = /[\\/:*?<>丨]/;
        if (this.queryParams.title && illegalCharsPattern.test(this.queryParams.title)) {
          this.$message.error("文件名不能包含 \\:/:*?<>丨 等特殊字符");
          this.queryParams.title = this.queryParams.title.replace(illegalCharsPattern, '');
          return; // 阻止搜索,直到用户修正输入
        }
        this.queryParams.pageNum = 1
        this.getList()
      },
@@ -1218,11 +1489,25 @@
          this.$modal.msgSuccess("删除成功")
        }).catch(() => {})
      },
      /** 导出按钮操作 */
      /** 导出按钮操作 - 支持导出选中行或全部数据 */
      handleExport() {
        this.download('system/materials/export', {
          ...this.queryParams
        }, `materials_${new Date().getTime()}.xlsx`)
        // 判断是否有选中的行
        if (this.ids && this.ids.length > 0) {
          // 显示导出选中行的提示
          this.$message.info(`正在导出${this.ids.length}条选中的数据...`);
          // 导出选中的行数据
          this.download('system/materials/export', {
            ids: this.ids.join(','),
         //   exportType: 'selected'
          }, `materials_selected_${new Date().getTime()}.xlsx`)
        } else {
          // 显示导出全部数据的提示
          this.$message.info('正在导出符合当前查询条件的所有数据...');
          // 没有选中行时,导出当前查询条件的数据
          this.download('system/materials/export', {
            ...this.queryParams
          }, `materials_${new Date().getTime()}.xlsx`)
        }
      },
       /** 导入模板下载操作*/
@@ -1241,7 +1526,7 @@
  // }
  const formData = new FormData();
  formData.append('file', file);
 // formData.append('recordId', this.recordId)
  formData.append('recordId', this.recordId)
  // alert(this.recordId)
  console.log(file)
@@ -1293,13 +1578,112 @@
      }).catch(() => {})
    },
    }
    // 滚动事件处理
    handleScroll() {
      const fixedRow = document.querySelector('.fixed-row');
      if (!fixedRow) return;
      // 获取元素当前位置信息
      const rect = fixedRow.getBoundingClientRect();
      const parentRect = fixedRow.parentNode.getBoundingClientRect();
      // 检查元素是否应该进入悬浮状态
      if (rect.top <= 0) {
        // 只在不在floating状态时添加,避免重复操作
        if (!fixedRow.classList.contains('floating')) {
          // 记录元素原始的左偏移量(相对于父容器)
          this.originalOffsetLeft = rect.left - parentRect.left;
          // 记录元素的原始宽度
          this.originalWidth = rect.width;
          // 添加floating类,使元素固定在顶部
          fixedRow.classList.add('floating');
          // 设置固定位置时的样式,保持与原始布局一致
          fixedRow.style.left = this.originalOffsetLeft + 'px';
          fixedRow.style.width = this.originalWidth + 'px';
          // 添加临时占位符,防止页面布局跳动
          if (!this.placeholderEl) {
            this.placeholderEl = document.createElement('div');
            this.placeholderEl.style.height = rect.height + 'px';
            this.placeholderEl.style.marginBottom = '10px';
            this.placeholderEl.style.boxSizing = 'border-box';
            fixedRow.parentNode.insertBefore(this.placeholderEl, fixedRow.nextSibling);
          }
        }
      } else {
        // 当元素回到视口顶部以上时,移除悬浮状态,恢复到文档流中
        if (fixedRow.classList.contains('floating')) {
          // 移除floating类
          fixedRow.classList.remove('floating');
          // 重置样式,让浏览器使用原始样式
          fixedRow.style.left = '';
          fixedRow.style.width = '';
          // 移除占位符,让元素回到原始位置
          if (this.placeholderEl && this.placeholderEl.parentNode) {
            this.placeholderEl.parentNode.removeChild(this.placeholderEl);
            this.placeholderEl = null;
          }
        }
      }
    },
}
  }
  </script>
</script>
<style scoped>
.title-search-wrapper {
        position: relative;
        width: 100%;
      }
      .title-suggestions {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 1000;
        background-color: #fff;
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
        max-height: 200px;
        overflow-y: auto;
        margin-top: 4px;
      }
      .suggestion-item {
        padding: 10px 15px;
        cursor: pointer;
        transition: background-color 0.2s;
      }
      .suggestion-item:hover {
        background-color: #f5f7fa;
      }
.title-border {
  border-bottom: 1px solid #dcdfe6;
  padding-bottom: 10px;
  margin-bottom: 20px;
}
.fixed-row {
  position: static;
  z-index: 1000;
  background-color: #fff;
  padding: 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-bottom: 10px;
  box-sizing: border-box;
}
.fixed-row.floating {
  position: fixed;
  top: 0;
  z-index: 2000;
  padding: 10px;
  margin-bottom: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  background-color: #fff;
}
</style>