chore: 优化 create-fes-app

This commit is contained in:
winixt 2022-11-20 17:50:16 +08:00
parent d2dab3b136
commit 7649895c77
15 changed files with 134 additions and 113 deletions

View File

@ -14,7 +14,7 @@
"docs:dev": "vuepress dev docs --clean-cache", "docs:dev": "vuepress dev docs --clean-cache",
"docs:build": "vuepress build docs --clean-cache", "docs:build": "vuepress build docs --clean-cache",
"test": "fes test", "test": "fes test",
"lint": "eslint -c ./.eslintrc.js --ext .js,.jsx,.vue,.ts", "lint": "eslint -c ./.eslintrc.js --ignore-pattern='templates' --ext .js,.jsx,.vue,.ts",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
}, },
"license": "MIT", "license": "MIT",
@ -57,7 +57,7 @@
}, },
"lint-staged": { "lint-staged": {
"*.{js,jsx,vue,ts}": [ "*.{js,jsx,vue,ts}": [
"eslint" "npm run lint"
] ]
}, },
"husky": { "husky": {
@ -71,4 +71,4 @@
"path": "./node_modules/cz-conventional-changelog" "path": "./node_modules/cz-conventional-changelog"
} }
} }
} }

View File

@ -1,19 +1,16 @@
module.exports = { module.exports = {
extends: [ extends: ['@webank/eslint-config-webank/vue.js'],
'@webank/eslint-config-webank/vue.js'
],
globals: { globals: {
// 这里填入你的项目需要的全局变量 // 这里填入你的项目需要的全局变量
// 这里值为 false 表示这个全局变量不允许被重新赋值,比如: // 这里值为 false 表示这个全局变量不允许被重新赋值,比如:
// //
// Vue: false // Vue: false
__DEV__: false __DEV__: false,
}, },
rules: { rules: {
'vue/comment-directive': 'off', 'vue/comment-directive': 'off',
'global-require': 'off', 'global-require': 'off',
'import/no-unresolved': 'off', 'import/no-unresolved': 'off',
'no-restricted-syntax': 'off' 'no-restricted-syntax': 'off',
} },
}; };

View File

@ -1,18 +1,18 @@
// fes.config.js 只负责管理 cli 相关的配置 // fes.config.js 只负责管理 cli 相关的配置
import { defineBuildConfig } from '@fesjs/fes';
import pxtoviewport from '@ttou/postcss-px-to-viewport'; import pxtoviewport from '@ttou/postcss-px-to-viewport';
export default defineBuildConfig({
export default {
define: { define: {
// __VUE_OPTIONS_API__: true, // __VUE_OPTIONS_API__: true,
// __VUE_PROD_DEVTOOLS__: false // __VUE_PROD_DEVTOOLS__: false
}, },
html: { html: {
title: '拉夫德鲁' title: '拉夫德鲁',
}, },
targets: { targets: {
chrome: '61', chrome: '61',
ios: '10' ios: '10',
}, },
extraPostCSSPlugins: [ extraPostCSSPlugins: [
pxtoviewport({ pxtoviewport({
@ -28,7 +28,7 @@ export default {
replace: true, replace: true,
exclude: [], exclude: [],
landscape: false, landscape: false,
landscapeUnit: 'vw' landscapeUnit: 'vw',
}) }),
] ],
}; });

View File

@ -44,12 +44,12 @@
"@ttou/postcss-px-to-viewport": "1.1.1" "@ttou/postcss-px-to-viewport": "1.1.1"
}, },
"dependencies": { "dependencies": {
"@fesjs/fes": "^3.0.0-rc.0", "@fesjs/fes": "^3.0.0-rc.1",
"@fesjs/plugin-icon": "^3.0.0-rc.0", "@fesjs/plugin-icon": "^3.0.0-rc.0",
"@fesjs/plugin-request": "^3.0.0-rc.0", "@fesjs/plugin-request": "^3.0.0-rc.3",
"@fesjs/builder-webpack": "^3.0.0-rc.0", "@fesjs/builder-webpack": "^3.0.0-rc.1",
"vue": "^3.2.37", "vue": "^3.2.37",
"core-js": "^3.19.2" "core-js": "^3.26.1"
}, },
"private": true "private": true
} }

View File

