diff --git a/App.vue b/App.vue
index 83f846e367eeac1ef37677100426f615c034c497..418f9dd3923a69330e0a738caed154943b05187e 100644
--- a/App.vue
+++ b/App.vue
@@ -43,31 +43,6 @@
});
}*/
// #endif
-
- let initLanguageAfter = () => {
- console.log('作用于多语言国际化功能,这里获取语言包lang/en.js、lang/zh-Hans.js的tabbar中配置的值更新当前应用的底部tabbar,如果你不需要多语言国际化。直接删除App.vue页面的47-55行即可');
- //底部tabbar更新
- this.$t('tabbar').split(',').forEach((text, index) => {
- uni.setTabBarItem({
- index,
- text,
- complete: e => {
- // console.log("e: " + JSON.stringify(e));
- }
- })
- })
- //更新 uni-starter.config
- //agreements
- let agreementsTitle = this.$t('agreementsTitle').split(',')
- let agreements = getApp().globalData.config.about.agreements
agreements[0].title = agreementsTitle[0]
agreements[1].title = agreementsTitle[1]
getApp().globalData.config.about.agreements = agreements
- }
- setTimeout(()=>{
- initLanguageAfter()
- },1000)
- uni.$on('changeLanguage', e => {
- console.log('changeLanguage',e);
- initLanguageAfter(e)
- })
},
onShow: function() {
console.log('App Show')
diff --git a/README.md b/README.md
index 6589eae5d99f44e66b9647e9d2fd8d6022346b3b..0877cde8c7d5dce1e16efa349dea493fdde97057 100644
--- a/README.md
+++ b/README.md
@@ -61,19 +61,36 @@ uni-starter + uniCloud admin,提供了用户端和管理端的基础模板,
你只需要在项目根目录的框架配置文件:`uni-starter.config.js`的`router`->`needLogin`和`login`中配置完整的路由名称即可:
```js
"router": {
- //needLogin:配置强制需要登陆的页面,在打开这些页面之前会自动检查(前端校验)uni_id_token的值是否有效,如果无效会自动跳转到登陆页面
- "needLogin": [
- "/pages/ucenter/userinfo/userinfo",
- "/uni_modules/uni-news-favorite/pages/uni-news-favorite/list",
- "/uni_modules/uni-feedback/pages/uni-feedback/add"
- ],
- /*
- login:配置登陆类型与优先级
- 未列举到的,或设备环境不支持的选项,将被隐藏。如果你需要在不同平台有不同的配置,直接用条件编译即可
- 根据数组的第0项,决定登录方式的第一优先级。
- 详情下文:2.登录配置详解
- */
- "login": ["username","smsCode","univerify", "weixin", "apple"],
+/*名词解释:“强制登陆页”
+ 在打开定义的需强制登陆的页面之前会自动检查(前端校验)uni_id_token的值是否有效,
+ 如果无效会自动跳转到登陆页面
+两种模式:
+ 1.needLogin:黑名单模式。枚举游客不可访问的页面。
+ 2.visitor:白名单模式。枚举游客可访问的页面。
+* 注意:黑名单与白名单模式二选一 */
+ //needLogin:配置强制需要登陆的页面,在打开这些页面之前会自动检查(前端校验)uni_id_token的值是否有效,如果无效会自动跳转到登陆页面
+ // "needLogin" : [
+ // {pattern:/^\/pages\/list.*/}, //支持正则表达式
+ // "/uni_modules/uni-news-favorite/pages/uni-news-favorite/list",
+ // "/uni_modules/uni-feedback/pages/uni-feedback/add"
+ // ],
+ "visitor" : [
+ "/",//注意入口页必须直接写 "/"
+ {"pattern":/^\/pages\/list.*/}, //支持正则表达式
+ {"pattern":/^\/pages\/ucenter\/login-page.*/},
+ "/pages/common/webview/webview",
+ "/pages/grid/grid",
+ "/pages/ucenter/ucenter",
+ "/pages/ucenter/guestbook/guestbook",
+ "/pages/ucenter/about/about",
+ "/pages/ucenter/settings/settings"
+ ],
+ /*
+ login:配置登陆类型与优先级
+ 未列举到的,或设备环境不支持的选项,将被隐藏。如果你需要在不同平台有不同的配置,直接用条件编译即可
+ 根据数组的第0项,决定登录方式的第一优先级。
+ */
+ "login": ["username","univerify","weixin", "smsCode", "apple"]
}
```
@@ -366,6 +383,10 @@ module.exports = {
"marketId":{
"ios":"id1417078253",
"android":"123456"
+ },
+ //配置多语言国际化。i18n为英文单词 internationalization的首末字符i和n,18为中间的字符数 是“国际化”的简称
+ "i18n":{
+ "enable":false //默认启用,国际化。如果你不想使用国际化相关功能,请改为false
}
}
```
@@ -462,7 +483,6 @@ uni-starter
1. 判断当前用户是否拥有某角色`uniIDHasRole` 演示页面:`/pages/grid/grid` [API文档详情:](https://uniapp.dcloud.io/api/global?id=uniidhasrole)
2. 指纹解锁、人脸解锁 演示页面:`/pages/ucenter/settings/settings` [API文档详情:](https://uniapp.dcloud.io/api/system/authentication)
-
### 注意事项
1. 真机运行需要制作自定义基座,制作后选择运行到自定义基座
2. 苹果登录的图标,需要满足苹果应用市场的审核规范请勿随便修改;如需修改请先阅读:[Sign in with Apple Button](https://appleid.apple.com/signinwithapple/button)
diff --git a/changelog.md b/changelog.md
index 062162adbace00e60f3de1f82169c7a9ca3cac70..94057126c5b37897e2d8c33dda977dd6721d8134 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,11 @@
+## 1.1.15(2021-10-02)
+新增,支持配置是否开启i18n多语言国际化。
+配置文件:`uni-starter.config.js`
+`
+"i18n":{
+ "enable":true //默认启用,国际化。如果你不想使用国际化相关功能,请改为false
+}
+`
## 1.1.14(2021-09-30)
1. 通过微信小程序登陆自动保存`sessionKey`到`uni-id-users`表
2. 我的-设置-个人资料 点击绑定手机号码,完善账号信息支持以下三种策略:
diff --git a/lang/i18n.js b/lang/i18n.js
index 5a3e2211cc8aa5b986994dde3ec5207f58fce73e..51260d801bfcac8e8c59441844e3f354af85d5d4 100644
--- a/lang/i18n.js
+++ b/lang/i18n.js
@@ -1,51 +1,98 @@
-import langEn from './en'
-import zhHans from './zh-Hans'
-const messages = {
- 'en': langEn,
- 'zh-Hans': zhHans
+import langEn from './en'
+import zhHans from './zh-Hans'
+import uniStarterConfig from '../uni-starter.config.js'
+const {i18n:{enable:i18nEnable} }= uniStarterConfig
+const messages = {
+ 'en': langEn,
+ 'zh-Hans': zhHans
}
-let currentLang = uni.getStorageSync('CURRENT_LANG')
+let currentLang
+if(i18nEnable){
+ currentLang = uni.getStorageSync('CURRENT_LANG')
+}else{
+ currentLang = "zh-Hans"
+}
+console.log(uni.getStorageSync('CURRENT_LANG'),currentLang);
if (!currentLang) {
- if(uni.getLocale){
- console.log('获取应用语言:',uni.getLocale() );
- let language = 'zh-Hans'
- if(uni.getLocale() != 'zh-Hans'){
- language = 'en'
- }
- uni.setStorageSync('CURRENT_LANG', language)
- currentLang = language
- }else{
- uni.getSystemInfo({
- success: function (res) {
- console.log('获取设备信息:',res);
- let language = 'zh-Hans'
- if(res.language == 'en'){
- language = 'en'
- }
- uni.setStorageSync('CURRENT_LANG', language)
- currentLang = language
- },
- fail: (err) => {
- console.error(err)
- }
- })
- }
-}
-let i18nConfig = {
- locale: currentLang, // set locale
- messages // set locale messages
-}
-
-// #ifdef VUE2
+ if (uni.getLocale) {
+ console.log('获取应用语言:', uni.getLocale());
+ let language = 'en'
+ if (uni.getLocale() != 'en') {
+ language = 'zh-Hans'
+ }
+ uni.setStorageSync('CURRENT_LANG', language)
+ currentLang = language
+ } else {
+ uni.getSystemInfo({
+ success: function(res) {
+ console.log('获取设备信息:', res);
+ let language = 'zh-Hans'
+ if (res.language == 'en') {
+ language = 'en'
+ }
+ uni.setStorageSync('CURRENT_LANG', language)
+ currentLang = language
+ },
+ fail: (err) => {
+ console.error(err)
+ }
+ })
+ }
+}
+let i18nConfig = {
+ locale: currentLang, // set locale
+ messages // set locale messages
+}
+
+// #ifdef VUE2
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
-const i18n = new VueI18n(i18nConfig)
-// #endif
+const i18n = new VueI18n(i18nConfig)
+// #endif
+
+// #ifdef VUE3
+import {
+ createI18n
+} from 'vue-i18n'
+const i18n = createI18n(i18nConfig)
+// #endif
+
+export default i18n
-// #ifdef VUE3
-import {createI18n} from 'vue-i18n'
-const i18n = createI18n(i18nConfig)
-// #endif
-export default i18n
\ No newline at end of file
+if(i18nEnable){
+ console.log(1);
+ let initLanguageAfter = () => {
+ //获得定义的文字
+ console.log($i18n('tabbar').split(','));
+ function $i18n(e){
+ return i18n.messages[i18n.locale][e]
+ }
+ setTimeout(function(){
+ //底部tabbar更新
+ $i18n('tabbar').split(',').forEach((text, index) => {
+ console.log(text);
+ uni.setTabBarItem({
+ index,
+ text,
+ complete: e => {
+ console.log("e: " + JSON.stringify(e));
+ }
+ })
+ })
+ },1)
+ //更新 uni-starter.config
+ //agreements
+ let agreementsTitle = $i18n('agreementsTitle').split(',')
+ let agreements = uniStarterConfig.about.agreements
+ agreements[0].title = agreementsTitle[0]
+ agreements[1].title = agreementsTitle[1]
+ uniStarterConfig.about.agreements = agreements
+ }
+ initLanguageAfter()
+ uni.$on('changeLanguage', e => {
+ console.log('changeLanguage', e);
+ initLanguageAfter(e)
+ })
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index 2462f87fb60dd818d826b5261b8f9eadb6ecbf17..27c26d63c88bea50cb5554165b9d7ea09f07118b 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"id": "uni-starter",
"displayName": "uni-starter",
- "version": "1.1.14",
+ "version": "1.1.15",
"description": "云端一体应用快速开发基本项目模版",
"keywords": [
"login",
diff --git a/pages/list/list.nvue b/pages/list/list.nvue
index 7cfea1b82e1e0d1ae0432d098e2b4830a16a1659..e184fec8e324a66ae38cfebaacd93a9888ba42ca 100644
--- a/pages/list/list.nvue
+++ b/pages/list/list.nvue
@@ -138,7 +138,7 @@
console.log('refresh');
},
onqueryerror(e) {
- console.log(e);
+ console.error(e);
}
},
onPullDownRefresh() {
diff --git a/pages/ucenter/settings/settings.vue b/pages/ucenter/settings/settings.vue
index 342134452dfe8cffe86c935dd87e731171f11ac7..198fcf657c80bb007d64c0d5e55b420560cafd93 100644
--- a/pages/ucenter/settings/settings.vue
+++ b/pages/ucenter/settings/settings.vue
@@ -15,7 +15,7 @@
-
+
@@ -50,7 +50,10 @@
...mapGetters({
'userInfo': 'user/info',
'hasLogin': 'user/hasLogin',
- })
+ }),
+ i18nEnable(){
+ return getApp().globalData.config.i18n.enable
+ }
},
onLoad() {
this.uniToken = uni.getStorageSync('uni_id_token')
diff --git a/uni-starter.config.js b/uni-starter.config.js
index 48d43012fdfc595125be7ec5c13f48c0fae1dc04..c29676986977fd7f0d32b35a0eeb1b6ed25a50b1 100644
--- a/uni-starter.config.js
+++ b/uni-starter.config.js
@@ -86,5 +86,9 @@ export default {
"marketId":{
"ios":"id1417078253",
"android":"123456"
+ },
+ //配置多语言国际化。i18n为英文单词 internationalization的首末字符i和n,18为中间的字符数 是“国际化”的简称
+ "i18n":{
+ "enable":true //默认启用,国际化。如果你不想使用国际化相关功能,请改为false
}
}
diff --git a/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback.vue b/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback.vue
index 40db16bf6d4144e07035b376df32e8e92aa1ee53..9c30b673f484ec0f120b7efabfd67178b0746358 100644
--- a/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback.vue
+++ b/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback.vue
@@ -26,7 +26,6 @@
import {
validator
} from '../../js_sdk/validator/opendb-feedback.js';
- console.log(validator);
const db = uniCloud.database();
const dbCollectionName = 'opendb-feedback';