增加无权限提醒

This commit is contained in:
liamzi
2025-01-15 15:31:08 +08:00
parent e4db203a9f
commit 81008d0159
13 changed files with 68 additions and 50 deletions

View File

@@ -24,8 +24,6 @@ export const useResources = (initialPagination, initialSorter, type) => {
setCurrentPagination(newPagination); setCurrentPagination(newPagination);
setCurrentSorter(newSorter); setCurrentSorter(newSorter);
console.log(params.searchQuery,'params.searchQuery');
const { data, total: newTotal } = await resourceService.getResources({ const { data, total: newTotal } = await resourceService.getResources({
page: newPagination.current, page: newPagination.current,
pageSize: newPagination.pageSize, pageSize: newPagination.pageSize,
@@ -77,8 +75,6 @@ export const useResources = (initialPagination, initialSorter, type) => {
const deleteResource = async (id) => { const deleteResource = async (id) => {
try { try {
const data= await resourceService.deleteResource(id, type); const data= await resourceService.deleteResource(id, type);
console.log(data,data.length,'data');
if(data?.length>0){ if(data?.length>0){
const newCurrent = const newCurrent =
resources.length === 1 && currentPagination.current > 1 resources.length === 1 && currentPagination.current > 1
@@ -87,7 +83,7 @@ export const useResources = (initialPagination, initialSorter, type) => {
await fetchResources({ current: newCurrent }); await fetchResources({ current: newCurrent });
message.success("删除成功"); message.success("删除成功");
}else{ }else{
throw new Error("no level"); throw new Error("暂无权限");
} }
} catch (error) { } catch (error) {
throw error; throw error;

View File

@@ -1,5 +1,5 @@
import { supabase } from "@/config/supabase"; import { supabase } from "@/config/supabase";
import { message } from "antd";
class SupabaseService { class SupabaseService {
async select(table, options = {}) { async select(table, options = {}) {
try { try {
@@ -60,12 +60,22 @@ class SupabaseService {
.from(table) .from(table)
.insert(data) .insert(data)
.select(); .select();
if (error) {
if (error.code === '42501' || error.status === 403) {
throw new Error('暂无权限:您没有执行此操作的权限');
if (error) throw error; }
throw new Error(error.message || '数据库操作失败');
}
if (result?.length === 0) {
throw new Error('暂无权限:您没有执行此操作的权限');
}
return result; return result;
} catch (error) { } catch (error) {
console.error(`Error inserting into ${table}:`, error.message); // 确保错误始终是 Error 对象
throw error; const errorMessage = error instanceof Error ? error.message : String(error);
console.error(`Insert error for table ${table}:`, errorMessage);
throw new Error(errorMessage);
} }
} }
@@ -83,22 +93,21 @@ class SupabaseService {
} }
const { data, error } = await query.select(); const { data, error } = await query.select();
if(data.length===0) throw '暂无权限' ;
if (error) throw error; if (error) throw error;
return data; return data;
} catch (error) { } catch (error) {
console.error(`Error updating ${table}:`, error.message); throw new Error('更新失败');
throw error;
} }
} }
// 通用 DELETE 请求 // 通用 DELETE 请求
async delete(table, match) { async delete(table, match) {
try { try {
const { error } = await supabase.from(table).delete().match(match); const { data,error } = await supabase.from(table).delete().match(match).select();
if(data.length===0) throw '暂无权限';
if (error) throw error; if (error) throw error;
return true; return data;
} catch (error) { } catch (error) {
console.error(`Error deleting from ${table}:`, error.message); console.error(`Error deleting from ${table}:`, error.message);
throw error; throw error;

View File

@@ -228,8 +228,7 @@ export default function ProjectDetail() {
.select(); .select();
} }
if (result.error) throw result.error; if (result.error||result.data.length===0) throw 'error';
message.success("保存成功"); message.success("保存成功");
navigate("/company/project"); navigate("/company/project");
} catch (error) { } catch (error) {

View File

@@ -268,7 +268,10 @@ const QuotationForm = () => {
} }
if (result.error) throw result.error; if (result.error) throw result.error;
if(result.length===0){
message.error('暂无权限');
return;
};
message.success("保存成功"); message.success("保存成功");
navigate("/company/quotation"); navigate("/company/quotation");
} catch (error) { } catch (error) {

View File

@@ -8,9 +8,9 @@ const ProjectTemplate = ({ form, id, isView }) => {
layout="vertical" layout="vertical"
disabled={isView} disabled={isView}
> >
{/* 专案模板特有的字段和组件 */}
<Card> <Card>
{/* 项目阶段、时间线等内容 */}
</Card> </Card>
</Form> </Form>
); );

View File

@@ -103,21 +103,17 @@ const QuotationTemplate = ({ id, isView, onCancel,isEdit }) => {
}; };
if (id) { if (id) {
// 更新 await supabaseService.update('resources', { id }, serviceData);
await supabaseService.update('resources',
{ id },
serviceData
);
} else { } else {
// 新增
await supabaseService.insert('resources', serviceData); await supabaseService.insert('resources', serviceData);
} }
message.success("保存成功"); message.success("保存成功");
onCancel(); onCancel();
} catch (error) { } catch (error) {
const errorMsg = error instanceof Error ? error.message : '保存失败';
console.error("保存失败:", error); console.error("保存失败:", error);
message.error("保存失败"); message.error(errorMsg);
} finally { } finally {
setLoading(false); setLoading(false);
} }

View File

@@ -104,15 +104,14 @@ const TaskTemplate = ({ id, isView, onCancel,isEdit }) => {
serviceData serviceData
); );
} else { } else {
// 新增
await supabaseService.insert('resources', serviceData); await supabaseService.insert('resources', serviceData);
} }
message.success("保存成功"); message.success("保存成功");
onCancel(); onCancel();
} catch (error) { } catch (error) {
message.error('保存失败');
console.error("保存失败:", error); console.error("保存失败:", error);
message.error("保存失败");
} finally { } finally {
setLoading(false); setLoading(false);
} }

View File

@@ -7,7 +7,6 @@ import TaskTemplate from './components/TaskTemplate';
const { Title } = Typography; const { Title } = Typography;
// 模板类型配置
const TEMPLATE_CONFIG = { const TEMPLATE_CONFIG = {
quotation: { quotation: {
title: '报价单模板', title: '报价单模板',
@@ -36,7 +35,6 @@ const ServiceForm = () => {
if (!currentTemplate) { if (!currentTemplate) {
return <div>无效的模板类型</div>; return <div>无效的模板类型</div>;
} }
return ( return (
<div className="bg-gradient-to-b from-gray-50 to-white dark:from-gray-800 dark:to-gray-900/90 min-h-screen p-2" > <div className="bg-gradient-to-b from-gray-50 to-white dark:from-gray-800 dark:to-gray-900/90 min-h-screen p-2" >
<Card <Card

View File

@@ -88,7 +88,7 @@ const ServicePage = () => {
setData(services || []); setData(services || []);
} catch (error) { } catch (error) {
console.error("获取服务模板失败:", error); console.error("获取服务模板失败:", error);
message.error("获取服<EFBFBD><EFBFBD><EFBFBD>模板失败"); message.error("获取服模板失败");
} finally { } finally {
setLoading(false); setLoading(false);
} }
@@ -127,7 +127,7 @@ const ServicePage = () => {
fetchServices(); fetchServices();
} catch (error) { } catch (error) {
console.error("删除失败:", error); console.error("删除失败:", error);
message.error("删除失败"); message.error(error);
} }
}; };
@@ -173,7 +173,7 @@ const ServicePage = () => {
} }
} catch (error) { } catch (error) {
console.error("保存失败:", error); console.error("保存失败:", error);
message.error("保存失败"); message.error(error);
} }
}; };

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Form, Input, Select, Button, Space, Card, Typography } from 'antd'; import { Form, Input, Select, Button, Space, Card, Typography, message } from 'antd';
import { ArrowLeftOutlined, SaveOutlined } from '@ant-design/icons'; import { ArrowLeftOutlined, SaveOutlined } from '@ant-design/icons';
import { supabase } from '@/config/supabase'; import { supabase } from '@/config/supabase';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
@@ -22,7 +22,6 @@ const SupplierForm = () => {
.select('*') .select('*')
.eq('id', id) .eq('id', id)
.single(); .single();
if (error) throw error; if (error) throw error;
if (id) { if (id) {
@@ -74,10 +73,14 @@ const SupplierForm = () => {
.insert([supplierData]) .insert([supplierData])
.select(); .select();
} }
if(result.data.length===0){
message.error('暂无权限');
return;
};
if (result.error) throw result.error; if (result.error) throw result.error;
navigate('/company/supplier'); navigate('/company/supplier');
} catch (error) { } catch (error) {
message.error('暂无权限');
console.error('保存失败:', error); console.error('保存失败:', error);
} }
}; };

