# vue-vite-h5

This template should help get you started developing mobile applications with Vue3 and Typescript and Vant in Vite.

## Project setup

```
yarn install
```

### Compiles and hot-reloads for development

```
yarn start
```

### Compiles and minifies for production

```
yarn build
```

### Lints and fixes files (eslint + prettier)

```
yarn lint
```

### Generate component(page) templates for development

```
yarn generate
```

### Customize configuration

See [Configuration Reference](https://vitejs.dev/config/).

## Browser adaptation

### 目录结构

```
/src/student -- 学生端页面目录
/src/teacher -- 老师端页面目录
/src/views 两端共用页面，路由最好配置到 routes-common 文件中

/src/components -- 公用组件
1、图片上传
2、图片裁切
3、图形验证码
4、协议
5、视频上传

/src/business-components -- 业务组件
1、详情头部
```

### 公用尺寸

1、所有的图片和视频尺寸统一 3:2
2、所有的金额四舍五入保留两位小数, 所有的金额保留 2 位小数，有百分符

### native-message api

<!-- 选择文件 -->

postMessage({ api: 'chooseFile', content: {
type: 'img' | 'video' | 'file' | 'midi' | 'mp3' | 'xml',
max: 1
}}, (res) => {

  <!-- fileUrl。 如果是视频 firstFrameImg -->

})

<!-- 进入直播间 -->

postMessage({ api: 'joinLiveRoom', content: {
roomId: 'xxx',
teacherId: 'xxx'
})

<!-- 进入群聊天 -->

postMessage({
api: 'joinChatGroup',
content: {
type: 'multi', // single 单人 multi 多人
id: item.id,
role: 'STUDENT' || 'TEACHER'
}
})

<!-- 拉起支付 -->

postMessage({
api: 'paymentOrder',
content: {
orderNo: this.orderInfo.orderNo,
payInfo: `alipays://platformapi/startapp?saId=10000007&qrcode=${res.data.pay_info}`
}
})

<!-- 原生导航是否显示 -->

postMessage({api:'setBarStatus',content:{status:1}});

<!-- 原生导航返回样式 -->

postMessage({api:'backIconChange',content:{iconStyle:'black'}});

<!-- 获取原生导航高度 -->

postMessage({ api: 'getNavHeight' })

### 获取某个目录下面的图片对象

export const getAssetsHomeFile = (fileName: string) => {
const path = `../images/${fileName}`
const modules = import.meta.globEager('../images/\*')
return modules[path].default
}

- 需要带上图片后辍
  getAssetsHomeFile('xxx.png')

### Rem Unit (default)

Vant uses `px` unit by default,You can use tools such as `postcss-pxtorem` to transform `px` unit to `rem` unit.

- [postcss-pxtorem](https://github.com/cuth/postcss-pxtorem)
- [lib-flexible](https://github.com/amfe/lib-flexible)

#### PostCSS Config

PostCSS config example:

```js
// .postcssrc.js
module.exports = {
  plugins: {
    'postcss-pxtorem': {
      rootValue: 37.5,
      propList: ['*']
    }
  }
}
```

### Viewport Units

you can use tools such as [postcss--px-to-viewport](https://github.com/evrone/postcss-px-to-viewport) to transform `px` unit to viewport units (vw, vh, vmin, vmax).

#### PostCSS Config

PostCSS config example:

```js
// .postcssrc.js
module.exports = {
  plugins: {
    'postcss-px-to-viewport': {
      viewportWidth: 375
    }
  }
}
```

### Custom rootValue

If the size of the design draft is 750 or other sizes, you can adjust the `rootValue` to:

```js
// .postcssrc.js
module.exports = {
  plugins: {
    // postcss-pxtorem version >= 5.0.0
    'postcss-pxtorem': {
      rootValue({ file }) {
        return file.indexOf('vant') !== -1 ? 37.5 : 75
      },
      propList: ['*']
    }
  }
}
```

## Recommended IDE Setup

- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)

## Type Support For `.vue` Imports in TS

Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's `.vue` type support plugin by running `Volar: Switch TS Plugin on/off` from VSCode command palette.
