diff --git a/miniprogram/api/ToolApi.ts b/miniprogram/api/ToolApi.ts new file mode 100644 index 0000000..1c3d7a6 --- /dev/null +++ b/miniprogram/api/ToolApi.ts @@ -0,0 +1,24 @@ +import { Network } from "../utils/Network"; + +/** + * Tool 工具 API + */ +export class ToolApi { + /** + * 获取备忘录内容 + */ + static getMemo(): Promise { + return Network.get("/journal/tool/memo"); + } + + /** + * 更新备忘录内容 + * + * @param data - 备忘录内容 + */ + static updateMemo(data: string): Promise { + return Network.post("/journal/tool/memo/update", { + data + }); + } +} diff --git a/miniprogram/app.json b/miniprogram/app.json index f0648a9..26bd41d 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -10,6 +10,7 @@ "pages/main/journal/editor/index", "pages/main/journal/map/index", "pages/main/journal/date/index", + "pages/main/other/memo/index", "pages/main/other/portfolio/index", "pages/main/travel/detail/index", "pages/main/travel/editor/index", diff --git a/miniprogram/assets/image/logo.jpg b/miniprogram/assets/image/logo.jpg new file mode 100644 index 0000000..1ca50e9 Binary files /dev/null and b/miniprogram/assets/image/logo.jpg differ diff --git a/miniprogram/assets/image/logo.png b/miniprogram/assets/image/logo.png deleted file mode 100644 index 149d600..0000000 Binary files a/miniprogram/assets/image/logo.png and /dev/null differ diff --git a/miniprogram/config/index.ts b/miniprogram/config/index.ts index e7704ef..463b2fd 100644 --- a/miniprogram/config/index.ts +++ b/miniprogram/config/index.ts @@ -1,12 +1,12 @@ const envArgs = { develop: { - url: "http://localhost:8091" + // url: "http://localhost:8091" // url: "https://api.imyeyu.dev" // url: "https://api.imyeyu.com" // url: "http://192.168.3.123:8091" // url: "http://192.168.3.137:8091" // url: "http://192.168.3.173:8091" - // url: "http://192.168.3.174:8091" + url: "http://192.168.3.174:8091" }, trial: { url: "https://api.imyeyu.com" diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index 6235c47..ea32ca7 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -2,7 +2,7 @@ - + 小糕 diff --git a/miniprogram/pages/main/other/memo/index.json b/miniprogram/pages/main/other/memo/index.json new file mode 100644 index 0000000..7d8f1e9 --- /dev/null +++ b/miniprogram/pages/main/other/memo/index.json @@ -0,0 +1,7 @@ +{ + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-navbar": "tdesign-miniprogram/navbar/navbar" + }, + "disableScroll": true +} \ No newline at end of file diff --git a/miniprogram/pages/main/other/memo/index.less b/miniprogram/pages/main/other/memo/index.less new file mode 100644 index 0000000..3df7b80 --- /dev/null +++ b/miniprogram/pages/main/other/memo/index.less @@ -0,0 +1,66 @@ +// pages/main/other/memo/index.less +.memo { + width: 100%; + min-height: 100vh; + position: relative; + + .content { + width: 100%; + min-height: 100vh; + position: relative; + } + + .status-card { + padding: 2rem 1.5rem; + display: flex; + justify-content: center; + } + + .empty-hint { + padding: 1.5rem 1rem 0 1rem; + } + + .container { + top: 0; + left: 0; + width: 100%; + position: absolute; + + .editor { + width: 100%; + height: 100%; + border: .0625rem solid var(--theme-border-light); + padding: 1rem 1rem 2rem 1rem; + overflow: auto; + font-size: 1rem; + background: var(--theme-bg-primary); + box-sizing: border-box; + line-height: 1.5; + } + } + + .toolbar { + left: 0; + width: 100%; + right: 100%; + height: 3.125rem; + bottom: 0; + border: .0625rem solid var(--theme-border-light); + padding: 0 1rem; + display: flex; + position: fixed; + background: var(--theme-bg-primary); + box-sizing: border-box; + align-items: center; + border-left: none; + border-right: none; + justify-content: space-between; + + .icon { + + &.active { + color: var(--theme-wx); + } + } + } +} diff --git a/miniprogram/pages/main/other/memo/index.ts b/miniprogram/pages/main/other/memo/index.ts new file mode 100644 index 0000000..e4ed370 --- /dev/null +++ b/miniprogram/pages/main/other/memo/index.ts @@ -0,0 +1,162 @@ +// 备忘录页面逻辑 +import { ToolApi } from "../../../../api/ToolApi"; + +type EditorInputEvent = WechatMiniprogram.CustomEvent<{ + html?: string; + text?: string; +}>; + +interface MemoData { + formats: Record; + placeholder: string; + editorHeight: number; + keyboardHeight: number; + isIOS: boolean; + isSaving: boolean; + isEditorReady: boolean; + contentHtml: string; + contentText: string; +} + +Page({ + data: { + formats: {}, + placeholder: "开始输入...", + editorHeight: 300, + keyboardHeight: 0, + isIOS: false, + isSaving: false, + isEditorReady: false, + contentHtml: "", + contentText: "" + }, + editorCtx: null as WechatMiniprogram.EditorContext | null, + pendingHtml: "", + hasSavedOnLeave: false, + hasLoadFailed: false, + async onLoad() { + const platform = wx.getSystemInfoSync().platform; + const isIOS = platform === "ios"; + this.setData({ isIOS }); + this.updatePosition(0); + this.bindKeyboardHeightChange(); + await this.loadMemo(); + }, + onShow() { + this.hasSavedOnLeave = false; + }, + async onUnload() { + await this.saveMemoOnLeave(); + }, + async onHide() { + await this.saveMemoOnLeave(); + }, + bindKeyboardHeightChange() { + let keyboardHeight = 0; + wx.onKeyboardHeightChange((res) => { + if (res.height === keyboardHeight) { + return; + } + const duration = 0 < res.height ? res.duration * 1000 : 0; + keyboardHeight = res.height; + setTimeout(() => { + wx.pageScrollTo({ + scrollTop: 0, + success: () => { + this.updatePosition(keyboardHeight); + this.editorCtx?.scrollIntoView(); + } + }); + }, duration); + }); + }, + updatePosition(keyboardHeight: number) { + const toolbarHeight = 50; + const { windowHeight } = wx.getSystemInfoSync(); + const editorHeight = 0 < keyboardHeight + ? windowHeight - keyboardHeight - toolbarHeight + : windowHeight; + this.setData({ editorHeight, keyboardHeight }); + }, + onEditorReady() { + const query = wx.createSelectorQuery(); + query.select("#memo-editor").context((res) => { + this.editorCtx = (res as { context?: WechatMiniprogram.EditorContext }).context || null; + this.setData({ isEditorReady: true }); + this.applyPendingContent(); + }); + query.exec(); + }, + applyPendingContent() { + if (!this.editorCtx || !this.pendingHtml) { + return; + } + this.editorCtx.setContents({ + html: this.pendingHtml + }); + this.pendingHtml = ""; + }, + onStatusChange(e: WechatMiniprogram.CustomEvent>) { + this.setData({ formats: e.detail || {} }); + }, + format(e: WechatMiniprogram.BaseEvent) { + const { name, value } = e.target.dataset as { name?: string; value?: string | number }; + if (!name || !this.editorCtx) { + return; + } + this.editorCtx.format(name, value); + }, + onEditorInput(e: EditorInputEvent) { + const { html = "", text = "" } = e.detail || {}; + this.setData({ + contentHtml: html, + contentText: text + }); + }, + async loadMemo() { + wx.showLoading({ title: "加载中..", mask: true }); + let shouldGoBack = false; + try { + const contentHtml = await ToolApi.getMemo(); + this.pendingHtml = contentHtml; + this.setData({ + contentHtml, + contentText: this.normalizeMemoText(contentHtml) + }); + this.applyPendingContent(); + } catch (error) { + console.error("加载备忘录失败", error); + this.hasLoadFailed = true; + shouldGoBack = true; + } finally { + wx.hideLoading(); + if (shouldGoBack) { + wx.navigateBack({ delta: 1 }); + } + } + }, + normalizeMemoText(html: string) { + const normalized = html + .replace(/<[^>]*>/g, "") + .replace(/ /g, " ") + .replace(/\s+/g, " ") + .trim(); + return normalized; + }, + async saveMemoOnLeave() { + if (this.hasLoadFailed || this.data.isSaving || this.hasSavedOnLeave) { + return; + } + this.hasSavedOnLeave = true; + this.setData({ isSaving: true }); + wx.showLoading({ title: "保存中..", mask: true }); + try { + await ToolApi.updateMemo(this.data.contentHtml || ""); + } catch (error) { + console.error("保存备忘录失败", error); + } finally { + wx.hideLoading(); + this.setData({ isSaving: false }); + } + } +}); \ No newline at end of file diff --git a/miniprogram/pages/main/other/memo/index.wxml b/miniprogram/pages/main/other/memo/index.wxml new file mode 100644 index 0000000..6e091bb --- /dev/null +++ b/miniprogram/pages/main/other/memo/index.wxml @@ -0,0 +1,65 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/miniprogram/pages/main/tabs/about/index.wxml b/miniprogram/pages/main/tabs/about/index.wxml index 0043e6c..30e4df8 100644 --- a/miniprogram/pages/main/tabs/about/index.wxml +++ b/miniprogram/pages/main/tabs/about/index.wxml @@ -4,7 +4,7 @@ - + 记录 小糕 diff --git a/miniprogram/pages/main/tabs/other/index.ts b/miniprogram/pages/main/tabs/other/index.ts index 52b1e62..779e01f 100644 --- a/miniprogram/pages/main/tabs/other/index.ts +++ b/miniprogram/pages/main/tabs/other/index.ts @@ -14,7 +14,7 @@ Page({ { title: "备忘录", icon: "task-checked", - url: "/pages/main/other/portfolio/index" + url: "/pages/main/other/memo/index" }, { title: "专拍", diff --git a/project.config.json b/project.config.json index 4155c7e..9f6dbca 100644 --- a/project.config.json +++ b/project.config.json @@ -42,7 +42,7 @@ "tabIndent": "tab", "tabSize": 4 }, - "libVersion": "3.10.1", + "libVersion": "3.11.3", "packOptions": { "ignore": [], "include": []