View File

@@ -251,9 +251,7 @@ const TaskPage = () => {
setLoading(true); setLoading(true);
const newAttributes = JSON.parse(JSON.stringify(record.attributes)); const newAttributes = JSON.parse(JSON.stringify(record.attributes));
// 修改任务名称,添加"副本"标识
newAttributes.taskName = `${newAttributes.taskName} (副本)`; newAttributes.taskName = `${newAttributes.taskName} (副本)`;
const { data, error } = await supabase const { data, error } = await supabase
.from("resources") .from("resources")
.insert([ .insert([
@@ -261,10 +259,12 @@ const TaskPage = () => {
type: "task", type: "task",
attributes: newAttributes, attributes: newAttributes,
}, },
]); ]).select()
if(!data||data?.length===0){
message.error('暂无权限');
return;
};
if (error) throw error; if (error) throw error;
message.success("复制成功"); message.success("复制成功");
fetchTasks(); // 刷新列表 fetchTasks(); // 刷新列表
} catch (error) { } catch (error) {

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Card, App, Table, Button, Modal, Form, Select, message, Input, Divider } from 'antd'; import { Card, App, Table, Button, Modal, Form, Select, message, Input, Divider, Popconfirm } from 'antd';
import { PlusOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons'; import { PlusOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons';
import { supabase } from '@/config/supabase'; import { supabase } from '@/config/supabase';
@@ -377,12 +377,19 @@ export default function PermissionManagement() {
setModalVisible(true); setModalVisible(true);
}} }}
/> />
<Popconfirm
title="确认删除"
description="确定要删除这条权限记录吗?"
okText="确认"
cancelText="取消"
onConfirm={() => handleDelete(record.id)}
>
<Button <Button
type="text" type="text"
danger danger
icon={<DeleteOutlined />} icon={<DeleteOutlined />}
onClick={() => handleDelete(record.id)}
/> />
</Popconfirm>
</div> </div>
), ),
}, },

View File

@@ -119,6 +119,14 @@ export const allRoutes = [
icon: "appstore", icon: "appstore",
key: "company/serviceTemplate", key: "company/serviceTemplate",
}, },
{
path: "serviceTemplateInfo/:id?",
hidden: true,
component: lazy(() => import("@/pages/company/service/detail")),
name: "服务模版详情",
icon: "container",
key: "company/serviceTemplateInfo",
},
{ {
path: "supplier", path: "supplier",
component: lazy(() => import("@/pages/company/supplier")), component: lazy(() => import("@/pages/company/supplier")),