diff --git a/miniprogram/pages/home/index.js b/miniprogram/pages/home/index.js
index 38a19e6..32f3ff1 100644
--- a/miniprogram/pages/home/index.js
+++ b/miniprogram/pages/home/index.js
@@ -7,13 +7,23 @@ const QUICK_TEXTS = [
'高薪兼职日结,扫码进群立刻赚钱。'
]
+const VISIBILITY_OPTIONS = [
+ { value: 'public', label: '公开信息发布' },
+ { value: 'private', label: '私有信息发布' },
+ { value: 'direct', label: '用户私信发布' }
+]
+
Page({
data: {
loading: false,
user: null,
text: '',
result: null,
- quickTexts: QUICK_TEXTS
+ quickTexts: QUICK_TEXTS,
+ visibilityOptions: VISIBILITY_OPTIONS,
+ visibilityIndex: 0,
+ visibility: 'public',
+ recipientUsername: ''
},
onShow() {
@@ -43,13 +53,20 @@ Page({
},
onInput(e) {
- this.setData({ text: e.detail.value || '' })
+ const field = e.currentTarget.dataset.field || 'text'
+ this.setData({ [field]: e.detail.value || '' })
},
fillQuick(e) {
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() {
if (this.data.loading) return
const text = (this.data.text || '').trim()
@@ -58,12 +75,26 @@ Page({
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 })
try {
const result = await request({
url: '/content/publish',
method: 'POST',
- data: { text }
+ data: payload
})
this.setData({
diff --git a/miniprogram/pages/home/index.wxml b/miniprogram/pages/home/index.wxml
index 08e0d87..476e092 100644
--- a/miniprogram/pages/home/index.wxml
+++ b/miniprogram/pages/home/index.wxml
@@ -10,10 +10,24 @@
内容文本
-
+
当前字数:{{text.length}},建议不少于 2 个字符。
+
+
+ 发布类型
+
+ {{visibilityOptions[visibilityIndex].label}}
+
+
+
+
+
+ 接收人用户名
+
+
+
识别反馈