@coze-arch/cli 0.0.1-alpha.89faa2 → 0.0.1-alpha.8b5326
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/.cozeproj/scripts/dev_run.sh +30 -21
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +2 -2
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +2 -2
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
- package/lib/__templates__/expo/README.md +4 -2
- package/lib/__templates__/expo/client/app/+not-found.tsx +30 -0
- package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
- package/lib/__templates__/expo/client/app/index.tsx +1 -1
- package/lib/__templates__/expo/client/app.config.ts +4 -3
- package/lib/__templates__/expo/client/components/Screen.tsx +3 -19
- package/lib/__templates__/expo/client/components/ThemedView.tsx +1 -2
- package/lib/__templates__/expo/client/constants/theme.ts +23 -700
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/client/eslint.config.mjs +37 -10
- package/lib/__templates__/expo/client/hooks/{useColorScheme.ts → useColorScheme.tsx} +20 -6
- package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
- package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/client/package.json +36 -34
- package/lib/__templates__/expo/client/screens/{home → demo}/index.tsx +7 -3
- package/lib/__templates__/expo/client/screens/{home → demo}/styles.ts +10 -6
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +11 -10
- package/lib/__templates__/expo/client/utils/index.ts +22 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
- 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/react-native/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
- package/lib/__templates__/expo/package.json +3 -0
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +1332 -2620
- package/lib/__templates__/expo/server/build.js +21 -0
- package/lib/__templates__/expo/server/package.json +10 -7
- package/lib/__templates__/expo/server/src/index.ts +3 -1
- package/lib/__templates__/expo/template.config.js +56 -0
- package/lib/__templates__/native-static/.coze +11 -0
- package/lib/__templates__/native-static/index.html +33 -0
- package/lib/__templates__/native-static/styles/main.css +136 -0
- package/lib/__templates__/native-static/template.config.js +22 -0
- package/lib/__templates__/nextjs/.babelrc +15 -0
- package/lib/__templates__/nextjs/README.md +5 -0
- package/lib/__templates__/nextjs/_npmrc +1 -0
- package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
- package/lib/__templates__/nextjs/next.config.ts +2 -1
- package/lib/__templates__/nextjs/package.json +8 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +3488 -1569
- 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 +5 -3
- package/lib/__templates__/nextjs/src/app/page.tsx +17 -60
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/template.config.js +52 -11
- package/lib/__templates__/nextjs/tsconfig.json +1 -1
- package/lib/__templates__/nuxt-vue/.coze +12 -0
- package/lib/__templates__/nuxt-vue/README.md +73 -0
- package/lib/__templates__/nuxt-vue/_gitignore +24 -0
- package/lib/__templates__/nuxt-vue/_npmrc +23 -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__/nuxt-vue/assets/css/main.css +24 -0
- 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__/nuxt-vue/postcss.config.mjs +8 -0
- package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
- package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
- package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +39 -0
- 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/.coze +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
- package/lib/__templates__/taro/README.md +751 -0
- package/lib/__templates__/taro/_gitignore +40 -0
- package/lib/__templates__/taro/_npmrc +18 -0
- package/lib/__templates__/taro/babel.config.js +12 -0
- package/lib/__templates__/taro/config/dev.ts +9 -0
- package/lib/__templates__/taro/config/index.ts +223 -0
- package/lib/__templates__/taro/config/prod.ts +34 -0
- package/lib/__templates__/taro/eslint.config.mjs +80 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +107 -0
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +23100 -0
- package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
- package/lib/__templates__/taro/project.config.json +15 -0
- package/lib/__templates__/taro/server/nest-cli.json +10 -0
- package/lib/__templates__/taro/server/package.json +40 -0
- package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
- package/lib/__templates__/taro/server/src/app.module.ts +10 -0
- package/lib/__templates__/taro/server/src/app.service.ts +8 -0
- package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
- package/lib/__templates__/taro/server/src/main.ts +49 -0
- package/lib/__templates__/taro/server/tsconfig.json +24 -0
- package/lib/__templates__/taro/src/app.config.ts +11 -0
- package/lib/__templates__/taro/src/app.css +52 -0
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/index.html +39 -0
- package/lib/__templates__/taro/src/network.ts +39 -0
- package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
- package/lib/__templates__/taro/src/pages/index/index.css +1 -0
- package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
- package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
- package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +201 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +142 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/taro/stylelint.config.mjs +4 -0
- package/lib/__templates__/taro/template.config.js +68 -0
- package/lib/__templates__/taro/tsconfig.json +29 -0
- package/lib/__templates__/taro/types/global.d.ts +32 -0
- package/lib/__templates__/templates.json +75 -0
- package/lib/__templates__/vite/README.md +190 -11
- package/lib/__templates__/vite/_gitignore +1 -0
- package/lib/__templates__/vite/_npmrc +1 -0
- package/lib/__templates__/vite/eslint.config.mjs +6 -1
- package/lib/__templates__/vite/package.json +19 -2
- package/lib/__templates__/vite/pnpm-lock.yaml +1547 -172
- 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/src/main.ts +17 -48
- package/lib/__templates__/vite/template.config.js +63 -6
- package/lib/__templates__/vite/tsconfig.json +4 -3
- package/lib/__templates__/vite/vite.config.ts +5 -0
- package/lib/cli.js +941 -195
- package/package.json +7 -3
- package/lib/__templates__/expo/client/app/home.tsx +0 -1
- package/lib/__templates__/expo/client/assets/images/coze-logo.png +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"miniprogramRoot": "./dist",
|
|
3
|
+
"projectname": "<%= appName %>",
|
|
4
|
+
"description": "test",
|
|
5
|
+
"appid": "touristappid",
|
|
6
|
+
"setting": {
|
|
7
|
+
"urlCheck": true,
|
|
8
|
+
"es6": false,
|
|
9
|
+
"enhance": false,
|
|
10
|
+
"compileHotReLoad": false,
|
|
11
|
+
"postcss": false,
|
|
12
|
+
"minified": false
|
|
13
|
+
},
|
|
14
|
+
"compileType": "miniprogram"
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "NestJS server application",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "nest build",
|
|
8
|
+
"dev": "nest start --watch",
|
|
9
|
+
"start": "nest start",
|
|
10
|
+
"start:debug": "nest start --debug --watch",
|
|
11
|
+
"start:prod": "node dist/main"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@aws-sdk/client-s3": "^3.958.0",
|
|
15
|
+
"@aws-sdk/lib-storage": "^3.958.0",
|
|
16
|
+
"@nestjs/common": "^10.4.15",
|
|
17
|
+
"@nestjs/core": "^10.4.15",
|
|
18
|
+
"@nestjs/platform-express": "^10.4.15",
|
|
19
|
+
"@supabase/supabase-js": "2.95.3",
|
|
20
|
+
"better-sqlite3": "^11.9.1",
|
|
21
|
+
"coze-coding-dev-sdk": "^0.7.16",
|
|
22
|
+
"dotenv": "^17.2.3",
|
|
23
|
+
"drizzle-kit": "^0.31.8",
|
|
24
|
+
"drizzle-orm": "^0.45.1",
|
|
25
|
+
"drizzle-zod": "^0.8.3",
|
|
26
|
+
"express": "5.2.1",
|
|
27
|
+
"pg": "^8.16.3",
|
|
28
|
+
"rxjs": "^7.8.1",
|
|
29
|
+
"zod": "^4.3.5"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@nestjs/cli": "^10.4.9",
|
|
33
|
+
"@nestjs/schematics": "^10.2.3",
|
|
34
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
35
|
+
"@types/express": "5.0.6",
|
|
36
|
+
"@types/node": "^22.10.2",
|
|
37
|
+
"drizzle-kit": "^0.31.8",
|
|
38
|
+
"typescript": "^5.7.2"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Controller, Get } from '@nestjs/common';
|
|
2
|
+
import { AppService } from '@/app.service';
|
|
3
|
+
|
|
4
|
+
@Controller()
|
|
5
|
+
export class AppController {
|
|
6
|
+
constructor(private readonly appService: AppService) {}
|
|
7
|
+
|
|
8
|
+
@Get('hello')
|
|
9
|
+
getHello(): { status: string; data: string } {
|
|
10
|
+
return {
|
|
11
|
+
status: 'success',
|
|
12
|
+
data: this.appService.getHello()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Get('health')
|
|
17
|
+
getHealth(): { status: string; data: string } {
|
|
18
|
+
return {
|
|
19
|
+
status: 'success',
|
|
20
|
+
data: new Date().toISOString(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Injectable,
|
|
3
|
+
NestInterceptor,
|
|
4
|
+
ExecutionContext,
|
|
5
|
+
CallHandler,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
import { Observable } from 'rxjs';
|
|
8
|
+
import { map } from 'rxjs/operators';
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class HttpStatusInterceptor implements NestInterceptor {
|
|
12
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
|
13
|
+
const request = context.switchToHttp().getRequest();
|
|
14
|
+
const response = context.switchToHttp().getResponse();
|
|
15
|
+
|
|
16
|
+
// 如果是 POST 请求且状态码为 201,改为 200
|
|
17
|
+
if (request.method === 'POST' && response.statusCode === 201) {
|
|
18
|
+
response.status(200);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return next.handle();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { NestFactory } from '@nestjs/core';
|
|
2
|
+
import { AppModule } from '@/app.module';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
import { HttpStatusInterceptor } from '@/interceptors/http-status.interceptor';
|
|
5
|
+
|
|
6
|
+
function parsePort(): number {
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const portIndex = args.indexOf('-p');
|
|
9
|
+
if (portIndex !== -1 && args[portIndex + 1]) {
|
|
10
|
+
const port = parseInt(args[portIndex + 1], 10);
|
|
11
|
+
if (!isNaN(port) && port > 0 && port < 65536) {
|
|
12
|
+
return port;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return <%= serverPort %>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function bootstrap() {
|
|
19
|
+
const app = await NestFactory.create(AppModule);
|
|
20
|
+
|
|
21
|
+
app.enableCors({
|
|
22
|
+
origin: true,
|
|
23
|
+
credentials: true,
|
|
24
|
+
});
|
|
25
|
+
app.setGlobalPrefix('api');
|
|
26
|
+
app.use(express.json({ limit: '50mb' }));
|
|
27
|
+
app.use(express.urlencoded({ limit: '50mb', extended: true }));
|
|
28
|
+
|
|
29
|
+
// 全局拦截器:统一将 POST 请求的 201 状态码改为 200
|
|
30
|
+
app.useGlobalInterceptors(new HttpStatusInterceptor());
|
|
31
|
+
// 1. 开启优雅关闭 Hooks (关键!)
|
|
32
|
+
app.enableShutdownHooks();
|
|
33
|
+
|
|
34
|
+
// 2. 解析端口
|
|
35
|
+
const port = parsePort();
|
|
36
|
+
try {
|
|
37
|
+
await app.listen(port);
|
|
38
|
+
console.log(`Server running on http://localhost:${port}`);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err.code === 'EADDRINUSE') {
|
|
41
|
+
console.error(`❌ 端口 \({port} 被占用! 请运行 'npx kill-port \){port}' 然后重试。`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
} else {
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
console.log(`Application is running on: http://localhost:<%= serverPort %>`);
|
|
48
|
+
}
|
|
49
|
+
bootstrap();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "ES2021",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"strictNullChecks": true,
|
|
16
|
+
"noImplicitAny": false,
|
|
17
|
+
"strictBindCallApply": false,
|
|
18
|
+
"forceConsistentCasingInFileNames": false,
|
|
19
|
+
"noFallthroughCasesInSwitch": false,
|
|
20
|
+
"paths": {
|
|
21
|
+
"@/*": ["./src/*"]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
@import url('tailwindcss');
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* H5 端 rem 适配:与小程序 rpx 缩放一致
|
|
5
|
+
* 375px 屏幕:1rem = 16px,小程序 32rpx = 16px
|
|
6
|
+
*/
|
|
7
|
+
html {
|
|
8
|
+
font-size: 4vw !important;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* 小程序页面容器高度设置,确保垂直居中生效 */
|
|
12
|
+
/* stylelint-disable-next-line selector-type-no-unknown */
|
|
13
|
+
page {
|
|
14
|
+
height: 100%;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* H5 端组件默认样式修复 */
|
|
18
|
+
taro-view-core {
|
|
19
|
+
display: block;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
taro-text-core {
|
|
23
|
+
display: inline;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
taro-input-core {
|
|
27
|
+
display: block;
|
|
28
|
+
width: 100%;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
taro-input-core input {
|
|
32
|
+
width: 100%;
|
|
33
|
+
background: transparent;
|
|
34
|
+
border: none;
|
|
35
|
+
outline: none;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* 全局按钮样式重置 */
|
|
39
|
+
taro-button-core,
|
|
40
|
+
button {
|
|
41
|
+
margin: 0 !important;
|
|
42
|
+
padding: 0 !important;
|
|
43
|
+
line-height: inherit;
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
taro-button-core::after,
|
|
50
|
+
button::after {
|
|
51
|
+
border: none;
|
|
52
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
6
|
+
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
|
|
7
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
8
|
+
<meta name="apple-touch-fullscreen" content="yes">
|
|
9
|
+
<meta name="format-detection" content="telephone=no,address=no">
|
|
10
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="white">
|
|
11
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
12
|
+
<title><%= appName %></title>
|
|
13
|
+
<script><%%= htmlWebpackPlugin.options.script %></script>
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
<div id="app">
|
|
18
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="lab(2.86037 0.455312 0.568903)"
|
|
19
|
+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="
|
|
20
|
+
position: fixed;
|
|
21
|
+
inset: 0;
|
|
22
|
+
margin: auto;
|
|
23
|
+
width: 24px;
|
|
24
|
+
height: 24px;
|
|
25
|
+
animation: __app-loading-spin 1s linear infinite;
|
|
26
|
+
">
|
|
27
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
28
|
+
</svg>
|
|
29
|
+
<style>
|
|
30
|
+
@keyframes __app-loading-spin {
|
|
31
|
+
to {
|
|
32
|
+
transform: rotate(360deg);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
</style>
|
|
36
|
+
</div>
|
|
37
|
+
</body>
|
|
38
|
+
|
|
39
|
+
</html>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 网络请求模块
|
|
5
|
+
* 封装 Taro.request、Taro.uploadFile、Taro.downloadFile,自动添加项目域名前缀
|
|
6
|
+
* 如果请求的 url 以 http:// 或 https:// 开头,则不会添加域名前缀
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: 项目已经全局注入 PROJECT_DOMAIN
|
|
9
|
+
* IMPORTANT: 除非你需要添加全局参数,如给所有请求加上 header,否则不能修改此文件
|
|
10
|
+
*/
|
|
11
|
+
export namespace Network {
|
|
12
|
+
const createUrl = (url: string): string => {
|
|
13
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
14
|
+
return url
|
|
15
|
+
}
|
|
16
|
+
return `${PROJECT_DOMAIN}${url}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const request: typeof Taro.request = option => {
|
|
20
|
+
return Taro.request({
|
|
21
|
+
...option,
|
|
22
|
+
url: createUrl(option.url),
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const uploadFile: typeof Taro.uploadFile = option => {
|
|
27
|
+
return Taro.uploadFile({
|
|
28
|
+
...option,
|
|
29
|
+
url: createUrl(option.url),
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const downloadFile: typeof Taro.downloadFile = option => {
|
|
34
|
+
return Taro.downloadFile({
|
|
35
|
+
...option,
|
|
36
|
+
url: createUrl(option.url),
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* 优先使用 tailwindcss,如无必要请不要使用css */
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { View, Text, Image } from '@tarojs/components';
|
|
2
|
+
import { useLoad } from '@tarojs/taro';
|
|
3
|
+
import { Network } from '@/network';
|
|
4
|
+
import './index.css';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 默认首页,直接覆盖本页内容
|
|
8
|
+
*/
|
|
9
|
+
const IndexPage = () => {
|
|
10
|
+
useLoad(async () => {
|
|
11
|
+
const res = await Network.request({ url: '/api/hello' });
|
|
12
|
+
console.log(res.data);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<View className="w-full h-full flex flex-col justify-center items-center gap-1">
|
|
17
|
+
<Image
|
|
18
|
+
className="w-32 h-28"
|
|
19
|
+
src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif"
|
|
20
|
+
/>
|
|
21
|
+
<View className="self-stretch flex flex-col justify-start items-start gap-2">
|
|
22
|
+
<Text className="self-stretch text-center justify-start text-base-accent-foreground text-base font-bold">
|
|
23
|
+
应用开发中
|
|
24
|
+
</Text>
|
|
25
|
+
<Text className="self-stretch text-center justify-start text-base-muted-foreground text-sm font-normal">
|
|
26
|
+
请稍候,界面即将呈现
|
|
27
|
+
</Text>
|
|
28
|
+
</View>
|
|
29
|
+
</View>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default IndexPage;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 小程序调试工具
|
|
5
|
+
* 在开发版/体验版自动开启调试模式
|
|
6
|
+
* 支持微信小程序和抖音小程序
|
|
7
|
+
*/
|
|
8
|
+
export function devDebug() {
|
|
9
|
+
const env = Taro.getEnv();
|
|
10
|
+
if (env === Taro.ENV_TYPE.WEAPP || env === Taro.ENV_TYPE.TT) {
|
|
11
|
+
try {
|
|
12
|
+
const accountInfo = Taro.getAccountInfoSync();
|
|
13
|
+
const envVersion = accountInfo.miniProgram.envVersion;
|
|
14
|
+
console.log('[Debug] envVersion:', envVersion);
|
|
15
|
+
|
|
16
|
+
if (envVersion !== 'release') {
|
|
17
|
+
Taro.setEnableDebug({ enableDebug: true });
|
|
18
|
+
}
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error('[Debug] 开启调试模式失败:', error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { H5NavBar } from './h5-navbar';
|
|
3
|
+
|
|
4
|
+
export const H5Container = ({ children }: PropsWithChildren) => {
|
|
5
|
+
if (TARO_ENV !== 'h5') {
|
|
6
|
+
return <>{children}</>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
<H5NavBar />
|
|
12
|
+
{children}
|
|
13
|
+
</>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { View, Text } from '@tarojs/components';
|
|
2
|
+
import Taro, { useDidShow, usePageScroll } from '@tarojs/taro';
|
|
3
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import { ChevronLeft, House } from 'lucide-react-taro';
|
|
5
|
+
|
|
6
|
+
interface NavConfig {
|
|
7
|
+
navigationBarTitleText?: string;
|
|
8
|
+
navigationBarBackgroundColor?: string;
|
|
9
|
+
navigationBarTextStyle?: 'black' | 'white';
|
|
10
|
+
navigationStyle?: 'default' | 'custom';
|
|
11
|
+
transparentTitle?: 'none' | 'always' | 'auto';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
enum LeftIcon {
|
|
15
|
+
Back = 'back',
|
|
16
|
+
Home = 'home',
|
|
17
|
+
None = 'none',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface NavState {
|
|
21
|
+
visible: boolean;
|
|
22
|
+
title: string;
|
|
23
|
+
bgColor: string;
|
|
24
|
+
textStyle: 'black' | 'white';
|
|
25
|
+
navStyle: 'default' | 'custom';
|
|
26
|
+
transparent: 'none' | 'always' | 'auto';
|
|
27
|
+
leftIcon: LeftIcon;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DEFAULT_NAV_STATE: NavState = {
|
|
31
|
+
visible: false,
|
|
32
|
+
title: '',
|
|
33
|
+
bgColor: '#ffffff',
|
|
34
|
+
textStyle: 'black',
|
|
35
|
+
navStyle: 'default',
|
|
36
|
+
transparent: 'none',
|
|
37
|
+
leftIcon: LeftIcon.None,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const getGlobalWindowConfig = (): Partial<NavConfig> => {
|
|
41
|
+
const app = Taro.getApp();
|
|
42
|
+
return app?.config?.window || {};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getTabBarPages = (): Set<string> => {
|
|
46
|
+
const tabBar = Taro.getApp()?.config?.tabBar;
|
|
47
|
+
return new Set(
|
|
48
|
+
tabBar?.list?.map((item: { pagePath: string }) => item.pagePath) || [],
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const computeLeftIcon = (
|
|
53
|
+
route: string,
|
|
54
|
+
tabBarPages: Set<string>,
|
|
55
|
+
historyLength: number,
|
|
56
|
+
): LeftIcon => {
|
|
57
|
+
if (!route) return LeftIcon.None;
|
|
58
|
+
|
|
59
|
+
const isHomePage =
|
|
60
|
+
route === 'pages/index/index' || route === '/pages/index/index';
|
|
61
|
+
const isTabBarPage = tabBarPages.has(route);
|
|
62
|
+
const hasHistory = historyLength > 1;
|
|
63
|
+
|
|
64
|
+
if (isTabBarPage || isHomePage) return LeftIcon.None;
|
|
65
|
+
if (hasHistory) return LeftIcon.Back;
|
|
66
|
+
return LeftIcon.Home;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const H5NavBar = () => {
|
|
70
|
+
const [navState, setNavState] = useState<NavState>(DEFAULT_NAV_STATE);
|
|
71
|
+
const [scrollOpacity, setScrollOpacity] = useState(0);
|
|
72
|
+
|
|
73
|
+
const updateNavState = useCallback(() => {
|
|
74
|
+
const pages = Taro.getCurrentPages();
|
|
75
|
+
const currentPage = pages[pages.length - 1];
|
|
76
|
+
const route = currentPage?.route || '';
|
|
77
|
+
const pageConfig: NavConfig = (currentPage as any)?.config || {};
|
|
78
|
+
const globalConfig = getGlobalWindowConfig();
|
|
79
|
+
const tabBarPages = getTabBarPages();
|
|
80
|
+
|
|
81
|
+
const isHomePage =
|
|
82
|
+
route === 'pages/index/index' || route === '/pages/index/index';
|
|
83
|
+
const isTabBarPage = tabBarPages.has(route);
|
|
84
|
+
const shouldHideNav =
|
|
85
|
+
tabBarPages.size <= 1 &&
|
|
86
|
+
pages.length <= 1 &&
|
|
87
|
+
(isHomePage || isTabBarPage);
|
|
88
|
+
|
|
89
|
+
setNavState({
|
|
90
|
+
visible: !shouldHideNav,
|
|
91
|
+
title:
|
|
92
|
+
pageConfig.navigationBarTitleText ||
|
|
93
|
+
globalConfig.navigationBarTitleText ||
|
|
94
|
+
'',
|
|
95
|
+
bgColor:
|
|
96
|
+
pageConfig.navigationBarBackgroundColor ||
|
|
97
|
+
globalConfig.navigationBarBackgroundColor ||
|
|
98
|
+
'#ffffff',
|
|
99
|
+
textStyle:
|
|
100
|
+
pageConfig.navigationBarTextStyle ||
|
|
101
|
+
globalConfig.navigationBarTextStyle ||
|
|
102
|
+
'black',
|
|
103
|
+
navStyle:
|
|
104
|
+
pageConfig.navigationStyle || globalConfig.navigationStyle || 'default',
|
|
105
|
+
transparent:
|
|
106
|
+
pageConfig.transparentTitle || globalConfig.transparentTitle || 'none',
|
|
107
|
+
leftIcon: shouldHideNav
|
|
108
|
+
? LeftIcon.None
|
|
109
|
+
: computeLeftIcon(route, tabBarPages, pages.length),
|
|
110
|
+
});
|
|
111
|
+
}, []);
|
|
112
|
+
|
|
113
|
+
useDidShow(() => {
|
|
114
|
+
updateNavState();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
usePageScroll(({ scrollTop }) => {
|
|
118
|
+
if (navState.transparent === 'auto') {
|
|
119
|
+
setScrollOpacity(Math.min(scrollTop / 100, 1));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (TARO_ENV !== 'h5') return;
|
|
125
|
+
|
|
126
|
+
const titleEl = document.querySelector('title') || document.head;
|
|
127
|
+
const observer = new MutationObserver(() => updateNavState());
|
|
128
|
+
observer.observe(titleEl, {
|
|
129
|
+
subtree: true,
|
|
130
|
+
childList: true,
|
|
131
|
+
characterData: true,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return () => observer.disconnect();
|
|
135
|
+
}, [updateNavState]);
|
|
136
|
+
|
|
137
|
+
const shouldRender =
|
|
138
|
+
TARO_ENV === 'h5' && navState.visible && navState.navStyle !== 'custom';
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (TARO_ENV !== 'h5') return;
|
|
142
|
+
if (shouldRender) {
|
|
143
|
+
document.body.classList.add('h5-navbar-visible');
|
|
144
|
+
} else {
|
|
145
|
+
document.body.classList.remove('h5-navbar-visible');
|
|
146
|
+
}
|
|
147
|
+
}, [shouldRender]);
|
|
148
|
+
|
|
149
|
+
if (!shouldRender) {
|
|
150
|
+
return <></>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const iconColor = navState.textStyle === 'white' ? '#fff' : '#333';
|
|
154
|
+
const textColorClass =
|
|
155
|
+
navState.textStyle === 'white' ? 'text-white' : 'text-gray-800';
|
|
156
|
+
|
|
157
|
+
const getBgStyle = () => {
|
|
158
|
+
if (navState.transparent === 'always') {
|
|
159
|
+
return { backgroundColor: 'transparent' };
|
|
160
|
+
}
|
|
161
|
+
if (navState.transparent === 'auto') {
|
|
162
|
+
return { backgroundColor: navState.bgColor, opacity: scrollOpacity };
|
|
163
|
+
}
|
|
164
|
+
return { backgroundColor: navState.bgColor };
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const handleBack = () => Taro.navigateBack();
|
|
168
|
+
const handleGoHome = () => Taro.reLaunch({ url: '/pages/index/index' });
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<View
|
|
173
|
+
className="fixed top-0 left-0 right-0 h-11 flex items-center justify-center z-1000"
|
|
174
|
+
style={getBgStyle()}
|
|
175
|
+
>
|
|
176
|
+
{navState.leftIcon === LeftIcon.Back && (
|
|
177
|
+
<View
|
|
178
|
+
className="absolute left-2 top-1/2 -translate-y-1/2 p-1 flex items-center justify-center"
|
|
179
|
+
onClick={handleBack}
|
|
180
|
+
>
|
|
181
|
+
<ChevronLeft size={24} color={iconColor} />
|
|
182
|
+
</View>
|
|
183
|
+
)}
|
|
184
|
+
{navState.leftIcon === LeftIcon.Home && (
|
|
185
|
+
<View
|
|
186
|
+
className="absolute left-2 top-1/2 -translate-y-1/2 p-1 flex items-center justify-center"
|
|
187
|
+
onClick={handleGoHome}
|
|
188
|
+
>
|
|
189
|
+
<House size={22} color={iconColor} />
|
|
190
|
+
</View>
|
|
191
|
+
)}
|
|
192
|
+
<Text
|
|
193
|
+
className={`text-base font-medium max-w-3/5 truncate ${textColorClass}`}
|
|
194
|
+
>
|
|
195
|
+
{navState.title}
|
|
196
|
+
</Text>
|
|
197
|
+
</View>
|
|
198
|
+
<View className="h-11 shrink-0" />
|
|
199
|
+
</>
|
|
200
|
+
);
|
|
201
|
+
};
|