feat: 完善安装部署与数字溯源码

This commit is contained in:
Nixevol
2026-07-06 23:26:21 +08:00
parent 7480e4d256
commit 7c6b0bff4c
59 changed files with 2174 additions and 166 deletions
+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Artveris Install</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+20
View File
@@ -0,0 +1,20 @@
{
"name": "@artveris/install",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "vite build",
"dev": "vite --host 0.0.0.0 --port 5175",
"lint": "echo \"(install) lint skipped\""
},
"dependencies": {
"axios": "^1.7.9",
"vue": "^3.5.13"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.1",
"typescript": "^5.6.3",
"vite": "^5.4.11"
}
}
+237
View File
@@ -0,0 +1,237 @@
<template>
<main class="install-page">
<section class="panel">
<header>
<h1>Artveris</h1>
<button v-if="!installed" :disabled="submitting" @click="submit">
{{ submitting ? t('installing') : t('start') }}
</button>
</header>
<p v-if="loading" class="muted">{{ t('loading') }}</p>
<p v-else-if="installed" class="success">{{ t('installed') }}</p>
<template v-else>
<div class="salt-row">
<span>traceCodeSalt</span>
<code>{{ traceCodeSalt }}</code>
</div>
<div class="grid">
<section>
<h2>{{ t('base') }}</h2>
<label>{{ t('appName') }}<input v-model="form.appName" /></label>
<label>{{ t('baseUrl') }}<input v-model="form.baseUrl" /></label>
<label>{{ t('clientBaseUrl') }}<input v-model="form.clientBaseUrl" /></label>
</section>
<section>
<h2>MySQL</h2>
<label>{{ t('host') }}<input v-model="form.mysql.host" /></label>
<label>{{ t('port') }}<input v-model.number="form.mysql.port" type="number" /></label>
<label>{{ t('database') }}<input v-model="form.mysql.database" /></label>
<label>{{ t('username') }}<input v-model="form.mysql.username" /></label>
<label>{{ t('password') }}<input v-model="form.mysql.password" type="password" /></label>
</section>
<section>
<h2>Redis</h2>
<label>{{ t('host') }}<input v-model="form.redis.host" /></label>
<label>{{ t('port') }}<input v-model.number="form.redis.port" type="number" /></label>
<label>{{ t('password') }}<input v-model="form.redis.password" type="password" /></label>
</section>
<section>
<h2>{{ t('admin') }}</h2>
<label>{{ t('username') }}<input v-model="form.admin.username" /></label>
<label>{{ t('password') }}<input v-model="form.admin.password" type="password" /></label>
<label>{{ t('realName') }}<input v-model="form.admin.realName" /></label>
</section>
<section>
<h2>{{ t('storage') }}</h2>
<label>
{{ t('driver') }}
<select v-model="form.storage.driver">
<option value="local">{{ t('local') }}</option>
<option value="oss">OSS/S3</option>
</select>
</label>
<label>{{ t('localDir') }}<input v-model="form.storage.localDir" /></label>
<label>{{ t('cdnBaseUrl') }}<input v-model="form.storage.cdnBaseUrl" /></label>
<template v-if="form.storage.driver === 'oss'">
<label>Endpoint<input v-model="form.storage.ossEndpoint" /></label>
<label>Region<input v-model="form.storage.ossRegion" /></label>
<label>Bucket<input v-model="form.storage.ossBucket" /></label>
<label>AccessKey ID<input v-model="form.storage.ossAccessKeyId" /></label>
<label>AccessKey Secret<input v-model="form.storage.ossAccessKeySecret" type="password" /></label>
</template>
</section>
</div>
<p v-if="error" class="error">{{ error }}</p>
<p v-if="success" class="success">{{ success }}</p>
</template>
</section>
</main>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue';
type StorageDriver = 'local' | 'oss';
interface InstallForm {
appName: string;
baseUrl: string;
clientBaseUrl: string;
mysql: { host: string; port: number; database: string; username: string; password: string };
redis: { host: string; port: number; password: string };
admin: { username: string; password: string; realName: string };
storage: {
driver: StorageDriver;
localDir: string;
cdnBaseUrl: string;
ossEndpoint: string;
ossRegion: string;
ossBucket: string;
ossAccessKeyId: string;
ossAccessKeySecret: string;
};
}
const messages = {
'zh-CN': {
start: '开始安装',
installing: '安装中',
loading: '正在读取安装状态...',
installed: '系统已完成初始化。',
base: '基础',
appName: '平台名称',
baseUrl: '服务地址',
clientBaseUrl: '客户端地址',
host: '主机',
port: '端口',
database: '数据库',
username: '账号',
password: '密码',
admin: '管理员',
realName: '姓名',
storage: '存储',
driver: '方式',
local: '本地',
localDir: '本地目录',
cdnBaseUrl: 'CDN 地址',
installFailed: '安装失败',
installDone: '初始化完成,服务正在重启。稍后访问管理后台。',
defaultAppName: '艺术品溯源平台',
defaultAdminName: '管理员',
},
'en-US': {
start: 'Start Install',
installing: 'Installing',
loading: 'Reading installation status...',
installed: 'The system has already been initialized.',
base: 'Base',
appName: 'Platform Name',
baseUrl: 'Service URL',
clientBaseUrl: 'Client URL',
host: 'Host',
port: 'Port',
database: 'Database',
username: 'Username',
password: 'Password',
admin: 'Admin',
realName: 'Name',
storage: 'Storage',
driver: 'Driver',
local: 'Local',
localDir: 'Local Directory',
cdnBaseUrl: 'CDN URL',
installFailed: 'Installation failed',
installDone: 'Initialization completed. The service is restarting; open the admin console shortly.',
defaultAppName: 'Artwork Traceability Platform',
defaultAdminName: 'Administrator',
},
} as const;
type MessageKey = keyof (typeof messages)['zh-CN'];
const locale = navigator.language.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
function t(key: MessageKey): string {
return messages[locale][key] || messages['zh-CN'][key];
}
function defaultText(key: MessageKey): string {
const lang = navigator.language.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
return messages[lang][key] || messages['zh-CN'][key];
}
const form = reactive<InstallForm>({
appName: defaultText('defaultAppName'),
baseUrl: location.origin,
clientBaseUrl: `${location.origin}/trace`,
mysql: { host: '127.0.0.1', port: 3306, database: 'artveris', username: 'artveris', password: '' },
redis: { host: '127.0.0.1', port: 6379, password: '' },
admin: { username: 'admin', password: '', realName: defaultText('defaultAdminName') },
storage: {
driver: 'local',
localDir: './storage',
cdnBaseUrl: '',
ossEndpoint: '',
ossRegion: '',
ossBucket: '',
ossAccessKeyId: '',
ossAccessKeySecret: '',
},
});
const loading = ref(true);
const submitting = ref(false);
const installed = ref(false);
const traceCodeSalt = ref('');
const error = ref('');
const success = ref('');
onMounted(async () => {
try {
const res = await fetch('/api/install/status');
const body = await res.json();
installed.value = Boolean(body.data?.installed);
traceCodeSalt.value = body.data?.traceCodeSalt || '';
const defaults = body.data?.defaults || {};
form.mysql.host = defaults.mysqlHost || form.mysql.host;
form.mysql.port = defaults.mysqlPort || form.mysql.port;
form.mysql.database = defaults.mysqlDatabase || form.mysql.database;
form.mysql.username = defaults.mysqlUser || form.mysql.username;
form.redis.host = defaults.redisHost || form.redis.host;
form.redis.port = defaults.redisPort || form.redis.port;
} catch (e) {
error.value = (e as Error).message;
} finally {
loading.value = false;
}
});
async function submit() {
error.value = '';
success.value = '';
submitting.value = true;
try {
const res = await fetch('/api/install', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(form),
});
const body = await res.json();
if (!res.ok || body.code !== 0) throw new Error(body.message || t('installFailed'));
success.value = t('installDone');
setTimeout(() => {
location.href = '/admin';
}, 5000);
} catch (e) {
error.value = (e as Error).message;
} finally {
submitting.value = false;
}
}
</script>
+5
View File
@@ -0,0 +1,5 @@
import { createApp } from 'vue';
import App from './App.vue';
import './styles.css';
createApp(App).mount('#app');
+116
View File
@@ -0,0 +1,116 @@
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: #172033;
background: #eef2f7;
}
.install-page {
min-height: 100vh;
padding: 24px;
}
.panel {
max-width: 1180px;
margin: 0 auto;
background: #fff;
border: 1px solid #d9e0ea;
border-radius: 8px;
padding: 20px;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
border-bottom: 1px solid #e4e9f1;
padding-bottom: 14px;
margin-bottom: 16px;
}
h1,
h2 {
margin: 0;
}
h1 {
font-size: 22px;
}
h2 {
font-size: 15px;
padding-bottom: 10px;
border-bottom: 1px solid #e9edf4;
}
button {
height: 36px;
padding: 0 18px;
border: 0;
border-radius: 6px;
background: #1769e0;
color: #fff;
cursor: pointer;
}
button:disabled {
opacity: 0.65;
cursor: wait;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
gap: 12px;
}
section {
border: 1px solid #e1e7f0;
border-radius: 8px;
padding: 14px;
}
label {
display: grid;
grid-template-columns: 96px 1fr;
align-items: center;
gap: 10px;
min-height: 42px;
color: #526070;
font-size: 14px;
}
input,
select {
width: 100%;
height: 32px;
border: 1px solid #cad3df;
border-radius: 6px;
padding: 0 10px;
color: #172033;
background: #fff;
}
.salt-row {
display: grid;
grid-template-columns: 120px 1fr;
gap: 10px;
align-items: center;
margin-bottom: 14px;
padding: 10px 12px;
background: #f7f9fc;
border: 1px solid #e1e7f0;
border-radius: 8px;
}
code {
overflow-wrap: anywhere;
color: #25324a;
}
.muted {
color: #6a7687;
}
.error,
.success {
margin: 14px 0 0;
padding: 10px 12px;
border-radius: 6px;
}
.error {
color: #a61b1b;
background: #fff1f0;
}
.success {
color: #17643b;
background: #edf9f1;
}
+17
View File
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"strict": true
},
"include": ["src/**/*.ts", "src/**/*.vue"]
}
+14
View File
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
base: process.env.VITE_BASE || '/install/',
plugins: [vue()],
server: {
port: 5175,
host: true,
proxy: {
'/api': { target: 'http://localhost:3000', changeOrigin: true },
},
},
});