HeadStdinfo.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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">{{ info.name }}</span>
  5. <span>:</span>
  6. <span>{{ 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. lenWidths: {
  24. 3: 44,
  25. 4: 62,
  26. 5: 72,
  27. 6: 86,
  28. 7: 100,
  29. 8: 114,
  30. },
  31. };
  32. },
  33. created() {
  34. this.init();
  35. },
  36. methods: {
  37. init() {
  38. this.fields = [
  39. ...this.data.requiredFields,
  40. ...this.data.extendFields,
  41. ].filter((item) => item.enable);
  42. const nameNums = this.fields.map((item) => item.name.length);
  43. const maxNameLen = Math.max.apply(null, nameNums);
  44. const num = maxNameLen < 3 ? 3 : maxNameLen > 8 ? 8 : maxNameLen;
  45. this.paramStyle = {
  46. width: this.lenWidths[num] + "px",
  47. };
  48. },
  49. },
  50. };
  51. </script>