多语言

This commit is contained in:
zhang zhuo 2025-06-19 13:53:23 +08:00
parent 81124a6329
commit 2f7a8e90e5
21 changed files with 134 additions and 32 deletions

9
.env.development Normal file
View File

@ -0,0 +1,9 @@
# 页面标题
VITE_APP_TITLE=里派基础框架
# 开发环境配置
VITE_APP_ENV='development'
# 开发环境
VITE_API_BASE='https://dev.api.leapy.cn/merchant/'
VITE_WS_URL='wss://dev.api.leapy.cn/mms'

9
.env.production Normal file
View File

@ -0,0 +1,9 @@
# 页面标题
VITE_APP_TITLE=里派基础框架
# 生产环境配置
VITE_APP_ENV='production'
# 生产环境
VITE_API_BASE='https://dev.api.leapy.cn/merchant/'
VITE_WS_URL='wss://dev.api.leapy.cn/mms'

3
.gitignore vendored
View File

@ -19,4 +19,5 @@ dist
*.njsproj
*.sln
*.sw?
yarn.lock
yarn.lock
package-lock.json

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 leapy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -50,6 +50,7 @@
"@dcloudio/uni-mp-weixin": "3.0.0-4030620241128001",
"@dcloudio/uni-mp-xhs": "3.0.0-4030620241128001",
"@dcloudio/uni-quickapp-webview": "3.0.0-4030620241128001",
"crypto-js": "^4.2.0",
"pinia": "^3.0.3",
"pinia-plugin-persistedstate": "^4.3.0",
"vue": "^3.4.21",
@ -61,6 +62,7 @@
"@dcloudio/uni-cli-shared": "3.0.0-4030620241128001",
"@dcloudio/uni-stacktracey": "3.0.0-4030620241128001",
"@dcloudio/vite-plugin-uni": "3.0.0-4030620241128001",
"@types/crypto-js": "^4.2.2",
"@vue/runtime-core": "^3.4.21",
"@vue/tsconfig": "^0.1.3",
"typescript": "^4.9.4",

View File

@ -1,13 +1,8 @@
<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import {onLaunch} from "@dcloudio/uni-app";
onLaunch(() => {
console.log("App Launch");
});
onShow(() => {
console.log("App Show");
});
onHide(() => {
console.log("App Hide");
console.log('%c PI %c 里派提供技术支持', 'background:#4caf50;color:#fff;border-radius:3px;', '')
});
</script>
<style></style>

0
src/api/index.ts Normal file
View File

0
src/config/index.ts Normal file
View File

6
src/locale/en.json Normal file
View File

@ -0,0 +1,6 @@
{
"system.title": "hello",
"index": {
"title": "user"
}
}

View File

@ -1,7 +1,7 @@
import {createI18n} from 'vue-i18n'
import en from './lang/en'
import zhHans from './lang/zh-cn'
import en from './en.json'
import zhHans from './zh-Hans.json'
const messages = {
en,
@ -9,9 +9,9 @@ const messages = {
}
const i18n = createI18n({
legacy: false,
locale: uni.getLocale(),
messages,
legacy: false
messages
})
export default i18n;

6
src/locale/zh-Hans.json Normal file
View File

@ -0,0 +1,6 @@
{
"system.title": "你好",
"index": {
"title": "用户"
}
}

View File

@ -1,5 +0,0 @@
export default {
system: {
title: 'hello',
},
}

View File

@ -1,5 +0,0 @@
export default {
system: {
title: '你好',
},
}

View File

@ -1,8 +1,8 @@
import { createSSRApp } from "vue";
import App from "./App.vue";
import pinia from "@/stores";
import pinia from "@/store";
import * as Pinia from 'pinia';
import i18n from "@/locales";
import i18n from "@/locale";
export function createApp() {
const app = createSSRApp(App);

View File

@ -1,10 +1,12 @@
{
"name" : "",
"appid" : "",
"name" : "user",
"appid" : "__UNI__8385663",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"locale": "zh-Hans",
"transformPx" : false,
"debug": true,
/* 5+App */
"app-plus" : {
"usingComponents" : true,
@ -50,7 +52,7 @@
"quickapp" : {},
/* */
"mp-weixin" : {
"appid" : "",
"appid" : "wxb6b7d1cc569581b2",
"setting" : {
"urlCheck" : false
},

View File

@ -3,7 +3,7 @@
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
"navigationBarTitleText": "%system.title%"
}
}
],

View File

@ -12,9 +12,8 @@ import {ref} from 'vue'
import {useI18n} from 'vue-i18n'
const {t, locale} = useI18n()
const title = ref(t('system.title'))
const title = ref(t('index.title'))
console.log(title)
</script>

0
src/utils/request.ts Normal file
View File

62
src/utils/tools.ts Normal file
View File

@ -0,0 +1,62 @@
import CryptoJS from 'crypto-js'
const tools = {
data: {
set(cacheKey: string, data: any, expireIn: number = 0) {
let cacheValue = {
content: data,
expireIn: expireIn === 0 ? 0 : new Date().getTime() + expireIn * 1000
}
return uni.setStorageSync(cacheKey, tools.base64.encrypt(JSON.stringify(cacheValue)))
},
get(cacheKey: string) {
try {
const cacheValue = JSON.parse(tools.base64.decrypt(uni.getStorageSync(cacheKey)))
if (cacheValue) {
let nowTime = new Date().getTime()
if (nowTime > cacheValue.expireIn && cacheValue.expireIn !== 0) {
uni.removeStorageSync(cacheKey)
return null;
}
return cacheValue.content
}
return null
} catch (err) {
return null
}
},
remove(cacheKey: string) {
return uni.removeStorageSync(cacheKey)
},
clear() {
return uni.clearStorageSync()
}
},
base64: {
encrypt(data: string) {
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
},
decrypt(cipher: string) {
return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8)
}
},
go: async function (fn: Function) {
try {
let res = await fn
return [res, null]
} catch (err) {
return [null, err]
}
},
crypto: {
//MD5加密
MD5(data: string) {
return CryptoJS.MD5(data).toString()
},
},
objCopy: function (obj: any) {
return JSON.parse(JSON.stringify(obj));
},
}
export default tools

View File

@ -9,5 +9,5 @@
"lib": ["esnext", "dom"],
"types": ["@dcloudio/types"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/*.json"]
}