diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..9632ac1 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# 仅当本次提交涉及 admin 源代码或配置时,运行 admin 构建(含 vue-tsc 类型检查) +# 通过检查暂存区是否有 zhican/admin/ 下的相关文件来决定 + +set -e + +CHANGED=$(git diff --cached --name-only --diff-filter=ACMR \ + | grep -E '^zhican/admin/(src/|.*\.(json|ts|html))' || true) + +if [ -z "$CHANGED" ]; then + exit 0 +fi + +echo "→ pre-commit: 检测到 admin 变更,运行 pnpm run build..." +cd "$(git rev-parse --show-toplevel)/zhican/admin" + +if ! command -v pnpm >/dev/null 2>&1; then + echo "pre-commit: 未找到 pnpm,跳过构建检查(请手动运行 pnpm run build 验证)" >&2 + exit 0 +fi + +pnpm run build diff --git a/zhican/admin/src/api/index.ts b/zhican/admin/src/api/index.ts deleted file mode 100644 index 69d8a93..0000000 --- a/zhican/admin/src/api/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -import request from '@/utils/request' - -// 绿色种采 - 土地环境 -export const landEnvApi = { - list: (params?: any) => request.get('/green-planting/land-env', { params }), - detail: (id: string) => request.get(`/green-planting/land-env/${id}`), - create: (data: any) => request.post('/green-planting/land-env', data), - update: (id: string, data: any) => request.put(`/green-planting/land-env/${id}`, data), - remove: (id: string) => request.delete(`/green-planting/land-env/${id}`), -} - -// 卫生供应 - 卫生检测 -export const hygieneTestApi = { - list: (params?: any) => request.get('/hygiene-supply/hygiene-test', { params }), - detail: (id: string) => request.get(`/hygiene-supply/hygiene-test/${id}`), - create: (data: any) => request.post('/hygiene-supply/hygiene-test', data), -} - -// 健康生产 - 食安监控 -export const foodSafetyApi = { - list: (params?: any) => request.get('/health-production/food-safety', { params }), - detail: (id: string) => request.get(`/health-production/food-safety/${id}`), -} - -// 营养用餐 - 用户管理 -export const userMgmtApi = { - list: (params?: any) => request.get('/nutrition-dining/users', { params }), - detail: (id: string) => request.get(`/nutrition-dining/users/${id}`), - create: (data: any) => request.post('/nutrition-dining/users', data), - update: (id: string, data: any) => request.put(`/nutrition-dining/users/${id}`, data), - remove: (id: string) => request.delete(`/nutrition-dining/users/${id}`), -} - -// 登录 -export const authApi = { - login: (data: { username: string; password: string }) => request.post('/auth/login', data), - logout: () => request.post('/auth/logout'), - profile: () => request.get('/auth/profile'), -} diff --git a/zhican/admin/src/mock/data.ts b/zhican/admin/src/mock/data.ts index 261db71..7529efb 100644 --- a/zhican/admin/src/mock/data.ts +++ b/zhican/admin/src/mock/data.ts @@ -1,5 +1,3 @@ -import { ref } from 'vue' - // ==================== 通用工具 ==================== export const randomId = () => Math.random().toString(36).slice(2, 10) export const randomNum = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min @@ -40,7 +38,7 @@ const supplierNames = ['绿源农业', '丰禾食品', '天然牧场', '鲜美 const materialNames = ['有机大米', '土鸡蛋', '新鲜猪肉', '活鱼', '时令蔬菜', '有机牛奶', '散养鸡', '绿色面粉', '菜籽油', '食用盐'] export function genLandEnvData(n = 12) { - return Array.from({ length: n }, (_, i) => ({ + return Array.from({ length: n }, () => ({ id: randomId(), name: pick(landNames), area: randomFloat(5, 200, 0) + '亩', @@ -372,8 +370,6 @@ export function genProductionStatsData() { } // ==================== 营养用餐 ==================== -const nutrientNames = ['蛋白质', '脂肪', '碳水化合物', '膳食纤维', '维生素A', '维生素C', '钙', '铁', '锌'] - export function genNutritionTestData(n = 12) { return Array.from({ length: n }, () => ({ id: randomId(), diff --git a/zhican/admin/src/utils/request.ts b/zhican/admin/src/utils/request.ts deleted file mode 100644 index 7f02259..0000000 --- a/zhican/admin/src/utils/request.ts +++ /dev/null @@ -1,40 +0,0 @@ -import axios from 'axios' -import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios' -import { message } from 'ant-design-vue' - -const request: AxiosInstance = axios.create({ - baseURL: '/api', - timeout: 15000, -}) - -request.interceptors.request.use( - (config) => { - const token = localStorage.getItem('token') - if (token) { - config.headers.Authorization = `Bearer ${token}` - } - return config - }, - (error) => Promise.reject(error) -) - -request.interceptors.response.use( - (response: AxiosResponse) => { - const { code, msg, data } = response.data - if (code === 0) { - return data - } - message.error(msg || '请求失败') - return Promise.reject(new Error(msg)) - }, - (error) => { - if (error.response?.status === 401) { - localStorage.removeItem('token') - window.location.href = '/login' - } - message.error(error.message || '网络错误') - return Promise.reject(error) - } -) - -export default request diff --git a/zhican/admin/src/views/dashboard/index.vue b/zhican/admin/src/views/dashboard/index.vue index 4fcfed4..77fd05a 100644 --- a/zhican/admin/src/views/dashboard/index.vue +++ b/zhican/admin/src/views/dashboard/index.vue @@ -245,11 +245,9 @@