2024-09-30 14:18:02 +08:00
|
|
|
import { h, ref } from 'vue';
|
2024-09-29 16:52:09 +08:00
|
|
|
import { userI18nStore } from '@/store/i18n/i18n';
|
2024-09-30 14:18:02 +08:00
|
|
|
import { addDialog, closeDialog } from '@/components/BaseDialog/index';
|
2024-09-29 23:47:08 +08:00
|
|
|
import I18nDialog from '@/views/i18n/i18n-setting/i18n-dialog.vue';
|
|
|
|
import type { FormProps } from '@/views/i18n/i18n-setting/utils/types';
|
2024-09-30 14:18:02 +08:00
|
|
|
import { $t } from '@/plugins/i18n';
|
2024-09-30 16:21:41 +08:00
|
|
|
import { messageBox } from '@/utils/message';
|
2024-09-29 16:52:09 +08:00
|
|
|
|
2024-09-29 23:47:08 +08:00
|
|
|
export const formRef = ref();
|
2024-09-29 16:52:09 +08:00
|
|
|
const i18nStore = userI18nStore();
|
2024-10-01 17:08:00 +08:00
|
|
|
export const deleteIds = ref([]);
|
2024-09-29 16:52:09 +08:00
|
|
|
|
2025-04-09 13:10:17 +08:00
|
|
|
/* 查询内容 */
|
2024-09-29 23:47:08 +08:00
|
|
|
export const onSearch = async () => {
|
2024-09-29 16:52:09 +08:00
|
|
|
i18nStore.loading = true;
|
|
|
|
await i18nStore.getI18nMangeList();
|
|
|
|
i18nStore.loading = false;
|
|
|
|
};
|
|
|
|
|
2025-04-09 13:10:17 +08:00
|
|
|
/* 下载多语言配置 */
|
|
|
|
export const downloadI18nSetting = () => {
|
|
|
|
i18nStore.downloadI18nSetting();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 行内容添加 打开添加弹窗 */
|
2024-09-29 23:47:08 +08:00
|
|
|
export const onAdd = () => {
|
|
|
|
addDialog({
|
2024-10-24 10:42:44 +08:00
|
|
|
title: $t('addMultilingual'),
|
2024-09-29 23:47:08 +08:00
|
|
|
width: '30%',
|
2024-09-30 14:18:02 +08:00
|
|
|
props: { formInline: { keyName: '', translation: '', typeName: '' } },
|
2024-09-29 23:47:08 +08:00
|
|
|
draggable: true,
|
|
|
|
fullscreenIcon: true,
|
|
|
|
closeOnClickModal: false,
|
|
|
|
contentRenderer: () => h(I18nDialog, { ref: formRef }),
|
2024-09-30 14:18:02 +08:00
|
|
|
footerButtons: [
|
|
|
|
{
|
2024-09-30 16:21:41 +08:00
|
|
|
label: $t('cancel'),
|
2024-09-30 14:18:02 +08:00
|
|
|
text: true,
|
|
|
|
bg: true,
|
|
|
|
btnClick: ({ dialog: { options, index } }) => {
|
|
|
|
closeDialog(options, index);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: $t('buttons.pureConfirm'),
|
|
|
|
type: 'primary',
|
|
|
|
text: true,
|
|
|
|
bg: true,
|
|
|
|
btnClick: ({ dialog: { options, index } }) => {
|
|
|
|
const form = options.props.formInline as FormProps;
|
|
|
|
formRef.value.ruleFormRef.validate(async (valid: any) => {
|
|
|
|
if (!valid) return;
|
2024-09-29 16:52:09 +08:00
|
|
|
|
2024-09-30 14:18:02 +08:00
|
|
|
const result = await i18nStore.addI18n(form);
|
|
|
|
if (!result) return;
|
|
|
|
closeDialog(options, index);
|
|
|
|
await onSearch();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-09-30 16:21:41 +08:00
|
|
|
label: $t('continue_adding'),
|
2024-09-30 14:18:02 +08:00
|
|
|
type: 'success',
|
|
|
|
text: true,
|
|
|
|
bg: true,
|
|
|
|
btnClick: ({ dialog: { options } }) => {
|
|
|
|
const form = options.props.formInline as FormProps;
|
|
|
|
formRef.value.ruleFormRef.validate(async (valid: any) => {
|
|
|
|
if (!valid) return;
|
|
|
|
const result = await i18nStore.addI18n(form);
|
|
|
|
if (!result) return;
|
|
|
|
await onSearch();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2024-09-29 23:47:08 +08:00
|
|
|
});
|
2024-09-29 16:52:09 +08:00
|
|
|
};
|
|
|
|
|
2025-04-09 13:10:17 +08:00
|
|
|
/* 当表格修改时 */
|
2024-09-29 23:47:08 +08:00
|
|
|
export const onUpdate = (row: any) => {
|
|
|
|
const id = row.id;
|
2024-09-29 16:52:09 +08:00
|
|
|
|
2024-09-29 23:47:08 +08:00
|
|
|
addDialog({
|
2024-09-30 16:21:41 +08:00
|
|
|
title: $t('update_multilingual'),
|
2024-09-29 23:47:08 +08:00
|
|
|
width: '30%',
|
2024-09-30 16:21:41 +08:00
|
|
|
props: { formInline: { keyName: row.keyName, translation: row.translation, typeName: row.typeName } },
|
2024-09-29 23:47:08 +08:00
|
|
|
draggable: true,
|
|
|
|
fullscreenIcon: true,
|
|
|
|
closeOnClickModal: false,
|
|
|
|
contentRenderer: () => h(I18nDialog, { ref: formRef }),
|
|
|
|
beforeSure: (done, { options }) => {
|
|
|
|
const form = options.props.formInline as FormProps;
|
|
|
|
formRef.value.ruleFormRef.validate(async (valid: any) => {
|
|
|
|
if (!valid) return;
|
2024-09-29 16:52:09 +08:00
|
|
|
|
2024-09-29 23:47:08 +08:00
|
|
|
const result = await i18nStore.updateI18n({ ...form, id });
|
|
|
|
if (!result) return;
|
|
|
|
done();
|
|
|
|
await onSearch();
|
|
|
|
});
|
|
|
|
},
|
2024-09-29 16:52:09 +08:00
|
|
|
});
|
|
|
|
};
|
2025-04-09 13:10:17 +08:00
|
|
|
|
|
|
|
/* 批量彻底删除行 */
|
2024-09-30 16:21:41 +08:00
|
|
|
export const onDelete = async (row: any) => {
|
2024-09-29 16:52:09 +08:00
|
|
|
const isConfirm = await messageBox({
|
2024-10-24 10:42:44 +08:00
|
|
|
message: $t('confirmDelete'),
|
2024-09-30 16:21:41 +08:00
|
|
|
title: $t('delete_warning'),
|
2024-09-29 16:52:09 +08:00
|
|
|
showMessage: false,
|
2024-09-30 16:21:41 +08:00
|
|
|
confirmMessage: $t('delete_success'),
|
2024-10-24 10:42:44 +08:00
|
|
|
cancelMessage: $t('confirmDelete'),
|
2024-09-29 16:52:09 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (isConfirm) {
|
2024-09-30 16:21:41 +08:00
|
|
|
await i18nStore.deleteI18n([row.id]);
|
2024-09-29 23:47:08 +08:00
|
|
|
await onSearch();
|
2024-09-29 16:52:09 +08:00
|
|
|
}
|
|
|
|
};
|
2024-10-01 17:08:00 +08:00
|
|
|
|
2025-04-09 13:10:17 +08:00
|
|
|
/* 批量删除 */
|
2024-10-01 17:08:00 +08:00
|
|
|
export const onDeleteBatch = async () => {
|
|
|
|
const isConfirm = await messageBox({
|
2024-10-24 10:42:44 +08:00
|
|
|
message: $t('confirmDelete'),
|
2024-10-01 17:08:00 +08:00
|
|
|
title: $t('delete_warning'),
|
|
|
|
showMessage: false,
|
|
|
|
confirmMessage: $t('delete_success'),
|
2024-10-24 10:42:44 +08:00
|
|
|
cancelMessage: $t('confirmDelete'),
|
2024-10-01 17:08:00 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (isConfirm) {
|
|
|
|
await i18nStore.deleteI18n(deleteIds.value);
|
|
|
|
await onSearch();
|
|
|
|
}
|
|
|
|
};
|