v3.3.5细节优化,使用手册更新

This commit is contained in:
ray_wuhao 2023-06-16 17:24:59 +08:00
parent 936ddf3c14
commit d1cb4ddb41
18 changed files with 211 additions and 35 deletions

146
MANUAL.md
View File

@ -2,7 +2,7 @@
## 前言 ## 前言
> `Ray Template` 默认使用 `yarn` 作为包管理器,并且默认启用严格模式的 `eslint` > `Ray Template` 默认使用 `yarn` 作为包管理器,并且默认启用严格模式的 `eslint`在导入模块的时候除 `.ts` `.tsx` `.d.ts` 文件等不需要手动补全后缀名,其余的模块导入应该手动补全所有后缀名。
### 使用 ### 使用
@ -16,4 +16,146 @@ yarn
npm i npm i
``` ```
#### 未完待续。。。后续慢慢更新该文件 #### 启动项目
```sh
# yarn
yarn dev
# npm
npm run dev
```
#### 构建项目
```sh
# yarn
yarn build
# npm
npm run build
```
### 国际化
#### Tip
- 每个新的语言包文件的文件名视为 path 开头menu.json => menu.xxx
#### 新增语言包、新增语言模块
> 项目国际化管理模块,统一放置于 `src/locales` 下。
##### 文件包
- lang
- helper.ts
- index.ts
- useI18n.ts
> 项目中使用 t locale 方法时使用模板提供方法useI18n.ts
```tsx
// 引入包
import { useI18n } from '@/locales/useI18n'
const { t, locale } = useI18n()
/**
*
* t: 用于绑定国际化 path
* locale: 用于切换系统语言。参数 key 必须与 lang 包中的语言包一致
*/
const demo = () => <span>{t('demo.demo')}</span>
locale('zh-CN')
locale('en-US')
```
##### 新增语言包
> 我们举例新增台湾地区语言包。
- `src/locales/lang` 文件下创建对应新语言包文件夹与语言文件
- zh-TW 文件夹
- zh-TW.ts 文件
- 创建与原有语言格式一样的文件夹(可以直接 cv 过去)
- 配置语言下拉项LOCAL_OPTIONS
- 配置 dayjs 国际化映射DAYJS_LOCAL_MAP
> 具体注意事项看注释。
##### 最后
> 按照上述步骤操作后,就已经给模板添加了一个新的语言包了。可以在页面的右上角国际化下拉框中看到新增的下拉选项,点击切换后,即可切换到对应的语言了。
### 路由
#### Tip
- 在该模板中,路由 path 属性视 `/` 开头的路由为根路由
- 路由会在初始化的时候将所有路由进行提升(全部提升为顶级路由),所以注意第一条 Tip
- 路由模块会影响菜单的输出显示(菜单模块与路由模块进行拆分开来的)
- 具体路由支持配置属性看 router/README.md 文件
#### 文件包
- constant 文件放置一些公共东西
- helper 文件放置 router 的一些 hook 方法
- modules 页面路由入口modules 文件中每一个 xxx.ts 文件都会被视为是一个路由模块)
- utils router 拓展方法
- ...
##### 新增路由页面
- modules 中添加一个新的模块log.ts
- 配置路由的相关信息
- views 中创建 log 相关的页面信息
```ts
// 辅助函数,配合 i18n-ally 插件使用
import { t } from '@/locales/useI18n'
// 路由配置类型提示
import type { AppRouteRecordRaw } from '@/router/type'
const log: AppRouteRecordRaw = {
path: '/log',
name: 'Log',
component: () => import('@/views/log/index.vue'),
meta: {
i18nKey: t('menu.Log'),
icon: 'log',
order: 3,
},
children: [
{
path: 'my-log',
name: 'MyLog',
component: () => import('@/views/my-log/index.vue'),
meta: {
i18nKey: t('menu.MyLog'),
order: 0,
},
},
{
path: 'group-log',
name: 'MyLog',
component: () => import('@/views/group-log/index.vue'),
meta: {
i18nKey: t('menu.GroupLog'),
order: 0,
},
},
],
}
export default log
```
##### 最后
> 打开浏览器可以看到页面菜单上已经有一个日志菜单。
#### 未完待续。。。后续慢慢更新该手册

View File

