feat(script): add i18n script
This commit is contained in:
parent
58932b9870
commit
e035c525d1
|
@ -23,5 +23,5 @@ ENV = 'development'
|
||||||
#VUE_APP_BASE_API = 'http://192.168.31.159:8080'
|
#VUE_APP_BASE_API = 'http://192.168.31.159:8080'
|
||||||
|
|
||||||
#测试
|
#测试
|
||||||
#VUE_APP_BASE_API = 'http://a1.hzs413.com/prod-api'
|
VUE_APP_BASE_API = 'http://a1.hzs413.com/prod-api'
|
||||||
VUE_APP_BASE_API = 'http://127.0.0.1:8080'
|
# VUE_APP_BASE_API = 'http://127.0.0.1:8080'
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const { glob } = require('glob')
|
||||||
|
|
||||||
|
// 读取中文语言包
|
||||||
|
const zhCN = require('../i8n.js')
|
||||||
|
|
||||||
|
// 递归获取所有需要处理的文件
|
||||||
|
async function getAllFiles(dir, patterns) {
|
||||||
|
console.log('搜索目录:', dir)
|
||||||
|
console.log('搜索模式:', patterns)
|
||||||
|
const files = await glob(patterns, {
|
||||||
|
cwd: dir,
|
||||||
|
ignore: ['node_modules/**', 'dist/**', '**/i18n/**', '**/languages/**']
|
||||||
|
})
|
||||||
|
console.log('找到的文件数量:', files.length)
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取嵌套对象的值
|
||||||
|
function getNestedValue(obj, path) {
|
||||||
|
return path.split('.').reduce((current, key) => current && current[key], obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 替换文件内容
|
||||||
|
function replaceContent(content) {
|
||||||
|
// 替换模板中的 $t('key')
|
||||||
|
content = content.replace(
|
||||||
|
/(?<!this\.|that\.)\$t\(['"]([^'"]+)['"]\)/g,
|
||||||
|
(match, key) => {
|
||||||
|
const value = getNestedValue(zhCN, key)
|
||||||
|
return value ? `'${value}'` : match
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 替换 JavaScript 中的 this.$t('key')
|
||||||
|
content = content.replace(/this\.\$t\(['"]([^'"]+)['"]\)/g, (match, key) => {
|
||||||
|
const value = getNestedValue(zhCN, key)
|
||||||
|
return value ? `'${value}'` : match
|
||||||
|
})
|
||||||
|
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主函数
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
const srcPath = path.resolve(__dirname, '../src')
|
||||||
|
console.log('源文件目录:', srcPath)
|
||||||
|
|
||||||
|
// 只处理 views 和 components 目录
|
||||||
|
const patterns = [
|
||||||
|
'views/**/*.vue',
|
||||||
|
'views/**/*.js',
|
||||||
|
'views/**/*.ts',
|
||||||
|
'components/**/*.vue',
|
||||||
|
'components/**/*.js',
|
||||||
|
'components/**/*.ts'
|
||||||
|
]
|
||||||
|
|
||||||
|
const files = await getAllFiles(srcPath, patterns)
|
||||||
|
|
||||||
|
if (files.length === 0) {
|
||||||
|
console.log('警告:没有找到匹配的文件!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const filePath = path.resolve(srcPath, file)
|
||||||
|
console.log('处理文件:', filePath)
|
||||||
|
|
||||||
|
const content = fs.readFileSync(filePath, 'utf8')
|
||||||
|
const newContent = replaceContent(content)
|
||||||
|
|
||||||
|
if (newContent !== content) {
|
||||||
|
fs.writeFileSync(filePath, newContent, 'utf8')
|
||||||
|
console.log(`已处理文件: ${file}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('所有文件处理完成!')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('处理过程中出错:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
|
@ -7,24 +7,34 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<el-form :model="ruleForm"
|
<el-form
|
||||||
:rules="rules"
|
ref="ruleForm"
|
||||||
ref="ruleForm"
|
:model="ruleForm"
|
||||||
label-width="100px"
|
:rules="rules"
|
||||||
class="demo-ruleForm">
|
label-width="100px"
|
||||||
<el-form-item :label="$t('MN_F_T_286')"
|
class="demo-ruleForm"
|
||||||
prop="name">
|
>
|
||||||
<el-radio-group v-model="ruleForm.functionType"
|
<el-form-item
|
||||||
@change="getRadio">
|
:label="$t('MN_F_T_286')"
|
||||||
<el-radio :label="item.value"
|
prop="name"
|
||||||
:disabled="lookOver"
|
>
|
||||||
v-for="item in funcList"
|
<el-radio-group
|
||||||
:key="item.value">{{ item.label }}</el-radio>
|
v-model="ruleForm.functionType"
|
||||||
|
@change="getRadio"
|
||||||
|
>
|
||||||
|
<el-radio
|
||||||
|
v-for="item in funcList"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.value"
|
||||||
|
:disabled="lookOver"
|
||||||
|
>{{ item.label }}</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label=""
|
<el-form-item
|
||||||
prop="name">
|
label=""
|
||||||
|
prop="name"
|
||||||
|
>
|
||||||
<!-- <el-checkbox-group v-model="ruleForm.websiteTypes">
|
<!-- <el-checkbox-group v-model="ruleForm.websiteTypes">
|
||||||
<el-checkbox :label="item.value"
|
<el-checkbox :label="item.value"
|
||||||
v-for="item in webList"
|
v-for="item in webList"
|
||||||
|
@ -32,139 +42,187 @@
|
||||||
)"
|
)"
|
||||||
:key="item.value">{{ item.label }}</el-checkbox>
|
:key="item.value">{{ item.label }}</el-checkbox>
|
||||||
</el-checkbox-group> -->
|
</el-checkbox-group> -->
|
||||||
<el-radio-group v-model="ruleForm.websiteType"
|
<el-radio-group
|
||||||
@change="getRadios">
|
v-model="ruleForm.websiteType"
|
||||||
<el-radio :label="item.value"
|
@change="getRadios"
|
||||||
:disabled="lookOver||(item.value==2&&ruleForm.functionType == 2
|
>
|
||||||
)"
|
<el-radio
|
||||||
v-for="item in webList"
|
v-for="item in webList"
|
||||||
:key="item.value">{{ item.label }}</el-radio>
|
:key="item.value"
|
||||||
|
:label="item.value"
|
||||||
|
:disabled="lookOver||(item.value==2&&ruleForm.functionType == 2
|
||||||
|
)"
|
||||||
|
>{{ item.label }}</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="22">
|
<el-col :span="22">
|
||||||
<el-form-item :label="$t('MN_F_T_287')"
|
<el-form-item
|
||||||
prop="name">
|
:label="$t('MN_F_T_287')"
|
||||||
<el-input clearable
|
prop="name"
|
||||||
v-model="ruleForm.title"
|
>
|
||||||
:disabled="lookOver"></el-input>
|
<el-input
|
||||||
|
v-model="ruleForm.title"
|
||||||
|
clearable
|
||||||
|
:disabled="lookOver"
|
||||||
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-form-item :label="$t('w_0445')"
|
<el-form-item
|
||||||
prop="name">
|
:label="$t('w_0445')"
|
||||||
<el-date-picker :disabled="lookOver"
|
prop="name"
|
||||||
v-model="ruleForm.effectiveDate"
|
>
|
||||||
type="datetime"
|
<el-date-picker
|
||||||
value-format="yyyy-MM-dd HH:mm:ss"
|
v-model="ruleForm.effectiveDate"
|
||||||
:placeholder="$t('CK_KS_38')"
|
:disabled="lookOver"
|
||||||
default-time="00:00:00">
|
type="datetime"
|
||||||
</el-date-picker>
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
|
:placeholder="$t('CK_KS_38')"
|
||||||
|
default-time="00:00:00"
|
||||||
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form-item :label="$t('w_0437')"
|
<el-form-item
|
||||||
prop="name">
|
:label="$t('w_0437')"
|
||||||
<el-date-picker :disabled="lookOver"
|
prop="name"
|
||||||
v-model="ruleForm.ruleFormTime"
|
>
|
||||||
@change="changeTime"
|
<el-date-picker
|
||||||
value-format="yyyy-MM-dd HH:mm:ss"
|
v-model="ruleForm.ruleFormTime"
|
||||||
type="datetimerange"
|
:disabled="lookOver"
|
||||||
:range-separator="$t('w_0139')"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
:start-placeholder="$t('CK_KS_4')"
|
type="datetimerange"
|
||||||
:end-placeholder="$t('CK_KS_5')">
|
:range-separator="$t('w_0139')"
|
||||||
</el-date-picker>
|
:start-placeholder="$t('CK_KS_4')"
|
||||||
|
:end-placeholder="$t('CK_KS_5')"
|
||||||
|
@change="changeTime"
|
||||||
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="6"
|
<el-col
|
||||||
v-show="ruleForm.websiteType == 1">
|
v-show="ruleForm.websiteType == 1"
|
||||||
|
:span="6"
|
||||||
|
>
|
||||||
<el-form-item :label="$t('MN_F_T_290')">
|
<el-form-item :label="$t('MN_F_T_290')">
|
||||||
<el-select clearable
|
<el-select
|
||||||
:disabled="lookOver"
|
v-model="ruleForm.publishLocations"
|
||||||
:placeholder="$t('CK_KS_38')"
|
clearable
|
||||||
multiple
|
:disabled="lookOver"
|
||||||
v-model="ruleForm.publishLocations">
|
:placeholder="$t('CK_KS_38')"
|
||||||
<el-option v-for="item in localList"
|
multiple
|
||||||
:key="item.value"
|
>
|
||||||
:label="item.label"
|
<el-option
|
||||||
:value="item.value"></el-option>
|
v-for="item in localList"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6"
|
<el-col
|
||||||
v-show="ruleForm.websiteType == 1">
|
v-show="ruleForm.websiteType == 1"
|
||||||
|
:span="6"
|
||||||
|
>
|
||||||
<el-form-item :label="$t('ENU_NOTICE_TYPE_1')">
|
<el-form-item :label="$t('ENU_NOTICE_TYPE_1')">
|
||||||
<el-select clearable
|
<el-select
|
||||||
:disabled="lookOver"
|
v-model="ruleForm.grades"
|
||||||
:placeholder="$t('CK_KS_38')"
|
clearable
|
||||||
multiple
|
:disabled="lookOver"
|
||||||
v-model="ruleForm.grades">
|
:placeholder="$t('CK_KS_38')"
|
||||||
<el-option v-for="item in gradeList"
|
multiple
|
||||||
:key="item.pkId"
|
>
|
||||||
:label="item.gradeName"
|
<el-option
|
||||||
:value="item.pkId"></el-option>
|
v-for="item in gradeList"
|
||||||
|
:key="item.pkId"
|
||||||
|
:label="item.gradeName"
|
||||||
|
:value="item.pkId"
|
||||||
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6"
|
<el-col
|
||||||
v-show="ruleForm.websiteType == 2">
|
v-show="ruleForm.websiteType == 2"
|
||||||
|
:span="6"
|
||||||
|
>
|
||||||
<el-form-item :label="$t('MN_F_T_291')">
|
<el-form-item :label="$t('MN_F_T_291')">
|
||||||
<el-select clearable
|
<el-select
|
||||||
:placeholder="$t('CK_KS_38')"
|
v-model="ruleForm.role"
|
||||||
v-model="ruleForm.role">
|
clearable
|
||||||
<el-option v-for="item in jsList"
|
:placeholder="$t('CK_KS_38')"
|
||||||
:key="item.roleId"
|
>
|
||||||
:label="item.roleName"
|
<el-option
|
||||||
:value="item.roleId"></el-option>
|
v-for="item in jsList"
|
||||||
|
:key="item.roleId"
|
||||||
|
:label="item.roleName"
|
||||||
|
:value="item.roleId"
|
||||||
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-form-item :label="$t('MN_F_T_292')">
|
<el-form-item :label="$t('MN_F_T_292')">
|
||||||
<el-select clearable
|
<el-select
|
||||||
:disabled="lookOver"
|
v-model="ruleForm.isPopScreen"
|
||||||
:placeholder="$t('CK_KS_38')"
|
clearable
|
||||||
v-model="ruleForm.isPopScreen">
|
:disabled="lookOver"
|
||||||
<el-option v-for="item in popList"
|
:placeholder="$t('CK_KS_38')"
|
||||||
:key="item.value"
|
>
|
||||||
:label="item.label"
|
<el-option
|
||||||
:value="item.value"></el-option>
|
v-for="item in popList"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="22">
|
<el-col :span="22">
|
||||||
<el-form-item :label="$t('MN_F_T_295')"
|
<el-form-item
|
||||||
v-if="lookOver">
|
v-if="lookOver"
|
||||||
<editor ref="sptwEditor"
|
:label="$t('MN_F_T_295')"
|
||||||
:readOnly="lookOver"
|
>
|
||||||
v-model="ruleForm.content"
|
<editor
|
||||||
:min-height="196"
|
ref="sptwEditor"
|
||||||
:uploadUrl="uploadImgUrl" />
|
v-model="ruleForm.content"
|
||||||
|
:read-only="lookOver"
|
||||||
|
:min-height="196"
|
||||||
|
:upload-url="uploadImgUrl"
|
||||||
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('MN_F_T_295')"
|
<el-form-item
|
||||||
v-else>
|
v-else
|
||||||
<editor ref="sptwEditor"
|
:label="$t('MN_F_T_295')"
|
||||||
v-model="ruleForm.content"
|
>
|
||||||
:min-height="196"
|
<editor
|
||||||
:uploadUrl="uploadImgUrl" />
|
ref="sptwEditor"
|
||||||
|
v-model="ruleForm.content"
|
||||||
|
:min-height="196"
|
||||||
|
:upload-url="uploadImgUrl"
|
||||||
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<el-button size="small"
|
<el-button
|
||||||
class="thebtn2"> {{ $t('ENU_P_TYPE0') }}</el-button>
|
size="small"
|
||||||
<el-button size="small"
|
class="thebtn2"
|
||||||
@click="submit"
|
> {{ $t('ENU_P_TYPE0') }}</el-button>
|
||||||
v-has-buttons="['EmailedAdd']"
|
<el-button
|
||||||
class="thebtn1"> {{ $t('MN_F_32') }}</el-button>
|
v-has-buttons="['EmailedAdd']"
|
||||||
|
size="small"
|
||||||
|
class="thebtn1"
|
||||||
|
@click="submit"
|
||||||
|
> {{ $t('MN_F_32') }}</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -174,7 +232,7 @@ import Editor from '@/components/Editor'
|
||||||
import * as api from '@/api/notice.js'
|
import * as api from '@/api/notice.js'
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
Editor,
|
Editor
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -185,7 +243,7 @@ export default {
|
||||||
endTime: '',
|
endTime: '',
|
||||||
websiteTypes: [],
|
websiteTypes: [],
|
||||||
publishLocations: [],
|
publishLocations: [],
|
||||||
grades: [],
|
grades: []
|
||||||
},
|
},
|
||||||
rules: {},
|
rules: {},
|
||||||
localList: [],
|
localList: [],
|
||||||
|
@ -196,13 +254,13 @@ export default {
|
||||||
funcList: [],
|
funcList: [],
|
||||||
jsList: [],
|
jsList: [],
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
lookOver: false,
|
lookOver: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.pkId = this.$route.query.pkId || ''
|
this.pkId = this.$route.query.pkId || ''
|
||||||
this.isAdmin = this.$route.query.isAdmin || false
|
this.isAdmin = this.$route.query.isAdmin || false
|
||||||
this.lookOver = this.$route.query.type == 1 ? true : false
|
this.lookOver = this.$route.query.type == 1
|
||||||
this.getData()
|
this.getData()
|
||||||
if (this.pkId != '') {
|
if (this.pkId != '') {
|
||||||
this.getDetails()
|
this.getDetails()
|
||||||
|
@ -229,7 +287,7 @@ export default {
|
||||||
getDetails() {
|
getDetails() {
|
||||||
api
|
api
|
||||||
.noticeDetails({
|
.noticeDetails({
|
||||||
pkId: this.pkId,
|
pkId: this.pkId
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.ruleForm = res.data
|
this.ruleForm = res.data
|
||||||
|
@ -248,7 +306,7 @@ export default {
|
||||||
|
|
||||||
this.$set(this.ruleForm, 'ruleFormTime', [
|
this.$set(this.ruleForm, 'ruleFormTime', [
|
||||||
this.ruleForm.startTime,
|
this.ruleForm.startTime,
|
||||||
this.ruleForm.endTime,
|
this.ruleForm.endTime
|
||||||
])
|
])
|
||||||
this.$forceUpdate()
|
this.$forceUpdate()
|
||||||
})
|
})
|
||||||
|
@ -280,7 +338,7 @@ export default {
|
||||||
this.ruleForm.grade = this.ruleForm.grades.join(',')
|
this.ruleForm.grade = this.ruleForm.grades.join(',')
|
||||||
this.ruleForm.publishLocation = this.ruleForm.publishLocations.join(',')
|
this.ruleForm.publishLocation = this.ruleForm.publishLocations.join(',')
|
||||||
this.ruleForm.websiteType
|
this.ruleForm.websiteType
|
||||||
let obj = Object.assign({}, this.ruleForm, { pkId: this.pkId })
|
const obj = Object.assign({}, this.ruleForm, { pkId: this.pkId })
|
||||||
let urlRequest = ''
|
let urlRequest = ''
|
||||||
|
|
||||||
if (this.pkId != '') {
|
if (this.pkId != '') {
|
||||||
|
@ -292,11 +350,11 @@ export default {
|
||||||
urlRequest(obj).then((res) => {
|
urlRequest(obj).then((res) => {
|
||||||
this.$message({
|
this.$message({
|
||||||
message: this.$t('MN_F_T_477'),
|
message: this.$t('MN_F_T_477'),
|
||||||
type: 'success',
|
type: 'success'
|
||||||
})
|
})
|
||||||
|
|
||||||
this.$router.replace({
|
this.$router.replace({
|
||||||
path: '/announcement/email',
|
path: '/announcement/email'
|
||||||
})
|
})
|
||||||
|
|
||||||
// console.log(
|
// console.log(
|
||||||
|
@ -305,8 +363,8 @@ export default {
|
||||||
// res
|
// res
|
||||||
// )
|
// )
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@ module.exports = {
|
||||||
'@': resolve('src')
|
'@': resolve('src')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
externals:{
|
externals: {
|
||||||
'zhCN':'zhCN',
|
'zhCN': 'zhCN',
|
||||||
'enUS':'enUS',
|
'enUS': 'enUS',
|
||||||
'zhTC':'zhTC',
|
'zhTC': 'zhTC',
|
||||||
'ruRU':'ruRU',
|
'ruRU': 'ruRU',
|
||||||
'frFR':'frFR',
|
'frFR': 'frFR'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
chainWebpack(config) {
|
chainWebpack(config) {
|
||||||
|
|
Loading…
Reference in New Issue