连接数据库,测试接口

This commit is contained in:
expressgy 2025-04-23 23:50:30 +08:00
parent 59236fbbe9
commit bed2d0c643
18 changed files with 551 additions and 102 deletions

View File

@ -24,6 +24,7 @@
/*字体颜色*/
--color-text: #333;
--bg-opacity: 0.5;
--header-bg-color: #dddddd99;
/*主要着重颜色*/
--main-strong-color: #333;

View File

@ -57,9 +57,15 @@
<ul class="icon_lists dib-box">
<li class="dib">
<span class="icon starIconFont">&#xe617;</span>
<div class="name">纸飞机</div>
<div class="code-name">&amp;#xe617;</div>
<span class="icon starIconFont">&#xe69f;</span>
<div class="name">tools</div>
<div class="code-name">&amp;#xe69f;</div>
</li>
<li class="dib">
<span class="icon starIconFont">&#xe9a2;</span>
<div class="name">rcd-home-f-copy</div>
<div class="code-name">&amp;#xe9a2;</div>
</li>
<li class="dib">
@ -74,12 +80,6 @@
<div class="code-name">&amp;#xe802;</div>
</li>
<li class="dib">
<span class="icon starIconFont">&#xe606;</span>
<div class="name">羽毛笔</div>
<div class="code-name">&amp;#xe606;</div>
</li>
<li class="dib">
<span class="icon starIconFont">&#xe9a1;</span>
<div class="name">羽毛笔-copy</div>
@ -116,12 +116,6 @@
<div class="code-name">&amp;#xe6cc;</div>
</li>
<li class="dib">
<span class="icon starIconFont">&#xe6bc;</span>
<div class="name">阅读</div>
<div class="code-name">&amp;#xe6bc;</div>
</li>
<li class="dib">
<span class="icon starIconFont">&#xe760;</span>
<div class="name">叶子</div>
@ -243,9 +237,9 @@
>@font-face {
font-family: 'starIconFont';
src:
url('iconfont.woff2?t=1745328881235') format('woff2'),
url('iconfont.woff?t=1745328881235') format('woff'),
url('iconfont.ttf?t=1745328881235') format('truetype');
url('iconfont.woff2?t=1745398567721') format('woff2'),
url('iconfont.woff?t=1745398567721') format('woff'),
url('iconfont.ttf?t=1745398567721') format('truetype');
}
</code></pre>
<h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3>
@ -272,11 +266,20 @@
<ul class="icon_lists dib-box">
<li class="dib">
<span class="icon starIconFont star-zhifeiji"></span>
<span class="icon starIconFont star-tools"></span>
<div class="name">
纸飞机
tools
</div>
<div class="code-name">.star-zhifeiji
<div class="code-name">.star-tools
</div>
</li>
<li class="dib">
<span class="icon starIconFont star-rcd-home-f-copy"></span>
<div class="name">
rcd-home-f-copy
</div>
<div class="code-name">.star-rcd-home-f-copy
</div>
</li>
@ -298,15 +301,6 @@
</div>
</li>
<li class="dib">
<span class="icon starIconFont star-yumaobi"></span>
<div class="name">
羽毛笔
</div>
<div class="code-name">.star-yumaobi
</div>
</li>
<li class="dib">
<span class="icon starIconFont star-yumaobi-copy"></span>
<div class="name">
@ -361,15 +355,6 @@
</div>
</li>
<li class="dib">
<span class="icon starIconFont star-yuedu1"></span>
<div class="name">
阅读
</div>
<div class="code-name">.star-yuedu1
</div>
</li>
<li class="dib">
<span class="icon starIconFont star-yezi"></span>
<div class="name">
@ -552,10 +537,18 @@
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#star-zhifeiji"></use>
<use xlink:href="#star-tools"></use>
</svg>
<div class="name">纸飞机</div>
<div class="code-name">#star-zhifeiji</div>
<div class="name">tools</div>
<div class="code-name">#star-tools</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#star-rcd-home-f-copy"></use>
</svg>
<div class="name">rcd-home-f-copy</div>
<div class="code-name">#star-rcd-home-f-copy</div>
</li>
<li class="dib">
@ -574,14 +567,6 @@
<div class="code-name">#star-shijie</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#star-yumaobi"></use>
</svg>
<div class="name">羽毛笔</div>
<div class="code-name">#star-yumaobi</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#star-yumaobi-copy"></use>
@ -630,14 +615,6 @@
<div class="code-name">#star-yueliang</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#star-yuedu1"></use>
</svg>
<div class="name">阅读</div>
<div class="code-name">#star-yuedu1</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#star-yezi"></use>

