所有页面的语法改写为setup形式;

修改了Header组件的样式、布局;
更新了IFLOW上下文;
添加了全局样式;
添加了pinia状态管理;
This commit is contained in:
User
2025-10-10 11:43:51 +08:00
parent 0d4c7353f4
commit e40288e8ef
20 changed files with 2147 additions and 1521 deletions

View File

@@ -9,7 +9,7 @@
* **核心框架**: Vue 3 (Composition API)
* **构建工具**: Vite
* **路由管理**: vue-router
* **状态管理**: Vue 3 响应式系统 (`reactive`, `provide`, `inject`)
* **状态管理**: Pinia (Vue 3 状态管理库)
* **UI 库**: 原生 CSS使用了锤子便签的经典配色方案定义在 `index.html` 的 CSS 变量中)
* **移动端支持**: Capacitor (用于构建 Android/iOS 应用)
* **代码语言**: JavaScript (ES6+)
@@ -17,18 +17,21 @@
## 项目结构
```
J:\git\SmartisanNote.vue
.
├── android/ # Capacitor Android 项目文件
├── dist/ # 构建后的生产文件
├── node_modules/ # 项目依赖
├── public/ # 静态资源目录
├── src/
│ ├── common/ # 全局样式和通用工具
│ ├── components/ # 可复用的 Vue 组件 (Header, NoteItem, FolderItem)
│ ├── pages/ # 页面级别的 Vue 组件 (NoteList, NoteDetail, NoteEditor, Folder, Settings)
│ ├── utils/ # 工具函数和数据上下文管理
│ │ ── AppDataContext.js # 全局状态管理provide/inject和数据操作函数
│ ├── stores/ # Pinia 状态管理 stores
│ │ ── useAppStore.js # 全局状态管理 store
│ ├── utils/ # 工具函数
│ │ └── storage.js # localStorage 封装,负责数据的读写
│ ├── App.vue # 根组件,包裹 AppDataProvider
│ └── main.js # 应用入口,初始化路由和挂载
│ ├── App.vue # 根组件
│ └── main.js # 应用入口,初始化路由、Pinia 和挂载
├── index.html # HTML 模板,包含 CSS 变量定义
├── package.json # 项目元数据和脚本命令
├── vite.config.js # Vite 构建配置
@@ -49,11 +52,57 @@ J:\git\SmartisanNote.vue
* **测试**: `npm run test`
* 当前脚本未定义具体测试命令。
## 开发规范与约定
## 代码规范与开发约定
* **状态管理**: 使用 `AppDataContext.js` 中的 `provide`/`inject` 模式进行全局状态管理,避免使用 Vuex 或 Pinia
* **状态管理**: 使用 Pinia 进行全局状态管理,通过 `useAppStore` composable 函数访问状态
* **数据持久化**: 所有数据(便签、文件夹、设置)均通过 `src/utils/storage.js``localStorage` 进行交互。
* **路由**: 使用 `vue-router``createWebHashHistory` 进行前端路由管理。
* **UI 风格**: 颜色方案严格遵循 `index.html` 中定义的 CSS 变量,以保持锤子便签的视觉风格。
* **组件组织**: 页面组件 (`pages/`) 和可复用组件 (`components/`) 分离,结构清晰。
* **代码风格**: 采用标准的 Vue 3 Composition API 写法,使用 ES6 模块系统 (`import`/`export`)。
* **代码风格**: 采用标准的 Vue 3 Composition API 写法,使用 ES6 模块系统 (`import`/`export`)。
## 样式
* 全局样式文件是位于 `common/` 目录下的 `base.css`
* `common.css` 提供了codefun原子类样式用于快速布局。
* 样式规范应遵循项目中已有的风格。
## JavaScript
* 严格遵循ES6规范。
* 遵循JavaScript函数式编程范式。
* 方法类函数应该使用 `function` 进行定义。
* 避免出现超过4个以上的 `ref`超过4个则使用 `reactive`
* 全局变量都集中放置于代码顶部。
* 变量名使用小驼峰命名法。
* 常量名使用全大写。
* 状态类变量命名参考 `isLogin``isOpen`
* 事件类方法命名参考 `onClick``onSelect`
* 变量都应该写有注释说明、类型说明。
* `Promise` 方法使用 `async` `await` 写法,并进行容错处理。
* 字符串拼接使用ES6的模板语法。
* JavaScript规范应遵循项目中已有的风格。
## 组件
* 项目集成了 `ionic framework` 组件库。
* 全局组件放在 `components/` 目录下。
* 页面独立组件放在页面根目录下的 `components/`
* 每个组件应该附带 `README.MD` 文档。
* 组件编写应遵循项目中已有的风格。
## 页面
* 页面使用 Composition API (setup语法糖) 编写。
* 注释、结构规范应遵循项目中已有的风格。
## 状态管理 (Pinia)
项目现在使用 Pinia 作为状态管理解决方案,主要特点包括:
* **Store 定义**: 在 `src/stores/useAppStore.js` 中定义了全局状态 store
* **状态结构**: 包含 notes、folders 和 settings 三个主要状态
* **Getters**: 提供了计算属性如 starredNotesCount 和 allNotesCount
* **Actions**: 包含所有状态变更操作,如 addNote、updateNote、deleteNote 等
* **数据持久化**: 通过 storage.js 工具函数与 localStorage 进行数据交互
* **使用方式**: 在组件中通过 `const store = useAppStore()` 来访问状态和方法

View File

@@ -2,8 +2,8 @@
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

846
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,10 +5,8 @@
"main": "index.js",
"scripts": {
"android": "npx cap run android",
"dev": "vite",
"build": "vite build && npx cap sync",
"preview": "vite preview",
"test": "echo \"Error: no test specified\" && exit 1"
"dev":"vite"
},
"keywords": [],
"author": "",
@@ -22,11 +20,13 @@
"@vue/cli-service": "^5.0.9",
"@vue/compiler-sfc": "^3.5.22",
"ionicons": "^7.4.0",
"pinia": "^3.0.3",
"vue": "^3.5.22",
"vue-router": "^4.5.1"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.1.4",
"less": "^4.4.2",
"vite": "^5.4.8"
}
}

View File

@@ -1,18 +1,10 @@
<template>
<AppDataProvider>
<div>
<router-view />
</div>
</AppDataProvider>
<div>
<router-view />
</div>
</template>
<script>
import { AppDataProvider } from './utils/AppDataContext';
export default {
name: 'App',
components: {
AppDataProvider
}
}
<script setup>
import '@/common/base.css'
// App根组件不需要额外的逻辑
</script>

532
src/common/base.css Normal file
View File

@@ -0,0 +1,532 @@
/************************************************************
** 请将全局样式拷贝到项目的全局 CSS 文件或者当前页面的顶部 **
** 否则页面将无法正常显示 **
************************************************************/
html {
font-size: 16px;
user-select: none;
-webkit-user-drag: none;
-webkit-tap-highlight-color: transparent;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Microsoft Yahei', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
view,
image,
text {
box-sizing: border-box;
flex-shrink: 0;
}
#app {
width: 100vw;
height: 100vh;
}
.code-fun-flex-row {
display: flex;
flex-direction: row;
}
.code-fun-flex-col {
display: flex;
flex-direction: column;
}
.code-fun-justify-start {
justify-content: flex-start;
}
.code-fun-justify-end {
justify-content: flex-end;
}
.code-fun-justify-center {
justify-content: center;
}
.code-fun-justify-between {
justify-content: space-between;
}
.code-fun-justify-around {
justify-content: space-around;
}
.code-fun-justify-evenly {
justify-content: space-evenly;
}
.code-fun-items-start {
align-items: flex-start;
}
.code-fun-items-end {
align-items: flex-end;
}
.code-fun-items-center {
align-items: center;
}
.code-fun-items-baseline {
align-items: baseline;
}
.code-fun-items-stretch {
align-items: stretch;
}
.code-fun-self-start {
align-self: flex-start;
}
.code-fun-self-end {
align-self: flex-end;
}
.code-fun-self-center {
align-self: center;
}
.code-fun-self-baseline {
align-self: baseline;
}
.code-fun-self-stretch {
align-self: stretch;
}
.code-fun-flex-1 {
flex: 1 1 0%;
}
.code-fun-flex-auto {
flex: 1 1 auto;
}
.code-fun-grow {
flex-grow: 1;
}
.code-fun-grow-0 {
flex-grow: 0;
}
.code-fun-shrink {
flex-shrink: 1;
}
.code-fun-shrink-0 {
flex-shrink: 0;
}
.code-fun-relative {
position: relative;
}
.code-fun-ml-2 {
margin-left: 0.13rem;
}
.code-fun-mt-2 {
margin-top: 0.13rem;
}
.code-fun-ml-4 {
margin-left: 0.25rem;
}
.code-fun-mt-4 {
margin-top: 0.25rem;
}
.code-fun-ml-6 {
margin-left: 0.38rem;
}
.code-fun-mt-6 {
margin-top: 0.38rem;
}
.code-fun-ml-8 {
margin-left: 0.5rem;
}
.code-fun-mt-8 {
margin-top: 0.5rem;
}
.code-fun-ml-10 {
margin-left: 0.63rem;
}
.code-fun-mt-10 {
margin-top: 0.63rem;
}
.code-fun-ml-12 {
margin-left: 0.75rem;
}
.code-fun-mt-12 {
margin-top: 0.75rem;
}
.code-fun-ml-14 {
margin-left: 0.88rem;
}
.code-fun-mt-14 {
margin-top: 0.88rem;
}
.code-fun-ml-16 {
margin-left: 1rem;
}
.code-fun-mt-16 {
margin-top: 1rem;
}
.code-fun-ml-18 {
margin-left: 1.13rem;
}
.code-fun-mt-18 {
margin-top: 1.13rem;
}
.code-fun-ml-20 {
margin-left: 1.25rem;
}
.code-fun-mt-20 {
margin-top: 1.25rem;
}
.code-fun-ml-22 {
margin-left: 1.38rem;
}
.code-fun-mt-22 {
margin-top: 1.38rem;
}
.code-fun-ml-24 {
margin-left: 1.5rem;
}
.code-fun-mt-24 {
margin-top: 1.5rem;
}
.code-fun-ml-26 {
margin-left: 1.63rem;
}
.code-fun-mt-26 {
margin-top: 1.63rem;
}
.code-fun-ml-28 {
margin-left: 1.75rem;
}
.code-fun-mt-28 {
margin-top: 1.75rem;
}
.code-fun-ml-30 {
margin-left: 1.88rem;
}
.code-fun-mt-30 {
margin-top: 1.88rem;
}
.code-fun-ml-32 {
margin-left: 2rem;
}
.code-fun-mt-32 {
margin-top: 2rem;
}
.code-fun-ml-34 {
margin-left: 2.13rem;
}
.code-fun-mt-34 {
margin-top: 2.13rem;
}
.code-fun-ml-36 {
margin-left: 2.25rem;
}
.code-fun-mt-36 {
margin-top: 2.25rem;
}
.code-fun-ml-38 {
margin-left: 2.38rem;
}
.code-fun-mt-38 {
margin-top: 2.38rem;
}
.code-fun-ml-40 {
margin-left: 2.5rem;
}
.code-fun-mt-40 {
margin-top: 2.5rem;
}
.code-fun-ml-42 {
margin-left: 2.63rem;
}
.code-fun-mt-42 {
margin-top: 2.63rem;
}
.code-fun-ml-44 {
margin-left: 2.75rem;
}
.code-fun-mt-44 {
margin-top: 2.75rem;
}
.code-fun-ml-46 {
margin-left: 2.88rem;
}
.code-fun-mt-46 {
margin-top: 2.88rem;
}
.code-fun-ml-48 {
margin-left: 3rem;
}
.code-fun-mt-48 {
margin-top: 3rem;
}
.code-fun-ml-50 {
margin-left: 3.13rem;
}
.code-fun-mt-50 {
margin-top: 3.13rem;
}
.code-fun-ml-52 {
margin-left: 3.25rem;
}
.code-fun-mt-52 {
margin-top: 3.25rem;
}
.code-fun-ml-54 {
margin-left: 3.38rem;
}
.code-fun-mt-54 {
margin-top: 3.38rem;
}
.code-fun-ml-56 {
margin-left: 3.5rem;
}
.code-fun-mt-56 {
margin-top: 3.5rem;
}
.code-fun-ml-58 {
margin-left: 3.63rem;
}
.code-fun-mt-58 {
margin-top: 3.63rem;
}
.code-fun-ml-60 {
margin-left: 3.75rem;
}
.code-fun-mt-60 {
margin-top: 3.75rem;
}
.code-fun-ml-62 {
margin-left: 3.88rem;
}
.code-fun-mt-62 {
margin-top: 3.88rem;
}
.code-fun-ml-64 {
margin-left: 4rem;
}
.code-fun-mt-64 {
margin-top: 4rem;
}
.code-fun-ml-66 {
margin-left: 4.13rem;
}
.code-fun-mt-66 {
margin-top: 4.13rem;
}
.code-fun-ml-68 {
margin-left: 4.25rem;
}
.code-fun-mt-68 {
margin-top: 4.25rem;
}
.code-fun-ml-70 {
margin-left: 4.38rem;
}
.code-fun-mt-70 {
margin-top: 4.38rem;
}
.code-fun-ml-72 {
margin-left: 4.5rem;
}
.code-fun-mt-72 {
margin-top: 4.5rem;
}
.code-fun-ml-74 {
margin-left: 4.63rem;
}
.code-fun-mt-74 {
margin-top: 4.63rem;
}
.code-fun-ml-76 {
margin-left: 4.75rem;
}
.code-fun-mt-76 {
margin-top: 4.75rem;
}
.code-fun-ml-78 {
margin-left: 4.88rem;
}
.code-fun-mt-78 {
margin-top: 4.88rem;
}
.code-fun-ml-80 {
margin-left: 5rem;
}
.code-fun-mt-80 {
margin-top: 5rem;
}
.code-fun-ml-82 {
margin-left: 5.13rem;
}
.code-fun-mt-82 {
margin-top: 5.13rem;
}
.code-fun-ml-84 {
margin-left: 5.25rem;
}
.code-fun-mt-84 {
margin-top: 5.25rem;
}
.code-fun-ml-86 {
margin-left: 5.38rem;
}
.code-fun-mt-86 {
margin-top: 5.38rem;
}
.code-fun-ml-88 {
margin-left: 5.5rem;
}
.code-fun-mt-88 {
margin-top: 5.5rem;
}
.code-fun-ml-90 {
margin-left: 5.63rem;
}
.code-fun-mt-90 {
margin-top: 5.63rem;
}
.code-fun-ml-92 {
margin-left: 5.75rem;
}
.code-fun-mt-92 {
margin-top: 5.75rem;
}
.code-fun-ml-94 {
margin-left: 5.88rem;
}
.code-fun-mt-94 {
margin-top: 5.88rem;
}
.code-fun-ml-96 {
margin-left: 6rem;
}
.code-fun-mt-96 {
margin-top: 6rem;
}
.code-fun-ml-98 {
margin-left: 6.13rem;
}
.code-fun-mt-98 {
margin-top: 6.13rem;
}
.code-fun-ml-100 {
margin-left: 6.25rem;
}
.code-fun-mt-100 {
margin-top: 6.25rem;
}

View File

@@ -57,80 +57,72 @@
</div>
</template>
<script>
<script setup>
import { ref, computed } from 'vue';
import { folder, star, trash, document } from 'ionicons/icons';
export default {
name: 'FolderItem',
props: {
id: {
type: String,
required: true
},
name: {
type: String,
required: true
},
noteCount: {
type: Number,
required: true
},
onPress: {
type: Function,
required: true
},
isSelected: {
type: Boolean,
default: false
}
const props = defineProps({
id: {
type: String,
required: true
},
data() {
return {
folder,
star,
trash,
document,
isPressed: false
}
name: {
type: String,
required: true
},
computed: {
folderIcon() {
switch (this.id) {
case 'all':
return this.folder;
case 'starred':
return this.star;
case 'trash':
return this.trash;
default:
return this.document;
}
},
folderIconSrc() {
switch (this.id) {
case 'all':
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_all.png';
case 'starred':
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_favorite.png';
case 'trash':
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_trash.png';
default:
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_document.png';
}
}
noteCount: {
type: Number,
required: true
},
methods: {
handleMouseDown() {
this.isPressed = true;
},
handleMouseUp() {
this.isPressed = false;
},
handleMouseLeave() {
this.isPressed = false;
}
onPress: {
type: Function,
required: true
},
isSelected: {
type: Boolean,
default: false
}
}
});
const isPressed = ref(false);
const folderIcon = computed(() => {
switch (props.id) {
case 'all':
return folder;
case 'starred':
return star;
case 'trash':
return trash;
default:
return document;
}
});
const folderIconSrc = computed(() => {
switch (props.id) {
case 'all':
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_all.png';
case 'starred':
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_favorite.png';
case 'trash':
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_trash.png';
default:
return '/assets/icons/drawable-xxhdpi/sidebar_folder_icon_document.png';
}
});
const handleMouseDown = () => {
isPressed.value = true;
};
const handleMouseUp = () => {
isPressed.value = false;
};
const handleMouseLeave = () => {
isPressed.value = false;
};
</script>
<style scoped>

View File

@@ -1,313 +1,186 @@
<template>
<div class="header-container">
<!-- 左侧区域 -->
<div class="header-left-area">
<!-- 左侧图标 -->
<div
v-if="onBack"
@click="onBack"
class="header-icon-button"
>
<img
src="/assets/icons/drawable-xxhdpi/btn_back.png"
class="header-icon"
alt="back"
/>
</div>
<div
v-else-if="leftIcon === 'back' && leftIconSource && onLeftAction"
@click="onLeftAction"
class="header-icon-button"
>
<img
:src="leftIconSource"
class="header-icon"
alt="left icon"
/>
</div>
<div
v-else-if="leftIcon === 'settings'"
@click="onLeftAction"
class="header-icon-button"
>
<img
:src="leftIconSource"
class="header-icon"
alt="settings"
/>
</div>
<div class="code-fun-flex-row code-fun-items-center component">
<!-- 左侧图标 -->
<img v-if="leftType == 'settings'" class="left-icon" src="/assets/icons/drawable-xxhdpi/btn_settings.png" @click="handleLeftAction" />
<img v-else class="left-icon" src="/assets/icons/drawable-xxhdpi/btn_back.png" @click="handleLeftAction" />
<!-- 标题区域 -->
<div class="title-container" @click="handleTitlePress" v-if="leftType == 'settings'">
<span class="text">{{ title }}</span>
<!-- 文件夹展开图标 -->
<img class="folder-icon" :src="folderExpanded ? '/assets/icons/drawable-xxhdpi/folder_title_arrow_pressed.png' : '/assets/icons/drawable-xxhdpi/folder_title_arrow_normal.png'" @click.stop="handleFolderToggle" />
</div>
<!-- 中间标题区域 -->
<div
@click="onTitlePress"
class="header-title-container"
>
<span class="header-title">
{{ title }}
</span>
<!-- 文件夹切换按钮 (在标题区域内) -->
<div
v-if="leftIcon === 'settings'"
@click.stop="handleFolderToggle"
class="folder-toggle-button"
>
<img
:src="folderExpanded ? '/assets/icons/drawable-xxhdpi/folder_title_arrow_pressed.png' : '/assets/icons/drawable-xxhdpi/folder_title_arrow_normal.png'"
class="folder-toggle-icon"
alt="folder toggle"
/>
</div>
</div>
<!-- 右侧区域 -->
<div class="header-right-area">
<div
v-if="onAction"
@click="onAction"
class="header-icon-button"
>
<img
v-if="actionIconSource"
:src="actionIconSource"
class="header-icon"
alt="action"
/>
<span
v-else
class="header-action-text"
>
{{ actionText }}
</span>
</div>
<div class="title-container" v-else>
<span class="text">{{ title }}</span>
</div>
<!-- 右侧操作按钮 -->
<img v-if="actionIcon === 'create'" class="image_4" src="/assets/icons/drawable-xxhdpi/btn_create.png" @click="handleAction" />
<i class="image_4" v-else></i>
</div>
</template>
<script>
export default {
name: 'Header',
props: {
title: {
type: String,
required: true
},
onBack: {
type: Function,
default: null
},
onAction: {
type: Function,
default: null
},
actionText: {
type: String,
default: ''
},
actionIcon: {
type: String,
default: ''
},
leftIcon: {
type: String,
default: ''
},
onLeftAction: {
type: Function,
default: null
},
onFolderToggle: {
type: Function,
default: null
},
isFolderExpanded: {
type: Boolean,
default: undefined
},
onTitlePress: {
type: Function,
default: null
}
<script setup>
import { ref, computed } from 'vue'
const props = defineProps({
title: {
type: String,
required: true,
},
data() {
return {
localFolderExpanded: false
}
onBack: {
type: Function,
default: null,
},
computed: {
folderExpanded() {
// 优先使用父组件传递的isFolderExpanded状态否则使用本地状态
return this.isFolderExpanded !== undefined ? this.isFolderExpanded : this.localFolderExpanded;
},
actionIconSource() {
// 根据actionIcon属性返回对应的图标路径
switch (this.actionIcon) {
case 'settings':
return '/assets/icons/drawable-xxhdpi/btn_settings.png';
case 'create':
return '/assets/icons/drawable-xxhdpi/btn_create.png';
default:
return null;
}
},
leftIconSource() {
// 根据leftIcon属性返回对应的图标路径
switch (this.leftIcon) {
case 'folder':
// 文件夹图标根据展开状态切换
return this.folderExpanded
? '/assets/icons/drawable-xxhdpi/folder_title_arrow_pressed.png'
: '/assets/icons/drawable-xxhdpi/folder_title_arrow_normal.png';
case 'back':
// 返回图标
return '/assets/icons/drawable-xxhdpi/btn_back.png';
case 'settings':
// 设置图标
return '/assets/icons/drawable-xxhdpi/btn_settings.png';
default:
return null;
}
}
onAction: {
type: Function,
default: null,
},
methods: {
handleFolderToggle() {
// 切换文件夹展开状态
if (this.isFolderExpanded === undefined) {
// 如果父组件没有传递isFolderExpanded则使用本地状态
this.localFolderExpanded = !this.localFolderExpanded;
}
// 调用父组件传递的回调函数
if (this.onFolderToggle) {
this.onFolderToggle();
}
}
actionText: {
type: String,
default: '',
},
actionIcon: {
type: String,
default: '',
},
leftIcon: {
type: String,
default: '',
},
leftType: {
type: String,
default: 'back',
},
onLeftAction: {
type: Function,
default: null,
},
onFolderToggle: {
type: Function,
default: null,
},
isFolderExpanded: {
type: Boolean,
default: undefined,
},
onTitlePress: {
type: Function,
default: null,
},
})
const localFolderExpanded = ref(false)
const folderExpanded = computed(() => {
// 优先使用父组件传递的isFolderExpanded状态否则使用本地状态
return props.isFolderExpanded !== undefined ? props.isFolderExpanded : localFolderExpanded.value
})
const actionIconSource = computed(() => {
// 根据actionIcon属性返回对应的图标路径
switch (props.actionIcon) {
case 'settings':
return '/assets/icons/drawable-xxhdpi/btn_settings.png'
case 'create':
return '/assets/icons/drawable-xxhdpi/btn_create.png'
default:
return null
}
})
const leftIconSource = computed(() => {
// 根据leftIcon属性返回对应的图标路径
switch (props.leftIcon) {
case 'folder':
// 文件夹图标根据展开状态切换
return folderExpanded.value ? '/assets/icons/drawable-xxhdpi/folder_title_arrow_pressed.png' : '/assets/icons/drawable-xxhdpi/folder_title_arrow_normal.png'
case 'back':
// 返回图标
return '/assets/icons/drawable-xxhdpi/btn_back.png'
case 'settings':
// 设置图标
return '/assets/icons/drawable-xxhdpi/btn_settings.png'
default:
return null
}
})
const handleFolderToggle = () => {
// 切换文件夹展开状态
if (props.isFolderExpanded === undefined) {
// 如果父组件没有传递isFolderExpanded则使用本地状态
localFolderExpanded.value = !localFolderExpanded.value
}
// 调用父组件传递的回调函数
if (props.onFolderToggle) {
props.onFolderToggle()
}
}
const handleLeftAction = () => {
// 处理左侧图标点击事件
if (props.onLeftAction) {
props.onLeftAction()
} else if (props.leftType !== 'settings' && props.onBack) {
// 兼容旧版本的onBack属性
props.onBack()
}
}
const handleAction = () => {
// 处理右侧操作按钮点击事件
if (props.onAction) {
props.onAction()
}
}
const handleTitlePress = () => {
// 处理标题点击事件
if (props.onTitlePress) {
props.onTitlePress()
}
}
</script>
<style scoped>
.header-container {
position: relative;
width: 100%;
height: 48px;
background-color: var(--background-card);
box-shadow: 0 1px 0 0 var(--border);
<style scoped lang="less">
.component {
padding: 2rem 0.72rem 0.5rem 0.72rem;
background-color: #00000000;
background-image: url(https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/686f20ecd54496f19f54e801/68e862ab9520a30011f388ff/17600644443142372133.png);
background-size: cover;
background-position: 0% 0%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 0 4px;
}
.header-left-area {
display: flex;
flex-direction: row;
align-items: center;
height: 100%;
flex-shrink: 0;
}
.left-icon,
.image_4 {
width: 1.7rem;
height: 1.7rem;
cursor: pointer;
}
.header-right-area {
display: flex;
flex-direction: row;
align-items: center;
height: 100%;
flex-shrink: 0;
}
.title-container {
display: flex;
align-items: center;
cursor: pointer;
flex: 1;
justify-content: center;
.header-icon-button {
width: 44px;
height: 44px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.2s ease;
flex-shrink: 0;
}
.folder-icon {
width: 0.8rem;
height: 0.8rem;
margin-left: 0.2rem;
cursor: pointer;
}
.header-icon-button:hover {
background-color: var(--black-05);
.text {
color: #e3dbd4;
font-size: 1.01rem;
line-height: 1.01rem;
}
}
}
.header-icon-button:active {
background-color: var(--black-10);
transform: scale(0.95);
}
.header-icon {
width: 24px;
height: 24px;
object-fit: contain;
}
.header-title-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
cursor: pointer;
transition: background-color 0.2s ease;
border-radius: 4px;
padding: 4px 8px;
flex: 1;
margin: 0 8px;
}
.header-title-container:hover {
background-color: var(--black-05);
}
.header-title-container:active {
background-color: var(--black-10);
transform: scale(0.98);
}
.header-title {
font-size: 18px;
font-weight: 600;
color: var(--text-primary);
text-align: center;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex-shrink: 1;
}
.folder-toggle-button {
width: 20px;
height: 20px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: background-color 0.2s ease;
border-radius: 4px;
flex-shrink: 0;
margin-left: 8px;
}
.folder-toggle-button:hover {
background-color: var(--black-05);
}
.folder-toggle-button:active {
background-color: var(--black-10);
transform: scale(0.95);
}
.folder-toggle-icon {
width: 20px;
height: 20px;
object-fit: contain;
}
.header-action-text {
font-size: 16px;
color: var(--primary);
font-weight: 500;
}
</style>
</style>

206
src/components/Modal.vue Normal file
View File

@@ -0,0 +1,206 @@
<template>
<div class="code-fun-flex-col code-fun-justify-start">
<div class="code-fun-flex-col code-fun-justify-start group_1">
<div class="code-fun-flex-col code-fun-justify-start code-fun-items-end group">
<div class="code-fun-flex-col code-fun-justify-start code-fun-items-start code-fun-relative group_2">
<div class="code-fun-flex-col section_7">
<div class="code-fun-flex-col code-fun-justify-start section_1">
<div class="code-fun-flex-row section_11">
<div class="code-fun-flex-col code-fun-justify-start section_12" @click="handleCancel">
<div class="code-fun-flex-col code-fun-justify-start code-fun-items-center text-wrapper_2">
<span class="text_4">{{ cancelText }}</span>
</div>
</div>
<div class="code-fun-flex-col code-fun-justify-start section_13 code-fun-ml-8" @click="handleConfirm">
<div class="code-fun-flex-col code-fun-justify-start code-fun-items-center text-wrapper_3">
<span class="text_5">{{ confirmText }}</span>
</div>
</div>
</div>
</div>
<div class="code-fun-flex-col code-fun-justify-start code-fun-relative section_9">
<div class="code-fun-flex-col code-fun-justify-start section_10">
<div class="code-fun-flex-col code-fun-justify-start code-fun-items-start text-wrapper">
<input
v-model="inputValue"
class="text_3"
:placeholder="placeholder"
@keyup.enter="handleConfirm"
/>
</div>
</div>
</div>
</div>
<div class="code-fun-flex-col section_8 pos">
<div class="code-fun-flex-col code-fun-justify-start code-fun-items-start code-fun-self-stretch group_3">
<span class="text_2">{{ title }}</span>
</div>
<div class="code-fun-self-start divider"></div>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
const props = defineProps({
title: {
type: String,
default: '新建文件夹'
},
placeholder: {
type: String,
default: '新建文件夹'
},
confirmText: {
type: String,
default: '确定'
},
cancelText: {
type: String,
default: '取消'
}
});
const emit = defineEmits(['confirm', 'cancel']);
const inputValue = ref('');
const handleConfirm = () => {
emit('confirm', inputValue.value);
};
const handleCancel = () => {
emit('cancel');
};
</script>
<style scoped lang="less">
.group_1 {
padding-bottom: 1rem;
.group {
padding: 0.5rem 0 0.25rem;
.group_2 {
margin-right: 0.75rem;
width: 32.31rem;
.section_7 {
padding-top: 5.75rem;
background-color: #00000000;
width: 29.06rem;
height: 18.16rem;
background-image: url(https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/686f20ecd54496f19f54e801/68e862ab9520a30011f388ff/17600601480475170758.png);
background-repeat: no-repeat;
background-size: 100% auto;
background-position: 0% 0%;
.section_1 {
margin-top: 7.88rem;
background-color: #00000000;
.section_11 {
padding: 0.5rem 0.5rem 0.75rem;
background-color: #f4f4f7;
border-radius: 0rem 0rem 0.75rem 0.75rem;
border: solid 0.032rem #edeee8;
.section_12 {
padding: 0.25rem 0;
background-color: #00000000;
width: 13.63rem;
height: 3.13rem;
.text-wrapper_2 {
margin: 0 0.25rem;
padding: 0.75rem 0;
background-color: #f2f2f2;
border-radius: 0.25rem;
width: 13.34rem;
border: solid 0.032rem #d7d7d7;
.text_4 {
color: #757575;
font-size: 1.23rem;
font-weight: 700;
line-height: 1.23rem;
}
}
}
.section_13 {
margin-right: 0.25rem;
padding-top: 0.25rem;
background-color: #00000000;
width: 13.59rem;
height: 3.06rem;
.text-wrapper_3 {
margin-left: 0.25rem;
padding: 0.75rem 0;
border-radius: 0.25rem;
background-image: url('assets/53062683132af1946e1a4953530af228.png');
background-size: 100% 100%;
background-repeat: no-repeat;
width: 13.34rem;
.text_5 {
color: #cddff2;
font-size: 1.19rem;
line-height: 1.19rem;
}
}
}
}
}
.section_9 {
margin-top: -12.5rem;
padding: 1.75rem 0 0.25rem;
background-color: #00000000;
.section_10 {
margin: 0 1.5rem;
padding-top: 0.25rem;
background-color: #00000000;
width: 25.88rem;
.text-wrapper {
margin: 0 0.25rem;
padding: 0.75rem 0;
background-color: #fefefe;
border-radius: 0.25rem;
width: 25.53rem;
border: solid 0.063rem #e1e1e1;
.text_3 {
margin-left: 1rem;
color: #d0d0d0;
font-size: 1.38rem;
font-weight: 700;
line-height: 1.38rem;
}
}
}
}
}
.section_8 {
padding: 0 0.13rem;
background-color: #00000000;
width: 32.31rem;
.group_3 {
padding: 1.5rem 0;
width: 32.06rem;
.text_2 {
margin-left: 10.5rem;
color: #7a7a7a;
font-size: 1.54rem;
font-weight: 700;
line-height: 1.54rem;
}
}
.divider {
background-color: #f0f0f0;
width: 29rem;
height: 0.094rem;
}
}
.pos {
position: absolute;
left: 0;
right: 0;
top: 0;
}
}
}
}
</style>

View File

@@ -1,20 +1,16 @@
<template>
<div class="note-item-container">
<!-- 左滑删除操作区域 -->
<div
v-if="onDelete"
class="delete-area"
:class="{ 'delete-area-visible': isSwiped }"
>
<div v-if="onDelete" class="delete-area" :class="{ 'delete-area-visible': isSwiped }">
<span class="delete-text">删除</span>
</div>
<!-- 便签内容区域 -->
<div
<div
class="note-content"
:class="{
:class="{
'note-content-swiped': isSwiped,
'note-content-pressed': isPressed
'note-content-pressed': isPressed,
}"
@click="onPress"
@touchstart="handleTouchStart"
@@ -22,17 +18,12 @@
@touchend="handleTouchEnd"
@mousedown="handleMouseDown"
@mouseup="handleMouseUp"
@mouseleave="handleMouseLeave"
>
@mouseleave="handleMouseLeave">
<div class="note-header">
<span class="note-date">
{{ date }}
</span>
<ion-icon
v-if="isStarred"
:icon="star"
class="star-icon"
></ion-icon>
<ion-icon v-if="isStarred" :icon="star" class="star-icon"></ion-icon>
</div>
<div class="note-title-container">
<span class="note-title">
@@ -43,89 +34,86 @@
</div>
</template>
<script>
import { star } from 'ionicons/icons';
<script setup>
import { ref, computed } from 'vue'
import { star } from 'ionicons/icons'
export default {
name: 'NoteItem',
props: {
title: {
type: String,
required: true
},
content: {
type: String,
required: true
},
date: {
type: String,
required: true
},
isStarred: {
type: Boolean,
default: false
},
onPress: {
type: Function,
required: true
},
onDelete: {
type: Function,
default: null
}
const props = defineProps({
title: {
type: String,
required: true,
},
data() {
return {
star,
isSwiped: false,
isPressed: false,
touchStartX: 0,
touchEndX: 0
}
content: {
type: String,
required: true,
},
computed: {
firstLine() {
if (!this.content) return '';
return this.content.split('\n')[0];
}
date: {
type: String,
required: true,
},
methods: {
handleTouchStart(event) {
this.touchStartX = event.touches[0].clientX;
this.isPressed = true;
},
handleTouchMove(event) {
this.touchEndX = event.touches[0].clientX;
// 如果有滑动,取消按下状态
if (Math.abs(this.touchStartX - this.touchEndX) > 5) {
this.isPressed = false;
}
},
handleTouchEnd() {
// 重置按下状态
this.isPressed = false;
// 计算滑动距离
const swipeDistance = this.touchStartX - this.touchEndX;
// 如果滑动距离超过阈值,则显示删除按钮
if (swipeDistance > 50) {
this.isSwiped = true;
} else if (swipeDistance < -50) {
this.isSwiped = false;
}
},
handleMouseDown() {
this.isPressed = true;
},
handleMouseUp() {
this.isPressed = false;
},
handleMouseLeave() {
this.isPressed = false;
}
isStarred: {
type: Boolean,
default: false,
},
onPress: {
type: Function,
required: true,
},
onDelete: {
type: Function,
default: null,
},
})
const isSwiped = ref(false)
const isPressed = ref(false)
const touchStartX = ref(0)
const touchEndX = ref(0)
const firstLine = computed(() => {
if (!props.content) return ''
return props.content.split('\n')[0]
})
const handleTouchStart = (event) => {
touchStartX.value = event.touches[0].clientX
isPressed.value = true
}
const handleTouchMove = (event) => {
touchEndX.value = event.touches[0].clientX
// 如果有滑动,取消按下状态
if (Math.abs(touchStartX.value - touchEndX.value) > 5) {
isPressed.value = false
}
}
const handleTouchEnd = () => {
// 重置按下状态
isPressed.value = false
// 计算滑动距离
const swipeDistance = touchStartX.value - touchEndX.value
// 如果滑动距离超过阈值,则显示删除按钮
if (swipeDistance > 50) {
isSwiped.value = true
} else if (swipeDistance < -50) {
isSwiped.value = false
}
}
const handleMouseDown = () => {
isPressed.value = true
}
const handleMouseUp = () => {
isPressed.value = false
}
const handleMouseLeave = () => {
isPressed.value = false
}
</script>
<style scoped>
@@ -220,4 +208,4 @@ export default {
white-space: nowrap;
line-height: 30px;
}
</style>
</style>

View File

@@ -1,5 +1,6 @@
import { createApp } from 'vue'
import { createRouter, createWebHashHistory } from 'vue-router'
import { createPinia } from 'pinia'
import App from './App.vue'
// Pages
@@ -27,5 +28,6 @@ const router = createRouter({
// App
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.mount('#app')

View File

@@ -38,95 +38,79 @@
</ion-page>
</template>
<script>
import { ref, computed } from 'vue';
import { useAppData } from '../utils/AppDataContext';
<script setup>
import { ref, computed, onMounted } from 'vue';
import { useAppStore } from '../stores/useAppStore';
import { search, closeCircle } from 'ionicons/icons';
import FolderItem from '../components/FolderItem.vue';
import Header from '../components/Header.vue';
export default {
name: 'FolderPage',
components: {
FolderItem,
Header
},
setup() {
const { state } = useAppData();
const searchQuery = ref('');
const selectedFolder = ref('all');
// Calculate note count for each folder
const foldersWithCount = computed(() => {
return state.folders.map(folder => {
const noteCount = state.notes.filter(note => note.folderId === folder.id).length;
return {
...folder,
noteCount,
};
});
});
// Add default folders at the beginning
const allNotesCount = computed(() => state.notes.length);
const starredNotesCount = computed(() => state.notes.filter(note => note.isStarred).length);
// Assuming we have a way to track deleted notes in the future
const trashNotesCount = 0;
const foldersWithAllNotes = computed(() => {
return [
{ id: 'all', name: '全部便签', noteCount: allNotesCount.value, createdAt: new Date() },
{ id: 'starred', name: '加星便签', noteCount: starredNotesCount.value, createdAt: new Date() },
{ id: 'trash', name: '回收站', noteCount: trashNotesCount, createdAt: new Date() },
...foldersWithCount.value,
];
});
const handleFolderPress = (folderId) => {
// 更新选中的文件夹状态
selectedFolder.value = folderId;
// 在实际应用中这里会将选中的文件夹传递回NoteListScreen
// 通过导航参数传递选中的文件夹ID
window.location.hash = `#/notes?folder=${folderId}`;
};
const handleAddFolder = () => {
// In a full implementation, this would open a folder creation dialog
console.log('Add folder pressed');
};
const handleSearch = () => {
// In a full implementation, this would filter folders based on searchQuery
console.log('Search for:', searchQuery.value);
};
const handleBackPress = () => {
window.history.back();
};
// Filter folders based on search query
const filteredFolders = computed(() => {
return foldersWithAllNotes.value.filter(folder =>
folder.name.toLowerCase().includes(searchQuery.value.toLowerCase())
);
});
const setSearchQuery = (value) => {
searchQuery.value = value;
};
const store = useAppStore();
// 加载初始数据
onMounted(() => {
store.loadData();
});
const searchQuery = ref('');
const selectedFolder = ref('all');
// Calculate note count for each folder
const foldersWithCount = computed(() => {
return store.folders.map(folder => {
const noteCount = store.notes.filter(note => note.folderId === folder.id).length;
return {
searchQuery,
selectedFolder,
filteredFolders,
handleFolderPress,
handleAddFolder,
handleSearch,
handleBackPress,
setSearchQuery,
search,
closeCircle
...folder,
noteCount,
};
}
});
});
// Add default folders at the beginning
const allNotesCount = computed(() => store.notes.length);
const starredNotesCount = computed(() => store.notes.filter(note => note.isStarred).length);
// Assuming we have a way to track deleted notes in the future
const trashNotesCount = 0;
const foldersWithAllNotes = computed(() => {
return [
{ id: 'all', name: '全部便签', noteCount: allNotesCount.value, createdAt: new Date() },
{ id: 'starred', name: '加星便签', noteCount: starredNotesCount.value, createdAt: new Date() },
{ id: 'trash', name: '回收站', noteCount: trashNotesCount, createdAt: new Date() },
...foldersWithCount.value,
];
});
const handleFolderPress = (folderId) => {
// 更新选中的文件夹状态
selectedFolder.value = folderId;
// 在实际应用中这里会将选中的文件夹传递回NoteListScreen
// 通过导航参数传递选中的文件夹ID
window.location.hash = `#/notes?folder=${folderId}`;
};
const handleAddFolder = () => {
// In a full implementation, this would open a folder creation dialog
console.log('Add folder pressed');
};
const handleSearch = () => {
// In a full implementation, this would filter folders based on searchQuery
console.log('Search for:', searchQuery.value);
};
const handleBackPress = () => {
window.history.back();
};
// Filter folders based on search query
const filteredFolders = computed(() => {
return foldersWithAllNotes.value.filter(folder =>
folder.name.toLowerCase().includes(searchQuery.value.toLowerCase())
);
});
const setSearchQuery = (value) => {
searchQuery.value = value;
};
</script>

