comment.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="app-page pa-6">
  3. <view class="content pt-24 pb-24 round-4">
  4. <!-- 表单区域 -->
  5. <tm-form @submit="fnOnSubmit">
  6. <tm-input
  7. :auto-focus="true"
  8. name="content"
  9. :vertical="true"
  10. required
  11. :height="220"
  12. input-type="textarea"
  13. bg-color="grey-lighten-5"
  14. :maxlength="200"
  15. :borderBottom="false"
  16. placeholder="请输入内容,不超过200字符..."
  17. v-model="form.content"
  18. ></tm-input>
  19. <tm-input name="author" align="right" required title="我的昵称" placeholder="请输入您的昵称..." v-model="form.author"></tm-input>
  20. <tm-input name="email" align="right" title="邮箱地址" placeholder="请输入您的邮箱..." v-model="form.email"></tm-input>
  21. <tm-input name="authorUrl" align="right" title="我的网站" placeholder="请输入您的网址..." v-model="form.authorUrl"></tm-input>
  22. <view class="mx-32 my-24 border-b-1 pb-24 flex-between">
  23. <text class="text-size-n ">接收提醒</text>
  24. <view><tm-switch :text="['是', '否']" v-model="form.allowNotification" color="bg-gradient-blue-accent"></tm-switch></view>
  25. </view>
  26. <view class="pa-24 pl-30 pr-30"><tm-button navtie-type="form" theme="bg-gradient-blue-accent" block>提交</tm-button></view>
  27. </tm-form>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import tmForm from '@/tm-vuetify/components/tm-form/tm-form.vue';
  33. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  34. import tmSwitch from '@/tm-vuetify/components/tm-switch/tm-switch.vue';
  35. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  36. export default {
  37. components: {
  38. tmForm,
  39. tmInput,
  40. tmSwitch,
  41. tmButton
  42. },
  43. data() {
  44. return {
  45. params: {
  46. postId: '',
  47. parentId: '',
  48. title: '', // 被回复的标题 type=user =用户名 否则为文章标题
  49. form: '',
  50. formPage: '', // 来自哪个页面
  51. type: 'post' // 来源文章/页面 还是用户 user=用户
  52. },
  53. form: {
  54. allowNotification: true,
  55. author: '', // 作者
  56. avatar: '',
  57. authorUrl: '', // 作者主页
  58. content: '', // 评论内容
  59. email: '', // 邮件
  60. parentId: 0,
  61. postId: 0
  62. }
  63. };
  64. },
  65. computed: {
  66. // 评论游客信息
  67. wxLoginVisitorUser() {
  68. return uni.$tm.vx.getters().getWxLoginInfo;
  69. }
  70. },
  71. onLoad() {
  72. this.params = this.$Route.query;
  73. this.form.postId = this.params.id;
  74. if (this.params.type == 'user') {
  75. this.form.parentId = this.params.parentId;
  76. this.fnSetPageTitle('回复用户:' + this.params.title);
  77. } else {
  78. this.form.parentId = 0;
  79. this.fnSetPageTitle(this.params.title);
  80. }
  81. this.form.author = this.wxLoginVisitorUser.nickName;
  82. this.form.avatar = this.wxLoginVisitorUser.avatarUrl;
  83. this.form.email = this.wxLoginVisitorUser.email;
  84. this.form.authorUrl = this.wxLoginVisitorUser.url;
  85. },
  86. methods: {
  87. fnOnSubmit(e) {
  88. if (e === false) {
  89. return uni.$tm.toast('请检查所有的必填项是否填写完整!');
  90. }
  91. if (this.form.allowNotification && !this.form.email) {
  92. return uni.$tm.toast('未填写邮箱地址,将无法接收提醒!');
  93. }
  94. if (this.form.email && !uni.$tm.test.email(this.form.email)) {
  95. return uni.$tm.toast('请填写正确的邮箱地址!');
  96. }
  97. if (this.form.authorUrl && !uni.$tm.test.url(this.form.authorUrl)) {
  98. return uni.$tm.toast('请输入正确的Url地址!');
  99. }
  100. this.fnHandle();
  101. },
  102. fnHandle() {
  103. uni.showLoading({
  104. title: '正在提交...'
  105. });
  106. const _api = {
  107. sheets: this.$httpApi.postSheetsComments,
  108. posts: this.$httpApi.postCommentPost
  109. };
  110. _api[this.params.from](this.form)
  111. .then(res => {
  112. if (res.status == 200) {
  113. uni.$tm.toast('提交成功,待博主审核通过后即可展示!');
  114. // 更新评论者信息
  115. uni.$tm.vx.commit('user/setWxLoginInfo', {
  116. avatarUrl: this.wxLoginVisitorUser.avatarUrl,
  117. nickName: this.form.author,
  118. email: this.form.email,
  119. url: this.form.authorUrl
  120. });
  121. // 清空评论内容
  122. this.form.content = '';
  123. // 触发刷新评论(可能需要评论审核不会有改变)
  124. // uni.$emit(this.params.formPage + '_refresh');
  125. } else {
  126. uni.$tm.toast('操作失败,请重试!');
  127. }
  128. })
  129. .catch(err => {
  130. uni.$tm.toast(err.message);
  131. });
  132. }
  133. }
  134. };
  135. </script>
  136. <style scoped lang="scss">
  137. .app-page {
  138. width: 100vw;
  139. min-height: 100vh;
  140. box-sizing: border-box;
  141. // background-color: #fafafd;
  142. background-color: #ffffff;
  143. .content {
  144. overflow: hidden;
  145. background-color: #fff;
  146. // box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.05);
  147. }
  148. }
  149. .poup-content {
  150. width: 500rpx;
  151. ::v-deep {
  152. .slider_id {
  153. width: 100% !important;
  154. }
  155. }
  156. }
  157. </style>