i18n.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import request from '/@/utils/request';
  2. import axios from 'axios';
  3. import { decrypt } from '/@/utils/apiCrypto';
  4. export function fetchList(query?: Object) {
  5. return request({
  6. url: '/admin/i18n/page',
  7. method: 'get',
  8. params: query,
  9. });
  10. }
  11. export function addObj(obj?: Object) {
  12. return request({
  13. url: '/admin/i18n',
  14. method: 'post',
  15. data: obj,
  16. });
  17. }
  18. export function getObj(id?: string) {
  19. return request({
  20. url: '/admin/i18n/details/' + id,
  21. method: 'get',
  22. });
  23. }
  24. export function getObjDetails(obj?: object) {
  25. return request({
  26. url: '/admin/i18n/details',
  27. method: 'get',
  28. params: obj,
  29. });
  30. }
  31. export function delObj(ids?: object) {
  32. return request({
  33. url: '/admin/i18n',
  34. method: 'delete',
  35. data: ids,
  36. });
  37. }
  38. export function putObj(obj?: Object) {
  39. return request({
  40. url: '/admin/i18n',
  41. method: 'put',
  42. data: obj,
  43. });
  44. }
  45. export function refreshCache() {
  46. return request({
  47. url: '/admin/i18n/sync',
  48. method: 'put',
  49. });
  50. }
  51. /**
  52. * 注意这里使用原声axios对象进行操作,request 实例中依赖i18n 所以还没有初始化会报错
  53. * @returns
  54. */
  55. export function info() {
  56. return axios.get(import.meta.env.VITE_API_URL + '/admin/i18n/info').then((response) => {
  57. if (response.data.encryption) {
  58. response.data = decrypt(response.data.encryption);
  59. }
  60. return response;
  61. });
  62. }
  63. export function validateName(rule: any, value: any, callback: any, isEdit: boolean) {
  64. if (isEdit) {
  65. return callback();
  66. }
  67. getObjDetails({ name: value }).then((response) => {
  68. const result = response.data;
  69. if (result !== null) {
  70. callback(new Error('国际化编码已经存在'));
  71. } else {
  72. callback();
  73. }
  74. });
  75. }
  76. export function validateZhCn(rule: any, value: any, callback: any, isEdit: boolean) {
  77. if (isEdit) {
  78. return callback();
  79. }
  80. getObjDetails({ zhCn: value }).then((response) => {
  81. const result = response.data;
  82. if (result !== null) {
  83. callback(new Error('国际化中文已经存在'));
  84. } else {
  85. callback();
  86. }
  87. });
  88. }
  89. export function validateEn(rule: any, value: any, callback: any, isEdit: boolean) {
  90. if (isEdit) {
  91. return callback();
  92. }
  93. getObjDetails({ en: value }).then((response) => {
  94. const result = response.data;
  95. if (result !== null) {
  96. callback(new Error('国际化英文已经存在'));
  97. } else {
  98. callback();
  99. }
  100. });
  101. }