增加无权限提醒
This commit is contained in:
@@ -24,8 +24,6 @@ export const useResources = (initialPagination, initialSorter, type) => {
|
||||
|
||||
setCurrentPagination(newPagination);
|
||||
setCurrentSorter(newSorter);
|
||||
console.log(params.searchQuery,'params.searchQuery');
|
||||
|
||||
const { data, total: newTotal } = await resourceService.getResources({
|
||||
page: newPagination.current,
|
||||
pageSize: newPagination.pageSize,
|
||||
@@ -77,8 +75,6 @@ export const useResources = (initialPagination, initialSorter, type) => {
|
||||
const deleteResource = async (id) => {
|
||||
try {
|
||||
const data= await resourceService.deleteResource(id, type);
|
||||
console.log(data,data.length,'data');
|
||||
|
||||
if(data?.length>0){
|
||||
const newCurrent =
|
||||
resources.length === 1 && currentPagination.current > 1
|
||||
@@ -87,7 +83,7 @@ export const useResources = (initialPagination, initialSorter, type) => {
|
||||
await fetchResources({ current: newCurrent });
|
||||
message.success("删除成功");
|
||||
}else{
|
||||
throw new Error("no level");
|
||||
throw new Error("暂无权限");
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { supabase } from "@/config/supabase";
|
||||
|
||||
import { message } from "antd";
|
||||
class SupabaseService {
|
||||
async select(table, options = {}) {
|
||||
try {
|
||||
@@ -60,12 +60,22 @@ class SupabaseService {
|
||||
.from(table)
|
||||
.insert(data)
|
||||
.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;
|
||||
} catch (error) {
|
||||
console.error(`Error inserting into ${table}:`, error.message);
|
||||
throw error;
|
||||
// 确保错误始终是 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();
|
||||
|
||||
if(data.length===0) throw '暂无权限' ;
|
||||
if (error) throw error;
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`Error updating ${table}:`, error.message);
|
||||
throw error;
|
||||
throw new Error('更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 通用 DELETE 请求
|
||||
async delete(table, match) {
|
||||
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;
|
||||
return true;
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`Error deleting from ${table}:`, error.message);
|
||||
throw error;
|
||||
|
||||
@@ -228,8 +228,7 @@ export default function ProjectDetail() {
|
||||
.select();
|
||||
}
|
||||
|
||||
if (result.error) throw result.error;
|
||||
|
||||
if (result.error||result.data.length===0) throw 'error';
|
||||
message.success("保存成功");
|
||||
navigate("/company/project");
|
||||
} catch (error) {
|
||||
|
||||
@@ -268,7 +268,10 @@ const QuotationForm = () => {
|
||||
}
|
||||
|
||||
if (result.error) throw result.error;
|
||||
|
||||
if(result.length===0){
|
||||
message.error('暂无权限');
|
||||
return;
|
||||
};
|
||||
message.success("保存成功");
|
||||
navigate("/company/quotation");
|
||||
} catch (error) {
|
||||
|
||||
@@ -8,9 +8,9 @@ const ProjectTemplate = ({ form, id, isView }) => {
|
||||
layout="vertical"
|
||||
disabled={isView}
|
||||
>
|
||||
{/* 专案模板特有的字段和组件 */}
|
||||
|
||||
<Card>
|
||||
{/* 项目阶段、时间线等内容 */}
|
||||
|
||||
</Card>
|
||||
</Form>
|
||||
);
|
||||
|
||||
@@ -103,21 +103,17 @@ const QuotationTemplate = ({ id, isView, onCancel,isEdit }) => {
|
||||
};
|
||||
|
||||
if (id) {
|
||||
// 更新
|
||||
await supabaseService.update('resources',
|
||||
{ id },
|
||||
serviceData
|
||||
);
|
||||
await supabaseService.update('resources', { id }, serviceData);
|
||||
} else {
|
||||
// 新增
|
||||
await supabaseService.insert('resources', serviceData);
|
||||
}
|
||||
|
||||
message.success("保存成功");
|
||||
onCancel();
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : '保存失败';
|
||||
console.error("保存失败:", error);
|
||||
message.error("保存失败");
|
||||
message.error(errorMsg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -104,15 +104,14 @@ const TaskTemplate = ({ id, isView, onCancel,isEdit }) => {
|
||||
serviceData
|
||||
);
|
||||
} else {
|
||||
// 新增
|
||||
await supabaseService.insert('resources', serviceData);
|
||||
}
|
||||
|
||||
message.success("保存成功");
|
||||
onCancel();
|
||||
} catch (error) {
|
||||
message.error('保存失败');
|
||||
console.error("保存失败:", error);
|
||||
message.error("保存失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import TaskTemplate from './components/TaskTemplate';
|
||||
|
||||
const { Title } = Typography;
|
||||
|
||||
// 模板类型配置
|
||||
const TEMPLATE_CONFIG = {
|
||||
quotation: {
|
||||
title: '报价单模板',
|
||||
@@ -36,7 +35,6 @@ const ServiceForm = () => {
|
||||
if (!currentTemplate) {
|
||||
return <div>无效的模板类型</div>;
|
||||
}
|
||||
|
||||
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" >
|
||||
<Card
|
||||
|
||||
@@ -88,7 +88,7 @@ const ServicePage = () => {
|
||||
setData(services || []);
|
||||
} catch (error) {
|
||||
console.error("获取服务模板失败:", error);
|
||||
message.error("获取服<EFBFBD><EFBFBD><EFBFBD>模板失败");
|
||||
message.error("获取服务模板失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -127,7 +127,7 @@ const ServicePage = () => {
|
||||
fetchServices();
|
||||
} catch (error) {
|
||||
console.error("删除失败:", error);
|
||||
message.error("删除失败");
|
||||
message.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,7 +173,7 @@ const ServicePage = () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("保存失败:", error);
|
||||
message.error("保存失败");
|
||||
message.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 { supabase } from '@/config/supabase';
|
||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||
@@ -22,9 +22,8 @@ const SupplierForm = () => {
|
||||
.select('*')
|
||||
.eq('id', id)
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
|
||||
if (id) {
|
||||
// 设置表单初始值
|
||||
form.setFieldsValue({
|
||||
@@ -74,10 +73,14 @@ const SupplierForm = () => {
|
||||
.insert([supplierData])
|
||||
.select();
|
||||
}
|
||||
|
||||
if(result.data.length===0){
|
||||
message.error('暂无权限');
|
||||
return;
|
||||
};
|
||||
if (result.error) throw result.error;
|
||||
navigate('/company/supplier');
|
||||
} catch (error) {
|
||||
message.error('暂无权限');
|
||||
console.error('保存失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -251,9 +251,7 @@ const TaskPage = () => {
|
||||
setLoading(true);
|
||||
const newAttributes = JSON.parse(JSON.stringify(record.attributes));
|
||||
|
||||
// 修改任务名称,添加"副本"标识
|
||||
newAttributes.taskName = `${newAttributes.taskName} (副本)`;
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("resources")
|
||||
.insert([
|
||||
@@ -261,10 +259,12 @@ const TaskPage = () => {
|
||||
type: "task",
|
||||
attributes: newAttributes,
|
||||
},
|
||||
]);
|
||||
|
||||
]).select()
|
||||
if(!data||data?.length===0){
|
||||
message.error('暂无权限');
|
||||
return;
|
||||
};
|
||||
if (error) throw error;
|
||||
|
||||
message.success("复制成功");
|
||||
fetchTasks(); // 刷新列表
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 { supabase } from '@/config/supabase';
|
||||
|
||||
@@ -377,12 +377,19 @@ export default function PermissionManagement() {
|
||||
setModalVisible(true);
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => handleDelete(record.id)}
|
||||
/>
|
||||
<Popconfirm
|
||||
title="确认删除"
|
||||
description="确定要删除这条权限记录吗?"
|
||||
okText="确认"
|
||||
cancelText="取消"
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
/>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -119,6 +119,14 @@ export const allRoutes = [
|
||||
icon: "appstore",
|
||||
key: "company/serviceTemplate",
|
||||
},
|
||||
{
|
||||
path: "serviceTemplateInfo/:id?",
|
||||
hidden: true,
|
||||
component: lazy(() => import("@/pages/company/service/detail")),
|
||||
name: "服务模版详情",
|
||||
icon: "container",
|
||||
key: "company/serviceTemplateInfo",
|
||||
},
|
||||
{
|
||||
path: "supplier",
|
||||
component: lazy(() => import("@/pages/company/supplier")),
|
||||
|
||||
Reference in New Issue
Block a user