Appearance
框架说明
- 使用
VUE3脚手架
进行开发 - 使用
vant ui
UI组件库
H5配置项
- 开启
H5
模式
ts
// src/config/base.ts
export default {
isH5: true
}
H5
其他配置项
ts
// src/config/config.ts
export default {
h5Config: {
showTopNav: true, // 是否显示头部导航
showBottomNav: true, // 是否显示底部导航
openPullRefresh: true, // 是否开启所有页面的下拉刷新功能
}
}
router
相关配置
ts
// src/router/modules/99-demo.ts
import { RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [
{
path: 'demo2',
name: 'Demo2',
meta: {
title: 'demo2',
icon: 'menus-menu',
openPullRefresh: false, // 是否开启本页面的下拉刷新
},
component: () => import('@/views/demo/test2.vue'),
},
];
export default routes;
- 底部导航栏数据跟后台管理系统模式的菜单栏数据保持一致,路由注册并无区别
- 如果需要配置公共页面头部导航信息,可在
src/components/layout/main-h5.vue
文件中进行配置
H5下拉刷新上拉加载组件
- 使用
mescroll.js
插件,官网,具体使用如下 - 默认使用脚手架
src/components/mescroll.vue
该组件(可自行根据实际项目进行调整),具体使用可参考src/views/demo/test3.vue
该页面代码
bash
npm install --save mescroll.js
vue
<template>
<div>
<!--mescroll滚动区域的基本结构-->
<mescroll-vue ref="mescroll" :down="mescrollDown" :up="mescrollUp" @init="mescrollInit">
<!--内容...-->
</mescroll-vue>
</div>
</template>
<script>
// 引入mescroll的vue组件
import MescrollVue from 'mescroll.js/mescroll.vue'
export default {
components: {
MescrollVue // 注册mescroll组件
},
data () {
return {
mescroll: null, // mescroll实例对象
mescrollDown:{}, //下拉刷新的配置. (如果下拉刷新和上拉加载处理的逻辑是一样的,则mescrollDown可不用写了)
mescrollUp: { // 上拉加载的配置.
callback: this.upCallback, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
//以下是一些常用的配置,当然不写也可以的.
page: {
num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
size: 10 //每页数据条数,默认10
},
htmlNodata: '<p class="upwarp-nodata">-- END --</p>',
noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于5才显示无更多数据;
避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
这就是为什么无更多数据有时候不显示的原因
toTop: {
//回到顶部按钮
src: "./static/mescroll/mescroll-totop.png", //图片路径,默认null,支持网络图
offset: 1000 //列表滚动1000px才显示回到顶部按钮
},
empty: {
//列表第一页无任何数据时,显示的空提示布局; 需配置warpId才显示
warpId: "xxid", //父布局的id (1.3.5版本支持传入dom元素)
icon: "./static/mescroll/mescroll-empty.png", //图标,默认null,支持网络图
tip: "暂无相关数据~" //提示
}
},
dataList: [] // 列表数据
}
},
beforeRouteEnter (to, from, next) { // 如果没有配置顶部按钮或isBounce,则beforeRouteEnter不用写
next(vm => {
// 滚动到原来的列表位置,恢复顶部按钮和isBounce的配置
vm.$refs.mescroll && vm.$refs.mescroll.beforeRouteEnter()
})
},
beforeRouteLeave (to, from, next) { // 如果没有配置顶部按钮或isBounce,则beforeRouteLeave不用写
// 记录列表滚动的位置,隐藏顶部按钮和isBounce的配置
this.$refs.mescroll && this.$refs.mescroll.beforeRouteLeave()
next()
},
methods: {
// mescroll组件初始化的回调,可获取到mescroll对象
mescrollInit (mescroll) {
this.mescroll = mescroll // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
},
// 上拉回调 page = {num:1, size:10}; num:当前页 ,默认从1开始; size:每页数据条数,默认10
upCallback (page, mescroll) {
// 联网请求
axios.get('xxxxxx', {
params: {
num: page.num, // 页码
size: page.size // 每页长度
}
}).then((response) => {
// 请求的列表数据
let arr = response.data
// 如果是第一页需手动置空列表
if (page.num === 1) this.dataList = []
// 把请求到的数据添加到列表
this.dataList = this.dataList.concat(arr)
// 数据渲染成功后,隐藏下拉刷新的状态
this.$nextTick(() => {
mescroll.endSuccess(arr.length)
})
}).catch((e) => {
// 联网失败的回调,隐藏下拉刷新和上拉加载的状态;
mescroll.endErr()
})
}
}
}
</script>
<style scoped>
/*通过fixed固定mescroll的高度*/
.mescroll {
position: fixed;
top: 44px;
bottom: 0;
height: auto;
}
</style>
多平台配置
- 使用 vitejs-plugin-config-auto-import 插件
- 新增配置文件,路径:
/src/config/platform-config.ts
,内容如下:
ts
const config = {
// A单位
a: {
bid: 'xxx',
signkey: 'xxx',
sapp_id: 'xxx',
sapp_name: 'xxx',
},
// B单位
b: {
bid: 'xxx',
signkey: 'xxx',
sapp_id: 'xxx',
sapp_name: 'xxx',
},
};
export const currentPlatform = 'a'; // 当前平台的标识
export default config;
- 在
/src/main.ts
中进行注册,内容如下:
ts
import ConfigAutoImport from "vitejs-plugin-config-auto-import"
app.use(ConfigAutoImport)
- 在
/vite.config.ts
中进行配置,内容如下:
ts
import utils from 'wp-utils/vite';
import config, { currentPlatform } from './src/config/platform-config';
import ConfigAutoImport from "vitejs-plugin-config-auto-import/vite"
export default defineConfig({
plugins: [
utils.initZhezhengding({
enable: false,
...config[currentPlatform],
}),
ConfigAutoImport({
globalName: '$platformConfig',
globalActive: currentPlatform,
globalData: config,
})
],
})
- 在
/eslintrc.js
中配置全局校验,内容如下:
ts
module.exports = {
globals: {
$platformConfig: true,
},
}
- 具体的业务层使用如下:
vue
<template>
{{$platformConfig}}
</template>
<script setup lang="ts">
console.log($platformConfig);
</script>