View File

@ -2,9 +2,9 @@
font-family: "starIconFont"; /* Project id 4902296 */
/* Color fonts */
src:
url('iconfont.woff2?t=1745328881235') format('woff2'),
url('iconfont.woff?t=1745328881235') format('woff'),
url('iconfont.ttf?t=1745328881235') format('truetype');
url('iconfont.woff2?t=1745398567721') format('woff2'),
url('iconfont.woff?t=1745398567721') format('woff'),
url('iconfont.ttf?t=1745398567721') format('truetype');
}
.starIconFont {
@ -15,8 +15,12 @@
-moz-osx-font-smoothing: grayscale;
}
.star-zhifeiji:before {
content: "\e617";
.star-tools:before {
content: "\e69f";
}
.star-rcd-home-f-copy:before {
content: "\e9a2";
}
.star-zhifeiji-copy:before {
@ -27,10 +31,6 @@
content: "\e802";
}
.star-yumaobi:before {
content: "\e606";
}
.star-yumaobi-copy:before {
content: "\e9a1";
}
@ -55,10 +55,6 @@
content: "\e6cc";
}
.star-yuedu1:before {
content: "\e6bc";
}
.star-yezi:before {
content: "\e760";
}

File diff suppressed because one or more lines are too long

View File

@ -6,11 +6,18 @@
"description": "",
"glyphs": [
{
"icon_id": "20860668",
"name": "纸飞机",
"font_class": "zhifeiji",
"unicode": "e617",
"unicode_decimal": 58903
"icon_id": "36208720",
"name": "tools",
"font_class": "tools",
"unicode": "e69f",
"unicode_decimal": 59039
},
{
"icon_id": "44129255",
"name": "rcd-home-f-copy",
"font_class": "rcd-home-f-copy",
"unicode": "e9a2",
"unicode_decimal": 59810
},
{
"icon_id": "44119317",
@ -26,13 +33,6 @@
"unicode": "e802",
"unicode_decimal": 59394
},
{
"icon_id": "3362566",
"name": "羽毛笔",
"font_class": "yumaobi",
"unicode": "e606",
"unicode_decimal": 58886
},
{
"icon_id": "44119318",
"name": "羽毛笔-copy",
@ -75,13 +75,6 @@
"unicode": "e6cc",
"unicode_decimal": 59084
},
{
"icon_id": "11278216",
"name": "阅读",
"font_class": "yuedu1",
"unicode": "e6bc",
"unicode_decimal": 59068
},
{
"icon_id": "14145811",
"name": "叶子",

View File

@ -64,6 +64,7 @@ onMounted(() => {
.homeHeader {
position: relative;
height: 2.5rem;
background: var(--header-bg-color);
div.logoContainer{
position: relative;
@ -117,6 +118,7 @@ onMounted(() => {
position: relative;
display: flex;
height: 4rem;
background: var(--header-bg-color);
& > * {
position: relative;
height: 100%;

View File

@ -9,12 +9,12 @@ const route = useRoute()
const menuList = ref([
{
name: '首页',
icon: '&#xe9a1;',
icon: '&#xe9a2;',
message: '',
path: ''
},
{
name: 'BLOG',
name: '博客',
icon: '&#xe9a1;',
message: '',
path: 'blog'
@ -37,6 +37,12 @@ const menuList = ref([
message: '',
path: 'hello'
},
{
name: '工具',
icon: '&#xe69f;',
message: '',
path: 'tools'
},
])
const activeMenu = computed(() => {
return route.path.split('/')[2] || ''
@ -69,7 +75,6 @@ const activeMenu = computed(() => {
width: 100%;
height: 0;
backdrop-filter: blur(10px);
background: #dddddd99;
transition: width 0.5s ease-in-out, height 0.5s ease-in-out;
z-index: 99;
display: flex;
@ -96,6 +101,7 @@ const activeMenu = computed(() => {
&:has(a:nth-child(3).active)::after { transform: translateY(calc(200% + 0.6rem *2)); }
&:has(a:nth-child(4).active)::after { transform: translateY(calc(300% + 0.6rem *3)); }
&:has(a:nth-child(5).active)::after { transform: translateY(calc(400% + 0.6rem *4)); }
&:has(a:nth-child(6).active)::after { transform: translateY(calc(500% + 0.6rem *5)); }
&>.menuItemContainer{
display: block;
@ -151,11 +157,12 @@ const activeMenu = computed(() => {
transition: all 0.3s ease;
}
/* 悬停效果 */
&:has(a:nth-child(1):hover)::after { transform: translateX(0); }
&:has(a:nth-child(2):hover)::after { transform: translateX(100%); }
&:has(a:nth-child(3):hover)::after { transform: translateX(200%); }
&:has(a:nth-child(4):hover)::after { transform: translateX(300%); }
&:has(a:nth-child(5):hover)::after { transform: translateX(400%); }
&:has(a:nth-child(1):hover)::after { transform: translateX(0) !important; }
&:has(a:nth-child(2):hover)::after { transform: translateX(100%) !important; }
&:has(a:nth-child(3):hover)::after { transform: translateX(200%) !important; }
&:has(a:nth-child(4):hover)::after { transform: translateX(300%) !important; }
&:has(a:nth-child(5):hover)::after { transform: translateX(400%) !important; }
&:has(a:nth-child(6):hover)::after { transform: translateX(500%) !important; }
/* 选中固定效果 */
&:has(a:nth-child(1).active)::after { transform: translateX(0); }
@ -163,6 +170,7 @@ const activeMenu = computed(() => {
&:has(a:nth-child(3).active)::after { transform: translateX(200%); }
&:has(a:nth-child(4).active)::after { transform: translateX(300%); }
&:has(a:nth-child(5).active)::after { transform: translateX(400%); }
&:has(a:nth-child(6).active)::after { transform: translateX(500%); }
.menuItemContainer{
position: relative;

View File

@ -47,13 +47,39 @@ export default defineNuxtConfig({
leave: 500
},
appear: true
}
},
},
hooks: {
'listen': (server) => {
startBroswer(server.address())
},
}
},
runtimeConfig: {
server: {
redis: {
host: process.env.REDIS_HOST || '127.0.0.1',
port: Number(process.env.REDIS_PORT) || 6379,
connectName: 'star-writ',
database: Number(process.env.REDIS_DB) || 9,
username: 'default',
password: process.env.REDIS_PASSWORD || 'Hxl1314521',
},
mysql:{
host: process.env.DB_HOST || '127.0.0.1',
port: process.env.DB_PORT || 3306,
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME || 'yuheng',
ssl:
process.env.NODE_ENV === 'production'
? {
rejectUnauthorized: false,
servername: '', // 明确置空servername参数
}
: null,
}
}
},
})
// 首次启动浏览器

334
package-lock.json generated
View File

@ -8,8 +8,12 @@
"hasInstallScript": true,
"dependencies": {
"@nuxt/eslint": "^1.3.0",
"consola": "^3.4.2",
"drizzle-orm": "^0.42.0",
"eslint": "^9.25.0",
"mysql2": "^3.14.0",
"nuxt": "^3.16.2",
"redis": "^4.7.0",
"vue": "^3.5.13",
"vue-router": "^4.5.0"
},
@ -3464,6 +3468,71 @@
"node": ">=18"
}
},
"node_modules/@redis/bloom": {
"version": "1.2.0",
"resolved": "https://registry.npmmirror.com/@redis/bloom/-/bloom-1.2.0.tgz",
"integrity": "sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/client": {
"version": "1.6.0",
"resolved": "https://registry.npmmirror.com/@redis/client/-/client-1.6.0.tgz",
"integrity": "sha512-aR0uffYI700OEEH4gYnitAnv3vzVGXCFvYfdpu/CJKvk4pHfLPEy/JSZyrpQ+15WhXe1yJRXLtfQ84s4mEXnPg==",
"license": "MIT",
"dependencies": {
"cluster-key-slot": "1.1.2",
"generic-pool": "3.9.0",
"yallist": "4.0.0"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@redis/client/node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"license": "ISC"
},
"node_modules/@redis/graph": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/@redis/graph/-/graph-1.1.1.tgz",
"integrity": "sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/json": {
"version": "1.0.7",
"resolved": "https://registry.npmmirror.com/@redis/json/-/json-1.0.7.tgz",
"integrity": "sha512-6UyXfjVaTBTJtKNG4/9Z8PSpKE6XgSyEb8iwaqDcy+uKrd/DGYHTWkUdnQDyzm727V7p21WUMhsqz5oy65kPcQ==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/search": {
"version": "1.2.0",
"resolved": "https://registry.npmmirror.com/@redis/search/-/search-1.2.0.tgz",
"integrity": "sha512-tYoDBbtqOVigEDMAcTGsRlMycIIjwMCgD8eR2t0NANeQmgK/lvxNAvYyb6bZDD4frHRhIHkJu2TBRvB0ERkOmw==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/time-series": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/@redis/time-series/-/time-series-1.1.0.tgz",
"integrity": "sha512-c1Q99M5ljsIuc4YdaCwfUEXsofakb9c8+Zse2qxTadu8TalLXuAESzLvFAvNVbkmSlvlzIQOLpBCmWI9wTOt+g==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@rollup/plugin-alias": {
"version": "5.1.1",
"resolved": "https://registry.npmmirror.com/@rollup/plugin-alias/-/plugin-alias-5.1.1.tgz",
@ -5627,6 +5696,15 @@
"postcss": "^8.1.0"
}
},
"node_modules/aws-ssl-profiles": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz",
"integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==",
"license": "MIT",
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/b4a": {
"version": "1.6.7",
"resolved": "https://registry.npmmirror.com/b4a/-/b4a-1.6.7.tgz",
@ -7145,6 +7223,127 @@
"url": "https://dotenvx.com"
}
},
"node_modules/drizzle-orm": {
"version": "0.42.0",
"resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.42.0.tgz",
"integrity": "sha512-pS8nNJm2kBNZwrOjTHJfdKkaU+KuUQmV/vk5D57NojDq4FG+0uAYGMulXtYT///HfgsMF0hnFFvu1ezI3OwOkg==",
"license": "Apache-2.0",
"peerDependencies": {
"@aws-sdk/client-rds-data": ">=3",
"@cloudflare/workers-types": ">=4",
"@electric-sql/pglite": ">=0.2.0",
"@libsql/client": ">=0.10.0",
"@libsql/client-wasm": ">=0.10.0",
"@neondatabase/serverless": ">=0.10.0",
"@op-engineering/op-sqlite": ">=2",
"@opentelemetry/api": "^1.4.1",
"@planetscale/database": ">=1.13",
"@prisma/client": "*",
"@tidbcloud/serverless": "*",
"@types/better-sqlite3": "*",
"@types/pg": "*",
"@types/sql.js": "*",
"@vercel/postgres": ">=0.8.0",
"@xata.io/client": "*",
"better-sqlite3": ">=7",
"bun-types": "*",
"expo-sqlite": ">=14.0.0",
"gel": ">=2",
"knex": "*",
"kysely": "*",
"mysql2": ">=2",
"pg": ">=8",
"postgres": ">=3",
"sql.js": ">=1",
"sqlite3": ">=5"
},
"peerDependenciesMeta": {
"@aws-sdk/client-rds-data": {
"optional": true
},
"@cloudflare/workers-types": {
"optional": true
},
"@electric-sql/pglite": {
"optional": true
},
"@libsql/client": {
"optional": true
},
"@libsql/client-wasm": {
"optional": true
},
"@neondatabase/serverless": {
"optional": true
},
"@op-engineering/op-sqlite": {
"optional": true
},
"@opentelemetry/api": {
"optional": true
},
"@planetscale/database": {
"optional": true
},
"@prisma/client": {
"optional": true
},
"@tidbcloud/serverless": {
"optional": true
},
"@types/better-sqlite3": {
"optional": true
},
"@types/pg": {
"optional": true
},
"@types/sql.js": {
"optional": true
},
"@vercel/postgres": {
"optional": true
},
"@xata.io/client": {
"optional": true
},
"better-sqlite3": {
"optional": true
},
"bun-types": {
"optional": true
},
"expo-sqlite": {
"optional": true
},
"gel": {
"optional": true
},
"knex": {
"optional": true
},
"kysely": {
"optional": true
},
"mysql2": {
"optional": true
},
"pg": {
"optional": true
},
"postgres": {
"optional": true
},
"prisma": {
"optional": true
},
"sql.js": {
"optional": true
},
"sqlite3": {
"optional": true
}
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/dunder-proto/-/dunder-proto-1.0.1.tgz",
@ -8551,6 +8750,24 @@
"node": ">=8"
}
},
"node_modules/generate-function": {
"version": "2.3.1",
"resolved": "https://registry.npmmirror.com/generate-function/-/generate-function-2.3.1.tgz",
"integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
"license": "MIT",
"dependencies": {
"is-property": "^1.0.2"
}
},
"node_modules/generic-pool": {
"version": "3.9.0",
"resolved": "https://registry.npmmirror.com/generic-pool/-/generic-pool-3.9.0.tgz",
"integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==",
"license": "MIT",
"engines": {
"node": ">= 4"
}
},
"node_modules/gensync": {
"version": "1.0.0-beta.2",
"resolved": "https://registry.npmmirror.com/gensync/-/gensync-1.0.0-beta.2.tgz",
@ -9034,6 +9251,18 @@
"node": ">=16.17.0"
}
},
"node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmmirror.com/ieee754/-/ieee754-1.2.1.tgz",
@ -9389,6 +9618,12 @@
"node": ">=8"
}
},
"node_modules/is-property": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/is-property/-/is-property-1.0.2.tgz",
"integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==",
"license": "MIT"
},
"node_modules/is-reference": {
"version": "1.2.1",
"resolved": "https://registry.npmmirror.com/is-reference/-/is-reference-1.2.1.tgz",
@ -10134,6 +10369,12 @@
"node": ">= 12.0.0"
}
},
"node_modules/long": {
"version": "5.3.2",
"resolved": "https://registry.npmmirror.com/long/-/long-5.3.2.tgz",
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==",
"license": "Apache-2.0"
},
"node_modules/lru-cache": {
"version": "5.1.1",
"resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-5.1.1.tgz",
@ -10143,6 +10384,21 @@
"yallist": "^3.0.2"
}
},
"node_modules/lru.min": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/lru.min/-/lru.min-1.1.2.tgz",
"integrity": "sha512-Nv9KddBcQSlQopmBHXSsZVY5xsdlZkdH/Iey0BlcBYggMd4two7cZnKOK9vmy3nY0O5RGH99z1PCeTpPqszUYg==",
"license": "MIT",
"engines": {
"bun": ">=1.0.0",
"deno": ">=1.30.0",
"node": ">=8.0.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wellwelwel"
}
},
"node_modules/luxon": {
"version": "3.6.1",
"resolved": "https://registry.npmmirror.com/luxon/-/luxon-3.6.1.tgz",
@ -10493,6 +10749,26 @@
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/mysql2": {
"version": "3.14.0",
"resolved": "https://registry.npmmirror.com/mysql2/-/mysql2-3.14.0.tgz",
"integrity": "sha512-8eMhmG6gt/hRkU1G+8KlGOdQi2w+CgtNoD1ksXZq9gQfkfDsX4LHaBwTe1SY0Imx//t2iZA03DFnyYKPinxSRw==",
"license": "MIT",
"dependencies": {
"aws-ssl-profiles": "^1.1.1",
"denque": "^2.1.0",
"generate-function": "^2.3.1",
"iconv-lite": "^0.6.3",
"long": "^5.2.1",
"lru.min": "^1.0.0",
"named-placeholders": "^1.1.3",
"seq-queue": "^0.0.5",
"sqlstring": "^2.3.2"
},
"engines": {
"node": ">= 8.0"
}
},
"node_modules/mz": {
"version": "2.7.0",
"resolved": "https://registry.npmmirror.com/mz/-/mz-2.7.0.tgz",
@ -10505,6 +10781,27 @@
"thenify-all": "^1.0.0"
}
},
"node_modules/named-placeholders": {
"version": "1.1.3",
"resolved": "https://registry.npmmirror.com/named-placeholders/-/named-placeholders-1.1.3.tgz",
"integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==",
"license": "MIT",
"dependencies": {
"lru-cache": "^7.14.1"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/named-placeholders/node_modules/lru-cache": {
"version": "7.18.3",
"resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-7.18.3.tgz",
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/nanoid": {
"version": "5.1.5",
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-5.1.5.tgz",
@ -12570,6 +12867,23 @@
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/redis": {
"version": "4.7.0",
"resolved": "https://registry.npmmirror.com/redis/-/redis-4.7.0.tgz",
"integrity": "sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==",
"license": "MIT",
"workspaces": [
"./packages/*"
],
"dependencies": {
"@redis/bloom": "1.2.0",
"@redis/client": "1.6.0",
"@redis/graph": "1.1.1",
"@redis/json": "1.0.7",
"@redis/search": "1.2.0",
"@redis/time-series": "1.1.0"
}
},
"node_modules/redis-errors": {
"version": "1.2.0",
"resolved": "https://registry.npmmirror.com/redis-errors/-/redis-errors-1.2.0.tgz",
@ -13112,6 +13426,12 @@
"node": ">=10"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/sass": {
"version": "1.86.3",
"resolved": "https://registry.npmmirror.com/sass/-/sass-1.86.3.tgz",
@ -13187,6 +13507,11 @@
"node": ">= 18"
}
},
"node_modules/seq-queue": {
"version": "0.0.5",
"resolved": "https://registry.npmmirror.com/seq-queue/-/seq-queue-0.0.5.tgz",
"integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q=="
},
"node_modules/serialize-javascript": {
"version": "6.0.2",
"resolved": "https://registry.npmmirror.com/serialize-javascript/-/serialize-javascript-6.0.2.tgz",
@ -13495,6 +13820,15 @@
"node": ">=0.10.0"
}
},
"node_modules/sqlstring": {
"version": "2.3.3",
"resolved": "https://registry.npmmirror.com/sqlstring/-/sqlstring-2.3.3.tgz",
"integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/stable-hash": {
"version": "0.0.5",
"resolved": "https://registry.npmmirror.com/stable-hash/-/stable-hash-0.0.5.tgz",

View File

@ -6,13 +6,17 @@
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"preview": "nuxt preview --port 4000",
"postinstall": "nuxt prepare"
},
"dependencies": {
"@nuxt/eslint": "^1.3.0",
"consola": "^3.4.2",
"drizzle-orm": "^0.42.0",
"eslint": "^9.25.0",
"mysql2": "^3.14.0",
"nuxt": "^3.16.2",
"redis": "^4.7.0",
"vue": "^3.5.13",
"vue-router": "^4.5.0"
},

View File

@ -1,11 +1,15 @@
<script setup lang="ts">
import consola from "consola";
definePageMeta({
layout: 'home',
})
const {data} = await useFetch('/api/hello')
consola.info(toValue(data))
</script>
<template>
<div class="homeIndex">
<div>redisData: {{data}}</div>
<div class="f1">汇文明朝体 ""| 星撰你好啊你叫什么名字,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890</div>
<div class="f2">落霞孤鹜 ""| 星撰你好啊你叫什么名字,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890</div>
<div class="f3">nice ""| 星撰你好啊你叫什么名字,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890</div>

6
server/api/hello.ts Normal file
View File

@ -0,0 +1,6 @@
export default defineEventHandler(async event => {
// console.log(await event.context.redis.get('SI HI'))
return {
'SI HI': await event.context.redis.get('SI HI')
}
})

View File

@ -0,0 +1,4 @@
export default defineEventHandler(event => {
})

61
server/plugins/mysql.ts Normal file
View File

@ -0,0 +1,61 @@
import { drizzle } from 'drizzle-orm/mysql2';
import { sql } from 'drizzle-orm';
import {createPool } from 'mysql2/promise';
import type { PoolOptions, Pool} from 'mysql2/promise';
import consola from "consola";
export default defineNitroPlugin(async nitroApp => {
const {server: {mysql: config}} = useRuntimeConfig()
consola.info('MySQL ...');
// 配置数据库
const poolOptions: PoolOptions = {
host: config.host,
port: config.port,
user: config.user,
password: config.password,
database: config.database,
// ssl: config.db.ssl,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
// 启用此选项后MySQL驱动程序将支持大数字big numbers这对于存储和处理 bigint 类型的数据尤为重要。
// 如果不启用此选项MySQL驱动程序可能无法正确处理超过 JavaScript 数字精度范围的大数值,导致数据精度丢失。
supportBigNumbers: true,
// 启用此选项后MySQL驱动程序将在接收 bigint 或其他大数值时将其作为字符串返回而不是作为JavaScript数字。
// 这种处理方式可以避免JavaScript本身的数值精度限制问题确保大数值在应用程序中保持精确。
bigNumberStrings: true,
// typeCast: function (field, next) {
// if (field.type === 'LONGLONG') { // 处理 BIGINT 类型
// return field.string(); // 强制转换为字符串
// }
// return next();
// }
}
let pool: Pool;
try{
pool = await createPool(poolOptions)
}catch (e) {
consola.error('MySQL onnection Error: ', e);
throw e;
}
// 暴露数据库
const db = drizzle(pool,{
logger: {
logQuery: (query, params) => {
consola.debug(`SQL: ${query} - Params: ${JSON.stringify(params)}`); // 打印日志,包括查询和参数
}
}
});
const [result] = await db.execute(sql`SHOW TABLES`);
const tableList = result.map(row => Object.values(row)[0]);
consola.info('TableList', tableList)
// 将连接池添加到 Nitro 应用上下文
nitroApp.hooks.hook('request', async (event) => {
event.context.mysql = db
})
nitroApp.hooks.hook('error', async () => {
db.close();
})
})

33
server/plugins/redis.ts Normal file
View File

@ -0,0 +1,33 @@
import { createClient } from 'redis';
import consola from 'consola'
export default defineNitroPlugin(async (nitroApp) => {
const {server: {redis: config}} = useRuntimeConfig()
consola.info('Redis ...');
const redisConnect = createClient({
name: config.connectName,
username: config.username,
password: config.password,
database: Number(config.database),
url: `redis://${config.username}:${config.password}@${config.host}:${config.port}/${config.database}`,
});
redisConnect.on('connect', async () => {
consola.info(`redis://${config.username}:${config.password}@${config.host}:${config.port}/${config.database}`)
consola.info(await redisConnect.set('SI HI', 'Star Writ'));
});
redisConnect.on('error', (err) => {
console.log(err)
consola.error('Redis error: ', err);
});
// 连接到 Redis
await redisConnect.connect();
// 将连接池添加到 Nitro 应用上下文
nitroApp.hooks.hook('request', async (event) => {
event.context.redis = redisConnect
})
nitroApp.hooks.hook('error', async () => {
redisConnect.disconnect()
})
})