feat: 首页发布增加发布类型选择(公开/私有/私信)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
刘正航
2026-05-14 21:20:57 +08:00
parent b8acc8be43
commit a0f7a758eb
2 changed files with 49 additions and 4 deletions

View File

@@ -7,13 +7,23 @@ const QUICK_TEXTS = [
'高薪兼职日结,扫码进群立刻赚钱。' '高薪兼职日结,扫码进群立刻赚钱。'
] ]
const VISIBILITY_OPTIONS = [
{ value: 'public', label: '公开信息发布' },
{ value: 'private', label: '私有信息发布' },
{ value: 'direct', label: '用户私信发布' }
]
Page({ Page({
data: { data: {
loading: false, loading: false,
user: null, user: null,
text: '', text: '',
result: null, result: null,
quickTexts: QUICK_TEXTS quickTexts: QUICK_TEXTS,
visibilityOptions: VISIBILITY_OPTIONS,
visibilityIndex: 0,
visibility: 'public',
recipientUsername: ''
}, },
onShow() { onShow() {
@@ -43,13 +53,20 @@ Page({
}, },
onInput(e) { onInput(e) {
this.setData({ text: e.detail.value || '' }) const field = e.currentTarget.dataset.field || 'text'
this.setData({ [field]: e.detail.value || '' })
}, },
fillQuick(e) { fillQuick(e) {
this.setData({ text: e.currentTarget.dataset.text || '' }) this.setData({ text: e.currentTarget.dataset.text || '' })
}, },
onVisibilityChange(e) {
const idx = Number(e.detail.value)
const row = this.data.visibilityOptions[idx] || this.data.visibilityOptions[0]
this.setData({ visibilityIndex: idx, visibility: row.value })
},
async publish() { async publish() {
if (this.data.loading) return if (this.data.loading) return
const text = (this.data.text || '').trim() const text = (this.data.text || '').trim()
@@ -58,12 +75,26 @@ Page({
return return
} }
const payload = {
text,
visibility: this.data.visibility
}
if (this.data.visibility === 'direct') {
const receiver = (this.data.recipientUsername || '').trim()
if (!receiver) {
wx.showToast({ title: '私信请填写接收人用户名', icon: 'none' })
return
}
payload.recipient_username = receiver
}
this.setData({ loading: true }) this.setData({ loading: true })
try { try {
const result = await request({ const result = await request({
url: '/content/publish', url: '/content/publish',
method: 'POST', method: 'POST',
data: { text } data: payload
}) })
this.setData({ this.setData({

View File

@@ -10,10 +10,24 @@
<view class="field"> <view class="field">
<text class="field-label">内容文本</text> <text class="field-label">内容文本</text>
<textarea class="textarea" placeholder="请输入要发布的文本信息" value="{{text}}" bindinput="onInput" /> <textarea class="textarea" placeholder="请输入要发布的文本信息" value="{{text}}" data-field="text" bindinput="onInput" />
<view class="field-help">当前字数:{{text.length}},建议不少于 2 个字符。</view> <view class="field-help">当前字数:{{text.length}},建议不少于 2 个字符。</view>
</view> </view>
<view class="field">
<view class="row">
<text class="field-label">发布类型</text>
<picker mode="selector" range="{{visibilityOptions}}" range-key="label" value="{{visibilityIndex}}" bindchange="onVisibilityChange">
<view class="picker-value">{{visibilityOptions[visibilityIndex].label}}</view>
</picker>
</view>
</view>
<view class="field" wx:if="{{visibility === 'direct'}}">
<text class="field-label">接收人用户名</text>
<input class="input" placeholder="私信发送时必填" value="{{recipientUsername}}" data-field="recipientUsername" bindinput="onInput" />
</view>
<view class="field" wx:if="{{result}}"> <view class="field" wx:if="{{result}}">
<text class="field-label">识别反馈</text> <text class="field-label">识别反馈</text>
<view class="row"> <view class="row">