yxh
8 天以前 af4d8bc390626edb43198c05692ff4792ff3d1d1
报销单信息加载失败,请重试
已修改6个文件
357 ■■■■■ 文件已修改
src/main.js 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/fileNameCheck.js 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/money.js 261 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/project/fund/applyDetail/index.vue 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/project/fund/performancedetails/index.vue 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/project/travelexpenseapply/travelexpensedetail/index.vue 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main.js
@@ -153,7 +153,7 @@
Vue.config.productionTip = false
// 前端构建标识:用于确认浏览器实际加载的是哪一版代码
window.__APP_BUILD__ = '2026-11-12-MONEY-1'
window.__APP_BUILD__ = '2026-11-13-FIX-1'
const app = new Vue({
  el: '#app',
src/utils/fileNameCheck.js
@@ -1,8 +1,9 @@
/**
 * 报销单附件文件名规范校验(2026-11-03 调整)
 * 报销单附件文件名规范校验(2026-11-17 调整)
 *
 * 业务口径:
 *   1. 允许文件名不含中文;含中文/纯英文/数字均可
 *   1. 专家劳务费、伦理专家费:允许文件名不含中文;其他类型报销单 **必须含中文**
 *      (医院报销单审批要求:附件名要反映发票主要内容);含中文/纯英文/数字均可
 *   2. 去掉扩展名后的主干,按字符数计算不能超过 20 个字
 *   3. 不能包含空格及 / \ : * ? " < > | # % 等特殊字符
 *   4. 同一明细行内不能重名(比较时忽略扩展名大小写与首尾空格)
@@ -17,6 +18,9 @@
/** 主干(去扩展名)最大字符数 */
export const MAX_MAIN_LENGTH = 20;
/** 中文匹配(主干是否含中文) */
const RE_CHINESE = /[\u4e00-\u9fa5]/;
/** 非法字符:空格(含各类空白)+ / \ : * ? " < > | # % */
const RE_ILLEGAL = /[\s/\\:*?"<>|#%]/;
@@ -24,6 +28,9 @@
export const MSG_TOO_LONG = "为方便查验附件,附件名字长度不能超过20个字!";
export const MSG_ILLEGAL = '为方便查验附件,附件名不能包含空格及 / \\ : * ? " < > | # % 等特殊字符!';
export const MSG_DUPLICATE = "为方便查验附件,同一行内不能有重名的附件!";
/** 2026-11-17:非专家费/伦理专家费的报销单,附件名必须含中文 */
export const MSG_NEED_CHINESE =
  '附件名不符合医院报销单审批要求:名称须反映发票主要内容(需包含中文),如"2026年10月住院费"';
/**
 * 取主干(去掉最后一个扩展名)
@@ -39,9 +46,11 @@
/**
 * 单个文件名校验
 * @param {string} fileName 原始文件名
 * @param {{requireChinese?: boolean}} [options] requireChinese=true 时主干必须含中文
 * @returns {{ok: boolean, msg: string, main: string}}
 */
export function checkFileName(fileName) {
export function checkFileName(fileName, options) {
  const requireChinese = !!(options && options.requireChinese);
  const name = (fileName || "").trim();
  if (!name) {
    return { ok: false, msg: MSG_EMPTY_NAME, main: "" };
@@ -50,7 +59,10 @@
    return { ok: false, msg: MSG_ILLEGAL, main: mainName(name) };
  }
  const main = mainName(name);
  // 不再强制要求中文;含中文、纯英文、数字均可
  // 2026-11-17:非专家费/伦理专家费的报销单,附件名主干必须含中文
  if (requireChinese && !RE_CHINESE.test(main)) {
    return { ok: false, msg: MSG_NEED_CHINESE, main };
  }
  // 按字符数计(用扩展运算符按码点计数,中文/字母/数字/全角各计 1)
  if ([...main].length > MAX_MAIN_LENGTH) {
    return { ok: false, msg: MSG_TOO_LONG, main };
@@ -68,15 +80,16 @@
/**
 * 一组附件校验(含同行重名)
 * @param {Array} list 附件数组,元素形如 {name, url}
 * @param {{requireChinese?: boolean}} [options]
 * @returns {{ok: boolean, msg: string, index: number}}
 */
export function checkFileList(list) {
export function checkFileList(list, options) {
  const arr = list || [];
  const seen = {};
  for (let i = 0; i < arr.length; i++) {
    const name = itemName(arr[i]);
    if (!name) continue; // 取不到原文件名则不判断,避免误拦
    const r = checkFileName(name);
    const r = checkFileName(name, options);
    if (!r.ok) {
      return { ok: false, msg: r.msg, index: i };
    }
@@ -92,9 +105,10 @@
/**
 * 保存前校验整单明细(发票 + 附件)
 * @param {Array} details 明细行数组,行内含 invoicefilesList / annexfilesList(数组)
 * @param {{requireChinese?: boolean}} [options]
 * @returns {{ok: boolean, msg: string}}
 */
export function checkDetails(details) {
export function checkDetails(details, options) {
  const rows = details || [];
  for (let i = 0; i < rows.length; i++) {
    const groups = [
@@ -107,7 +121,7 @@
      for (let j = 0; j < arr.length; j++) {
        const name = itemName(arr[j]);
        if (!name) continue;
        const r = checkFileName(name);
        const r = checkFileName(name, options);
        if (!r.ok) {
          return {
            ok: false,
@@ -135,12 +149,13 @@
/**
 * 整单里所有附件(不分行)的扁平校验,供只有单个文件列表的页面使用
 * @param {Array} lists 多个附件数组
 * @param {{requireChinese?: boolean}} [options]
 * @returns {{ok: boolean, msg: string}}
 */
export function checkAllLists(lists) {
export function checkAllLists(lists, options) {
  const all = lists || [];
  for (let i = 0; i < all.length; i++) {
    const r = checkFileList(all[i]);
    const r = checkFileList(all[i], options);
    if (!r.ok) {
      return { ok: false, msg: r.msg };
    }
src/utils/money.js
@@ -1,22 +1,261 @@
/**
 * 金额展示格式化:
 * - null/undefined/空串保持空;
 * - 0 显示 0.00;
 * - 数字统一两位小数;
 * - 非数字原样返回,避免把异常数据吞掉。
 * 金额计算工具
 *
 * 背景:本系统金额一律以「元」为单位、保留 2 位小数,属财务数据。
 * JS 的 Number 是 IEEE-754 双精度浮点,直接做加减乘会引入二进制舍入误差,
 * 典型表现:
 *   0.1 + 0.2        -> 0.30000000000000004
 *   1.1 * 3          -> 3.3000000000000003
 *   0.3 - 0.2 - 0.1  -> -2.7755575615628914e-17   (退费/扣税相减后残留尾差)
 * 这类尾差导致「合计对不上」「金额显示为 -0」「相等判断失败」等线上问题,
 * 且会随单据流转被写入数据库,事后难以追溯。
 *
 * 因此:所有金额运算统一走本模块,禁止直接对金额使用 + - * / 与 parseFloat 累加。
 * 内部基于 decimal.js(package.json 已引入),保证十进制精确运算。
 *
 * 用法示例:
 *   import { moneySum, moneyMul, moneySub, moneyRound, moneyEq } from "@/utils/money";
 *
 *   // 累加明细(过滤非数字与空值,不会把 NaN 传染给合计)
 *   const total = moneySum(this.rbDetails, "amount");
 *
 *   // 单价 × 数量
 *   const preTax = moneyMul(row.price, row.quantity);
 *
 *   // 税前 - 扣税 = 税后
 *   const afterTax = moneySub(row.amount, row.taxamount);
 *
 *   // 落库/展示前统一保留 2 位(四舍五入)
 *   this.form.amountrequested = moneyRound(total);
 *
 *   // 金额比较(勿用 == / === 或 parseFloat 后相减)
 *   if (!moneyEq(sumOfPayees, this.form.amountrequested)) { ... }
 */
import Decimal from 'decimal.js'
/** 金额保留小数位 */
export const MONEY_SCALE = 2
/**
 * 转为 Decimal;无法识别的值(空串/undefined/null/NaN/非数字)一律按 0 处理。
 * 按 0 处理而非抛错,是为了保持既有页面「!isNaN(parseFloat(x)) 才累加」的行为,
 * 同时避免 NaN 污染整条合计链。
 *
 * @param {string|number|Decimal|null|undefined} value
 * @returns {Decimal}
 */
export function toMoney(value) {
  if (value === null || value === undefined || value === '') {
    return new Decimal(0)
  }
  if (value instanceof Decimal) {
    return value
  }
  let d
  try {
    d = new Decimal(value)
  } catch (e) {
    return new Decimal(0)
  }
  return d.isFinite() ? d : new Decimal(0)
}
/**
 * 判断是否为有效金额(可参与计算)。用于原本 !isNaN(parseFloat(x)) 的校验场景。
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isValidMoney(value) {
  if (value === null || value === undefined || value === '') {
    return false
  }
  if (value instanceof Decimal) {
    return value.isFinite()
  }
  if (typeof value === 'number') {
    return Number.isFinite(value)
  }
  const s = String(value).trim()
  if (s === '') {
    return false
  }
  try {
    return new Decimal(s).isFinite()
  } catch (e) {
    return false
  }
}
/**
 * 累加求和。
 *
 * @param {Array} list 待累加的数组
 * @param {string|Function} [selector] 取金额的方式:
 *        字符串 -> 取该项的该属性名,如 "amount";
 *        函数   -> 用返回值,如 (item) => item.detail && item.detail.amount;
 *        省略   -> 直接累加数组元素本身。
 * @returns {number} 求和结果(Number,便于赋值给表单字段)
 */
export function moneySum(list, selector) {
  if (!Array.isArray(list) || list.length === 0) {
    return 0
  }
  let acc = new Decimal(0)
  for (let i = 0; i < list.length; i++) {
    const raw =
      selector === undefined
        ? list[i]
        : typeof selector === 'function'
          ? selector(list[i])
          : list[i][selector]
    acc = acc.plus(toMoney(raw))
  }
  return acc.toNumber()
}
/**
 * 求和后保留 2 位小数(优先在展示/落库时使用)。
 */
export function moneySumRound(list, selector) {
  return roundNumber(moneySum(list, selector))
}
/**
 * 精确加法。支持多参数或数组:moneyAdd(1.1, 2.2) / moneyAdd([1.1, 2.2])
 */
export function moneyAdd(...args) {
  const list = args.length === 1 && Array.isArray(args[0]) ? args[0] : args
  let acc = new Decimal(0)
  list.forEach((v) => {
    acc = acc.plus(toMoney(v))
  })
  return acc.toNumber()
}
/**
 * 精确减法 a - b(可传多个:a - b - c)
 */
export function moneySub(a, ...rest) {
  let acc = toMoney(a)
  rest.forEach((v) => {
    acc = acc.minus(toMoney(v))
  })
  return acc.toNumber()
}
/**
 * 精确乘法(单价 × 数量、金额 × 税率)
 */
export function moneyMul(a, ...rest) {
  let acc = toMoney(a)
  rest.forEach((v) => {
    acc = acc.times(toMoney(v))
  })
  return acc.toNumber()
}
/**
 * 精确除法(金额 ÷ 数量),divideBy 为 0 时返回 0,不产生 Infinity
 */
export function moneyDiv(a, b) {
  const divisor = toMoney(b)
  if (divisor.isZero()) {
    return 0
  }
  return toMoney(a).div(divisor).toNumber()
}
/**
 * 金额是否相等(十进制精确比较,不受浮点尾差影响)。
 * 会自动归一化到 2 位,避免 100 与 100.001 这类边界误判。
 *
 * @returns {boolean}
 */
export function moneyEq(a, b) {
  return roundDecimal(a).eq(roundDecimal(b))
}
/**
 * 金额大小比较:a > b 返回 1,a < b 返回 -1,相等返回 0
 */
export function moneyCmp(a, b) {
  return roundDecimal(a).cmp(roundDecimal(b))
}
/**
 * 保留 2 位小数并返回 Number(四舍五入,ROUND_HALF_UP)。
 * 用于赋值给表单字段、参与后端交互。
 *
 * @param {*} value
 * @param {number} [scale=2]
 * @returns {number}
 */
export function moneyRound(value, scale = MONEY_SCALE) {
  return roundDecimal(value, scale).toNumber()
}
/**
 * 保留 2 位小数并返回字符串(用于金额展示,避免大额时出现科学计数法)。
 *
 * @param {*} value
 * @param {number} [scale=2]
 * @returns {string}
 */
export function moneyText(value, scale = MONEY_SCALE) {
  return roundDecimal(value, scale).toFixed(scale)
}
/**
 * 保留 2 位小数并返回 Decimal,供后续继续精确运算
 */
export function moneyDecimal(value, scale = MONEY_SCALE) {
  return roundDecimal(value, scale)
}
function roundDecimal(value, scale = MONEY_SCALE) {
  return toMoney(value).toDecimalPlaces(scale, Decimal.ROUND_HALF_UP)
}
// moneySum 内部已返回 Number,这里统一走同一套四舍五入
function roundNumber(value) {
  return roundDecimal(value).toNumber()
}
export default {
  MONEY_SCALE,
  toMoney,
  isValidMoney,
  moneySum,
  moneySumRound,
  moneyAdd,
  moneySub,
  moneyMul,
  moneyDiv,
  moneyEq,
  moneyCmp,
  moneyRound,
  moneyText,
  moneyDecimal,
  formatMoneyValue,
  moneyColumnFormatter
}
/**
 * 金额展示格式化:null/空保持空,0 显示 0.00,其余保留两位小数。
 */
export function formatMoneyValue(value) {
  if (value === null || value === undefined || value === "") {
    return "";
  if (value === null || value === undefined || value === '') {
    return ''
  }
  const num = Number(value);
  const num = Number(value)
  if (!Number.isFinite(num)) {
    return value;
    return value
  }
  return num.toFixed(2);
  return num.toFixed(2)
}
/** el-table-column formatter 签名:(row, column, cellValue, index) */
export function moneyColumnFormatter(row, column, cellValue) {
  return formatMoneyValue(cellValue);
  return formatMoneyValue(cellValue)
}
src/views/project/fund/applyDetail/index.vue
@@ -3087,9 +3087,17 @@
     * 规则与后端 AttachmentNameValidator 同口径:不强制含中文 / 去掉扩展名后主干 ≤20 字 /
     * 不含空格及 / \ : * ? " < > | # % 等特殊字符。
     */
    /**
     * 2026-11-17:附件名是否必须含中文
     * 专家劳务费(1)、伦理专家费(2) 不要求;医学成本(3)、办公费用(4) 等其他类型必须含中文
     * (医院报销单审批要求:附件名要反映发票主要内容)
     */
    requireChineseName() {
      return !(this.businessType == "1" || this.businessType == "2");
    },
    checkUploadFileName(file) {
      const raw = file && file.raw ? file.raw.name : file && file.name;
      const r = checkFileName(raw);
      const r = checkFileName(raw, { requireChinese: this.requireChineseName() });
      if (!r.ok) {
        this.$modal.msgError(r.msg);
        return false;
@@ -3107,7 +3115,9 @@
      if (this.form && this.form.id) {
        return true;
      }
      const c = checkDetails(this.rbDetails);
      const c = checkDetails(this.rbDetails, {
        requireChinese: this.requireChineseName()
      });
      if (!c.ok) {
        this.$modal.msgError(c.msg);
        return false;
src/views/project/fund/performancedetails/index.vue
@@ -2857,9 +2857,16 @@
     * 规则与后端 AttachmentNameValidator 同口径:不强制含中文 / 去掉扩展名后主干 ≤20 字 /
     * 不含空格及 / \ : * ? " < > | # % 等特殊字符。
     */
    /**
     * 2026-11-17:附件名是否必须含中文
     * 专家劳务费(1)、伦理专家费(2) 不要求;绩效及其他类型必须含中文
     */
    requireChineseName() {
      return !(this.businessType == "1" || this.businessType == "2");
    },
    checkUploadFileName(file) {
      const raw = file && file.raw ? file.raw.name : file && file.name;
      const r = checkFileName(raw);
      const r = checkFileName(raw, { requireChinese: this.requireChineseName() });
      if (!r.ok) {
        this.$modal.msgError(r.msg);
        return false;
@@ -2877,7 +2884,9 @@
      if (this.form && this.form.id) {
        return true;
      }
      const c = checkDetails(this.rbDetails);
      const c = checkDetails(this.rbDetails, {
        requireChinese: this.requireChineseName()
      });
      if (!c.ok) {
        this.$modal.msgError(c.msg);
        return false;
src/views/project/travelexpenseapply/travelexpensedetail/index.vue
@@ -883,6 +883,9 @@
        deptmentname: [
          { required: true, message: "请输入所属业务组", trigger: "blur" }
        ],
        managername: [
          { required: true, message: "请正确输入组长", trigger: "blur" }
        ],
        costtype: [
          { required: true, message: "请输入报销类别", trigger: "blur" }
        ]
@@ -1008,9 +1011,7 @@
  mounted() {
    window.addEventListener("beforeunload", e => this.beforeunloadHandler(e));
    this.$nextTick(() => {
      const viewer = this.$refs.imagePreview.$el.querySelector(
        ".el-image-viewer"
      );
      const viewer = this.getImageViewer();
      if (viewer) {
        viewer.addEventListener("click", this.handlePreviewClick);
      }
@@ -1039,9 +1040,7 @@
  }, //生命周期 - 销毁完成
  beforeDestroy() {
    // 移除事件监听
    const viewer = this.$refs.imagePreview.$el.querySelector(
      ".el-image-viewer"
    );
    const viewer = this.getImageViewer();
    if (viewer) {
      viewer.removeEventListener("click", this.handlePreviewClick);
    }
@@ -1064,10 +1063,15 @@
        return "关闭提示";
      }
    },
    // 安全获取图片预览 DOM,避免组件未渲染时 $refs.imagePreview 为空
    getImageViewer() {
      const ref = this.$refs.imagePreview;
      return ref && ref.$el
        ? ref.$el.querySelector(".el-image-viewer")
        : null;
    },
    handlePreviewClick(e) {
      const viewer = this.$refs.imagePreview.$el.querySelector(
        ".el-image-viewer"
      );
      const viewer = this.getImageViewer();
      if (!viewer) return;
      // 判断是否点击了“下一张”按钮(右侧箭头)
@@ -1083,9 +1087,7 @@
    },
    // 获取当前预览的图片索引
    getCurrentPreviewIndex() {
      const viewer = this.$refs.imagePreview.$el.querySelector(
        ".el-image-viewer"
      );
      const viewer = this.getImageViewer();
      if (viewer) {
        const img = viewer.querySelector(".el-image-viewer__img");
        if (img) {
@@ -1359,7 +1361,8 @@
     */
    checkUploadFileName(file) {
      const raw = file && file.raw ? file.raw.name : file && file.name;
      const r = checkFileName(raw);
      // 2026-11-17:差旅费报销属于"其他类型",附件名必须含中文
      const r = checkFileName(raw, { requireChinese: true });
      if (!r.ok) {
        this.$modal.msgError(r.msg);
        return false;
@@ -1377,7 +1380,8 @@
      if (this.form && this.form.id) {
        return true;
      }
      const c = checkDetails(this.rbDetails);
      // 2026-11-17:差旅费报销属于"其他类型",附件名必须含中文
      const c = checkDetails(this.rbDetails, { requireChinese: true });
      if (!c.ok) {
        this.$modal.msgError(c.msg);
        return false;