Files
wasm-go/web/README.md
lychang 7f5350db62 update
2026-05-20 03:25:35 +08:00

64 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# WASM企业行业分类器
这是一个使用WebAssembly技术的前端版本企业行业分类器,允许在浏览器中直接运行Go代码。
## 功能特性
- 在浏览器中直接运行Go代码(通过WASM)
- 输入企业名称进行行业分类
- 显示主要行业和次要行业信息
- 响应式设计,适配不同设备
## 架构说明
- `cmd/wasm/main.go`: Go源代码,编译为WASM
- `web/index.html`: 前端界面
- `build_wasm.bat`: Windows编译脚本
## 编译步骤
### Windows
1. 确保已安装Go 1.12或更高版本
2. 运行编译脚本:
```cmd
build_wasm.bat
```
### 手动编译(Linux/Mac)
```bash
# 复制WASM执行器
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" web/
# 编译为WASM
GOOS=js GOARCH=wasm go build -o web/main.wasm cmd/wasm/main.go
```
## 运行
由于浏览器安全策略限制,需要通过HTTP服务器运行,不能直接打开HTML文件:
```bash
# 使用Python 3
cd web
python -m http.server 8080
# 或使用Node.js
npx http-server web -p 8080
# 然后在浏览器中访问 http://localhost:8080/index.html
```
## 技术细节
- 使用Go的`syscall/js`包实现Go与JavaScript互操作
- WASM模块负责调用行业分类算法
- 前端界面使用原生JavaScript和CSS
- 支持异步API调用和错误处理
## 注意事项
- WASM版本目前使用固定的API配置
- 实际部署时需要考虑安全性,如API密钥管理
- 需要后端服务支持API调用(企业信息获取、LLM调用等)