@coze-arch/cli 0.0.1-alpha.fc5c04 → 0.0.1-alpha.ff3d06
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/__templates__/expo/_npmrc +1 -0
- package/lib/__templates__/expo/client/components/Screen.tsx +2 -2
- package/lib/__templates__/expo/client/eslint.config.mjs +7 -0
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +10 -10
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/rule.js +120 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/tech.md +58 -0
- package/lib/__templates__/nextjs/AGENTS.md +54 -0
- package/lib/__templates__/nextjs/README.md +5 -0
- package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
- package/lib/__templates__/nextjs/next.config.ts +1 -2
- package/lib/__templates__/nextjs/package.json +2 -5
- package/lib/__templates__/nextjs/pnpm-lock.yaml +1028 -5
- package/lib/__templates__/nextjs/scripts/build.sh +4 -1
- package/lib/__templates__/nextjs/scripts/dev.sh +8 -2
- package/lib/__templates__/nextjs/scripts/start.sh +7 -1
- package/lib/__templates__/nextjs/src/app/layout.tsx +1 -1
- package/lib/__templates__/nextjs/src/app/page.tsx +1 -2
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/tsconfig.json +1 -1
- package/lib/__templates__/nuxt-vue/AGENTS.md +42 -0
- package/lib/__templates__/nuxt-vue/README.md +73 -0
- package/lib/__templates__/nuxt-vue/_gitignore +24 -0
- package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
- package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
- package/lib/__templates__/{vite-vue/src/index.css → nuxt-vue/assets/css/main.css} +6 -11
- package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
- package/lib/__templates__/nuxt-vue/package.json +35 -0
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
- package/lib/__templates__/{vite-vue → nuxt-vue}/postcss.config.mjs +3 -1
- package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
- package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
- package/lib/__templates__/{vite-vue → nuxt-vue}/scripts/build.sh +2 -2
- package/lib/__templates__/{vite-vue → nuxt-vue}/scripts/dev.sh +9 -2
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/start.sh +21 -0
- package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
- package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
- package/lib/__templates__/nuxt-vue/template.config.js +87 -0
- package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
- package/lib/__templates__/taro/README.md +57 -45
- package/lib/__templates__/taro/config/index.ts +45 -30
- package/lib/__templates__/taro/eslint.config.mjs +61 -6
- package/lib/__templates__/taro/package.json +8 -3
- package/lib/__templates__/taro/pnpm-lock.yaml +515 -203
- package/lib/__templates__/taro/src/app.css +140 -36
- package/lib/__templates__/taro/src/components/ui/accordion.tsx +159 -0
- package/lib/__templates__/taro/src/components/ui/alert-dialog.tsx +260 -0
- package/lib/__templates__/taro/src/components/ui/alert.tsx +60 -0
- package/lib/__templates__/taro/src/components/ui/aspect-ratio.tsx +36 -0
- package/lib/__templates__/taro/src/components/ui/avatar.tsx +84 -0
- package/lib/__templates__/taro/src/components/ui/badge.tsx +37 -0
- package/lib/__templates__/taro/src/components/ui/breadcrumb.tsx +117 -0
- package/lib/__templates__/taro/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/taro/src/components/ui/button.tsx +67 -0
- package/lib/__templates__/taro/src/components/ui/calendar.tsx +394 -0
- package/lib/__templates__/taro/src/components/ui/card.tsx +108 -0
- package/lib/__templates__/taro/src/components/ui/carousel.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/checkbox.tsx +58 -0
- package/lib/__templates__/taro/src/components/ui/code-block.tsx +169 -0
- package/lib/__templates__/taro/src/components/ui/collapsible.tsx +71 -0
- package/lib/__templates__/taro/src/components/ui/command.tsx +385 -0
- package/lib/__templates__/taro/src/components/ui/context-menu.tsx +614 -0
- package/lib/__templates__/taro/src/components/ui/dialog.tsx +256 -0
- package/lib/__templates__/taro/src/components/ui/drawer.tsx +192 -0
- package/lib/__templates__/taro/src/components/ui/dropdown-menu.tsx +561 -0
- package/lib/__templates__/taro/src/components/ui/field.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/hover-card.tsx +282 -0
- package/lib/__templates__/taro/src/components/ui/input-group.tsx +197 -0
- package/lib/__templates__/taro/src/components/ui/input-otp.tsx +136 -0
- package/lib/__templates__/taro/src/components/ui/input.tsx +56 -0
- package/lib/__templates__/taro/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/taro/src/components/ui/menubar.tsx +595 -0
- package/lib/__templates__/taro/src/components/ui/navigation-menu.tsx +264 -0
- package/lib/__templates__/taro/src/components/ui/pagination.tsx +118 -0
- package/lib/__templates__/taro/src/components/ui/popover.tsx +291 -0
- package/lib/__templates__/taro/src/components/ui/portal.tsx +19 -0
- package/lib/__templates__/taro/src/components/ui/progress.tsx +28 -0
- package/lib/__templates__/taro/src/components/ui/radio-group.tsx +64 -0
- package/lib/__templates__/taro/src/components/ui/resizable.tsx +346 -0
- package/lib/__templates__/taro/src/components/ui/scroll-area.tsx +34 -0
- package/lib/__templates__/taro/src/components/ui/select.tsx +438 -0
- package/lib/__templates__/taro/src/components/ui/separator.tsx +30 -0
- package/lib/__templates__/taro/src/components/ui/sheet.tsx +262 -0
- package/lib/__templates__/taro/src/components/ui/skeleton.tsx +17 -0
- package/lib/__templates__/taro/src/components/ui/slider.tsx +203 -0
- package/lib/__templates__/taro/src/components/ui/sonner.tsx +1 -0
- package/lib/__templates__/taro/src/components/ui/switch.tsx +55 -0
- package/lib/__templates__/taro/src/components/ui/table.tsx +142 -0
- package/lib/__templates__/taro/src/components/ui/tabs.tsx +114 -0
- package/lib/__templates__/taro/src/components/ui/textarea.tsx +54 -0
- package/lib/__templates__/taro/src/components/ui/toast.tsx +517 -0
- package/lib/__templates__/taro/src/components/ui/toggle-group.tsx +120 -0
- package/lib/__templates__/taro/src/components/ui/toggle.tsx +77 -0
- package/lib/__templates__/taro/src/components/ui/tooltip.tsx +455 -0
- package/lib/__templates__/taro/src/lib/hooks/use-keyboard-offset.ts +37 -0
- package/lib/__templates__/taro/src/lib/measure.ts +115 -0
- package/lib/__templates__/taro/src/lib/platform.ts +12 -0
- package/lib/__templates__/taro/src/lib/utils.ts +6 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +49 -12
- package/lib/__templates__/taro/src/presets/h5-styles.ts +78 -0
- package/lib/__templates__/templates.json +17 -17
- package/lib/__templates__/vite/AGENTS.md +41 -0
- package/lib/__templates__/vite/README.md +190 -11
- package/lib/__templates__/vite/_gitignore +1 -0
- package/lib/__templates__/vite/eslint.config.mjs +6 -1
- package/lib/__templates__/vite/package.json +10 -3
- package/lib/__templates__/vite/pnpm-lock.yaml +755 -15
- package/lib/__templates__/vite/scripts/build.sh +4 -1
- package/lib/__templates__/vite/scripts/dev.sh +9 -2
- package/lib/__templates__/vite/scripts/start.sh +9 -3
- package/lib/__templates__/vite/server/routes/index.ts +31 -0
- package/lib/__templates__/vite/server/server.ts +65 -0
- package/lib/__templates__/vite/server/vite.ts +67 -0
- package/lib/__templates__/vite/tsconfig.json +4 -3
- package/lib/__templates__/vite/vite.config.ts +4 -0
- package/lib/cli.js +3251 -768
- package/package.json +9 -3
- package/lib/__templates__/vite-vue/README.md +0 -451
- package/lib/__templates__/vite-vue/_gitignore +0 -66
- package/lib/__templates__/vite-vue/eslint.config.mjs +0 -9
- package/lib/__templates__/vite-vue/index.html +0 -13
- package/lib/__templates__/vite-vue/package.json +0 -38
- package/lib/__templates__/vite-vue/pnpm-lock.yaml +0 -3132
- package/lib/__templates__/vite-vue/scripts/prepare.sh +0 -9
- package/lib/__templates__/vite-vue/scripts/start.sh +0 -15
- package/lib/__templates__/vite-vue/src/App.vue +0 -6
- package/lib/__templates__/vite-vue/src/main.ts +0 -8
- package/lib/__templates__/vite-vue/src/router/index.ts +0 -17
- package/lib/__templates__/vite-vue/src/views/Home.vue +0 -38
- package/lib/__templates__/vite-vue/src/vite-env.d.ts +0 -8
- package/lib/__templates__/vite-vue/tailwind.config.js +0 -9
- package/lib/__templates__/vite-vue/template.config.js +0 -127
- package/lib/__templates__/vite-vue/tsconfig.json +0 -17
- package/lib/__templates__/vite-vue/vite.config.ts +0 -28
- /package/lib/__templates__/{vite-vue → nuxt-vue}/.coze +0 -0
- /package/lib/__templates__/{vite-vue → nuxt-vue}/_npmrc +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coze-arch/cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.ff3d06",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "coze coding devtools cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"ajv-formats": "^3.0.1",
|
|
37
37
|
"change-case": "^5.4.4",
|
|
38
38
|
"commander": "~12.1.0",
|
|
39
|
+
"debug": "^4.3.7",
|
|
39
40
|
"ejs": "^3.1.10",
|
|
40
41
|
"js-yaml": "^4.1.0",
|
|
41
42
|
"minimist": "^1.2.5",
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@coze-arch/cli-logger": "workspace:*",
|
|
47
|
+
"@coze-arch/cli-slardar": "workspace:*",
|
|
46
48
|
"@coze-arch/eslint-config": "workspace:*",
|
|
47
49
|
"@coze-arch/monorepo-kits": "workspace:*",
|
|
48
50
|
"@coze-arch/rollup-config": "workspace:*",
|
|
@@ -50,6 +52,8 @@
|
|
|
50
52
|
"@coze-arch/vitest-config": "workspace:*",
|
|
51
53
|
"@coze-coding/lambda": "workspace:*",
|
|
52
54
|
"@inquirer/prompts": "^3.2.0",
|
|
55
|
+
"@playwright/test": "~1.55.0",
|
|
56
|
+
"@types/debug": "^4.1.12",
|
|
53
57
|
"@types/ejs": "^3.1.5",
|
|
54
58
|
"@types/iarna__toml": "^2.0.5",
|
|
55
59
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -57,14 +61,16 @@
|
|
|
57
61
|
"@types/minimist": "^1.2.5",
|
|
58
62
|
"@types/node": "^24",
|
|
59
63
|
"@types/shelljs": "^0.10.0",
|
|
60
|
-
"@vitest/coverage-v8": "~4.0.
|
|
64
|
+
"@vitest/coverage-v8": "~4.0.18",
|
|
61
65
|
"json-schema-to-typescript": "^15.0.3",
|
|
62
66
|
"minimatch": "^10.0.1",
|
|
67
|
+
"playwright": "~1.55.0",
|
|
63
68
|
"rollup": "^4.41.1",
|
|
64
69
|
"sucrase": "^3.35.0",
|
|
70
|
+
"tree-kill": "^1.2.2",
|
|
65
71
|
"tsx": "^4.20.6",
|
|
66
72
|
"vite-tsconfig-paths": "^4.2.1",
|
|
67
|
-
"vitest": "~4.0.
|
|
73
|
+
"vitest": "~4.0.18"
|
|
68
74
|
},
|
|
69
75
|
"publishConfig": {
|
|
70
76
|
"access": "public",
|
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
# <%= appName %>
|
|
2
|
-
|
|
3
|
-
这是一个基于 Vue 3 + TypeScript + Vite + Tailwind CSS 的现代化 Web 应用项目,由扣子编程 CLI 创建。
|
|
4
|
-
|
|
5
|
-
## 快速开始
|
|
6
|
-
|
|
7
|
-
### 启动开发服务器
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
coze dev
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
启动后,在浏览器中打开 [http://localhost:<%= port %>](http://localhost:<%= port %>) 查看应用。
|
|
14
|
-
|
|
15
|
-
开发服务器支持热更新(HMR),修改代码后页面会自动刷新。
|
|
16
|
-
|
|
17
|
-
### 构建生产版本
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
coze build
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
构建产物位于 `dist/` 目录,可直接部署到静态托管服务。
|
|
24
|
-
|
|
25
|
-
### 预览生产版本
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
coze start
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
在本地启动一个静态服务器,预览生产构建的效果。
|
|
32
|
-
|
|
33
|
-
## 项目结构
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
├── index.html # HTML 入口文件
|
|
37
|
-
├── src/
|
|
38
|
-
│ ├── main.ts # Vue 应用入口(初始化 + 路由注册)
|
|
39
|
-
│ ├── App.vue # 根 Vue 组件(包含 router-view)
|
|
40
|
-
│ ├── router/
|
|
41
|
-
│ │ └── index.ts # Vue Router 路由配置
|
|
42
|
-
│ ├── views/
|
|
43
|
-
│ │ └── Home.vue # 首页视图组件
|
|
44
|
-
│ ├── vite-env.d.ts # Vite 类型声明
|
|
45
|
-
│ └── index.css # 全局样式(包含 Tailwind 指令)
|
|
46
|
-
├── vite.config.ts # Vite 配置(含 Vue 插件)
|
|
47
|
-
├── tailwind.config.ts # Tailwind CSS 配置
|
|
48
|
-
└── tsconfig.json # TypeScript 配置
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## 路由使用
|
|
52
|
-
|
|
53
|
-
本项目集成了 Vue Router 4 进行页面路由管理,支持基于 History 模式的单页面应用导航。
|
|
54
|
-
|
|
55
|
-
### 路由配置
|
|
56
|
-
|
|
57
|
-
路由配置文件位于 `src/router/index.ts`:
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
import { createRouter, createWebHistory } from 'vue-router';
|
|
61
|
-
import type { RouteRecordRaw } from 'vue-router';
|
|
62
|
-
|
|
63
|
-
const routes: RouteRecordRaw[] = [
|
|
64
|
-
{
|
|
65
|
-
path: '/',
|
|
66
|
-
name: 'Home',
|
|
67
|
-
component: () => import('../views/Home.vue'),
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
const router = createRouter({
|
|
72
|
-
history: createWebHistory(),
|
|
73
|
-
routes,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
export default router;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 添加新页面
|
|
80
|
-
|
|
81
|
-
1. **创建视图组件**:在 `src/views/` 目录下创建新的 Vue 组件
|
|
82
|
-
|
|
83
|
-
```vue
|
|
84
|
-
<!-- src/views/About.vue -->
|
|
85
|
-
<script setup lang="ts">
|
|
86
|
-
</script>
|
|
87
|
-
|
|
88
|
-
<template>
|
|
89
|
-
<div>
|
|
90
|
-
<h1>About Page</h1>
|
|
91
|
-
</div>
|
|
92
|
-
</template>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
2. **注册路由**:在 `src/router/index.ts` 中添加路由配置
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
const routes: RouteRecordRaw[] = [
|
|
99
|
-
{
|
|
100
|
-
path: '/',
|
|
101
|
-
name: 'Home',
|
|
102
|
-
component: () => import('../views/Home.vue'),
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
path: '/about',
|
|
106
|
-
name: 'About',
|
|
107
|
-
component: () => import('../views/About.vue'),
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### 页面导航
|
|
113
|
-
|
|
114
|
-
**使用 `<router-link>` 声明式导航**:
|
|
115
|
-
|
|
116
|
-
```vue
|
|
117
|
-
<template>
|
|
118
|
-
<nav>
|
|
119
|
-
<router-link to="/">首页</router-link>
|
|
120
|
-
<router-link to="/about">关于</router-link>
|
|
121
|
-
</nav>
|
|
122
|
-
</template>
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
**使用 `router.push()` 编程式导航**:
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
import { useRouter } from 'vue-router';
|
|
129
|
-
|
|
130
|
-
const router = useRouter();
|
|
131
|
-
|
|
132
|
-
// 导航到指定路径
|
|
133
|
-
router.push('/about');
|
|
134
|
-
|
|
135
|
-
// 带参数导航
|
|
136
|
-
router.push({ name: 'About', params: { id: '123' } });
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### 获取路由信息
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
import { useRoute } from 'vue-router';
|
|
143
|
-
|
|
144
|
-
const route = useRoute();
|
|
145
|
-
|
|
146
|
-
// 当前路径
|
|
147
|
-
console.log(route.path);
|
|
148
|
-
|
|
149
|
-
// 路由参数
|
|
150
|
-
console.log(route.params);
|
|
151
|
-
|
|
152
|
-
// 查询参数
|
|
153
|
-
console.log(route.query);
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## 核心开发规范
|
|
157
|
-
|
|
158
|
-
### 1. 样式开发
|
|
159
|
-
|
|
160
|
-
**使用 Tailwind CSS**
|
|
161
|
-
|
|
162
|
-
本项目使用 Tailwind CSS 进行样式开发,支持亮色/暗色模式自动切换。
|
|
163
|
-
|
|
164
|
-
```vue
|
|
165
|
-
<template>
|
|
166
|
-
<div class="flex items-center justify-center min-h-screen bg-white dark:bg-black">
|
|
167
|
-
<h1 class="text-4xl font-bold text-black dark:text-white">
|
|
168
|
-
Hello World
|
|
169
|
-
</h1>
|
|
170
|
-
</div>
|
|
171
|
-
</template>
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
**主题变量**
|
|
175
|
-
|
|
176
|
-
主题变量定义在 `src/index.css` 中,支持自动适配系统主题:
|
|
177
|
-
|
|
178
|
-
```css
|
|
179
|
-
:root {
|
|
180
|
-
--background: #ffffff;
|
|
181
|
-
--foreground: #171717;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
@media (prefers-color-scheme: dark) {
|
|
185
|
-
:root {
|
|
186
|
-
--background: #0a0a0a;
|
|
187
|
-
--foreground: #ededed;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
**常用 Tailwind 类名**
|
|
193
|
-
|
|
194
|
-
- 布局:`flex`, `grid`, `container`, `mx-auto`
|
|
195
|
-
- 间距:`p-4`, `m-4`, `gap-4`, `space-x-4`
|
|
196
|
-
- 颜色:`bg-white`, `text-black`, `dark:bg-black`, `dark:text-white`
|
|
197
|
-
- 排版:`text-lg`, `font-bold`, `leading-8`, `tracking-tight`
|
|
198
|
-
- 响应式:`sm:`, `md:`, `lg:`, `xl:`
|
|
199
|
-
|
|
200
|
-
### 2. 依赖管理
|
|
201
|
-
|
|
202
|
-
**必须使用 pnpm 管理依赖**
|
|
203
|
-
|
|
204
|
-
```bash
|
|
205
|
-
# ✅ 安装依赖
|
|
206
|
-
pnpm install
|
|
207
|
-
|
|
208
|
-
# ✅ 添加新依赖
|
|
209
|
-
pnpm add package-name
|
|
210
|
-
|
|
211
|
-
# ✅ 添加开发依赖
|
|
212
|
-
pnpm add -D package-name
|
|
213
|
-
|
|
214
|
-
# ❌ 禁止使用 npm 或 yarn
|
|
215
|
-
# npm install # 错误!
|
|
216
|
-
# yarn add # 错误!
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
项目已配置 `preinstall` 脚本,使用其他包管理器会报错。
|
|
220
|
-
|
|
221
|
-
### 3. TypeScript 开发
|
|
222
|
-
|
|
223
|
-
**类型安全**
|
|
224
|
-
|
|
225
|
-
充分利用 TypeScript 的类型系统,确保代码质量:
|
|
226
|
-
|
|
227
|
-
```vue
|
|
228
|
-
<script setup lang="ts">
|
|
229
|
-
import { ref } from 'vue';
|
|
230
|
-
|
|
231
|
-
// 定义接口
|
|
232
|
-
interface User {
|
|
233
|
-
id: number;
|
|
234
|
-
name: string;
|
|
235
|
-
email: string;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// 使用响应式数据和类型
|
|
239
|
-
const user = ref<User>({
|
|
240
|
-
id: 1,
|
|
241
|
-
name: 'John Doe',
|
|
242
|
-
email: 'john@example.com'
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// 使用类型化的函数
|
|
246
|
-
const createUser = (data: User): void => {
|
|
247
|
-
console.log(`Creating user: ${data.name}`);
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
// 事件处理
|
|
251
|
-
const handleClick = (): void => {
|
|
252
|
-
console.log('Button clicked');
|
|
253
|
-
};
|
|
254
|
-
</script>
|
|
255
|
-
|
|
256
|
-
<template>
|
|
257
|
-
<div>
|
|
258
|
-
<p>{{ user.name }}</p>
|
|
259
|
-
<button @click="handleClick">Click me</button>
|
|
260
|
-
</div>
|
|
261
|
-
</template>
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
**避免 any 类型**
|
|
265
|
-
|
|
266
|
-
尽量避免使用 `any`,使用 `unknown` 或具体类型:
|
|
267
|
-
|
|
268
|
-
```typescript
|
|
269
|
-
// ❌ 不推荐
|
|
270
|
-
function process(data: any) { }
|
|
271
|
-
|
|
272
|
-
// ✅ 推荐
|
|
273
|
-
function process(data: unknown) {
|
|
274
|
-
if (typeof data === 'string') {
|
|
275
|
-
console.log(data.toUpperCase());
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
## 常见开发场景
|
|
281
|
-
|
|
282
|
-
### 创建新组件
|
|
283
|
-
|
|
284
|
-
在 `src/` 下创建新的 `.vue` 文件:
|
|
285
|
-
|
|
286
|
-
```vue
|
|
287
|
-
<!-- src/components/HelloWorld.vue -->
|
|
288
|
-
<script setup lang="ts">
|
|
289
|
-
import { ref } from 'vue';
|
|
290
|
-
|
|
291
|
-
interface Props {
|
|
292
|
-
msg: string;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const props = defineProps<Props>();
|
|
296
|
-
const count = ref(0);
|
|
297
|
-
|
|
298
|
-
const increment = (): void => {
|
|
299
|
-
count.value++;
|
|
300
|
-
};
|
|
301
|
-
</script>
|
|
302
|
-
|
|
303
|
-
<template>
|
|
304
|
-
<div class="flex flex-col items-center gap-4">
|
|
305
|
-
<h1 class="text-2xl font-bold">{{ msg }}</h1>
|
|
306
|
-
<p class="text-lg">Count: {{ count }}</p>
|
|
307
|
-
<button
|
|
308
|
-
@click="increment"
|
|
309
|
-
class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
310
|
-
>
|
|
311
|
-
Increment
|
|
312
|
-
</button>
|
|
313
|
-
</div>
|
|
314
|
-
</template>
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
在 `App.vue` 中使用:
|
|
318
|
-
|
|
319
|
-
```vue
|
|
320
|
-
<script setup lang="ts">
|
|
321
|
-
import HelloWorld from './components/HelloWorld.vue';
|
|
322
|
-
</script>
|
|
323
|
-
|
|
324
|
-
<template>
|
|
325
|
-
<HelloWorld msg="Hello Vue 3!" />
|
|
326
|
-
</template>
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### 组合式 API(Composition API)
|
|
330
|
-
|
|
331
|
-
使用 Vue 3 的 Composition API 管理组件逻辑:
|
|
332
|
-
|
|
333
|
-
```vue
|
|
334
|
-
<script setup lang="ts">
|
|
335
|
-
import { ref, computed, onMounted } from 'vue';
|
|
336
|
-
|
|
337
|
-
// 响应式状态
|
|
338
|
-
const count = ref(0);
|
|
339
|
-
const message = ref('Hello');
|
|
340
|
-
|
|
341
|
-
// 计算属性
|
|
342
|
-
const doubleCount = computed(() => count.value * 2);
|
|
343
|
-
|
|
344
|
-
// 方法
|
|
345
|
-
const increment = (): void => {
|
|
346
|
-
count.value++;
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
// 生命周期钩子
|
|
350
|
-
onMounted(() => {
|
|
351
|
-
console.log('Component mounted');
|
|
352
|
-
});
|
|
353
|
-
</script>
|
|
354
|
-
|
|
355
|
-
<template>
|
|
356
|
-
<div>
|
|
357
|
-
<p>{{ message }}</p>
|
|
358
|
-
<p>Count: {{ count }}, Double: {{ doubleCount }}</p>
|
|
359
|
-
<button @click="increment">Increment</button>
|
|
360
|
-
</div>
|
|
361
|
-
</template>
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
### 数据获取
|
|
365
|
-
|
|
366
|
-
使用 Vue 的响应式系统配合异步数据获取:
|
|
367
|
-
|
|
368
|
-
```vue
|
|
369
|
-
<script setup lang="ts">
|
|
370
|
-
import { ref, onMounted } from 'vue';
|
|
371
|
-
|
|
372
|
-
interface ApiData {
|
|
373
|
-
id: number;
|
|
374
|
-
title: string;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const data = ref<ApiData | null>(null);
|
|
378
|
-
const loading = ref(false);
|
|
379
|
-
const error = ref<string | null>(null);
|
|
380
|
-
|
|
381
|
-
const fetchData = async (): Promise<void> => {
|
|
382
|
-
loading.value = true;
|
|
383
|
-
error.value = null;
|
|
384
|
-
|
|
385
|
-
try {
|
|
386
|
-
const response = await fetch('https://api.example.com/data');
|
|
387
|
-
data.value = await response.json();
|
|
388
|
-
} catch (err) {
|
|
389
|
-
error.value = 'Failed to fetch data';
|
|
390
|
-
console.error('Failed to fetch data:', err);
|
|
391
|
-
} finally {
|
|
392
|
-
loading.value = false;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
onMounted(() => {
|
|
397
|
-
fetchData();
|
|
398
|
-
});
|
|
399
|
-
</script>
|
|
400
|
-
|
|
401
|
-
<template>
|
|
402
|
-
<div>
|
|
403
|
-
<div v-if="loading">Loading...</div>
|
|
404
|
-
<div v-else-if="error" class="text-red-500">{{ error }}</div>
|
|
405
|
-
<div v-else-if="data">
|
|
406
|
-
<h2>{{ data.title }}</h2>
|
|
407
|
-
<p>ID: {{ data.id }}</p>
|
|
408
|
-
</div>
|
|
409
|
-
</div>
|
|
410
|
-
</template>
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
### 环境变量
|
|
414
|
-
|
|
415
|
-
在 `.env` 文件中定义环境变量(需以 `VITE_` 开头):
|
|
416
|
-
|
|
417
|
-
```bash
|
|
418
|
-
VITE_API_URL=https://api.example.com
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
在代码中使用:
|
|
422
|
-
|
|
423
|
-
```typescript
|
|
424
|
-
const apiUrl = import.meta.env.VITE_API_URL;
|
|
425
|
-
console.log(apiUrl); // https://api.example.com
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
## 技术栈
|
|
429
|
-
|
|
430
|
-
- **框架**: Vue 3.x (Composition API)
|
|
431
|
-
- **构建工具**: Vite 6.x
|
|
432
|
-
- **语言**: TypeScript 5.x
|
|
433
|
-
- **样式**: Tailwind CSS 3.x
|
|
434
|
-
- **包管理器**: pnpm 9+
|
|
435
|
-
|
|
436
|
-
## 参考文档
|
|
437
|
-
|
|
438
|
-
- [Vue 3 官方文档](https://cn.vuejs.org/)
|
|
439
|
-
- [Vue 3 Composition API](https://cn.vuejs.org/guide/extras/composition-api-faq.html)
|
|
440
|
-
- [Vite 官方文档](https://cn.vitejs.dev/)
|
|
441
|
-
- [TypeScript 官方文档](https://www.typescriptlang.org/zh/docs/)
|
|
442
|
-
- [Tailwind CSS 文档](https://tailwindcss.com/docs)
|
|
443
|
-
|
|
444
|
-
## 重要提示
|
|
445
|
-
|
|
446
|
-
1. **必须使用 pnpm** 作为包管理器
|
|
447
|
-
2. **使用 Vue 3 Composition API** (`<script setup>`) 进行组件开发
|
|
448
|
-
3. **使用 TypeScript** 进行类型安全开发,为 props、emit 和 ref 添加类型
|
|
449
|
-
4. **使用 Tailwind CSS** 进行样式开发,支持响应式和暗色模式
|
|
450
|
-
5. **环境变量必须以 `VITE_` 开头** 才能在客户端代码中访问
|
|
451
|
-
6. **开发时使用 `coze dev`**,支持热更新和快速刷新
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# Dependencies
|
|
2
|
-
node_modules/
|
|
3
|
-
.pnp
|
|
4
|
-
.pnp.js
|
|
5
|
-
|
|
6
|
-
# Production build
|
|
7
|
-
dist/
|
|
8
|
-
build/
|
|
9
|
-
out/
|
|
10
|
-
|
|
11
|
-
# Testing
|
|
12
|
-
coverage/
|
|
13
|
-
*.lcov
|
|
14
|
-
.nyc_output
|
|
15
|
-
|
|
16
|
-
# Environment variables
|
|
17
|
-
.env
|
|
18
|
-
.env.local
|
|
19
|
-
.env.development.local
|
|
20
|
-
.env.test.local
|
|
21
|
-
.env.production.local
|
|
22
|
-
|
|
23
|
-
# Logs
|
|
24
|
-
logs/
|
|
25
|
-
*.log
|
|
26
|
-
npm-debug.log*
|
|
27
|
-
yarn-debug.log*
|
|
28
|
-
yarn-error.log*
|
|
29
|
-
pnpm-debug.log*
|
|
30
|
-
lerna-debug.log*
|
|
31
|
-
|
|
32
|
-
# Runtime data
|
|
33
|
-
pids
|
|
34
|
-
*.pid
|
|
35
|
-
*.seed
|
|
36
|
-
*.pid.lock
|
|
37
|
-
|
|
38
|
-
# Cache
|
|
39
|
-
.cache/
|
|
40
|
-
.eslintcache
|
|
41
|
-
.stylelintcache
|
|
42
|
-
|
|
43
|
-
# Editor directories and files
|
|
44
|
-
.vscode/*
|
|
45
|
-
!.vscode/extensions.json
|
|
46
|
-
!.vscode/settings.json
|
|
47
|
-
.idea/
|
|
48
|
-
*.suo
|
|
49
|
-
*.ntvs*
|
|
50
|
-
*.njsproj
|
|
51
|
-
*.sln
|
|
52
|
-
*.sw?
|
|
53
|
-
|
|
54
|
-
# OS files
|
|
55
|
-
.DS_Store
|
|
56
|
-
.DS_Store?
|
|
57
|
-
._*
|
|
58
|
-
Thumbs.db
|
|
59
|
-
|
|
60
|
-
# TypeScript
|
|
61
|
-
*.tsbuildinfo
|
|
62
|
-
|
|
63
|
-
# Vite
|
|
64
|
-
.vite/
|
|
65
|
-
|
|
66
|
-
.coze-logs
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
4
|
-
|
|
5
|
-
export default defineConfig([
|
|
6
|
-
eslint.configs.recommended,
|
|
7
|
-
...tseslint.configs.recommended,
|
|
8
|
-
globalIgnores(['dist/**', 'node_modules/**']),
|
|
9
|
-
]);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<meta name="description" content="扣子编程,你的 AI 开发伙伴已就位" />
|
|
7
|
-
<title>扣子编程 - AI 开发伙伴</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"></div>
|
|
11
|
-
<script type="module" src="/src/main.ts"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "<%= appName %>",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Vue 3 application with Vite + TypeScript",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "bash ./scripts/build.sh",
|
|
8
|
-
"dev": "bash ./scripts/dev.sh",
|
|
9
|
-
"preinstall": "npx only-allow pnpm",
|
|
10
|
-
"lint": "eslint",
|
|
11
|
-
"start": "bash ./scripts/start.sh",
|
|
12
|
-
"ts-check": "vue-tsc --noEmit"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@supabase/supabase-js": "2.95.3",
|
|
16
|
-
"dotenv": "^17.2.3",
|
|
17
|
-
"vue": "^3.5.13",
|
|
18
|
-
"vue-router": "^4.5.0"
|
|
19
|
-
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@vitejs/plugin-vue": "^5.2.1",
|
|
22
|
-
"autoprefixer": "^10.4.20",
|
|
23
|
-
"coze-coding-dev-sdk": "^0.7.16",
|
|
24
|
-
"eslint": "^9",
|
|
25
|
-
"less": "^4.2.1",
|
|
26
|
-
"only-allow": "^1.2.2",
|
|
27
|
-
"postcss": "^8.4.49",
|
|
28
|
-
"tailwindcss": "^3.4.17",
|
|
29
|
-
"typescript": "^5.6.0",
|
|
30
|
-
"typescript-eslint": "^8",
|
|
31
|
-
"vite": "^7.2.4",
|
|
32
|
-
"vue-tsc": "^2.2.0"
|
|
33
|
-
},
|
|
34
|
-
"packageManager": "pnpm@9.0.0",
|
|
35
|
-
"engines": {
|
|
36
|
-
"pnpm": ">=9.0.0"
|
|
37
|
-
}
|
|
38
|
-
}
|