refactor: refactor
This commit is contained in:
parent
03df696476
commit
b2088df062
@ -1,6 +1,7 @@
|
|||||||
package ltd.qubit.survey.controller;
|
package ltd.qubit.survey.controller;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import ltd.qubit.survey.model.User;
|
import ltd.qubit.survey.model.User;
|
||||||
import ltd.qubit.survey.service.UserService;
|
import ltd.qubit.survey.service.UserService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -8,11 +9,13 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户控制器
|
* 用户控制器
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class UserController {
|
public class UserController {
|
||||||
@ -48,7 +51,8 @@ public class UserController {
|
|||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("/user/phone/{phone}")
|
@GetMapping("/user/phone/{phone}")
|
||||||
public User findByPhone(@PathVariable String phone) {
|
public User findByPhone(@PathVariable String phone, @RequestHeader(value = "Origin", required = false) String origin) {
|
||||||
|
log.info("Find by phone - phone: {}, Origin: {}", phone, origin);
|
||||||
return userService.findByPhone(phone)
|
return userService.findByPhone(phone)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@
|
|||||||
<!-- 配置跨域支持 -->
|
<!-- 配置跨域支持 -->
|
||||||
<mvc:cors>
|
<mvc:cors>
|
||||||
<mvc:mapping path="/**"
|
<mvc:mapping path="/**"
|
||||||
allowed-origins="http://localhost:3000,http://localhost:8080"
|
allowed-origins="http://localhost:3000,http://localhost:8080,https://qubit.ltd,https://dev.qubit.ltd,https://www.qubit.ltd,https://api.qubit.ltd"
|
||||||
allowed-methods="GET,POST,PUT,DELETE,OPTIONS"
|
allowed-methods="GET,POST,PUT,DELETE,OPTIONS"
|
||||||
allowed-headers="Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers"
|
allowed-headers="Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers"
|
||||||
allow-credentials="true"
|
allow-credentials="true"
|
||||||
|
|||||||
2
frontend/.env.development
Normal file
2
frontend/.env.development
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# 开发环境配置
|
||||||
|
VITE_API_BASE_URL=http://127.0.0.1:8080/llm-survey-api
|
||||||
2
frontend/.env.staging
Normal file
2
frontend/.env.staging
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# 预发布环境配置
|
||||||
|
VITE_API_BASE_URL=https://api.qubit.ltd/llm-survey-api
|
||||||
Binary file not shown.
160
frontend/deploy-frontend.sh
Executable file
160
frontend/deploy-frontend.sh
Executable file
@ -0,0 +1,160 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# Copyright (c) 2017-2024
|
||||||
|
# Qubit Technology Inc. (https://www.qubit.ltd)
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This script will publish the frontend project to the remote server.
|
||||||
|
#
|
||||||
|
# Author: Haixing Hu
|
||||||
|
# Date: 2024-12-08
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# 打印使用说明
|
||||||
|
print_usage() {
|
||||||
|
echo "使用方法:$0 配置文件路径"
|
||||||
|
echo "配置文件格式:"
|
||||||
|
echo " # 注释行"
|
||||||
|
echo " PROPERTY_NAME = PROPERTY_VALUE"
|
||||||
|
echo "必填属性:"
|
||||||
|
echo " PROJECT_ENV: 项目编译环境"
|
||||||
|
echo " PROJECT_NAME: 项目名称"
|
||||||
|
echo " REMOTE_SERVER: 远程服务器地址"
|
||||||
|
echo " REMOTE_PORT: 远程服务器端口"
|
||||||
|
echo " REMOTE_USER: 远程服务器账号名"
|
||||||
|
echo " REMOTE_PASSWORD: 远程服务器账号密码(可选)"
|
||||||
|
echo " REMOTE_NGINX_HTML_PATH: 远程服务器nginx html发布目录"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 参数校验
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
echo "错误:未提供配置文件路径!"
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CONFIG_FILE="$1"
|
||||||
|
|
||||||
|
# 检查配置文件是否存在
|
||||||
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
|
echo "错误:配置文件不存在:$CONFIG_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 读取配置文件
|
||||||
|
declare -A CONFIG
|
||||||
|
while IFS='=' read -r key value; do
|
||||||
|
key=$(echo "$key" | xargs) # 去除前后空格
|
||||||
|
value=$(echo "$value" | xargs)
|
||||||
|
[[ "$key" =~ ^#.*$ || -z "$key" ]] && continue # 跳过注释或空行
|
||||||
|
CONFIG["$key"]="$value"
|
||||||
|
done < "$CONFIG_FILE"
|
||||||
|
|
||||||
|
# 检查必填配置项
|
||||||
|
REQUIRED_KEYS=("PROJECT_ENV" "PROJECT_NAME" "REMOTE_SERVER" "REMOTE_PORT" "REMOTE_USER" "REMOTE_NGINX_HTML_PATH")
|
||||||
|
for key in "${REQUIRED_KEYS[@]}"; do
|
||||||
|
if [ -z "${CONFIG[$key]}" ]; then
|
||||||
|
echo "错误:缺少必填配置项:$key"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 读取配置
|
||||||
|
PROJECT_ENV="${CONFIG["PROJECT_ENV"]}"
|
||||||
|
PROJECT_NAME="${CONFIG["PROJECT_NAME"]}"
|
||||||
|
REMOTE_SERVER="${CONFIG["REMOTE_SERVER"]}"
|
||||||
|
REMOTE_PORT="${CONFIG["REMOTE_PORT"]}"
|
||||||
|
REMOTE_USER="${CONFIG["REMOTE_USER"]}"
|
||||||
|
REMOTE_PASSWORD="${CONFIG["REMOTE_PASSWORD"]}"
|
||||||
|
REMOTE_NGINX_HTML_PATH="${CONFIG["REMOTE_NGINX_HTML_PATH"]}"
|
||||||
|
|
||||||
|
# 提示发布
|
||||||
|
read -p "确定要发布项目 ${PROJECT_NAME} 到 ${PROJECT_ENV} 环境吗?(yes/no): " CONFIRM
|
||||||
|
CONFIRM=$(echo "$CONFIRM" | tr '[:upper:]' '[:lower:]') # 将用户输入转换为小写
|
||||||
|
if [[ "$CONFIRM" != "y" && "$CONFIRM" != "yes" ]]; then
|
||||||
|
echo "发布已取消。"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检查 package.json 中的 build 脚本
|
||||||
|
echo "正在检查 package.json ..."
|
||||||
|
if [ ! -f "package.json" ]; then
|
||||||
|
echo "错误:当前目录下未找到 package.json 文件!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
BUILD_SCRIPT="build:${PROJECT_ENV}"
|
||||||
|
if [[ "$PROJECT_ENV" == "prod" ]]; then
|
||||||
|
BUILD_SCRIPT="build"
|
||||||
|
if ! grep -q "\"build\"" package.json; then
|
||||||
|
BUILD_SCRIPT="build:prod"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -q "\"$BUILD_SCRIPT\"" package.json; then
|
||||||
|
echo "错误:未在 package.json 中找到 $BUILD_SCRIPT 脚本!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 编译项目
|
||||||
|
echo "正在安装依赖..."
|
||||||
|
yarn install
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "安装依赖失败,发布终止!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "正在编译项目(使用脚本:${BUILD_SCRIPT})..."
|
||||||
|
yarn "$BUILD_SCRIPT"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "编译失败,发布终止!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 获取当前时间戳
|
||||||
|
TIMESTAMP=$(date +%Y%m%d%H%M%S)
|
||||||
|
|
||||||
|
# 远程操作
|
||||||
|
echo "正在发布到远程服务器 $REMOTE_SERVER ..."
|
||||||
|
|
||||||
|
# 创建远程备份目录并重命名现有目录
|
||||||
|
BACKUP_DIR="${REMOTE_NGINX_HTML_PATH}/${PROJECT_NAME}_${TIMESTAMP}"
|
||||||
|
ssh -p "$REMOTE_PORT" "$REMOTE_USER@$REMOTE_SERVER" <<EOF
|
||||||
|
if [ -d "${REMOTE_NGINX_HTML_PATH}/${PROJECT_NAME}" ]; then
|
||||||
|
mv "${REMOTE_NGINX_HTML_PATH}/${PROJECT_NAME}" "$BACKUP_DIR"
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "远程目录重命名失败,发布终止!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 上传编译后的代码
|
||||||
|
echo "正在上传文件..."
|
||||||
|
scp -P "$REMOTE_PORT" -r dist/* "$REMOTE_USER@$REMOTE_SERVER:${REMOTE_NGINX_HTML_PATH}/${PROJECT_NAME}/"
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "文件上传失败,发布终止!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 设置远程目录及文件的权限
|
||||||
|
echo "正在设置远程目录和文件权限..."
|
||||||
|
ssh -p "$REMOTE_PORT" "$REMOTE_USER@$REMOTE_SERVER" <<EOF
|
||||||
|
# 确保目标目录存在并设置权限
|
||||||
|
if [ -d "${REMOTE_NGINX_HTML_PATH}/${PROJECT_NAME}" ]; then
|
||||||
|
chmod -R 755 "${REMOTE_NGINX_HTML_PATH}/${PROJECT_NAME}"
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "设置远程权限失败,发布终止!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 发布成功
|
||||||
|
echo "发布成功!"
|
||||||
@ -3,8 +3,10 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite --mode development",
|
||||||
"build": "vite build",
|
"dev:stage": "vite --mode staging",
|
||||||
|
"build:dev": "vite build --mode development",
|
||||||
|
"build:stage": "vite build --mode staging",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
|
||||||
},
|
},
|
||||||
|
|||||||
BIN
frontend/src/assets/logo.png
Normal file
BIN
frontend/src/assets/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
@ -1,7 +1,7 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHashHistory } from 'vue-router';
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHashHistory(import.meta.env.BASE_URL),
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import axios from 'axios';
|
|||||||
import { showToast } from 'vant';
|
import { showToast } from 'vant';
|
||||||
|
|
||||||
const request = axios.create({
|
const request = axios.create({
|
||||||
baseURL: '/api',
|
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
class="logo"
|
class="logo"
|
||||||
width="200"
|
width="200"
|
||||||
height="200"
|
height="200"
|
||||||
src="/logo.png"
|
:src="logoUrl"
|
||||||
fit="contain"
|
fit="contain"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -59,14 +59,17 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useUserStore } from '@/stores/user';
|
import { useUserStore } from '@/stores/user';
|
||||||
import { useSurveyStore } from '@/stores/survey';
|
import { useSurveyStore } from '@/stores/survey';
|
||||||
import { showToast } from 'vant';
|
import { showToast } from 'vant';
|
||||||
|
import logoImage from '@/assets/logo.png';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const surveyStore = useSurveyStore();
|
const surveyStore = useSurveyStore();
|
||||||
|
const logoUrl = ref(logoImage);
|
||||||
|
|
||||||
function onLogout() {
|
function onLogout() {
|
||||||
userStore.logout();
|
userStore.logout();
|
||||||
|
|||||||
8
frontend/stage.deploy.conf
Normal file
8
frontend/stage.deploy.conf
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 常量定义
|
||||||
|
PROJECT_ENV="stage"
|
||||||
|
PROJECT_NAME="llm-survey"
|
||||||
|
REMOTE_SERVER="dev.qubit.ltd"
|
||||||
|
REMOTE_PORT="22"
|
||||||
|
REMOTE_USER="dev"
|
||||||
|
REMOTE_PASSWORD=""
|
||||||
|
REMOTE_NGINX_HTML_PATH="/var/www/html"
|
||||||
@ -7,6 +7,7 @@ import postcssPxToViewport from 'postcss-px-to-viewport';
|
|||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
base: './', // 使用相对路径
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
// 自动导入 Vant 组件
|
// 自动导入 Vant 组件
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user