i18n.ts 2.1 KB

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