增加前端页面

master
yutent 2024-01-04 15:37:42 +08:00
parent c062258901
commit e4c4e4c655
17 changed files with 320 additions and 25 deletions

11
.prettierrc.yaml Normal file
View File

@ -0,0 +1,11 @@
jsxBracketSameLine: true
jsxSingleQuote: true
semi: false
singleQuote: true
printWidth: 80
useTabs: false
tabWidth: 2
trailingComma: none
bracketSpacing: true
arrowParens: avoid

5
.vscode/launch.json vendored
View File

@ -7,10 +7,7 @@
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"args": ["."]
"args": [".", "--NODE_ENV=development"]
}
]
}

44
front-end/fite.config.js Normal file
View File

@ -0,0 +1,44 @@
import { resolve } from 'path'
export default {
// 用于配置部署目录, 默认为根目录, 如果需要部署到二级目录的话,
// 请取消以下注释, 并填写你最终需要部署的二级目录名, 必须以 / 开头及结尾。如: '/foo/'
// base: '/',
devServer: {
port: 26666,
domain: '',
https: false,
ssl: {
key: '',
cert: ''
// ca: '' //可选
}
},
// 如果多页应用, 则这里写传入多个值即可(注意不是数组格式)
pages: {
// 这里的key值, 将是最终的页面的名称
index: {
// 这里的resolve可将相对路径转为绝对路径
// 如果传入的路径已经是绝对路径的, 可不需要resolve
entry: resolve('./src/main.js'),
title: 'fite-app 应用示例'
}
},
inject: {
// v1.0.1之后, 可以注入一个scss, 所有的vue文件中的样式都会被注入这个公共scss
// 注意: 该文件不支持热更新, 不可被vue/js文件引用 (但可以被其他的scss文件引用)
scss: resolve('./src/inject.scss')
},
// 以下cdn地址, 可自行修改为适合的
// 有用到其他的库, 可以手动添加,
// 也可以在页面中直接引入完整的路径, 而不必须在这里声明
imports: {
vue: '//jscdn.ink/vue/3.2.47/vue.runtime.esm-browser.prod.js',
// 这个vue-router库, 移除了 @vue/devtools-api 相关的代码。 以达到减少不必须的体积的效果
// 如需要支持devtools的, 请修改为原版vue-router地址即可。
'vue-router': '//jscdn.ink/@bytedo/vue-router/4.1.6/vue-router.js',
// 'vue-router': '//jscdn.ink/vue-router/4.1.6/vue-router.esm-browser.js',
// '@vue/devtools-api': '//jscdn.ink/@vue/devtools-api/6.5.0/esm/index.js',
fetch: '//jscdn.ink/@bytedo/fetch/2.1.5/next.js'
}
}

21
front-end/index.html Normal file
View File

