HeadStdinfo.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="head-stdinfo card-head-body-spin">
  3. <div class="stdinfo-item" v-for="(info, index) in fields" :key="index">
  4. <span :style="paramStyle" v-html="info.contentHtml"></span>
  5. <span>:</span>
  6. <span :style="contStyle">{{ fieldInfos[info.code] }}</span>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: "head-stdinfo",
  13. props: {
  14. data: {
  15. type: Object,
  16. },
  17. },
  18. data() {
  19. return {
  20. fieldInfos: this.data["fieldInfos"] || {},
  21. fields: [],
  22. paramStyle: {},
  23. contStyle: {},
  24. lenWidths: {
  25. 3: 45,
  26. 4: 62,
  27. 5: 75,
  28. 6: 90,
  29. 7: 105,
  30. 8: 120,
  31. },
  32. };
  33. },
  34. created() {
  35. this.init();
  36. },
  37. methods: {
  38. init() {
  39. this.fields = [...this.data.requiredFields, ...this.data.extendFields]
  40. .filter((item) => item.enable)
  41. .map((item) => {
  42. // 兼容wkhtmltopdf 汉字两端对齐的问题
  43. item.contentHtml = item.name
  44. .split("")
  45. .map((str) => `<i>${str}</i>`)
  46. .join(" ");
  47. return item;
  48. });
  49. const nameNums = this.fields.map((item) => item.name.length);
  50. const maxNameLen = Math.max.apply(null, nameNums);
  51. const num = maxNameLen < 3 ? 3 : maxNameLen > 8 ? 8 : maxNameLen;
  52. this.paramStyle = {
  53. width: this.lenWidths[num] + "px",
  54. };
  55. this.contStyle = {
  56. marginLeft: this.lenWidths[num] + 20 + "px",
  57. };
  58. },
  59. },
  60. };
  61. </script>