前端 uni-app 重写: 9页面 H5

This commit is contained in:
zhiqui
2026-11-15 15:09:37 +08:00
parent 513b53672e
commit ea7c2529e9
24104 changed files with 3667749 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<script>
export default { onLaunch() {} };
</script>
<style>
page { background: #0d0e18; color: #f2f4ff; font-size: 15px;
font-family: -apple-system, "PingFang SC", sans-serif; }
.glass { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.22);
border-radius: 20px; padding: 14px; margin-bottom: 12px; }
.btn { background: rgba(124,154,255,.25); border: 1px solid rgba(255,255,255,.22);
color: #f2f4ff; border-radius: 14px; padding: 8px 16px; font-size: 14px; display: inline-block; }
.btn.primary { background: #7c9aff; color: #0d0e18; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { background: rgba(255,90,90,.3); }
input, textarea, select { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.2);
border-radius: 12px; color: #f2f4ff; padding: 10px; font-size: 14px; width: 100%;
box-sizing: border-box; margin-bottom: 10px; }
.hint { color: rgba(242,244,255,.55); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
.tag { background: rgba(124,154,255,.18); border-radius: 8px; padding: 1px 8px;
font-size: 11px; color: #7c9aff; }
</style>
+3
View File
@@ -0,0 +1,3 @@
import App from "./App.vue";
import { createSSRApp } from "vue";
export function createApp() { const app = createSSRApp(App); return { app }; }
+6
View File
@@ -0,0 +1,6 @@
{
"name": "Open Maopaoya",
"appid": "",
"vueVersion": "3",
"h5": { "router": { "mode": "hash" }, "title": "Open Maopaoya" }
}
+14
View File
@@ -0,0 +1,14 @@
{
"pages": [
{ "path": "pages/login/index", "style": { "navigationStyle": "custom" } },
{ "path": "pages/shelf/index", "style": { "navigationBarTitleText": "书架" } },
{ "path": "pages/characters/index","style": { "navigationBarTitleText": "角色" } },
{ "path": "pages/novels/index", "style": { "navigationBarTitleText": "动态小说" } },
{ "path": "pages/chat/index", "style": { "navigationBarTitleText": "对话" } },
{ "path": "pages/moments/index", "style": { "navigationBarTitleText": "朋友圈" } },
{ "path": "pages/plaza/index", "style": { "navigationBarTitleText": "广场" } },
{ "path": "pages/channels/index", "style": { "navigationBarTitleText": "渠道" } },
{ "path": "pages/admin/index", "style": { "navigationBarTitleText": "后台" } }
],
"globalStyle": { "navigationBarTextStyle": "white", "navigationBarBackgroundColor": "#141528", "backgroundColor": "#0d0e18" }
}
+56
View File
@@ -0,0 +1,56 @@
<template>
<view style="padding:14px">
<view class="glass"><text style="font-weight:600">权限开关</text>
<view v-for="(v, k) in toggles" :key="k" class="row spread" style="margin-top:8px">
<text>{{ labels[k] || k }}</text>
<button class="btn small" :class="v === 'true' ? 'primary' : ''" @click="toggle(k, v)">
{{ v === 'true' ? '开' : '关' }}</button>
</view>
</view>
<view class="glass"><view class="row spread"><text style="font-weight:600">用户管理</text>
<text class="hint">用户 {{ stats.users }} · 会话 {{ stats.sessions }}</text></view>
<view class="row" style="margin:8px 0">
<button class="btn small primary" @click="createUser">+ 新建用户</button>
</view>
<view v-for="x in users" :key="x.id" class="row spread" style="margin-bottom:6px">
<text>{{ x.username }} {{ x.is_admin ? '(管理员)' : '' }}{{ x.is_active ? '' : ' [封禁]' }}</text>
<view class="row">
<button class="btn small" @click="patch(x.id, { is_active: !x.is_active })">
{{ x.is_active ? '封禁' : '解封' }}</button>
<button class="btn small" @click="resetPwd(x)">改密</button>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast } from "../../utils/api";
const toggles = ref({}), users = ref([]), stats = ref({});
const labels = { allow_register: "允许注册", allow_delete_account: "允许注销",
allow_byok: "允许自定义API", admin_data_visible: "数据可见(关=加密)" };
async function load() {
toggles.value = await api("/admin/settings");
const u = await api("/admin/users");
users.value = u.users; stats.value = u.stats;
}
load();
async function toggle(k, cur) {
await api(`/admin/settings?key=${k}&value=${cur === 'true' ? 'false' : 'true'}`, { method: "POST" });
load();
}
async function patch(id, body) { await api(`/admin/users/${id}`, { method: "PATCH", body }); load(); }
function createUser() {
uni.showModal({ editable: true, placeholderText: "用户名,密码",
success: async m => { if (!m.content) return;
const [username, password] = m.content.split(",");
try { await api("/admin/users", { method: "POST", body: { username, password } });
load(); toast("已创建"); } catch (e) { toast(e.message); } } });
}
function resetPwd(x) {
uni.showModal({ editable: true, placeholderText: "新密码",
success: async m => { if (!m.content) return;
await api(`/admin/users/${x.id}`, { method: "PATCH", body: { new_password: m.content } });
toast("已重置"); } });
}
</script>
+38
View File
@@ -0,0 +1,38 @@
<template>
<view style="padding:14px">
<button class="btn primary" @click="adding = true">+ 添加渠道</button>
<view v-if="adding" class="glass">
<input v-model="f.name" placeholder="渠道名" />
<input v-model="f.base_url" placeholder="Base URL (OpenAI兼容)" />
<input v-model="f.api_key" password placeholder="API Key" />
<view class="row"><button class="btn primary" @click="save">保存</button>
<button class="btn" @click="adding = false">取消</button></view>
</view>
<view v-for="c in chans" :key="c.id" class="glass">
<view class="row spread"><text style="font-weight:600">{{ c.name }}</text>
<text class="tag">{{ c.visibility }}</text></view>
<view class="hint">{{ c.base_url }}</view>
<view class="row" style="margin-top:6px">
<button class="btn small" @click="test(c)">测试</button>
<button class="btn small danger" @click="del(c)">删</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast } from "../../utils/api";
const chans = ref([]), adding = ref(false);
const f = ref({ name: "", base_url: "", api_key: "" });
async function load() { chans.value = (await api("/channels")).channels; }
load();
async function save() {
await api("/channels", { method: "POST", body: { ...f.value, models: {}, visibility: "admin" } });
adding.value = false; load(); toast("已保存");
}
async function test(c) {
try { const d = await api(`/channels/${c.id}/test`); toast(d.ok ? "✅ 通" : "❌ " + d.message); }
catch (e) { toast(e.message); }
}
async function del(c) { await api(`/channels/${c.id}`, { method: "DELETE" }); load(); }
</script>
@@ -0,0 +1,48 @@
<template>
<view style="padding:14px">
<button class="btn primary" @click="edit(0)">+ 新建角色</button>
<view v-for="c in chars" :key="c.id" class="glass">
<view class="row spread"><text style="font-weight:600">{{ c.name }}</text>
<text v-if="c.source!=='manual'" class="tag">{{ c.source==='novel_auto'?'AI生成':'导入' }}</text></view>
<view class="hint" style="margin:6px 0">{{ c.persona || '(无人设)' }}</view>
<view class="row">
<button class="btn small primary" @click="startChat(c)">对话</button>
<button class="btn small" @click="edit(c.id)">编辑</button>
<button class="btn small" @click="share(c)">分享</button>
<button class="btn small danger" @click="del(c)">删</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast } from "../../utils/api";
const chars = ref([]);
async function load() { chars.value = (await api("/characters")).characters; }
load();
function startChat(c) {
api("/sessions", { method: "POST", body: { mode: "roleplay", character_id: c.id } })
.then(s => uni.navigateTo({ url: `/pages/chat/index?sid=${s.id}&mode=roleplay` }));
}
function edit(id) {
api("/characters").then(d => {
const c = d.characters.find(x => x.id === id) || { name: "", persona: "", greeting: "", voice: "tongtong" };
uni.showModal({ editable: true, placeholderText: "名字,人设,开场白(逗号分隔)",
content: [c.name, c.persona, c.greeting].join(","),
success: async m => { if (!m.content) return;
const [name, persona = "", greeting = ""] = m.content.split(",");
const body = { name, persona, greeting, voice: c.voice, avatar_url: c.avatar_url || "" };
if (id) await api(`/characters/${id}`, { method: "PATCH", body });
else await api("/characters", { method: "POST", body });
load(); } });
});
}
async function share(c) {
const d = await api(`/characters/${c.id}/export`);
toast("分享码: " + d.share_code);
}
async function del(c) {
uni.showModal({ content: "删除 " + c.name + "?", success: async m => {
if (m.confirm) { await api(`/characters/${c.id}`, { method: "DELETE" }); load(); } } });
}
</script>
+72
View File
@@ -0,0 +1,72 @@
<template>
<view style="padding:14px;display:flex;flex-direction:column;height:100vh;box-sizing:border-box">
<scroll-view scroll-y style="flex:1" :scroll-top="scrollTop" scroll-anchoring>
<view v-for="m in msgs" :key="m.id" class="bubble" :class="m.role === 'user' ? 'me' : ''">
<view v-if="m.speaker" class="hint">{{ m.speaker }}</view>
<text>{{ m.content }}</text>
<view class="row" style="margin-top:4px;opacity:.5">
<text class="mini" @click="star(m)">{{ m.starred ? '⭐' : '☆' }}</text>
<text v-if="m.role !== 'user'" class="mini" @click="regen(m)">🎲</text>
<text v-if="m.role !== 'user'" class="mini" @click="tts(m)">🔊</text>
<text v-if="(m.swipe_count || 0) > 1" class="mini">{{ m.active_swipe + 1 }}/{{ m.swipe_count }}
<text @click="swipe(m, -1)">‹</text><text @click="swipe(m, 1)">›</text></text>
</view>
</view>
<view v-if="sending" class="bubble">…</view>
</scroll-view>
<view class="row" style="padding-top:10px">
<input v-model="text" placeholder="说点什么…" style="flex:1" @confirm="send" />
<button class="btn primary" @click="send">发</button>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { api, token, toast } from "../../utils/api";
const msgs = ref([]), text = ref(""), sending = ref(false), scrollTop = ref(0);
let sid = 0, mode = "roleplay";
onLoad(o => { sid = +o.sid; mode = o.mode || "roleplay"; load(); });
async function load() {
const d = await api(`/sessions/${sid}/messages`);
msgs.value = d.messages; scrollTop.value = msgs.value.length * 500;
}
async function send() {
const t = text.value.trim(); if (!t || sending.value) return;
sending.value = true; text.value = "";
try {
const url = mode === "group" ? `/sessions/${sid}/send_group` : `/sessions/${sid}/send`;
const d = await api(url, { method: "POST", body: { content: t } });
await load();
(d.new_characters || []).forEach(c =>
toast("✨ 新角色入场: " + c.name));
} catch (e) { toast(e.message); }
sending.value = false;
}
async function regen(m) {
await api(`/messages/${m.id}/regenerate`, { method: "POST" }); load();
}
async function swipe(m, delta) {
await api(`/messages/${m.id}/swipe`, { method: "POST", body: { delta } }); load();
}
async function star(m) {
await api(`/messages/${m.id}/star`, { method: "POST", body: { starred: !m.starred } }); load();
}
async function tts(m) {
const r = await uni.request({
url: `/api/sessions/${sid}/tts/${m.id}`,
header: { Authorization: "Bearer " + token() }, responseType: "arraybuffer" });
// H5 环境:转 base64 播放
let bin = ""; const bytes = new Uint8Array(r.data);
for (let i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);
const audio = uni.createInnerAudioContext();
audio.src = "data:audio/wav;base64," + uni.arrayBufferToBase64(r.data);
audio.play();
}
</script>
<style>
.bubble { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.2);
border-radius: 16px; padding: 10px 12px; margin-bottom: 8px; max-width: 85%; }
.bubble.me { margin-left: auto; background: rgba(124,154,255,.25); }
.mini { font-size: 12px; margin-right: 8px; }
</style>
+32
View File
@@ -0,0 +1,32 @@
<template>
<view class="wrap">
<view class="glass card">
<view style="font-size:26px;text-align:center">🦆 Open Maopaoya</view>
<view class="hint" style="text-align:center;margin:6px 0 14px">冒泡鸭开源复刻 · 动态小说引擎</view>
<input v-model="u" placeholder="用户名" />
<input v-model="p" password placeholder="密码" />
<view class="row" style="margin-top:6px">
<button class="btn primary" style="flex:1" @click="doLogin">登录</button>
<button class="btn" style="flex:1" @click="doRegister">注册</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast } from "../../utils/api";
const u = ref(""), p = ref("");
async function _auth(path) {
try {
const d = await api(path, { method: "POST", body: { username: u.value, password: p.value } });
uni.setStorageSync("token", d.token);
uni.reLaunch({ url: "/pages/shelf/index" });
} catch (e) { toast(e.message); }
}
const doLogin = () => _auth("/auth/login");
const doRegister = () => _auth("/auth/register");
</script>
<style>
.wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card { width: 100%; max-width: 420px; }
</style>
+39
View File
@@ -0,0 +1,39 @@
<template>
<view style="padding:14px">
<button class="btn primary" @click="pick">让角色发一条</button>
<view v-for="m in feed" :key="m.id" class="glass">
<view class="row spread"><text style="font-weight:600">{{ m.author }}</text></view>
<view style="margin:8px 0">{{ m.content }}</view>
<image v-if="m.image_url" :src="m.image_url" mode="widthFix" style="width:100%;border-radius:12px" />
<view class="row">
<button class="btn small" :class="m.liked_by_me ? 'primary' : ''" @click="like(m)">❤</button>
<button class="btn small" @click="comment(m)">评论</button>
</view>
<view v-for="(cm, i) in m.comments || []" :key="i" class="hint">💬 {{ cm.author }}: {{ cm.content }}</view>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast } from "../../utils/api";
const feed = ref([]);
async function load() { feed.value = (await api("/moments")).moments; }
load();
async function pick() {
const d = await api("/characters");
uni.showActionSheet({
itemList: d.characters.slice(0, 6).map(c => c.name),
success: async r => {
await api("/moments/generate", { method: "POST", body: {
character_id: d.characters[r.tapIndex].id, topic: "" } });
load();
} });
}
async function like(m) { await api(`/moments/${m.id}/like`, { method: "POST" }); load(); }
function comment(m) {
uni.showModal({ editable: true, placeholderText: "说点什么…",
success: async r => { if (r.content) {
await api(`/moments/${m.id}/comment`, { method: "POST", body: { content: r.content } });
load(); } } });
}
</script>
+31
View File
@@ -0,0 +1,31 @@
<template>
<view style="padding:14px">
<button class="btn primary" @click="creating = true">📖 开新小说</button>
<view class="hint" style="margin:8px 0">AI 编剧自主写剧情、引入新角色并自动建档生成立绘。</view>
<view v-if="creating" class="glass">
<input v-model="t" placeholder="小说标题" />
<textarea v-model="s" placeholder="设定:世界观、主角、开篇场景…" style="height:100px" />
<view class="row"><button class="btn primary" @click="create">开写</button>
<button class="btn" @click="creating = false">取消</button></view>
</view>
<view v-for="n in novels" :key="n.id" class="glass" @click="open(n)">
<text>{{ n.title }}</text> <text class="tag">AI自主扩列</text>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api } from "../../utils/api";
const novels = ref([]), creating = ref(false), t = ref(""), s = ref("");
async function load() {
const d = await api("/sessions");
novels.value = d.sessions.filter(x => x.mode === "novel");
}
load();
async function create() {
const r = await api("/sessions", { method: "POST", body: {
mode: "novel", title: t.value || "未命名小说", novel_setting: s.value } });
uni.navigateTo({ url: `/pages/chat/index?sid=${r.id}&mode=novel` });
}
function open(n) { uni.navigateTo({ url: `/pages/chat/index?sid=${n.id}&mode=novel` }); }
</script>
+25
View File
@@ -0,0 +1,25 @@
<template>
<view style="padding:14px">
<view class="row"><input v-model="q" placeholder="搜索公开角色" style="flex:1" @confirm="load" />
<button class="btn" @click="load">搜</button></view>
<view v-for="c in chars" :key="c.id" class="glass">
<text style="font-weight:600">{{ c.name }}</text> <text class="tag">{{ c.tags }}</text>
<view class="hint" style="margin:6px 0">{{ (c.persona || '').slice(0, 60) }}</view>
<button class="btn small primary" @click="clone(c)">领养</button>
</view>
<view class="hint" style="margin-top:10px">有分享码?</view>
<input v-model="code" placeholder="输入分享码导入" @confirm="importCode" />
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast } from "../../utils/api";
const chars = ref([]), q = ref(""), code = ref("");
async function load() { chars.value = (await api("/plaza?q=" + encodeURIComponent(q.value))).characters; }
load();
async function clone(c) { await api(`/characters/${c.id}/clone`, { method: "POST" }); toast("已领养"); }
async function importCode() {
try { await api("/characters/import", { method: "POST", body: { share_code: code.value } });
toast("导入成功"); } catch (e) { toast(e.message); }
}
</script>
+69
View File
@@ -0,0 +1,69 @@
<template>
<view style="padding:14px">
<view class="row spread" style="margin-bottom:10px">
<button class="btn primary" @click="newChat">+ 新对话</button>
<button class="btn" @click="go('/pages/novels/index')">📖 小说</button>
<button class="btn" @click="go('/pages/moments/index')">🌟 朋友圈</button>
<button class="btn" @click="go('/pages/plaza/index')">🏪</button>
<button class="btn" @click="go('/pages/channels/index')">🔌</button>
<button v-if="me.is_admin" class="btn" @click="go('/pages/admin/index')">⚙️</button>
</view>
<input placeholder="🔍 搜索所有会话内容" v-model="q" @confirm="search" />
<view v-for="r in results" :key="'r'+r.session_id" class="glass" @click="openSession(r.session_id, r.mode)">
<text class="hint">{{ r.speaker || '' }}: {{ r.snippet }}</text>
</view>
<view v-for="s in sessions" :key="s.id" class="glass" @click="openSession(s.id, s.mode)">
<view class="row spread">
<text>{{ s.pinned ? '📌 ' : '' }}{{ s.title }}</text>
<text class="tag">{{ { roleplay:'角色扮演', novel:'动态小说', group:'群聊' }[s.mode] || s.mode }}</text>
</view>
<view class="row" style="margin-top:6px">
<button class="btn small" @click.stop="rename(s)">✏️</button>
<button class="btn small" @click.stop="archive(s)">📦</button>
</view>
</view>
<view v-if="!sessions.length" class="hint">还没有会话,点「新对话」开一个。</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast, go } from "../../utils/api";
const sessions = ref([]), me = ref({}), q = ref(""), results = ref([]);
async function load() {
me.value = await api("/auth/me");
const d = await api("/sessions");
sessions.value = d.sessions.filter(s => !s.archived)
.sort((a, b) => (b.pinned - a.pinned) || (b.id - a.id));
}
async function search() {
if (!q.value) return;
const d = await api("/search?q=" + encodeURIComponent(q.value));
results.value = d.results.slice(0, 10);
}
function openSession(id, mode) {
uni.setStorageSync("curSession", id);
uni.navigateTo({ url: `/pages/chat/index?sid=${id}&mode=${mode}` });
}
async function newChat() {
const d = await api("/characters");
uni.showActionSheet({
itemList: d.characters.slice(0, 6).map(c => c.name),
success: async r => {
const s = await api("/sessions", { method: "POST", body: {
mode: "roleplay", character_id: d.characters[r.tapIndex].id } });
openSession(s.id, "roleplay");
},
});
}
async function rename(s) {
uni.showModal({ editable: true, placeholderText: "新标题", content: s.title,
success: async m => { if (m.content) {
await api(`/sessions/${s.id}/settings`, { method: "PATCH", body: { title: m.content } });
load(); } } });
}
async function archive(s) {
await api(`/sessions/${s.id}/settings`, { method: "PATCH", body: { archived: !s.archived } });
load();
}
load();
</script>
+14
View File
@@ -0,0 +1,14 @@
const BASE = "/api";
export const token = () => uni.getStorageSync("token") || "";
export async function api(path, opts = {}) {
const r = await uni.request({
url: BASE + path,
method: opts.method || "GET",
data: opts.body,
header: { "Content-Type": "application/json", Authorization: "Bearer " + token() },
});
if (r.statusCode >= 400) throw new Error((r.data && r.data.detail) || r.statusCode);
return r.data;
}
export function toast(t) { uni.showToast({ title: String(t).slice(0, 40), icon: "none" }); }
export function go(url) { uni.navigateTo({ url }); }