CardNameEdit.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="card-name-edit">
  3. <div class="style-edit mb-2">
  4. <el-button
  5. size="small"
  6. :type="isBold ? 'primary' : 'default'"
  7. @click="boldChange"
  8. >B</el-button
  9. >
  10. <size-select
  11. v-model="modalForm.nameFontSize"
  12. :predefine="PREDEFINE_OPTIONS"
  13. class="ml-2 escape"
  14. @change="emitChange"
  15. >
  16. </size-select>
  17. </div>
  18. <el-input
  19. v-model="modalForm.topicName"
  20. type="textarea"
  21. :autosize="{ minRows: 2, maxRows: 5 }"
  22. resize="none"
  23. placeholder="请输入题目名称"
  24. clearable
  25. :style="styles"
  26. @input="emitChange"
  27. ></el-input>
  28. </div>
  29. </template>
  30. <script>
  31. import { objAssign } from "../../plugins/utils";
  32. import SizeSelect from "./SizeSelect.vue";
  33. const initModalForm = {
  34. topicName: "",
  35. nameFontSize: "14px",
  36. nameFontWeight: 400,
  37. };
  38. export default {
  39. name: "CardNameEdit",
  40. components: { SizeSelect },
  41. props: {
  42. value: {
  43. type: Object,
  44. default() {
  45. return {
  46. topicName: "",
  47. nameFontSize: "14px",
  48. nameFontWeight: 400,
  49. };
  50. },
  51. },
  52. },
  53. data() {
  54. return {
  55. modalForm: { ...initModalForm },
  56. PREDEFINE_OPTIONS: [
  57. {
  58. value: "14px",
  59. label: "小",
  60. },
  61. {
  62. value: "18px",
  63. label: "中",
  64. },
  65. {
  66. value: "21px",
  67. label: "大",
  68. },
  69. ],
  70. };
  71. },
  72. watch: {
  73. value: {
  74. immediate: true,
  75. handler(val) {
  76. this.initData(val);
  77. },
  78. },
  79. },
  80. computed: {
  81. isBold() {
  82. return this.modalForm.nameFontWeight === 700;
  83. },
  84. styles() {
  85. return {
  86. fontWeight: this.modalForm.nameFontWeight,
  87. fontSize: this.modalForm.nameFontSize,
  88. };
  89. },
  90. },
  91. methods: {
  92. initData() {
  93. this.modalForm = objAssign(initModalForm, this.value);
  94. },
  95. boldChange() {
  96. this.modalForm.nameFontWeight = this.isBold ? 400 : 700;
  97. this.emitChange();
  98. },
  99. emitChange() {
  100. const val = objAssign(this.value, this.modalForm);
  101. this.$emit("input", val);
  102. this.$emit("change", val);
  103. },
  104. },
  105. };
  106. </script>
  107. <style lang="scss">
  108. .card-name-edit textarea {
  109. font-weight: inherit;
  110. }
  111. </style>