contractManagement.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * 合同管理相关接口
  3. * 使用独立的 axios 实例,端口为 33333
  4. */
  5. import axios from "axios";
  6. import { ResultEnum } from "@/enums/httpEnum";
  7. import { useUserStore } from "@/stores/modules/user";
  8. import { ElMessage } from "element-plus";
  9. import { LOGIN_URL } from "@/config";
  10. import router from "@/routers";
  11. // 合同接口专用配置 - 使用不同的端口
  12. const CONTRACT_BASE_URL = "http://120.26.186.130:33333";
  13. // 创建专门用于合同接口的 axios 实例
  14. // 注意:不使用 withCredentials,因为认证通过 Authorization header 传递,且服务器 CORS 配置为通配符
  15. const contractAxios = axios.create({
  16. baseURL: CONTRACT_BASE_URL,
  17. timeout: ResultEnum.TIMEOUT as number,
  18. withCredentials: false
  19. });
  20. // 请求拦截:补充 token
  21. contractAxios.interceptors.request.use(
  22. config => {
  23. const userStore = useUserStore();
  24. if (config.headers) {
  25. (config.headers as any).Authorization = userStore.token;
  26. }
  27. return config;
  28. },
  29. error => Promise.reject(error)
  30. );
  31. // 响应拦截:直接返回响应数据
  32. contractAxios.interceptors.response.use(
  33. response => {
  34. const data = response.data;
  35. return data;
  36. },
  37. error => {
  38. ElMessage.error("请求失败,请稍后重试");
  39. return Promise.reject(error);
  40. }
  41. );
  42. /**
  43. * 获取合同列表
  44. * @param {string} storeId - 店铺ID
  45. * @param {object} params - 请求参数 { page, page_size, status, file_name }
  46. * @returns {Promise}
  47. */
  48. export const getContractList = (storeId: string | number, params: any = {}) => {
  49. return contractAxios.get(`/api/store/contracts/${storeId}`, { params });
  50. };
  51. /**
  52. * 获取合同详情
  53. * @param {string} storeId - 店铺ID
  54. * @param {string} contractId - 合同ID
  55. * @returns {Promise}
  56. */
  57. export const getContractDetail = (storeId: string | number, contractId: string | number) => {
  58. return contractAxios.get(`/api/store/contarcts/${storeId}/${contractId}`);
  59. };
  60. /**
  61. * 签署合同
  62. * @param {string} storeId - 店铺ID
  63. * @param {string} contractId - 合同ID
  64. * @param {object} data - 签署数据
  65. * @returns {Promise}
  66. */
  67. export const signContract = (storeId: string | number, contractId: string | number, data: any = {}) => {
  68. return contractAxios.post(`/api/store/contarcts/${storeId}/${contractId}/sign`, data);
  69. };
  70. /**
  71. * 获取合同签署链接(查看合同)
  72. * @param {object} data - 请求参数 { sign_flow_id, contact_phone }
  73. * @returns {Promise}
  74. */
  75. export const getContractSignUrl = (data: any = {}) => {
  76. return contractAxios.post(`/api/store/esign/signurl`, data);
  77. };