editDesc.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="content">
  3. <editor
  4. @ready="onEditorReady"
  5. id="editor"
  6. :placeholder="isCompanyIntroduction?'输入公司简介内容':'输入个人简介内容'"
  7. placeholder-class="placeholder"
  8. class="textarea"
  9. @input="descInput"
  10. :read-only="isReadOnly"
  11. ></editor>
  12. <view class="btn" @click="save()">保存</view>
  13. </view>
  14. </template>
  15. <script>
  16. const app = getApp();
  17. const req = require('../../utils/request.js');
  18. export default {
  19. data() {
  20. return {
  21. id: '',
  22. brief: '',
  23. isReadOnly: true,
  24. isCompanyIntroduction:false
  25. };
  26. },
  27. onLoad(opt) {
  28. this.id = opt.id;
  29. let pages = getCurrentPages();
  30. let prevPage = pages[pages.length - 2];
  31. if(opt.isCompanyIntroduction){
  32. this.isCompanyIntroduction = true
  33. this.brief = prevPage.$vm.companyIntroduction;
  34. }else{
  35. this.brief = prevPage.$vm.brief;
  36. }
  37. },
  38. methods: {
  39. descInput(event) {
  40. this.brief = event.detail.html;
  41. // if (this.brief) {
  42. // this.descLength = event.detail.text.length - 1;
  43. // } else {
  44. // this.descLength = 0;
  45. // }
  46. },
  47. onEditorReady() {
  48. if (this.isEndit) {
  49. return;
  50. }
  51. const that = this;
  52. uni.createSelectorQuery()
  53. .select('#editor')
  54. .context(function(res) {
  55. that.editorCtx = res.context;
  56. that.editorCtx.setContents({
  57. html: that.brief //这里就是设置默认值的地方(html 后面给什么就显示什么)
  58. });
  59. that.isReadOnly = false;
  60. })
  61. .exec();
  62. },
  63. save() {
  64. let pages = getCurrentPages(); //获取所有页面栈实例列表
  65. let prevPage = pages[pages.length - 2]; //上一页页面实例
  66. if(this.isCompanyIntroduction){
  67. prevPage.$vm.companyIntroduction = this.brief;
  68. }else{
  69. prevPage.$vm.brief = this.brief;
  70. }
  71. uni.navigateBack({
  72. //uni.navigateTo跳转的返回,默认1为返回上一级
  73. delta: 1
  74. });
  75. }
  76. }
  77. };
  78. </script>
  79. <style>
  80. @import './editDesc.css';
  81. .ql-editor.ql-blank:before {
  82. /* 此处设置 placeholder 样式 */
  83. color: rgba(204, 204, 204, 1);
  84. font-style: normal;
  85. min-height: 400px;
  86. }
  87. </style>