View File

@@ -59,81 +59,62 @@
</ion-page>
</template>
<script>
import { computed } from 'vue';
import { useAppData } from '../utils/AppDataContext';
<script setup>
import { computed, onMounted } from 'vue';
import { useAppStore } from '../stores/useAppStore';
import { star, starOutline, share, folder, alarm, trash } from 'ionicons/icons';
import Header from '../components/Header.vue';
export default {
name: 'NoteDetailPage',
components: {
Header
},
props: {
noteId: {
type: String,
required: true
}
},
setup(props) {
const { state, updateNote } = useAppData();
// Find the note by ID
const note = computed(() => state.notes.find(n => n.id === props.noteId));
const handleEdit = () => {
// 导航到编辑页面的逻辑将在路由中处理
window.location.hash = `#/editor/${props.noteId}`;
};
const handleShare = () => {
// In a full implementation, this would share the note
console.log('Share note');
};
const handleMoveToFolder = () => {
// In a full implementation, this would move the note to a folder
console.log('Move to folder');
};
const handleDelete = () => {
// In a full implementation, this would delete the note
console.log('Delete note');
};
const handleStar = async () => {
// Toggle star status
if (note.value) {
await updateNote(props.noteId, { isStarred: !note.value.isStarred });
}
};
const handleReminder = () => {
// In a full implementation, this would set a reminder
console.log('Set reminder');
};
const formatDate = (dateString) => {
return new Date(dateString).toLocaleDateString();
};
return {
note: note.value,
handleEdit,
handleShare,
handleMoveToFolder,
handleDelete,
handleStar,
handleReminder,
formatDate,
star,
starOutline,
share,
folder,
alarm,
trash
};
const props = defineProps({
noteId: {
type: String,
required: true
}
});
const store = useAppStore();
// 加载初始数据
onMounted(() => {
store.loadData();
});
// Find the note by ID
const note = computed(() => store.notes.find(n => n.id === props.noteId));
const handleEdit = () => {
// 导航到编辑页面的逻辑将在路由中处理
window.location.hash = `#/editor/${props.noteId}`;
};
const handleShare = () => {
// In a full implementation, this would share the note
console.log('Share note');
};
const handleMoveToFolder = () => {
// In a full implementation, this would move the note to a folder
console.log('Move to folder');
};
const handleDelete = () => {
// In a full implementation, this would delete the note
console.log('Delete note');
};
const handleStar = async () => {
// Toggle star status
if (note.value) {
await store.updateNote(props.noteId, { isStarred: !note.value.isStarred });
}
};
const handleReminder = () => {
// In a full implementation, this would set a reminder
console.log('Set reminder');
};
const formatDate = (dateString) => {
return new Date(dateString).toLocaleDateString();
};
</script>

View File

@@ -62,136 +62,113 @@
</ion-page>
</template>
<script>
import { ref, computed } from 'vue';
import { useAppData } from '../utils/AppDataContext';
<script setup>
import { ref, computed, onMounted } from 'vue';
import { useAppStore } from '../stores/useAppStore';
import { save, text, list } from 'ionicons/icons';
import Header from '../components/Header.vue';
export default {
name: 'NoteEditorPage',
components: {
Header
},
props: {
noteId: {
type: String,
default: null
const props = defineProps({
noteId: {
type: String,
default: null
}
});
const store = useAppStore();
// 加载初始数据
onMounted(() => {
store.loadData();
});
// Check if we're editing an existing note
const isEditing = !!props.noteId;
const existingNote = isEditing ? store.notes.find(n => n.id === props.noteId) : null;
// Initialize state with existing note data or empty strings
const title = ref(existingNote?.title || '');
const content = ref(existingNote?.content || '');
const showAlert = ref(false);
const handleSave = async () => {
// Validate input
if (!title.value.trim()) {
// In a full implementation, show an alert or toast
console.log('Validation error: Please enter a note title.');
return;
}
try {
if (isEditing && existingNote) {
// Update existing note
await store.updateNote(props.noteId, { title: title.value, content: content.value });
} else {
// Create new note
await store.addNote({ title: title.value, content: content.value, isStarred: false });
}
},
setup(props) {
const { state, addNote, updateNote } = useAppData();
// Check if we're editing an existing note
const isEditing = !!props.noteId;
const existingNote = isEditing ? state.notes.find(n => n.id === props.noteId) : null;
// Initialize state with existing note data or empty strings
const title = ref(existingNote?.title || '');
const content = ref(existingNote?.content || '');
const showAlert = ref(false);
const handleSave = async () => {
// Validate input
if (!title.value.trim()) {
// In a full implementation, show an alert or toast
console.log('Validation error: Please enter a note title.');
return;
}
try {
if (isEditing && existingNote) {
// Update existing note
await updateNote(props.noteId, { title: title.value, content: content.value });
} else {
// Create new note
await addNote({ title: title.value, content: content.value, isStarred: false });
}
// Navigate back to the previous screen
window.history.back();
} catch (error) {
// In a full implementation, show an alert or toast
console.log('Save error: Failed to save note. Please try again.');
}
};
const handleCancel = () => {
// Check if there are unsaved changes
const hasUnsavedChanges =
title.value !== (existingNote?.title || '') ||
content.value !== (existingNote?.content || '');
if (hasUnsavedChanges) {
showAlert.value = true;
} else {
window.history.back();
}
};
// Toolbar actions
const handleBold = () => {
// In a full implementation, this would apply bold formatting
console.log('Bold pressed');
};
const handleItalic = () => {
// In a full implementation, this would apply italic formatting
console.log('Italic pressed');
};
const handleUnderline = () => {
// In a full implementation, this would apply underline formatting
console.log('Underline pressed');
};
const handleList = () => {
// In a full implementation, this would insert a list
console.log('List pressed');
};
const handleHeader = () => {
// In a full implementation, this would apply header formatting
console.log('Header pressed');
};
const handleQuote = () => {
// In a full implementation, this would apply quote formatting
console.log('Quote pressed');
};
const setTitle = (value) => {
title.value = value;
};
const setContent = (value) => {
content.value = value;
};
const setShowAlert = (value) => {
showAlert.value = value;
};
return {
isEditing,
title,
content,
showAlert,
handleSave,
handleCancel,
handleBold,
handleItalic,
handleUnderline,
handleList,
handleHeader,
handleQuote,
setTitle,
setContent,
setShowAlert,
save,
text,
list
};
// Navigate back to the previous screen
window.history.back();
} catch (error) {
// In a full implementation, show an alert or toast
console.log('Save error: Failed to save note. Please try again.');
}
};
const handleCancel = () => {
// Check if there are unsaved changes
const hasUnsavedChanges =
title.value !== (existingNote?.title || '') ||
content.value !== (existingNote?.content || '');
if (hasUnsavedChanges) {
showAlert.value = true;
} else {
window.history.back();
}
};
// Toolbar actions
const handleBold = () => {
// In a full implementation, this would apply bold formatting
console.log('Bold pressed');
};
const handleItalic = () => {
// In a full implementation, this would apply italic formatting
console.log('Italic pressed');
};
const handleUnderline = () => {
// In a full implementation, this would apply underline formatting
console.log('Underline pressed');
};
const handleList = () => {
// In a full implementation, this would insert a list
console.log('List pressed');
};
const handleHeader = () => {
// In a full implementation, this would apply header formatting
console.log('Header pressed');
};
const handleQuote = () => {
// In a full implementation, this would apply quote formatting
console.log('Quote pressed');
};
const setTitle = (value) => {
title.value = value;
};
const setContent = (value) => {
content.value = value;
};
const setShowAlert = (value) => {
showAlert.value = value;
};
</script>

View File

@@ -4,7 +4,7 @@
:title="headerTitle"
:onAction="handleAddNote"
actionIcon="create"
leftIcon="settings"
leftType="settings"
:onLeftAction="handleSettingsPress"
:onFolderToggle="handleFolderToggle"
:isFolderExpanded="isFolderExpanded"
@@ -123,185 +123,154 @@
</ion-page>
</template>
<script>
import { ref, computed } from 'vue';
import { useAppData } from '../utils/AppDataContext';
<script setup>
import { ref, computed, onMounted } from 'vue';
import { useAppStore } from '../stores/useAppStore';
import { create, settings } from 'ionicons/icons';
import NoteItem from '../components/NoteItem.vue';
import Header from '../components/Header.vue';
import FolderItem from '../components/FolderItem.vue';
export default {
name: 'NoteListPage',
components: {
NoteItem,
Header,
FolderItem
},
setup() {
const { state, deleteNote } = useAppData();
const searchQuery = ref('');
const sortBy = ref('date'); // 'date', 'title', 'starred'
const isFolderExpanded = ref(false);
const currentFolder = ref('all'); // 默认文件夹是"全部便签"
const showAlert = ref(false);
const noteToDelete = ref(null);
// 计算加星便签数量
const starredNotesCount = computed(() => {
return state.notes.filter(note => note.isStarred).length;
});
// 根据当前文件夹过滤便签
const filteredNotes = computed(() => {
return state.notes.filter(note => {
switch (currentFolder.value) {
case 'all':
return true;
case 'starred':
return note.isStarred;
case 'trash':
// 假设我们有一个isDeleted属性来标识已删除的便签
return note.isDeleted || false;
default:
return note.folderId === currentFolder.value;
}
});
});
// Filter and sort notes
const filteredAndSortedNotes = computed(() => {
return filteredNotes.value
.filter(note =>
note.title.toLowerCase().includes(searchQuery.value.toLowerCase()) ||
note.content.toLowerCase().includes(searchQuery.value.toLowerCase())
)
.sort((a, b) => {
if (sortBy.value === 'title') {
return a.title.localeCompare(b.title);
} else if (sortBy.value === 'starred') {
return (b.isStarred ? 1 : 0) - (a.isStarred ? 1 : 0);
} else {
return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
}
});
});
// 计算头部标题
const headerTitle = computed(() => {
switch (currentFolder.value) {
case 'all':
return '全部便签';
case 'starred':
return '加星便签';
case 'trash':
return '回收站';
default:
return '文件夹';
const store = useAppStore();
// 加载初始数据
onMounted(() => {
store.loadData();
});
const searchQuery = ref('');
const sortBy = ref('date'); // 'date', 'title', 'starred'
const isFolderExpanded = ref(false);
const currentFolder = ref('all'); // 默认文件夹是"全部便签"
const showAlert = ref(false);
const noteToDelete = ref(null);
// 计算加星便签数量
const starredNotesCount = computed(() => {
return store.notes.filter(note => note.isStarred).length;
});
// 根据当前文件夹过滤便签
const filteredNotes = computed(() => {
return store.notes.filter(note => {
switch (currentFolder.value) {
case 'all':
return true;
case 'starred':
return note.isStarred;
case 'trash':
// 假设我们有一个isDeleted属性来标识已删除的便签
return note.isDeleted || false;
default:
return note.folderId === currentFolder.value;
}
});
});
// Filter and sort notes
const filteredAndSortedNotes = computed(() => {
return filteredNotes.value
.filter(note =>
note.title.toLowerCase().includes(searchQuery.value.toLowerCase()) ||
note.content.toLowerCase().includes(searchQuery.value.toLowerCase())
)
.sort((a, b) => {
if (sortBy.value === 'title') {
return a.title.localeCompare(b.title);
} else if (sortBy.value === 'starred') {
return (b.isStarred ? 1 : 0) - (a.isStarred ? 1 : 0);
} else {
return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
}
});
const handleNotePress = (noteId) => {
// 导航到详情页面的逻辑将在路由中处理
window.location.hash = `#/notes/${noteId}`;
};
const handleAddNote = () => {
// 导航到编辑页面的逻辑将在路由中处理
window.location.hash = '#/editor';
};
const handleDeleteNote = (noteId) => {
noteToDelete.value = noteId;
showAlert.value = true;
};
const confirmDeleteNote = () => {
if (noteToDelete.value) {
deleteNote(noteToDelete.value);
noteToDelete.value = null;
}
showAlert.value = false;
};
const handleSort = () => {
// In a full implementation, this would cycle through sort options
const sortOptions = ['date', 'title', 'starred'];
const currentIndex = sortOptions.indexOf(sortBy.value);
const nextIndex = (currentIndex + 1) % sortOptions.length;
sortBy.value = sortOptions[nextIndex];
console.log('Sort by:', sortOptions[nextIndex]);
};
const handleFolderPress = () => {
// 导航到文件夹页面的逻辑将在路由中处理
window.location.hash = '#/folders';
};
const handleSettingsPress = () => {
// 导航到设置页面的逻辑将在路由中处理
window.location.hash = '#/settings';
};
const handleFolderToggle = () => {
// 在实际应用中,这里会触发文件夹列表的展开/收起
isFolderExpanded.value = !isFolderExpanded.value;
console.log('Folder expanded:', !isFolderExpanded.value);
};
const handleSearch = () => {
// In a full implementation, this would filter notes based on searchQuery
console.log('Search for:', searchQuery.value);
};
const formatDate = (dateString) => {
return new Date(dateString).toLocaleDateString();
};
const setCurrentFolder = (folder) => {
currentFolder.value = folder;
};
const setIsFolderExpanded = (expanded) => {
isFolderExpanded.value = expanded;
};
const setSearchQuery = (query) => {
searchQuery.value = query;
};
const setShowAlert = (show) => {
showAlert.value = show;
};
return {
notes: state.notes,
searchQuery,
sortBy,
isFolderExpanded,
currentFolder,
showAlert,
noteToDelete,
starredNotesCount,
filteredAndSortedNotes,
headerTitle,
handleNotePress,
handleAddNote,
handleDeleteNote,
confirmDeleteNote,
handleSearch,
handleSort,
handleFolderPress,
handleSettingsPress,
handleFolderToggle,
formatDate,
setCurrentFolder,
setIsFolderExpanded,
setSearchQuery,
setShowAlert,
create,
settings
};
});
// 计算头部标题
const headerTitle = computed(() => {
switch (currentFolder.value) {
case 'all':
return '全部便签';
case 'starred':
return '加星便签';
case 'trash':
return '回收站';
default:
return '文件夹';
}
});
const handleNotePress = (noteId) => {
// 导航到详情页面的逻辑将在路由中处理
window.location.hash = `#/notes/${noteId}`;
};
const handleAddNote = () => {
// 导航到编辑页面的逻辑将在路由中处理
window.location.hash = '#/editor';
};
const handleDeleteNote = (noteId) => {
noteToDelete.value = noteId;
showAlert.value = true;
};
const confirmDeleteNote = () => {
if (noteToDelete.value) {
store.deleteNote(noteToDelete.value);
noteToDelete.value = null;
}
showAlert.value = false;
};
const handleSort = () => {
// In a full implementation, this would cycle through sort options
const sortOptions = ['date', 'title', 'starred'];
const currentIndex = sortOptions.indexOf(sortBy.value);
const nextIndex = (currentIndex + 1) % sortOptions.length;
sortBy.value = sortOptions[nextIndex];
console.log('Sort by:', sortOptions[nextIndex]);
};
const handleFolderPress = () => {
// 导航到文件夹页面的逻辑将在路由中处理
window.location.hash = '#/folders';
};
const handleSettingsPress = () => {
// 导航到设置页面的逻辑将在路由中处理
window.location.hash = '#/settings';
};
const handleFolderToggle = () => {
// 在实际应用中,这里会触发文件夹列表的展开/收起
isFolderExpanded.value = !isFolderExpanded.value;
console.log('Folder expanded:', !isFolderExpanded.value);
};
const handleSearch = () => {
// In a full implementation, this would filter notes based on searchQuery
console.log('Search for:', searchQuery.value);
};
const formatDate = (dateString) => {
return new Date(dateString).toLocaleDateString();
};
const setCurrentFolder = (folder) => {
currentFolder.value = folder;
};
const setIsFolderExpanded = (expanded) => {
isFolderExpanded.value = expanded;
};
const setSearchQuery = (query) => {
searchQuery.value = query;
};
const setShowAlert = (show) => {
showAlert.value = show;
};
const notes = computed(() => store.notes);
</script>

View File

@@ -79,78 +79,64 @@
</ion-page>
</template>
<script>
import { useAppData } from '../utils/AppDataContext';
<script setup>
import { computed, onMounted } from 'vue';
import { useAppStore } from '../stores/useAppStore';
import Header from '../components/Header.vue';
export default {
name: 'SettingsPage',
components: {
Header
},
setup() {
const { state, updateSettings } = useAppData();
const toggleCloudSync = () => {
updateSettings({ cloudSync: !state.settings.cloudSync });
};
const toggleDarkMode = () => {
updateSettings({ darkMode: !state.settings.darkMode });
};
const handleLogin = () => {
// In a full implementation, this would open a login screen
console.log('Login to cloud');
};
const handlePrivacyPolicy = () => {
// In a full implementation, this would show the privacy policy
console.log('Privacy policy');
};
const handleTermsOfService = () => {
// In a full implementation, this would show the terms of service
console.log('Terms of service');
};
const handleBackup = () => {
// In a full implementation, this would backup notes
console.log('Backup notes');
};
const handleRestore = () => {
// In a full implementation, this would restore notes
console.log('Restore notes');
};
const handleExport = () => {
// In a full implementation, this would export notes
console.log('Export notes');
};
const handleImport = () => {
// In a full implementation, this would import notes
console.log('Import notes');
};
const handleBackPress = () => {
window.history.back();
};
return {
settings: state.settings,
toggleCloudSync,
toggleDarkMode,
handleLogin,
handlePrivacyPolicy,
handleTermsOfService,
handleBackup,
handleRestore,
handleExport,
handleImport,
handleBackPress
};
}
const store = useAppStore();
// 加载初始数据
onMounted(() => {
store.loadData();
});
const toggleCloudSync = () => {
store.toggleCloudSync();
};
const toggleDarkMode = () => {
store.toggleDarkMode();
};
const handleLogin = () => {
// In a full implementation, this would open a login screen
console.log('Login to cloud');
};
const handlePrivacyPolicy = () => {
// In a full implementation, this would show the privacy policy
console.log('Privacy policy');
};
const handleTermsOfService = () => {
// In a full implementation, this would show the terms of service
console.log('Terms of service');
};
const handleBackup = () => {
// In a full implementation, this would backup notes
console.log('Backup notes');
};
const handleRestore = () => {
// In a full implementation, this would restore notes
console.log('Restore notes');
};
const handleExport = () => {
// In a full implementation, this would export notes
console.log('Export notes');
};
const handleImport = () => {
// In a full implementation, this would import notes
console.log('Import notes');
};
const handleBackPress = () => {
window.history.back();
};
const settings = computed(() => store.settings);
</script>

139
src/stores/useAppStore.js Normal file
View File

@@ -0,0 +1,139 @@
import { defineStore } from 'pinia';
import * as storage from '../utils/storage';
export const useAppStore = defineStore('app', {
state: () => ({
notes: [],
folders: [],
settings: { cloudSync: false, darkMode: false }
}),
getters: {
starredNotesCount: (state) => {
return state.notes.filter(note => note.isStarred).length;
},
allNotesCount: (state) => {
return state.notes.length;
}
},
actions: {
// 初始化数据
async loadData() {
try {
const loadedNotes = await storage.getNotes();
const loadedFolders = await storage.getFolders();
const loadedSettings = await storage.getSettings();
this.notes = loadedNotes;
this.folders = loadedFolders;
this.settings = loadedSettings;
} catch (error) {
console.error('Error loading data:', error);
}
},
// 保存notes到localStorage
async saveNotes() {
try {
await storage.saveNotes(this.notes);
} catch (error) {
console.error('Error saving notes:', error);
}
},
// 保存folders到localStorage
async saveFolders() {
try {
await storage.saveFolders(this.folders);
} catch (error) {
console.error('Error saving folders:', error);
}
},
// 保存settings到localStorage
async saveSettings() {
try {
await storage.saveSettings(this.settings);
} catch (error) {
console.error('Error saving settings:', error);
}
},
// Note functions
async addNote(note) {
try {
const newNote = await storage.addNote(note);
this.notes.push(newNote);
return newNote;
} catch (error) {
console.error('Error adding note:', error);
throw error;
}
},
async updateNote(id, updates) {
try {
const updatedNote = await storage.updateNote(id, updates);
if (updatedNote) {
const index = this.notes.findIndex(note => note.id === id);
if (index !== -1) {
this.notes[index] = updatedNote;
}
}
return updatedNote;
} catch (error) {
console.error('Error updating note:', error);
throw error;
}
},
async deleteNote(id) {
try {
const result = await storage.deleteNote(id);
if (result) {
this.notes = this.notes.filter(note => note.id !== id);
}
return result;
} catch (error) {
console.error('Error deleting note:', error);
throw error;
}
},
// Folder functions
async addFolder(folder) {
try {
const newFolder = await storage.addFolder(folder);
this.folders.push(newFolder);
return newFolder;
} catch (error) {
console.error('Error adding folder:', error);
throw error;
}
},
// Settings functions
async updateSettings(newSettings) {
try {
const updatedSettings = { ...this.settings, ...newSettings };
this.settings = updatedSettings;
await storage.saveSettings(updatedSettings);
} catch (error) {
console.error('Error updating settings:', error);
throw error;
}
},
// 切换云同步设置
async toggleCloudSync() {
await this.updateSettings({ cloudSync: !this.settings.cloudSync });
},
// 切换深色模式设置
async toggleDarkMode() {
await this.updateSettings({ darkMode: !this.settings.darkMode });
}
}
});

View File

@@ -0,0 +1,9 @@
import { useAppStore } from './useAppStore';
// 测试store是否能正常工作
describe('AppStore', () => {
it('should initialize with default state', () => {
// 这里可以添加测试代码
expect(true).toBe(true);
});
});

View File

@@ -1,119 +0,0 @@
import { reactive, provide, inject, watch } from 'vue';
import * as storage from './storage';
// Define the context key
const AppDataContextKey = Symbol('AppDataContext');
// Create the provider component
export const AppDataProvider = {
setup(props, { slots }) {
// Initialize reactive state
const state = reactive({
notes: [],
folders: [],
settings: { cloudSync: false, darkMode: false }
});
// Load data on app start
const loadData = async () => {
const loadedNotes = await storage.getNotes();
const loadedFolders = await storage.getFolders();
const loadedSettings = await storage.getSettings();
state.notes = loadedNotes;
state.folders = loadedFolders;
state.settings = loadedSettings;
};
// Save notes when they change
watch(
() => state.notes,
(newNotes) => {
storage.saveNotes(newNotes);
},
{ deep: true }
);
// Save folders when they change
watch(
() => state.folders,
(newFolders) => {
storage.saveFolders(newFolders);
},
{ deep: true }
);
// Save settings when they change
watch(
() => state.settings,
(newSettings) => {
storage.saveSettings(newSettings);
},
{ deep: true }
);
// Note functions
const addNote = async (note) => {
const newNote = await storage.addNote(note);
state.notes.push(newNote);
return newNote;
};
const updateNote = async (id, updates) => {
const updatedNote = await storage.updateNote(id, updates);
if (updatedNote) {
const index = state.notes.findIndex(note => note.id === id);
if (index !== -1) {
state.notes[index] = updatedNote;
}
}
return updatedNote;
};
const deleteNote = async (id) => {
const result = await storage.deleteNote(id);
if (result) {
state.notes = state.notes.filter(note => note.id !== id);
}
return result;
};
// Folder functions
const addFolder = async (folder) => {
const newFolder = await storage.addFolder(folder);
state.folders.push(newFolder);
return newFolder;
};
// Settings functions
const updateSettings = async (newSettings) => {
const updatedSettings = { ...state.settings, ...newSettings };
state.settings = updatedSettings;
await storage.saveSettings(updatedSettings);
};
// Load initial data
loadData();
// Provide the context
provide(AppDataContextKey, {
state,
addNote,
updateNote,
deleteNote,
addFolder,
updateSettings
});
return () => slots.default?.();
}
};
// Hook to use the context
export const useAppData = () => {
const context = inject(AppDataContextKey);
if (!context) {
throw new Error('useAppData must be used within an AppDataProvider');
}
return context;
};

View File

@@ -11,5 +11,15 @@ export default defineConfig({
},
server: {
port: 3000
},
build: {
rollupOptions: {
output: {
// 为CSS和JS文件添加哈希后缀
entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash].[ext]'
}
}
}
})