🐛 Fixing a bug. 系统管理 国际化管理幂等性问题

This commit is contained in:
aeizzz 2023-03-09 09:12:31 +08:00
parent bdc815a39d
commit 44eefc68f9
4 changed files with 337 additions and 274 deletions

View File

@ -1,4 +1,5 @@
import request from '/@/utils/request';
import { getObjDetails } from '/@/api/admin/param';
export function fetchList(query?: Object) {
return request({
@ -18,11 +19,19 @@ export function addObj(obj?: Object) {
export function getObj(id?: string) {
return request({
url: '/admin/i18n/' + id,
url: '/admin/i18n/details/' + id,
method: 'get',
});
}
export function getObjDetails(obj?: object) {
return request({
url: '/admin/i18n/details/',
method: 'get',
params: obj,
});
}
export function delObj(ids?: object) {
return request({
url: '/admin/i18n',
@ -50,5 +59,50 @@ export function refreshCache() {
return request({
url: '/admin/i18n/sync',
method: 'put',
})
});
}
export function validateName(rule: any, value: any, callback: any, isEdit: boolean) {
if (isEdit) {
return callback();
}
getObjDetails({ name: value }).then((response) => {
const result = response.data;
if (result !== null) {
callback(new Error('国际化编码已经存在'));
} else {
callback();
}
});
}
export function validateZhCn(rule: any, value: any, callback: any, isEdit: boolean) {
if (isEdit) {
return callback();
}
getObjDetails({ zhCn: value }).then((response) => {
const result = response.data;
if (result !== null) {
callback(new Error('国际化中文已经存在'));
} else {
callback();
}
});
}
export function validateEn(rule: any, value: any, callback: any, isEdit: boolean) {
if (isEdit) {
return callback();
}
getObjDetails({ en: value }).then((response) => {
const result = response.data;
if (result !== null) {
callback(new Error('国际化英文已经存在'));
} else {
callback();
}
});
}

View File

@ -1,131 +1,149 @@
<template>
<el-dialog :close-on-click-modal="false" :title="form.id ? $t('common.editBtn') : $t('common.addBtn')" draggable
v-model="visible">
<el-form :model="form" :rules="dataRules" formDialogRef label-width="90px" ref="dataFormRef">
<el-row :gutter="20">
<el-col :span="24" class="mb20">
<el-form-item :label="t('i18n.name')" prop="name">
<el-input :placeholder="t('i18n.inputKeyTip')" v-model="form.name"/>
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item :label="t('i18n.zhCn')" prop="zhCn">
<el-input :placeholder="t('i18n.inputZhCnTip')" v-model="form.zhCn"/>
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-form-item :label="t('i18n.en')" prop="en">
<el-input :placeholder="t('i18n.inputEnTip')" v-model="form.en"/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-dialog :close-on-click-modal="false" :title="form.id ? $t('common.editBtn') : $t('common.addBtn')" draggable v-model="visible">
<el-form :model="form" :rules="dataRules" formDialogRef label-width="90px" ref="dataFormRef">
<el-row :gutter="20">
<el-col :span="12" class="mb20">
<el-form-item :label="t('i18n.name')" prop="name">
<el-input :placeholder="t('i18n.inputKeyTip')" v-model="form.name" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="t('i18n.zhCn')" prop="zhCn">
<el-input :placeholder="t('i18n.inputZhCnTip')" v-model="form.zhCn" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="t('i18n.en')" prop="en">
<el-input :placeholder="t('i18n.inputEnTip')" v-model="form.en" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
<el-button @click="onSubmit" type="primary">{{ $t('common.confirmButtonText') }}</el-button>
</span>
</template>
</el-dialog>
</template>
</el-dialog>
</template>
<script lang="ts" name="SysI18nDialog" setup>
// /
import {useMessage} from '/@/hooks/message';
import {addObj, getObj, putObj} from '/@/api/admin/i18n';
import {useI18n} from 'vue-i18n';
import {rule} from '/@/utils/validate';
// /
import { useMessage } from '/@/hooks/message';
import { addObj, getObj, putObj, validateName, validateZhCn, validateEn } from '/@/api/admin/i18n';
import { useI18n } from 'vue-i18n';
import { rule } from '/@/utils/validate';
import { validateTenantCode } from '/@/api/admin/tenant';
const emit = defineEmits(['refresh']);
const emit = defineEmits(['refresh']);
const {t} = useI18n();
const { t } = useI18n();
//
const dataFormRef = ref();
const visible = ref(false);
//
//
const dataFormRef = ref();
const visible = ref(false);
//
//
const form = reactive({
id: '',
name: '',
zhCn: '',
en: '',
});
//
const form = reactive({
id: '',
name: '',
zhCn: '',
en: '',
});
//
const dataRules = ref({
name: [
{required: true, message: 'name不能为空', trigger: 'blur'},
{validator: rule.noChinese, trigger: 'blur'},
],
zhCn: [
{required: true, message: '中文不能为空', trigger: 'blur'},
],
en: [
{required: true, message: '英文不能为空', trigger: 'blur'},
{validator: rule.letter, trigger: 'blur'},
],
});
//
const dataRules = ref({
name: [
{ required: true, message: 'name不能为空', trigger: 'blur' },
{ validator: rule.noChinese, trigger: 'blur' },
{
validator: (rule: any, value: any, callback: any) => {
validateName(rule, value, callback, form.id !== '');
},
trigger: 'blur',
},
],
zhCn: [
{ required: true, message: '中文不能为空', trigger: 'blur' },
{
validator: (rule: any, value: any, callback: any) => {
validateZhCn(rule, value, callback, form.id !== '');
},
trigger: 'blur',
},
],
en: [
{ required: true, message: '英文不能为空', trigger: 'blur' },
{ validator: rule.letter, trigger: 'blur' },
{
validator: (rule: any, value: any, callback: any) => {
validateEn(rule, value, callback, form.id !== '');
},
trigger: 'blur',
},
],
});
//
const openDialog = (id: string) => {
visible.value = true;
form.id = '';
//
const openDialog = (id: string) => {
visible.value = true;
form.id = '';
//
if (dataFormRef.value) {
dataFormRef.value.resetFields();
}
//
if (dataFormRef.value) {
dataFormRef.value.resetFields();
}
// sysI18n
if (id) {
form.id = id;
getsysI18nData(id);
}
};
// sysI18n
if (id) {
form.id = id;
getsysI18nData(id);
}
};
//
const onSubmit = () => {
dataFormRef.value.validate((valid: boolean) => {
if (!valid) {
return false;
}
//
if (form.id) {
putObj(form)
.then(() => {
useMessage().success(t('common.editSuccessText'));
visible.value = false; //
emit('refresh');
})
.catch((err: any) => {
useMessage().error(err.msg);
});
} else {
addObj(form)
.then(() => {
useMessage().success(t('common.addSuccessText'));
visible.value = false; //
emit('refresh');
})
.catch((err: any) => {
useMessage().error(err.msg);
});
}
});
};
//
const onSubmit = () => {
dataFormRef.value.validate((valid: boolean) => {
if (!valid) {
return false;
}
//
if (form.id) {
putObj(form)
.then(() => {
useMessage().success(t('common.editSuccessText'));
visible.value = false; //
emit('refresh');
})
.catch((err: any) => {
useMessage().error(err.msg);
});
} else {
addObj(form)
.then(() => {
useMessage().success(t('common.addSuccessText'));
visible.value = false; //
emit('refresh');
})
.catch((err: any) => {
useMessage().error(err.msg);
});
}
});
};
//
const getsysI18nData = (id: string) => {
//
getObj(id).then((res: any) => {
Object.assign(form, res.data);
});
};
//
const getsysI18nData = (id: string) => {
//
getObj(id).then((res: any) => {
Object.assign(form, res.data);
});
};
//
defineExpose({
openDialog,
});
//
defineExpose({
openDialog,
});
</script>

View File

@ -1,174 +1,165 @@
<template>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-row class="mb8" v-show="showSearch">
<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList" ref="queryRef">
<el-form-item :label="$t('i18n.name')" prop="name">
<el-input :placeholder="t('i18n.inputKeyTip')" style="max-width: 180px"
v-model="state.queryForm.name"/>
</el-form-item>
<el-form-item :label="$t('i18n.zhCn')" prop="zh-cn">
<el-input :placeholder="t('i18n.inputZhCnTip')" style="max-width: 180px"
v-model="state.queryForm.zhCn"/>
</el-form-item>
<el-form-item :label="$t('i18n.en')" prop="en">
<el-input :placeholder="t('i18n.inputEnTip')" style="max-width: 180px"
v-model="state.queryForm.en"/>
</el-form-item>
<el-form-item class="ml2">
<el-button @click="getDataList" formDialogRef icon="search" type="primary">
{{ $t('common.queryBtn') }}
</el-button>
<el-button @click="resetQuery" formDialogRef icon="Refresh">{{ $t('common.resetBtn') }}
</el-button>
</el-form-item>
</el-form>
</el-row>
<el-row>
<div class="mb8" style="width: 100%">
<el-button @click="formDialogRef.openDialog()" class="ml10" formDialogRef icon="folder-add"
type="primary" v-auth="'admin_i18n_add'">
{{ $t('common.addBtn') }}
</el-button>
<el-button @click="exportExcel" class="ml10" formDialogRef icon="Download" type="primary"
v-auth="'admin_i18n_export'">
{{ $t('common.exportBtn') }}
</el-button>
<el-button
:disabled="multiple"
@click="handleDelete(selectObjs)"
class="ml10"
formDialogRef
icon="Delete"
type="primary"
v-auth="'admin_i18n_del'"
>
{{ $t('common.delBtn') }}
</el-button>
<el-button @click="handleRefreshCache()" class="ml10" icon="refresh-left" type="primary">
{{ $t('common.refreshCacheBtn') }}
</el-button>
<right-toolbar
@queryTable="getDataList"
class="ml10"
style="float: right; margin-right: 20px"
v-model:showSearch="showSearch"
></right-toolbar>
</div>
</el-row>
<el-table
:data="state.dataList"
@selection-change="handleSelectionChange"
@sort-change="sortChangeHandle"
border
style="width: 100%"
v-loading="state.loading"
>
<el-table-column align="center" type="selection" width="60"/>
<el-table-column :label="t('file.index')" type="index" width="80"/>
<el-table-column :label="t('i18n.name')" prop="name" show-overflow-tooltip/>
<el-table-column :label="t('i18n.zhCn')" prop="zhCn" show-overflow-tooltip/>
<el-table-column :label="t('i18n.en')" prop="en" show-overflow-tooltip/>
<el-table-column :label="t('i18n.createBy')" prop="createBy" show-overflow-tooltip/>
<el-table-column :label="t('i18n.createTime')" prop="createTime" show-overflow-tooltip/>
<el-table-column :label="$t('common.action')" width="150">
<template #default="scope">
<el-button @click="formDialogRef.openDialog(scope.row.id)" text type="primary"
v-auth="'admin_i18n_edit'"
>{{ $t('common.editBtn') }}
</el-button>
<el-button @click="handleDelete([scope.row.id])" text type="primary" v-auth="'admin_i18n_del'">
{{ $t('common.delBtn') }}
</el-button>
</template>
</el-table-column>
</el-table>
<pagination @current-change="currentChangeHandle" @size-change="sizeChangeHandle"
v-bind="state.pagination"/>
</div>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-row class="mb8" v-show="showSearch">
<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList" ref="queryRef">
<el-form-item :label="$t('i18n.name')" prop="name">
<el-input :placeholder="t('i18n.inputKeyTip')" style="max-width: 180px" v-model="state.queryForm.name" />
</el-form-item>
<el-form-item :label="$t('i18n.zhCn')" prop="zhCn">
<el-input :placeholder="t('i18n.inputZhCnTip')" style="max-width: 180px" v-model="state.queryForm.zhCn" />
</el-form-item>
<el-form-item :label="$t('i18n.en')" prop="en">
<el-input :placeholder="t('i18n.inputEnTip')" style="max-width: 180px" v-model="state.queryForm.en" />
</el-form-item>
<el-form-item class="ml2">
<el-button @click="getDataList" formDialogRef icon="search" type="primary">
{{ $t('common.queryBtn') }}
</el-button>
<el-button @click="resetQuery" icon="Refresh">{{ $t('common.resetBtn') }} </el-button>
</el-form-item>
</el-form>
</el-row>
<el-row>
<div class="mb8" style="width: 100%">
<el-button @click="formDialogRef.openDialog()" class="ml10" formDialogRef icon="folder-add" type="primary" v-auth="'admin_i18n_add'">
{{ $t('common.addBtn') }}
</el-button>
<el-button @click="exportExcel" class="ml10" formDialogRef icon="Download" type="primary" v-auth="'admin_i18n_export'">
{{ $t('common.exportBtn') }}
</el-button>
<el-button
:disabled="multiple"
@click="handleDelete(selectObjs)"
class="ml10"
formDialogRef
icon="Delete"
type="primary"
v-auth="'admin_i18n_del'"
>
{{ $t('common.delBtn') }}
</el-button>
<el-button @click="handleRefreshCache()" class="ml10" icon="refresh-left" type="primary">
{{ $t('common.refreshCacheBtn') }}
</el-button>
<right-toolbar
@queryTable="getDataList"
class="ml10"
style="float: right; margin-right: 20px"
v-model:showSearch="showSearch"
></right-toolbar>
</div>
</el-row>
<el-table
:data="state.dataList"
@selection-change="handleSelectionChange"
@sort-change="sortChangeHandle"
border
style="width: 100%"
v-loading="state.loading"
>
<el-table-column align="center" type="selection" width="60" />
<el-table-column :label="t('file.index')" type="index" width="80" />
<el-table-column :label="t('i18n.name')" prop="name" show-overflow-tooltip />
<el-table-column :label="t('i18n.zhCn')" prop="zhCn" show-overflow-tooltip />
<el-table-column :label="t('i18n.en')" prop="en" show-overflow-tooltip />
<el-table-column :label="t('i18n.createBy')" prop="createBy" show-overflow-tooltip />
<el-table-column :label="t('i18n.createTime')" prop="createTime" show-overflow-tooltip />
<el-table-column :label="$t('common.action')" width="150">
<template #default="scope">
<el-button @click="formDialogRef.openDialog(scope.row.id)" text type="primary" v-auth="'admin_i18n_edit'"
>{{ $t('common.editBtn') }}
</el-button>
<el-button @click="handleDelete([scope.row.id])" text type="primary" v-auth="'admin_i18n_del'">
{{ $t('common.delBtn') }}
</el-button>
</template>
</el-table-column>
</el-table>
<pagination @current-change="currentChangeHandle" @size-change="sizeChangeHandle" v-bind="state.pagination" />
</div>
<!-- 编辑新增 -->
<form-dialog @refresh="getDataList()" ref="formDialogRef"/>
</div>
<!-- 编辑新增 -->
<form-dialog @refresh="getDataList()" ref="formDialogRef" />
</div>
</template>
<script lang="ts" name="systemSysI18n" setup>
import {BasicTableProps, useTable} from '/@/hooks/table';
import {delObj, fetchList,refreshCache} from '/@/api/admin/i18n';
import {useMessage, useMessageBox} from '/@/hooks/message';
import {useI18n} from 'vue-i18n';
import { BasicTableProps, useTable } from '/@/hooks/table';
import { delObj, fetchList, refreshCache } from '/@/api/admin/i18n';
import { useMessage, useMessageBox } from '/@/hooks/message';
import { useI18n } from 'vue-i18n';
//
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
const { t } = useI18n();
//
//
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
const {t} = useI18n();
//
//
const formDialogRef = ref();
//
const queryRef = ref();
const showSearch = ref(true);
//
const selectObjs = ref([]) as any;
const multiple = ref(true);
//
const formDialogRef = ref();
//
const queryRef = ref();
const showSearch = ref(true);
//
const selectObjs = ref([]) as any;
const multiple = ref(true);
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {
name: '',
zhCn: '',
en: '',
},
pageList: fetchList,
descs: ['create_time'],
});
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {
name: '',
zhCn: '',
en: '',
},
pageList: fetchList,
descs: ['create_time'],
});
// table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile } = useTable(state);
// table hook
const {getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile} = useTable(state);
//
const resetQuery = () => {
//
queryRef.value.resetFields();
//
state.queryForm!.descs = [];
state.queryForm!.ascs = [];
//
selectObjs.value = [];
getDataList();
};
const handleRefreshCache = () => {
refreshCache().then(() => {
useMessage().success('同步成功');
});
};
//
const resetQuery = () => {
//
queryRef.value.resetFields();
//
state.queryForm!.descs = [];
state.queryForm!.ascs = [];
//
selectObjs.value = [];
getDataList();
};
const handleRefreshCache = () => {
refreshCache().then(() => {
useMessage().success('同步成功');
});
};
// excel
const exportExcel = () => {
downBlobFile('/admin/i18n/export', state.queryForm, 'i18n.xlsx');
};
// excel
const exportExcel = () => {
downBlobFile('/admin/i18n/export', state.queryForm, 'i18n.xlsx');
};
//
const handleSelectionChange = (objs: any) => {
objs.forEach((val: any) => {
selectObjs.value.push(val.id);
});
multiple.value = !objs.length;
};
//
const handleSelectionChange = (objs: any) => {
objs.forEach((val: any) => {
selectObjs.value.push(val.id);
});
multiple.value = !objs.length;
};
//
const handleDelete = (ids: string[]) => {
useMessageBox()
.confirm(t('common.delConfirmText'))
.then(() => {
delObj(ids)
.then(() => {
getDataList();
useMessage().success(t('common.delSuccessText'));
})
.catch((err: any) => {
useMessage().error(err.msg);
});
});
};
//
const handleDelete = (ids: string[]) => {
useMessageBox()
.confirm(t('common.delConfirmText'))
.then(() => {
delObj(ids)
.then(() => {
getDataList();
useMessage().success(t('common.delSuccessText'));
})
.catch((err: any) => {
useMessage().error(err.msg);
});
});
};
</script>

View File

@ -103,7 +103,7 @@ const dataRules = reactive({
],
publicKey: [
{ required: true, message: '参数键不能为空', trigger: 'blur' },
{ validator: rule.validatorLowercase, trigger: 'blur' },
{ validator: rule.validatorCapital, trigger: 'blur' },
{
validator: (rule: any, value: any, callback: any) => {
validateParamsCode(rule, value, callback, form.publicId !== '');