comment.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 :auto-focus="true" name="content" :vertical="true" required :height="220"
  7. input-type="textarea" bg-color="grey-lighten-5" :maxlength="200" :borderBottom="false"
  8. placeholder="请输入内容,不超过200字符..." v-model="form.content"></tm-input>
  9. <tm-input name="author" align="right" required title="我的昵称" placeholder="请输入您的昵称..."
  10. v-model="form.author"></tm-input>
  11. <tm-input name="avatar" align="right" required title="我的头像" placeholder="请输入您的头像..."
  12. v-model="form.avatar"></tm-input>
  13. <tm-input name="email" align="right" required title="邮箱地址" placeholder="请输入您的邮箱..."
  14. v-model="form.email"></tm-input>
  15. <tm-input name="authorUrl" align="right" required title="我的网站" placeholder="请输入您的网址..."
  16. v-model="form.authorUrl"></tm-input>
  17. <view class="pa-24 pl-30 pr-30"><tm-button navtie-type="form" theme="bg-gradient-blue-accent"
  18. block>提交</tm-button></view>
  19. </tm-form>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import tmForm from '@/tm-vuetify/components/tm-form/tm-form.vue';
  25. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  26. import tmSwitch from '@/tm-vuetify/components/tm-switch/tm-switch.vue';
  27. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  28. export default {
  29. components: {
  30. tmForm,
  31. tmInput,
  32. tmSwitch,
  33. tmButton
  34. },
  35. data() {
  36. return {
  37. isComment: true,
  38. params: {
  39. postName: '',
  40. title: '', // 被回复的标题 type=user =用户名 否则为文章标题
  41. form: '',
  42. formPage: '', // 来自哪个页面
  43. type: 'post' // 来源文章/页面 还是用户 user=用户
  44. },
  45. form: {
  46. allowNotification: true,
  47. author: '', // 作者
  48. avatar: '',
  49. authorUrl: '', // 作者主页
  50. content: '', // 评论内容
  51. email: '', // 邮件
  52. postName: ""
  53. }
  54. };
  55. },
  56. onLoad() {
  57. this.params = this.$Route.query;
  58. this.isComment = this.params.isComment;
  59. this.form.postName = this.params.postName;
  60. if (!this.isComment) {
  61. this.fnSetPageTitle('回复用户:' + this.params.title);
  62. } else {
  63. this.fnSetPageTitle(this.params.title);
  64. }
  65. try {
  66. let visitor = uni.getStorageSync('Visitor')
  67. if (visitor) {
  68. visitor = JSON.parse(visitor)
  69. this.form.author = visitor.author;
  70. this.form.avatar = visitor.avatar;
  71. this.form.email = visitor.email;
  72. this.form.authorUrl = visitor.authorUrl;
  73. }
  74. } catch (e) {}
  75. },
  76. methods: {
  77. fnOnSubmit(e) {
  78. if (e === false) {
  79. return uni.$tm.toast('请检查所有的必填项是否填写完整!');
  80. }
  81. if (!this.form.email) {
  82. return uni.$tm.toast('未填写邮箱地址,将无法接收提醒!');
  83. }
  84. if (this.form.email && !uni.$tm.test.email(this.form.email)) {
  85. return uni.$tm.toast('请填写正确的邮箱地址!');
  86. }
  87. if (this.form.authorUrl && !uni.$tm.test.url(this.form.authorUrl)) {
  88. return uni.$tm.toast('请输入正确的Url地址!');
  89. }
  90. this.fnHandle();
  91. },
  92. handleSetVisitor() {
  93. uni.setStorageSync('Visitor', JSON.stringify({
  94. author: this.form.author,
  95. avatar: this.form.avatar,
  96. email: this.form.email,
  97. authorUrl: this.form.authorUrl,
  98. }))
  99. },
  100. fnHandle() {
  101. uni.showLoading({
  102. title: '正在提交...'
  103. });
  104. // 评论
  105. if (this.isComment) {
  106. const commentForm = {
  107. allowNotification: true,
  108. raw: this.form.content,
  109. content: this.form.content,
  110. owner: {
  111. avatar: this.form.avatarUrl,
  112. displayName: this.form.author,
  113. email: this.form.email,
  114. website: this.form.authorUrl,
  115. },
  116. subjectRef: {
  117. group: "content.halo.run",
  118. kind: "Post",
  119. name: this.form.postName,
  120. version: "v1alpha1",
  121. }
  122. }
  123. this.$httpApi.v2.addPostComment(commentForm)
  124. .then(res => {
  125. uni.$tm.toast('日志:提交成功!');
  126. // 更新评论者信息
  127. this.handleSetVisitor();
  128. setTimeout(() => {
  129. uni.navigateBack()
  130. }, 1500)
  131. })
  132. .catch(err => {
  133. uni.$tm.toast("提示:评论失败");
  134. });
  135. return;
  136. }
  137. // 回复
  138. const replyForm = {
  139. allowNotification: true,
  140. raw: this.form.content,
  141. content: this.form.content,
  142. owner: {
  143. avatar: this.form.avatarUrl,
  144. displayName: this.form.author,
  145. email: this.form.email,
  146. website: this.form.authorUrl,
  147. },
  148. quoteReply: this.form.postName
  149. }
  150. this.$httpApi.v2.addPostCommentReply(this.form.postName, replyForm)
  151. .then(res => {
  152. uni.$tm.toast('提示:提交成功!');
  153. // 更新评论者信息
  154. this.handleSetVisitor();
  155. setTimeout(() => {
  156. uni.navigateBack()
  157. }, 1500)
  158. })
  159. .catch(err => {
  160. uni.$tm.toast("提示:回复失败");
  161. });
  162. }
  163. }
  164. };
  165. </script>
  166. <style scoped lang="scss">
  167. .app-page {
  168. width: 100vw;
  169. min-height: 100vh;
  170. box-sizing: border-box;
  171. // background-color: #fafafd;
  172. background-color: #ffffff;
  173. .content {
  174. overflow: hidden;
  175. background-color: #fff;
  176. // box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.05);
  177. }
  178. }
  179. .poup-content {
  180. width: 500rpx;
  181. ::v-deep {
  182. .slider_id {
  183. width: 100% !important;
  184. }
  185. }
  186. }
  187. </style>