feat: 帮助文档多语言文件上传

This commit is contained in:
TsMask
2023-11-24 14:20:59 +08:00
parent 030254db4e
commit 627e579729
8 changed files with 140 additions and 109 deletions

View File

@@ -4,7 +4,7 @@ import { onMounted, reactive } from 'vue';
import useAppStore from '@/store/modules/app';
import useI18n from '@/hooks/useI18n';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { changeValue } from '@/api/system/config';
import { transferHelpDoc } from '@/api/index';
import { uploadFileChunk } from '@/api/tool/file';
import { FileType } from 'ant-design-vue/lib/upload/interface';
import { UploadRequestOption } from 'ant-design-vue/lib/vc-upload/interface';
@@ -12,20 +12,20 @@ import { sessionGet } from '@/utils/cache-session-utils';
import { useRouter } from 'vue-router';
const appStore = useAppStore();
const router = useRouter();
const { t } = useI18n();
const { t, currentLocale, optionsLocale } = useI18n();
type StateType = {
edite: boolean;
loading: boolean;
language: string;
filePath: string;
flag: string;
};
let state: StateType = reactive({
edite: false,
loading: false,
language: '',
filePath: '',
flag: '',
});
/**上传前检查或转换压缩 */
@@ -54,11 +54,6 @@ function fnUpload(up: UploadRequestOption) {
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('views.system.setting.uploadSuccess'), 3);
state.filePath = res.data.fileName;
// 兼容旧前端可改配置文件
const baseUrl = import.meta.env.PROD
? sessionGet('baseUrl') || import.meta.env.VITE_API_BASE_URL
: import.meta.env.VITE_API_BASE_URL;
state.flag = `${baseUrl}${res.data.fileName}`;
} else {
message.error(res.msg, 3);
}
@@ -71,51 +66,30 @@ function fnUpload(up: UploadRequestOption) {
function fnEdit(v: boolean) {
state.edite = v;
if (!v) {
state.filePath = '#';
state.flag = appStore.getHelpDoc;
state.filePath = '';
}
}
/**提交保存 */
function fnSave() {
const item = optionsLocale.find(s => s.value === state.language);
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.system.setting.sysHelpDocTipContent'),
content: t('views.system.setting.sysHelpDocTipContent', {
lang: item?.label,
}),
onOk() {
// 发送请求
const hide = message.loading(t('common.loading'), 0);
state.loading = true;
changeValue({ key: 'sys.helpDoc', value: state.filePath }).then(res => {
transferHelpDoc({
language: state.language,
uploadPath: state.filePath,
}).then(res => {
state.loading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('views.system.setting.saveSuccess'), 3);
appStore.helpDoc = state.filePath;
fnEdit(false);
} else {
message.error(res.msg, 3);
}
});
},
});
}
/**还原清空文件 */
function fnRevert() {
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.system.setting.sysHelpDocTipContentRevert'),
onOk() {
// 发送请求
const hide = message.loading(t('common.loading'), 0);
state.loading = true;
state.filePath = '#';
changeValue({ key: 'sys.helpDoc', value: state.filePath }).then(res => {
state.loading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('views.system.setting.revertSuccess'), 3);
appStore.helpDoc = state.filePath;
fnEdit(false);
} else {
message.error(res.msg, 3);
@@ -126,70 +100,91 @@ function fnRevert() {
}
onMounted(() => {
state.filePath = appStore.getHelpDoc;
state.flag = appStore.getHelpDoc;
state.language = currentLocale.value;
});
</script>
<template>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24" style="margin-bottom: 30px">
<a-form layout="vertical" v-if="state.edite">
<a-form-item>
<a-upload
name="file"
list-type="text"
accept=".pdf"
:max-count="1"
:show-upload-list="false"
:before-upload="fnBeforeUpload"
:custom-request="fnUpload"
>
<a-button type="link" :disabled="state.loading">
{{ t('views.system.setting.uploadFile') }}
<a-form layout="vertical">
<template v-if="state.edite">
<a-form-item>
<a-select
v-model:value="state.language"
style="width: 100px"
size="small"
>
<a-select-option
v-for="opt in optionsLocale"
:key="opt.value"
:value="opt.value"
>
{{ opt.label }}
</a-select-option>
</a-select>
<a-upload
name="file"
list-type="text"
accept=".pdf"
:max-count="1"
:show-upload-list="false"
:before-upload="fnBeforeUpload"
:custom-request="fnUpload"
>
<a-button type="link" :disabled="state.loading">
{{ t('views.system.setting.uploadFile') }}
</a-button>
</a-upload>
</a-form-item>
<a-form-item>
<a-button
type="primary"
:disabled="state.filePath === ''"
@click="fnSave"
>
{{ t('views.system.setting.saveSubmit') }}
</a-button>
</a-upload>
</a-form-item>
<a-button style="margin-left: 10px" @click="fnEdit(false)">
{{ t('common.cancel') }}
</a-button>
</a-form-item>
</template>
<a-form-item>
<a-button
type="primary"
:disabled="state.filePath === state.flag"
@click="fnSave"
>
{{ t('views.system.setting.saveSubmit') }}
<template v-else>
<a-form-item>
<a-space direction="horizontal" :size="18">
<a-select
v-model:value="state.language"
style="width: 100px"
size="small"
>
<a-select-option
v-for="opt in optionsLocale"
:key="opt.value"
:value="opt.value"
>
{{ opt.label }}
</a-select-option>
</a-select>
<a-button
type="link"
:href="'/help?language=' + state.language"
target="_blank"
>
<template #icon>
<QuestionCircleOutlined />
{{ t('views.system.setting.sysHelpDocOpen') }}
</template>
</a-button>
</a-space>
</a-form-item>
<a-button type="default" @click="fnEdit(true)">
{{ t('common.editText') }}
</a-button>
<a-button style="margin-left: 10px" @click="fnEdit(false)">
{{ t('common.cancel') }}
</a-button>
</a-form-item>
</template>
</a-form>
<template v-else>
<a-form-item>
<a-button type="text" v-if="state.flag === '#'">
{{ t('views.system.setting.sysHelpDocNo') }}
</a-button>
<a-button type="link" href="/help" target="_blank" v-else>
<template #icon>
<QuestionCircleOutlined />
{{ t('views.system.setting.sysHelpDocOpen') }}
</template>
</a-button>
</a-form-item>
<a-button type="default" @click="fnEdit(true)">
{{ t('common.editText') }}
</a-button>
<a-button
type="text"
danger
style="margin-left: 10px"
@click="fnRevert"
>
{{ t('views.system.setting.revert') }}
</a-button>
</template>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-typography>