慧眼平台V2版本,基于Vue.js和Webpack构建的前端项目,支持中英文国际化。
yarn install
-
yarn dev
或yarn start
- 启动开发服务器 -
yarn serve
- 使用Vue CLI服务启动开发服务器
-
yarn build
- 构建生产版本 -
yarn build:prod
- 构建生产版本(别名) -
yarn build:dev
- 构建开发版本 -
yarn clean
- 清理dist目录
-
yarn lint
- 运行ESLint检查代码 -
yarn lint:fix
- 运行ESLint并自动修复问题 -
yarn format
- 使用Prettier格式化代码
-
yarn analyze
- 分析打包结果
-
yarn install:clean
- 清理并重新安装依赖 -
yarn update
- 交互式更新依赖包
项目支持中英文切换,通过以下方式控制:
-
localStorage控制:
// 设置为英文 localStorage.setItem('cutoverLanguage', 'en') // 设置为中文 localStorage.setItem('cutoverLanguage', 'zh')
-
语言切换器:
- 点击右上角的语言切换器
- 选择中文或英文
- 切换后会自动保存到localStorage
- 中文语言包:
src/i18n/index.js
中的zhCN
对象 - 英文语言包:
src/i18n/index.js
中的enUS
对象
在 src/i18n/index.js
中添加新的翻译键值:
const zhCN = {
newKey: '中文翻译'
}
const enUS = {
newKey: 'English translation'
}
然后在组件中使用:
<template>
<div>{{ $t('newKey') }}</div>
</template>
src/
├── assets/ # 静态资源
│ └── imgs/ # 图片资源
├── i18n/ # 国际化配置
│ └── index.js # 语言包配置
├── index.js # 入口文件
├── index.vue # 主组件
├── LanguageSwitcher.vue # 语言切换组件
├── msgWebSocket.vue # WebSocket消息组件
├── g_bindvx.vue # 微信绑定组件
└── utils.js # 工具函数
- Vue.js 2.x
- Webpack 3.x
- Element UI
- Vue I18n
- Axios
- Moment.js
- 克隆项目后运行
yarn install
安装依赖 - 使用
yarn dev
启动开发服务器 - 开发完成后使用
yarn build
构建生产版本 - 使用
yarn lint
和yarn format
保持代码质量
# 启动开发服务器
yarn dev
# 访问 http://localhost:8080 查看效果
# 先构建项目
yarn build:dev
# 然后直接在浏览器中打开 public/index.html 文件
- 打开浏览器开发者工具查看控制台输出
- 使用Vue DevTools插件进行Vue组件调试
- 修改src/index.vue文件后重新构建即可看到效果
- 切换语言:修改localStorage中的cutoverLanguage值
项目使用 svg-sprite-loader
来处理 SVG 图标,支持动态颜色配置。
-
Webpack 配置:在
webpack.config.js
中配置了svg-sprite-loader
-
自动导入:
src/utils/svgIcons.js
自动导入所有 SVG 文件 -
组件封装:
src/SvgIcon.vue
提供统一的 SVG 图标组件
import SvgIcon from './SvgIcon.vue'
export default {
components: { SvgIcon }
}
<template>
<svg-icon icon-class="help_center" style="width: 24px; height: 24px; color: #409eff;" />
</template>
-
icon-class
:SVG 文件名(不含 .svg 扩展名) -
className
:额外的 CSS 类名 -
color
:颜色属性(也可使用 style 属性)
.svg-icon {
fill: currentColor;
transition: fill 0.3s ease;
}
.svg-icon:hover {
fill: #409eff;
}
项目中的 SVG 图标包括:
-
help_center
- 帮助中心 -
downsvg
- 下载图标 -
refresh
- 刷新图标 -
success
- 成功图标 -
await
- 等待图标 -
fail
- 失败图标 -
jumpTo
- 跳转图标 -
jumpToHover
- 跳转悬停图标 -
passwordView
- 密码可见图标 -
passwordeye
- 密码隐藏图标
访问 public/svg-demo.html
查看 SVG 图标演示和动态颜色效果。