profile.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="profile" id="profile">
  3. <header>
  4. <h5>个人介绍</h5>
  5. <div v-if="editing" class="opts">
  6. <el-button type="info" @click="editing = false">取消</el-button>
  7. <el-button type="primary" @click="onSubmit">保存</el-button>
  8. </div>
  9. <div v-else class="opts">
  10. <el-button type="primary" @click="handleEdit">编辑</el-button>
  11. </div>
  12. </header>
  13. <div v-if="!content&&!editing" class="empty">点击右上角“编辑”按钮添加个人介绍</div>
  14. <div v-else-if="editing" class="edit">
  15. <editor :hideImage="true" :content="content" @change="handleChange"></editor>
  16. </div>
  17. <!-- <div v-else class="show" v-html="content"></div> -->
  18. <div v-else class="show ql-snow ql-editor" v-html="content"></div>
  19. </div>
  20. </template>
  21. <script>
  22. import { mapState } from "vuex";
  23. import editor from "@/components/editor";
  24. export default {
  25. data() {
  26. return {
  27. editing: false,
  28. content: ""
  29. };
  30. },
  31. components: { editor },
  32. watch: {
  33. // content: function(val) {
  34. // console.log(val);
  35. // }
  36. },
  37. computed: {
  38. ...mapState(["userinfo"])
  39. },
  40. async mounted() {
  41. let res = await this.$axios.$post("/api/user/get_resume");
  42. this.content = res.data ? res.data.personaldetails : "";
  43. },
  44. methods: {
  45. handleEdit() {
  46. if (this.userinfo && this.userinfo.realname_verify_status === "0") {
  47. this.$message.error("请先进行实名认证");
  48. return;
  49. }
  50. this.editing = true;
  51. },
  52. handleChange(val) {
  53. this.content = val;
  54. },
  55. async onSubmit() {
  56. if (!this.content) {
  57. this.$message.error("请输入个人介绍");
  58. return false;
  59. }
  60. if (this.content.length < 150) {
  61. this.$message.error("个人介绍不得低于150字");
  62. return false;
  63. }
  64. if (!this.content.length > 3000) {
  65. this.$message.error("个人介绍不得 超过3000字");
  66. return false;
  67. }
  68. const formData = {
  69. personaldetails: this.content
  70. };
  71. let res = await this.$axios.$post("/api/user/update_resume", formData);
  72. if (res.status === 1) {
  73. this.$message.success("保存成功!");
  74. this.editing = false;
  75. } else {
  76. this.$message.error(res.info);
  77. }
  78. }
  79. }
  80. };
  81. </script>
  82. <style lang="scss">
  83. .profile {
  84. .edit {
  85. padding: 0 20px;
  86. width: 1000px;
  87. min-height: 244px;
  88. > div {
  89. border: 0 !important;
  90. }
  91. & > .ql-toolbar.ql-snow {
  92. border: 0 !important;
  93. }
  94. }
  95. .show {
  96. padding: 20px;
  97. * {
  98. word-break: break-all;
  99. }
  100. }
  101. .empty {
  102. margin: 112px auto 104px;
  103. font-size: 27px;
  104. font-family: PingFangSC-Regular;
  105. font-weight: 400;
  106. text-align: center;
  107. color: rgba(205, 205, 205, 1);
  108. line-height: 38px;
  109. }
  110. }
  111. </style>