releaseFirendCircle.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!-- 发布朋友圈 -->
  2. <template>
  3. <view class="content">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <u-navbar title=" " :background="{ background: '#F6F7F8' }" :border-bottom="false" back-icon-name="" back-text="取消" :back-text-style="{ color: '#404133' }">
  6. <view class="slot-wrap" slot="right"><u-button size="mini" type="success" @click="handleRelease" :disabled="$u.trim(this.content) ? false : true">发表</u-button></view>
  7. </u-navbar>
  8. <!-- #endif -->
  9. <textarea class="input" v-model="content" placeholder="这一刻的想法..." :show-confirm-bar="false" :adjust-position="false" :disable-default-padding="true"></textarea>
  10. <upload
  11. class="upload"
  12. ref="upload"
  13. :action="action"
  14. :max-size="maxSize"
  15. :max-count="3"
  16. :size-type="['compressed']"
  17. @on-success="getImgUrl"
  18. @on-remove="onRemove"
  19. @on-uploaded="isAdd = true"
  20. :before-upload="filterFileType"
  21. ></upload>
  22. <view class="tips">
  23. <u-cell-group>
  24. <u-cell-item bg-color="#F6F7F8" title="所在位置" :title-style="{ marginLeft: '10rpx' }">
  25. <u-icon slot="icon" name="map" size="40"></u-icon>
  26. </u-cell-item>
  27. <u-cell-item bg-color="#F6F7F8" title="谁可以看" :title-style="{ marginLeft: '10rpx' }">
  28. <u-icon slot="icon" name="account" size="40"></u-icon>
  29. </u-cell-item>
  30. </u-cell-group>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import upload from '@/components/upload.vue';
  36. export default {
  37. components:{upload},
  38. data() {
  39. return {
  40. content: '',
  41. action: this.$uploadUrl,
  42. maxSize: 2 * 1024 * 1024, //限制文件大小 2M
  43. btnLoading: false, //防止重复点击
  44. imgUrls: [],
  45. isAdd: true
  46. };
  47. },
  48. onShow() {},
  49. methods: {
  50. filterFileType(index, lists) {
  51. if (lists[index].fileType != 'jpg' && lists[index].fileType != 'png' && lists[index].fileType != 'gif') {
  52. lists.splice(index, 1);
  53. // 当前文件不支持
  54. uni.showModal({
  55. title: '暂不支持当前图片类型',
  56. showCancel: false
  57. });
  58. } else {
  59. this.isAdd = false;
  60. }
  61. },
  62. getImgUrl(res) {
  63. this.imgUrls.push(res.data);
  64. },
  65. onRemove(index) {
  66. this.imgUrls.splice(index, 1);
  67. },
  68. //自定义标题栏按钮 h5&&app
  69. onNavigationBarButtonTap({ index }) {
  70. if (index == 0) {
  71. this.handleRelease();
  72. }
  73. },
  74. //自定义标题栏按钮点击事件 微信小程序
  75. handleRelease() {
  76. if (!this.isAdd) {
  77. uni.showModal({
  78. title: '图片未上传完成请稍后再试',
  79. showCancel: false
  80. });
  81. }
  82. if (this.$u.trim(this.content)) {
  83. this.btnLoading = true;
  84. uni.showLoading({
  85. title: '正在发布...',
  86. mask: true
  87. });
  88. let urls = '';
  89. for (let imgUrl of this.imgUrls) {
  90. urls += imgUrl + ',';
  91. }
  92. if (urls.length > 0) {
  93. urls.substring(0, urls.length - 1);
  94. }
  95. this.$socket.createPostReq(this.userData.user.operId, this.content, urls, res => {
  96. if (res.response.success) {
  97. uni.hideLoading();
  98. this.$u.route({ type: 'back' });
  99. } else {
  100. uni.showModal({
  101. title: '请求失败',
  102. showCancel: false
  103. });
  104. }
  105. });
  106. }
  107. }
  108. }
  109. };
  110. </script>
  111. <style lang="scss">
  112. .content {
  113. padding: 20rpx 40rpx;
  114. .input {
  115. caret-color: $uni-color-success;
  116. height: 160rpx;
  117. padding: 0 15rpx;
  118. }
  119. .tips {
  120. margin-top: 120rpx;
  121. }
  122. .upload {
  123. /deep/.u-list-item,
  124. .u-add-wrap {
  125. background-color: #eceae8;
  126. }
  127. }
  128. .slot-wrap {
  129. display: flex;
  130. align-items: center;
  131. padding: 0 30rpx;
  132. }
  133. }
  134. </style>