@ -1,7 +1,44 @@
export const request = { import { defineRuntimeConfig } from '@fesjs/fes';
errorConfig: {
404() { export default defineRuntimeConfig({
console.log('to 404 page'); request: {
// API 前缀
baseURL: '',
dataHandler(data, response) {
// 处理响应内容异常
if (data.code !== '0') {
if (data.code === '20000') {
console.log('hello world');
}
throw new Error(response);
}
// 响应数据格式化
return data?.result ? data.result : data;
}, },
// http 异常,和插件异常
errorHandler(error) {
if (error.response) {
// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// 请求已经成功发起,但没有收到响应
// `error.request` 在浏览器中是 XMLHttpRequest 的实例,
// 而在node.js中是 http.ClientRequest 的实例
console.log(error.request);
} else if (error.type) {
// 插件异常
console.log(error.msg);
} else {
// 发送请求时出了点问题
console.log('Error', error.message);
}
console.log(error.config);
},
// 请求拦截器
requestInterceptors: [],
// 响应拦截器
responseInterceptors: [],
}, },
}; });

View File

@ -4,7 +4,6 @@
// 手机号、身份证号 等的校验 // 手机号、身份证号 等的校验
// 数字分割 // 数字分割
export function resetContainerHeight(dom) { export function resetContainerHeight(dom) {
const originalHeight = document.body.clientHeight || document.documentElement.clientHeight; const originalHeight = document.body.clientHeight || document.documentElement.clientHeight;
@ -18,12 +17,11 @@ export function resetContainerHeight(dom) {
}; };
} }
export function resetInputBlur() { export function resetInputBlur() {
const isWechat = window.navigator.userAgent.match(/MicroMessenger\/([\d.]+)/i); const isWechat = window.navigator.userAgent.match(/MicroMessenger\/([\d.]+)/i);
if (!isWechat) return; if (!isWechat) return;
const wechatVersion = isWechat[1]; const wechatVersion = isWechat[1];
const version = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); const version = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
// 如果设备类型为iOS 12+ 和wechat 6.7.4+,恢复成原来的视口 // 如果设备类型为iOS 12+ 和wechat 6.7.4+,恢复成原来的视口
if (+wechatVersion.replace(/\./g, '') >= 674 && +version[1] >= 12) { if (+wechatVersion.replace(/\./g, '') >= 674 && +version[1] >= 12) {

View File

@ -1,4 +0,0 @@
<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 1024 1024">
<path d="M288 421a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm352 0a48 48 0 1 0 96 0 48 48 0 1 0-96 0zM512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm263 711c-34.2 34.2-74 61-118.3 79.8C611 874.2 562.3 884 512 884c-50.3 0-99-9.8-144.8-29.2A370.4 370.4 0 0 1 248.9 775c-34.2-34.2-61-74-79.8-118.3C149.8 611 140 562.3 140 512s9.8-99 29.2-144.8A370.4 370.4 0 0 1 249 248.9c34.2-34.2 74-61 118.3-79.8C413 149.8 461.7 140 512 140c50.3 0 99 9.8 144.8 29.2A370.4 370.4 0 0 1 775.1 249c34.2 34.2 61 74 79.8 118.3C874.2 413 884 461.7 884 512s-9.8 99-29.2 144.8A368.89 368.89 0 0 1 775 775zM664 533h-48.1c-4.2 0-7.8 3.2-8.1 7.4C604 589.9 562.5 629 512 629s-92.1-39.1-95.8-88.6c-.3-4.2-3.9-7.4-8.1-7.4H360a8 8 0 0 0-8 8.4c4.4 84.3 74.5 151.6 160 151.6s155.6-67.3 160-151.6a8 8 0 0 0-8-8.4z"/>
</svg>

Before

Width:  |  Height:  |  Size: 936 B

View File

@ -3,18 +3,16 @@
fes & 拉夫德鲁 <br /> fes & 拉夫德鲁 <br />
<fes-icon :spin="true" class="one-icon" type="smile" @click="clickIcon" /> <fes-icon :spin="true" class="one-icon" type="smile" @click="clickIcon" />
<div v-if="loading" class="loading">loading</div> <div v-if="loading" class="loading">loading</div>
<div v-else class="data">{{data}}</div> <div v-else class="data">{{ data }}</div>
</div> </div>
</template> </template>
<config>
{
"title": "首页",
"layout": "false"
}
</config>
<script> <script>
import { ref, onMounted } from 'vue'; import { ref, onMounted } from 'vue';
import { useRouter, useRequest } from '@fesjs/fes'; import { useRouter, useRequest, defineRouteMeta } from '@fesjs/fes';
defineRouteMeta({
title: '首页',
});
export default { export default {
setup() { setup() {
@ -34,15 +32,15 @@ export default {
data, data,
fes, fes,
rotate, rotate,
clickIcon clickIcon,
}; };
} },
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@import "~@/styles/mixins/hairline"; @import '~@/styles/mixins/hairline';
@import "~@/styles/mixins/hover"; @import '~@/styles/mixins/hover';
div { div {
padding: 20px; padding: 20px;
@ -56,7 +54,7 @@ div {
.hover(); .hover();
} }
.onepiece { .onepiece {
.hairline("top"); .hairline('top');
background: url('../images/male.png'); background: url('../images/male.png');
} }
</style> </style>

View File

@ -1,21 +1,20 @@
<template> <template>
<div>{{fes}}</div> <div>{{ fes }}</div>
</template> </template>
<config>
{
"title": "onepiece",
"layout": "true"
}
</config>
<script> <script>
import { defineRouteMeta } from '@fesjs/fes';
import { ref } from 'vue'; import { ref } from 'vue';
defineRouteMeta({
title: 'one piece',
});
export default { export default {
setup() { setup() {
const fes = ref('fes upgrade to vue3'); const fes = ref('fes upgrade to vue3');
return { return {
fes fes,
}; };
} },
}; };
</script> </script>

View File

@ -1,23 +1,27 @@
// .fes.js 只负责管理编译时配置只能使用plain Object import { defineBuildConfig } from '@fesjs/fes';
export default defineBuildConfig({
export default {
access: { access: {
roles: { roles: {
admin: ["*"], admin: ['*'],
manager: ["/"] manager: ['/'],
} },
}, },
layout: { layout: {
title: "Fes.js", title: 'Fes.js',
footer: 'Created by MumbleFE', footer: 'Created by MumbleFE',
navigation: 'mixin', navigation: 'mixin',
multiTabs: false, multiTabs: false,
menus: [{ menus: [
name: 'index' {
}] name: 'index',
},
],
}, },
enums: { enums: {
status: [['0', '无效的'], ['1', '有效的']] status: [
} ['0', '无效的'],
}; ['1', '有效的'],
],
},
});

View File

@ -1,6 +1,5 @@
// .fes.js 只负责管理编译时配置只能使用plain Object import { defineBuildConfig } from '@fesjs/fes';
export default defineBuildConfig({
export default { publicPath: './',
publicPath: './' });
};

View File

@ -51,10 +51,10 @@
"@fesjs/plugin-layout": "^5.0.0-rc.0", "@fesjs/plugin-layout": "^5.0.0-rc.0",
"@fesjs/plugin-model": "^3.0.0-rc.0", "@fesjs/plugin-model": "^3.0.0-rc.0",
"@fesjs/plugin-enums": "^3.0.0-rc.0", "@fesjs/plugin-enums": "^3.0.0-rc.0",
"@fesjs/fes-design": "^0.7.0", "@fesjs/fes-design": "^0.7.9",
"@fesjs/builder-webpack": "^3.0.0-rc.0", "@fesjs/builder-webpack": "^3.0.0-rc.0",
"vue": "^3.2.37", "vue": "^3.2.45",
"core-js": "^3.19.2" "core-js": "^3.26.1"
}, },
"private": true "private": true
} }

View File

@ -1,23 +1,25 @@
import { access } from '@fesjs/fes'; import { access, defineRuntimeConfig } from '@fesjs/fes';
import PageLoading from '@/components/pageLoading.vue'; import PageLoading from '@/components/pageLoading.vue';
import UserCenter from '@/components/userCenter.vue'; import UserCenter from '@/components/userCenter.vue';
export const beforeRender = { export default defineRuntimeConfig({
loading: <PageLoading />, beforeRender: {
action() { loading: <PageLoading />,
const { setRole } = access; action() {
return new Promise((resolve) => { const { setRole } = access;
setTimeout(() => { return new Promise((resolve) => {
setRole('admin'); setTimeout(() => {
// useModel('@@initialState') @/components/UserCenter setRole('admin');
resolve({ // useModel('@@initialState') @/components/UserCenter
userName: '李雷', resolve({
}); userName: '李雷',
}, 1000); });
}); }, 1000);
});
},
}, },
}; layout: {
renderCustom: () => <UserCenter />,
export const layout = { },
customHeader: <UserCenter />, });
};

View File

@ -1,21 +1,12 @@
<template> <template>
<div style="padding: 32px;"> <div style="padding: 32px">hello world</div>
hello world
</div>
</template> </template>
<script> <script setup>
export default { import { defineRouteMeta } from '@fesjs/fes';
setup() {
return {
};
}
};
</script>
<config> defineRouteMeta({
{ name: 'index',
"name": "index", title: '首页',
"title": "首页" });
} </script>
</config>