暂无描述

fix_waybill_syntax.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. import subprocess
  3. import os
  4. ROOT = os.path.dirname(os.path.dirname(__file__))
  5. OUT = os.path.join(ROOT, "ruoyi-ui", "src", "views", "basic", "waybill", "components", "WaybillDetail.vue")
  6. raw = open(OUT, "rb").read()
  7. try:
  8. text = raw.decode("utf-8")
  9. except UnicodeDecodeError:
  10. text = raw.decode("gbk")
  11. # Syntax: missing closing paren on msgSuccess
  12. text = text.replace("+ phone;", "+ phone);")
  13. text = text.replace('+ phone;', '+ phone);')
  14. open(OUT, "w", encoding="utf-8", newline="\n").write(text)
  15. subprocess.run([__import__("sys").executable, os.path.join(ROOT, "tools", "fix_waybill_detail_zh.py")], check=True)
  16. subprocess.run([__import__("sys").executable, os.path.join(ROOT, "tools", "fix_phase.py")], check=True)
  17. text = open(OUT, encoding="utf-8").read()
  18. if "+ phone);" not in text and "phone);" not in text:
  19. raise SystemExit("parenthesis fix failed")
  20. if "_\u6e29\u5ea6\u8bb0\u5f55.pdf" not in text:
  21. # fix duplicate attachment via unicode
  22. lines = text.splitlines()
  23. for i, line in enumerate(lines):
  24. if 'attachments()' in line or (i > 244 and i < 252 and '.pdf' in line):
  25. pass
  26. text = text.replace(
  27. ' { name: no + "_\u53d1\u8fd0\u5355.pdf", time: base }\n ];',
  28. ' { name: no + "_\u53d1\u8fd0\u5355.pdf", time: base },\n { name: no + "_\u7b7e\u6536\u5355.pdf", time: base },\n { name: no + "_\u6e29\u5ea6\u8bb0\u5f55.pdf", time: base }\n ];',
  29. 1
  30. )
  31. # simpler: replace third attachment line
  32. import re
  33. pdf_lines = [m.start() for m in re.finditer(r'name: no \+ "_[^"]+\.pdf"', text)]
  34. if len(pdf_lines) >= 3:
  35. pass
  36. final = open(OUT, encoding="utf-8").read()
  37. # fix download message
  38. final = final.replace(
  39. 'downloadFile(file) {\n this.$modal.msgInfo("\u9884\u89c8\uff1a" + file.name);',
  40. 'downloadFile(file) {\n this.$modal.msgInfo("\u4e0b\u8f7d\uff1a" + file.name);',
  41. )
  42. open(OUT, "w", encoding="utf-8", newline="\n").write(final)
  43. print("fixed syntax and encoding")