message.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="msg">
  3. <view class="text">
  4. <textarea placeholder="你想留下来点什么呢~" v-model="content" maxlength="200" placeholder-style="color:#999;font-size:28rpx;" @input="textInp" />
  5. <text>{{ remnant }}/200</text>
  6. </view>
  7. <view class="msg_btn" @click="addMsg">发表留言</view>
  8. </view>
  9. </template>
  10. <script>
  11. import { putMsg } from '../../api/msg.js';
  12. export default {
  13. data() {
  14. return {
  15. remnant: 1, //字数初始值
  16. content: '', //留言内容
  17. timer: null //toast定时器
  18. };
  19. },
  20. beforeDestroy() {
  21. clearInterval(this.timer);
  22. this.timer = null;
  23. },
  24. methods: {
  25. /*
  26. * 字数递减
  27. */
  28. textInp() {
  29. var txtVal = this.content.length;
  30. if (txtVal <= 200) {
  31. this.remnant = 0 + txtVal;
  32. }
  33. if (txtVal == 200) {
  34. uni.showToast({
  35. title: '文字超出限制',
  36. icon: 'none'
  37. });
  38. }
  39. },
  40. /*
  41. * 发表留言
  42. * @params:content 留言的内容
  43. */
  44. addMsg() {
  45. if (!this.content) {
  46. uni.showModal({
  47. content: '留言内容不能为空',
  48. showCancel: false
  49. });
  50. return false;
  51. }
  52. putMsg({
  53. content: this.content
  54. }).then(res => {
  55. if (res.code == 200) {
  56. uni.showToast({
  57. title: '发表留言成功',
  58. icon: 'success',
  59. duration: 2000,
  60. mask: true,
  61. success: res => {
  62. this.timer = setTimeout(res => {
  63. uni.hideToast();
  64. uni.redirectTo({
  65. url: '../msg_board/msg_board?tabType=' + 1
  66. });
  67. }, 2000);
  68. }
  69. });
  70. } else {
  71. uni.showModal({
  72. content: res.message || '发表留言失败',
  73. showCancel: false
  74. });
  75. }
  76. });
  77. }
  78. }
  79. };
  80. </script>
  81. <style>
  82. page {
  83. width: 100%;
  84. height: 100%;
  85. background-color: #fff;
  86. }
  87. </style>
  88. <style lang="scss">
  89. .msg {
  90. width: 690rpx;
  91. margin: 0 auto;
  92. .text {
  93. position: relative;
  94. margin: 20rpx 0 180rpx;
  95. margin-top: 20rpx;
  96. margin-bottom: 27vh;
  97. textarea {
  98. width: 690rpx;
  99. padding: 30rpx;
  100. height: 520rpx;
  101. line-height: 1.5;
  102. box-sizing: border-box;
  103. background-color: #f8f8f8;
  104. border-radius: 24rpx;
  105. }
  106. text {
  107. position: absolute;
  108. bottom: 30rpx;
  109. right: 30rpx;
  110. font-size: 28rpx;
  111. color: #999;
  112. }
  113. textarea {
  114. font-size: 28rpx;
  115. }
  116. }
  117. .msg_btn {
  118. width: 460rpx;
  119. margin: 0 auto;
  120. text-align: center;
  121. height: 88rpx;
  122. line-height: 88rpx;
  123. background: linear-gradient(93deg, #f97c55 0%, #f44545 100%);
  124. opacity: 1;
  125. border-radius: 44rpx;
  126. font-size: 32rpx;
  127. color: #fff;
  128. }
  129. }
  130. </style>