From 8abd0280b7946558ef008b14c217d130f8b7a2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=98=E9=A3=8E?= Date: Wed, 29 Apr 2026 19:08:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E6=96=B0=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../super-article-editor.js | 160 +-------- .../super-article-editor.wxml | 159 +-------- .../super-article-editor.wxss | 310 +----------------- soul-api/__pycache__/master.cpython-311.pyc | Bin 24959 -> 53525 bytes 开发文档/10、项目管理/运营与变更.md | 10 + 开发文档/5、接口/API接口完整文档.md | 40 +++ 6 files changed, 92 insertions(+), 587 deletions(-) diff --git a/miniprogram/pages/super-article-editor/super-article-editor.js b/miniprogram/pages/super-article-editor/super-article-editor.js index d163ecd1..b24da970 100644 --- a/miniprogram/pages/super-article-editor/super-article-editor.js +++ b/miniprogram/pages/super-article-editor/super-article-editor.js @@ -3,18 +3,9 @@ const app = getApp() Page({ data: { statusBarHeight: 44, - // 'input' → 'generating' → 'preview' → 'publishing' - step: 'input', - - // 输入阶段 - description: '', - images: [], // [{tempPath, url, uploading, error}] - - // 预览/编辑阶段 title: '', content: '', - - genError: '', + saving: false, meNickname: '', }, @@ -23,10 +14,10 @@ Page({ statusBarHeight: app.globalData.statusBarHeight || 44, meNickname: String(app.globalData.userInfo?.nickname || '我').trim() || '我', }) - this._checkIdentity() + this.ensureSuperIdentity() }, - async _checkIdentity() { + async ensureSuperIdentity() { const userId = app.globalData.userInfo?.id if (!app.globalData.isLoggedIn || !userId) { wx.showToast({ title: '请先登录', icon: 'none' }) @@ -48,83 +39,6 @@ Page({ } }, - // ─────────────── 图片管理 ─────────────── - - chooseImages() { - const remain = 3 - this.data.images.length - if (remain <= 0) return - wx.chooseMedia({ - count: remain, - mediaType: ['image'], - sourceType: ['album', 'camera'], - success: (res) => { - const newImgs = res.tempFiles.map((f) => ({ - tempPath: f.tempFilePath, - url: '', - uploading: true, - error: false, - })) - const images = [...this.data.images, ...newImgs] - this.setData({ images }) - // 并发上传 - newImgs.forEach((img, offset) => { - const idx = this.data.images.length - newImgs.length + offset - this._uploadImage(img.tempPath, idx) - }) - }, - }) - }, - - async _uploadImage(tempPath, idx) { - const baseUrl = app.globalData.baseUrl || '' - const token = wx.getStorageSync('token') || '' - return new Promise((resolve) => { - wx.uploadFile({ - url: `${baseUrl}/api/upload`, - filePath: tempPath, - name: 'file', - formData: { folder: 'article-images' }, - header: token ? { Authorization: `Bearer ${token}` } : {}, - success: (res) => { - try { - const parsed = JSON.parse(res.data) - if (parsed.success && parsed.url) { - this._updateImage(idx, { url: parsed.url, uploading: false, error: false }) - resolve(parsed.url) - return - } - } catch (_) { /* ignore */ } - this._updateImage(idx, { uploading: false, error: true }) - resolve('') - }, - fail: () => { - this._updateImage(idx, { uploading: false, error: true }) - resolve('') - }, - }) - }) - }, - - _updateImage(idx, patch) { - const images = [...this.data.images] - if (images[idx]) { - images[idx] = { ...images[idx], ...patch } - this.setData({ images }) - } - }, - - removeImage(e) { - const idx = Number(e.currentTarget.dataset.index) - const images = this.data.images.filter((_, i) => i !== idx) - this.setData({ images }) - }, - - // ─────────────── 输入 ─────────────── - - onDescInput(e) { - this.setData({ description: e.detail.value || '' }) - }, - onTitleInput(e) { this.setData({ title: e.detail.value || '' }) }, @@ -133,63 +47,25 @@ Page({ this.setData({ content: e.detail.value || '' }) }, - // ─────────────── AI 生成 ─────────────── - - async generateArticle() { - if (this.data.step === 'generating') return - const desc = String(this.data.description || '').trim() - if (!desc) { - wx.showToast({ title: '请先填写描述', icon: 'none' }) - return - } - - // 等待所有图片上传完成 - const stillUploading = this.data.images.some((img) => img.uploading) - if (stillUploading) { - wx.showToast({ title: '图片上传中,请稍候', icon: 'none' }) - return - } - - const imageUrls = this.data.images.filter((img) => img.url).map((img) => img.url) - const userId = app.globalData.userInfo?.id || '' - - this.setData({ step: 'generating', genError: '' }) - - try { - const res = await app.request({ - url: '/api/miniprogram/super/articles/generate', - method: 'POST', - data: { userId, description: desc, imageUrls }, - timeout: 90000, - }) - if (!res?.success) throw new Error(res?.error || 'AI 生成失败') - this.setData({ - step: 'preview', - title: String(res.data?.title || '').trim(), - content: String(res.data?.content || '').trim(), - }) - } catch (err) { - this.setData({ step: 'input', genError: err.message || 'AI 生成失败,请重试' }) - wx.showToast({ title: this.data.genError, icon: 'none', duration: 2500 }) - } + insertMentionSelf() { + const nick = this.data.meNickname || '我' + this.setData({ content: `${this.data.content}@${nick} ` }) }, - backToInput() { - this.setData({ step: 'input', genError: '' }) + insertHashLink() { + this.setData({ content: `${this.data.content}#链接(https://)` }) }, - // ─────────────── 发布 ─────────────── - async submitArticle() { - if (this.data.step === 'publishing') return + if (this.data.saving) return const userId = app.globalData.userInfo?.id const title = String(this.data.title || '').trim() const content = String(this.data.content || '').trim() if (!title || !content) { - wx.showToast({ title: '标题和正文不能为空', icon: 'none' }) + wx.showToast({ title: '请填写标题和正文', icon: 'none' }) return } - this.setData({ step: 'publishing' }) + this.setData({ saving: true }) try { const res = await app.request({ url: '/api/miniprogram/super/articles', @@ -201,22 +77,12 @@ Page({ setTimeout(() => wx.navigateBack(), 400) } catch (e) { wx.showToast({ title: e.message || '发布失败', icon: 'none' }) - this.setData({ step: 'preview' }) + } finally { + this.setData({ saving: false }) } }, goBack() { wx.navigateBack({ fail: () => wx.switchTab({ url: '/pages/my/my' }) }) }, - - // ─────────────── 手动添加 @自己 / #链接 ─────────────── - - insertMentionSelf() { - const nick = this.data.meNickname || '我' - this.setData({ content: `${this.data.content}@${nick} ` }) - }, - - insertHashLink() { - this.setData({ content: `${this.data.content}#链接(https://)` }) - }, }) diff --git a/miniprogram/pages/super-article-editor/super-article-editor.wxml b/miniprogram/pages/super-article-editor/super-article-editor.wxml index 8ff8647d..ee8528d3 100644 --- a/miniprogram/pages/super-article-editor/super-article-editor.wxml +++ b/miniprogram/pages/super-article-editor/super-article-editor.wxml @@ -1,166 +1,29 @@ - - - {{step === 'preview' || step === 'publishing' ? '预览 & 发布' : 'AI 写文章'}} + 发文章 - - - 人工智能生成 - 本服务为AI生成内容,结果仅供参考,请自行核对后再发布 - - - - - - - - - 📷 - 添加图片 - 选填,最多3张,AI 可理解图片内容 - - - - - - - - - - - 上传失败 - - - × - - - - - + - 拍照/相册 - - + + 标题 + + - - - - ✏️ - 用几句话描述你想写什么 - - -