From 7649895c778c4c191e9398d7d7d7726cb5c1b0e7 Mon Sep 17 00:00:00 2001 From: winixt Date: Sun, 20 Nov 2022 17:50:16 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=20create-fes-app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 +-- .../templates/app/h5/.eslintrc.js | 11 ++--- .../create-fes-app/templates/app/h5/.fes.js | 16 +++---- .../templates/app/h5/package.json | 8 ++-- .../templates/app/h5/src/app.js | 47 +++++++++++++++++-- .../templates/app/h5/src/common/utils.js | 4 +- .../templates/app/h5/src/icons/hello.svg | 4 -- .../templates/app/h5/src/models/user.js | 0 .../templates/app/h5/src/pages/index.vue | 24 +++++----- .../templates/app/h5/src/pages/onepiece.vue | 17 ++++--- .../create-fes-app/templates/app/pc/.fes.js | 30 +++++++----- .../templates/app/pc/.fes.prod.js | 9 ++-- .../templates/app/pc/package.json | 6 +-- .../templates/app/pc/src/app.jsx | 40 ++++++++-------- .../templates/app/pc/src/pages/index.vue | 25 ++++------ 15 files changed, 134 insertions(+), 113 deletions(-) delete mode 100644 packages/create-fes-app/templates/app/h5/src/icons/hello.svg delete mode 100644 packages/create-fes-app/templates/app/h5/src/models/user.js diff --git a/package.json b/package.json index 1b357cff..691717da 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "docs:dev": "vuepress dev docs --clean-cache", "docs:build": "vuepress build docs --clean-cache", "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" }, "license": "MIT", @@ -57,7 +57,7 @@ }, "lint-staged": { "*.{js,jsx,vue,ts}": [ - "eslint" + "npm run lint" ] }, "husky": { @@ -71,4 +71,4 @@ "path": "./node_modules/cz-conventional-changelog" } } -} +} \ No newline at end of file diff --git a/packages/create-fes-app/templates/app/h5/.eslintrc.js b/packages/create-fes-app/templates/app/h5/.eslintrc.js index 74c6bf29..9847c436 100644 --- a/packages/create-fes-app/templates/app/h5/.eslintrc.js +++ b/packages/create-fes-app/templates/app/h5/.eslintrc.js @@ -1,19 +1,16 @@ - module.exports = { - extends: [ - '@webank/eslint-config-webank/vue.js' - ], + extends: ['@webank/eslint-config-webank/vue.js'], globals: { // 这里填入你的项目需要的全局变量 // 这里值为 false 表示这个全局变量不允许被重新赋值,比如: // // Vue: false - __DEV__: false + __DEV__: false, }, rules: { 'vue/comment-directive': 'off', 'global-require': 'off', 'import/no-unresolved': 'off', - 'no-restricted-syntax': 'off' - } + 'no-restricted-syntax': 'off', + }, }; diff --git a/packages/create-fes-app/templates/app/h5/.fes.js b/packages/create-fes-app/templates/app/h5/.fes.js index 6b90b7d6..c8fd19f6 100644 --- a/packages/create-fes-app/templates/app/h5/.fes.js +++ b/packages/create-fes-app/templates/app/h5/.fes.js @@ -1,18 +1,18 @@ // fes.config.js 只负责管理 cli 相关的配置 +import { defineBuildConfig } from '@fesjs/fes'; import pxtoviewport from '@ttou/postcss-px-to-viewport'; - -export default { +export default defineBuildConfig({ define: { // __VUE_OPTIONS_API__: true, // __VUE_PROD_DEVTOOLS__: false }, html: { - title: '拉夫德鲁' + title: '拉夫德鲁', }, targets: { chrome: '61', - ios: '10' + ios: '10', }, extraPostCSSPlugins: [ pxtoviewport({ @@ -28,7 +28,7 @@ export default { replace: true, exclude: [], landscape: false, - landscapeUnit: 'vw' - }) - ] -}; + landscapeUnit: 'vw', + }), + ], +}); diff --git a/packages/create-fes-app/templates/app/h5/package.json b/packages/create-fes-app/templates/app/h5/package.json index 4a0cbb5e..dbe6dd11 100644 --- a/packages/create-fes-app/templates/app/h5/package.json +++ b/packages/create-fes-app/templates/app/h5/package.json @@ -44,12 +44,12 @@ "@ttou/postcss-px-to-viewport": "1.1.1" }, "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-request": "^3.0.0-rc.0", - "@fesjs/builder-webpack": "^3.0.0-rc.0", + "@fesjs/plugin-request": "^3.0.0-rc.3", + "@fesjs/builder-webpack": "^3.0.0-rc.1", "vue": "^3.2.37", - "core-js": "^3.19.2" + "core-js": "^3.26.1" }, "private": true } \ No newline at end of file diff --git a/packages/create-fes-app/templates/app/h5/src/app.js b/packages/create-fes-app/templates/app/h5/src/app.js index d508ce12..fb0e2fd9 100644 --- a/packages/create-fes-app/templates/app/h5/src/app.js +++ b/packages/create-fes-app/templates/app/h5/src/app.js @@ -1,7 +1,44 @@ -export const request = { - errorConfig: { - 404() { - console.log('to 404 page'); +import { defineRuntimeConfig } from '@fesjs/fes'; + +export default defineRuntimeConfig({ + 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: [], }, -}; +}); diff --git a/packages/create-fes-app/templates/app/h5/src/common/utils.js b/packages/create-fes-app/templates/app/h5/src/common/utils.js index 97d6e99c..27bf8a19 100644 --- a/packages/create-fes-app/templates/app/h5/src/common/utils.js +++ b/packages/create-fes-app/templates/app/h5/src/common/utils.js @@ -4,7 +4,6 @@ // 手机号、身份证号 等的校验 // 数字分割 - export function resetContainerHeight(dom) { const originalHeight = document.body.clientHeight || document.documentElement.clientHeight; @@ -18,12 +17,11 @@ export function resetContainerHeight(dom) { }; } - export function resetInputBlur() { const isWechat = window.navigator.userAgent.match(/MicroMessenger\/([\d.]+)/i); if (!isWechat) return; 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+,恢复成原来的视口 if (+wechatVersion.replace(/\./g, '') >= 674 && +version[1] >= 12) { diff --git a/packages/create-fes-app/templates/app/h5/src/icons/hello.svg b/packages/create-fes-app/templates/app/h5/src/icons/hello.svg deleted file mode 100644 index a382e266..00000000 --- a/packages/create-fes-app/templates/app/h5/src/icons/hello.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/packages/create-fes-app/templates/app/h5/src/models/user.js b/packages/create-fes-app/templates/app/h5/src/models/user.js deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/create-fes-app/templates/app/h5/src/pages/index.vue b/packages/create-fes-app/templates/app/h5/src/pages/index.vue index 75098745..5b275aa0 100644 --- a/packages/create-fes-app/templates/app/h5/src/pages/index.vue +++ b/packages/create-fes-app/templates/app/h5/src/pages/index.vue @@ -3,18 +3,16 @@ fes & 拉夫德鲁
loading
-
{{data}}
+
{{ data }}
- -{ - "title": "首页", - "layout": "false" -} - diff --git a/packages/create-fes-app/templates/app/h5/src/pages/onepiece.vue b/packages/create-fes-app/templates/app/h5/src/pages/onepiece.vue index 3df0594e..d431b44d 100644 --- a/packages/create-fes-app/templates/app/h5/src/pages/onepiece.vue +++ b/packages/create-fes-app/templates/app/h5/src/pages/onepiece.vue @@ -1,21 +1,20 @@ - -{ - "title": "onepiece", - "layout": "true" -} - diff --git a/packages/create-fes-app/templates/app/pc/.fes.js b/packages/create-fes-app/templates/app/pc/.fes.js index 517a4880..ac710753 100644 --- a/packages/create-fes-app/templates/app/pc/.fes.js +++ b/packages/create-fes-app/templates/app/pc/.fes.js @@ -1,23 +1,27 @@ -// .fes.js 只负责管理编译时配置,只能使用plain Object +import { defineBuildConfig } from '@fesjs/fes'; - -export default { +export default defineBuildConfig({ access: { roles: { - admin: ["*"], - manager: ["/"] - } + admin: ['*'], + manager: ['/'], + }, }, layout: { - title: "Fes.js", + title: 'Fes.js', footer: 'Created by MumbleFE', navigation: 'mixin', multiTabs: false, - menus: [{ - name: 'index' - }] + menus: [ + { + name: 'index', + }, + ], }, enums: { - status: [['0', '无效的'], ['1', '有效的']] - } -}; + status: [ + ['0', '无效的'], + ['1', '有效的'], + ], + }, +}); diff --git a/packages/create-fes-app/templates/app/pc/.fes.prod.js b/packages/create-fes-app/templates/app/pc/.fes.prod.js index b784e9ae..41c58644 100644 --- a/packages/create-fes-app/templates/app/pc/.fes.prod.js +++ b/packages/create-fes-app/templates/app/pc/.fes.prod.js @@ -1,6 +1,5 @@ -// .fes.js 只负责管理编译时配置,只能使用plain Object +import { defineBuildConfig } from '@fesjs/fes'; - -export default { - publicPath: './' -}; +export default defineBuildConfig({ + publicPath: './', +}); diff --git a/packages/create-fes-app/templates/app/pc/package.json b/packages/create-fes-app/templates/app/pc/package.json index e7bfd228..28ac9f23 100644 --- a/packages/create-fes-app/templates/app/pc/package.json +++ b/packages/create-fes-app/templates/app/pc/package.json @@ -51,10 +51,10 @@ "@fesjs/plugin-layout": "^5.0.0-rc.0", "@fesjs/plugin-model": "^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", - "vue": "^3.2.37", - "core-js": "^3.19.2" + "vue": "^3.2.45", + "core-js": "^3.26.1" }, "private": true } \ No newline at end of file diff --git a/packages/create-fes-app/templates/app/pc/src/app.jsx b/packages/create-fes-app/templates/app/pc/src/app.jsx index 4c95b9f9..e6c27f4d 100644 --- a/packages/create-fes-app/templates/app/pc/src/app.jsx +++ b/packages/create-fes-app/templates/app/pc/src/app.jsx @@ -1,23 +1,25 @@ -import { access } from '@fesjs/fes'; +import { access, defineRuntimeConfig } from '@fesjs/fes'; + import PageLoading from '@/components/pageLoading.vue'; import UserCenter from '@/components/userCenter.vue'; -export const beforeRender = { - loading: , - action() { - const { setRole } = access; - return new Promise((resolve) => { - setTimeout(() => { - setRole('admin'); - // 初始化应用的全局状态,可以通过 useModel('@@initialState') 获取,具体用法看@/components/UserCenter 文件 - resolve({ - userName: '李雷', - }); - }, 1000); - }); +export default defineRuntimeConfig({ + beforeRender: { + loading: , + action() { + const { setRole } = access; + return new Promise((resolve) => { + setTimeout(() => { + setRole('admin'); + // 初始化应用的全局状态,可以通过 useModel('@@initialState') 获取,具体用法看@/components/UserCenter 文件 + resolve({ + userName: '李雷', + }); + }, 1000); + }); + }, }, -}; - -export const layout = { - customHeader: , -}; + layout: { + renderCustom: () => , + }, +}); diff --git a/packages/create-fes-app/templates/app/pc/src/pages/index.vue b/packages/create-fes-app/templates/app/pc/src/pages/index.vue index 4cab0d6c..50e20b7a 100644 --- a/packages/create-fes-app/templates/app/pc/src/pages/index.vue +++ b/packages/create-fes-app/templates/app/pc/src/pages/index.vue @@ -1,21 +1,12 @@ - +