profile.vue 2.7 KB

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