diary.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view>
  3. <view class="con">
  4. <view class="imgbox ddflex" @tap="uploadImgs">
  5. <view class="imgs" v-if="posterUrl">
  6. <image :src="posterUrl" class="img" mode="aspectFill"></image>
  7. <!-- <image src="../static/images/close.png" class="del" @tap="cleanimages(index)"></image> @tap="previewImg(zhiPicUrls, index)" -->
  8. </view>
  9. <view class="upload ddflex" v-else><image src="../static/images/upload.png"></image>请上传封面图</view>
  10. </view>
  11. <input v-model="title" placeholder="请输入话题标题" placeholder-class="placeholder" class="ipt" />
  12. <textarea v-model="desc" placeholder="请输入话题描述" placeholder-class="placeholder" class="textarea"></textarea>
  13. <!-- <editor id="editor" @input="descInput" class="ql-container" placeholder="请输入圈子描述" @ready="onEditorReady"></editor> -->
  14. </view>
  15. <view class="btn" @click="submit()">完成</view>
  16. </view>
  17. </template>
  18. <script>
  19. const app = getApp();
  20. const req = require('../../utils/request.js');
  21. export default {
  22. data() {
  23. return {
  24. title: '',
  25. picCount: 1,
  26. desc: '', //描述
  27. posterUrl: '',
  28. };
  29. },
  30. onLoad() {},
  31. methods: {
  32. onEditorReady() {},
  33. descInput(event) {
  34. this.desc = event.detail.html;
  35. // console.log('desc数据>>>>>>', this.desc);
  36. if (this.desc) {
  37. this.descLength = event.detail.text.length - 1;
  38. } else {
  39. this.descLength = 0;
  40. }
  41. },
  42. uploadImgs() {
  43. let that = this;
  44. uni.chooseImage({
  45. count: that.picCount,
  46. sizeType: ['original', 'compressed'],
  47. sourceType: ['album', 'camera'],
  48. success: function({ tempFilePaths }) {
  49. uni.showLoading({
  50. title:'上传中'
  51. })
  52. var promise = Promise.all(
  53. tempFilePaths.map(tempFilePath => {
  54. return new Promise(function(resolve, reject) {
  55. req.uploadFile('/api/nocheck/upload', tempFilePath, res => {
  56. that.posterUrl = res.src;
  57. resolve()
  58. });
  59. });
  60. })
  61. );
  62. promise
  63. .then(function(results) {
  64. uni.hideLoading()
  65. console.log(results);
  66. })
  67. .catch(function(err) {
  68. uni.hideLoading()
  69. console.log(err);
  70. });
  71. }
  72. });
  73. },
  74. //预览图片
  75. previewImg(picUrls, index) {
  76. //预览合同图片
  77. var src = picUrls[index];
  78. let imgs = picUrls;
  79. uni.previewImage({
  80. current: src, // 当前显示图片的http链接
  81. urls: imgs
  82. });
  83. },
  84. cleanimages(index) {
  85. // 删除图片
  86. let arr = this.zhiPicUrls;
  87. arr.splice(index, 1);
  88. this.zhiPicUrls = arr;
  89. },
  90. submit() {
  91. var dataPream = {};
  92. if (!this.title) {
  93. return req.msg('请输入话题标题');
  94. }
  95. dataPream.title = this.title;
  96. dataPream.subtitle = this.desc;
  97. dataPream.posterUrl = this.posterUrl;
  98. //图片
  99. req.postRequest('/api/v3/dialogue/save', dataPream, data => {
  100. req.msg('话题保存成功');
  101. setTimeout(() => {
  102. uni.redirectTo({
  103. url: '/topics/detail/detail?topicId=' + data.id
  104. });
  105. }, 1500);
  106. });
  107. }
  108. }
  109. };
  110. </script>
  111. <style>
  112. @import './diary.css';
  113. </style>