ElemFillField.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="elem-fill-field" :style="elemStyles">
  3. <div
  4. v-for="(info, index) in fieldList"
  5. :key="index"
  6. class="fill-field-item"
  7. :style="itemStyles"
  8. >
  9. <div class="fill-field-content" :style="lineStyles">
  10. <span :style="paramStyle">{{ info }}</span>
  11. <span>:</span>
  12. <span></span>
  13. </div>
  14. </div>
  15. <div v-if="!fieldList.length" class="fill-field-item" :style="itemStyles">
  16. <div class="fill-field-content" :style="lineStyles">
  17. <span :style="paramStyle">名称名</span>
  18. <span>:</span>
  19. <span></span>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. name: "ElemFillField",
  27. props: {
  28. data: {
  29. type: Object,
  30. default() {
  31. return {};
  32. },
  33. },
  34. },
  35. data() {
  36. return {
  37. questions: [],
  38. paramStyle: {},
  39. lenWidths: {
  40. 3: 44,
  41. 4: 62,
  42. 5: 72,
  43. 6: 86,
  44. 7: 100,
  45. 8: 114,
  46. },
  47. fieldList: [],
  48. };
  49. },
  50. computed: {
  51. itemStyles() {
  52. return {
  53. width: 100 / this.data.fieldCountPerLine + "%",
  54. };
  55. },
  56. lineStyles() {
  57. return {
  58. height: this.data.lineSpacing + "px",
  59. paddingTop: this.data.lineSpacing - 26 + "px",
  60. };
  61. },
  62. elemStyles() {
  63. if (this.data.mode === "side") {
  64. return {
  65. position: "absolute",
  66. width: this.data.h + "px",
  67. height: this.data.w + "px",
  68. transform: "rotate(-90deg)",
  69. "transform-origin": "0 100%",
  70. bottom: 0,
  71. left: this.data.w + "px",
  72. };
  73. } else {
  74. return null;
  75. }
  76. },
  77. },
  78. watch: {
  79. data: {
  80. immediate: true,
  81. handler() {
  82. this.init();
  83. },
  84. },
  85. },
  86. methods: {
  87. init() {
  88. this.fieldList = this.data.fields
  89. .split(/[,,]/)
  90. .filter((item) => item.trim());
  91. if (this.data.nameIsJustify) {
  92. const nameNums = this.fieldList.map((item) => item.length);
  93. const maxNameLen = Math.max.apply(null, nameNums);
  94. const num = maxNameLen < 3 ? 3 : maxNameLen > 8 ? 8 : maxNameLen;
  95. this.paramStyle = {
  96. width: this.lenWidths[num] + "px",
  97. };
  98. } else {
  99. this.paramStyle = {};
  100. }
  101. },
  102. },
  103. };
  104. </script>