Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
0afa02f1
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0afa02f1
编写于
9月 02, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(i18n): getLocale,setLocale,onLocaleChange
上级
afe4d8e3
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
404 addition
and
174 deletion
+404
-174
lib/apis.js
lib/apis.js
+3
-2
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+294
-137
packages/uni-app-plus/dist/view.umd.min.js
packages/uni-app-plus/dist/view.umd.min.js
+2
-2
packages/uni-h5/dist/index.umd.min.js
packages/uni-h5/dist/index.umd.min.js
+1
-1
packages/uni-h5/manifest.json
packages/uni-h5/manifest.json
+16
-0
src/core/helpers/i18n/index.js
src/core/helpers/i18n/index.js
+19
-0
src/core/service/api/ui/locale.js
src/core/service/api/ui/locale.js
+44
-4
src/core/service/plugins/app/create-app.js
src/core/service/plugins/app/create-app.js
+8
-3
src/core/service/plugins/app/index.js
src/core/service/plugins/app/index.js
+2
-2
src/core/service/plugins/index.js
src/core/service/plugins/index.js
+2
-2
src/platforms/app-plus/constants.js
src/platforms/app-plus/constants.js
+1
-1
src/platforms/app-plus/service/framework/app.js
src/platforms/app-plus/service/framework/app.js
+8
-3
src/platforms/app-plus/service/framework/plugins/index.js
src/platforms/app-plus/service/framework/plugins/index.js
+3
-3
src/platforms/app-plus/service/framework/subscribe-handlers/index.js
...ms/app-plus/service/framework/subscribe-handlers/index.js
+1
-14
未找到文件。
lib/apis.js
浏览文件 @
0afa02f1
...
...
@@ -184,7 +184,8 @@ const ui = [
'
setLeftWindowStyle
'
,
'
setRightWindowStyle
'
,
'
getLocale
'
,
'
setLocale
'
'
setLocale
'
,
'
onLocaleChange
'
]
const
event
=
[
...
...
@@ -267,4 +268,4 @@ const apis = [
...
ad
]
module
.
exports
=
apis
module
.
exports
=
apis
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
0afa02f1
此差异已折叠。
点击以展开。
packages/uni-app-plus/dist/view.umd.min.js
浏览文件 @
0afa02f1
此差异已折叠。
点击以展开。
packages/uni-h5/dist/index.umd.min.js
浏览文件 @
0afa02f1
此差异已折叠。
点击以展开。
packages/uni-h5/manifest.json
浏览文件 @
0afa02f1
...
...
@@ -35,6 +35,10 @@
]
]
],
"interceptors"
:
[
"/core/service/api/base/interceptor.js"
,
[]
],
"request"
:
[
"/platforms/h5/service/api/network/request.js"
,
[
...
...
@@ -837,6 +841,18 @@
"/platforms/h5/service/api/ui/windows.js"
,
[]
],
"getLocale"
:
[
"/core/service/api/ui/locale.js"
,
[]
],
"setLocale"
:
[
"/core/service/api/ui/locale.js"
,
[]
],
"onLocaleChange"
:
[
"/core/service/api/ui/locale.js"
,
[]
],
"$emit"
:
[
"/platforms/h5/service/api/base/event-bus.js"
,
[
...
...
src/core/helpers/i18n/index.js
浏览文件 @
0afa02f1
...
...
@@ -47,3 +47,22 @@ export const i18nMixin = i18n.mixin = {
}
export
const
setLocale
=
i18n
.
setLocale
export
const
getLocale
=
i18n
.
getLocale
export
function
initAppLocale
(
Vue
,
appVm
)
{
const
state
=
Vue
.
observable
({
locale
:
i18n
.
getLocale
()
})
const
localeWatchers
=
[]
appVm
.
$watchLocale
=
(
fn
)
=>
{
localeWatchers
.
push
(
fn
)
}
Object
.
defineProperty
(
appVm
,
'
$locale
'
,
{
get
()
{
return
state
.
locale
},
set
(
v
)
{
state
.
locale
=
v
localeWatchers
.
forEach
(
watch
=>
watch
(
v
))
}
})
}
src/core/service/api/ui/locale.js
浏览文件 @
0afa02f1
export
{
getLocale
,
setLocale
}
from
'
uni-core/helpers/i18n
'
import
{
invoke
}
from
'
uni-core/service/bridge
'
import
{
i18n
}
from
'
uni-helpers/i18n
'
export
function
getLocale
()
{
// 优先使用 $locale
const
app
=
getApp
({
allowDefault
:
true
})
if
(
app
&&
app
.
$vm
)
{
return
app
.
$vm
.
$locale
}
return
i18n
.
getLocale
()
}
export
function
setLocale
(
locale
)
{
const
oldLocale
=
getApp
().
$vm
.
$locale
if
(
oldLocale
!==
locale
)
{
getApp
().
$vm
.
$locale
=
locale
if
(
__PLATFORM__
===
'
app-plus
'
)
{
const
pages
=
getCurrentPages
()
pages
.
forEach
((
page
)
=>
{
UniServiceJSBridge
.
publishHandler
(
'
setLocale
'
,
locale
,
page
.
$page
.
id
)
})
weex
.
requireModule
(
'
plus
'
).
setLanguage
(
locale
)
}
callbacks
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
locale
})
})
return
true
}
return
false
}
const
callbacks
=
[]
export
function
onLocaleChange
(
callbackId
)
{
callbacks
.
push
(
callbackId
)
}
src/core/service/plugins/app/create-app.js
浏览文件 @
0afa02f1
import
{
initAppLocale
}
from
'
uni-helpers/i18n
'
import
initRouterGuard
from
'
./router-guard
'
let
appVm
=
false
...
...
@@ -23,7 +27,8 @@ export function getCurrentPages (isAll = false, ignoreError = false) {
childrenVm
=
layoutVm
}
childrenVm
.
$children
.
forEach
(
vm
=>
{
if
(
tabBarVm
!==
vm
&&
vm
.
$children
.
length
&&
vm
.
$children
[
0
].
$options
.
name
===
'
Page
'
&&
vm
.
$children
[
0
].
$slots
if
(
tabBarVm
!==
vm
&&
vm
.
$children
.
length
&&
vm
.
$children
[
0
].
$options
.
name
===
'
Page
'
&&
vm
.
$children
[
0
]
.
$slots
.
page
)
{
// vm.$children[0]=Page->PageBody->RealPage
const
pageBody
=
vm
.
$children
[
0
].
$children
.
find
(
vm
=>
vm
.
$options
.
name
===
'
PageBody
'
)
...
...
@@ -63,11 +68,11 @@ export function getCurrentPages (isAll = false, ignoreError = false) {
return
pages
}
export
default
function
createApp
(
vm
,
routes
)
{
export
default
function
createApp
(
Vue
,
vm
,
routes
)
{
appVm
=
vm
appVm
.
$vm
=
vm
appVm
.
globalData
=
appVm
.
$options
.
globalData
||
{}
initAppLocale
(
Vue
,
appVm
)
// initEvents(appVm)
initRouterGuard
(
appVm
,
routes
)
}
src/core/service/plugins/app/index.js
浏览文件 @
0afa02f1
...
...
@@ -10,10 +10,10 @@ export {
}
from
'
./create-app
'
export
function
createAppMixin
(
routes
,
entryRoute
)
{
export
function
createAppMixin
(
Vue
,
routes
,
entryRoute
)
{
return
{
created
:
function
AppCreated
()
{
createApp
(
this
,
routes
)
createApp
(
Vue
,
this
,
routes
)
// TODO
if
(
!
entryRoute
.
meta
.
name
)
{
// PageNotFound
UniServiceJSBridge
.
emit
(
'
onPageNotFound
'
,
{
...
...
src/core/service/plugins/index.js
浏览文件 @
0afa02f1
...
...
@@ -147,7 +147,7 @@ export default {
keepAliveInclude
}
}
const
appMixin
=
createAppMixin
(
routes
,
entryRoute
)
const
appMixin
=
createAppMixin
(
Vue
,
routes
,
entryRoute
)
// mixin app hooks
Object
.
keys
(
appMixin
).
forEach
(
hook
=>
{
options
[
hook
]
=
options
[
hook
]
?
[].
concat
(
appMixin
[
hook
],
options
[
hook
])
:
[
...
...
@@ -207,4 +207,4 @@ export default {
Vue
.
use
(
VueRouter
)
}
}
}
src/platforms/app-plus/constants.js
浏览文件 @
0afa02f1
...
...
@@ -21,4 +21,4 @@ export const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
export
const
WEBVIEW_INSERTED
=
'
webviewInserted
'
export
const
WEBVIEW_REMOVED
=
'
webviewRemoved
'
export
const
WEBVIEW_ID_PREFIX
=
'
webviewId
'
export
const
SET_LOCALE
=
'
i18n.
setLocale
'
export
const
SET_LOCALE
=
'
setLocale
'
src/platforms/app-plus/service/framework/app.js
浏览文件 @
0afa02f1
import
{
initAppLocale
}
from
'
uni-helpers/i18n
'
import
{
callAppHook
}
from
'
uni-core/service/plugins/util
'
...
...
@@ -207,12 +211,13 @@ export function clearTempFile () {
})
}
export
function
registerApp
(
appVm
)
{
export
function
registerApp
(
appVm
,
Vue
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
[uni-app] registerApp
'
)
}
appCtx
=
appVm
appCtx
.
$vm
=
appVm
initAppLocale
(
Vue
,
appVm
)
Object
.
assign
(
appCtx
,
defaultApp
)
// 拷贝默认实现
...
...
@@ -233,7 +238,7 @@ export function registerApp (appVm) {
initSubscribeHandlers
()
initAppLaunch
(
appVm
)
initAppLaunch
(
Vue
,
appVm
)
// 10s后清理临时文件
setTimeout
(
clearTempFile
,
10000
)
...
...
@@ -241,4 +246,4 @@ export function registerApp (appVm) {
__uniConfig
.
ready
=
true
process
.
env
.
NODE_ENV
!==
'
production
'
&&
perf
(
'
registerApp
'
)
}
}
src/platforms/app-plus/service/framework/plugins/index.js
浏览文件 @
0afa02f1
...
...
@@ -72,12 +72,12 @@ export default {
console
.
log
(
'
[uni-app] launchApp
'
)
}
plus
.
updateConfigInfo
&&
plus
.
updateConfigInfo
()
registerApp
(
this
)
registerApp
(
this
,
Vue
)
oldMount
.
call
(
this
,
el
,
hydrating
)
})
return
}
registerApp
(
this
)
registerApp
(
this
,
Vue
)
}
return
oldMount
.
call
(
this
,
el
,
hydrating
)
}
...
...
@@ -100,4 +100,4 @@ export default {
return
callback
?
undefined
:
result
}
}
}
}
src/platforms/app-plus/service/framework/subscribe-handlers/index.js
浏览文件 @
0afa02f1
...
...
@@ -7,8 +7,7 @@ import {
WEBVIEW_READY
,
WEB_INVOKE_APPSERVICE
,
WEBVIEW_INSERTED
,
WEBVIEW_REMOVED
,
SET_LOCALE
WEBVIEW_REMOVED
}
from
'
../../../constants
'
import
{
...
...
@@ -28,10 +27,6 @@ import {
onWebviewRemoved
}
from
'
./on-webview-lifecycle
'
import
{
i18n
}
from
'
uni-core/helpers/i18n
'
export
function
initSubscribeHandlers
()
{
const
{
on
,
...
...
@@ -75,12 +70,4 @@ export function initSubscribeHandlers () {
subscribe
(
WEBVIEW_INSERTED
,
onWebviewInserted
)
subscribe
(
WEBVIEW_REMOVED
,
onWebviewRemoved
)
i18n
.
i18n
.
watchLocale
(
locale
=>
{
const
pages
=
getCurrentPages
()
pages
.
forEach
(
page
=>
{
publishHandler
(
SET_LOCALE
,
locale
,
page
.
$page
.
id
)
})
weex
.
requireModule
(
'
plus
'
).
setLanguage
(
locale
)
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录