EditFieldText.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div class="edit-text">
  3. <el-form
  4. ref="modalFormComp"
  5. :key="modalForm.id"
  6. :model="modalForm"
  7. :rules="rules"
  8. label-width="100px"
  9. >
  10. <el-form-item label="字号:">
  11. <size-select
  12. v-model="modalForm.fontSize"
  13. style="width: 100%"
  14. ></size-select>
  15. </el-form-item>
  16. <el-form-item label="字体:">
  17. <font-family-select
  18. v-model="modalForm.fontFamily"
  19. style="width: 100%"
  20. ></font-family-select>
  21. </el-form-item>
  22. <el-form-item label="颜色:">
  23. <color-select v-model="modalForm.color"></color-select>
  24. </el-form-item>
  25. <el-form-item label="加粗:">
  26. <el-checkbox v-model="isBold" @change="boldChange"
  27. >是否加粗</el-checkbox
  28. >
  29. </el-form-item>
  30. <el-form-item label="对齐:">
  31. <el-radio-group v-model="modalForm.textAlign">
  32. <el-radio-button label="left">左</el-radio-button>
  33. <el-radio-button label="center">居中</el-radio-button>
  34. <el-radio-button label="right">右</el-radio-button>
  35. <!-- <el-radio-button label="justify">两端</el-radio-button> -->
  36. </el-radio-group>
  37. </el-form-item>
  38. <el-form-item prop="field" label="字段:">
  39. <el-select
  40. v-model="modalForm.field"
  41. placeholder="请选择"
  42. @change="fieldChange"
  43. >
  44. <el-option
  45. v-for="item in FIELD_LIST"
  46. :key="item.field"
  47. :label="item.name"
  48. :value="item.field"
  49. ></el-option>
  50. </el-select>
  51. </el-form-item>
  52. <el-form-item>
  53. <el-checkbox v-model="modalForm.showLabel">显示字段名称</el-checkbox>
  54. <el-checkbox v-model="modalForm.showUnderline"
  55. >显示字段内容下划线</el-checkbox
  56. >
  57. </el-form-item>
  58. </el-form>
  59. </div>
  60. </template>
  61. <script>
  62. import SizeSelect from "../../../card/components/common/SizeSelect";
  63. import ColorSelect from "../../../card/components/common/ColorSelect";
  64. import FontFamilySelect from "../../../card/components/common/FontFamilySelect";
  65. import { FIELD_LIST } from "./model";
  66. const initModalForm = {
  67. id: "",
  68. fontSize: "14px",
  69. color: "",
  70. fontFamily: "",
  71. fontWeight: 400,
  72. rotation: 0,
  73. textAlign: null,
  74. content: [],
  75. contentStr: "",
  76. showLabel: false,
  77. showUnderline: false,
  78. };
  79. export default {
  80. name: "EditText",
  81. components: {
  82. SizeSelect,
  83. ColorSelect,
  84. FontFamilySelect,
  85. },
  86. props: {
  87. instance: {
  88. type: Object,
  89. default() {
  90. return {};
  91. },
  92. },
  93. },
  94. data() {
  95. return {
  96. modalForm: { ...initModalForm },
  97. isBold: false,
  98. FIELD_LIST,
  99. rules: {
  100. field: [
  101. {
  102. required: true,
  103. message: "请选择字段",
  104. trigger: "change",
  105. },
  106. ],
  107. },
  108. };
  109. },
  110. mounted() {
  111. this.initData(this.instance);
  112. },
  113. methods: {
  114. initData(val) {
  115. this.modalForm = { ...val };
  116. this.isBold = val.fontWeight > 400;
  117. },
  118. boldChange(isBold) {
  119. this.modalForm.fontWeight = isBold ? 700 : 400;
  120. },
  121. fieldChange(val) {
  122. const item = FIELD_LIST.find((elem) => elem.field === val);
  123. this.modalForm.fieldName = item ? item.name : "";
  124. this.modalForm.content = "$" + this.modalForm.fieldName;
  125. },
  126. async submit() {
  127. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  128. if (!valid) return;
  129. this.$emit("modified", this.modalForm);
  130. },
  131. },
  132. };
  133. </script>