@ -0,0 +1,21 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>{{title}}</title>
<meta name="keywords" content="{{keywords}}">
<meta name="description" content="{{description}}">
<link rel="stylesheet" href="//jscdn.ink/@bd/ui/latest/css/reset-basic.css">
<script async src="//jscdn.ink/es-module-shims/latest/es-module-shims.wasm.js"></script>
<script type="importmap">{{importmap}}</script>
{{#if process.env.NODE_ENV === 'development' }}
<!-- todo... -->
{{#/if}}
</head>
<body>
<div id="app"></div>
<script src="main.js"></script>
</body>
</html>

14
front-end/package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "fite-app",
"type": "module",
"scripts": {
"start": "fite dev",
"build": "fite build",
"build:keep": "fite build --no-clean"
},
"devDependencies": {
"fite": "^1.2.0"
}
}

83
front-end/src/app.vue Normal file
View File

@ -0,0 +1,83 @@
<template>
<header>
<img
alt="Vue logo"
class="logo"
src="/assets/logo.svg"
width="125"
height="125"
/>
<div class="wrapper">
<Hello msg="It works!!!" />
<nav>
<router-link to="/">Home</router-link>
<router-link to="/about">About</router-link>
</nav>
</div>
</header>
<router-view v-slot="{ Component }">
<keep-alive>
<component :is="Component" />
</keep-alive>
</router-view>
</template>
<script>
import Hello from './components/hello.vue'
export default {
components: { Hello }
}
</script>
<style>
#app {
padding: 32px;
}
</style>
<style lang="scss" scoped>
header {
display: flex;
flex-direction: column;
align-items: center;
}
a {
color: var(--color-teal-1);
transition: 0.2s;
}
a:hover {
color: var(--color-teal-3);
}
nav {
margin-top: 32px;
display: flex;
justify-content: center;
a {
margin: 0 16px;
color: var(--color-dark-1);
}
.router-link-active {
text-decoration: none;
color: var(--color-teal-1);
cursor: default;
}
}
main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 32px;
text-align: center;
}
</style>

View File

@ -0,0 +1 @@
<svg viewBox="0 0 261.76 226.69" xmlns="http://www.w3.org/2000/svg"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/><path d="M36.21 192.639l160.921-74.805-81.778-5.063 119.519-67.69L49.06 126.138l88.8 2.712z" fill="rgb(252, 118, 97)"/></svg>

After

Width:  |  Height:  |  Size: 394 B

View File

@ -0,0 +1,52 @@
<template>
<div class="greetings">
<h1 class="green">{{ msg }}</h1>
<h3>
你已经成功运行了一个项目, 项目基于
<a href="//github.com/bytedo/vue-live" target="_blank">
<img
:src="`https://img.shields.io/badge/fite-${$store.version}-red?style=flat-square`"
alt="fite"
/>
</a>
+
<a href="//vuejs.org" target="_blank">
<img
src="https://img.shields.io/badge/vue-3.2.47-teal?style=flat-square"
alt="fite"
/>
</a>
</h3>
</div>
</template>
<script>
export default {
props: {
msg: String
}
}
</script>
<style lang="scss" scoped>
.greetings {
text-align: center;
}
h1 {
font-size: 52px;
font-family: 'Courier New', Courier, monospace;
color: var(--color-blue-1);
}
h3 {
display: flex;
align-items: center;
font-size: 1.2rem;
font-weight: normal;
a {
display: inline-flex;
margin: 0 4px;
}
}
</style>

7
front-end/src/main.js Normal file
View File

@ -0,0 +1,7 @@
import { createApp } from 'vue'
import App from './app.vue'
import router from './router'
import store from './store'
createApp(App).use(router).use(store).mount('#app')

23
front-end/src/router.js Normal file
View File

@ -0,0 +1,23 @@
import { createRouter, createWebHistory } from 'vue-router'
import Home from './views/home.vue'
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: () => import('./views/about.vue')
}
]
})
export default router

11
front-end/src/store.js Normal file
View File

@ -0,0 +1,11 @@
import { reactive } from 'vue'
const store = reactive({
foo: 'bar',
version: '1.2.0'
})
export default function (app) {
app.config.globalProperties.$store = store
}

View File

@ -0,0 +1,27 @@
<template>
<main>
<h1>{{ content }}</h1>
<cite
>fite是一种不算新型前端构建工具能够显著提升前端开发体验基于原生ESM模块运行
fite的理念是, 让第三方依赖全部走CDN, fite只处理业务代码本身,
从而让编译和构建的速度达到今人发指的地步比vite快十几到几十倍</cite
>
</main>
</template>
<script>
export default {
data() {
return {
content: '这是关于我们页面'
}
}
}
</script>
<style scoped>
cite {
width: 600px;
color: var(--color-grey-3);
}
</style>

View File

@ -0,0 +1,17 @@
<script>
export default {
data() {
return {
content: '欢迎访问~~ 这是首页',
now: ~~performance.now()
}
}
}
</script>
<template>
<main>
<h1>{{ content }}</h1>
<section>页面渲染完成时间: {{ now }}ms</section>
</main>
</template>

View File

@ -4,8 +4,6 @@
"description": "MySQL/MariaDB database management for Linux",
"main": "src/main.js",
"scripts": {
"preinstall": "source .npmrc",
"start": "electron .",
"pack": "electron-builder --linux"
},
"author": {

View File

@ -1,15 +0,0 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Examples</title>
<meta name="keywords" content="">
<meta name="description" content="">
<link href="" rel="stylesheet">
</head>
<body>
<h1>It works!</h1>
</body>
</html>

View File

@ -45,9 +45,9 @@ protocol.registerSchemesAsPrivileged([
app.once('ready', () => {
// 注册协议
protocol.registerStreamProtocol('app', function (req, cb) {
var file = decodeURIComponent(req.url.replace(/^app:\/\/local\//, ''))
var ext = path.extname(req.url)
file = path.resolve(__dirname, file)
let file = decodeURIComponent(req.url.replace(/^app:\/\/local\//, ''))
let ext = path.extname(req.url)
file = path.resolve(__dirname, 'dist/', file)
cb({
data: fs.origin.createReadStream(file),

View File

@ -32,7 +32,11 @@ exports.createMainWindow = function (icon) {
// 然后加载应用的 index.html。
win.loadURL('app://local/index.html')
win.loadURL(
process.argv.includes('--NODE_ENV=development')
? 'http://127.0.0.1:26666'
: 'app://local/index.html'
)
win.on('ready-to-show', _ => {
win.show()