@ -1,3 +1,19 @@
/**
*
* `echarts` . 便使 `chart`
*
* `chart` , 使, 使 `use`
*
* 预引入: 柱状图, 线, , k线图,
* 预引入: 提示框, , , ,
*
* , `setOption`
*
* ,
*
* 注意: 尽量别一次性倒入全部 `chart`
*/
import './index.scss' import './index.scss'
import * as echarts from 'echarts/core' // `echarts` 核心模块 import * as echarts from 'echarts/core' // `echarts` 核心模块
@ -24,7 +40,7 @@ import { CanvasRenderer } from 'echarts/renderers' // `echarts` 渲染器
import { useSetting } from '@/store' import { useSetting } from '@/store'
import { cloneDeep, debounce } from 'lodash-es' import { cloneDeep, debounce } from 'lodash-es'
import { on, off, addStyle } from '@/utils/element' import { on, off, addStyle, completeSize } from '@/utils/element'
import type { PropType } from 'vue' import type { PropType } from 'vue'
@ -209,8 +225,8 @@ const RayChart = defineComponent({
const cssVarsRef = computed(() => { const cssVarsRef = computed(() => {
const cssVars = { const cssVars = {
'--ray-chart-width': props.width, '--ray-chart-width': completeSize(props.width),
'--ray-chart-height': props.height, '--ray-chart-height': completeSize(props.height),
} }
return cssVars return cssVars
@ -483,19 +499,3 @@ const RayChart = defineComponent({
}) })
export default RayChart export default RayChart
/**
*
* `echarts` . 便使 `chart`
*
* `chart` , 使, 使 `use`
*
* 预引入: 柱状图, 线, , k线图,
* 预引入: 提示框, , , ,
*
* , `setOption`
*
* ,
*
* 注意: 尽量别一次性倒入全部 `chart`
*/

View File

@ -20,7 +20,6 @@
* `naive ui` * `naive ui`
* *
* : * :
* - 使 `i18n` , `locales` ,
* - * -
*/ */

View File

@ -42,3 +42,12 @@ export const useI18n = (namespace?: string) => {
locale: overrideLocaleFunc, locale: overrideLocaleFunc,
} }
} }
/**
*
* ,
* i18n-ally 使
*
* t path
*/
export const t = <T = unknown>(key: T) => key

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const axios: AppRouteRecordRaw = { const axios: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const axios: AppRouteRecordRaw = {
name: 'Axios', name: 'Axios',
component: () => import('@/views/axios/index'), component: () => import('@/views/axios/index'),
meta: { meta: {
i18nKey: 'Axios', i18nKey: t('menu.Axios'),
icon: 'axios', icon: 'axios',
order: 3, order: 3,
keepAlive: true, keepAlive: true,

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const dashboard: AppRouteRecordRaw = { const dashboard: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const dashboard: AppRouteRecordRaw = {
name: 'Dashboard', name: 'Dashboard',
component: () => import('@/views/dashboard/index'), component: () => import('@/views/dashboard/index'),
meta: { meta: {
i18nKey: 'Dashboard', i18nKey: t('menu.Dashboard'),
icon: 'dashboard', icon: 'dashboard',
order: 0, order: 0,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const docLocal: AppRouteRecordRaw = { const docLocal: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const docLocal: AppRouteRecordRaw = {
name: 'DocLocal', name: 'DocLocal',
component: () => import('@/views/doc/index'), component: () => import('@/views/doc/index'),
meta: { meta: {
i18nKey: 'DocLocal', i18nKey: t('menu.DocLocal'),
icon: 'doc', icon: 'doc',
windowOpen: 'https://ray-template.yunkuangao.com/ray-template-doc/', windowOpen: 'https://ray-template.yunkuangao.com/ray-template-doc/',
order: 6, order: 6,

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const doc: AppRouteRecordRaw = { const doc: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const doc: AppRouteRecordRaw = {
name: 'Doc', name: 'Doc',
component: () => import('@/views/doc/index'), component: () => import('@/views/doc/index'),
meta: { meta: {
i18nKey: 'Doc', i18nKey: t('menu.Doc'),
icon: 'doc', icon: 'doc',
windowOpen: 'https://xiaodaigua-ray.github.io/ray-template-doc/', windowOpen: 'https://xiaodaigua-ray.github.io/ray-template-doc/',
order: 5, order: 5,

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const echart: AppRouteRecordRaw = { const echart: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const echart: AppRouteRecordRaw = {
name: 'Echart', name: 'Echart',
component: () => import('@/views/echart/index'), component: () => import('@/views/echart/index'),
meta: { meta: {
i18nKey: 'Echart', i18nKey: t('menu.Echart'),
icon: 'echart', icon: 'echart',
order: 1, order: 1,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const error: AppRouteRecordRaw = { const error: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const error: AppRouteRecordRaw = {
name: 'ErrorPage', name: 'ErrorPage',
component: () => import('@/error/views/Error404/index'), component: () => import('@/error/views/Error404/index'),
meta: { meta: {
i18nKey: 'Error', i18nKey: t('menu.Error'),
icon: 'error', icon: 'error',
hidden: true, hidden: true,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const iframe: AppRouteRecordRaw = { const iframe: AppRouteRecordRaw = {

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
import { LAYOUT } from '@/router/constant/index' import { LAYOUT } from '@/router/constant/index'
@ -7,7 +9,7 @@ const multiMenu: AppRouteRecordRaw = {
name: 'MultiMenu', name: 'MultiMenu',
component: LAYOUT, component: LAYOUT,
meta: { meta: {
i18nKey: 'MultiMenu', i18nKey: t('menu.MultiMenu'),
icon: 'table', icon: 'table',
order: 4, order: 4,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const office: AppRouteRecordRaw = { const office: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const office: AppRouteRecordRaw = {
name: 'Office', name: 'Office',
component: () => import('@/views/office/index'), component: () => import('@/views/office/index'),
meta: { meta: {
i18nKey: 'Office', i18nKey: t('menu.Office'),
icon: 'office', icon: 'office',
hidden: true, hidden: true,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const precision: AppRouteRecordRaw = { const precision: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const precision: AppRouteRecordRaw = {
name: 'CalculatePrecision', name: 'CalculatePrecision',
component: () => import('@/views/precision/index'), component: () => import('@/views/precision/index'),
meta: { meta: {
i18nKey: 'CalculatePrecision', i18nKey: t('menu.CalculatePrecision'),
icon: 'rely', icon: 'rely',
order: 2, order: 2,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
import { LAYOUT } from '@/router/constant/index' import { LAYOUT } from '@/router/constant/index'
@ -7,7 +9,7 @@ const rely: AppRouteRecordRaw = {
name: 'Rely', name: 'Rely',
component: LAYOUT, component: LAYOUT,
meta: { meta: {
i18nKey: 'Rely', i18nKey: t('menu.Rely'),
icon: 'rely', icon: 'rely',
order: 7, order: 7,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const scrollReveal: AppRouteRecordRaw = { const scrollReveal: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const scrollReveal: AppRouteRecordRaw = {
name: 'ScrollReveal', name: 'ScrollReveal',
component: () => import('@/views/scroll-reveal/index'), component: () => import('@/views/scroll-reveal/index'),
meta: { meta: {
i18nKey: 'scrollReveal', i18nKey: t('menu.scrollReveal'),
icon: 'scroll_reveal', icon: 'scroll_reveal',
hidden: true, hidden: true,
}, },

View File

@ -1,3 +1,5 @@
import { t } from '@/locales/useI18n'
import type { AppRouteRecordRaw } from '@/router/type' import type { AppRouteRecordRaw } from '@/router/type'
const table: AppRouteRecordRaw = { const table: AppRouteRecordRaw = {
@ -5,7 +7,7 @@ const table: AppRouteRecordRaw = {
name: 'TableView', name: 'TableView',
component: () => import('@/views/table/index'), component: () => import('@/views/table/index'),
meta: { meta: {
i18nKey: 'Table', i18nKey: t('menu.Table'),
icon: 'table', icon: 'table',
order: 2, order: 2,
}, },

View File

@ -179,7 +179,7 @@ export const useMenu = defineStore(
/** 设置 label, i18nKey 优先级最高 */ /** 设置 label, i18nKey 优先级最高 */
const label = computed(() => const label = computed(() =>
meta?.i18nKey ? t(`menu.${meta!.i18nKey}`) : meta?.noLocalTitle, meta?.i18nKey ? t(`${meta!.i18nKey}`) : meta?.noLocalTitle,
) )
/** 拼装菜单项 */ /** 拼装菜单项 */
const route = { const route = {