style: 字典数据管理多语言

This commit is contained in:
TsMask
2023-11-11 17:25:23 +08:00
parent 7a93768fd0
commit 3389146569
4 changed files with 224 additions and 102 deletions

View File

@@ -21,7 +21,7 @@ import useTabsStore from '@/store/modules/tabs';
import useDictStore from '@/store/modules/dict';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useI18n from '@/hooks/useI18n';
const { t } = useI18n();
const { t, currentLocale } = useI18n();
const tabsStore = useTabsStore();
const { parseDataDict, getDict } = useDictStore();
const route = useRoute();
@@ -30,27 +30,29 @@ const router = useRouter();
// 获取地址栏参数
const dictId = route.params && (route.params.dictId as string);
const zh = currentLocale.value === 'zh_CN';
/**标签类型数据固定项 */
const tagTypeOptions = ref([
{ value: '', label: '普通文本' },
{ value: 'default', label: '默认default' },
{ value: 'blue ', label: '蓝色blue' },
{ value: 'cyan', label: '青色cyan' },
{ value: 'gold', label: '金色gold' },
{ value: 'green', label: '绿色green' },
{ value: 'lime', label: '亮绿lime' },
{ value: 'magenta', label: '紫红magenta' },
{ value: 'orange', label: '橘黄orange' },
{ value: 'pink', label: '粉色pink' },
{ value: 'purple', label: '紫色purple' },
{ value: 'red', label: '红色red' },
{ value: 'yellow', label: '黄色yellow' },
{ value: 'geekblue', label: '深蓝geekblue' },
{ value: 'volcano', label: '棕色volcano' },
{ value: 'processing', label: '进行processing' },
{ value: 'warning', label: '警告warning' },
{ value: 'error', label: '错误error' },
{ value: 'success', label: '成功success' },
{ value: '', label: zh ? '普通文本' : 'Plain text' },
{ value: 'default', label: zh ? '默认default' : 'Default' },
{ value: 'blue ', label: zh ? '蓝色blue' : 'Blue' },
{ value: 'cyan', label: zh ? '青色cyan' : 'Cyan' },
{ value: 'gold', label: zh ? '金色gold' : 'Gold' },
{ value: 'green', label: zh ? '绿色green' : 'Green' },
{ value: 'lime', label: zh ? '亮绿lime' : 'Lime' },
{ value: 'magenta', label: zh ? '紫红magenta' : 'Magenta' },
{ value: 'orange', label: zh ? '橘黄orange' : 'Orange' },
{ value: 'pink', label: zh ? '粉色pink' : 'Pink' },
{ value: 'purple', label: zh ? '紫色purple' : 'Purple' },
{ value: 'red', label: zh ? '红色red' : 'Red' },
{ value: 'yellow', label: zh ? '黄色yellow' : 'Yellow' },
{ value: 'geekblue', label: zh ? '深蓝geekblue' : 'Geekblue' },
{ value: 'volcano', label: zh ? '棕色volcano' : 'Volcano' },
{ value: 'processing', label: zh ? '进行processing' : 'Processing' },
{ value: 'warning', label: zh ? '警告warning' : 'Warning' },
{ value: 'error', label: zh ? '错误error' : 'Error' },
{ value: 'success', label: zh ? '成功success' : 'Success' },
]);
/**字典数据 */
@@ -130,33 +132,33 @@ let tableState: TabeStateType = reactive({
/**表格字段列 */
let tableColumns: ColumnsType = [
{
title: '数据代码',
title: t('views.system.dictData.dictCode'),
dataIndex: 'dictCode',
align: 'center',
},
{
title: '数据标签',
title: t('views.system.dictData.dictLabel'),
dataIndex: 'dictLabel',
align: 'center',
},
{
title: '数据键值',
title: t('views.system.dictData.dictValue'),
dataIndex: 'dictValue',
align: 'center',
},
{
title: '数据排序',
title: t('views.system.dictData.dictSort'),
dataIndex: 'dictSort',
align: 'center',
},
{
title: '数据状态',
title: t('views.system.dictData.status'),
dataIndex: 'status',
key: 'status',
align: 'center',
},
{
title: '创建时间',
title: t('views.system.dictData.createTime'),
dataIndex: 'createTime',
align: 'center',
customRender(opt) {
@@ -165,7 +167,7 @@ let tableColumns: ColumnsType = [
},
},
{
title: '操作',
title: t('common.operate'),
key: 'dictCode',
align: 'center',
},
@@ -189,7 +191,8 @@ let tablePagination = reactive({
showSizeChanger: true,
/**数据总数 */
total: 0,
showTotal: (total: number) => `总共 ${total}`,
showTotal: (total: number) =>
t('common.tablePaginationTotal', { total: total }),
onChange: (page: number, pageSize: number) => {
tablePagination.current = page;
tablePagination.pageSize = pageSize;
@@ -254,10 +257,20 @@ const modalStateFrom = Form.useForm(
modalState.from,
reactive({
dictLabel: [
{ required: true, min: 1, max: 50, message: '请正确输入数据标签' },
{
required: true,
min: 1,
max: 50,
message: t('views.system.dictData.dictLabelPleac'),
},
],
dictValue: [
{ required: true, min: 1, max: 50, message: '请正确输入数据键值' },
{
required: true,
min: 1,
max: 50,
message: t('views.system.dictData.dictValuePleac'),
},
],
})
);
@@ -268,7 +281,7 @@ const modalStateFrom = Form.useForm(
*/
function fnModalVisibleByVive(row: Record<string, string>) {
modalState.from = Object.assign(modalState.from, row);
modalState.title = '字典数据信息';
modalState.title = t('views.system.dictData.viewInfo');
modalState.visibleByView = true;
}
@@ -280,7 +293,7 @@ function fnModalVisibleByEdit(dictCode?: string | number) {
if (!dictCode) {
modalStateFrom.resetFields();
modalState.from.dictType = queryParams.dictType;
modalState.title = '添加字典数据';
modalState.title = t('views.system.dictData.addInfo');
modalState.visibleByEdit = true;
} else {
if (modalState.confirmLoading) return;
@@ -291,10 +304,10 @@ function fnModalVisibleByEdit(dictCode?: string | number) {
hide();
if (res.code === RESULT_CODE_SUCCESS) {
modalState.from = Object.assign(modalState.from, res.data);
modalState.title = '修改字典数据';
modalState.title = t('views.system.dictData.editInfo');
modalState.visibleByEdit = true;
} else {
message.error(`获取字典数据信息失败`, 2);
message.error(t('views.system.dictData.viewInfoErr'), 2);
}
});
}
@@ -317,7 +330,7 @@ function fnModalOk() {
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: `${modalState.title}成功`,
content: t('common.msgSuccess', { msg: modalState.title }),
key,
duration: 2,
});
@@ -337,7 +350,7 @@ function fnModalOk() {
});
})
.catch(e => {
message.error(`请正确填写 ${e.errorFields.length} 处必填信息!`, 2);
message.error(t('common.errorFields', { num: e.errorFields.length }), 2);
});
}
@@ -361,14 +374,14 @@ function fnRecordDelete(dictCode: string = '0') {
}
Modal.confirm({
title: t('common.tipTitle'),
content: `确认删除字典数据代码为 【${dictCode}】 的数据项?`,
content: t('views.system.dictData.delTip', { txt: dictCode }),
onOk() {
const key = 'delData';
message.loading({ content: t('common.loading'), key });
delData(dictCode).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: `删除成功`,
content: t('views.system.dictData.delOk'),
key,
duration: 2,
});
@@ -389,14 +402,14 @@ function fnRecordDelete(dictCode: string = '0') {
function fnExportList() {
Modal.confirm({
title: t('common.tipTitle'),
content: `确认根据搜索条件导出xlsx表格文件吗?`,
content: t('views.system.dictData.exportTip'),
onOk() {
const key = 'exportData';
message.loading({ content: t('common.loading'), key });
exportData(toRaw(queryParams)).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: `已完成导出`,
content: t('views.system.dictData.exportOk'),
key,
duration: 2,
});
@@ -427,7 +440,7 @@ function fnClose() {
function fnGetList(pageNum?: number) {
if (tableState.loading) return;
tableState.loading = true;
if(pageNum){
if (pageNum) {
queryParams.pageNum = pageNum;
}
listData(toRaw(queryParams)).then(res => {
@@ -466,7 +479,7 @@ onMounted(() => {
queryParams.dictType = res.data.dictType;
fnGetList();
} else {
message.error(`获取字典类型信息失败`, 3);
message.error(t('views.system.dictData.typeDataErr'), 3);
}
});
} else {
@@ -487,32 +500,41 @@ onMounted(() => {
<a-form :model="queryParams" name="queryParams" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="6" :md="12" :xs="24">
<a-form-item label="字典名称" name="dictType">
<a-form-item
:label="t('views.system.dictData.dictType')"
name="dictType"
>
<a-select
v-model:value="queryParams.dictType"
:allow-clear="dictId === '0'"
:disabled="dictId !== '0'"
placeholder="请选择字典名称"
:placeholder="t('common.selectPlease')"
:options="dict.sysDictType"
>
</a-select>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item label="数据标签" name="dictLabel">
<a-form-item
:label="t('views.system.dictData.dictLabel')"
name="dictLabel"
>
<a-input
v-model:value="queryParams.dictLabel"
allow-clear
placeholder="请输入数据标签"
:placeholder="t('common.ipnutPlease')"
></a-input>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item label="数据状态" name="status">
<a-form-item
:label="t('views.system.dictData.status')"
name="status"
>
<a-select
v-model:value="queryParams.status"
allow-clear
placeholder="请选择数据状态"
:placeholder="t('common.selectPlease')"
:options="dict.sysNormalDisable"
>
</a-select>
@@ -523,12 +545,12 @@ onMounted(() => {
<a-space :size="8">
<a-button type="primary" @click.prevent="fnGetList(1)">
<template #icon><SearchOutlined /></template>
搜索</a-button
>
{{ t('common.search') }}
</a-button>
<a-button type="default" @click.prevent="fnQueryReset">
<template #icon><ClearOutlined /></template>
重置</a-button
>
{{ t('common.reset') }}
</a-button>
</a-space>
</a-form-item>
</a-col>
@@ -542,7 +564,7 @@ onMounted(() => {
<a-space :size="8" align="center">
<a-button type="default" @click.prevent="fnClose()">
<template #icon><CloseOutlined /></template>
关闭
{{ t('common.close') }}
</a-button>
<a-button
type="primary"
@@ -550,7 +572,7 @@ onMounted(() => {
v-perms:has="['system:dict:add']"
>
<template #icon><PlusOutlined /></template>
新增
{{ t('common.addText') }}
</a-button>
<a-button
type="default"
@@ -560,7 +582,7 @@ onMounted(() => {
v-perms:has="['system:dict:remove']"
>
<template #icon><DeleteOutlined /></template>
删除
{{ t('common.deleteText') }}
</a-button>
<a-button
type="dashed"
@@ -568,7 +590,7 @@ onMounted(() => {
v-perms:has="['system:dict:export']"
>
<template #icon><ExportOutlined /></template>
导出
{{ t('common.export') }}
</a-button>
</a-space>
</template>
@@ -577,31 +599,31 @@ onMounted(() => {
<template #extra>
<a-space :size="8" align="center">
<a-tooltip>
<template #title>搜索栏</template>
<template #title>{{ t('common.searchBarText') }}</template>
<a-switch
v-model:checked="tableState.seached"
checked-children=""
un-checked-children=""
:checked-children="t('common.switch.show')"
:un-checked-children="t('common.switch.hide')"
size="small"
/>
</a-tooltip>
<a-tooltip>
<template #title>表格斑马纹</template>
<template #title>{{ t('common.tableStripedText') }}</template>
<a-switch
v-model:checked="tableState.striped"
checked-children=""
un-checked-children=""
:checked-children="t('common.switch.open')"
:un-checked-children="t('common.switch.shut')"
size="small"
/>
</a-tooltip>
<a-tooltip>
<template #title>刷新</template>
<template #title>{{ t('common.reloadText') }}</template>
<a-button type="text" @click.prevent="fnGetList()">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip placement="topRight">
<template #title>密度</template>
<template #title>{{ t('common.sizeText') }}</template>
<a-dropdown placement="bottomRight" trigger="click">
<a-button type="text">
<template #icon><ColumnHeightOutlined /></template>
@@ -611,9 +633,15 @@ onMounted(() => {
:selected-keys="[tableState.size as string]"
@click="fnTableSize"
>
<a-menu-item key="default">默认</a-menu-item>
<a-menu-item key="middle">中等</a-menu-item>
<a-menu-item key="small">紧凑</a-menu-item>
<a-menu-item key="default">
{{ t('common.size.default') }}
</a-menu-item>
<a-menu-item key="middle">
{{ t('common.size.middle') }}
</a-menu-item>
<a-menu-item key="small">
{{ t('common.size.small') }}
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
@@ -645,7 +673,7 @@ onMounted(() => {
<template v-if="column.key === 'dictCode'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>查看详情</template>
<template #title>{{ t('common.viewText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByVive(record)"
@@ -655,7 +683,7 @@ onMounted(() => {
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>编辑</template>
<template #title>{{ t('common.editText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByEdit(record.dictCode)"
@@ -665,7 +693,7 @@ onMounted(() => {
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>删除</template>
<template #title>{{ t('common.deleteText') }}</template>
<a-button
type="link"
@click.prevent="fnRecordDelete(record.dictCode)"
@@ -690,7 +718,10 @@ onMounted(() => {
<a-form layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="字典名称" name="dictType">
<a-form-item
:label="t('views.system.dictData.dictType')"
name="dictType"
>
{{
dict.sysDictType.find(
item => item.value === modalState.from.dictType
@@ -699,7 +730,10 @@ onMounted(() => {
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="创建时间" name="createTime">
<a-form-item
:label="t('views.system.dictData.createTime')"
name="createTime"
>
<span v-if="+modalState.from.createTime > 0">
{{ parseDateToStr(+modalState.from.createTime) }}
</span>
@@ -708,12 +742,18 @@ onMounted(() => {
</a-row>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="数据代码" name="dictCode">
<a-form-item
:label="t('views.system.dictData.dictCode')"
name="dictCode"
>
{{ modalState.from.dictCode }}
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="数据状态" name="status">
<a-form-item
:label="t('views.system.dictData.status')"
name="status"
>
<DictTag
:options="dict.sysNormalDisable"
:value="modalState.from.status"
@@ -723,19 +763,28 @@ onMounted(() => {
</a-row>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="数据标签" name="dictLabel">
<a-form-item
:label="t('views.system.dictData.dictLabel')"
name="dictLabel"
>
{{ modalState.from.dictLabel }}
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="数据键值" name="dictValue">
<a-form-item
:label="t('views.system.dictData.dictValue')"
name="dictValue"
>
{{ modalState.from.dictValue }}
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="标签类型" name="tagType">
<a-form-item
:label="t('views.system.dictData.tagType')"
name="tagType"
>
<DictTag
:options="tagTypeOptions"
:value="modalState.from.tagType"
@@ -743,14 +792,20 @@ onMounted(() => {
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="样式属性" name="tagClass">
<a-form-item
:label="t('views.system.dictData.tagClass')"
name="tagClass"
>
{{ modalState.from.tagClass }}
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="回显预览" name="tagType">
<a-form-item
:label="t('views.system.dictData.tagTypeShow')"
name="tagType"
>
<DictTag
:options="parseDataDict(modalState.from)"
:value="modalState.from.dictValue"
@@ -758,17 +813,22 @@ onMounted(() => {
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="数据排序" name="dictSort">
<a-form-item
:label="t('views.system.dictData.dictSort')"
name="dictSort"
>
{{ modalState.from.dictSort }}
</a-form-item>
</a-col>
</a-row>
<a-form-item label="数据说明" name="remark">
<a-form-item :label="t('views.system.dictData.remark')" name="remark">
{{ modalState.from.remark }}
</a-form-item>
</a-form>
<template #footer>
<a-button key="cancel" @click="fnModalCancel">关闭</a-button>
<a-button key="cancel" @click="fnModalCancel">
{{ t('common.close') }}
</a-button>
</template>
</a-modal>
@@ -786,11 +846,14 @@ onMounted(() => {
<a-form name="modalStateFrom" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="字典类型" name="dictType">
<a-form-item
:label="t('views.system.dictData.dictType')"
name="dictType"
>
<a-select
v-model:value="modalState.from.dictType"
default-value="sys_oper_type"
placeholder="字典类型"
:placeholder="t('common.selectPlease')"
:options="dict.sysDictType"
:disabled="true"
>
@@ -798,11 +861,14 @@ onMounted(() => {
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="数据状态" name="status">
<a-form-item
:label="t('views.system.dictData.status')"
name="status"
>
<a-select
v-model:value="modalState.from.status"
default-value="0"
placeholder="数据状态"
:placeholder="t('common.selectPlease')"
:options="dict.sysNormalDisable"
>
</a-select>
@@ -812,67 +878,75 @@ onMounted(() => {
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
label="数据标签"
:label="t('views.system.dictData.dictLabel')"
name="dictLabel"
v-bind="modalStateFrom.validateInfos.dictLabel"
>
<a-input
v-model:value="modalState.from.dictLabel"
allow-clear
placeholder="请输入数据标签"
:placeholder="t('views.system.dictData.dictLabelPleac')"
></a-input>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
label="数据键值"
:label="t('views.system.dictData.dictValue')"
name="dictValue"
v-bind="modalStateFrom.validateInfos.dictValue"
>
<a-input
v-model:value="modalState.from.dictValue"
allow-clear
placeholder="请输入数据键值"
:placeholder="t('views.system.dictData.dictValuePleac')"
></a-input>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="标签类型" name="tagType">
<a-form-item
:label="t('views.system.dictData.tagType')"
name="tagType"
>
<a-select
v-model:value="modalState.from.tagType"
placeholder="标签类型"
:placeholder="t('common.selectPlease')"
:options="tagTypeOptions"
>
</a-select>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item label="数据排序" name="dictSort">
<a-form-item
:label="t('views.system.dictData.dictSort')"
name="dictSort"
>
<a-input-number
v-model:value="modalState.from.dictSort"
:min="0"
:max="65535"
placeholder="请输入数据排序"
:placeholder="t('common.ipnutPlease')"
></a-input-number>
</a-form-item>
</a-col>
</a-row>
<a-form-item label="样式属性" name="tagClass">
<a-form-item
:label="t('views.system.dictData.tagClass')"
name="tagClass"
>
<a-input
v-model:value="modalState.from.tagClass"
allow-clear
placeholder="请输入样式属性"
:placeholder="t('common.ipnutPlease')"
></a-input>
</a-form-item>
<a-form-item label="数据说明" name="remark">
<a-form-item :label="t('views.system.dictData.remark')" name="remark">
<a-textarea
v-model:value="modalState.from.remark"
:auto-size="{ minRows: 4, maxRows: 6 }"
:maxlength="450"
:show-count="true"
placeholder="请输入数据说明"
/>
</a-form-item>
</a-form>