miroir de
https://github.com/ialley-workshop-open/uni-halo.git
synchronisé 2026-06-12 13:19:31 +08:00
release: 发布 uni-halo beta-v2.0 版本
Cette révision appartient à :
@@ -3,15 +3,19 @@
|
||||
<view class="content pt-24 pb-24 round-4">
|
||||
<!-- 表单区域 -->
|
||||
<tm-form @submit="fnOnSubmit">
|
||||
<tm-input :auto-focus="true" name="content" :vertical="true" required :height="220" input-type="textarea" bg-color="grey-lighten-5" :maxlength="200" :borderBottom="false" placeholder="请输入内容,不超过200字符..." v-model="form.content"></tm-input>
|
||||
<tm-input name="author" align="right" required title="我的昵称" placeholder="请输入您的昵称..." v-model="form.author"></tm-input>
|
||||
<tm-input name="email" align="right" title="邮箱地址" placeholder="请输入您的邮箱..." v-model="form.email"></tm-input>
|
||||
<tm-input name="authorUrl" align="right" title="我的网站" placeholder="请输入您的网址..." v-model="form.authorUrl"></tm-input>
|
||||
<view class="mx-32 my-24 border-b-1 pb-24 flex-between">
|
||||
<text class="text-size-n ">接收提醒</text>
|
||||
<view><tm-switch :text="['是', '否']" v-model="form.allowNotification" color="bg-gradient-blue-accent"></tm-switch></view>
|
||||
</view>
|
||||
<view class="pa-24 pl-30 pr-30"><tm-button navtie-type="form" theme="bg-gradient-blue-accent" block>提交</tm-button></view>
|
||||
<tm-input :auto-focus="true" name="content" :vertical="true" required :height="220"
|
||||
input-type="textarea" bg-color="grey-lighten-5" :maxlength="200" :borderBottom="false"
|
||||
placeholder="请输入内容,不超过200字符..." v-model="form.content"></tm-input>
|
||||
<tm-input name="author" align="right" required title="我的昵称" placeholder="请输入您的昵称..."
|
||||
v-model="form.author"></tm-input>
|
||||
<tm-input name="avatar" align="right" required title="我的头像" placeholder="请输入您的头像..."
|
||||
v-model="form.avatar"></tm-input>
|
||||
<tm-input name="email" align="right" required title="邮箱地址" placeholder="请输入您的邮箱..."
|
||||
v-model="form.email"></tm-input>
|
||||
<tm-input name="authorUrl" align="right" required title="我的网站" placeholder="请输入您的网址..."
|
||||
v-model="form.authorUrl"></tm-input>
|
||||
<view class="pa-24 pl-30 pr-30"><tm-button navtie-type="form" theme="bg-gradient-blue-accent"
|
||||
block>提交</tm-button></view>
|
||||
</tm-form>
|
||||
</view>
|
||||
</view>
|
||||
@@ -32,9 +36,9 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isComment: true,
|
||||
params: {
|
||||
postId: '',
|
||||
parentId: '',
|
||||
postName: '',
|
||||
title: '', // 被回复的标题 type=user =用户名 否则为文章标题
|
||||
form: '',
|
||||
formPage: '', // 来自哪个页面
|
||||
@@ -46,40 +50,39 @@
|
||||
avatar: '',
|
||||
authorUrl: '', // 作者主页
|
||||
content: '', // 评论内容
|
||||
email: '', // 邮件
|
||||
parentId: 0,
|
||||
postId: 0
|
||||
email: '', // 邮件
|
||||
postName: ""
|
||||
}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 评论游客信息
|
||||
wxLoginVisitorUser() {
|
||||
return uni.$tm.vx.getters().getWxLoginInfo;
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.params = this.$Route.query;
|
||||
this.form.postId = this.params.id;
|
||||
if (this.params.type == 'user') {
|
||||
this.form.parentId = this.params.parentId;
|
||||
this.isComment = this.params.isComment;
|
||||
this.form.postName = this.params.postName;
|
||||
|
||||
if (!this.isComment) {
|
||||
this.fnSetPageTitle('回复用户:' + this.params.title);
|
||||
} else {
|
||||
this.form.parentId = 0;
|
||||
this.fnSetPageTitle(this.params.title);
|
||||
}
|
||||
this.form.author = this.wxLoginVisitorUser.nickName;
|
||||
this.form.avatar = this.wxLoginVisitorUser.avatarUrl;
|
||||
this.form.email = this.wxLoginVisitorUser.email;
|
||||
this.form.authorUrl = this.wxLoginVisitorUser.url;
|
||||
|
||||
try {
|
||||
let visitor = uni.getStorageSync('Visitor')
|
||||
if (visitor) {
|
||||
visitor = JSON.parse(visitor)
|
||||
this.form.author = visitor.author;
|
||||
this.form.avatar = visitor.avatar;
|
||||
this.form.email = visitor.email;
|
||||
this.form.authorUrl = visitor.authorUrl;
|
||||
}
|
||||
} catch (e) {}
|
||||
},
|
||||
methods: {
|
||||
fnOnSubmit(e) {
|
||||
console.log('提交评论');
|
||||
if (e === false) {
|
||||
return uni.$tm.toast('请检查所有的必填项是否填写完整!');
|
||||
}
|
||||
if (this.form.allowNotification && !this.form.email) {
|
||||
if (!this.form.email) {
|
||||
return uni.$tm.toast('未填写邮箱地址,将无法接收提醒!');
|
||||
}
|
||||
if (this.form.email && !uni.$tm.test.email(this.form.email)) {
|
||||
@@ -90,36 +93,77 @@
|
||||
}
|
||||
this.fnHandle();
|
||||
},
|
||||
|
||||
handleSetVisitor() {
|
||||
uni.setStorageSync('Visitor', JSON.stringify({
|
||||
author: this.form.author,
|
||||
avatar: this.form.avatar,
|
||||
email: this.form.email,
|
||||
authorUrl: this.form.authorUrl,
|
||||
}))
|
||||
},
|
||||
fnHandle() {
|
||||
uni.showLoading({
|
||||
title: '正在提交...'
|
||||
});
|
||||
const _api = {
|
||||
sheets: this.$httpApi.postSheetsComments,
|
||||
posts: this.$httpApi.postCommentPost
|
||||
};
|
||||
_api[this.params.from](this.form)
|
||||
.then(res => {
|
||||
if (res.status == 200) {
|
||||
uni.$tm.toast('提交成功,待博主审核通过后即可展示!');
|
||||
// 更新评论者信息
|
||||
uni.$tm.vx.commit('user/setWxLoginInfo', {
|
||||
avatarUrl: this.wxLoginVisitorUser.avatarUrl,
|
||||
nickName: this.form.author,
|
||||
email: this.form.email,
|
||||
url: this.form.authorUrl
|
||||
});
|
||||
// 清空评论内容
|
||||
this.form.content = '';
|
||||
// 触发刷新评论(可能需要评论审核不会有改变)
|
||||
// uni.$emit(this.params.formPage + '_refresh');
|
||||
} else {
|
||||
uni.$tm.toast('操作失败,请重试!');
|
||||
|
||||
// 评论
|
||||
if (this.isComment) {
|
||||
const commentForm = {
|
||||
allowNotification: true,
|
||||
raw: this.form.content,
|
||||
content: this.form.content,
|
||||
owner: {
|
||||
avatar: this.form.avatarUrl,
|
||||
displayName: this.form.author,
|
||||
email: this.form.email,
|
||||
website: this.form.authorUrl,
|
||||
},
|
||||
subjectRef: {
|
||||
group: "content.halo.run",
|
||||
kind: "Post",
|
||||
name: this.form.postName,
|
||||
version: "v1alpha1",
|
||||
}
|
||||
}
|
||||
this.$httpApi.v2.addPostComment(commentForm)
|
||||
.then(res => {
|
||||
uni.$tm.toast('日志:提交成功!');
|
||||
// 更新评论者信息
|
||||
this.handleSetVisitor();
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
})
|
||||
.catch(err => {
|
||||
uni.$tm.toast("提示:评论失败");
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 回复
|
||||
const replyForm = {
|
||||
allowNotification: true,
|
||||
raw: this.form.content,
|
||||
content: this.form.content,
|
||||
owner: {
|
||||
avatar: this.form.avatarUrl,
|
||||
displayName: this.form.author,
|
||||
email: this.form.email,
|
||||
website: this.form.authorUrl,
|
||||
},
|
||||
quoteReply: this.form.postName
|
||||
}
|
||||
this.$httpApi.v2.addPostCommentReply(this.form.postName, replyForm)
|
||||
.then(res => {
|
||||
uni.$tm.toast('提示:提交成功!');
|
||||
// 更新评论者信息
|
||||
this.handleSetVisitor();
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
})
|
||||
.catch(err => {
|
||||
uni.$tm.toast(err.message);
|
||||
uni.$tm.toast("提示:回复失败");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur