Files
mayfly-go/frontend/src/hooks/useI18n.ts

95 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-11-20 22:43:53 +08:00
import { i18n } from '@/i18n';
import { ElMessage, ElMessageBox } from 'element-plus';
/**
* rule message
* @param label key
* @returns
*/
export function useI18nPleaseInput(labelI18nKey: string) {
const t = i18n.global.t;
return t('common.pleaseInput', { label: t(labelI18nKey) });
}
/**
* rule message
* @param label key
* @returns
*/
export function useI18nPleaseSelect(labelI18nKey: string) {
const t = i18n.global.t;
return t('common.pleaseSelect', { label: t(labelI18nKey) });
}
/**
*
* @param name
* @returns
*/
export async function useI18nDeleteConfirm(name: string = '') {
2024-11-23 17:23:18 +08:00
return useI18nConfirm('common.deleteConfirm2', { name });
2024-11-20 22:43:53 +08:00
}
/**
*
* @param i18nKey i18n msg key
* @param value i18n msg value
* @returns
*/
export async function useI18nConfirm(i18nKey: string = '', value = {}) {
const t = i18n.global.t;
return ElMessageBox.confirm(t(i18nKey, value), t('common.hint'), {
confirmButtonText: t('common.confirm'),
cancelButtonText: t('common.cancel'),
type: 'warning',
});
}
/**
*
* @param formRef ref
* @param callback
* @returns
*/
export async function useI18nFormValidate(formRef: any) {
const t = i18n.global.t;
try {
await formRef.value.validate();
return true;
} catch (e: any) {
ElMessage.error(t('common.formValidationError'));
throw e;
}
}
export function useI18nCreateTitle(i18nKey: string) {
const t = i18n.global.t;
return t('common.createTitle', { name: t(i18nKey) });
}
export function useI18nEditTitle(i18nKey: string) {
const t = i18n.global.t;
return t('common.editTitle', { name: t(i18nKey) });
}
export function useI18nDetailTitle(i18nKey: string) {
const t = i18n.global.t;
return t('common.detailTitle', { name: t(i18nKey) });
}
export function useI18nOperateSuccessMsg() {
const t = i18n.global.t;
ElMessage.success(t('common.operateSuccess'));
}
export function useI18nSaveSuccessMsg() {
const t = i18n.global.t;
ElMessage.success(t('common.saveSuccess'));
}
export function useI18nDeleteSuccessMsg() {
const t = i18n.global.t;
ElMessage.success(t('common.deleteSuccess'));
}